/data/websites/motori/web/app/themes/motori/src/CarPriceList/Components/ModelData.php
return new ComponentData(self::NAME, $model);
}
protected function getModelData() : array {
$apiBase = BLZ_DB_AUTO;
$data = wp_remote_get( "{$apiBase}/motori.it/brands/{$this->brandSlug}/models/{$this->modelSlug}?d67s", [ 'sslverify' => false ] );
if ( is_wp_error( $data ) ) {
return [];
}
$body = wp_remote_retrieve_body( $data );
$data = json_decode($body, true);
$data['description'] = $data['description'] ? $this->formatText( $data['description'] ) : '';
$data['excerpt'] = $data['excerpt'] ? $data['excerpt'] : '';
return $data;
}
public function getModelCars() {
$apiBase = BLZ_DB_AUTO;
$response = wp_remote_get("{$apiBase}/motori.it/brands/{$this->brandSlug}/models/{$this->modelSlug}/cars", ['sslverify' => false]);
if (is_wp_error($response)) {
return [];
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
/data/websites/motori/web/app/themes/motori/src/CarPriceList/Components/ModelData.php
return new ComponentData(self::NAME, $model);
}
protected function getModelData() : array {
$apiBase = BLZ_DB_AUTO;
$data = wp_remote_get( "{$apiBase}/motori.it/brands/{$this->brandSlug}/models/{$this->modelSlug}?d67s", [ 'sslverify' => false ] );
if ( is_wp_error( $data ) ) {
return [];
}
$body = wp_remote_retrieve_body( $data );
$data = json_decode($body, true);
$data['description'] = $data['description'] ? $this->formatText( $data['description'] ) : '';
$data['excerpt'] = $data['excerpt'] ? $data['excerpt'] : '';
return $data;
}
public function getModelCars() {
$apiBase = BLZ_DB_AUTO;
$response = wp_remote_get("{$apiBase}/motori.it/brands/{$this->brandSlug}/models/{$this->modelSlug}/cars", ['sslverify' => false]);
if (is_wp_error($response)) {
return [];
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
/data/websites/motori/web/app/themes/motori/src/CarPriceList/Components/ModelData.php
// rileva il termine corrente
$termModel = get_term($data->object->term_id);
// Verifica se il termine ha un genitore
if ($termModel && $termModel->parent) {
// Ottieni il termine genitore
$termBrand = get_term($termModel->parent);
}
$this->modelSlug = $termModel->slug;
$this->brandSlug = $termBrand->slug;
}
public function getData() : ComponentData {
$modelData = $this->getModelData();
$modelCars = $this->getModelCars();
// Unisci i due array
$model = array_merge($modelData, $modelCars);
return new ComponentData(self::NAME, $model);
}
protected function getModelData() : array {
$apiBase = BLZ_DB_AUTO;
$data = wp_remote_get( "{$apiBase}/motori.it/brands/{$this->brandSlug}/models/{$this->modelSlug}?d67s", [ 'sslverify' => false ] );
if ( is_wp_error( $data ) ) {
return [];
}
/data/websites/motori/web/app/themes/motori/src/ViewModel/Common/HasComponents.php
<?php
namespace THEME\ViewModel\Common;
trait HasComponents {
protected array $components = []; // list of components that yield data
protected object|null $data = null; // basic data of the current object ( post, term, queried_object, etc.)
protected array $context = []; // data gathered while loading components from the compontent's list
protected function loadComponents() {
foreach($this->components as $component) {
$component_instance = ( new $component( $this->data, $this->context) )->getData();
$this->context[$component_instance->name] = $component_instance->data;
}
}
public function getContext() {
return $this->context;
}
}
/data/websites/motori/web/app/themes/motori/src/ViewModel/Base.php
* expose getContext() to the view
*
*/
abstract class Base {
use HasComponents;
use CanPurgeCachedComponents;
public function __construct() {
$this->context = $this->initContext();
$this->components = array_merge(
$this->listBasicComponents(),
$this->listComponents(),
$this->listStructureComponents()
);
$this->loadComponents();
}
protected function listBasicComponents() : array {
return [
Components\Domain::class,
Components\IsMobile::class,
Components\AssetsDir::class,
Components\GoogleTagManager::class,
Components\Menus::class,
BrandModelList::class,
];
}
/**
* componenti da calcolare sempre dopo l'esecuzione degli
* altri hook
*
* @return array
/data/websites/motori/web/app/themes/motori/src/ViewModel/Archive.php
//protected $archiveTemplate;
protected $paged;
public function __construct( $postTemplate = PostTemplates\Minimal::class, $archiveTemplate = 'Archive' ) {
global $wp_query; // peccato originale avere la wp_query;
$this->data = (object) [
'object' => get_queried_object(),
'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
'tot_pages' => $wp_query->max_num_pages,
'posts' => $wp_query->posts,
];
$this->postTemplate = new $postTemplate ;
parent::__construct();
// set the archiveTemplate (default 'Archive')
// $this->archiveTemplate = $archiveTemplate;
$this->setArticles();
}
/**
* Writes the basic page info
*/
protected function initContext(): array
{
$context = [
'type' => 'archive',
'is_electric' => false,
'infinite' => 'false'
];
// Controlla se lo slug della categoria corrente è 'auto-elettriche'
/data/websites/motori/web/app/themes/motori/taxonomy-listino.php
<?php
use THEME\Utils\Timber;
use THEME\CarPriceList\ViewModel\Brand;
use THEME\CarPriceList\ViewModel\Model;
$term = get_queried_object();
$paged = (get_query_var('paged') && get_query_var('paged') !== 0) ? get_query_var('paged') : 1;
if ( $term->parent ) {
$data = ( new Model )->getContext( $term );
Timber::render( 'single-model.twig', $data );
} else {
// load data
$data = ( new Brand )->getContext();
$template = $paged <= 1 ? 'single-brand.twig' : 'archive-paged.twig';
Timber::render( $template, $data );
}
/data/websites/motori/web/wp/wp-includes/template-loader.php
}
break;
}
}
if ( ! $template ) {
$template = get_index_template();
}
/**
* Filters the path of the current template before including it.
*
* @since 3.0.0
*
* @param string $template The path of the template to include.
*/
$template = apply_filters( 'template_include', $template );
if ( $template ) {
include $template;
} elseif ( current_user_can( 'switch_themes' ) ) {
$theme = wp_get_theme();
if ( $theme->errors() ) {
wp_die( $theme->errors() );
}
}
return;
}
/data/websites/motori/web/wp/wp-blog-header.php
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( ! isset( $wp_did_header ) ) {
$wp_did_header = true;
// Load the WordPress library.
require_once __DIR__ . '/wp-load.php';
// Set up the WordPress query.
wp();
// Load the theme template.
require_once ABSPATH . WPINC . '/template-loader.php';
}
/data/websites/motori/web/index.php
<?php
/**
* WordPress View Bootstrapper
*/
define('WP_USE_THEMES', true);
require __DIR__ . '/wp/wp-blog-header.php';