PageRenderTime 29ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/createNewProject.php

http://marcel-as3-framework.googlecode.com/
PHP | 326 lines | 220 code | 43 blank | 63 comment | 46 complexity | 61ab5b47be155587051bc7b3d12f72e7 MD5 | raw file
  1. <?php
  2. /**
  3. * Licensed under the MIT License
  4. *
  5. * Copyright (c) 2010 Alexandre Croiseaux
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. */
  25. if (isset($_POST["go"]))
  26. {
  27. //echo "<pre>";
  28. //print_r($_POST);
  29. //echo "</pre>";
  30. $destFolderContainer = $_POST["destFolderContainer"];
  31. if ($destFolderContainer[strlen($destFolderContainer) - 1] == "/") $destFolderContainer = substr($destFolderContainer, 0, strlen($destFolderContainer) - 1);
  32. $destPackageName = $_POST["destPackageName"];
  33. $site_xml = $destFolderContainer."/apps/site/web/xml/config/site.xml";
  34. ///////////////////////////////////////
  35. // create rep
  36. ///////////////////////////////////////
  37. if (!is_dir($destFolderContainer))
  38. {
  39. if (!mkdir($destFolderContainer))
  40. {
  41. echo "Folder '".$destFolderContainer."' not found!";
  42. exit;
  43. }
  44. }
  45. ///////////////////////////////////////
  46. // copy files
  47. ///////////////////////////////////////
  48. $copy = copyr(".", $destFolderContainer);
  49. echo $copy ? "<br/>Copy OK<br/>" : "<br/>Copy KO<br/>";
  50. ///////////////////////////////////////
  51. // rename proj file
  52. ///////////////////////////////////////
  53. @rename($destFolderContainer."/marcel-as3-framework.as3proj", $destFolderContainer."/".array_pop(explode("/", $destFolderContainer)).".as3proj");
  54. @rename($destFolderContainer."/src/actionscript/project/project_name", $destFolderContainer."/src/actionscript/project/".$destPackageName);
  55. ///////////////////////////////////////
  56. // create uis
  57. ///////////////////////////////////////
  58. $imports = "";
  59. $classNames = "";
  60. $nodes = "";
  61. for ($i = 0; $i < 10; $i++)
  62. {
  63. $assets = "";
  64. $name = $_POST["ui_id_".$i];
  65. $fullQualifiedClassName = $destPackageName.".".$_POST["ui_class_".$i];
  66. if ($name != "name_ui")
  67. {
  68. $src_file = "src/actionscript/project/project_name/uis/content/PageUI.as";
  69. if (isset($_POST["ui_".$i."_form_cb"]) && $_POST["ui_".$i."_form_cb"])
  70. {
  71. $src_file = "src/actionscript/project/project_name/uis/content/FormUI.as";
  72. $assets = "assets=\"forms_xml\" ";
  73. }
  74. if (isset($_POST["ui_".$i."_video_cb"]) && $_POST["ui_".$i."_video_cb"]) $src_file = "src/actionscript/project/project_name/uis/content/VideoUI.as";
  75. $imports .= "import ".$fullQualifiedClassName.";\n\t";
  76. $nodes .= "\n\t\t<ui id=\"".$name."\" classname=\"".$fullQualifiedClassName."\" ".$assets."/>";
  77. $path = explode(".", $fullQualifiedClassName);
  78. @mkdir($destFolderContainer."/src/actionscript/project/".implode("/", array_slice($path, 0, count($path)-1)), 0777, true);
  79. $dest_file = $destFolderContainer."/src/actionscript/project/".implode("/", $path).".as";
  80. $classNames .= "\t\t".array_pop($path).";\n";
  81. echo "<br/>Creating UI '".$name."' (".$fullQualifiedClassName.")";
  82. copy($src_file, $dest_file);
  83. chmod($dest_file, 0777);
  84. updateUIFile($dest_file, $fullQualifiedClassName);
  85. }
  86. }
  87. // update Index.as
  88. $file = $destFolderContainer."/src/actionscript/project/".$destPackageName."/Index.as";
  89. $content = file_get_contents($file);
  90. $content = str_replace("import ".$destPackageName.".uis.content.*;", $imports, $content);
  91. $content = str_replace("PageUI; VideoUI; FormUI;", $classNames, $content);
  92. file_put_contents($file, $content);
  93. // update site.xml
  94. $content = file_get_contents($site_xml);
  95. $content = str_replace("</uis>", $nodes."\n\t</uis>", $content);
  96. file_put_contents($site_xml, $content);
  97. ///////////////////////////////////////
  98. // create states
  99. ///////////////////////////////////////
  100. echo "<br/><br/>";
  101. $nav_xml = "<navigation>\n\t<btns>\n\t\t<btn state=\"home\">State home</btn>\n";
  102. $nodes = "";
  103. for ($i = 0; $i < 10; $i++)
  104. {
  105. $name = $_POST["state_id_".$i];
  106. if ($name != "state")
  107. {
  108. $nodes .= "\n\t\t<state id=\"".$name."\" open_uis=\"".implode(",", $_POST["state_".$i."_cb"])."\" keep_uis=\"\" />";
  109. $nav_xml .= "\t\t<btn state=\"".$name."\">State ".$name."</btn>\n";
  110. echo "<br/>Creating State '".$name."' (".implode(",", $_POST["state_".$i."_cb"]).")";
  111. }
  112. }
  113. // update site.xml
  114. $content = file_get_contents($site_xml);
  115. $content = str_replace("</states>", $nodes."\n\t</states>", $content);
  116. file_put_contents($site_xml, $content);
  117. // update nav.xml
  118. $nav_xml .= "\n\t</btns>\n</navigation>";
  119. file_put_contents($destFolderContainer."/apps/site/web/xml/texts/fr/navigation.xml", $nav_xml);
  120. ///////////////////////////////////////
  121. // remove FW default stuff
  122. ///////////////////////////////////////
  123. /*
  124. unlink($destFolderContainer."/src/actionscript/project/".$destPackageName."/uis/content/FormUI.as");
  125. unlink($destFolderContainer."/src/actionscript/project/".$destPackageName."/uis/content/PageUI.as");
  126. unlink($destFolderContainer."/src/actionscript/project/".$destPackageName."/uis/content/PageUI.as");
  127. rmdir($destFolderContainer."/src/actionscript/project/".$destPackageName."/uis/content");
  128. */
  129. $doc = new DomDocument();
  130. $doc->load($site_xml);
  131. for ($i = 0; $i < 4; $i++)
  132. {
  133. $doc->getElementsByTagName('uis')->item(0)->removeChild($doc->getElementsByTagName('ui')->item(3));
  134. $doc->getElementsByTagName('states')->item(0)->removeChild($doc->getElementsByTagName('state')->item(1));
  135. }
  136. $doc->save($site_xml);
  137. ///////////////////////////////////////
  138. // done
  139. ///////////////////////////////////////
  140. echo "<br/><br/>Project created!";
  141. }
  142. function parseFile($file)
  143. {
  144. global $destPackageName;
  145. $startContent = file_get_contents($file);
  146. $content = str_replace("project_name", $destPackageName, $startContent);
  147. if ($content != $startContent)
  148. {
  149. file_put_contents($file, $content);
  150. echo "Updating file ".$file."<br>";
  151. }
  152. }
  153. function updateUIFile($file, $fullQualifiedClassName)
  154. {
  155. $a = explode(".", $fullQualifiedClassName);
  156. $className = array_pop($a);
  157. $packageName = implode(".", $a);
  158. $content = file_get_contents($file);
  159. $content = str_replace("package project_name.uis.content", "package ".$packageName, $content);
  160. $content = str_replace("public class VideoUI", "public class ".$className, $content);
  161. $content = str_replace("public class FormUI", "public class ".$className, $content);
  162. $content = str_replace("public class PageUI", "public class ".$className, $content);
  163. $content = str_replace("project_name", array_shift($a), $content);
  164. file_put_contents($file, $content);
  165. }
  166. function copyr($source, $dest)
  167. {
  168. // Simple copy for a file
  169. if (is_file($source))
  170. {
  171. $c = copy($source, $dest);
  172. chmod($dest, 0777);
  173. // Check .xml and .as files
  174. $ext = strrchr($dest, ".");
  175. if ($c && ($ext == ".as" || $ext == ".xml" || $ext == ".as3proj")) parseFile($dest);
  176. return $c;
  177. }
  178. // Make destination directory
  179. if (!is_dir($dest))
  180. {
  181. $oldumask = umask(0);
  182. mkdir($dest, 0777);
  183. umask($oldumask);
  184. }
  185. // Loop through the folder
  186. $dir = dir($source);
  187. $scriptName = array_pop(explode("/", $_SERVER["SCRIPT_NAME"]));
  188. while (false !== $entry = $dir->read())
  189. {
  190. if ($entry == "." || $entry == "content" || $entry == ".." || stristr($entry, ".svn") || stristr($entry, "_svn") || $entry == $scriptName)
  191. {
  192. continue;
  193. }
  194. // Deep copy directories
  195. if ($dest !== $source."/".$entry)
  196. {
  197. copyr($source."/".$entry, $dest."/".$entry);
  198. }
  199. }
  200. // Clean up
  201. $dir->close();
  202. return true;
  203. }
  204. ?>
  205. <html>
  206. <head>
  207. <script language="javascript">
  208. function updatePackageName()
  209. {
  210. for (var i = 0; i < 10; i++)
  211. {
  212. document.getElementById("span_" + i).innerHTML = document.getElementById("destPackageName").value + ".";
  213. }
  214. }
  215. function updateUIList()
  216. {
  217. var list = [];
  218. for (var i = 0; i < 10; i++)
  219. {
  220. var uiId = document.getElementById("ui_id_" + i).value;
  221. if (uiId != "name_ui") list.push(uiId);
  222. }
  223. for (i = 0; i < 10; i++)
  224. {
  225. var innerHtml = "";
  226. for (j = 0; j < list.length; j++)
  227. {
  228. var cbId = "state_" + i + "_cb_" + j;
  229. innerHtml += '<input type="checkbox" name="state_' + i + '_cb[]" id="' + cbId + '" value="' + list[j] + '" /><label for="' + cbId + '">' + list[j] + '</label>';
  230. }
  231. document.getElementById("state_id_uis_" + i).innerHTML = innerHtml;
  232. }
  233. }
  234. </script>
  235. </head>
  236. <body onload="updatePackageName();updateUIList();">
  237. <?php
  238. if (!isset($_POST["go"]))
  239. {
  240. ?>
  241. <form action="" method="POST">
  242. New Project path: <input name="destFolderContainer" style="width:300px;" value="<?php echo str_replace('\\', '/', realpath('../')); ?>/client_YYYYMMDD_project">
  243. <br><br>
  244. Package name: <input id="destPackageName" name="destPackageName" value="clientproj" onkeyup="updatePackageName();">
  245. <br><br>
  246. UIs :
  247. <br>
  248. <?php
  249. for ($i = 0; $i < 10; $i++) {
  250. ?>
  251. <input id="ui_id_<?php echo $i;?>" name="ui_id_<?php echo $i;?>" value="name_ui" onkeyup="updateUIList();">
  252. <span id="span_<?php echo $i;?>">clientproj.</span><input name="ui_class_<?php echo $i;?>" value="uis.UI">
  253. <input type="checkbox" name="ui_<?php echo $i;?>_form_cb" id="ui_<?php echo $i;?>_form_cb" /><label for="ui_<?php echo $i;?>_form_cb"> contains form</label>
  254. <input type="checkbox" name="ui_<?php echo $i;?>_video_cb" id="ui_<?php echo $i;?>_video_cb" /><label for="ui_<?php echo $i;?>_video_cb"> contains video</label>
  255. <br/>
  256. <?php
  257. }
  258. ?>
  259. <br>
  260. States :
  261. <br>
  262. <?php
  263. for ($i = 0; $i < 10; $i++) {
  264. ?>
  265. <input name="state_id_<?php echo $i;?>" value="state">
  266. <span id="state_id_uis_<?php echo $i;?>"></span>
  267. <br/>
  268. <?php
  269. }
  270. ?>
  271. <br><br>
  272. <input type="hidden" name="go" value="ok">
  273. <input type="submit" value="Go go go !">
  274. </form>
  275. <?php
  276. }
  277. ?>
  278. </body>
  279. </html>