Ejemplo n.º 1
0
 function ngfb_get_sharing_buttons($ids = array(), $atts = array())
 {
     global $ngfb;
     if ($ngfb->is_avail['ssb']) {
         if ($ngfb->is_avail['cache']['transient']) {
             $cache_salt = __METHOD__ . '(lang:' . SucomUtil::get_locale() . '_url:' . $ngfb->util->get_sharing_url() . '_ids:' . implode('_', $ids) . '_atts:' . implode('_', $atts) . ')';
             $cache_id = $ngfb->cf['lca'] . '_' . md5($cache_salt);
             $cache_type = 'object cache';
             $ngfb->debug->log($cache_type . ': transient salt ' . $cache_salt);
             $html = get_transient($cache_id);
             if ($html !== false) {
                 $ngfb->debug->log($cache_type . ': html retrieved from transient ' . $cache_id);
                 return $ngfb->debug->get_html() . $html;
             }
         }
         $html = '<!-- ' . $ngfb->cf['lca'] . ' sharing buttons begin -->' . $ngfb->sharing->get_js('sharing-buttons-header', $ids) . $ngfb->sharing->get_html($ids, $atts) . $ngfb->sharing->get_js('sharing-buttons-footer', $ids) . '<!-- ' . $ngfb->cf['lca'] . ' sharing buttons end -->';
         if ($ngfb->is_avail['cache']['transient']) {
             set_transient($cache_id, $html, $ngfb->cache->object_expire);
             $ngfb->debug->log($cache_type . ': html saved to transient ' . $cache_id . ' (' . $ngfb->cache->object_expire . ' seconds)');
         }
     } else {
         $html = '<!-- ' . $ngfb->cf['lca'] . ' sharing sharing buttons disabled -->';
     }
     return $ngfb->debug->get_html() . $html;
 }
Ejemplo n.º 2
0
 function ngfb_get_sharing_buttons($ids = array(), $atts = array(), $expire = 86400)
 {
     $ngfb =& Ngfb::get_instance();
     if ($ngfb->is_avail['ssb']) {
         $cache_salt = __METHOD__ . '(lang:' . SucomUtil::get_locale() . '_url:' . $ngfb->util->get_sharing_url() . '_ids:' . implode('_', $ids) . '_atts:' . implode('_', $atts) . ')';
         $cache_id = $ngfb->cf['lca'] . '_' . md5($cache_salt);
         $cache_type = 'object cache';
         // clear the cache if $expire = 0
         if (empty($expire)) {
             if ($ngfb->is_avail['cache']['transient']) {
                 delete_transient($cache_id);
             } elseif ($ngfb->is_avail['cache']['object']) {
                 wp_cache_delete($cache_id, __METHOD__);
             }
             return;
         } elseif (!isset($atts['read_cache']) || $atts['read_cache']) {
             if ($ngfb->is_avail['cache']['transient']) {
                 if ($ngfb->debug->enabled) {
                     $ngfb->debug->log($cache_type . ': transient salt ' . $cache_salt);
                 }
                 $html = get_transient($cache_id);
             } elseif ($ngfb->is_avail['cache']['object']) {
                 if ($ngfb->debug->enabled) {
                     $ngfb->debug->log($cache_type . ': wp_cache salt ' . $cache_salt);
                 }
                 $html = wp_cache_get($cache_id, __METHOD__);
             } else {
                 $html = false;
             }
         } else {
             $html = false;
         }
         if ($html !== false) {
             if ($ngfb->debug->enabled) {
                 $ngfb->debug->log($cache_type . ': html retrieved from cache ' . $cache_id);
             }
             return $ngfb->debug->get_html() . $html;
         }
         $html = '<!-- ' . $ngfb->cf['lca'] . ' sharing buttons begin -->' . $ngfb->sharing->get_script('sharing-buttons-header', $ids) . $ngfb->sharing->get_html($ids, $atts) . $ngfb->sharing->get_script('sharing-buttons-footer', $ids) . '<!-- ' . $ngfb->cf['lca'] . ' sharing buttons end -->';
         if ($ngfb->is_avail['cache']['transient'] || $ngfb->is_avail['cache']['object']) {
             if ($ngfb->is_avail['cache']['transient']) {
                 set_transient($cache_id, $html, $expire);
             } elseif ($ngfb->is_avail['cache']['object']) {
                 wp_cache_set($cache_id, $html, __METHOD__, $expire);
             }
             if ($ngfb->debug->enabled) {
                 $ngfb->debug->log($cache_type . ': html saved to cache ' . $cache_id . ' (' . $expire . ' seconds)');
             }
         }
     } else {
         $html = '<!-- ' . $ngfb->cf['lca'] . ' sharing sharing buttons disabled -->';
     }
     return $ngfb->debug->get_html() . $html;
 }
Ejemplo n.º 3
0
 public function widget($args, $instance)
 {
     if (is_feed()) {
         return;
     }
     // nothing to do in the feeds
     if (!empty($_SERVER['NGFB_DISABLE'])) {
         return;
     }
     if (!is_object($this->p)) {
         return;
     }
     if (is_object($this->p->sharing) && $this->p->sharing->is_disabled()) {
         $this->p->debug->log('widget buttons skipped: sharing buttons disabled');
         return;
     }
     extract($args);
     if ($this->p->is_avail['cache']['transient']) {
         $sharing_url = $this->p->util->get_sharing_url();
         $cache_salt = __METHOD__ . '(lang:' . SucomUtil::get_locale() . '_widget:' . $this->id . '_url:' . $sharing_url . ')';
         $cache_id = $this->p->cf['lca'] . '_' . md5($cache_salt);
         $cache_type = 'object cache';
         $this->p->debug->log($cache_type . ': transient salt ' . $cache_salt);
         $html = get_transient($cache_id);
         if ($html !== false) {
             $this->p->debug->log($cache_type . ': html retrieved from transient ' . $cache_id);
             echo $html;
             $this->p->debug->show_html();
             return;
         }
     }
     // sort enabled sharing buttons by their preferred order
     $sorted_ids = array();
     foreach ($this->p->cf['opt']['pre'] as $id => $pre) {
         if (array_key_exists($id, $instance) && (int) $instance[$id]) {
             $sorted_ids[$this->p->options[$pre . '_order'] . '-' . $id] = $id;
         }
     }
     ksort($sorted_ids);
     $atts = array('css_id' => $args['widget_id'], 'filter_id' => 'widget', 'use_post' => false, 'preset_id' => $this->p->options['buttons_preset_widget']);
     $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     $html = '<!-- ' . $this->p->cf['lca'] . ' ' . $args['widget_id'] . ' begin -->' . $before_widget . (empty($title) ? '' : $before_title . $title . $after_title) . $this->p->sharing->get_html($sorted_ids, $atts) . $after_widget . '<!-- ' . $this->p->cf['lca'] . ' ' . $args['widget_id'] . ' end -->' . "\n";
     if ($this->p->is_avail['cache']['transient']) {
         set_transient($cache_id, $html, $this->p->cache->object_expire);
         $this->p->debug->log($cache_type . ': html saved to transient ' . $cache_id . ' (' . $this->p->cache->object_expire . ' seconds)');
     }
     echo $html;
     $this->p->debug->show_html();
 }
Ejemplo n.º 4
0
 public function flush_post_cache($post_id)
 {
     switch (get_post_status($post_id)) {
         case 'draft':
         case 'pending':
         case 'future':
         case 'private':
         case 'publish':
             $lang = SucomUtil::get_locale();
             $cache_type = 'object cache';
             $sharing_url = $this->p->util->get_sharing_url($post_id);
             $transients = array('WpssoHead::get_header_array' => array('lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url, 'lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url . '_crawler:pinterest'));
             $transients = apply_filters($this->p->cf['lca'] . '_post_cache_transients', $transients, $post_id, $lang, $sharing_url);
             $objects = array('SucomWebpage::get_content' => array('lang:' . $lang . '_post:' . $post_id . '_filtered', 'lang:' . $lang . '_post:' . $post_id . '_unfiltered'), 'SucomWebpage::get_hashtags' => array('lang:' . $lang . '_post:' . $post_id));
             $objects = apply_filters($this->p->cf['lca'] . '_post_cache_objects', $objects, $post_id, $lang, $sharing_url);
             $this->flush_cache_objects($transients, $objects);
             break;
     }
 }
Ejemplo n.º 5
0
 public function shortcode($atts, $content = null)
 {
     $atts = apply_filters($this->p->cf['lca'] . '_shortcode_' . NGFB_SHARING_SHORTCODE, $atts, $content);
     if (($obj = $this->p->util->get_post_object()) === false) {
         $this->p->debug->log('exiting early: invalid object type');
         return $content;
     }
     $post_id = empty($obj->ID) || empty($obj->post_type) ? 0 : $obj->ID;
     $atts['url'] = empty($atts['url']) ? $this->p->util->get_sharing_url(true) : $atts['url'];
     $atts['css_id'] = empty($atts['css_id']) && !empty($post_id) ? 'shortcode' : $atts['css_id'];
     $atts['css_class'] = empty($atts['css_class']) ? 'button' : $atts['css_class'];
     $atts['filter_id'] = empty($atts['filter_id']) ? 'shortcode' : $atts['filter_id'];
     $atts['preset_id'] = empty($atts['preset_id']) ? $this->p->options['buttons_preset_shortcode'] : $atts['preset_id'];
     $html = '';
     if (!empty($atts['buttons'])) {
         $atts['css_id'] .= '-buttons';
         if ($this->p->is_avail['cache']['transient']) {
             $keys = implode('|', array_keys($atts));
             $vals = preg_replace('/[, ]+/', '_', implode('|', array_values($atts)));
             $cache_salt = __METHOD__ . '(lang:' . SucomUtil::get_locale() . '_post:' . $post_id . '_atts_keys:' . $keys . '_atts_vals:' . $vals . ')';
             $cache_id = $this->p->cf['lca'] . '_' . md5($cache_salt);
             $cache_type = 'object cache';
             $this->p->debug->log($cache_type . ': transient salt ' . $cache_salt);
             $html = get_transient($cache_id);
             if ($html !== false) {
                 $this->p->debug->log($cache_type . ': html retrieved from transient ' . $cache_id);
                 return $this->p->debug->get_html() . $html;
             }
         }
         $ids = array_map('trim', explode(',', $atts['buttons']));
         unset($atts['buttons']);
         $html .= '<!-- ' . $this->p->cf['lca'] . ' ' . $atts['css_id'] . ' begin -->' . $this->p->sharing->get_js('shortcode-header', $ids) . '<div class="' . $this->p->cf['lca'] . '-' . $atts['css_id'] . '">' . $this->p->sharing->get_html($ids, $atts) . '</div>' . $this->p->sharing->get_js('shortcode-footer', $ids) . '<!-- ' . $this->p->cf['lca'] . ' ' . $atts['css_id'] . ' end -->';
         if ($this->p->is_avail['cache']['transient']) {
             set_transient($cache_id, $html, $this->p->cache->object_expire);
             $this->p->debug->log($cache_type . ': html saved to transient ' . $cache_id . ' (' . $this->p->cache->object_expire . ' seconds)');
         }
     }
     return $html . $this->p->debug->get_html();
 }
 public function clear_cache($term_id, $term_tax_id = false)
 {
     $post_id = 0;
     $lca = $this->p->cf['lca'];
     $lang = SucomUtil::get_locale();
     $sharing_url = $this->p->util->get_sharing_url(false);
     $transients = array('WpssoHead::get_header_array' => array('lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url, 'lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url . '_crawler:pinterest'), 'WpssoMeta::get_mod_column_content' => array('mod:taxonomy_lang:' . $lang . '_id:' . $term_id . '_column:' . $lca . '_og_image'));
     $transients = apply_filters($this->p->cf['lca'] . '_taxonomy_cache_transients', $transients, $term_id, $lang, $sharing_url);
     $deleted = $this->p->util->clear_cache_objects($transients);
     if (!empty($this->p->options['plugin_cache_info']) && $deleted > 0) {
         $this->p->notice->inf($deleted . ' items removed from the WordPress object and transient caches.', true);
     }
     return $term_id;
 }
Ejemplo n.º 7
0
 public function clear_post_cache($post_id)
 {
     switch (get_post_status($post_id)) {
         case 'draft':
         case 'pending':
         case 'future':
         case 'private':
         case 'publish':
             $lca = $this->p->cf['lca'];
             $lang = SucomUtil::get_locale();
             $permalink = get_permalink($post_id);
             $permalink_no_meta = add_query_arg(array('WPSSO_META_TAGS_DISABLE' => 1), $permalink);
             $sharing_url = $this->p->util->get_sharing_url($post_id);
             $transients = array('SucomCache::get' => array('url:' . $permalink, 'url:' . $permalink_no_meta), 'WpssoHead::get_header_array' => array('lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url, 'lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url . '_crawler:pinterest'), 'WpssoMeta::get_mod_column_content' => array('mod:post_lang:' . $lang . '_id:' . $post_id . '_column:' . $lca . '_og_image'));
             $transients = apply_filters($lca . '_post_cache_transients', $transients, $post_id, $lang, $sharing_url);
             $objects = array('SucomWebpage::get_content' => array('lang:' . $lang . '_post:' . $post_id . '_filtered', 'lang:' . $lang . '_post:' . $post_id . '_unfiltered'), 'SucomWebpage::get_hashtags' => array('lang:' . $lang . '_post:' . $post_id));
             $objects = apply_filters($lca . '_post_cache_objects', $objects, $post_id, $lang, $sharing_url);
             $deleted = $this->clear_cache_objects($transients, $objects);
             if (!empty($this->p->options['plugin_cache_info']) && $deleted > 0) {
                 $this->p->notice->inf($deleted . ' items removed from the WordPress object and transient caches.', true);
             }
             if (function_exists('w3tc_pgcache_flush_post')) {
                 // w3 total cache
                 w3tc_pgcache_flush_post($post_id);
             }
             if (function_exists('wp_cache_post_change')) {
                 // wp super cache
                 wp_cache_post_change($post_id);
             }
             break;
     }
 }
Ejemplo n.º 8
0
 public function get_array(&$og = array(), $use_post = false)
 {
     $obj = $this->p->util->get_post_object($use_post);
     $post_id = empty($obj->ID) || empty($obj->post_type) ? 0 : $obj->ID;
     $post_type = '';
     $has_video_image = false;
     $og_max = $this->p->util->get_max_nums($post_id);
     $og = apply_filters($this->p->cf['lca'] . '_og_seed', $og, $use_post);
     if (!isset($og['fb:admins'])) {
         $og['fb:admins'] = $this->p->options['fb_admins'];
     }
     if (!isset($og['fb:app_id'])) {
         $og['fb:app_id'] = $this->p->options['fb_app_id'];
     }
     if (!isset($og['og:locale'])) {
         // get the current or configured language for og:locale
         $lang = empty($this->p->options['fb_lang']) ? SucomUtil::get_locale($post_id) : $this->p->options['fb_lang'];
         $lang = apply_filters($this->p->cf['lca'] . '_lang', $lang, SucomUtil::get_pub_lang('facebook'), $post_id);
         $og['og:locale'] = $lang;
     }
     if (!isset($og['og:site_name'])) {
         // pass options array to allow fallback if locale option does not exist
         $key = SucomUtil::get_locale_key('og_site_name', $this->p->options, $post_id);
         if (!empty($this->p->options[$key])) {
             $og['og:site_name'] = $this->p->options[$key];
         } else {
             $og['og:site_name'] = get_bloginfo('name', 'display');
         }
     }
     if (!isset($og['og:url'])) {
         $og['og:url'] = $this->p->util->get_sharing_url($use_post, true, $this->p->util->get_source_id('opengraph'));
     }
     if (!isset($og['og:title'])) {
         $og['og:title'] = $this->p->webpage->get_title($this->p->options['og_title_len'], '...', $use_post);
     }
     if (!isset($og['og:description'])) {
         $og['og:description'] = $this->p->webpage->get_description($this->p->options['og_desc_len'], '...', $use_post);
     }
     if (!isset($og['og:type'])) {
         // singular posts / pages are articles by default
         // check post_type for exceptions (like product pages)
         if (is_singular() || $use_post !== false) {
             if (!empty($obj->post_type)) {
                 $post_type = $obj->post_type;
             }
             switch ($post_type) {
                 case 'article':
                 case 'book':
                 case 'music.song':
                 case 'music.album':
                 case 'music.playlist':
                 case 'music.radio_station':
                 case 'product':
                 case 'profile':
                 case 'video.episode':
                 case 'video.movie':
                 case 'video.other':
                 case 'video.tv_show':
                 case 'website':
                     $og['og:type'] = $post_type;
                     break;
                 default:
                     $og['og:type'] = 'article';
                     break;
             }
             // check for default author info on indexes and searches
         } elseif (!(is_singular() || $use_post !== false) && !is_search() && !empty($this->p->options['og_def_author_on_index']) && !empty($this->p->options['og_def_author_id']) || is_search() && !empty($this->p->options['og_def_author_on_search']) && !empty($this->p->options['og_def_author_id'])) {
             $og['og:type'] = 'article';
             if (!isset($og['article:author'])) {
                 $og['article:author'] = $this->p->addons['util']['user']->get_article_author($this->p->options['og_def_author_id']);
             }
             // default for everything else is 'website'
         } else {
             $og['og:type'] = 'website';
         }
         $og['og:type'] = apply_filters($this->p->cf['lca'] . '_og_type', $og['og:type'], $use_post);
     }
     // if the page is an article, then define the other article meta tags
     if (isset($og['og:type']) && $og['og:type'] == 'article') {
         if (!isset($og['article:author'])) {
             if (is_singular() || $use_post !== false) {
                 if (!empty($obj->post_author)) {
                     $og['article:author'] = $this->p->addons['util']['user']->get_article_author($obj->post_author);
                 } elseif (!empty($this->p->options['og_def_author_id'])) {
                     $og['article:author'] = $this->p->addons['util']['user']->get_article_author($this->p->options['og_def_author_id']);
                 }
             }
         }
         if (!isset($og['article:publisher'])) {
             $og['article:publisher'] = $this->p->options['og_publisher_url'];
         }
         if (!isset($og['article:tag'])) {
             $og['article:tag'] = $this->p->webpage->get_tags($post_id);
         }
         if (!isset($og['article:section'])) {
             $og['article:section'] = $this->p->webpage->get_section($post_id);
         }
         if (!isset($og['article:published_time'])) {
             $og['article:published_time'] = trim(get_the_date('c'));
         }
         if (!isset($og['article:modified_time'])) {
             $og['article:modified_time'] = trim(get_the_modified_date('c'));
         }
     }
     // get all videos
     // check first, to add video preview images
     if (!isset($og['og:video'])) {
         if (empty($og_max['og_vid_max'])) {
             $this->p->debug->log('videos disabled: maximum videos = 0');
         } else {
             $og['og:video'] = $this->get_all_videos($og_max['og_vid_max'], $post_id);
             if (is_array($og['og:video'])) {
                 foreach ($og['og:video'] as $val) {
                     if (is_array($val) && !empty($val['og:image'])) {
                         $this->p->debug->log('og:image found in og:video array (no default image required)');
                         $has_video_image = true;
                     }
                 }
             }
         }
     }
     // get all images
     if (!isset($og['og:image'])) {
         if (empty($og_max['og_img_max'])) {
             $this->p->debug->log('images disabled: maximum images = 0');
         } else {
             $og['og:image'] = $this->get_all_images($og_max['og_img_max'], $this->size_name, $post_id);
             // if there's no image, and no video preview image, then add the default image for non-index webpages
             if (empty($og['og:image']) && $has_video_image === false && (is_singular() || $use_post !== false)) {
                 $og['og:image'] = $this->p->media->get_default_image($og_max['og_img_max'], $this->size_name);
             }
         }
     }
     // only a few opengraph meta tags are allowed to be empty
     foreach ($og as $key => $val) {
         switch ($key) {
             case 'og:locale':
             case 'og:site_name':
             case 'og:description':
                 break;
             default:
                 if ($val === '' || is_array($val) && empty($val)) {
                     unset($og[$key]);
                 }
                 break;
         }
     }
     // twitter cards are hooked into this filter to use existing open graph values
     return apply_filters($this->p->cf['lca'] . '_og', $og, $use_post);
 }
Ejemplo n.º 9
0
 public function get_header_array($use_post = false, $read_cache = true, &$meta_og = array())
 {
     $lca = $this->p->cf['lca'];
     $short_aop = $this->p->cf['plugin'][$lca]['short'] . ($this->p->is_avail['aop'] ? ' Pro' : '');
     $obj = $this->p->util->get_post_object($use_post);
     $post_id = empty($obj->ID) || empty($obj->post_type) || !is_singular() && $use_post === false ? 0 : $obj->ID;
     $sharing_url = $this->p->util->get_sharing_url($use_post);
     $author_id = false;
     if ($this->p->debug->enabled) {
         $this->p->debug->log('use_post: ' . ($use_post === false ? 'false' : ($use_post === true ? 'true' : $use_post)));
         $this->p->debug->log('post_id: ' . $post_id);
         $this->p->debug->log('obj post_type: ' . (empty($obj->post_type) ? '' : $obj->post_type));
         $this->p->debug->log('sharing url: ' . $sharing_url);
     }
     $header_array = array();
     if ($this->p->is_avail['cache']['transient']) {
         $cache_salt = __METHOD__ . '(' . apply_filters($lca . '_head_cache_salt', 'lang:' . SucomUtil::get_locale() . '_post:' . $post_id . '_url:' . $sharing_url, $use_post) . ')';
         $cache_id = $lca . '_' . md5($cache_salt);
         $cache_type = 'object cache';
         if ($this->p->debug->enabled) {
             $this->p->debug->log($cache_type . ': transient salt ' . $cache_salt);
         }
         if (apply_filters($lca . '_header_read_cache', $read_cache)) {
             $header_array = get_transient($cache_id);
             if ($header_array !== false) {
                 if ($this->p->debug->enabled) {
                     $this->p->debug->log($cache_type . ': header array retrieved from transient ' . $cache_id);
                 }
                 return $header_array;
             }
         }
     }
     /**
      * Define an author_id, if one is available
      */
     if (is_singular() || $use_post !== false) {
         if (!empty($obj->post_author)) {
             $author_id = $obj->post_author;
         } elseif (!empty($this->p->options['seo_def_author_id'])) {
             $author_id = $this->p->options['seo_def_author_id'];
         }
     } elseif (SucomUtil::is_author_page()) {
         $author_id = $this->p->util->get_author_object('id');
     } elseif ($this->p->util->force_default_author($use_post, 'seo')) {
         $author_id = $this->p->options['seo_def_author_id'];
     }
     if ($this->p->debug->enabled && $author_id !== false) {
         $this->p->debug->log('author_id: ' . $author_id);
     }
     /**
      * Open Graph, Twitter Card
      *
      * The Twitter Card meta tags are added by the 
      * NgfbHeadTwittercard class using an 'ngfb_og' filter hook.
      */
     $meta_og = $this->p->og->get_array($meta_og, $use_post, $obj);
     /**
      * Name / SEO meta tags
      */
     $meta_name = array();
     if (!empty($this->p->options['add_meta_name_author'])) {
         if (isset($this->p->options['seo_author_name']) && $this->p->options['seo_author_name'] !== 'none') {
             $meta_name['author'] = $this->p->mods['util']['user']->get_author_name($author_id, $this->p->options['seo_author_name']);
         }
     }
     if (!empty($this->p->options['add_meta_name_canonical'])) {
         $meta_name['canonical'] = $sharing_url;
     }
     if (!empty($this->p->options['add_meta_name_description'])) {
         $meta_name['description'] = $this->p->webpage->get_description($this->p->options['seo_desc_len'], '...', $use_post, true, false, true, 'seo_desc');
     }
     // add_hashtags = false
     if (!empty($this->p->options['add_meta_name_p:domain_verify'])) {
         if (!empty($this->p->options['rp_dom_verify'])) {
             $meta_name['p:domain_verify'] = $this->p->options['rp_dom_verify'];
         }
     }
     $meta_name = apply_filters($lca . '_meta_name', $meta_name, $use_post, $obj);
     /**
      * Link relation tags
      */
     $link_rel = array();
     if (!empty($this->p->options['add_link_rel_author'])) {
         if (!empty($author_id)) {
             $link_rel['author'] = $this->p->mods['util']['user']->get_author_website_url($author_id, $this->p->options['seo_author_field']);
         }
     }
     if (!empty($this->p->options['add_link_rel_publisher'])) {
         if (!empty($this->p->options['seo_publisher_url'])) {
             $link_rel['publisher'] = $this->p->options['seo_publisher_url'];
         }
     }
     $link_rel = apply_filters($lca . '_link_rel', $link_rel, $use_post, $obj);
     /**
      * Schema meta tags
      */
     $meta_schema = $this->p->schema->get_meta_array($use_post, $obj, $meta_og);
     /**
      * Combine and return all meta tags
      */
     $comment = $this->p->cf['lca'] . ' meta tags';
     $header_array = array_merge($this->get_single_tag('meta', 'name', 'generator', $short_aop . ' ' . $this->p->cf['plugin'][$lca]['version'] . ($this->p->check->aop() ? 'L' : ($this->p->is_avail['aop'] ? 'U' : 'G')) . ($this->p->is_avail['util']['um'] ? ' +' : ' -') . 'UM', '', $use_post), $this->get_tag_array('link', 'rel', $link_rel, $use_post), $this->get_tag_array('meta', 'property', $meta_og, $use_post), $this->get_tag_array('meta', 'itemprop', $meta_schema, $use_post), $this->get_tag_array('meta', 'name', $meta_name, $use_post), SucomUtil::a2aa($this->p->schema->get_json_array($post_id, $author_id, $this->p->cf['lca'] . '-schema')));
     /**
      * Save the header array to the WordPress transient cache
      */
     if (apply_filters($lca . '_header_set_cache', $this->p->is_avail['cache']['transient'])) {
         set_transient($cache_id, $header_array, $this->p->options['plugin_object_cache_exp']);
         if ($this->p->debug->enabled) {
             $this->p->debug->log($cache_type . ': header array saved to transient ' . $cache_id . ' (' . $this->p->options['plugin_object_cache_exp'] . ' seconds)');
         }
     }
     return $header_array;
 }
Ejemplo n.º 10
0
 public function get_array($use_post = false, $obj = false, &$og = array())
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->mark();
     }
     if (!is_object($obj)) {
         $obj = $this->p->util->get_post_object($use_post);
     }
     $post_id = empty($obj->ID) || empty($obj->post_type) || !SucomUtil::is_post_page($use_post) ? 0 : $obj->ID;
     // counter for video previews found
     $video_previews = 0;
     // post_id 0 returns the default plugin settings
     $og_max = $this->p->util->get_max_nums($post_id, 'post');
     $og = apply_filters($this->p->cf['lca'] . '_og_seed', $og, $use_post, $obj);
     if (!empty($og) && $this->p->debug->enabled) {
         $this->p->debug->log($this->p->cf['lca'] . '_og_seed filter returned:');
         $this->p->debug->log($og);
     }
     if (!isset($og['fb:admins']) && !empty($this->p->options['fb_admins'])) {
         foreach (explode(',', $this->p->options['fb_admins']) as $fb_admin) {
             $og['fb:admins'][] = trim($fb_admin);
         }
     }
     if (!isset($og['fb:app_id'])) {
         $og['fb:app_id'] = $this->p->options['fb_app_id'];
     }
     if (!isset($og['og:url'])) {
         $og['og:url'] = $this->p->util->get_sharing_url($use_post, true, $this->p->util->get_source_id('opengraph'));
     }
     // define the type after the url
     if (!isset($og['og:type'])) {
         // singular posts / pages are articles by default
         // check the post_type for a match with a known open graph type
         if (SucomUtil::is_post_page($use_post)) {
             if (!empty($obj->post_type) && isset($this->p->cf['head']['og_type_ns'][$obj->post_type])) {
                 $og['og:type'] = $obj->post_type;
             } else {
                 $og['og:type'] = 'article';
             }
             // check for default author info on indexes and searches
         } elseif ($this->p->util->force_default_author($use_post, 'og') && !empty($this->p->options['og_def_author_id'])) {
             $og['og:type'] = 'article';
             // meta tag not defined or value is null
             if (!isset($og['article:author'])) {
                 $og['article:author'] = $this->p->mods['util']['user']->get_article_author($this->p->options['og_def_author_id']);
             }
             // default for everything else is 'website'
         } else {
             $og['og:type'] = 'website';
         }
         $og['og:type'] = apply_filters($this->p->cf['lca'] . '_og_type', $og['og:type'], $use_post);
         // pre-define basic open graph meta tags for this type
         if (isset($this->p->cf['head']['og_type_mt'][$og['og:type']])) {
             foreach ($this->p->cf['head']['og_type_mt'][$og['og:type']] as $mt_name) {
                 if (!isset($og[$mt_name])) {
                     $og[$mt_name] = null;
                     if ($this->p->debug->enabled) {
                         $this->p->debug->log($og['og:type'] . ' pre-defined mt: ' . $mt_name);
                     }
                 }
             }
         }
     }
     if (!isset($og['og:locale'])) {
         // get the current or configured language for og:locale
         $lang = empty($this->p->options['fb_lang']) ? SucomUtil::get_locale($post_id) : $this->p->options['fb_lang'];
         $lang = apply_filters($this->p->cf['lca'] . '_lang', $lang, SucomUtil::get_pub_lang('facebook'), $post_id);
         $og['og:locale'] = $lang;
     }
     if (!isset($og['og:site_name'])) {
         $og['og:site_name'] = $this->get_site_name($post_id);
     }
     if (!isset($og['og:title'])) {
         $og['og:title'] = $this->p->webpage->get_title($this->p->options['og_title_len'], '...', $use_post);
     }
     if (!isset($og['og:description'])) {
         $og['og:description'] = $this->p->webpage->get_description($this->p->options['og_desc_len'], '...', $use_post);
     }
     // if the page is an article, then define the other article meta tags
     if (isset($og['og:type']) && $og['og:type'] == 'article') {
         // meta tag not defined or value is null
         if (!isset($og['article:author'])) {
             if (SucomUtil::is_post_page($use_post)) {
                 if (!empty($obj->post_author)) {
                     $og['article:author'] = $this->p->mods['util']['user']->get_article_author($obj->post_author);
                 } elseif (!empty($this->p->options['og_def_author_id'])) {
                     $og['article:author'] = $this->p->mods['util']['user']->get_article_author($this->p->options['og_def_author_id']);
                 }
             }
         }
         // meta tag not defined or value is null
         if (!isset($og['article:publisher'])) {
             $og['article:publisher'] = $this->p->options['fb_publisher_url'];
         }
         // meta tag not defined or value is null
         if (!isset($og['article:tag'])) {
             $og['article:tag'] = $this->p->webpage->get_tags($post_id);
         }
         // meta tag not defined or value is null
         if (!isset($og['article:section'])) {
             $og['article:section'] = $this->p->webpage->get_section($post_id);
         }
         // meta tag not defined or value is null
         if (!isset($og['article:published_time'])) {
             $og['article:published_time'] = trim(get_the_date('c'));
         }
         // meta tag not defined or value is null
         if (!isset($og['article:modified_time'])) {
             $og['article:modified_time'] = trim(get_the_modified_date('c'));
         }
     }
     // get all videos
     // call before getting all images to find / use preview images
     if (!isset($og['og:video'])) {
         if (empty($og_max['og_vid_max'])) {
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('videos disabled: maximum videos = 0');
             }
         } else {
             $og['og:video'] = $this->get_all_videos($og_max['og_vid_max'], $post_id, 'post', false, 'og');
             if (!empty($og['og:video']) && is_array($og['og:video'])) {
                 foreach ($og['og:video'] as $val) {
                     if (!empty($val['og:image'])) {
                         $video_previews++;
                     }
                 }
                 if ($video_previews > 0) {
                     $og_max['og_img_max'] -= $video_previews;
                     if ($this->p->debug->enabled) {
                         $this->p->debug->log($video_previews . ' video preview images found (og_img_max adjusted to ' . $og_max['og_img_max'] . ')');
                     }
                 }
             }
         }
     }
     // get all images
     if (!isset($og['og:image'])) {
         if (empty($og_max['og_img_max'])) {
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('images disabled: maximum images = 0');
             }
         } else {
             $img_sizes = array();
             $crawler_name = SucomUtil::crawler_name();
             if ((is_admin() || $crawler_name === 'pinterest') && !SucomUtil::get_const('WPSSO_RICH_PIN_DISABLE')) {
                 $img_sizes['rp'] = $this->p->cf['lca'] . '-richpin';
             }
             $img_sizes['og'] = $this->p->cf['lca'] . '-opengraph';
             // must be last for meta tags preview
             foreach ($img_sizes as $md_pre => $size_name) {
                 // only check for dupes on last image size
                 $check_dupes = is_admin() && $md_pre !== 'og' ? false : true;
                 $og['og:image'] = $this->get_all_images($og_max['og_img_max'], $size_name, $post_id, $check_dupes, $md_pre);
                 // if there's no image, and no video preview image, then add the default image for non-index webpages
                 if (empty($og['og:image']) && $video_previews === 0 && SucomUtil::is_post_page($use_post)) {
                     $og['og:image'] = $this->p->media->get_default_image($og_max['og_img_max'], $size_name, $check_dupes);
                 }
             }
         }
     }
     return apply_filters($this->p->cf['lca'] . '_og', $og, $use_post, $obj);
 }
Ejemplo n.º 11
0
 public function get_content($post_id = 0, $use_post = true, $use_cache = true, $md_idx = null, $src_id = '')
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->args(array('post_id' => $post_id, 'use_post' => $use_post, 'use_cache' => $use_cache, 'md_idx' => $md_idx, 'src_id' => $src_id));
     }
     $content = false;
     // if $post_id is 0, then pass the $use_post (true/false) value instead
     if (($obj = $this->p->util->get_post_object(empty($post_id) ? $use_post : $post_id)) === false) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log('exiting early: invalid object type');
         }
         return $content;
     }
     $post_id = empty($obj->ID) || empty($obj->post_type) ? 0 : $obj->ID;
     if ($this->p->debug->enabled) {
         $this->p->debug->log('using content from object id ' . $post_id);
     }
     $filter_content = $this->p->options['plugin_filter_content'];
     $filter_name = $filter_content ? 'filtered' : 'unfiltered';
     $caption_prefix = isset($this->p->options['plugin_p_cap_prefix']) ? $this->p->options['plugin_p_cap_prefix'] : 'Caption:';
     /*
      * retrieve the content
      */
     if ($filter_content == true) {
         if ($this->p->is_avail['cache']['object']) {
             // if the post id is 0, then add the sharing url to ensure a unique salt string
             $cache_salt = __METHOD__ . '(lang:' . SucomUtil::get_locale() . '_post:' . $post_id . '_' . $filter_name . (empty($post_id) ? '_url:' . $this->p->util->get_sharing_url($use_post, true, $src_id) : '') . ')';
             $cache_id = $this->p->cf['lca'] . '_' . md5($cache_salt);
             $cache_type = 'object cache';
             if ($use_cache === true) {
                 if ($this->p->debug->enabled) {
                     $this->p->debug->log($cache_type . ': wp_cache salt ' . $cache_salt);
                 }
                 $content = wp_cache_get($cache_id, __METHOD__);
                 if ($content !== false) {
                     if ($this->p->debug->enabled) {
                         $this->p->debug->log($cache_type . ': ' . $filter_name . ' content retrieved from wp_cache ' . $cache_id);
                     }
                     return $content;
                 }
             } elseif ($this->p->debug->enabled) {
                 $this->p->debug->log('use_cache = false');
             }
         }
     }
     $content = apply_filters($this->p->cf['lca'] . '_content_seed', '', $post_id, $use_post, $md_idx, $src_id);
     if (!empty($content)) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log('content seed = "' . $content . '"');
         }
     } elseif (!empty($obj->post_content)) {
         $content = $obj->post_content;
     } elseif ($this->p->debug->enabled) {
         $this->p->debug->log('exiting early: empty post content');
     }
     /*
      * modify the content
      */
     // save content length (for comparison) before making changes
     $content_strlen_before = strlen($content);
     // remove singlepics, which we detect and use before-hand
     $content = preg_replace('/\\[singlepic[^\\]]+\\]/', '', $content, -1, $count);
     if ($count > 0) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log($count . ' [singlepic] shortcode(s) removed from content');
         }
     }
     if ($filter_content == true) {
         $filter_removed = apply_filters($this->p->cf['lca'] . '_pre_filter_remove', false, 'the_content');
         // remove all of our shortcodes
         if (isset($this->p->cf['*']['lib']['shortcode']) && is_array($this->p->cf['*']['lib']['shortcode'])) {
             foreach ($this->p->cf['*']['lib']['shortcode'] as $id => $name) {
                 if (array_key_exists($id, $this->shortcode) && is_object($this->shortcode[$id])) {
                     $this->shortcode[$id]->remove();
                 }
             }
         }
         global $post;
         $saved_post = $post;
         // woocommerce can change the $post, so save and restore
         if ($this->p->debug->enabled) {
             $this->p->debug->log('saving $post and applying the_content filters');
         }
         $content = apply_filters('the_content', $content);
         $post = $saved_post;
         // cleanup for NGG pre-v2 album shortcode
         unset($GLOBALS['subalbum']);
         unset($GLOBALS['nggShowGallery']);
         if ($filter_removed) {
             $filter_added = apply_filters($this->p->cf['lca'] . '_post_filter_add', false, 'the_content');
         }
         // add our shortcodes back
         if (isset($this->p->cf['*']['lib']['shortcode']) && is_array($this->p->cf['*']['lib']['shortcode'])) {
             foreach ($this->p->cf['*']['lib']['shortcode'] as $id => $name) {
                 if (array_key_exists($id, $this->shortcode) && is_object($this->shortcode[$id])) {
                     $this->shortcode[$id]->add();
                 }
             }
         }
     } elseif ($this->p->debug->enabled) {
         $this->p->debug->log('the_content filters skipped');
     }
     $content = preg_replace('/[\\s\\n\\r]+/s', ' ', $content);
     // put everything on one line
     $content = preg_replace('/^.*<!--' . $this->p->cf['lca'] . '-content-->(.*)<!--\\/' . $this->p->cf['lca'] . '-content-->.*$/', '$1', $content);
     if (strpos($content, '>Google+<') !== false) {
         $content = preg_replace('/<a +rel="author" +href="" +style="display:none;">Google\\+<\\/a>/', ' ', $content);
     }
     if (!empty($caption_prefix) && strpos($content, '<p class="wp-caption-text">') !== false) {
         $content = preg_replace('/<p class="wp-caption-text">/', '${0}' . $caption_prefix . ' ', $content);
     }
     if (strpos($content, ']]>') !== false) {
         $content = str_replace(']]>', ']]&gt;', $content);
     }
     $content_strlen_after = strlen($content);
     if ($this->p->debug->enabled) {
         $this->p->debug->log('content strlen before ' . $content_strlen_before . ' and after changes / filters ' . $content_strlen_after);
     }
     // apply filters before caching
     $content = apply_filters($this->p->cf['lca'] . '_content', $content, $post_id, $use_post, $md_idx, $src_id);
     if ($filter_content == true && !empty($cache_id)) {
         // only some caching plugins implement this function
         wp_cache_add_non_persistent_groups(array(__METHOD__));
         wp_cache_set($cache_id, $content, __METHOD__, $this->p->options['plugin_object_cache_exp']);
         if ($this->p->debug->enabled) {
             $this->p->debug->log($cache_type . ': ' . $filter_name . ' content saved to wp_cache ' . $cache_id . ' (' . $this->p->options['plugin_object_cache_exp'] . ' seconds)');
         }
     }
     return $content;
 }
Ejemplo n.º 12
0
 public function get_header_array($use_post = false, $read_cache = true, &$meta_og = array())
 {
     $lca = $this->p->cf['lca'];
     $short_aop = $this->p->cf['plugin'][$lca]['short'] . ($this->p->is_avail['aop'] ? ' Pro' : '');
     $obj = $this->p->util->get_post_object($use_post);
     $post_id = empty($obj->ID) || empty($obj->post_type) || !is_singular() && $use_post === false ? 0 : $obj->ID;
     $sharing_url = $this->p->util->get_sharing_url($use_post);
     $author_id = 0;
     $header_array = array();
     if ($this->p->is_avail['cache']['transient']) {
         $cache_salt = __METHOD__ . '(' . apply_filters($lca . '_head_cache_salt', 'lang:' . SucomUtil::get_locale() . '_post:' . $post_id . '_url:' . $sharing_url, $use_post) . ')';
         $cache_id = $lca . '_' . md5($cache_salt);
         $cache_type = 'object cache';
         $this->p->debug->log($cache_type . ': transient salt ' . $cache_salt);
         if ($read_cache) {
             $header_array = get_transient($cache_id);
             if ($header_array !== false) {
                 $this->p->debug->log($cache_type . ': header array retrieved from transient ' . $cache_id);
                 return $header_array;
             }
         }
     }
     /**
      * Define an author_id, if one is available
      */
     if (is_singular() || $use_post !== false) {
         if (!empty($obj->post_author)) {
             $author_id = $obj->post_author;
         } elseif (!empty($this->p->options['seo_def_author_id'])) {
             $author_id = $this->p->options['seo_def_author_id'];
         }
     } elseif (is_author() || is_admin() && ($screen = get_current_screen()) && ($screen->id === 'user-edit' || $screen->id === 'profile')) {
         $author = $this->p->util->get_author_object();
         $author_id = $author->ID;
     } elseif (!(is_singular() || $use_post !== false) && !is_search() && !empty($this->p->options['seo_def_author_on_index']) && !empty($this->p->options['seo_def_author_id']) || is_search() && !empty($this->p->options['seo_def_author_on_search']) && !empty($this->p->options['seo_def_author_id'])) {
         $author_id = $this->p->options['seo_def_author_id'];
     }
     /**
      * Open Graph, Twitter Card
      *
      * The Twitter Card meta tags are added by the NgfbHeadTwittercard class using an 'ngfb_og' filter hook.
      */
     if ($this->p->is_avail['opengraph']) {
         $meta_og = $this->p->og->get_array($meta_og, $use_post);
     }
     /**
      * Name / SEO meta tags
      */
     $meta_name = array();
     if (isset($this->p->options['seo_author_name']) && $this->p->options['seo_author_name'] !== 'none') {
         $meta_name['author'] = $this->p->addons['util']['user']->get_author_name($author_id, $this->p->options['seo_author_name']);
     }
     $meta_name['description'] = $this->p->webpage->get_description($this->p->options['seo_desc_len'], '...', $use_post, true, false, true, 'seo_desc');
     // add_hashtags = false, custom meta = seo_desc
     $meta_name = apply_filters($lca . '_meta_name', $meta_name);
     /**
      * Link relation tags
      */
     $link_rel = array();
     if (!empty($author_id)) {
         $link_rel['author'] = $this->p->addons['util']['user']->get_author_website_url($author_id, $this->p->options['link_author_field']);
     }
     if (!empty($this->p->options['link_publisher_url'])) {
         $link_rel['publisher'] = $this->p->options['link_publisher_url'];
     }
     $link_rel = apply_filters($lca . '_link_rel', $link_rel);
     /**
      * Schema meta tags
      */
     $meta_schema = array();
     $meta_schema['description'] = $this->p->webpage->get_description($this->p->options['og_desc_len'], '...', $use_post, true, true, true, 'schema_desc');
     // custom meta = schema_desc
     $meta_schema = apply_filters($lca . '_meta_schema', $meta_schema);
     /**
      * Combine and return all meta tags
      */
     $header_array = array_merge($this->get_single_tag('meta', 'name', 'generator', $short_aop . ' ' . $this->p->cf['plugin'][$lca]['version'] . ($this->p->check->aop() ? 'L' : ($this->p->is_avail['aop'] ? 'U' : 'G'))), $this->get_tag_array('link', 'rel', $link_rel), $this->get_tag_array('meta', 'name', $meta_name), $this->get_tag_array('meta', 'itemprop', $meta_schema), $this->get_tag_array('meta', 'property', $meta_og));
     if (!empty($this->p->is_avail['cache']['transient'])) {
         set_transient($cache_id, $header_array, $this->p->cache->object_expire);
         $this->p->debug->log($cache_type . ': header array saved to transient ' . $cache_id . ' (' . $this->p->cache->object_expire . ' seconds)');
     }
     return $header_array;
 }
 public function get_array(&$og = array(), $use_post = false, $obj = false)
 {
     if (!is_object($obj)) {
         $obj = $this->p->util->get_post_object($use_post);
     }
     $post_id = empty($obj->ID) || empty($obj->post_type) || !is_singular() && $use_post === false ? 0 : $obj->ID;
     $post_type = '';
     $video_previews = 0;
     $og_max = $this->p->util->get_max_nums($post_id, 'post');
     // post_id 0 returns the plugin settings
     $og = apply_filters($this->p->cf['lca'] . '_og_seed', $og, $use_post, $obj);
     if (!empty($og) && $this->p->debug->enabled) {
         $this->p->debug->log($this->p->cf['lca'] . '_og_seed filter returned:');
         $this->p->debug->log($og);
     }
     if (!isset($og['fb:admins']) && !empty($this->p->options['fb_admins'])) {
         foreach (explode(',', $this->p->options['fb_admins']) as $fb_admin) {
             $og['fb:admins'][] = trim($fb_admin);
         }
     }
     if (!isset($og['fb:app_id'])) {
         $og['fb:app_id'] = $this->p->options['fb_app_id'];
     }
     if (!isset($og['og:url'])) {
         $og['og:url'] = $this->p->util->get_sharing_url($use_post, true, $this->p->util->get_source_id('opengraph'));
     }
     // define the type after the url
     if (!isset($og['og:type'])) {
         // singular posts / pages are articles by default
         // check the post_type for a match with a known open graph type
         if (is_singular() || $use_post !== false) {
             if (!empty($obj->post_type)) {
                 $post_type = $obj->post_type;
             }
             if (isset($this->p->cf['head']['og_type_ns'][$post_type])) {
                 $og['og:type'] = $post_type;
             } else {
                 $og['og:type'] = 'article';
             }
             // check for default author info on indexes and searches
         } elseif ($this->p->util->force_default_author($use_post, 'og') && !empty($this->p->options['og_def_author_id'])) {
             $og['og:type'] = 'article';
             if (!isset($og['article:author'])) {
                 $og['article:author'] = $this->p->mods['util']['user']->get_article_author($this->p->options['og_def_author_id']);
             }
             // default for everything else is 'website'
         } else {
             $og['og:type'] = 'website';
         }
         $og['og:type'] = apply_filters($this->p->cf['lca'] . '_og_type', $og['og:type'], $use_post);
     }
     if (!isset($og['og:locale'])) {
         // get the current or configured language for og:locale
         $lang = empty($this->p->options['fb_lang']) ? SucomUtil::get_locale($post_id) : $this->p->options['fb_lang'];
         $lang = apply_filters($this->p->cf['lca'] . '_lang', $lang, SucomUtil::get_pub_lang('facebook'), $post_id);
         $og['og:locale'] = $lang;
     }
     if (!isset($og['og:site_name'])) {
         $og['og:site_name'] = $this->get_site_name($post_id);
     }
     if (!isset($og['og:title'])) {
         $og['og:title'] = $this->p->webpage->get_title($this->p->options['og_title_len'], '...', $use_post);
     }
     if (!isset($og['og:description'])) {
         $og['og:description'] = $this->p->webpage->get_description($this->p->options['og_desc_len'], '...', $use_post);
     }
     // if the page is an article, then define the other article meta tags
     if (isset($og['og:type']) && $og['og:type'] == 'article') {
         if (!isset($og['article:author'])) {
             if (is_singular() || $use_post !== false) {
                 if (!empty($obj->post_author)) {
                     $og['article:author'] = $this->p->mods['util']['user']->get_article_author($obj->post_author);
                 } elseif (!empty($this->p->options['og_def_author_id'])) {
                     $og['article:author'] = $this->p->mods['util']['user']->get_article_author($this->p->options['og_def_author_id']);
                 }
             }
         }
         if (!isset($og['article:publisher'])) {
             $og['article:publisher'] = $this->p->options['fb_publisher_url'];
         }
         if (!isset($og['article:tag'])) {
             $og['article:tag'] = $this->p->webpage->get_tags($post_id);
         }
         if (!isset($og['article:section'])) {
             $og['article:section'] = $this->p->webpage->get_section($post_id);
         }
         if (!isset($og['article:published_time'])) {
             $og['article:published_time'] = trim(get_the_date('c'));
         }
         if (!isset($og['article:modified_time'])) {
             $og['article:modified_time'] = trim(get_the_modified_date('c'));
         }
     }
     // get all videos
     // call before getting all images to find / use preview images
     if (!isset($og['og:video'])) {
         if (empty($og_max['og_vid_max'])) {
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('videos disabled: maximum videos = 0');
             }
         } else {
             $og['og:video'] = $this->get_all_videos($og_max['og_vid_max'], $post_id, true, 'og');
             if (is_array($og['og:video'])) {
                 foreach ($og['og:video'] as $val) {
                     if (!empty($val['og:image'])) {
                         $video_previews++;
                     }
                 }
                 if ($video_previews > 0) {
                     $og_max['og_img_max'] -= $video_previews;
                     if ($this->p->debug->enabled) {
                         $this->p->debug->log($video_previews . ' video preview images found (og_img_max adjusted to ' . $og_max['og_img_max'] . ')');
                     }
                 }
             }
         }
     }
     // get all images
     if (!isset($og['og:image'])) {
         if (empty($og_max['og_img_max'])) {
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('images disabled: maximum images = 0');
             }
         } else {
             if (is_admin()) {
                 $img_sizes = array('rp' => $this->p->cf['lca'] . '-richpin', 'og' => $this->p->cf['lca'] . '-opengraph');
             } else {
                 switch (SucomUtil::crawler_name()) {
                     case 'pinterest':
                         $img_sizes = array('rp' => $this->p->cf['lca'] . '-richpin');
                         break;
                     default:
                         $img_sizes = array('og' => $this->p->cf['lca'] . '-opengraph');
                         break;
                 }
             }
             foreach ($img_sizes as $meta_pre => $size_name) {
                 // only check for dupes on last image size
                 $check_dupes = is_admin() && $meta_pre !== 'og' ? false : true;
                 $og['og:image'] = $this->get_all_images($og_max['og_img_max'], $size_name, $post_id, $check_dupes, $meta_pre);
                 // if there's no image, and no video preview image, then add the default image for non-index webpages
                 if (empty($og['og:image']) && $video_previews === 0 && (is_singular() || $use_post !== false)) {
                     $og['og:image'] = $this->p->media->get_default_image($og_max['og_img_max'], $size_name, $check_dupes);
                 }
             }
         }
     }
     // only a few opengraph meta tags are allowed to be empty
     foreach ($og as $key => $val) {
         switch ($key) {
             case 'og:locale':
             case 'og:site_name':
             case 'og:description':
                 break;
             default:
                 if ($val === '' || is_array($val) && empty($val)) {
                     unset($og[$key]);
                 }
                 break;
         }
     }
     // twitter cards are hooked into this filter to use existing open graph values
     return apply_filters($this->p->cf['lca'] . '_og', $og, $use_post, $obj);
 }
Ejemplo n.º 14
0
 protected function get_mod_column_content($value, $column_name, $id, $mod = '')
 {
     // optimize performance and return immediately if this is not our column
     if (strpos($column_name, $this->p->cf['lca'] . '_') !== 0) {
         return $value;
     }
     // when adding a new category, $screen_id may be false
     $screen_id = SucomUtil::get_screen_id();
     if (!empty($screen_id)) {
         $hidden = get_user_option('manage' . $screen_id . 'columnshidden');
         if (is_array($hidden) && in_array($column_name, $hidden)) {
             return 'Reload to View';
         }
     }
     switch ($column_name) {
         case $this->p->cf['lca'] . '_og_image':
         case $this->p->cf['lca'] . '_og_desc':
             $use_cache = true;
             break;
         default:
             $use_cache = false;
             break;
     }
     if ($use_cache === true && $this->p->is_avail['cache']['transient']) {
         $lang = SucomUtil::get_locale();
         $cache_salt = __METHOD__ . '(mod:' . $mod . '_lang:' . $lang . '_id:' . $id . '_column:' . $column_name . ')';
         $cache_id = $this->p->cf['lca'] . '_' . md5($cache_salt);
         $value = get_transient($cache_id);
         if ($value !== false) {
             return $value;
         }
     }
     switch ($column_name) {
         case $this->p->cf['lca'] . '_og_image':
             // set custom image dimensions for this post/term/user id
             $this->p->util->add_plugin_image_sizes($id, array(), true, $mod);
             break;
     }
     $value = apply_filters($column_name . '_' . $mod . '_column_content', $value, $column_name, $id);
     if ($use_cache === true && $this->p->is_avail['cache']['transient']) {
         set_transient($cache_id, $value, $this->p->options['plugin_object_cache_exp']);
     }
     return $value;
 }
Ejemplo n.º 15
0
 public function flush_cache($user_id)
 {
     $lang = SucomUtil::get_locale();
     $post_id = 0;
     $sharing_url = $this->p->util->get_sharing_url(false);
     $transients = array('WpssoHead::get_header_array' => array('lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url, 'lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url . '_crawler:pinterest'));
     $transients = apply_filters($this->p->cf['lca'] . '_user_cache_transients', $transients, $post_id, $lang, $sharing_url);
     $this->p->util->flush_cache_objects($transients);
 }
Ejemplo n.º 16
0
 public function get_content($use_post = true, $use_cache = true)
 {
     $this->p->debug->args(array('use_post' => $use_post, 'use_cache' => $use_cache));
     $content = false;
     if (($obj = $this->p->util->get_post_object($use_post)) === false) {
         $this->p->debug->log('exiting early: invalid object type');
         return $content;
     }
     $post_id = empty($obj->ID) ? 0 : $obj->ID;
     $this->p->debug->log('using content from object id ' . $post_id);
     $filter_content = $this->p->options['plugin_filter_content'];
     $filter_name = $filter_content ? 'filtered' : 'unfiltered';
     /*
      * retrieve the content
      */
     if ($filter_content == true) {
         if ($this->p->is_avail['cache']['object']) {
             // if the post id is 0, then add the sharing url to ensure a unique salt string
             $cache_salt = __METHOD__ . '(lang:' . SucomUtil::get_locale() . '_post:' . $post_id . '_' . $filter_name . (empty($post_id) ? '_url:' . $this->p->util->get_sharing_url($use_post) : '') . ')';
             $cache_id = $this->p->cf['lca'] . '_' . md5($cache_salt);
             $cache_type = 'object cache';
             if ($use_cache === true) {
                 $this->p->debug->log($cache_type . ': wp_cache salt ' . $cache_salt);
                 $content = wp_cache_get($cache_id, __METHOD__);
                 if ($content !== false) {
                     $this->p->debug->log($cache_type . ': ' . $filter_name . ' content retrieved from wp_cache ' . $cache_id);
                     return $content;
                 }
             } else {
                 $this->p->debug->log('use cache = false');
             }
         }
     }
     $content = apply_filters($this->p->cf['lca'] . '_content_seed', '');
     if (!empty($content)) {
         $this->p->debug->log('content seed = "' . $content . '"');
     } elseif (!empty($obj->post_content)) {
         $content = $obj->post_content;
     } else {
         $this->p->debug->log('exiting early: empty post content');
     }
     /*
      * modify the content
      */
     // save content length (for comparison) before making changes
     $content_strlen_before = strlen($content);
     // remove singlepics, which we detect and use before-hand
     $content = preg_replace('/\\[singlepic[^\\]]+\\]/', '', $content, -1, $count);
     if ($count > 0) {
         $this->p->debug->log($count . ' [singlepic] shortcode(s) removed from content');
     }
     if ($filter_content == true) {
         // remove the sharing buttons filter to avoid recursive loops
         if (!empty($this->p->sharing) && is_object($this->p->sharing)) {
             $filter_removed = $this->p->sharing->remove_buttons_filter('the_content');
         } else {
             $filter_removed = false;
         }
         // remove all of our shortcodes
         if (!empty($this->p->cf['lib']['shortcode']) && is_array($this->p->cf['lib']['shortcode'])) {
             foreach ($this->p->cf['lib']['shortcode'] as $id => $name) {
                 if (array_key_exists($id, $this->shortcode) && is_object($this->shortcode[$id])) {
                     $this->shortcode[$id]->remove();
                 }
             }
         }
         $this->p->debug->log('saving $post and calling apply_filters()');
         global $post;
         $saved_post = $post;
         // woocommerce can change the $post, so save and restore
         $content = apply_filters('the_content', $content);
         $post = $saved_post;
         // cleanup for NGG pre-v2 album shortcode
         unset($GLOBALS['subalbum']);
         unset($GLOBALS['nggShowGallery']);
         // add the sharing buttons filter back, if it was removed
         if ($filter_removed) {
             $this->p->sharing->add_buttons_filter('the_content');
         }
         // add our shortcodes back
         if (!empty($this->p->cf['lib']['shortcode']) && is_array($this->p->cf['lib']['shortcode'])) {
             foreach ($this->p->cf['lib']['shortcode'] as $id => $name) {
                 if (array_key_exists($id, $this->shortcode) && is_object($this->shortcode[$id])) {
                     $this->shortcode[$id]->add();
                 }
             }
         }
     }
     $content = preg_replace('/[\\r\\n\\t ]+/s', ' ', $content);
     // put everything on one line
     $content = preg_replace('/^.*<!--' . $this->p->cf['lca'] . '-content-->(.*)<!--\\/' . $this->p->cf['lca'] . '-content-->.*$/', '$1', $content);
     $content = preg_replace('/<a +rel="author" +href="" +style="display:none;">Google\\+<\\/a>/', ' ', $content);
     $content = str_replace(']]>', ']]&gt;', $content);
     $content_strlen_after = strlen($content);
     $this->p->debug->log('content strlen() before = ' . $content_strlen_before . ', after = ' . $content_strlen_after);
     // apply filters before caching
     $content = apply_filters($this->p->cf['lca'] . '_content', $content);
     if ($filter_content == true && !empty($cache_id)) {
         // only some caching plugins implement this function
         wp_cache_add_non_persistent_groups(array(__METHOD__));
         wp_cache_set($cache_id, $content, __METHOD__, $this->p->cache->object_expire);
         $this->p->debug->log($cache_type . ': ' . $filter_name . ' content saved to wp_cache ' . $cache_id . ' (' . $this->p->cache->object_expire . ' seconds)');
     }
     return $content;
 }
Ejemplo n.º 17
0
        public function get_buttons(&$text, $type = 'content', $use_post = true, $location = '')
        {
            // should we skip the sharing buttons for this content type or webpage?
            if (is_admin()) {
                if (strpos($type, 'admin_') !== 0) {
                    if ($this->p->debug->enabled) {
                        $this->p->debug->log($type . ' filter skipped: ' . $type . ' ignored with is_admin()');
                    }
                    return $text;
                }
            } elseif (is_feed()) {
                if ($this->p->debug->enabled) {
                    $this->p->debug->log($type . ' filter skipped: no buttons allowed in rss feeds');
                }
                return $text;
            } else {
                if (!is_singular() && empty($this->p->options['buttons_on_index'])) {
                    if ($this->p->debug->enabled) {
                        $this->p->debug->log($type . ' filter skipped: index page without buttons_on_index enabled');
                    }
                    return $text;
                } elseif (is_front_page() && empty($this->p->options['buttons_on_front'])) {
                    if ($this->p->debug->enabled) {
                        $this->p->debug->log($type . ' filter skipped: front page without buttons_on_front enabled');
                    }
                    return $text;
                }
                if ($this->is_post_buttons_disabled()) {
                    if ($this->p->debug->enabled) {
                        $this->p->debug->log($type . ' filter skipped: sharing buttons disabled');
                    }
                    return $text;
                }
            }
            if (!$this->have_buttons_for_type($type)) {
                if ($this->p->debug->enabled) {
                    $this->p->debug->log($type . ' filter exiting early: no sharing buttons enabled');
                }
                return $text;
            }
            $lca = $this->p->cf['lca'];
            $obj = $this->p->util->get_post_object($use_post);
            $post_id = empty($obj->ID) || empty($obj->post_type) || !is_singular() && $use_post === false ? 0 : $obj->ID;
            $source_id = $this->p->util->get_source_id($type);
            $html = false;
            if ($this->p->is_avail['cache']['transient']) {
                $cache_salt = __METHOD__ . '(' . apply_filters($lca . '_buttons_cache_salt', 'lang:' . SucomUtil::get_locale() . '_type:' . $type . '_post:' . $post_id . (empty($post_id) ? '_url:' . $this->p->util->get_sharing_url($use_post, true, $source_id) : ''), $type, $use_post) . ')';
                $cache_id = $lca . '_' . md5($cache_salt);
                $cache_type = 'object cache';
                if ($this->p->debug->enabled) {
                    $this->p->debug->log($cache_type . ': transient salt ' . $cache_salt);
                }
                $html = get_transient($cache_id);
            }
            if ($html !== false) {
                if ($this->p->debug->enabled) {
                    $this->p->debug->log($cache_type . ': ' . $type . ' html retrieved from transient ' . $cache_id);
                }
            } else {
                // sort enabled sharing buttons by their preferred order
                $sorted_ids = array();
                foreach ($this->p->cf['opt']['pre'] as $id => $pre) {
                    if (!empty($this->p->options[$pre . '_on_' . $type])) {
                        $sorted_ids[zeroise($this->p->options[$pre . '_order'], 3) . '-' . $id] = $id;
                    }
                }
                ksort($sorted_ids);
                $atts['use_post'] = $use_post;
                $css_type = $atts['css_id'] = $type . '-buttons';
                if (!empty($this->p->options['buttons_preset_' . $type])) {
                    $atts['preset_id'] = $this->p->options['buttons_preset_' . $type];
                    $css_preset = $lca . '-preset-' . $atts['preset_id'];
                } else {
                    $css_preset = '';
                }
                $buttons_html = $this->get_html($sorted_ids, $atts);
                if (trim($buttons_html) !== '') {
                    $html = '
<!-- ' . $lca . ' ' . $css_type . ' begin -->
<div class="' . ($css_preset ? $css_preset . ' ' : '') . ($use_post ? $lca . '-' . $css_type . '">' : '" id="' . $lca . '-' . $css_type . '">') . '
' . $buttons_html . '</div><!-- .' . $lca . '-' . $css_type . ' -->
<!-- ' . $lca . ' ' . $css_type . ' end -->' . "\n\n";
                    if ($this->p->is_avail['cache']['transient']) {
                        set_transient($cache_id, $html, $this->p->options['plugin_object_cache_exp']);
                        if ($this->p->debug->enabled) {
                            $this->p->debug->log($cache_type . ': ' . $type . ' html saved to transient ' . $cache_id . ' (' . $this->p->options['plugin_object_cache_exp'] . ' seconds)');
                        }
                    }
                }
            }
            if (empty($location)) {
                $location = empty($this->p->options['buttons_pos_' . $type]) ? 'bottom' : $this->p->options['buttons_pos_' . $type];
            }
            switch ($location) {
                case 'top':
                    $text = $html . $text;
                    break;
                case 'bottom':
                    $text = $text . $html;
                    break;
                case 'both':
                    $text = $html . $text . $html;
                    break;
            }
            return $text . ($this->p->debug->enabled ? $this->p->debug->get_html() : '');
        }
Ejemplo n.º 18
0
 public function get_buttons(&$text, $type = 'content', $use_post = true)
 {
     // should we skip the sharing buttons for this content type or webpage?
     if (is_admin()) {
         if (strpos($type, 'admin_') !== 0) {
             $this->p->debug->log($type . ' filter skipped: ' . $type . ' ignored with is_admin()');
             return $text;
         }
     } else {
         if (!is_singular() && empty($this->p->options['buttons_on_index'])) {
             $this->p->debug->log($type . ' filter skipped: index page without buttons_on_index enabled');
             return $text;
         } elseif (is_front_page() && empty($this->p->options['buttons_on_front'])) {
             $this->p->debug->log($type . ' filter skipped: front page without buttons_on_front enabled');
             return $text;
         }
         if ($this->is_disabled()) {
             $this->p->debug->log($type . ' filter skipped: buttons disabled');
             return $text;
         }
     }
     if (!$this->have_buttons($type)) {
         $this->p->debug->log($type . ' filter exiting early: no buttons enabled');
         return $text;
     }
     // get the post id for the transient cache salt
     if (($obj = $this->p->util->get_post_object($use_post)) === false) {
         $this->p->debug->log('exiting early: invalid object type');
         return $text;
     }
     $html = false;
     if ($this->p->is_avail['cache']['transient']) {
         // if the post id is 0, then add the sharing url to ensure a unique salt string
         $cache_salt = __METHOD__ . '(lang:' . SucomUtil::get_locale() . '_post:' . $obj->ID . '_type:' . $type . (empty($obj->ID) ? '_url:' . $this->p->util->get_sharing_url(true) : '') . ')';
         $cache_id = $this->p->cf['lca'] . '_' . md5($cache_salt);
         $cache_type = 'object cache';
         $this->p->debug->log($cache_type . ': transient salt ' . $cache_salt);
         $html = get_transient($cache_id);
     }
     if ($html !== false) {
         $this->p->debug->log($cache_type . ': ' . $type . ' html retrieved from transient ' . $cache_id);
     } else {
         // sort enabled sharing buttons by their preferred order
         $sorted_ids = array();
         foreach ($this->p->cf['opt']['pre'] as $id => $pre) {
             if (!empty($this->p->options[$pre . '_on_' . $type])) {
                 $sorted_ids[$this->p->options[$pre . '_order'] . '-' . $id] = $id;
             }
         }
         ksort($sorted_ids);
         $atts['use_post'] = $use_post;
         $css_type = $atts['css_id'] = $type . '-buttons';
         if (!empty($this->p->options['buttons_preset_' . $type])) {
             $atts['preset_id'] = $this->p->options['buttons_preset_' . $type];
         }
         $buttons_html = $this->get_html($sorted_ids, $atts, $this->p->options);
         if (!empty($buttons_html)) {
             $html = '<!-- ' . $this->p->cf['lca'] . ' ' . $css_type . ' begin --><div ' . ($use_post ? 'class' : 'id') . '="' . $this->p->cf['lca'] . '-' . $css_type . '">' . $buttons_html . '</div><!-- ' . $this->p->cf['lca'] . ' ' . $css_type . ' end -->';
             if (!empty($cache_id)) {
                 set_transient($cache_id, $html, $this->p->cache->object_expire);
                 $this->p->debug->log($cache_type . ': ' . $type . ' html saved to transient ' . $cache_id . ' (' . $this->p->cache->object_expire . ' seconds)');
             }
         }
     }
     // just in case
     $buttons_pos = empty($this->p->options['buttons_pos_' . $type]) ? 'bottom' : $this->p->options['buttons_pos_' . $type];
     switch ($buttons_pos) {
         case 'top':
             $text = $html . $text;
             break;
         case 'bottom':
             $text = $text . $html;
             break;
         case 'both':
             $text = $html . $text . $html;
             break;
     }
     return $text . $this->p->debug->get_html();
 }
Ejemplo n.º 19
0
 public function flush_post_cache($post_id)
 {
     switch (get_post_status($post_id)) {
         case 'draft':
         case 'pending':
         case 'future':
         case 'private':
         case 'publish':
             $lang = SucomUtil::get_locale();
             $cache_type = 'object cache';
             $sharing_url = $this->p->util->get_sharing_url($post_id);
             $transients = array('NgfbHead::get_header_array' => array('lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url, 'lang:' . $lang . '_post:' . $post_id . '_url:' . $sharing_url . '_crawler:pinterest'));
             $transients = apply_filters($this->p->cf['lca'] . '_post_cache_transients', $transients, $post_id, $lang, $sharing_url);
             $objects = array('SucomWebpage::get_content' => array('lang:' . $lang . '_post:' . $post_id . '_filtered', 'lang:' . $lang . '_post:' . $post_id . '_unfiltered'), 'SucomWebpage::get_hashtags' => array('lang:' . $lang . '_post:' . $post_id));
             $objects = apply_filters($this->p->cf['lca'] . '_post_cache_objects', $objects, $post_id, $lang, $sharing_url);
             $deleted = $this->flush_cache_objects($transients, $objects);
             if (!empty($this->p->options['plugin_cache_info'])) {
                 $this->p->notice->inf($deleted . ' items removed from the WordPress object and transient caches.', true);
             }
             break;
     }
 }