} if (isset($template_var)) { $template->assign($template_var . strtoupper($field), '<a href="' . $url . $anchor . '" title="' . l10n('Sort order') . '">' . $disp . '</a>'); } } return $ret; } if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } include_once PHPWG_ROOT_PATH . 'admin/include/functions_permalinks.php'; $selected_cat = array(); if (isset($_POST['set_permalink']) and $_POST['cat_id'] > 0) { $permalink = $_POST['permalink']; if (empty($permalink)) { delete_cat_permalink($_POST['cat_id'], isset($_POST['save'])); } else { set_cat_permalink($_POST['cat_id'], $permalink, isset($_POST['save'])); } $selected_cat = array($_POST['cat_id']); } elseif (isset($_GET['delete_permanent'])) { $query = ' DELETE FROM ' . OLD_PERMALINKS_TABLE . ' WHERE permalink=\'' . $_GET['delete_permanent'] . '\' LIMIT 1'; $result = pwg_query($query); if (pwg_db_changes($result) == 0) { $page['errors'][] = l10n('Cannot delete the old permalink !'); } } $template->set_filename('permalinks', 'permalinks.tpl');
/** sets a new permalink for a category * returns true on success * @param int cat_id the target category id * @param string permalink the new permalink * @param boolean save if true, the current category-permalink association * is saved in the old permalinks table in case external links hit it */ function set_cat_permalink($cat_id, $permalink, $save) { global $page, $cache; $sanitized_permalink = preg_replace('#[^a-zA-Z0-9_/-]#', '', $permalink); $sanitized_permalink = trim($sanitized_permalink, '/'); $sanitized_permalink = str_replace('//', '/', $sanitized_permalink); if ($sanitized_permalink != $permalink or preg_match('#^(\\d)+(-.*)?$#', $permalink)) { $page['errors'][] = l10n('The permalink name must be composed of a-z, A-Z, 0-9, "-", "_" or "/". It must not be numeric or start with number followed by "-"'); return false; } // check if the new permalink is actively used $existing_cat_id = get_cat_id_from_permalink($permalink); if (isset($existing_cat_id)) { if ($existing_cat_id == $cat_id) { // no change required return true; } else { $page['errors'][] = sprintf(l10n('Permalink %s is already used by album %s'), $permalink, $existing_cat_id); return false; } } // check if the new permalink was historically used $old_cat_id = get_cat_id_from_old_permalink($permalink); if (isset($old_cat_id) and $old_cat_id != $cat_id) { $page['errors'][] = sprintf(l10n('Permalink %s has been previously used by album %s. Delete from the permalink history first'), $permalink, $old_cat_id); return false; } if (!delete_cat_permalink($cat_id, $save)) { return false; } if (isset($old_cat_id)) { // the new permalink must not be active and old at the same time assert($old_cat_id == $cat_id); $query = ' DELETE FROM ' . OLD_PERMALINKS_TABLE . ' WHERE cat_id=' . $old_cat_id . ' AND permalink=\'' . $permalink . '\''; pwg_query($query); } $query = ' UPDATE ' . CATEGORIES_TABLE . ' SET permalink=\'' . $permalink . '\' WHERE id=' . $cat_id; // LIMIT 1'; pwg_query($query); unset($cache['cat_names']); //force regeneration return true; }