/data/websites/telefonino/web/app/themes/telefonino/src/AffiliateMarketing/Contents/Components/ProductSearchLinks.php
]
];
private $special_categories = [ 'home', 'videogames', 'elettronica' ];
private $post_id;
private $keyword;
private $categories;
protected $category;
function getData( $product, $offers, $post_id ) {
$this->post_id = $post_id;
$this->categories = $this->getCategories();
$this->category = $this->categories[0]; // non mettere array_shift perché elimineresti il contenuto
$this->keyword = $this->getKeyword();
return (object) [ 'name' => 'product_search_links', 'data' => $this->getSearchLinks() ];
}
/**
* Ritorna un array con gli slug delle categorie
*
* @return array
*/
private function getCategories() {
$categories = wp_get_post_terms( $this->post_id, 'category' );
return array_map( function( $category ) { return $category->slug; }, $categories );
}
/**
/data/websites/telefonino/web/app/themes/telefonino/src/AffiliateMarketing/Contents/Components/ProductSearchLinks.php
]
];
private $special_categories = [ 'home', 'videogames', 'elettronica' ];
private $post_id;
private $keyword;
private $categories;
protected $category;
function getData( $product, $offers, $post_id ) {
$this->post_id = $post_id;
$this->categories = $this->getCategories();
$this->category = $this->categories[0]; // non mettere array_shift perché elimineresti il contenuto
$this->keyword = $this->getKeyword();
return (object) [ 'name' => 'product_search_links', 'data' => $this->getSearchLinks() ];
}
/**
* Ritorna un array con gli slug delle categorie
*
* @return array
*/
private function getCategories() {
$categories = wp_get_post_terms( $this->post_id, 'category' );
return array_map( function( $category ) { return $category->slug; }, $categories );
}
/**
/data/websites/telefonino/web/app/themes/telefonino/src/AffiliateMarketing/Contents/AffiliateContents.php
*
* @return void
*/
protected function getQuery() {
return Utils\StringHelper::slugify( $this->keyword );
}
/**
* Ritorna i dati delle offerte per tutti i content types
*/
function getData () {
return array_reduce ( $this->contentTypes, function( $data, $content ) {
// get the task class
$content = __NAMESPACE__ .'\\Components\\'. $content;
$content_data = ( new $content() )->getData( $this->keyword, $this->offers, $this->product_post_id );
if (!empty($content_data)) {
if (is_array($content_data->data) && array_key_exists(1, $content_data->data)) {
$data[$content_data->name] = array_values($content_data->data);
} else {
$data[$content_data->name] = $content_data->data;
}
}
return $data;
});
}
}
/data/websites/telefonino/web/app/themes/telefonino/src/AffiliateMarketing/Contents/AffiliateContents.php
}
/**
* Serve a comporre la query da inviare all'offerRetriever
*
* @return void
*/
protected function getQuery() {
return Utils\StringHelper::slugify( $this->keyword );
}
/**
* Ritorna i dati delle offerte per tutti i content types
*/
function getData () {
return array_reduce ( $this->contentTypes, function( $data, $content ) {
// get the task class
$content = __NAMESPACE__ .'\\Components\\'. $content;
$content_data = ( new $content() )->getData( $this->keyword, $this->offers, $this->product_post_id );
if (!empty($content_data)) {
if (is_array($content_data->data) && array_key_exists(1, $content_data->data)) {
$data[$content_data->name] = array_values($content_data->data);
} else {
$data[$content_data->name] = $content_data->data;
}
}
return $data;
});
}
}
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Post/Components/AffiliateMarketing/ProductButtons.php
$buttons = array_merge( $search_buttons, $deep_buttons );
return $buttons;
}
/**
* Solo per testare la chiamata diretta alla factory
*
* @return void
*/
private function getDirectData() {
$product = get_post( $this->post_id );
$productButtons = \THEME\AffiliateMarketing\ButtonsFactory::get( $product );
//echo get_class( $productButtons); die;
$data = $productButtons->getData();
return $data;
}
/**
* Ritorna una mappa basata sui marketplace
*
* @param array $offers
* @return array
*/
private function formatDeepButtons( $offers ) {
return array_reduce( $offers, function( $buttons, $offer ) {
if( in_array( strtolower($offer['marketplace']), $this->marketplaces ) ) {
/// ad ogni marketplace associa un link e le sue proprietà
$buttons[ strtolower($offer[ 'marketplace' ]) ] = [
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Post/Components/AffiliateMarketing/ProductButtons.php
public function getData() {
$data = $this->getButtons();
//var_dump( $data ); die;
return (object) [ 'name' => 'product_affiliate_buttons', 'data' => $data ];
}
/**
* Return the links for the buttons
*
* @return array
*/
private function getButtons() {
//$data = $this->getTaskData();
/// SOLO PER TEST -->
$data = $this->getDirectData();
/// ottiene una mappa di deep link basata su marketplace
$deep_buttons = $this->formatDeepButtons( $data['offers'] );
if (isset($data['offers'][0]) && isset($data['offers'][0]["domination"])){
/// tornare creatività domination
return $deep_buttons;
}
/// ottiene una mappa di search link basata su marketplace
$search_buttons = $this->formatSearchButtons( $data );
/// prende i search_link come fallback
$buttons = array_merge( $search_buttons, $deep_buttons );
return $buttons;
}
/**
* Solo per testare la chiamata diretta alla factory
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Post/Components/AffiliateMarketing/ProductButtons.php
'amazon',
'google',
];
/**
*
* @param int $post_id - si riferisce ad un post di post_type = 'prodotti'
*/
public function __construct( $post_id , $versus_post_id = null ) {
$this->post_id = $post_id;
$this->versus_post_id = (is_int($versus_post_id)) ? $versus_post_id : $post_id;
}
public function getData() {
$data = $this->getButtons();
//var_dump( $data ); die;
return (object) [ 'name' => 'product_affiliate_buttons', 'data' => $data ];
}
/**
* Return the links for the buttons
*
* @return array
*/
private function getButtons() {
//$data = $this->getTaskData();
/// SOLO PER TEST -->
$data = $this->getDirectData();
/// ottiene una mappa di deep link basata su marketplace
$deep_buttons = $this->formatDeepButtons( $data['offers'] );
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Single.php
'Taxonomies',
'Credits',
'Canonical',
'StructuredDataFaq',
'AnalysisTracking',
'Meta'
];
}
/**
* Get data from all the components in the
* $components list
*/
private function setComponents() {
foreach($this->components as $component) {
$component = __NAMESPACE__ .'\\Post\Components\\'. $component;
$component_instance = (new $component( $this->post->ID, $this->data ))->getData();
$this->data[$component_instance->name] = $component_instance->data;
}
}
/**
* questa parte deve essere applicata al content
*
* filter the embeds and removes width attributes
*
* va aggiunto ? comunque in content
*//*
protected function removeWidthAttributes(){
$content = $this->data['post']['content'];
$patterns = [
'/width\s*=\s*".*?"/i',
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Single.php
function __construct($post, $postTemplate = 'Single') {
parent::__construct();
$this->post = $post;
// assign the post template (default is 'Single')
$this->postTemplate = $this->postTemplateFactory($postTemplate);
// init the post template
// (includes content details as well)
$this->setPost();
// set the components list into property
// $components
$this->initComponents();
// add all the default components
$this->setComponents();
}
/**
* Writes the basic page info
*/
protected function setPageData(){
$this->data = [
'type' => 'single_post',
'infinite' => 'true'
];
}
/**
* Add the post info to data
*/
protected function setPost() {
$this->data['post'] = $this->postTemplate->getPostData($this->post);
/data/websites/telefonino/web/app/themes/telefonino/single-prodotti.php
<?php
use THEME\ViewModel\SingleProduct;
use THEME\Utils\Timber;
// load data
$data = ( new SingleProduct($posts[0], 'SingleProdotti') )->getData();
$template = 'single-product.twig';
Timber::render( $template, $data );
/data/websites/telefonino/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/telefonino/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/telefonino/web/index.php
<?php
/**
* WordPress View Bootstrapper
*/
define('WP_USE_THEMES', true);
require __DIR__ . '/wp/wp-blog-header.php';