P_BLOG本体の改造
Tag: 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;
}
/*
 * Load Plug-in Modules
 */
function include_plugin($mode)
{
    global $cd, $cfg, $plugin;
+   static $done;
+
+   if ($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>';
        }        
PHPがセーフモードの場合、mb_send_mail の additional_parameters が無効になるので、エラーとなる。この場合、./var/feedback/contents/feedback.inc.php の94行目を次のように変更する。(5つ目のパラメータを外すだけ)
if (mb_send_mail($cfg['sendmail_address'], $subject, $message, $header, $param)) {
if (mb_send_mail($cfg['sendmail_address'], $subject, $message, $header)) {
定量的な検証はしていないので、どの程度早くなるかは気持ちの問題が大きいような・・・。

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

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']);
    }
画像などのバイナリファイルを「resources」フォルダにアップロードすると、FTPソフトなどで、そのファイルのダウンロードやパーミッションの変更が出来なくなる。 これは、アップロードされたファイルのパーミッションが「600」となるのが原因のよう。(うちのサーバーだけの問題かも?) 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']);
    }
function file_uploaded() 
{
    global $cfg, $lang;
    // upload binary resources to the specified "resources" directory
    $file_uploaded = '<table summary="Uploaded Files">'.
                     '<tr><th colspan="3" abbr="Resource Directory">'.$lang['resource_dir'].' : '.
                     '<strong><a href="'.$cfg['uploaddir'].'">'.$cfg['uploaddir']."</a></strong></th></tr>\n";
    for ($i = 1; $i < $cfg['up_img_max']+1; $i++){
        if(isset($_FILES['myfile'])) {
            if (move_uploaded_file($_FILES['myfile']['tmp_name'][$i],
                                   $cfg['uploaddir'] . $_FILES['myfile']['name'][$i])) {
+               ///// 追加ここから ///// Change file mode to 644
+               chmod ($cfg['uploaddir'] . $_FILES['myfile']['name'][$i], 0644);
+               ///// 追加ここまで /////
                $file_uploaded .= '<tr><td>'.$lang['file'].$i.'</td><td>'.$lang['upload_ok']."</td>\n".
                                  '<td>'.
                                  $lang['file_name'].' : '.$_FILES['myfile']['name'][$i].'<br />'.
                                  $lang['file_type'].' : '.$_FILES['myfile']['type'][$i].'<br />'.
                                  $lang['file_size'].' : '.$_FILES['myfile']['size'][$i].' bytes<br />'.
                                  $lang['temp_name'].' : '.$_FILES['myfile']['tmp_name'][$i].'<br />'.
                                  $lang['error_msg'].' : '.$_FILES['myfile']['error'][$i].'<br />'.
                                  '</td></tr>';
            } else {
                $file_uploaded .= '<tr><td>'.$lang['file'].$i.'</td><td>'.$lang['no_files_added'].'</td>'.
                                  '<td>0</td></tr>'; 
            }
        }
    }
    $file_uploaded .= '</table>';
    return $file_uploaded;
}

カテゴリ : P_BLOG