PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/jscript/editor-plugins/pixieGeSHi/dialogs/dialog.php

http://pixie-cms.googlecode.com/
PHP | 237 lines | 178 code | 10 blank | 49 comment | 35 complexity | 86790e7a2e4db01d089f8dd5b49fa0a9 MD5 | raw file
  1. <?php
  2. header('Content-Type: text/html; charset=UTF-8');
  3. /**
  4. * Pixie: The Small, Simple, Site Maker.
  5. *
  6. * Licence: GNU General Public License v3
  7. * Copyright (C) 2010, Scott Evans
  8. *
  9. * GeSHi output parser script.
  10. *
  11. * Licence: GNU General Public License v3
  12. * Copyright (C) 2004, Nigel McNie
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see http://www.gnu.org/licenses/
  26. *
  27. * Title: CKEditor GeSHi Dialog
  28. *
  29. * @package Pixie
  30. * @copyright 2008-2010 Scott Evans
  31. * @author Nigel McNie
  32. * @author T White
  33. * @link http://heydojo.co.cc/
  34. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3
  35. *
  36. */
  37. if (defined('DIRECT_ACCESS')) {
  38. require_once '../../../../lib/lib_misc.php';
  39. pixieExit();
  40. exit();
  41. }
  42. define('DIRECT_ACCESS', 1);
  43. require_once '../../../../lib/lib_misc.php';
  44. /* perform basic sanity checks */
  45. bombShelter();
  46. /* check URL size */
  47. error_reporting(0);
  48. $refering = NULL;
  49. $refering = parse_url(($_SERVER['HTTP_REFERER']));
  50. if (($refering['host'] == $_SERVER['HTTP_HOST'])) {
  51. if ((is_readable('../../../../lib/geshi.php'))) {
  52. $path = '../../../../lib/';
  53. } elseif ((is_readable('geshi.php'))) {
  54. $path = './';
  55. } else {
  56. ?>
  57. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  58. <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  59. <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>GeSHi</title>
  60. <style type="text/css">
  61. body{font-family:'Lucida Grande',Verdana,Arial,Sans-Serif;font-size:11pt;line-height:14pt;padding-left:1%;padding-right:1%;}
  62. #center{text-align:center;}
  63. #right{text-align:right;}
  64. </style>
  65. </head>
  66. <body>
  67. <p id="center">To activate this plugin you must do the following first :</p>
  68. <p>
  69. <ol>
  70. <li>Download GeSHi from <a href="http://sourceforge.net/projects/geshi/files/" target="_blank">here</a> (Version 1.0.8.6 or higher recommended)</li>
  71. <li>Extract the downloaded archive</li>
  72. <li>Copy the folder geshi/geshi/ into Pixie's lib directory admin/lib/</li>
  73. <li>Copy the file geshi/geshi.php into Pixie's lib directory admin/lib/</li>
  74. <li>Close this dialogue by clicking cancel</li>
  75. <li>Finally, click the "Post syntax highlighted code" Icon again to re-launch this dialogue.</li>
  76. </ol>
  77. </p>
  78. <p id="right">Enjoy!<p>
  79. </body>
  80. </html>
  81. <?php
  82. die();
  83. }
  84. require_once "{$path}geshi.php";
  85. $fill_source = FALSE;
  86. if (isset($_POST['submit'])) {
  87. if (get_magic_quotes_gpc()) {
  88. $_POST['source'] = stripslashes($_POST['source']);
  89. }
  90. if (!strlen(trim($_POST['source']))) {
  91. $_POST['language'] = preg_replace('#[^a-zA-Z0-9\-_]#', '', $_POST['language']);
  92. $_POST['source'] = implode('', @file($path . 'geshi/' . $_POST['language'] . '.php'));
  93. $_POST['language'] = 'php';
  94. } else {
  95. $fill_source = TRUE;
  96. }
  97. /* Set GeSHi options */
  98. $geshi = new GeSHi($_POST['source'], $_POST['language']);
  99. if (($_POST['container-type']) == 1) {
  100. $geshi->set_header_type(GESHI_HEADER_DIV);
  101. }
  102. if (($_POST['container-type']) == 2) {
  103. $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
  104. }
  105. if (($_POST['line_numbers']) == 2) {
  106. $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
  107. $geshi->set_line_style('background: transparent;', 'background: #F0F5FE;', TRUE);
  108. }
  109. if (($_POST['line_numbers']) == 3) {
  110. $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
  111. }
  112. if (($_POST['style_type']) == 2) {
  113. $geshi->enable_classes();
  114. }
  115. if (isset($_POST['submit'])) {
  116. $geshi_out = $geshi->parse_code();
  117. }
  118. } else {
  119. /* Don't pre-select any language */
  120. $_POST['language'] = NULL;
  121. }
  122. ?>
  123. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  124. <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  125. <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>GeSHi</title>
  126. <?php
  127. if (isset($_POST['submit'])) {
  128. ?>
  129. <script type="text/javascript"> //<![CDATA[
  130. var CKEDITOR = window.parent.CKEDITOR;
  131. var okListener = function(ev) {
  132. this._.editor.insertHtml('<?php
  133. echo preg_replace("/\r?\n/", "\\n", addslashes($geshi_out));
  134. ?>');
  135. CKEDITOR.dialog.getCurrent().removeListener("ok", okListener);
  136. };
  137. CKEDITOR.dialog.getCurrent().on("ok", okListener);
  138. //]]></script>
  139. <?php
  140. }
  141. ?>
  142. <style type="text/css">
  143. body{font-family:Arial,'Lucida Grande',Verdana,Sans-Serif;font-size:12px;padding-left:1%;padding-right:1%;color:#676666;}
  144. h3{color:#676666;font-weight:400;max-width:59%;margin:0;}
  145. #footer{text-align:center;font-size:80%;color:#BBBABA;clear:both;padding-top:16px;}
  146. a{color:#0497D3;text-decoration:none;}
  147. a:hover{color:#191919;}
  148. textarea{border:1px solid #BBBABA;font-size:90%;color:#676666;width:53%;margin-bottom:6px;}
  149. p{font-size:90%;}
  150. #clear{text-align:right;width:100px;float:left;padding-right:1%;}
  151. #submit{width:100px;float:left;}
  152. #style-radio{float:right;padding-right:2%;margin:0;}
  153. #style-radio input:hover{cursor:pointer;}
  154. #language{text-align:left;width:31%;color:#676666;background-color:#FFF;border:1px solid #BBBABA;height:24px;margin-bottom:12px;}
  155. .ui_button{font-size:12px;text-align:center;width:86px;border:1px solid #BBBABA;color:#4F4E4E;background-color:#FFF;background-image:url(../../../../admin/theme/ckPixie/images/sprites.gif);background-position:-27px -765px;padding:4px 12px;}
  156. .ui_button:hover{background-color:#DBDADA;background-image:none;cursor:pointer;}
  157. <?php
  158. if ((isset($_POST['submit'])) && ($_POST['style_type'] === 2)) {
  159. /* Output the stylesheet. Note it doesn't output the <style> tag */
  160. echo $geshi->get_stylesheet(TRUE);
  161. }
  162. ?>
  163. </style>
  164. </head>
  165. <body>
  166. <?php
  167. if (isset($_POST['submit'])) {
  168. print $geshi_out;
  169. }
  170. if (!(isset($_POST['submit']))) {
  171. ?>
  172. <form accept-charset="UTF-8" action="<?php
  173. echo basename($_SERVER['PHP_SELF']);
  174. ?>" method="post">
  175. <h3 id="lang">Choose a language *</h3>
  176. <p>
  177. <div id="style-radio"><input type="radio" name="style_type" value="1" checked> Use inline syles (<a href="http://qbnz.com/highlighter/geshi-doc.html#using-css-classes" target="_blank">?</a>)</input><br /><input type="radio" name="style_type" value="2"> Use your own css</input><br /><br />
  178. <input type="radio" name="line_numbers" value="1" checked> No Line numbers (<a href="http://qbnz.com/highlighter/geshi-doc.html#enabling-line-numbers" target="_blank">?</a>)</input><br /><input type="radio" name="line_numbers" value="2"> Fancy Line numbers</input><br /><input type="radio" name="line_numbers" value="3"> Normal line numbers</input><br /><br />
  179. <input type="radio" name="container-type" value="1" checked> Use a div container (<a href="http://qbnz.com/highlighter/geshi-doc.html#the-code-container" target="_blank">?</a>)</input><br /><input type="radio" name="container-type" value="2"> Use a (Valid) pre container</input></div>
  180. </div>
  181. <select name="language" id="language">
  182. <?php
  183. if (!($dir = @opendir(dirname(__FILE__) . '/../../../../lib/geshi'))) {
  184. echo '<option>No languages available!</option>';
  185. }
  186. $languages = array();
  187. while ($file = readdir($dir)) {
  188. if ($file[0] == '.' or strpos($file, '.', 1) === FALSE) {
  189. continue;
  190. }
  191. $lang = substr($file, 0, strpos($file, '.'));
  192. $languages[] = $lang;
  193. }
  194. closedir($dir);
  195. sort($languages);
  196. echo "<option selected=\"selected\" value=\"javascript\">javascript</option>";
  197. foreach ($languages as $lang) {
  198. if (isset($_POST['language']) && $_POST['language'] == $lang) {
  199. $selected = 'selected="selected"';
  200. } else {
  201. $selected = '';
  202. }
  203. echo '<option value="' . $lang . '">' . $lang . "</option>\n";
  204. }
  205. ?>
  206. </select>
  207. </p>
  208. <h3 id="src">Code to highlight *</h3>
  209. <p><textarea rows="6" name="source" id="source"><?php
  210. echo $fill_source ? htmlspecialchars($_POST['source']) : '';
  211. ?></textarea></p>
  212. <span id="submit"><input class="ui_button" type="submit" name="submit" value="Highlight" /></span>
  213. <span id="clear"><input class="ui_button" type="submit" name="clear" onclick="document.getElementById('source').value='';document.getElementById('language').value='';return false" value="clear" /></span>
  214. </form>
  215. <div id="footer"><p><a href="http://qbnz.com/highlighter/" target="_blank">GeSHi</a> &copy; Nigel McNie, 2004, released under the <a href="http://www.gnu.org/copyleft/gpl.html" target="_blank">GNU GPL</a></p></div>
  216. <?php
  217. /* End isset post submit */
  218. }
  219. ?>
  220. </body>
  221. </html>
  222. <?php
  223. } else {
  224. header('Location: ../../../../../');
  225. exit();
  226. }
  227. ?>