Example #1
0
function handleRequest()
{
    $type = param('q', 'tag');
    $outputType = param('f', 'html');
    switch ($type) {
        case 'item':
            //refresh: always from cache
            $zf_aggregator = new Aggregator();
            $item = $zf_aggregator->getItem(param('itemid'));
            $view = zf_createView($outputType);
            $view->renderArticle($item);
            break;
        case 'download-item':
            //refresh: always from cache
            $zf_aggregator = new Aggregator();
            $item = $zf_aggregator->downloadItem(param('itemid'));
            $view = zf_createView($outputType);
            $view->renderArticle($item);
            break;
        case 'save-item':
            //refresh: always from cache
            $zf_aggregator = new Aggregator();
            $item = $zf_aggregator->saveItem(param('itemid'), param('save', 1));
            $view = zf_createView($outputType);
            $view->renderArticle($item);
            break;
        case 'summary':
            //refresh: always from cache
            $zf_aggregator = new Aggregator();
            $item = $zf_aggregator->getItem(param('itemid'));
            $view = zf_createView($outputType);
            $view->renderSummary($item);
            break;
        case 'channel':
            //refresh: user defined
            $zf_aggregator = new Aggregator();
            $feed = $zf_aggregator->getPublisherFeed(param('id'), param('mode', ZF_REFRESHMODE == 'automatic' ? 'auto' : 'none'), param('trim', 'auto'), int_param('onlynew', ZF_ONLYNEW == 'no' ? 0 : 1));
            $view = zf_createView($outputType);
            $view->renderFeed($feed, array('groupbyday' => false, 'decoration' => int_param('decoration'), 'summary' => param('sum', 1) == 1));
            break;
        case 'tag':
            //refresh: always auto refresh for tag view
            // if html output & sorted by feed, trim every single item
            // according to subcription's settings
            $sort = param('sort', ZF_SORT);
            if ($sort == 'feed' && strstr($outputType, 'html')) {
                $groupbyday = false;
                $aggregate = false;
            } else {
                // otherwise just aggregate in a single feed
                $groupbyday = true;
                $aggregate = true;
            }
            $zf_aggregator = new Aggregator();
            $tag = param('tag', ZF_HOMETAG);
            $feeds = $zf_aggregator->getFeedsForTag($tag, $aggregate, $trim = param('trim', 'auto'), int_param('onlynew', ZF_ONLYNEW == 'no' ? 0 : 1));
            zf_debugRuntime("before rendering");
            $view = zf_createView($outputType);
            $view->renderFeedList($feeds, array('groupbyday' => $groupbyday, 'summary' => int_param('sum', 1) == 1, 'tag' => $tag));
            break;
        case 'subs':
            //only JSON
            $subs = SubscriptionStorage::getInstance()->getSortedActiveSubscriptions(param('tag', ''));
            if (!headers_sent()) {
                header('Content-Type: application/json; charset=' . ZF_ENCODING);
            }
            echo json_encode($subs, JSON_FORCE_OBJECT);
            break;
        case 'tags':
            $tags = SubscriptionStorage::getInstance()->getTags();
            if (!headers_sent()) {
                header('Content-Type: application/json; charset=' . ZF_ENCODING);
            }
            echo json_encode($tags, JSON_FORCE_OBJECT);
            break;
        case 'force-refresh':
            // only internal use
            // TODO: check API key
            $sub = SubscriptionStorage::getInstance()->getSubscription(param('id'));
            FeedCache::getInstance()->updateSingle($sub->source);
            echo $sub->source->title . ' DONE. ';
            break;
        case 'refresh-all':
            $subs = SubscriptionStorage::getInstance()->getActiveSubscriptions(param('tag', ''));
            FeedCache::getInstance()->update($subs);
            echo ' DONE. ';
            break;
    }
}
Example #2
0
 protected function updateAllParallel($subscriptions)
 {
     zf_debugRuntime("before feeds parallel update");
     $urls = array();
     foreach ($subscriptions as $sub) {
         $url = ZF_URL . '/pub/index.php?q=force-refresh&id=' . $sub->source->id;
         $urls[] = $url;
     }
     // Request all feed items in parallel (if supported)
     $http = new HumbleHttpAgent();
     $http->userAgentDefault = HumbleHttpAgent::UA_PHP;
     zf_debug('fetching all ' . sizeof($urls) . ' feeds', DBG_FEED);
     $http->fetchAll($urls);
     foreach ($urls as $url) {
         zf_debug('going after ' . $url, DBG_FEED);
         if ($url && ($response = $http->get($url, true)) && ($response['status_code'] < 300 || $response['status_code'] > 400)) {
             $effective_url = $response['effective_url'];
             /*zf_debug('response: '. $response['body'], DBG_FEED);
             		if(DBG_FEED & ZF_DEBUG) var_dump($response);*/
         }
     }
     zf_debugRuntime("End of parallel update");
 }
Example #3
0
 public function printCredits()
 {
     if (!defined("ZF_SHOWCREDITS") || ZF_SHOWCREDITS != 'no') {
         echo ' <div id="generator">aggregated by <a href="http://www.cazalet.org/zebrafeeds">ZebraFeeds</a></div>';
     }
     zf_debugRuntime("after credits");
 }
Example #4
0
 public function getFeedsForTag($tag, $aggregate, $trim, $onlyNew)
 {
     $subs = SubscriptionStorage::getInstance()->getActiveSubscriptions($tag);
     zf_debugRuntime("before feeds update");
     zf_debug('processing ' . sizeof($subs) . ' subs for tag ' . $tag, DBG_AGGR);
     if (ZF_DEBUG & DBG_AGGR) {
         var_dump($subs);
     }
     $this->cache->update($subs, ZF_REFRESHMODE == 'automatic' ? 'auto' : 'none');
     $feeds = array();
     $params1 = array();
     if ($onlyNew == 1) {
         $params1['impressedSince'] = time() - ZF_SESSION_DURATION;
     }
     if ($aggregate) {
         if ($trim == 'auto') {
             $trim = ZF_TRIMSIZE . ZF_TRIMTYPE;
         }
         $params = array_merge($params1, $this->buildLimiterParam($trim));
         $feeds[] = $this->cache->getFeed($subs, $params);
     } else {
         // keeps feed separate (no aggregation): use individual subscription trim setting if auto is set
         foreach ($subs as $id => $sub) {
             if ($trim == 'auto') {
                 $trim = $sub->shownItems . 'news';
             }
             $params = array_merge($params1, $this->buildLimiterParam($trim));
             $feeds[] = $this->cache->getFeed($sub, $params);
         }
     }
     zf_debugRuntime("after feeds update and aggr");
     zf_debug('returning ' . sizeof($feeds) . ' feeds for tag ' . $tag, DBG_AGGR);
     return $feeds;
 }