PageRenderTime 69ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/fck/editor/plugins/ImageManager/editorFrame.php

https://github.com/Asherontas/Active-CMS
PHP | 315 lines | 239 code | 42 blank | 34 comment | 51 complexity | 110ad7de4277ad199eaca112631ea987 MD5 | raw file
  1. <?php
  2. /**
  3. * The frame that contains the image to be edited.
  4. * @author Wei Zhuo
  5. * @author Paul Moers <mail@saulmade.nl> - watermarking and replace code + several small enhancements <http://www.saulmade.nl/FCKeditor/FCKPlugins.php>
  6. * @version $Id: editorFrame.php,v 1.7 2006/12/20 18:19:28 thierrybo Exp $
  7. * @package ImageManager
  8. */
  9. require_once('config.inc.php');
  10. require_once('Classes/ImageManager.php');
  11. require_once('Classes/ImageEditor.php');
  12. //default path is /
  13. $relative = '/';
  14. $manager = new ImageManager($IMConfig);
  15. $editor = new ImageEditor($manager);
  16. // process any uploaded files
  17. $imageRelative = $manager->processUploads();
  18. // get image info and process any action
  19. $imageInfo = $editor->processImage($imageRelative);
  20. ?>
  21. <!--[if IE]>
  22. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  23. <![endif]-->
  24. <html>
  25. <head>
  26. <title></title>
  27. <link href="assets/editorFrame.css" rel="stylesheet" type="text/css" />
  28. <script type="text/javascript" src="assets/wz_jsgraphics.js"></script>
  29. <script type="text/javascript" src="assets/wz_dragdrop.js"></script>
  30. <script type="text/javascript" src="assets/EditorContent.js"></script>
  31. <script type="text/javascript" src="assets/editorFrame.js"></script>
  32. <style>
  33. /* for centering the image vertically in IE */
  34. html, body
  35. {
  36. height: 100%;
  37. }
  38. </style>
  39. <script type="text/javascript">
  40. // <![CDATA[
  41. var processedAction = "<?php echo (isset($_GET['action']) ? $_GET['action'] : ''); ?>";
  42. if (processedAction == 'replace' && parent.old)
  43. {
  44. // reallow the user to close the editor window now uploading is done
  45. parent.onbeforeunload = function () {parent.old();};
  46. }
  47. // set function for the wz_dragdrop script to use when dragging
  48. function my_DragFunc()
  49. {
  50. verifyBounds();
  51. }
  52. // keep the watermark within the background
  53. function verifyBounds()
  54. {
  55. var
  56. orig = dd.elements.background,
  57. floater = dd.elements.floater,
  58. newX = floater.x,
  59. newY = floater.y
  60. ;
  61. if (floater.x < orig.x)
  62. {
  63. newX = orig.x;
  64. }
  65. else if (floater.x + floater.w > orig.x + orig.w)
  66. {
  67. newX = orig.x + (orig.w - floater.w);
  68. }
  69. if (floater.y < orig.y)
  70. {
  71. newY = orig.y;
  72. }
  73. else if (floater.y + floater.h > orig.y + orig.h)
  74. {
  75. newY = orig.y + (orig.h - floater.h);
  76. }
  77. if (newX != floater.x || newY != floater.y)
  78. {
  79. floater.moveTo(newX, newY);
  80. }
  81. }
  82. // ]]>
  83. </script>
  84. <script type="text/javascript">
  85. var mode = "<?php echo $editor->getAction(); ?>" //crop, scale, measure
  86. var currentImageFile = "<?php if(count($imageInfo)>0) echo rawurlencode($imageInfo['file']); ?>";
  87. if(window.top)
  88. {
  89. I18N = window.top.I18N;
  90. }
  91. function i18n(str)
  92. {
  93. if(I18N)
  94. return (I18N[str] || str);
  95. else
  96. return str;
  97. };
  98. </script>
  99. <script type="text/javascript">
  100. <?php
  101. if ($editor->isFileSaved() == 1)
  102. {
  103. ?>
  104. // Reload the images in the imageframe of the Manager :
  105. // Is there a "imgManager" frame.
  106. if ((popupWindow = parent.opener.parent) && (imgManager = parent.opener.parent.document.getElementById("imgManager")))
  107. {
  108. // refresh it - so it shows the edited image.
  109. imgManager.src = imgManager.src;
  110. }
  111. else
  112. {
  113. popupWindow = parent;
  114. }
  115. // Reload the images in the editor :
  116. // base system is the FCKeditor?
  117. if (popupWindow.opener.FCK)
  118. {
  119. editorFrame = popupWindow.opener.parent.document.getElementById(popupWindow.opener.FCK.Name + '___Frame');
  120. // get document
  121. if (editorDocument = popupWindow.opener.FCK.EditorDocument.body)
  122. {
  123. editorImages = editorDocument.getElementsByTagName("img");
  124. for (i = 0; i < editorImages.length; i++)
  125. {
  126. // reapply images their src to reload'm
  127. editorImages[i].src = editorImages[i].src;
  128. }
  129. }
  130. }
  131. // not found?
  132. if (!editorImages)
  133. {
  134. alert(i18n("Error: Couldn't update editor window.\nAny image that was edited and saved will still be visible as the old version!\nPlease save and reload the editor content."));
  135. }
  136. // save message
  137. var message = i18n('File saved.');
  138. <?php
  139. if ($editor->forcedNewName != false)
  140. {
  141. ?>
  142. message += '\n' + i18n('File name was changed into ') + '<?php echo $editor->forcedNewName; ?>';
  143. <?php
  144. }
  145. ?>
  146. alert(message);
  147. <?php
  148. }
  149. else if ($editor->isFileSaved() == -1)
  150. {
  151. ?>
  152. alert(i18n('File was not saved.'));
  153. <?php
  154. }
  155. ?>
  156. // show action buttons and current action's controls - were hidden during processing
  157. if (processedAction != '')
  158. {
  159. if ('flip' == processedAction)
  160. {
  161. processedAction = 'rotate';
  162. }
  163. var tools = parent.document.getElementById('tools_' + processedAction);
  164. tools.style.display = 'block';
  165. var buttons = parent.document.getElementById('buttons');
  166. buttons.style.display = 'block';
  167. }
  168. // populating watermarks select box (excluding watermarks that are to big or became to big for the editted image)
  169. watermarkBox = parent.document.getElementById("watermark_file");
  170. imagesArray = new Array();
  171. // first clear all its options
  172. watermarkBox.options.length = 0;
  173. <?php
  174. foreach($IMConfig['watermarks'] as $watermark)
  175. {
  176. $watermarkInfo = @getImageSize($IMConfig['base_dir'] . $watermark);
  177. // populate
  178. if ($watermarkInfo[0] < $imageInfo['width'] && $watermarkInfo[1] < $imageInfo['height'] && $watermarkInfo[0] != '')
  179. {
  180. $pos = strrpos(basename($watermark), ".");
  181. $filename = substr(basename($watermark), 0, $pos);
  182. echo "watermarkBox.options[watermarkBox.options.length] = new Option('" . basename($watermark) . "', '$filename');";
  183. echo "watermarkBox.options[watermarkBox.options.length - 1].setAttribute('fullPath', '" . $IMConfig['base_dir'] . $watermark . "');";
  184. echo "watermarkBox.options[watermarkBox.options.length - 1].setAttribute('x', $watermarkInfo[0]);";
  185. echo "watermarkBox.options[watermarkBox.options.length - 1].setAttribute('y', $watermarkInfo[1]);";
  186. echo $filename . "Preload = new Image(10, 10);";
  187. echo $filename . "Preload.src = '" . $IMConfig['base_url'] . $watermark . "';";
  188. }
  189. // first item unavailable?
  190. else if ($watermark == $IMConfig['watermarks'][0])
  191. {
  192. echo "var firstWatermarkItemUnavailable = true;";
  193. }
  194. }
  195. ?>
  196. // no watermarks found? Show message instead of watermarking controls.
  197. if (!watermarkBox.options[0])
  198. {
  199. parent.document.getElementById("watermarkControls").style.display = "none";
  200. parent.document.getElementById("watermarkMessage").style.display = "block";
  201. var watermarkingEnabled = false;
  202. }
  203. // else just show the controls
  204. else
  205. {
  206. parent.document.getElementById("watermarkControls").style.display = "block";
  207. parent.document.getElementById("watermarkMessage").style.display = "none";
  208. var watermarkingEnabled = true;
  209. }
  210. </script>
  211. </head>
  212. <body>
  213. <div id="status"></div>
  214. <div id="ant" class="selection" style="visibility:hidden"><img src="img/spacer.gif" width="0" height="0" border="0" alt="" id="cropContent"></div>
  215. <?php if ($editor->isGDEditable() == -1) { ?>
  216. <div style="text-align:center; padding:10px;"><span class="error">GIF format is not supported, image editing not supported.</span></div>
  217. <?php } ?>
  218. <table height="100%" width="100%">
  219. <tr>
  220. <td>
  221. <?php if(count($imageInfo) > 0 && is_file($imageInfo['fullpath'])) { ?>
  222. <div id="background" name="background" style="margin: auto; width: <?php echo $imageInfo['width']; ?>px; height: <?php echo $imageInfo['height']; ?>px; background-image: url(<?php echo $imageInfo['src']; ?>);">
  223. <?php if (count($IMConfig['watermarks']) > 0) { ?>
  224. <img name="floater" id="floater" style="width: 150px; height: 150px; behavior: url('assets/pngbehavior.htc'); position: absolute" src="<?php echo $IMConfig['base_url'] . $IMConfig['watermarks'][0]; ?>" />
  225. <?php } ?>
  226. </div>
  227. <span id="imgCanvas" name="imgCanvas" class="crop" style="display: none;"><img src="<?php echo $imageInfo['src']; ?>" <?php echo $imageInfo['dimensions']; ?> alt="" id="theImage" name="theImage" /></span>
  228. <?php } else { ?>
  229. <span class="error">No Image Available</span>
  230. <?php } ?>
  231. </td>
  232. </tr>
  233. </table>
  234. <script type="text/javascript">
  235. // <![CDATA[
  236. if (watermarkingEnabled == true)
  237. {
  238. SET_DHTML("background"+NO_DRAG, "floater"+CURSOR_MOVE);
  239. if (window.firstWatermarkItemUnavailable == true)
  240. {
  241. dd.elements.floater.swapImage(eval("window." + watermarkBox.options[0].value + "Preload.src"));
  242. }
  243. dd.elements.floater.resizeTo(watermarkBox.options[0].getAttribute("x"), watermarkBox.options[0].getAttribute("y"));
  244. dd.elements.floater.hide();
  245. verifyBounds();
  246. dd.elements.floater.nimg.style.behavior = "url('assets/pngbehavior.htc')";
  247. <?php
  248. if (isset($_GET['action']))
  249. {
  250. if ($_GET['action'] == "watermark")
  251. {?>
  252. dd.elements.floater.show();
  253. <?php }
  254. }
  255. ?>
  256. }
  257. else
  258. {
  259. if (document.getElementById("floater"))
  260. {
  261. document.getElementById("floater").style.display = "none";
  262. }
  263. }
  264. // hiding parent processing message
  265. parent.window.hideMessage();
  266. // make sure the slider of the watermark's opacity if at max
  267. parent.window.updateSlider(100, 'watermark');
  268. // ]]>
  269. </script>
  270. </body>
  271. </html>