コード例 #1
0
ファイル: webpage.php プロジェクト: leotaillard/btws2016
 public function get_caption($type = 'title', $textlen = 200, $use_post = true, $use_cache = true, $add_hashtags = true, $encode = true, $md_idx = true, $src_id = '')
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->args(array('type' => $type, 'textlen' => $textlen, 'use_post' => $use_post, 'use_cache' => $use_cache, 'add_hashtags' => $add_hashtags, 'encode' => $encode, 'md_idx' => $md_idx, 'src_id' => $src_id));
     }
     $caption = false;
     $separator = html_entity_decode($this->p->options['og_title_sep'], ENT_QUOTES, get_bloginfo('charset'));
     if ($md_idx === true) {
         switch ($type) {
             case 'title':
                 $md_idx = 'og_title';
                 break;
             case 'excerpt':
                 $md_idx = 'og_desc';
                 break;
             case 'both':
                 $md_idx = 'og_caption';
                 break;
         }
     }
     if (is_singular() || $use_post !== false) {
         if (($obj = $this->p->util->get_post_object($use_post)) === false) {
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('exiting early: invalid object type');
             }
             return $caption;
         }
         $post_id = empty($obj->ID) || empty($obj->post_type) ? 0 : $obj->ID;
     }
     // skip if no metadata index / key name
     if (!empty($md_idx)) {
         if (is_singular() || $use_post !== false) {
             if (!empty($post_id)) {
                 $caption = $this->p->util->get_mod_options('post', $post_id, $md_idx);
             }
             if (!empty($caption) && !empty($add_hashtags) && !preg_match('/( #[a-z0-9\\-]+)+$/U', $caption)) {
                 $hashtags = $this->get_hashtags($post_id, $add_hashtags);
                 if (!empty($hashtags)) {
                     $caption = $this->p->util->limit_text_length($caption, $textlen - strlen($hashtags) - 1, '...', false) . ' ' . $hashtags;
                 }
             }
         } elseif (SucomUtil::is_term_page()) {
             $term = $this->p->util->get_term_object();
             if (!empty($term->term_id)) {
                 $caption = $this->p->util->get_mod_options('taxonomy', $term->term_id, $md_idx);
             }
         } elseif (SucomUtil::is_author_page()) {
             $author = $this->p->util->get_author_object();
             if (!empty($author->ID)) {
                 $caption = $this->p->util->get_mod_options('user', $author->ID, $md_idx);
             }
         }
     }
     if (empty($caption)) {
         if (!empty($md_idx)) {
             $md_prefix = preg_replace('/_(title|desc|caption)$/', '', $md_idx);
             $md_title = $md_prefix . '_title';
             $md_desc = $md_prefix . '_desc';
         } else {
             $md_title = $md_desc = $md_idx;
         }
         // request all values un-encoded, then encode once we have the complete caption text
         switch ($type) {
             case 'title':
                 $caption = $this->get_title($textlen, '...', $use_post, $use_cache, $add_hashtags, false, $md_title, $src_id);
                 break;
             case 'excerpt':
                 $caption = $this->get_description($textlen, '...', $use_post, $use_cache, $add_hashtags, false, $md_desc, $src_id);
                 break;
             case 'both':
                 $prefix = $this->get_title(0, '', $use_post, $use_cache, false, false, $md_title, $src_id) . ' ' . $separator . ' ';
                 $caption = $prefix . $this->get_description($textlen - strlen($prefix), '...', $use_post, $use_cache, $add_hashtags, false, $md_desc, $src_id);
                 break;
         }
     }
     if ($encode === true) {
         $caption = wp_encode_emoji(htmlentities($caption, ENT_QUOTES, get_bloginfo('charset'), false));
     } else {
         // just in case
         $charset = get_bloginfo('charset');
         $caption = html_entity_decode(SucomUtil::decode_utf8($caption), ENT_QUOTES, $charset);
     }
     return apply_filters($this->p->cf['lca'] . '_caption', $caption, $use_post, $add_hashtags, $md_idx, $src_id);
 }
コード例 #2
0
 public function get_caption($type = 'title', $length = 200, $use_post = true, $use_cache = true, $add_hashtags = true, $encode = true, $custom_idx = 'og_title', $source_id = '')
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->args(array('type' => $type, 'length' => $length, 'use_post' => $use_post, 'use_cache' => $use_cache, 'add_hashtags' => $add_hashtags, 'encode' => $encode, 'custom_idx' => $custom_idx, 'source_id' => $source_id));
     }
     $caption = false;
     $separator = html_entity_decode($this->p->options['og_title_sep'], ENT_QUOTES, get_bloginfo('charset'));
     if (is_singular() || $use_post !== false) {
         if (($obj = $this->p->util->get_post_object($use_post)) === false) {
             if ($this->p->debug->enabled) {
                 $this->p->debug->log('exiting early: invalid object type');
             }
             return $caption;
         }
         $post_id = empty($obj->ID) || empty($obj->post_type) ? 0 : $obj->ID;
         if (!empty($post_id)) {
             $caption = $this->p->util->get_mod_options('post', $post_id, $custom_idx);
         }
     } elseif (SucomUtil::is_term_page()) {
         $term = $this->p->util->get_term_object();
         if (!empty($term->term_id)) {
             $caption = $this->p->util->get_mod_options('taxonomy', $term->term_id, $custom_idx);
         }
     } elseif (SucomUtil::is_author_page()) {
         $author = $this->p->util->get_author_object();
         if (!empty($author->ID)) {
             $caption = $this->p->util->get_mod_options('user', $author->ID, $custom_idx);
         }
     }
     if (empty($caption)) {
         $custom_prefix = preg_replace('/_(title|desc|caption)$/', '', $custom_idx);
         // request all values un-encoded, then encode once we have the complete caption text
         switch (strtolower($type)) {
             case 'title':
                 $caption = $this->get_title($length, '...', $use_post, $use_cache, $add_hashtags, false, $custom_prefix . '_title', $source_id);
                 break;
             case 'excerpt':
                 $caption = $this->get_description($length, '...', $use_post, $use_cache, $add_hashtags, false, $custom_prefix . '_desc', $source_id);
                 break;
             case 'both':
                 $prefix = $this->get_title(0, '', $use_post, $use_cache, false, false, $custom_prefix . '_title', $source_id) . ' ' . $separator . ' ';
                 $caption = $prefix . $this->get_description($length - strlen($prefix), '...', $use_post, $use_cache, $add_hashtags, false, $custom_prefix . '_desc', $source_id);
                 break;
         }
     }
     if ($encode === true) {
         $caption = htmlentities($caption, ENT_QUOTES, get_bloginfo('charset'), false);
     } else {
         // just in case
         $charset = get_bloginfo('charset');
         $caption = html_entity_decode(SucomUtil::decode_utf8($caption), ENT_QUOTES, $charset);
     }
     return apply_filters($this->p->cf['lca'] . '_caption', $caption, $use_post, $add_hashtags, $custom_idx, $source_id);
 }