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

/www/admin/templateeditor.php

http://kandidat-cms.googlecode.com/
PHP | 98 lines | 93 code | 4 blank | 1 comment | 3 complexity | f3710fe8dd51e37861e998d4e9b26ea9 MD5 | raw file
Possible License(s): CC0-1.0
  1. <?php
  2. $path=substr(str_replace('\\','/',dirname(__FILE__)),0,-6);
  3. include $path.'/admin/adminses.php';
  4. if(3>getpermision())header('LOCATION:index.php');
  5. $updateornot = @$_POST["Submit"];
  6. $content = @$_POST["article"];
  7. $content=get_magic_quotes_gpc()?stripslashes($content):$content;
  8. @$fedit = (isset($_GET["file"]))?$_GET["file"]:"template.php";
  9. @$fedit = preg_replace("/..\//i","",$fedit);
  10. $sitetitle="?????????????? ???????? ??????? ????? $fedit";
  11. if (empty($updateornot)) {
  12. $myFile = $localpath."/templates/$template/".$fedit;
  13. $fh = fopen($myFile, 'r');
  14. $data = fread($fh, filesize($myFile));
  15. fclose($fh);
  16. if(!preg_match('//u', $data)){
  17. if(stripos( $data,"charset=windows-1251")!==false){
  18. $data=iconv('windows-1251','UTF-8',$data);
  19. $data=str_ireplace("charset=windows-1251","charset=UTF-8",$data);
  20. }
  21. }
  22. $directory="$localpath/templates/$template";
  23. $dir = opendir($directory);
  24. while(($file = readdir($dir)))
  25. if ( is_file ($directory."/".$file))
  26. if($file!=$fedit)
  27. @$all_files .="|&nbsp;&nbsp;<a href=\"?file=$file\"> $file</a>&nbsp;&nbsp;|";
  28. closedir($dir);
  29. $url=$_SERVER['PHP_SELF'];
  30. $ext=getftype($fedit);
  31. $ext=(preg_match("/php|html|htm|css|js/i",$ext)?$ext:"php");
  32. @$contentcenter .=<<<EOT
  33. <script language="Javascript" type="text/javascript" src="edit_area/edit_area_full.js"></script>
  34. <script language="Javascript" type="text/javascript">
  35. // initialisation
  36. editAreaLoader.init({
  37. id: "code"// id of the textarea to transform
  38. ,start_highlight: true// if start with highlight
  39. ,allow_resize: "both"
  40. ,allow_toggle: true
  41. ,word_wrap: true
  42. ,language: "ru"
  43. ,syntax: "$ext"
  44. ,toolbar: "search, go_to_line, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, word_wrap, help"
  45. ,syntax_selection_allow: "css,html,js,php,perl"
  46. ,show_line_colors: true
  47. });
  48. </script>
  49. <form action="$url?file=$fedit" method="post" name="my_form">
  50. <h3>$sitetitle</h3>??????? ??????: <div class="template"><b>$template</b></div>
  51. ????? ? ???????: $all_files<br>
  52. <textarea name="article" id="code" rows=30 style="width: 100%;">$data</textarea>
  53. <br /><br>
  54. <div class="submit"><input type="submit" class="submit-button" id="Submit" name="Submit" value="????????? ?????????" /></div><br />
  55. </form>
  56. EOT;
  57. $contentcenter = stripslashes($contentcenter);
  58. }else{
  59. $myFile = "../templates/$template/$fedit";
  60. unlink($myFile);
  61. @chmod("../templates/$template/$fedit", 0777);
  62. $ourFileName = "../templates/$template/$fedit";
  63. $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
  64. fclose($ourFileHandle);
  65. $filename=$ourFileName;
  66. if (is_writable($filename)) {
  67. @$somecontent=stripslashes($content);
  68. if (!$handle = fopen($filename, 'a')) {
  69. echo "?????????? ??????? ($filename)";
  70. exit;
  71. }
  72. if (fwrite($handle, $content) === FALSE) {
  73. echo "?????????? ?????? ? ($filename)";
  74. exit;
  75. }
  76. fclose($handle);
  77. @chmod("../templates/$template/$fedit", 0644);
  78. @$contentcenter.="<div class=\"message_warn_ok\">????????? ? ??????? ?????????!</div><br><br><br><br><a href='javascript:history.back(1)'><B>????????? ?????</B></a>";
  79. }
  80. }
  81. include $localpath.'/admin/admintemplate.php';
  82. ?>