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

/vj-admin/file-edit.php

http://vanilla-journal.googlecode.com/
PHP | 233 lines | 227 code | 6 blank | 0 comment | 16 complexity | 78ccd8a852bf09a7ab7f5376b4b2057e MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0
  1. <?php
  2. include("admin.php");
  3. if (!function_exists('mime_content_type')) {
  4. function mime_content_type ($f) {
  5. $str = exec(trim('file -bi '.escapeshellarg($f))) ;
  6. $array = explode(";", $str);
  7. $str = $array[0];
  8. return $str;
  9. }
  10. }
  11. if (!function_exists('file_put_contents')) {
  12. define('FILE_APPEND', 1);
  13. function file_put_contents($n, $d, $flag = false) {
  14. $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
  15. $f = @fopen($n, $mode);
  16. if ($f == false) {
  17. return 0;
  18. } else {
  19. if (is_array($d)) $d = implode($d);
  20. $bytes_written = fwrite($f, $d);
  21. fclose($f);
  22. return $bytes_written;
  23. }
  24. }
  25. }
  26. function change_theme($theme = "") {
  27. global $vj;
  28. global $msg;
  29. if(!$_POST['theme']) return;
  30. update_key("theme", $_POST['theme']);
  31. $vj->query_info();
  32. $msg = "?????????? <strong>".$_POST['theme']."</strong> ??";
  33. }
  34. if($_POST['submit'] && $_POST['action'] == "theme") {
  35. change_theme($_POST['theme']);
  36. }
  37. admin_header("??????");
  38. ?>
  39. <?php
  40. if($_POST['submit'] && $_POST['action'] == "edit") {
  41. $page = $_POST['page'];
  42. $content = $_POST['content'];
  43. $filename = $config['theme_path'].$page;
  44. @copy($filename, $filename.".bak");
  45. $content = str_replace('\"', '"', $content);
  46. $content = str_replace("\'", "'", $content);
  47. @file_put_contents($filename, $content);
  48. echo "<h2>?????</h2>";
  49. echo "<p>???????????????</p>";
  50. if(file_exists($filename.".bak")) {
  51. echo "<p>?????????????????<a href=\"file-edit.php?page=".$page.".bak\">??????????</a>?????????</p>";
  52. }
  53. } else if($_GET['page']){
  54. $page = $_GET['page'];
  55. $filename = $config['theme_path'].$page;
  56. $content = @file_get_contents($filename);
  57. $contenttype = mime_content_type($filename);
  58. if(!file_exists($filename)) {
  59. echo "<h2>??????</h2>";
  60. echo "<p>???????????</p>";
  61. } else if(!strstr($contenttype, "text")) {
  62. echo "<h2>???????</h2>";
  63. echo "<p>?????????????????????</p>";
  64. } else {
  65. ?>
  66. <h2>????????</h2>
  67. <form action="file-edit.php" method="post">
  68. <p><strong>????</strong>? <?php echo $page ?> ?<strong>????</strong>?<?php echo mime_content_type($filename) ?></p>
  69. <input type="hidden" value="<?php echo $page; ?>" name="page" id="page" />
  70. <textarea id="content" name="content" style="padding: 5px; width: 90%; height: 300px; font-size: 12pt; font-family: mono-space;"><?php echo $content; ?></textarea> <br />
  71. <?php
  72. if(is_dir($filename)) {
  73. echo "<p>????????????????????</p>";
  74. } else if (!is_writable($filename)) {
  75. echo "<p>??????????????????????</p>";
  76. echo "<p>??????????????? Linux ??????????????? <code>chmod 666 ".$page."</code>?</p>";
  77. } else {
  78. ?>
  79. <input type="submit" id="submit" name="submit" value="?????"/>
  80. <input type="hidden" name="action" value="edit"/>
  81. </form>
  82. <? }
  83. }
  84. } else {
  85. ?>
  86. <h2>??????</h2>
  87. <div id="filetool" class="tool">
  88. ????
  89. <a href="#theme" onclick="return vj.file.show_area('file_theme');">??????</a> |
  90. <a href="#edit" onclick="return vj.file.show_area('file_edit');">????????</a>
  91. </div>
  92. <div id="file_theme" class="wrap">
  93. <?php if($msg) {
  94. echo '<div id="msg">'.$msg.'</div>';
  95. }?>
  96. <a name="theme"></a>
  97. <h3>??????</h3>
  98. <p>??????????????????????????????????</p>
  99. <p>??????????????????</p>
  100. <?php
  101. function parse_about($file="") {
  102. $about = array();
  103. $content = file_get_contents($file);
  104. if(!$content) return $about;
  105. preg_match("/<name>(.+?)<\/name>/", $content, $match);
  106. $about['name'] = $match[1];
  107. preg_match("/<author>(.+?)<\/author/", $content, $match);
  108. $about['author'] = $match[1];
  109. preg_match("/<description>(.+?)<\/description>/", $content, $match);
  110. $about['description'] = $match[1];
  111. preg_match("/<url>(.+?)<\/url>/", $content, $match);
  112. $about['url'] = $match[1];
  113. return $about;
  114. }
  115. function parse_xml($file="") {
  116. $about = array();
  117. $doc = new DOMDocument();
  118. $doc->load($file);
  119. $doc->normalize();
  120. // $about['name'] = $doc->getElementsByTagName('name')->item(0)->nodeValue;
  121. // $about['author'] = $doc->getElementsByTagName('author')->item(0)->nodeValue;
  122. // $about['description'] = $doc->getElementsByTagName('description')->item(0)->nodeValue;
  123. // $about['url'] = $doc->getElementsByTagName('url')->item(0)->nodeValue;
  124. return $about;
  125. }
  126. function show_row($v="", $nowrap=0) {
  127. if($nowrap) {echo "<td style=\"white-space: pre;\">";}
  128. else echo "<td>";
  129. if($v) { echo $v; } else { echo "&nbsp;"; }
  130. echo "</td>";
  131. }
  132. function show_info($f) {
  133. $about = array();
  134. $file = $f."/about.xml";
  135. if(file_exists($file)) {
  136. if(class_exists("DOMDocument")) {
  137. $about = parse_xml($file);
  138. } else {
  139. $about = parse_about($file);
  140. }
  141. }
  142. show_row($about['name'], 1);
  143. show_row($about['author'], 1);
  144. show_row($about['description']);
  145. }
  146. $themes = $config['basepath']."theme/";
  147. $d = opendir($themes);
  148. echo "<form method=\"post\" action=\"file-edit.php\">";
  149. echo "<table class=\"list_table\">";
  150. echo "<tr><th>??</th><th>??????</th><th>??????</th><th>??</th><th>??</th><th>??</th></tr>";
  151. while($f = readdir($d)) {
  152. $fullpath = $themes.$f;
  153. if($f[0] == ".") continue;
  154. if(is_dir($fullpath)) {
  155. echo "<tr><td style=\"width: 3em; text-align: center;\">";
  156. echo "<input ";
  157. if($f == vjinfo('theme')) {
  158. echo 'checked="checked" ';
  159. }
  160. echo "type=\"radio\" name=\"theme\" id=\"theme_$f\" value=\"$f\" />&nbsp;";
  161. echo "</td><td style=\"white-space: pre;\"><strong><label for=\"theme_$f\">$f</label></strong>";
  162. if($f == vjinfo('theme')) {
  163. echo "<br />???????????";
  164. }
  165. echo "</td>";
  166. show_info($fullpath);
  167. echo "<td style=\"white-space: pre;\"><a href=\"file-preview.php?theme=$f\" class=\"viewpage\">??????</a></td>";
  168. echo "</tr>";
  169. }
  170. }
  171. echo "</table>";
  172. echo "<p>";
  173. echo "<input type=\"submit\" name=\"submit\" value=\"??????\" />&nbsp;";
  174. echo "<input type=\"reset\" name=\"reset\" value=\"??????\" />";
  175. echo "<input type=\"hidden\" name=\"action\" value=\"theme\" />";
  176. echo "</p>";
  177. echo "</form>";
  178. ?>
  179. </div>
  180. <div id="file_edit" class="wrap">
  181. <a name="edit"></a>
  182. <h3>????????</h3>
  183. <p>??????????? <strong><?php echo $config['theme'] ?></strong>???????????????????????? PHP ?????? CSS ????</p>
  184. <p>???????????? PHP ?????? PHP ?????????????????????????????????????????????????????????????????????????????????????????????</p>
  185. <p>?????????????</p>
  186. <?php
  187. $filenames = array();
  188. $filename['toc.php'] = "?????????";
  189. $filename['post.php'] = "????????";
  190. $filename['style.css'] = "??????";
  191. $filename['print.css'] = "??????";
  192. $filename['vj.js'] = "?? Javascript ??";
  193. $filename['header.php'] = "????????";
  194. $filename['footer.php'] = "????????";
  195. $d = opendir($config['theme_path']);
  196. echo "<ul>\n";
  197. while($f = readdir($d)) {
  198. $fullpath = $config['theme_path'].$f;
  199. if(is_dir($fullpath)) continue;
  200. $contenttype = mime_content_type($fullpath);
  201. if(!strstr($contenttype, "text")) continue;
  202. echo "<li>";
  203. echo "<a href=\"file-edit.php?page=".$f."\"> ?? ";
  204. if($filename[$f]) {
  205. echo $filename[$f];
  206. } else {
  207. echo "$f"; // replace with db insert
  208. }
  209. echo "</a>";
  210. if(!is_writable($fullpath)) {
  211. echo " (?????";
  212. }
  213. echo "</li>\n";
  214. }
  215. echo "</ul>\n";
  216. }
  217. ?>
  218. </div>
  219. <?php admin_footer(); ?>