Tag: P_BLOG

P_BLOG本体の改造

負荷軽減

Plug-in 読込み処理を1回だけに

include/func_base.inc.php
function include_plugin($mode)
{
    global $cd, $cfg, $plugin;
+   static $done;
+
+   if (isset($done)) return;
+
    if ($handlerDir = @opendir($cd . '/include/user_include/plugins')) {
        while ($filename = readdir($handlerDir)) {
            if ($filename != '.' && $filename != '..' && preg_match('/^plg_.+\.inc\.php$/', $filename)) {
                include_once $cd . '/include/user_include/plugins/' . $filename;
            }
        }
    }
+
+   $done = true;
}

SQL へのアクセスを減らす

include/func_base.inc.php
function db_connect() 
{
    global $dbname, $host, $user, $password;
+   static $link;
+
+   if (isset($link)) return $link;
+
    $link = @mysql_connect($host, $user, $password);
    if ($link && mysql_select_db($dbname)) {
        return $link;
    } else {
+       unset($link);
        if (file_exists('./SETUP/')) {
            $update_dir = '<p class="ref">Go to <a href="./SETUP/">SETUP</a> directory.</p>';
        } else {
            $update_dir = '<p>No SETUP directory found.</p>';
        }        
function init_config()
{
    global $config_table, $cd;
+   static $cfg;
+
+   if (isset($cfg)) return $cfg;
+
    $cfg = array();
    $sql = 'SELECT * FROM `' . $config_table . '`';
    $res = mysql_query($sql);
    if ($res) {
        while ($row = mysql_fetch_assoc($res)) {
            $cfg[$row['config_key']] = $row['config_value'];
        }
    } else {
+       unset($cfg);
        if (file_exists('./SETUP/')) {
            $update_dir = '<p class="ref">Go to <a href="./SETUP/">SETUP</a> directory.</p>';
        } else {
            $update_dir = '<p>No SETUP directory found.</p>';
        }        

定量的な検証はしていないので、どの程度早くなるかは気持ちの問題が大きいような・・・。

「もっと読む」のリンク先を文書の続きに変更

include/func_logs.inc.php
function display_article_box($row) 
{
    global $cfg, $lang, $cd, $session_status, $id, $admin_dir, $article_addition;

    // Permanent Link
    if (empty($id)) {
        $permalink = '<a href="'.$cd.'/article.php?id='.$row['id'].'" title="'.
                     $lang['permalink_title_1'] . htmlspecialchars(strip_tags($row['name'])) . $lang['permalink_title_2'].
                     '" rel="Bookmark">Permalink</a> ';
-       $read_more = '<p class="read-more"><a href="' . $cd . '/article.php?id=' . $row['id'] . '" title="' . $row['name'] . '">' . $lang['more'] . '</a></p>';
+       $read_more = '<p class="read-more"><a href="' . $cd . '/article.php?id=' . $row['id'] . '#more" title="' . $row['name'] . '">' . $lang['more'] . '</a></p>';
        $row['comment'] = preg_replace('/<!-- ?more ?-->.*<!-- ?\/more ?-->/is', $read_more, $row['comment']);
        $row['comment'] = preg_replace('/<!-- ?more ?-->.*/is', $read_more, $row['comment']);
    } else {
        $permalink = '';
+       $read_more = '<span id="more"></span>';
+       $row['comment'] = preg_replace('/<!-- ?more ?-->/is', $read_more, $row['comment']);
    }
files/include/func_files.inc.php
function display_binary_box($row) 
{
    global $cfg, $lang, $cd, $session_status, $admin_dir, $http, $id;

    $bin_type = $row['bintype'];        //Check file types
    $bin_size = $row['binsize'] / 1024; // Convert "Byte" to "KB"
    $bin_size = ceil($bin_size);


    // Permanent Link
    if (empty($_GET['id'])) {
        $permalink  = '<a href="' .$cd. '/files/article.php?id=' . $row['id'] . '" title="'.
                      $lang['permalink_title_1'] . htmlspecialchars(strip_tags($row['binname'])) . $lang['permalink_title_2'].
                      '" rel="Bookmark" class="permalink">Permalink</a>';
        if (($_SERVER["SCRIPT_NAME"] != $cfg['root_path'].'files/search.php') &&
            ($_SERVER["SCRIPT_NAME"] != $cfg['root_path'].'files/search_plus.php')) {
-           $read_more = '<p class="read-more"><a href="' . $cd . '/files/article.php?id=' . $row['id'] . '" title="' . $row['bin_title'] . '">' . $lang['more'] . '</a></p>';
+           $read_more = '<p class="read-more"><a href="' . $cd . '/files/article.php?id=' . $row['id'] . '#more" title="' . $row['bin_title'] . '">' . $lang['more'] . '</a></p>';
            $row['bincomment'] = preg_replace('/<!-- ?more ?-->.*<!-- ?\/more ?-->/is', $read_more, $row['bincomment']);
            $row['bincomment'] = preg_replace('/<!-- ?more ?-->.*/is', $read_more, $row['bincomment']);
        }
    } else {
        $permalink = '';
+       $read_more = '<span id="more"></span>';
+       $row['bincomment'] = preg_replace('/<!-- ?more ?-->.*/is', $read_more, $row['bincomment']);
    }