/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/Content/SplittedContentParts/Winner.php
$content = str_replace(["”","″"], "\"", $content);
preg_match_all('/(.*)(\[winner-id value="(.*?)"\])(.*)/s', $content, $info_split);
if ( empty( $info_split[0] ) ) return [];
$winner_label = get_field("model_winner",$this->post->ID);
if (!empty($winner_label)) {
$winner = ($winner_label == "prodotto_a") ? get_field("model_a",$this->post->ID) : get_field("model_b",$this->post->ID);
$id_winner = $this->getProduct($winner)->ID;
}else{
$id_winner = $info_split[3][0];
if (empty($id_winner)) return [];
}
if( empty( $id_winner )) {
return [];
}
$winner = new SmartphoneVersusButton( $id_winner );
$offer = $winner->getData();
if (!empty($offer["offers"])) {
$offer = $offer["offers"][0];
}else{
if (isset($offer["product_search_links"]["amazon"])) {
$offer = $offer["product_search_links"]["amazon"];
$offer["marketplace"] = "amazon";
}elseif (isset($offer["product_search_links"]["ebay"])) {
$offer = $offer["product_search_links"]["ebay"];
$offer["marketplace"] = "ebay";
}else{
return [];
}
}
$link = $offer['link'];
$cta = '<div class="best_price_btn"><div class="bpb_container"><div class="bpb_cta">Acquistalo su</div></div><div class="bpb_logo"><img class="align_'.$offer["marketplace"].'" src="/app/themes/telefonino/assets/mtz/'.$offer["marketplace"].'_logo.png" alt="Offerta '.$offer["marketplace"].'"></div></div>';
if (isset($offer["domination"]) && $offer["domination"] == "true" )
$cta = '<div class="best_price_btn"><div class="bpb_container"><div class="bpb_cta">'.$offer['call_to_action'].'</div></div><div class="bpb_logo"><img class="align_'.strtolower($offer["marketplace"]).'" src="https://'.$offer["merchant_logo"].'" alt="Offerta '.$offer["marketplace"].'"></div></div>';
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Post/Content/SplittedContent.php
* Recursive method that divides
* progressively the contents into
* smaller, specialized sections
*
* according with the given splitter
* component
*
* @param Object $splitter
*/
private function splitSections($splitter) {
$splits = [];
// split content sections and
// keep track of their positions in the array
foreach ($this->sections as $idx => $section) {
if ($section['type'] == 'content') {
$split = $splitter->split($section);
if (!empty($split)) {
$splits[] = (object) ['idx' => $idx , 'sections' => $split ];
}
}
}
// replace old sections with the splitted ones
// starting from the bottom to the top
foreach (array_reverse($splits) as $split)
array_splice($this->sections, $split->idx, 1, $split->sections);
// no more splits exit the recursive loop
if (empty($splits))
return;
// else do another ride
else
$this->splitSections($splitter);
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Post/Content/SplittedContent.php
private function init($content) {
// load all the splitters
$this->getAvailableSplitters();
// cambiare gli shortcode "mutati"
foreach($this->splitters as $splitter){
$content = $splitter->convertShortCode($content);
}
// initialize the content as a big section to split
$this->sections = [
[ 'type' => 'content', 'content' => apply_filters('the_content', $content) ]
];
foreach ($this->splitters as $splitter) {
$this->splitSections($splitter);
}
}
/**
* Return the list of the splitters
*/
private function getAvailableSplitters() {
// una reflection un po' accroccata ma funzionale
$composer = require get_template_directory() . '/vendor/composer/autoload_classmap.php';
$namespaces = array_keys($composer);
$splitters = array_filter( $namespaces, function($item){
return str_starts_with($item, "THEME\\ViewModel\\Post\\Content\\SplittedContentParts\\") && !str_ends_with($item, 'iSplittedContentPart');
});
$this->splitters = array_map( function( $splitter ) { return new $splitter($this->post_id); } , $splitters );
}
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Post/Content/SplittedContent.php
* @param content:string - is the content to split
* @param post_id:int - the current post id
*
* getSections() - Array with the sequence of content sections to print
* each one indentified with a type and a content
*
* splitContent() - activate the splitter on a new content
*/
class SplittedContent
{
private $splitters;
private $sections = [];
private $post_id = 0;
function __construct($post) {
$this->post_id = $post->ID;
$this->init( $post->post_content );
}
/**
* Fix momentaneo per risolvere il problema di compatibilità con LeadPack
*
* @param string $content
* @return string
*/
function filtroH2LeadPack( string $content ) : string {
$pos = strrpos($content, "[disclaimer]");
return $content . ( $pos === false ? "[disclaimer]" : '' );
}
/**
* Expose the sections
*
* @return Array sections
*/
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Post/Templates/SingleSplittedContent.php
*
public function getPostData($post) {
$processedPost = parent::getPostData($post);
$processedPost['content'] = $this->getContent($post);
return $processedPost;
}
*/
/**
* Returns the content as a list (array) of splitted sections
*
* @param WP_Post $post
* @return array
*/
protected function getContent( $post ) {
return ( new SplittedContent( $post ) )->getSections();
}
}
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Post/Templates/Single.php
use THEME\ViewModel\Post\Content\FeaturedImage;
class Single implements iTemplate {
/**
* Basic post data for a generic Single
*
* @param WP_Post $post
* @return array
*/
public function getPostData( $post ) {
/// basic post data
$postData = [
'id' => $post->ID,
'title' => $post->post_title,
'excerpt' => $post->post_excerpt,
'content' => $this->getContent( $post ),
'image' => $this->getImage( $post ),
'pubdate' => $this->getDate("post_date", $post ),
'moddate' => $this->getDate("post_modified", $post ),
'tags' => $this->getTags( $post ),
'link' => get_the_permalink( $post ),
'categories' => $this->getCategories( $post )
];
/// add post_meta to basic data
$customFields = $this->getCustomFields( $post );
if( is_array( $customFields ) && !empty( $customFields ) ) {
$postData = array_merge( $postData, $customFields );
}
return $postData;
}
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Single.php
}
/**
* 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);
}
/**
* set the list of the components
* override this to add or remove components
*/
protected function initComponents() {
$this->components = [
'Author',
'Taxonomies',
'Credits',
'Canonical',
'StructuredDataFaq',
'AnalysisTracking',
'Meta'
];
}
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Single.php
*/
class Single extends Base {
protected $post;
protected $postTemplate;
protected $components;
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'
];
/data/websites/telefonino/web/app/themes/telefonino/single-confronti.php
<?php
use THEME\ViewModel\SingleVersus;
use THEME\Utils\Timber;
// load data
$data = ( new SingleVersus($posts[0], 'SingleSplittedContent') )->getData();
$template = 'single-versus.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';