HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
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/quadcodewordpressapi/public/wp-content/themes/intentionally-blank/functions.php
<?php

require_once __DIR__ . '/lib/blankTheme.php';
require_once __DIR__ . '/lib/api.php';

function mb_str_word_count($str, $format = 0): int
{
    $pattern = '#[\p{L}\p{N}]+#u';
    preg_match_all($pattern, $str, $matches);
    return count($matches[0]);
}

function getWordsNumber(string $content): int
{
    return mb_str_word_count(wp_strip_all_tags($content));
}

function getEstReadingTime(string $content, string $lang = 'en'): int
{
    // Based on GPT reading speed analysis
    $wordsPerMinute = [
        'en' => 228,
        'ru' => 184,
        'es' => 181,
        'pt' => 181,
        'ko' => 195,
        'vi' => 200,
        'th' => 249,
    ];

    $wordsPerMinute = $wordsPerMinute[$lang];
    $words = getWordsNumber($content);

    return round($words / $wordsPerMinute) > 0 ? round($words / $wordsPerMinute)  : 1; // If post is very short, return 1 minute
}

add_shortcode('quoteAuthor', 'quoteAuthorShortCode');
function quoteAuthorShortCode($atts, $content)
{
    $html = '<blockquote>' . $content;

    if (!empty($atts['id'])) {
        $userId = $atts['id'];

        $author = get_user_by('id', $userId);
        if (!empty($author)) {
            $position = get_field('position', 'user_' . $userId);
            $avatar = get_field('avatar', 'user_' . $userId);
            $linkedinLink = get_user_meta($userId, 'linkedin', true);
            // Available fields: facebook instagram myspace pinterest soundcloud tumblr twitter youtube wikipedia

            $html .= '<footer>';
            $html .= '<img src="' . $avatar['sizes']['thumbnail'] . '" alt=\"\">';
            $html .= '<div>';
            $html .= '<p>';
            $html .= $author->data->display_name;
            if (!empty($linkedinLink)) {
                $html .= '<a href="' . $linkedinLink . '">';
                $html .= '<svg width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">';
                $html .= '<rect x="6" y="6" width="18" height="18" rx="2" fill="#323232"/>';
                $html .= '<path d="M12.8164 13.6025H11.1012V18.9998H12.8164V13.6025Z" fill="white"/>';
                $html .= '<path d="M11.9703 11C11.3834 11 11 11.4036 11 11.9324C11 12.4502 11.3718 12.8647 11.9475 12.8647H11.9586C12.5567 12.8647 12.9289 12.45 12.9289 11.9324C12.9178 11.4034 12.5567 11 11.9702 11H11.9703Z" fill="white"/>';
                $html .= '<path d="M17.0253 13.4755C16.1152 13.4755 15.7082 13.9989 15.4799 14.3666V13.6028H13.7653C13.788 14.1087 13.7653 18.9999 13.7653 18.9999H15.4799V15.9854C15.4799 15.824 15.491 15.6628 15.5368 15.5475C15.6606 15.2252 15.9429 14.8915 16.4167 14.8915C17.0368 14.8915 17.2853 15.3866 17.2853 16.1115V18.9995H19.0001V15.9048C18.9997 14.2467 18.1536 13.4755 17.0253 13.4755Z" fill="white"/>';
                $html .= '</svg>';
                $html .= '</a>';
            }
            $html .= '</p>';
            if (!empty($position)) {
                $html .= '<span>' . $position . '</span>';
            }
            $html .= '</div>';
            $html .= '</footer>';
        }
    }
    $html .= '</blockquote>';

    return $html;
}

add_shortcode('quote', 'quoteShortCode');
function quoteShortCode(array $attributes): string
{
    $quoteId = $attributes['id'] ?? null;
    if (empty($quoteId)) {
        return '';
    }
    $quoteId--;

    $postId = get_the_ID();
    $quotes = get_field('quotes', $postId);
    if (empty($quotes) || empty($quotes[$quoteId])) {
        return '';
    }
    $quote = $quotes[$quoteId];

    $html = '<blockquote>' . $quote['quote'];
    $html .= '<footer>';
    $html .= '<img src="' . $quote['avatar'] . '">';
    $html .= '<div>';
    $html .= '<p>';
    $html .= $quote['name'];
    if (!empty($quote['linkedin'])) {
        $html .= '<a href="' . $quote['linkedin'] . '">';
        $html .= '<svg width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">';
        $html .= '<rect x="6" y="6" width="18" height="18" rx="2" fill="#323232"/>';
        $html .= '<path d="M12.8164 13.6025H11.1012V18.9998H12.8164V13.6025Z" fill="white"/>';
        $html .= '<path d="M11.9703 11C11.3834 11 11 11.4036 11 11.9324C11 12.4502 11.3718 12.8647 11.9475 12.8647H11.9586C12.5567 12.8647 12.9289 12.45 12.9289 11.9324C12.9178 11.4034 12.5567 11 11.9702 11H11.9703Z" fill="white"/>';
        $html .= '<path d="M17.0253 13.4755C16.1152 13.4755 15.7082 13.9989 15.4799 14.3666V13.6028H13.7653C13.788 14.1087 13.7653 18.9999 13.7653 18.9999H15.4799V15.9854C15.4799 15.824 15.491 15.6628 15.5368 15.5475C15.6606 15.2252 15.9429 14.8915 16.4167 14.8915C17.0368 14.8915 17.2853 15.3866 17.2853 16.1115V18.9995H19.0001V15.9048C18.9997 14.2467 18.1536 13.4755 17.0253 13.4755Z" fill="white"/>';
        $html .= '</svg>';
        $html .= '</a>';
    }
    $html .= '</p>';
    if (!empty($quote['position'])) {
        $html .= '<span>' . $quote['position'] . '</span>';
    }
    $html .= '</div>';
    $html .= '</footer>';
    $html .= '</blockquote>';

    return $html;
}

add_shortcode('video', 'videoShortCode');
function videoShortCode(array $attributes): string
{
    $videoId = $attributes['id'] ?? null;
    if (empty($videoId)) {
        return '';
    }
    $videoId--;

    $postId = get_the_ID();
    $videos = get_field('youtube_video', $postId);

    if (empty($videos) || !is_array($videos) || empty($videos[$videoId])) {
        return '';
    }
    $video = $videos[$videoId];

    $lang = !empty($_GET['lang']) ? $_GET['lang'] : 'en';
    $translation = getPostTranslation($postId, $lang);
    if (!empty($translation) && !empty($translation[0])) {
        $translation = $translation[0];
        if (property_exists($translation, 'post_attributes') && $translation->post_attributes != '') {
            $attributes = unserialize($translation->post_attributes);
            if (!empty($attributes['youtube_video']) && is_array($attributes['youtube_video']) && !empty($attributes['youtube_video'][$videoId])) {
                $video = $attributes['youtube_video'][$videoId];
            }
        }
    }

    $html = '<div class="videoBlock">' . (!empty($video['quote']) ? $video['quote'] : '');
    $html .= '<div class="videoBlock__title">' . $video['title'] . '</div>';
    $html .= '<div class="videoBlock__description">' . $video['description'] . '</div>';
    $html .= '<div class="videoBlock__embed">';
    $html .= '<iframe src="' . $video['video-embed'] . '" frameborder="0" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>';
    $html .= '</div>';
    $html .= '</div>';

    return $html;
}

add_shortcode('postLink', 'postLinkShortCode');
function postLinkShortCode(array $attributes): string
{
    $postId = $attributes['id'] ?? null;
    if (empty($postId)) {
        return '';
    }

    $relatedPost = get_post($postId);

    ob_start();

    require __DIR__ . '/templates/relatedPost.php';

    return ob_get_clean();
}

// Change max allowed posts per page
add_filter('rest_post_collection_params', 'custom_per_page_limit');
function custom_per_page_limit($params) {
    $params['per_page']['maximum'] = 10000;
    return $params;
}