PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/install/setup.info.php

https://github.com/good-web-master/modx.evo.custom
PHP | 318 lines | 259 code | 15 blank | 44 comment | 65 complexity | c057e77c9eb6cc732007335a684b1c9e MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0, MIT, BSD-3-Clause
  1. <?php
  2. //:: MODx Installer Setup file
  3. //:::::::::::::::::::::::::::::::::::::::::
  4. require_once('../manager/includes/version.inc.php');
  5. $moduleName = "MODx";
  6. $moduleVersion = $modx_branch.' '.$modx_version;
  7. $moduleRelease = $modx_release_date;
  8. $moduleSQLBaseFile = "setup.sql";
  9. $moduleSQLDataFile = "setup.data.sql";
  10. $chunkPath = $setupPath .'/assets/chunks';
  11. $snippetPath = $setupPath .'/assets/snippets';
  12. $pluginPath = $setupPath .'/assets/plugins';
  13. $modulePath = $setupPath .'/assets/modules';
  14. $templatePath = $setupPath .'/assets/templates';
  15. $tvPath = $setupPath .'/assets/tvs';
  16. // setup Template template files - array : name, description, type - 0:file or 1:content, parameters, category
  17. $mt = &$moduleTemplates;
  18. if(is_dir($templatePath) && is_readable($templatePath)) {
  19. $d = dir($templatePath);
  20. while (false !== ($tplfile = $d->read()))
  21. {
  22. if(substr($tplfile, -4) != '.tpl') continue;
  23. $params = parse_docblock($templatePath, $tplfile);
  24. if(is_array($params) && (count($params)>0))
  25. {
  26. $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}";
  27. $mt[] = array
  28. (
  29. $params['name'],
  30. $description,
  31. // Don't think this is gonna be used ... but adding it just in case 'type'
  32. $params['type'],
  33. "$templatePath/{$params['filename']}",
  34. $params['modx_category'],
  35. $params['lock_template'],
  36. array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false
  37. );
  38. }
  39. }
  40. $d->close();
  41. }
  42. // setup Template Variable template files
  43. $mtv = &$moduleTVs;
  44. if(is_dir($tvPath) && is_readable($tvPath)) {
  45. $d = dir($tvPath);
  46. while (false !== ($tplfile = $d->read())) {
  47. if(substr($tplfile, -4) != '.tpl') continue;
  48. $params = parse_docblock($tvPath, $tplfile);
  49. if(is_array($params) && (count($params)>0)) {
  50. $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}";
  51. $mtv[] = array(
  52. $params['name'],
  53. $params['caption'],
  54. $description,
  55. $params['input_type'],
  56. $params['input_options'],
  57. $params['input_default'],
  58. $params['output_widget'],
  59. $params['output_widget_params'],
  60. "$templatePath/{$params['filename']}", /* not currently used */
  61. $params['template_assignments'], /* comma-separated list of template names */
  62. $params['modx_category'],
  63. $params['lock_tv'], /* value should be 1 or 0 */
  64. array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false
  65. );
  66. }
  67. }
  68. $d->close();
  69. }
  70. // setup chunks template files - array : name, description, type - 0:file or 1:content, file or content
  71. $mc = &$moduleChunks;
  72. if(is_dir($chunkPath) && is_readable($chunkPath)) {
  73. $d = dir($chunkPath);
  74. while (false !== ($tplfile = $d->read())) {
  75. if(substr($tplfile, -4) != '.tpl') {
  76. continue;
  77. }
  78. $params = parse_docblock($chunkPath, $tplfile);
  79. if(is_array($params) && count($params) > 0) {
  80. $mc[] = array(
  81. $params['name'],
  82. $params['description'],
  83. "$chunkPath/{$params['filename']}",
  84. $params['modx_category'],
  85. array_key_exists('overwrite', $params) ? $params['overwrite'] : 'true',
  86. array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false
  87. );
  88. }
  89. }
  90. $d->close();
  91. }
  92. // setup snippets template files - array : name, description, type - 0:file or 1:content, file or content,properties
  93. $ms = &$moduleSnippets;
  94. if(is_dir($snippetPath) && is_readable($snippetPath)) {
  95. $d = dir($snippetPath);
  96. while (false !== ($tplfile = $d->read())) {
  97. if(substr($tplfile, -4) != '.tpl') {
  98. continue;
  99. }
  100. $params = parse_docblock($snippetPath, $tplfile);
  101. if(is_array($params) && count($params) > 0) {
  102. $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}";
  103. $ms[] = array(
  104. $params['name'],
  105. $description,
  106. "$snippetPath/{$params['filename']}",
  107. $params['properties'],
  108. $params['modx_category'],
  109. array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false
  110. );
  111. }
  112. }
  113. $d->close();
  114. }
  115. // setup plugins template files - array : name, description, type - 0:file or 1:content, file or content,properties
  116. $mp = &$modulePlugins;
  117. if(is_dir($pluginPath) && is_readable($pluginPath)) {
  118. $d = dir($pluginPath);
  119. while (false !== ($tplfile = $d->read())) {
  120. if(substr($tplfile, -4) != '.tpl') {
  121. continue;
  122. }
  123. $params = parse_docblock($pluginPath, $tplfile);
  124. if(is_array($params) && count($params) > 0) {
  125. $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}";
  126. $mp[] = array(
  127. $params['name'],
  128. $description,
  129. "$pluginPath/{$params['filename']}",
  130. $params['properties'],
  131. $params['events'],
  132. $params['guid'],
  133. $params['modx_category'],
  134. $params['legacy_names'],
  135. array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false
  136. );
  137. }
  138. }
  139. $d->close();
  140. }
  141. // setup modules - array : name, description, type - 0:file or 1:content, file or content,properties, guid,enable_sharedparams
  142. $mm = &$moduleModules;
  143. if(is_dir($modulePath) && is_readable($modulePath)) {
  144. $d = dir($modulePath);
  145. while (false !== ($tplfile = $d->read())) {
  146. if(substr($tplfile, -4) != '.tpl') {
  147. continue;
  148. }
  149. $params = parse_docblock($modulePath, $tplfile);
  150. if(is_array($params) && count($params) > 0) {
  151. $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}";
  152. $mm[] = array(
  153. $params['name'],
  154. $description,
  155. "$modulePath/{$params['filename']}",
  156. $params['properties'],
  157. $params['guid'],
  158. intval($params['shareparams']),
  159. $params['modx_category'],
  160. array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false
  161. );
  162. }
  163. }
  164. $d->close();
  165. }
  166. // setup callback function
  167. $callBackFnc = "clean_up";
  168. function clean_up($sqlParser) {
  169. $ids = array();
  170. $mysqlVerOk = -1;
  171. if(function_exists("mysql_get_server_info")) {
  172. $mysqlVerOk = (version_compare(mysql_get_server_info(),"4.0.2")>=0);
  173. }
  174. // secure web documents - privateweb
  175. mysql_query("UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 0 WHERE privateweb = 1",$sqlParser->conn);
  176. $sql = "SELECT DISTINCT sc.id
  177. FROM `".$sqlParser->prefix."site_content` sc
  178. LEFT JOIN `".$sqlParser->prefix."document_groups` dg ON dg.document = sc.id
  179. LEFT JOIN `".$sqlParser->prefix."webgroup_access` wga ON wga.documentgroup = dg.document_group
  180. WHERE wga.id>0";
  181. $ds = mysql_query($sql,$sqlParser->conn);
  182. if(!$ds) {
  183. echo "An error occurred while executing a query: ".mysql_error();
  184. }
  185. else {
  186. while($r = mysql_fetch_assoc($ds)) $ids[]=$r["id"];
  187. if(count($ids)>0) {
  188. mysql_query("UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 1 WHERE id IN (".implode(", ",$ids).")");
  189. unset($ids);
  190. }
  191. }
  192. // secure manager documents privatemgr
  193. mysql_query("UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 0 WHERE privatemgr = 1");
  194. $sql = "SELECT DISTINCT sc.id
  195. FROM `".$sqlParser->prefix."site_content` sc
  196. LEFT JOIN `".$sqlParser->prefix."document_groups` dg ON dg.document = sc.id
  197. LEFT JOIN `".$sqlParser->prefix."membergroup_access` mga ON mga.documentgroup = dg.document_group
  198. WHERE mga.id>0";
  199. $ds = mysql_query($sql);
  200. if(!$ds) {
  201. echo "An error occurred while executing a query: ".mysql_error();
  202. }
  203. else {
  204. while($r = mysql_fetch_assoc($ds)) $ids[]=$r["id"];
  205. if(count($ids)>0) {
  206. mysql_query("UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 1 WHERE id IN (".implode(", ",$ids).")");
  207. unset($ids);
  208. }
  209. }
  210. /**** Add Quick Plugin to Module
  211. // get quick edit module id
  212. $ds = mysql_query("SELECT id FROM `".$sqlParser->prefix."site_modules` WHERE name='QuickEdit'");
  213. if(!$ds) {
  214. echo "An error occurred while executing a query: ".mysql_error();
  215. }
  216. else {
  217. $row = mysql_fetch_assoc($ds);
  218. $moduleid=$row["id"];
  219. }
  220. // get plugin id
  221. $ds = mysql_query("SELECT id FROM `".$sqlParser->prefix."site_plugins` WHERE name='QuickEdit'");
  222. if(!$ds) {
  223. echo "An error occurred while executing a query: ".mysql_error();
  224. }
  225. else {
  226. $row = mysql_fetch_assoc($ds);
  227. $pluginid=$row["id"];
  228. }
  229. // setup plugin as module dependency
  230. $ds = mysql_query("SELECT module FROM `".$sqlParser->prefix."site_module_depobj` WHERE module='$moduleid' AND resource='$pluginid' AND type='30' LIMIT 1");
  231. if(!$ds) {
  232. echo "An error occurred while executing a query: ".mysql_error();
  233. }
  234. elseif (mysql_num_rows($ds)==0){
  235. mysql_query("INSERT INTO `".$sqlParser->prefix."site_module_depobj` (module, resource, type) VALUES('$moduleid','$pluginid',30)");
  236. }
  237. ***/
  238. }
  239. function parse_docblock($element_dir, $filename) {
  240. $params = array();
  241. $fullpath = $element_dir . '/' . $filename;
  242. if(is_readable($fullpath)) {
  243. $tpl = @fopen($fullpath, "r");
  244. if($tpl) {
  245. $params['filename'] = $filename;
  246. $docblock_start_found = false;
  247. $name_found = false;
  248. $description_found = false;
  249. $docblock_end_found = false;
  250. while(!feof($tpl)) {
  251. $line = fgets($tpl);
  252. if(!$docblock_start_found) {
  253. // find docblock start
  254. if(strpos($line, '/**') !== false) {
  255. $docblock_start_found = true;
  256. }
  257. continue;
  258. } elseif(!$name_found) {
  259. // find name
  260. $ma = null;
  261. if(preg_match("/^\s+\*\s+(.+)/", $line, $ma)) {
  262. $params['name'] = trim($ma[1]);
  263. $name_found = !empty($params['name']);
  264. }
  265. continue;
  266. } elseif(!$description_found) {
  267. // find description
  268. $ma = null;
  269. if(preg_match("/^\s+\*\s+(.+)/", $line, $ma)) {
  270. $params['description'] = trim($ma[1]);
  271. $description_found = !empty($params['description']);
  272. }
  273. continue;
  274. } else {
  275. $ma = null;
  276. if(preg_match("/^\s+\*\s+\@([^\s]+)\s+(.+)/", $line, $ma)) {
  277. $param = trim($ma[1]);
  278. $val = trim($ma[2]);
  279. if(!empty($param) && !empty($val)) {
  280. if($param == 'internal') {
  281. $ma = null;
  282. if(preg_match("/\@([^\s]+)\s+(.+)/", $val, $ma)) {
  283. $param = trim($ma[1]);
  284. $val = trim($ma[2]);
  285. }
  286. //if($val !== '0' && (empty($param) || empty($val))) {
  287. if(empty($param)) {
  288. continue;
  289. }
  290. }
  291. $params[$param] = $val;
  292. }
  293. } elseif(preg_match("/^\s*\*\/\s*$/", $line)) {
  294. $docblock_end_found = true;
  295. break;
  296. }
  297. }
  298. }
  299. @fclose($tpl);
  300. }
  301. }
  302. return $params;
  303. }