HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/hcv/wp-content/themes/hockey/pages/drill-store.php
<?php
/*
 * Template Name: Drill store
 *
 */

$context = Timber::context();

$context['reset_url'] = strtok($_SERVER['REQUEST_URI'], '?');

if(empty($_GET["filter"])){
    $filter = null;
}else{
    $filter = $_GET["filter"];
}

$context['filter'] = $filter;

$filter = $filter == null ? array() : explode(',', $filter);

$url = 'https://hcv-admin-api.azurewebsites.net/articles/drill-store';
$data = array('categories' => $filter);

$options = array(
    'http' => array(
        'header'  => "Content-Type: application/json\r\n",
        'method'  => 'POST',
        'content' => json_encode($data),
        'timeout' => 30,
    )
);
$stream_context  = stream_context_create($options);
$response = file_get_contents($url, false, $stream_context);

$response = json_decode($response);

foreach ($response as $drill){
    //Compare dates
    $post_date  = $drill->created;
    $two_weeks_ago =   strtotime("-14 days");
    $drill->is_new = $post_date > $two_weeks_ago;
}

$response = array_reverse((array)$response);
$context['posts'] = $response;

$set_link = get_field( 'drill_set_page_template','options');
$context['set_link'] = $set_link . '?id=';



$context['filter_age'] = array(
    array(
        'id'  => 'YOUTH',
        'name' => 'Youth',
        'is_chacked'  => in_array('YOUTH', $filter)
    ),
    array(
        'id'  => 'JUNIOR',
        'name' => 'Junior',
        'is_chacked'  => in_array('JUNIOR', $filter)
    ),
    array(
        'id'  => 'PROFESIONAL',
        'name' => 'Profesional',
        'is_chacked'  => in_array('PROFESIONAL', $filter)
    )
);

$context['filter_category'] = array(
    array(
        'id'  => 'FREE',
        'name' => 'Free',
        'is_chacked'  => in_array('FREE', $filter)
    ),
    array(
        'id'  => 'OFF_ICE',
        'name' => 'Off ice',
        'is_chacked'  => in_array('OFF_ICE', $filter)
    ),
    array(
        'id'  => 'INITIATION',
        'name' => 'Initiation',
        'is_chacked'  => in_array('INITIATION', $filter)
    ),
    array(
        'id'  => 'INLINE',
        'name' => 'Inline',
        'is_chacked'  => in_array('INLINE', $filter)
    ),
    array(
        'id'  => 'RINGETTE',
        'name' => 'Ringette',
        'is_chacked'  => in_array('RINGETTE', $filter)
    ),
    array(
        'id'  => 'GOALIE',
        'name' => 'Goalie',
        'is_chacked'  => in_array('GOALIE', $filter)
    ),
    array(
        'id'  => 'VIDEO_CONTENT',
        'name' => 'Video content',
        'is_chacked'  => in_array('VIDEO_CONTENT', $filter)
    ),
    array(
        'id'  => 'ICE_HOCKEY',
        'name' => 'Ice hockey',
        'is_chacked'  => in_array('ICE_HOCKEY', $filter)
    )
    , array(
        'id'  => 'SKILL_DEVELOPMENT',
        'name' => 'Skill development',
        'is_chacked'  => in_array('SKILL_DEVELOPMENT', $filter)
    )
);

Timber::render( array( 'pages/drill-store.twig', 'page.twig' ), $context );