/** * TODO: This code is old and is not used by any package in the bitweaver CVS anymore. * We will clean up this code as soon as we migrated all legacy code */ function store(&$pParamHash) { //deprecated( "This method has been replaced by a method in LibertyMime. Please try to migrate your code." ); global $gLibertySystem, $gBitSystem, $gBitUser; $this->mDb->StartTrans(); if (LibertyAttachable::verify($pParamHash) && (isset($pParamHash['skip_content_store']) || LibertyContent::store($pParamHash))) { if (!empty($pParamHash['STORAGE']) && count($pParamHash['STORAGE'])) { foreach (array_keys($pParamHash['STORAGE']) as $guid) { $storeRows =& $pParamHash['STORAGE'][$guid]; // short hand variable assignment // If it is empty then nothing more to do. Avoid error in foreach. if (empty($storeRows)) { continue; } foreach ($storeRows as $key => $value) { $storeRow =& $pParamHash['STORAGE'][$guid][$key]; $storeRow['plugin_guid'] = $guid; if (!@BitBase::verifyId($pParamHash['content_id'])) { $storeRow['content_id'] = NULL; } else { $storeRow['content_id'] = $pParamHash['content_id']; // copy in content_id } if (!empty($pParamHash['user_id'])) { $storeRow['user_id'] = $pParamHash['user_id']; // copy in the user_id } else { $storeRow['user_id'] = $gBitUser->mUserId; } // do we have a verify function for this storage type, and do things verify? $verifyFunc = $gLibertySystem->getPluginFunction($guid, 'verify_function'); if ($verifyFunc && $verifyFunc($storeRow)) { // For backwards compatibility with a single upload. if (@BitBase::verifyId($pParamHash['attachment_id'])) { $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = $pParamHash['attachment_id']; } else { if (!isset($storeRow['skip_insert'])) { if (defined('LINKED_ATTACHMENTS') && @BitBase::verifyId($pParamHash['content_id'])) { $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = $pParamHash['content_id']; } else { $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = defined('LINKED_ATTACHMENTS') ? $this->mDb->GenID('liberty_content_id_seq') : $this->mDb->GenID('liberty_attachments_id_seq'); } } } // if we have uploaded a file, we can take care of that generically if (!empty($storeRow['upload']) && is_array($storeRow['upload']) && !empty($storeRow['upload']['size'])) { if (empty($storeRow['upload']['type'])) { $ext = substr($storeRow['upload']['name'], strrpos($storeRow['upload']['name'], '.') + 1); $storeRow['upload']['type'] = $gBitSystem->lookupMimeType($ext); } $storeRow['upload']['dest_branch'] = $this->getStorageBranch($storeRow['attachment_id'], $storeRow['user_id'], $this->getStorageSubDirName()); if (!empty($pParamHash['thumbnail_sizes'])) { $storeRow['upload']['thumbnail_sizes'] = $pParamHash['thumbnail_sizes']; } $storagePath = liberty_process_upload($storeRow['upload']); // We're gonna store to local file system & liberty_files table if (empty($storagePath)) { $this->mErrors['file'] = tra("Could not store file") . ": " . $storeRow['upload']['name'] . '.'; $storeRow['attachment_id'] = NULL; $storeRow['upload']['attachment_id'] = NULL; } else { $storeRow['upload']['dest_file_path'] = $storagePath; } } if (@BitBase::verifyId($storeRow['attachment_id']) && ($storeFunc = $gLibertySystem->getPluginFunction($storeRow['plugin_guid'], 'store_function'))) { $this->mStorage = $storeFunc($storeRow); } // don't insert if we already have an entry with this attachment_id if (@BitBase::verifyId($storeRow['attachment_id']) && !isset($storeRow['skip_insert']) && !LibertyMime::loadAttachment($storeRow['attachment_id'])) { $sql = "INSERT INTO `" . BIT_DB_PREFIX . "liberty_attachments` ( `content_id`, `attachment_id`, `attachment_plugin_guid`, `foreign_id`, `user_id` ) VALUES ( ?, ?, ?, ?, ? )"; $rs = $this->mDb->query($sql, array($storeRow['content_id'], $storeRow['attachment_id'], $storeRow['plugin_guid'], (int) $storeRow['foreign_id'], $storeRow['user_id'])); } } } } } // set the primary attachment id $this->setPrimaryAttachment($pParamHash['liberty_attachments']['primary'], $pParamHash['content_id'], empty($pParamHash['liberty_attachments']['auto_primary']) || $pParamHash['liberty_attachments']['auto_primary'] ? TRUE : FALSE); } $this->mDb->CompleteTrans(); return count($this->mErrors) == 0; }
function mime_default_store(&$pStoreRow) { global $gBitSystem, $gLibertySystem; $ret = FALSE; // take care of the uploaded file and insert it into the liberty_files and liberty_attachments tables if ($storagePath = liberty_process_upload($pStoreRow['upload'], empty($pStoreRow['upload']['copy_file']))) { // add row to liberty_files $storeHash = array("file_name" => $pStoreRow['upload']['name'], "file_id" => $pStoreRow['attachment_id'], "mime_type" => $pStoreRow['upload']['type'], "file_size" => $pStoreRow['upload']['size'], "user_id" => $pStoreRow['user_id']); if (!$storeHash['file_size']) { $storeHash['file_size'] = 0; } $gBitSystem->mDb->associateInsert(BIT_DB_PREFIX . "liberty_files", $storeHash); // add the data into liberty_attachments to make this file available as attachment $storeHash = array("attachment_id" => $pStoreRow['attachment_id'], "content_id" => $pStoreRow['content_id'], "attachment_plugin_guid" => !empty($pStoreRow['attachment_plugin_guid']) ? $pStoreRow['attachment_plugin_guid'] : PLUGIN_MIME_GUID_FLATDEFAULT, "foreign_id" => $pStoreRow['attachment_id'], "user_id" => $pStoreRow['user_id']); $gBitSystem->mDb->associateInsert(BIT_DB_PREFIX . "liberty_attachments", $storeHash); $ret = TRUE; } else { $pStoreRow['errors']['liberty_process'] = "There was a problem processing the file."; } return $ret; }