Skip to main content.

[14] インライン画像のサムネイル表示

大きい画像はインライン表示の際に小さい画像にリサイズして(サムネイル)表示し、サムネイルをクリックすれば基の大きい画像をポップアップ表示させる機能を追加する改造です。

※ かなり修正箇所が多いので、修正前のファイルを必ずバックアップしてください。不都合が起きても責任は負えません。

用意するもの:
GD自動サムネイル作成
↑ここより「gdthumb.zip」をダウンロード、解凍。

修正するプログラムファイル:
nucleus\libディレクトリ内の
BLOG.php
ADMIN.php
japanese.php
の3つのファイル。 1)gdthumb.phpの設定編集
mediaディレクトリ内に生成された「gdthumb.php」を置く。
ファイルを開き、
27行目========
$img_pass = "./";
==============
と設定する。

または、
$img_pass = "/home/user/public_html/media/";
のように絶対指定も可。

以下の残り3つも設定。
//表示画像の最大幅(デフォルト値)
//表示画像の最大縦幅
//GDのバージョン(0 = 2.0以前 / 1 = 2.0以降)

FTP転送後、URLを叩いて動作確認してください。
例;
http://xx.nakahara21.net/media/gdthumb.php?pass=1/1.gif

2) BLOG.phpの編集
◆880行目付近
function getDefinedActions()内のarrayにある、
'image',
'popup',
という行を
'image',
'timage',
'popup',
という具合に、'timage'要素を追加。

◆1060行目付近function parse_image()と、
1070行目付近function parse_popup()との間に、function追加
==============
function parse_timage() {
// image/popup calls have arguments separated by |
$args = func_get_args();
$args = explode('|',implode($args,', '));
call_user_func_array(array(&$this,'createTimageCode'),$args);
}
==============

◆function highlightAndParse(&$data)内の
        $this->parser->actions = array('image','media','popup');
を以下のように修正。
        $this->parser->actions = array('image','timage','media','popup');
※その上の行に怖いこと書いてますが(^_^;


◆function createImageCodeとfunction createMediaCodeとの間にfunction追加。
==============
    function createTimageCode($filename, $width, $height, $text = '') {
        global $CONF;
        
        // select private collection when no collection given
        if (!strstr($filename,'/')) {
            $filename = $this->currentItem->authorid . '/' . $filename;
        }
        
        $windowwidth = $width;
        $windowheight = $height;
        
        $vars['link']            = htmlspecialchars($CONF['MediaURL']. 'gdthumb.php?pass=' . $filename);
        $vars['text']            = htmlspecialchars($text);
        $vars['timage'] = '<img src="' . $vars['link'] . '" alt="' . $vars['text'] . '" />';
        $vars['width']             = $width;
        $vars['height']            = $height;
        $vars['rawpopuplink']     = $CONF['Self'] . "?imagepopup=" . htmlspecialchars($filename) . "&width=$width&height=$height&imagetext=" . htmlspecialchars($text);
        $vars['popupcode']         = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;";
        $vars['popuptext']         = htmlspecialchars($text);
        $vars['popuplink']         = '<a href="' . $vars['rawpopuplink']. '" onclick="'. $vars['popupcode'].'" >' . $vars['timage'] . '</a>';
                
        
        
        echo TEMPLATE::fill($this->template['TIMAGE_CODE'],$vars);;

    }
==============

◆保存後FTP上書き転送。


3) ADMIN.phpの編集
◆3180行目付近
    $this->_templateEditRow($template, _TEMPLATE_ICODE, 'IMAGE_CODE', '', 250);            
という行の下に次の1行追加
==============
    $this->_templateEditRow($template, _TEMPLATE_ITCODE, 'TIMAGE_CODE', '', 250000);            
==============

◆3280行目付近
        $this->addToTemplate($templateid, 'IMAGE_CODE', postVar('IMAGE_CODE'));
という行の下に1行追加
==============
        $this->addToTemplate($templateid, 'TIMAGE_CODE', postVar('TIMAGE_CODE'));
==============

◆保存後FTP上書き転送。

4)テンプレート編集時のタイトル表示
japanese.phpの568行目
define('_TEMPLATE_ICODE',            'インライン画像のコード');
の下に次の一行追加
==============
define('_TEMPLATE_ITCODE',            'サムネイル画像のコード');
==============

◆保存後FTP上書き転送。

5)テンプレート編集
「サムネイル画像のコード」欄に<%popuplink%>と書きます。
これだけで、勝手にサムネイル表示してポップアップリンクを貼ります。
なお、この欄で使用できるコードは、
<%popuplink%>
のほかに、
<%timage%>
<%link%>
<%text%>
<%width%>
<%height%>
と、インライン画像と同様。さらに、
<%popuplink%>
<%rawpopuplink%>
<%popupcode%>
も使用できます。


6)アイテムの作成又は編集
埋込み式の画像を配置する手順でテキストエリアにコードが挿入されたら、
例;
<%image(20030624-122m.jpg|94|140|[テキスト])%>

<%timage(20030624-122m.jpg|94|140|[テキスト])%>
という具合に、「t」1文字を挿入すればサムネイル表示&ポップアップリンクが表示されます。

※ 縦幅、横幅はオリジナル画像のサイズを入れてください。(生成されたコードをそのまま使う)。
表示されるサムネイルの大きさは、一番最初にgdthumb.phpで定義したサイズになりますので。
(引数渡してサムネイルの大きさもその都度指定できると、もっと便利になるんでしょうか?またまただいぶ面倒だけど、やってできない事はないかもしれないけど...)

Comments

かなりやばかったです

Posted by エロアニメ at 07/01/10 23:09:33

Add Comment

:

:
: