PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tools/clean-xheditor.php

http://lazycms.googlecode.com/
PHP | 275 lines | 238 code | 6 blank | 31 comment | 14 complexity | e47c68c41f4c55e7f7e6796a6c832fc1 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. // ??????
  3. define('ABS_PATH',dirname(__FILE__));
  4. // ???????
  5. $op_files = array(
  6. array('D','demos'),
  7. array('D','jquery'),
  8. array('D','serverscript'),
  9. array('D','xheditor_emot'),
  10. array('C','src/xheditor-zh-cn.src.js','xheditor.js','translate'),
  11. array('D','src'),
  12. array('M','LGPL-LICENSE.txt','LGPL-LICENSE'),
  13. array('D','*.txt'),
  14. array('D','*.html'),
  15. array('D','*.min.js'),
  16. array('D','xheditor_plugins'),
  17. array('A','plugins'),
  18. array('M','xheditor_skin','skins'),
  19. array('D','skins/default'),
  20. array('D','skins/o2007blue'),
  21. array('D','skins/o2007silver'),
  22. array('D','skins/vista'),
  23. array('M','skins/nostyle','skins/default','process_css'),
  24. );
  25. foreach ($op_files as $action) {
  26. switch($action[0]) {
  27. // ?????
  28. case 'A':
  29. @mkdirs(ABS_PATH.'/'.$action[1]);
  30. break;
  31. // ????
  32. case 'D':
  33. foreach((array)glob($action[1]) as $file) {
  34. $abs_path = ABS_PATH.'/'.$file;
  35. if (is_dir($abs_path)) {
  36. @rmdirs($abs_path);
  37. echo "Delete floder: {$file}\n";
  38. } elseif(is_file($abs_path)) {
  39. @unlink($abs_path);
  40. echo "Delete file: {$file}\n";
  41. }
  42. }
  43. break;
  44. // ????
  45. case 'M':
  46. if (count($action)>=3) {
  47. @rename(ABS_PATH.'/'.$action[1], ABS_PATH.'/'.$action[2]);
  48. echo "Changed path ".$action[1]." to ".$action[2]."\n";
  49. // ??????
  50. if (isset($action[3])) {
  51. call_user_func($action[3], $action[1], $action[2]);
  52. }
  53. }
  54. break;
  55. // ????
  56. case 'C':
  57. if (count($action)>=3) {
  58. @copy(ABS_PATH.'/'.$action[1], ABS_PATH.'/'.$action[2]);
  59. echo "Copyed path ".$action[1]." to ".$action[2]."\n";
  60. // ??????
  61. if (isset($action[3])) {
  62. call_user_func($action[3], $action[1], $action[2]);
  63. }
  64. }
  65. break;
  66. }
  67. }
  68. // ??CSS
  69. function process_css($source,$target) {
  70. if ($source=='skins/nostyle' && $target=='skins/default') {
  71. $content = file_get_contents(ABS_PATH.'/'.$target.'/ui.css');
  72. $content = str_replace('.xhe_nostyle', '.xhe_default', $content);
  73. file_put_contents(ABS_PATH.'/'.$target.'/ui.css', $content);
  74. }
  75. }
  76. // ??
  77. function translate($source,$target) {
  78. $translates = array(
  79. array("xheditor_skin/","skins/"),
  80. array("xheditor_emot/","emots/"),
  81. array("[\w-\:]","[\w\-\:]"),
  82. array("tool=arrEmbed[target.type.toLowerCase()];","var lazyType=$(target).attr('lazytype'); tool=lazyType ? lazyType : arrEmbed[target.type.toLowerCase()];"),
  83. array("t:'????'","t:_('Paragraph')"),
  84. array("t:'??1'","t:_('Heading 1')"),
  85. array("t:'??2'","t:_('Heading 2')"),
  86. array("t:'??3'","t:_('Heading 3')"),
  87. array("t:'??4'","t:_('Heading 4')"),
  88. array("t:'??5'","t:_('Heading 5')"),
  89. array("t:'??6'","t:_('Heading 6')"),
  90. array("t:'?????'","t:_('Preformatted')"),
  91. array("t:'??'","t:_('Address')"),
  92. array("t:'??'","t:_('xx-small')"),
  93. array("t:'??'","t:_('x-small')"),
  94. array("t:'?'","t:_('small')"),
  95. array("t:'?'","t:_('medium')"),
  96. array("t:'?'","t:_('large')"),
  97. array("t:'??'","t:_('x-large')"),
  98. array("t:'??'","t:_('xx-large')"),
  99. array("{n:'??',c:'SimSun'},{n:'???',c:'FangSong_GB2312'},{n:'??',c:'SimHei'},{n:'??',c:'KaiTi_GB2312'},{n:'????',c:'Microsoft YaHei'},{n:'Arial'},","{n:'Arial'},"),
  100. array("s:'???'","s:_('Align left')"),
  101. array("s:'??'","s:_('Align center')"),
  102. array("s:'???'","s:_('Align right')"),
  103. array("s:'????'","s:_('Align full')"),
  104. array("s:'????'","s:_('Ordered list')"),
  105. array("s:'????'","s:_('Unordered list')"),
  106. array("???????(Ctrl+V)??????????? ??","' + _('Use Ctrl+V on your keyboard to paste the text.') + '"),
  107. array("value=\"??\"","value=\"' + _('Ok') + '\""),
  108. array("????:","' + _('Link URL:') + '"),
  109. array("????:","' + _('Target:&nbsp;&nbsp;') + '"),
  110. array("????:","' + _('Link Text:') + '"),
  111. array("????:","' + _('Img URL:&nbsp;') + '"),
  112. array("????:","' + _('Alt text:') + '"),
  113. array("????:","' + _('Alignment:') + '"),
  114. array("????:","' + _('Dimension:') + '"),
  115. array("????:","' + _('Border:&nbsp;&nbsp;&nbsp;') + '"),
  116. array("????:","' + _('Hspace:&nbsp;&nbsp;&nbsp;') + '"),
  117. array("????:","' + _('Vspace:') + '"),
  118. array("????:","' + _('Flash URL:') + '"),
  119. array("????:","' + _('Media URL:') + '"),
  120. array("????:","' + _('Rows&Cols:&nbsp;&nbsp;') + '"),
  121. array("????:","' + _('Headers:&nbsp;&nbsp;&nbsp;&nbsp;') + '"),
  122. array("????:","' + _('CellSpacing:') + '"),
  123. array("????:","' + _('CellPadding:') + '"),
  124. array("????:","' + _('Caption:&nbsp;&nbsp;&nbsp;&nbsp;') + '"),
  125. array("????: <input type=\"text\" id=\"xheTableBorder\"","' + _('Border:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;') + ' <input type=\"text\" id=\"xheTableBorder\""),
  126. array("<option selected=\"selected\" value=\"\">??</option>","<option selected=\"selected\" value=\"\">' + _('Default') +'</option>"),
  127. array("<option value=\"_blank\">???</option>","<option value=\"_blank\">' + _('New window') + '</option>"),
  128. array("<option value=\"_self\">????</option>","<option value=\"_self\">' + _('Same window') + '</option>"),
  129. array("<option value=\"_parent\">???</option>","<option value=\"_parent\">' + _('Parent window') + '</option>"),
  130. array("<option value=\"left\">???</option>","<option value=\"left\">' + _('Left') + '</option>"),
  131. array("<option value=\"right\">???</option>","<option value=\"right\">' + _('Right') + '</option>"),
  132. array("<option value=\"top\">??</option>","<option value=\"top\">' + _('Top') + '</option>"),
  133. array("<option value=\"middle\">??</option>","<option value=\"middle\">' + _('Middle') + '</option>"),
  134. array("<option value=\"center\">??</option>","<option value=\"center\">' + _('Center') + '</option>"),
  135. array("<option value=\"baseline\">??</option>","<option value=\"baseline\">' + _('Baseline') + '</option>"),
  136. array("<option value=\"bottom\">??</option>","<option value=\"bottom\">' + _('Bottom') + '</option>"),
  137. array("<option selected=\"selected\" value=\"\">?</option>","<option selected=\"selected\" value=\"\">' + _('None') + '</option>"),
  138. array("<option value=\"row\">???</option>","<option value=\"row\">' + _('First row') + '</option>"),
  139. array("<option value=\"col\">???</option>","<option value=\"col\">' + _('First column') + '</option>"),
  140. array("<option value=\"both\">???????</option>","<option value=\"both\">' + _('Both') + '</option>"),
  141. array("xhEditor???jQuery????????XHTML??????<a href=\"http://www.gnu.org/licenses/lgpl.html\" target=\"_blank\">LGPL</a>???????","' + _('xhEditor is a platform independent WYSWYG XHTML editor based by jQuery,released as Open Source under <a href=\"http://www.gnu.org/licenses/lgpl.html\" target=\"_blank\">LGPL</a>.') + '"),
  142. array("name:'??'","name:_('Default')"),
  143. array("'smile':'??'","'smile':_('Smile')"),
  144. array("'tongue':'???'","'tongue':_('Tongue')"),
  145. array("'titter':'??'","'titter':_('Titter')"),
  146. array("'laugh':'??'","'laugh':_('Laugh')"),
  147. array("'sad':'??'","'sad':_('Sad')"),
  148. array("'wronged':'??'","'wronged':_('Wronged')"),
  149. array("'fastcry':'???'","'fastcry':_('Fast cry')"),
  150. array("'cry':'?'","'cry':_('Cry')"),
  151. array("'wail':'??'","'wail':_('Wail')"),
  152. array("'mad':'??'","'mad':_('Mad')"),
  153. array("'knock':'??'","'knock':_('Knock')"),
  154. array("'curse':'??'","'curse':_('Curse')"),
  155. array("'crazy':'??'","'crazy':_('Crazy')"),
  156. array("'angry':'??'","'angry':_('Angry')"),
  157. array("'ohmy':'??'","'ohmy':_('Oh my')"),
  158. array("'awkward':'??'","'awkward':_('Awkward')"),
  159. array("'panic':'??'","'panic':_('Panic')"),
  160. array("'shy':'??'","'shy':_('Shy')"),
  161. array("'cute':'??'","'cute':_('Cute')"),
  162. array("'envy':'??'","'envy':_('Envy')"),
  163. array("'proud':'??'","'proud':_('Proud')"),
  164. array("'struggle':'??'","'struggle':_('Struggle')"),
  165. array("'quiet':'??'","'quiet':_('Quiet')"),
  166. array("'shutup':'??'","'shutup':_('Shut up')"),
  167. array("'doubt':'??'","'doubt':_('Doubt')"),
  168. array("'despise':'??'","'despise':_('Despise')"),
  169. array("'sleep':'??'","'sleep':_('Sleep')"),
  170. array("'bye':'??'","'bye':_('Bye')"),
  171. array("t:'?? (Ctrl+X)'","t:_('Cut (Ctrl+X)')"),
  172. array("t:'?? (Ctrl+C)'","t:_('Copy (Ctrl+C)')"),
  173. array("t:'?? (Ctrl+V)'","t:_('Paste (Ctrl+V)')"),
  174. array("t:'????'","t:_('Paste as plain text')"),
  175. array("t:'????'","t:_('Block tag')"),
  176. array("t:'??'","t:_('Font family')"),
  177. array("t:'????'","t:_('Font size')"),
  178. array("t:'?? (Ctrl+B)'","t:_('Bold (Ctrl+B)')"),
  179. array("t:'?? (Ctrl+I)'","t:_('Italic (Ctrl+I)')"),
  180. array("t:'??? (Ctrl+U)'","t:_('Underline (Ctrl+U)')"),
  181. array("t:'??? (Ctrl+S)'","t:_('Strikethrough (Ctrl+S)')"),
  182. array("t:'????'","t:_('Select text color')"),
  183. array("t:'????'","t:_('Select background color')"),
  184. array("t:'?? (Ctrl+A)'","t:_('SelectAll (Ctrl+A)')"),
  185. array("t:'??????'","t:_('Remove formatting')"),
  186. array("t:'??'","t:_('Align')"),
  187. array("t:'??'","t:_('List')"),
  188. array("t:'???? (Shift+Tab)'","t:_('Outdent (Shift+Tab)')"),
  189. array("t:'???? (Tab)'","t:_('Indent (Tab)')"),
  190. array("t:'??? (Ctrl+K)'","t:_('Insert/edit link (Ctrl+K)')"),
  191. array("t:'?????'","t:_('Unlink')"),
  192. array("t:'??'","t:_('Insert/edit image')"),
  193. array("t:'Flash??'","t:_('Insert/edit flash')"),
  194. array("t:'?????'","t:_('Insert/edit media')"),
  195. array("t:'??'","t:_('Emotions')"),
  196. array("t:'??'","t:_('Insert a new table')"),
  197. array("t:'???'","t:_('Edit source code')"),
  198. array("t:'??'","t:_('Preview')"),
  199. array("t:'?? (Ctrl+P)'","t:_('Print (Ctrl+P)')"),
  200. array("t:'???? (Esc)'","t:_('Toggle fullscreen (Esc)')"),
  201. array("t:'?? xhEditor'","t:_('About xhEditor')"),
  202. array("defLinkText:'??????'","defLinkText:_('Click to open link')"),
  203. array("'??textarea?????????????????xhEditor???????textarea?width?height??'","_('Current textarea is hidden, please make it show before initialization xhEditor, or directly initialize the height.')"),
  204. array("'????????????'","_('Upload file extension required for this: ')"),
  205. array("'??????????????'","_('You can only drag and drop the same type of file.')"),
  206. array("<title>??</title>","<title>' + _('Preview') + '</title>"),
  207. array("?????????……","' + _('File uploading,please wait...') + '"),
  208. array("'?????????'+upMultiple+'???'","_('Please do not upload more then \{\$upMultiple\} files.').replace('\{\$upMultiple\}', upMultiple)"),
  209. array("'?????(Esc????)'","_('File uploading(Esc cancel)')"),
  210. array("' ?????????","_(' upload interface error!') + '"),
  211. array("????????:","' + _('return error:') + '"),
  212. array("title=\"?? (Esc)\"","title=\"' + _('Close (Esc)') + '\""),
  213. array("value=\"??\"","value=\"' + _('Cancel') + '\""),
  214. array("'???????????????????????????(Ctrl + X)???'","_('Currently not supported by your browser, use keyboard shortcuts(Ctrl+X) instead.')"),
  215. array("'???????????????????????????(Ctrl + C)???'","_('Currently not supported by your browser, use keyboard shortcuts(Ctrl+C) instead.')"),
  216. array("'???????????????????????????(Ctrl + V)???'","_('Currently not supported by your browser, use keyboard shortcuts(Ctrl+V) instead.')"),
  217. array("'??????????: '","_('Upload file extension required for this: ')"),
  218. array("'??'","_('Upload')"),
  219. array("'????'","_('Upload file')"),
  220. array("arrCmd=['Link','Img','Flash','Media']","arrCmd=['Link','Img','Flash','Media','Video']"),
  221. array("sText=url[1]?url[1]:","sText=url[1]?url[1].replace(/%20/g,' '):"),
  222. array("sLink=sLink.replace('xhe_tmptext',url[1]?url[1]:","sLink=sLink.replace('xhe_tmptext',url[1]?url[1].replace(/%20/g,' '):"),
  223. /*array("_this.showIframeModal(_('Upload file'),toUrl.substr(1),setUploadMsg,null,null,function(){bShowPanel=true;});","var wh,w=null,h=null,i,s = toUrl.substr(1);
  224. if ((i=s.indexOf('||')) != -1) {
  225. wh = s.substr(0,i);
  226. s = s.substr(i+2);
  227. w = wh.substr(0, wh.indexOf('x'));
  228. h = wh.substr(wh.indexOf('x')+1);
  229. }
  230. _this.showIframeModal(_('Upload file'),s,setUploadMsg,w,h,function(){bShowPanel=true;});"),*/
  231. );
  232. $content = file_get_contents(ABS_PATH.'/'.$source);
  233. foreach($translates as $t) {
  234. $content = str_replace($t[0],$t[1],$content);
  235. }
  236. file_put_contents(ABS_PATH.'/'.$target, $content);
  237. }
  238. /**
  239. * ?????
  240. *
  241. * @param string $path ?????????
  242. * @return bool
  243. */
  244. function rmdirs($path){
  245. if ($dh=@opendir($path)) {
  246. while (false !== ($file=readdir($dh))) {
  247. if ($file != "." && $file != "..") {
  248. $file_path = $path.'/'.$file;
  249. is_dir($file_path) ? rmdirs($file_path) : @unlink($file_path);
  250. }
  251. }
  252. closedir($dh);
  253. }
  254. return @rmdir($path);
  255. }
  256. /**
  257. * ??????
  258. *
  259. * @param string $path ?????
  260. * @param int $mode ??
  261. * @return bool
  262. */
  263. function mkdirs($path, $mode = 0777){
  264. if (!is_dir($path)) {
  265. mkdirs(dirname($path), $mode);
  266. return mkdir($path, $mode);
  267. }
  268. return true;
  269. }