PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/source/unused/html/index.php

http://sharebooks.googlecode.com/
PHP | 190 lines | 176 code | 6 blank | 8 comment | 11 complexity | b1bc646373d199b9c8e084987b58d0ea MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. include_once('define.php');
  3. include_once('filter.class.php');
  4. $filter = new filter();
  5. /*
  6. * cache file action.
  7. */
  8. if(isset($_POST['d'])) {
  9. $file = "{$view_dir}{$_POST['d']}";
  10. $newfile = $cache_html_dir . str_replace("/", "-", $file);
  11. if(!rename($file, $newfile)) {
  12. echo json_encode(array('rep' => 'error'));
  13. } else {
  14. if(is_file("{$file}.ini"))
  15. rename("{$file}.ini", "{$newfile}.ini");
  16. echo json_encode(array('rep' => 'ok'));
  17. }
  18. exit;
  19. }
  20. /*
  21. * restore cache action.
  22. */
  23. if(isset($_POST['r'])) {
  24. $file = "{$cache_html_dir}{$_POST['r']}";
  25. $newfile = str_replace("-", "/", $_POST['r']);
  26. if(!rename($file, $newfile)) {
  27. echo json_encode(array('rep' => 'error'));
  28. } else {
  29. if(is_file("{$file}.ini"))
  30. rename("{$file}.ini", "{$newfile}.ini");
  31. echo json_encode(array('rep' => 'ok'));
  32. }
  33. exit;
  34. }
  35. // files on disk
  36. $files = $filter->dirfiles($view_dir, array('.svn'), array('html'));
  37. // files on use
  38. $usefiles = $filter->dirfiles(
  39. "{$root}",
  40. array('.svn', 'config', 'files', 'language', 'logs', 'templates_pub'),
  41. array('html', 'php')
  42. );
  43. $contains = Array();
  44. foreach($usefiles as $key => $file) {
  45. $info = pathinfo($file);
  46. $content = file_get_contents($file);
  47. $out = Array();
  48. if($info['extension'] == 'php') {
  49. preg_match_all("@\->(display|fetch)\(('|\")(.*)('|\")\)@U", $content, $outs);
  50. if(count($outs[3]) > 0) {
  51. $out = $outs[3];
  52. }
  53. }
  54. if($info['extension'] == 'html') {
  55. preg_match_all("@file=('|\")(.*)('|\")@U", $content, $outs);
  56. if(count($outs[2]) > 0) {
  57. $out = $outs[2];
  58. }
  59. }
  60. if(count($out) > 0)
  61. foreach($out as $i => $html) {
  62. $contains[$html][] = $file;
  63. if(preg_match('@\$@U', 'master/widget_welcome_".$language_code.".html', $out)) {
  64. preg_match('@((\'|")(.*)(\'|"))@U', $html, $output);
  65. if(count($output) == 0) {
  66. $out = $html;
  67. } else {
  68. $out = str_replace('.', '', $output[3]);
  69. }
  70. $out = str_replace('$', '', $out);
  71. if(isset($defines[$out])) {
  72. foreach($defines[$out] as $defineFile) {
  73. if(count($output) > 0)
  74. $defineFile = str_replace($output[0], $defineFile, $html);
  75. $contains[$defineFile][] = $file;
  76. }
  77. }
  78. }
  79. }
  80. }
  81. // cache file
  82. $cacheFiles = $filter->files($cache_html_dir, array('html'));
  83. ?>
  84. <html>
  85. <head>
  86. <title>html unused</title>
  87. <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
  88. <script type="text/javascript">
  89. $(document).ready(function(){
  90. $('.true').click(function(){
  91. var panel = $(this).next();
  92. if(panel.is(':hidden')) {
  93. panel.show();
  94. } else {
  95. panel.hide();
  96. }
  97. return false;
  98. });
  99. $('.delete').click(function(){
  100. var self = $(this);
  101. $.post(window.location.href, { d: self.attr('href') }, function(data){
  102. if(data.rep == 'ok') {
  103. window.location.reload();
  104. } else {
  105. alert("Error!");
  106. }
  107. }, 'json');
  108. return false;
  109. });
  110. $('.restore').click(function(){
  111. var self = $(this);
  112. $.post(window.location.href, { r: self.attr('href') }, function(data){
  113. if(data.rep == 'ok') {
  114. window.location.reload();
  115. } else {
  116. alert("Error!");
  117. }
  118. }, 'json');
  119. return false;
  120. });
  121. });
  122. </script>
  123. <style type="text/css">
  124. .result {
  125. background-color:#f1f1f1;
  126. border:1px solid #ccc;
  127. padding:5px;
  128. margin:0px;
  129. margin-bottom:10px;
  130. color:#333
  131. }
  132. .files {
  133. }
  134. .filesuse {
  135. color:#060
  136. }
  137. .true {
  138. color:#060;cursor:pointer;font-weight:bold
  139. }
  140. .restore,
  141. .delete {
  142. color:#f00;font-weight:bold
  143. }
  144. </style>
  145. </head>
  146. <body>
  147. <?php
  148. if(count($cacheFiles) > 0) {
  149. ?>
  150. <h1>Files delete</h1>
  151. <pre class="result">
  152. <?php
  153. foreach($cacheFiles as $key => $file) {
  154. $newfile = str_replace('-', '/', $file);
  155. $seefile = str_replace($view_dir, '', $newfile);
  156. echo "<div class=\"files\">{$seefile} <a href=\"{$file}\" class=\"restore\">Restore</a></div>";
  157. }
  158. ?>
  159. </pre>
  160. <?php
  161. }
  162. ?>
  163. <h1>Html unused</h1>
  164. <pre class="result">
  165. <?php
  166. foreach($files as $key => $file) {
  167. $act = '';
  168. $file = str_replace($view_dir, "", $file);
  169. if(isset($contains[$file])) {
  170. $act .= '<a href="#" class="true">is use</a><div class="filesuse">';
  171. foreach($contains[$file] as $i => $fileuse){
  172. $act .= "\t{$fileuse}\n";
  173. }
  174. $act .= '</div>';
  175. } else {
  176. $act = "<a href=\"{$file}\" class=\"delete\">delete</a>";
  177. }
  178. echo "<div class=\"files\">{$file} {$act}</div>";
  179. }
  180. ?>
  181. </pre>
  182. </body>
  183. </html>