| 1 |
<?php |
| 2 |
/* |
| 3 |
* License: GPLv3 |
| 4 |
* License URI: https://www.gnu.org/licenses/gpl.txt |
| 5 |
* Copyright 2016-2026 Jean-Sebastien Morisset (https://wpsso.com/) |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
|
| 10 |
die( 'These aren\'t the droids you\'re looking for.' ); |
| 11 |
} |
| 12 |
|
| 13 |
if ( ! class_exists( 'WpssoJsonTypeMovie' ) ) { |
| 14 |
|
| 15 |
class WpssoJsonTypeMovie { |
| 16 |
|
| 17 |
private $p; // Wpsso class object. |
| 18 |
|
| 19 |
/* |
| 20 |
* Instantiated by Wpsso->init_json_filters(). |
| 21 |
*/ |
| 22 |
public function __construct( &$plugin ) { |
| 23 |
|
| 24 |
$this->p =& $plugin; |
| 25 |
|
| 26 |
if ( $this->p->debug->enabled ) { |
| 27 |
|
| 28 |
$this->p->debug->mark(); |
| 29 |
} |
| 30 |
|
| 31 |
$this->p->util->add_plugin_filters( $this, array( |
| 32 |
'json_data_https_schema_org_movie' => 5, |
| 33 |
) ); |
| 34 |
} |
| 35 |
|
| 36 |
public function filter_json_data_https_schema_org_movie( $json_data, $mod, $mt_og, $page_type_id, $is_main ) { |
| 37 |
|
| 38 |
if ( $this->p->debug->enabled ) { |
| 39 |
|
| 40 |
$this->p->debug->mark(); |
| 41 |
} |
| 42 |
|
| 43 |
/* |
| 44 |
* Maybe remove values related to the WordPress post object. |
| 45 |
*/ |
| 46 |
unset( $json_data[ 'author' ] ); |
| 47 |
unset( $json_data[ 'contributor' ] ); |
| 48 |
unset( $json_data[ 'dateCreated' ] ); |
| 49 |
unset( $json_data[ 'datePublished' ] ); |
| 50 |
unset( $json_data[ 'dateModified' ] ); |
| 51 |
|
| 52 |
$json_ret = array(); |
| 53 |
$md_opts = array(); |
| 54 |
|
| 55 |
WpssoSchema::add_type_opts_md_pad( $md_opts, $mod ); |
| 56 |
|
| 57 |
/* |
| 58 |
* Movie Release Date, Time, Timezone. |
| 59 |
* |
| 60 |
* Add the movie released (aka created) date, if one is available. |
| 61 |
*/ |
| 62 |
if ( $date = WpssoSchema::get_opts_date_iso( $md_opts, 'schema_movie_released' ) ) { |
| 63 |
|
| 64 |
$json_ret[ 'dateCreated' ] = $date; |
| 65 |
} |
| 66 |
|
| 67 |
/* |
| 68 |
* See https://schema.org/duration. |
| 69 |
*/ |
| 70 |
WpssoSchema::add_data_time_from_assoc( $json_ret, $md_opts, array( |
| 71 |
'duration' => 'schema_movie_duration', // Option prefix for days, hours, mins, secs. |
| 72 |
) ); |
| 73 |
|
| 74 |
/* |
| 75 |
* See https://schema.org/actor. |
| 76 |
*/ |
| 77 |
WpssoSchema::add_person_names_data( $json_ret, 'actor', $md_opts, 'schema_movie_actor_person_name' ); |
| 78 |
|
| 79 |
/* |
| 80 |
* See https://schema.org/director. |
| 81 |
*/ |
| 82 |
WpssoSchema::add_person_names_data( $json_ret, 'director', $md_opts, 'schema_movie_director_person_name' ); |
| 83 |
|
| 84 |
/* |
| 85 |
* See https://schema.org/productionCompany. |
| 86 |
*/ |
| 87 |
if ( WpssoSchema::is_valid_key( $md_opts, 'schema_movie_prodco_org_id' ) ) { // Not null, an empty string, or 'none'. |
| 88 |
|
| 89 |
$md_val = $md_opts[ 'schema_movie_prodco_org_id' ]; |
| 90 |
|
| 91 |
$org_logo_key = 'org_logo_url'; |
| 92 |
|
| 93 |
WpssoSchemaSingle::add_organization_data( $json_ret[ 'productionCompany' ], $mod, $md_val, $org_logo_key, $list_el = true ); |
| 94 |
} |
| 95 |
|
| 96 |
if ( $this->p->debug->enabled ) { |
| 97 |
|
| 98 |
$this->p->debug->log( 'merging json_data and json_ret arrays' ); |
| 99 |
} |
| 100 |
|
| 101 |
return WpssoSchema::return_data_from_filter( $json_data, $json_ret, $is_main ); |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
|