HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/td-oi-plugin/shortcodes/td_zodiac_sign.php
<?php

class td_zodiac_sign extends td_block
{

    const BASE_URL = 'https://www.adnkronos.com/NewsFeed/Oroscopo.xml?username=%s&password=%s';

    private $username = 'corrieretoscano';
    private $password = 'c0rrty6k7o';

    public function get_custom_css()
    {
        // $unique_block_class - the unique class that is on the block. use this to target the specific instance via css
        $unique_block_class = ((td_util::tdc_is_live_editor_iframe() || td_util::tdc_is_live_editor_ajax()) ? 'tdc-row .' : '') . $this->block_uid;

        $compiled_css = '';

        $raw_css =
            "<style>            
            </style>";


        $td_css_res_compiler = new td_css_res_compiler($raw_css);
        $td_css_res_compiler->load_settings(__CLASS__ . '::cssMedia', $this->get_all_atts());

        $compiled_css .= $td_css_res_compiler->compile_css();
        return $compiled_css;
    }

    static function cssMedia($res_ctx)
    {

    }

    /**
     * Disable loop block features. This block does not use a loop and it doesn't need to run a query.
     */
    function __construct()
    {
        parent::disable_loop_block_features();

        $this->show_dots = 'true';

    }

    function xml2array($xmlObject, $out = array())
    {
        foreach ((array)$xmlObject as $index => $node) {
            $out[$index] = (is_object($node)) ? $this->xml2array($node) : $node;
        }
        return $out;
    }

    function render($atts, $content = null)
    {
        $log_file = dirname(__FILE__) . '/../logs/zodiac_import.log';

        $in_composer = td_util::tdc_is_live_editor_iframe() || td_util::tdc_is_live_editor_ajax();
        $uniqClass = 'zodiac-' . uniqid();

        parent::render($atts); // sets the live atts, $this->atts, $this->block_uid, $this->td_query (it runs the query)

        $date = date('Ymd');
        $cacheFile = __DIR__ . '/../logs/' . $date . '.json';

        if (!file_exists($cacheFile)) {
            $username = $this->get_att('username');
            if (trim($username) !== '') {
                $this->username = $username;
            }

            $password = $this->get_att('password');
            if (trim($password) !== '') {
                $this->password = $password;
            }

            $url = sprintf(self::BASE_URL, $this->username, $this->password);

            file_put_contents($log_file, "Load feed: " . $url . "\n ", FILE_APPEND);

            $clientHttp = new WP_Http();
            $response = $clientHttp->request($url);

            if ($response instanceof WP_Error) {
                file_put_contents($log_file, " Response: " . json_encode($response) . "\n", FILE_APPEND);
                return;
            }

            $response_xml_data = $response['body'];

            if (is_string($response_xml_data)) {
                libxml_use_internal_errors(true);
                $data = simplexml_load_string($response_xml_data, null, LIBXML_NOCDATA);
                if (!$data) {
                    foreach (libxml_get_errors() as $error) {
                        file_put_contents($log_file, " Errore: " . $error->message . "\n", FILE_APPEND);
                    }
                }

                $out = $this->xml2array($data);

                file_put_contents($log_file, " Parsing: " . json_encode($out) . "\n", FILE_APPEND);

                $fh = fopen($cacheFile, 'w+');
                fwrite($fh, json_encode($out['channel']['item']));
                fclose($fh);
            }
        }

        $json = json_decode(file_get_contents($cacheFile), true);
        $sign = $this->get_att('sign');

        $signData = null;
        foreach ($json as $data) {
            if (strtolower($data['title']) == strtolower($sign)) {
                $signData = $data;
            }
        }

        /** Code for splitting the array for offset */
        /** $authors_data -> array_slice($authors_data, 0, 1) */
        /** (end of) Code for splitting the array for offset */

        $buffy = ''; //output buffer

        $buffy .= '<div class="' . $this->get_block_classes() . '" ' . $this->get_block_html_atts() . '>';

        //get the block css
        $buffy .= $this->get_block_css();

        //get the js for this block
        $buffy .= $this->get_block_js();


        $buffy .= "
                <style>
               
                /* Slick Slider */
                .$uniqClass.td-sign h2 {
                    margin-top: 15px;
                    font-weight: 700;
                    text-transform: uppercase;
                }
                .$uniqClass.td-sign p {
                    margin-top: -20px;
                    font-family: 'Noto Sans' !important;
                    font-size: 18px;
                    line-height: 1.7;
                }
                .$uniqClass.td-sign img {
                    width: 100%;
                }

                @media (max-width: 480px) {
                }
                </style>
            ";

        $imgUri = TD_OI_URL . 'assets/img/zodiac/cover/' . strtolower($sign) . '.png';

        if (isset($no_posts)) {
            $buffy .= $no_posts;
        } else {
            $buffy .= '<div class="tdw-block-inner td-fix-index">';

            $buffy .= '<div class="td-sign ' . $uniqClass . '">';

            $buffy .= '<a id="' . strtolower($sign) . '"  name="' . strtolower($sign) . '"><img src="' . $imgUri . '" alt="' . $signData['title'] . '"></a>';
            $buffy .= '<h2>' . $signData['title'] . '</h2>';
            $buffy .= '<p>' . str_replace(array(
                    '(Adnkronos) - ',
                    '(Adnkronos) -',
                    '(Adnkronos)- ',
                    '(Adnkronos)-',
                    '(Adnkronos)',
                ), array(
                    '',
                    '',
                    '',
                    '',
                    '',
                ), $signData['description']) . '</p>';

            $buffy .= '</div>';

            $buffy .= '</div>';
        }

        $buffy .= '</div>';

        return $buffy;
    }

}