/** * duplicate all links for a given anchor * * This function duplicates records in the database, and changes anchors * to attach new records as per second parameter. * * @param string the source anchor * @param string the target anchor * @return int the number of duplicated records * * @see shared/anchors.php */ public static function duplicate_for_anchor($anchor_from, $anchor_to) { global $context; // look for records attached to this anchor $count = 0; $query = "SELECT * FROM " . SQL::table_name('links') . " WHERE anchor LIKE '" . SQL::escape($anchor_from) . "'"; if (($result = SQL::query($query)) && SQL::count($result)) { // process all matching records one at a time while ($item = SQL::fetch($result)) { // a new id will be allocated $old_id = $item['id']; unset($item['id']); // target anchor $item['anchor'] = $anchor_to; // actual duplication if ($item['id'] = Links::post($item)) { // duplicate elements related to this item Anchors::duplicate_related_to('link:' . $old_id, 'link:' . $item['id']); // stats $count++; } } } // number of duplicated records return $count; }
$_REQUEST['link_url'] = preg_replace($from, $to, $_REQUEST['link_url']); } // an anchor is mandatory if (!is_object($anchor)) { Logger::error(i18n::s('No anchor has been found.')); $item = $_REQUEST; $with_form = TRUE; // stop robots } elseif (Surfer::may_be_a_robot()) { Logger::error(i18n::s('Please prove you are not a robot.')); $item = $_REQUEST; $with_form = TRUE; // reward the poster for new posts } elseif (!isset($item['id'])) { // display the form on error if (!($_REQUEST['id'] = Links::post($_REQUEST))) { $item = $_REQUEST; $with_form = TRUE; // follow-up } else { // touch the related anchor $anchor->touch('link:create', $_REQUEST['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y'); // clear cache Links::clear($_REQUEST); // increment the post counter of the surfer Users::increment_posts(Surfer::get_id()); // thanks $context['page_title'] = i18n::s('Thank you for your contribution'); // the action $context['text'] .= '<p>' . i18n::s('The link has been successfully recorded.') . '</p>'; // list persons that have been notified
$fields['title'] = $matches[1]; } elseif (preg_match("/<title>(.*)<\\/title>/i", $content, $matches)) { $fields['title'] = $matches[1]; } // try to extract some text around the link $extract = strip_tags(substr($content, max(0, $position - 70), 210), '<a><b><i>'); if (preg_match('/[^<]*>(.*)$/', $extract, $matches)) { $extract = $matches[1]; } if ($extract) { $fields['description'] = '...' . $extract . '...'; } // save in the database $fields['anchor'] = $anchor; $fields['link_url'] = $source; if (!($fields['id'] = Links::post($fields))) { $response = 0; } else { $response = 'Thanks for the ping'; Links::clear($fields); } } } break; // ping an external reference to some page on this site // ping an external reference to some page on this site case 'weblogUpdates.ping': list($label, $url) = $parameters['params']; // caller has been banned if ($_SERVER['REMOTE_HOST'] && ($server = Servers::get($_SERVER['REMOTE_HOST']) && $server['process_ping'] != 'Y')) { $response = array('flerror' => 49, 'message' => 'Access denied');
/** * get news from remote servers * * This function queries remote sources and populate the table of links based on fetched news. * * On tick, the including hook calls [code]Feeds::tick_hook()[/code]. * See [script]control/scan.php[/script] for a more complete description of hooks. * * The function browses the database to locate servers acting as feeders, and read the URLs to use. * * A round-robin algorithm is implemented, meaning that servers are polled in sequence throughout successive ticks. * At most 1 feed is parsed on each tick, to limit impact when the "poor-man" cron mechanism is used, * which is the default setting. * * XML feeds are fetched and parsed according to their type. * At the moment YACS is able to process RSS and slashdot feeds. * Link records are created or updated in the database saving as much of possible of provided data. * Item data is reflected in Link, Title, and Description fields. * Channel data is used to populate the Source field. * Stamping information is based on feeding date, and channel title. * Also, the edit action 'link:feed' marks links that are collected from feeders. * The anchor field is set to the category assigned in the server profile. * * At the end of the feeding process, the database is purged from oldest links according to the limit * defined in parameters/feeds.include.php, set through feeds/configure.php. * See Links::purge_old_news(). * * @param boolean if set to true, fetch news on each call; else use normal period of time * @return a string to be displayed in resulting page, if any * * @see control/scan.php * @see feeds/configure.php */ public static function tick_hook($forced = FALSE) { global $context; // load librairies only once include_once $context['path_to_root'] . 'links/links.php'; include_once $context['path_to_root'] . 'servers/servers.php'; include_once $context['path_to_root'] . 'shared/values.php'; // feeds.tick // get feeding parameters Safe::load('parameters/feeds.include.php'); // delay between feeds - minimum is 5 minutes if (!isset($context['minutes_between_feeds']) || $context['minutes_between_feeds'] < 5) { $context['minutes_between_feeds'] = 5; } // do not wait for the end of a feeding cycle if ($forced) { $threshold = gmstrftime('%Y-%m-%d %H:%M:%S'); } else { $threshold = gmstrftime('%Y-%m-%d %H:%M:%S', time() - $context['minutes_between_feeds'] * 60); } // get a batch of feeders if (!($feeders = Servers::list_for_feed(0, 1, 'feed'))) { return 'feeds/feeds.php: no feed has been defined' . BR; } // remember start time $start_time = get_micro_time(); // list banned tokens $banned_pattern = Servers::get_banned_pattern(); // browse each feed $count = 0; foreach ($feeders as $server_id => $attributes) { // get specific feed parameters list($feed_url, $feed_title, $anchor, $stamp) = $attributes; // skip servers processed recently if ($stamp > $threshold) { continue; } // flag this record to enable round-robin even on error Servers::stamp($server_id); // fetch news from the provided link if (!($news = Feeds::get_remote_news_from($feed_url)) || !is_array($news)) { continue; } // no anchor has been defined for this feed if (!$anchor) { // create a default section if necessary if (!($anchor = Sections::lookup('external_news'))) { $fields = array(); $fields['nick_name'] = 'external_news'; $fields['create_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', time()); $fields['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', time()); $fields['index_map'] = 'N'; $fields['locked'] = 'Y'; // no direct contributions $fields['rank'] = 40000; // at the end of the list $fields['title'] = i18n::c('External News'); $fields['description'] = i18n::c('Received from feeding servers'); if (!($fields['id'] = Sections::post($fields))) { Logger::remember('feeds/feeds.php: Impossible to add a section.'); return; } $anchor = 'section:' . $fields['id']; } } // process retrieved links $links = 0; foreach ($news as $item) { // link has to be valid if (!isset($item['link']) || !($item['title'] . $item['description'])) { if (isset($context['debug_feeds']) && $context['debug_feeds'] == 'Y') { Logger::remember('feeds/feeds.php: feed item is invalid', $item, 'debug'); } continue; } // skip banned servers if ($banned_pattern && preg_match($banned_pattern, $item['link'])) { if (isset($context['debug_feeds']) && $context['debug_feeds'] == 'Y') { Logger::remember('feeds/feeds.php: feed host has been banned', $item['link'], 'debug'); } continue; } // one link processed $links++; // link description $fields = array(); $fields['anchor'] = $anchor; $fields['link_url'] = $item['link']; $fields['title'] = $item['title']; $fields['description'] = $item['description']; if ($item['category']) { $fields['description'] .= ' (' . $item['category'] . ')'; } $fields['edit_name'] = $feed_title; $fields['edit_address'] = $feed_url; $fields['edit_action'] = 'link:feed'; if ($item['pubDate']) { $fields['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', strtotime($item['pubDate'])); } // update links that already exist in the database if (Links::have($item['link'], $anchor, $fields)) { continue; } // save link in the database if (!Links::post($fields)) { Logger::remember('feeds/feeds.php: Impossible to save feed link: ' . Logger::error_pop()); } } // one feed has been processed $count += 1; // remember tick date Values::set('feeds.tick.' . $feed_url, $links); } // cap the number of links used for news if (!isset($context['maximum_news']) || !$context['maximum_news']) { $context['maximum_news'] = 1000; } if ($context['maximum_news'] > 10) { include_once $context['path_to_root'] . 'links/links.php'; Links::purge_old_news($context['maximum_news']); } // compute execution time $time = round(get_micro_time() - $start_time, 2); // report on work achieved if ($count > 1) { return 'feeds/feeds.php: ' . $count . ' feeds have been processed (' . $time . ' seconds)' . BR; } elseif ($count == 1) { return 'feeds/feeds.php: 1 feed has been processed (' . $time . ' seconds)' . BR; } else { return 'feeds/feeds.php: nothing to do (' . $time . ' seconds)' . BR; } }