/[drupal]/contributions/modules/openwysiwyg/openwysiwyg.module
ViewVC logotype

Contents of /contributions/modules/openwysiwyg/openwysiwyg.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.28 - (show annotations) (download) (as text)
Thu Jun 25 16:26:36 2009 UTC (5 months ago) by thenicespider
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-RC1, HEAD
Changes since 1.27: +5 -4 lines
File MIME type: text/x-php
6.x-1.0-rc1:   Fixed: "Show editor on specific pages" from textfield to textarea
               Fixed: Disable "add custom buttons" feature
               Fixed: Replace '-' to '_' for arg(2) when add new content
1 <?php
2 /* $Id: openwysiwyg.module,v 1.27 2009/06/19 21:20:24 thenicespider Exp $ */
3
4 /**
5 * Display help and module information
6 * @param section which section of the site we're displaying help
7 * @return help text for section
8 */
9 function openwysiwyg_help($section='') {
10 $output = '';
11 switch ($section) {
12 case 'admin/settings/help#description':
13 $output = t("Enables openwysiwyg WYSIWYG editor.");
14 break;
15 case "admin/help#openwysiwyg":
16 $output = t("Enables openwysiwyg WYSIWYG editor.");
17 break;
18 case "admin/settings/openwysiwyg/custombuttons":
19 $output = t("<p>You can add extra buttons to the openwysiwyg editor on this page.
20 This allows you to specify HTML code and tags for your users to use.
21 The instructions below tell you how to add a custom button.
22 In this example we want to add a button that transforms selected text into superscript, by using the &lt;sup&gt; tags.</p>
23 <ul>
24 <li>Specify a name for your custom button in the table below. Don't use spaces or special characters. Example: <em>sup</em></li>
25 <li>Specify the tag that should be provided by your custom button in the next column. You shouldn't specify the closing tag.
26 Example: <em>&lt;sup&gt;</em></li>
27 <li>If you save this page, the button will be available in the 'Toolbar settings' on the 'Settings' tab.
28 Just add it to the button list. Note: This will only work if you chose the option 'As specified below:' for the toolbar.
29 It will not work when you have selected 'All'.</li>
30 <li>Optionally, you can supply an image to be used for this custom button.
31 Create a file named '&lt;name&gt;.gif' in the buttons directory of the openwysiwyg module folder.
32 Example: <em>sup.gif</em></li>
33 </ul>
34 Note: the Tag field can also have tags with parameters,
35 for example <em>&lt;span style=\"color:red;\"&gt;</em> will give selected text a red color.
36 ");
37 break;
38 }
39 return $output;
40 }
41
42 // Valid permissions for this module
43 function openwysiwyg_perm() {
44 return array('access openwysiwyg', 'administer openwysiwyg',
45 'file browse', 'file delete', 'file upload','file resize',
46 'folder create', 'folder delete', 'folder manage',
47 'toolbar buttons: full', 'toolbar buttons: custom');
48 }
49
50 // Implementation of hook_menu().
51 function openwysiwyg_menu() {
52 $items = array();
53
54 $items['admin/settings/openwysiwyg'] = array(
55 'title' => 'OpenWYSIWYG',
56 'description' => 'Enables OpenWYSIWYG.',
57 'access arguments' => array('administer openwysiwyg'),
58 'page callback' => 'drupal_get_form',
59 'page arguments' => array('openwysiwyg_admin_settings'),
60 'type' => MENU_NORMAL_ITEM,
61 'file' => 'openwysiwyg.settings.inc',
62 );
63
64 $items['admin/settings/openwysiwyg/settings'] = array(
65 'title' => 'Basic Settings',
66 'access arguments' => array('administer openwysiwyg'),
67 'weight' => -10,
68 'type' => MENU_DEFAULT_LOCAL_TASK,
69 'file' => 'openwysiwyg.settings.inc',
70 );
71
72 $items['admin/settings/openwysiwyg/visibility'] = array(
73 'title' => 'Visibility',
74 'description' => 'Openwysiwyg Visibility',
75 'access arguments' => array('administer openwysiwyg'),
76 'page callback' => 'drupal_get_form',
77 'page arguments' => array('openwysiwyg_settings_visibility'),
78 'type' => MENU_LOCAL_TASK,
79 'file' => 'openwysiwyg.settings.inc',
80 );
81
82 $items['admin/settings/openwysiwyg/browser'] = array(
83 'title' => 'File Browser',
84 'description' => 'Openwysiwyg File Browser',
85 'access arguments' => array('administer openwysiwyg'),
86 'page callback' => 'drupal_get_form',
87 'page arguments' => array('openwysiwyg_settings_file_browser'),
88 'type' => MENU_LOCAL_TASK,
89 'file' => 'openwysiwyg.settings.inc',
90 );
91
92 /*
93 $items['admin/settings/openwysiwyg/configs'] = array(
94 'title' => 'Custom Buttons',
95 'description' => 'Custom Buttons',
96 'access arguments' => array('administer openwysiwyg'),
97 'page callback' => 'drupal_get_form',
98 'page arguments' => array('openwysiwyg_settings_custombuttons'),
99 'type' => MENU_LOCAL_TASK,
100 'file' => 'openwysiwyg.settings.inc',
101 'weight' => '50',
102 );
103 */
104
105 $items['openwysiwyg/image_form'] = array(
106 'title' => 'Image Form',
107 'description' => 'Image Form',
108 'access arguments' => array('access openwysiwyg'),
109 'page callback' => 'openwysiwyg_ow_image_form',
110 'type' => MENU_CALLBACK,
111 );
112
113 //File Browse
114 $items['openwysiwyg/image_browse'] = array(
115 'access arguments' => array('access openwysiwyg'),
116 'page callback' => 'openwysiwyg_ow_image_browse',
117 //'page arguments' => $folder_name,$sub_folder,$error_msg,
118 'page arguments' => array($error_msg),
119 'type' => MENU_CALLBACK,
120 );
121
122 //File Delete
123
124 $items['openwysiwyg/file_delete'] = array(
125 'access arguments' => array('access openwysiwyg'),
126 'page callback' => 'openwysiwyg_ow_file_delete',
127 'type' => MENU_CALLBACK,
128 );
129
130 //Folder create
131 $items['openwysiwyg/folder_create'] = array(
132 'access arguments' => array('access openwysiwyg'),
133 'page callback' => 'openwysiwyg_ow_folder_create',
134 //'page arguments' => $folder_name, $sub_folder, $new_folder,
135 'type' => MENU_CALLBACK,
136 );
137
138 //File Upload
139 $items['openwysiwyg/file_upload'] = array(
140 'access arguments' => array('access openwysiwyg'),
141 'page callback' => 'openwysiwyg_ow_file_upload',
142 //'page arguments' => $_REQUEST['folder_name'],$_FILES['file_upload'],
143 'type' => MENU_CALLBACK,
144 );
145
146 //Image Resize Form
147 $items['openwysiwyg/file_resize_form'] = array(
148 'access arguments' => array('access openwysiwyg'),
149 'page callback' => 'openwysiwyg_ow_file_resize_form',
150 //'page arguments' => $folder_name,$file_name,
151 'type' => MENU_CALLBACK,
152 );
153
154 //Image Resize Action
155 $items['openwysiwyg/file_resize_action'] = array(
156 'access arguments' => array('access openwysiwyg'),
157 'page callback' => 'openwysiwyg_ow_file_resize_action',
158 //'page arguments' => $folder_name, $file_name,$resize_width,$resize_height,$resize_name,
159 'type' => MENU_CALLBACK,
160 );
161
162 return $items;
163 }
164
165 /**
166 * Implementation of hook_elements() to show the openwysiwyg editor when a textarea is loaded
167 */
168 function openwysiwyg_elements(){
169 $type = array();
170 if (user_access('access openwysiwyg')) {
171 $type['textarea'] = array('#process' => array('openwysiwyg_process_textarea'));
172 }
173 return $type;
174 }
175
176 /**
177 * Implementation of hook_form_alter()
178 */
179 function openwysiwyg_form_alter(&$form, &$form_state) {
180 // disable 'teaser' textarea
181 unset($form['body_field']['teaser_js']);
182 $form['body_field']['teaser_include'] = array();
183 }
184
185 // Modify the textarea to show openwysiwyg editor if certain conditions are met.
186 // function openwysiwyg_change_textarea($element) {
187
188 function openwysiwyg_process_textarea($element) {
189 static $openwysiwyg_ready = FALSE;
190
191 if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2)=='edit') {
192 $node = node_load(arg(1));
193 $form_type = $node->type;
194 }
195 if (arg(0) == 'node' && arg(1)=='add') {
196 $form_type = str_replace('-','_',arg(2));
197 }
198
199 $openwysiwyg_enable = 0;
200
201 if(_openwysiwyg_validate_element_id($element["#id"]) && _openwysiwyg_validate_content_type($form_type) && _openwysiwyg_allowed_pages()) {
202 $openwysiwyg_enable= 1;
203 } else {
204 $openwysiwyg_comment = variable_get('openwysiwyg_comment', 0);
205 if ($openwysiwyg_comment && arg(0)=='comment') {
206 $openwysiwyg_enable= 1;
207 }
208 }
209
210 if ($openwysiwyg_enable) {
211 if (!$openwysiwyg_ready) {
212 // get the path for the buttom images
213 $base_path = base_path();
214 $openwysiwyg_path = $base_path.drupal_get_path('module', 'openwysiwyg');
215 $buttonpath = $openwysiwyg_path.'/library/images/';
216 $PopupsDir = $openwysiwyg_path.'/library/popups/';
217 // add the openwysiwyg js library
218 drupal_add_js(drupal_get_path('module','openwysiwyg').'/library/scripts/openwysiwyg.modified.js');
219 drupal_add_css(drupal_get_path('module','openwysiwyg')."/library/styles/".variable_get("openwysiwyg_style","openwysiwyg.css"));
220
221 if (user_access('toolbar buttons: full')) {
222 $toolbar_button1 = 'new Array("fonts","fontsizes","headings","bold","italic","underline","strikethrough","seperator",'.
223 '"forecolor","backcolor","seperator","justifyfull","justifyleft","justifycenter","justifyright",'.
224 '"seperator","unorderedlist","orderedlist","outdent","indent")';
225 $toolbar_button2 = 'new Array("subscript", "superscript", "seperator", "cut", "copy", "paste","removeformat",'.
226 '"seperator","undo","redo","seperator","inserttable","insertimage","createlink","seperator",'.
227 '"preview","print","seperator","viewSource","maximize","seperator","teaser","seperator","help")';
228 } else {
229 $openwysiwyg_toolbar_buttons_1 = strtolower(trim(variable_get('openwysiwyg_toolbar_buttons_1', 'bold italic underline strikethrough seperator unorderedlist orderedlist')));
230 $openwysiwyg_toolbar_buttons_2 = strtolower(trim(variable_get('openwysiwyg_toolbar_buttons_2', 'subscript superscript seperator removeformat seperator inserttable insertimage')));
231
232 if ($openwysiwyg_toolbar_buttons_1=='') {
233 $toolbar_button1 = '\'\'';
234 } else {
235 $values_arr = explode(' ',$openwysiwyg_toolbar_buttons_1);
236 $toolbar_button1 = 'new Array(';
237 foreach ($values_arr as $value) { $toolbar_button1 .= "\"$value\","; }
238 $toolbar_button1 .= ')';
239 $toolbar_button1 = str_replace(',)',')', $toolbar_button1);
240 }
241
242 if ($openwysiwyg_toolbar_buttons_2=='') {
243 $toolbar_button2 = '\'\'';
244 } else {
245 $values_arr = explode(' ',$openwysiwyg_toolbar_buttons_2);
246 $toolbar_button2 = 'new Array(';
247 foreach ($values_arr as $value) { $toolbar_button2 .= "\"$value\","; }
248 $toolbar_button2 .= ')';
249 $toolbar_button2 = str_replace(',)',')', $toolbar_button2);
250 }
251 }
252
253 drupal_add_js("var mysettings = new WYSIWYG.Settings();
254 mysettings.ImagesDir = \"$buttonpath\";
255 mysettings.PopupsDir = \"$PopupsDir\";
256 mysettings.base_path = \"$base_path\";
257 mysettings.openwysiwyg_path = \"$openwysiwyg_path\";
258 mysettings.Toolbar[0] = $toolbar_button1;
259 mysettings.Toolbar[1] = $toolbar_button2;
260 ", inline);
261 $openwysiwyg_ready = TRUE;
262 }
263 //$script = "mysettings.Toolbar[0] = new Array(". $buttons1 .");\n";
264 //disable resize script
265 $element['#resizable'] = FALSE;
266
267 //set the width & height of the textarea, so openwysiwyg can inherit this
268 $editor_width = variable_get('openwysiwyg_editor_width', '100%');
269 $editor_height = variable_get('openwysiwyg_editor_height', 0);
270 if($editor_height != 0){
271 // set both
272 $element['#attributes'] = array('style' => "width: $editor_width; height: $editor_height;");
273 }else{
274 // only set width
275 $element['#attributes'] = array('style' => "width: $editor_width;");
276 }
277
278 // initialize openwysiwyg
279 $element_id = $element['#id'];
280 drupal_add_js("WYSIWYG.attach('$element_id', mysettings);", inline);
281 }
282 return $element;
283 }
284
285 function openwysiwyg_settings_custombuttons_submit($form_id, $form_values) {
286 // unset any thing that was deleted
287 foreach ($form_values['openwysiwyg_custombuttons'] as $key => $val) {
288 if ($val['delete'] == '1' || $val['btnname'] == '') {
289 unset($form_values['openwysiwyg_custombuttons'][$key]);
290 }
291 }
292 system_settings_form_submit($form_id, $form_values);
293 drupal_goto('admin/settings/openwysiwyg/custombuttons');
294 }
295
296 function theme_openwysiwyg_settings_custombuttons(&$form) {
297 foreach (element_children($form['openwysiwyg_custombuttons']) as $key) {
298 $row = array();
299 if (is_array($form['openwysiwyg_custombuttons'][$key]['btnname'])) {
300 $row[] = drupal_render($form['openwysiwyg_custombuttons'][$key]['btnname']);
301 $row[] = drupal_render($form['openwysiwyg_custombuttons'][$key]['btnvalue']);
302 $row[] = drupal_render($form['openwysiwyg_custombuttons'][$key]['delete']);
303 }
304 $rows[] = $row;
305 }
306 $header = array(t('Name'), t('Tag'), t('Delete'));
307 $output = theme('table', $header, $rows);
308 $output .= drupal_render($form);
309
310 return $output;
311 }
312
313 // Validation against textarea ID filters.
314 function _openwysiwyg_validate_element_id($id){
315 $valid = false;
316 // when returned valid, the openwysiwyg editor will be shown
317 $values = strtolower(str_replace(' ','',variable_get('openwysiwyg_textarea_id_val','edit-teaser,edit-body')));
318 $values_arr = split(',',$values);
319 // exclude some textfields that we need on the settings page from showing the editor
320 array_push($values_arr,'edit-openwysiwyg-textarea-id-val');
321 array_push($values_arr,'edit-openwysiwyg-visibility-path-val');
322 array_push($values_arr,'edit-openwysiwyg-toolbar-buttons-list');
323 if(variable_get('openwysiwyg_textarea_id',1) == 0){
324 // don't show editor if id is found in values
325 if(!in_array($id,$values_arr)){
326 $valid = true;
327 }
328 }else{
329 // only show editor if id is found in values
330 if(in_array($id,$values_arr)){
331 $valid = true;
332 }
333 }
334 return $valid;
335 }
336
337 // Validation against content-type filters.
338 function _openwysiwyg_validate_content_type($content_type){
339 $valid = false;
340 // when returned valid, the openwysiwyg editor will be shown
341 $values = strtolower(str_replace(' ','',variable_get('openwysiwyg_content_type_val','page')));
342 $values_arr = split(',',$values);
343 // exclude some textfields that we need on the settings page from showing the editor
344 array_push($values_arr,'edit-openwysiwyg-textarea-id-val');
345 array_push($values_arr,'edit-openwysiwyg-visibility-path-val');
346 array_push($values_arr,'edit-openwysiwyg-toolbar-buttons-list');
347 if(variable_get('openwysiwyg_content_type',1) == 0){
348 // don't show editor if id is found in values
349 if(!in_array($content_type,$values_arr)){$valid = true;}
350 }else{
351 // only show editor if id is found in values
352 if(in_array($content_type,$values_arr)){$valid = true;}
353 }
354 return $valid;
355 }
356
357 // Validation against pages filters.
358 function _openwysiwyg_allowed_pages() {
359 $openwysiwyg_page = variable_get('openwysiwyg_page','0');
360 $values = strtolower(str_replace(' ','',variable_get('openwysiwyg_page_val','')));
361
362 if ($openwysiwyg_page < 2) {
363 $path = drupal_get_path_alias($_GET['q']);
364 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($values, '/')) .')$/';
365 // Compare with the internal and path alias (if any).
366 $page_match = preg_match($regexp, $path);
367 if ($path != $_GET['q']) {
368 $page_match = $page_match || preg_match($regexp, $_GET['q']);
369 }
370 // When $block->visibility has a value of 0, the block is displayed on
371 // all pages except those listed in $block->pages. When set to 1, it
372 // is displayed only on those pages listed in $block->pages.
373 $page_match = !($openwysiwyg_page xor $page_match);
374 } else {
375 $page_match = drupal_eval($values);
376 }
377 return $page_match;
378 }
379
380 // Generate script for openwysiwyg toolbar creation in settings
381 function _openwysiwyg_settings_toolbar_js(){
382 return "\n<script type=\"text/javascript\">
383 function addToToolbar1(txt){
384 var curText= $(\"#edit-openwysiwyg-toolbar-buttons-1\").val();
385 $(\"#edit-openwysiwyg-toolbar-buttons-1\").val(curText + ' ' + txt);
386 }
387
388 function addToToolbar2(txt){
389 var curText= $(\"#edit-openwysiwyg-toolbar-buttons-2\").val();
390 $(\"#edit-openwysiwyg-toolbar-buttons-2\").val(curText + ' ' + txt);
391 }
392 </script>\n";
393 }
394
395 // Generate the toolbar buttons for the openwysiwyg settings page
396 function _openwysiwyg_settings_toolbar($id){
397 $buttonspath = base_path().drupal_get_path('module', 'openwysiwyg').'/library/images/';
398 $output = '<div><strong>'. t('Click to add buttons').':</strong> <br>';
399 $i=0;
400 foreach(_openwysiwyg_buttonlist() as $btn){
401 $i++;
402 $path = $buttonspath.$btn.'.gif';
403 if ($i==16) { $output .= '<br>'; }
404 $output .= "<a href=\"javascript:addToToolbar$id('$btn');\"><img src=\"$path\" alt=\"$btn\" /></a> ";
405 }
406 /*
407 $output .= "<br /> <strong>". t('Add lists').":</strong> ";
408 foreach(_openwysiwyg_selectlist() as $sel){
409 $output .= "<a href=\"javascript:addToToolbar$id('$sel');\">$sel</a> ";
410 }
411 */
412 $custombtn_arr = variable_get("openwysiwyg_custombuttons", NULL);
413 if(!empty($custombtn_arr)){
414 $output .= "<br /> <strong>". t('Add custom buttons').":</strong> ";
415 foreach($custombtn_arr as $key => $val){
416 $btnname = $val['btnname'];
417 $output .= "<a href=\"javascript:addToToolbar$id('$btnname');\">$btnname</a> ";
418 }
419 }
420
421 //$output .= "<br /> <strong>". t('Add separator').":</strong> ";
422 //$output .= "<a href=\"javascript:addToToolbar$id('|');\">seperator</a>";
423 $output .= '</div>';
424 return $output;
425 }
426
427 /*
428 * List of buttons to show for toolbar settings
429 */
430 function _openwysiwyg_buttonlist(){
431 return array("fonts","fontsizes","headings","bold","italic","underline","strikethrough", "forecolor","backcolor", "justifyfull","justifyleft","justifycenter","justifyright","unorderedlist","orderedlist","outdent","indent", "subscript", "superscript", "cut", "copy", "paste","removeformat", "undo","redo","inserttable","insertimage","createlink", "preview","print","viewsource","maximize","seperator","teaser","seperator","help"
432 );
433 }
434
435 /*
436 * List of selects (dropdownlists) to show for toolbar settings
437 */
438 function _openwysiwyg_selectlist(){
439 return array("select_font", "select_size", "select_heading"
440 );
441 }
442
443 function openwysiwyg_ow_image_form() {
444 $base_path = base_path();
445 $openwysiwyg_path = $base_path.drupal_get_path('module', 'openwysiwyg');
446
447
448 //create predefine folder
449 $openwysiwyg_predefine_folder = variable_get('openwysiwyg_predefine_folder','');
450 if ($openwysiwyg_predefine_folder <> '') {
451 $openwysiwyg_predefine_folder_arr = split(',',$openwysiwyg_predefine_folder);
452 // someone might put a space between the comma and the next textarea id
453 foreach ($openwysiwyg_predefine_folder_arr as $value) {
454 $predefine_folder = $user_dir."/".trim($value);
455 if (file_exists($predefine_folder)) {
456 if (!is_dir($predefine_folder)) {
457 mkdir($predefine_folder);
458 }
459 } else {
460 mkdir($predefine_folder);
461 }
462 }
463 }
464
465 $output = '';
466 $output .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
467 $output .= '<html>';
468 $output .= '<head>';
469 $output .= '<title>openWYSIWYG | Insert or Modify Image</title>';
470
471 $output .= '<script type="text/javascript" src="'.$openwysiwyg_path.'/library/scripts/wysiwyg-popup.js"></script>';
472 $output .= '<script language="JavaScript" type="text/javascript">';
473
474 $output .= "function GetValueFromChild(imgS,imgW,imgH) { \n";
475 $output .= " document.getElementById('src').value = imgS; \n";
476 $output .= " document.getElementById('width').value = imgW; \n";
477 $output .= " document.getElementById('height').value = imgH; \n";
478 $output .= "} \n\n";
479
480 $output .= '// ----------------------------------------------------------------------'."\n";
481 $output .= '// Function: Inserts image into the WYSIWYG.'."\n";
482 $output .= '// ----------------------------------------------------------------------'."\n";
483 $output .= 'function insertImage() {'."\n";
484 $output .= ' var n = WYSIWYG_Popup.getParam(\'wysiwyg\');'."\n";
485 $output .= ' '."\n";
486 $output .= ' // get values from form fields'."\n";
487 $output .= ' var src = document.getElementById(\'src\').value;'."\n";
488 $output .= ' var alt = document.getElementById(\'alt\').value;'."\n";
489 $output .= ' var width = document.getElementById(\'width\').value'."\n";
490 $output .= ' var height = document.getElementById(\'height\').value'."\n";
491 $output .= ' var border = document.getElementById(\'border\').value'."\n";
492 $output .= ' var align = document.getElementById(\'align\').value'."\n";
493 $output .= ' var vspace = document.getElementById(\'vspace\').value'."\n";
494 $output .= ' var hspace = document.getElementById(\'hspace\').value'."\n";
495 $output .= ' '."\n";
496 $output .= ' // insert image'."\n";
497 $output .= ' WYSIWYG.insertImage(src, width, height, align, border, alt, hspace, vspace, n);'."\n";
498 $output .= ' window.close();'."\n";
499 $output .= '}'."\n";
500
501 $output .= '// ----------------------------------------------------------------------'."\n";
502 $output .= '// Function: load the settings of a selected image into the form fields'."\n";
503 $output .= '// ---------------------------------------------------------------------- '."\n";
504 $output .= 'function loadImage() {'."\n";
505 $output .= ' var n = WYSIWYG_Popup.getParam(\'wysiwyg\');'."\n";
506 $output .= ' '."\n";
507 $output .= ' // get selection and range'."\n";
508 $output .= ' var sel = WYSIWYG.getSelection(n);'."\n";
509 $output .= ' var range = WYSIWYG.getRange(sel);'."\n";
510 $output .= ' '."\n";
511 $output .= ' // the current tag of range'."\n";
512 $output .= ' var img = WYSIWYG.findParent("img", range);'."\n";
513 $output .= ' '."\n";
514 $output .= ' // if no image is defined then return'."\n";
515 $output .= ' if(img == null) return;'."\n";
516 $output .= ' '."\n";
517 $output .= ' // assign the values to the form elements'."\n";
518 $output .= ' for(var i = 0;i < img.attributes.length;i++) {'."\n";
519 $output .= ' var attr = img.attributes[i].name.toLowerCase();'."\n";
520 $output .= ' var value = img.attributes[i].value;'."\n";
521 $output .= ' //alert(attr + " = " + value);'."\n";
522 $output .= ' if(attr && value && value != "null") {'."\n";
523 $output .= ' switch(attr) {'."\n";
524 $output .= ' case "src": '."\n";
525 $output .= ' // strip off urls on IE'."\n";
526 $output .= ' if(WYSIWYG_Core.isMSIE) value = WYSIWYG.stripURLPath(n, value, false);'."\n";
527 $output .= ' document.getElementById(\'src\').value = value;'."\n";
528 $output .= ' break;'."\n";
529 $output .= ' case "alt":'."\n";
530 $output .= ' document.getElementById(\'alt\').value = value;'."\n";
531 $output .= ' break;'."\n";
532 $output .= ' case "align":'."\n";
533 $output .= ' selectItemByValue(document.getElementById(\'align\'), value);'."\n";
534 $output .= ' break;'."\n";
535 $output .= ' case "border":'."\n";
536 $output .= ' document.getElementById(\'border\').value = value;'."\n";
537 $output .= ' break;'."\n";
538 $output .= ' case "hspace":'."\n";
539 $output .= ' document.getElementById(\'hspace\').value = value;'."\n";
540 $output .= ' break;'."\n";
541 $output .= ' case "vspace":'."\n";
542 $output .= ' document.getElementById(\'vspace\').value = value;'."\n";
543 $output .= ' break;'."\n";
544 $output .= ' case "width":'."\n";
545 $output .= ' document.getElementById(\'width\').value = value;'."\n";
546 $output .= ' break;'."\n";
547 $output .= ' case "height":'."\n";
548 $output .= ' document.getElementById(\'height\').value = value;'."\n";
549 $output .= ' break; '."\n";
550 $output .= ' }'."\n";
551 $output .= ' }'."\n";
552 $output .= ' }'."\n";
553 $output .= ' '."\n";
554 $output .= ' // get width and height from style attribute in none IE browsers'."\n";
555 $output .= ' if(!WYSIWYG_Core.isMSIE && document.getElementById(\'width\').value == "" && document.getElementById(\'width\').value == "") {'."\n";
556 $output .= ' document.getElementById(\'width\').value = img.style.width.replace(/px/, "");'."\n";
557 $output .= ' document.getElementById(\'height\').value = img.style.height.replace(/px/, "");'."\n";
558 $output .= ' }'."\n";
559 $output .= '}'."\n";
560
561 $output .= '// ---------------------------------------------------------------------- '."\n";
562 $output .= '// Function : Select an item of an select box element by value.'."\n";
563 $output .= '// ---------------------------------------------------------------------- '."\n";
564 $output .= 'function selectItemByValue(element, value) {'."\n";
565 $output .= ' if(element.options.length) {'."\n";
566 $output .= ' for(var i=0;i<element.options.length;i++) {'."\n";
567 $output .= ' if(element.options[i].value == value) {'."\n";
568 $output .= ' element.options[i].selected = true;'."\n";
569 $output .= ' }'."\n";
570 $output .= ' }'."\n";
571 $output .= ' }'."\n";
572 $output .= '}'."\n";
573
574 $output .= 'function browseImage() {'."\n";
575 $output .= ' window.open(\''.$base_path.'openwysiwyg/image_browse\', \'browseImage\', \'location=0,status=0,scrollbars=1,width=600,height=500,top=100,left=100\').focus();'."\n";
576 $output .= '}'."\n";
577
578 $output .= '</script>';
579 $output .= '</head>';
580 $output .= '<body bgcolor="#EEEEEE" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" onLoad="loadImage();">';
581
582 $output .= '<table border="0" cellpadding="0" cellspacing="0" style="padding: 10px;"><tr><td>';
583
584 $output .= '<span style="font-size: 11px; font-weight: bold;">Insert Image</span>';
585 $output .= '<table width="380" border="0" cellpadding="0" cellspacing="0" style="background:#F7F7F7; border:2px solid white;padding:5px;">';
586 $output .= ' <tr>';
587 $output .= ' <td style="padding:1px; font-size: 11px;" width="80">Image URL</td>';
588 $output .= ' <td style="padding:1px;" width="260"><input type="text" name="src" id="src" value="" style="font-size: 10px; width:100%;"/></td>';
589 $output .= ' ';
590 $output .= ' <td>';
591 if (user_access('file browse')) {
592 $output .= ' <input type="button" value="Browse" onclick="browseImage();" style="font-size: 12px;" />';
593 }
594 $output .= ' </td>';
595 $output .= ' ';
596 $output .= ' </tr>';
597 $output .= ' <tr>';
598 $output .= ' <td style="padding:1px; font-size: 11px;">Alt Text</td>';
599 $output .= ' <td style="padding:1px;"><input type="text" name="alt" id="alt" value="" style="font-size:10px; width: 100%;"/></td>';
600 $output .= ' <td></td>';
601 $output .= ' </tr>';
602 $output .= '</table>';
603 $output .= ' ';
604
605 $output .= '<table width="380" border="0" cellpadding="0" cellspacing="0" style="margin-top: 10px;"><tr><td style="vertical-align:top;">';
606
607 $output .= '<span style="font-size: 11px; font-weight: bold;">Layout</span>';
608 $output .= '<table width="180" border="0" cellpadding="0" cellspacing="0" style="background: #F7F7F7; border: 2px solid white; padding: 5px;">';
609 $output .= '<tr>';
610 $output .= ' <td style="padding:1px; font-size: 11px;">Width</td>';
611 $output .= ' <td style="width:60px;padding:1px;"><input type="text" name="width" id="width" value="" style="font-size:10px;width:100%;"/></td>';
612 $output .= ' </tr>';
613 $output .= ' <tr>';
614 $output .= ' <td style="padding:1px; font-size: 11px;">Height</td>';
615 $output .= ' <td style="padding:1px;"><input type="text" name="height" id="height" value="" style="font-size:10px;width: 100%;"/></td>';
616 $output .= ' </tr>';
617 $output .= ' <tr>';
618 $output .= ' <td style="padding:1px; font-size: 11px;">Border</td>';
619 $output .= ' <td style="padding:1px;"><input type="text" name="border" id="border" value="0" style="font-size: 10px; width: 100%;"/></td>';
620 $output .= ' </tr>';
621 $output .= '</table> ';
622
623 $output .= '</td>';
624 $output .= '<td width="10">&nbsp;</td>';
625 $output .= '<td style="vertical-align:top;">';
626
627 $output .= '<span style="font-size: 11px; font-weight: bold;">&nbsp;</span>';
628 $output .= '<table width="190" border="0" cellpadding="0" cellspacing="0" style="background: #F7F7F7; border: 2px solid white; padding: 5px;">';
629 $output .= '<tr>';
630 $output .= ' <td style="width: 90px;padding:1px; font-size: 11px;" width="100">Alignment</td>';
631 $output .= ' <td style="width: 95px;padding:1px;">';
632 $output .= ' <select name="align" id="align" style="font-size: 11px; width: 100%;">';
633 $output .= ' <option value="">Not Set</option>';
634 $output .= ' <option value="left">Left</option>';
635 $output .= ' <option value="right">Right</option>';
636 $output .= ' <option value="texttop">Texttop</option>';
637 $output .= ' <option value="absmiddle">Absmiddle</option>';
638 $output .= ' <option value="baseline">Baseline</option>';
639 $output .= ' <option value="absbottom">Absbottom</option>';
640 $output .= ' <option value="bottom">Bottom</option>';
641 $output .= ' <option value="middle">Middle</option>';
642 $output .= ' <option value="top">Top</option>';
643 $output .= ' </select>';
644 $output .= ' </td>';
645 $output .= ' </tr>';
646 $output .= ' <tr>';
647 $output .= ' <td style="padding:1px; font-size: 11px;">H Space</td>';
648 $output .= ' <td style="padding:1px;"><input type="text" name="hspace" id="hspace" value="" style="font-size: 10px; width: 100%;"/></td>';
649 $output .= ' </tr>';
650 $output .= ' <tr>';
651 $output .= ' <td style="padding:1px; font-size: 11px;">V Space</td>';
652 $output .= ' <td style="padding:1px;"><input type="text" name="vspace" id="vspace" value="" style="font-size: 10px; width: 100%;"/></td>';
653 $output .= ' </tr>';
654 $output .= '</table> ';
655
656 $output .= '</td></tr></table>';
657
658 $output .= '<div align="right" style="padding-top: 5px;"><input type="submit" value=" Submit " onClick="insertImage();" style="font-size: 12px;" />&nbsp;<input type="submit" value=" Cancel " onClick="window.close();" style="font-size: 12px;" /></div>';
659
660 $output .= '</td></tr></table>';
661
662 $output .= '</body>';
663 $output .= '</html>';
664 print $output;
665 exit;
666 }
667
668 function openwysiwyg_ow_image_browse($error_msg) {
669 global $user;
670
671 if (!user_access('access openwysiwyg')) { return; }
672
673 if (!user_access('file browse')) {
674 print t("Sorry, you have no 'File Browse' access.")."<hr>";
675 print '<input type="submit" value=" Close " onClick="window.close();" />';
676 exit();
677 }
678
679 $folder_name = $_REQUEST['folder_name'];
680 $sub_folder = $_REQUEST['sub_folder'];
681
682 $uid = $user->uid;
683 $name = $user->name;
684 $base_path = base_path();
685 $openwysiwyg_path = $base_path.drupal_get_path('module', 'openwysiwyg');
686 $files_path = file_directory_path();
687 $openwysiwyg_folder_format = variable_get('openwysiwyg_folder_format', 'u[uid]');
688
689 $openwysiwyg_folder_format = str_replace('[uid]',$uid,$openwysiwyg_folder_format);
690 $openwysiwyg_folder_format = str_replace('[username]',$name,$openwysiwyg_folder_format);
691 $openwysiwyg_folder_format = str_replace('[domainname]',$_SERVER['HTTP_HOST'],$openwysiwyg_folder_format);
692
693 $user_dir = "$files_path/$openwysiwyg_folder_format";
694
695 if ($folder_name=='') {
696 $folder_name = "$files_path/$openwysiwyg_folder_format";
697 //Check and create user folder
698 if (file_exists($folder_name)) {
699 if (!is_dir($folder_name)) { mkdir($folder_name); }
700 } else { mkdir($folder_name); }
701 } else {
702 if ($sub_folder!='') { $folder_name = $folder_name."/".$sub_folder; }
703 if (strpos($folder_name, '/..')) {
704 $folder_name = str_replace('/..','', $folder_name);
705 $pos = 0;
706 while(strpos($folder_name,'/',$pos) ) {
707 $pos++;
708 }
709 if ($pos!=0) { $pos=$pos-1;}
710 $folder_name = substr($folder_name,0,$pos);
711 }
712 }
713 //Folder manager
714 if (!user_access('folder manage')) {
715 if (!strpos($dir,$user_dir)) {
716 $error_msg = t("Sorry, you have no 'folder manage' access, you only can browse to your own folder.");
717 $folder_name = $user_dir;
718 }
719 }
720
721 $dir = $folder_name;
722
723 //Form of Image Browse
724 $output = '';
725 $output .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
726
727 $output .= '<html>';
728 $output .= '<head>';
729 $output .= '<title>openWYSIWYG | Insert or Modify Image</title>';
730
731 $output .= '<style media="all" type="text/css">';
732 $output .= '@import "'.$openwysiwyg_path.'/library/styles/'.variable_get("openwysiwyg_style","openwysiwyg.css").'";';
733 $output .= '</style>';
734 $output .= '<script language="JavaScript" type="text/javascript">';
735
736 $output .= '// ----------------------------------------------------------------------'."\n";
737 $output .= '// Function : Inserts image into the WYSIWYG.'."\n";
738 $output .= '// ----------------------------------------------------------------------'."\n";
739
740 $output .= "function fillImageForm(imgS,imgW,imgH) { \n";
741 $output .= " window.opener.GetValueFromChild(imgS,imgW,imgH); \n";
742 $output .= " window.close(); \n";
743 $output .= " return false; \n";
744 $output .= "}\n\n";
745
746 $output .= "function confSubmit(form) { \n";
747 $output .= " if (confirm('Are you sure?')) { \n";
748 $output .= " form.submit(); \n";
749 $output .= " }\n";
750 $output .= "}\n\n";
751
752 $output .= '</script>';
753 $output .= '</head>';
754 $output .= '<body bgcolor="#EEEEEE">';
755
756 if ($error_msg) { $output .= "<div id='error_msg'>$error_msg</div>"; }
757
758 //Folder Navigation
759 $output .= "<form action='".url("openwysiwyg/image_browse")."' name='folder_nav' id='folder_nav' method='post' style='margin-bottom:2px;'>";
760 $output .= '<table border=0 width="100%" style="border:solid 2px #FFF; background:#F7F7F7;">';
761 $output .= '<tr>';
762 $output .= '<td style="font-size: 11px;">';
763 $output .= t('Current Folder').": $folder_name".' <select name="sub_folder" id="sub_folder" style="font-size: 11px;">';
764 foreach (list_dir($dir) as $value) {
765 $output .= " <option value='$value' ".($value==$sub_folder ? " selected='selected'" : '').">$value</option>";
766 }
767 $output .= '</select>';
768 $output .= '<input type="submit" value="Change folder" style="font-size: 11px;"/>';
769 $output .= '<input type="hidden" name="folder_name" value="'. $folder_name.'" />';
770 $output .= '<input type="hidden" name="token" value="'. $token .'" />';
771 $output .= '</td>';
772 $output .= '</tr>';
773 $output .= '</table>';
774 $output .= '</form>';
775
776 //Folder create
777 if (user_access('folder create')) {
778 $output .= '<form name="folder_create" action="'.url("openwysiwyg/folder_create").'" method="post" id="folder_create" enctype="multipart/form-data" style="margin-bottom:2px;">';
779 $output .= '<table border=0 width="100%" style="border:solid 2px #FFF; background:#F7F7F7;">';
780 $output .= '<tr>';
781 $output .= '<td style="font-size: 11px;">'.t('Sub folder name').'</td>';
782 // $output . = '<input type="hidden" name="token" value="'. $token .'" />';
783 $output .= "<input type='hidden' name='folder_name' value='$folder_name' />";
784 $output .= '<td><input type="text" name="new_folder" id="new_folder" value="" style="font-size: 11px;width:100%"/></td>';
785 $output .= '<td><input type="submit" name="folder_create" value="'.t('Create sub folder').'" style="font-size: 11px;"/></td>';
786 $output .= '</tr>';
787 $output .= '</table>';
788 $output .= '</form>';
789 }
790
791 if (user_access('file upload')) {
792 $output .= '<form name="form_upload" action="'.url("openwysiwyg/file_upload").'" method="post" id="uploadform" enctype="multipart/form-data">';
793 $output .= '<table border=0 width="100%" style="border:solid 2px #FFF; background:#F7F7F7;">';
794 $output .= '<tr>';
795 $output .= '<td style="font-size: 11px;">'.t('File to upload').'</td>';
796 $output .= '<td><input type="file" name="file_upload" id="file_upload" size=25 style="font-size: 11px;"/></td>';
797 $output .= "<input type='hidden' name='folder_name' value='$folder_name' />";
798 //$output .= '<input type="hidden" name="sub_folder" value="'. $sub_folder .'" />';
799 $output .= '<td><input type="submit" name="file_upload" value="'.t('Upload Now').'" style="font-size: 11px;"/></td>';
800 $output .= '</tr>';
801 $output .= '</table>';
802 $output .= '</form>';
803 }
804
805 if(is_dir($dir)) {
806 if($handle = opendir($dir)) {
807 $output .= "<table cellspacing=0 style='border:solid 2px #AAAAAA;' width='100%'>";
808 $output .= "<tr bgcolor='#B4B4B4'>";
809 $output .= "<td style='font-size: 11px;'><b>#</b></td>";
810 $output .= "<td style='font-size: 11px;'><b>FILE NAME</b></td>";
811 $output .= "<td style='font-size: 11px;' align='right' width='100'><b>SIZE (KB)</b></td>";
812 $output .= "<td style='font-size: 11px;' align='right'><b>DIMENSION</b></td>";
813 $output .= "<td style='font-size: 11px;' align='center' colspan='3'><b>ACTION</b></td>";
814 $output .= "</tr>";
815 $folder_size = 0;
816 $i = 0;
817 while(($file = readdir($handle)) !== false) {
818 if(!is_dir("$dir/$file") && $file != "." && $file != ".." && $file != "Thumbs.db" && $file!=".htaccess") {
819 $i++;
820 if ($i % 2) { $bgcolor='#FFFFFF';} else { $bgcolor="#DDDDDD";}
821 $output .= "<tr bgcolor='$bgcolor'>";
822 $file_path = "$dir/$file";
823 $file_url = "$base_path$dir/$file";
824 $file_size = number_format(filesize($file_path)/1024,1);
825 $folder_size += $file_size;
826 list($imgW,$imgH) = @getimagesize($file_path);
827 $output .= "<td style='font-size: 11px;' align='right'>$i.</td>";
828 $output .= "<td style='font-size: 11px;'>$file</td>";
829 $output .= "<td style='font-size: 11px;' align='right'>$file_size </td>";
830 $output .= "<td style='font-size: 11px;' align='right'>$imgW x $imgH &nbsp;</td>";
831
832 $output .= "<td style='font-size: 11px;margin:0;padding:0;' align='center' width=10 valign='center'>";
833 $output .= "<form name='form_insert' method='post' style='margin:0;'>";
834 $output .= "<input type='submit' value='Insert' onClick=\"fillImageForm('$file_url',$imgW,$imgH); return false;\" style='font-size:11px;' />";
835 $output .= '</form>';
836 $output .= "</td>";
837
838 if (user_access('file delete')) {
839 $output .= "<td style='font-size: 11px;' align='center' width=10>";
840 $output .= "<form action='".url('openwysiwyg/file_delete')."' method='post' style='margin:0;'>";
841 $output .= "<input type='hidden' name='folder_name' value='$folder_name' />";
842 $output .= "<input type='hidden' name='file_name' value='$file' />";
843 $output .= '<input type="button" value="Delete" onclick="confSubmit(this.form);" style="font-size: 11px;">';
844 $output .= '</form>';
845 $output .= "</td>";
846 }
847
848 if (user_access('file resize')) {
849 $output .= "<td style='font-size: 11px;' align='center' width=10>";
850 $output .= "<form action='".url('openwysiwyg/file_resize_form')."' method='post' style='margin:0;'>";
851 $output .= '<input type="submit" name="resize" value="'.t('Resize').'" style="font-size: 11px;"/>';
852 $output .= "<input type='hidden' name='folder_name' value='$folder_name' />";
853 $output .= "<input type='hidden' name='file_name' value='$file' />";
854 $output .= '</form></td>';
855 }
856
857 $output .= "</tr>";
858 }
859 }
860 $output .= "<tr bgcolor='#B4B4B4'>";
861 $output .= "<td style='font-size: 11px;'>&nbsp;</td>";
862 $output .= "<td style='font-size: 11px;' align='right'>Total</td>";
863 $output .= "<td style='font-size: 11px;' align='right'>".number_format($folder_size,1)."</td>";
864 $output .= "<td style='font-size: 11px;'>&nbsp;</td>";
865 $output .= "<td style='font-size: 11px;' align='center' colspan='3'>&nbsp;</td>";
866 $output .= "</tr>";
867 $output .= "</table>";
868 $output .= '</body>';
869 $output .= '</html>';
870 closedir($handle);
871
872 print $output;
873 exit();
874 }
875 }
876 }
877
878 function openwysiwyg_ow_file_delete() {
879 $folder_name = $_REQUEST['folder_name'];
880 $file_name = $_REQUEST['file_name'];
881
882 if (!user_access('access openwysiwyg') || !user_access('file delete')) { return; }
883
884 if (file_delete("$folder_name/$file_name")) {
885 $error_msg = t("Success. File '$file_name' deleted.");
886 } else {
887 $error_msg = t("Error deleting file: $folder_name/$file_name");
888 }
889 openwysiwyg_ow_image_browse($error_msg);
890 }
891
892 function openwysiwyg_ow_file_upload() {
893 $folder_name = $_REQUEST['folder_name'];
894 $files = $_FILES['file_upload'];
895
896 if (!user_access('access openwysiwyg') || !user_access('file upload')) { return; }
897
898 $file_name = $files["name"];
899 //File exists
900 if (file_exists("$folder_name/$file_name")) {
901 $error_msg = t("Error. The '$file_name' already exists.");
902 openwysiwyg_ow_image_browse($error_msg);return;
903 }
904 //File Extension
905 $pos = 0;
906 while( strpos($file_name,'.',$pos) ) {
907 $pos++;
908 }
909 if ($pos<>0) { $pos= $pos-1; }
910 $values = strtolower(str_replace(' ','',variable_get('openwysiwyg_file_extension','')));
911 if ($values<>'') {
912 $values_arr = split(',',$values);
913 $file_extension = substr($file_name,$pos);
914
915 if(!in_array($file_extension,$values_arr)) {
916 $error_msg = t("Error. File extension disallowed: $file_extension");
917 openwysiwyg_ow_image_browse($error_msg);
918 return;
919 }
920 }
921
922 //File dimension
923 $openwysiwyg_image_dimension = strtoupper(trim(variable_get('openwysiwyg_image_dimension','480x480')));
924 $pos=0;
925 $image_max_w = substr($openwysiwyg_image_dimension,0,$pos=strpos($openwysiwyg_image_dimension,'X',$pos));
926 $image_max_h = substr($openwysiwyg_image_dimension,$pos+1);
927
928 list($imgW,$imgH) = @getimagesize($files['tmp_name']);
929 if ($openwysiwyg_image_dimension<>'' && ($imgW > $image_max_w || $imgH > $image_max_h)) {
930 $image_max_h = ceil($imgH/$imgW * $image_max_w);
931 if (!image_resize($files['tmp_name'], "$folder_name/$file_name", $image_max_w, $image_max_h)) {
932 $error_msg = t("Error. Can not resize file to $image_max_w x $image_max_h");
933 openwysiwyg_ow_image_browse($error_msg);
934 return;
935 }
936 } else {
937 //File move
938 if (!move_uploaded_file($files["tmp_name"],"$folder_name/$file_name")) {
939 $error_msg = t("Error. Invalid file");
940 openwysiwyg_ow_image_browse($error_msg);
941 return;
942 }
943 }
944 //File size
945 $openwysiwyg_file_size = variable_get('openwysiwyg_file_size', '0');
946 if ($openwysiwyg_file_size) {
947 $upload_size= ceil(filesize("$folder_name/$file_name")/1024);
948 if ($upload_size > $openwysiwyg_file_size) {
949 $error_msg = t("Error. Your file is: $upload_size KB. Maximum file size is: $openwysiwyg_file_size KB");
950 file_delete("$folder_name/$file_name");
951 openwysiwyg_ow_image_browse($error_msg);
952 return;
953 }
954 }
955
956 $error_msg = t("Success. File '$file_name' uploaded");
957 openwysiwyg_ow_image_browse($error_msg);
958 return;
959 }
960
961 function list_dir($base_dir) {
962 if(!is_dir($base_dir)) { return; }
963
964 if($handle = opendir($base_dir)) {
965 $result = array();
966 while(($file = readdir($handle)) !== false) {
967 if(is_dir("$base_dir/$file") && $file<>'.') { $result[] .= $file; }
968 }
969 }
970 return $result;
971 }
972
973 function openwysiwyg_ow_folder_create() {
974 global $user;
975
976 $folder_name = $_REQUEST['folder_name'];
977 $sub_folder = $_REQUEST['sub_folder'];
978 $new_folder = $_REQUEST['new_folder'];
979
980 //print "Folder= $folder_name Sub-folder= $sub_folder New-folder = $new_folder";
981 //exit();
982
983 if (!user_access('access openwysiwyg') || !user_access('folder create')) { return; }
984
985 $error_msg ='';
986 if ($new_folder=='') { openwysiwyg_ow_image_browse($error_msg); }
987
988 $uid = $user->uid;
989 $base_path = base_path();
990 $files_path = file_directory_path();
991
992 $openwysiwyg_folder_format = variable_get('openwysiwyg_folder_format', 'u[uid]');
993 $openwysiwyg_folder_format = str_replace('[uid]',$uid,$openwysiwyg_folder_format);
994 $openwysiwyg_folder_format = str_replace('[username]',$name,$openwysiwyg_folder_format);
995 $openwysiwyg_folder_format = str_replace('[domainname]',$_SERVER['HTTP_HOST'],$openwysiwyg_folder_format);
996
997 $user_dir = "$files_path/$openwysiwyg_folder_format";
998 $dir = "$folder_name/$new_folder";
999
1000 //Security check
1001 if (strpos($dir,'..')) {
1002 print t("Sorry. Invalid sub folder name.")."<hr>";
1003 print '<input type="submit" value=" Close " onClick="window.close();" />';
1004 exit();
1005 }
1006 //Folder manager
1007 if (!user_access('folder manage')) {
1008 if (!strpos($dir,$user_dir)) {
1009 print t("Sorry, you have no 'folder manage' access, you only can create folder into your own folder.");
1010 exit();
1011 }
1012 }
1013
1014 //Check and create user sub folder
1015 $success = false;
1016 if (file_exists("$dir")) {
1017 if (is_dir("$dir")) {
1018 $error_msg = t("Error. Sub folder '$new_folder' already exists.");
1019 } else {
1020 if (mkdir($dir)) {
1021 $success = true;
1022 $error_msg = t("Success. Create sub folder: $new_folder");
1023 } else {
1024 $error_msg = __line__.": ".t("Error. Can not create sub folder: $new_folder");
1025 }
1026 }
1027 } else {
1028 if (mkdir($dir)) {
1029 $success = true;
1030 $error_msg = t("Success. Create sub folder: $new_folder");
1031 } else {
1032 $error_msg = __line__.": ".t("Error. Can not create sub folder: $new_folder");
1033 }
1034 }
1035 openwysiwyg_ow_image_browse($error_msg);
1036 }
1037
1038 function openwysiwyg_ow_file_resize_form() {
1039 $folder_name = $_REQUEST['folder_name'];
1040 $file_name = $_REQUEST['file_name'];
1041
1042 $openwysiwyg_file_resize_width = variable_get('openwysiwyg_file_resize_width', '100');
1043 $openwysiwyg_file_resize_height = variable_get('openwysiwyg_file_resize_height', '');
1044
1045 $output = '';
1046 $output .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
1047 $output .= '<html>';
1048 $output .= '<head>';