/vj-admin/file-edit.php
PHP | 233 lines | 227 code | 6 blank | 0 comment | 16 complexity | 78ccd8a852bf09a7ab7f5376b4b2057e MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0
- <?php
- include("admin.php");
- if (!function_exists('mime_content_type')) {
- function mime_content_type ($f) {
- $str = exec(trim('file -bi '.escapeshellarg($f))) ;
- $array = explode(";", $str);
- $str = $array[0];
- return $str;
- }
- }
- if (!function_exists('file_put_contents')) {
- define('FILE_APPEND', 1);
- function file_put_contents($n, $d, $flag = false) {
- $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
- $f = @fopen($n, $mode);
- if ($f == false) {
- return 0;
- } else {
- if (is_array($d)) $d = implode($d);
- $bytes_written = fwrite($f, $d);
- fclose($f);
- return $bytes_written;
- }
- }
- }
- function change_theme($theme = "") {
- global $vj;
- global $msg;
- if(!$_POST['theme']) return;
- update_key("theme", $_POST['theme']);
- $vj->query_info();
- $msg = "?????????? <strong>".$_POST['theme']."</strong> ??";
- }
- if($_POST['submit'] && $_POST['action'] == "theme") {
- change_theme($_POST['theme']);
- }
- admin_header("??????");
- ?>
- <?php
- if($_POST['submit'] && $_POST['action'] == "edit") {
- $page = $_POST['page'];
- $content = $_POST['content'];
- $filename = $config['theme_path'].$page;
- @copy($filename, $filename.".bak");
- $content = str_replace('\"', '"', $content);
- $content = str_replace("\'", "'", $content);
- @file_put_contents($filename, $content);
- echo "<h2>?????</h2>";
- echo "<p>???????????????</p>";
- if(file_exists($filename.".bak")) {
- echo "<p>?????????????????<a href=\"file-edit.php?page=".$page.".bak\">??????????</a>?????????</p>";
- }
- } else if($_GET['page']){
- $page = $_GET['page'];
- $filename = $config['theme_path'].$page;
- $content = @file_get_contents($filename);
- $contenttype = mime_content_type($filename);
- if(!file_exists($filename)) {
- echo "<h2>??????</h2>";
- echo "<p>???????????</p>";
- } else if(!strstr($contenttype, "text")) {
- echo "<h2>???????</h2>";
- echo "<p>?????????????????????</p>";
- } else {
- ?>
- <h2>????????</h2>
- <form action="file-edit.php" method="post">
- <p><strong>????</strong>? <?php echo $page ?> ?<strong>????</strong>?<?php echo mime_content_type($filename) ?></p>
- <input type="hidden" value="<?php echo $page; ?>" name="page" id="page" />
- <textarea id="content" name="content" style="padding: 5px; width: 90%; height: 300px; font-size: 12pt; font-family: mono-space;"><?php echo $content; ?></textarea> <br />
- <?php
- if(is_dir($filename)) {
- echo "<p>????????????????????</p>";
- } else if (!is_writable($filename)) {
- echo "<p>??????????????????????</p>";
- echo "<p>??????????????? Linux ??????????????? <code>chmod 666 ".$page."</code>?</p>";
- } else {
- ?>
- <input type="submit" id="submit" name="submit" value="?????"/>
- <input type="hidden" name="action" value="edit"/>
- </form>
- <? }
- }
- } else {
- ?>
- <h2>??????</h2>
- <div id="filetool" class="tool">
- ????
- <a href="#theme" onclick="return vj.file.show_area('file_theme');">??????</a> |
- <a href="#edit" onclick="return vj.file.show_area('file_edit');">????????</a>
- </div>
- <div id="file_theme" class="wrap">
- <?php if($msg) {
- echo '<div id="msg">'.$msg.'</div>';
- }?>
-
- <a name="theme"></a>
- <h3>??????</h3>
- <p>??????????????????????????????????</p>
- <p>??????????????????</p>
- <?php
- function parse_about($file="") {
- $about = array();
- $content = file_get_contents($file);
- if(!$content) return $about;
- preg_match("/<name>(.+?)<\/name>/", $content, $match);
- $about['name'] = $match[1];
- preg_match("/<author>(.+?)<\/author/", $content, $match);
- $about['author'] = $match[1];
- preg_match("/<description>(.+?)<\/description>/", $content, $match);
- $about['description'] = $match[1];
- preg_match("/<url>(.+?)<\/url>/", $content, $match);
- $about['url'] = $match[1];
- return $about;
- }
- function parse_xml($file="") {
- $about = array();
- $doc = new DOMDocument();
- $doc->load($file);
- $doc->normalize();
- // $about['name'] = $doc->getElementsByTagName('name')->item(0)->nodeValue;
- // $about['author'] = $doc->getElementsByTagName('author')->item(0)->nodeValue;
- // $about['description'] = $doc->getElementsByTagName('description')->item(0)->nodeValue;
- // $about['url'] = $doc->getElementsByTagName('url')->item(0)->nodeValue;
- return $about;
- }
- function show_row($v="", $nowrap=0) {
- if($nowrap) {echo "<td style=\"white-space: pre;\">";}
- else echo "<td>";
- if($v) { echo $v; } else { echo " "; }
- echo "</td>";
- }
- function show_info($f) {
- $about = array();
- $file = $f."/about.xml";
- if(file_exists($file)) {
- if(class_exists("DOMDocument")) {
- $about = parse_xml($file);
- } else {
- $about = parse_about($file);
- }
- }
- show_row($about['name'], 1);
- show_row($about['author'], 1);
- show_row($about['description']);
- }
- $themes = $config['basepath']."theme/";
- $d = opendir($themes);
- echo "<form method=\"post\" action=\"file-edit.php\">";
- echo "<table class=\"list_table\">";
- echo "<tr><th>??</th><th>??????</th><th>??????</th><th>??</th><th>??</th><th>??</th></tr>";
- while($f = readdir($d)) {
- $fullpath = $themes.$f;
- if($f[0] == ".") continue;
- if(is_dir($fullpath)) {
- echo "<tr><td style=\"width: 3em; text-align: center;\">";
- echo "<input ";
- if($f == vjinfo('theme')) {
- echo 'checked="checked" ';
- }
- echo "type=\"radio\" name=\"theme\" id=\"theme_$f\" value=\"$f\" /> ";
- echo "</td><td style=\"white-space: pre;\"><strong><label for=\"theme_$f\">$f</label></strong>";
- if($f == vjinfo('theme')) {
- echo "<br />???????????";
- }
- echo "</td>";
- show_info($fullpath);
- echo "<td style=\"white-space: pre;\"><a href=\"file-preview.php?theme=$f\" class=\"viewpage\">??????</a></td>";
- echo "</tr>";
- }
- }
- echo "</table>";
- echo "<p>";
- echo "<input type=\"submit\" name=\"submit\" value=\"??????\" /> ";
- echo "<input type=\"reset\" name=\"reset\" value=\"??????\" />";
- echo "<input type=\"hidden\" name=\"action\" value=\"theme\" />";
- echo "</p>";
- echo "</form>";
- ?>
- </div>
- <div id="file_edit" class="wrap">
- <a name="edit"></a>
- <h3>????????</h3>
- <p>??????????? <strong><?php echo $config['theme'] ?></strong>???????????????????????? PHP ?????? CSS ????</p>
- <p>???????????? PHP ?????? PHP ?????????????????????????????????????????????????????????????????????????????????????????????</p>
- <p>?????????????</p>
- <?php
- $filenames = array();
- $filename['toc.php'] = "?????????";
- $filename['post.php'] = "????????";
- $filename['style.css'] = "??????";
- $filename['print.css'] = "??????";
- $filename['vj.js'] = "?? Javascript ??";
- $filename['header.php'] = "????????";
- $filename['footer.php'] = "????????";
- $d = opendir($config['theme_path']);
- echo "<ul>\n";
- while($f = readdir($d)) {
- $fullpath = $config['theme_path'].$f;
- if(is_dir($fullpath)) continue;
- $contenttype = mime_content_type($fullpath);
- if(!strstr($contenttype, "text")) continue;
- echo "<li>";
- echo "<a href=\"file-edit.php?page=".$f."\"> ?? ";
- if($filename[$f]) {
- echo $filename[$f];
- } else {
- echo "$f"; // replace with db insert
- }
- echo "</a>";
- if(!is_writable($fullpath)) {
- echo " (?????";
- }
- echo "</li>\n";
- }
- echo "</ul>\n";
- }
- ?>
- </div>
- <?php admin_footer(); ?>