:::
6-8 過濾所有讀出的函數
- 過濾 show_action 函數
//顯示單一活動 function show_action($action_id) { global $xoopsDB, $xoopsTpl; $tbl = $xoopsDB->prefix('actions'); $sql = "SELECT * FROM `{$tbl}` WHERE `action_id` ='{$action_id}'"; $result = $xoopsDB->query($sql) or web_error($sql); $action = $xoopsDB->fetchArray($result); $myts = MyTextSanitizer::getInstance(); $action['title'] = $myts->htmlSpecialChars($action['title']); $action['content'] = $myts->displayTarea($action['content'], 1, 1, 1, 1, 0); $xoopsTpl->assign('action', $action); } -
過濾 list_action 函數
//顯示活動列表 function list_action() { global $xoopsDB, $xoopsTpl; $tbl = $xoopsDB->prefix('actions'); $sql = "SELECT * FROM `{$tbl}` WHERE `enable` ='1' AND `end_date` > now() ORDER BY `end_date` DESC"; $result = $xoopsDB->query($sql) or web_error($sql); $myts = MyTextSanitizer::getInstance(); while ($action = $xoopsDB->fetchArray($result)) { $action['title'] = $myts->htmlSpecialChars($action['title']); $action['content'] = $myts->displayTarea($action['content'], 1, 1, 1, 1, 0); $actions[] = $action; } $xoopsTpl->assign('actions', $actions); }
6-7 讀出資料的安全性過濾