<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="ARTICLE @ XOOPS powered by FeedCreator" -->
<rss version="0.91">
    <channel>
        <title>睡蓮‧池水間 :: 文章</title>
        <description><![CDATA[文章XML]]></description>
        <link>http://waterlily-lsl.com/modules/article/view.article.php/184/c11</link>
        <lastBuildDate>Sat, 11 Feb 2012 03:55:30 +0200</lastBuildDate>
        <generator>ARTICLE @ XOOPS powered by FeedCreator</generator>
        <image>
            <url>http://waterlily-lsl.com/modules/article/images/logo.png</url>
            <title>睡蓮‧池水間 :: 文章</title>
            <link>http://waterlily-lsl.com/modules/article/</link>
            <width>92</width>
            <height>52</height>
            <description>文章XML</description>
        </image>
        <language>zh-TW</language>
        <managingEditor>waterlily at waterlily-lsl dot com</managingEditor>
        <webMaster>waterlily at waterlily-lsl dot com</webMaster>
        <category>文章</category>
        <item>
            <title>讓個別模組單獨顯示於評論區塊</title>
            <link>http://waterlily-lsl.com/modules/article/view.article.php/184/c11</link>
            <description><![CDATA[類別: xoops<br />來源: (池水間)現時XOOPS系統預設的評論區塊只提供一個，將不同模組的最新評論匯集在一起，依發表時間的先後來排序。如果使用帶評論功能的模組不多，基本上一個評論區塊已足夠使用。<br /><br />不過鑑於目前有人對獨立評論區塊的需求，為此寫一篇詳細教學，讓使用者去增設多個評論區塊。<br /><br />目前預設評論區塊裡的表格分為圖示、標題、模組名稱、發表者和發表時間共五欄，當增設多個評論區塊後，由於可在區塊標題上標示模組名稱，表格裡頭的模組名稱欄位就變得多餘了，因此在進行區塊複製之前，先將模組名稱欄位的代碼去掉。<br /><br />以下是/modules/system/templates/blocks/system_block_comments.html 裡的評論區塊代碼，橘字部份是模組名稱欄，可以將它刪除或加上如下綠色地方將之註解掉。<br /><div class="xoopsCode"><p class="cTitle"><img class="icon-l" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif" alt=""/><img class="icon-r" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif" alt=""/></p><pre>
&lt;table width=&quot;100%&quot; cellspacing=&quot;1&quot; class=&quot;outer&quot;&gt;
  &lt;{foreach item=comment from=$block.comments}&gt;
  &lt;tr class=&quot;&lt;{cycle values=&quot;even,odd&quot;}&gt;&quot;&gt;
    &lt;td align=&quot;center&quot;&gt;&lt;img src=&quot;&lt;{$xoops_url}&gt;/images/subject/&lt;{$comment.icon}&gt;&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;td&gt;&lt;{$comment.title}&gt;&lt;/td&gt;
 <span style="color: #00ff00;">&lt;{*</span> <span style="color: #ffac00;">&lt;td align=&quot;center&quot;&gt;&lt;{$comment.module}&gt;&lt;/td&gt;</span> <span style="color: #00ff00;">*}&gt;</span>
    &lt;td align=&quot;center&quot;&gt;&lt;{$comment.poster}&gt;&lt;/td&gt;
    &lt;td align=&quot;right&quot;&gt;&lt;{$comment.time}&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;{/foreach}&gt;
&lt;/table&gt;
</pre></div><br /><br />接下來建立新檔案，假設這是給新聞模組用的評論區塊，可以將它命名為system_block_comments<span style="color: #ffac00;">_news</span>.html。打開新建的檔案，將 system_block_comments.html 裡面代碼全複製到 system_block_comments<span style="color: #ffac00;">_news</span>.html 裡。<br /><br />打開 /modules/system/xoops_version.php，將下圖的「1」複製到「2」位置<br /><span style="background:url(/uploads/article/images/090614.gif) no-repeat;width:650px;height:604px;display:block"><!--090614.gif--></span><br />然後將「2」裡每一行的數值[10 ]改為[13]，與上方小綠框裡的數值[12]成為連號。<br /><br /><div class="xoopsCode"><p class="cTitle"><img class="icon-l" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif" alt=""/><img class="icon-r" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif" alt=""/></p><pre>
$modversion[&#039;blocks&#039;][13][&#039;file&#039;] = &quot;system_blocks.php&quot;;
$modversion[&#039;blocks&#039;][13][&#039;name&#039;] = <span style="color: #ffac00;">_MI_SYSTEM_BNAME11</span>;
$modversion[&#039;blocks&#039;][13][&#039;description&#039;] = &quot;Shows most recent comments&quot;;
$modversion[&#039;blocks&#039;][13][&#039;show_func&#039;] = &quot;b_system_comments_show&quot;;
$modversion[&#039;blocks&#039;][13][&#039;options&#039;] = &quot;10&quot;;
$modversion[&#039;blocks&#039;][13][&#039;edit_func&#039;] = &quot;b_system_comments_edit&quot;;
$modversion[&#039;blocks&#039;][13][&#039;template&#039;] = &#039;<span style="color: #00ff00;">system_block_comments.html</span>&#039;;
</pre></div><br />將上面綠色檔名改為system_block_comments<span style="color: #ffac00;">_news</span>.html，再將上面橘色一行的 _MI_SYSTEM_BNAME<span style="color: #ffac00;">11</span>改為_MI_SYSTEM_BNAME<span style="color: #00ff00;">14</span>，並在 /modules/system/language/選用的語言/modinfo.php下第24行的 _MI_SYSTEM_BNAME<span style="color: #ffac00;">13</span> 後面加入如下<br /><div class="xoopsCode"><p class="cTitle"><img class="icon-l" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif" alt=""/><img class="icon-r" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif" alt=""/></p><pre>
define(&#039;_MI_SYSTEM_BNAME13&#039;, &quot;網站佈景&quot;);
<span style="color: #00ff00;">define(&#039;_MI_SYSTEM_BNAME14&#039;, &quot;這是區塊名稱&quot;);</span>
</pre></div><br />或是直接在原來的檔案下將它改成如下帶引號的中文也可。<br /><div class="xoopsCode"><p class="cTitle"><img class="icon-l" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif" alt=""/><img class="icon-r" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif" alt=""/></p><pre>
$modversion[&#039;blocks&#039;][13][&#039;file&#039;] = &quot;system_blocks.php&quot;;
$modversion[&#039;blocks&#039;][13][&#039;name&#039;] =<span style="color: #ffac00;">&quot;這是區塊名稱例如命名為新聞評論&quot;</span>;
$modversion[&#039;blocks&#039;][13][&#039;description&#039;] = &quot;Shows most recent comments&quot;;
$modversion[&#039;blocks&#039;][13][&#039;show_func&#039;] = &quot;b_system_comments_show&quot;;
$modversion[&#039;blocks&#039;][13][&#039;options&#039;] = &quot;10&quot;;
$modversion[&#039;blocks&#039;][13][&#039;edit_func&#039;] = &quot;b_system_comments_edit&quot;;
$modversion[&#039;blocks&#039;][13][&#039;template&#039;] = &#039;system_block_comments_news.html&#039;;
</pre></div><br />接下來打開 /modules/system/blocks/system_blocks.php，將大約361行位置註解掉(見下面綠色雙斜槓)，並在下一行加入如下綠色的一行：<br /><div class="xoopsCode"><p class="cTitle"><img class="icon-l" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif" alt=""/><img class="icon-r" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif" alt=""/></p><pre>
    // Check modules permissions

    $comments = $comment_handler-&gt;getObjects($criteria, true);
    $member_handler =&amp; xoops_gethandler(&#039;member&#039;);
    $module_handler =&amp; xoops_gethandler(&#039;module&#039;);
    $modules = $module_handler-&gt;getObjects(new Criteria(&#039;hascomments&#039;, 1), true);
    $comment_config = array();
    foreach (array_keys($comments) as $i) {
        $mid = $comments[$i]-&gt;getVar(&#039;com_modid&#039;);
        <span style="color: #00ff00;">//</span>$com[&#039;module&#039;] = &#039;&lt;a href=&quot;&#039;.XOOPS_URL.&#039;/modules/&#039;.$modules[$mid]-&gt;getVar(&#039;dirname&#039;).&#039;/&quot;&gt;&#039;.$modules[$mid]-&gt;getVar(&#039;name&#039;).&#039;&lt;/a&gt;&#039;;
       <span style="color: #00ff00;">$com[&#039;module&#039;] = $modules[$mid]-&gt;getVar(&#039;dirname&#039;);</span>
        if (!isset($comment_config[$mid])) {
            $comment_config[$mid] = $modules[$mid]-&gt;getInfo(&#039;comments&#039;);
        }
        $com[&#039;id&#039;] = $i;
        $com[&#039;title&#039;] = &#039;&lt;a href=&quot;&#039;.XOOPS_URL.&#039;/modules/&#039;.$modules[$mid]-&gt;getVar(&#039;dirname&#039;).&#039;/&#039;.$comment_config[$mid][&#039;pageName&#039;].&#039;?&#039;.$comment_config[$mid][&#039;itemName&#039;].&#039;=&#039;.$comments[$i]-&gt;getVar(&#039;com_itemid&#039;).&#039;&amp;com_id=&#039;.$i.&#039;&amp;com_rootid=&#039;.$comments[$i]-&gt;getVar(&#039;com_rootid&#039;).&#039;&amp;&#039;.htmlspecialchars($comments[$i]-&gt;getVar(&#039;com_exparams&#039;)).&#039;#comment&#039;.$i.&#039;&quot;&gt;&#039;.$comments[$i]-&gt;getVar(&#039;com_title&#039;).&#039;&lt;/a&gt;&#039;;
</pre></div><br />接下來給每個區塊指定評論模組名稱，例如 /modules/system/templates/blocks/system_block_comments<span style="color: #ffac00;">_news</span>.html  這個檔是給新聞模組的，那就在裡面加上橘字smarty語法如下<br /><div class="xoopsCode"><p class="cTitle"><img class="icon-l" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif" alt=""/><img class="icon-r" src="http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif" alt=""/></p><pre>
&lt;table width=&quot;100%&quot; cellspacing=&quot;1&quot; class=&quot;outer&quot;&gt;
  &lt;{foreach item=comment from=$block.comments}&gt;
  <span style="color: #ffac00;">&lt;{if $comment.module eq</span><span style="color: #ff0000;"> news</span><span style="color: #ffac00;">}&gt;</span>
  &lt;tr class=&quot;&lt;{cycle values=&quot;even,odd&quot;}&gt;&quot;&gt;
    &lt;td align=&quot;center&quot;&gt;&lt;img src=&quot;&lt;{$xoops_url}&gt;/images/subject/&lt;{$comment.icon}&gt;&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;td&gt;&lt;{$comment.title}&gt;&lt;/td&gt;
 <span style="color: #00ff00;">&lt;{*</span> &lt;td align=&quot;center&quot;&gt;&lt;{$comment.module}&gt;&lt;/td&gt; <span style="color: #00ff00;">*}&gt;</span>
    &lt;td align=&quot;center&quot;&gt;&lt;{$comment.poster}&gt;&lt;/td&gt;
    &lt;td align=&quot;right&quot;&gt;&lt;{$comment.time}&gt;&lt;/td&gt;
  &lt;/tr&gt;
<span style="color: #ffac00;">&lt;{/if}&gt;</span>
  &lt;{/foreach}&gt;
&lt;/table&gt;
</pre></div><br />上面橘字smarty語法中的紅字為模組名稱；另外預設的 /modules/system/templates/blocks/system_block_comments.html 這個檔，可以依樣畫葫蘆，加入如上的另一個模組名稱的smarty。<br /><br />到後台更新system模組後，就可以到區塊管理去進行多個評論區塊的設定了。<br />]]></description>
            <author>睡蓮</author>
            <pubDate>Mon, 15 Jun 2009 00:20:47 +0200</pubDate>
        </item>
    </channel>
</rss>

