Exemplo n.º 1
0
 /**
  * @desc Loads a feed by its url
  * @param string $url the feed url
  */
 public function load_file($url)
 {
     if (($file = @file_get_contents($url)) !== false) {
         $this->data = new FeedData();
         if (preg_match('`<entry>(.*)</entry>`is', $file)) {
             $expParsed = explode('<entry>', $file);
             $nbItems = count($expParsed) - 1 > $nbItems ? $nbItems : count($expParsed) - 1;
             $this->data->set_date(preg_match('`<updated>(.*)</updated>`is', $expParsed[0], $var) ? $var[1] : '');
             $this->data->set_title(preg_match('`<title>(.*)</title>`is', $expParsed[0], $var) ? $var[1] : '');
             $this->data->set_link(preg_match('`<link href="(.*)"/>`is', $expParsed[0], $var) ? $var[1] : '');
             $this->data->set_host(preg_match('`<link href="(.*)"/>`is', $expParsed[0], $var) ? $var[1] : '');
             for ($i = 1; $i <= $nbItems; $i++) {
                 $item = new FeedItem();
                 $item->set_title(preg_match('`<title>(.*)</title>`is', $expParsed[$i], $title) ? $title[1] : '');
                 $item->set_link(preg_match('`<link href="(.*)"/>`is', $expParsed[$i], $url) ? $url[1] : '');
                 $item->set_guid(preg_match('`<id>(.*)</id>`is', $expParsed[$i], $guid) ? $guid[1] : '');
                 $item->set_desc(preg_match('`<summary>(.*)</summary>`is', $expParsed[$i], $desc) ? $desc[1] : '');
                 $item->set_date(preg_match('`<updated>(.*)</updated>`is', $expParsed[$i], $date) ? new Date(strtotime($date[1]), Timezone::SERVER_TIMEZONE) : null);
                 $enclosure = preg_match('`<enclosure rel="enclosure" url="(.*)" length="(.*)" type="(.*)" />`is', $expParsed[$i]);
                 if ($enclosure) {
                     $enclosure_item = new FeedItemEnclosure();
                     $enclosure_item->set_lenght($enclosure[2]);
                     $enclosure_item->set_type($enclosure[3]);
                     $enclosure_item->set_url($enclosure[1]);
                     $item->set_enclosure($enclosure_item);
                 }
                 $this->data->add_item($item);
             }
             return true;
         }
         return false;
     }
     return false;
 }
    function get_feed_data_struct($idcat = 0, $name = '')
    {
        if (MediaService::get_categories_manager()->get_categories_cache()->category_exists($idcat)) {
            require_once PATH_TO_ROOT . '/media/media_constant.php';
            $category = MediaService::get_categories_manager()->get_categories_cache()->get_category($idcat);
            $site_name = GeneralConfig::load()->get_site_name();
            $site_name = $idcat != Category::ROOT_CATEGORY ? $site_name . ' : ' . $category->get_name() : $site_name;
            $feed_module_name = LangLoader::get_message('module_title', 'common', 'media');
            $data = new FeedData();
            $data->set_title($feed_module_name . ' - ' . $site_name);
            $data->set_date(new Date());
            $data->set_link(SyndicationUrlBuilder::rss('media', $idcat));
            $data->set_host(HOST);
            $data->set_desc($feed_module_name . ' - ' . $site_name);
            $data->set_lang(LangLoader::get_message('xml_lang', 'main'));
            $data->set_auth_bit(Category::READ_AUTHORIZATIONS);
            $categories = MediaService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true);
            $ids_categories = array_keys($categories);
            $results = PersistenceContext::get_querier()->select('SELECT media.*, cat.image
				FROM ' . MediaSetup::$media_table . ' media
				LEFT JOIN ' . MediaSetup::$media_cats_table . ' cat ON cat.id = media.idcat
				WHERE media.idcat IN :ids_categories
				AND infos = :status_approved
				ORDER BY timestamp DESC', array('ids_categories' => $ids_categories, 'status_approved' => MEDIA_STATUS_APROBED));
            foreach ($results as $row) {
                // Rewriting
                $link = new Url('/media/media' . url('.php?id=' . $row['id'], '-' . $row['id'] . '+' . Url::encode_rewrite($row['name']) . '.php'));
                $item = new FeedItem();
                $item->set_title($row['name']);
                $item->set_link($link);
                $item->set_guid($link);
                $item->set_desc(FormatingHelper::second_parse($row['contents']));
                $item->set_date(new Date($row['timestamp'], Timezone::SERVER_TIMEZONE));
                $item->set_image_url($row['image']);
                $item->set_auth(MediaService::get_categories_manager()->get_heritated_authorizations($row['idcat'], Category::READ_AUTHORIZATIONS, Authorizations::AUTH_PARENT_PRIORITY));
                $enclosure = new FeedItemEnclosure();
                $enclosure->set_lenght(@filesize($row['url']));
                $enclosure->set_type($row['mime_type']);
                $enclosure->set_url($row['url']);
                $item->set_enclosure($enclosure);
                $data->add_item($item);
            }
            $results->dispose();
            return $data;
        }
    }
Exemplo n.º 3
0
 /**
  * @desc Loads a feed by its url
  * @param string $url the feed url
  */
 public function load_file($url)
 {
     if (($file = @file_get_contents($url)) !== false) {
         $this->data = new FeedData();
         if (preg_match('`<item>(.*)</item>`is', $file)) {
             $expParsed = explode('<item>', $file);
             $nbItems = count($expParsed) - 1 > $nbItems ? $nbItems : count($expParsed) - 1;
             $this->data->set_date(preg_match('`<!-- RSS generated by PHPBoost on (.*) -->`is', $expParsed[0], $var) ? $var[1] : '');
             $this->data->set_title(preg_match('`<title>(.*)</title>`is', $expParsed[0], $var) ? $var[1] : '');
             $this->data->set_link(preg_match('`<atom:link href="(.*)" rel="self" type="application/rss+xml" />`is', $expParsed[0], $var) ? $var[1] : '');
             $this->data->set_host(preg_match('`<link>(.*)</link>`is', $expParsed[0], $var) ? $var[1] : '');
             $this->data->set_desc(preg_match('`<description>(.*)</description>`is', $expParsed[0], $var) ? $var[1] : '');
             $this->data->set_lang(preg_match('`<language>(.*)</language>`is', $expParsed[0], $var) ? $var[1] : '');
             for ($i = 1; $i <= $nbItems; $i++) {
                 $pubDate = strtotime($date[1]);
                 $item = new FeedItem();
                 $item->set_title(preg_match('`<title>(.*)</title>`is', $expParsed[$i], $title) ? $title[1] : '');
                 $item->set_link(preg_match('`<link>(.*)</link>`is', $expParsed[$i], $url) ? $url[1] : '');
                 $item->set_guid(preg_match('`<guid>(.*)</guid>`is', $expParsed[$i], $guid) ? $guid[1] : '');
                 $item->set_desc(preg_match('`<desc>(.*)</desc>`is', $expParsed[$i], $desc) ? $desc[1] : '');
                 $item->set_date(preg_match('`<pubDate>(.*)</pubDate>`is', $expParsed[$i], $date) ? new Date(strtotime($date[1]), Timezone::SERVER_TIMEZONE) : null);
                 $enclosure = preg_match('`<enclosure url="(.*)" length="(.*)" type="(.*)" />`is', $expParsed[$i]);
                 if ($enclosure) {
                     $enclosure_item = new FeedItemEnclosure();
                     $enclosure_item->set_lenght($enclosure[2]);
                     $enclosure_item->set_type($enclosure[3]);
                     $enclosure_item->set_url($enclosure[1]);
                     $item->set_enclosure($enclosure_item);
                 }
                 $this->data->add_item($item);
             }
             return true;
         }
         return false;
     }
     return false;
 }