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

/admin_goeventreg/archive.php

https://gitlab.com/endomorphosis/go_event_reg
PHP | 193 lines | 182 code | 7 blank | 4 comment | 2 complexity | b4b97c3fe615446a32f935afa564d957 MD5 | raw file
  1. <?php
  2. // copies files to archive directory. Appends file date and replaces folders delimiters with @ signs
  3. //================ Needed Definitions ===================
  4. // configure this section
  5. $TITLE = 'Website';
  6. $FOLDER_TO_ARCHIVE = dirname(__FILE__);
  7. $ARCHIVE_FOLDER = $FOLDER_TO_ARCHIVE . '/archive';
  8. $EXCLUDE_LIST = 'Desktop.ini,Thumbs,logs,tmp'; // already will exclude the archive folder
  9. $IMAGELIST = array('.gif','.jpg','.png');
  10. //======================================================
  11. $ROOT = $_SERVER['DOCUMENT_ROOT'];
  12. $REQUEST_URI = strTo($_SERVER['REQUEST_URI'],'?');
  13. function Post($name) {return (isset($_POST[$name]))? $_POST[$name] : '';}
  14. function Get($name) {return (isset($_GET[$name]))? $_GET[$name] : '';}
  15. function strTo($string, $to) {
  16. $i = strpos($string,$to);
  17. if ( $i !== false ) return substr($string,0,$i);
  18. else return $string;
  19. }
  20. function StripRoot($str)
  21. {
  22. global $ROOT;
  23. $str = str_replace('\\', '/', $str); // needed for Windows
  24. $str = str_replace($ROOT,'',$str);
  25. return $str;
  26. }
  27. //---------CHECK IF ARRAY ITEMS IN STRING----------
  28. function ArrayItemsWithinStr($myarray,$str)
  29. {
  30. $arraycount = count($myarray);
  31. if (empty($str) or ($arraycount==0)) return false;
  32. for($i=0; $i<$arraycount; $i++) {
  33. if (stristr($str,$myarray[$i]) != '') return true;
  34. }
  35. return false;
  36. }
  37. function GetDirectory() {
  38. //gets a directory and subdirectory filelist with optional include and exclude string
  39. //$url,$includestr,$excludestr
  40. $numargs = func_num_args();
  41. $url = func_get_arg(0);
  42. $includestr = ($numargs>1)? func_get_arg(1) : '';
  43. $excludestr = ($numargs>2)? func_get_arg(2) : '';
  44. $files = array();
  45. if (!file_exists($url)) return $files;
  46. if (!empty($includestr)) $include_strings = explode(',',$includestr);
  47. if (!empty($excludestr)) $exclude_strings = explode(',',$excludestr);
  48. $dir = opendir("$url/");
  49. while (false !== ($file = readdir($dir))) {
  50. if ($file != '.' && $file != '..') {
  51. if (is_dir("$url/$file")) {
  52. $echeck = (!empty($excludestr))? !ArrayItemsWithinStr($exclude_strings,"$url/$file") : true;
  53. if ($echeck and !eregi('.svn',$file)) {
  54. $sfiles = GetDirectory("$url/$file",$includestr,$excludestr);
  55. foreach ($sfiles as $f) $files[] = "$file/$f";
  56. }
  57. } else {
  58. $icheck = (!empty($includestr))? ArrayItemsWithinStr($include_strings,$file) : true;
  59. $echeck = (!empty($excludestr))? !ArrayItemsWithinStr($exclude_strings,$file) : true;
  60. if ($icheck and $echeck) $files[] = $file;
  61. }
  62. }
  63. }
  64. closedir($dir);
  65. natcasesort($files);
  66. $files = array_values($files);
  67. return $files;
  68. }
  69. $ARCHIVE = Post('ARCHIVE');
  70. $VIEW = Post('VIEW');
  71. $LISTARCHIVE = Post('LISTARCHIVE');
  72. $viewfile = Get('viewfile');
  73. $INCLUDE = Post('INCLUDE');
  74. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  75. <html xmlns="http://www.w3.org/1999/xhtml">
  76. <head>
  77. <title>Archive &mdash; <?php echo $TITLE; ?></title>
  78. <style type="text/css">
  79. body{background-color:#eee;}
  80. #content{margin:1em auto; background-color:#fff; padding:1em; border:1px dashed #888;}
  81. h1{color:#036; border-bottom:2px solid #036; margin-top:0px;}
  82. h2{background-color:#eee; border-bottom:1px solid #888;}
  83. #submitbuttons {float:right; text-align:right;}
  84. #info {float:right; white-space:nowrap; font-size:0.7em; padding:0px 0px 2em 4em;}
  85. img {border: 1px solid #000;}
  86. </style>
  87. <script type="text/javascript" src="../std_gtmm/lib/core.js"></script>
  88. </head>
  89. <body>
  90. <div id="content">
  91. <form method="post" action="<?php echo $REQUEST_URI; ?>">
  92. <div id="info">
  93. <?php
  94. $info = "<b>FROM:</b> $FOLDER_TO_ARCHIVE<br /><b>TO:</b> $ARCHIVE_FOLDER";
  95. echo StripRoot($info);
  96. ?>
  97. </div>
  98. <div id="submitbuttons">
  99. <input type="submit" value="View Files to Archive" name="VIEW" />&nbsp;&nbsp;
  100. <input type="submit" value="Archive" name="ARCHIVE" />&nbsp;&nbsp;
  101. <input type="submit" value="List Archive" name="LISTARCHIVE" />
  102. <input type="text" value="<?php echo $INCLUDE; ?>" name="INCLUDE" />
  103. </div>
  104. <h1>Archive &mdash; <?php echo $TITLE; ?></h1>
  105. <?php
  106. if ($viewfile) {
  107. echo "<h2>FILE: $viewfile</h2>";
  108. if(ArrayItemsWithinStr($IMAGELIST,$viewfile)) {
  109. $link = StripRoot("$ARCHIVE_FOLDER/$viewfile");
  110. echo "<img src=\"$link\" alt=\"IMAGE: $link\" />";
  111. } else {
  112. $content = htmlentities(file_get_contents("$ARCHIVE_FOLDER/$viewfile"));
  113. echo "<textarea rows=\"25\" style=\"width:100%\">$content</textarea>";
  114. }
  115. }
  116. if ($LISTARCHIVE) {
  117. echo '<h2>Archive List. . .</h2>';
  118. $ArchiveFiles = GetDirectory($ARCHIVE_FOLDER,$INCLUDE);
  119. echo '<ol>';
  120. foreach ($ArchiveFiles as $file) {
  121. $link = urlencode($file);
  122. echo "<li><a href=\"$REQUEST_URI?viewfile=$link\">$file</a></li>\n";
  123. }
  124. echo '</ol>';
  125. }
  126. if ($ARCHIVE or $VIEW) {
  127. define('CONTENT_DIR',$FOLDER_TO_ARCHIVE);
  128. $exclude_archive = basename($ARCHIVE_FOLDER);
  129. if($ARCHIVE) echo '<h2>Archiving Files. . .</h2>';
  130. else echo '<h2>Viewing Files to Archive. . .</h2>';
  131. //----------ARCHIVE ALL FILES (/content and /common)-------------
  132. $ContentFiles = GetDirectory(CONTENT_DIR,'',"/$exclude_archive,$EXCLUDE_LIST");
  133. $count = 0;
  134. echo '<ol style="text-align:left; font-size:1.2em;">';
  135. //------------ARCHIVE CONTENT FILES--------------
  136. foreach ($ContentFiles as $AF) {
  137. $filename = CONTENT_DIR."/$AF";
  138. $filedate = date("Ymdhi",filemtime($filename));
  139. $AF = str_replace('/','@',$AF);
  140. if (ArrayItemsWithinStr($IMAGELIST,$filename)) {
  141. $ext = substr($filename,-4);
  142. } else $ext = '.php';
  143. $filename2 = "$ARCHIVE_FOLDER/{$AF}_$filedate$ext";
  144. if (!file_exists($filename2)) {
  145. if($ARCHIVE) {
  146. copy($filename,$filename2);
  147. $out ="<li>$filename --> $ARCHIVE_FOLDER/{$AF}_$filedate$ext</li>\n";
  148. } else {
  149. $out ="<li>$filename</li>\n";
  150. }
  151. echo StripRoot($out);
  152. $count++;
  153. }
  154. }
  155. if ($count==0) {
  156. echo '<li>All files Archived!</li>';
  157. }
  158. echo '</ol>';
  159. }
  160. ?>
  161. </form>
  162. </div>
  163. </body>
  164. </html>