示例#1
0
 function parseRSS($filename, $showDetails, $showDescription, $path)
 {
     global $objDatabase, $_ARRAYLANG;
     if ($showDetails == 1) {
         $objResult = $objDatabase->Execute("SELECT id, FROM_UNIXTIME(xml_refresh, '%d. %M %Y %H:%i:%s') AS xml_refresh FROM " . DBPREFIX . "module_directory_dir WHERE rss_file='" . contrexx_addslashes($filename) . "'");
         if ($objResult !== false) {
             while (!$objResult->EOF) {
                 $this->rssRefresh = $objResult->fields['xml_refresh'];
                 // Not used -- see below
                 //                    $feedId = $objResult->fields['id'];
                 $objResult->MoveNext();
             }
         }
     }
     $filename = $this->mediaPath . $path . $filename;
     //rss class
     $rss = new \XML_RSS($filename);
     $rss->parse();
     if ($showDetails == 1) {
         //channel info
         $info = $rss->getChannelInfo();
         $this->rssTitle = $info['title'];
         //image
         foreach ($rss->getImages() as $img) {
             $this->rssImage = "<img src=" . $img['url'] . " alt='' /><br />";
         }
         // TODO: Never used
         //            $image = "<a href='".CONTREXX_SCRIPT_PATH."?section=Directory&amp;linkid=$feedId' target='_blank'><img src='/images/modules/directory/rss.gif' border='0' alt='Source' /></a>&nbsp;";
         $feeds = "<b>" . $this->rssTitle . "</b><br />" . $_ARRAYLANG['TXT_DIR_LAST_UPDATE'] . ": " . $this->rssRefresh . "<br />";
     }
     //items
     $feeds .= "<ul>";
     $x = 0;
     $limit = $this->settings['xmlLimit']['value'];
     foreach ($rss->getItems() as $value) {
         if ($x < $limit) {
             $feeds .= "<li><a href='" . $value['link'] . "' target='_blank'>" . $value['title'] . "</a><br />";
             if ($showDescription == 1) {
                 $feeds .= substr($value['description'], 0, 200);
             }
             $feeds .= "</li>";
             $x++;
         }
     }
     $feeds .= "</ul>";
     return $feeds;
 }
示例#2
0
 function showNewsPreview($id)
 {
     global $objDatabase, $_ARRAYLANG;
     $query = "SELECT filename,\n             FROM_UNIXTIME(time, '%d. %M %Y, %H:%i') AS time\n                      FROM " . DBPREFIX . "module_feed_news\n                     WHERE id = '" . $id . "'";
     $objResult = $objDatabase->Execute($query);
     $filename = $this->feedpath . $objResult->fields['filename'];
     //rss class
     $rss = new \XML_RSS($filename);
     $rss->parse();
     //channel info
     $info = $rss->getChannelInfo();
     echo "<b>" . strip_tags($info['title']) . "</b><br />";
     echo $_ARRAYLANG['TXT_FEED_LAST_UPDATE'] . ": " . $objResult->fields['time'] . "<br />";
     //image
     foreach ($rss->getImages() as $img) {
         if ($img['url'] != '') {
             echo '<img src="' . strip_tags($img['url']) . '" /><br />';
         }
     }
     echo '<br />';
     echo '<i>' . $_ARRAYLANG['TXT_FEED_MESSAGE_IMPORTANT'] . '</i><br />';
     //items
     foreach ($rss->getItems() as $value) {
         echo '<li>' . strip_tags($value['title']) . '</li>';
     }
 }
示例#3
0
 function showNews()
 {
     global $objDatabase, $_ARRAYLANG, $_LANGID;
     $this->_objTpl->setTemplate($this->pageContent, true, true);
     //feed path
     $this->feedpath = \Env::get('cx')->getWebsiteFeedPath() . '/';
     //active (with $_LANGID) categories
     $query = "SELECT id,\n                           name\n                      FROM " . DBPREFIX . "module_feed_category\n                     WHERE status = '1'\n                       AND lang = '" . $_LANGID . "'\n                  ORDER BY pos";
     if ($objResult = $objDatabase->Execute($query)) {
         while (!$objResult->EOF) {
             $cat_id[$objResult->fields['id']] = $objResult->fields['id'];
             $cat_name[$objResult->fields['id']] = $objResult->fields['name'];
             $objResult->MoveNext();
         }
     }
     //active news
     $query = "SELECT id,\n                           subid,\n                           name\n                      FROM " . DBPREFIX . "module_feed_news\n                     WHERE status = '1'\n                  ORDER BY pos";
     $objResult = $objDatabase->Execute($query);
     while (!$objResult->EOF) {
         $news_subid[$objResult->fields['subid']][$objResult->fields['id']] = $objResult->fields['subid'];
         $news_id[$objResult->fields['subid']][$objResult->fields['id']] = $objResult->fields['id'];
         $news_name[$objResult->fields['subid']][$objResult->fields['id']] = $objResult->fields['name'];
         $objResult->MoveNext();
     }
     //no empty categories
     if (is_array($cat_id)) {
         foreach ($cat_id as $x) {
             if (!isset($news_id[$x])) {
                 unset($cat_id[$x]);
                 unset($cat_name[$x]);
             }
         }
     }
     if (count($cat_id) == 0) {
         unset($cat_id);
     }
     //output structure
     if (!is_array($cat_id)) {
         if (!isset($_GET['cat']) and !isset($_GET['news'])) {
             $this->_objTpl->setVariable('FEED_NO_NEWSFEED', $_ARRAYLANG['TXT_FEED_NO_NEWSFEED']);
         } else {
             \Cx\Core\Csrf\Controller\Csrf::header("Location: " . CONTREXX_DIRECTORY_INDEX . "?section=Feed");
         }
     } else {
         if ($this->_objTpl->blockExists('feed_cat')) {
             foreach ($cat_id as $x) {
                 //out cat
                 $this->_objTpl->setVariable('FEED_CAT_NAME', $cat_name[$x]);
                 //out news
                 foreach ($news_id[$x] as $y) {
                     $this->_objTpl->setVariable(array('FEED_NEWS_LINK' => CONTREXX_DIRECTORY_INDEX . '?section=Feed&amp;cat=' . $news_subid[$x][$y] . '&amp;news=' . $news_id[$x][$y], 'FEED_NEWS_NAME' => strip_tags($news_name[$x][$y])));
                     $this->_objTpl->parse('feed_news');
                 }
                 $this->_objTpl->parse('feed_cat');
             }
         }
         // first access
         if (!isset($_GET['cat']) and !isset($_GET['news'])) {
             reset($cat_id);
             $_GET['cat'] = current($cat_id);
             reset($news_id[$_GET['cat']]);
             $_GET['news'] = current($news_id[$_GET['cat']]);
             /*
                             foreach($cat_id as $x)
                             {
                                 $_GET['cat'] = $cat_id[$x];
             
                                 foreach($news_id[$x] as $y)
                                 {
                                     $_GET['news'] = $news_id[$x][$y];
                                     break;
                                 }
                                 break;
                             }*/
         }
         $getCat = intval($_GET['cat']);
         $getNews = intval($_GET['news']);
         //refresh control
         $query = "SELECT time,\n                               cache\n                          FROM " . DBPREFIX . "module_feed_news\n                         WHERE id = '" . $getNews . "'\n                           AND subid = '" . $getCat . "'\n                           AND status = '1'";
         $objResult = $objDatabase->Execute($query);
         if ($objResult->RecordCount() == 0) {
             \Cx\Core\Csrf\Controller\Csrf::header("Location: " . CONTREXX_DIRECTORY_INDEX . "?section=Feed");
             die;
         }
         $old_time = $objResult->fields['time'] + $objResult->fields['cache'];
         $time = time();
         if ($time >= $old_time) {
             $this->showNewsRefresh($getNews, $time, $this->feedpath);
         }
         $query = "SELECT name,\n                               filename,\n                               time,\n                               articles,\n                               image\n                          FROM " . DBPREFIX . "module_feed_news\n                         WHERE id = '" . $getNews . "'\n                           AND subid = '" . $getCat . "'\n                           AND status = '1'";
         $objResult = $objDatabase->Execute($query);
         //output selected news
         $news_name = $objResult->fields['name'];
         $this->_objTpl->setVariable(array('FEED_CAT' => $cat_name[$getCat], 'FEED_PAGE' => $news_name));
         $filename = $this->feedpath . $objResult->fields['filename'];
         //rss class
         $rss = new \XML_RSS($filename);
         $rss->parse();
         //channel info
         $out_title = strip_tags($rss->channel['title']);
         $out_time = date(ASCMS_DATE_FORMAT, $objResult->fields['time']);
         //image
         foreach ($rss->getImages() as $img) {
             if ($img['url'] != '' && $objResult->fields['image'] == 1) {
                 $out_image = '<img src="' . strip_tags($img['url']) . '" alt="" /><br />';
             }
         }
         $this->_objTpl->setVariable(array('FEED_IMAGE' => $out_image, 'FEED_TITLE' => $out_title, 'FEED_TIME' => $out_time, 'TXT_FEED_LAST_UPTDATE' => $_ARRAYLANG['TXT_FEED_LAST_UPDATE']));
         //items
         $x = 0;
         foreach ($rss->getItems() as $value) {
             if ($x < $objResult->fields['articles']) {
                 $this->_objTpl->setVariable(array('FEED_ROWCLASS' => $x % 2 ? 'row2' : 'row1', 'FEED_DATE' => date('d.m.Y', strtotime($value['pubdate'])), 'FEED_LINK' => $value['link'], 'FEED_NAME' => $value['title']));
                 $this->_objTpl->parse('feed_output_news');
                 $x++;
             }
         }
         $this->_objTpl->parse('feed_show_news');
     }
 }
 function testGetImages()
 {
     $r = new XML_RSS(dirname(__FILE__) . '/test.rss');
     $r->parse();
     $expected = array();
     $expected[] = array('title' => 'PEAR', 'url' => 'http://pear.php.net/gifs/pearsmall.gif', 'link' => 'http://pear.php.net/');
     $actual = $r->getImages();
     $this->assertEquals($expected, $actual);
 }