request ) ); $id = (isset($this->id)) ? $this->id : $current.'/#'.strtolower($this->getTypeName()); $elements = array_map( function ($value) { if (is_a($value, Thing::class)) { return $value->outputSchema(); } elseif (is_array($value)) { $temp = []; foreach ($value as $v) { if (is_a($v, Thing::class)) { $temp[] = $v->outputSchema(); } else { $temp[] = $v; } } return $temp; }elseif (is_a($value, DateTime::class)) { $value = $value->getDateTime(); }else if (is_a($value, Date::class)) { $value = $value->getDate(); } else if (is_a($value, Time::class)) { $value = $value->getTime(); }else if (!is_string($value)) { if (JVB_TESTING && !is_numeric($value)) { // error_log('Normal value? '.print_r($value, true)); } } return $value; }, array_filter(get_object_vars($this), function ($property) { return !in_array($property, $this->ignore); }, ARRAY_FILTER_USE_KEY) ); return array_merge([ '@type' => $this->getTypeName(), '@id' => $id, ], array_filter($elements)); } public function getTypeName():string { return (new \ReflectionClass($this))->getShortName(); } public function getProperties():array { $properties = get_class_vars(self::class); $remove = [ 'mappedMethods' ]; return array_filter($properties, function($property) use ($remove) { return !in_array($property, $remove); }, ARRAY_FILTER_USE_KEY); } public static function fromArray(array $config):self { $instance = new self(); foreach ($config as $key => $value) { if (!property_exists($instance, $key)){ error_log('[SEO]Could not instantiate '.get_class($instance).' property: '.$key); continue; } $instance->$key = $value; } return $instance; } public function getId():string { return $this->id??false; } public function setId(string $id):void { if (!filter_var($id, FILTER_VALIDATE_URL)) { global $wp; $id = home_url( add_query_arg( $_GET, $wp->request ) ).'/#'.sanitize_title($id); } $this->id = $id; } public function delete(string $property):void { if (property_exists($this, $property)) { unset($this->$property); } } public static function createImageFromID(int $ID):ImageObject|false { $cache = Cache::for('schemaImage')->connect('post'); return $cache->remember( $ID, function() use($ID) { $imagePost = get_post($ID); if (!$imagePost) { return false; } $image = wp_get_attachment_image_src($ID,'full'); if (empty($image)) { return false; } $imageObject = new ImageObject(); $imageObject->setUploadDate($imagePost->post_date); $imageObject->setWidth($image[1]); $imageObject->setHeight($image[2]); $imageObject->setContentUrl($image[0]); $caption = wp_get_attachment_caption($ID); if (!empty($caption)) { $imageObject->setCaption($caption); } return $imageObject; } ); } }