本文整理汇总了PHP中SucomUtil::crawler_name方法的典型用法代码示例。如果您正苦于以下问题:PHP SucomUtil::crawler_name方法的具体用法?PHP SucomUtil::crawler_name怎么用?PHP SucomUtil::crawler_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SucomUtil
的用法示例。
在下文中一共展示了SucomUtil::crawler_name方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter_head_cache_salt
public function filter_head_cache_salt($salt, $use_post = false)
{
switch (SucomUtil::crawler_name()) {
case 'pinterest':
$salt .= '_crawler:' . SucomUtil::crawler_name();
break;
}
return $salt;
}
示例2: __construct
public function __construct(&$plugin)
{
$this->p =& $plugin;
$this->p->util->add_img_sizes_from_opts(array('og_img' => 'opengraph', 'rp_img' => 'opengraph-rp'));
switch (SucomUtil::crawler_name()) {
case 'pinterest':
$this->size_name = $this->p->cf['lca'] . '-opengraph-rp';
break;
default:
$this->size_name = $this->p->cf['lca'] . '-opengraph';
break;
}
add_filter('language_attributes', array(&$this, 'add_doctype'));
}
示例3: __construct
public function __construct(&$plugin)
{
$this->p =& $plugin;
switch (SucomUtil::crawler_name()) {
case 'pinterest':
$this->meta_pre = 'rp';
$this->size_name = $this->p->cf['lca'] . '-richpin';
break;
default:
$this->meta_pre = 'og';
$this->size_name = $this->p->cf['lca'] . '-opengraph';
break;
}
$this->p->util->add_plugin_filters($this, array('plugin_image_sizes' => 1));
add_filter('language_attributes', array(&$this, 'add_doctype'));
}
示例4: crawler_name
public static function crawler_name($id = '')
{
if (self::$crawler_name === false) {
// optimize perf - only check once
$str = $_SERVER['HTTP_USER_AGENT'];
switch (true) {
// "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"
case strpos($str, 'facebookexternalhit/') === 0:
self::$crawler_name = 'facebook';
break;
// "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
// "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
case strpos($str, 'compatible; Googlebot/') !== false:
self::$crawler_name = 'google';
break;
// "Pinterest/0.1 +http://pinterest.com/"
// "Pinterest/0.1 +http://pinterest.com/"
case strpos($str, 'Pinterest/') === 0:
self::$crawler_name = 'pinterest';
break;
// "Twitterbot/1.0"
// "Twitterbot/1.0"
case strpos($str, 'Twitterbot/') === 0:
self::$crawler_name = 'twitter';
break;
// "W3C_Validator/1.3 http://validator.w3.org/services"
// "W3C_Validator/1.3 http://validator.w3.org/services"
case strpos($str, 'W3C_Validator/') === 0:
self::$crawler_name = 'w3c';
break;
}
}
if (!empty($id)) {
return $id === self::$crawler_name ? true : false;
} else {
return self::$crawler_name;
}
}
示例5: __construct
public function __construct(&$plugin)
{
$this->p =& $plugin;
$crawler_name = SucomUtil::crawler_name();
if ($this->p->debug->enabled) {
$this->p->debug->mark();
}
add_filter('amp_post_template_metadata', array(&$this, 'filter_amp_post_template_metadata'), 9000, 2);
// pinterest does not (currently) read json markup
switch ($crawler_name) {
case 'pinterest':
break;
default:
$this->p->util->add_plugin_filters($this, array('add_schema_head_attributes' => '__return_false', 'add_schema_meta_array' => '__return_false', 'add_schema_noscript_array' => '__return_false', 'json_data_https_schema_org_thing' => 5), -100);
// make sure we run first
break;
}
$this->p->util->add_plugin_filters($this, array('get_md_defaults' => 2));
if (is_admin()) {
$this->p->util->add_plugin_actions($this, array('admin_post_head' => 1));
$this->p->util->add_plugin_filters($this, array('option_type' => 2, 'save_post_options' => 4, 'post_cache_transients' => 4, 'pub_google_rows' => 2));
$this->p->util->add_plugin_filters($this, array('messages_tooltip_meta' => 2, 'status_gpl_features' => 3, 'status_pro_features' => 3), 10, 'wpssojson');
}
}
示例6: get_array
//.........这里部分代码省略.........
$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);
}
示例7: get_array
//.........这里部分代码省略.........
}
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);
}
示例8: get_article_author
public function get_article_author($author_id, $url_field = 'og_author_field')
{
$ret = array();
if (!empty($author_id)) {
$ret[] = $this->get_author_website_url($author_id, $this->p->options[$url_field]);
// add the author's name if this is the Pinterest crawler
if (SucomUtil::crawler_name('pinterest') === true) {
$ret[] = $this->get_author_name($author_id, $this->p->options['rp_author_name']);
}
} elseif ($this->p->debug->enabled) {
$this->p->debug->log('author_id provided is empty');
}
return $ret;
}
示例9: get_author_profile_url
public function get_author_profile_url($author_ids, $url_field = 'og_author_field')
{
$ret = array();
if (!empty($author_ids)) {
if (!is_array($author_ids)) {
$author_ids = array($author_ids);
}
foreach ($author_ids as $author_id) {
if (!empty($author_id)) {
if (SucomUtil::crawler_name('pinterest') === true) {
$ret[] = $this->get_author_name($author_id, $this->p->options['rp_author_name']);
} else {
$ret[] = $this->get_author_website_url($author_id, $this->p->options[$url_field]);
}
}
}
}
return $ret;
}