Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 public function getDownloadUrl()
 {
     $ret = "";
     if ($this->isValid() && $this->getField('attachment_id')) {
         $ret = LibertyMime::getAttachmentDownloadUrl($this->getField('attachment_id'));
     }
     return $ret;
 }