/** * @param string $name * * @return null|self */ public static function get($name) { if (!$name) { return null; } return self::getInstance($name, function ($name) { $media_path = rex_path::addonCache('mediapool', $name . '.media'); if (!file_exists($media_path)) { rex_media_cache::generate($name); } if (file_exists($media_path)) { $cache = rex_file::getCache($media_path); $aliasMap = ['filename' => 'name', 'filetype' => 'type', 'filesize' => 'size']; $media = new self(); foreach ($cache as $key => $value) { if (array_key_exists($key, $aliasMap)) { $var_name = $aliasMap[$key]; } else { $var_name = $key; } $media->{$var_name} = $value; } $media->category = null; return $media; } return null; }); }
} // *************************************** EXTRA FUNCTIONS if ($PERMALL && $media_method == 'updatecat_selectedmedia') { $selectedmedia = rex_post('selectedmedia', 'array'); if (isset($selectedmedia[0]) && $selectedmedia[0] != '') { foreach ($selectedmedia as $file_name) { $db = rex_sql::factory(); // $db->setDebug(); $db->setTable(rex::getTablePrefix() . 'media'); $db->setWhere(['filename' => $file_name]); $db->setValue('category_id', $rex_file_category); $db->addGlobalUpdateFields(); try { $db->update(); $success = rex_i18n::msg('pool_selectedmedia_moved'); rex_media_cache::delete($file_name); } catch (rex_sql_exception $e) { $error = rex_i18n::msg('pool_selectedmedia_error'); } } } else { $error = rex_i18n::msg('pool_selectedmedia_error'); } } if ($PERMALL && $media_method == 'delete_selectedmedia') { $selectedmedia = rex_post('selectedmedia', 'array'); if (count($selectedmedia) != 0) { $error = []; $success = []; $countDeleted = 0; foreach ($selectedmedia as $file_name) {
/** * @param string $filename * * @return bool */ function rex_mediapool_deleteMedia($filename) { if ($uses = rex_mediapool_mediaIsInUse($filename)) { $msg = '<strong>' . rex_i18n::msg('pool_file_delete_error_1', $filename) . ' ' . rex_i18n::msg('pool_file_delete_error_2') . '</strong><br />' . $uses; return ['ok' => false, 'msg' => $msg]; } $sql = rex_sql::factory(); $sql->setQuery('DELETE FROM ' . rex::getTable('media') . ' WHERE filename = ? LIMIT 1', [$filename]); rex_file::delete(rex_path::media($filename)); rex_media_cache::delete($filename); rex_extension::registerPoint(new rex_extension_point('MEDIA_DELETED', '', ['filename' => $filename])); return ['ok' => true, 'msg' => rex_i18n::msg('pool_file_deleted')]; }
/** * @return rex_media[] */ public function getMedia() { return self::getInstanceList([$this->getId(), 'media'], 'rex_media::get', function ($id) { $list_path = rex_path::addonCache('mediapool', $id . '.mlist'); if (!file_exists($list_path)) { rex_media_cache::generateList($id); } return rex_file::getCache($list_path); }); }
rex_media_cache::deleteLists(); $success = rex_i18n::msg('pool_kat_deleted'); } else { $error = rex_i18n::msg('pool_kat_not_deleted'); } } elseif ($media_method == 'add_file_cat') { $db = rex_sql::factory(); $db->setTable(rex::getTablePrefix() . 'media_category'); $db->setValue('name', rex_request('catname', 'string')); $db->setValue('parent_id', rex_request('cat_id', 'int')); $db->setValue('path', rex_request('catpath', 'string')); $db->addGlobalCreateFields(); $db->addGlobalUpdateFields(); $db->insert(); $success = rex_i18n::msg('pool_kat_saved', rex_request('catname')); rex_media_cache::deleteCategoryList(rex_request('cat_id', 'int')); } } catch (rex_sql_exception $e) { $error = $e->getMessage(); } $link = rex_url::currentBackendPage(array_merge($arg_url, ['cat_id' => ''])); $breadcrumb = []; $n = []; $n['title'] = rex_i18n::msg('pool_kat_start'); $n['href'] = $link . '0'; $breadcrumb[] = $n; $cat_id = rex_request('cat_id', 'int'); if ($cat_id == 0 || !($OOCat = rex_media_category::get($cat_id))) { $OOCats = rex_media_category::getRootCategories(); $cat_id = 0; $catpath = '|';
foreach ($db_files as $db_file) { $file_filesize = filesize(rex_path::media($db_file['filename'])); if ($db_file['filesize'] != $file_filesize) { $file_sql = rex_sql::factory(); $file_sql->debugsql = 1; $file_sql->setTable(rex::getTable('media')); $file_sql->setWhere(['filename' => $db_file['filename']]); $file_sql->setValue('filesize', $file_filesize); if ($db_file['width'] > 0) { if ($size = @getimagesize(rex_path::media($db_file['filename']))) { $file_sql->setValue('width', $size[0]); $file_sql->setValue('height', $size[1]); } } $file_sql->update(); rex_media_cache::delete($db_file['filename']); } } $error = []; if (rex_post('save', 'boolean') && rex_post('sync_files', 'boolean')) { $sync_files = rex_post('sync_files', 'array'); $ftitle = rex_post('ftitle', 'string'); if ($diff_count > 0) { $success = []; $first = true; foreach ($sync_files as $file) { // hier mit is_int, wg kompatibilität zu PHP < 4.2.0 if (!is_int($key = array_search($file, $diff_files))) { continue; } $syncResult = rex_mediapool_syncFile($file, $rex_file_category, $ftitle, '', '');