/** * Load a list of item referenced by their urltitle into the cache * * @param array of urltitles of Items to load */ function load_urltitle_array($req_array) { global $DB, $Debuglog; $req_list = "'" . implode("','", $req_array) . "'"; $Debuglog->add("Loading <strong>{$this->objtype}({$req_list})</strong> into cache", 'dataobjects'); $sql = "SELECT * FROM {$this->dbtablename} WHERE post_urltitle IN ( {$req_list} )"; $dbIDname = $this->dbIDname; $objtype = $this->objtype; foreach ($DB->get_results($sql) as $row) { $this->cache[$row->{$dbIDname}] = new $objtype($row); // COPY! // $obj = $this->cache[ $row->$dbIDname ]; // $obj->disp( 'name' ); // put into index: $this->urltitle_index[$row->post_urltitle] =& $this->cache[$row->{$dbIDname}]; $Debuglog->add("Cached <strong>{$this->objtype}({$row->post_urltitle})</strong>"); } // Set cache from Slug table: foreach ($req_array as $urltitle) { if (!isset($this->urltitle_index[$urltitle])) { // not yet in cache: $SlugCache =& get_SlugCache(); if ($req_Slug = $SlugCache->get_by_name($urltitle, false, false)) { if ($req_Slug->get('type') == 'item') { // Is item slug if ($Item = $this->get_by_ID($req_Slug->get('itm_ID'), false)) { // Set cache $this->urltitle_index[$urltitle] = $Item; $Debuglog->add("Cached <strong>{$this->objtype}({$urltitle})</strong>"); continue; } } } // Set cache for non found objects: $this->urltitle_index[$urltitle] = false; // Remember it doesn't exist in DB either $Debuglog->add("Cached <strong>{$this->objtype}({$urltitle})</strong> as NON EXISTENT"); } } }
/** * Get the item tinyslug. If not exists -> create new * * @return string|boolean tinyslug on success, false otherwise */ function get_tinyslug() { global $preview; $tinyslug_ID = $this->tiny_slug_ID; if ($tinyslug_ID != NULL) { // the tiny slug for this item was already created $SlugCache =& get_SlugCache(); $Slug =& $SlugCache->get_by_ID($tinyslug_ID, false, false); return $Slug === false ? false : $Slug->get('title'); } elseif ($this->ID > 0 && !$preview) { // create new tiny Slug for this item // Note: This may happen only in case of posts created before the tiny slug was introduced global $DB; load_funcs('slugs/model/_slug.funcs.php'); $Slug = new Slug(); $Slug->set('title', getnext_tinyurl()); $Slug->set('itm_ID', $this->ID); $Slug->set('type', 'item'); $DB->begin(); if (!$Slug->dbinsert()) { // Slug dbinsert failed $DB->rollback(); return false; } $this->set('tiny_slug_ID', $Slug->ID); // Update Item preserving mod date: if (!$this->dbupdate(false)) { // Item dbupdate failed $DB->rollback(); return false; } $DB->commit(); // update last tinyurl value on database // Note: This doesn't have to be part of the above transaction, no problem if it doesn't succeed to update, or if override a previously updated value. global $Settings; $Settings->set('tinyurl', $Slug->get('title')); $Settings->dbupdate(); return $Slug->get('title'); } return false; }
} load_class('slugs/model/_slug.class.php', 'Slug'); /** * @var User */ global $current_User; // Check minimum permission: $current_User->check_perm('slugs', 'view', true); $AdminUI->set_path('options', 'slugs'); param_action('list'); param('slug_filter', 'string', '', true); param('slug_item_ID', 'string', '', true); // other slug object type IDs come here if (param('slug_ID', 'integer', '', true)) { // Load file type: $SlugCache =& get_SlugCache(); if (($edited_Slug =& $SlugCache->get_by_ID($slug_ID, false)) === false) { // We could not find the goal to edit: unset($edited_Slug); forget_param('slug_ID'); $Messages->add(sprintf(T_('Requested «%s» object does not exist any longer.'), T_('Slug')), 'error'); $action = 'nil'; } } switch ($action) { case 'list': break; case 'new': $edited_Slug = new Slug(); break; case 'edit':
if ($filter_type = get_param('slug_type')) { // add filter for post type $SQL->WHERE_and('slug_type = "' . $DB->escape(get_param('slug_ftype')) . '"'); $list_is_filtered = true; } if ($filter_item_ID = get_param('slug_item_ID')) { // add filter for item ID if (is_number($filter_item_ID)) { $SQL->WHERE_and('slug_itm_ID = ' . $DB->quote($filter_item_ID)); $list_is_filtered = true; } } // Create result set: $Results = new Results($SQL->get(), 'slug_', 'A'); $Results->title = T_('Slugs') . ' (' . $Results->get_total_rows() . ')' . get_manual_link('slugs-list'); $Results->Cache = get_SlugCache(); if ($list_is_filtered) { // List is filtered, offer option to reset filters: $Results->global_icon(T_('Reset all filters!'), 'reset_filters', $admin_url . '?ctrl=slugs', T_('Reset filters'), 3, 3, array('class' => 'action_icon btn-warning')); } /** * Callback to add filters on top of the result set * * @param Form */ function filter_slugs(&$Form) { $Form->text_input('slug_filter', get_param('slug_filter'), 24, T_('Slug'), '', array('maxlength' => 253)); $item_ID_filter_note = ''; if ($filter_item_ID = get_param('slug_item_ID')) { // check item_Id filter. It must be a number