/** * Löscht eine Clang. * * @param int $id Zu löschende ClangId * * @throws rex_exception */ public static function deleteCLang($id) { $startClang = rex_clang::getStartId(); if ($id == $startClang) { throw new rex_functional_exception(rex_i18n::msg('clang_error_startidcanotbedeleted', $startClang)); } if (!rex_clang::exists($id)) { throw new rex_functional_exception(rex_i18n::msg('clang_error_idcanotbedeleted', $id)); } $clang = rex_clang::get($id); $del = rex_sql::factory(); $del->setQuery('delete from ' . rex::getTablePrefix() . 'clang where id=?', [$id]); rex_sql_util::organizePriorities(rex::getTable('clang'), 'priority', '', 'priority'); rex_delete_cache(); // ----- EXTENSION POINT rex_extension::registerPoint(new rex_extension_point('CLANG_DELETED', '', ['id' => $clang->getId(), 'name' => $clang->getName(), 'clang' => $clang])); }
public static function clangAdded(\rex_extension_point $ep) { $firstLang = \rex_sql::factory(); $firstLang->setQuery('SELECT * FROM ' . \rex::getTable('sprog_wildcard') . ' WHERE clang_id=?', [\rex_clang::getStartId()]); $fields = $firstLang->getFieldnames(); $newLang = \rex_sql::factory(); $newLang->setDebug(false); foreach ($firstLang as $firstLangEntry) { $newLang->setTable(\rex::getTable('sprog_wildcard')); foreach ($fields as $key => $value) { if ($value == 'pid') { echo ''; } elseif ($value == 'clang_id') { $newLang->setValue('clang_id', $ep->getParam('clang')->getId()); } else { $newLang->setValue($value, $firstLangEntry->getValue($value)); } } $newLang->insert(); } }
//ggf wiederanzeige des add forms, falls ungueltige id uebermittelt $content .= ' <tr class="mark"> <td class="rex-table-icon"><i class="rex-icon rex-icon-language"></i></td> <td class="rex-table-id" data-title="' . rex_i18n::msg('id') . '">–</td> <td data-title="' . rex_i18n::msg('clang_code') . '"><input class="form-control" type="text" id="rex-form-clang-code" name="clang_code" value="' . htmlspecialchars($clang_code) . '" autofocus /></td> <td data-title="' . rex_i18n::msg('clang_name') . '"><input class="form-control" type="text" id="rex-form-clang-name" name="clang_name" value="' . htmlspecialchars($clang_name) . '" /></td> <td class="rex-table-priority" data-title="' . rex_i18n::msg('clang_priority') . '"><input class="form-control" type="text" id="rex-form-clang-prio" name="clang_prio" value="' . ($clang_prio ?: rex_clang::count() + 1) . '" /></td> <td class="rex-table-action" colspan="2"><button class="btn btn-save" type="submit" name="add_clang_save"' . rex::getAccesskey(rex_i18n::msg('clang_add'), 'save') . ' value="1">' . rex_i18n::msg('clang_add') . '</button></td> </tr> '; } foreach (rex_clang::getAll() as $lang_id => $lang) { $add_td = '<td class="rex-table-id" data-title="' . rex_i18n::msg('id') . '">' . $lang_id . '</td>'; $delLink = rex_i18n::msg('delete'); if ($lang_id == rex_clang::getStartId()) { $delLink = '<span class="text-muted"><i class="rex-icon rex-icon-delete"></i> ' . $delLink . '</span>'; } else { $delLink = '<a href="' . rex_url::currentBackendPage(['func' => 'deleteclang', 'clang_id' => $lang_id]) . '" data-confirm="' . rex_i18n::msg('delete') . ' ?"><i class="rex-icon rex-icon-delete"></i> ' . $delLink . '</a>'; } // Edit form if ($func == 'editclang' && $clang_id == $lang_id) { $content .= ' <tr class="mark"> <td class="rex-table-icon"><i class="rex-icon rex-icon-language"></i></td> ' . $add_td . ' <td data-title="' . rex_i18n::msg('clang_code') . '"><input class="form-control" type="text" id="rex-form-clang-code" name="clang_code" value="' . htmlspecialchars($lang->getCode()) . '" autofocus /></td> <td data-title="' . rex_i18n::msg('clang_name') . '"><input class="form-control" type="text" id="rex-form-clang-name" name="clang_name" value="' . htmlspecialchars($lang->getName()) . '" /></td> <td class="rex-table-priority" data-title="' . rex_i18n::msg('clang_priority') . '"><input class="form-control" type="text" id="rex-form-clang-prio" name="clang_prio" value="' . htmlspecialchars($lang->getPriority()) . '" /></td> <td class="rex-table-action" colspan="2"><button class="btn btn-save" type="submit" name="edit_clang_save"' . rex::getAccesskey(rex_i18n::msg('clang_update'), 'save') . ' value="1">' . rex_i18n::msg('clang_update') . '</button></td> </tr>';
/** * Verschieben einer Kategorie in eine andere. * * @param int $from_cat KategorieId der Kategorie, die verschoben werden soll (Quelle) * @param int $to_cat KategorieId der Kategorie, IN die verschoben werden soll (Ziel) * * @return bool TRUE bei Erfolg, sonst FALSE */ public static function moveCategory($from_cat, $to_cat) { $from_cat = (int) $from_cat; $to_cat = (int) $to_cat; if ($from_cat == $to_cat) { // kann nicht in gleiche kategroie kopiert werden return false; } else { // kategorien vorhanden ? // ist die zielkategorie im pfad der quellkategeorie ? $fcat = rex_sql::factory(); $fcat->setQuery('select * from ' . rex::getTablePrefix() . 'article where startarticle=1 and id=? and clang_id=?', [$from_cat, rex_clang::getStartId()]); $tcat = rex_sql::factory(); $tcat->setQuery('select * from ' . rex::getTablePrefix() . 'article where startarticle=1 and id=? and clang_id=?', [$to_cat, rex_clang::getStartId()]); if ($fcat->getRows() != 1 or $tcat->getRows() != 1 && $to_cat != 0) { // eine der kategorien existiert nicht return false; } else { if ($to_cat > 0) { $tcats = explode('|', $tcat->getValue('path')); if (in_array($from_cat, $tcats)) { // zielkategorie ist in quellkategorie -> nicht verschiebbar return false; } } // ----- folgende cats regenerate $RC = []; $RC[$fcat->getValue('parent_id')] = 1; $RC[$from_cat] = 1; $RC[$to_cat] = 1; if ($to_cat > 0) { $to_path = $tcat->getValue('path') . $to_cat . '|'; } else { $to_path = '|'; } $from_path = $fcat->getValue('path') . $from_cat . '|'; $gcats = rex_sql::factory(); // $gcats->setDebug(); $gcats->setQuery('select * from ' . rex::getTablePrefix() . 'article where path like ? and clang_id=?', [$from_path . '%', rex_clang::getStartId()]); $up = rex_sql::factory(); // $up->setDebug(); for ($i = 0; $i < $gcats->getRows(); ++$i) { // make update $new_path = $to_path . $from_cat . '|' . str_replace($from_path, '', $gcats->getValue('path')); $icid = $gcats->getValue('id'); // path aendern und speichern $up->setTable(rex::getTablePrefix() . 'article'); $up->setWhere("id={$icid}"); $up->setValue('path', $new_path); $up->update(); // cat in gen eintragen $RC[$icid] = 1; $gcats->next(); } // ----- clang holen, max catprio holen und entsprechen updaten $gmax = rex_sql::factory(); $up = rex_sql::factory(); // $up->setDebug(); foreach (rex_clang::getAllIds() as $clang) { $gmax->setQuery('select max(catpriority) from ' . rex::getTablePrefix() . "article where parent_id={$to_cat} and clang_id=" . $clang); $catpriority = (int) $gmax->getValue('max(catpriority)'); $up->setTable(rex::getTablePrefix() . 'article'); $up->setWhere("id={$from_cat} and clang_id={$clang} "); $up->setValue('path', $to_path); $up->setValue('parent_id', $to_cat); $up->setValue('catpriority', $catpriority + 1); $up->update(); } // ----- generiere artikel neu - ohne neue inhaltsgenerierung foreach ($RC as $id => $key) { rex_article_cache::delete($id); } foreach (rex_clang::getAllIds() as $clang) { self::newCatPrio($fcat->getValue('parent_id'), $clang, 0, 1); } } } return true; }
require_once rex_path::core('functions/function_rex_other.php'); // ----------------- VERSION rex::setProperty('version', '5.0.0-alpha7'); $cacheFile = rex_path::cache('config.yml.cache'); $configFile = rex_path::data('config.yml'); if (file_exists($cacheFile) && file_exists($configFile) && filemtime($cacheFile) >= filemtime($configFile)) { $config = rex_file::getCache($cacheFile); } else { $config = array_merge(rex_file::getConfig(rex_path::core('default.config.yml')), rex_file::getConfig($configFile)); rex_file::putCache($cacheFile, $config); } foreach ($config as $key => $value) { if (in_array($key, ['fileperm', 'dirperm'])) { $value = octdec($value); } rex::setProperty($key, $value); } date_default_timezone_set(rex::getProperty('timezone', 'Europe/Berlin')); if (!rex::isSetup()) { rex_error_handler::register(); } // ----------------- REX PERMS rex_complex_perm::register('clang', 'rex_clang_perm'); // ----- SET CLANG if (!rex::isSetup()) { rex_clang::setCurrentId(rex_request('clang', 'int', rex_clang::getStartId())); } if (isset($REX['LOAD_PAGE']) && $REX['LOAD_PAGE']) { unset($REX); require rex_path::core(rex::isBackend() ? 'backend.php' : 'frontend.php'); }
public static function getMissingWildcards() { $wildcards = []; if (\rex_addon::get('structure')->isAvailable() && \rex_plugin::get('structure', 'content')->isAvailable()) { $sql = \rex_sql::factory(); // Slices der Artikel durchsuchen // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $fields = ['s.value' => range('1', '20')]; $searchFields = []; $selectFields = []; foreach ($fields as $field => $numbers) { $concatFields = []; foreach ($numbers as $number) { $concatFields[] = $field . $number; $searchFields[] = $field . $number . ' RLIKE ' . $sql->escape(preg_quote(trim(self::getOpenTag())) . '.*' . preg_quote(trim(self::getCloseTag()))); } $selectFields[] = 'CONCAT_WS("|", ' . implode(',', $concatFields) . ') AS subject'; } $fields = $searchFields; $sql_query = ' SELECT s.article_id AS id, s.clang_id, s.ctype_id, ' . implode(', ', $selectFields) . ' FROM ' . \rex::getTable('article_slice') . ' AS s LEFT JOIN ' . \rex::getTable('article') . ' AS a ON (s.article_id = a.id AND s.clang_id = a.clang_id) WHERE ' . implode(' OR ', $fields) . ' '; $sql->setDebug(false); $sql->setQuery($sql_query); if ($sql->getRows() >= 1) { $items = $sql->getArray(); foreach ($items as $item) { preg_match_all(self::getRegexp(), $item['subject'], $matchesSubject, PREG_SET_ORDER); foreach ($matchesSubject as $match) { $wildcards[$match[0]]['wildcard'] = str_replace([self::getOpenTag(), self::getCloseTag()], '', $match[0]); $wildcards[$match[0]]['url'] = \rex_url::backendController(['page' => 'content/edit', 'article_id' => $item['id'], 'mode' => 'edit', 'clang' => $item['clang_id'], 'ctype' => $item['ctype_id']]); } } } // Alle bereits angelegten Platzhalter entfernen if (count($wildcards)) { $sql = \rex_sql::factory(); $sql_query = ' SELECT CONCAT("' . self::getOpenTag() . '", wildcard, "' . self::getCloseTag() . '") AS wildcard FROM ' . \rex::getTable('sprog_wildcard') . ' WHERE clang_id = "' . \rex_clang::getStartId() . '"'; $sql->setDebug(false); $sql->setQuery($sql_query); if ($sql->getRows() >= 1) { $items = $sql->getArray(); foreach ($items as $item) { if (isset($wildcards[$item['wildcard']])) { unset($wildcards[$item['wildcard']]); } } } } return $wildcards; } return false; }
* Verwaltung der Inhalte. EditierModul / Metadaten ... * * @package redaxo5 */ /* // TODOS: // - alles vereinfachen // - <?php ?> $ Problematik bei REX_ACTION */ $content = ''; $article_id = rex_request('article_id', 'int'); $clang = rex_request('clang', 'int'); $slice_id = rex_request('slice_id', 'int', ''); $function = rex_request('function', 'string'); $article_id = rex_article::get($article_id) ? $article_id : 0; $clang = rex_clang::exists($clang) ? $clang : rex_clang::getStartId(); $article_revision = 0; $slice_revision = 0; $template_attributes = []; $warning = ''; $global_warning = ''; $info = ''; $global_info = ''; $article = rex_sql::factory(); $article->setQuery(' SELECT article.*, template.attributes as template_attributes FROM ' . rex::getTablePrefix() . 'article as article LEFT JOIN ' . rex::getTablePrefix() . "template as template\n ON template.id=article.template_id\n WHERE\n article.id='{$article_id}'\n AND clang_id={$clang}"); if ($article->getRows() == 1) {
/** * Konvertiert einen Artikel zum Startartikel der eigenen Kategorie. * * @param int $neu_id Artikel ID des Artikels, der Startartikel werden soll * * @return bool TRUE bei Erfolg, sonst FALSE */ public static function article2startarticle($neu_id) { $GAID = []; // neuen startartikel holen und schauen ob da $neu = rex_sql::factory(); $neu->setQuery('select * from ' . rex::getTablePrefix() . 'article where id=? and startarticle=0 and clang_id=?', [$neu_id, rex_clang::getStartId()]); if ($neu->getRows() != 1) { return false; } $neu_cat_id = $neu->getValue('parent_id'); // in oberster kategorie dann return if ($neu_cat_id == 0) { return false; } // alten startartikel $alt = rex_sql::factory(); $alt->setQuery('select * from ' . rex::getTablePrefix() . 'article where id=? and startarticle=1 and clang_id=?', [$neu_cat_id, rex_clang::getStartId()]); if ($alt->getRows() != 1) { return false; } $alt_id = $alt->getValue('id'); $parent_id = $alt->getValue('parent_id'); // cat felder sammeln. + $params = ['path', 'priority', 'catname', 'startarticle', 'catpriority', 'status']; $db_fields = rex_structure_element::getClassVars(); foreach ($db_fields as $field) { if (substr($field, 0, 4) == 'cat_') { $params[] = $field; } } // LANG SCHLEIFE foreach (rex_clang::getAllIds() as $clang) { // alter startartikel $alt->setQuery('select * from ' . rex::getTablePrefix() . "article where id={$neu_cat_id} and startarticle=1 and clang_id={$clang}"); // neuer startartikel $neu->setQuery('select * from ' . rex::getTablePrefix() . "article where id={$neu_id} and startarticle=0 and clang_id={$clang}"); // alter startartikel updaten $alt2 = rex_sql::factory(); $alt2->setTable(rex::getTablePrefix() . 'article'); $alt2->setWhere(['id' => $alt_id, 'clang_id' => $clang]); $alt2->setValue('parent_id', $neu_id); // neuer startartikel updaten $neu2 = rex_sql::factory(); $neu2->setTable(rex::getTablePrefix() . 'article'); $neu2->setWhere(['id' => $neu_id, 'clang_id' => $clang]); $neu2->setValue('parent_id', $alt->getValue('parent_id')); // austauschen der definierten paramater foreach ($params as $param) { $alt2->setValue($param, $neu->getValue($param)); $neu2->setValue($param, $alt->getValue($param)); } $alt2->update(); $neu2->update(); } // alle artikel suchen nach |art_id| und pfade ersetzen // alles artikel mit parent_id alt_id suchen und ersetzen $articles = rex_sql::factory(); $ia = rex_sql::factory(); $articles->setQuery('select * from ' . rex::getTablePrefix() . "article where path like '%|{$alt_id}|%'"); for ($i = 0; $i < $articles->getRows(); ++$i) { $iid = $articles->getValue('id'); $ipath = str_replace("|{$alt_id}|", "|{$neu_id}|", $articles->getValue('path')); $ia->setTable(rex::getTablePrefix() . 'article'); $ia->setWhere(['id' => $iid]); $ia->setValue('path', $ipath); if ($articles->getValue('parent_id') == $alt_id) { $ia->setValue('parent_id', $neu_id); } $ia->update(); $GAID[$iid] = $iid; $articles->next(); } $GAID[$neu_id] = $neu_id; $GAID[$alt_id] = $alt_id; $GAID[$parent_id] = $parent_id; foreach ($GAID as $gid) { rex_article_cache::delete($gid); } rex_complex_perm::replaceItem('structure', $alt_id, $neu_id); foreach (rex_clang::getAllIds() as $clang) { rex_extension::registerPoint(new rex_extension_point('ART_TO_STARTARTICLE', '', ['id' => $neu_id, 'id_old' => $alt_id, 'clang' => $clang])); } return true; }
if (!rex::getUser()->getComplexPerm('clang')->hasPerm($clang)) { $stop = true; foreach (rex_clang::getAllIds() as $key) { if (rex::getUser()->getComplexPerm('clang')->hasPerm($key)) { $clang = $key; $stop = false; break; } } if ($stop) { echo rex_view::error('You have no permission to this area'); exit; } } } else { $clang = rex_clang::getStartId(); } $context = new rex_context(['page' => 'structure', 'category_id' => $category_id, 'article_id' => $article_id, 'clang' => $clang]); // --------------------- Extension Point echo rex_extension::registerPoint(new rex_extension_point('PAGE_STRUCTURE_HEADER_PRE', '', ['context' => $context])); // --------------------------------------------- TITLE echo rex_view::title(rex_i18n::msg('title_structure')); // --------------------------------------------- Languages echo rex_view::clangSwitchAsButtons($context); // --------------------------------------------- Path require __DIR__ . '/../functions/function_rex_category.php'; // -------------- STATUS_TYPE Map $catStatusTypes = rex_category_service::statusTypes(); $artStatusTypes = rex_article_service::statusTypes(); // --------------------------------------------- API MESSAGES echo rex_api_function::getMessage();
/** * Generiert alle *.alist u. *.clist Dateien einer Kategorie/eines Artikels. * * @param int $parent_id KategorieId oder ArtikelId, die erneuert werden soll * * @return bool TRUE wenn der Artikel gelöscht wurde, sonst eine Fehlermeldung */ public static function generateLists($parent_id) { // sanity check if ($parent_id < 0) { return false; } // --------------------------------------- ARTICLE LIST $GC = rex_sql::factory(); // $GC->setDebug(); $GC->setQuery('select * from ' . rex::getTablePrefix() . 'article where clang_id=:clang AND ((parent_id=:id and startarticle=0) OR (id=:id and startarticle=1)) order by priority,name', ['id' => $parent_id, 'clang' => rex_clang::getStartId()]); $cacheArray = []; foreach ($GC as $row) { $cacheArray[] = (int) $row->getValue('id'); } $article_list_file = rex_path::addonCache('structure', $parent_id . '.alist'); if (rex_file::putCache($article_list_file, $cacheArray) === false) { return rex_i18n::msg('article_could_not_be_generated') . ' ' . rex_i18n::msg('check_rights_in_directory') . rex_path::addonCache('structure'); } // --------------------------------------- CAT LIST $GC = rex_sql::factory(); $GC->setQuery('select * from ' . rex::getTablePrefix() . 'article where parent_id=:id and clang_id=:clang and startarticle=1 order by catpriority,name', ['id' => $parent_id, 'clang' => rex_clang::getStartId()]); $cacheArray = []; foreach ($GC as $row) { $cacheArray[] = (int) $row->getValue('id'); } $article_categories_file = rex_path::addonCache('structure', $parent_id . '.clist'); if (rex_file::putCache($article_categories_file, $cacheArray) === false) { return rex_i18n::msg('article_could_not_be_generated') . ' ' . rex_i18n::msg('check_rights_in_directory') . rex_path::addonCache('structure'); } return true; }
// TODO remove container (just their to get some linkmap styles) $tree .= '<div id="rex-linkmap">'; $categoryTree = new rex_sitemap_category_tree($context); $tree .= $categoryTree->getTree($category_id); $tree .= '</div>'; $tree .= '</div>'; return $tree; }); if (rex_be_controller::getCurrentPagePart(1) == 'system') { rex_system_setting::register(new rex_system_setting_article_id('start_article_id')); rex_system_setting::register(new rex_system_setting_article_id('notfound_article_id')); } } rex_extension::register('CLANG_ADDED', function (rex_extension_point $ep) { $firstLang = rex_sql::factory(); $firstLang->setQuery('select * from ' . rex::getTablePrefix() . 'article where clang_id=?', [rex_clang::getStartId()]); $fields = $firstLang->getFieldnames(); $newLang = rex_sql::factory(); // $newLang->setDebug(); foreach ($firstLang as $firstLangArt) { $newLang->setTable(rex::getTablePrefix() . 'article'); foreach ($fields as $key => $value) { if ($value == 'pid') { echo ''; } elseif ($value == 'clang_id') { $newLang->setValue('clang_id', $ep->getParam('clang')->getId()); } elseif ($value == 'status') { $newLang->setValue('status', '0'); } else { $newLang->setValue($value, $firstLangArt->getValue($value)); }