当前位置: 首页>>代码示例>>PHP>>正文


PHP SucomUtil::meta_image_tags方法代码示例

本文整理汇总了PHP中SucomUtil::meta_image_tags方法的典型用法代码示例。如果您正苦于以下问题:PHP SucomUtil::meta_image_tags方法的具体用法?PHP SucomUtil::meta_image_tags怎么用?PHP SucomUtil::meta_image_tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SucomUtil的用法示例。


在下文中一共展示了SucomUtil::meta_image_tags方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_term_images

 public function get_term_images($num = 0, $size_name = 'thumbnail', $term_id, $check_dupes = true, $force_regen = false, $meta_pre = 'og', $tag_pre = 'og')
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->args(array('num' => $num, 'size_name' => $size_name, 'term_id' => $term_id, 'check_dupes' => $check_dupes, 'force_regen' => $force_regen, 'meta_pre' => $meta_pre, 'tag_pre' => $tag_pre));
     }
     $meta_ret = array();
     $meta_image = SucomUtil::meta_image_tags($tag_pre);
     if (empty($term_id)) {
         return $meta_ret;
     }
     foreach (apply_filters($this->p->cf['lca'] . '_term_image_ids', array(), $term_id) as $pid) {
         if ($pid > 0) {
             list($meta_image[$tag_pre . ':image'], $meta_image[$tag_pre . ':image:width'], $meta_image[$tag_pre . ':image:height'], $meta_image[$tag_pre . ':image:cropped'], $meta_image[$tag_pre . ':image:id']) = $this->p->media->get_attachment_image_src($pid, $size_name, $check_dupes, $force_regen);
             if (!empty($meta_image[$tag_pre . ':image']) && $this->p->util->push_max($meta_ret, $meta_image, $num)) {
                 return $meta_ret;
             }
         }
     }
     return $meta_ret;
 }
开发者ID:eugene-gromky-co,项目名称:mindfulnesssummit,代码行数:20,代码来源:taxonomy.php

示例2: get_content_images

 public function get_content_images($num = 0, $size_name = 'thumbnail', $post_id = 0, $check_dupes = true, $content = '')
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->args(array('num' => $num, 'size_name' => $size_name, 'post_id' => $post_id, 'check_dupes' => $check_dupes, 'content' => strlen($content) . ' chars'));
     }
     $og_ret = array();
     $og_image = SucomUtil::meta_image_tags('og');
     $size_info = $this->get_size_info($size_name);
     // allow custom content to be passed as argument
     if (empty($content)) {
         $content = $this->p->webpage->get_content($post_id, false);
     }
     // use_post = false
     if (empty($content)) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log('exiting early: empty post content');
         }
         return $og_ret;
     }
     // img attributes in order of preference
     // data_tags_preg provides a filter hook for 3rd party modules like ngg to return image information
     if (preg_match_all('/<(' . $this->data_tags_preg . '[^>]*? ' . $this->data_attr_preg . '=[\'"]([0-9]+)[\'"]|' . '(img)[^>]*? (data-share-src|src)=[\'"]([^\'"]+)[\'"])[^>]*>/s', $content, $match, PREG_SET_ORDER)) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log(count($match) . ' x matching <' . $this->data_tags_preg . '/> html tag(s) found');
         }
         foreach ($match as $img_num => $img_arr) {
             $tag_value = $img_arr[0];
             if (empty($img_arr[5])) {
                 $tag_name = $img_arr[2];
                 // img
                 $attr_name = $img_arr[3];
                 // data-wp-pid
                 $attr_value = $img_arr[4];
                 // id
             } else {
                 $tag_name = $img_arr[5];
                 // img
                 $attr_name = $img_arr[6];
                 // data-share-src|src
                 $attr_value = $img_arr[7];
                 // url
             }
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('match ' . $img_num . ': ' . $tag_name . ' ' . $attr_name . '="' . $attr_value . '"');
             }
             switch ($attr_name) {
                 case 'data-wp-pid':
                     list($og_image['og:image'], $og_image['og:image:width'], $og_image['og:image:height'], $og_image['og:image:cropped'], $og_image['og:image:id']) = $this->get_attachment_image_src($attr_value, $size_name, false);
                     break;
                     // filter hook for 3rd party modules to return image information
                 // filter hook for 3rd party modules to return image information
                 case preg_match('/^data-[a-z]+-pid$/', $attr_name) ? true : false:
                     $filter_name = $this->p->cf['lca'] . '_get_content_' . $tag_name . '_' . preg_replace('/-/', '_', $attr_name);
                     list($og_image['og:image'], $og_image['og:image:width'], $og_image['og:image:height'], $og_image['og:image:cropped'], $og_image['og:image:id']) = apply_filters($filter_name, array(null, null, null, null), $attr_value, $size_name, false);
                     break;
                 default:
                     // prevent duplicates by silently ignoring ngg images (already processed by the ngg module)
                     if ($this->p->is_avail['media']['ngg'] === true && !empty($this->p->mods['media']['ngg']) && (strpos($tag_value, " class='ngg-") !== false || preg_match('/^' . $this->p->mods['media']['ngg']->img_src_preg . '$/', $attr_value))) {
                         break;
                     }
                     // stop here
                     // recognize gravatar images in the content
                     if (preg_match('/^https?:\\/\\/([^\\.]+\\.)?gravatar\\.com\\/avatar\\/[a-zA-Z0-9]+/', $attr_value, $match)) {
                         $og_image['og:image'] = $match[0] . '?s=' . $size_info['width'] . '&d=404&r=G';
                         $og_image['og:image:width'] = $size_info['width'];
                         $og_image['og:image:height'] = $size_info['width'];
                         // square image
                         break;
                         // stop here
                     }
                     $og_image = array('og:image' => $attr_value, 'og:image:width' => -1, 'og:image:height' => -1);
                     // try and get the width and height from the image attributes
                     if (!empty($og_image['og:image'])) {
                         if (preg_match('/ width=[\'"]?([0-9]+)[\'"]?/i', $tag_value, $match)) {
                             $og_image['og:image:width'] = $match[1];
                         }
                         if (preg_match('/ height=[\'"]?([0-9]+)[\'"]?/i', $tag_value, $match)) {
                             $og_image['og:image:height'] = $match[1];
                         }
                     }
                     $is_sufficient_width = $og_image['og:image:width'] >= $size_info['width'] ? true : false;
                     $is_sufficient_height = $og_image['og:image:height'] >= $size_info['height'] ? true : false;
                     // make sure the image width and height are large enough
                     if ($attr_name == 'data-share-src' || $attr_name == 'src' && empty($this->p->options['plugin_ignore_small_img']) || $attr_name == 'src' && $size_info['crop'] === 1 && $is_sufficient_width && $is_sufficient_height || $attr_name == 'src' && $size_info['crop'] !== 1 && ($is_sufficient_width || $is_sufficient_height)) {
                         // data-share-src attribute used and/or image size is acceptable
                         // check for relative urls, just in case
                         $og_image['og:image'] = $this->p->util->fix_relative_url($og_image['og:image']);
                     } else {
                         if ($this->p->debug->enabled) {
                             $this->p->debug->log('image rejected: width / height attributes missing or too small for ' . $size_name);
                             if (is_admin()) {
                                 $this->p->notice->err('Image ' . $og_image['og:image'] . ' rejected - width / height missing or too small for ' . $size_name . '.');
                             }
                         }
                         $og_image = array();
                     }
                     break;
             }
             if (!empty($og_image['og:image']) && ($check_dupes === false || $this->p->util->is_uniq_url($og_image['og:image'], $size_name))) {
                 if ($this->p->util->push_max($og_ret, $og_image, $num)) {
//.........这里部分代码省略.........
开发者ID:jamesvillarrubia,项目名称:uniken-web,代码行数:101,代码来源:media.php

示例3: get_content_images

 public function get_content_images($num = 0, $size_name = 'thumbnail', $post_id = 0, $check_dupes = true, $content = '')
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->args(array('num' => $num, 'size_name' => $size_name, 'post_id' => $post_id, 'check_dupes' => $check_dupes, 'content' => strlen($content) . ' chars'));
     }
     $og_ret = array();
     // allow custom content to be passed as argument
     if (empty($content)) {
         $content_provided = false;
         $content = $this->p->webpage->get_content($post_id, false);
         // use_post = false
     } else {
         $content_provided = true;
     }
     if (empty($content)) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log('exiting early: empty post content');
         }
         return $og_ret;
     }
     $og_image = SucomUtil::meta_image_tags('og');
     $size_info = $this->get_size_info($size_name);
     $img_preg = $this->default_img_preg;
     // allow the html_tag and pid_attr regex to be modified
     foreach (array('html_tag', 'pid_attr') as $type) {
         $filter_name = $this->p->cf['lca'] . '_content_image_preg_' . $type;
         if (has_filter($filter_name)) {
             $img_preg[$type] = apply_filters($filter_name, $this->default_img_preg[$type]);
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('filtered image preg ' . $type . ' = \'' . $img_preg[$type] . '\'');
             }
         }
     }
     // img attributes in order of preference
     if (preg_match_all('/<((' . $img_preg['html_tag'] . ')[^>]*? (' . $img_preg['pid_attr'] . ')=[\'"]([0-9]+)[\'"]|' . '(img)[^>]*? (data-share-src|src)=[\'"]([^\'"]+)[\'"])[^>]*>/s', $content, $all_matches, PREG_SET_ORDER)) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log(count($all_matches) . ' x matching <' . $img_preg['html_tag'] . '/> html tag(s) found');
         }
         foreach ($all_matches as $img_num => $img_arr) {
             $tag_value = $img_arr[0];
             if (empty($img_arr[5])) {
                 $tag_name = $img_arr[2];
                 // img
                 $attr_name = $img_arr[3];
                 // data-wp-pid
                 $attr_value = $img_arr[4];
                 // id
             } else {
                 $tag_name = $img_arr[5];
                 // img
                 $attr_name = $img_arr[6];
                 // data-share-src|src
                 $attr_value = $img_arr[7];
                 // url
             }
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('match ' . $img_num . ': ' . $tag_name . ' ' . $attr_name . '="' . $attr_value . '"');
             }
             switch ($attr_name) {
                 // wordpress media library image id
                 case 'data-wp-pid':
                     list($og_image['og:image'], $og_image['og:image:width'], $og_image['og:image:height'], $og_image['og:image:cropped'], $og_image['og:image:id']) = $this->get_attachment_image_src($attr_value, $size_name, false);
                     break;
                     // check for other data attributes like 'data-ngg-pid'
                 // check for other data attributes like 'data-ngg-pid'
                 case preg_match('/^' . $img_preg['pid_attr'] . '$/', $attr_name) ? true : false:
                     // build a filter hook for 3rd party modules to return image information
                     $filter_name = $this->p->cf['lca'] . '_get_content_' . $tag_name . '_' . preg_replace('/-/', '_', $attr_name);
                     list($og_image['og:image'], $og_image['og:image:width'], $og_image['og:image:height'], $og_image['og:image:cropped'], $og_image['og:image:id']) = apply_filters($filter_name, array(null, null, null, null, null), $attr_value, $size_name, false);
                     break;
                 default:
                     // prevent duplicates by silently ignoring ngg images (already processed by the ngg module)
                     if ($this->p->is_avail['media']['ngg'] === true && !empty($this->p->mods['media']['ngg']) && (preg_match('/ class=[\'"]ngg[_-]/', $tag_value) || preg_match('/^(' . $img_preg['ngg_src'] . ')$/', $attr_value))) {
                         break;
                     }
                     // stop here
                     // recognize gravatar images in the content
                     if (preg_match('/^https?:\\/\\/([^\\.]+\\.)?gravatar\\.com\\/avatar\\/[a-zA-Z0-9]+/', $attr_value, $match)) {
                         $og_image['og:image'] = $match[0] . '?s=' . $size_info['width'] . '&d=404&r=G';
                         $og_image['og:image:width'] = $size_info['width'];
                         $og_image['og:image:height'] = $size_info['width'];
                         // square image
                         break;
                         // stop here
                     }
                     // check for image ID in class for old content w/o the data-wp-pid attribute
                     if (preg_match('/class="[^"]+ wp-image-([0-9]+)/', $tag_value, $match)) {
                         list($og_image['og:image'], $og_image['og:image:width'], $og_image['og:image:height'], $og_image['og:image:cropped'], $og_image['og:image:id']) = $this->get_attachment_image_src($match[1], $size_name, false);
                         break;
                         // stop here
                     } else {
                         $og_image = array('og:image' => $attr_value, 'og:image:width' => -1, 'og:image:height' => -1);
                     }
                     // try and get the width and height from the image attributes
                     if (!empty($og_image['og:image'])) {
                         if (preg_match('/ width=[\'"]?([0-9]+)[\'"]?/i', $tag_value, $match)) {
                             $og_image['og:image:width'] = $match[1];
                         }
                         if (preg_match('/ height=[\'"]?([0-9]+)[\'"]?/i', $tag_value, $match)) {
                             $og_image['og:image:height'] = $match[1];
//.........这里部分代码省略.........
开发者ID:leotaillard,项目名称:btws2016,代码行数:101,代码来源:media.php

示例4: get_meta_image

 public function get_meta_image($num = 0, $size_name = 'thumbnail', $id, $check_dupes = true, $force_regen = false, $meta_pre = 'og', $tag_pre = 'og')
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->args(array('num' => $num, 'size_name' => $size_name, 'id' => $id, 'check_dupes' => $check_dupes, 'force_regen' => $force_regen, 'meta_pre' => $meta_pre, 'tag_pre' => $tag_pre), get_class($this));
     }
     $meta_ret = array();
     $meta_image = SucomUtil::meta_image_tags($tag_pre);
     if (empty($id)) {
         return $meta_ret;
     }
     foreach (array_unique(array($meta_pre, 'og')) as $prefix) {
         $pid = $this->get_options($id, $prefix . '_img_id');
         $pre = $this->get_options($id, $prefix . '_img_id_pre');
         $url = $this->get_options($id, $prefix . '_img_url');
         if ($pid > 0) {
             $pid = $pre === 'ngg' ? 'ngg-' . $pid : $pid;
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('using custom ' . $prefix . ' image id = "' . $pid . '"', get_class($this));
             }
             // log extended class name
             list($meta_image[$tag_pre . ':image'], $meta_image[$tag_pre . ':image:width'], $meta_image[$tag_pre . ':image:height'], $meta_image[$tag_pre . ':image:cropped'], $meta_image[$tag_pre . ':image:id']) = $this->p->media->get_attachment_image_src($pid, $size_name, $check_dupes, $force_regen);
         }
         if (empty($meta_image[$tag_pre . ':image']) && !empty($url)) {
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('using custom ' . $prefix . ' image url = "' . $url . '"', get_class($this));
             }
             // log extended class name
             list($meta_image[$tag_pre . ':image'], $meta_image[$tag_pre . ':image:width'], $meta_image[$tag_pre . ':image:height'], $meta_image[$tag_pre . ':image:cropped'], $meta_image[$tag_pre . ':image:id']) = array($url, -1, -1, -1, -1);
         }
         if (!empty($meta_image[$tag_pre . ':image']) && $this->p->util->push_max($meta_ret, $meta_image, $num)) {
             return $meta_ret;
         }
     }
     return $meta_ret;
 }
开发者ID:jamesvillarrubia,项目名称:uniken-web,代码行数:35,代码来源:meta.php


注:本文中的SucomUtil::meta_image_tags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。