W
W
webviktor2021-07-09 10:50:09
PHP
webviktor, 2021-07-09 10:50:09

Why is the code error in 7.4 but not in 7.2?

Greetings.

Help to understand please.
A man wrote a plugin for WP a few years ago. Now there is no contact with him.
The bottom line is that it works fine on 7.2. The server has been updated and now there are two versions of php - 7.4 and 8.0.
On 8 it gives the following error:
FastCGI sent in stderr: "PHP message: PHP Parse error: Unclosed '{' on line 17 in
On 7.4 :
FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected end of file in

I'm not a programmer. So please don't drink too much. I just need to launch the site.
My assumption is that the block is somehow incorrectly inserted at the end.
Although the code passes all syntax checks.

Thank you in advance.

php code

<?php
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) die('Not allowed to call this page directly.');

add_action( 'init', 'archivedmmm_load_shortcodes' );

function archivedmmm_load_shortcodes (  ) {
    wp_enqueue_style('archivedmmm-css', plugins_url('css/style.css', __FILE__));
    add_shortcode('archivedmmm_index', 'archivedmmm_index');
}

function archivedmmm_index() {
    global $wpdb;

    $items_per_page = 50;
    $page = 1;

    if (isset($_GET['archive_page']) && intval(abs($_GET['archive_page'])) > 0) {
        $page = intval(abs($_GET['archive_page']));
    }

    $fields = array(
        'truck' => 58,
        'truck_route' => 23,
        'date_start' => 30,
        'date_end' => 31,
        'truck_type' => 77,
        'cabotage' => 28,
        'adr' => 20,
        'driver_name' => 78,
        'driver_phone' => 79,
        'tractor' => 9,
        'trailer' => 16,
        'trailer_number' => 12,
        'pallet' => 17,
        'wood' => 18,
        'country' => 86,
        'city_code' => 39,
        'city' => 41,
        'description' => 27,

        'load' => 25, // Загрузка
    );

    $search = '';
    $query_where_part = '';
    $query_params = array();

    if (isset($_GET['search']) && strlen(trim($_GET['search'])) > 1) {
        $search = addslashes(trim($_GET['search']));
        $query_params = array($search,$search,$search,$search,$search,$search,$search,$search,$search,$search,$search,$search,$search,$search);
        $query_params = array_map(function($a) {
            return '%'.$a.'%';
        }, $query_params);
        $query_where_part = "AND (
                t2.meta_value LIKE %s 
                OR t31.meta_value LIKE %s
                OR t6.meta_value LIKE %s 
                OR t7.meta_value LIKE %s
                OR t8.meta_value LIKE %s 
                OR t9.meta_value LIKE %s
                OR t10.meta_value LIKE %s 
                OR t11.meta_value LIKE %s 
                OR t12.meta_value LIKE %s 
                OR t13.meta_value LIKE %s 
                OR t14.meta_value LIKE %s 
                OR t15.meta_value LIKE %s
                OR t16.meta_value LIKE %s
                OR t17.meta_value LIKE %s
                )";
        $total_items_query = $wpdb->prepare("
            SELECT count( DISTINCT  t1.item_id) as `total_items`
            FROM `" . $wpdb->prefix . "frm_item_metas` t1
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t2 ON t1.meta_value = t2.item_id AND t2.field_id = " . $fields['truck'] . "
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t3 ON t1.meta_value = t3.item_id AND t3.field_id = " . $fields['trailer'] . "
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t31 ON t3.meta_value = t31.item_id AND t31.field_id = 81
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t6 ON t1.item_id = t6.item_id AND t6.field_id = 88
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t7 ON t1.item_id = t7.item_id AND t7.field_id = 26
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t8 ON t1.meta_value = t8.item_id AND t8.field_id = ".$fields['tractor']."
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t9 ON t1.item_id = t9.item_id AND t9.field_id = 91
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t10 ON t1.item_id = t10.item_id AND t10.field_id = ".$fields['date_start']."
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t11 ON t1.item_id = t11.item_id AND t11.field_id = ".$fields['date_end']."
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t12 ON t1.item_id = t12.item_id AND t12.field_id = 38
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t13 ON t1.item_id = t13.item_id AND t13.field_id = 40
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t14 ON t1.item_id = t14.item_id AND t14.field_id = ".$fields['country']."
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t15 ON t1.item_id = t15.item_id AND t15.field_id = ".$fields['city']."
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t16 ON t1.item_id = t16.item_id AND t16.field_id = ".$fields['city_code']."
            LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t17 ON t1.item_id = t17.item_id AND t17.field_id = 85
            WHERE t1.field_id = ".$fields['truck_route']."
            ".$query_where_part." 
        ", $query_params);
        //echo $total_items_query;
        $total_items = $wpdb->get_var($total_items_query);
    } else {
        $total_items = $wpdb->get_var("
            SELECT count(*) as `total_items`
            FROM `" . $wpdb->prefix . "frm_item_metas`
            WHERE `field_id`='" . $fields['truck_route'] . "'
        ");
    }

    $total_pages = ceil($total_items / $items_per_page);
    $page = min($total_pages, $page);

    if ($total_items > 0) {
        $items_query = $wpdb->prepare("
    SELECT t1.item_id as item_id, t2.meta_value as truck_name, t31.meta_value as trailer_type, t4.meta_value as `k`, t5.meta_value as `adr`, t6.meta_value as `driver`, t7.meta_value as `order`, t8.meta_value as `truck`, t9.meta_value as `trailer`, t10.meta_value as `upload_date`, t11.meta_value as `download_date`, t12.meta_value as upload_country, t17.meta_value as upload_city_code, t13.meta_value as `upload_address`, t14.meta_value as download_country, t16.meta_value as download_city_code, t15.meta_value as `download_address`
        FROM `" . $wpdb->prefix . "frm_item_metas` t1
        LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t2 ON t1.meta_value = t2.item_id AND t2.field_id = " . $fields['truck'] . "
        LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t16 ON t1.item_id = t16.item_id AND t16.field_id = ".$fields['city_code']."
        LEFT JOIN `" . $wpdb->prefix . "frm_item_metas` t17 ON t1.item_id = t17.item_id AND t17.field_id = 85
    WHERE t1.field_id = ".$fields['truck_route']." 
    ".($query_where_part ? $query_where_part : '')."
    GROUP BY t1.item_id
    ORDER BY t1.item_id DESC
    LIMIT ".$items_per_page." OFFSET ".(($page-1) * $items_per_page)."
  ", $query_params);
        $items = $wpdb->get_results($items_query);
    } else {
        $items = array();
    }
    ?>
        <div class="archivedmm__container">
            <p>Total: <?=$total_items?></p>
            <table class="archivedmm__table">
                <tbody>
                <?php if ($total_items > 0): ?>
                    <?php foreach ($items as $item): ?>
                        <tr>
                            <td><?php echo $item->k ?></td>
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr>
                    </tr>
                <?php endif; ?>
                </tbody>
            </table>
            <?php if ($total_pages > 1):?>
                <div class="archivedmm__pagination">
                    <a  <?php if ($page != 1):?>href="?archive_page=1<?php echo $search != '' ? '&search='.$search : '' ?>"<?php endif;?>
                        class="<?php echo $page == 1 ? 'active' : ''?>">1</a>
                    <?php echo (max(2, $page - 5) !== 2) ? '...' : '' ?>
                    <?php for($i = max(2, $page - 5); $i <= min($total_pages-1, $page + 5); $i++): ?>
                        <a  <?php if ($page != $i):?>href="?archive_page=<?php echo $i?><?php echo $search != '' ? '&search='.$search : '' ?>"<?php endif;?>
                            class="<?php echo $page == $i ? 'active' : ''?>"><?php echo $i ?></a>
                    <?php endfor; ?>

                    <?php echo min($total_pages-1, $page + 5) !== $total_pages-1 ? '...' : '' ?>
                    <a  <?php if ($page != $total_pages):?>href="?archive_page=<?php echo $total_pages?><?php echo $search != '' ? '&search='.$search : '' ?>"<?php endif;?>
                        class="<?php echo $page == $total_pages ? 'active' : ''?>"><?php echo $total_pages ?></a>
                </div>
            <?php endif ?>
        </div>
    <?
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2021-07-09
@webviktor

as I wrote in the comments, 99% that you have a problem in shorttags. In the last lines you use <? instead of <?php, and in freshly installed puff, the shorttag is disabled by default.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question