Get() public method

-------------------------------------------------------------------
public Get ( $rss_url )
Example #1
0
function mod_rss($module_id, $cfg)
{
    cmsCore::includeFile('includes/rss/lastRSS.php');
    $rss = new lastRSS();
    $rss->cache_dir = PATH . '/cache';
    $rss->cache_time = (int) @$cfg['cachetime'] * 3600;
    $rss->cp = 'UTF-8';
    $rss->items_limit = $cfg['itemslimit'];
    $rs = $rss->Get($cfg['rssurl']);
    if (!$rs) {
        return false;
    }
    cmsPage::initTemplate('modules', 'mod_rss')->assign('rs', $rs)->assign('cfg', $cfg)->display('mod_rss.tpl');
    return true;
}
}
$rss->cache_dir = $cacheDir;
$rss->cache_time = $cfg["rss_cache_min"] * 60;
// 1200 = 20 min.  3600 = 1 hour
$rss->strip_html = false;
// don't remove HTML from the description
// init template-instance
tmplInitializeInstance($cfg["theme"], "page.readrss.tmpl");
// set vars
// Loop through each RSS feed
$rss_list = array();
foreach ($arURL as $rid => $url) {
    if (isset($_REQUEST["debug"])) {
        $rss->cache_time = 0;
    }
    $rs = $rss->Get($url);
    if ($rs !== false) {
        if (!empty($rs["items"])) {
            // Check this feed has a title tag:
            if (!isset($rs["title"]) || empty($rs["title"])) {
                $rs["title"] = "Feed URL " . htmlentities($url, ENT_QUOTES) . " Note: this feed does not have a valid 'title' tag";
            }
            // Check each item in this feed has link, title and publication date:
            for ($i = 0; $i < count($rs["items"]); $i++) {
                // Don't include feed items without a link:
                if (!isset($rs["items"][$i]["link"]) || empty($rs["items"][$i]["link"])) {
                    array_splice($rs["items"], $i, 1);
                    // Continue to next feed item:
                    continue;
                }
                // Set the label for the link title (<a href="foo" title="$label">)
Example #3
0
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
require_once 'lastRSS.php';
require_once 'iCalcreator.class.php';
$lr = new lastRSS();
$data = $lr->Get("http://feeds.feedburner.com/danaevents");
/*print_r($data);
exit;*/
$v = new vcalendar();
// create a new calendar instance
$v->setConfig('unique_id', $data['link']);
// set your unique id
$v->setProperty('method', 'PUBLISH');
// required of some calendar software
$v->setConfig('filename', "danaevents-" . $v->getConfig('filename'));
$v->setXprop("X-WR-CALNAME", $data['title']);
$v->setXprop("X-WR-CALDESC", $data['description']);
foreach ($data['items'] as $item) {
    $lines = explode("\n", $item['description']);
    //<p>28/05/2008, 19:00 - 20:30</p>
    //print $lines[count($lines)-1];
Example #4
0
//   http://reloadcms.com                                                     //
//   This product released under GNU General Public License v2                //
////////////////////////////////////////////////////////////////////////////////
$rss_cfg = rcms_parse_ini_file(CONFIG_PATH . 'rss_aggregator.ini', true);
$rss = new lastRSS();
$rss->cache_time = $rss_cfg['config']['cache_time'];
$rss->cache_dir = DATA_PATH . 'rss_cache';
$rss->items_limit = $system->config['num_of_latest'];
if (function_exists('iconv')) {
    $rss->default_cp = $system->config['encoding'];
    $rss->cp = $system->config['encoding'];
}
$rss->stripHTML = true;
if (!empty($rss_cfg['feeds'])) {
    foreach ($rss_cfg['feeds'] as $feed_url) {
        if ($feed = $rss->Get($feed_url)) {
            $i = 2;
            $result = '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
            foreach ($feed['items'] as $id => $item) {
                if (empty($item['title'])) {
                    $item['title'] = $item['description'];
                }
                $item['title'] = mb_substr($item['title'], 0, $rss_cfg['config']['max_title_length']) . (mb_strlen($item['title']) > $rss_cfg['config']['max_title_length'] ? '...' : '');
                $item['description'] = mb_substr($item['description'], 0, $rss_cfg['config']['max_desc_length']) . (mb_strlen($item['description']) > $rss_cfg['config']['max_desc_length'] ? '...' : '');
                if (!empty($item['link'])) {
                    $result .= '<tr><td class="row' . $i . '"><a href="' . $rss->unhtmlentities($item['link']) . '"><abbr title="' . $item['description'] . '">' . $item['title'] . '</abbr></a></td></tr>';
                }
                $i++;
                if ($i > 3) {
                    $i = 2;
                }
Example #5
0
 /**
  * ADD News by cron
  * */
 public function CronNewsAction()
 {
     ini_set('max_execution_time', 0);
     $newsModel = new NewsModel();
     $sec_to_delete_news_from_feeds = $this->getParam("SEC_TO_DELETE_NEWS_FROM_FEEDS");
     $newsModel->deleteOldNews(date("Y-m-d H:i:s", time() - $sec_to_delete_news_from_feeds));
     $lastRSS = new lastRSS();
     $lastRSS->cache_dir = './rss_cache';
     $lastRSS->cache_time = 3600;
     // one hour
     $aNewsTreeFeeds = $newsModel->getAllNewsTreeFeeds("", true, true, true);
     foreach ($aNewsTreeFeeds as $newsTreeFeeds) {
         echo $newsTreeFeeds['url'];
         echo "<br>";
         $aFeeds = $lastRSS->Get($newsTreeFeeds['url']);
         echo "<pre>";
         //print_r($aFeeds);
         //print_r($newsTreeFeeds);
         //echo $newsTreeFeeds['last_parse_date']."<br>";
         $n = 0;
         if (is_array($aFeeds) && count($aFeeds) > 0 && is_array($aFeeds['items'])) {
             foreach ($aFeeds['items'] as $item) {
                 //print_r($item); echo "<hr>";
                 $pubDate = isset($item['pubDate']) ? $item['pubDate'] : date("Y-m-d H:i:s");
                 $title = isset($item['title']) ? $item['title'] : "";
                 $link = isset($item['link']) ? $item['link'] : "";
                 $description = isset($item['description']) ? $item['description'] : "";
                 $category = isset($item['category']) ? $item['category'] : "";
                 $enclosure = isset($item['enclosure']) ? $item['enclosure'] : "";
                 $enclosure_type = isset($item['enclosure_type']) ? $item['enclosure_type'] : "";
                 if (strtoupper($aFeeds['encoding']) != 'UTF-8') {
                     $title = iconv(strtoupper($aFeeds['encoding']), 'UTF-8', $title);
                     $description = iconv(strtoupper($aFeeds['encoding']), 'UTF-8', $description);
                     $category = iconv(strtoupper($aFeeds['encoding']), 'UTF-8', $category);
                     $enclosure = iconv(strtoupper($aFeeds['encoding']), 'UTF-8', $enclosure);
                 }
                 $short_text = $newsModel->getNWordsFromText($description, 40);
                 $pub_date = date("Y-m-d H:i:s", strtotime($pubDate));
                 if (!$newsTreeFeeds['category_tag'] || strtoupper($newsTreeFeeds['category_tag']) == strtoupper($category)) {
                     // if RSS-feeds have different categories => it should be same as in item
                     $pub_date_in_sec = strtotime($pub_date);
                     if ((!$newsTreeFeeds['last_parse_date'] || $newsTreeFeeds['last_parse_date'] < $pub_date) && time() - $sec_to_delete_news_from_feeds < $pub_date_in_sec) {
                         // not parsed yet
                         $n++;
                         $newsModel->addNews($newsTreeFeeds['id'], $title, $link, $short_text, $description, $category, $pub_date, $enclosure, $enclosure_type, 0, 0, 0, $newsTreeFeeds['text_parse_type']);
                         $newsModel->setParseDate($newsTreeFeeds['feed_id'], date("Y-m-d H:i:s"));
                     }
                 }
             }
         }
         echo "Added " . $n . " News";
         echo "</pre>";
         echo "<hr>";
     }
 }
Example #6
0
function rss_get_go($arg)
{
    // здесь нет проверок на корректность $arg, потому что мы её уже выполнили в rss_get_widget_custom
    if (!$arg['url']) {
        return false;
    }
    # проверим кеш, может уже есть в нем все данные
    $cache_key = 'rss/' . 'rss_get_' . md5(serialize($arg));
    $k = mso_get_cache($cache_key, true);
    if ($k) {
        return $k;
        // да есть в кэше
    } else {
        require_once getinfo('plugins_dir') . 'rss_get/lastrss.php';
        $rss_pars = new lastRSS();
        $rss_pars->convert_cp = $arg['charset'];
        $rss_pars->itemtags = mso_explode($arg['fields'], false);
        $rss = $rss_pars->Get($arg['url']);
    }
    if (!$rss) {
        return '';
    }
    if (isset($rss[$arg['fields_items']])) {
        $rss = $rss[$arg['fields_items']];
        $rss = array_slice($rss, 0, $arg['count']);
        // колво записей
    } else {
        return '';
        // нет items
    }
    // меняем ключи с values и заполняем нулями - это шаблон для полей
    $fields = array_fill_keys(mso_explode($arg['fields'], false), false);
    $out = '';
    foreach ($rss as $item) {
        // заполним массив шаблона полей значениями из итема
        $fields_out = $fields;
        foreach ($fields as $field => $tmp) {
            if (isset($item[$field])) {
                $fields_out[$field] = $item[$field];
                continue;
            }
        }
        $out1 = $arg['format'];
        foreach ($fields_out as $field => $value) {
            // обратное преобразование в html
            $value = str_replace('&lt;', '<', $value);
            $value = str_replace('&gt;', '>', $value);
            $value = str_replace('&amp;', '&', $value);
            $value = str_replace('<![CDATA[', '', $value);
            $value = str_replace(']]>', '', $value);
            // если стоит максимальное колво слов, то обрежем лишнее
            if ($arg['max_word_description'] and $field != 'link') {
                $value = mso_str_word($value, $arg['max_word_description']);
            }
            // если поле содержит date, то пробуем его преобразовать в нужный нам формат даты
            if (strpos($field, 'dc:date') !== false or strpos($field, 'date') !== false or $field == 'published' or $field == 'updated') {
                if (($d = strtotime($value)) !== -1) {
                    // успешное преобразование
                    $value = date($arg['format_date'], $d);
                }
            }
            if ($field == 'link') {
                $link_host = parse_url($value);
                $link_host = $link_host['host'];
                $out1 = str_replace('[link-host]', $link_host, $out1);
            }
            $out1 = str_replace('[' . $field . ']', $value, $out1);
        }
        $out .= $out1;
    }
    if ($out and $arg['time_cache']) {
        mso_add_cache($cache_key, $out, $arg['time_cache'] * 60, true);
    }
    return $out;
}