/source/unused/html/index.php
PHP | 190 lines | 176 code | 6 blank | 8 comment | 11 complexity | b1bc646373d199b9c8e084987b58d0ea MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- include_once('define.php');
- include_once('filter.class.php');
- $filter = new filter();
- /*
- * cache file action.
- */
- if(isset($_POST['d'])) {
- $file = "{$view_dir}{$_POST['d']}";
- $newfile = $cache_html_dir . str_replace("/", "-", $file);
- if(!rename($file, $newfile)) {
- echo json_encode(array('rep' => 'error'));
- } else {
- if(is_file("{$file}.ini"))
- rename("{$file}.ini", "{$newfile}.ini");
- echo json_encode(array('rep' => 'ok'));
- }
- exit;
- }
- /*
- * restore cache action.
- */
- if(isset($_POST['r'])) {
- $file = "{$cache_html_dir}{$_POST['r']}";
- $newfile = str_replace("-", "/", $_POST['r']);
- if(!rename($file, $newfile)) {
- echo json_encode(array('rep' => 'error'));
- } else {
- if(is_file("{$file}.ini"))
- rename("{$file}.ini", "{$newfile}.ini");
- echo json_encode(array('rep' => 'ok'));
- }
- exit;
- }
- // files on disk
- $files = $filter->dirfiles($view_dir, array('.svn'), array('html'));
- // files on use
- $usefiles = $filter->dirfiles(
- "{$root}",
- array('.svn', 'config', 'files', 'language', 'logs', 'templates_pub'),
- array('html', 'php')
- );
- $contains = Array();
- foreach($usefiles as $key => $file) {
- $info = pathinfo($file);
- $content = file_get_contents($file);
- $out = Array();
- if($info['extension'] == 'php') {
- preg_match_all("@\->(display|fetch)\(('|\")(.*)('|\")\)@U", $content, $outs);
- if(count($outs[3]) > 0) {
- $out = $outs[3];
- }
- }
- if($info['extension'] == 'html') {
- preg_match_all("@file=('|\")(.*)('|\")@U", $content, $outs);
- if(count($outs[2]) > 0) {
- $out = $outs[2];
- }
- }
- if(count($out) > 0)
- foreach($out as $i => $html) {
- $contains[$html][] = $file;
- if(preg_match('@\$@U', 'master/widget_welcome_".$language_code.".html', $out)) {
- preg_match('@((\'|")(.*)(\'|"))@U', $html, $output);
- if(count($output) == 0) {
- $out = $html;
- } else {
- $out = str_replace('.', '', $output[3]);
- }
- $out = str_replace('$', '', $out);
- if(isset($defines[$out])) {
- foreach($defines[$out] as $defineFile) {
- if(count($output) > 0)
- $defineFile = str_replace($output[0], $defineFile, $html);
- $contains[$defineFile][] = $file;
- }
- }
- }
- }
- }
- // cache file
- $cacheFiles = $filter->files($cache_html_dir, array('html'));
- ?>
- <html>
- <head>
- <title>html unused</title>
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- $('.true').click(function(){
- var panel = $(this).next();
- if(panel.is(':hidden')) {
- panel.show();
- } else {
- panel.hide();
- }
- return false;
- });
- $('.delete').click(function(){
- var self = $(this);
- $.post(window.location.href, { d: self.attr('href') }, function(data){
- if(data.rep == 'ok') {
- window.location.reload();
- } else {
- alert("Error!");
- }
- }, 'json');
- return false;
- });
- $('.restore').click(function(){
- var self = $(this);
- $.post(window.location.href, { r: self.attr('href') }, function(data){
- if(data.rep == 'ok') {
- window.location.reload();
- } else {
- alert("Error!");
- }
- }, 'json');
- return false;
- });
- });
- </script>
- <style type="text/css">
- .result {
- background-color:#f1f1f1;
- border:1px solid #ccc;
- padding:5px;
- margin:0px;
- margin-bottom:10px;
- color:#333
- }
- .files {
- }
- .filesuse {
- color:#060
- }
- .true {
- color:#060;cursor:pointer;font-weight:bold
- }
- .restore,
- .delete {
- color:#f00;font-weight:bold
- }
- </style>
- </head>
- <body>
- <?php
- if(count($cacheFiles) > 0) {
- ?>
- <h1>Files delete</h1>
- <pre class="result">
- <?php
- foreach($cacheFiles as $key => $file) {
- $newfile = str_replace('-', '/', $file);
- $seefile = str_replace($view_dir, '', $newfile);
- echo "<div class=\"files\">{$seefile} <a href=\"{$file}\" class=\"restore\">Restore</a></div>";
- }
- ?>
- </pre>
- <?php
- }
- ?>
- <h1>Html unused</h1>
- <pre class="result">
- <?php
- foreach($files as $key => $file) {
- $act = '';
- $file = str_replace($view_dir, "", $file);
- if(isset($contains[$file])) {
- $act .= '<a href="#" class="true">is use</a><div class="filesuse">';
- foreach($contains[$file] as $i => $fileuse){
- $act .= "\t{$fileuse}\n";
- }
- $act .= '</div>';
- } else {
- $act = "<a href=\"{$file}\" class=\"delete\">delete</a>";
- }
- echo "<div class=\"files\">{$file} {$act}</div>";
- }
- ?>
- </pre>
- </body>
- </html>