예제 #1
0
 public function printFile($id)
 {
     $db = \Database::newDB();
     $t = $db->addTable('multimedia');
     $t->addFieldConditional('id', (int) $id);
     $row = $db->selectOneRow();
     if (empty($row)) {
         return null;
     }
     $ext = \PHPWS_File::getFileExtension($row['file_name']);
     if ($ext == 'mp3') {
         $template = 'filters/audio.tpl';
     } else {
         $template = 'filters/media.tpl';
     }
     return \PHPWS_Template::process(array('FILE_PATH' => $row['file_directory'] . $row['file_name']), 'filecabinet', $template);
 }
예제 #2
0
 public function classifyIntoFolder($folder_id, $files)
 {
     if (empty($files)) {
         return;
     }
     $folder = new Folder($folder_id);
     if (!$folder->id) {
         return;
     }
     $classify_dir = $this->getClassifyDir();
     if (empty($classify_dir)) {
         return;
     }
     switch ($folder->ftype) {
         case IMAGE_FOLDER:
             $type = 'image';
             PHPWS_Core::initModClass('filecabinet', 'Image.php');
             $class_name = 'PHPWS_Image';
             break;
         case DOCUMENT_FOLDER:
             $type = 'document';
             PHPWS_Core::initModClass('filecabinet', 'Document.php');
             $class_name = 'PHPWS_Document';
             break;
         case MULTIMEDIA_FOLDER:
             $type = 'media';
             PHPWS_Core::initModClass('filecabinet', 'Multimedia.php');
             $class_name = 'PHPWS_Multimedia';
             break;
     }
     $allowed_types = $this->getAllowedTypes($type);
     foreach ($files as $filename) {
         $path = $classify_dir . $filename;
         $ext = PHPWS_File::getFileExtension($filename);
         if ($this->fileTypeAllowed($path, $type) && PHPWS_File::checkMimeType($path) && in_array($ext, $allowed_types)) {
             $file_obj = new $class_name();
             $file_obj->folder_id = $folder->id;
             $file_obj->setFilename($filename);
             $file_obj->setTitle(str_replace(".{$ext}", '', $filename));
             $file_obj->setDirectory($folder->getFullDirectory());
             $folder_directory = $file_obj->getPath();
             if (!@rename($path, $folder_directory)) {
                 PHPWS_Error::log(FC_FILE_MOVE, 'filecabinet', 'Cabinet::classifyIntoFolder', $folder_directory);
                 continue;
             }
             $file_obj->file_type = PHPWS_File::getMimeType($file_obj->getPath());
             $file_obj->loadFileSize();
             if ($folder->ftype == IMAGE_FOLDER) {
                 $file_obj->loadDimensions();
                 $file_obj->save(true, false);
             } else {
                 $file_obj->save(false);
             }
         }
     }
 }
예제 #3
0
파일: File.php 프로젝트: HaldunA/phpwebsite
 public function getVbType($ext)
 {
     $ext = trim(strtolower($ext));
     if (strpos($ext, '.')) {
         $ext = PHPWS_File::getFileExtension($ext);
     }
     $all_types = PHPWS_File::getAllFileTypes();
     if (!isset($all_types[$ext])) {
         return _('Unknown type');
     } else {
         return $all_types[$ext]['vb'];
     }
 }
예제 #4
0
 private function checkMimeType($source_directory, $filename, $ftype)
 {
     switch ($ftype) {
         case DOCUMENT_FOLDER:
             $type_list = \PHPWS_Settings::get('filecabinet', 'document_files');
             break;
         case IMAGE_FOLDER:
             $type_list = \PHPWS_Settings::get('filecabinet', 'image_files');
             break;
         case MULTIMEDIA_FOLDER:
             $type_list = \PHPWS_Settings::get('filecabinet', 'media_files');
             break;
     }
     $ext = PHPWS_File::getFileExtension($filename);
     // First check if the extension is allowed for the current folder type.
     $type_array = explode(',', str_replace(' ', '', $type_list));
     if (!in_array($ext, $type_array)) {
         $this->sendErrorHeader('File type not allowed in folder');
     }
     // second check that file is the type it claims to be
     if (!PHPWS_File::checkMimeType($source_directory, $ext)) {
         $this->sendErrorHeader('Unknown file type');
     }
 }
예제 #5
0
 public function classifyFile($files)
 {
     $tpl = null;
     $this->cabinet->title = dgettext('filecabinet', 'Classify Files');
     $classify_dir = $this->cabinet->getClassifyDir();
     if (empty($classify_dir) || !is_dir($classify_dir)) {
         $this->cabinet->content = dgettext('filecabinet', 'Unable to locate the classify directory. Please check your File Cabinet settings, configuration file and directory permissions.');
         return;
     }
     if (!is_array($files)) {
         $files = array($files);
     }
     // image folders
     $image_folders = Cabinet::listFolders(IMAGE_FOLDER, true);
     // document folders
     $document_folders = Cabinet::listFolders(DOCUMENT_FOLDER, true);
     // multimedia folders
     $multimedia_folders = Cabinet::listFolders(MULTIMEDIA_FOLDER, true);
     $count = 0;
     $image_types = $this->cabinet->getAllowedTypes('image');
     $document_types = $this->cabinet->getAllowedTypes('document');
     $media_types = $this->cabinet->getAllowedTypes('media');
     foreach ($files as $file) {
         if (!is_file($classify_dir . $file) || !PHPWS_File::checkMimeType($classify_dir . $file) || !$this->cabinet->fileTypeAllowed($file)) {
             continue;
         }
         $form = new PHPWS_Form('file_form_' . $count);
         $ext = PHPWS_File::getFileExtension($file);
         if (in_array($ext, $image_types)) {
             $folders =& $image_folders;
         } elseif (in_array($ext, $media_types)) {
             $folders =& $multimedia_folders;
         } elseif (in_array($ext, $document_types)) {
             $folders =& $document_folders;
         } else {
             continue;
         }
         $form->addSelect("folder[{$count}]", $folders);
         $form->setTag("folder[{$count}]", 'folder');
         $form->setLabel("folder[{$count}]", dgettext('filecabinet', 'Folder'));
         $form->addText("file_title[{$count}]", $file);
         $form->setLabel("file_title[{$count}]", dgettext('filecabinet', 'Title'));
         $form->setTag("file_title[{$count}]", 'file_title');
         $form->setSize("file_title[{$count}]", 40);
         $form->addTextarea("file_description[{$count}]");
         $form->setLabel("file_description[{$count}]", dgettext('filecabinet', 'Description'));
         $form->setTag("file_description[{$count}]", 'file_description');
         $form->addSubmit('submit', dgettext('filecabinet', 'Classify files'));
         $subtpl = $form->getTemplate();
         $subtpl['HIDDEN'] = sprintf('<input type="hidden" name="file_count[%s]" value="%s" />', $count, $file);
         $subtpl['FILE_NAME'] = $file;
         $subtpl['FILE_NAME_LABEL'] = dgettext('filecabinet', 'File name');
         unset($subtpl['START_FORM']);
         unset($subtpl['END_FORM']);
         $tpl['files'][] = $subtpl;
         $count++;
     }
     $form = new PHPWS_Form('classify_files');
     $form->addHidden('module', 'filecabinet');
     $form->addHidden('aop', 'post_classifications');
     if (!empty($tpl)) {
         $form_template = $form->getTemplate(true, true, $tpl);
         $this->cabinet->content = PHPWS_Template::process($form_template, 'filecabinet', 'Forms/classify_file.tpl');
     } else {
         $this->cabinet->content = dgettext('filecabinet', 'Unable to classify files.');
     }
 }
예제 #6
0
 public function post()
 {
     $this->setTitle($_POST['title']);
     $this->setPropertyId($_POST['pid']);
     $photo =& $_FILES['photo'];
     if (!$this->pid) {
         throw new \Exception('Photo missing property id');
     }
     \PHPWS_Core::initModClass('properties', 'Property.php');
     $property = new Property($this->pid);
     $this->setContactId($property->contact_id);
     $destination_directory = 'images/properties/c' . $this->cid . '/';
     if (!is_dir($destination_directory)) {
         if (!@mkdir($destination_directory)) {
             throw new \Exception('Could not create photo directory');
         }
     }
     $filename = time() . '.' . \PHPWS_File::getFileExtension($photo['name']);
     $path = $destination_directory . $filename;
     if (!empty($photo['error'])) {
         switch ($photo['error']) {
             case UPLOAD_ERR_INI_SIZE:
             case UPLOAD_ERR_FORM_SIZE:
                 throw new \Exception('Image file size is too large.');
             case UPLOAD_ERR_NO_FILE:
                 throw new \Exception('No file upload');
             case UPLOAD_ERR_NO_TMP_DIR:
                 \PHPWS_Core::log('Temporary file directory is not writable', 'error.log', _('Error'));
                 throw new \Exception('File could not be written');
         }
     }
     list($this->width, $this->height, $image_type, $image_attr) = getimagesize($photo['tmp_name']);
     if (!in_array($image_type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         throw new \Exception('Unacceptable image file type.');
     }
     if (\PHPWS_File::scaleImage($photo['tmp_name'], $path, PROPERTIES_MAX_WIDTH, PROPERTIES_MAX_HEIGHT)) {
         $this->path = $path;
         $this->save();
         $tn = Photo::thumbnailPath($path);
         $this->resize($path, $tn, PROP_THUMBNAIL_WIDTH, PROP_THUMBNAIL_HEIGHT);
     } else {
         throw new \Exception('Could not save image');
     }
 }
예제 #7
0
 /**
  * The IXR library required a change to make this work.
  * If you update that file, make sure the base64 decode contains
  * a trim call on the currentTagContents variable.
  */
 public function metaWeblog_newMediaObject($args)
 {
     PHPWS_Core::requireInc('core', 'file_types.php');
     PHPWS_Core::initCoreClass('File.php');
     $allowed_images = unserialize(ALLOWED_IMAGE_TYPES);
     /* Login the user */
     $logged = $this->logUser($args[1], $args[2], 'media');
     if ($logged !== true) {
         return $logged;
     }
     $filename = PHPWS_File::nameToSafe($args[3]['name']);
     $filetype = $args[3]['type'];
     $ext = PHPWS_File::getFileExtension($filename);
     if (!(ALLOW_OCTET_STREAM && $filetype == 'application/octet-stream') && !in_array($filetype, $allowed_images)) {
         return new IXR_Error(-652, "File type '{$filetype}' not allowed.");
     }
     if (!isset($allowed_images[$ext])) {
         return new IXR_Error(-653, "File extension '{$ext}' not allowed.");
     }
     if (isset($this->image_directory)) {
         $img_directory =& $this->image_directory;
     } else {
         $img_directory = 'images/';
     }
     PHPWS_File::appendSlash($img_directory);
     $source_file = $img_directory . $filename;
     @unlink($source_file);
     $handle = @fopen($source_file, 'wb');
     if (!$handle) {
         return new IXR_Error(-2323, 'Unable to open file.');
     }
     $image = $args[3]['bits'];
     if (!@fwrite($handle, $image)) {
         return new IXR_Error(-651, "Unable to write file - {$filename}.");
     }
     fclose($handle);
     $url = PHPWS_Core::getHomeHttp() . $img_directory . $filename;
     return $url;
 }
예제 #8
0
 private function postMenu($request)
 {
     $title = $request->getVar('title');
     $template = $request->getVar('template');
     $menu = new Menu_Item($request->getVar('menu_id'));
     if ($request->isVar('assoc_key')) {
         $assoc_key = $request->getVar('assoc_key');
     } elseif ($menu->assoc_key) {
         $assoc_key = $menu->assoc_key;
     } else {
         $assoc_key = 0;
     }
     if ($request->isVar('assoc_url')) {
         $assoc_url = trim(strip_tags($request->getVar('assoc_url')));
     }
     if ($request->isVar('carousel_slide')) {
         $carousel = trim(strip_tags($request->getVar('carousel_slide')));
     }
     $menu->setTitle($title);
     $menu->setTemplate($template);
     $menu->assoc_url = null;
     $menu->assoc_key = 0;
     if ($assoc_key) {
         $key = new \Key($assoc_key);
         if ($key->module == 'pagesmith') {
             $db = \Database::newDB();
             $t1 = $db->addTable('access_shortcuts');
             $t1->addFieldConditional('url', 'pagesmith:' . $key->item_id);
             $t1->addFieldConditional('active', '1');
             $access = $db->selectOneRow();
             if (!empty($access)) {
                 $menu->assoc_url = './' . $access['keyword'];
             }
         }
         $menu->setAssocKey($assoc_key);
     } elseif (!empty($assoc_url)) {
         $menu->setAssocUrl($assoc_url);
     }
     if ($request->isUploadedFile('assoc_image')) {
         $menu->deleteImage();
         $file = $request->getUploadedFileArray('assoc_image');
         $file_name = randomString(12) . '.' . str_replace('image/', '', $file['type']);
         \PHPWS_File::fileCopy($file['tmp_name'], 'images/menu/', $file_name, false, true);
         \PHPWS_File::makeThumbnail($file_name, 'images/menu/', 'images/menu/', 200);
         $menu->setAssocImage('images/menu/' . $file_name);
     } elseif (!empty($carousel)) {
         $menu->deleteImage();
         $ext = \PHPWS_File::getFileExtension($carousel);
         $file_name = randomString(12) . '.' . str_replace('image/', '', $ext);
         \PHPWS_File::fileCopy($carousel, 'images/menu/', $file_name, false, true);
         \PHPWS_File::makeThumbnail($file_name, 'images/menu/', 'images/menu/', 200);
         $menu->setAssocImage('images/menu/' . $file_name);
     }
     $menu->save();
 }
예제 #9
0
 private static function savePicture(array $file, \election\Resource\Candidate $candidate)
 {
     $filename = $file['name'];
     $tmpDir = $file['tmp_name'];
     $filetype = $file['type'];
     $size = $file['size'];
     if (!in_array($filetype, array('image/png', 'image/jpg', 'image/jpeg', 'image/gif'))) {
         throw new \Exception('Bad file type. Expecting image.');
     }
     $subDirectory = self::getImageDirectory();
     if (!is_dir($subDirectory)) {
         mkdir($subDirectory, 0755);
     }
     if (!is_writable($subDirectory)) {
         throw new \Exception('Election image directory not writable.');
     }
     $extension = \PHPWS_File::getFileExtension($filename);
     if (empty($extension)) {
         throw new \Exception('Bad file type. Expecting image.');
     }
     $filename = preg_replace('/[^\\w\\-]/', '-', $candidate->getFirstName()) . '-' . preg_replace('/[^\\w\\-]/', '-', $candidate->getLastName()) . '-' . time();
     $destination = $subDirectory . $filename . '.' . $extension;
     $count = 0;
     while (is_file($destination)) {
         $count++;
         $destination = $subDirectory . $filename . $count . '.' . $extension;
     }
     move_uploaded_file($tmpDir, $destination);
     list($width, $height) = getimagesize($destination);
     if ($width > ELECTION_MAX_CANDIDATE_WIDTH) {
         \PHPWS_File::scaleImage($destination, $destination, ELECTION_MAX_CANDIDATE_WIDTH, ELECTION_MAX_CANDIDATE_HEIGHT);
     }
     return $filename . '.' . $extension;
 }