Exemple #1
0
 /**
  * A method to launch and display the widget
  *
  * @param array $aParams The parameters array, usually $_REQUEST
  */
 function display()
 {
     if (!$this->oTpl->is_cached()) {
         RV::disableErrorHandling();
         $oRss = new XML_RSS($this->url);
         $result = $oRss->parse();
         RV::enableErrorHandling();
         // ignore bad character error which could appear if rss is using invalid characters
         if (PEAR::isError($result)) {
             if (!strstr($result->getMessage(), 'Invalid character')) {
                 PEAR::raiseError($result);
                 // rethrow
                 $this->oTpl->caching = false;
             }
         }
         $aPost = array_slice($oRss->getItems(), 0, $this->posts);
         foreach ($aPost as $key => $aValue) {
             $aPost[$key]['origTitle'] = $aValue['title'];
             if (strlen($aValue['title']) > 38) {
                 $aPost[$key]['title'] = substr($aValue['title'], 0, 38) . '...';
             }
         }
         $this->oTpl->assign('title', $this->title);
         $this->oTpl->assign('feed', $aPost);
         $this->oTpl->assign('siteTitle', $this->siteTitle);
         $this->oTpl->assign('siteUrl', $this->siteUrl);
     }
     $this->oTpl->display();
 }
Exemple #2
0
 /**
  * function get_items:
  * this function returns the rss_feed items from a single url
  *
  * @param string $url the url of the rss_feed
  * 
  * @return mixed array with the items
  *
  */
 public function get_items($url)
 {
     $rss = new XML_RSS($url);
     $rss->parse();
     $items = $rss->getItems();
     return $items;
 }
 function testGetItems()
 {
     $r = new XML_RSS(dirname(__FILE__) . '/test.rss');
     $r->parse();
     $expected = array();
     $expected[] = array('title' => 'PHP homepage', 'link' => 'http://php.net/', 'category' => array('php'));
     $expected[] = array('title' => 'PEAR homepage', 'link' => 'http://pear.php.net/', 'category' => array('php', 'pear'));
     $expected[] = array('title' => 'PHP-GTK homepage', 'link' => 'http://gtk.php.net/', 'category' => array('php', 'gtk'));
     $expected[] = array('title' => 'PHP QA homepage', 'link' => 'http://qa.php.net/', 'category' => array('php', 'qa'));
     $actual = $r->getItems();
     $this->assertEquals($expected, $actual);
 }
Exemple #4
0
 /**
  * リソースリクエスト実行
  *
  * リモートURLにアクセスしてRSSだったら配列に、
  * そうでなかったらHTTP Body文字列をリソースとして扱います。
  *
  * @return BEAR_Ro
  * @throws BEAR_Resource_Execute_Exception
  */
 public function request()
 {
     $reqMethod = array();
     $reqMethod[BEAR_Resource::METHOD_CREATE] = HTTP_Request2::METHOD_POST;
     $reqMethod[BEAR_Resource::METHOD_READ] = HTTP_Request2::METHOD_GET;
     $reqMethod[BEAR_Resource::METHOD_UPDATE] = HTTP_Request2::METHOD_PUT;
     $reqMethod[BEAR_Resource::METHOD_DELETE] = HTTP_Request2::METHOD_DELETE;
     assert(isset($reqMethod[$this->_config['method']]));
     try {
         // 引数以降省略可能  config で proxy とかも設定可能
         $request = new HTTP_Request2($this->_config['uri'], $reqMethod[$this->_config['method']]);
         $request->setHeader("user-agent", 'BEAR/' . BEAR::VERSION);
         $request->setConfig("follow_redirects", true);
         if ($this->_config['method'] === BEAR_Resource::METHOD_CREATE || $this->_config['method'] === BEAR_Resource::METHOD_UPDATE) {
             foreach ($this->_config['values'] as $key => $value) {
                 $request->addPostParameter($key, $value);
             }
         }
         $response = $request->send();
         $code = $response->getStatus();
         $headers = $response->getHeader();
         if ($code == 200) {
             $body = $response->getBody();
         } else {
             $info = array('code' => $code, 'headers' => $headers);
             throw $this->_exception($response->getBody(), $info);
         }
     } catch (HTTP_Request2_Exception $e) {
         throw $this->_exception($e->getMessage());
     } catch (Exception $e) {
         throw $this->_exception($e->getMessage());
     }
     $rss = new XML_RSS($body, 'utf-8', 'utf-8');
     PEAR::setErrorHandling(PEAR_ERROR_RETURN);
     // @todo Panda::setPearErrorHandling(仮称)に変更しエラーを画面化しないようにする
     $rss->parse();
     $items = $rss->getItems();
     if (is_array($items) && count($items) > 0) {
         $body = $items;
         $headers = $rss->getChannelInfo();
         $headers['type'] = 'rss';
     } else {
         $headers['type'] = 'string';
         $body = array($body);
     }
     // UTF-8に
     $encode = mb_convert_variables('UTF-8', 'auto', $body);
     $ro = BEAR::factory('BEAR_Ro')->setBody($body)->setHeaders($headers);
     /* @var $ro BEAR_Ro */
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('Panda', 'onPearError'));
     return $ro;
 }
Exemple #5
0
 /**
  * Bind RSS data 
  * 
  * @access  public
  * @param   string $file        RSS file
  * @param   array $options      Options as an associative array
  * @return  mixed               true on success, PEAR_Error on failure 
  */
 function bind($file, $options = array())
 {
     if ($options) {
         $this->setOptions($options);
     }
     $rss = new XML_RSS($file);
     $result = $rss->parse();
     if (PEAR::isError($result)) {
         return $result;
     }
     $this->_ar = $rss->getItems();
     return true;
 }
Exemple #6
0
 function getHomePage()
 {
     global $_CORELANG, $_CONFIG, $objTemplate, $objDatabase;
     $objTemplate->addBlockfile('ADMIN_CONTENT', 'content', 'index_home.html');
     \JS::activate('jquery-bootstrap');
     \JS::activate('jquery-jqplot');
     $arrAccessIDs = array(5, 10, 76, '84_1', 6, 19, 75, '84_2', 17, 18, 7, 32, 21);
     foreach ($arrAccessIDs as $id) {
         $accessID = strpos($id, '_') ? substr($id, 0, strpos($id, '_')) : $id;
         if (\Permission::checkAccess($accessID, 'static', true)) {
             $objTemplate->touchBlock('check_access_' . $id);
         } else {
             $objTemplate->hideBlock('check_access_' . $id);
         }
     }
     $objTemplate->setVariable(array('CSRF' => \Cx\Core\Csrf\Controller\Csrf::param(), 'TXT_LAST_LOGIN' => htmlentities($_CORELANG['TXT_LAST_LOGIN'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_CONTREXX_NEWS' => htmlentities($_CORELANG['TXT_CONTREXX_NEWS'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_CREATING_AND_PUBLISHING' => htmlentities($_CORELANG['TXT_CREATING_AND_PUBLISHING'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_EVALUATE_AND_VIEW' => htmlentities($_CORELANG['TXT_EVALUATE_AND_VIEW'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_MANAGE' => htmlentities($_CORELANG['TXT_MANAGE'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_NEW_SITE' => htmlentities($_CORELANG['TXT_NEW_PAGE'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_ADD_NEWS' => htmlentities($_CORELANG['TXT_ADD_NEWS'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_ADD_BLOCK' => htmlentities($_CORELANG['TXT_ADD_BLOCK'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_ADD_FORM' => htmlentities($_CORELANG['TXT_ADD_FORM'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_CONTENT_MANAGER' => htmlentities($_CORELANG['TXT_CONTENT_MANAGER'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_STATS' => htmlentities($_CORELANG['TXT_STATS'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_WORKFLOW' => htmlentities($_CORELANG['TXT_WORKFLOW'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_FORMS' => htmlentities($_CORELANG['TXT_FORMS'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_SYSTEM_SETTINGS' => htmlentities($_CORELANG['TXT_SYSTEM_SETTINGS'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_USER_MANAGER' => htmlentities($_CORELANG['TXT_USER_ADMINISTRATION'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_MEDIA_MANAGER' => htmlentities($_CORELANG['TXT_MEDIA_MANAGER'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_IMAGE_ADMINISTRATION' => htmlentities($_CORELANG['TXT_IMAGE_ADMINISTRATION'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_SKINS' => htmlentities($_CORELANG['TXT_DESIGN_MANAGEMENT'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_VISITORS' => htmlentities($_CORELANG['TXT_CORE_VISITORS'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_REQUESTS' => htmlentities($_CORELANG['TXT_CORE_REQUESTS'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_DASHBOARD_NEWS_ALERT' => htmlentities($_CORELANG['TXT_DASHBOARD_NEWS_ALERT'], ENT_QUOTES, CONTREXX_CHARSET), 'TXT_DASHBOARD_STATS_ALERT' => htmlentities($_CORELANG['TXT_DASHBOARD_STATS_ALERT'], ENT_QUOTES, CONTREXX_CHARSET)));
     $objTemplate->setGlobalVariable('TXT_LOGOUT', $_CORELANG['TXT_LOGOUT']);
     if (\Permission::checkAccess(17, 'static', true)) {
         $objTemplate->touchBlock('news_delete');
         $objTemplate->touchBlock('stats_delete');
     } else {
         $objTemplate->hideBlock('news_delete');
         $objTemplate->hideBlock('stats_delete');
     }
     $license = \Cx\Core_Modules\License\License::getCached($_CONFIG, $objDatabase);
     $message = $license->getMessage(true, \FWLanguage::getLanguageCodeById(BACKEND_LANG_ID), $_CORELANG);
     if ($message instanceof \Cx\Core_Modules\License\Message && strlen($message->getText()) && $message->showInDashboard()) {
         $licenseManager = new \Cx\Core_Modules\License\LicenseManager('', null, $_CORELANG, $_CONFIG, $objDatabase);
         $objTemplate->setVariable('MESSAGE_TITLE', contrexx_raw2xhtml($licenseManager->getReplacedMessageText($message)));
         $licenseType = $message->getType();
         switch ($licenseType) {
             case '--this case is not defined by license --':
                 $bsCalloutType = 'danger';
                 break;
             case 'alertbox':
                 $bsCalloutType = 'warning';
                 break;
             case 'okbox':
             default:
                 $bsCalloutType = 'info';
                 break;
         }
         $objTemplate->setVariable('MESSAGE_TYPE', $bsCalloutType);
         $objTemplate->setVariable('MESSAGE_LINK', contrexx_raw2xhtml($message->getLink()));
         $objTemplate->setVariable('MESSAGE_LINK_TARGET', contrexx_raw2xhtml($message->getLinkTarget()));
     }
     // TODO: Unused
     //        $objFWUser = \FWUser::getFWUserObject();
     $objResult = $objDatabase->SelectLimit('SELECT `logs`.`datetime`, `users`.`username`
         FROM `' . DBPREFIX . 'log` AS `logs`
         LEFT JOIN `' . DBPREFIX . 'access_users` AS `users`
         ON `users`.`id`=`logs`.`userid`
         ORDER BY `logs`.`id` DESC', 1);
     if ($objResult && $objResult->RecordCount() > 0) {
         $objTemplate->setVariable(array('LAST_LOGIN_USERNAME' => contrexx_raw2xhtml($objResult->fields['username']), 'LAST_LOGIN_TIME' => date('d.m.Y', strtotime($objResult->fields['datetime']))));
         $objTemplate->parse('last_login');
     } else {
         $objTemplate->setVariable('LOG_ERROR_MESSAGE', $_CORELANG['TXT_NO_DATA_FOUND']);
     }
     if ($_CONFIG['dashboardStatistics'] == 'on') {
         $arrStatistics = $this->getStatistics();
         $objTemplate->setVariable(array('STATS_TITLE' => $_CORELANG['TXT_CORE_STATS_FROM'] . ' ' . reset($arrStatistics['dates']) . ' - ' . end($arrStatistics['dates']), 'STATS_TICKS' => json_encode($arrStatistics['ticks']), 'STATS_DATES' => json_encode($arrStatistics['dates']), 'STATS_VISITORS' => json_encode($arrStatistics['visitors']), 'STATS_REQUESTS' => json_encode($arrStatistics['requests']), 'STATS_TOTAL_VISITORS' => array_sum($arrStatistics['visitors']), 'STATS_TOTAL_REQUESTS' => array_sum($arrStatistics['requests'])));
     } else {
         $objTemplate->hideBlock('stats');
         $objTemplate->hideBlock('stats_javascript');
     }
     $arrItems = null;
     // This index may be unset
     if (!empty($_CONFIG['dashboardNewsSrc'])) {
         $objRss = new \XML_RSS($_CONFIG['dashboardNewsSrc'] . '?version=' . $_CONFIG['coreCmsVersion']);
         $objRss->parse();
         $arrItems = $objRss->getItems();
     }
     if (!empty($arrItems) && $_CONFIG['dashboardNews'] == 'on') {
         if (empty($arrItems[0]['description'])) {
             $objTemplate->setVariable(array('NEWS_CONTENT' => $arrItems[0]['title'], 'NEWS_LINK' => $arrItems[0]['link']));
             $objTemplate->hideBlock('news_title');
         } else {
             $objTemplate->setVariable(array('NEWS_TITLE' => $arrItems[0]['title'], 'NEWS_CONTENT' => $arrItems[0]['description'], 'NEWS_LINK' => $arrItems[0]['link']));
         }
         $objTemplate->parse('news');
     } else {
         $objTemplate->hideBlock('news');
     }
 }
Exemple #7
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;
 }
Exemple #8
0
<?
$title = "Recent Package Updates";
$cvs_author = '$Author: gecko2 $';
$cvs_date = '$Date: 2010/09/15 23:43:38 $';
$is_home = 1;

$metatags = '<meta name="description" content="Fink, a distribution of Unix software for Mac OS X and Darwin">
<meta name="keywords" content="Mac OS X, Darwin, GNU, Unix, GNOME, KDE, software, distribution, Fink">
';

include "header.inc";
include "XML/RSS.php";
?>

<h1>Recent Package Updates</h1>

<?
$rss = new XML_RSS("news/rdf/fink-unstable-no-splitoffs.rdf");
$rss->parse();

$count = 0;
foreach($rss->getItems() as $item) {
	$date = $item['dc:date'];
	$date = preg_replace('|T.*$|', '', $date);
	echo "<a style=\"text-decoration: none\" href=\"" . htmlentities($item['link']) . "\" name=\"" . urlencode($item['title']) . "\"><span class=\"news-date\">" . $date . ": </span><span class=\"news-headline\" style=\"text-decoration: underline\">" . $item['title'] . "</span></a><br />\n";
	echo $item['description'];
}

include "footer.inc";
?>
Exemple #9
0
 /**
  * Search keyword on OpenSearch compatible engine.
  *
  * @access public
  * @param  string $query keyword
  * @return array
  */
 function search($query)
 {
     $url = $this->_setupQuery($query);
     // trigger_error($url);
     $rss = new XML_RSS($url);
     array_push($rss->channelTags, 'OPENSEARCH:TOTALRESULTS', 'OPENSEARCH:STARTINDEX', 'OPENSEARCH:ITEMSPERPAGE');
     $rss->parse();
     $ch = $rss->getChannelInfo();
     if (isset($ch['opensearch:totalresults'])) {
         $this->pager_param['totalResults'] = $ch['opensearch:totalresults'];
     }
     if (isset($ch['opensearch:itemsperpage'])) {
         $this->pager_param['itemsPerPage'] = $ch['opensearch:itemsperpage'];
     }
     if (isset($ch['opensearch:startindex'])) {
         $this->pager_param['startIndex'] = $ch['opensearch:startindex'];
     }
     return $rss->getItems();
 }
Exemple #10
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');
     }
 }
Exemple #11
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>';
     }
 }
 /**
  * RSSフィードのURLを指定して内容をparseする
  *
  * @param $rss_url RSSフィードのURL(http)
  * @return RSS取得時=RSS情報(連想配列) / RSS取得エラー時=false
  */
 static function get_external_rss_row_array($rss_url)
 {
     // XML_RSS, XML_Parser
     require_once 'XML/RSS.php';
     // RSS情報
     $rss_row_array = array();
     $line_array = file($rss_url);
     if ($line_array == false) {
         return false;
     }
     $rss_data = implode(NULL, $line_array);
     $rss_encoding = mb_detect_encoding($rss_data, 'auto');
     // XML_RSS
     $rss = new XML_RSS();
     $rss->setInputString($rss_data);
     $rss->parse();
     // Channel Info
     $channel_info = $rss->getchannelInfo();
     $rss_row_array['channel_info'] = array();
     $rss_row_array['channel_info']['rss_channel_title'] = mb_convert_encoding($channel_info['title'], mb_internal_encoding(), $rss_encoding);
     $rss_row_array['channel_info']['rss_url'] = $rss_url;
     // Items
     $rss_row_array['items'] = array();
     foreach ($rss->getItems() as $item) {
         $item_row = array();
         $item_row['rss_item_title'] = mb_convert_encoding($item['title'], mb_internal_encoding(), $rss_encoding);
         $item_row['rss_item_content'] = strip_tags(mb_convert_encoding($item['content:encoded'], mb_internal_encoding(), $rss_encoding));
         if (trim($item_row['rss_item_content']) == '') {
             // <content:encoded>が無い場合は<description>を取得
             $item_row['rss_item_content'] = strip_tags(mb_convert_encoding($item['description'], mb_internal_encoding(), $rss_encoding));
         }
         $item_row['rss_item_date'] = mb_convert_encoding($item['dc:date'], mb_internal_encoding(), $rss_encoding);
         $item_row['rss_item_link'] = mb_convert_encoding($item['link'], mb_internal_encoding(), $rss_encoding);
         array_push($rss_row_array['items'], $item_row);
     }
     return $rss_row_array;
 }
Exemple #13
0
function process_url($url, &$channel)
{
    $url = addslashes(stripslashes($url));
    $content = "";
    if (RSSZ_USE_SHELL_EXEC) {
        $command = RSSZ_USE_PROXY ? 'curl -x ' . RSSZ_PROXY . ' "' . $url . '" -iX GET' : 'curl "' . $url . '" -iX GET';
        $response = shell_exec($command);
    } else {
        $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        if (RSSZ_USE_PROXY) {
            curl_setopt($ch, CURLOPT_PROXY, RSSZ_PROXY);
        } else {
            curl_setopt($ch, CURLOPT_PROXY, null);
        }
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        $response = curl_exec($ch);
        curl_close($ch);
    }
    $isHeader = true;
    foreach (preg_split("/((\r?\n)|(\r\n?))/", $response) as $line) {
        if ($isHeader) {
            if (empty($line)) {
                $isHeader = false;
                continue;
            } else {
                //HTTP/1.1 429 Too Many Requests
                if (preg_match("/HTTP.*?\\s(\\d+?)\\s(.*?)\$/", $line, $im)) {
                    logThis($im[1] . " " . $im[2], "HTTP Response status");
                    if (intval($im[1]) == 429) {
                        $GLOBALS['errors'][] = "Torrentz.eu says: [" . $im[1] . "] " . $im[2];
                    }
                }
            }
        }
        if (!$isHeader) {
            $content .= $line . PHP_EOL;
        }
    }
    if (preg_match("/class=\"error\">(.*?)</", $content, $m)) {
        $GLOBALS['errors'][] = "Torrentz.eu says: " . $m[1];
    }
    $filename = microtime(true);
    file_put_contents("data/" . $filename . ".xml", $content);
    $rss = new XML_RSS("data/" . $filename . ".xml");
    $rss->parse();
    $items = $rss->getItems();
    foreach ($items as $item) {
        preg_match("/Size\\:\\s(.*?)\\sSeeds\\:\\s([\\d,]+)\\D.*?Peers\\:\\s([\\d,]+)\\D.*?Hash\\:\\s(.*?)\$/", $item['description'], $m);
        $m[2] = str_replace(',', '', $m[2]);
        $m[3] = str_replace(',', '', $m[3]);
        $item['title_lowercase'] = strtolower(htmlentities($item['title'], ENT_COMPAT, "UTF-8"));
        switch ($GLOBALS['linksSource']) {
            case "r":
                $item['link'] = "http://torrage.com/torrent/" . strtoupper($m[4]) . ".torrent";
                break;
            case "c":
                $item['link'] = "http://torcache.net/torrent/" . strtoupper($m[4]) . ".torrent";
                break;
            case "m":
            default:
                $item['link'] = "magnet:?xt=urn:btih:" . strtolower($m[4]) . "&dn=" . urlencode($item['title']);
                break;
        }
        $item['size'] = $m[1];
        $item['size_raw'] = intval($m[1]);
        $item['hash'] = strtoupper($m[4]);
        $item['seeds'] = intval($m[2]);
        $item['peers'] = intval($m[2]) + intval($m[3]);
        $item['leechers'] = intval($m[3]);
        $item['seeds-leechers'] = intval($m[2]) - intval($m[3]);
        @($item['pubtimestamp'] = strtotime($item['pubdate']));
        $channel[] = $item;
    }
    unset($rss);
    unlink("data/" . $filename . ".xml");
    return count($items);
}