一、程式
case "opShow": opShow($sn); break;
二、函數
#單筆顯示 function opShow($sn = "") { global $xoopsDB,$xoopsTpl,$module_name; if (!$sn) { redirect_header(XOOPS_URL, 3, "資料錯誤!!"); } #---- 過濾讀出的變數值 ---- $myts = MyTextSanitizer::getInstance(); //sn kind kind_gallery title summary content price amount enable date sort $sql = "select a.*,b.title as kind_title from " . $xoopsDB->prefix("cnu_show_prod") . " as a left join " . $xoopsDB->prefix("cnu_show_kind") . " as b on a.kind=b.sn where a.sn='{$sn}' and a.enable='1' "; //die($sql); $result = $xoopsDB->query($sql) or redirect_header(XOOPS_URL, 3, web_error()); $row = $xoopsDB->fetchArray($result); #----------------------------------------------------- if (!$row) { redirect_header(XOOPS_URL, 3, "資料錯誤!!"); } #計數器+1 InsertCounteAddOne($row['sn'], "cnu_show_prod"); //ugm_tools2/ugmTools.php #----------------------------------------------------- //以下會產生這些變數: a.sn,a.kind,a.title,a.url,a.content,b.file_name,b.sub_dir $row['sn'] = intval($row['sn']); $row['kind'] = intval($row['kind']); #一般文字 $row['title'] = $myts->htmlSpecialChars($row['title']); $row['date'] = intval($row['date']); #日期 $row['date'] = date("Y-m-d", xoops_getUserTimestamp($row['date'])); //從資料庫撈出 $row['counter'] = intval($row['counter']); $row['kind_title'] = $myts->htmlSpecialChars($row['kind_title']); $row['youtube'] = $myts->htmlSpecialChars($row['youtube']);//大類名稱 #大量文字, $html = 0; $br = 1; $row['summary'] = $myts->displayTarea($row['summary'], $html, 1, 0, 1, $br); #大量文字,編輯器 $html = 1; $br = 0; $row['content'] = $myts->displayTarea($row['content'], $html, 1, 0, 1, $br); #----單檔圖片上傳 $subdir = "prod"; //子目錄(前後不要有 / ) $ugmUpFiles = new ugmUpFiles($module_name, $subdir); //實體化 $col_name = "prod"; //資料表關鍵字 $thumb = false ; //顯示縮圖 $col_sn = $row['sn']; //關鍵字流水號 $row['prod'] = $ugmUpFiles->get_rowPicSingleUrl($col_name,$col_sn,$thumb); #----------------------------------------------------- #型錄 #上傳pdf型錄 $multiple = false; $col_name = "prodPdf"; $ugmUpFiles->set_col($col_name, $row['sn']); $row['pdf'] = $ugmUpFiles->get_rowFileSingleUrl($col_name, $row['sn']); #----------------------------------------------------- $xoopsTpl->assign("row", $row); #----------------------------------------------------- }
三、樣板
<{if $op == "opShow"}> <style type="text/css"> .prod-head { padding: 10px; background-color: #333; color:#fff; } .space-10{ height:10px; } .space-20{ height:20px; } .space-30{ height:30px; } .space-40{ height:40px; } .space-50{ height:50px; } .space-60{ height:60px; } .show{ padding-bottom:50px; letter-spacing: 1.5px; font-family: -apple-system,"PingFang SC","Helvetica Neue","Hiragino Sans GB","Microsoft YaHei","Microsoft JhengHei","Source Han Sans SC","Noto Sans CJK SC","Source Han Sans CN","Noto Sans SC","Source Han Sans TC","Noto Sans CJK TC","WenQuanYi Micro Hei",SimSun,sans-serif; } .mg-post h1{ font-size:24px; color:#000; } .mg-post .mg-post-title { margin-bottom: 15px; } } .mg-post .mg-post-title a { color: #16262e; } .mg-post .mg-post-title a:hover { color: #e7b315; } .mg-post .mg-post-meta { border-bottom: 1px solid #f2f2f2; margin-bottom: 20px; color: #96a3a9; } .mg-post .mg-post-meta span { padding-right: 10px; } .mg-post .mg-post-meta span:after { content: '/'; padding-left: 15px; color: #0f0f0f; } #show .mg-post .mg-post-meta span:last-child:after { content: ''; padding-left: 0; } .mg-post .mg-post-meta a { color: #0f0f0f; } .mg-post .mg-post-meta a:hover { color: #e7b315; } .mg-post .mg-read-more { font-family: "Playfair Display", serif; font-style: italic; font-size: 15px; } .mg-post-title i { display: block; width: 60px; line-height: 60px; background-color: #32c5d2; text-align: center; font-size: 40px; color: #000; border-radius: 50%; float: left; -webkit-transition: background-color 0.3s; transition: background-color 0.3s; } .content{ line-height: 1.7; font-size: 16px; color: #404040; font-family: -apple-system,"PingFang SC","Helvetica Neue","Hiragino Sans GB","Microsoft YaHei","Microsoft JhengHei","Source Han Sans SC","Noto Sans CJK SC","Source Han Sans CN","Noto Sans SC","Source Han Sans TC","Noto Sans CJK TC","WenQuanYi Micro Hei",SimSun,sans-serif; } .show img{ border: 2px solid #fafafa; border-radius: 8px; background-image: -webkit-gradient(linear, center top, center bottom, from(#fcfcfc), to(#bfbfbf), color-stop(3%, #f7f7f7), color-stop(12%, #f2f2f2), color-stop(90%, #d9d9d9)); background-image: -webkit-linear-gradient(top, #fcfcfc, #f7f7f7 3%, #f2f2f2 12%, #d9d9d9 90%, #bfbfbf); background-image: -moz-linear-gradient(top, #fcfcfc, #f7f7f7 3%, #f2f2f2 12%, #d9d9d9 90%, #bfbfbf); background-image: -o-linear-gradient(top, #fcfcfc, #f7f7f7 3%, #f2f2f2 12%, #d9d9d9 90%, #bfbfbf); background-image: -ms-linear-gradient(top, #fcfcfc, #f7f7f7 3%, #f2f2f2 12%, #d9d9d9 90%, #bfbfbf); background-image: linear-gradient(to bottom, #fcfcfc, #f7f7f7 3%, #f2f2f2 12%, #d9d9d9 90%, #bfbfbf); -webkit-box-shadow: 0 1px 1px 1px rgba(58,60,61,0.75), inset 0 1px 0 #f5f5f5; -moz-box-shadow: 0 1px 1px 1px rgba(58,60,61,0.75), inset 0 1px 0 #f5f5f5; box-shadow: 0 1px 1px 1px rgba(58,60,61,0.75), inset 0 1px 0 #f5f5f5; } </style> <div id="show" class="show"> <!--內容--> <div class="row"> <div class="col-sm-4"> <a href="#myModal" data-toggle="modal" > <img src="<{$row.prod}>" class="img-responsive" alt="<{$row.title}>"> </a> </div> <div class="col-sm-8 mg-post"> <h1><{$row.title}></h1> <div class="mg-post-meta"> <span><{$row.date}></span> <span> <a href="<{xoAppUrl modules/cnu_show/index.php?op=showKind&kind=}><{$row.kind}>"><{$row.kind_title}></a> </span> <span><{$row.counter}></span> <{if $isAdmin}> <span> <a href="<{xoAppUrl modules/cnu_show/admin/main.php?op=opForm&sn=}><{$row.sn}>"><{$smarty.const._EDIT}></a> </span> <{/if}> </div> <div style="margin:10px 0;" id="link"> <{if $row.pdf}> <a href="<{$row.pdf}>" title="<{$row.title}>" class="btn btn-info btn-lg" target="_blank" >型錄</a> <{/if}> <{if $row.youtube}> <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#Modal-Movie">影片</button> <{/if}> </div> </div> </div> <div class="space-20"></div> <div class="row"> <div class="col-sm-12"> <{$row.content}> </div> </div> </div> <!-- Modal --> <div class="modal fade" id="myModal" role="dialog" style="padding-top:50px;"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title text-center" style="color:#000;"><{$row.title}></h4> </div> <div class="modal-body"> <img src="<{$row.prod}>" class="img-responsive " alt="<{$row.title}>"> </div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> </div> </div> </div> </div> <{if $row.youtube}> <!-- Modal --> <div class="modal fade" id="Modal-Movie" role="dialog" style="padding-top:50px;"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title text-center" style="color:#000;"><{$row.title}></h4> </div> <div class="modal-body"> <div class="video-container"> <iframe width="560" height="315" src="https://www.youtube.com/embed/<{$row.youtube}>" frameborder="0" allowfullscreen></iframe> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> </div> </div> </div> </div> <{/if}> <{/if}>