public function getFileAssoc($file_type, $id, $update = true) { $file_assoc = new FC_File_Assoc(); $cropped = (int) $file_type == FC_IMAGE_CROP; if ($file_type == FC_IMAGE_FOLDER) { $vertical = (int) $_GET['direction']; $num_visible = (int) $_GET['num_visible']; if ($num_visible < 0 || $num_visible > 8) { $num_visible = $file_assoc->num_visible; } } if ($file_type == FC_IMAGE_LIGHTBOX) { $vertical = (int) $_GET['direction']; $num_visible = (int) $_GET['num_visible']; if ($num_visible < 0 || $num_visible > 99) { $num_visible = $file_assoc->num_visible; } } $db = new PHPWS_DB('fc_file_assoc'); $db->addWhere('file_type', (int) $file_type); switch ($file_type) { case FC_IMAGE_RESIZE: case FC_IMAGE_CROP: $db->addWhere('width', $this->max_width); $db->addWhere('height', $this->max_height); break; case FC_IMAGE_FOLDER: case FC_IMAGE_LIGHTBOX: $db->addWhere('vertical', $vertical); $db->addWhere('num_visible', $num_visible); break; } $db->addWhere('file_id', (int) $id); $result = $db->loadObject($file_assoc); if ($result) { if (PHPWS_Error::logIfError($result)) { return false; } elseif (!$update) { return $file_assoc; } } $file_assoc->file_type =& $file_type; $file_assoc->file_id = $id; switch ($file_type) { case FC_IMAGE_RESIZE: case FC_IMAGE_CROP: $file_assoc->width = $this->max_width; $file_assoc->height = $this->max_height; PHPWS_Core::initModClass('filecabinet', 'Image.php'); $image = new PHPWS_Image($id); if (!($dst = $image->makeResizePath())) { return false; } if ($cropped) { $resize_file_name = sprintf('%sx%s_crop.%s', $this->max_width, $this->max_height, $image->getExtension()); } else { $resize_file_name = sprintf('%sx%s.%s', $this->max_width, $this->max_height, $image->getExtension()); } if (!$image->resize($dst . $resize_file_name, $this->max_width, $this->max_height, $cropped)) { return false; } $file_assoc->resize =& $resize_file_name; break; case FC_IMAGE_FOLDER: case FC_IMAGE_LIGHTBOX: $file_assoc->vertical = $vertical; $file_assoc->num_visible = $num_visible; break; case FC_MEDIA_RESIZE: $file_assoc->width = $this->max_width; $file_assoc->height = $this->max_height; break; } $file_assoc->save(); $file_assoc->loadSource(); return $file_assoc; }
public function postTN() { PHPWS_Core::initModClass('filecabinet', 'Image.php'); if ($_POST['type'] == 'mm') { PHPWS_Core::initModClass('filecabinet', 'Multimedia.php'); $obj = new PHPWS_Multimedia($_POST['id']); if (!$obj->id) { return false; } } $thumb = PHPWS_Settings::get('filecabinet', 'max_thumbnail_size'); $image = new PHPWS_Image(); $image->setMaxWidth($thumb); $image->setMaxHeight($thumb); if (!$image->importPost('thumbnail')) { return false; } if ($obj->isVideo() && $image->file_type != 'image/jpeg' && $image->file_type != 'image/jpg') { return false; } if (!$obj->embedded) { $image->file_directory = $obj->thumbnailDirectory(); $image->file_name = $obj->dropExtension() . '.' . $image->getExtension(); } else { $image->file_directory = 'files/multimedia/folder' . $obj->folder_id . '/tn/'; } $image->write(); $image->resize($image->file_directory . $image->file_name, $image->getMaxWidth(), $image->getMaxHeight(), true); if ($obj->_classtype == 'multimedia') { $obj->thumbnail = $image->file_name; $obj->save(false, false); } return true; }