Esempio n. 1
0
 public function get_single_mt($tag = 'meta', $type = 'property', $name, $value = '', $cmt = '', $use_post = false)
 {
     // known exceptions for the 'property' $type
     if ($tag === 'meta' && $type === 'property' && (strpos($name, 'twitter:') === 0 || strpos($name, ':') === false)) {
         $type = 'name';
     }
     $ret = array();
     $attr = $tag === 'link' ? 'href' : 'content';
     $log_pre = $tag . ' ' . $type . ' ' . $name;
     $charset = get_bloginfo('charset');
     if (is_array($value)) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log($log_pre . ' value is an array (skipped)');
         }
         return $ret;
     } elseif (is_object($value)) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log($log_pre . ' value is an object (skipped)');
         }
         return $ret;
     }
     if (strpos($value, '%%')) {
         $value = $this->p->util->replace_inline_vars($value, $use_post);
     }
     switch ($name) {
         case 'og:image':
         case 'og:image:url':
         case 'og:video':
         case 'og:video:url':
             // add secure_url meta tag for open graph images and videos
             if (strpos($value, 'https://') === 0) {
                 $secure_value = $value;
                 $secure_name = preg_replace('/:url$/', '', $name) . ':secure_url';
                 $value = preg_replace('/^https:/', 'http:', $value);
                 $ret[] = array('', $tag, $type, $secure_name, $attr, $secure_value, $cmt);
             }
             break;
     }
     $ret[] = array('', $tag, $type, $name, $attr, $value, $cmt);
     // filtering of single meta tags can be enabled by defining NGFB_FILTER_SINGLE_TAGS as true
     if (defined('NGFB_FILTER_SINGLE_TAGS') && NGFB_FILTER_SINGLE_TAGS) {
         $ret = $this->filter_single_mt($ret, $use_post);
     }
     // $parts = array( $html, $tag, $type, $name, $attr, $value, $cmt );
     foreach ($ret as $num => $parts) {
         $log_pre = $parts[1] . ' ' . $parts[2] . ' ' . $parts[3];
         if ($this->p->debug->enabled) {
             $this->p->debug->log($log_pre . ' = "' . $parts[5] . '"');
         }
         if ($parts[5] === '' || $parts[5] === null) {
             // allow for 0
             if ($this->p->debug->enabled) {
                 $this->p->debug->log($log_pre . ' value is empty (skipped)');
             }
         } elseif ($parts[5] == -1) {
             // -1 is reserved
             if ($this->p->debug->enabled) {
                 $this->p->debug->log($log_pre . ' value is -1 (skipped)');
             }
         } elseif (!empty($this->p->options['add_' . $parts[1] . '_' . $parts[2] . '_' . $parts[3]])) {
             // change meta itemtype "image.url" to "url" (for example)
             if ($parts[1] === 'meta' && $parts[2] === 'itemprop' && strpos($parts[3], '.') !== 0) {
                 $parts[3] = preg_replace('/^.*\\./', '', $parts[3]);
             }
             switch ($parts[3]) {
                 case 'og:url':
                 case 'og:image':
                 case 'og:image:url':
                 case 'og:image:secure_url':
                 case 'og:video':
                 case 'og:video:url':
                 case 'og:video:url:secure_url':
                 case 'og:video:url:embed_url':
                 case 'twitter:image':
                 case 'twitter:player':
                 case 'canonical':
                 case 'url':
                     $parts[5] = SucomUtil::esc_url_encode($parts[5]);
                     break;
                 case 'og:title':
                 case 'og:description':
                 case 'twitter:title':
                 case 'twitter:description':
                 case 'description':
                 case 'name':
                     $parts[5] = wp_encode_emoji(htmlentities($parts[5], ENT_QUOTES, $charset, false));
                     // double_encode = false
                 // double_encode = false
                 default:
                     $parts[5] = htmlentities($parts[5], ENT_QUOTES, $charset, false);
                     // double_encode = false
                     break;
             }
             $parts[0] = (empty($parts[6]) ? '' : '<!-- ' . $parts[6] . ' -->') . '<' . $parts[1] . ' ' . $parts[2] . '="' . $parts[3] . '" ' . $parts[4] . '="' . $parts[5] . '"/>' . "\n";
             $ret[$num] = $parts;
         } elseif ($this->p->debug->enabled) {
             $this->p->debug->log($log_pre . ' is disabled (skipped)');
         }
     }
     return $ret;
 }