Пример #1
0
 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;
 }
Пример #2
0
/**
 * liberty_process_generic
 *
 * @param array $pFileHash
 * @param array $pMoveFile
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function liberty_process_generic(&$pFileHash, $pMoveFile = TRUE)
{
    global $gBitSystem;
    $ret = NULL;
    if (!empty($pFileHash['dest_file'])) {
        $destFile = $pFileHash['dest_file'];
    } else {
        if ($gBitSystem->isFeatureActive('liberty_originalize_file_names')) {
            $destFile = STORAGE_PKG_PATH . $pFileHash['dest_branch'] . liberty_mime_get_default_file_name($pFileHash['name'], $pFileHash['type']);
        } else {
            $destFile = STORAGE_PKG_PATH . $pFileHash['dest_branch'] . $pFileHash['name'];
        }
        if (is_windows()) {
            $destFile = str_replace('//', '\\', str_replace("\\", '\\', $destFile));
        }
    }
    mkdir_p(dirname($destFile));
    if (is_file($pFileHash['source_file'])) {
        if ($pFileHash['source_file'] == $destFile) {
            // do nothing if source and dest are the same
        } elseif ($pMoveFile) {
            if (is_uploaded_file($pFileHash['source_file'])) {
                move_uploaded_file($pFileHash['source_file'], $destFile);
            } else {
                rename($pFileHash['source_file'], $destFile);
            }
        } else {
            copy($pFileHash['source_file'], $destFile);
        }
        $ret = $destFile;
    }
    $pFileHash['size'] = filesize($destFile);
    return $ret;
}
Пример #3
0
 function getSourceFile($pParamHash = array())
 {
     $ret = NULL;
     if (empty($pParamHash) && !empty($this)) {
         $pParamHash = $this->mInfo;
     }
     if ($fileName = $this->getParameter($pParamHash, 'file_name', $this->getField('file_name'))) {
         $defaultFileName = liberty_mime_get_default_file_name($fileName, $pParamHash['mime_type']);
         $ret = $this->getStoragePath($pParamHash) . $defaultFileName;
         if (!file_exists($ret)) {
             $ret = $this->getStoragePath($pParamHash) . basename($fileName);
         }
     }
     return $ret;
 }