/** * Process a single feed * * @param array $feed Feed information (required elements are 'name' for error reporting, 'feed' for the feed URL and 'id' for the feed's unique internal ID) * @return int Number of items added */ public static function process_single($feed) { do_action('iu-feed-start', $feed); $sp =& self::load_feed($feed); if ($error = $sp->error()) { self::log(sprintf(_r('An error occurred with "%2$s": %1$s'), $error, $feed['name']), Errors::get_code('api.itemupdater.itemerror')); do_action('iu-feed-finish', $feed); return -1; } $count = 0; $items = $sp->get_items(); foreach ($items as $item) { $new_item = self::normalise($item, $feed['id']); $new_item = apply_filters('item_data_precache', $new_item, $feed); if (Items::get_instance()->check_item($new_item)) { $count++; do_action('iu-item-add', $new_item, $feed); } else { do_action('iu-item-noadd', $new_item, $feed); } } $sp->__destruct(); unset($sp); do_action('iu-feed-finish', $feed); return $count; }
public static function process() { header('Content-Type: text/plain; charset=utf-8'); require_once LILINA_INCPATH . '/contrib/simplepie.class.php'; $updated = false; foreach (self::$feeds as $feed) { do_action('iu-feed-start', $feed); $sp = self::load_feed($feed); if ($error = $sp->error()) { self::log(sprintf(_r('An error occurred with "%2$s": %1$s'), $error, $feed['name']), Errors::get_code('api.itemupdater.itemerror')); continue; } $count = 0; $items = $sp->get_items(); foreach ($items as $item) { $new_item = self::normalise($item, $feed['id']); $new_item = apply_filters('item_data_precache', $new_item); if (Items::get_instance()->check_item($new_item)) { $count++; $updated = true; } } do_action('iu-feed-finish', $feed); } Items::get_instance()->sort_all(); if ($updated) { Items::get_instance()->save_cache(); } }
function instapaper_submit() { $id = $_GET['id']; $item = Items::get_instance()->get_item($id); if (false === $item) { throw new Exception(_r('Invalid item ID specified', 'instapaper')); } $user = get_option('instapaper_user'); if (empty($user)) { throw new Exception(sprintf(_r('Please set your username and password in the <a href="%s">settings</a>.', 'instapaper'), get_option('baseurl') . 'admin/settings.php')); } if (!check_nonce($_GET['_nonce'])) { throw new Exception(_r('Nonces did not match. Try again.', 'instapaper')); } $data = array('username' => get_option('instapaper_user', ''), 'password' => get_option('instapaper_pass', ''), 'url' => $item->permalink, 'title' => apply_filters('the_title', $item->title)); $request = new HTTPRequest('', 2); $response = $request->post("https://www.instapaper.com/api/add", array(), $data); switch ($response->status_code) { case 400: throw new Exception(_r('Internal error. Please report this.', 'instapaper')); case 403: throw new Exception(sprintf(_r('Invalid username/password. Please check your details in the <a href="%s">settings</a>.', 'instapaper'), get_option('baseurl') . 'admin/settings.php')); case 500: throw new Exception(_r('An error occurred when contacting Instapaper. Please try again later.', 'instapaper')); } instapaper_page_head(); ?> <div id="message"> <h1><?php _e('Success!'); ?> </h1> <p class="sidenote"><?php _e('Closing window in...', 'instapaper'); ?> </p> <p class="sidenote" id="counter">3</p> </div> <script> $(document).ready(function () { setInterval(countdown, 1000); }); function countdown() { if(timer > 0) { $('#counter').text(timer); timer--; } else { self.close(); } } var timer = 2; </script> <?php instapaper_page_foot(); die; }
public static function items_getList($start = 0, $limit = null) { $items = Items::get_instance()->retrieve(); if ($limit == null) { return $items; } return array_slice($items, $start, $limit, true); }
/** * Generates a SimplePie object from a list of feeds * * Takes an input array and parses it using the SimplePie library. Returns a SimplePie object. * @param array $input Deprecated * @return object SimplePie object with all feed's associated data */ function lilina_return_items($input = '', $conditions = array()) { foreach (Feeds::get_instance()->getAll() as $the_feed) { $feed_list[] = $the_feed['feed']; } $itemcache = Items::get_instance(); $itemcache->init(); $conditions = apply_filters('return_items-conditions', array('time' => time() - 86400)); $itemcache->set_conditions($conditions); $itemcache->filter(); return apply_filters('return_items', $itemcache); }
/** * HTTP header handler * * Handles the output of all default headers, but can be changed via the * `template-headers` filter. * * Also controls working with If-None-Match/If-Modified-Since */ public static function headers() { // Basic default headers $headers = array('Content-Type' => 'text/html; charset=utf-8'); // Last-Modified and ETag $itemcache = Items::get_instance(); $itemcache->init(); $items = $itemcache->retrieve(); if (is_array($items)) { $item = reset($items); } if ($item !== false) { $last_modified_timestamp = $item->timestamp; } else { $last_modified_timestamp = time(); } $last_modified = date('D, d M Y H:i:s', $last_modified_timestamp); $headers['Last-Modified'] = $last_modified . ' GMT'; $headers['ETag'] = '"' . md5($last_modified) . '"'; // Do the header dance $headers = apply_filters('template-headers', $headers); foreach ($headers as $name => $value) { header($name . ': ' . $value); } // Conditional GET if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); } else { $client_etag = false; } $client_modified = !empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false; $protocol = $_SERVER["SERVER_PROTOCOL"]; if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol) { $protocol = 'HTTP/1.0'; } if ($client_modified !== false && $client_etag !== false) { if ($client_modified >= $last_modified_timestamp && $client_etag == $headers['ETag']) { header($protocol . ' 304 Not Modified'); die; } } elseif ($client_modified >= $last_modified_timestamp || $client_etag == $headers['ETag']) { header($protocol . ' 304 Not Modified'); die; } }
/** * @todo Document * @return boolean Are items available? */ function has_items() { global $lilina_items; if (count(Feeds::get_instance()->getAll()) === 0) { return false; } if (empty($lilina_items)) { foreach (Feeds::get_instance()->getAll() as $the_feed) { $feed_list[] = $the_feed['feed']; } $lilina_items = Items::get_instance(); $lilina_items->init(); $conditions = apply_filters('return_items-conditions', array('time' => time() - get_offset())); $lilina_items->set_conditions($conditions); $lilina_items->filter(); } return $lilina_items->has_items(); }
?> </h1> <?php if (count(Feeds::get_instance()->getAll()) === 0) { ?> <p><?php _e("Firstly, thanks for using Lilina! To help you settle in, we've included a few nifty tools in Lilina, just to help you get started."); ?> </p> <?php } else { $updated = get_option('last_updated'); if (!$updated) { $message = sprintf(_r('You currently have %d items in %d feeds. Never updated.', count(Items::get_instance()->get_items()), count(Feeds::get_instance()->getAll()))); } else { $message = sprintf(_r('You currently have %d items in %d feeds. Last updated %s.'), count(Items::get_instance()->get_items()), count(Feeds::get_instance()->getAll()), relative_time($updated)); } ?> <p><?php echo $message; ?> </p> <?php } ?> <h2><?php _e('Import'); ?> </h2> <p><?php _e("We can import from any service which supports an open standard called OPML. Here's some services you can import from:");