Exemplo n.º 1
0
 public static function add_media_data(&$json_data, $mod, $mt_og, $size_name = false)
 {
     $wpsso =& Wpsso::get_instance();
     /*
      * Property:
      *	image as https://schema.org/ImageObject
      */
     $og_image = array();
     $prev_count = 0;
     $max = $wpsso->util->get_max_nums($mod, 'schema');
     if (empty($size_name)) {
         $size_name = $wpsso->cf['lca'] . '-schema';
     }
     // include any video preview images first
     if (!empty($mt_og['og:video']) && is_array($mt_og['og:video'])) {
         // prevent duplicates - exclude text/html videos
         foreach ($mt_og['og:video'] as $num => $og_video) {
             if (isset($og_video['og:video:type']) && $og_video['og:video:type'] !== 'text/html') {
                 if (SucomUtil::get_mt_media_url($og_video, 'og:image')) {
                     $prev_count++;
                 }
                 $og_image[] = SucomUtil::preg_grep_keys('/^og:image/', $og_video);
             }
         }
         if ($prev_count > 0) {
             $max['schema_img_max'] -= $prev_count;
             if ($wpsso->debug->enabled) {
                 $wpsso->debug->log($prev_count . ' video preview images found (og_img_max adjusted to ' . $max['schema_img_max'] . ')');
             }
         }
     }
     $og_image = array_merge($og_image, $wpsso->og->get_all_images($max['schema_img_max'], $size_name, $mod, true, 'schema'));
     if (!empty($og_image)) {
         $images_added = WpssoSchema::add_image_list_data($json_data['image'], $og_image, 'og:image');
     } else {
         $images_added = 0;
     }
     if (!$images_added && $mod['is_post']) {
         $og_image = $wpsso->media->get_default_image(1, $size_name, true);
         $images_added = WpssoSchema::add_image_list_data($json_data['image'], $og_image, 'og:image');
     }
     if (!$images_added) {
         unset($json_data['image']);
     }
     // prevent null assignment
     /*
      * Property:
      *	video as https://schema.org/VideoObject
      */
     if (!empty($mt_og['og:video'])) {
         WpssoJsonSchema::add_video_list_data($json_data['video'], $mt_og['og:video'], 'og:video');
     }
 }
Exemplo n.º 2
0
 public function filter_json_data_https_schema_org_webpage($json_data, $mod, $mt_og, $type_id, $is_main)
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->mark();
     }
     $ret = array();
     $lca = $this->p->cf['lca'];
     // blogposting is a child of article
     // use the article image size and add the headline property
     if ($this->p->schema->is_schema_type_child_of($type_id, 'article')) {
         $org_logo_key = 'org_banner_url';
         // use a banner for all article sub-types
         $size_name = $this->p->cf['lca'] . '-schema-article';
         // same size, but minimum width is 696px
         /*
          * Property:
          * 	headline
          */
         $headline_max_len = WpssoJsonConfig::$cf['schema']['article']['headline']['max_len'];
         $ret['headline'] = $this->p->webpage->get_title($headline_max_len, '...', $mod);
     } else {
         $org_logo_key = 'org_logo_url';
         $size_name = $this->p->cf['lca'] . '-schema';
     }
     /*
      * Property:
      * 	datepublished
      * 	datemodified
      */
     WpssoSchema::add_data_itemprop_from_assoc($ret, $mt_og, array('datepublished' => 'article:published_time', 'datemodified' => 'article:modified_time'));
     /*
      * Property:
      *	inLanguage
      */
     $ret['inLanguage'] = get_locale();
     /*
      * Property:
      *	publisher as https://schema.org/Organization
      */
     $org_id = is_object($mod['obj']) ? $mod['obj']->get_options($mod['id'], 'schema_pub_org_id') : false;
     // null, false, 'none', 'site', or number (including 0)
     if ($this->p->debug->enabled) {
         $this->p->debug->log('publisher / organization id is ' . (empty($org_id) ? 'empty' : $org_id));
     }
     WpssoSchema::add_single_organization_data($ret['publisher'], $mod, $org_id, $org_logo_key, false);
     // $list_element = false
     /*
      * Property:
      *	author as https://schema.org/Person
      *	contributor as https://schema.org/Person
      */
     WpssoSchema::add_author_coauthor_data($ret, $mod);
     /*
      * Property:
      *	image as https://schema.org/ImageObject
      *	video as https://schema.org/VideoObject
      */
     WpssoJsonSchema::add_media_data($ret, $mod, $mt_og, $size_name);
     if (empty($ret['image'])) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log('creativework image is missing and required');
         }
         if (is_admin() && (!$mod['is_post'] || $mod['post_status'] === 'publish')) {
             $this->p->notice->err($this->p->msgs->get('notice-missing-schema-image'));
         }
     }
     return WpssoSchema::return_data_from_filter($json_data, $ret);
 }