/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Archive/Components/Author.php
}
function getData() {
$author_id = get_the_author_meta('ID');
/** @var \WP_User $author */
$author = get_user_by('ID', get_the_author_meta('ID'));
$user_data['data'] = $author->data;
$user_data['display_name'] = $author->display_name;
$user_data['avatar'] = $this->takeProdAvatarImage( get_field('immagine_autore', 'user_'.$author_id) );
$user_data['author_image']['url'] = get_avatar_url(get_the_author_meta('ID'));
$user_data['description'] = get_the_author_meta('description', get_the_author_meta('ID'));
return (object) [ 'name' => $this->name, 'data' => $user_data];
}
private function takeProdAvatarImage( $avatar ) {
$avatar[ 'url' ] = $this->takeProdImgUrl( $avatar[ 'url' ] );
$avatar_keys = empty($avatar['sizes']) ? [] : array_keys( $avatar['sizes'] );
foreach( $avatar_keys as $key ) {
$avatar['sizes'][$key] = $this->takeProdImgUrl( $avatar['sizes'][$key] );
}
return $avatar;
}
private function takeProdImgUrl( $url ){
return str_replace( [ 'staging','new','local','preprod' ], 'www', $url );
}
}
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Archive/Components/Author.php
}
function getData() {
$author_id = get_the_author_meta('ID');
/** @var \WP_User $author */
$author = get_user_by('ID', get_the_author_meta('ID'));
$user_data['data'] = $author->data;
$user_data['display_name'] = $author->display_name;
$user_data['avatar'] = $this->takeProdAvatarImage( get_field('immagine_autore', 'user_'.$author_id) );
$user_data['author_image']['url'] = get_avatar_url(get_the_author_meta('ID'));
$user_data['description'] = get_the_author_meta('description', get_the_author_meta('ID'));
return (object) [ 'name' => $this->name, 'data' => $user_data];
}
private function takeProdAvatarImage( $avatar ) {
$avatar[ 'url' ] = $this->takeProdImgUrl( $avatar[ 'url' ] );
$avatar_keys = empty($avatar['sizes']) ? [] : array_keys( $avatar['sizes'] );
foreach( $avatar_keys as $key ) {
$avatar['sizes'][$key] = $this->takeProdImgUrl( $avatar['sizes'][$key] );
}
return $avatar;
}
private function takeProdImgUrl( $url ){
return str_replace( [ 'staging','new','local','preprod' ], 'www', $url );
}
}
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Archive/Components/Author.php
namespace THEME\ViewModel\Archive\Components;
class Author implements iComponent {
private $name = 'author';
private $pageData;
function __construct($pageData) {
$this->pageData = $pageData;
}
function getData() {
$author_id = get_the_author_meta('ID');
/** @var \WP_User $author */
$author = get_user_by('ID', get_the_author_meta('ID'));
$user_data['data'] = $author->data;
$user_data['display_name'] = $author->display_name;
$user_data['avatar'] = $this->takeProdAvatarImage( get_field('immagine_autore', 'user_'.$author_id) );
$user_data['author_image']['url'] = get_avatar_url(get_the_author_meta('ID'));
$user_data['description'] = get_the_author_meta('description', get_the_author_meta('ID'));
return (object) [ 'name' => $this->name, 'data' => $user_data];
}
private function takeProdAvatarImage( $avatar ) {
$avatar[ 'url' ] = $this->takeProdImgUrl( $avatar[ 'url' ] );
$avatar_keys = empty($avatar['sizes']) ? [] : array_keys( $avatar['sizes'] );
foreach( $avatar_keys as $key ) {
$avatar['sizes'][$key] = $this->takeProdImgUrl( $avatar['sizes'][$key] );
}
return $avatar;
}
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Archive.php
$this->components = [
'Pagination',
'BreadcrumbsYoastNoLeaf',
'CustomTitle',
'Adv',
];
}
/**
* Get data from all the components in the
* $components list
*/
protected function setComponents() {
foreach($this->components as $component) {
//load local components or the common ones
$componentClass = __NAMESPACE__ .'\\Archive\Components\\'. $component;
$component_instance = (new $componentClass($this->data))->getData();
$this->data[$component_instance->name] = $component_instance->data;
}
}
/**
* archiveTemplateFactory
*
* @param [string] $archiveTemplate
* @return [object] the instance of an archive template
*/
protected function archiveTemplateFactory( $archiveTemplate ) {
$class= __NAMESPACE__ . '\\Archive\Templates\\' . $archiveTemplate;
return new $class;
}
}
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/Archive.php
parent::__construct();
// set the postTemplate (default 'Archive')
$this->postTemplate = $this->postTemplateFactory( $postTemplate );
// set the archiveTemplate (default 'Archive')
$this->archiveTemplate = $this->archiveTemplateFactory( $archiveTemplate );
// add the current term's data
$this->setTerm( $obj_type );
// add the articles to data
$this->setArticles();
// set the components list into property
// $components
$this->initComponents();
// add all the default components
$this->setComponents();
}
/**
* Writes the basic page informations
*/
protected function setPageData(){
$this->data = [
'type' => 'archive',
'infinite' => 'true',
];
}
/**
* Add the data of the current term or post type or author
*
* @return void
*/
protected function setTerm( $object_type = 'WP_Term' ) {
/data/websites/telefonino/web/app/themes/telefonino/src/ViewModel/ArchiveAuthor.php
<?php
namespace THEME\ViewModel;
use THEME\ViewModel\Post\Templates\ArchiveGuide as GuideTemplate;
use THEME\ViewModel\Post\Templates\Archive as NewsTemplate;
/**
* Populate the data
* using the given post-template
*/
class ArchiveAuthor extends Archive {
protected $guidesTemplate;
/// inutile se non si aggiunge nulla ma probabile ch de
function __construct( $postTemplate = 'Archive', $archiveTemplate = 'Author') {
parent::__construct( $postTemplate, $archiveTemplate );
}
/**
* Writes the basic page informations
*/
protected function setPageData(){
$this->data = [
'type' => 'archive_author',
'infinite' => 'false'
];
}
/*protected function setArticles() {
// $this->setGuides();
// $this->setNews();
}*/
/data/websites/telefonino/web/app/themes/telefonino/author.php
if( is_admin() || $query->is_main_query() ) return;
if ($query->is_author()){
$cpts = [ 'prodotti', 'prodotto', 'notizie', 'guide' ];
$query->set( 'post_type', $cpts );
return;
}
return;
}
$paged = ( get_query_var('paged') && get_query_var('paged') !== 0 ) ? get_query_var('paged') : 1;
$data = ( new ArchiveAuthor() )->getData();
$template = ( $paged == 1 ) ? 'archive-author.twig' : 'archive-author-paged.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';