🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
获取某篇文章信息 `GetOneArchive($id)` ~~~ [typeid] => 6 [click] => 219 [title] => KBS 2TV电视剧[适合] [writer] => 管理员 [litpic] => public/images/222.jpg [pubdate] => 1530861461 [arcurl] => /html/gszx/1.html 静态地址 ~~~ ip `GetIP()` 字符截取 `cn_substr($str, $slen, $startdd=0) `字符截取 格式化时间` MyDate('Y-m-d H:i:s',@me)` 转换时间戳 GetMkTime(@me) 友好时间 FloorTime(@me) {field:description function='Html2Text(@me)'/} {field:body function=Text2Html(@me)'/} GetEditor('content','默认值') 编辑器 显示信息 跳转地址 ShowMsg($msg, $gourl) GetTopTypename($typeid) 顶级栏目名 GetChannelArcpic($typeid)顶级栏目图片 自定义函数 ~~~ if (!function_exists('dump')) { function dump($arr){ echo '<pre>'.print_r($arr,TRUE).'</pre>'; } } //读取文章内容,传入id, function get_body($id,$len=0){ global $db; $rs = $db->get('addonarticle',array('aid'=>$id),array('body')) ; if($len==0) { $rs = empty($rs['body']) ?"": html2text(trim($rs['body']) ); } else{ $rs = empty($rs['body']) ?"":cn_substr( html2text(trim($rs['body'] )),$len); } return $rs; } //字符截取 if ( !function_exists('cutstr')) { function cutstr($str, $slen, $sq="...",$startdd=0) { $sq = strlen($str)>$slen ? "..." : ""; $text = cn_substr_utf8($str,$slen,$startdd).$sq; return $text; } } //是否有子栏目 function is_subnav($typeid,$echo1='',$echo2=''){ global $dsql; $sql = "SELECT id From `#@__arctype` WHERE reid=$typeid And ishidden<>1 order by sortrank asc limit 0, 10"; $row = $dsql->GetOne($sql); return is_array($row)?$echo1:$echo2; } /** * 分页时候计算记录总条数 * @param $table 表名称,不要带前缀 * @param string $where 查询条件 需要带 where * $psize 每页显示数据 * {dede:field.typeid function="page_count('zhaopin','where typeid=16 ')"/} */ function page_count($table,$where=' ',$psize=6){ global $db; $where = (empty($where))? " 1=1":" typeid=$where"; $row =$db->fetchcolumn("select count(*) from ".$db->tablename($table)." where $where"); $maxpage = ceil($row/$psize); return $maxpage; } /** * @param $aid 图片集id * num 显示数量 * @return string */ function get_imgs($aid,$num = 0){ global $dsql; $imgurls = ''; $row = $dsql->GetOne("Select imgurls,typeid From #@__addonimages where aid=$aid order by aid desc"); $imgurls = $row['imgurls']; preg_match_all("/{dede:img (.*)}(.*){\/dede:img/isU", $imgurls, $wordcount); preg_match_all("/text='(.*?)' width=/is", $imgurls, $wordcount1);//$wordcount1[1][$i] 图片描述 $typename = get_chanel_name($row['typeid']); $typelink = get_chanel_link($row['typeid']); $title= $dsql->GetOne("Select title From #@__archives where id=$aid"); $count = count($wordcount[2]); $num = ($num==0 || $num>$count)?$count:$num; $imglist=''; for($i = 0;$i < $num;$i++){ $imglist.=" <li class='is-visible'> <div class='cd-half-block image' style='background-image:url(".$wordcount[2][$i].")'></div> <div class='cd-half-block content'> <div> <h2><a href='".$typelink."'>".$typename."</a></h2> <p>产品名称: ".$title['title']." </p> </div> </div> </li>"; } return $imglist; } /** * 返回顶级栏目图片,用于列表页,任何时候都只返回顶栏目级图片 * @param $typeid * @param string $default_pic * @return string */ function get_topchannel_pic($typeid,$default_pic="/images/defaultpic.gif") { global $dsql; $row = $dsql->GetOne("SELECT topid,arcpic FROM #@__arctype WHERE id= $typeid"); if(0 == $row['topid']){ return (empty($row['arcpic']))?$default_pic:$row['arcpic']; }else{ $row1 = $dsql->GetOne("SELECT arcpic FROM #@__arctype WHERE id= $row[topid]"); return (empty($row1['arcpic']))?$default_pic:$row1['arcpic']; } } /* * 获取本栏目图片,只有找不到时候才返回顶级图片 * $typeid 栏目id * $default_pic 找不到时候默认图片 * [field:id function='get_channel_pic(@me)'/] * */ function get_channel_pic($typeid,$default_pic="/images/defaultpic.gif") { global $dsql; $row = $dsql->GetOne("SELECT arcpic,topid FROM #@__arctype WHERE id= $typeid"); if(empty($row['arcpic'])){ if(0 == $row['topid']){ return $default_pic; }else{ $row1 = $dsql->GetOne("SELECT arcpic FROM #@__arctype WHERE id= $row[topid]"); return (empty($row1['arcpic']))?$default_pic:$row1['arcpic']; } }else{ return $row['arcpic']; } } /** * 根据id获取栏目名称 * @param $typeid * @return mixed */ function get_chanel_name($typeid) { global $dsql; $row = $dsql->GetOne("SELECT typename FROM #@__arctype WHERE id= $typeid"); return $row['typename']; } /* * 获取栏目连接,根据typeid */ function get_chanel_link($typeid){ global $dsql ; $typename = $dsql->GetOne("SELECT typedir FROM #@__arctype where id=$typeid"); return str_replace("{cmspath}",'',$typename['typedir']); } /*栏目描述*/ function get_channel_desc($tid){ global $db; return $db->getcolumn('arctype',array('id'=>$tid),'description'); } ~~~ 无限极栏目调用 /* * $channel 要调用的栏目id {dede:tagname runphp='yes'} @me =menu(2); {/dede:tagname} */ function menu($channel=0,$line=100) { global $dsql,$result; $line = empty($line)?10 : $line; $dsql->SetQuery("SELECT * FROM #@__arctype WHERE reid='$channel' And ishidden<>1 order by sortrank asc limit 0, $line "); $dsql->Execute($channel); if($dsql->GetTotalRow($channel)>0) { $result .= "<ul class='top-nav'>"; while($row = $dsql->GetArray($channel)) { $id = $row['id']; $typename = $row['typename']; $typelink = GetOneTypeUrlA($row); $result .= "<li>"; $result .= "<a href='{$typelink}' >{$typename}</a>"; menu($id,$line); $result .= "</li>"; } $result .= "</ul>"; } return $result; }