| 1 |
<?php
|
| 2 |
/* $Id: whizzywig.module,v 1.20 2009/10/28 23:46:11 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 whizzywig_help($section='') {
|
| 10 |
switch ($section) {
|
| 11 |
case 'admin/settings/help#description':
|
| 12 |
case "admin/help#whizzywig":
|
| 13 |
$output = t("Enables whizzywig WYSIWYG editor.");
|
| 14 |
break;
|
| 15 |
}
|
| 16 |
return $output;
|
| 17 |
}
|
| 18 |
|
| 19 |
// Valid permissions for this module
|
| 20 |
function whizzywig_perm() {
|
| 21 |
return array('access whizzywig', 'administer whizzywig',
|
| 22 |
'file browse', 'file delete', 'file upload','file resize',
|
| 23 |
'folder create', 'folder delete', 'folder manage',
|
| 24 |
'toolbar buttons: full', 'toolbar buttons: custom');
|
| 25 |
}
|
| 26 |
|
| 27 |
// Implementation of hook_menu().
|
| 28 |
function whizzywig_menu() {
|
| 29 |
$items = array();
|
| 30 |
|
| 31 |
$items['admin/settings/whizzywig'] = array(
|
| 32 |
'title' => 'Whizzywig',
|
| 33 |
'description' => 'Enables whizzywig.',
|
| 34 |
'access arguments' => array('administer whizzywig'),
|
| 35 |
'page callback' => 'drupal_get_form',
|
| 36 |
'page arguments' => array('whizzywig_admin_settings'),
|
| 37 |
'type' => MENU_NORMAL_ITEM,
|
| 38 |
'file' => 'whizzywig.settings.inc',
|
| 39 |
);
|
| 40 |
|
| 41 |
$items['admin/settings/whizzywig/settings'] = array(
|
| 42 |
'title' => 'Basic Settings',
|
| 43 |
'access arguments' => array('administer whizzywig'),
|
| 44 |
'weight' => -10,
|
| 45 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 46 |
'file' => 'whizzywig.settings.inc',
|
| 47 |
);
|
| 48 |
|
| 49 |
$items['admin/settings/whizzywig/visibility'] = array(
|
| 50 |
'title' => 'Visibility',
|
| 51 |
'description' => 'whizzywig Visibility',
|
| 52 |
'access arguments' => array('administer whizzywig'),
|
| 53 |
'page callback' => 'drupal_get_form',
|
| 54 |
'page arguments' => array('whizzywig_settings_visibility'),
|
| 55 |
'type' => MENU_LOCAL_TASK,
|
| 56 |
'file' => 'whizzywig.settings.inc',
|
| 57 |
);
|
| 58 |
|
| 59 |
$items['admin/settings/whizzywig/browser'] = array(
|
| 60 |
'title' => 'File Browser',
|
| 61 |
'description' => 'Whizzywig File Browser',
|
| 62 |
'access arguments' => array('administer whizzywig'),
|
| 63 |
'page callback' => 'drupal_get_form',
|
| 64 |
'page arguments' => array('whizzywig_settings_file_browser'),
|
| 65 |
'type' => MENU_LOCAL_TASK,
|
| 66 |
'file' => 'whizzywig.settings.inc',
|
| 67 |
);
|
| 68 |
|
| 69 |
//File Browse
|
| 70 |
$items['whizzywig/image_browse'] = array(
|
| 71 |
'access arguments' => array('access whizzywig'),
|
| 72 |
'page callback' => 'whizzywig_ow_image_browse',
|
| 73 |
//'page arguments' => $folder_name,$sub_folder,$error_msg,
|
| 74 |
'page arguments' => array($error_msg),
|
| 75 |
'type' => MENU_CALLBACK,
|
| 76 |
);
|
| 77 |
|
| 78 |
//File Delete
|
| 79 |
|
| 80 |
$items['whizzywig/file_delete'] = array(
|
| 81 |
'access arguments' => array('access whizzywig'),
|
| 82 |
'page callback' => 'whizzywig_ow_file_delete',
|
| 83 |
'type' => MENU_CALLBACK,
|
| 84 |
);
|
| 85 |
|
| 86 |
//Folder create
|
| 87 |
$items['whizzywig/folder_create'] = array(
|
| 88 |
'access arguments' => array('access whizzywig'),
|
| 89 |
'page callback' => 'whizzywig_ow_folder_create',
|
| 90 |
//'page arguments' => $folder_name, $sub_folder, $new_folder,
|
| 91 |
'type' => MENU_CALLBACK,
|
| 92 |
);
|
| 93 |
|
| 94 |
//File Upload
|
| 95 |
$items['whizzywig/file_upload'] = array(
|
| 96 |
'access arguments' => array('access whizzywig'),
|
| 97 |
'page callback' => 'whizzywig_ow_file_upload',
|
| 98 |
//'page arguments' => $_REQUEST['folder_name'],$_FILES['file_upload'],
|
| 99 |
'type' => MENU_CALLBACK,
|
| 100 |
);
|
| 101 |
|
| 102 |
//Image Resize Form
|
| 103 |
$items['whizzywig/file_resize_form'] = array(
|
| 104 |
'access arguments' => array('access whizzywig'),
|
| 105 |
'page callback' => 'whizzywig_ow_file_resize_form',
|
| 106 |
//'page arguments' => $folder_name,$file_name,
|
| 107 |
'type' => MENU_CALLBACK,
|
| 108 |
);
|
| 109 |
|
| 110 |
//Image Resize Action
|
| 111 |
$items['whizzywig/file_resize_action'] = array(
|
| 112 |
'access arguments' => array('access whizzywig'),
|
| 113 |
'page callback' => 'whizzywig_ow_file_resize_action',
|
| 114 |
//'page arguments' => $folder_name, $file_name,$resize_width,$resize_height,$resize_name,
|
| 115 |
'type' => MENU_CALLBACK,
|
| 116 |
);
|
| 117 |
|
| 118 |
return $items;
|
| 119 |
}
|
| 120 |
|
| 121 |
/**
|
| 122 |
* Implementation of hook_elements() to show the whizzywig editor when a textarea is loaded
|
| 123 |
*/
|
| 124 |
function whizzywig_elements(){
|
| 125 |
$type = array();
|
| 126 |
if (user_access('access whizzywig')) {
|
| 127 |
$type['textarea'] = array('#process' => array('whizzywig_process_textarea'));
|
| 128 |
}
|
| 129 |
return $type;
|
| 130 |
}
|
| 131 |
|
| 132 |
/**
|
| 133 |
* Implementation of hook_form_alter()
|
| 134 |
*/
|
| 135 |
function whizzywig_form_alter(&$form, &$form_state) {
|
| 136 |
// disable 'teaser' textarea
|
| 137 |
unset($form['body_field']['teaser_js']);
|
| 138 |
$form['body_field']['teaser_include'] = array();
|
| 139 |
}
|
| 140 |
|
| 141 |
// Modify the textarea to show whizzywig editor if certain conditions are met.
|
| 142 |
// function whizzywig_change_textarea($element) , whizzywig_process_textarea {
|
| 143 |
|
| 144 |
function whizzywig_process_textarea($element) {
|
| 145 |
//static $whizzywig_ready = FALSE;
|
| 146 |
|
| 147 |
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2)=='edit') {
|
| 148 |
$node = node_load(arg(1));
|
| 149 |
$form_type = $node->type;
|
| 150 |
}
|
| 151 |
if (arg(0) == 'node' && arg(1)=='add') {
|
| 152 |
$form_type = str_replace('-','_',arg(2));
|
| 153 |
}
|
| 154 |
|
| 155 |
$whizzywig_enable = 0;
|
| 156 |
|
| 157 |
if(_whizzywig_validate_element_id($element["#id"]) && _whizzywig_validate_content_type($form_type) && _whizzywig_allowed_pages()) {
|
| 158 |
$whizzywig_enable= 1;
|
| 159 |
} else {
|
| 160 |
$whizzywig_comment = variable_get('whizzywig_comment', 0);
|
| 161 |
if ($whizzywig_comment && arg(0)=='comment') {
|
| 162 |
$whizzywig_enable= 1;
|
| 163 |
}
|
| 164 |
}
|
| 165 |
|
| 166 |
if ($whizzywig_enable) {
|
| 167 |
if (!$whizzywig_ready) {
|
| 168 |
// get the path for the buttom images
|
| 169 |
$whizzywig_path = base_path().drupal_get_path('module', 'whizzywig');
|
| 170 |
$base_path = base_path();
|
| 171 |
$buttonpath = $whizzywig_path.'/library/buttons/';
|
| 172 |
|
| 173 |
//$buttonpath = base_path() . drupal_get_path('module', 'whizzywig') .'/whizzywig/buttons/';
|
| 174 |
//$PopupsDir = $whizzywig_path.'/library/popups/';
|
| 175 |
// add the whizzywig js library
|
| 176 |
drupal_add_js(drupal_get_path('module','whizzywig').'/library/whizzywig.js');
|
| 177 |
//drupal_add_css(drupal_get_path('module','whizzywig')."/library/".variable_get("whizzywig_style","whizzywig.css"))
|
| 178 |
|
| 179 |
$whizzywig_ready = TRUE;
|
| 180 |
}
|
| 181 |
//$script = "mysettings.Toolbar[0] = new Array(". $buttons1 .");\n";
|
| 182 |
//disable resize script
|
| 183 |
$element['#resizable'] = FALSE;
|
| 184 |
|
| 185 |
//set the width & height of the textarea, so whizzywig can inherit this
|
| 186 |
$editor_width = variable_get('whizzywig_editor_width', '100%');
|
| 187 |
$editor_height = variable_get('whizzywig_editor_height', 0);
|
| 188 |
if($editor_height != 0){
|
| 189 |
// set both
|
| 190 |
$element['#attributes'] = array('style' => "width: $editor_width; height: $editor_height;");
|
| 191 |
}else{
|
| 192 |
// only set width
|
| 193 |
$element['#attributes'] = array('style' => "width: $editor_width;");
|
| 194 |
}
|
| 195 |
|
| 196 |
// initialize whizzywig
|
| 197 |
$buttons = "all";
|
| 198 |
$element_id = $element['#id'];
|
| 199 |
$toolbarpath = $whizzywig_path . "/library/WhizzywigToolbar.png";
|
| 200 |
|
| 201 |
// initialize Whizzywig
|
| 202 |
// imageBrowse="/devel/sites/all/modules/whizzywig/library/whizzypic.php";
|
| 203 |
// imageBrowse = \"".base_path()."whizzywig/image_browse\";
|
| 204 |
$imageBrowse = "$whizzywig_path/library/whizzypic.php?d=".$base_path."sites/default/files";
|
| 205 |
$element['#suffix'] .= "\n<script type=\"text/javascript\">
|
| 206 |
buttonPath = \"$whizzywig_path/library/buttons/\";
|
| 207 |
btn._f = \"$whizzywig_path/library/WhizzywigToolbar.png\";
|
| 208 |
imageBrowse = \"".base_path()."whizzywig/image_browse\";
|
| 209 |
makeWhizzyWig(\"$element_id\", \"$buttons\");
|
| 210 |
</script>\n";
|
| 211 |
|
| 212 |
}
|
| 213 |
return $element;
|
| 214 |
}
|
| 215 |
|
| 216 |
// Validation against textarea ID filters.
|
| 217 |
function _whizzywig_validate_element_id($id){
|
| 218 |
$valid = false;
|
| 219 |
// when returned valid, the whizzywig editor will be shown
|
| 220 |
$values = strtolower(str_replace(' ','',variable_get('whizzywig_textarea_id_val','edit-teaser,edit-body')));
|
| 221 |
$values_arr = split(',',$values);
|
| 222 |
// exclude some textfields that we need on the settings page from showing the editor
|
| 223 |
array_push($values_arr,'edit-whizzywig-textarea-id-val');
|
| 224 |
array_push($values_arr,'edit-whizzywig-visibility-path-val');
|
| 225 |
array_push($values_arr,'edit-whizzywig-toolbar-buttons-list');
|
| 226 |
if(variable_get('whizzywig_textarea_id',1) == 0){
|
| 227 |
// don't show editor if id is found in values
|
| 228 |
if(!in_array($id,$values_arr)){
|
| 229 |
$valid = true;
|
| 230 |
}
|
| 231 |
}else{
|
| 232 |
// only show editor if id is found in values
|
| 233 |
if(in_array($id,$values_arr)){
|
| 234 |
$valid = true;
|
| 235 |
}
|
| 236 |
}
|
| 237 |
return $valid;
|
| 238 |
}
|
| 239 |
|
| 240 |
// Validation against content-type filters.
|
| 241 |
function _whizzywig_validate_content_type($content_type){
|
| 242 |
$valid = false;
|
| 243 |
// when returned valid, the whizzywig editor will be shown
|
| 244 |
$values = strtolower(str_replace(' ','',variable_get('whizzywig_content_type_val','page')));
|
| 245 |
$values_arr = split(',',$values);
|
| 246 |
// exclude some textfields that we need on the settings page from showing the editor
|
| 247 |
array_push($values_arr,'edit-whizzywig-textarea-id-val');
|
| 248 |
array_push($values_arr,'edit-whizzywig-visibility-path-val');
|
| 249 |
array_push($values_arr,'edit-whizzywig-toolbar-buttons-list');
|
| 250 |
if(variable_get('whizzywig_content_type',1) == 0){
|
| 251 |
// don't show editor if id is found in values
|
| 252 |
if(!in_array($content_type,$values_arr)){$valid = true;}
|
| 253 |
}else{
|
| 254 |
// only show editor if id is found in values
|
| 255 |
if(in_array($content_type,$values_arr)){$valid = true;}
|
| 256 |
}
|
| 257 |
return $valid;
|
| 258 |
}
|
| 259 |
|
| 260 |
// Validation against pages filters.
|
| 261 |
function _whizzywig_allowed_pages() {
|
| 262 |
$whizzywig_page = variable_get('whizzywig_page','0');
|
| 263 |
$values = strtolower(str_replace(' ','',variable_get('whizzywig_page_val','')));
|
| 264 |
|
| 265 |
if ($whizzywig_page < 2) {
|
| 266 |
$path = drupal_get_path_alias($_GET['q']);
|
| 267 |
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($values, '/')) .')$/';
|
| 268 |
// Compare with the internal and path alias (if any).
|
| 269 |
$page_match = preg_match($regexp, $path);
|
| 270 |
if ($path != $_GET['q']) {
|
| 271 |
$page_match = $page_match || preg_match($regexp, $_GET['q']);
|
| 272 |
}
|
| 273 |
// When $block->visibility has a value of 0, the block is displayed on
|
| 274 |
// all pages except those listed in $block->pages. When set to 1, it
|
| 275 |
// is displayed only on those pages listed in $block->pages.
|
| 276 |
$page_match = !($whizzywig_page xor $page_match);
|
| 277 |
} else {
|
| 278 |
$page_match = drupal_eval($values);
|
| 279 |
}
|
| 280 |
return $page_match;
|
| 281 |
}
|
| 282 |
|
| 283 |
function whizzywig_ow_image_browse($error_msg) {
|
| 284 |
global $user;
|
| 285 |
$form_id_name = $_GET['rtn'];
|
| 286 |
|
| 287 |
if (!user_access('access whizzywig')) { return; }
|
| 288 |
|
| 289 |
if (!user_access('file browse')) {
|
| 290 |
print t("Sorry, you have no 'File Browse' access.")."<hr>";
|
| 291 |
print '<input type="submit" value=" Close " onClick="window.close();" />';
|
| 292 |
exit();
|
| 293 |
}
|
| 294 |
|
| 295 |
$folder_name = $_REQUEST['folder_name'];
|
| 296 |
$sub_folder = $_REQUEST['sub_folder'];
|
| 297 |
|
| 298 |
$uid = $user->uid;
|
| 299 |
$name = $user->name;
|
| 300 |
$base_path = base_path();
|
| 301 |
$whizzywig_path = $base_path.drupal_get_path('module', 'whizzywig');
|
| 302 |
$files_path = file_directory_path();
|
| 303 |
$whizzywig_folder_format = variable_get('whizzywig_folder_format', 'u[uid]');
|
| 304 |
|
| 305 |
$whizzywig_folder_format = str_replace('[uid]',$uid,$whizzywig_folder_format);
|
| 306 |
$whizzywig_folder_format = str_replace('[username]',$name,$whizzywig_folder_format);
|
| 307 |
$whizzywig_folder_format = str_replace('[domainname]',$_SERVER['HTTP_HOST'],$whizzywig_folder_format);
|
| 308 |
|
| 309 |
$user_dir = "$files_path/$whizzywig_folder_format";
|
| 310 |
|
| 311 |
if ($folder_name=='') {
|
| 312 |
$folder_name = "$files_path/$whizzywig_folder_format";
|
| 313 |
//Check and create user folder
|
| 314 |
if (file_exists($folder_name)) {
|
| 315 |
if (!is_dir($folder_name)) { mkdir($folder_name); }
|
| 316 |
} else { mkdir($folder_name); }
|
| 317 |
} else {
|
| 318 |
if ($sub_folder!='') { $folder_name = $folder_name."/".$sub_folder; }
|
| 319 |
if (strpos($folder_name, '/..')) {
|
| 320 |
$folder_name = str_replace('/..','', $folder_name);
|
| 321 |
$pos = 0;
|
| 322 |
while(strpos($folder_name,'/',$pos) ) {
|
| 323 |
$pos++;
|
| 324 |
}
|
| 325 |
if ($pos!=0) { $pos=$pos-1;}
|
| 326 |
$folder_name = substr($folder_name,0,$pos);
|
| 327 |
}
|
| 328 |
}
|
| 329 |
//Folder manager
|
| 330 |
if (!user_access('folder manage')) {
|
| 331 |
if (!strpos($dir,$user_dir)) {
|
| 332 |
$error_msg = t("Sorry, you have no 'folder manage' access, you only can browse to your own folder.");
|
| 333 |
$folder_name = $user_dir;
|
| 334 |
}
|
| 335 |
}
|
| 336 |
|
| 337 |
$dir = $folder_name;
|
| 338 |
|
| 339 |
//Form of Image Browse
|
| 340 |
$output = '';
|
| 341 |
$output .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
|
| 342 |
|
| 343 |
$output .= '<html>';
|
| 344 |
$output .= '<head>';
|
| 345 |
$output .= '<title>whizzywig | Insert or Modify Image</title>';
|
| 346 |
|
| 347 |
$output .= '<style media="all" type="text/css">';
|
| 348 |
$output .= '@import "'.$whizzywig_path.'/library/styles/'.variable_get("whizzywig_style","whizzywig.css").'";';
|
| 349 |
$output .= '</style>';
|
| 350 |
$output .= '<script language="JavaScript" type="text/javascript">';
|
| 351 |
|
| 352 |
//$output .= "function GetValueFromChild(imgS,imgW,imgH) { \n";
|
| 353 |
//$output .= " document.getElementById('if_urledit-body').value = imgS; \n";
|
| 354 |
//$output .= " document.getElementById('width').value = imgW; \n";
|
| 355 |
//$output .= " document.getElementById('height').value = imgH; \n";
|
| 356 |
//$output .= "} \n\n";
|
| 357 |
|
| 358 |
$output .= '// ----------------------------------------------------------------------'."\n";
|
| 359 |
$output .= '// Function : Inserts image into the WYSIWYG.'."\n";
|
| 360 |
$output .= '// ----------------------------------------------------------------------'."\n";
|
| 361 |
|
| 362 |
$output .= "function fillImageForm(imgS,imgW,imgH) { \n";
|
| 363 |
|
| 364 |
$output .= " window.opener.document.getElementById('".$form_id_name."').value = imgS; \n";
|
| 365 |
//$output .= " window.opener.GetValueFromChild(imgS,imgW,imgH); \n";
|
| 366 |
$output .= " window.close(); \n";
|
| 367 |
$output .= " return false; \n";
|
| 368 |
$output .= "}\n\n";
|
| 369 |
|
| 370 |
$output .= "function confSubmit(form) { \n";
|
| 371 |
$output .= " if (confirm('Are you sure?')) { \n";
|
| 372 |
$output .= " form.submit(); \n";
|
| 373 |
$output .= " }\n";
|
| 374 |
$output .= "}\n\n";
|
| 375 |
|
| 376 |
$output .= '</script>';
|
| 377 |
$output .= '</head>';
|
| 378 |
$output .= '<body bgcolor="#EEEEEE">';
|
| 379 |
|
| 380 |
if ($error_msg) { $output .= "<div id='error_msg'>$error_msg</div>"; }
|
| 381 |
|
| 382 |
//Folder Navigation
|
| 383 |
$output .= "<form action='".url("whizzywig/image_browse")."' name='folder_nav' id='folder_nav' method='post' style='margin-bottom:2px;'>";
|
| 384 |
$output .= '<table border=0 width="100%" style="border:solid 2px #FFF; background:#F7F7F7;">';
|
| 385 |
$output .= '<tr>';
|
| 386 |
$output .= '<td style="font-size: 11px;">';
|
| 387 |
$output .= t('Current Folder').": $folder_name".' <select name="sub_folder" id="sub_folder" style="font-size: 11px;">';
|
| 388 |
foreach (whizzywig_list_dir($dir) as $value) {
|
| 389 |
$output .= " <option value='$value' ".($value==$sub_folder ? " selected='selected'" : '').">$value</option>";
|
| 390 |
}
|
| 391 |
$output .= '</select>';
|
| 392 |
$output .= '<input type="submit" value="Change folder" style="font-size: 11px;"/>';
|
| 393 |
$output .= '<input type="hidden" name="folder_name" value="'. $folder_name.'" />';
|
| 394 |
$output .= '<input type="hidden" name="token" value="'. $token .'" />';
|
| 395 |
$output .= '</td>';
|
| 396 |
$output .= '</tr>';
|
| 397 |
$output .= '</table>';
|
| 398 |
$output .= '</form>';
|
| 399 |
|
| 400 |
//Folder create
|
| 401 |
if (user_access('folder create')) {
|
| 402 |
$output .= '<form name="folder_create" action="'.url("whizzywig/folder_create").'" method="post" id="folder_create" enctype="multipart/form-data" style="margin-bottom:2px;">';
|
| 403 |
$output .= '<table border=0 width="100%" style="border:solid 2px #FFF; background:#F7F7F7;">';
|
| 404 |
$output .= '<tr>';
|
| 405 |
$output .= '<td style="font-size: 11px;">'.t('Sub folder name').'</td>';
|
| 406 |
// $output . = '<input type="hidden" name="token" value="'. $token .'" />';
|
| 407 |
$output .= "<input type='hidden' name='folder_name' value='$folder_name' />";
|
| 408 |
$output .= '<td><input type="text" name="new_folder" id="new_folder" value="" style="font-size: 11px;width:100%"/></td>';
|
| 409 |
$output .= '<td><input type="submit" name="folder_create" value="'.t('Create sub folder').'" style="font-size: 11px;"/></td>';
|
| 410 |
$output .= '</tr>';
|
| 411 |
$output .= '</table>';
|
| 412 |
$output .= '</form>';
|
| 413 |
}
|
| 414 |
|
| 415 |
if (user_access('file upload')) {
|
| 416 |
$output .= '<form name="form_upload" action="'.url("whizzywig/file_upload").'" method="post" id="uploadform" enctype="multipart/form-data">';
|
| 417 |
$output .= '<table border=0 width="100%" style="border:solid 2px #FFF; background:#F7F7F7;">';
|
| 418 |
$output .= '<tr>';
|
| 419 |
$output .= '<td style="font-size: 11px;">'.t('File to upload').'</td>';
|
| 420 |
$output .= '<td><input type="file" name="file_upload" id="file_upload" size=25 style="font-size: 11px;"/></td>';
|
| 421 |
$output .= "<input type='hidden' name='folder_name' value='$folder_name' />";
|
| 422 |
//$output .= '<input type="hidden" name="sub_folder" value="'. $sub_folder .'" />';
|
| 423 |
$output .= '<td><input type="submit" name="file_upload" value="'.t('Upload Now').'" style="font-size: 11px;"/></td>';
|
| 424 |
$output .= '</tr>';
|
| 425 |
$output .= '</table>';
|
| 426 |
$output .= '</form>';
|
| 427 |
}
|
| 428 |
|
| 429 |
if(is_dir($dir)) {
|
| 430 |
if($handle = opendir($dir)) {
|
| 431 |
$output .= "<table cellspacing=0 style='border:solid 2px #AAAAAA;' width='100%'>";
|
| 432 |
$output .= "<tr bgcolor='#B4B4B4'>";
|
| 433 |
$output .= "<td style='font-size: 11px;'><b>#</b></td>";
|
| 434 |
$output .= "<td style='font-size: 11px;'><b>FILE NAME</b></td>";
|
| 435 |
$output .= "<td style='font-size: 11px;' align='right' width='100'><b>SIZE (KB)</b></td>";
|
| 436 |
$output .= "<td style='font-size: 11px;' align='right'><b>DIMENSION</b></td>";
|
| 437 |
$output .= "<td style='font-size: 11px;' align='center' colspan='3'><b>ACTION</b></td>";
|
| 438 |
$output .= "</tr>";
|
| 439 |
$folder_size = 0;
|
| 440 |
$i = 0;
|
| 441 |
while(($file = readdir($handle)) !== false) {
|
| 442 |
if(!is_dir("$dir/$file") && $file != "." && $file != ".." && $file != "Thumbs.db" && $file!=".htaccess") {
|
| 443 |
$i++;
|
| 444 |
if ($i % 2) { $bgcolor='#FFFFFF';} else { $bgcolor="#DDDDDD";}
|
| 445 |
$output .= "<tr bgcolor='$bgcolor'>";
|
| 446 |
$file_path = "$dir/$file";
|
| 447 |
$file_url = "$base_path$dir/$file";
|
| 448 |
$file_size = number_format(filesize($file_path)/1024,1);
|
| 449 |
$folder_size += $file_size;
|
| 450 |
list($imgW,$imgH) = @getimagesize($file_path);
|
| 451 |
$output .= "<td style='font-size: 11px;' align='right'>$i.</td>";
|
| 452 |
$output .= "<td style='font-size: 11px;'>$file</td>";
|
| 453 |
$output .= "<td style='font-size: 11px;' align='right'>$file_size </td>";
|
| 454 |
$output .= "<td style='font-size: 11px;' align='right'>$imgW x $imgH </td>";
|
| 455 |
|
| 456 |
$output .= "<td style='font-size: 11px;margin:0;padding:0;' align='center' width=10 valign='center'>";
|
| 457 |
$output .= "<form name='form_insert' method='post' style='margin:0;'>";
|
| 458 |
$output .= "<input type='submit' id='if_url' value='Insert' onClick=\"fillImageForm('$file_url',$imgW,$imgH); return false;\" style='font-size:11px;' />";
|
| 459 |
$output .= '</form>';
|
| 460 |
$output .= "</td>";
|
| 461 |
|
| 462 |
if (user_access('file delete')) {
|
| 463 |
$output .= "<td style='font-size: 11px;' align='center' width=10>";
|
| 464 |
$output .= "<form action='".url('whizzywig/file_delete')."' method='post' style='margin:0;'>";
|
| 465 |
$output .= "<input type='hidden' name='folder_name' value='$folder_name' />";
|
| 466 |
$output .= "<input type='hidden' name='file_name' value='$file' />";
|
| 467 |
$output .= '<input type="button" value="Delete" onclick="confSubmit(this.form);" style="font-size: 11px;">';
|
| 468 |
$output .= '</form>';
|
| 469 |
$output .= "</td>";
|
| 470 |
}
|
| 471 |
|
| 472 |
if (user_access('file resize')) {
|
| 473 |
$output .= "<td style='font-size: 11px;' align='center' width=10>";
|
| 474 |
$output .= "<form action='".url('whizzywig/file_resize_form')."' method='post' style='margin:0;'>";
|
| 475 |
$output .= '<input type="submit" name="resize" value="'.t('Resize').'" style="font-size: 11px;"/>';
|
| 476 |
$output .= "<input type='hidden' name='folder_name' value='$folder_name' />";
|
| 477 |
$output .= "<input type='hidden' name='file_name' value='$file' />";
|
| 478 |
$output .= '</form></td>';
|
| 479 |
}
|
| 480 |
|
| 481 |
$output .= "</tr>";
|
| 482 |
}
|
| 483 |
}
|
| 484 |
$output .= "<tr bgcolor='#B4B4B4'>";
|
| 485 |
$output .= "<td style='font-size: 11px;'> </td>";
|
| 486 |
$output .= "<td style='font-size: 11px;' align='right'>Total</td>";
|
| 487 |
$output .= "<td style='font-size: 11px;' align='right'>".number_format($folder_size,1)."</td>";
|
| 488 |
$output .= "<td style='font-size: 11px;'> </td>";
|
| 489 |
$output .= "<td style='font-size: 11px;' align='center' colspan='3'> </td>";
|
| 490 |
$output .= "</tr>";
|
| 491 |
$output .= "</table>";
|
| 492 |
$output .= '</body>';
|
| 493 |
$output .= '</html>';
|
| 494 |
closedir($handle);
|
| 495 |
|
| 496 |
print $output;
|
| 497 |
exit();
|
| 498 |
}
|
| 499 |
}
|
| 500 |
}
|
| 501 |
|
| 502 |
function whizzywig_ow_file_delete() {
|
| 503 |
$folder_name = $_REQUEST['folder_name'];
|
| 504 |
$file_name = $_REQUEST['file_name'];
|
| 505 |
|
| 506 |
if (!user_access('access whizzywig') || !user_access('file delete')) { return; }
|
| 507 |
|
| 508 |
if (file_delete("$folder_name/$file_name")) {
|
| 509 |
$error_msg = t("Success. File '$file_name' deleted.");
|
| 510 |
} else {
|
| 511 |
$error_msg = t("Error deleting file: $folder_name/$file_name");
|
| 512 |
}
|
| 513 |
whizzywig_ow_image_browse($error_msg);
|
| 514 |
}
|
| 515 |
|
| 516 |
function whizzywig_ow_file_upload() {
|
| 517 |
$folder_name = strtolower($_REQUEST['folder_name']);
|
| 518 |
$files = $_FILES['file_upload'];
|
| 519 |
|
| 520 |
if (!user_access('access whizzywig') || !user_access('file upload')) { return; }
|
| 521 |
|
| 522 |
$file_name = $files["name"];
|
| 523 |
//File exists
|
| 524 |
if (file_exists("$folder_name/$file_name")) {
|
| 525 |
$error_msg = t("Error. The '$file_name' already exists.");
|
| 526 |
whizzywig_ow_image_browse($error_msg);return;
|
| 527 |
}
|
| 528 |
//File Extension
|
| 529 |
$pos = 0;
|
| 530 |
while( strpos($file_name,'.',$pos) ) {
|
| 531 |
$pos++;
|
| 532 |
}
|
| 533 |
if ($pos<>0) { $pos= $pos-1; }
|
| 534 |
$values = trim(strtolower(variable_get('whizzywig_file_extension','gif jpg jpeg png')));
|
| 535 |
if ($values<>'') {
|
| 536 |
$values_arr = split(' ',$values);
|
| 537 |
$file_extension = strtolower(substr($file_name,$pos+1));
|
| 538 |
|
| 539 |
if(!in_array($file_extension,$values_arr)) {
|
| 540 |
$error_msg = t("Error. File extension disallowed: $file_extension");
|
| 541 |
whizzywig_ow_image_browse($error_msg);
|
| 542 |
return;
|
| 543 |
}
|
| 544 |
}
|
| 545 |
|
| 546 |
//File dimension
|
| 547 |
$whizzywig_image_dimension = strtoupper(trim(variable_get('whizzywig_image_dimension','480x480')));
|
| 548 |
$pos=0;
|
| 549 |
$image_max_w = substr($whizzywig_image_dimension,0,$pos=strpos($whizzywig_image_dimension,'X',$pos));
|
| 550 |
$image_max_h = substr($whizzywig_image_dimension,$pos+1);
|
| 551 |
|
| 552 |
list($imgW,$imgH) = @getimagesize($files['tmp_name']);
|
| 553 |
if ($whizzywig_image_dimension<>'' && ($imgW > $image_max_w || $imgH > $image_max_h)) {
|
| 554 |
$image_max_h = ceil($imgH/$imgW * $image_max_w);
|
| 555 |
if (!image_resize($files['tmp_name'], "$folder_name/$file_name", $image_max_w, $image_max_h)) {
|
| 556 |
$error_msg = t("Error. Can not resize file to $image_max_w x $image_max_h");
|
| 557 |
whizzywig_ow_image_browse($error_msg);
|
| 558 |
return;
|
| 559 |
}
|
| 560 |
} else {
|
| 561 |
//File move
|
| 562 |
if (!move_uploaded_file($files["tmp_name"],"$folder_name/$file_name")) {
|
| 563 |
$error_msg = t("Error. Invalid file");
|
| 564 |
whizzywig_ow_image_browse($error_msg);
|
| 565 |
return;
|
| 566 |
}
|
| 567 |
}
|
| 568 |
//File size
|
| 569 |
$whizzywig_file_size = variable_get('whizzywig_file_size', '0');
|
| 570 |
if ($whizzywig_file_size) {
|
| 571 |
$upload_size= ceil(filesize("$folder_name/$file_name")/1024);
|
| 572 |
if ($upload_size > $whizzywig_file_size) {
|
| 573 |
$error_msg = t("Error. Your file is: $upload_size KB. Maximum file size is: $whizzywig_file_size KB");
|
| 574 |
file_delete("$folder_name/$file_name");
|
| 575 |
whizzywig_ow_image_browse($error_msg);
|
| 576 |
return;
|
| 577 |
}
|
| 578 |
}
|
| 579 |
|
| 580 |
$error_msg = t("Success. File '$file_name' uploaded");
|
| 581 |
whizzywig_ow_image_browse($error_msg);
|
| 582 |
return;
|
| 583 |
}
|
| 584 |
|
| 585 |
function whizzywig_list_dir($base_dir) {
|
| 586 |
if(!is_dir($base_dir)) { return; }
|
| 587 |
|
| 588 |
if($handle = opendir($base_dir)) {
|
| 589 |
$result = array();
|
| 590 |
while(($file = readdir($handle)) !== false) {
|
| 591 |
if(is_dir("$base_dir/$file") && $file<>'.') { $result[] .= $file; }
|
| 592 |
}
|
| 593 |
}
|
| 594 |
return $result;
|
| 595 |
}
|
| 596 |
|
| 597 |
function whizzywig_ow_folder_create() {
|
| 598 |
global $user;
|
| 599 |
|
| 600 |
$folder_name = $_REQUEST['folder_name'];
|
| 601 |
$sub_folder = $_REQUEST['sub_folder'];
|
| 602 |
$new_folder = $_REQUEST['new_folder'];
|
| 603 |
|
| 604 |
//print "Folder= $folder_name Sub-folder= $sub_folder New-folder = $new_folder";
|
| 605 |
//exit();
|
| 606 |
|
| 607 |
if (!user_access('access whizzywig') || !user_access('folder create')) { return; }
|
| 608 |
|
| 609 |
$error_msg ='';
|
| 610 |
if ($new_folder=='') { whizzywig_ow_image_browse($error_msg); }
|
| 611 |
|
| 612 |
$uid = $user->uid;
|
| 613 |
$base_path = base_path();
|
| 614 |
$files_path = file_directory_path();
|
| 615 |
|
| 616 |
$whizzywig_folder_format = variable_get('whizzywig_folder_format', 'u[uid]');
|
| 617 |
$whizzywig_folder_format = str_replace('[uid]',$uid,$whizzywig_folder_format);
|
| 618 |
$whizzywig_folder_format = str_replace('[username]',$name,$whizzywig_folder_format);
|
| 619 |
$whizzywig_folder_format = str_replace('[domainname]',$_SERVER['HTTP_HOST'],$whizzywig_folder_format);
|
| 620 |
|
| 621 |
$user_dir = "$files_path/$whizzywig_folder_format";
|
| 622 |
$dir = "$folder_name/$new_folder";
|
| 623 |
|
| 624 |
//Security check
|
| 625 |
if (strpos($dir,'..')) {
|
| 626 |
print t("Sorry. Invalid sub folder name.")."<hr>";
|
| 627 |
print '<input type="submit" value=" Close " onClick="window.close();" />';
|
| 628 |
exit();
|
| 629 |
}
|
| 630 |
//Folder manager
|
| 631 |
if (!user_access('folder manage')) {
|
| 632 |
if (!strpos($dir,$user_dir)) {
|
| 633 |
print t("Sorry, you have no 'folder manage' access, you only can create folder into your own folder.");
|
| 634 |
exit();
|
| 635 |
}
|
| 636 |
}
|
| 637 |
|
| 638 |
//Check and create user sub folder
|
| 639 |
$success = false;
|
| 640 |
if (file_exists("$dir")) {
|
| 641 |
if (is_dir("$dir")) {
|
| 642 |
$error_msg = t("Error. Sub folder '$new_folder' already exists.");
|
| 643 |
} else {
|
| 644 |
if (mkdir($dir)) {
|
| 645 |
$success = true;
|
| 646 |
$error_msg = t("Success. Create sub folder: $new_folder");
|
| 647 |
} else {
|
| 648 |
$error_msg = __line__.": ".t("Error. Can not create sub folder: $new_folder");
|
| 649 |
}
|
| 650 |
}
|
| 651 |
} else {
|
| 652 |
if (mkdir($dir)) {
|
| 653 |
$success = true;
|
| 654 |
$error_msg = t("Success. Create sub folder: $new_folder");
|
| 655 |
} else {
|
| 656 |
$error_msg = __line__.": ".t("Error. Can not create sub folder: $new_folder");
|
| 657 |
}
|
| 658 |
}
|
| 659 |
whizzywig_ow_image_browse($error_msg);
|
| 660 |
}
|
| 661 |
|
| 662 |
function whizzywig_ow_file_resize_form() {
|
| 663 |
$folder_name = $_REQUEST['folder_name'];
|
| 664 |
$file_name = $_REQUEST['file_name'];
|
| 665 |
|
| 666 |
$whizzywig_file_resize_width = variable_get('whizzywig_file_resize_width', '100');
|
| 667 |
$whizzywig_file_resize_height = variable_get('whizzywig_file_resize_height', '');
|
| 668 |
|
| 669 |
$output = '';
|
| 670 |
$output .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
|
| 671 |
$output .= '<html>';
|
| 672 |
$output .= '<head>';
|
| 673 |
$output .= '<title>whizzywig | Insert or Modify Image</title>';
|
| 674 |
|
| 675 |
$output .= '<script language="JavaScript" type="text/javascript">';
|
| 676 |
|
| 677 |
$output .= "function confSubmit(form) { \n";
|
| 678 |
$output .= " if (resize_name= form.resize_name.value=='') { \n";
|
| 679 |
$output .= " if (confirm('This will replace existing File Name, are you sure?')) { \n";
|
| 680 |
$output .= " form.submit(); \n";
|
| 681 |
$output .= " }\n";
|
| 682 |
$output .= " }\n";
|
| 683 |
$output .= "}\n\n";
|
| 684 |
|
| 685 |
$output .= '</script>';
|
| 686 |
$output .= '</head>';
|
| 687 |
|
| 688 |
$output .= '<body bgcolor="#EEEEEE">';
|
| 689 |
$output .= "<form action='".url("whizzywig/file_resize_action")."' name='file_resize_form' id='file_resize_form' method='post' style='margin-bottom:2px;'>";
|
| 690 |
$output .= "<span style='font-size: 11px; font-weight: bold;'>Resize '$folder_name/$file_name' image to:</span>";
|
| 691 |
$output .= '<table width="100%" border="0" cellpadding="1" cellspacing="0" style="background: #F7F7F7;border:2px solid white;padding:5px;">';
|
| 692 |
$output .= '<tr>';
|
| 693 |
$output .= "<td width='50' style='font-size:11px;'>Width1:</td><td><input type='text' name='resize_width' id='resize_width' style='font-size:10px;' value='$whizzywig_file_resize_width'/></td>";
|
| 694 |
$output .= "<td style='font-size:11px;'>Height:</td><td><input type='text' name='resize_height' id='resize_height' style='font-size:10px;' value='$whizzywig_file_resize_height'/></td>";
|
| 695 |
$output .= '</tr>';
|
| 696 |
$output .= '<tr><td colspan="4" style="font-size:11px;">'.t('* Proportional width: fill only the <b>Width</b> field, leave Height blank').'</td></tr>';
|
| 697 |
$output .= '<tr><td colspan="4" style="font-size:11px;">'.t('* Proportional height: fill only the <b>Height</b> field, leave Width blank').'</td></tr>';
|
| 698 |
$output .= '</table>';
|
| 699 |
$output .= '<table width="100%" border="0" cellpadding="1" cellspacing="0" style="background: #F7F7F7;border:2px solid white;padding:5px;">';
|
| 700 |
$output .= '<tr>';
|
| 701 |
$output .= ' <td width="50" style="font-size:11px;">File name:</td>';
|
| 702 |
$output .= ' <td style="font-size:10px;"><input type="text" name="resize_name" id="resize_name" value="" style="font-size:10px;width:100%;"/>';
|
| 703 |
$output .= ' </tr>';
|
| 704 |
$output .= ' <tr>';
|
| 705 |
$output .= '<td colspan="2" style="font-size:11px;">'.t("* Leave blank if you want to use original file name!");
|
| 706 |
$output .= '</td>';
|
| 707 |
$output .= ' </tr>';
|
| 708 |
$output .= '</table><br>';
|
| 709 |
$output .= '<input type="hidden" name="file_name" value="'.$file_name.'" />';
|
| 710 |
$output .= '<input type="hidden" name="folder_name" value="'.$folder_name.'" />';
|
| 711 |
$output .= "<input type='button' name='resize' value='".t('Resize now')."' onclick=\"confSubmit(this.form);\" style='font-size: 11px;'/>";
|
| 712 |
$output .= '<input type="button" value=" Back" onClick="history.go(-1);" style="font-size: 11px;"/>';
|
| 713 |
$output .= "</form>";
|
| 714 |
|
| 715 |
$output .= '</body>';
|
| 716 |
print $output;
|
| 717 |
exit();
|
| 718 |
}
|
| 719 |
|
| 720 |
function whizzywig_ow_file_resize_action() {
|
| 721 |
$folder_name = $_REQUEST['folder_name'];
|
| 722 |
$file_name = $_REQUEST['file_name'];
|
| 723 |
$resize_width = $_REQUEST['resize_width'];
|
| 724 |
$resize_height = $_REQUEST['resize_height'];
|
| 725 |
$resize_name = $_REQUEST['resize_name'];
|
| 726 |
|
| 727 |
$old_file = "$folder_name/$file_name";
|
| 728 |
$new_file = "$folder_name/".($resize_name!='' ? $resize_name : $file_name);
|
| 729 |
|
| 730 |
list($imgW,$imgH) = @getimagesize("$folder_name/$file_name");
|
| 731 |
|
| 732 |
if ($resize_width=='') {$resize_width = ceil($imgW/$imgH * $resize_height);}
|
| 733 |
if ($resize_height=='') {$resize_height = ceil($imgH/$imgW * $resize_width); }
|
| 734 |
|
| 735 |
if (image_resize("$old_file","$new_file",$resize_width,$resize_height)) {
|
| 736 |
$error_msg= t("Success. Resize file '$old_file' ($imgW x $imgH) to '$new_file' ($resize_width x $resize_height).");
|
| 737 |
} else {
|
| 738 |
$error_msg= t("Error. Can not resize file '$old_file' ($imgW x $imgH) to '$new_file' ($resize_width x $resize_height).");
|
| 739 |
}
|
| 740 |
whizzywig_ow_image_browse($error_msg);
|
| 741 |
exit();
|
| 742 |
}
|