国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

289 行
8.8KB

  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * 命令行工具
  5. *
  6. * @version 2020年12月11日 tianya $
  7. * @package DedeBIZ.Command
  8. * @copyright Copyright (c) 2020, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. // 切换工作目录到./src
  13. $workDir = dirname(__FILE__) . "/src";
  14. chdir($workDir);
  15. if (substr(php_sapi_name(), 0, 3) === 'cgi') {
  16. die("DedeCMSV6:needs php-cli to run\n\n");
  17. }
  18. $helpStr = "
  19. NAME:
  20. DedeBIZ Cli Tools
  21. USAGE:
  22. php ./dedebiz command [arguments...]
  23. COMMANDS:
  24. serv,s Run cli web server for DedeCMSV6
  25. make,m Make DedeCMSV6 HTML
  26. update,u Update to latest system
  27. help,h Shows a list of commands or help
  28. WEBSITE:
  29. https://www.dedebiz.com/help/
  30. ";
  31. // 将选项转化为SQL IN参数
  32. function Option2SQLin($str = "")
  33. {
  34. $str = preg_replace("#[^0-9-,]#", "", $str);
  35. $strs = explode(",", $str);
  36. foreach ($strs as $key => $si) {
  37. if (preg_match("#-#", $si)) {
  38. $tstart = 0;
  39. $tend = 0;
  40. $tss = explode("-", $si);
  41. if (intval($tss[0]) > intval($tss[1])) {
  42. $tstart = intval($tss[1]);
  43. $tend = intval($tss[0]);
  44. } else {
  45. $tstart = intval($tss[0]);
  46. $tend = intval($tss[1]);
  47. }
  48. $tmpArr = array();
  49. for ($i = $tstart; $i <= $tend; $i++) {
  50. $tmpArr[] = $i;
  51. }
  52. $strs[$key] = implode(",", $tmpArr);
  53. }
  54. }
  55. return implode(",", $strs);
  56. }
  57. if (count($argv) > 1 && ($argv[1] == "serv" || $argv[1] == "s")) {
  58. // PHP5.4以下不支持内建服务器
  59. // 用于开发调试
  60. if (phpversion() < "5.4") {
  61. die("DedeCMSV6:command web server not support\n\n");
  62. }
  63. echo "Start Dev Server For DedeCMSV6\n\r";
  64. echo "Open http://localhost:8088\n\r";
  65. passthru(PHP_BINARY . ' -S localhost:8088 -t' . escapeshellarg('./'));
  66. } else if (count($argv) > 1 && $argv[1] == "make") {
  67. if (!file_exists($workDir . "/include/common.inc.php")) {
  68. DedeCli::error("Check your root path is right");
  69. exit;
  70. }
  71. require_once($workDir . "/include/common.inc.php");
  72. require_once(DEDEINC . "/cli.class.php");
  73. // 一个命令行的生成工具
  74. if (count($argv) > 2 && ($argv[2] == "arc" || $argv[2] == "a")) {
  75. // 生成文档
  76. // make arc typeid=1
  77. $t1 = ExecTime();
  78. $addsql = "1=1";
  79. $typeid = Option2SQLin(DedeCli::getOption("typeid"));
  80. if (!empty($typeid)) {
  81. $addsql .= " AND typeid IN(" . $typeid . ")";
  82. }
  83. $aid = Option2SQLin(DedeCli::getOption("aid"));
  84. if (!empty($aid)) {
  85. $addsql .= " AND id IN(" . $typeid . ")";
  86. }
  87. $tt = $dsql->GetOne("SELECT COUNT(id) as dd FROM `#@__arctiny` WHERE " . $addsql);
  88. $total = intval($tt['dd']);
  89. $dsql->Execute('out', "SELECT id FROM `#@__arctiny` WHERE " . $addsql . " ORDER BY typeid ASC");
  90. $i = 0;
  91. while ($row = $dsql->GetObject('out')) {
  92. $id = $row->id;
  93. $ac = new Archives($id);
  94. $rurl = $ac->MakeHtml(0);
  95. DedeCli::showProgress(ceil(($i / $total) * 100), 100);
  96. $i++;
  97. }
  98. DedeCli::write("Make archive html successfull");
  99. $queryTime = ExecTime() - $t1;
  100. DedeCli::write($queryTime);
  101. exit;
  102. } else if (count($argv) > 2 && ($argv[2] == "list" || $argv[2] == "l")) {
  103. // 生成栏目
  104. $addsql = "1=1";
  105. $typeid = Option2SQLin(DedeCli::getOption("typeid"));
  106. if (!empty($typeid)) {
  107. $addsql .= " AND id IN(" . $typeid . ")";
  108. }
  109. $dsql->Execute('out', "SELECT id,channeltype FROM `#@__arctype` WHERE " . $addsql);
  110. $i = 0;
  111. while ($row = $dsql->GetObject('out')) {
  112. if ($row->channeltype > 0) {
  113. $lv = new ListView($row->id);
  114. } else {
  115. $lv = new SgListView($row->id);
  116. }
  117. $lv->CountRecord();
  118. DedeCli::write("Start make list html[id:{$row->id}]");
  119. $lv->MakeHtml('', '', 0);
  120. }
  121. exit;
  122. } else if (count($argv) > 2 && ($argv[2] == "index" || $argv[2] == "i")) {
  123. // 生成首页
  124. $position = DedeCli::getOption("position");
  125. if (empty($position)) {
  126. $position = "../index.html";
  127. }
  128. if (!preg_match("#\.html$#", $position)) {
  129. DedeCli::error("position must end with .html");
  130. exit;
  131. }
  132. $homeFile = DEDEINC . "/" . $position;
  133. $homeFile = str_replace("\\", "/", $homeFile);
  134. $homeFile = str_replace("//", "/", $homeFile);
  135. $row = $dsql->GetOne("SELECT * FROM `#@__homepageset`");
  136. $templet = $row['templet'];
  137. $templet = str_replace("{style}", $cfg_df_style, $templet);
  138. $pv = new PartView();
  139. $GLOBALS['_arclistEnv'] = 'index';
  140. $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $templet);
  141. $pv->SaveToHtml($homeFile);
  142. DedeCli::write("Make index html successfull");
  143. } else if (count($argv) > 2 && ($argv[2] == "auto" || $argv[2] == "o")) {
  144. // 自动生成
  145. function OptimizeData($dsql)
  146. {
  147. global $cfg_dbprefix;
  148. $tptables = array("{$cfg_dbprefix}archives", "{$cfg_dbprefix}arctiny");
  149. $dsql->SetQuery("SELECT maintable,addtable FROM `#@__channeltype` ");
  150. $dsql->Execute();
  151. while ($row = $dsql->GetObject()) {
  152. $addtable = str_replace('#@__', $cfg_dbprefix, $row->addtable);
  153. if ($addtable != '' && !in_array($addtable, $tptables)) $tptables[] = $addtable;
  154. }
  155. $tptable = '';
  156. foreach ($tptables as $t) $tptable .= ($tptable == '' ? "`{$t}`" : ",`{$t}`");
  157. $dsql->ExecuteNoneQuery(" OPTIMIZE TABLE $tptable; ");
  158. }
  159. $start = empty(DedeCli::getOption("start"))? "-1 day" : DedeCli::getOption("start");
  160. $start = strtotime($start);
  161. if (!$start) {
  162. DedeCli::error("start is empty");
  163. exit;
  164. }
  165. // 1.生成首页
  166. $pv = new PartView();
  167. $row = $pv->dsql->GetOne("SELECT * FROM `#@__homepageset` ");
  168. $templet = str_replace("{style}", $cfg_df_style, $row['templet']);
  169. $homeFile = DEDEINC . '/' . $row['position'];
  170. $homeFile = str_replace("\\", '/', $homeFile);
  171. $homeFile = preg_replace("#\/{1,}#", '/', $homeFile);
  172. if ($row['showmod'] == 1) {
  173. $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . '/' . $templet);
  174. $pv->SaveToHtml($homeFile);
  175. $pv->Close();
  176. } else {
  177. if (file_exists($homeFile)) @unlink($homeFile);
  178. }
  179. DedeCli::write("Make index html successfull");
  180. // 2.生成栏目
  181. $query = "SELECT DISTINCT typeid From `#@__arctiny` WHERE senddate >=" . $start . " AND arcrank>-1";
  182. $dsql->SetQuery($query);
  183. $dsql->Execute();
  184. $typeids = array();
  185. while ($row = $dsql->GetArray()) {
  186. $typeids[$row['typeid']] = 1;
  187. }
  188. if (count($typeids) > 0) {
  189. foreach ($typeids as $k => $v) {
  190. $vs = array();
  191. $vs = GetParentIds($k);
  192. if (!isset($typeidsok[$k])) {
  193. $typeidsok[$k] = 1;
  194. }
  195. foreach ($vs as $k => $v) {
  196. if (!isset($typeidsok[$v])) {
  197. $typeidsok[$v] = 1;
  198. }
  199. }
  200. }
  201. foreach ($typeidsok as $tt=> $k) {
  202. $row = $dsql->GetOne("SELECT id,channeltype FROM `#@__arctype` WHERE id=".$tt);
  203. if ($row['channeltype'] > 0) {
  204. $lv = new ListView($tt);
  205. } else {
  206. $lv = new SgListView($tt);
  207. }
  208. $lv->CountRecord();
  209. DedeCli::write("Start make list html[id:{$tt}]");
  210. $lv->MakeHtml('', '', 0);
  211. }
  212. DedeCli::write("Make list html successfull");
  213. }
  214. // 生成文档
  215. $tt = $dsql->GetOne("SELECT COUNT(id) as dd FROM `#@__arctiny` WHERE senddate >=" . $start . " AND arcrank>-1");
  216. $total = intval($tt['dd']);
  217. $dsql->Execute('out', "SELECT id FROM `#@__arctiny` WHERE senddate >=" . $start . " AND arcrank>-1 ORDER BY typeid ASC");
  218. $i = 0;
  219. while ($row = $dsql->GetObject('out')) {
  220. $id = $row->id;
  221. $ac = new Archives($id);
  222. $rurl = $ac->MakeHtml(0);
  223. DedeCli::showProgress(ceil(($i / $total) * 100), 100);
  224. $i++;
  225. }
  226. DedeCli::write("Make archives html successfull");
  227. // 优化数据
  228. OptimizeData($dsql);
  229. DedeCli::write("Optimize data successfull");
  230. } else {
  231. $helpStr = "
  232. USAGE:
  233. php ./dedebiz make action [arguments...]
  234. ACTIONS:
  235. index,i Make Index html
  236. --position index html position,default: ../index.html(relative include dir)
  237. arc,a Make Archive htmls
  238. --typeid type id
  239. --aid archive id
  240. list,l Make List htmls
  241. --typeid type id
  242. auto,o Auto Make htmls
  243. --start start time(format:2012-03-12)
  244. WEBSITE:
  245. https://www.dedebiz.com/help/";
  246. DedeCli::write($helpStr);
  247. exit;
  248. }
  249. } else if (count($argv) > 1 && ($argv[1] == "update" || $argv[1] == "u")) {
  250. define("DEDEINC", $workDir."/include");
  251. require_once(DEDEINC."/dedehttpdown.class.php");
  252. require_once(DEDEINC . "/cli.class.php");
  253. // 更新系统
  254. $latestURL = "https://cdn.dedebiz.com/release/latest.txt";
  255. $del = new DedeHttpDown();
  256. $del->OpenUrl($latestURL);
  257. $remoteVerStr = $del->GetHtml();
  258. $commStr = file_get_contents(DEDEINC."/common.inc.php");
  259. preg_match("#_version_detail = '([\d\.]+)'#", $commStr, $matchs);
  260. $cfg_version_detail = $localVerStr = $matchs[1];
  261. if (version_compare($localVerStr, $remoteVerStr, '>=')) {
  262. DedeCli::error("latest version,don't need to update");
  263. exit;
  264. }
  265. $fileHashURL = "https://cdn.dedebiz.com/release/{$cfg_version_detail}.json";
  266. $del = new DedeHttpDown();
  267. $del->OpenUrl($fileHashURL);
  268. $filelist = $del->GetJSON();
  269. $offFiles = array();
  270. // foreach ($filelist as $key => $ff) {
  271. // $offFiles[$ff->filename] = $ff->hash;
  272. // }
  273. var_dump($filelist);
  274. } else {
  275. echo $helpStr;
  276. }