/** * @access public * @return Returns <code>true</code> on success or <code>false</code> on error */ function delete($recurse = false) { // Rekursiv lˆschen? if (!$recurse && $this->hasChildren()) { return false; } if ($recurse) { $childs = $this->getChildren(); foreach ($childs as $child) { if (!$child->delete($recurse)) { return false; } } } // Alle Dateien lˆschen if ($this->hasMedia()) { $files = $this->getMedia(); foreach ($files as $file) { if (!$file->delete()) { return false; } } } $qry = 'DELETE FROM ' . $this->_getTableName() . ' WHERE id = ' . $this->getId() . ' LIMIT 1'; $sql = rex_sql::factory(); // $sql->debugsql = true; $sql->setQuery($qry); rex_deleteCacheMediaCategory($this->getId()); rex_deleteCacheMediaList($this->getId()); return !$sql->hasError() || $sql->getRows() != 1; }
/** * Holt ein upgeloadetes File und legt es in den Medienpool * Dabei wird kontrolliert ob das File schon vorhanden ist und es * wird eventuell angepasst, weiterhin werden die Fileinformationen übergeben * * @param $FILE * @param $rex_file_category * @param $FILEINFOS * @param $userlogin */ function rex_mediapool_saveMedia($FILE, $rex_file_category, $FILEINFOS, $userlogin = null, $doSubindexing = TRUE) { global $REX, $I18N; $rex_file_category = (int) $rex_file_category; $gc = rex_sql::factory(); $gc->setQuery('SELECT * FROM ' . $REX['TABLE_PREFIX'] . 'file_category WHERE id=' . $rex_file_category); if ($gc->getRows() != 1) { $rex_file_category = 0; } $isFileUpload = isset($FILE['tmp_name']); if ($isFileUpload) { $doSubindexing = TRUE; } $FILENAME = $FILE['name']; $FILESIZE = $FILE['size']; $FILETYPE = $FILE['type']; $NFILENAME = rex_mediapool_filename($FILENAME, $doSubindexing); $message = ''; // ----- alter/neuer filename $srcFile = $REX['MEDIAFOLDER'] . '/' . $FILENAME; $dstFile = $REX['MEDIAFOLDER'] . '/' . $NFILENAME; $success = true; if ($isFileUpload) { if (!@move_uploaded_file($FILE['tmp_name'], $dstFile)) { $message .= $I18N->msg("pool_file_movefailed"); $success = false; } } else { if (!@rename($srcFile, $dstFile)) { $message .= $I18N->msg("pool_file_movefailed"); $success = false; } } if ($success) { @chmod($dstFile, $REX['FILEPERM']); // get widht height $size = @getimagesize($dstFile); if ($FILETYPE == '' && isset($size['mime'])) { $FILETYPE = $size['mime']; } $FILESQL = rex_sql::factory(); $FILESQL->setTable($REX['TABLE_PREFIX'] . 'file'); $FILESQL->setValue('filetype', $FILETYPE); $FILESQL->setValue('title', $FILEINFOS['title']); $FILESQL->setValue('filename', $NFILENAME); $FILESQL->setValue('originalname', $FILENAME); $FILESQL->setValue('filesize', $FILESIZE); if ($size) { $FILESQL->setValue('width', $size[0]); $FILESQL->setValue('height', $size[1]); } $FILESQL->setValue('category_id', $rex_file_category); $FILESQL->addGlobalCreateFields($userlogin); $FILESQL->addGlobalUpdateFields($userlogin); $FILESQL->insert(); $message .= $I18N->msg("pool_file_added"); rex_deleteCacheMediaList($rex_file_category); } $RETURN['title'] = $FILEINFOS['title']; $RETURN['type'] = $FILETYPE; $RETURN['msg'] = $message; // Aus BC gruenden hier mit int 1/0 $RETURN['ok'] = $success ? 1 : 0; $RETURN['filename'] = $NFILENAME; $RETURN['old_filename'] = $FILENAME; if ($size) { $RETURN['width'] = $size[0]; $RETURN['height'] = $size[1]; } // ----- EXTENSION POINT if ($success) { rex_register_extension_point('MEDIA_ADDED', '', $RETURN); } return $RETURN; }
/** * @access public * @return Returns <code>true</code> on success or <code>false</code> on error */ function save() { $sql = rex_sql::factory(); $sql->setTable($this->_getTableName()); $sql->setValue('re_file_id', $this->getParentId()); $sql->setValue('category_id', $this->getCategoryId()); $sql->setValue('filetype', $this->getType()); $sql->setValue('filename', $this->getFileName()); $sql->setValue('originalname', $this->getOrgFileName()); $sql->setValue('filesize', $this->getSize()); $sql->setValue('width', $this->getWidth()); $sql->setValue('height', $this->getHeight()); $sql->setValue('title', $this->getTitle()); if ($this->getId() !== null) { $sql->addGlobalUpdateFields(); $sql->setWhere('file_id=' . $this->getId() . ' LIMIT 1'); $success = $sql->update(); if ($success) { rex_deleteCacheMedia($this->getFileName()); } return $success; } else { $sql->addGlobalCreateFields(); $success = $sql->insert(); if ($success) { rex_deleteCacheMediaList($this->getCategoryId()); } return $success; } }