/**
  * Perform on the action call
  *
  * @param mixed $data Data passed to this action
  */
 public function perform($data = FALSE)
 {
     if (!defined('MAGPIE_OUTPUT_ENCODING')) {
         if (isset($data['encoding'])) {
             define('MAGPIE_OUTPUT_ENCODING', $data['encoding']);
         }
     }
     if (isset($data['cache_time'])) {
         define('MAGPIE_CACHE_ON', TRUE);
         define('MAGPIE_CACHE_AGE', (int) $data['cache_time']);
         define('MAGPIE_CACHE_DIR', SMART_BASE_DIR . 'data/common/rss_cache');
     }
     if (!($rss = fetch_rss($data['url']))) {
         trigger_error('Rss feed not available: ' . magpie_error(), E_USER_WARNING);
         $data['result']['items'] = array();
         $data['result']['channel'] = array();
         $data['result']['image'] = array();
         $data['result']['textinput'] = array();
         return;
     }
     $data['result']['items'] = $rss->items;
     $data['result']['channel'] = $rss->channel;
     $data['result']['image'] = $rss->image;
     $data['result']['textinput'] = $rss->textinput;
 }
Esempio n. 2
0
 function handleJSON_getContent($smarty, $module_name, $appletlist)
 {
     $respuesta = array('status' => 'success', 'message' => '(no message)');
     define('MAGPIE_CACHE_DIR', '/tmp/rss-cache');
     define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
     $infoRSS = @fetch_rss('http://elastix.org/index.php?option=com_mediarss&feed_id=1&format=raw');
     $sMensaje = magpie_error();
     if (strpos($sMensaje, 'HTTP Error: connection failed') !== FALSE) {
         $respuesta['status'] = 'error';
         $respuesta['message'] = _tr('Could not get web server information. You may not have internet access or the web server is down');
     } else {
         // Formato de fecha y hora
         for ($i = 0; $i < count($infoRSS->items); $i++) {
             $infoRSS->items[$i]['date_format'] = date('Y.m.d', $infoRSS->items[$i]['date_timestamp']);
         }
         $smarty->assign(array('WEBSITE' => 'http://www.elastix.org', 'NO_NEWS' => _tr('No News to display'), 'NEWS_LIST' => array_slice($infoRSS->items, 0, 7)));
         $local_templates_dir = getWebDirModule($module_name) . "/applets/News/tpl";
         $respuesta['html'] = $smarty->fetch("{$local_templates_dir}/rssfeed.tpl");
     }
     $json = new Services_JSON();
     Header('Content-Type: application/json');
     return $json->encode($respuesta);
 }
Esempio n. 3
0
                                $aso_page['date'] = strftime('%d.%m.%Y', $aso_page['datestamp']);
                                break;
                            case 'jmh':
                                $aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['datestamp']);
                                break;
                            case 'jmah':
                                $aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['datestamp']);
                                break;
                            default:
                                $aso_page['date'] = '';
                        }
                    }
                    $syndication['pagination'] = $pagination;
                    $syndication['pages'][$aso_page['datestamp']] = $aso_page;
                }
            } else {
                echo '<p class="alert alert-danger">' . _t('ERROR') . ' ' . magpie_error() . '</p>' . "\n";
            }
        }
    }
    // Trie des pages par date
    krsort($syndication['pages']);
    echo '<div class="feed_syndication' . ($class ? ' ' . $class : '') . '">' . "\n";
    // Gestion des squelettes
    include $template;
    echo '</div>' . "\n";
} else {
    echo '<div class="alert alert-danger"><strong>' . _t('SYNDICATION_ACTION_SYNDICATION') . '</strong> : ' . _t('SYNDICATION_PARAM_URL_REQUIRED') . '.</div>' . "\n";
}
//ajout du javascript
$this->AddJavascriptFile('tools/syndication/presentation/javascripts/syndication.js');
Esempio n. 4
0
function update_rss_feed_real($link, $feed, $ignore_daemon = false)
{
    global $memcache;
    if (!$_REQUEST["daemon"] && !$ignore_daemon) {
        return false;
    }
    if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
        _debug("update_rss_feed: start");
    }
    if (!$ignore_daemon) {
        if (DB_TYPE == "pgsql") {
            $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')";
        } else {
            $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))";
        }
        $result = db_query($link, "SELECT id,update_interval,auth_login,\n\t\t\t\tauth_pass,cache_images,update_method\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}' AND {$updstart_thresh_qpart}");
    } else {
        $result = db_query($link, "SELECT id,update_interval,auth_login,\n\t\t\t\tfeed_url,auth_pass,cache_images,update_method,last_updated\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
    }
    if (db_num_rows($result) == 0) {
        if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
            _debug("update_rss_feed: feed {$feed} NOT FOUND/SKIPPED");
        }
        return false;
    }
    $update_method = db_fetch_result($result, 0, "update_method");
    $last_updated = db_fetch_result($result, 0, "last_updated");
    db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\tWHERE id = '{$feed}'");
    $auth_login = db_fetch_result($result, 0, "auth_login");
    $auth_pass = db_fetch_result($result, 0, "auth_pass");
    if (ALLOW_SELECT_UPDATE_METHOD) {
        if (ENABLE_SIMPLEPIE) {
            $use_simplepie = $update_method != 1;
        } else {
            $use_simplepie = $update_method == 2;
        }
    } else {
        $use_simplepie = ENABLE_SIMPLEPIE;
    }
    if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
        _debug("use simplepie: {$use_simplepie} (feed setting: {$update_method})\n");
    }
    if (!$use_simplepie) {
        $auth_login = urlencode($auth_login);
        $auth_pass = urlencode($auth_pass);
    }
    $update_interval = db_fetch_result($result, 0, "update_interval");
    $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
    $fetch_url = db_fetch_result($result, 0, "feed_url");
    if ($update_interval < 0) {
        return;
    }
    $feed = db_escape_string($feed);
    if ($auth_login && $auth_pass) {
        $url_parts = array();
        preg_match("/(^[^:]*):\\/\\/(.*)/", $fetch_url, $url_parts);
        if ($url_parts[1] && $url_parts[2]) {
            $fetch_url = $url_parts[1] . "://{$auth_login}:{$auth_pass}@" . $url_parts[2];
        }
    }
    if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
        _debug("update_rss_feed: fetching [{$fetch_url}]...");
    }
    if (!defined('DAEMON_EXTENDED_DEBUG') && !$_REQUEST['xdebug']) {
        error_reporting(0);
    }
    $obj_id = md5("FDATA:{$use_simplepie}:{$fetch_url}");
    if ($memcache && ($obj = $memcache->get($obj_id))) {
        if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
            _debug("update_rss_feed: data found in memcache.");
        }
        $rss = $obj;
    } else {
        if (!$use_simplepie) {
            $rss = fetch_rss($fetch_url);
        } else {
            if (!is_dir(SIMPLEPIE_CACHE_DIR)) {
                mkdir(SIMPLEPIE_CACHE_DIR);
            }
            $rss = new SimplePie();
            $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT);
            #			$rss->set_timeout(10);
            $rss->set_feed_url($fetch_url);
            $rss->set_output_encoding('UTF-8');
            if (SIMPLEPIE_CACHE_IMAGES && $cache_images) {
                if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                    _debug("enabling image cache");
                }
                $rss->set_image_handler('./image.php', 'i');
            }
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("feed update interval (sec): " . get_feed_update_interval($link, $feed) * 60);
            }
            if (is_dir(SIMPLEPIE_CACHE_DIR)) {
                $rss->set_cache_location(SIMPLEPIE_CACHE_DIR);
                $rss->set_cache_duration(get_feed_update_interval($link, $feed) * 60);
            }
            $rss->init();
        }
        if ($memcache && $rss) {
            $memcache->add($obj_id, $rss, 0, 300);
        }
    }
    //		print_r($rss);
    if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
        _debug("update_rss_feed: fetch done, parsing...");
    } else {
        error_reporting(DEFAULT_ERROR_LEVEL);
    }
    $feed = db_escape_string($feed);
    if ($use_simplepie) {
        $fetch_ok = !$rss->error();
    } else {
        $fetch_ok = !!$rss;
    }
    if ($fetch_ok) {
        if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
            _debug("update_rss_feed: processing feed data...");
        }
        //			db_query($link, "BEGIN");
        $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
        $registered_title = db_fetch_result($result, 0, "title");
        $orig_icon_url = db_fetch_result($result, 0, "icon_url");
        $orig_site_url = db_fetch_result($result, 0, "site_url");
        $owner_uid = db_fetch_result($result, 0, "owner_uid");
        if ($use_simplepie) {
            $site_url = $rss->get_link();
        } else {
            $site_url = $rss->channel["link"];
        }
        if (get_pref($link, 'ENABLE_FEED_ICONS', $owner_uid, false)) {
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: checking favicon...");
            }
            check_feed_favicon($site_url, $feed, $link);
        }
        if (!$registered_title || $registered_title == "[Unknown]") {
            if ($use_simplepie) {
                $feed_title = db_escape_string($rss->get_title());
            } else {
                $feed_title = db_escape_string($rss->channel["title"]);
            }
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: registering title: {$feed_title}");
            }
            db_query($link, "UPDATE ttrss_feeds SET \n\t\t\t\t\ttitle = '{$feed_title}' WHERE id = '{$feed}'");
        }
        // weird, weird Magpie
        if (!$use_simplepie) {
            if (!$site_url) {
                $site_url = db_escape_string($rss->channel["link_"]);
            }
        }
        if ($site_url && $orig_site_url != db_escape_string($site_url)) {
            db_query($link, "UPDATE ttrss_feeds SET \n\t\t\t\t\tsite_url = '{$site_url}' WHERE id = '{$feed}'");
        }
        //			print "I: " . $rss->channel["image"]["url"];
        if (!$use_simplepie) {
            $icon_url = $rss->image["url"];
        } else {
            $icon_url = $rss->get_image_url();
        }
        if ($icon_url && !$orig_icon_url != db_escape_string($icon_url)) {
            $icon_url = db_escape_string($icon_url);
            db_query($link, "UPDATE ttrss_feeds SET icon_url = '{$icon_url}' WHERE id = '{$feed}'");
        }
        if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
            _debug("update_rss_feed: loading filters...");
        }
        $filters = load_filters($link, $feed, $owner_uid);
        if ($use_simplepie) {
            $iterator = $rss->get_items();
        } else {
            $iterator = $rss->items;
            if (!$iterator || !is_array($iterator)) {
                $iterator = $rss->entries;
            }
            if (!$iterator || !is_array($iterator)) {
                $iterator = $rss;
            }
        }
        if (!is_array($iterator)) {
            /* db_query($link, "UPDATE ttrss_feeds 
            			SET last_error = 'Parse error: can\'t find any articles.'
            			WHERE id = '$feed'"); */
            // clear any errors and mark feed as updated if fetched okay
            // even if it's blank
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: entry iterator is not an array, no articles?");
            }
            db_query($link, "UPDATE ttrss_feeds \n\t\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
            return;
            // no articles
        }
        if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
            _debug("update_rss_feed: processing articles...");
        }
        foreach ($iterator as $item) {
            if ($_REQUEST['xdebug'] == 2) {
                print_r($item);
            }
            if ($use_simplepie) {
                $entry_guid = $item->get_id();
                if (!$entry_guid) {
                    $entry_guid = $item->get_link();
                }
                if (!$entry_guid) {
                    $entry_guid = make_guid_from_title($item->get_title());
                }
            } else {
                $entry_guid = $item["id"];
                if (!$entry_guid) {
                    $entry_guid = $item["guid"];
                }
                if (!$entry_guid) {
                    $entry_guid = $item["link"];
                }
                if (!$entry_guid) {
                    $entry_guid = make_guid_from_title($item["title"]);
                }
            }
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: guid {$entry_guid}");
            }
            if (!$entry_guid) {
                continue;
            }
            $entry_timestamp = "";
            if ($use_simplepie) {
                $entry_timestamp = strtotime($item->get_date());
            } else {
                $rss_2_date = $item['pubdate'];
                $rss_1_date = $item['dc']['date'];
                $atom_date = $item['issued'];
                if (!$atom_date) {
                    $atom_date = $item['updated'];
                }
                if ($atom_date != "") {
                    $entry_timestamp = parse_w3cdtf($atom_date);
                }
                if ($rss_1_date != "") {
                    $entry_timestamp = parse_w3cdtf($rss_1_date);
                }
                if ($rss_2_date != "") {
                    $entry_timestamp = strtotime($rss_2_date);
                }
            }
            if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) {
                $entry_timestamp = time();
                $no_orig_date = 'true';
            } else {
                $no_orig_date = 'false';
            }
            $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: date {$entry_timestamp} [{$entry_timestamp_fmt}]");
            }
            if ($use_simplepie) {
                $entry_title = $item->get_title();
            } else {
                $entry_title = trim(strip_tags($item["title"]));
            }
            if ($use_simplepie) {
                $entry_link = $item->get_link();
            } else {
                // strange Magpie workaround
                $entry_link = $item["link_"];
                if (!$entry_link) {
                    $entry_link = $item["link"];
                }
            }
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: title {$entry_title}");
            }
            if (!$entry_title) {
                $entry_title = date("Y-m-d H:i:s", $entry_timestamp);
            }
            $entry_link = strip_tags($entry_link);
            if ($use_simplepie) {
                $entry_content = $item->get_content();
                if (!$entry_content) {
                    $entry_content = $item->get_description();
                }
            } else {
                $entry_content = $item["content:escaped"];
                if (!$entry_content) {
                    $entry_content = $item["content:encoded"];
                }
                if (!$entry_content) {
                    $entry_content = $item["content"]["encoded"];
                }
                if (!$entry_content) {
                    $entry_content = $item["content"];
                }
                // Magpie bugs are getting ridiculous
                if (trim($entry_content) == "Array") {
                    $entry_content = false;
                }
                if (!$entry_content) {
                    $entry_content = $item["atom_content"];
                }
                if (!$entry_content) {
                    $entry_content = $item["summary"];
                }
                if (!$entry_content || strlen($entry_content) < strlen($item["description"])) {
                    $entry_content = $item["description"];
                }
                // WTF
                if (is_array($entry_content)) {
                    $entry_content = $entry_content["encoded"];
                    if (!$entry_content) {
                        $entry_content = $entry_content["escaped"];
                    }
                }
            }
            if ($_REQUEST["xdebug"] == 2) {
                print "update_rss_feed: content: ";
                print_r(htmlspecialchars($entry_content));
            }
            $entry_content_unescaped = $entry_content;
            if ($use_simplepie) {
                $entry_comments = strip_tags($item->data["comments"]);
                if ($item->get_author()) {
                    $entry_author_item = $item->get_author();
                    $entry_author = $entry_author_item->get_name();
                    if (!$entry_author) {
                        $entry_author = $entry_author_item->get_email();
                    }
                    $entry_author = db_escape_string($entry_author);
                }
            } else {
                $entry_comments = strip_tags($item["comments"]);
                $entry_author = db_escape_string(strip_tags($item['dc']['creator']));
                if ($item['author']) {
                    if (is_array($item['author'])) {
                        if (!$entry_author) {
                            $entry_author = db_escape_string(strip_tags($item['author']['name']));
                        }
                        if (!$entry_author) {
                            $entry_author = db_escape_string(strip_tags($item['author']['email']));
                        }
                    }
                    if (!$entry_author) {
                        $entry_author = db_escape_string(strip_tags($item['author']));
                    }
                }
            }
            if (preg_match('/^[\\t\\n\\r ]*$/', $entry_author)) {
                $entry_author = '';
            }
            $entry_guid = db_escape_string(strip_tags($entry_guid));
            $entry_guid = mb_substr($entry_guid, 0, 250);
            $result = db_query($link, "SELECT id FROM\tttrss_entries \n\t\t\t\t\tWHERE guid = '{$entry_guid}'");
            $entry_content = db_escape_string($entry_content);
            $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
            $entry_title = db_escape_string($entry_title);
            $entry_link = db_escape_string($entry_link);
            $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250);
            $entry_author = mb_substr($entry_author, 0, 250);
            if ($use_simplepie) {
                $num_comments = 0;
                #FIXME#
            } else {
                $num_comments = db_escape_string($item["slash"]["comments"]);
            }
            if (!$num_comments) {
                $num_comments = 0;
            }
            // parse <category> entries into tags
            if ($use_simplepie) {
                $additional_tags = array();
                $additional_tags_src = $item->get_categories();
                if (is_array($additional_tags_src)) {
                    foreach ($additional_tags_src as $tobj) {
                        array_push($additional_tags, $tobj->get_term());
                    }
                }
                if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                    _debug("update_rss_feed: category tags:");
                    print_r($additional_tags);
                }
            } else {
                $t_ctr = $item['category#'];
                $additional_tags = false;
                if ($t_ctr == 0) {
                    $additional_tags = false;
                } else {
                    if ($t_ctr > 0) {
                        $additional_tags = array($item['category']);
                        if ($item['category@term']) {
                            array_push($additional_tags, $item['category@term']);
                        }
                        for ($i = 0; $i <= $t_ctr; $i++) {
                            if ($item["category#{$i}"]) {
                                array_push($additional_tags, $item["category#{$i}"]);
                            }
                            if ($item["category#{$i}@term"]) {
                                array_push($additional_tags, $item["category#{$i}@term"]);
                            }
                        }
                    }
                }
                // parse <dc:subject> elements
                $t_ctr = $item['dc']['subject#'];
                if ($t_ctr > 0) {
                    $additional_tags = array($item['dc']['subject']);
                    for ($i = 0; $i <= $t_ctr; $i++) {
                        if ($item['dc']["subject#{$i}"]) {
                            array_push($additional_tags, $item['dc']["subject#{$i}"]);
                        }
                    }
                }
            }
            // enclosures
            $enclosures = array();
            if ($use_simplepie) {
                $encs = $item->get_enclosures();
                if (is_array($encs)) {
                    foreach ($encs as $e) {
                        $e_item = array($e->link, $e->type, $e->length);
                        array_push($enclosures, $e_item);
                    }
                }
            } else {
                // <enclosure>
                $e_ctr = $item['enclosure#'];
                if ($e_ctr > 0) {
                    $e_item = array($item['enclosure@url'], $item['enclosure@type'], $item['enclosure@length']);
                    array_push($enclosures, $e_item);
                    for ($i = 0; $i <= $e_ctr; $i++) {
                        if ($item["enclosure#{$i}@url"]) {
                            $e_item = array($item["enclosure#{$i}@url"], $item["enclosure#{$i}@type"], $item["enclosure#{$i}@length"]);
                            array_push($enclosures, $e_item);
                        }
                    }
                }
                // <media:content>
                // can there be many of those? yes -fox
                $m_ctr = $item['media']['content#'];
                if ($m_ctr > 0) {
                    $e_item = array($item['media']['content@url'], $item['media']['content@medium'], $item['media']['content@length']);
                    array_push($enclosures, $e_item);
                    for ($i = 0; $i <= $m_ctr; $i++) {
                        if ($item["media"]["content#{$i}@url"]) {
                            $e_item = array($item["media"]["content#{$i}@url"], $item["media"]["content#{$i}@medium"], $item["media"]["content#{$i}@length"]);
                            array_push($enclosures, $e_item);
                        }
                    }
                }
            }
            # sanitize content
            $entry_content = sanitize_article_content($entry_content);
            $entry_title = sanitize_article_content($entry_title);
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: done collecting data [TITLE:{$entry_title}]");
            }
            db_query($link, "BEGIN");
            if (db_num_rows($result) == 0) {
                if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                    _debug("update_rss_feed: base guid not found");
                }
                // base post entry does not exist, create it
                $result = db_query($link, "INSERT INTO ttrss_entries \n\t\t\t\t\t\t\t(title,\n\t\t\t\t\t\t\tguid,\n\t\t\t\t\t\t\tlink,\n\t\t\t\t\t\t\tupdated,\n\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\tcontent_hash,\n\t\t\t\t\t\t\tno_orig_date,\n\t\t\t\t\t\t\tdate_entered,\n\t\t\t\t\t\t\tcomments,\n\t\t\t\t\t\t\tnum_comments,\n\t\t\t\t\t\t\tauthor)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('{$entry_title}', \n\t\t\t\t\t\t\t'{$entry_guid}', \n\t\t\t\t\t\t\t'{$entry_link}',\n\t\t\t\t\t\t\t'{$entry_timestamp_fmt}', \n\t\t\t\t\t\t\t'{$entry_content}', \n\t\t\t\t\t\t\t'{$content_hash}',\n\t\t\t\t\t\t\t{$no_orig_date}, \n\t\t\t\t\t\t\tNOW(), \n\t\t\t\t\t\t\t'{$entry_comments}',\n\t\t\t\t\t\t\t'{$num_comments}',\n\t\t\t\t\t\t\t'{$entry_author}')");
            } else {
                // we keep encountering the entry in feeds, so we need to
                // update date_entered column so that we don't get horrible
                // dupes when the entry gets purged and reinserted again e.g.
                // in the case of SLOW SLOW OMG SLOW updating feeds
                $base_entry_id = db_fetch_result($result, 0, "id");
                db_query($link, "UPDATE ttrss_entries SET date_entered = NOW()\n\t\t\t\t\t\tWHERE id = '{$base_entry_id}'");
            }
            // now it should exist, if not - bad luck then
            $result = db_query($link, "SELECT \n\t\t\t\t\t\tid,content_hash,no_orig_date,title,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(date_entered,1,19) as date_entered,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(updated,1,19) as updated,\n\t\t\t\t\t\tnum_comments\n\t\t\t\t\tFROM \n\t\t\t\t\t\tttrss_entries \n\t\t\t\t\tWHERE guid = '{$entry_guid}'");
            $entry_ref_id = 0;
            $entry_int_id = 0;
            if (db_num_rows($result) == 1) {
                if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                    _debug("update_rss_feed: base guid found, checking for user record");
                }
                // this will be used below in update handler
                $orig_content_hash = db_fetch_result($result, 0, "content_hash");
                $orig_title = db_fetch_result($result, 0, "title");
                $orig_num_comments = db_fetch_result($result, 0, "num_comments");
                $orig_date_entered = strtotime(db_fetch_result($result, 0, "date_entered"));
                $ref_id = db_fetch_result($result, 0, "id");
                $entry_ref_id = $ref_id;
                // check for user post link to main table
                // do we allow duplicate posts with same GUID in different feeds?
                if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
                    $dupcheck_qpart = "AND (feed_id = '{$feed}' OR feed_id IS NULL)";
                } else {
                    $dupcheck_qpart = "";
                }
                //					error_reporting(0);
                $article_filters = get_article_filters($filters, $entry_title, $entry_content, $entry_link, $entry_timestamp, $entry_author);
                if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                    _debug("update_rss_feed: article filters: ");
                    if (count($article_filters) != 0) {
                        print_r($article_filters);
                    }
                }
                if (find_article_filter($article_filters, "filter")) {
                    db_query($link, "COMMIT");
                    // close transaction in progress
                    continue;
                }
                //					error_reporting (DEFAULT_ERROR_LEVEL);
                $score = calculate_article_score($article_filters);
                if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                    _debug("update_rss_feed: initial score: {$score}");
                }
                $query = "SELECT ref_id, int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}'\n\t\t\t\t\t\t\t{$dupcheck_qpart}";
                //					if ($_REQUEST["xdebug"]) print "$query\n";
                $result = db_query($link, $query);
                // okay it doesn't exist - create user entry
                if (db_num_rows($result) == 0) {
                    if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                        _debug("update_rss_feed: user record not found, creating...");
                    }
                    if ($score >= -500 && !find_article_filter($article_filters, 'catchup')) {
                        $unread = 'true';
                        $last_read_qpart = 'NULL';
                    } else {
                        $unread = 'false';
                        $last_read_qpart = 'NOW()';
                    }
                    if (find_article_filter($article_filters, 'mark') || $score > 1000) {
                        $marked = 'true';
                    } else {
                        $marked = 'false';
                    }
                    if (find_article_filter($article_filters, 'publish')) {
                        $published = 'true';
                    } else {
                        $published = 'false';
                    }
                    $result = db_query($link, "INSERT INTO ttrss_user_entries \n\t\t\t\t\t\t\t\t(ref_id, owner_uid, feed_id, unread, last_read, marked, \n\t\t\t\t\t\t\t\t\tpublished, score) \n\t\t\t\t\t\t\tVALUES ('{$ref_id}', '{$owner_uid}', '{$feed}', {$unread},\n\t\t\t\t\t\t\t\t{$last_read_qpart}, {$marked}, {$published}, '{$score}')");
                    $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}' AND\n\t\t\t\t\t\t\t\tfeed_id = '{$feed}' LIMIT 1");
                    if (db_num_rows($result) == 1) {
                        $entry_int_id = db_fetch_result($result, 0, "int_id");
                    }
                } else {
                    if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                        _debug("update_rss_feed: user record FOUND");
                    }
                    $entry_ref_id = db_fetch_result($result, 0, "ref_id");
                    $entry_int_id = db_fetch_result($result, 0, "int_id");
                }
                if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                    _debug("update_rss_feed: RID: {$entry_ref_id}, IID: {$entry_int_id}");
                }
                $post_needs_update = false;
                if (get_pref($link, "UPDATE_POST_ON_CHECKSUM_CHANGE", $owner_uid, false) && $content_hash != $orig_content_hash) {
                    //						print "<!-- [$entry_title] $content_hash vs $orig_content_hash -->";
                    $post_needs_update = true;
                }
                if (db_escape_string($orig_title) != $entry_title) {
                    $post_needs_update = true;
                }
                if ($orig_num_comments != $num_comments) {
                    $post_needs_update = true;
                }
                //					this doesn't seem to be very reliable
                //
                //					if ($orig_timestamp != $entry_timestamp && !$orig_no_orig_date) {
                //						$post_needs_update = true;
                //					}
                // if post needs update, update it and mark all user entries
                // linking to this post as updated
                if ($post_needs_update) {
                    if (defined('DAEMON_EXTENDED_DEBUG')) {
                        _debug("update_rss_feed: post {$entry_guid} needs update...");
                    }
                    //						print "<!-- post $orig_title needs update : $post_needs_update -->";
                    db_query($link, "UPDATE ttrss_entries \n\t\t\t\t\t\t\tSET title = '{$entry_title}', content = '{$entry_content}',\n\t\t\t\t\t\t\t\tcontent_hash = '{$content_hash}',\n\t\t\t\t\t\t\t\tnum_comments = '{$num_comments}'\n\t\t\t\t\t\t\tWHERE id = '{$ref_id}'");
                    if (get_pref($link, "MARK_UNREAD_ON_UPDATE", $owner_uid, false)) {
                        db_query($link, "UPDATE ttrss_user_entries \n\t\t\t\t\t\t\t\tSET last_read = null, unread = true WHERE ref_id = '{$ref_id}'");
                    } else {
                        db_query($link, "UPDATE ttrss_user_entries \n\t\t\t\t\t\t\t\tSET last_read = null WHERE ref_id = '{$ref_id}' AND unread = false");
                    }
                }
            }
            db_query($link, "COMMIT");
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: assigning labels...");
            }
            assign_article_to_labels($link, $entry_ref_id, $article_filters, $owner_uid);
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: looking for enclosures...");
            }
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                print_r($enclosures);
            }
            db_query($link, "BEGIN");
            foreach ($enclosures as $enc) {
                $enc_url = db_escape_string($enc[0]);
                $enc_type = db_escape_string($enc[1]);
                $enc_dur = db_escape_string($enc[2]);
                $result = db_query($link, "SELECT id FROM ttrss_enclosures\n\t\t\t\t\t\tWHERE content_url = '{$enc_url}' AND post_id = '{$entry_ref_id}'");
                if (db_num_rows($result) == 0) {
                    db_query($link, "INSERT INTO ttrss_enclosures\n\t\t\t\t\t\t\t(content_url, content_type, title, duration, post_id) VALUES\n\t\t\t\t\t\t\t('{$enc_url}', '{$enc_type}', '', '{$enc_dur}', '{$entry_ref_id}')");
                }
            }
            db_query($link, "COMMIT");
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: looking for tags...");
            }
            /* taaaags */
            // <a href="..." rel="tag">Xorg</a>, //
            $entry_tags = null;
            preg_match_all("/<a.*?rel=['\"]tag['\"].*?>([^<]+)<\\/a>/i", $entry_content_unescaped, $entry_tags);
            /*				print "<p><br/>$entry_title : $entry_content_unescaped<br>";
            				print_r($entry_tags);
            				print "<br/></p>"; */
            $entry_tags = $entry_tags[1];
            # check for manual tags
            foreach ($article_filters as $f) {
                if ($f[0] == "tag") {
                    $manual_tags = trim_array(split(",", $f[1]));
                    foreach ($manual_tags as $tag) {
                        if (tag_is_valid($tag)) {
                            array_push($entry_tags, $tag);
                        }
                    }
                }
            }
            $boring_tags = trim_array(split(",", mb_strtolower(get_pref($link, 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
            if ($additional_tags && is_array($additional_tags)) {
                foreach ($additional_tags as $tag) {
                    if (tag_is_valid($tag) && array_search($tag, $boring_tags) === FALSE) {
                        array_push($entry_tags, $tag);
                    }
                }
            }
            //				print "<p>TAGS: "; print_r($entry_tags); print "</p>";
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                print_r($entry_tags);
            }
            if (count($entry_tags) > 0) {
                db_query($link, "BEGIN");
                foreach ($entry_tags as $tag) {
                    $tag = sanitize_tag($tag);
                    $tag = db_escape_string($tag);
                    if (!tag_is_valid($tag)) {
                        continue;
                    }
                    $result = db_query($link, "SELECT id FROM ttrss_tags\t\t\n\t\t\t\t\t\t\t\tWHERE tag_name = '{$tag}' AND post_int_id = '{$entry_int_id}' AND \n\t\t\t\t\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
                    //						print db_fetch_result($result, 0, "id");
                    if ($result && db_num_rows($result) == 0) {
                        db_query($link, "INSERT INTO ttrss_tags \n\t\t\t\t\t\t\t\t\t(owner_uid,tag_name,post_int_id)\n\t\t\t\t\t\t\t\t\tVALUES ('{$owner_uid}','{$tag}', '{$entry_int_id}')");
                    }
                }
                db_query($link, "COMMIT");
            }
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: article processed");
            }
        }
        if (!$last_updated) {
            if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                _debug("update_rss_feed: new feed, catching it up...");
            }
            catchup_feed($link, $feed, false, $owner_uid);
        }
        purge_feed($link, $feed, 0);
        db_query($link, "UPDATE ttrss_feeds \n\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
        //			db_query($link, "COMMIT");
    } else {
        if ($use_simplepie) {
            $error_msg = mb_substr($rss->error(), 0, 250);
        } else {
            $error_msg = mb_substr(magpie_error(), 0, 250);
        }
        if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
            _debug("update_rss_feed: error fetching feed: {$error_msg}");
        }
        $error_msg = db_escape_string($error_msg);
        db_query($link, "UPDATE ttrss_feeds SET last_error = '{$error_msg}', \n\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'");
    }
    if ($use_simplepie) {
        unset($rss);
    }
    if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
        _debug("update_rss_feed: done");
    }
}
Esempio n. 5
0
                $title = $item['title'];
                $link = $item['link'];
                $description = $item['description'];
                $pubdate = isset($item['pubdate']) ? "|" . $item['pubdate'] . "|" : "";
                $author = isset($item['author']) ? "by " . $item['author'] : "";
                echo "<li><a href=\"{$link}\">{$title} {$author}</a> <span style=\"font-size: 7pt;\">{$pubdate}</span></li>";
            }
            $count++;
        }
        $retry = $MAX_RETRY;
    }
    $retry++;
}
if (!$rss) {
    echo "<li>Unable to fetch rss feed, try refreshing the page</li>";
    echo "<li><span style=\"font-size: 7pt;\">" . magpie_error() . "</span></li>";
}
?>
</ul>

<h2>Download</h2><a name="download"></a>
<p>To run Entagged, you need first of all to download the Java Runtime Environment (JRE) because Entagged is written in Java. This ensures a great crossplatform compatibility at the (little: approx. 10Mb) cost of these libraries.</p>
<p>You can get the <a href="http://java.sun.com/j2se/1.4.2/download.html">latest Sun JRE</a> (Entagged needs at least JRE v1.4.1 to work properly !).</p> 
<p>Select the "Download J2SE v 1.4.xxx" column and pick under "JRE" your platform's version.</p>
<p>You can then <a href="http://sourceforge.net/project/showfiles.php?group_id=88759&package_id=92893">download Entagged</a> at sourceforge file release section, make sure you are downloading the latest version !</p>
<p>Entagged is packaged in three different ways:</p>
<ul>
	<li>"entagged-install-vx.xx.exe" is the windows installer version of this package (note that it is only a .exe wrapper to lauch the jar file, no native code here)</li>
	<li>"entagged-vx.xx.zip" is the "all platform" package, it contains mainly the executable jar file, and some images files (make sure you extract this archive using the directory structure inside it)</li>
	<li>"entagged-src-vx.xx.tar.gz" wich contains the source code and the resources needed to compile and build entagged (ant file, images, NSIS script, etc). This package is NOT needed if you only want to use Entagged (this is a developper resource)</li>
</ul>
Esempio n. 6
0
if ($rss) {
    // Show first 50 items
    //      $items = array_slice($rss->items, 0, 50);
    $items = $rss->items;
    // Cycle through each item and echo
    echo '<dl>';
    foreach ($items as $item) {
        $description = $item['description'];
        $publish_date = $item['pubdate'];
        // Check to see if the first 10 characters in the description are a date... when the old
        // news items were imported, the original publish date was put at the start of the description.
        if (substr($description, 10, 1) == ' ') {
            $possible_date = substr($description, 0, 10);
            // verify date is in expected format: yyyy/mm/dd
            if (substr($possible_date, 4, 1) == '/' && substr($possible_date, 7, 1) == '/' && is_numeric(substr($possible_date, 0, 4)) && is_numeric(substr($possible_date, 5, 2)) && is_numeric(substr($possible_date, 8, 2))) {
                $description = substr($description, 11);
                $publish_date = $possible_date;
            }
        }
        $formatted_date = date("Y/m/d", strtotime($publish_date));
        echo '<p><dt><b>' . $formatted_date . '</b> - <a href="' . $item['link'] . '">' . $item['title'] . '</a>' . '</dt><dd>' . $description . '</dd></dt></p>';
    }
    echo '</dl>';
} else {
    echo '<h2>Error:</h2><p>' . magpie_error() . '</p>';
}
// Restore original error reporting value
@ini_restore('error_reporting');
?>
 
Esempio n. 7
0
function fof_update_feed($url)
{
    global $FOF_FEED_TABLE, $FOF_ITEM_TABLE;
    $FOF_FEED_TABLE = FOF_FEED_TABLE;
    $FOF_ITEM_TABLE = FOF_ITEM_TABLE;
    if (!$url) {
        return 0;
    }
    $rss = fetch_rss($url);
    if (!$rss) {
        print "Error: <B>" . magpie_error() . "</b> ";
        print "<a href=\"http://feeds.archive.org/validator/check?url={$url}\">try to validate it?</a> ";
        return 0;
    }
    $title = mysql_escape_string($rss->channel['title']);
    $link = $rss->channel['link'];
    $description = mysql_escape_string($rss->channel['description']);
    $safeurl = mysql_escape_string($url);
    $result = fof_do_query("select id, url from {$FOF_FEED_TABLE} where url='{$safeurl}'");
    $row = mysql_fetch_array($result);
    $feed_id = $row['id'];
    $items = $rss->items;
    foreach ($items as $item) {
        if (AMP_CONTENT_RSS_CUSTOMFORMAT == 'true') {
            $link = mysql_escape_string($item['source']);
            $contacts = mysql_escape_string($item['contacts']);
            $subtitle = mysql_escape_string($item['subtitle']);
            $custom1 = mysql_escape_string($item['media_text']);
        } else {
            $link = mysql_escape_string($item['link']);
        }
        $title = mysql_escape_string($item['title']);
        $content = mysql_escape_string($item['description']);
        if ($item['content']['encoded']) {
            $content = mysql_escape_string($item['content']['encoded']);
        }
        if ($item['atom_content']) {
            $content = mysql_escape_string($item['atom_content']);
        }
        if (isset($item['dc'])) {
            $dcdate = strtotime(mysql_escape_string($item['dc']['date']));
            $dcdate = date("Y-m-d", $dcdate);
            $dccreator = mysql_escape_string($item['dc']['creator']);
            $dcsubject = mysql_escape_string($item['dc']['subject']);
        } else {
            $pubdate = isset($item['pubdate']) ? $item['pubdate'] : (isset($item['pubDate']) ? $item['pubDate'] : false);
            if ($pubdate) {
                $dcdate = strtotime(mysql_escape_string($pubdate));
                $dcdate = date("Y-m-d", $dcdate);
            }
            $dccreator = mysql_escape_string($item['author']);
            $dcsubject = mysql_escape_string($item['category']);
        }
        if (!$link) {
            $link = $item['guid'];
        }
        if (!$title) {
            $title = "[no title]";
        }
        $result = fof_do_query("select id from {$FOF_ITEM_TABLE} where feed_id='{$feed_id}' and link='{$link}'");
        $row = mysql_fetch_array($result);
        $id = $row['id'];
        if (mysql_num_rows($result) == 0) {
            $n++;
            if (AMP_CONTENT_RSS_CUSTOMFORMAT == 'true') {
                $sql = "insert into {$FOF_ITEM_TABLE} (feed_id,link,title,content,dcdate,dccreator,dcsubject,contacts,subtitle,custom1) values ('{$feed_id}','{$link}','{$title}','{$content}','{$dcdate}','{$dccreator}','{$dcsubject}','{$contacts}','{$subtitle}','{$custom1}')";
            } else {
                $sql = "insert into {$FOF_ITEM_TABLE} (feed_id,link,title,content,dcdate,dccreator,dcsubject) values ('{$feed_id}','{$link}','{$title}','{$content}','{$dcdate}','{$dccreator}','{$dcsubject}')";
            }
            $result = fof_do_query($sql);
        } else {
            $ids[] = $id;
        }
    }
    if (defined('FOF_KEEP_DAYS')) {
        $keep_days = FOF_KEEP_DAYS;
        if (count($ids) != 0) {
            $first = 1;
            foreach ($ids as $id) {
                if ($first) {
                    $stat = "({$id}";
                    $first = 0;
                } else {
                    $stat .= ", {$id}";
                }
            }
            $stat .= ")";
            $sql = "delete from {$FOF_ITEM_TABLE} where feed_id = {$feed_id} and `read`=1 and id not in {$stat} and to_days( CURDATE(  )  )  - to_days( timestamp )  > {$keep_days}";
            fof_do_query($sql);
        }
    }
    return $n;
}
Esempio n. 8
0
 /**
  * Fetch the feed
  */
 function fetch()
 {
     if ($this->getUrl() != "") {
         $this->feed = @fetch_rss($this->getUrl());
     }
     if (!$this->feed) {
         $error = magpie_error();
         if ($error == "") {
             $this->setError("Unknown Error.");
         } else {
             $this->setError(magpie_error());
         }
         return false;
     }
     if (is_array($this->feed->items)) {
         foreach ($this->feed->items as $item) {
             $item_obj = new ilExternalFeedItem();
             $item_obj->setMagpieItem($item);
             $this->items[] = $item_obj;
         }
     }
 }
Esempio n. 9
0
define('MAGPIE_DIR', '/home/kellan/projs/magpierss/');
require_once MAGPIE_DIR . 'rss_fetch.inc';
require_once MAGPIE_DIR . 'rss_utils.inc';
// optionally show lots of debugging info
# define('MAGPIE_DEBUG', 2);
// optionally flush cache quickly for debugging purposes,
// don't do this on a live site
# define('MAGPIE_CACHE_AGE', 10);
// use cache?  default is yes.  see rss_fetch for other Magpie options
# define('MAGPIE_CACHE_ON', 1)
// setup template object
$smarty = new Smarty();
$smarty->compile_check = true;
// url of an rss file
$url = htmlspecialchars($_GET['rss_url'], ENT_QUOTES);
if ($url) {
    // assign a variable to smarty for use in the template
    $smarty->assign('rss_url', $url);
    // use MagpieRSS to fetch remote RSS file, and parse it
    $rss = fetch_rss($url);
    // if fetch_rss returned false, we encountered an error
    if (!$rss) {
        $smarty->assign('error', magpie_error());
    }
    $smarty->assign('rss', $rss);
    $item = $rss->items[0];
    $date = parse_w3cdtf($item['dc']['date']);
    $smarty->assign('date', $date);
}
// parse smarty template, and display using the variables we assigned
$smarty->display('simple.smarty');
Esempio n. 10
0
/**
 * Fetches an RSS or Atom feed, and displays it on a page.
 *
 * Example:
 * <pre>
 * [[ feed url="http://api.flickr.com/services/feeds/photos_public.gne?id=26205235@N02&lang=en-us&format=rss_200"
 *   amount=8 dateformat="%dayname% %day% %monthname%" allowtags="<img><a><strong><em>" ]]
 * <p><strong><a href="%link%">%title%</a></strong><br/></p>
 * <p>%description% (%date%)</p>
 * [[ /feed ]]
 * </pre>
 *
 * In addition to the standard formatting tags (%title%, %link%, %description%,
 * %content%, %author%, %date%, and %id%), you can use any key defined in feed 
 * (by using %keyname%). Upto two-level arrays with keys are supported (as 
 * "%keyname->subkeyname->subsubkeyname%")
 *
 * @param array $params
 * @param string $text
 * @param object $smarty
 * @return string
 */
function smarty_feed($params, $text, &$smarty)
{
    global $PIVOTX;
    $params = cleanParams($params);
    // This function gets called twice. Once when enter it, and once when
    // leaving the block. In the latter case we return an empty string.
    if (!isset($text)) {
        return "";
    }
    if (!isset($params['url'])) {
        return __("You need to specify an URL to a feed");
    }
    $amount = getDefault($params['amount'], 8);
    $dateformat = getDefault($params['dateformat'], "%dayname% %day% %monthname% %year%");
    $trimlength = getDefault($params['trimlength'], 10000);
    include_once $PIVOTX['paths']['pivotx_path'] . 'includes/magpie/rss_fetch.inc';
    // Parse it
    $rss = fetch_rss($params['url']);
    $output = "";
    if (count($rss->items) > 0) {
        // Slice it, so no more than '$amount' items will be shown.
        $rss->items = array_slice($rss->items, 0, $amount);
        foreach ($rss->items as $feeditem) {
            $item = $text;
            // If the feed has authors on an entry-level, override the author name..
            if ($author = $feeditem['author']) {
                $authorname = $feeditem['author'];
            }
            $date = formatDate(date("Y-m-d H-i-s", $feeditem['date_timestamp']), $dateformat);
            // Get the title, description and content, since we might want to do some
            // parsing on it..
            $title = $feeditem['title'];
            $description = $feeditem['description'];
            $content = getDefault($feeditem['atom_content'], $feeditem['summary']);
            // Do some parsing: stripping tags, trimming length, stuff like that.
            if (!empty($params['allowtags'])) {
                $title = stripTagsAttributes($title, $params['allowtags']);
                $description = stripTagsAttributes($description, $params['allowtags']);
                $content = stripTagsAttributes($content, $params['allowtags']);
            } else {
                $title = trimText(stripTagsAttributes($title, "<>"), $trimlength);
                $description = trimText(stripTagsAttributes($description, "<>"), $trimlength);
                $content = trimText(stripTagsAttributes($content, "<>"), $trimlength);
            }
            $item = str_replace('%title%', $title, $item);
            $item = str_replace('%link%', $feeditem['link'], $item);
            $item = str_replace('%description%', $description, $item);
            $item = str_replace('%content%', $content, $item);
            $item = str_replace('%author%', $authorname, $item);
            $item = str_replace('%date%', $date, $item);
            $item = str_replace('%id%', $feeditem['id'], $item);
            // Supporting upto two level arrays in item elements.
            foreach ($feeditem as $key => $value) {
                if (is_string($value)) {
                    if ($key == "link" || $trimlength == -1) {
                        $value = trim($value);
                    } else {
                        $value = trimText(trim($value), $trimlength);
                    }
                    $item = str_replace("%{$key}%", $value, $item);
                } else {
                    if (is_array($value)) {
                        foreach ($value as $arrkey => $arrvalue) {
                            if (is_string($arrvalue)) {
                                $arrvalue = trim($arrvalue);
                                if ($trimlength != -1) {
                                    $arrvalue = trimText($arrvalue, $trimlength);
                                }
                                $item = str_replace("%{$key}" . '->' . "{$arrkey}%", $arrvalue, $item);
                            } else {
                                if (is_array($arrvalue)) {
                                    foreach ($arrvalue as $subarrkey => $subarrvalue) {
                                        if (is_string($subarrvalue)) {
                                            $subarrvalue = trim($subarrvalue);
                                            if ($trimlength != -1) {
                                                $subarrvalue = trimText($subarrvalue, $trimlength);
                                            }
                                            $item = str_replace("%{$key}" . '->' . "{$arrkey}" . '->' . "{$subarrkey}%", $subarrvalue, $item);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // Remove any unused formatting tags.
            $item = preg_replace("/%[^%]+%/", "", $item);
            $output .= $item;
        }
    } else {
        debug("<p>Oops! I'm afraid I couldn't read the the feed.</p>");
        echo "<p>" . __("Oops! I'm afraid I couldn't read the feed.") . "</p>";
        debug(magpie_error());
    }
    return $output;
}
Esempio n. 11
0
function update_rss_feed($link, $feed, $ignore_daemon = false, $no_cache = false, $override_url = false)
{
    require_once "lib/simplepie/simplepie.inc";
    require_once "lib/magpierss/rss_fetch.inc";
    require_once 'lib/magpierss/rss_utils.inc';
    $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
    if (!$_REQUEST["daemon"] && !$ignore_daemon) {
        return false;
    }
    if ($debug_enabled) {
        _debug("update_rss_feed: start");
    }
    if (!$ignore_daemon) {
        if (DB_TYPE == "pgsql") {
            $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')";
        } else {
            $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))";
        }
        $result = db_query($link, "SELECT id,update_interval,auth_login,\n\t\t\t\tauth_pass,cache_images,update_method,last_updated\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}' AND {$updstart_thresh_qpart}");
    } else {
        $result = db_query($link, "SELECT id,update_interval,auth_login,\n\t\t\t\tfeed_url,auth_pass,cache_images,update_method,last_updated,\n\t\t\t\tmark_unread_on_update, owner_uid, update_on_checksum_change,\n\t\t\t\tpubsub_state\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
    }
    if (db_num_rows($result) == 0) {
        if ($debug_enabled) {
            _debug("update_rss_feed: feed {$feed} NOT FOUND/SKIPPED");
        }
        return false;
    }
    $update_method = db_fetch_result($result, 0, "update_method");
    $last_updated = db_fetch_result($result, 0, "last_updated");
    $owner_uid = db_fetch_result($result, 0, "owner_uid");
    $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
    $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result, 0, "update_on_checksum_change"));
    $pubsub_state = db_fetch_result($result, 0, "pubsub_state");
    db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\tWHERE id = '{$feed}'");
    $auth_login = db_fetch_result($result, 0, "auth_login");
    $auth_pass = db_fetch_result($result, 0, "auth_pass");
    if ($update_method == 0) {
        $update_method = DEFAULT_UPDATE_METHOD + 1;
    }
    // 1 - Magpie
    // 2 - SimplePie
    // 3 - Twitter OAuth
    if ($update_method == 2) {
        $use_simplepie = true;
    } else {
        $use_simplepie = false;
    }
    if ($debug_enabled) {
        _debug("update method: {$update_method} (feed setting: {$update_method}) (use simplepie: {$use_simplepie})\n");
    }
    if ($update_method == 1) {
        $auth_login = urlencode($auth_login);
        $auth_pass = urlencode($auth_pass);
    }
    $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
    $fetch_url = db_fetch_result($result, 0, "feed_url");
    $feed = db_escape_string($feed);
    if ($auth_login && $auth_pass) {
        $url_parts = array();
        preg_match("/(^[^:]*):\\/\\/(.*)/", $fetch_url, $url_parts);
        if ($url_parts[1] && $url_parts[2]) {
            $fetch_url = $url_parts[1] . "://{$auth_login}:{$auth_pass}@" . $url_parts[2];
        }
    }
    if ($override_url) {
        $fetch_url = $override_url;
    }
    if ($debug_enabled) {
        _debug("update_rss_feed: fetching [{$fetch_url}]...");
    }
    // Ignore cache if new feed or manual update.
    $cache_age = is_null($last_updated) || $last_updated == '1970-01-01 00:00:00' ? -1 : get_feed_update_interval($link, $feed) * 60;
    if ($update_method == 3) {
        $rss = fetch_twitter_rss($link, $fetch_url, $owner_uid);
    } else {
        if ($update_method == 1) {
            define('MAGPIE_CACHE_AGE', $cache_age);
            define('MAGPIE_CACHE_ON', !$no_cache);
            define('MAGPIE_FETCH_TIME_OUT', 60);
            define('MAGPIE_CACHE_DIR', CACHE_DIR . "/magpie");
            $rss = @fetch_rss($fetch_url);
        } else {
            $simplepie_cache_dir = CACHE_DIR . "/simplepie";
            if (!is_dir($simplepie_cache_dir)) {
                mkdir($simplepie_cache_dir);
            }
            $rss = new SimplePie();
            $rss->set_useragent(SELF_USER_AGENT);
            #			$rss->set_timeout(10);
            $rss->set_feed_url($fetch_url);
            $rss->set_output_encoding('UTF-8');
            //$rss->force_feed(true);
            if ($debug_enabled) {
                _debug("feed update interval (sec): " . get_feed_update_interval($link, $feed) * 60);
            }
            $rss->enable_cache(!$no_cache);
            if (!$no_cache) {
                $rss->set_cache_location($simplepie_cache_dir);
                $rss->set_cache_duration($cache_age);
            }
            $rss->init();
        }
    }
    //		print_r($rss);
    if ($debug_enabled) {
        _debug("update_rss_feed: fetch done, parsing...");
    }
    $feed = db_escape_string($feed);
    if ($update_method == 2) {
        $fetch_ok = !$rss->error();
    } else {
        $fetch_ok = !!$rss;
    }
    if ($fetch_ok) {
        if ($debug_enabled) {
            _debug("update_rss_feed: processing feed data...");
        }
        //			db_query($link, "BEGIN");
        if (DB_TYPE == "pgsql") {
            $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
        } else {
            $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
        }
        $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid,\n\t\t\t\t(favicon_last_checked IS NULL OR {$favicon_interval_qpart}) AS\n\t\t\t\t\t\tfavicon_needs_check\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
        $registered_title = db_fetch_result($result, 0, "title");
        $orig_icon_url = db_fetch_result($result, 0, "icon_url");
        $orig_site_url = db_fetch_result($result, 0, "site_url");
        $favicon_needs_check = sql_bool_to_bool(db_fetch_result($result, 0, "favicon_needs_check"));
        $owner_uid = db_fetch_result($result, 0, "owner_uid");
        if ($use_simplepie) {
            $site_url = db_escape_string(trim($rss->get_link()));
        } else {
            $site_url = db_escape_string(trim($rss->channel["link"]));
        }
        // weird, weird Magpie
        if (!$use_simplepie) {
            if (!$site_url) {
                $site_url = db_escape_string($rss->channel["link_"]);
            }
        }
        $site_url = rewrite_relative_url($fetch_url, $site_url);
        $site_url = substr($site_url, 0, 250);
        if ($debug_enabled) {
            _debug("update_rss_feed: checking favicon...");
        }
        if ($favicon_needs_check) {
            check_feed_favicon($site_url, $feed, $link);
            db_query($link, "UPDATE ttrss_feeds SET favicon_last_checked = NOW()\n\t\t\t\t\tWHERE id = '{$feed}'");
        }
        if (!$registered_title || $registered_title == "[Unknown]") {
            if ($use_simplepie) {
                $feed_title = db_escape_string($rss->get_title());
            } else {
                $feed_title = db_escape_string($rss->channel["title"]);
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: registering title: {$feed_title}");
            }
            db_query($link, "UPDATE ttrss_feeds SET\n\t\t\t\t\ttitle = '{$feed_title}' WHERE id = '{$feed}'");
        }
        if ($site_url && $orig_site_url != $site_url) {
            db_query($link, "UPDATE ttrss_feeds SET\n\t\t\t\t\tsite_url = '{$site_url}' WHERE id = '{$feed}'");
        }
        //			print "I: " . $rss->channel["image"]["url"];
        if (!$use_simplepie) {
            $icon_url = db_escape_string(trim($rss->image["url"]));
        } else {
            $icon_url = db_escape_string(trim($rss->get_image_url()));
        }
        $icon_url = rewrite_relative_url($fetch_url, $icon_url);
        $icon_url = substr($icon_url, 0, 250);
        if ($icon_url && $orig_icon_url != $icon_url) {
            db_query($link, "UPDATE ttrss_feeds SET icon_url = '{$icon_url}' WHERE id = '{$feed}'");
        }
        if ($debug_enabled) {
            _debug("update_rss_feed: loading filters...");
        }
        $filters = load_filters($link, $feed, $owner_uid);
        //			if ($debug_enabled) {
        //				print_r($filters);
        //			}
        if ($use_simplepie) {
            $iterator = $rss->get_items();
        } else {
            $iterator = $rss->items;
            if (!$iterator || !is_array($iterator)) {
                $iterator = $rss->entries;
            }
            if (!$iterator || !is_array($iterator)) {
                $iterator = $rss;
            }
        }
        if (!is_array($iterator)) {
            /* db_query($link, "UPDATE ttrss_feeds
            			SET last_error = 'Parse error: can\'t find any articles.'
            			WHERE id = '$feed'"); */
            // clear any errors and mark feed as updated if fetched okay
            // even if it's blank
            if ($debug_enabled) {
                _debug("update_rss_feed: entry iterator is not an array, no articles?");
            }
            db_query($link, "UPDATE ttrss_feeds\n\t\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
            return;
            // no articles
        }
        if ($pubsub_state != 2 && PUBSUBHUBBUB_ENABLED) {
            if ($debug_enabled) {
                _debug("update_rss_feed: checking for PUSH hub...");
            }
            $feed_hub_url = false;
            if ($use_simplepie) {
                $links = $rss->get_links('hub');
                if ($links && is_array($links)) {
                    foreach ($links as $l) {
                        $feed_hub_url = $l;
                        break;
                    }
                }
            } else {
                $atom = $rss->channel['atom'];
                if ($atom) {
                    if ($atom['link@rel'] == 'hub') {
                        $feed_hub_url = $atom['link@href'];
                    }
                    if (!$feed_hub_url && $atom['link#'] > 1) {
                        for ($i = 2; $i <= $atom['link#']; $i++) {
                            if ($atom["link#{$i}@rel"] == 'hub') {
                                $feed_hub_url = $atom["link#{$i}@href"];
                                break;
                            }
                        }
                    }
                } else {
                    $feed_hub_url = $rss->channel['link_hub'];
                }
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: feed hub url: {$feed_hub_url}");
            }
            if ($feed_hub_url && function_exists('curl_init') && !ini_get("open_basedir")) {
                require_once 'lib/pubsubhubbub/subscriber.php';
                $callback_url = get_self_url_prefix() . "/public.php?op=pubsub&id={$feed}";
                $s = new Subscriber($feed_hub_url, $callback_url);
                $rc = $s->subscribe($fetch_url);
                if ($debug_enabled) {
                    _debug("update_rss_feed: feed hub url found, subscribe request sent.");
                }
                db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 1\n\t\t\t\t\t\tWHERE id = '{$feed}'");
            }
        }
        if ($debug_enabled) {
            _debug("update_rss_feed: processing articles...");
        }
        foreach ($iterator as $item) {
            if ($_REQUEST['xdebug'] == 2) {
                print_r($item);
            }
            if ($use_simplepie) {
                $entry_guid = $item->get_id();
                if (!$entry_guid) {
                    $entry_guid = $item->get_link();
                }
                if (!$entry_guid) {
                    $entry_guid = make_guid_from_title($item->get_title());
                }
            } else {
                $entry_guid = $item["id"];
                if (!$entry_guid) {
                    $entry_guid = $item["guid"];
                }
                if (!$entry_guid) {
                    $entry_guid = $item["about"];
                }
                if (!$entry_guid) {
                    $entry_guid = $item["link"];
                }
                if (!$entry_guid) {
                    $entry_guid = make_guid_from_title($item["title"]);
                }
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: guid {$entry_guid}");
            }
            if (!$entry_guid) {
                continue;
            }
            $entry_timestamp = "";
            if ($use_simplepie) {
                $entry_timestamp = strtotime($item->get_date());
            } else {
                $rss_2_date = $item['pubdate'];
                $rss_1_date = $item['dc']['date'];
                $atom_date = $item['issued'];
                if (!$atom_date) {
                    $atom_date = $item['updated'];
                }
                if ($atom_date != "") {
                    $entry_timestamp = parse_w3cdtf($atom_date);
                }
                if ($rss_1_date != "") {
                    $entry_timestamp = parse_w3cdtf($rss_1_date);
                }
                if ($rss_2_date != "") {
                    $entry_timestamp = strtotime($rss_2_date);
                }
            }
            if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) {
                $entry_timestamp = time();
                $no_orig_date = 'true';
            } else {
                $no_orig_date = 'false';
            }
            $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
            if ($debug_enabled) {
                _debug("update_rss_feed: date {$entry_timestamp} [{$entry_timestamp_fmt}]");
            }
            if ($use_simplepie) {
                $entry_title = $item->get_title();
            } else {
                $entry_title = trim(strip_tags($item["title"]));
            }
            if ($use_simplepie) {
                $entry_link = $item->get_link();
            } else {
                // strange Magpie workaround
                $entry_link = $item["link_"];
                if (!$entry_link) {
                    $entry_link = $item["link"];
                }
            }
            $entry_link = rewrite_relative_url($site_url, $entry_link);
            if ($debug_enabled) {
                _debug("update_rss_feed: title {$entry_title}");
                _debug("update_rss_feed: link {$entry_link}");
            }
            if (!$entry_title) {
                $entry_title = date("Y-m-d H:i:s", $entry_timestamp);
            }
            $entry_link = strip_tags($entry_link);
            if ($use_simplepie) {
                $entry_content = $item->get_content();
                if (!$entry_content) {
                    $entry_content = $item->get_description();
                }
            } else {
                $entry_content = $item["content:escaped"];
                if (!$entry_content) {
                    $entry_content = $item["content:encoded"];
                }
                if (!$entry_content && is_array($entry_content)) {
                    $entry_content = $item["content"]["encoded"];
                }
                if (!$entry_content) {
                    $entry_content = $item["content"];
                }
                if (is_array($entry_content)) {
                    $entry_content = $entry_content[0];
                }
                // Magpie bugs are getting ridiculous
                if (trim($entry_content) == "Array") {
                    $entry_content = false;
                }
                if (!$entry_content) {
                    $entry_content = $item["atom_content"];
                }
                if (!$entry_content) {
                    $entry_content = $item["summary"];
                }
                if (!$entry_content || strlen($entry_content) < strlen($item["description"])) {
                    $entry_content = $item["description"];
                }
                // WTF
                if (is_array($entry_content)) {
                    $entry_content = $entry_content["encoded"];
                    if (!$entry_content) {
                        $entry_content = $entry_content["escaped"];
                    }
                }
            }
            if ($cache_images && is_writable(CACHE_DIR . '/images')) {
                $entry_content = cache_images($entry_content, $site_url, $debug_enabled);
            }
            if ($_REQUEST["xdebug"] == 2) {
                print "update_rss_feed: content: ";
                print $entry_content;
                print "\n";
            }
            $entry_content_unescaped = $entry_content;
            if ($use_simplepie) {
                $entry_comments = strip_tags($item->data["comments"]);
                if ($item->get_author()) {
                    $entry_author_item = $item->get_author();
                    $entry_author = $entry_author_item->get_name();
                    if (!$entry_author) {
                        $entry_author = $entry_author_item->get_email();
                    }
                    $entry_author = db_escape_string($entry_author);
                }
            } else {
                $entry_comments = strip_tags($item["comments"]);
                $entry_author = db_escape_string(strip_tags($item['dc']['creator']));
                if ($item['author']) {
                    if (is_array($item['author'])) {
                        if (!$entry_author) {
                            $entry_author = db_escape_string(strip_tags($item['author']['name']));
                        }
                        if (!$entry_author) {
                            $entry_author = db_escape_string(strip_tags($item['author']['email']));
                        }
                    }
                    if (!$entry_author) {
                        $entry_author = db_escape_string(strip_tags($item['author']));
                    }
                }
            }
            if (preg_match('/^[\\t\\n\\r ]*$/', $entry_author)) {
                $entry_author = '';
            }
            $entry_guid = db_escape_string(strip_tags($entry_guid));
            $entry_guid = mb_substr($entry_guid, 0, 250);
            $result = db_query($link, "SELECT id FROM\tttrss_entries\n\t\t\t\t\tWHERE guid = '{$entry_guid}'");
            $entry_content = db_escape_string($entry_content, false);
            $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
            $entry_title = db_escape_string($entry_title);
            $entry_link = db_escape_string($entry_link);
            $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250);
            $entry_author = mb_substr($entry_author, 0, 250);
            if ($use_simplepie) {
                $num_comments = 0;
                #FIXME#
            } else {
                $num_comments = db_escape_string($item["slash"]["comments"]);
            }
            if (!$num_comments) {
                $num_comments = 0;
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: looking for tags [1]...");
            }
            // parse <category> entries into tags
            $additional_tags = array();
            if ($use_simplepie) {
                $additional_tags_src = $item->get_categories();
                if (is_array($additional_tags_src)) {
                    foreach ($additional_tags_src as $tobj) {
                        array_push($additional_tags, $tobj->get_term());
                    }
                }
                if ($debug_enabled) {
                    _debug("update_rss_feed: category tags:");
                    print_r($additional_tags);
                }
            } else {
                $t_ctr = $item['category#'];
                if ($t_ctr == 0) {
                    $additional_tags = array();
                } else {
                    if ($t_ctr > 0) {
                        $additional_tags = array($item['category']);
                        if ($item['category@term']) {
                            array_push($additional_tags, $item['category@term']);
                        }
                        for ($i = 0; $i <= $t_ctr; $i++) {
                            if ($item["category#{$i}"]) {
                                array_push($additional_tags, $item["category#{$i}"]);
                            }
                            if ($item["category#{$i}@term"]) {
                                array_push($additional_tags, $item["category#{$i}@term"]);
                            }
                        }
                    }
                }
                // parse <dc:subject> elements
                $t_ctr = $item['dc']['subject#'];
                if ($t_ctr > 0) {
                    array_push($additional_tags, $item['dc']['subject']);
                    for ($i = 0; $i <= $t_ctr; $i++) {
                        if ($item['dc']["subject#{$i}"]) {
                            array_push($additional_tags, $item['dc']["subject#{$i}"]);
                        }
                    }
                }
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: looking for tags [2]...");
            }
            /* taaaags */
            // <a href="..." rel="tag">Xorg</a>, //
            $entry_tags = null;
            preg_match_all("/<a.*?rel=['\"]tag['\"].*?\\>([^<]+)<\\/a>/i", $entry_content_unescaped, $entry_tags);
            $entry_tags = $entry_tags[1];
            $entry_tags = array_merge($entry_tags, $additional_tags);
            $entry_tags = array_unique($entry_tags);
            for ($i = 0; $i < count($entry_tags); $i++) {
                $entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8');
            }
            if ($debug_enabled) {
                //_debug("update_rss_feed: unfiltered tags found:");
                //print_r($entry_tags);
            }
            # sanitize content
            $entry_content = sanitize_article_content($entry_content);
            $entry_title = sanitize_article_content($entry_title);
            if ($debug_enabled) {
                _debug("update_rss_feed: done collecting data [TITLE:{$entry_title}]");
            }
            db_query($link, "BEGIN");
            if (db_num_rows($result) == 0) {
                if ($debug_enabled) {
                    _debug("update_rss_feed: base guid not found");
                }
                // base post entry does not exist, create it
                $result = db_query($link, "INSERT INTO ttrss_entries\n\t\t\t\t\t\t\t(title,\n\t\t\t\t\t\t\tguid,\n\t\t\t\t\t\t\tlink,\n\t\t\t\t\t\t\tupdated,\n\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\tcontent_hash,\n\t\t\t\t\t\t\tno_orig_date,\n\t\t\t\t\t\t\tdate_updated,\n\t\t\t\t\t\t\tdate_entered,\n\t\t\t\t\t\t\tcomments,\n\t\t\t\t\t\t\tnum_comments,\n\t\t\t\t\t\t\tauthor)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('{$entry_title}',\n\t\t\t\t\t\t\t'{$entry_guid}',\n\t\t\t\t\t\t\t'{$entry_link}',\n\t\t\t\t\t\t\t'{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t'{$entry_content}',\n\t\t\t\t\t\t\t'{$content_hash}',\n\t\t\t\t\t\t\t{$no_orig_date},\n\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t'{$entry_comments}',\n\t\t\t\t\t\t\t'{$num_comments}',\n\t\t\t\t\t\t\t'{$entry_author}')");
            } else {
                // we keep encountering the entry in feeds, so we need to
                // update date_updated column so that we don't get horrible
                // dupes when the entry gets purged and reinserted again e.g.
                // in the case of SLOW SLOW OMG SLOW updating feeds
                $base_entry_id = db_fetch_result($result, 0, "id");
                db_query($link, "UPDATE ttrss_entries SET date_updated = NOW()\n\t\t\t\t\t\tWHERE id = '{$base_entry_id}'");
            }
            // now it should exist, if not - bad luck then
            $result = db_query($link, "SELECT\n\t\t\t\t\t\tid,content_hash,no_orig_date,title,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(date_updated,1,19) as date_updated,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(updated,1,19) as updated,\n\t\t\t\t\t\tnum_comments\n\t\t\t\t\tFROM\n\t\t\t\t\t\tttrss_entries\n\t\t\t\t\tWHERE guid = '{$entry_guid}'");
            $entry_ref_id = 0;
            $entry_int_id = 0;
            if (db_num_rows($result) == 1) {
                if ($debug_enabled) {
                    _debug("update_rss_feed: base guid found, checking for user record");
                }
                // this will be used below in update handler
                $orig_content_hash = db_fetch_result($result, 0, "content_hash");
                $orig_title = db_fetch_result($result, 0, "title");
                $orig_num_comments = db_fetch_result($result, 0, "num_comments");
                $orig_date_updated = strtotime(db_fetch_result($result, 0, "date_updated"));
                $ref_id = db_fetch_result($result, 0, "id");
                $entry_ref_id = $ref_id;
                // check for user post link to main table
                // do we allow duplicate posts with same GUID in different feeds?
                if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
                    $dupcheck_qpart = "AND (feed_id = '{$feed}' OR feed_id IS NULL)";
                } else {
                    $dupcheck_qpart = "";
                }
                /* Collect article tags here so we could filter by them: */
                $article_filters = get_article_filters($filters, $entry_title, $entry_content, $entry_link, $entry_timestamp, $entry_author, $entry_tags);
                if ($debug_enabled) {
                    _debug("update_rss_feed: article filters: ");
                    if (count($article_filters) != 0) {
                        print_r($article_filters);
                    }
                }
                if (find_article_filter($article_filters, "filter")) {
                    db_query($link, "COMMIT");
                    // close transaction in progress
                    continue;
                }
                $score = calculate_article_score($article_filters);
                if ($debug_enabled) {
                    _debug("update_rss_feed: initial score: {$score}");
                }
                $query = "SELECT ref_id, int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}'\n\t\t\t\t\t\t\t{$dupcheck_qpart}";
                //					if ($_REQUEST["xdebug"]) print "$query\n";
                $result = db_query($link, $query);
                // okay it doesn't exist - create user entry
                if (db_num_rows($result) == 0) {
                    if ($debug_enabled) {
                        _debug("update_rss_feed: user record not found, creating...");
                    }
                    if ($score >= -500 && !find_article_filter($article_filters, 'catchup')) {
                        $unread = 'true';
                        $last_read_qpart = 'NULL';
                    } else {
                        $unread = 'false';
                        $last_read_qpart = 'NOW()';
                    }
                    if (find_article_filter($article_filters, 'mark') || $score > 1000) {
                        $marked = 'true';
                    } else {
                        $marked = 'false';
                    }
                    if (find_article_filter($article_filters, 'publish')) {
                        $published = 'true';
                    } else {
                        $published = 'false';
                    }
                    // N-grams
                    if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_DUPLICATE_THRESHOLD')) {
                        $result = db_query($link, "SELECT COUNT(*) AS similar FROM\n\t\t\t\t\t\t\t\t\tttrss_entries,ttrss_user_entries\n\t\t\t\t\t\t\t\tWHERE ref_id = id AND updated >= NOW() - INTERVAL '7 day'\n\t\t\t\t\t\t\t\t\tAND similarity(title, '{$entry_title}') >= " . _NGRAM_TITLE_DUPLICATE_THRESHOLD . "\n\t\t\t\t\t\t\t\t\tAND owner_uid = {$owner_uid}");
                        $ngram_similar = db_fetch_result($result, 0, "similar");
                        if ($debug_enabled) {
                            _debug("update_rss_feed: N-gram similar results: {$ngram_similar}");
                        }
                        if ($ngram_similar > 0) {
                            $unread = 'false';
                        }
                    }
                    $result = db_query($link, "INSERT INTO ttrss_user_entries\n\t\t\t\t\t\t\t\t(ref_id, owner_uid, feed_id, unread, last_read, marked,\n\t\t\t\t\t\t\t\t\tpublished, score, tag_cache, label_cache, uuid)\n\t\t\t\t\t\t\tVALUES ('{$ref_id}', '{$owner_uid}', '{$feed}', {$unread},\n\t\t\t\t\t\t\t\t{$last_read_qpart}, {$marked}, {$published}, '{$score}', '', '', '')");
                    if (PUBSUBHUBBUB_HUB && $published == 'true') {
                        $rss_link = get_self_url_prefix() . "/public.php?op=rss&id=-2&key=" . get_feed_access_key($link, -2, false, $owner_uid);
                        $p = new Publisher(PUBSUBHUBBUB_HUB);
                        $pubsub_result = $p->publish_update($rss_link);
                    }
                    $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}' AND\n\t\t\t\t\t\t\t\tfeed_id = '{$feed}' LIMIT 1");
                    if (db_num_rows($result) == 1) {
                        $entry_int_id = db_fetch_result($result, 0, "int_id");
                    }
                } else {
                    if ($debug_enabled) {
                        _debug("update_rss_feed: user record FOUND");
                    }
                    $entry_ref_id = db_fetch_result($result, 0, "ref_id");
                    $entry_int_id = db_fetch_result($result, 0, "int_id");
                }
                if ($debug_enabled) {
                    _debug("update_rss_feed: RID: {$entry_ref_id}, IID: {$entry_int_id}");
                }
                $post_needs_update = false;
                $update_insignificant = false;
                if ($orig_num_comments != $num_comments) {
                    $post_needs_update = true;
                    $update_insignificant = true;
                }
                if ($content_hash != $orig_content_hash) {
                    $post_needs_update = true;
                    $update_insignificant = false;
                }
                if (db_escape_string($orig_title) != $entry_title) {
                    $post_needs_update = true;
                    $update_insignificant = false;
                }
                // if post needs update, update it and mark all user entries
                // linking to this post as updated
                if ($post_needs_update) {
                    if (defined('DAEMON_EXTENDED_DEBUG')) {
                        _debug("update_rss_feed: post {$entry_guid} needs update...");
                    }
                    //						print "<!-- post $orig_title needs update : $post_needs_update -->";
                    db_query($link, "UPDATE ttrss_entries\n\t\t\t\t\t\t\tSET title = '{$entry_title}', content = '{$entry_content}',\n\t\t\t\t\t\t\t\tcontent_hash = '{$content_hash}',\n\t\t\t\t\t\t\t\tupdated = '{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t\tnum_comments = '{$num_comments}'\n\t\t\t\t\t\t\tWHERE id = '{$ref_id}'");
                    if (!$update_insignificant) {
                        if ($mark_unread_on_update) {
                            db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\t\t\t\t\t\tSET last_read = null, unread = true WHERE ref_id = '{$ref_id}'");
                        } else {
                            if ($update_on_checksum_change) {
                                db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\t\t\t\t\t\tSET last_read = null WHERE ref_id = '{$ref_id}'\n\t\t\t\t\t\t\t\t\t\tAND unread = false");
                            }
                        }
                    }
                }
            }
            db_query($link, "COMMIT");
            if ($debug_enabled) {
                _debug("update_rss_feed: assigning labels...");
            }
            assign_article_to_labels($link, $entry_ref_id, $article_filters, $owner_uid);
            if ($debug_enabled) {
                _debug("update_rss_feed: looking for enclosures...");
            }
            // enclosures
            $enclosures = array();
            if ($use_simplepie) {
                $encs = $item->get_enclosures();
                if (is_array($encs)) {
                    foreach ($encs as $e) {
                        $e_item = array($e->link, $e->type, $e->length);
                        array_push($enclosures, $e_item);
                    }
                }
            } else {
                // <enclosure>
                $e_ctr = $item['enclosure#'];
                if ($e_ctr > 0) {
                    $e_item = array($item['enclosure@url'], $item['enclosure@type'], $item['enclosure@length']);
                    array_push($enclosures, $e_item);
                    for ($i = 0; $i <= $e_ctr; $i++) {
                        if ($item["enclosure#{$i}@url"]) {
                            $e_item = array($item["enclosure#{$i}@url"], $item["enclosure#{$i}@type"], $item["enclosure#{$i}@length"]);
                            array_push($enclosures, $e_item);
                        }
                    }
                }
                // <media:content>
                // can there be many of those? yes -fox
                $m_ctr = $item['media']['content#'];
                if ($m_ctr > 0) {
                    $e_item = array($item['media']['content@url'], $item['media']['content@medium'], $item['media']['content@length']);
                    array_push($enclosures, $e_item);
                    for ($i = 0; $i <= $m_ctr; $i++) {
                        if ($item["media"]["content#{$i}@url"]) {
                            $e_item = array($item["media"]["content#{$i}@url"], $item["media"]["content#{$i}@medium"], $item["media"]["content#{$i}@length"]);
                            array_push($enclosures, $e_item);
                        }
                    }
                }
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: article enclosures:");
                print_r($enclosures);
            }
            db_query($link, "BEGIN");
            foreach ($enclosures as $enc) {
                $enc_url = db_escape_string($enc[0]);
                $enc_type = db_escape_string($enc[1]);
                $enc_dur = db_escape_string($enc[2]);
                $result = db_query($link, "SELECT id FROM ttrss_enclosures\n\t\t\t\t\t\tWHERE content_url = '{$enc_url}' AND post_id = '{$entry_ref_id}'");
                if (db_num_rows($result) == 0) {
                    db_query($link, "INSERT INTO ttrss_enclosures\n\t\t\t\t\t\t\t(content_url, content_type, title, duration, post_id) VALUES\n\t\t\t\t\t\t\t('{$enc_url}', '{$enc_type}', '', '{$enc_dur}', '{$entry_ref_id}')");
                }
            }
            db_query($link, "COMMIT");
            // check for manual tags (we have to do it here since they're loaded from filters)
            foreach ($article_filters as $f) {
                if ($f["type"] == "tag") {
                    $manual_tags = trim_array(explode(",", $f["param"]));
                    foreach ($manual_tags as $tag) {
                        if (tag_is_valid($tag)) {
                            array_push($entry_tags, $tag);
                        }
                    }
                }
            }
            // Skip boring tags
            $boring_tags = trim_array(explode(",", mb_strtolower(get_pref($link, 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
            $filtered_tags = array();
            $tags_to_cache = array();
            if ($entry_tags && is_array($entry_tags)) {
                foreach ($entry_tags as $tag) {
                    if (array_search($tag, $boring_tags) === false) {
                        array_push($filtered_tags, $tag);
                    }
                }
            }
            $filtered_tags = array_unique($filtered_tags);
            if ($debug_enabled) {
                _debug("update_rss_feed: filtered article tags:");
                print_r($filtered_tags);
            }
            // Save article tags in the database
            if (count($filtered_tags) > 0) {
                db_query($link, "BEGIN");
                foreach ($filtered_tags as $tag) {
                    $tag = sanitize_tag($tag);
                    $tag = db_escape_string($tag);
                    if (!tag_is_valid($tag)) {
                        continue;
                    }
                    $result = db_query($link, "SELECT id FROM ttrss_tags\n\t\t\t\t\t\t\tWHERE tag_name = '{$tag}' AND post_int_id = '{$entry_int_id}' AND\n\t\t\t\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
                    if ($result && db_num_rows($result) == 0) {
                        db_query($link, "INSERT INTO ttrss_tags\n\t\t\t\t\t\t\t\t\t(owner_uid,tag_name,post_int_id)\n\t\t\t\t\t\t\t\t\tVALUES ('{$owner_uid}','{$tag}', '{$entry_int_id}')");
                    }
                    array_push($tags_to_cache, $tag);
                }
                /* update the cache */
                $tags_to_cache = array_unique($tags_to_cache);
                $tags_str = db_escape_string(join(",", $tags_to_cache));
                db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\t\t\tSET tag_cache = '{$tags_str}' WHERE ref_id = '{$entry_ref_id}'\n\t\t\t\t\t\tAND owner_uid = {$owner_uid}");
                db_query($link, "COMMIT");
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: article processed");
            }
        }
        if (!$last_updated) {
            if ($debug_enabled) {
                _debug("update_rss_feed: new feed, catching it up...");
            }
            catchup_feed($link, $feed, false, $owner_uid);
        }
        if ($debug_enabled) {
            _debug("purging feed...");
        }
        purge_feed($link, $feed, 0, $debug_enabled);
        db_query($link, "UPDATE ttrss_feeds\n\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
        //			db_query($link, "COMMIT");
    } else {
        if ($use_simplepie) {
            $error_msg = mb_substr($rss->error(), 0, 250);
        } else {
            $error_msg = mb_substr(magpie_error(), 0, 250);
        }
        if ($debug_enabled) {
            _debug("update_rss_feed: error fetching feed: {$error_msg}");
        }
        $error_msg = db_escape_string($error_msg);
        db_query($link, "UPDATE ttrss_feeds SET last_error = '{$error_msg}',\n\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'");
    }
    if ($use_simplepie) {
        unset($rss);
    }
    if ($debug_enabled) {
        _debug("update_rss_feed: done");
    }
}
Esempio n. 12
0
    function getDataApplet_News()
    {
        define('MAGPIE_CACHE_DIR', '/tmp/rss-cache');
        $infoRSS = @fetch_rss($this->arrConf['dir_RSS']);
        $sMensaje = magpie_error();
        if (preg_match("/HTTP Error: connection failed/", $sMensaje)) {
            return _tr('Could not get web server information. You may not have internet access or the web server is down');
        }
        $sContentList = '<div class="neo-applet-news-row">' . _tr('No News to display') . '</div>';
        if (!empty($infoRSS) && is_array($infoRSS->items) && count($infoRSS->items) > 0) {
            $sContentList = '';
            $sPlantilla = <<<PLANTILLA_RSS_ROW
<div class="neo-applet-news-row">
    <span class="neo-applet-news-row-date">%s</span>
    <a href="https://twitter.com/share?original_referer=%s&related=&source=tweetbutton&text=%s&url=%s&via=elastixGui"  target="_blank">
        <img src="modules/dashboard/images/twitter-icon.png" width="16" height="16" alt="tweet" />
    </a>
    <a href="%s" target="_blank">%s</a>
</div>
PLANTILLA_RSS_ROW;
            for ($i = 0; $i < 7 && $i < count($infoRSS->items); $i++) {
                $sContentList .= sprintf($sPlantilla, date('Y.m.d', $infoRSS->items[$i]['date_timestamp']), rawurlencode('http://www.elastix.org'), rawurlencode(utf8_encode($infoRSS->items[$i]['title'])), rawurlencode($infoRSS->items[$i]['link']), $infoRSS->items[$i]['link'], htmlentities($infoRSS->items[$i]['title'], ENT_COMPAT));
            }
        }
        return $sContentList;
    }
Esempio n. 13
0
 protected static function _getTagFeedHelper($feedurl, $feedname, $tag)
 {
     global $PIVOTX;
     $amount = getDefault($PIVOTX['config']->get('tag_fetcher_amount'), 8);
     include_once $PIVOTX['paths']['pivotx_path'] . 'includes/magpie/rss_fetch.inc';
     $rss = fetch_rss($feedurl);
     $output = "";
     if (count($rss->items) > 0) {
         // Slice it, so no more than '$amount' items will be shown.
         $rss->items = array_slice($rss->items, 0, $amount);
         foreach ($rss->items as $item) {
             $output .= sprintf("\n<li><a href='%s'>%s</a><br /><small>%s</small></li> \n", $item['link'], $item['title'], trimText($item['summary'], 200), $readon);
         }
     } else {
         debug("<p>Oops! I'm afraid I couldn't read the Tag feed.</p>");
         echo "<p>" . __("Oops! I'm afraid I couldn't read Tag feed.") . "</p>";
         debug(magpie_error());
     }
     $output = @html_entity_decode($output, ENT_COMPAT, 'UTF-8');
     if ($output == '') {
         $output = sprintf(__('Nothing on <strong>%s</strong> for <strong>%s</strong>'), $feedname, $tag);
     } else {
         $output = sprintf(__('Latest on <strong>%s</strong> for <strong>%s</strong>'), $feedname, $tag) . ':<ul class="taggeratilist">' . $output . '</ul>';
     }
     echo $output;
 }
Esempio n. 14
0
function update($id)
{
    $kses_allowed = getConfig('rss.input.allowed');
    //getAllowedTags();
    $updatedIds = array();
    $sql = "select id, url, title, mode from " . getTable("channels");
    if ($id != "" && is_numeric($id)) {
        $sql .= " where id={$id}";
        $sql .= " and not(mode & " . RSS_MODE_DELETED_STATE . ") ";
    } else {
        $sql .= " where not(mode & " . RSS_MODE_DELETED_STATE . ") ";
    }
    if (getConfig('rss.config.absoluteordering')) {
        $sql .= " order by parent, position";
    } else {
        $sql .= " order by parent, title";
    }
    $res = rss_query($sql);
    while (list($cid, $url, $title, $mode) = rss_fetch_row($res)) {
        // suppress warnings because Magpie is rather noisy
        $old_level = error_reporting(E_ERROR);
        $rss = fetch_rss($url);
        //reset
        error_reporting($old_level);
        if (!$rss && $id != "" && is_numeric($id)) {
            return array(magpie_error(), array());
        } elseif (!$rss || !($rss->rss_origin & MAGPIE_FEED_ORIGIN_HTTP_200)) {
            continue;
            // no need to do anything if we do not get a 200 OK from the feed
        }
        // base URL for items in this feed.
        if (array_key_exists('link', $rss->channel)) {
            $baseUrl = $rss->channel['link'];
        } else {
            $baseUrl = $url;
            // The feed is invalid
        }
        // Keep track of guids we've handled, because some feeds (hello,
        // Technorati!) have this insane habit of serving the same item
        // twice in the same feed.
        $guids = array();
        // Allow updates in this feed?
        $allowUpdates = getProperty($cid, 'rss.input.allowupdates');
        if ($allowUpdates === null) {
            $allowUpdates = getConfig('rss.input.allowupdates');
        }
        $itemIdsInFeed = array();
        // This variable will store the item id's of the elements in the feed
        foreach ($rss->items as $item) {
            $item = rss_plugin_hook('rss.plugins.rssitem', $item);
            // a plugin might delete this item
            if (!isset($item)) {
                continue;
            }
            // item title: strip out html tags
            $title = array_key_exists('title', $item) ? strip_tags($item['title']) : "";
            //$title = str_replace('& ', '&amp; ', $title);
            $description = "";
            // item content, if any
            if (array_key_exists('content', $item) && is_array($item['content']) && array_key_exists('encoded', $item['content'])) {
                $description = $item['content']['encoded'];
            } elseif (array_key_exists('description', $item)) {
                $description = $item['description'];
            } elseif (array_key_exists('atom_content', $item)) {
                $description = $item['atom_content'];
            } elseif (array_key_exists('summary', $item)) {
                $description = $item['summary'];
            } else {
                $description = "";
            }
            $md5sum = "";
            $guid = "";
            if (array_key_exists('guid', $item) && $item['guid'] != "") {
                $guid = $item['guid'];
            } elseif (array_key_exists('id', $item) && $item['id'] != "") {
                $guid = $item['id'];
            }
            $guid = trim($guid);
            $guid = rss_real_escape_string($guid);
            // skip this one if it's an  in-feed-dupe
            if ($guid && isset($guids[$guid])) {
                continue;
            } elseif ($guid) {
                $guids[$guid] = true;
            }
            if ($description != "") {
                $md5sum = md5($description);
                $description = kses($description, $kses_allowed);
                // strip out tags
                if ($baseUrl != "") {
                    $description = relative_to_absolute($description, $baseUrl);
                }
            }
            // Now let plugins modify the description
            $description = rss_plugin_hook('rss.plugins.import.description', $description);
            // link
            if (array_key_exists('link', $item) && $item['link'] != "") {
                $url = $item['link'];
            } elseif (array_key_exists('guid', $item) && $item['guid'] != "") {
                $url = $item['guid'];
            } elseif (array_key_exists('link_', $item) && $item['link_'] != "") {
                $url = $item['link_'];
            } else {
                // fall back to something basic
                $url = md5($title);
            }
            // make sure the url is properly escaped
            $url = htmlentities($url, ENT_QUOTES);
            $url = rss_real_escape_string($url);
            // author
            if (array_key_exists('dc', $item) && array_key_exists('creator', $item['dc'])) {
                // RSS 1.0
                $author = $item['dc']['creator'];
            } else {
                if (array_key_exists('author_name', $item)) {
                    // Atom 0.3
                    $author = $item['author_name'];
                } else {
                    $author = "";
                }
            }
            $author = trim(strip_tags($author));
            // pubdate
            $cDate = -1;
            if (array_key_exists('dc', $item) && array_key_exists('date', $item['dc'])) {
                // RSS 1.0
                $cDate = parse_w3cdtf($item['dc']['date']);
            } elseif (array_key_exists('pubdate', $item)) {
                // RSS 2.0 (?)
                // We use the second param of strtotime here as a workaround
                // of a PHP bug with strtotime. If the pubdate field doesn't
                // contain seconds, the strtotime function will use the current
                // time to fill in seconds in PHP4. This interferes with the
                // update mechanism of gregarius. See ticket #328 for the full
                // gory details. Giving a known date as a second param to
                // strtotime fixes this problem, hence the 0 here.
                $cDate = strtotime($item['pubdate'], 0);
            } elseif (array_key_exists('published', $item)) {
                // atom 1.0
                $cDate = parse_iso8601($item['published']);
            } elseif (array_key_exists('issued', $item)) {
                //Atom, alternative
                $cDate = parse_iso8601($item['issued']);
            } elseif (array_key_exists('updated', $item)) {
                //Atom, alternative
                $cDate = parse_iso8601($item['updated']);
            } elseif (array_key_exists('created', $item)) {
                // atom 0.3
                $cDate = parse_iso8601($item['created']);
            }
            // enclosure
            if (array_key_exists('enclosure@url', $item)) {
                $enclosure = $item['enclosure@url'];
                // If the enclosure is an image, append it to the content
                // but only if it isn't there yet
                if ($enclosure && array_key_exists('enclosure@type', $item) && preg_match('#image/(png|gif|jpe?g)#', $item['enclosure@type']) && FALSE == strpos($description, $enclosure)) {
                    $description = '<img src="' . $enclosure . '" alt="" />' . $description;
                    $enclosure = '';
                }
            } else {
                $enclosure = "";
            }
            // drop items with an url exceeding our column length: we couldn't provide a
            // valid link back anyway.
            if (strlen($url) >= 255) {
                continue;
            }
            $dbtitle = rss_real_escape_string($title);
            if (strlen($dbtitle) >= 255) {
                $dbtitle = substr($dbtitle, 0, 254);
            }
            if ($cDate > 0) {
                $sec = "FROM_UNIXTIME({$cDate})";
            } else {
                $sec = "null";
            }
            // check whether we already have this item
            if ($guid) {
                $sql = "select id,unread, md5sum, guid, pubdate from " . getTable("item") . " where cid={$cid} and guid='{$guid}'";
            } else {
                $sql = "select id,unread, md5sum, guid, pubdate from " . getTable("item") . " where cid={$cid} and url='{$url}' and title='{$dbtitle}'" . " and (pubdate is NULL OR pubdate={$sec})";
            }
            $subres = rss_query($sql);
            list($indb, $state, $dbmd5sum, $dbGuid, $dbPubDate) = rss_fetch_row($subres);
            if ($indb) {
                $itemIdsInFeed[] = $indb;
                if (!($state & RSS_MODE_DELETED_STATE) && $md5sum != $dbmd5sum) {
                    // the md5sums do not match.
                    if ($allowUpdates) {
                        // Are we allowed update items in the db?
                        list($cid, $indb, $description) = rss_plugin_hook('rss.plugins.items.updated', array($cid, $indb, $description));
                        $sql = "update " . getTable("item") . " set " . " description='" . rss_real_escape_string($description) . "', " . " unread = unread | " . RSS_MODE_UNREAD_STATE . ", md5sum='{$md5sum}'" . " where cid={$cid} and id={$indb}";
                        rss_query($sql);
                        $updatedIds[] = $indb;
                        continue;
                    }
                }
            } else {
                // $indb = "" . This must be new item then. In you go.
                list($cid, $dbtitle, $url, $description) = rss_plugin_hook('rss.plugins.items.new', array($cid, $dbtitle, $url, $description));
                $sql = "insert into " . getTable("item") . " (cid, added, title, url, enclosure," . " description, author, unread, pubdate, md5sum, guid) " . " values (" . "{$cid}, now(), '{$dbtitle}', " . " '{$url}', '" . rss_real_escape_string($enclosure) . "', '" . rss_real_escape_string($description) . "', '" . rss_real_escape_string($author) . "', " . "{$mode}, {$sec}, '{$md5sum}', '{$guid}')";
                rss_query($sql);
                $newIid = rss_insert_id();
                $itemIdsInFeed[] = $newIid;
                $updatedIds[] = $newIid;
                rss_plugin_hook('rss.plugins.items.newiid', array($newIid, $item, $cid));
            }
            // end handling of this item
        }
        // end handling of all the items in this feed
        $sql = "update " . getTable("channels") . " set " . " itemsincache = '" . serialize($itemIdsInFeed) . "' where id={$cid}";
        rss_query($sql);
    }
    // end handling all the feeds we were asked to handle
    if ($id != "" && is_numeric($id)) {
        if ($rss) {
            // when everything went well, return the error code
            // and numer of new items
            return array($rss->rss_origin, $updatedIds);
        } else {
            return array(-1, array());
        }
    } else {
        return array(-1, $updatedIds);
    }
}
Esempio n. 15
0
    $url = 'http://magpierss.sf.net/test.rss';
}
test_library_support();
$rss = fetch_rss($url);
if ($rss) {
    echo "<h3>Example Output</h3>";
    echo "Channel: " . $rss->channel['title'] . "<p>";
    echo "<ul>";
    foreach ($rss->items as $item) {
        $href = $item['link'];
        $title = $item['title'];
        echo "<li><a href={$href}>{$title}</a></li>";
    }
    echo "</ul>";
} else {
    echo "Error: " . magpie_error();
}
?>
<form>
	RSS URL: <input type="text" size="30" name="url" value="<?php 
echo $url;
?>
"><br />
	<input type="submit" value="Parse RSS">
</form>

<h3>Parsed Results (var_dump'ed)</h3>
<pre>
<?php 
var_dump($rss);
?>
Esempio n. 16
0
                // echo "SKIPPING!";
                $ski++;
            }
            if (!empty($sql)) {
                if ($result = mysql_query($sql)) {
                    $_echo .= " DONE\n";
                    $gc++;
                } else {
                    $_echo .= " ERROR: " . mysql_error() . "\n";
                    $ge++;
                }
            }
        }
        if (!empty($_echo_LT5) || !empty($_echo)) {
            #echo $_echo_source . $_echo_LT5 . $_echo . "\n";
        }
    } else {
        #fputs(STDERR, $_echo_source . "\n" . magpie_error());
        $sql = "INSERT INTO updatelog (feed_id, timestamp, message) VALUES (" . $row[$i]['id'] . ", '" . $start_time . "', '" . mysql_real_escape_string(magpie_error()) . "')";
        mysql_query($sql);
    }
    $sql = "UPDATE feeds SET updated='" . time() . "' WHERE id = " . $row[$i]['id'];
    $result = mysql_query($sql) or die(mysql_error() . $sql);
}
touch('/webs/sascha/root/www/aggregator.de/temp/stoplastupdate');
unlink('/webs/sascha/root/www/aggregator.de/temp/updaterunning');
/*
$sek = time() - $start_time;

echo "\n\nUpdate beendet. $ins neue Items, $upd Updates, $ski Doubletten uebergangen. $ge MySql-Fehler. $sek Sekunden";
*/
Esempio n. 17
0
if ($_GET['album']) {
    $ssq = "ALB." . $_GET['album'];
}
if (!$_GET['key']) {
    $_GET['key'] = "00000";
}
if (!$_GET['num_items']) {
    $num_items = 10;
} else {
    $num_items = $_GET['num_items'];
}
$feed = "http://www.zoto.com/" . $username . "/feeds/rss/" . $ssq;
$rss = fetch_rss($feed);
if ($rss) {
    $items = array_slice($rss->items, 0, $num_items);
    $image_string = 'var images_' . $_GET['key'] . ' = new Array(';
    $link_string = 'var links_' . $_GET['key'] . ' = new Array(';
    foreach ($items as $item) {
        $matches = array();
        preg_match("/img\\/[0-9x]+\\/([a-z0-9\\-]+)\\.jpg/", $item['description'], $matches);
        $image_string .= ' "' . $matches[1] . '",';
        $item['link'] = preg_replace("/http:\\/\\/([a-z][-a-z0-9]+)" . BASE_URI . "\\/user\\/image_detail/", "http://www" . BASE_URI . "/user/\\1/image_detail", $item['link']);
        $link_string .= ' "' . $item['link'] . '",';
    }
    $image_string = preg_replace("/,\$/", "", $image_string);
    $link_string = preg_replace("/,\$/", "", $link_string);
    print $image_string . '); ';
    print $link_string . '); ';
} else {
    echo magpie_error();
}
Esempio n. 18
0
                                break;
                            case 'jmh':
                                $aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['datestamp']);
                                break;
                            case 'jmah':
                                $aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['datestamp']);
                                break;
                            default:
                                $aso_page['date'] = '';
                        }
                    }
                    $syndication['pagination'] = $pagination;
                    $syndication['pages'][$aso_page['datestamp']] = $aso_page;
                }
            } else {
                echo '<p class="erreur">Erreur ' . magpie_error() . '</p>' . "\n";
            }
        }
    }
    // Trie des pages par date
    krsort($syndication['pages']);
    echo '<div class="boite_syndication' . ($class ? ' ' . $class : '') . '">' . "\n";
    if (count($tab_url) == 1 || $titre != '') {
        echo '<h2 class="rss_site_titre"><a href="' . $syndication['pages'][key($syndication['pages'])]['url_site'] . '">' . $syndication['pages'][key($syndication['pages'])]['titre_site'] . '</a></h2>' . "\n";
    }
    // Gestion des squelettes
    include $template;
    echo '</div>' . "\n";
} else {
    echo 'Il faut entrer obligatoirement le param&ecirc;tre de l\'url pour syndiquer un flux RSS.';
}