PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/develop/include/script.php

https://github.com/jinbo51/DiscuzX
PHP | 264 lines | 235 code | 9 blank | 20 comment | 70 complexity | 42f82ee1f384a28ed8289d16d0369379 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: script.php 30659 2012-06-11 02:10:10Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $scripttype = array('navigation', 'secqaa');
  12. if(!defined('DISCUZ_VERSION')) {
  13. require_once DISCUZ_ROOT.'./source/discuz_version.php';
  14. }
  15. $version = floatval(substr(DISCUZ_VERSION, 1));
  16. if($version > 2.5) {
  17. $scripttype = array_merge($scripttype, array('seccode', 'magic', 'cron', 'adv', 'task'));
  18. } elseif($version > 2) {
  19. $scripttype = array_merge($scripttype, array('seccode'));
  20. }
  21. $basetype = array('general', 'special', 'mobile');
  22. $type = in_array($_GET['type'], array_merge($scripttype, $basetype, array('system'))) ? $_GET['type'] : '';
  23. $filename = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9_\.\]]/", '', $_GET['filename']));
  24. if(!submitcheck('pluginsubmit')) {
  25. $scripts = array();
  26. $scriptList = false;
  27. if($type && $filename && (in_array($type, $basetype) && $plugin['modules'][$type] || $plugin['modules'][$type][$filename])) {
  28. if(in_array($type, $basetype)) {
  29. $module = $plugin['modules'][$type];
  30. require_once DISCUZ_ROOT.'develop/include/hooklist.php';
  31. $hooklist = $type == 'mobile' ? $mobilehook : $generalhook;
  32. } else {
  33. $module = $plugin['modules'][$type][$filename];
  34. if($type == 'cron') {
  35. $days = array(-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);
  36. $week = array('0'=>'星期日', '1'=>'星期一', '2'=>'星期二', '3'=>'星期三', '4'=>'星期四', '5'=>'星期五', '6'=>'星期六');
  37. $module['weekday'] = isset($module['weekday']) ? $module['weekday'] : '-1';
  38. $module['day'] = isset($module['day']) ? $module['day'] : '-1';
  39. $module['hour'] = isset($module['hour']) ? $module['hour'] : '-1';
  40. } elseif($type == 'navigation') {
  41. $allowgroup = array('0' => '普通用户', '1' => '管理员', '2' => '超级版主', '3' => '版主');
  42. }
  43. }
  44. } elseif($type == 'system' && in_array($filename, array('install', 'uninstall', 'upgrade'))) {
  45. $extra = $plugin['modules']['extra'];
  46. } else {
  47. $scriptList = true;
  48. $scripts = $plugin['modules'];
  49. }
  50. $navtypes = array(
  51. 'g1' => array(
  52. '1' => array('h' => '1100100', 'e' => 'inc', 'value' => '1', 'desc' => $devlang['plugins_edit_modules_type_1']),
  53. '5' => array('h' => '1111', 'e' => 'inc', 'value' => '5', 'desc' => $devlang['plugins_edit_modules_type_5']),
  54. '27' => array('h' => '1100100', 'e' => 'inc', 'value' => '27', 'desc' => $devlang['plugins_edit_modules_type_27']),
  55. '23' => array('h' => '1100100', 'e' => 'inc', 'value' => '23', 'desc' => $devlang['plugins_edit_modules_type_23']),
  56. '25' => array('h' => '1100110', 'e' => 'inc', 'value' => '25', 'desc' => $devlang['plugins_edit_modules_type_25']),
  57. '24' => array('h' => '1100111', 'e' => 'inc', 'value' => '24', 'desc' => $devlang['plugins_edit_modules_type_24'])
  58. ),
  59. 'g3' => array(
  60. '7' => array('h' => '1111', 'e' => 'inc', 'value' => '7', 'desc' => $devlang['plugins_edit_modules_type_7']),
  61. '17' => array('h' => '1111', 'e' => 'inc', 'value' => '17', 'desc' => $devlang['plugins_edit_modules_type_17']),
  62. '19' => array('h' => '1111', 'e' => 'inc', 'value' => '19', 'desc' => $devlang['plugins_edit_modules_type_19']),
  63. '14' => array('h' => '1001', 'e' => 'inc', 'value' => '14', 'desc' => $devlang['plugins_edit_modules_type_14']),
  64. '26' => array('h' => '1111', 'e' => 'inc', 'value' => '26', 'desc' => $devlang['plugins_edit_modules_type_26']),
  65. '21' => array('h' => '1111', 'e' => 'inc', 'value' => '21', 'desc' => $devlang['plugins_edit_modules_type_21']),
  66. '15' => array('h' => '1001', 'e' => 'inc', 'value' => '15', 'desc' => $devlang['plugins_edit_modules_type_15']),
  67. '16' => array('h' => '1001', 'e' => 'inc', 'value' => '16', 'desc' => $devlang['plugins_edit_modules_type_16']),
  68. '3' => array('h' => '1001', 'e' => 'inc', 'value' => '3', 'desc' => $devlang['plugins_edit_modules_type_3'])
  69. )
  70. );
  71. } else {
  72. require_once libfile('function/admincp');
  73. require_once libfile('function/plugin');
  74. $_GET['description'] = dhtmlspecialchars($_GET['description']);
  75. if(submitcheck('addhook')) {
  76. require_once DISCUZ_ROOT.'develop/include/hooklist.php';
  77. $sort = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9_\]]/", '', $_GET['sort']));
  78. $page = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9_\.\]]/", '', $_GET['page']));
  79. $hooklist = $type == 'mobile' ? $mobilehook : $generalhook;
  80. if(in_array($type, $basetype)) {
  81. //初始化钩子
  82. $plugin['modules'][$type]['hooks'] = array();
  83. foreach($_GET['hooks'] as $skey => $value) {
  84. $sorts = $hooklist[$skey];
  85. if($sorts) {
  86. foreach($value as $fkey => $hval) {
  87. if($sorts[$fkey]) {
  88. foreach($hval as $hook) {
  89. $key = $hook;
  90. if(stripos($hook, '_output') && substr($hook, stripos($hook, '_output')) == '_output') {
  91. $key = substr($key, 0, stripos($hook, '_output'));
  92. }
  93. //判断是否有选择主方法,如果没有抛弃output的钩子
  94. if(isset($sorts[$fkey][$key]) && isset($_GET['hooks'][$skey][$fkey][$key])) {
  95. $plugin['modules'][$type]['hooks'][$skey][$fkey][$hook] = $hook;
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }
  102. //添加钩子
  103. if(isset($hooklist[$sort])) {
  104. $sorts = $hooklist[$sort];
  105. if($sorts && $sorts[$page]) {
  106. foreach($_GET['newhook'] as $hook) {
  107. $key = $hook;
  108. if(stripos($hook, '_output') && substr($hook, stripos($hook, '_output')) == '_output') {
  109. $key = substr($key, 0, stripos($hook, '_output'));
  110. }
  111. //判断是否有选择主方法,如果没有抛弃output的钩子
  112. if(isset($sorts[$page][$key]) && isset($_GET['newhook'][$key])) {
  113. $plugin['modules'][$type]['hooks'][$sort][$page][$hook] = $hook;
  114. }
  115. }
  116. }
  117. }
  118. //写入插件信息
  119. C::t('common_plugin')->update($pluginid, array('modules' => serialize($plugin['modules'])));
  120. }
  121. devmessage('嵌入点添加成功,继续下一步。', "develop.php?mod=plugins&action=$action&operation=$operation&pluginid=$pluginid&filename=$filename&type=$type", 'succeed');
  122. } elseif(submitcheck('editcron')) {
  123. //过滤分钟数据
  124. $minutes = explode(',', $_GET['newminute']);
  125. foreach($minutes as $minute) {
  126. $minute = intval($minute);
  127. if($minute < 0 || 59 < $minute) {
  128. continue;
  129. }
  130. $newminute[$minute] = $minute;
  131. }
  132. $plugin['modules'][$type][$filename]['weekday'] = $_GET['newweekday'] < -1 || 6 < $_GET['newweekday'] ? -1 : intval($_GET['newweekday']);
  133. $plugin['modules'][$type][$filename]['day'] = $_GET['newday'] < -1 || 31 < $_GET['newday'] ? -1 : intval($_GET['newday']);
  134. $plugin['modules'][$type][$filename]['hour'] = $_GET['newhour'] < -1 || 23 < $_GET['newhour'] ? -1 : intval($_GET['newhour']);
  135. $plugin['modules'][$type][$filename]['minute'] = $newminute ? implode(',', $newminute) : '';
  136. $plugin['modules'][$type][$filename]['description'] = $_GET['description'];
  137. //写入插件信息
  138. C::t('common_plugin')->update($pluginid, array('modules' => serialize($plugin['modules'])));
  139. devmessage('计划任务设置完成', "develop.php?mod=plugins&action=$action&operation=$operation&pluginid=$pluginid", 'succeed');
  140. } elseif(submitcheck('editadv')) {
  141. $plugin['modules'][$type][$filename]['description'] = $_GET['description'];
  142. //写入插件信息
  143. C::t('common_plugin')->update($pluginid, array('modules' => serialize($plugin['modules'])));
  144. devmessage('脚本编辑完成', "develop.php?mod=plugins&action=$action&operation=$operation&pluginid=$pluginid", 'succeed');
  145. } elseif(submitcheck('editnav')) {
  146. if(!ispluginkey($_GET['name'])) {
  147. devmessage($devlang['plugins_edit_modules_name_invalid'], '', 'error');
  148. } elseif($_GET['name'] != $filename && isset($plugin['modules'][$type][$_GET['name']])) {
  149. devmessage($devlang['plugins_script_'.$type].$devlang['plugins_script_repeat'], '', 'error');
  150. }
  151. $plugin['modules'][$type][$filename] = array(
  152. 'name' => $_GET['name'],
  153. 'menu' => trim($_GET['menu']),
  154. 'url' => trim($_GET['url']),
  155. 'type' => intval($_GET['newtype']),
  156. 'adminid' => $_GET['adminid'] >= 0 && $_GET['adminid'] <= 3 ? intval($_GET['adminid']) : 1,
  157. 'displayorder' => intval($_GET['order']),
  158. 'navtitle' => $_GET['navtitle'],
  159. 'navicon' => $_GET['navicon'],
  160. 'navsubname' => $_GET['navsubname'],
  161. 'navsuburl' => $_GET['navsuburl'],
  162. 'description' => trim($_GET['menu'])
  163. );
  164. //写入插件信息
  165. C::t('common_plugin')->update($pluginid, array('modules' => serialize($plugin['modules'])));
  166. devmessage('脚本编辑完成', "develop.php?mod=plugins&action=$action&operation=$operation&pluginid=$pluginid", 'succeed');
  167. } elseif(submitcheck('editsystem')) {
  168. if(in_array($filename, array('install', 'uninstall', 'upgrade'))) {
  169. $plugin['modules']['extra'][$filename] = $_GET[$filename];
  170. //添加表时同时增加删除表SQL
  171. if($filename == 'install' && empty($plugin['modules']['extra']['uninstall'])) {
  172. preg_match_all("/CREATE\s+TABLE.+?pre\_(.+?)\s*\((.+?)\)\s*(ENGINE|TYPE)\s*\=/is", $_GET[$filename], $matches);
  173. if($matches[1]) {
  174. $uninstall = '';
  175. foreach($matches[1] as $table) {
  176. $uninstall .= "DROP TABLE IF EXISTS pre_$table;\n";
  177. }
  178. $plugin['modules']['extra']['uninstall'] = $uninstall;
  179. }
  180. }
  181. //写入插件信息
  182. C::t('common_plugin')->update($pluginid, array('modules' => serialize($plugin['modules'])));
  183. }
  184. devmessage('脚本编辑完成', "develop.php?mod=plugins&action=$action&operation=$operation&pluginid=$pluginid", 'succeed');
  185. } else {
  186. $modules = array();
  187. //整理新的脚本名称
  188. foreach($_POST['script'] as $key => $scripts) {
  189. if($key === 'extra' || $key === 'system') {
  190. continue;
  191. }
  192. if(in_array($key, array('general', 'special', 'mobile'))) {
  193. if(empty($scripts)) {
  194. unset($plugin['modules'][$key]);
  195. continue;
  196. } elseif(!empty($scripts)) {
  197. if(!ispluginkey($scripts)) {
  198. devmessage($devlang['plugins_edit_modules_name_invalid'], '', 'error');
  199. }
  200. $plugin['modules'][$key]['name'] = $scripts;
  201. $plugin['modules'][$key]['displayorder'] = 0;
  202. $plugin['modules'][$key]['menu'] = '';
  203. $plugin['modules'][$key]['url'] = '';
  204. $plugin['modules'][$key]['type'] = $key == 'general' ? 11 : ($key == 'special' ? 12 : 28);
  205. $plugin['modules'][$key]['adminid'] = 1;
  206. $plugin['modules'][$key]['navtitle'] = '';
  207. $plugin['modules'][$key]['navicon'] = '';
  208. $plugin['modules'][$key]['navsubname'] = '';
  209. $plugin['modules'][$key]['navsuburl'] = '';
  210. }
  211. } elseif(in_array($key, $scripttype)) {
  212. $existscripts = array();
  213. foreach($scripts as $scrkey => $scriptname) {
  214. if(isset($_POST['delete'][$key][$scriptname])) {
  215. unset($plugin['modules'][$key][$scriptname]);
  216. continue;
  217. } elseif(!empty($scriptname)) {
  218. if(!ispluginkey($scriptname)) {
  219. devmessage($devlang['plugins_edit_modules_name_invalid'], '', 'error');
  220. } elseif(@in_array($scriptname, $existscripts)) {
  221. devmessage($devlang['plugins_script_'.$key].$devlang['plugins_script_repeat'], '', 'error');
  222. }
  223. $init = isset($plugin['modules'][$key][$scriptname]) ? false : true;
  224. //更名
  225. if($scrkey != $scriptname && !is_numeric($scrkey)) {
  226. $plugin['modules'][$key][$scriptname] = $plugin['modules'][$key][$scrkey];
  227. unset($plugin['modules'][$key][$scrkey]);
  228. }
  229. $plugin['modules'][$key][$scriptname]['name'] = $scriptname;
  230. $plugin['modules'][$key][$scriptname]['displayorder'] = 0;
  231. if($key == 'navigation' && $init) {
  232. $plugin['modules'][$key][$scriptname]['menu'] = '';
  233. $plugin['modules'][$key][$scriptname]['url'] = '';
  234. $plugin['modules'][$key][$scriptname]['type'] = 1;
  235. $plugin['modules'][$key][$scriptname]['adminid'] = 0;
  236. $plugin['modules'][$key][$scriptname]['navtitle'] = '';
  237. $plugin['modules'][$key][$scriptname]['navicon'] = '';
  238. $plugin['modules'][$key][$scriptname]['navsubname'] = '';
  239. $plugin['modules'][$key][$scriptname]['navsuburl'] = '';
  240. }
  241. $existscripts[$scriptname] = $scriptname;
  242. }
  243. }
  244. }
  245. }
  246. C::t('common_plugin')->update($pluginid, array('modules' => serialize($plugin['modules'])));
  247. if($action == 'edit') {
  248. devmessage('脚本添加成功', "develop.php?mod=plugins&action=$action&operation=script&pluginid=$pluginid", 'succeed');
  249. } else {
  250. dheader("location:develop.php?mod=plugins&action=$action&operation=setting&pluginid=$pluginid");
  251. //devmessage('脚本添加成功', "develop.php?mod=plugins&action=$action&operation=setting&pluginid=$pluginid", 'succeed');
  252. }
  253. }
  254. }
  255. ?>