Plugin Directory

Changeset 2593652


Ignore:
Timestamp:
09/04/2021 11:36:31 AM (5 years ago)
Author:
codents
Message:

Fixed php8 bug

Location:
simple-googlebot-visit/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • simple-googlebot-visit/trunk/changelog.txt

    r2531418 r2593652  
    11== Changelog ==
     2
     3= 1.2.2 =
     4* Fixed bug with version 8 of PHP.
    25
    36= 1.2.1 =
  • simple-googlebot-visit/trunk/includes/class-simple-googlebot-visit-template.php

    r2301574 r2593652  
    11<?php
    22
    3     class Simple_Googlebot_Visit_Template {
     3class Simple_Googlebot_Visit_Template {
    44
    5         private $path = '';
    6         private $data = array();
     5    private $path = '';
     6    private $data = array();
    77
    8         public function __construct($path, $labels = null) {
    9             if ($path) {
    10                 $this->path = $path;
     8    public function __construct($path, $labels = null) {
     9        if ($path) {
     10            $this->path = $path;
     11        }
     12        if ($labels) {
     13            $this->add($labels);
     14        }
     15    }
     16
     17    public function get($key = null) {
     18        if ($key) {
     19            return isset($this->data[strtoupper($key)]) ?
     20                $this->data[strtoupper($key)] : strtoupper($key);
     21        } else {
     22            return $this->data;
     23        }
     24    }
     25
     26    public function add($labels, $block = null) {
     27        if ($block) {
     28            $this->blocks($block, $labels);
     29            return false;
     30        }
     31        foreach ($labels as $key => $value) {
     32            $this->data[strtoupper($key)] = $value;
     33        }
     34        return true;
     35    }
     36
     37    private function blocks($block, $labels) {
     38        // Before saving a block, we update it
     39        // including the index of the same
     40        $index = isset($this->data[$block]) ? sizeof($this->data[$block]) : 0;
     41        $this->data[$block][] = array_merge(array(
     42            'INDEX' => $index
     43        ), array_change_key_case($labels, CASE_UPPER));
     44        return true;
     45    }
     46
     47    private function load($file, $context = null) {
     48        // Get the template source
     49        $file = $this->path . '/' . $file;
     50        $fileCode = implode('', @file($file));
     51        if ($context) {
     52            $contextReference = 'CONTEXT_' . strtoupper(md5(sizeof($this->data)));
     53            $this->data[$contextReference] = $context;
     54            $fileCode = str_replace('{FOR ', '{FOR ' . $contextReference . '.', $fileCode);
     55            $fileCode = str_replace('{{', '{{' . $contextReference . '.', $fileCode);
     56        }
     57        return $fileCode;
     58    }
     59
     60    public function render($mainFile, $regions = array()) {
     61        // Main template load
     62        $mainCode = $this->load($mainFile);
     63        // We load all regions and include
     64        // them in the main template code
     65        foreach ($regions as $key => $value) {
     66            $template = isset($value['TEMPLATE']) ? $value['TEMPLATE'] : $value;
     67            $context = isset($value['CONTEXT']) ? $value['CONTEXT'] : null;
     68            $regionCode = $this->load($template, $context);
     69            $mainCode = str_replace($key, $regionCode, $mainCode);
     70        }
     71        // After loading the regions, we compiled
     72        // the complete code and we execute it
     73        eval($this->compile($mainCode));
     74        return true;
     75    }
     76
     77    public function getSource($mainFile, $regions = null) {
     78        // Main template load
     79        $mainCode = $this->load($mainFile);
     80        // We load all regions and include
     81        // them in the main template code
     82        $regions = (is_array($regions) ? $regions : array());
     83        while (list($regionFile, $regionLocation) = each($regions)) {
     84            $regionCode = $this->load($regionFile);
     85            $mainCode = str_replace($regionLocation, $regionCode, $mainCode);
     86        }
     87        return $mainCode;
     88    }
     89
     90    private function replaceVars($code) {
     91        $varReferences = array();
     92        preg_match_all('#\{\{(UCASE_|LCASE_)?(.*?)\}\}#is', $code, $varReferences);
     93        foreach ($varReferences[2] as $key => $value) {
     94            $code = str_replace($varReferences[0][$key], '/*START-ISSET*/ . ' . $this->getIsset($value, array(
     95                'UPPER_CASE' => ($varReferences[1][$key] === 'UCASE_') ? true : false,
     96                'LOWER_CASE' => ($varReferences[1][$key] === 'LCASE_') ? true : false
     97            )) . '. /*END-ISSET*/', $code);
     98        }
     99        return $code;
     100    }
     101
     102    private function getIsset($var, $options = array()) {
     103        $defaultValue = '\'\'';
     104        if (isset($options['FOR']) && $options['FOR']) {
     105            $defaultValue = 'array()';
     106        }
     107        $references = explode('.', $var);
     108        $references = array_reverse($references);
     109        $isset = '$temp = ({HERE})';
     110        $base = '';
     111        $base1 = '';
     112        foreach ($references as $key => $value) {
     113            $prefix = str_replace('.', '_', explode($value, $var)[0]);
     114            $base1 = '$_' . $prefix . $value . '_value' . $base;
     115            $base = '[\'' . $value . '\']' . $base;
     116            $look = '$this->data';
     117            $look = ($key === 0) ? $look . $base : $base1;
     118            $print = $look;
     119            if (isset($options['UPPER_CASE']) && $options['UPPER_CASE']) {
     120                $print = 'strtoupper(' . $print . ')';
    11121            }
    12             if ($labels) {
    13                 $this->add($labels);
     122            if (isset($options['LOWER_CASE']) && $options['LOWER_CASE']) {
     123                $print = 'strtolower(' . $print . ')';
     124            }
     125            $isset = str_replace('{HERE}', '(isset(' . $look . ') ? ' . $print . ' : {HERE})', $isset);
     126            if ($key === (sizeof($references) - 1)) {
     127                $isset = str_replace('{HERE}', '(isset($this->data' . $base . ') ? $this->data' . $base . ' : {HERE})', $isset);
    14128            }
    15129        }
     130        $isset = str_replace('{HERE}', $defaultValue, $isset);
     131        return $isset;
     132    }
    16133
    17         public function get($key = null) {
    18             if ($key) {
    19                 return isset($this->data[strtoupper($key)]) ?
    20                     $this->data[strtoupper($key)] : strtoupper($key);
     134    // Compiles the given string of code,
     135    // and return the result in a string
     136    private function compile($code) {
     137        // Replace \ with \\ and then ' with \'.
     138        $code = str_replace('\\', '\\\\', $code);
     139        $code = str_replace('\'', '\\\'', $code);
     140        $code = $this->replaceVars($code);
     141        // Break it up into lines
     142        $codeLines = explode("\n", $code);
     143        for ($i = 0; $i < sizeof($codeLines); $i++) {
     144            $codeLines[$i] = chop($codeLines[$i]);
     145            if (preg_match('#{IF (.*?)}#', $codeLines[$i], $m)) {
     146                $ifCondition = str_replace('/*START-ISSET*/ .', '', $m[1]);
     147                $ifCondition = str_replace('. /*END-ISSET*/', '', $ifCondition);
     148                $codeLines[$i] = "\n" . 'if (' . $ifCondition . ')';
     149                $codeLines[$i] .= "\n" . '{';
     150            } elseif (preg_match('#{ELSE IF (.*?)}#', $codeLines[$i], $m)) {
     151                $ifCondition = str_replace('/*START-ISSET*/ .', '', $m[1]);
     152                $ifCondition = str_replace('. /*END-ISSET*/', '', $ifCondition);
     153                $codeLines[$i] = "\n" . ' } else if (' . $ifCondition . ')';
     154                $codeLines[$i] .= "\n" . '{';
     155            } else if (preg_match('#{ELSE}#', $codeLines[$i], $m)) {
     156                $codeLines[$i] = '} else {' . "\n";
     157            } else if (preg_match('#{END IF}#', $codeLines[$i], $m)) {
     158                $codeLines[$i] = '} // END IF';
     159            } else if (preg_match('#{FOR (.*?)}#', $codeLines[$i], $m)) {
     160                $key = str_replace('.', '_', $m[1]);
     161                $codeLines[$i] = 'foreach (' . $this->getIsset($m[1], array(
     162                    'FOR' => true
     163                )) . ' as $_' . $key . '_key => $_' . $key . '_value)';
     164                $codeLines[$i] .= "\n" . '{';
     165            } else if (preg_match('#{END FOR}#', $codeLines[$i], $m)) {
     166                $codeLines[$i] = '} // END FOR';
    21167            } else {
    22                 return $this->data;
     168                $codeLines[$i] = 'echo \'' . $codeLines[$i] . '\' . "\\n";';
    23169            }
    24170        }
    25 
    26         public function add($labels, $block = null) {
    27             if ($block) {
    28                 $this->blocks($block, $labels);
    29                 return false;
    30             }
    31             while (list($key, $value) = each($labels)) {
    32                 $this->data[strtoupper($key)] = $value;
    33             }
    34             return true;
    35         }
    36 
    37         private function blocks($block, $labels) {
    38             // Before saving a block, we update it
    39             // including the index of the same
    40             $index = isset($this->data[$block]) ? sizeof($this->data[$block]) : 0;
    41             $this->data[$block][] = array_merge(array(
    42                 'INDEX' => $index
    43             ), array_change_key_case($labels, CASE_UPPER));
    44             return true;
    45         }
    46 
    47         private function load($file, $context = null) {
    48             // Get the template source
    49             $file = $this->path . '/' . $file;
    50             $fileCode = implode('', @file($file));
    51             if ($context) {
    52                 $contextReference = 'CONTEXT_' . strtoupper(md5(sizeof($this->data)));
    53                 $this->data[$contextReference] = $context;
    54                 $fileCode = str_replace('{FOR ', '{FOR ' . $contextReference . '.', $fileCode);
    55                 $fileCode = str_replace('{{', '{{' . $contextReference . '.', $fileCode);
    56             }
    57             return $fileCode;
    58         }
    59 
    60         public function render($mainFile, $regions = array()) {
    61             // Main template load
    62             $mainCode = $this->load($mainFile);
    63             // We load all regions and include
    64             // them in the main template code
    65             foreach ($regions as $key => $value) {
    66                 $template = isset($value['TEMPLATE']) ? $value['TEMPLATE'] : $value;
    67                 $context = isset($value['CONTEXT']) ? $value['CONTEXT'] : null;
    68                 $regionCode = $this->load($template, $context);
    69                 $mainCode = str_replace($key, $regionCode, $mainCode);
    70             }
    71             // After loading the regions, we compiled
    72             // the complete code and we execute it
    73             eval($this->compile($mainCode));
    74             return true;
    75         }
    76 
    77         public function getSource($mainFile, $regions = null) {
    78             // Main template load
    79             $mainCode = $this->load($mainFile);
    80             // We load all regions and include
    81             // them in the main template code
    82             $regions = (is_array($regions) ? $regions : array());
    83             while(list($regionFile, $regionLocation) = each($regions)) {
    84                 $regionCode = $this->load($regionFile);
    85                 $mainCode = str_replace($regionLocation, $regionCode, $mainCode);
    86             }
    87             return $mainCode;
    88         }
    89 
    90         private function replaceVars($code) {
    91             $varReferences = array();
    92             preg_match_all('#\{\{(UCASE_|LCASE_)?(.*?)\}\}#is', $code, $varReferences);
    93             foreach ($varReferences[2] as $key => $value) {
    94                 $code = str_replace($varReferences[0][$key], '/*START-ISSET*/ . ' . $this->getIsset($value, array(
    95                     'UPPER_CASE' => ($varReferences[1][$key] === 'UCASE_') ? true : false,
    96                     'LOWER_CASE' => ($varReferences[1][$key] === 'LCASE_') ? true : false
    97                 )) . '. /*END-ISSET*/', $code);
    98             }
    99             return $code;
    100         }
    101 
    102         private function getIsset($var, $options = array()) {
    103             $defaultValue = '\'\'';
    104             if (isset($options['FOR']) && $options['FOR']) {
    105                 $defaultValue = 'array()';
    106             }
    107             $references = explode('.', $var);
    108             $references = array_reverse($references);
    109             $isset = '$temp = ({HERE})';
    110             $base = '';
    111             $base1 = '';
    112             foreach ($references as $key => $value) {
    113                 $prefix = str_replace('.', '_', explode($value, $var)[0]);
    114                 $base1 = '$_' . $prefix . $value . '_value' . $base;
    115                 $base = '[\'' . $value . '\']' . $base;
    116                 $look = '$this->data';
    117                 $look = ($key === 0) ? $look . $base : $base1;
    118                 $print = $look;
    119                 if (isset($options['UPPER_CASE']) && $options['UPPER_CASE']) {
    120                     $print = 'strtoupper(' . $print . ')';
    121                 }
    122                 if (isset($options['LOWER_CASE']) && $options['LOWER_CASE']) {
    123                     $print = 'strtolower(' . $print . ')';
    124                 }
    125                 $isset = str_replace('{HERE}', '(isset(' . $look . ') ? ' . $print . ' : {HERE})', $isset);
    126                 if ($key === (sizeof($references) - 1))  {
    127                     $isset = str_replace('{HERE}', '(isset($this->data' . $base . ') ? $this->data' . $base . ' : {HERE})', $isset);
    128                 }
    129             }
    130             $isset = str_replace('{HERE}', $defaultValue, $isset);
    131             return $isset;
    132         }
    133        
    134         // Compiles the given string of code,
    135         // and return the result in a string
    136         private function compile($code) {
    137             // Replace \ with \\ and then ' with \'.
    138             $code = str_replace('\\', '\\\\', $code);
    139             $code = str_replace('\'', '\\\'', $code);
    140             $code = $this->replaceVars($code);
    141             // Break it up into lines
    142             $codeLines = explode("\n", $code);
    143             for ($i = 0; $i < sizeof($codeLines); $i++) {
    144                 $codeLines[$i] = chop($codeLines[$i]);
    145                 if (preg_match('#{IF (.*?)}#', $codeLines[$i], $m)) {
    146                     $ifCondition = str_replace('/*START-ISSET*/ .', '', $m[1]);
    147                     $ifCondition = str_replace('. /*END-ISSET*/', '', $ifCondition);
    148                     $codeLines[$i] = "\n" . 'if (' . $ifCondition . ')';
    149                     $codeLines[$i] .= "\n" . '{';
    150                 } elseif (preg_match('#{ELSE IF (.*?)}#', $codeLines[$i], $m)) {
    151                     $ifCondition = str_replace('/*START-ISSET*/ .', '', $m[1]);
    152                     $ifCondition = str_replace('. /*END-ISSET*/', '', $ifCondition);
    153                     $codeLines[$i] = "\n" . ' } else if (' . $ifCondition . ')';
    154                     $codeLines[$i] .= "\n" . '{';
    155                 } else if (preg_match('#{ELSE}#', $codeLines[$i], $m)) {
    156                     $codeLines[$i] = '} else {' . "\n";
    157                 } else if (preg_match('#{END IF}#', $codeLines[$i], $m)) {
    158                     $codeLines[$i] = '} // END IF';
    159                 } else if (preg_match('#{FOR (.*?)}#', $codeLines[$i], $m)) {
    160                     $key = str_replace('.', '_', $m[1]);
    161                     $codeLines[$i] = 'foreach (' . $this->getIsset($m[1], array(
    162                         'FOR' => true
    163                     )) . ' as $_' . $key . '_key => $_' . $key . '_value)';
    164                     $codeLines[$i] .= "\n" . '{';
    165                 } else if (preg_match('#{END FOR}#', $codeLines[$i], $m)) {
    166                     $codeLines[$i] = '} // END FOR';
    167                 } else {
    168                     $codeLines[$i] = 'echo \'' . $codeLines[$i] . '\' . "\\n";';
    169                 }
    170             }
    171             // Bring it back into a single string of lines of code
    172             $code = implode("\n", $codeLines);
    173             $code = str_replace('/*START-ISSET*/', '\'', $code);
    174             $code = str_replace('/*END-ISSET*/', '\'', $code);
    175             return $code;
    176         }
    177 
     171        // Bring it back into a single string of lines of code
     172        $code = implode("\n", $codeLines);
     173        $code = str_replace('/*START-ISSET*/', '\'', $code);
     174        $code = str_replace('/*END-ISSET*/', '\'', $code);
     175        return $code;
    178176    }
     177}
  • simple-googlebot-visit/trunk/readme.txt

    r2531418 r2593652  
    44Tags: seo, googlebot, google, indexation, pages, entries, woocommerce, products
    55Requires at least: 3.0.1
    6 Tested up to: 5.7.2
     6Tested up to: 5.8
    77Stable tag: trunk
    88Requires PHP: 5.5
     
    4343== Changelog ==
    4444
     45= 1.2.2 =
     46* Fixed bug with version 8 of PHP.
     47
    4548= 1.2.1 =
    4649* Added compatibility with Wordpress 5.7.2.
Note: See TracChangeset for help on using the changeset viewer.