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
Exemplo 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;
    }
}
Exemplo n.º 2
0
 function lmm_dashboard_widget()
 {
     global $wpdb;
     $lmm_options = get_option('leafletmapsmarker_options');
     $table_name_markers = $wpdb->prefix . 'leafletmapsmarker_markers';
     $widgets = get_option('dashboard_widget_options');
     $widget_id = 'lmm-admin-dashboard-widget';
     $number_of_markers = isset($widgets[$widget_id]) && isset($widgets[$widget_id]['items']) ? absint($widgets[$widget_id]['items']) : 4;
     $result = $wpdb->get_results($wpdb->prepare("SELECT `id`,`markername`,`icon`,`createdon`,`createdby` FROM `{$table_name_markers}` ORDER BY `createdon` desc LIMIT %d", $number_of_markers), ARRAY_A);
     echo '<p><a style="background:#f99755;display:block;padding:5px;text-decoration:none;color:#2702c6;text-align:center;" href="' . LEAFLET_WP_ADMIN_URL . 'admin.php?page=leafletmapsmarker_pro_upgrade">' . __('Upgrade to pro version for even more features - click here to find out how you can start a free 30-day-trial easily', 'lmm') . '</a><hr style="border:0;height:1px;background-color:#d8d8d8;"/></p>';
     if ($result != NULL) {
         echo '<table style="margin-bottom:5px;"><tr>';
         foreach ($result as $row) {
             $icon = $row['icon'] == NULL ? LEAFLET_PLUGIN_URL . 'leaflet-dist/images/marker.png' : LEAFLET_PLUGIN_ICONS_URL . '/' . $row['icon'];
             echo '<td><a href="' . LEAFLET_WP_ADMIN_URL . 'admin.php?page=leafletmapsmarker_marker&id=' . $row['id'] . '" title="' . esc_attr__('edit marker', 'lmm') . '"><img src="' . $icon . '" style="width:80%;"></a>';
             echo '<td style="vertical-align:top;line-height:1.2em;">';
             echo '<a href="' . LEAFLET_WP_ADMIN_URL . 'admin.php?page=leafletmapsmarker_marker&id=' . $row['id'] . '" title="' . esc_attr__('edit marker', 'lmm') . '">' . htmlspecialchars(stripslashes($row['markername'])) . '</a><br/>' . __('created on', 'lmm') . ' ' . date("Y-m-d - h:m", strtotime($row['createdon'])) . ', ' . __('created by', 'lmm') . ' ' . $row['createdby'];
             echo '</td></tr>';
         }
         echo '</table>';
     } else {
         echo '<p style="margin-bottom:5px;">' . __('No marker created yet', 'lmm') . '</p>';
     }
     if (!isset($widgets[$widget_id]['blogposts'])) {
         $show_rss = 1;
     } else {
         if (isset($widgets[$widget_id]['blogposts']) && $widgets[$widget_id]['blogposts'] == 1) {
             $show_rss = 0;
         } else {
             $show_rss = 1;
         }
     }
     //info: use custom name to prevent false malware detection by WordFence plugin
     function lmm_spc_custom_name($string)
     {
         return 'mapsmarker-dashboard-widget-rss-item-cache';
     }
     if ($show_rss == 1) {
         require_once ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'class-simplepie.php';
         $feed = new SimplePie();
         if (file_exists(LEAFLET_PLUGIN_ICONS_DIR . DIRECTORY_SEPARATOR . 'readme-icons.txt')) {
             $feed->enable_cache(true);
             $feed->set_cache_location($location = LEAFLET_PLUGIN_ICONS_DIR);
             $feed->set_cache_name_function('lmm_spc_custom_name');
             $feed->set_cache_duration(86400);
         } else {
             $feed->enable_cache(false);
         }
         $feed->set_feed_url('http://feeds.feedburner.com/MapsMarkerPro');
         $feed->set_stupidly_fast(true);
         $feed->enable_order_by_date(true);
         $feed->init();
         $feed->handle_content_type();
         echo '<hr style="border:0;height:1px;background-color:#d8d8d8;"/><strong><p>' . __('Latest blog posts from www.mapsmarker.com', 'lmm') . '</p></strong>';
         if ($feed->get_items() == NULL) {
             $blogpost_url = '<a href="https://www.mapsmarker.com/news" target="_blank">https://www.mapsmarker.com/news</a>';
             echo sprintf(__('Feed could not be retrieved, please try again later or read the latest blog posts at %s', 'lmm'), $blogpost_url);
         }
         foreach ($feed->get_items(0, 3) as $item) {
             echo '<p  style="margin:0.5em 0;">' . $item->get_date('j F Y') . ': <strong><a href="' . $item->get_permalink() . '?ref=dashboard">' . $item->get_title() . '</a></strong></p>' . PHP_EOL;
         }
         echo '<p><a style="text-decoration:none;" href="https://www.mapsmarker.com" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-website-home.png" width="16" height="16" alt="mapsmarker.com"> MapsMarker.com</a>&nbsp;<a href="' . LEAFLET_WP_ADMIN_URL . 'admin.php?page=leafletmapsmarker_pro_upgrade' . '"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-up16.png" width="16" height="16" alt="upgrade to pro"> ' . __('Upgrade to Pro', 'lmm') . '</a>&nbsp;<a style="text-decoration:none;" title="' . esc_attr__('MapsMarker affiliate program - sign up now and receive commissions up to 50%!', 'lmm') . '" href="https://www.mapsmarker.com/affiliates" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-affiliates.png" width="16" height="16" alt="affiliates"> ' . __('Affiliates', 'lmm') . '</a>&nbsp;<a style="text-decoration:none;" title="' . esc_attr__('MapsMarker reseller program - re-sell with a 20% discount!', 'lmm') . '" href="https://www.mapsmarker.com/reseller" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-resellers.png" width="16" height="16" alt="resellers"> ' . __('Resellers', 'lmm') . '</a>&nbsp;<a style="text-decoration:none;" href="https://www.mapsmarker.com/reviews" target="_blank" title="' . esc_attr__('please rate this plugin on wordpress.org', 'lmm') . '"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-star.png" width="16" height="16" alt="ratings"> ' . __('rate plugin', 'lmm') . '</a>&nbsp;<a href="https://translate.mapsmarker.com/projects/lmm" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-translations.png" width="16" height="16" alt="translations"> ' . __('translations', 'lmm') . '</a> <a href="https://twitter.com/mapsmarker" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-twitter.png" width="16" height="16" alt="twitter">&nbsp;Twitter</a>&nbsp;<a href="https://facebook.com/mapsmarker" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-facebook.png" width="16" height="16" alt="facebook"> Facebook</a>&nbsp;<a href="https://www.mapsmarker.com/+" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-google-plus.png" width="16" height="16" alt="google+"> Google+</a>&nbsp;<a style="text-decoration:none;" href="https://www.mapsmarker.com/changelog" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-changelog-header.png" width="16" height="16" alt="changelog"> ' . __('Changelog', 'lmm') . '</a>&nbsp;<a href="https://feeds.feedburner.com/MapsMarker" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-rss.png" width="16" height="16" alt="rss"> RSS</a>&nbsp;<a href="http://feedburner.google.com/fb/a/mailverify?uri=MapsMarker" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-rss-email.png" width="16" height="16" alt="rss-email"> ' . __('E-Mail', 'lmm') . '</a></p>';
     }
 }
Exemplo n.º 3
0
 static function fetchRSS($params, $force = 0)
 {
     $type = $params->get('type', '');
     $rssurl = $params->get('rss_url', '');
     $twitter_timeline = $params->get('twitter_timeline', 'user');
     $twitter_keyword = $params->get('twitter_keyword', '');
     if ($type == 'twitter' && $twitter_timeline == 'search') {
         $rssurl = 'http://search.twitter.com/search.atom?q=' . urlencode($twitter_keyword);
     }
     $items_limit = intval($params->get('items_limit', 10));
     $rss_image_only = intval($params->get('rss_image_only', 0));
     $doCache = intval($params->get('scr_cache', 1));
     $CacheTime = intval($params->get('cache_time', 3600));
     $feed_desc = 1;
     $item_desc = 1;
     $cacheDir = JPATH_BASE . DS . 'cache' . DS;
     $feed_array = array();
     $feed_array[0] = '';
     jimport('simplepie.simplepie');
     $simplepie = new SimplePie();
     // check if cache directory is writeable
     if (!is_writable($cacheDir) || !$doCache) {
         $simplepie->enable_cache(false);
     } else {
         // delete the cache file if fetch forced
         $cache_file = $cacheDir . md5($rssurl) . '.spc';
         if ($force && file_exists($cache_file)) {
             // delete the cache, force the new fetch
             @unlink($cache_file);
         }
         $simplepie->set_cache_name_function('md5');
         $simplepie->set_cache_location($cacheDir);
         $simplepie->set_cache_duration($CacheTime);
     }
     $simplepie->set_feed_url($rssurl);
     $simplepie->init();
     $simplepie->handle_content_type();
     if ($simplepie->data) {
         $rssDoc = $simplepie;
     } else {
         return 'Error: Feed not retrieved';
     }
     //$feed_array[0]['feed_title'] = @$rssDoc->get_title();
     //$feed_array[0]['feed_link'] = @$rssDoc->get_link();
     //$feed_array[0]['feed_desc'] = @$rssDoc->get_description();
     // items
     $feed_items = @$rssDoc->get_items();
     if (empty($feed_items)) {
         return 'Error: No items fetched';
     }
     if ($rss_image_only) {
         // filter only feeds that contain image
         $temp_array = array();
         foreach ($feed_items as $item) {
             $description = @$item->get_description();
             if ($description && stristr($description, 'img src')) {
                 $temp_array[] = $item;
             }
         }
         $feed_items = $temp_array;
     }
     if ($items_limit > 0) {
         $feed_items = array_slice($feed_items, 0, $items_limit);
     }
     foreach ($feed_items as $j => $item) {
         if (!is_null(@$item->get_link())) {
             $feed_array[0][$j]['item_href'] = $item->get_link();
         }
         if (!is_null(@$item->get_title())) {
             $feed_array[0][$j]['item_title'] = @$item->get_title();
         }
         if (!is_null(@$item->get_date())) {
             $feed_array[0][$j]['item_date'] = @$item->get_date();
         }
         if (@$item->get_description()) {
             $feed_array[0][$j]['item_desc'] = @$item->get_description();
             $feed_array[0][$j]['item_desc'] = str_replace('&apos;', "'", $feed_array[0][$j]['item_desc']);
         }
         // Twitter search
         if (preg_match('/^tag:search.twitter.com/', @$item->get_id())) {
             $user_profile_image_url = @$item->get_link(0, 'image');
             $user_screen_name = '';
             if (@$item->get_author()) {
                 $author = @$item->get_author();
                 if (isset($author->name)) {
                     $author = $author->name;
                     if (!empty($author) && stristr($author, ' ')) {
                         $author = explode(' ', $author);
                         $author = $author[0];
                         $user_screen_name = $author;
                     }
                 }
             }
             // Replace title
             $feed_array[0][$j]['item_title'] = $user_screen_name;
             // Replace text
             $text = $feed_array[0][$j]['item_desc'];
             $created_at = $feed_array[0][$j]['item_date'];
             $source = @$item->get_item_tags('http://api.twitter.com/', 'source');
             $source = @$item->sanitize($source[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
             $feed_array[0][$j]['item_desc'] = modAjaxScrollerCommonHelper::ajax_scroller_format_twitter($text, $params, $user_profile_image_url, $user_screen_name, $created_at, $source);
         }
     }
     //echo '<pre>'; print_r($feed_array[0]); die;
     return $feed_array[0];
 }