/** * 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 la.`attachment_id`, la.`content_id`, la.`attachment_plugin_guid`, la.`foreign_id`, la.`user_id`, la.`is_primary`, la.`pos`, la.`error_code`, la.`caption`, la.`hits` AS `downloads`,\n\t\t\t\t\tlf.`file_id`, lf.`user_id`, lf.`file_name`, lf.`file_size`, lf.`mime_type`\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; $defaultFileName = liberty_mime_get_default_file_name($row['file_name'], $row['mime_type']); $storageBranchPath = liberty_mime_get_storage_branch(array('sub_dir' => $row['attachment_id'], 'user_id' => $row['user_id'], 'package' => liberty_mime_get_storage_sub_dir_name($row))); $storageBranch = $storageBranchPath . $defaultFileName; if (!file_exists(STORAGE_PKG_PATH . $storageBranch)) { $storageBranch = liberty_mime_get_storage_branch(array('sub_dir' => $row['attachment_id'], 'user_id' => $row['user_id'], 'package' => liberty_mime_get_storage_sub_dir_name($row))) . $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['mime_type'] = $row['mime_type']; $ret['source_file'] = STORAGE_PKG_PATH . $storageBranch; $ret['source_url'] = STORAGE_PKG_URL . $storageBranch; $ret['last_modified'] = filemtime($ret['source_file']); $ret['download_url'] = LibertyMime::getAttachmentDownloadUrl($row['attachment_id']); } // add a description of how to insert this file into a wiki page if ($gLibertySystem->isPluginActive('dataattachment')) { $ret['wiki_plugin_link'] = "{attachment id=" . $row['attachment_id'] . "}"; } } } return $ret; }
function liberty_mime_get_source_file($pParamHash) { if (empty($pParamHash['package'])) { $pParamHash['package'] = liberty_mime_get_storage_sub_dir_name(array('type' => BitBase::getParameter($pParamHash, 'mime_type'), 'name' => BitBase::getParameter($pParamHash, 'file_name'))); } if (empty($pParamHash['sub_dir'])) { $pParamHash['sub_dir'] = BitBase::getParameter($pParamHash, 'attachment_id'); } return STORAGE_PKG_PATH . liberty_mime_get_storage_branch($pParamHash) . basename(BitBase::getParameter($pParamHash, 'file_name')); }
/** * getStorageBranch - get url to store files for the feature site_upload_dir. It creates a calculable hierarchy of directories * * @access public * @author Christian Fowler<*****@*****.**> * @param $pSubDir any desired directory below the StoragePath. this will be created if it doesn't exist * @param $pUserId indicates the 'users/.../<user_id>' branch or use the 'common' branch if null * @param $pRootDir **deprecated, unused, will be removed in future relase**. * @return string full path on local filsystem to store files. */ function getStorageBranch($pParamHash) { return liberty_mime_get_storage_branch($pParamHash); }