public function confirm() { if ($this->isPOST()) { return $this->setAction('subscribe'); } $feeds = array(); $url = $this->params('feedlink'); $feedlinks = FeedUtils::getFeedlinks($url); foreach ($feedlinks as $feedlink) { $feed = $this->Feed->findByFeedlink($feedlink); if ($feed) { $sub = $this->member->subscribed($feed['Feed']['id']); if ($sub) { $feed['subscribe_id'] = $sub['Subscription']['id']; } $feeds[] = $feed; continue; } $feeddata = FeedUtils::getFeed($feedlink); if (!$feeddata) { continue; } $feeds[] = array('Feed' => array('id' => 0, 'subscribers_count' => 0, 'feedlink' => $feedlink, 'link' => $feeddata->get_permalink(), 'title' => $feeddata->get_title())); } if (empty($feeds)) { $this->Flash->notice('please check URL'); $this->redirect('/subscribe/index'); } $this->set('feeds', $feeds); $this->set('feedlink', $feedlink); }
function find_with_content_category_by_account($account) { $db =& DBUtils::connect(); $sql = 'SELECT cc.id AS category_id, cc.name AS category_name, mcf.feed_id FROM member_to_content_category_to_feed mcf JOIN member m ON mcf.member_id = m.id JOIN content_category cc ON mcf.content_category_id = cc.id WHERE m.account = ?'; $result = $db->getAll($sql, array($account)); if (DB::isError($result)) { trigger_error(__CLASS__ . '::' . __FUNCTION__ . '(): ' . $result->toString(), E_USER_ERROR); return false; } $mcfs = $result; $other = ContentCategoryUtils::get(PLNET_OTHER_CATEGORY_ID); $feeds = FeedUtils::get_feeds_by_account($account); $feeds_with_category = array(); foreach ($feeds as $key => $feed) { foreach ($mcfs as $i => $mcf) { if ($feed['id'] == $mcf['feed_id']) { $feed['category_id'] = $mcf['category_id']; $feed['category_name'] = $mcf['category_name']; } } if (!isset($feed['category_id'])) { $feed['category_id'] = $other['id']; $feed['category_name'] = $other['name']; } $feeds_with_category[] = $feed; } return $feeds_with_category; }
public function discover() { $url = $this->params('url'); $feeds = array(); $feedlinks = FeedUtils::getFeedlinks($url); if (!$feedlinks) { $this->renderJSON(json_encode($feeds)); return; } foreach ($feedlinks as $feedlink) { $feed = $this->Feed->findByFeedlink($feedlink); if ($feed) { $result = array('subscribers_count' => $feed['Feed']['subscribers_count'], 'feedlink' => $feed['Feed']['feedlink'], 'link' => $feed['Feed']['link'], 'title' => $feed['Feed']['title']); $conditions = array(); $conditions[] = es('Subscription.member_id = %s', $this->member->id); $conditions[] = es('Subscription.feed_id = %s', $feed['Feed']['id']); $sub = $this->Subscription->find($conditions); if ($sub) { $result['subscribe_id'] = $sub['Subscription']['id']; } $feeds[] = $result; } else { $feeddata = FeedUtils::getFeed($feedlink); if (!$feeddata) { continue; } $feeds[] = array('subscribers_count' => 0, 'feedlink' => $feedlink, 'link' => $feeddata->get_permalink(), 'title' => $feeddata->get_title()); } } $this->renderJSON(json_encode($feeds)); }
/** * main() */ public function execute($par) { global $wgContLang, $wgFeedClasses, $wgLanguageCode, $wgMemc, $wgOut, $wgGNSMsmaxage; list($params, $categories, $notCategories) = $this->getParams(); // if there's an error parsing the params, bail out and return if (isset($params['error'])) { wfHttpError(500, 'Internal Server Error', $params['error']); return; } // Check to make sure that feed type is supported. if (FeedUtils::checkFeedOutput($params['feed'])) { $msg = wfMessage('feed-' . $params['feed'])->inContentLanguage(); if ($msg->exists()) { // This seems a little icky since // its re-using another message in a // different context. // uses feed-rss and feed-atom messages. $feedType = $msg->text(); } else { $feedType = $wgContLang->uc($params['feed']); } $feed = new $wgFeedClasses[$params['feed']](wfMsgExt('googlenewssitemap_feedtitle', array('parsemag', 'content'), $wgContLang->getLanguageName($wgLanguageCode), $feedType, $wgLanguageCode), wfMsgExt('tagline', array('parsemag', 'content')), Title::newMainPage()->getFullURL()); } else { // FeedUtils outputs an error if wrong feed type. // So nothing else to do at this point return; } $wgOut->setSquidMaxage($wgGNSMsmaxage); $cacheInvalidationInfo = $this->getCacheInvalidationInfo($params, $categories, $notCategories); $cacheKey = $this->getCacheKey($params, $categories, $notCategories); // The way this does caching is based on ChangesFeed::execute. $cached = $this->getCachedVersion($cacheKey, $cacheInvalidationInfo); if ($cached !== false) { $feed->httpHeaders(); echo $cached; echo "<!-- From cache: {$cacheKey} -->"; } else { wfProfileIn(__METHOD__ . '-not-cached'); $res = $this->getCategories($params, $categories, $notCategories); ob_start(); $this->makeFeed($feed, $res); $output = ob_get_contents(); ob_end_flush(); echo "<!-- Not cached. Saved as: {$cacheKey} -->"; $wgMemc->set($cacheKey, array($cacheInvalidationInfo, $output), $this->maxCacheTime); wfProfileOut(__METHOD__ . '-not-cached'); } }
function execute(&$controller, &$request, &$user) { $cc_name = $request->getAttribute('cc_name'); $title = sprintf(msg('user list of this content category service'), msg($cc_name)); $ms = MemberUtils::get_list_by_content_category_name($cc_name); foreach ((array) $ms as $member) { if ($member['show_profile']) { $feeds = FeedUtils::get_feeds_by_account($member['account']); $m = array('account' => $member['account'], 'profile_icon' => $member['photo'] ? SCRIPT_PATH . "photo.php?member_id={$member['id']}" : SCRIPT_PATH . 'images/profile_icon.jpg', 'self_introduction' => $member['self_introduction'], 'feeds' => $feeds); $members[] = $m; } } $request->setAttribute('title', $title); $request->setAttribute('pager', ActionUtils::pager($members, 50)); return VIEW_SUCCESS; }
function execute(&$controller, &$request, &$user) { $account = $request->getParameter('account'); $urls = array(); $last_update = EntryUtils::get_last_update($account); $last_update = $last_update > 0 ? $last_update : time(); // top $urls[] = array('loc' => SCRIPT_PATH . $account . '/', 'lastmod' => $last_update, 'changefreq' => PLNET_SITEMAP_TOP_FREQ, 'priority' => PLNET_SITEMAP_TOP_PRIORITY); // archive $archives = EntryUtils::get_archives_by_account($account); foreach ($archives as $archive) { $last_update = EntryUtils::get_last_update_by_account_and_year_month($account, $archive['y'], $archive['m']); $last_update = $last_update > 0 ? $last_update : time(); $urls[] = array('loc' => SCRIPT_PATH . "{$account}/{$archive['y']}/{$archive['m']}/", 'lastmod' => $last_update, 'changefreq' => PLNET_SITEMAP_ARCHIVE_FREQ, 'priority' => PLNET_SITEMAP_ARCHIVE_PRIORITY); } /* // tag $tags = TagUtils::get_tags_by_account($account); foreach ($tags as $tag) { $last_update = EntryUtils::get_last_update_by_account_and_tagname($account, $tag['id']); $last_update = $last_update > 0 ? $last_update : time(); $urls[] = array( 'loc' => SCRIPT_PATH . "{$account}/tag/{$tag['name']}/", 'lastmod' => $last_update, 'changefreq' => PLNET_SITEMAP_TAG_FREQ, 'priority' => PLNET_SITEMAP_TAG_PRIORITY ); } */ // source $sources = FeedUtils::get_feeds_by_account($account); foreach ($sources as $source) { $last_update = EntryUtils::get_last_update_by_account_feed_id($account, $source['id']); $last_update = $last_update > 0 ? $last_update : time(); $urls[] = array('loc' => SCRIPT_PATH . $account . '/source/' . $source['id'], 'lastmod' => $last_update, 'changefreq' => PLNET_SITEMAP_SOURCE_FREQ, 'priority' => PLNET_SITEMAP_SOURCE_PRIORITY); } // individual $entries = EntryUtils::get_entries_by_account($account); foreach ($entries as $entry) { $last_update = $entry['lastupdatedtime']; $last_update = $last_update > 0 ? $last_update : time(); $urls[] = array('loc' => SCRIPT_PATH . "{$account}/{$entry['id']}", 'lastmod' => $last_update, 'changefreq' => PLNET_SITEMAP_INDIVIDUAL_FREQ, 'priority' => PLNET_SITEMAP_INDIVIDUAL_PRIORITY); } $request->setAttribute('urls', $urls); return VIEW_SUCCESS; }
function execute(&$controller, &$request, &$user) { $entry_id = $request->hasParameter('entry_id') ? $request->getParameter('entry_id') : null; $request->setAttribute('entry_id', $entry_id); $page = $request->hasParameter('page') ? $request->getParameter('page') : ''; $request->setAttribute('page', $page); $display = $request->hasParameter('display') ? $request->getParameter('display') : null; $request->setAttribute('display', $display); $tag = $request->hasParameter('tag') ? $request->getParameter('tag') : false; $request->setAttribute('tag', $tag); $source_id = $request->hasParameter('source_id') ? $request->getParameter('source_id') : null; $request->setAttribute('source_id', $source_id); if ($source_id) { $feed = FeedUtils::get_feed_by_id($source_id); $request->setAttribute('feed_title', $feed['title']); } $member = DB_DataObject::factory('member'); $member->account = $request->getParameter('account'); if ($member->count() === 0) { Controller::redirect('404.html'); } $member = DB_DataObject::factory('member'); $member->get('account', $request->getParameter('account')); $request->setAttribute('member', $member); $request->setAttribute('account', $member->account); // entry check $entry = DB_DataObject::factory('entry'); if (!$entry->entryIsExistsByMemberId($member->id)) { return VIEW_ERROR; } // design $design = DB_DataObject::factory('design'); $design->get('id', $member->design_id); $request->setAttribute('design', $design); // site $site = DB_DataObject::factory('site'); $site->get('member_id', $member->id); $request->setAttribute('site', $site); if ($display == 'profile' && !$site->show_profile) { $controller->redirect('/404.html'); return VIEW_NONE; } return VIEW_INDEX; }
function execute(&$controller, &$request, &$user) { $format = $request->hasParameter('format') ? $request->getParameter('format') : 'html'; $limit = $format != 'html' ? PLNET_FEED_NUMBER : null; $this->attrs['title'] = 'Plnet > ' . msg('plnet list'); $member = DB_DataObject::factory('member'); $sql = 'SELECT m.id, m.account, m.photo, UNIX_TIMESTAMP(m.createdtime) AS createdtime, s.title, s.description FROM member m JOIN site s ON m.id = s.member_id ORDER BY createdtime DESC'; if ($limit) { $sql .= " LIMIT {$limit}"; } $member->query($sql); $members = array(); while ($member->fetch()) { $feeds = FeedUtils::get_feeds_by_account($member->account); $m = array('account' => $member->account, 'profile_icon' => $member->photo ? SCRIPT_PATH . "photo.php?member_id={$member->id}" : SCRIPT_PATH . 'images/profile_icon.jpg', 'author' => $member->account, 'title' => $member->title, 'link' => SCRIPT_PATH . "{$member->account}/", 'date' => $member->createdtime, 'description' => $member->description, 'feeds' => $feeds); $members[] = $m; } $channel = array('title' => '新しいPlnet', 'link' => SCRIPT_PATH . 'list/', 'description' => '新しいPlnet'); switch ($format) { case 'rss10': $writer =& new FeedWriter(); $channel['uri'] = "{$channel['link']}rss"; $writer->setChannel($channel); $writer->setItems($members); $writer->display($format); return VIEW_NONE; case 'rss20': $writer =& new FeedWriter(); $channel['uri'] = "{$channel['link']}rss2"; $writer->setChannel($channel); $writer->setItems($members); $writer->display($format); return VIEW_NONE; case 'html': default: $request->setAttribute('pager', ActionUtils::pager($members, 50)); return VIEW_INDEX; } }
function execute(&$controller, &$request, &$user) { $account = $request->getParameter('account'); $request->setAttribute('account', $account); $feed_id = $request->getParameter('source_id'); $request->setAttribute('feed_id', $feed_id); $callback = $request->hasParameter('callback') ? $request->getParameter('callback') : false; $request->setAttribute('callback', $callback); $raw = $request->hasParameter('raw') ? true : false; $request->setAttribute('raw', $raw); $format = $request->hasParameter('format') ? $request->getParameter('format') : false; $request->setAttribute('format', $format); $feed = FeedUtils::get_feed_by_id($feed_id); $site = array('title' => $feed['title'], 'description' => $feed['description']); $request->setAttribute('feed', $feed); $entries = EntryUtils::get_entries_by_account_and_feed_id($account, $feed_id); foreach ($entries as $key => $entry) { $entry['src'] = $feed['uri']; $entry['uri'] = SCRIPT_PATH . "{$account}/source/{$entry['id']}"; $entries[$key] = $entry; } $request->setAttribute('entries', $entries); return VIEW_SUCCESS; }
/** * Generate the feed items given a row from the database. * @param object $rows DatabaseBase resource with recentchanges rows * @return array */ public static function buildItems($rows) { $items = []; # Merge adjacent edits by one user $sorted = []; $n = 0; foreach ($rows as $obj) { if ($obj->rc_type == RC_EXTERNAL) { continue; } if ($n > 0 && $obj->rc_type == RC_EDIT && $obj->rc_namespace >= 0 && $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id && $obj->rc_user_text == $sorted[$n - 1]->rc_user_text) { $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid; } else { $sorted[$n] = $obj; $n++; } } foreach ($sorted as $obj) { $title = Title::makeTitle($obj->rc_namespace, $obj->rc_title); $talkpage = MWNamespace::canTalk($obj->rc_namespace) ? $title->getTalkPage()->getFullURL() : ''; // Skip items with deleted content (avoids partially complete/inconsistent output) if ($obj->rc_deleted) { continue; } if ($obj->rc_this_oldid) { $url = $title->getFullURL(['diff' => $obj->rc_this_oldid, 'oldid' => $obj->rc_last_oldid]); } else { // log entry or something like that. $url = $title->getFullURL(); } $items[] = new FeedItem($title->getPrefixedText(), FeedUtils::formatDiff($obj), $url, $obj->rc_timestamp, $obj->rc_deleted & Revision::DELETED_USER ? wfMessage('rev-deleted-user')->escaped() : $obj->rc_user_text, $talkpage); } return $items; }
/** * Generate a FeedItem object from a given revision table row * Borrows Recent Changes' feed generation functions for formatting; * includes a diff to the previous revision (if any). * * @param stdClass|array $row Database row * @return FeedItem */ function feedItem($row) { $rev = new Revision($row); $rev->setTitle($this->getTitle()); $text = FeedUtils::formatDiffRow($this->getTitle(), $this->getTitle()->getPreviousRevisionID($rev->getId()), $rev->getId(), $rev->getTimestamp(), $rev->getComment()); if ($rev->getComment() == '') { global $wgContLang; $title = $this->msg('history-feed-item-nocomment', $rev->getUserText(), $wgContLang->timeanddate($rev->getTimestamp()), $wgContLang->date($rev->getTimestamp()), $wgContLang->time($rev->getTimestamp()))->inContentLanguage()->text(); } else { $title = $rev->getUserText() . $this->msg('colon-separator')->inContentLanguage()->text() . FeedItem::stripComment($rev->getComment()); } return new FeedItem($title, $text, $this->getTitle()->getFullURL('diff=' . $rev->getId() . '&oldid=prev'), $rev->getTimestamp(), $rev->getUserText(), $this->getTitle()->getTalkPage()->getFullURL()); }
return $counter; // Nothing to do. } if (!$self->options['feeds_enable']) { return $counter; // Nothing to do. } if (!$self->options['cache_clear_xml_feeds_enable']) { return $counter; // Nothing to do. } if (!is_dir($cache_dir = $self->cacheDir())) { return $counter; // Nothing to do. } $utils = new FeedUtils(); // Feed utilities. $variations = $variation_regex_frags = array(); // Initialize. switch ($type) { // Handle clearing based on the `$type`. case 'blog': // The blog feed; i.e. `/feed/` on most WP installs. $variations = array_merge($variations, $utils->feedLinkVariations()); break; // Break switch handler. // Break switch handler. case 'blog-comments': // The blog comments feed; i.e. `/comments/feed/` on most WP installs. $variations = array_merge($variations, $utils->feedLinkVariations('comments_')); break;
/** * Generate the feed items given a row from the database. * @param $rows DatabaseBase resource with recentchanges rows * @param $feed Feed object */ public static function generateFeed($rows, &$feed) { wfProfileIn(__METHOD__); $feed->outHeader(); # Merge adjacent edits by one user $sorted = array(); $n = 0; foreach ($rows as $obj) { if ($n > 0 && $obj->rc_namespace >= 0 && $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id && $obj->rc_user_text == $sorted[$n - 1]->rc_user_text) { $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid; } else { $sorted[$n] = $obj; $n++; } } foreach ($sorted as $obj) { $title = Title::makeTitle($obj->rc_namespace, $obj->rc_title); $talkpage = $title->getTalkPage(); // Skip items with deleted content (avoids partially complete/inconsistent output) if ($obj->rc_deleted) { continue; } $item = new FeedItem($title->getPrefixedText(), FeedUtils::formatDiff($obj), $obj->rc_this_oldid ? $title->getFullURL('diff=' . $obj->rc_this_oldid . '&oldid=prev') : $title->getFullURL(), $obj->rc_timestamp, $obj->rc_deleted & Revision::DELETED_USER ? wfMsgHtml('rev-deleted-user') : $obj->rc_user_text, $talkpage->getFullURL()); $feed->outItem($item); } $feed->outFooter(); wfProfileOut(__METHOD__); }
public function buildRssOwn() { global $wgSitename, $wgRequest; $user = $wgRequest->getInt('u', 0); $dbr = wfGetDB(DB_SLAVE); $tbl_rc = $dbr->tableName('recentchanges'); $res = $dbr->query("SELECT rc_id\n\t\t\t\t\t\tFROM {$tbl_rc}\n\t\t\t\t\t\tWHERE rc_user = {$user}\n\t\t\t\t\t\t AND rc_timestamp > '" . $dbr->timestamp(time() - intval(7 * 86400)) . "'"); $ids = array(); while ($row = $res->fetchObject()) { $ids[] = $row->rc_id; } if (count($ids)) { $res = $dbr->query("SELECT *\n\t\t\t\t\t\t\tFROM {$tbl_rc}\n\t\t\t\t\t\t\tWHERE rc_id IN (" . implode(',', $ids) . ")\n\t\t\t\t\t\t\t AND rc_timestamp > '" . $dbr->timestamp(time() - intval(7 * 86400)) . "'\n\t\t\t\t\t\t\tORDER BY rc_timestamp DESC"); } else { $res = false; } $channel = RSSCreator::createChannel(RSSCreator::xmlEncode($wgSitename . ' - ' . wfMessage('bs-rssstandards-title-own')->plain()), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], wfMessage('bs-rssstandards-desc-own')->plain()); if ($res) { while ($obj = $res->fetchObject()) { $title = Title::makeTitle($obj->rc_namespace, $obj->rc_title); $entry = RSSItemCreator::createItem(wfMessage('bs-rssstandards-changes-from', $obj->rc_user_text)->text(), $title->getFullURL('diff=' . $obj->rc_this_oldid . '&oldid=prev'), FeedUtils::formatDiff($obj)); $entry->setPubDate(wfTimestamp(TS_UNIX, $obj->rc_timestamp)); $channel->addItem($entry); } $dbr->freeResult($res); } return $channel->buildOutput(); }
/** * Generate the feed items given a row from the database. * @param $rows DatabaseBase resource with recentchanges rows * @param $feed Feed object */ public static function generateFeed($rows, &$feed) { wfProfileIn(__METHOD__); $feed->outHeader(); # Merge adjacent edits by one user $sorted = array(); $n = 0; foreach ($rows as $obj) { if ($n > 0 && $obj->rc_type == RC_EDIT && $obj->rc_namespace >= 0 && $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id && $obj->rc_user_text == $sorted[$n - 1]->rc_user_text) { $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid; } else { $sorted[$n] = $obj; $n++; } } foreach ($sorted as $obj) { $title = Title::makeTitle($obj->rc_namespace, $obj->rc_title); $talkpage = MWNamespace::canTalk($obj->rc_namespace) ? $title->getTalkPage()->getFullURL() : ''; // Skip items with deleted content (avoids partially complete/inconsistent output) if ($obj->rc_deleted) { continue; } if ($obj->rc_this_oldid) { $url = $title->getFullURL(array('diff' => $obj->rc_this_oldid, 'oldid' => $obj->rc_last_oldid)); } else { // log entry or something like that. $url = $title->getFullURL(); } $item = new FeedItem($title->getPrefixedText(), FeedUtils::formatDiff($obj), $url, $obj->rc_timestamp, $obj->rc_deleted & Revision::DELETED_USER ? wfMessage('rev-deleted-user')->escaped() : $obj->rc_user_text, $talkpage); $feed->outItem($item); } $feed->outFooter(); wfProfileOut(__METHOD__); }
protected function feedItem($row) { $title = Title::MakeTitle($row->page_namespace, $row->page_title); if ($title) { $date = $row->pending_since; $comments = $title->getTalkPage()->getFullURL(); $curRev = Revision::newFromTitle($title); return new FeedItem($title->getPrefixedText(), FeedUtils::formatDiffRow($title, $row->stable, $curRev->getId(), $row->pending_since, $curRev->getComment()), $title->getFullURL(), $date, $curRev->getUserText(), $comments); } else { return null; } }
function execute(&$controller, &$request, &$user) { $account = $request->getParameter('account'); $year = $request->hasParameter('year') ? $request->getParameter('year') : null; $month = $request->hasParameter('month') ? $request->getParameter('month') : null; $q = $request->hasParameter('q') ? $request->getParameter('q') : null; $tag = $request->hasParameter('tag') ? $request->getParameter('tag') : null; $source_id = $request->hasParameter('source_id') ? $request->getParameter('source_id') : null; $category_id = $request->hasParameter('category_id') ? $request->getParameter('category_id') : null; $format = $request->hasParameter('format') ? $request->getParameter('format') : 'html'; $page = $request->hasParameter('page') ? $request->getParameter('page') : 1; $per_page = $format == 'html' ? PLNET_ENTRIES_PER_PAGE : PLNET_FEED_NUMBER; $start = ($page - 1) * PLNET_ENTRIES_PER_PAGE; $channel = array(); $site = SiteUtils::get_by_account($account); $member = MemberUtils::get_by_account($account); switch (true) { case $year && $month: $t = "Archive: {$year}年{$month}月"; $channel['title'] = $site['title'] . " {$t}"; $channel['link'] = SCRIPT_PATH . "{$account}/{$year}/{$month}/"; $channel['description'] = $site['description']; $rss1 = "{$channel['link']}rss"; $request->setAttribute('entries_title', "{$t} <a href=\"{$rss1}\"><img class=\"favicon\" src=\"images/feed_icon.gif\" /></a>"); $entries = EntryUtils::get_entries_by_account_and_year_month($account, $year, $month, $per_page, $start); $entries_count = EntryUtils::get_entries_count_by_account_and_year_month($account, $year, $month); $path = "/{$account}/{$year}/{$month}/"; break; case $q: $t = "Search: {$q}"; $channel['title'] = $site['title'] . " {$t}"; $channel['link'] = SCRIPT_PATH . "{$account}/search/{$q}"; $channel['description'] = $site['description']; $rss1 = "{$channel['link']}rss"; $request->setAttribute('entries_title', $t . " <a href=\"{$rss1}\"><img class=\"favicon\" " . "src=\"images/feed_icon.gif\" /></a>"); $entries = EntryUtils::get_entries_by_account_and_query($account, $q, $per_page, $start); $entries_count = EntryUtils::get_entries_count_by_account_and_query($account, $q); $path = "/{$account}/search/{$q}"; break; case $tag: $t = "Tag: {$tag}"; $channel['title'] = $site['title'] . " {$t}"; $channel['link'] = SCRIPT_PATH . "{$account}/tag/{$tag}"; $channel['description'] = $site['description']; $rss1 = "{$channel['link']}rss"; $request->setAttribute('entries_title', "Tag: {$tag} <a href=\"{$SCRIPT_PATH}tag/{$tag}\" " . "title=\"Plnet Tag: {$tag}\">[all]</a> <a href=\"{$rss1}\">" . "<img class=\"favicon\" src=\"images/feed_icon.gif\" /></a> "); $entries = EntryUtils::get_entries_by_account_and_tagname($account, $tag, $per_page, $start); $entries_count = EntryUtils::get_entries_count_by_account_and_tagname($account, $tag); $path = "/{$account}/tag/{$tag}"; break; case $source_id: $feed = FeedUtils::get_feed_by_id($source_id); $t = "Source: {$feed['title']}"; $channel['title'] = $site['title'] . " {$t}"; $request->setAttribute('feed_title', $feed['title']); $channel['link'] = SCRIPT_PATH . "{$account}/source/{$source_id}/"; $channel['description'] = $site['description']; $rss1 = "{$channel['link']}rss"; $entries_title = "Source: <a href=\"{$feed['link']} \">" . "{$feed['title']}</a> <a href=\"{$rss1}\"><img class=\"favicon\" " . "src=\"images/feed_icon.gif\" /></a>"; $request->setAttribute('entries_title', $entries_title); $entries = EntryUtils::get_entries_by_account_feed_id($account, $source_id, $per_page, $start); $entries_count = EntryUtils::get_entries_count_by_account_feed_id($account, $source_id); $path = "/{$account}/source/{$source_id}"; break; case $category_id: $content_category = ContentCategoryUtils::get($category_id); $entries_title = msg('category') . ": " . msg($content_category['name']); $request->setAttribute('entries_title', $entries_title); $entries = EntryUtils::find_by_member_id_and_category_id($member['id'], $category_id, $per_page, $start); $entries_count = EntryUtils::find_count_by_member_id_and_category_id($member['id'], $category_id); $path = "/{$account}/category/{$category_id}"; break; default: $channel['title'] = $site['title']; $channel['link'] = SCRIPT_PATH . "{$account}/"; $channel['description'] = $site['description']; $entries = EntryUtils::get_entries_by_account($account, $per_page, $start); $entries_count = EntryUtils::get_entries_count_by_account($account); $path = "/{$account}/"; break; } // tags foreach ($entries as $key => $entry) { $entries[$key]['link'] = SCRIPT_PATH . "{$account}/{$entry['id']}"; $entries[$key]['formated_date'] = date(msg('entry date format'), $entry['date']); $tags = TagUtils::get_tags_by_entry_id($entry['id']); if (count($tags) > 0) { foreach ($tags as $tag) { $entries[$key]['tags'][] = $tag['name']; } } } switch ($format) { case 'rss10': $channel['uri'] = $channel['link'] . 'rss'; $writer =& new FeedWriter(); $writer->setChannel($channel); $writer->setItems($entries); $writer->display($format); return VIEW_NONE; case 'rss20': $channel['uri'] = $channel['link'] . 'rss2'; $writer =& new FeedWriter(); $writer->setChannel($channel); $writer->setItems($entries); $writer->display($format); return VIEW_NONE; case 'html': default: $request->setAttribute('entries', $entries); $request->setAttribute('pager', Utils::pager($page, $entries_count, $path)); return VIEW_SUCCESS; } }
public function subscribeFeed($feedlink, $options = array()) { if ($this->countSubscriptions() >= SUBSCRUBE_LIMIT) { $msg = sprintf('SUBSCRIBE LIMIT: %s(%s) %s', $this->data['Member']['username'], $this->id, $feedlink); CakeLog::write(LOG_WARNING, $msg); return false; } $Feed = new Feed(); $feed = $Feed->findByFeedlink($feedlink); if ($feed) { // subscribed.. $Feed->set($feed); } elseif (isset($options['quick'])) { $data = array('feedlink' => $feedlink, 'link' => $feedlink, 'title' => $options['title'], 'description' => ''); $Feed->set($data); $Feed->save(); $Feed->createCrawlStatus(); } else { $feeddata = FeedUtils::getFeed($feedlink); if (!$feeddata) { return false; } $data = array('subscribers_count' => 0, 'feedlink' => $feedlink, 'link' => $feeddata->get_permalink() ? $feeddata->get_permalink() : '', 'title' => $feeddata->get_title() ? $feeddata->get_title() : ''); $Feed->set($data); $Feed->save(); $Feed->createCrawlStatus(); } unset($options['quick']); unset($options['title']); $conditions = array(); $conditions[] = es('Subscription.member_id = %s', $this->id); $conditions[] = es('Subscription.feed_id = %s', $Feed->id); $sub = $this->Subscription->find($conditions); if ($sub) { return $sub; } $data = array('member_id' => $this->id, 'feed_id' => $Feed->id, 'has_unread' => true); $data = array_merge($data, $options); $this->Subscription->create($data); return $this->Subscription->save(); }
public function crawl($data) { $result = array('new_items' => 0, 'updated_items' => 0, 'error' => null); $feed = FeedUtils::getFeed($data['Feed']['feedlink']); if ($feed->error()) { $result['message'] = $feed->error(); $result['error'] = 1; return $result; } $items = $feed->get_items(); if (count($items) > self::ITEMS_LIMIT) { $this->log("too large feed: {$data['Feed']['feedlink']}" . '(' . count($items) . ')', LOG_INFO); array_splice($items, self::ITEMS_LIMIT); } // update items foreach ($items as $k => $item) { $r = array('Item' => array('feed_id' => $data['Feed']['id'], 'link' => $item->get_link(), 'title' => $item->get_title(), 'body' => $item->get_content(), 'author' => $item->get_author(), 'category' => $item->get_category(), 'enclosure' => null, 'enclosure_type' => null, 'digest' => $this->itemDigest($item->get_title(), $item->get_content()), 'stored_on' => date('Y-m-d H:i:s'), 'modified_on' => $item->get_date('Y-m-d H:i:s'))); $items[$k] = $r; } foreach ($items as $k => $item) { $conditions = array(); $conditions[] = es('Feed.id = %s', $data['Feed']['id']); $conditions[] = es('Item.title = %s', $item['Item']['title']); $conditions[] = es('Item.link = %s', $item['Item']['link']); $r = $this->Item->find($conditions); if ($r) { unset($items[$k]); } } foreach ($items as $k => $item) { $conditions = array(); $conditions[] = es('Feed.id = %s', $data['Feed']['id']); $conditions[] = es('Item.link = %s', $item['Item']['link']); $old_item = $this->Item->find($conditions); if ($old_item) { $same_title = $this->almostSame($old_item['Item']['title'], $item['Item']['title']); $same_body = $this->almostSame($old_item['Item']['body'], $item['Item']['body']); if (!$same_title || !$same_body) { $result['updated_items']++; } $item['Item'] = array_merge($old_item['Item'], $item['Item']); $this->Item->set($item); $this->Item->save(); } else { $result['new_items']++; $this->Item->create($item); $this->Item->save(); } } // update subscriptions if ($result['new_items'] + $result['updated_items'] > 0) { $data['Feed']['modified_on'] = date('Y-m-d H:i:s'); $conditions = array(); $conditions[] = es('Subscription.feed_id = %s', $data['Feed']['id']); $this->Subscription->updateAll(array('has_unread' => true), $conditions); } // update feed $new_feed = array('title' => $feed->get_title(), 'link' => $feed->get_link(), 'description' => $feed->get_description(), 'image' => null); $data['Feed'] = array_merge($data['Feed'], $new_feed); $this->Feed->set($data['Feed']); $this->Feed->save(); $result['message'] = "{$result['new_items']} new items, {$result['updated_items']} updated items"; return $result; }
/** * Execute the feed driver, generating the syndication feed and printing * the results. */ public function execute() { global $wgOut; if ( !$this->checkFeedOutput() ) return; $feed = $this->getFeedObject(); if ( !$feed ) { wfHttpError( 404, "Not found", "There is no such wikilog feed available from this site." ); return; } list( $timekey, $feedkey ) = $this->getCacheKeys(); FeedUtils::checkPurge( $timekey, $feedkey ); if ( $feed->isCacheable() ) { # Check if client cache is ok. if ( $wgOut->checkLastModified( $feed->getUpdated() ) ) { # Client cache is fresh. OutputPage takes care of sending # the appropriate headers, nothing else to do. return; } # Try to load the feed from our cache. $cached = $this->loadFromCache( $feed->getUpdated(), $timekey, $feedkey ); if ( is_string( $cached ) ) { wfDebug( __METHOD__ . ": Outputting cached feed\n" ); $feed->httpHeaders(); echo $cached; } else { wfDebug( __METHOD__ . ": rendering new feed and caching it\n" ); ob_start(); $this->printFeed( $feed ); $cached = ob_get_contents(); ob_end_flush(); $this->saveToCache( $cached, $timekey, $feedkey ); } } else { # This feed is not cacheable. $this->printFeed( $feed ); } }