PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/define_pages_editor.php

https://github.com/ZenMagick/zc-base
PHP | 270 lines | 233 code | 22 blank | 15 comment | 42 complexity | b27430935f6193b93960688300b28061 MD5 | raw file
  1. <?php
  2. /**
  3. * @package admin
  4. * @copyright Copyright 2003-2006 Zen Cart Development Team
  5. * @copyright Portions Copyright 2003 osCommerce
  6. * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  7. * @version $Id: define_pages_editor.php 4279 2006-08-26 03:31:29Z drbyte $
  8. */
  9. require('includes/application_top.php');
  10. function zen_display_files() {
  11. global $check_directory, $found, $configuration_key_lookup;
  12. for ($i = 0, $n = sizeof($check_directory); $i < $n; $i++) {
  13. //echo 'I SEE ' . $check_directory[$i] . '<br>';
  14. $dir_check = $check_directory[$i];
  15. $file_extension = '.php';
  16. if ($dir = @dir($dir_check)) {
  17. while ($file = $dir->read()) {
  18. if (!is_dir($dir_check . $file)) {
  19. if (substr($file, strrpos($file, '.')) == $file_extension) {
  20. $directory_array[] = $file;
  21. }
  22. }
  23. }
  24. if (sizeof($directory_array)) {
  25. sort($directory_array);
  26. }
  27. $dir->close();
  28. }
  29. }
  30. return $directory_array;
  31. }
  32. $action = (isset($_GET['action']) ? $_GET['action'] : '');
  33. $za_who = $_GET['za_lookup'];
  34. if ($action == 'new_page') {
  35. $page = $_GET['define_it'];
  36. $check_directory = array();
  37. $check_directory[] = DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/html_includes/';
  38. $directory_files = zen_display_files();
  39. $za_lookup = array();
  40. for ($i = 0, $n = sizeof($directory_files); $i < $n; $i++) {
  41. $za_lookup[] = array('id' => $i, 'text' => $directory_files[$i]);
  42. }
  43. // This will cause it to look for 'define_conditions.php'
  44. $_GET['filename'] = $za_lookup[$page]['text'];
  45. $_GET['box_name'] = BOX_TOOLS_DEFINE_CONDITIONS;
  46. }
  47. // define template specific file name defines
  48. $file = zen_get_file_directory(DIR_FS_CATALOG_LANGUAGES . $_SESSION['language'] . '/html_includes/', $_GET['filename'], 'false');
  49. ?>
  50. <?php
  51. switch ($_GET['action']) {
  52. case 'set_editor':
  53. // Reset will be done by init_html_editor.php. Now we simply redirect to refresh page properly.
  54. $action='';
  55. zen_redirect(zen_href_link(FILENAME_DEFINE_PAGES_EDITOR));
  56. break;
  57. case 'save':
  58. if ( ($_GET['lngdir']) && ($_GET['filename']) ) {
  59. if (file_exists($file)) {
  60. if (file_exists('bak' . $file)) {
  61. @unlink('bak' . $file);
  62. }
  63. @rename($file, 'bak' . $file);
  64. $new_file = fopen($file, 'w');
  65. $file_contents = stripslashes($_POST['file_contents']);
  66. fwrite($new_file, $file_contents, strlen($file_contents));
  67. fclose($new_file);
  68. }
  69. zen_redirect(zen_href_link(FILENAME_DEFINE_PAGES_EDITOR));
  70. }
  71. break;
  72. }
  73. if (!$_SESSION['language']) $_SESSION['language'] = $language;
  74. $languages_array = array();
  75. $languages = zen_get_languages();
  76. $lng_exists = false;
  77. for ($i=0; $i<sizeof($languages); $i++) {
  78. if ($languages[$i]['directory'] == $_SESSION['language']) $lng_exists = true;
  79. $languages_array[] = array('id' => $languages[$i]['directory'],
  80. 'text' => $languages[$i]['name']);
  81. }
  82. if (!$lng_exists) $_SESSION['language'] = $language;
  83. ?>
  84. <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
  85. <html <?php echo HTML_PARAMS; ?>>
  86. <head>
  87. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
  88. <title><?php echo TITLE; ?></title>
  89. <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
  90. <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
  91. <script language="javascript" src="includes/menu.js"></script>
  92. <script language="javascript" src="includes/general.js"></script>
  93. <script type="text/javascript">
  94. <!--
  95. function init()
  96. {
  97. cssjsmenu('navbar');
  98. if (document.getElementById)
  99. {
  100. var kill = document.getElementById('hoverJS');
  101. kill.disabled = true;
  102. }
  103. if (typeof _editor_url == "string") HTMLArea.replaceAll();
  104. }
  105. // -->
  106. </script>
  107. <?php if ($editor_handler != '') include ($editor_handler); ?>
  108. </head>
  109. <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="init()">
  110. <div id="spiffycalendar" class="text"></div>
  111. <!-- header //-->
  112. <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
  113. <!-- header_eof //-->
  114. <!-- body //-->
  115. <table border="0" width="100%" cellspacing="2" cellpadding="2">
  116. <tr>
  117. <!-- body_text //-->
  118. <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
  119. <tr>
  120. <td class="pageHeading"><?php echo HEADING_TITLE . '&nbsp;' . $_SESSION['language']; ?> &nbsp;&nbsp;
  121. <?php
  122. $check_directory = array();
  123. $check_directory[] = DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/html_includes/';
  124. $directory_files = zen_display_files();
  125. $za_lookup = array();
  126. $za_lookup[] = array('id' => -1, 'text' => TEXT_INFO_SELECT_FILE);
  127. for ($i = 0, $n = sizeof($directory_files); $i < $n; $i++) {
  128. $za_lookup[] = array('id' => $i, 'text' => $directory_files[$i]);
  129. }
  130. echo zen_draw_form('new_page', FILENAME_DEFINE_PAGES_EDITOR, '', 'get') . '&nbsp;&nbsp;' . zen_draw_pull_down_menu('define_it', $za_lookup, '-1', 'onChange="this.form.submit();"') .
  131. zen_hide_session_id() .
  132. zen_draw_hidden_field('action', 'new_page') . '&nbsp;&nbsp;</form>';
  133. ?>
  134. <?php
  135. // toggle switch for editor
  136. echo TEXT_EDITOR_INFO . zen_draw_form('set_editor_form', FILENAME_DEFINE_PAGES_EDITOR, '', 'get') . '&nbsp;&nbsp;' . zen_draw_pull_down_menu('reset_editor', $editors_pulldown, $current_editor_key, 'onChange="this.form.submit();"') .
  137. zen_draw_hidden_field('action', 'set_editor') .
  138. zen_hide_session_id() .
  139. '</form>';
  140. ?>
  141. </td>
  142. </tr>
  143. <?php
  144. // show editor
  145. if (isset($_GET['filename'])) {
  146. ?>
  147. <tr>
  148. <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
  149. <?php
  150. if ( ($_SESSION['language']) && ($_GET['filename']) ) {
  151. if (file_exists($file)) {
  152. $file_array = @file($file);
  153. $file_contents = @implode('', $file_array);
  154. $file_writeable = true;
  155. if (!is_writeable($file)) {
  156. $file_writeable = false;
  157. $messageStack->reset();
  158. $messageStack->add(sprintf(ERROR_FILE_NOT_WRITEABLE, $file), 'error');
  159. echo $messageStack->output();
  160. }
  161. ?>
  162. <tr>
  163. <td class="main"><b><?php echo TEXT_INFO_CAUTION . '<br /><br />' . TEXT_INFO_EDITING . '<br />' . $file . '<br />'; ?></b></td>
  164. </tr>
  165. <tr><?php echo zen_draw_form('language', FILENAME_DEFINE_PAGES_EDITOR, 'lngdir=' . $_SESSION['language'] . '&filename=' . $_GET['filename'] . '&action=save'); ?>
  166. <td><table border="0" cellspacing="0" cellpadding="2">
  167. <tr>
  168. <td class="main">
  169. <?php if ($_SESSION['html_editor_preference_status']=="FCKEDITOR") {
  170. $oFCKeditor = new FCKeditor('file_contents') ;
  171. $oFCKeditor->Value = $file_contents ;
  172. $oFCKeditor->Width = '700' ;
  173. $oFCKeditor->Height = '450' ;
  174. // $oFCKeditor->Create() ;
  175. $output = $oFCKeditor->CreateHtml() ; echo $output;
  176. } else { // using HTMLAREA or just raw "source"
  177. echo zen_draw_textarea_field('file_contents', 'soft', '100%', '30', $file_contents, (($file_writeable) ? '' : 'readonly') . ' id="file_contents"');
  178. } ?>
  179. </td>
  180. </tr>
  181. <tr>
  182. <td><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  183. </tr>
  184. <tr>
  185. <td align="right"><?php if ($file_writeable) { echo zen_image_submit('button_save.gif', IMAGE_SAVE) . '&nbsp;<a href="' . zen_href_link(FILENAME_DEFINE_PAGES_EDITOR, 'define_it=' .$_GET['define_it'] . '&action=new_page') . '">' . zen_image_button('button_reset.gif', IMAGE_RESET) . '</a>' . '&nbsp;' . '<a href="' . zen_href_link(FILENAME_DEFINE_PAGES_EDITOR . '.php') . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; } else { echo '<a href="' . zen_href_link(FILENAME_DEFINE_PAGES_EDITOR, 'lngdir=' . $_SESSION['language']) . '">' . zen_image_button('button_back.gif', IMAGE_BACK) . '</a>'; } ?></td>
  186. </tr>
  187. </table></td>
  188. </form></tr>
  189. <?php
  190. } else {
  191. ?>
  192. <tr>
  193. <td class="main"><b><?php echo sprintf(TEXT_FILE_DOES_NOT_EXIST, $file); ?></b></td>
  194. </tr>
  195. <tr>
  196. <td><?php echo zen_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
  197. </tr>
  198. <tr>
  199. <td><?php echo '<a href="' . zen_href_link($_GET['filename'], 'lngdir=' . $_SESSION['language']) . '">' . zen_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
  200. </tr>
  201. <?php
  202. }
  203. } else {
  204. $filename = $_SESSION['language'] . '.php';
  205. ?>
  206. <tr>
  207. <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
  208. <tr>
  209. <td class="smallText"><a href="<?php echo zen_href_link($_GET['filename'], 'lngdir=' . $_SESSION['language'] . '&filename=' . $filename); ?>"><b><?php echo $filename; ?></b></a></td>
  210. <?php
  211. $dir = dir(DIR_FS_CATALOG_LANGUAGES . $_SESSION['language']);
  212. $left = false;
  213. if ($dir) {
  214. $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
  215. while ($file = $dir->read()) {
  216. if (substr($file, strrpos($file, '.')) == $file_extension) {
  217. echo ' <td class="smallText"><a href="' . zen_href_link($_GET['filename'], 'lngdir=' . $_SESSION['language'] . '&filename=' . $file) . '">' . $file . '</a></td>' . "\n";
  218. if (!$left) {
  219. echo ' </tr>' . "\n" .
  220. ' <tr>' . "\n";
  221. }
  222. $left = !$left;
  223. }
  224. }
  225. $dir->close();
  226. }
  227. ?>
  228. </tr>
  229. </table></td>
  230. </tr>
  231. <?php
  232. }
  233. ?>
  234. </table></td>
  235. <?php } // filename ?>
  236. </tr>
  237. </table></td>
  238. <!-- body_text_eof //-->
  239. </tr>
  240. </table>
  241. <!-- body_eof //-->
  242. <!-- footer //-->
  243. <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
  244. <!-- footer_eof //-->
  245. <br />
  246. </body>
  247. </html>
  248. <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>