SimplePie::set_cache_name_function PHP Method

set_cache_name_function() public method

Set callback function to create cache filename with
public set_cache_name_function ( mixed $function = 'md5' )
$function mixed Callback function
    public function set_cache_name_function($function = 'md5')
    {
        if (is_callable($function)) {
            $this->cache_name_function = $function;
        }
    }

Usage Example

Ejemplo n.º 1
0
function repress_blog($feed_url)
{
    $output = array();
    $output[snippet] = '';
    $output[title] = '';
    $output[link] = '';
    if (filter_var($feed_url, FILTER_VALIDATE_URL)) {
        /* Check in cache if we've collected the latest post from this blog within past 24 hours */
        $cache_file = repressed_cache_dirname() . '/' . repressed_cache_filename($feed_url);
        /* Cache the whole RSS to a file if the file isn't there, or if it's older than 24 hours */
        $expire_seconds = 86400;
        $expire_date = time() + $expire_seconds;
        $max = 3;
        /* Number of posts to collect from each feed */
        $feed = new SimplePie();
        $feed->set_feed_url($feed_url);
        $feed->set_cache_name_function('repressed_cache_filename');
        $feed->enable_order_by_date(true);
        $feed->set_cache_duration($expire_seconds);
        $feed->set_cache_location(repressed_cache_dirname());
        $feed->enable_cache(true);
        $feed->set_timeout(3);
        $feed->set_item_limit($max);
        $feed->init();
        $post_title = array();
        $post_link = array();
        $post_snip = array();
        $post_date = array();
        $snip_words = 15;
        /* Length of snippet in words */
        foreach ($feed->get_items() as $item) {
            array_push($post_title, $item->get_title());
            array_push($post_link, $item->get_link());
            $snip = substr(strip_tags($item->get_content()), 0, 500);
            $snip = implode(" ", array_slice(explode(" ", $snip), 0, $snip_words));
            $snip = preg_replace('/\\s*$/', '...', $snip);
            array_push($post_snip, $snip);
        }
        $output[title] = $post_title[0];
        $output[link] = $post_link[0];
        $output[snippet] = $post_snip[0];
        return $output;
    } else {
        return FALSE;
    }
}
All Usage Examples Of SimplePie::set_cache_name_function