/** * transcode some references * * @see images/images.php * * @param array of pairs of strings to be used in preg_replace() */ function transcode($transcoded) { global $context; // no item bound if (!isset($this->item['id'])) { return; } // prepare preg_replace() $from = array(); $to = array(); foreach ($transcoded as $pair) { $from[] = $pair[0]; $to[] = $pair[1]; } // transcode various fields $this->item['introduction'] = preg_replace($from, $to, $this->item['introduction']); $this->item['description'] = preg_replace($from, $to, $this->item['description']); // update the database $query = "UPDATE " . SQL::table_name('sections') . " SET " . " introduction = '" . SQL::escape($this->item['introduction']) . "'," . " description = '" . SQL::escape($this->item['description']) . "'" . " WHERE id = " . SQL::escape($this->item['id']); SQL::query($query); // always clear the cache, even on no update Sections::clear($this->item); }
/** * change the template of a section * * This function saves the template as an attribute of the section. * * Also, it attempts to translate it as a valid YACS skin made * of [code]template.php[/code] and [code]skin.php[/code]. * The theme name is [code]section_<id>[/code]. * * Lastly, it updates the options field to actually use the template for pages of this section. * * @param int the id of the target section * @param string the new or updated template * @return string either a null string, or some text describing an error to be inserted into the html response * * @see services/blog.php * @see skins/import.php **/ public static function put_template($id, $template, $directory = NULL) { global $context; // id cannot be empty if (!$id || !is_numeric($id)) { return i18n::s('No item has the provided id.'); } // load section attributes if (!($item = Sections::get($id))) { return i18n::s('No item has the provided id.'); } // locate the new skin if (!$directory) { $directory = 'section_' . $id; } // make a valid YACS skin include_once $context['path_to_root'] . 'skins/import.php'; if ($error = Import::process($template, $directory)) { return $error; } // change the skin for this section $options = preg_replace('/\\bskin_.+\\b/i', '', $item['options']) . ' skin_' . $directory; // set default values for this editor Surfer::check_default_editor(array()); // update an existing record $query = "UPDATE " . SQL::table_name('sections') . " SET " . "template='" . SQL::escape($template) . "',\n" . "options='" . SQL::escape($options) . "',\n" . "edit_name='" . SQL::escape($fields['edit_name']) . "',\n" . "edit_id=" . SQL::escape($fields['edit_id']) . ",\n" . "edit_address='" . SQL::escape($fields['edit_address']) . "',\n" . "edit_action='section:update',\n" . "edit_date='" . SQL::escape($fields['edit_date']) . "'\n" . "\tWHERE id = " . SQL::escape($id); SQL::query($query); // clear the cache because of the new rendering Sections::clear(array('sections', 'section:' . $id, 'categories')); }
$count = 0; foreach ($_REQUEST['selected_sections'] as $dummy => $id) { // an section to lock if (($section = Sections::get($id)) && $section['locked'] == 'Y') { $attributes = array(); $attributes['id'] = $section['id']; $attributes['locked'] = 'N'; $attributes['silent'] = 'Y'; // too minor to be noted if (Sections::put_attributes($attributes)) { $count++; } } } // clear cache for containing section Sections::clear($item); // report on results $context['text'] .= '<p>' . sprintf(i18n::ns('%d section has been unlocked.', '%d sections have been unlocked.', $count), $count) . '</p>'; // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array(); $menu[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the section'), 'span'); $menu[] = Skin::build_link(Sections::get_url($item['id'], 'manage'), i18n::s('Manage it'), 'span'); $follow_up .= Skin::finalize_list($menu, 'menu_bar'); $context['text'] .= Skin::build_block($follow_up, 'bottom'); // nothing to do } else { Logger::error(i18n::s('No section has been selected.')); } // which operation? } else {