| | |
| | | namespace JVBase\admin; |
| | | |
| | | use JVBase\meta\Form; |
| | | use JVBase\meta\Sanitizer; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\ui\Tabs; |
| | | |
| | |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\MusicRecording' => ' - - Music Recording', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\Photograph' => ' - - Photograph', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\Review' => ' - - Review', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\VisualArtwork\VisualArtwork' => ' - - Visual Artwork', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\Webpage' => ' - - WebPage', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\AboutPage' => ' - - - About Page', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\CheckoutPage' => ' - - - Checkout Page', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\CollectionPage' => ' - - - Collection Page', |
| | | 'JVBase\inc\managers\SEO\render\Thing\CreativeWork\WebPage\CollectionPage\CollectionPage' => ' - - - Collection Page', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\ContactPage' => ' - - - Contact Page', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\FAQPage' => ' - - - FAQ Page', |
| | | 'JVBase\managers\SEO\render\Thing\CreativeWork\WebPage\ItemPage' => ' - - - Item Page', |
| | |
| | | 'sponsor', |
| | | 'containsInPlace', |
| | | 'containsPlace', |
| | | 'openingHours' |
| | | 'openingHours', |
| | | 'id', |
| | | 'ignore', |
| | | ]; |
| | | |
| | | protected array $hints = [ |
| | |
| | | protected function setChecks():void |
| | | { |
| | | $checks = [ |
| | | 'website' |
| | | 'website', |
| | | 'organization' |
| | | ]; |
| | | $this->checks = array_merge($checks, Registrar::getRegistered()); |
| | | } |
| | |
| | | |
| | | public function addDashboardSection(string $content, string $page):string |
| | | { |
| | | if ($page !== 'jvb-seo') { |
| | | if ($page !== 'SEO') { |
| | | return $content; |
| | | } |
| | | ob_start(); |
| | |
| | | $this->renderStyles(); |
| | | } |
| | | } |
| | | private function renderStyles(): void |
| | | { |
| | | jvbInlineStyles('forms'); |
| | | } |
| | | |
| | | public function renderProperty(string $property, ?string $value, mixed $class):void |
| | | { |
| | |
| | | } |
| | | public function renderFieldsFor(string $class, array $stored):void |
| | | { |
| | | $fields = $this->getFieldsFor($class); |
| | | $fields = $this->getFieldsForClass($class); |
| | | $instance = new $class(); |
| | | foreach ($fields as $property => $value) { |
| | | $this->renderProperty($property, $stored[$property]??null, $instance); |
| | | } |
| | | } |
| | | |
| | | public function getFieldsFor(string $class):array |
| | | public function getFieldsForClass(string $class):array |
| | | { |
| | | if (!class_exists($class)) { |
| | | error_log('Class not found: '.$class); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | $_POST['type'] = $type; |
| | | $result = $this->saveFields($action, $type, $_POST); |
| | | |
| | | |
| | |
| | | |
| | | public function saveFields(string $action, string $class, array $data):array |
| | | { |
| | | $action = strtolower($action); |
| | | if (!in_array($action, $this->checks)) { |
| | | error_log('[SEOAdmin]Action is not allowed: '.$action); |
| | | return [ |
| | |
| | | ]; |
| | | } |
| | | |
| | | $allowed = $this->getFieldsFor($class); |
| | | if (empty($allowed)) { |
| | | return [ |
| | | 'jvb_notice' => 'error', |
| | | 'jvb_message' => 'Could not get fields from class' |
| | | ]; |
| | | } |
| | | |
| | | $checked = array_filter($data, function ($item) use ($allowed) { |
| | | return array_key_exists($item, $allowed); |
| | | }, ARRAY_FILTER_USE_KEY); |
| | | |
| | | $stored = get_option(BASE.ucfirst($action).'Schema', []); |
| | | $updates = []; |
| | | foreach ($checked as $property => $value) { |
| | | $sanitized = Sanitizer::sanitize($value, $this->buildConfig($property)); |
| | | if (!array_key_exists($property, $stored) || $stored[$property] !== $sanitized) |
| | | $updates[$property] = $sanitized; |
| | | } |
| | | if (!empty($updates)) { |
| | | $history = get_option(BASE.ucfirst($action).'SchemaHistory', []); |
| | | array_unshift($history, $stored); |
| | | if (count($history) > 5){ |
| | | array_pop($history); |
| | | } |
| | | update_option(BASE.ucfirst($action).'SchemaHistory', $history); |
| | | |
| | | $update = array_merge($stored, $updates); |
| | | update_option(BASE.ucfirst($action).'Schema', $update); |
| | | } |
| | | return [ |
| | | $success = JVB()->schemaHelper()->updateSchema($action, $data); |
| | | return $success ? [ |
| | | 'jvb_notice' => 'success', |
| | | 'jvb_message' => 'Saved changes successfully' |
| | | ] : [ |
| | | 'jvb_notice' => 'error', |
| | | 'jvb_message' => 'Something went wrong...' |
| | | ]; |
| | | } |
| | | } |