function translateArticlelist($template) { global $pagesize, $picwidth, $picheight; //如果指定页大小,则用用户参数填充$pagesize //匹配自定义文章列表标签正则 $flag = "/【articlelist(\\([\\d\\w]*,\\d*,\\d*,\\d*,\\d*,\\d*,\\d*,\\d*\\))】([\\s\\S]*?)【\\/articlelist】/"; preg_match_all($flag, $template, $matches, PREG_SET_ORDER); //替换所有articlelist标签 $html = $template; //echo $template; foreach ($matches as $matche) { //得到需要循环的部分 $str = $matche[2]; //得到标签参数参数 $parameter = substr($matche[1], 1, strlen($matche[1]) - 2); $parameter = split(',', $parameter); $columnid = $parameter[0]; $articlenum = $parameter[1]; $titlelen = $parameter[2]; $ifpage = $parameter[3]; $timetype = $parameter[4]; //echo $timetype; $sorttype = $parameter[5]; //缩略图的宽和高 $picwidth = $parameter[6]; $picheight = $parameter[7]; $ifshowpic = ""; if ($picwidth != null && $picheight != null && $picheight != 0 && $picheight != 0) { $ifshowpic = "picurl<>'' and picurl is not NULL and"; } //定义排序方式的字串 if ($sorttype == "0") { //id降序 $sortstr = "order by id desc"; } else { $sortstr = "order by id asc"; } //如果参数columnid的值为thiscolumn则替换为当前栏目id if ($columnid == "columnid" || $columnid == "") { $columnid = $_GET["columnid"]; } //栏目子栏目串 $childColumnString = ""; getchildcolumnid($columnid, $childColumnString); //得到url参数 $oldpagesize = $pagesize; $pagesize = $articlenum; $currentpage = $_GET["currentpage"] == NULL || $_GET["currentpage"] <= 0 ? 1 : $_GET["currentpage"]; //根据参数从数据库取得数据 if ($ifpage == "1") { $articlesql = "select *,left(title,{$titlelen}) as title from I_article where " . $ifshowpic . " columnid in ({$childColumnString}) and ifpass=1 " . $sortstr . " limit " . ($currentpage - 1) * $pagesize . ",{$pagesize}"; } else { $articlesql = "select *,left(title,{$titlelen}) as title from I_article where " . $ifshowpic . " columnid in ({$childColumnString}) and ifpass=1 " . $sortstr . " limit 0,{$articlenum}"; } //echo $articlesql; $result = getresult($articlesql); //匹配循环部分的标签 $tag_flag = "/【#[\\s\\S]*?】/"; preg_match_all($tag_flag, $str, $data_tag, PREG_SET_ORDER); $tag_index = null; //记录标签循环部分每中标签出现的次数,如果出现第二次,则视为要显示两列数据,依次类推... //将要输出的html代码; $temphtml = ""; while ($row = getresultArray($result)) { $str = $matche[2]; foreach ($data_tag as $temp) { //$tempindex = 0; for (;;) { if ($tag_index[$temp[0]] < 1) { //初始化一篇文章数据 initarticledata($row); //替换标签 $str = replace_once($temp[0], $str, getvalue($temp[0], $timetype)); //当前匹配标签计数器加1 if (isset($tag_index[$temp[0]])) { $tag_index[$temp[0]]++; } else { $tag_index[$temp[0]] = 1; } break; } else { //取新文章数据 $row = getresultArray($result); //第二次出现的标签都会引发取得新数据,故产生错误 //初始化数据 initarticledata($row); //当前匹配标签计数器加1 $tag_index = NULL; } } } $tag_index = NULL; $temphtml .= $str; } if (trim($temphtml) == "") { $html = str_replace($matche[0], gettext_r("haveNot") . gettext_r("article"), $html); } else { $html = str_replace($matche[0], $temphtml, $html); } //echo "||".$ifpage; if ($ifpage == 0) { $pagesize = $oldpagesize; } } return $html; }
function translateSearchlist($template) { global $pagesize; //如果指定页大小,则用用户参数填充$pagesize //匹配自定义文章列表标签正则 $flag = "/【searchlist(\\(\\d*,\\d*,\\d*,\\d*\\))】([\\s\\S]*?)【\\/searchlist】/"; preg_match_all($flag, $template, $matches, PREG_SET_ORDER); //替换所有articlelist标签 $html = $template; //echo $template; foreach ($matches as $matche) { //得到需要循环的部分 $str = $matche[2]; //得到标签参数参数 $parameter = substr($matche[1], 1, strlen($matche[1]) - 2); $parameter = split(',', $parameter); $articlenum = $parameter[0]; $titlelen = $parameter[1]; $timetype = $parameter[2]; $sorttype = $parameter[3]; //定义排序方式的字串 if ($sorttype == "0") { //id降序 $sortstr = "order by id desc"; } else { $sortstr = "order by id asc"; } //得到url参数 $pagesize = $articlenum; //($_GET["pagesize"]==NULL || $_GET["pagesize"]<=0)?10:$_GET["pagesize"]; $currentpage = $_GET["currentpage"] == NULL || $_GET["currentpage"] <= 0 ? 1 : $_GET["currentpage"]; //根据参数从数据库取得数据 $searchSql = "select *,left(title,{$titlelen}) as title from I_article where ifpass=1"; if ($_GET["title"] != NULL && $_GET["title"] != "") { $searchSql .= " and title like '%" . $_GET["title"] . "%'"; } if ($_GET["columnid"] != NULL && $_GET["columnid"] > 0) { $sdef_fields = getresult("select * from I_field where columnid=" . getChanelidByColumnid($_GET["columnid"])); while ($row = getresultarray($sdef_fields)) { if ($_GET[$row["fieldname"]] == NULL || $_GET[$row["fieldname"]] == "") { continue; } if ($row["datatype"] == "double") { $searchSql .= " and " . $row["fieldname"] . " " . $_GET[$row["fieldname"] . "ctype"] . $_GET[$row["fieldname"]]; //echo $_GET[$row["fieldname"]."ctype"]."测试"; } else { $searchSql .= " and " . $row["fieldname"] . " like '" . $_GET[$row["fieldname"]] . "'"; } } //在所有子栏目中搜索 $childcolumnStr = ""; getchildcolumnid($_GET["columnid"], $childcolumnStr); $searchSql .= " and columnid in (" . $childcolumnStr . ")"; //echo "Iron".$searchSql; } $searchSql .= " " . $sortstr . " limit " . ($currentpage - 1) * $pagesize . ",{$pagesize}"; //echo $searchSql; $result = getresult($searchSql); //匹配循环部分的标签 $tag_flag = "/【#[\\s\\S]*?】/"; preg_match_all($tag_flag, $str, $data_tag, PREG_SET_ORDER); $tag_index = null; //记录标签循环部分每中标签出现的次数,如果出现第二次,则视为要显示两列数据,依次类推... //将要输出的html代码; $temphtml = ""; while ($row = getresultArray($result)) { $str = $matche[2]; foreach ($data_tag as $temp) { //$tempindex = 0; for (;;) { if ($tag_index[$temp[0]] < 1) { //初始化一篇文章数据 initarticledata($row); //替换标签 $str = replace_once($temp[0], $str, getvalue($temp[0], $timetype)); //当前匹配标签计数器加1 if (isset($tag_index[$temp[0]])) { $tag_index[$temp[0]]++; } else { $tag_index[$temp[0]] = 1; } break; } else { //取新文章数据 $row = getresultArray($result); //第二次出现的标签都会引发取得新数据,故产生错误 //初始化数据 initarticledata($row); //当前匹配标签计数器加1 $tag_index = NULL; } } } $tag_index = NULL; $temphtml .= $str; } //echo $matche[0]."<br>";//.$temphtml; if (trim($temphtml) == "") { $html = str_replace($matche[0], gettext_r("haveNot") . gettext_r("search") . gettext_r("result"), $html); } else { $html = str_replace($matche[0], $temphtml, $html); } } //显示搜索表单 $html = str_replace("【#searchform】", getsearchform(), $html); //显示分页 $html = str_replace("【#showpage】", getsearchPage($pagesize), $html); return $html; }