| | |
| | | exit; |
| | | } |
| | | |
| | | use JVBase\managers\Cache; |
| | | use JVBase\managers\SEO\render\DataType\Date; |
| | | use JVBase\managers\SEO\render\DataType\DateTime; |
| | | use JVBase\managers\SEO\render\DataType\Time; |
| | | use JVBase\managers\SEO\render\Thing\CreativeWork\MediaObject\ImageObject; |
| | | use JVBase\managers\SEO\render\Thing\Intangible\StructuredValue\PropertyValue; |
| | | use JVBase\managers\SEO\render\Thing\Thing; |
| | | use JVBase\managers\SEO\render\Traits\_Properties\additionalTypeTrait; |
| | | use JVBase\managers\SEO\render\Traits\_Properties\alternateNameTrait; |
| | |
| | | { |
| | | global $wp; |
| | | $current = home_url( add_query_arg( $_GET, $wp->request ) ); |
| | | $id = (isset($this->id)) ? $this->id : $current.'#'.strtolower($this->getTypeName()); |
| | | $id = (isset($this->id)) ? $this->id : $current.'/#'.strtolower($this->getTypeName()); |
| | | $elements = array_map( |
| | | function ($value) { |
| | | |
| | |
| | | } else if (is_a($value, Time::class)) { |
| | | $value = $value->getTime(); |
| | | }else if (!is_string($value)) { |
| | | |
| | | error_log('Normal value? '.print_r($value, true)); |
| | | if (JVB_TESTING && !is_numeric($value)) { |
| | | // error_log('Normal value? '.print_r($value, true)); |
| | | } |
| | | } |
| | | |
| | | return $value; |
| | |
| | | } |
| | | |
| | | public function getId():string { |
| | | return $this->id; |
| | | return $this->id??false; |
| | | } |
| | | public function setId(string $id):void |
| | | { |
| | | if (!filter_var($id, FILTER_VALIDATE_URL)) { |
| | | error_log('[SEO]Could not set id: '.$id.'. Should be a valid URL'); |
| | | return; |
| | | global $wp; |
| | | $id = home_url( add_query_arg( $_GET, $wp->request ) ).'/#'.sanitize_title($id); |
| | | } |
| | | $this->id = $id; |
| | | } |
| | |
| | | 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; |
| | | } |
| | | ); |
| | | |
| | | } |
| | | } |