SimplePie::get_type PHP Method

get_type() public method

This returns a SIMPLEPIE_TYPE_* constant, which can be tested against using {@link http://php.net/language.operators.bitwise bitwise operators}
See also: SIMPLEPIE_TYPE_NONE Unknown.
See also: SIMPLEPIE_TYPE_RSS_090 RSS 0.90.
See also: SIMPLEPIE_TYPE_RSS_091_NETSCAPE RSS 0.91 (Netscape).
See also: SIMPLEPIE_TYPE_RSS_091_USERLAND RSS 0.91 (Userland).
See also: SIMPLEPIE_TYPE_RSS_091 RSS 0.91.
See also: SIMPLEPIE_TYPE_RSS_092 RSS 0.92.
See also: SIMPLEPIE_TYPE_RSS_093 RSS 0.93.
See also: SIMPLEPIE_TYPE_RSS_094 RSS 0.94.
See also: SIMPLEPIE_TYPE_RSS_10 RSS 1.0.
See also: SIMPLEPIE_TYPE_RSS_20 RSS 2.0.x.
See also: SIMPLEPIE_TYPE_RSS_RDF RDF-based RSS.
See also: SIMPLEPIE_TYPE_RSS_SYNDICATION Non-RDF-based RSS (truly intended as syndication format).
See also: SIMPLEPIE_TYPE_RSS_ALL Any version of RSS.
See also: SIMPLEPIE_TYPE_ATOM_03 Atom 0.3.
See also: SIMPLEPIE_TYPE_ATOM_10 Atom 1.0.
See also: SIMPLEPIE_TYPE_ATOM_ALL Any version of Atom.
See also: SIMPLEPIE_TYPE_ALL Any known/supported feed type.
Since: 0.8 (usage changed to using constants in 1.0)
public get_type ( ) : integer
return integer SIMPLEPIE_TYPE_* constant
    public function get_type()
    {
        if (!isset($this->data['type'])) {
            $this->data['type'] = SIMPLEPIE_TYPE_ALL;
            if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) {
                $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
            } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) {
                $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
            } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) {
                if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel']) || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image']) || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']) || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput'])) {
                    $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
                }
                if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel']) || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image']) || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']) || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput'])) {
                    $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
                }
            } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'])) {
                $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
                if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) {
                    switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) {
                        case '0.91':
                            $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
                            if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) {
                                switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) {
                                    case '0':
                                        $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
                                        break;
                                    case '24':
                                        $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
                                        break;
                                }
                            }
                            break;
                        case '0.92':
                            $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
                            break;
                        case '0.93':
                            $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
                            break;
                        case '0.94':
                            $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
                            break;
                        case '2.0':
                            $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
                            break;
                    }
                }
            } else {
                $this->data['type'] = SIMPLEPIE_TYPE_NONE;
            }
        }
        return $this->data['type'];
    }

Usage Example

Example #1
0
 /**
  */
 public function add()
 {
     $feed_user_title = $this->input->post('feed_title', TRUE);
     $feed_url = $this->input->post('feed_url');
     $usercat = $this->input->post('category');
     $feed_filter_type = $this->input->post('feed_type');
     $_icon = $this->input->post('favicon_icon');
     $favicon_icon = $_icon;
     if (!isset($feed_url) || $feed_url == '') {
         $this->stencil->title('Feeds');
         $this->stencil->layout('admin_layout');
         $this->stencil->css(array('admin_css/bootstrap.min', 'admin_css/bootstrap-responsive.min', 'admin_css/styles'));
         $this->stencil->js(array('vendors/datatables/js/jquery.dataTables.min.js', 'DT_bootstrap'));
         $this->stencil->paint('admin/feeds/add');
     } else {
         $check = $this->validateUrl($feed_url);
         if ($check == FALSE) {
             echo json_encode(array('result' => 'fail', 'msg' => '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>Url Already exists in the database!</div>'));
             die;
         }
         $feed = new SimplePie();
         $feed->set_feed_url($feed_url);
         $feed->set_cache_location(APPPATH . '/cache');
         $feed->set_output_encoding('ISO-8859-1');
         $feed->init();
         $feed->handle_content_type();
         // Language
         $lang = $feed->get_language();
         $language = isset($lang) ? $lang : 'en-us';
         if ($feed->get_type() & SIMPLEPIE_TYPE_NONE) {
             $feed_type = 'Unknown';
         } elseif ($feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) {
             $feed_type = 'RSS';
         } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) {
             $feed_type = 'Atom';
         } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ALL) {
             $feed_type = 'Supported';
         }
         // Author
         if ($author = $feed->get_author()) {
             $feedAuthor = $author->get_name();
         } else {
             $feedAuthor = '';
         }
         if ($feed->error()) {
             echo json_encode(array('result' => 'fail', 'msg' => '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>Found error while making request</div>'));
         } else {
             //                $return = $this->feed_model->addFeeds($feed->get_items(0, 500));
             $feed_image_link = $feed->get_image_link();
             $feed_image_url = $feed->get_image_url();
             $feed_image_title = $feed->get_image_title();
             $return = $this->feedModel->addFeeds($feed->get_items(0, 500), $feed_image_link, $feed_image_url, $feed_image_title, $usercat, $feed_url, $language, $feed_type, $feedAuthor, $feed_filter_type, $feed_user_title, $favicon_icon);
             if ($return) {
                 echo json_encode(array('result' => 'success', 'msg' => '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>Blog is added successfully</div>'));
             } else {
                 echo json_encode(array('result' => 'fail', 'msg' => '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>Found error while making request</div>'));
             }
         }
     }
 }
All Usage Examples Of SimplePie::get_type