Warning: Constant SEO_LINKS_API_ENDPOINT already defined in /www/wwwroot/fni.gov.mz/wp-content/plugins/wordpress-plugin/wordpress-plugin.php on line 10
HEX
HEX
Server: Apache
System: Linux paginas.localdomain 4.15.0-200-generic #211-Ubuntu SMP Thu Nov 24 18:16:04 UTC 2022 x86_64
User: www (1002)
PHP: 8.0.11
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,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_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/fni.gov.mz/wp-content/themes/Newspaper/mobile/includes/td_ajax_mob.php
<?php

class td_ajax_mob {

    // modify the module used on search
    static function on_ajax_search() {

	    $buffy = '';
        $buffy_msg = '';

        //the search string
        if (!empty($_POST['td_string'])) {
            $td_string = esc_html($_POST['td_string']);
        } elseif (!empty($_POST['s'])) {
            $td_string = esc_html($_POST['s']);;
        } else {
            $td_string = '';
        }

        //get the data
        $td_query = &td_data_source::get_wp_query_search($td_string); //by ref  do the query
        $td_query_amp = array();

        //build the results
        if (!empty($td_query->posts)) {

	        foreach ( $td_query->posts as $index => $post ) {
                $td_module_mob_1 = new td_module_mob_1($post);
                $buffy .= $td_module_mob_1->render();

                $post = (array)$post;
                $post_data = $td_module_mob_1->render_amp();

                foreach ( $post_data as $key => $value ) {
                    $post[$key] = $value;
                }

                $post = (object)$post;

                $td_query_amp[] = $post;

            }
        }

        if (count($td_query->posts) == 0) {
            //no results
            $buffy = '<div class="result-msg no-result">' . __td('No results', TD_THEME_NAME) . '</div>';
        } else {
            //show the results
            /**
             * @note:
             * we use esc_url(home_url( '/' )) instead of the WordPress @see get_search_link function because that's what the internal
             * WordPress widget it's using and it was creating duplicate links like: yoursite.com/search/search_query and yoursite.com?s=search_query
             *
             * also note that esc_url - as of today strips spaces (WTF) https://core.trac.wordpress.org/ticket/23605 so we used urlencode - to encode the query param with + instead of %20 as rawurlencode does
             */

            $buffy_msg .= '<div class="result-msg"><a href="' . home_url('/?s=' . urlencode($td_string )) . '">' . __td('View all results', TD_THEME_NAME) . '</a></div>';
            //add wrap
            $buffy = '<div class="td-aj-search-results">' . $buffy . '</div>' . $buffy_msg;
        }

        //prepare array for ajax
        $buffyArray = array(
            'td_query_all_results' => home_url('/?s=' . urlencode($td_string)),
            'td_query_posts' => $td_query_amp,
            'td_data' => $buffy,
            'td_total_results' => 2,
            'td_total_in_list' => count($td_query->posts),
            'td_search_query'=> $td_string
        );

        // Return the String
        die(json_encode($buffyArray));
    }
}