{"id":31,"date":"2009-08-11T08:58:15","date_gmt":"2009-08-11T00:58:15","guid":{"rendered":"http:\/\/www.magki.com\/blog\/?p=31"},"modified":"2009-08-15T13:16:55","modified_gmt":"2009-08-15T05:16:55","slug":"code-optimization-for-phpcms","status":"publish","type":"post","link":"http:\/\/www.ijony.com\/blog\/2009\/08\/code-optimization-for-phpcms.html","title":{"rendered":"\u7ed9 PHPCMS \u6dfb\u52a0\u5220\u9664\u680f\u76ee\u7684\u4ee3\u7801\u505a\u4f18\u5316"},"content":{"rendered":"<p>\u6700\u8fd1\u51e0\u4e2a\u5355\u90fd\u662f\u7528 PHPCMS \u505a\u4e8c\u6b21\u5f00\u53d1\uff0c\u5305\u62ec\u73b0\u5728\u6b63\u5728\u8fdb\u884c\u7684\u8fd9\u4e2a\u5927\u5355\uff0c\u6709\u591a\u5927\uff1f\u7ed9\u5ba2\u6237\u6dfb\u6570\u636e\u540e\uff0c\u5149\u662f\u680f\u76ee\u6570\u5c31\u5df2\u7ecf\u8bbe\u7f6e\u52303000+\u5e76\u4e14\u4e0a\u5347\u52bf\u5934\u4e0d\u51cf\u2026\u2026<\/p>\n<p>\u4ee5\u524d\u6ca1\u9047\u5230\u8fc7\u4e00\u4e2a\u7f51\u7ad9\u6709\u90a3\u4e48\u591a\u680f\u76ee\u7684\u60c5\u51b5\uff0c\u4f30\u8ba1 PHPCMS \u7684\u5f00\u53d1\u4eba\u5458\u4e5f\u6ca1\u9047\u5230\u8fc7\uff0c\u56e0\u4e3a\u6211\u53d1\u73b0\u680f\u76ee\u8d8a\u591a\uff0c\u6dfb\u52a0\u548c\u4fee\u6539\u680f\u76ee\u7684\u901f\u5ea6\u8d8a\u6162\uff0c\u680f\u76ee\u6570\u8fc71000\u7684\u65f6\u5019\uff0c\u57fa\u672c\u4fee\u6539\u4e00\u6b21\u680f\u76ee\u5c31\u5f97\u82b1\u4e0a1\u5206\u949f\u65f6\u95f4\uff0c\u73b0\u5728 3000+ \u680f\u76ee\u5df2\u7ecf\u89814\uff0c5\u5206\u949f\u4e86\u2026\u2026\u67e5\u9605\u4e86\u4e0b PHPCMS \u7684\u4ee3\u7801\u53d1\u73b0\u4e86\u95ee\u9898\u6240\u5728\u3002<\/p>\n<p>PHPCMS \u7684\u680f\u76ee\u76f8\u5173\u5904\u7406\u65b9\u6cd5\u90fd\u662f\u5728 include\\admin\\category.class.php \u91cc\uff0c\u8fd9\u4e2a\u7c7b\u6587\u4ef6\u4e2d\u6709\u4e00\u4e2a\u88ab\u9891\u7e41\u4f7f\u7528\u7684\u65b9\u6cd5 repair\uff0c\u95ee\u9898\u5c31\u51fa\u5728\u8fd9\u91cc\u3002\u65e0\u8bba\u662f\u6dfb\u52a0\u3001\u5220\u9664\u8fd8\u662f\u5176\u4ed6\u7684\u4e00\u4e9b\u680f\u76ee\u64cd\u4f5c\uff0c\u5927\u591a\u90fd\u4f1a\u6267\u884c\u4e00\u6b21\u8fd9\u4e2a\u65b9\u6cd5\uff08\u6709\u4e2a\u5730\u65b9\u8fde\u7eed\u6267\u884c\u4e24\u6b21\uff0c\u4e0d\u89e3\uff0c\u5e94\u8be5\u662f\u5f00\u53d1\u4eba\u5458\u7684\u5931\u8bef\uff09\u3002\u800c\u8fd9\u4e2a\u65b9\u6cd5\u7684\u4e3b\u8981\u5de5\u4f5c\u5c31\u662f\u5c06\u6574\u4e2a\u7ad9\u7684\u6240\u6709\u680f\u76ee\u904d\u5386\u4e00\u6b21\u904d\uff0c\u5bf9\u6bcf\u4e2a\u680f\u76ee\u90fd\u66f4\u65b0\u4e00\u4e0b <span style=\"color: #ff0000;\">arrparentid<\/span>, <span style=\"color: #ff0000;\">parentdir<\/span>, <span style=\"color: #ff0000;\">arrchildid<\/span> \u4e09\u4e2a\u5b57\u6bb5\u7684\u5185\u5bb9\u3002\u5988\u5988\u5440\uff0c\u90a33000\u591a\u4e2a\u680f\u76ee\u5c82\u4e0d\u662f\u8981\u6267\u884c3000\u591a\u6b21 update\uff1f\u602a\u4e0d\u5f97\u2026\u2026<\/p>\n<p><!--more--><\/p>\n<p>\u6211\u60f3\u5f00\u53d1\u4eba\u5458\u4e4b\u6240\u4ee5\u8fd9\u4e48\u8bbe\u8ba1\uff0c\u5e94\u8be5\u662f\u8003\u8651\u5230\u4e00\u4e2a\u680f\u76ee\u7684\u8def\u5f84\u4ee5\u53ca\u7236\u680f\u76ee\u7684\u53d8\u66f4\u5bf9\u5176\u7236\u680f\u76ee\u548c\u5b50\u680f\u76ee\u7684\u5f71\u54cd\uff0c\u5c31\u8ba1\u5212\u8981\u6574\u4f53\u66f4\u65b0\u4e00\u904d\u9632\u6b62\u51fa\u9519\u3002\u4e0d\u8fc7\u8fd9\u79cd\u5168\u76d8\u66f4\u65b0\u7684\u65b9\u5f0f\u6709\u5931\u659f\u914c\u5440\uff01\u4e00\u822c\u53ea\u9700\u8981\u5bf9\u5f71\u54cd\u5230\u5230\u7684\u67d0\u51e0\u4e2a\u680f\u76ee\u5206\u652f\u7684\u6240\u6709\u680f\u76ee\u66f4\u65b0\u4e00\u904d\u5c31\u53ef\u4ee5\u4e86\u3002\u4e8e\u662f\u6211\u5c06\u8fd9\u4e2a\u65b9\u6cd5\u4fee\u6539\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>\nfunction repair($id=0,$pid=-1,$opid=-1)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;@set_time_limit(600);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;if($id==0){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(is_array($this->category))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach($this->category as $catid => $cat)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($catid == 0) continue;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$arrparentid = $this->get_arrparentid($catid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$parentdir = $this->get_parentdir($catid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$arrchildid = $this->get_arrchildid($catid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$child = is_numeric($arrchildid) ? 0 : 1;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->db->query(&#8220;UPDATE `$this->table` SET arrparentid=&#8217;$arrparentid&#8217;,parentdir=&#8217;$parentdir&#8217;,arrchildid=&#8217;$arrchildid&#8217;,child=&#8217;$child&#8217; WHERE catid=$catid&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($cat[&#8216;module&#8217;]==&#8217;phpcms&#8217;) $this->url($catid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->cache();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return TRUE;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;if($pid<1) $pid=$id;\n&nbsp;&nbsp;&nbsp;&nbsp;if($opid<1) $opid=$id;\n&nbsp;&nbsp;&nbsp;&nbsp;$arrpid = explode(\",\",$this->get_arrparentid($pid).&#8221;,&#8221;.$pid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$arropid = explode(&#8220;,&#8221;,$this->get_arrparentid($opid).&#8221;,&#8221;.$opid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$arrchildid = explode(&#8220;,&#8221;,$this->get_arrchildid($id));<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$allid = array_merge($arrpid,$arropid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$allid = array_merge($allid,$arrchildid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$allid = array_flip($allid);<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;foreach($allid as $catid=>$v)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($catid == 0) continue;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$arrparentid = $this->get_arrparentid($catid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$parentdir = $this->get_parentdir($catid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$arrchildid = $this->get_arrchildid($catid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$child = is_numeric($arrchildid) ? 0 : 1;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->db->query(&#8220;UPDATE `$this->table` SET arrparentid=&#8217;$arrparentid&#8217;,parentdir=&#8217;$parentdir&#8217;,arrchildid=&#8217;$arrchildid&#8217;,child=&#8217;$child&#8217; WHERE catid=$catid&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($this->category[$catid][&#8216;module&#8217;]==&#8217;phpcms&#8217;) $this->url($catid);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;$this->cache();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return TRUE;<br \/>\n}\n<\/p><\/blockquote>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u4fee\u6539\u5b8c\u6bd5\u540e\uff0c\u5728\u53bb\u8fd9\u4e2a\u7c7b\u6587\u4ef6\u7684 add \u548c edit \u65b9\u6cd5\u4e2d\u4fee\u6539 <span style=\"color: #ff0000;\">$this-&gt;repair();<\/span> \u8fd9\u4e00\u884c\uff0c\u4e3b\u8981\u662f\u6709\u4e09\u4e2a\u53c2\u6570\u4f9d\u6b21\u4e3a<span style=\"color: #ff0000;\">\u680f\u76eeID<\/span>\uff0c<span style=\"color: #ff0000;\">\u6700\u540e\u7684\u7236\u7ea7ID<\/span>\uff0c<span style=\"color: #ff0000;\">\u4e4b\u524d\u7684\u7236\u7ea7ID<\/span>\u3002\u4e09\u4e2a\u53c2\u6570\u90fd\u4e0d\u8bbe\u7f6e\u5219\u548c\u539f\u6765\u7684\u6548\u679c\u5b8c\u5168\u4e00\u81f4\uff0c\u53ea\u586b\u680f\u76eeID\u5219\u53ea\u66f4\u65b0\u8be5\u680f\u76ee\u4ee5\u53ca\u5176\u5b50\u680f\u76ee\u7684\u524d\u9762\u6240\u8bf4\u7684\u90a3\u4e09\u4e2a\u5b57\u6bb5\u5185\u5bb9\uff0c\u586b\u5199\u6700\u540e\u7684\u7236\u7ea7ID\uff0c\u5219\u4f1a\u5c06\u6240\u6307\u5b9a\u680f\u76ee\u6700\u540e\u6240\u5728\u680f\u76ee\u5206\u652f\u91cc\u7684\u6240\u6709\u680f\u76ee\u66f4\u65b0\u4e00\u904d\uff0c\u586b\u5199\u4e4b\u524d\u7684\u7236\u7ea7ID\uff0c\u5219\u4f1a\u5c06\u6240\u6307\u5b9a\u680f\u76ee\u66f4\u6539\u7236\u7ea7\u680f\u76ee\u4e4b\u524d\u6240\u5728\u7684\u680f\u76ee\u5206\u652f\u91cc\u6240\u6709\u680f\u76ee\u66f4\u65b0\u4e00\u904d\u3002\u6ce8\u610f\uff0c\u5982\u679c\u8981\u66f4\u65b0\u76f8\u5173\u680f\u76ee\u5206\u652f\u91cc\u7684\u680f\u76ee\uff0c\u680f\u76eeID\u8fd9\u4e2a\u53c2\u6570\u5fc5\u987b\u540c\u65f6\u8bbe\u7f6e\u3002\u9488\u5bf9\u6211\u8fd9\u8fb9\u7684\u60c5\u51b5\uff0c\u6211\u5c06 add \u65b9\u6cd5\u91cc\u7684 repair \u65b9\u6cd5\u8c03\u7528\u4fee\u6539\u6210 <span style=\"color: #ff0000;\">$this-&gt;repair($catid,$parentid);<\/span>\uff0cedit \u65b9\u6cd5\u91cc\u5219\u6539\u6210 <span style=\"color: #ff0000;\">$this-&gt;repair($catid,$parentid,$oldparentid);<\/span>\u3002<\/p>\n<p>\u53e6\u5916 add \u65b9\u6cd5\u91cc\u6267\u884c repair \u65b9\u6cd5\u4e4b\u524d\u8fd8\u5f97\u63d2\u5165\u5982\u4e0b\u4ee3\u7801\uff0c\u4ee5\u4fdd\u8bc1\u65b0\u6dfb\u52a0\u7684\u680f\u76ee\u53ef\u4ee5\u66f4\u65b0\u5230\u7f13\u5b58\u91cc\u53bb\u3002<\/p>\n<blockquote><p>\n$this->category[$catid][&#8216;parentid&#8217;] = $category[&#8216;parentid&#8217;];<br \/>\n$this->category[$catid][&#8216;arrparentid&#8217;] = $category[&#8216;arrparentid&#8217;];<br \/>\n$this->category[$catid][&#8216;parentdir&#8217;] = $category[&#8216;parentdir&#8217;];<br \/>\n$this->category[$catid][&#8216;arrchildid&#8217;] = $catid;\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u51e0\u4e2a\u5355\u90fd\u662f\u7528 PHPCMS \u505a\u4e8c\u6b21\u5f00\u53d1\uff0c\u5305\u62ec\u73b0\u5728\u6b63\u5728\u8fdb\u884c\u7684\u8fd9\u4e2a\u5927\u5355\uff0c\u6709\u591a\u5927\uff1f\u7ed9\u5ba2\u6237\u6dfb\u6570\u636e\u540e\uff0c\u5149\u662f\u680f\u76ee\u6570\u5c31\u5df2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[16],"_links":{"self":[{"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/posts\/31"}],"collection":[{"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":0,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}