Example #1
0
 function mime_default_update(&$pStoreRow)
 {
     global $gBitSystem;
     // this will reset the uploaded file
     if (BitBase::verifyId($pStoreRow['attachment_id']) && !empty($pStoreRow['upload'])) {
         if (empty($pStoreRow['dest_branch'])) {
             $pStoreRow['dest_branch'] = liberty_mime_get_storage_branch(array('attachment_id' => $pStoreRow['attachment_id']));
         }
         if (!empty($pStoreRow['dest_branch']) && !empty($pStoreRow['file_name'])) {
             // First we remove the old file
             $path = STORAGE_PKG_PATH . $pStoreRow['dest_branch'];
             $file = $path . $pStoreRow['file_name'];
             if (($nuke = LibertyMime::validateStoragePath($path)) && is_dir($nuke)) {
                 if (!empty($pStoreRow['unlink_dir'])) {
                     @unlink_r($path);
                     mkdir($path);
                 } else {
                     @unlink($file);
                 }
             }
             // make sure we store the new file in the same place as before
             $pStoreRow['upload']['dest_branch'] = $pStoreRow['dest_branch'];
             // if we can create new thumbnails for this file, we remove the old ones first
             $canThumbFunc = liberty_get_function('can_thumbnail');
             if (!empty($canThumbFunc) && $canThumbFunc($pStoreRow['upload']['type'])) {
                 liberty_clear_thumbnails($pStoreRow['upload']);
             }
             // Now we process the uploaded file
             if ($storagePath = liberty_process_upload($pStoreRow['upload'])) {
                 $sql = "UPDATE `" . BIT_DB_PREFIX . "liberty_files` SET `file_name` = ?, `mime_type` = ?, `file_size` = ?, `user_id` = ? WHERE `file_id` = ?";
                 $gBitSystem->mDb->query($sql, array($pStoreRow['upload']['name'], $pStoreRow['upload']['type'], $pStoreRow['upload']['size'], $pStoreRow['user_id'], $pStoreRow['file_id']));
             }
             // ensure we have the correct guid in the db
             if (empty($pStoreRow['attachment_plugin_guid'])) {
                 $pStoreRow['attachment_plugin_guid'] = LIBERTY_DEFAULT_MIME_HANDLER;
             }
             $gBitSystem->mDb->associateUpdate(BIT_DB_PREFIX . "liberty_attachments", array('attachment_plugin_guid' => $pStoreRow['attachment_plugin_guid']), array('attachment_id' => $pStoreRow['attachment_id']));
         }
     }
     return TRUE;
 }
Example #2
0
 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'];
 }
Example #3
0
 /**
  * convertColorspace
  *
  * @param string $pColorSpace - target color space, only 'grayscale' is currently supported, and only when using the MagickWand image processor
  * @access public
  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  */
 function convertColorspace($pColorSpace)
 {
     global $gBitSystem;
     $ret = FALSE;
     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'] = dirname($this->getSourceFile()) . '/';
         $fileHash['name'] = $this->getField('file_name');
         if ($convertFunc = liberty_get_function('convert_colorspace')) {
             if ($ret = $convertFunc($fileHash, $pColorSpace)) {
                 liberty_clear_thumbnails($fileHash);
                 $sql = "UPDATE `" . BIT_DB_PREFIX . "liberty_files SET `file_size`=? WHERE `file_id` = ?";
                 $this->mDb->query($sql, array(filesize($fileHash['dest_file']), $this->mInfo['file_id']));
                 $this->generateThumbnails();
             }
         }
     }
     return $ret;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
            $_FILES['file']['error'] = 0;
            $_REQUEST['update_file'] = TRUE;
        }
    } else {
        $feedback['error'] = tra('The file could not be reprocessed. There was a problem locating the original file.');
    }
}
if (!empty($_REQUEST['update_file'])) {
    // this will override any thumbnails created by the plugin
    if (!empty($_FILES['icon']['tmp_name'])) {
        if (preg_match('#^image/#i', strtolower($_FILES['icon']['type']))) {
            if (!empty($_FILES['icon']['tmp_name'])) {
                $fileHash = $_FILES['icon'];
                $fileHash['dest_branch'] = dirname($gContent->mInfo['storage_path']) . '/';
                $fileHash['source_file'] = $_FILES['icon']['tmp_name'];
                liberty_clear_thumbnails($fileHash);
                liberty_generate_thumbnails($fileHash);
            }
            // we've done everything with the icon. this will ensure that LibertyMime doesn't get any crazy ideas
            unset($_FILES['icon']);
        } else {
            $feedback['error'] = tra("The file you uploaded doesn't appear to be a valid image. The reported mime type is") . ": " . $_FILES['icon']['type'];
        }
    }
    if (!empty($_FILES['file']['tmp_name'])) {
        $_REQUEST['upload'] = $_FILES['file'];
    }
    if ($gContent->store($_REQUEST)) {
        $feedback = $gContent->mErrors;
    }
    // give some feedback if all went well