private function checkSize($source_file, $size, $ftype) { static $sizes; if (empty($sizes)) { $sizes = Cabinet::getMaxSizes(); } switch ($ftype) { case DOCUMENT_FOLDER: $folder_max = $sizes['document']; break; case IMAGE_FOLDER: $folder_max = $sizes['image']; break; case MULTIMEDIA_FOLDER: $folder_max = $sizes['multimedia']; break; } if ($size > $sizes['system'] || $size > $sizes['form'] || $size > $sizes['absolute'] || $size > $folder_max) { $this->sendErrorHeader('File size too large'); } }
public function edit() { static $folder; if (empty($this->multimedia)) { $this->loadMultimedia(); } if (empty($folder)) { $folder = new Folder($this->multimedia->folder_id); } PHPWS_Core::initCoreClass('File.php'); $form = new PHPWS_FORM(); $form->setFormId('file-form'); $form->addHidden('module', 'filecabinet'); $form->addHidden('mop', 'post_multimedia_upload'); $form->addHidden('ms', $this->max_size); $form->addHidden('folder_id', $this->multimedia->folder_id); $form->addFile('file_name'); $form->setLabel('file_name', dgettext('filecabinet', 'Multimedia location')); $form->addText('title', $this->multimedia->title); $form->setLabel('title', dgettext('filecabinet', 'Title')); $form->setClass('title', 'form-control'); $form->addTextArea('description', $this->multimedia->description); $form->setLabel('description', dgettext('filecabinet', 'Description')); $form->setClass('description', 'form-control'); if ($this->multimedia->id) { $this->title = 'Edit multimedia'; $form->addHidden('multimedia_id', $this->multimedia->id); $form->addText('width', $this->multimedia->width); $form->setLabel('width', dgettext('filecabinet', 'Width')); $form->addText('height', $this->multimedia->height); $form->setLabel('height', dgettext('filecabinet', 'Height')); } else { $this->title = 'Upload multimedia'; } if ($this->multimedia->id && Current_User::allow('filecabinet', 'edit_folders', $this->multimedia->folder_id, 'folder', true)) { Cabinet::moveToForm($form, $folder); } $template = $form->getTemplate(); if ($this->multimedia->id) { $template['CURRENT_MULTIMEDIA_LABEL'] = dgettext('filecabinet', 'Current multimedia'); $template['CURRENT_MULTIMEDIA_ICON'] = $this->multimedia->getThumbnail(); $template['CURRENT_MULTIMEDIA_FILE'] = $this->multimedia->file_name; $ow['address'] = PHPWS_Text::linkAddress('filecabinet', array('aop' => 'change_tn', 'type' => 'mm', 'id' => $this->multimedia->id), true); $ow['label'] = 'Change thumbnail'; $ow['width'] = 400; $ow['height'] = 250; $template['EDIT_THUMBNAIL'] = javascript('open_window', $ow); } $template['MAX_SIZE_LABEL'] = dgettext('filecabinet', 'Maximum file size'); $size_max = Cabinet::getMaxSizes(); $sys_size =& $size_max['system']; $form_max =& $size_max['form']; if ($form_max < $sys_size && $form_max < $this->max_size) { $max_size =& $form_max; } elseif ($sys_size < $form_max && $sys_size < $this->max_size) { $max_size =& $sys_size; } else { $max_size =& $this->max_size; } if ($max_size >= 1000000) { $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%dMB (%d bytes)'), floor($max_size / 1000000), $max_size); } elseif ($max_size >= 1000) { $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%dKB (%d bytes)'), floor($max_size / 1000), $max_size); } else { $template['MAX_SIZE'] = sprintf(dgettext('filecabinet', '%d bytes'), $max_size); } if ($this->message) { $template['ERROR'] = $this->message; } $this->content = PHPWS_Template::process($template, 'filecabinet', 'Forms/multimedia_edit.tpl'); }
public function settings() { $sizes = Cabinet::getMaxSizes(); $form = new PHPWS_Form('settings'); $form->addHidden('module', 'filecabinet'); $form->addHidden('aop', 'save_settings'); $form->addTplTag('DOCUMENT_SETTINGS', dgettext('filecabinet', 'Document settings')); $form->addTplTag('IMAGE_SETTINGS', dgettext('filecabinet', 'Image settings')); $form->addTplTag('MULTIMEDIA_SETTINGS', dgettext('filecabinet', 'Multimedia settings')); $form->addText('base_doc_directory', PHPWS_Settings::get('filecabinet', 'base_doc_directory')); $form->setSize('base_doc_directory', '50'); $form->setLabel('base_doc_directory', dgettext('filecabinet', 'Base document directory')); $form->addCheckBox('autofloat', 1); $form->setMatch('autofloat', PHPWS_Settings::get('filecabinet', 'autofloat')); $form->setLabel('autofloat', dgettext('filecabinet', 'Float new images under 300px to the right of content')); $form->addText('max_image_dimension', PHPWS_Settings::get('filecabinet', 'max_image_dimension')); $form->setLabel('max_image_dimension', dgettext('filecabinet', 'Maximum image pixel dimension')); $form->setSize('max_image_dimension', 4, 4); $form->addText('max_image_size', $sizes['image']); $form->setLabel('max_image_size', dgettext('filecabinet', 'Maximum image file size (in bytes)')); $form->setSize('max_image_size', 10, 10); $form->addText('max_document_size', $sizes['document']); $form->setLabel('max_document_size', dgettext('filecabinet', 'Maximum document file size (in bytes)')); $form->setSize('max_document_size', 10, 10); $form->addText('max_multimedia_size', $sizes['multimedia']); $form->setLabel('max_multimedia_size', dgettext('filecabinet', 'Maximum multimedia file size (in bytes)')); $form->setSize('max_multimedia_size', 10, 10); $form->addText('max_pinned_images', PHPWS_Settings::get('filecabinet', 'max_pinned_images')); $form->setLabel('max_pinned_images', dgettext('filecabinet', 'Maximum pinned images shown (0 for all)')); $form->setSize('max_pinned_images', 3, 3); $form->addText('max_pinned_documents', PHPWS_Settings::get('filecabinet', 'max_pinned_documents')); $form->setLabel('max_pinned_documents', dgettext('filecabinet', 'Maximum pinned documents shown (0 for all)')); $form->setSize('max_pinned_documents', 3, 3); $form->addText('crop_threshold', PHPWS_Settings::get('filecabinet', 'crop_threshold')); $form->setLabel('crop_threshold', dgettext('filecabinet', 'Crop pixel threshold')); $form->setSize('crop_threshold', 4, 4); $form->addCheck('use_ffmpeg', 1); $form->setMatch('use_ffmpeg', PHPWS_Settings::get('filecabinet', 'use_ffmpeg')); $form->addCheck('caption_images', 1); $form->setMatch('caption_images', PHPWS_Settings::get('filecabinet', 'caption_images')); $form->setLabel('caption_images', dgettext('filecabinet', 'Caption images')); $form->addCheck('allow_direct_links', 1); $form->setMatch('allow_direct_links', PHPWS_Settings::get('filecabinet', 'allow_direct_links')); $form->setLabel('allow_direct_links', dgettext('filecabinet', 'Allow direct links to documents')); $form->addCheck('force_thumbnail_dimensions', 1); $form->setMatch('force_thumbnail_dimensions', PHPWS_Settings::get('filecabinet', 'force_thumbnail_dimensions')); $form->setLabel('force_thumbnail_dimensions', dgettext('filecabinet', 'Force thumbnail dimensions on display')); $form->addCheck('popup_image_navigation', 1); $form->setMatch('popup_image_navigation', PHPWS_Settings::get('filecabinet', 'popup_image_navigation')); $form->setLabel('popup_image_navigation', dgettext('filecabinet', 'Popup images allow folder navigation')); $form->addText('max_thumbnail_size', PHPWS_Settings::get('filecabinet', 'max_thumbnail_size')); $form->setLabel('max_thumbnail_size', dgettext('filecabinet', 'Maximum thumbnail pixel dimension')); $form->setSize('max_thumbnail_size', 3, 3); $ffmpeg_directory = PHPWS_Settings::get('filecabinet', 'ffmpeg_directory'); if (empty($ffmpeg_directory) || !is_file($ffmpeg_directory . 'ffmpeg')) { $form->setDisabled('use_ffmpeg'); $form->setLabel('use_ffmpeg', dgettext('filecabinet', 'Enable FFMpeg thumbnails (enabled on ffmpeg confirmation)')); } else { $form->setLabel('use_ffmpeg', dgettext('filecabinet', 'Enable FFMpeg thumbnails')); } $form->addTplTag('CLASSIFY_SETTINGS', dgettext('filecabinet', 'Classify settings')); $form->addText('ffmpeg_directory', $ffmpeg_directory); $form->setLabel('ffmpeg_directory', dgettext('filecabinet', 'FFMpeg directory')); $form->setSize('ffmpeg_directory', 40); if (FC_ALLOW_CLASSIFY_DIR_SETTING) { $form->addText('classify_directory', PHPWS_Settings::get('filecabinet', 'classify_directory')); $form->setLabel('classify_directory', dgettext('filecabinet', 'Incoming classify directory')); $form->setSize('classify_directory', 50, 255); } $form->addRadioAssoc('jcaro_type', array(0 => dgettext('filecabinet', 'Horizontal'), 1 => dgettext('filecabinet', 'Vertical'))); $form->setMatch('jcaro_type', (int) PHPWS_Settings::get('filecabinet', 'vertical_folder')); $num = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8); $form->addSelect('number_visible', $num); $form->setMatch('number_visible', PHPWS_Settings::get('filecabinet', 'number_visible')); $form->setLabel('number_visible', dgettext('filecabinet', 'Number of thumbnails visible')); $form->addSubmit(dgettext('filecabinet', 'Save settings')); $tpl = $form->getTemplate(); $tpl['CAROUSEL'] = dgettext('filecabinet', 'Carousel defaults'); $tpl['SYSTEM_SIZE'] = dgettext('filecabinet', 'System upload limits'); $tpl['SYSTEM_LABEL'] = dgettext('filecabinet', 'Server upload limit'); $tpl['FORM_LABEL'] = dgettext('filecabinet', 'Form upload limit'); $tpl['ABSOLUTE_LABEL'] = dgettext('filecabinet', 'Absolute upload limit'); $tpl['MAX_SYSTEM_SIZE'] = File_Common::humanReadable($sizes['system']); $tpl['MAX_FORM_SIZE'] = File_Common::humanReadable($sizes['form']); $tpl['ABSOLUTE_SIZE'] = File_Common::humanReadable($sizes['absolute']); if (Current_User::isDeity()) { $link = new PHPWS_Link(null, 'filecabinet', array('aop' => 'fix_document_dir'), true); $js = array('question' => dgettext('filecabinet', 'This process will update all of your document files with the current base directory. Do not run this process unless you are sure it will fix download problems. If you are sure, type Y-E-S below.'), 'address' => $link->getAddress(), 'value_name' => 'confirm', 'link' => dgettext('filecabinet', 'Reindex document directories')); $tpl['FIX_DIRECTORIES'] = javascript('prompt', $js); } return PHPWS_Template::process($tpl, 'filecabinet', 'Forms/settings.tpl'); }