Welcome to Geeklog, Anonymous Friday, March 29 2024 @ 04:59 am EDT

Geeklog Forums

Geeklog v2.2.1 - Manual Fix for #884 - Update Search Cache for Staticpages that are template or


Status: offline

Laugh

Site Admin
Admin
Registered: 09/27/05
Posts: 1468
Location:Canada
This is in regards to the following bug https://github.com/Geeklog-Core/geeklog/issues/884

If you use Static Pages with PHP or templates, the search results returned by Geeklog could show any code embedded in the page. This has now been fixed as all pages that use these features will now save a cached copy of the final executed page. This cached page is generated on the save of the page in the editor and (if page cache enabled) when a new cached file of the page is made. This means that all users that have access to the page will use the same search cache. If autotags, PHP, or the is device_mobile template variable is used by the page this may generate different contents depending on the user. Since the search cache is only one view of the page it will be the one searched. Therefore what the search result returns may be slightly different than what the user will see when they visit the page. Please take this short coming into consideration when using template and php pages and having the "Include in Search" config option set to true (config options includesearchphp and/or includesearchtemplate).

Unfortunately, updating this search cache during the install is not possible as runtime errors could occur (if for example the page needs something that the installer cannot access) or other issues could crop up (like a php redirect stored in a staticpage) and will interrupt the install.

Therefore after the upgrade, before these pages search cache can be created and searched on, you must: Pages that are not cached must be saved again, Pages that use the page cache must be visited or saved again. These pages will not appear in the search results until this is done.

For an automated script to perform this process automatically after the upgrade is complete, create a text file with the following name "fix-staticpage-issue-884.php" in the public_html directory of your geeklog website. Add the code below to the file and save it.

Please make sure all staticpages that could cause runtime errors or redirects are saved as a draft so that this script can execute.

Text Formatted Code

<?php

require_once 'lib-common.php';

global $_CONF, $_GROUPS, $_TABLES, $MESSAGE, $_USER;

COM_errorLog("Someone has run a custom Geeklog Database Upgrade Routine {$_SERVER["SCRIPT_NAME"]}  User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: " . $_SERVER['REMOTE_ADDR'],1);

$display = '<h1>Custom Development Database Update</h1>';
$display .= '<p>Update Search Cache for Staticpages that are template or PHP pages. Related to Issue #<a href="https://github.com/Geeklog-Core/geeklog/issues/884" target="_blank">884</a></p>';
$display .= '<p>When running this process you should be an anonymous user.</p>';
$display .= '<p>Any Staticpage PHP page or Template page that cannot execute successfully should be set as a draft page else this process could error out.</p>';

$display .= "<p><strong>Starting Process</strong></p>";

$display .= "<p><em>WORKING</em></p>";

// For Root users only
if (COM_isAnonUser()) {
        // Now find the php pages and template pages and update search cache
        // Note Code can cause runtime errors if the template page or php page requires something that is not accessible by the Geeklog Installer

        $sql = "SELECT * FROM {$_TABLES['staticpage']}
                WHERE draft_flag = 0 AND (template_id !='' OR sp_php > 0)";
               
        $result = DB_query($sql);
        $nrows = DB_numRows($result);

        for ($i = 0; $i < $nrows; $i++) {
                $A = DB_fetchArray($result);

                $display .= "<p><strong>Updating:</strong> {$A['sp_id']}</p>";
                COM_errorLog("Updating: {$A['sp_id']}");
               
                if ($A['sp_php'] > 0) {
                        if ($A['sp_php'] == 1) {
                                $search_sp_content = eval($A['page_data']);
                        } elseif ($A['sp_php'] == 2) {
                                ob_start();
                                eval($A['page_data']);
                                $search_sp_content = ob_get_contents();
                                ob_end_clean();
                        }
                } else {
                        $search_sp_content = SP_returnStaticpage($A['sp_id'], 'autotag');
                }

                $search_sp_content = DB_escapeString($search_sp_content);
                $sqlB = "UPDATE {$_TABLES['staticpage']} SET sp_content = '$search_sp_content' WHERE sp_id = '{$A['sp_id']}'";
                $resultB = DB_query($sqlB);
        }
       
        COM_errorLog("Finished Upgrade Routine Successfully.");
        $display .= "<p><strong>Finished Process</strong></p>";

        CTL_clearCache();
       
        $display .= '<p>The Geeklog Custom Development Database Update has completed.</p>';
} else {
        $display .= '<p><em>Error:</em> You need to be an anonymous user when you run this process.</p>';
}

$display .= '<p><em>Important:</em> Remember to delete the script file <code>' . $_SERVER["SCRIPT_NAME"] . '</code> once this process has run successfully.</p>
             <p>Please visit the <a href="https://www.geeklog.net/forum/viewtopic.php?showtopic=97115" target="_blank">Geeklog Support Forums</a> if you have any questions or run into any problems.</p>';

$display = COM_createHTMLDocument($display, array('pagetitle' => $MESSAGE[40]));
COM_output($display);
 


Using your browser then visit the file to execute the code (you must be an anonymous user to run the code).

Once complete, delete the file (DO NOT FORGET THIS).
One of the Geeklog Core Developers.
 Quote

All times are EDT. The time is now 04:59 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content