/data/websites/htmlit/web/app/plugins/affiliation/src/Rendering/DirectLink/ImpactAttributes.php
namespace Blazemedia\Affiliation\Rendering\DirectLink;
use Blazemedia\Affiliation\Utils\HttpRequest;
/**
* Sono i parametri per i link diretti
* ( tipicamente Amazon/eBay )
*/
class ImpactAttributes extends Attributes {
protected function setDirectLinkAttributes() {
$this->label = 'Impact';
$this->code = 'impt';
$program = $this->getProgramData();
$this->program = $program->name;
$this->program_suffix = $program->suffix;
$this->subject = $program->subject;
$this->subject_code = $program->subject_code;
$this->theme_label = $program->theme_label;
$this->theme_code = $program->theme_code;
$this->built_url = $program->built_url;
}
protected function getProgramData() {
$impactDomains = $this->getCachedDomains();
usort($impactDomains, function ($a, $b) {
return (strlen($a) > strlen($b)) ? -1 : 1;
});
$programDomain = array_filter($impactDomains, fn ($impactDomain) => str_contains(strtolower($this->url), $impactDomain));
$programDomain = !empty($programDomain) ? array_shift($programDomain) : '';
$program = $this->getCachedProgram($programDomain);
Arguments
"Cannot assign null to property Blazemedia\Affiliation\Rendering\DirectLink\Attributes::$program of type string"
/data/websites/htmlit/web/app/plugins/affiliation/src/Rendering/DirectLink/Attributes.php
*/
abstract class Attributes {
protected $url;
public string $label;
public string $code;
public string $program;
public string $program_suffix;
public string $subject;
public string $subject_code;
public string $theme_label;
public string $theme_code;
public ?string $built_url;
function __construct( string $url ) {
$this->url = $url;
$this->setDirectLinkAttributes();
}
abstract protected function setDirectLinkAttributes();
}
/data/websites/htmlit/web/app/plugins/affiliation/src/Rendering/DirectLink/AttributesFactory.php
<?php
namespace Blazemedia\Affiliation\Rendering\DirectLink;
class AttributesFactory {
public static function get( $platform, $url ) {
$platform = strtolower( $platform );
switch( $platform ) {
case 'amazon' : return new AmazonAttributes( $url );
case 'ebay' : return new EbayAttributes( $url );
case 'awin' : return new AwinAttributes( $url );
case 'tradetracker' : return new TradeTrackerAttributes( $url );
case 'partnerize' : return new PartnerizeAttributes( $url );
case 'primevideo' : return new PrimeVideoAttributes( $url );
case 'impact' : return new ImpactAttributes( $url );
}
}
}
/data/websites/htmlit/web/app/plugins/affiliation/src/Rendering/DirectLink/Params.php
<?php
namespace Blazemedia\Affiliation\Rendering\DirectLink;
trait Params {
/**
* Ricava i parametri per i link inseriti direttamente in pagina
*
* @param string $marketPlace
* @param string $link
* @return array
*/
function getDirectLinkParams( $platform, $link ) {
$link = str_replace( '&', '&', $link );
$attributes = AttributesFactory::get( $platform, $link );
/**
* Nel caso di "Impact" l'url è costruito da alcuni parametri custom del link provider
* ed è passato tramite un parametro "built_url"
*/
if(array_key_exists( 'built_url' , (array) $attributes)){
$link = $attributes->built_url;
}
return [
'format' => $this->format,
'format_id' => 0,
'link_id' => 0,
'extra' => urlencode( json_encode( [
'id' => 0,
'title' => $attributes->label,
'link' => urlencode( $link ),
'subject' => $attributes->subject,
'subject_code' => $attributes->subject_code,
'program' => $attributes->program,
'program_suffix' => $attributes->program_suffix,
/data/websites/htmlit/web/app/plugins/affiliation/src/Rendering/Parse.php
return str_replace([
'{{ placeholder }}'
],[
$placeHolder
],
$url
);
}
/**
* Stampa il formato impostato da shortcode
*/
public function renderLink( $link ) {
$trackedLink = $this->addTrackingIdPlaceholder( $link, 'booBLZTRKood' );
/// ricava i parametri per i link inseriti direttamente in pagina
$directLinkParams = $this->getDirectLinkParams( $link->marketplace, $trackedLink );
$params = $this->pageData->getParams( $directLinkParams );
$this->getFormatData( $params );
return $this->markup;
}
public function insertCSS() { }
}
/data/websites/htmlit/web/app/plugins/affiliation/src/Rendering/Parse.php
}
/**
* Rileva i link all'interno del contenuto
* e li trasforma aggiungendo i dati di affiliazione
*
* @param string $content
* @return string
*/
public function parseLinks( string $content ) {
// conversione degli shortcode da formati precedenti
$content = $this->convert( $content );
$links = $this->parser->parse( $content );
foreach( $links as $link ) {
//! se il link contiene il tag "data-no-affiliate" non viene modificato - modifica per la campagna paid
if(str_contains($link->tag, 'data-no-affiliate='))continue;
$content = str_replace( $link->tag, $this->renderLink( $link ), $content );
}
return $content;
}
protected function addTrackingIdPlaceholder( $link, $placeHolder = 'booBLZTRKood' ) {
switch( strtolower( $link->marketplace ) ) {
case 'amazon' : return $this->addAmazonTrackingIdPlaceholder( $link->url, $placeHolder );
case 'ebay' : return $this->addEbayTrackingIdPlaceholder( $link->url, $placeHolder );
case 'awin' : return $this->addAwinTrackingIdPlaceholder( $link->url, $placeHolder );
case 'tradetracker' : return $this->addTradeTrackerTrackingIdPlaceholder( $link->url, $placeHolder );
case 'partnerize' : return $this->addPartnerizeTrackingIdPlaceholder( $link->url, $placeHolder );
case 'primevideo' : return $this->addPrimeVideoTrackingIdPlaceholder( $link->url, $placeHolder );
case 'impact' : return $this->addImpactTrackingIdPlaceholder( $link->url, $placeHolder );
}
}
protected function addAmazonTrackingIdPlaceholder( $url, $placeHolder ) {
/data/websites/htmlit/web/wp/wp-includes/class-wp-hook.php
$this->iterations[ $nesting_level ] = $this->priorities;
$num_args = count( $args );
do {
$this->current_priority[ $nesting_level ] = current( $this->iterations[ $nesting_level ] );
$priority = $this->current_priority[ $nesting_level ];
foreach ( $this->callbacks[ $priority ] as $the_ ) {
if ( ! $this->doing_action ) {
$args[0] = $value;
}
// Avoid the array_slice() if possible.
if ( 0 === $the_['accepted_args'] ) {
$value = call_user_func( $the_['function'] );
} elseif ( $the_['accepted_args'] >= $num_args ) {
$value = call_user_func_array( $the_['function'], $args );
} else {
$value = call_user_func_array( $the_['function'], array_slice( $args, 0, $the_['accepted_args'] ) );
}
}
} while ( false !== next( $this->iterations[ $nesting_level ] ) );
unset( $this->iterations[ $nesting_level ] );
unset( $this->current_priority[ $nesting_level ] );
--$this->nesting_level;
return $value;
}
/**
* Calls the callback functions that have been added to an action hook.
*
* @since 4.7.0
*
* @param array $args Parameters to pass to the callback functions.
/data/websites/htmlit/web/wp/wp-includes/plugin.php
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
_wp_call_all_hook( $all_args );
}
if ( ! isset( $wp_filter[ $hook_name ] ) ) {
if ( isset( $wp_filter['all'] ) ) {
array_pop( $wp_current_filter );
}
return $value;
}
if ( ! isset( $wp_filter['all'] ) ) {
$wp_current_filter[] = $hook_name;
}
// Pass the value to WP_Hook.
array_unshift( $args, $value );
$filtered = $wp_filter[ $hook_name ]->apply_filters( $value, $args );
array_pop( $wp_current_filter );
return $filtered;
}
/**
* Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
*
* @since 3.0.0
*
* @see apply_filters() This function is identical, but the arguments passed to the
* functions hooked to `$hook_name` are supplied using an array.
*
* @global WP_Hook[] $wp_filter Stores all of the filters and actions.
* @global int[] $wp_filters Stores the number of times each filter was triggered.
* @global string[] $wp_current_filter Stores the list of current filters with the current one last.
*
* @param string $hook_name The name of the filter hook.
* @param array $args The arguments supplied to the functions hooked to `$hook_name`.
/data/websites/htmlit/web/app/themes/htmlit/src/ViewModel/Post/Content/SplittedContent.php
*
* @return Array sections
*/
public function getSections() {
return $this->sections;
}
private function init($content) {
// load all the splitters
$this->getAvailableSplitters();
// cambiare gli shortcode "mutati"
foreach($this->splitters as $splitter)
$content = $splitter->convertShortCode($content);
// applicare gli shortcode "reali"
$content = apply_filters('the_content', $content);
// initialize the content as a big section to split
$this->sections = [
[ 'type' => 'content', '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 );
/data/websites/htmlit/web/app/themes/htmlit/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);
}
/**
* Expose the sections
*
* @return Array sections
*/
public function getSections() {
return $this->sections;
}
private function init($content) {
// load all the splitters
$this->getAvailableSplitters();
// cambiare gli shortcode "mutati"
/data/websites/htmlit/web/app/themes/htmlit/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/htmlit/web/app/themes/htmlit/src/ViewModel/Post/Templates/Single.php
class Single implements iTemplate {
/**
* Basic post data for a generic Single
*
* @param WP_Post $post
* @return array
*/
public function getPostData( $post ) {
$ratings_average = get_post_meta( $post->ID , 'ratings_average', true );
/// 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 ),
'ratings_average' => $ratings_average,
];
/// 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/htmlit/web/app/themes/htmlit/src/ViewModel/Single.php
/**
* Writes the basic page info
*/
protected function setPageData(){
$this->data = [
'type' => 'single_post',
'area' => 'learn',
'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',
'Adv',
'BreadcrumbsPrimary',
'Relateds',
'StructuredData',
'Credits',
'Newsletter',
'Canonical',
'Meta'
];
/data/websites/htmlit/web/app/themes/htmlit/src/ViewModel/Single.php
*/
class Single extends BaseHtmlIt {
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',
'area' => 'learn',
'infinite' => 'true'
/data/websites/htmlit/web/app/themes/htmlit/src/ViewModel/SingleNews.php
<?php
namespace HTML\ViewModel;
use HTML\ViewModel\Single;
/**
* Set data common to all the single contents
*/
class SingleNews extends Single {
protected $infinite = true;
function __construct( $post, $postTemplate = 'Single') {
$this->infinite = !has_tag('no-infinite', $post );
parent::__construct( $post, $postTemplate );
}
/**
* Writes the basic page info
*/
protected function setPageData(){
$this->data = [
'type' => 'single_news',
'area' => 'magazine',
'infinite' => $this->infinite ? 'true' : 'false'
];
}
/**
* set the list of the components
* override this to add or remove components
*/
protected function initComponents() {
$this->components = [
/data/websites/htmlit/web/app/themes/htmlit/single-news.php
<?php
use HTML\ViewModel\SingleNews;
use Timber\Timber;
$is_ajax = ( isset( $_GET['is_ajax_request']) );
$single = ( new SingleNews($post , 'SingleSplittedContent') )->getData();
$template = $is_ajax ? 'singleAjax.twig' : 'single-notizia.twig';
Timber::render( $template, $single );
/data/websites/htmlit/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;
}
Arguments
"/data/websites/htmlit/web/app/themes/htmlit/single-news.php"
/data/websites/htmlit/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';
}
Arguments
"/data/websites/htmlit/web/wp/wp-includes/template-loader.php"
/data/websites/htmlit/web/index.php
<?php
/** WordPress view bootstrapper */
define('WP_USE_THEMES', true);
require __DIR__ . '/wp/wp-blog-header.php';
Arguments
"/data/websites/htmlit/web/wp/wp-blog-header.php"