{"id":2170,"date":"2018-12-19T09:52:39","date_gmt":"2018-12-19T01:52:39","guid":{"rendered":"https:\/\/www.baishitou.cn\/?p=2170"},"modified":"2019-02-27T11:55:32","modified_gmt":"2019-02-27T03:55:32","slug":"%e7%bb%87%e6%a2%a6dedecms%e7%94%a8dedesql%e6%a0%b9%e6%8d%ae%e5%bd%93%e5%89%8d%e6%96%87%e7%ab%a0%e7%9a%84%e5%85%b3%e9%94%ae%e5%ad%97%e8%b0%83%e7%94%a8%e7%9b%b8%e5%85%b3%e6%96%87%e7%ab%a0","status":"publish","type":"post","link":"https:\/\/www.baishitou.cn\/2170.html","title":{"rendered":"\u7ec7\u68a6DEDECMS\u6839\u636e\u5f53\u524d\u6587\u7ae0\u7684\u5173\u952e\u5b57\u8c03\u7528\u76f8\u5173\u6587\u7ae0\uff08\u652f\u6301\u81ea\u5b9a\u4e49\u5b57\u6bb5\uff09"},"content":{"rendered":"
\u6253\u5f00 \/include\/taglib\/arclist.lib.php\u00a0\u641c\u7d22<\/strong><\/p>\n \u5728\u5b83\u4e0b\u9762\u52a0\u4e0a<\/p>\n \u6a21\u677f\u91cc\u8c03\u7528\u4ee3\u7801\uff1a<\/p>\n \u8bf4\u660e\uff1akeyword='~keywords~'\u00a0\u662f\u8c03\u7528\u5f53\u524d\u9875\u9762\u5173\u952e\u8bcd\uff0c\u5982\u679c\u4f60\u8981\u8c03\u7528\u6807\u9898\u7528~title~\uff0c\u5176\u4ed6\u7684\u6839\u636e\u81ea\u5df1\u5f53\u524d\u9875\u9762\u7684\u6807\u7b7e\u586b\u5b57\u6bb5<\/p>\n \u4fdd\u5b58\u540e\u5728\u540e\u53f0\u66f4\u65b0\u7cfb\u7edf\u7f13\u5b58\u3002<\/p>\n \u6b64\u65b9\u6cd5\u53ef\u5b9e\u73b0\u7cbe\u51c6\u83b7\u53d6\u76f8\u5173\u6587\u7ae0\uff0c\u652f\u6301\u76f4\u63a5\u8f93\u51fa\u81ea\u5b9a\u4e49\u5b57\u6bb5\uff0c\u652f\u6301flag\u6587\u7ae0\u5c5e\u6027\uff0ceregtype='all|tag|keyword'\uff0c\u5355\u7528tag\u6765\u8c03\u7528\u76f8\u5173\u6587\u7ae0\uff0c\u4e5f\u53ef\u7528tag|keyword\u6765\u8c03\u7528\u76f8\u5173\u6587\u7ae0(\u9ed8\u8ba4tag\u4f18\u5148\u4e8ekeyword\uff0c\u53ef\u4ee5\u81ea\u5df1\u6392\u5e8f)<\/p>\n \u5728 \/include\/taglib \u4e0b\u6dfb\u52a0\u4e00\u4e2a\u540d\u4e3aliketags.lib.php\u7684\u6587\u4ef6\uff0c\u6587\u4ef6\u5185\u5bb9\u6dfb\u52a0\u4e0b\u5217\u4ee3\u7801:<\/p>\n \u6a21\u677f\u8c03\u7528\u4ee3\u7801\uff1a<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" \u65b9\u6cd5\u4e00 \u6253\u5f00 \/include\/taglib\/arclist.lib.php\u00a0\u641c\u7d22 $keyword = tr […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[43,350,731,180],"class_list":["post-2170","post","type-post","status-publish","format-standard","hentry","category-web","tag-dedecms","tag-350","tag-731","tag-180"],"_links":{"self":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/posts\/2170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/comments?post=2170"}],"version-history":[{"count":0,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/posts\/2170\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/media?parent=2170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/categories?post=2170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.baishitou.cn\/wp-json\/wp\/v2\/tags?post=2170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}$keyword = trim($keyword);<\/code><\/pre>\n
preg_match(\"\/~([A-Za-z0-9_]+)~\/s\", $keyword, $conditions);\r\nif(isset($refObj->Fields[$conditions[1]]))\r\n{\r\n\t$keyword = addslashes($refObj->Fields[$conditions[1]]);\r\n}<\/code><\/pre>\n
{dede:arclist row='10' titlelen='250' keyword='~keywords~'}\r\n<li><a href=\"[field:arcurl\/]\">[field:title\/]<\/a><\/li>\r\n{\/dede:arclist}<\/code><\/pre>\n
\u65b9\u6cd5\u4e8c<\/h2>\n
<?php\r\nif(!defined('DEDEINC')) exit('Request Error!');\r\nfunction lib_liketags(&$ctag,&$refObj)\r\n{\r\n global $dsql,$envs;\r\n \r\n \/\/\u5c5e\u6027\u5904\u7406\r\n $attlist=\"row|12,titlelen|30,infolen|250,col|1,tablewidth|100,typeid|0,byabs|0,imgwidth|120,imgheight|90,flag|\";\r\n FillAttsDefault($ctag->CAttribute->Items,$attlist);\r\n extract($ctag->CAttribute->Items, EXTR_SKIP);\r\n $revalue = '';\r\n \r\n if(empty($tablewidth)) $tablewidth = 100;\r\n if(empty($col)) $col = 1;\r\n $colWidth = ceil(100\/$col);\r\n $tablewidth = $tablewidth.\"%\";\r\n $colWidth = $colWidth.\"%\";\r\n\t$orwheres = '';\r\n\tif($flag != '') {\r\n\t\t$flags = explode(',', $flag);\r\n\t\tfor($i=0; isset($flags[$i]); $i++) $orwheres .= \" AND FIND_IN_SET('{$flags[$i]}', arc.flag)>0 \";\r\n\t}\r\n\t\r\n $ids = array();\r\n $tids = array();\r\n \r\n if(!empty($refObj->Fields['tags'])) {\r\n $keyword = $refObj->Fields['tags'];\r\n }\r\n else {\r\n $keyword = ( !empty($refObj->Fields['keywords']) ? $refObj->Fields['keywords'] : '' );\r\n }\r\n \r\n $typeid = ( !empty($typeid) ? $typeid : 0 );\r\n if(empty($typeid))\r\n {\r\n if(!empty($refObj->Typelink->TypeInfos['reid'])) {\r\n $typeid = $refObj->Typelink->TypeInfos['reid'];\r\n }\r\n else {\r\n if(!empty($refObj->Fields['typeid'])) $typeid = $refObj->Fields['typeid'];\r\n }\r\n }\r\n \r\n if( !empty($typeid) && !preg_match('#,#', $typeid) ) {\r\n $typeid = GetSonIds($typeid);\r\n }\r\n \r\n\tif(!empty($refObj->Fields['tags']) && $eregtype != 'keyword' ) \r\n\t{\r\n\t\t$tags = explode(',', addslashes($refObj->Fields['tags']));\r\n\t\t$getsql = \" tag like '\".join(\"' OR tag like '\", $tags).\"' \";\r\n\t\t$dsql->Execute('me', \"Select * From `#@__tagindex` where $getsql \");\r\n\t\twhile($arow = $dsql->GetArray('me'))\r\n\t\t{\r\n\t\t\t$tids[] = $arow['id'];\r\n\t\t}\r\n\t\t$tid = join(',', $tids);\r\n\t\tif($tid!='')\r\n\t\t{\r\n\t\t\t$dsql->Execute(\"me\", \"Select aid From `#@__taglist` where tid in($tid) And arcrank > -1 group by aid order by aid desc\");\r\n\t\t\twhile($arow = $dsql->GetArray(\"me\"))\r\n\t\t\t{\r\n\t\t\t\t$ids[] = $arow['aid'];\r\n\t\t\t\t$arcid = $refObj->Fields['aid'];\r\n\t\t\t}\r\n\t\t} \r\n\t}\r\n\t\r\n\t\/\/\u83b7\u5f97\u9644\u52a0\u8868\u7684\u76f8\u5173\u4fe1\u606f\r\n\t$addField = \"\";\r\n\t$addJoin = \"\";\r\n\tif(is_object($refObj->ChannelUnit))\r\n\t{\r\n\t\t$addtable = $refObj->ChannelUnit->ChannelInfos['addtable'];\r\n\t\tif($addtable!=\"\")\r\n\t\t{\r\n\t\t\t$addJoin = \" LEFT JOIN $addtable ON arc.id = \".$addtable.\".aid \";\r\n\t\t\t$addField = \"\";\r\n\t\t\t$fields = explode(\",\",$refObj->ChannelUnit->ChannelInfos['listfields']);\r\n\t\t\tforeach($fields as $k=>$v)\r\n\t\t\t{\r\n\t\t\t\t$nfields[$v] = $k;\r\n\t\t\t}\r\n\t\t\tforeach($refObj->ChannelUnit->ChannelFields as $k=>$arr)\r\n\t\t\t{\r\n\t\t\t\tif(isset($nfields[$k]))\r\n\t\t\t\t{\r\n\t\t\t\t\tif(!empty($arr['rename']))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t$addField .= \",\".$addtable.\".\".$k.\" as \".$arr['rename'];\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t$addField .= \",\".$addtable.\".\".$k;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tif($eregtype == 'tag' && count($ids) == 0 )\r\n\t{\r\n\t\treturn;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tif(count($ids) > 0)\r\n\t\t{\r\n\t\t\tif(!empty($typeid))\r\n\t\t\t{\r\n\t\t\t\t$typeid = \" And arc.typeid in($typeid) And arc.id<>$arcid \";\r\n\t\t\t}\r\n\t\t\t$idsStr = join(',', $ids);\r\n\t\t\t$query = \"Select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule, \r\n\t\t\ttp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addField \r\n\t\t\tfrom `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id $addJoin \r\n\t\t\twhere arc.arcrank>-1 and arc.id in($idsStr) $typeid order by arc.id desc limit 0, $row\";\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t$limitRow = $row - count($ids);\r\n\t\t\t$keyword = '';\r\n\t\t\tif(!empty($refObj->Fields['keywords']))\r\n\t\t\t{\r\n\t\t\t\t$keywords = explode(',' , trim($refObj->Fields['keywords']));\r\n\t\t\t\t$keyword = '';\r\n\t\t\t\t$n = 1;\r\n\t\t\t\tforeach($keywords as $k)\r\n\t\t\t\t{\r\n\t\t\t\t\tif($n > 3) break;\r\n\r\n\t\t\t\t\tif(trim($k)=='') continue;\r\n\t\t\t\t\telse $k = addslashes($k);\r\n\r\n\t\t\t\t\t$keyword .= ($keyword=='' ? \" CONCAT(arc.keywords,' ',arc.title) like '%$k%' \" : \" OR CONCAT(arc.keywords,' ',arc.title) like '%$k%' \");\r\n\t\t\t\t\t$n++;\r\n\t\t\t\t}\r\n\t\t\t} \r\n\t\t\t$arcid = (!empty($refObj->Fields['id']) ? $refObj->Fields['aid'] : 0);\r\n\t\t\tif( empty($arcid) || $byabs==0 )\r\n\t\t\t{\r\n\t\t\t\t$orderquery = \" order by arc.id desc \";\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t$orderquery = \" order by ABS(arc.id - \".$arcid.\") \";\r\n\t\t\t}\r\n\t\t\tif($keyword != '')\r\n\t\t\t{\r\n\t\t\t\tif(!empty($typeid))\r\n\t\t\t\t{\r\n\t\t\t\t\t$typeid = \" And arc.typeid in($typeid) And arc.id<>$arcid \";\r\n\t\t\t\t}\r\n\t\t\t\t$query = \"Select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule, \r\n\t\t\t\ttp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addField \r\n\t\t\t\tfrom `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id $addJoin \r\n\t\t\t\twhere arc.arcrank>-1 and ($keyword) $typeid $orderquery limit 0, $row\";\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif(!empty($typeid))\r\n\t\t\t\t{\r\n\t\t\t\t\t$typeid = \" arc.typeid in($typeid) And arc.id<>$arcid \";\r\n\t\t\t\t}\r\n\t\t\t\t$query = \"Select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule, \r\n\t\t\t\ttp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addField \r\n\t\t\t\tfrom `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id $addJoin \r\n\t\t\t\twhere arc.arcrank>-1 and $typeid $orderquery limit 0, $row\";\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n $innertext = trim( $ctag->GetInnerText() );\r\n if($innertext=='') $innertext = GetSysTemplets('part_arclist.htm');\r\n $dsql->SetQuery($query);\r\n $dsql->Execute('al');\r\n $artlist = '';\r\n if($col > 1){\r\n $artlist = \"<table width='$tablewidth' border='0' cellspacing='0' cellpadding='0'>\";\r\n }\r\n $dtp2 = new DedeTagParse();\r\n $dtp2->SetNameSpace('field', '[', ']');\r\n $dtp2->LoadString($innertext);\r\n $GLOBALS['autoindex'] = 0;\r\n $line = $row;\r\n for($i=0; $i < $line; $i++)\r\n {\r\n if($col>1) $artlist .= \"<tr>\";\r\n for($j=0; $j < $col; $j++)\r\n {\r\n if($col>1) $artlist .= \" <td width='$colWidth'>\";\r\n if($row = $dsql->GetArray(\"al\"))\r\n {\r\n $ids[] = $row['id'];\r\n \/\/\u5904\u7406\u4e00\u4e9b\u7279\u6b8a\u5b57\u6bb5\r\n $row['info'] = $row['infos'] = cn_substr($row['description'],$infolen);\r\n $row['id'] = $row['id'];\r\n\r\n if($row['corank'] > 0 && $row['arcrank']==0)\r\n {\r\n $row['arcrank'] = $row['corank'];\r\n }\r\n\r\n $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],\r\n $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);\r\n\r\n $row['typeurl'] = GetTypeUrl($row['typeid'],$row['typedir'],$row['isdefault'],$row['defaultname'],$row['ispart'],\r\n $row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);\r\n\r\n if($row['litpic'] == '-' || $row['litpic'] == '')\r\n {\r\n $row['litpic'] = $GLOBALS['cfg_cmspath'].'\/images\/defaultpic.gif';\r\n }\r\n if(!preg_match(\"#^http:\/\/#i\", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')\r\n {\r\n $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];\r\n }\r\n $row['picname'] = $row['litpic'];\r\n $row['stime'] = GetDateMK($row['pubdate']);\r\n $row['typelink'] = \"<a href='\".$row['typeurl'].\"'>\".$row['typename'].\"<\/a>\";\r\n $row['image'] = \"<img src='\".$row['picname'].\"' border='0' width='$imgwidth' height='$imgheight' alt='\".preg_replace(\"#['><]#\",\"\",$row['title']).\"'>\";\r\n $row['imglink'] = \"<a href='\".$row['filename'].\"'>\".$row['image'].\"<\/a>\";\r\n $row['fulltitle'] = $row['title'];\r\n $row['title'] = cn_substr($row['title'], $titlelen);\r\n if($row['color']!='') $row['title'] = \"<font color='\".$row['color'].\"'>\".$row['title'].\"<\/font>\";\r\n if(preg_match('#b#', $row['flag'])) $row['title'] = \"<strong>\".$row['title'].\"<\/strong>\";\r\n $row['textlink'] = \"<a href='\".$row['filename'].\"'>\".$row['title'].\"<\/a>\";\r\n $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];\r\n $row['memberurl'] = $GLOBALS['cfg_memberurl'];\r\n $row['templeturl'] = $GLOBALS['cfg_templeturl'];\r\n \r\n if(is_array($dtp2->CTags))\r\n {\r\n foreach($dtp2->CTags as $k=>$ctag)\r\n {\r\n if($ctag->GetName()=='array') {\r\n $dtp2->Assign($k,$row);\r\n }\r\n else {\r\n if(isset($row[$ctag->GetName()])) $dtp2->Assign($k,$row[$ctag->GetName()]);\r\n else $dtp2->Assign($k,'');\r\n }\r\n }\r\n $GLOBALS['autoindex']++;\r\n }\r\n\r\n $artlist .= $dtp2->GetResult();\r\n }\r\n \/\/if hasRow\r\n else\r\n {\r\n $artlist .= '';\r\n }\r\n if($col>1) $artlist .= \" <\/td>\";\r\n }\r\n \/\/Loop Col\r\n if($col>1) $i += $col - 1;\r\n if($col>1) $artlist .= \" <\/tr>\";\r\n }\r\n \/\/loop line\r\n if($col>1) $artlist .= \" <\/table>\";\r\n $dsql->FreeResult(\"al\");\r\n return $artlist;\r\n}<\/code><\/pre>\n
{dede:liketags row='3' typeid='6' titlelen='250' eregtype='all|tag|keyword' flag='c' infolen='250'}\r\n<li>\r\n\t<a href=\"[field:arcurl\/]\" title=\"[field:title\/]\" target=\"_blank\">\r\n\t<img src=\"[field:litpic\/]\" alt=\"[field:title\/]\"\/>\r\n\t<p class=\"title\">[field:title\/]<\/p>\r\n\t<\/a>\r\n<\/li>\r\n{\/dede:liketags}<\/code><\/pre>\n