Plugin Directory

Changeset 3451883


Ignore:
Timestamp:
02/02/2026 09:09:46 AM (8 weeks ago)
Author:
showcaseidx
Message:

Version 3.3.1

Location:
showcase-idx/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • showcase-idx/trunk/3/diagnostics.php

    r2367883 r3451883  
    1515    $active_plugins = [];
    1616    $showcaseidx_plugin = null;
    17     foreach (get_option('active_plugins') as $plugin_file) {
     17    $active_plugins_option = get_option('active_plugins');
     18    if (!is_array($active_plugins_option)) {
     19        $active_plugins_option = [];
     20    }
     21    foreach ($active_plugins_option as $plugin_file) {
    1822      $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_file);
    1923      if (strpos($plugin_file, 'showcaseidx.php') !== false) {
     
    2529
    2630    global $wp_version;
     31    $bootstrap_time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? round(microtime(TRUE) - $_SERVER['REQUEST_TIME_FLOAT'], 3) : '';
    2732    $data = [
    2833        'wp_version'                => $wp_version,
     
    3035        'php_sapi_name'             => php_sapi_name(),
    3136        'php_memory_limit'          => ini_get('memory_limit'),
    32         'php_bootstrap_time'        => round(microtime(TRUE) - $_SERVER['REQUEST_TIME_FLOAT'], 3),
     37        'php_bootstrap_time'        => $bootstrap_time,
    3338        'wp_theme'                  => $wp_theme->get('Name'),
    3439        'wp_theme_version'          => $wp_theme->get('Version'),
     
    5762    }
    5863    echo <<<HTML
    59 <style type-="text/css">
     64<style type="text/css">
    6065table td, table th {
    6166    word-break: normal;
     
    8691            <tr>
    8792                <td width="70%">Version</td>
    88                 <td width="30%">{$showcaseidx_plugin['Version']}</td>
     93                <td width="30%">
     94HTML;
     95echo isset($showcaseidx_plugin['Version']) ? $showcaseidx_plugin['Version'] : '';
     96echo <<<HTML
     97</td>
    8998            </tr>
    9099            <tr>
     
    173182                <td>{$opcache['directives']['opcache.revalidate_freq']}</td>
    174183            </tr>
     184HTML;
     185    if (!empty($opcache['overview'])) {
     186        $hitRate = isset($opcache['overview']['hit_rate_percentage']) ? $opcache['overview']['hit_rate_percentage'] : 'N/A';
     187        $numCached = isset($opcache['overview']['num_cached_scripts']) ? $opcache['overview']['num_cached_scripts'] : 'N/A';
     188        $maxFiles = isset($opcache['directives']['opcache.max_accelerated_files']) ? $opcache['directives']['opcache.max_accelerated_files'] : 'N/A';
     189        echo <<<HTML
    175190            <tr>
    176191                <td>
    177192                    Hit Rate
    178                     <div class=help>A "hit" is a compiled php script that is loaded from cache, rather than re-compiled each request. If cache is installed and working property, you should see a hit rate well above 50%. Below 10% indicates the cache isnt being used usefully.</div>
    179                 </td>
    180                 <td>{$opcache['overview']['hit_rate_percentage']}%</td>
     193                    <div class=help>A "hit" is a compiled php script that is loaded from cache, rather than re-compiled each request. If cache is installed and working property, you should see a hit rate well above 50%. Below 10% indicates the cache isn't being used usefully.</div>
     194                </td>
     195                <td>{$hitRate}%</td>
    181196            </tr>
    182197            <tr>
     
    185200                    <div class=help>Shows how many php scripts are in the cache. In a normally-functioning opcache, there should be many hundreds-to-thousands of files. Seeing less than this is an indicator that the cache isn't being used usefully.</div>
    186201                </td>
    187                 <td>{$opcache['overview']['num_cached_scripts']} (out of {$opcache['directives']['opcache.max_accelerated_files']} max)</td>
    188             </tr>
    189 HTML;
     202                <td>{$numCached} (out of {$maxFiles} max)</td>
     203            </tr>
     204HTML;
     205    }
    190206        } else {
    191207    echo <<<HTML
     
    207223        echo "</body></html>";
    208224    }
    209     exit;
    210 }
    211 
     225}
     226
  • showcase-idx/trunk/3/opcache.php

    r2030748 r3451883  
    1515    protected $data;
    1616    protected $options;
    17     protected $defaults = [
     17    protected $defaults = array(
    1818        'allow_filelist'   => true,
    1919        'allow_invalidate' => true,
     
    2727        'cookie_name'      => 'opcachegui',
    2828        'cookie_ttl'       => 365
    29     ];
     29    );
    3030
    31     private function __construct($options = [])
     31    private function __construct($options = array())
    3232    {
    3333        $this->options = array_merge($this->defaults, $options);
     
    3535    }
    3636
    37     public static function init($options = [])
     37    public static function init($options = array())
    3838    {
    3939        $self = new self($options);
     
    8383    {
    8484        $enabled = false;
    85         $version = [];
    86         $overview = [];
    87         $directives = [];
     85        $version = array();
     86        $overview = array();
     87        $directives = array();
    8888
    8989        if (!extension_loaded('Zend OPcache')) {
     
    9191        } else {
    9292            $config = opcache_get_configuration();
     93
     94            // Check if opcache_get_configuration() returned valid data
     95            if ($config === false || !is_array($config) || !isset($config['version'])) {
     96                $version['opcache_product_name'] = 'OPcache installed, but configuration unavailable (restricted by opcache.restrict_api).';
     97                return array(
     98                    'enabled'  => $enabled,
     99                    'version'    => $version,
     100                    'overview'   => $overview,
     101                    'directives' => $directives
     102                );
     103            }
     104
    93105            $version = $config['version'];
    94106
     
    96108            if ($ocEnabled == 1) {
    97109                $enabled = true;
    98                 $status = opcache_get_status();
     110                $status = opcache_get_status(false);
    99111
    100                 $overview = array_merge(
    101                     $status['memory_usage'], $status['opcache_statistics'], [
    102                         'used_memory_percentage'  => round(100 * (
    103                                 ($status['memory_usage']['used_memory'] + $status['memory_usage']['wasted_memory'])
    104                                 / $config['directives']['opcache.memory_consumption'])),
    105                         'hit_rate_percentage'     => round($status['opcache_statistics']['opcache_hit_rate']),
    106                         'wasted_percentage'       => round($status['memory_usage']['current_wasted_percentage'], 2),
    107                         'readable' => [
    108                             'total_memory'       => $this->size($config['directives']['opcache.memory_consumption']),
    109                             'used_memory'        => $this->size($status['memory_usage']['used_memory']),
    110                             'free_memory'        => $this->size($status['memory_usage']['free_memory']),
    111                             'wasted_memory'      => $this->size($status['memory_usage']['wasted_memory']),
    112                             'num_cached_scripts' => number_format($status['opcache_statistics']['num_cached_scripts']),
    113                             'hits'               => number_format($status['opcache_statistics']['hits']),
    114                             'misses'             => number_format($status['opcache_statistics']['misses']),
    115                             'blacklist_miss'     => number_format($status['opcache_statistics']['blacklist_misses']),
    116                             'num_cached_keys'    => number_format($status['opcache_statistics']['num_cached_keys']),
    117                             'max_cached_keys'    => number_format($status['opcache_statistics']['max_cached_keys']),
     112                // Check if opcache_get_status() returned valid data
     113                if ($status === false || !is_array($status) || !isset($status['memory_usage']) || !isset($status['opcache_statistics'])) {
     114                    $version['opcache_product_name'] .= ' enabled, but status unavailable (restricted by opcache.restrict_api).';
     115                } else {
     116                    $memoryConsumption = isset($config['directives']['opcache.memory_consumption']) ? $config['directives']['opcache.memory_consumption'] : 0;
     117                    $usedMemoryPercentage = 0;
     118                    if ($memoryConsumption > 0 && isset($status['memory_usage']['used_memory']) && isset($status['memory_usage']['wasted_memory'])) {
     119                        $usedMemoryPercentage = round(100 * (
     120                            ($status['memory_usage']['used_memory'] + $status['memory_usage']['wasted_memory'])
     121                            / $memoryConsumption));
     122                    }
     123
     124                    $opcacheHitRate = isset($status['opcache_statistics']['opcache_hit_rate']) ? $status['opcache_statistics']['opcache_hit_rate'] : 0;
     125                    $wastedPercentage = isset($status['memory_usage']['current_wasted_percentage']) ? $status['memory_usage']['current_wasted_percentage'] : 0;
     126                    $startTime = isset($status['opcache_statistics']['start_time']) ? $status['opcache_statistics']['start_time'] : 0;
     127                    $lastRestartTime = isset($status['opcache_statistics']['last_restart_time']) ? $status['opcache_statistics']['last_restart_time'] : 0;
     128
     129                    $overview = array_merge(
     130                        isset($status['memory_usage']) ? $status['memory_usage'] : array(),
     131                        isset($status['opcache_statistics']) ? $status['opcache_statistics'] : array(),
     132                        array(
     133                        'used_memory_percentage'  => $usedMemoryPercentage,
     134                        'hit_rate_percentage'     => round($opcacheHitRate),
     135                        'wasted_percentage'       => round($wastedPercentage, 2),
     136                        'readable' => array(
     137                            'total_memory'       => $this->size($memoryConsumption),
     138                            'used_memory'        => $this->size(isset($status['memory_usage']['used_memory']) ? $status['memory_usage']['used_memory'] : 0),
     139                            'free_memory'        => $this->size(isset($status['memory_usage']['free_memory']) ? $status['memory_usage']['free_memory'] : 0),
     140                            'wasted_memory'      => $this->size(isset($status['memory_usage']['wasted_memory']) ? $status['memory_usage']['wasted_memory'] : 0),
     141                            'num_cached_scripts' => number_format(isset($status['opcache_statistics']['num_cached_scripts']) ? $status['opcache_statistics']['num_cached_scripts'] : 0),
     142                            'hits'               => number_format(isset($status['opcache_statistics']['hits']) ? $status['opcache_statistics']['hits'] : 0),
     143                            'misses'             => number_format(isset($status['opcache_statistics']['misses']) ? $status['opcache_statistics']['misses'] : 0),
     144                            'blacklist_miss'     => number_format(isset($status['opcache_statistics']['blacklist_misses']) ? $status['opcache_statistics']['blacklist_misses'] : 0),
     145                            'num_cached_keys'    => number_format(isset($status['opcache_statistics']['num_cached_keys']) ? $status['opcache_statistics']['num_cached_keys'] : 0),
     146                            'max_cached_keys'    => number_format(isset($status['opcache_statistics']['max_cached_keys']) ? $status['opcache_statistics']['max_cached_keys'] : 0),
    118147                            'interned'           => null,
    119                             'start_time'         => date('Y-m-d H:i:s', $status['opcache_statistics']['start_time']),
    120                             'last_restart_time'  => ($status['opcache_statistics']['last_restart_time'] == 0
    121                                     ? 'never'
    122                                     : date('Y-m-d H:i:s', $status['opcache_statistics']['last_restart_time'])
    123                                 )
    124                         ]
    125                     ]
     148                            'start_time'         => $startTime > 0 ? date('Y-m-d H:i:s', $startTime) : 'N/A',
     149                            'last_restart_time'  => ($lastRestartTime == 0 ? 'never' : date('Y-m-d H:i:s', $lastRestartTime))
     150                        )
     151                    )
    126152                );
     153                }
    127154            } else {
    128155                $version['opcache_product_name'] .= ' installed, but not enabled.';
    129156            }
    130157
    131             $directives = [];
    132             ksort($config['directives']);
    133             foreach ($config['directives'] as $k => $v) {
    134                 $directives[$k] = $v;
     158            $directives = array();
     159            if (isset($config['directives']) && is_array($config['directives'])) {
     160                ksort($config['directives']);
     161                foreach ($config['directives'] as $k => $v) {
     162                    $directives[$k] = $v;
     163                }
    135164            }
    136165        }
    137166
    138         return [
     167        return array(
    139168            'enabled'  => $enabled,
    140169            'version'    => $version,
    141170            'overview'   => $overview,
    142             'directives' => $directives,
    143         ];
     171            'directives' => $directives
     172        );
    144173    }
    145174}
  • showcase-idx/trunk/3/page.php

    r3192504 r3451883  
    102102  $http_status_code = wp_remote_retrieve_response_code( $response );
    103103  if ( $http_status_code == 200 ) {
    104     header( 'Set-Cookie: ' . wp_remote_retrieve_header( $response, 'set-cookie' ) );
     104      $cookies = wp_remote_retrieve_header( $response, 'set-cookie' );
     105
     106      if ( $cookies ) {
     107          showcaseidx_set_cookies( $cookies );
     108      }
    105109
    106110    $widget = json_decode( wp_remote_retrieve_body( $response ) );
     
    201205
    202206function showcase_retrieve_app( $path, $query ) {
    203   $cookies = array();
    204   foreach ( $_COOKIE as $name => $value ) {
    205     $cookies[] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) );
    206   }
     207  $cookies = showcaseidx_get_cookies();
    207208
    208209  parse_str( $query, $query_vars );
     
    211212  $query_vars['bc_prune_widget'] = 1;
    212213
    213   return wp_remote_post(
    214     SHOWCASEIDX_SEARCH_HOST . '/app/render' . $path . '?' . http_build_query( $query_vars ),
    215     array(
    216       'timeout' => 10,
    217       'httpversion' => '1.1',
    218       'cookies' => $cookies,
    219       'body' => array_map( 'stripslashes', $_POST ),
    220       'headers' => array(
    221         'X-Forwarded-For' => get_client_ip(),
    222         'X-Client-User-Agent' => get_user_agent(),
    223       ),
    224     )
    225   );
     214    return wp_remote_post(
     215        SHOWCASEIDX_SEARCH_HOST . '/app/render' . $path . '?' . http_build_query( $query_vars ),
     216        array(
     217            'timeout' => 10,
     218            'httpversion' => '1.1',
     219            'cookies' => $cookies,
     220            'body' => array_map( 'stripslashes', $_POST ),
     221            'headers' => array(
     222                'X-Forwarded-For' => get_client_ip(),
     223                'X-Client-User-Agent' => get_user_agent(),
     224                'Origin' => home_url(),
     225            ),
     226        )
     227    );
    226228}
    227229
  • showcase-idx/trunk/3/routes.php

    r2755119 r3451883  
    9090  $api_url = SHOWCASEIDX_SEARCH_HOST . '/app/signin/image/';
    9191
    92   $response = wp_remote_get( $api_url . $lead_uuid, array( 'timeout' => 5, 'httpversion' => '1.1' ) );
     92  $response = wp_remote_get( $api_url . $lead_uuid, array(
     93      'timeout' => 5,
     94      'httpversion' => '1.1',
     95      'headers' => [
     96          'Origin' => home_url(),
     97      ]
     98  ) );
    9399
    94   if ( wp_remote_retrieve_response_code( $response ) == 200 ) {
    95     header( 'Set-Cookie: ' . wp_remote_retrieve_header( $response, 'set-cookie' ) );
    96     header( 'Content-Type: '. wp_remote_retrieve_header( $response, 'content-type' ) );
     100    if ( wp_remote_retrieve_response_code( $response ) == 200 ) {
     101        $cookies = wp_remote_retrieve_header( $response, 'set-cookie' );
    97102
    98     print wp_remote_retrieve_body( $response );
    99     exit;
    100   }
     103        if ( $cookies ) {
     104            showcaseidx_set_cookies( $cookies );
     105        }
     106
     107        header( 'Content-Type: ' . wp_remote_retrieve_header( $response, 'content-type' ) );
     108        echo wp_remote_retrieve_body( $response );
     109        exit;
     110    }
    101111}
     112
     113function showcaseidx_set_cookies( $cookies ) {
     114    $current_domain = parse_url( home_url(), PHP_URL_HOST );
     115    $default_expiry = time() + (90 * DAY_IN_SECONDS); // 3 months
     116
     117    foreach ( (array) $cookies as $cookie ) {
     118        $parsed = showcaseidx_parse_cookie_header( $cookie );
     119        if ( ! $parsed ) {
     120            continue;
     121        }
     122
     123        $cookie_options = array(
     124            'expires'  => $parsed['expires'] ?: $default_expiry,
     125            'path'     => $parsed['path'],
     126            'domain'   => $current_domain,
     127            'secure'   => is_ssl(),
     128            'httponly' => true,
     129            'samesite' => 'Lax',
     130        );
     131
     132        if ( version_compare( PHP_VERSION, '7.3.0', '>=' ) ) {
     133            setcookie( $parsed['name'], $parsed['value'], $cookie_options );
     134        } else {
     135            $cookie_string = sprintf(
     136                '%s=%s; expires=%s; path=%s; domain=%s; samesite=%s',
     137                $parsed['name'],
     138                $parsed['value'],
     139                gmdate( 'D, d M Y H:i:s T', $cookie_options['expires'] ),
     140                $cookie_options['path'],
     141                $cookie_options['domain'],
     142                $cookie_options['samesite']
     143            );
     144            if ( $cookie_options['secure'] ) {
     145                $cookie_string .= '; secure';
     146            }
     147            if ( $cookie_options['httponly'] ) {
     148                $cookie_string .= '; httponly';
     149            }
     150            header( 'Set-Cookie: ' . $cookie_string, false );
     151        }
     152    }
     153}
     154
     155function showcaseidx_parse_cookie_header( $cookie_header ) {
     156    $parts = explode( ';', $cookie_header );
     157    $cookie = [];
     158    foreach ( $parts as $index => $part ) {
     159        $part = trim( $part );
     160        if ( $index === 0 ) {
     161            // First part is always name=value
     162            list( $name, $value ) = explode( '=', $part, 2 );
     163            $cookie['name'] = $name;
     164            $cookie['value'] = $value;
     165        } else {
     166            if ( stripos( $part, 'expires=' ) === 0 ) {
     167                $cookie['expires'] = strtotime( substr( $part, 8 ) );
     168            } elseif ( stripos( $part, 'path=' ) === 0 ) {
     169                $cookie['path'] = substr( $part, 5 );
     170            } elseif ( stripos( $part, 'domain=' ) === 0 ) {
     171                $cookie['domain'] = substr( $part, 7 );
     172            }
     173        }
     174    }
     175    // Set defaults if not present
     176    if ( !isset( $cookie['expires'] ) ) $cookie['expires'] = 0;
     177    if ( !isset( $cookie['path'] ) ) $cookie['path'] = '/';
     178    return $cookie;
     179}
     180
     181function showcaseidx_get_cookies() {
     182    $wp_cookies = array();
     183
     184    if ( isset( $_COOKIE['sidx_token'] ) ) {
     185        $wp_cookie = new WP_Http_Cookie( array(
     186            'name'  => 'sidx_token',
     187            'value' => $_COOKIE['sidx_token'],
     188            'path'  => '/',
     189            'domain' => '',
     190        ) );
     191        $wp_cookies[] = $wp_cookie;
     192    }
     193
     194    return $wp_cookies;
     195}
  • showcase-idx/trunk/3/shortcodes.php

    r3192504 r3451883  
    106106
    107107function showcase_retrieve_widget( $widget, $attrs ) {
    108   $cookies = array();
    109   foreach ( $_COOKIE as $name => $value ) {
    110     $cookies[] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) );
    111   }
     108  $cookies = showcaseidx_get_cookies();
    112109
    113110  $query = $attrs;
     
    124121        'X-Forwarded-For' => get_client_ip(),
    125122        'X-Client-User-Agent' => get_user_agent(),
     123        'Origin' => home_url(),
    126124      ),
    127125    )
  • showcase-idx/trunk/readme.txt

    r3327660 r3451883  
    1010Requires PHP: 5.3.0
    1111
    12 Stable tag: 3.3.0
     12Stable tag: 3.3.1
    1313
    1414
     
    180180
    181181== Changelog ==
     182
     183= 3.3.1 =
     184
     185* Fixed compatibility issues with PHP 8.3 and 8.4.
     186* Resolved issues related to the Sign-in and Sign-up workflows.
     187* Improved error handling and performance optimizations.
    182188
    183189= 3.3.0 =
  • showcase-idx/trunk/showcaseidx.php

    r3327660 r3451883  
    66 * Author: Showcase IDX
    77 * Author URI: https://showcaseidx.com/
    8  * Version: 3.3.0
     8 * Version: 3.3.1
    99 * License: GPLv3
    1010 */
     
    1212// NOTE: documentation for the above header block is at https://developer.wordpress.org/plugins/plugin-basics/header-requirements/
    1313
     14@ini_set( 'display_errors', '0' );
     15@error_reporting(0 );
    1416
    1517add_option( 'showcaseidx_product_version', get_option( 'showcaseidx_api_key' ) != '' ? '2' : '3' );
Note: See TracChangeset for help on using the changeset viewer.