function bit_files_load($pRow) { // this fuction broken, will fix soon - spiderr // I think its fixed now - no promises though! - drewslater global $gBitSystem, $gLibertySystem; $ret = array(); if (!empty($pRow['foreign_id']) && is_numeric($pRow['foreign_id'])) { $query = "\n\t\t\tSELECT *\n\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_attachments` la\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_files` lf ON (lf.`file_id` = la.`foreign_id`)\n\t\t\tWHERE la.`foreign_id` = ? AND `attachment_plugin_guid` = ?"; if ($ret = $gBitSystem->mDb->getRow($query, array($pRow['foreign_id'], PLUGIN_GUID_BIT_FILES))) { $ret['file_name'] = basename($ret['file_name']); $ret['source_file'] = liberty_mime_get_source_file($ret); $canThumbFunc = liberty_get_function('can_thumbnail'); if ($canThumbFunc($ret['mime_type'])) { $thumbHash['default_image'] = LIBERTY_PKG_URL . 'icons/generating_thumbnails.png'; } $ret['source_url'] = liberty_mime_get_source_url($ret); $ret['thumbnail_url'] = liberty_fetch_thumbnails($ret); $ret['wiki_plugin_link'] = "{attachment id=" . $ret['attachment_id'] . "}"; } } return $ret; }
/** * mime_image_create_panorama * * @param array $pStoreRow * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function mime_image_create_panorama(&$pStoreRow) { global $gBitSystem, $gThumbSizes; // we know the panorama image will be a jpeg, so we don't need the canThumbFunc check here if (($panoramaFunc = liberty_get_function('panorama')) && !empty($pStoreRow['source_file']) && is_file($pStoreRow['source_file'])) { // the panorama has to be a jpg $gBitSystem->setConfig('liberty_thumbnail_format', 'jpg'); $width = $gBitSystem->getConfig('mime_image_panorama_width', 3000); $gThumbSizes['panorama'] = array($width, $width / 2); // for the panorama, we will force a quality lower than 75 to reduce image size if ($gBitSystem->getConfig('liberty_thumbnail_quality', 85) > 75) { $gBitSystem->setConfig('liberty_thumbnail_quality', 75); } $genHash = array('attachment_id' => $pStoreRow['attachment_id'], 'dest_branch' => liberty_mime_get_storage_branch(array('sub_dir' => $pStoreRow['attachment_id'], 'user_id' => $pStoreRow['user_id'], 'package' => liberty_mime_get_storage_sub_dir_name($pStoreRow))), 'file_name' => dirname($pStoreRow['file_name']) . "/", 'source_file' => $pStoreRow['source_file'], 'type' => $pStoreRow['mime_type'], 'thumbnail_sizes' => array('panorama')); if (liberty_generate_thumbnails($genHash)) { // we want to modify the panorama $genHash['source_file'] = $genHash['icon_thumb_path']; if (!$panoramaFunc($genHash)) { $pStoreRow['errors']['panorama'] = $genHash['error']; } } return empty($pStoreRow['errors']); } }
function mime_default_load($pFileHash, &$pPrefs) { global $gBitSystem, $gLibertySystem; $ret = FALSE; if (@BitBase::verifyId($pFileHash['attachment_id'])) { $query = "\n\t\t\t\tSELECT *\n\t\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_attachments` la\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` lf ON( la.`foreign_id` = lf.`file_id` )\n\t\t\t\tWHERE la.`attachment_id`=?"; if ($row = $gBitSystem->mDb->getRow($query, array($pFileHash['attachment_id']))) { $ret = array_merge($pFileHash, $row); $storageName = basename($row['file_name']); // compatibility with _FILES hash $row['name'] = $storageName; $row['type'] = $row['mime_type']; $storageBranch = liberty_mime_get_storage_branch(array('attachment_id' => $row['attachment_id'])) . $storageName; // this will fetch the correct thumbnails $thumbHash['source_file'] = STORAGE_PKG_PATH . $storageBranch; $row['source_file'] = STORAGE_PKG_PATH . $storageBranch; $canThumbFunc = liberty_get_function('can_thumbnail'); if ($canThumbFunc && $canThumbFunc($row['mime_type'])) { $thumbHash['default_image'] = LIBERTY_PKG_URL . 'icons/generating_thumbnails.png'; } $ret['thumbnail_url'] = liberty_fetch_thumbnails($thumbHash); // indicate that this is a mime thumbnail if (!empty($ret['thumbnail_url']['medium']) && strpos($ret['thumbnail_url']['medium'], '/mime/')) { $ret['thumbnail_is_mime'] = TRUE; } // pretty URLs if ($gBitSystem->isFeatureActive("pretty_urls") || $gBitSystem->isFeatureActive("pretty_urls_extended")) { $ret['display_url'] = LIBERTY_PKG_URL . "view/file/" . $row['attachment_id']; } else { $ret['display_url'] = LIBERTY_PKG_URL . "view_file.php?attachment_id=" . $row['attachment_id']; } // legacy table data was named storage path and included a partial path. strip out any path just in case $ret['file_name'] = $storageName; $ret['preferences'] = $pPrefs; // some stuff is only available if we have a source file // make sure to check for these when you use them. frequently the original might not be available // e.g.: video files are large and the original might be deleted after conversion if (is_file(STORAGE_PKG_PATH . $storageBranch)) { $ret['source_file'] = STORAGE_PKG_PATH . $storageBranch; $ret['source_url'] = STORAGE_PKG_URL . $storageBranch; $ret['last_modified'] = filemtime($ret['source_file']); if ($gBitSystem->isFeatureActive("pretty_urls") || $gBitSystem->isFeatureActive("pretty_urls_extended")) { $ret['download_url'] = LIBERTY_PKG_URL . "download/file/" . $row['attachment_id']; } else { $ret['download_url'] = LIBERTY_PKG_URL . "download_file.php?attachment_id=" . $row['attachment_id']; } } // add a description of how to insert this file into a wiki page if ($gLibertySystem->isPluginActive('dataattachment')) { $ret['wiki_plugin_link'] = "{image id=" . $row['attachment_id'] . "}"; } // additionally we'll add this to distinguish between old plugins and new ones // TODO: this should hopefully not be necessary for too long $ret['is_mime'] = TRUE; } } return $ret; }
/** * liberty_generate_thumbnails * * @param array $pFileHash * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function liberty_generate_thumbnails($pFileHash) { global $gBitSystem, $gThumbSizes; $resizeFunc = liberty_get_function('resize'); $ret = FALSE; // allow custom selection of thumbnail sizes if (empty($pFileHash['thumbnail_sizes'])) { if (!empty($gThumbSizes) && is_array($gThumbSizes)) { $pFileHash['thumbnail_sizes'] = array_keys($gThumbSizes); } else { $pFileHash['thumbnail_sizes'] = array('large', 'medium', 'small', 'avatar', 'icon'); } } if (!preg_match('#image/(gif|jpe?g|png)#i', $pFileHash['type']) && $gBitSystem->isFeatureActive('liberty_jpeg_originals') || in_array('original', $pFileHash['thumbnail_sizes'])) { // jpeg version of original if (preg_match('/pdf/i', $pFileHash['type'])) { // has a customer pdf rasterization function been defined? if (function_exists('liberty_rasterize_pdf') && ($rasteredFile = liberty_rasterize_pdf($pFileHash['source_file']))) { $pFileHash['source_file'] = $rasteredFile; } else { $magickWand = NewMagickWand(); if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickReadImage($magickWand, $pFileHash['source_file']), $magickWand))) { MagickSetFormat($magickWand, 'JPG'); if (MagickGetImageColorspace($magickWand) == MW_CMYKColorspace) { MagickProfileImage($magickWand, "ICC", UTIL_PKG_PATH . 'icc/srgb.icm'); MagickSetImageColorspace($magickWand, MW_sRGBColorspace); } $imgWidth = MagickGetImageWidth($magickWand); $imgHeight = MagickGetImageHeight($magickWand); MagickSetImageUnits($magickWand, MW_PixelsPerInchResolution); MagickSetResolution($magickWand, 300, 300); $rasteredFile = dirname($pFileHash['source_file']) . '/original.jpg'; if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickWriteImage($magickWand, $rasteredFile), $magickWand))) { $pFileHash['source_file'] = $rasteredFile; } } } } else { $pFileHash['dest_base_name'] = 'original'; $pFileHash['name'] = 'original.jpg'; $pFileHash['max_width'] = MAX_THUMBNAIL_DIMENSION; $pFileHash['max_height'] = MAX_THUMBNAIL_DIMENSION; if ($convertedFile = $resizeFunc($pFileHash)) { $pFileHash['source_file'] = $convertedFile; $ret = TRUE; } } $pFileHash['type'] = $gBitSystem->verifyMimeType($pFileHash['source_file']); } // override $mimeExt if we have a custom setting for it if ($gBitSystem->isFeatureActive('liberty_thumbnail_format')) { $mimeExt = $gBitSystem->getConfig('liberty_thumbnail_format'); } else { list($type, $mimeExt) = preg_split('#/#', strtolower($pFileHash['type'])); } if (preg_match("!(png|gif)!", $mimeExt)) { $destExt = '.' . $mimeExt; } else { $destExt = '.jpg'; } $initialDestPath = $pFileHash['dest_branch']; foreach ($pFileHash['thumbnail_sizes'] as $thumbSize) { if (isset($gThumbSizes[$thumbSize])) { $pFileHash['dest_base_name'] = $thumbSize; $pFileHash['name'] = $thumbSize . $destExt; if (!empty($gThumbSizes[$thumbSize]['width'])) { $pFileHash['max_width'] = $gThumbSizes[$thumbSize]['width']; } else { // Have to unset since we reuse $pFileHash unset($pFileHash['max_width']); } // reset dest_branch for created thumbs if (!empty($pFileHash['thumb_path'])) { $pFileHash['dest_file'] = $pFileHash['thumb_path'] . $pFileHash['name']; } else { // create a subdirectory for the thumbs $pFileHash['dest_branch'] = $initialDestPath . 'thumbs/'; clearstatcache(); if (!is_dir(STORAGE_PKG_PATH . $pFileHash['dest_branch'])) { mkdir(STORAGE_PKG_PATH . $pFileHash['dest_branch'], 0775, TRUE); clearstatcache(); } } if (!empty($gThumbSizes[$thumbSize]['height'])) { $pFileHash['max_height'] = $gThumbSizes[$thumbSize]['height']; } else { // Have to unset since we reuse $pFileHash unset($pFileHash['max_height']); } if ($pFileHash['icon_thumb_path'] = $resizeFunc($pFileHash)) { $ret = TRUE; // use the previous thumb as the source for the next, decreasingly smaller thumb as this GREATLY increases speed $pFileHash['source_file'] = $pFileHash['icon_thumb_path']; } } } // to keep everything in bitweaver working smoothly, we need to remove the thumbs/ subdir again $pFileHash['dest_branch'] = $initialDestPath; return $ret; }
public function storeTopic($iParamHash = NULL) { global $gLibertySystem; global $gBitUser; if ($this->verify($iParamHash)) { if (!$iParamHash['topic_id']) { $topicId = $this->mDb->GenID('article_topics_id_seq'); } else { $topicId = $this->mTopicId; } if (!empty($_FILES['upload']) && $_FILES['upload']['tmp_name']) { $checkFunc = liberty_get_function('can_thumbnail'); if ($checkFunc($_FILES['upload']['type'])) { $fileHash = $_FILES['upload']; $fileHash['dest_branch'] = $this->getTopicImageBaseUrl($topicId); $fileHash['source_file'] = $fileHash['tmp_name']; liberty_clear_thumbnails($fileHash); liberty_generate_thumbnails($fileHash); $iParamHash['has_topic_image'] = 'y'; } else { $this->mErrors = tra("The file you uploaded doesn't appear to be a valid image. The reported mime type is") . ": " . $_FILES['upload']['type']; } } if ($iParamHash['topic_id']) { $this->mDb->associateUpdate(BIT_DB_PREFIX . "article_topics", $iParamHash, array('topic_id' => $iParamHash['topic_id'])); } else { $iParamHash['topic_id'] = $topicId; $this->mDb->associateInsert(BIT_DB_PREFIX . "article_topics", $iParamHash); } } $this->mTopicId = $iParamHash['topic_id']; }
/** * Store TreasuryGallery * * @param $pParamHash contains all data to store the gallery * @param $pParamHash[title] title of the new gallery * @param $pParamHash[edit] description of the gallery * @param $pParamHash[root_structure_id] if this is set, it will add the gallery to this structure. if it's not set, a new structure / top level gallery is created * @param $pParamHash[parent_id] set the structure_id that will server as the parent in the structure * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why * @access public **/ function store(&$pParamHash) { $this->mDb->StartTrans(); if ($this->verify($pParamHash) && LibertyContent::store($pParamHash)) { $table = BIT_DB_PREFIX . "treasury_gallery"; // this really confusing, strange order way of saving items is due to strange behaviour of GenID // probably has to do with not null default nextval('public.liberty_structures_id_seq'::text) if (!empty($pParamHash['update'])) { if (!empty($pParamHash['gallery_store'])) { $result = $this->mDb->associateUpdate($table, $pParamHash['gallery_store'], array("content_id" => $this->mContentId)); } $pParamHash['structure_location_id'] = $this->mStructureId; } else { // update the gallery_store and structure_store content_id with the one from LibertyMime::store() $pParamHash['structure_store']['content_id'] = $pParamHash['content_id']; $pParamHash['gallery_store']['content_id'] = $pParamHash['content_id']; // we need to store the new structure node now global $gStructure; // create new object if needed if (empty($gStructure)) { $gStructure = new LibertyStructure(); } $pParamHash['structure_location_id'] = $gStructure->storeNode($pParamHash['structure_store']); // get the corrent structure_id // structure_id has to be done like this since it's screwed up in the schema $pParamHash['gallery_store']['structure_id'] = $this->mDb->getOne("SELECT MAX( `structure_id` ) FROM `" . BIT_DB_PREFIX . "liberty_structures`"); $result = $this->mDb->associateInsert($table, $pParamHash['gallery_store']); } $this->mDb->CompleteTrans(); // process image upload if (empty($this->mErrors)) { // now deal with the uploaded image if (!empty($pParamHash['thumb']['tmp_name'])) { $checkFunc = liberty_get_function('can_thumbnail'); if ($checkFunc($pParamHash['thumb']['type'])) { $fileHash = $pParamHash['thumb']; $fileHash['dest_branch'] = $this->getGalleryThumbBaseUrl(); $fileHash['source_file'] = $fileHash['tmp_name']; liberty_clear_thumbnails($fileHash); liberty_generate_thumbnails($fileHash); } else { $this->mErrors['thumb'] = tra("The file you uploaded doesn't appear to be a valid image. The reported mime type is") . ": " . $pParamHash['thumb']['type']; } } } $this->load(); } return count($this->mErrors) == 0; }
/** * All the files that have been extracted so far need to be processed and moved around * * @param array $pStoreRow * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function treasury_theme_process_extracted_files($pStoreRow) { // if this is a theme, we need to convert the preview image into thumbnails if (!empty($pStoreRow['thumb'])) { $pStoreRow['thumb']['source_file'] = $pStoreRow['thumb']['tmp_name']; $pStoreRow['thumb']['dest_branch'] = $pStoreRow['upload']['dest_branch']; $pStoreRow['thumb']['dest_base_name'] = $pStoreRow['thumb']['name']; liberty_generate_thumbnails($pStoreRow['thumb']); } // if we have screenshots we better do something with them if (!empty($pStoreRow['screenshots'])) { foreach ($pStoreRow['screenshots'] as $key => $sshot) { $resizeFunc = liberty_get_function('resize'); $sshot['source_file'] = $sshot['tmp_name']; $sshot['dest_base_name'] = $sshot['name']; $sshot['dest_branch'] = $pStoreRow['upload']['dest_branch']; $sshot['max_width'] = 400; $sshot['max_height'] = 300; $sshot['medium_thumb_path'] = BIT_ROOT_PATH . $resizeFunc($sshot); } } // if we have icons, we should place them somewhere that we can display them if (!empty($pStoreRow['icons'])) { @mkdir(BIT_ROOT_PATH . $pStoreRow['upload']['dest_branch'] . 'icons'); foreach ($pStoreRow['icons'] as $icon) { $dest = BIT_ROOT_PATH . $pStoreRow['upload']['dest_branch'] . 'icons/' . basename($icon); if ($icon != $dest) { rename($icon, $dest); } } } // now that all is done, we can remove temporarily extracted files if (!empty($pStoreRow['ext_path'])) { unlink_r($pStoreRow['ext_path']); } }
function resizeOriginal($pResizeOriginal) { global $gBitSystem; if ($this->getField('file_name') || $this->load()) { $fileHash['source_file'] = $this->getSourceFile(); $fileHash['dest_base_name'] = preg_replace('/(.+)\\..*$/', '$1', basename($fileHash['source_file'])); $fileHash['type'] = $gBitSystem->verifyMimeType($fileHash['source_file']); $fileHash['size'] = filesize($fileHash['source_file']); $fileHash['dest_branch'] = $this->getStorageBranch(); $fileHash['name'] = $this->getField('file_name'); $fileHash['max_height'] = $fileHash['max_width'] = $pResizeOriginal; // make a copy of the fileHash that we can compare output after processing $preResize = $fileHash; $resizeFunc = liberty_get_function('resize'); if ($resizeFile = $resizeFunc($fileHash)) { clearstatcache(); // Ack this is evil direct bashing of the liberty tables! XOXO spiderr // should be a cleaner way eventually // we need to update the souce_file in case it's changed from a non jpg to a jpg if ($fileHash['name'] != $preResize['name']) { $fileHash['source_file'] = dirname($fileHash['source_file']) . '/' . $fileHash['name']; // make absolutely certain that we have 2 image files and that they are different, then remove the original if ($fileHash['source_file'] != $preResize['source_file'] && is_file($fileHash['source_file']) && is_file($preResize['source_file'])) { @unlink($preResize['source_file']); } } $details = $this->getImageDetails($resizeFile); // store all the values that might have changed due to the resize $storeHash = array('file_size' => filesize($resizeFile), 'mime_type' => $details['mime']); $this->mDb->associateUpdate(BIT_DB_PREFIX . "liberty_files", $storeHash, array('file_id' => $this->mInfo['file_id'])); //$query = "UPDATE `".BIT_DB_PREFIX."liberty_files` SET `file_size`=? WHERE `file_id`=?"; //$this->mDb->query( $query, array( $details['size'], $this->mInfo['file_id'] ) ); $query = "UPDATE `" . BIT_DB_PREFIX . "fisheye_image` SET `width`=?, `height`=? WHERE `content_id`=?"; $this->mDb->query($query, array($details['width'], $details['height'], $this->mContentId)); // if we've come this far, we can try removing the original if it's different to the resized image // make absolutely certain that we have 2 image files and that they are different, then remove the original if ($fileHash['source_file'] != $preResize['source_file'] && is_file($fileHash['source_file']) && is_file($preResize['source_file'])) { @unlink($preResize['source_file']); } } else { $this->mErrors['resize'] = $fileHash['error']; } } return count($this->mErrors) == 0; }