| Server IP : 121.121.20.254 / Your IP : 216.73.216.202 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/KnowledgeBase/wp-content/plugins/wp-seopress-pro/src/Models/ |
Upload File : |
<?php
namespace SEOPressPro\Models;
if ( ! defined('ABSPATH')) {
exit;
}
use SEOPress\Helpers\RichSnippetType;
use SEOPress\Models\JsonSchemaValue as JsonSchemaValueBase;
/**
* @abstract
*/
abstract class JsonSchemaValue extends JsonSchemaValueBase {
/**
* @since 4.5.0
*
* @param string $file
* @param mixed $name
*
* @return string
*/
public function getJson() {
$file = apply_filters('seopress_get_json_from_file', sprintf('%s/%s.json', SEOPRESS_PRO_TEMPLATE_JSON_SCHEMAS, $this->getName(), '.json'));
if ( ! file_exists($file)) {
return '';
}
$json = file_get_contents($file);
return $json;
}
/**
* @since 4.6.0
*
* @param array $context
*
* @return array|null
*/
public function getCurrentSchemaManual($context) {
if ( ! seopress_get_service('CheckContextPage')->hasSchemaManualValues($context)) {
return null;
}
return $context['schemas_manual'][$context['key_get_json_schema']];
}
/**
* @since 4.7.0
*
* @return array
*/
protected function getKeysForSchemaManual() {
return [];
}
/**
* @since 4.7.0
*
* @return array
*/
protected function getKeysForOptionLocalBusiness() {
return [];
}
/**
* @since 4.7.0
*
* @param array $keys
* @param array $data
*
* @return array
*/
protected function getVariablesByKeysAndData($keys, $data = []) {
$variables = [];
foreach ($keys as $key => $item) {
if (is_string($item)) {
$variables[$key] = isset($data[$item]) ? $data[$item] : '';
} elseif (is_array($item)) {
$variables[$key] = (isset($item['value']) && isset($data[$item['value']]) && ! empty($data[$item['value']])) ? $data[$item['value']] : $item['default'];
}
}
return $variables;
}
/**
* @since 4.7.0
*
* @param string $type
* @param array $context
*
* @return array
*/
public function getVariablesByType($type, $context) {
switch ($type) {
case RichSnippetType::MANUAL:
$data = $this->getCurrentSchemaManual($context);
if (null === $data) {
return [];
}
$keys = $this->getKeysForSchemaManual();
return $this->getVariablesByKeysAndData($keys, $data);
case RichSnippetType::OPTION_LOCAL_BUSINESS:
return $this->getKeysForOptionLocalBusiness();
case RichSnippetType::SUB_TYPE:
return isset($context['variables']) ? $context['variables'] : [];
default:
return [];
}
}
}