Files
andaira/src/AndairaSite.php
2025-07-29 11:08:33 +00:00

198 lines
5.4 KiB
PHP

<?php
namespace App;
use Timber\Site;
use Timber\Timber;
use Twig\Environment;
use Twig\TwigFilter;
\Routes::map('equipo/:slug', function($params){
$query = '';
\Routes::load('team-member.php', $params, $query, 200);
});
\Routes::map('actualidad', function($params){
$query = '';
\Routes::load('actualidad.php', $params, $query, 200);
});
\Routes::map('proyectos', function($params){
$query = '';
\Routes::load('proyectos.php', $params, $query, 200);
});
class AndairaSite extends Site {
public $enable_ua = true;
function __construct() {
add_action('after_setup_theme', array($this, 'theme_supports'));
//$this->recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
//$this->recaptcha_secret = '6Ldp7-cUAAAAALND-F6N211yRaam8jBF_W_jkzg_';
//$this->recaptcha_public = '6Ldp7-cUAAAAANJ68d2DomQJn-TbnUxfVPNHm95K';
//$this->CONTACT_FORM = dirname( __FILE__ ).'/templates/form_contact.html';
add_filter('timber/context', array($this, 'add_to_context'));
add_filter('timber/twig/environment/options', [$this, 'update_twig_environment_options']);
add_filter('timber/twig', array($this, 'add_to_twig'));
add_action('wp_enqueue_scripts', [$this,'load_assets']);
parent::__construct();
}
public function theme_supports()
{
add_theme_support('automatic-feed-links');
add_theme_support( 'disable-layout-styles' );
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_theme_support(
'html5',
[
'gallery',
'caption',
]
);
add_theme_support(
'post-formats',
array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'audio',
)
);
add_theme_support('menus');
}
function update_twig_environment_options($options)
{
// $options['autoescape'] = true;
return $options;
}
public function add_to_twig($twig)
{
$twig->addFunction(
new \Twig\TwigFunction( 'frontpage_posts', [$this, 'frontpage_posts'] )
);
$twig->addFunction(
new \Twig\TwigFunction( 'posts_by_term', [$this, 'posts_by_term'] )
);
$twig->addFunction(
new \Twig\TwigFunction( 'posts_by_type', [$this, 'posts_by_type'] )
);
$twig->addFunction(
new \Twig\TwigFunction( 'posts_by_service', 'posts_by_service' )
);
return $twig;
}
public function frontpage_posts($numberposts=-1,$template_name='frontpage_post.twig')
{
$args = [
'posts_per_page' => $numberposts,
'post_type' => 'post',
];
$ctx = [
'posts' => Timber::get_posts( $args )
];
return Timber::fetch($template_name, $ctx);
}
public function posts_by_type($post_type, $numberposts=8, $template_name='posts_by_taxonomy.twig')
{
$args = [
'post_type' => $post_type,
'posts_per_page' => $numberposts,
];
$ctx = [
'posts' => Timber::get_posts( $args ),
];
return Timber::fetch($template_name, $ctx);
}
public function posts_by_term($taxonomy_slug, $term_slug, $numberposts=8, $post_type='post', $template_name='posts_by_taxonomy.twig')
{
$args = [
'post_type' => $post_type,
'posts_per_page' => $numberposts,
'tax_query' => [
[
'taxonomy' => $taxonomy_slug,
'field' => 'slug',
'terms' => $term_slug,
],
]
];
$ctx = [
'posts' => Timber::get_posts( $args ),
'taxonomy' => get_taxonomy($taxonomy_slug),
'term' => get_term($term_slug, $taxonomy_slug),
];
return Timber::fetch($template_name, $ctx);
}
function add_to_context( $context ) {
// $context = parent::add_to_context($context);
// Servicios
$svs = array(
'child_of' => 27,
'parent' => 27,
'hierarchical' => 0,
'sort_column' => 'menu_order',
'sort_order' => 'asc',
'post_type' => 'page',
'post_status' => 'publish',
);
$servicios = get_pages( $svs );
// dump($servicios);
$context['servicios'] = Timber::get_posts($servicios);
//return $context;
// Areas
$areas = get_terms( [
'taxonomy' => 'category',
'parent' => 29,
'hide_empty' => false,
]
);
//dump($areas);
$context['areas'] = $areas;
//Logotipos
$context['logotipo_cabecera'] = get_field('logotipo_cabecera', 'option');
return $context;
}
function load_assets() {
$version = 4;
// $version_for_app = $version;
$version_for_app = time();
wp_enqueue_style( 'twbsi', get_template_directory_uri() . '/assets/css/bootstrap.min.css', [], $version, 'all');
//wp_enqueue_style( 'lust', get_template_directory_uri() . '/style.css', [], $version, 'all');
// wp_enqueue_script( 'pop', get_template_directory_uri() . '/static/popper.min.js', [], $version, false);
// wp_enqueue_script( 'twbs', get_template_directory_uri() . '/vendor/twbs/bootstrap/dist/js/bootstrap.min.js', [], $version, false);
// wp_enqueue_script( 'lust', get_template_directory_uri() . '/assets/scripts/site.js', [], $version, false);
}
}