header
來定義文件的檔頭,進而憑空生出檔案(匯出記得關除錯)。
header("Content-type: text/html"); header("Content-Disposition: attachment; filename=檔名"); echo 主要內容; exit;
tadtools/tad_function.php
中的 html5()
來套入HTML5頁面:
html5($content = "", $ui = false, $bootstrap = true, $bootstrap_version = 3, $use_jquery = true, $container='container')
iconv("UTF-8","Big5",$檔名)
,將檔名轉成Big5編碼即可。(但若遇到檔名有特殊字的,就會變成缺字了)file_put_contents ($檔名, $檔案內容);
file_put_contents(XOOPS_ROOT_PATH . "/uploads/snews/snews_{$sn}.html", $html);
file_get_contents ($檔名);
$html=file_get_contents(XOOPS_ROOT_PATH . "/uploads/snews/snews_{$sn}.html");
application/json
即可header()
來指定格式,直接echo
即可。json_encode($陣列, JSON_UNESCAPED_UNICODE);
就可把陣列轉換為json格式(JSON_UNESCAPED_UNICODE
亦可用256取代,讓中文不被編碼)
$json = json_encode($all, JSON_UNESCAPED_UNICODE); file_put_contents(XOOPS_ROOT_PATH . "/uploads/snews/focus.json", $json);
json_decode($json,true)
就可以把json轉換為PHP陣列。file_get_contents ($檔名)
來抓取!
$json = file_get_contents(XOOPS_URL . "/uploads/snews/focus.json"); $focus = json_decode($json, true);
xoops_version.php
中的區塊設定取消註解,並依序填入資料。
$modversion['blocks'] = array(); $i = 1; $modversion['blocks'][$i]['file'] = "snews_focus.php"; $modversion['blocks'][$i]['name'] = _MI_SNEWS_FOCUS; $modversion['blocks'][$i]['description'] = _MI_SNEWS_FOCUS_DESC; $modversion['blocks'][$i]['show_func'] = "snews_focus"; $modversion['blocks'][$i]['template'] = "snews_focus.tpl"; $modversion['blocks'][$i]['edit_func'] = "snews_focus_edit"; $modversion['blocks'][$i]['options'] = "1";
$i++
下方,將七個設定陣列再複製一份來修改即可。blocks/snews_focus.php
show_func
設定值一樣,例如:
<?php function snews_focus($options = ""){ } function snews_focus_edit($options = ""){ }
$options
參數,如:$options[0]
xoops_version.php
中的options
設定值,根據「|
」拆開後,第一個值就是$options[0]
,第二個值就是$options[1]
依此類推。
function snews_focus($options = "") { $json = file_get_contents(XOOPS_URL . "/uploads/snews/focus.json"); $focus = json_decode($json, true); $rand_focus = array_rand($focus, $options[0]); if (is_array($rand_focus)) { foreach ($rand_focus as $k) { $block[] = $focus[$k]; } } else { $block[] = $focus[$rand_focus]; } return $block; }
array_rand($陣列,數量)
用來隨機取得陣列索引,若指定數量為1,則傳回數字;若指定數量大於1,則傳回陣列。return
即可,可以是陣列,也可以是單一值,變數名稱不拘。<form></form>
。
function snews_focus_edit($options = "") { $form = "顯示文章數:<input type='text' name='options[0]' value='{$options[0]}'>"; return $form; }
snews_focus.tpl
,樣板放在「templates/blocks
」下。<{$block}>
,不管顯示函數傳回的變數名稱為何。
<div class="container"> <{foreach from=$block item=focus}> <div class="row"> <div class="col-sm-3"> <img src="<{$focus.cover}>" class="img-responsive img-rounded"> </div> <div class="col-sm-9"> <h3><{$focus.title}></h3><{$focus.content2}> </div> </div> <{/foreach}> <div class="text-right"> <a href="<{$xoops_url}>/modules/snews/focus.php">[閱讀更多]</a> </div> </div>
<{$xoops_url}>
function word_cut($string, $limit, $pad = "...") { $len = mb_strlen($string, 'UTF-8'); if ($len <= $limit) { return $string; } //先找出裁切後的字串有多少英文字 $tmp_content = mb_substr($string, 0, $limit, 'UTF-8'); preg_match_all('/(\w)/', $tmp_content, $match); $eng = count($match[1]); $add = round($eng / 2, 0); $limit += $add; $string = mb_substr($string, 0, $limit, 'UTF-8'); return $string . $pad; }