/** * Common Form helper method * * This method, intended to be used solely by other methods of the * section class, creates a base form that all other page types can * build off of. This form includes a name textbox, and either a rank * meta field (hidden input) or a rank dropdown. * * @param $object * * @return \form */ function _commonForm(&$object) { // Create a new blank form. $form = new form(); if (!isset($object->id)) { // This is a new section, so we need to set up some defaults. $object->name = ''; $object->sef_name = ''; $object->active = 1; $object->public = 1; $object->secured = 0; $object->new_window = 0; $object->subtheme = ''; $object->page_title = SITE_TITLE; $object->keywords = SITE_KEYWORDS; $object->description = SITE_DESCRIPTION; if (!isset($object->parent)) { // This is another precaution. The parent attribute // should ALWAYS be set by the caller. //FJD - if that's the case, then we should die. die(SITE_403_REAL_HTML); //$object->parent = 0; } } else { // If we are editing the section, we should store the section's id // in a hidden value, so that it comes through when the form is // submitted. $form->meta('id', $object->id); } // The name of the section, as it will be linked in the section hierarchy. $form->register('name', gt('Name'), new textcontrol($object->name)); $form->register('sef_name', gt('SEF Name') . '<p class="sefinfo">' . gt('If you don\'t put in an SEF Name one will be generated based on the title provided. SEF names can only contain alpha-numeric characters, hyphens and underscores.') . '</p>', new textcontrol($object->sef_name)); if (!isset($object->id)) { // This is a new section, so we can add the positional dropdown // Pull the database object in from the global scope. global $db; // Retrieve all of the sections that are siblings of the new section $sections = $db->selectObjects('section', 'parent=' . $object->parent); if (count($sections) && $object->parent >= 0) { // Initialize the sorting subsystem so that we can order the sections // by rank, ascending, and get the proper ordering. $sections = expSorter::sort(array('array' => $sections, 'sortby' => 'rank', 'order' => 'ASC')); // Generate the Position dropdown array. $positions = array(gt('At the Top')); foreach ($sections as $section) { $positions[] = sprintf(gt('After') . " %s", $section->name); } $form->meta('rank', count($positions) - 1); //$form->register('rank',gt('Rank'),new dropdowncontrol(count($positions)-1,$positions)); } else { // If there are no siblings, the new section gets the first // slot, with a rank of 0. $form->meta('rank', 0); } // Store the section's parent in a hidden field, so that it comes through // when the form is submitted. $form->meta('parent', $object->parent); } else { if ($object->parent >= 0) { // Allow them to change parents, but not if the section is outside of the hierarchy (parent > 0) $form->register('parent', gt('Parent Page'), new dropdowncontrol($object->parent, navigationmodule::levelDropdownControlArray(0, 0, array($object->id), true, 'manage'))); } } $form->register('new_window', gt('Open in New Window'), new checkboxcontrol($object->new_window, false)); // Return the form to the calling scope, which should always be a // member method of this class. return $form; }
/** * Returns a flat representation of the full site hierarchy. * * @param $parent top level parent id * @param int $depth variable to hold level of recursion * @param array $ignore_ids array of pages to ignore * @param bool $full include a 'top' level entry * * @return array */ static function levelDropDownControlArray($parent, $depth = 0, $ignore_ids = array(), $full = false, $perm = 'view') { $ar = array(); if ($parent == 0 && $full) { $ar[0] = '<' . gt('Top of Hierarchy') . '>'; } global $db; $nodes = $db->selectObjects('section', 'parent=' . $parent); $nodes = expSorter::sort(array('array' => $nodes, 'sortby' => 'rank', 'order' => 'ASC')); foreach ($nodes as $node) { if (($perm == 'view' && $node->public == 1 || expPermissions::check($perm, expCore::makeLocation('navigationmodule', '', $node->id))) && !in_array($node->id, $ignore_ids)) { if ($node->active == 1) { $text = str_pad('', ($depth + ($full ? 1 : 0)) * 3, '.', STR_PAD_LEFT) . $node->name; } else { $text = str_pad('', ($depth + ($full ? 1 : 0)) * 3, '.', STR_PAD_LEFT) . '(' . $node->name . ')'; } $ar[$node->id] = $text; foreach (navigationmodule::levelDropdownControlArray($node->id, $depth + 1, $ignore_ids, $full, $perm) as $id => $text) { $ar[$id] = $text; } } } return $ar; }
function _commonForm(&$object) { $i18n = exponent_lang_loadFile('datatypes/section.php'); // Create a new blank form. $form = new form(); if (!isset($object->id)) { // This is a new section, so we need to set up some defaults. $object->name = ''; $object->active = 1; $object->public = 1; $object->new_window = 0; $object->subtheme = ''; $object->page_title = SITE_TITLE; $object->keywords = SITE_KEYWORDS; $object->description = SITE_DESCRIPTION; if (!isset($object->parent)) { // This is another precaution. The parent attribute // should ALWAYS be set by the caller. //FJD - if that's the case, then we should die. die(SITE_403_REAL_HTML); //$object->parent = 0; } } else { // If we are editing the section, we should store the section's id // in a hidden value, so that it comes through when the form is // submitted. $form->meta('id', $object->id); } // The name of the section, as it will be linked in the section hierarchy. $form->register('name', $i18n['name'], new textcontrol($object->name)); if (!isset($object->id)) { // This is a new section, so we can add the positional dropdown // Pull the database object in from the global scope. global $db; // Retrieve all of the sections that are siblings of the new section $sections = $db->selectObjects('section', 'parent=' . $object->parent); if (count($sections) && $object->parent >= 0) { // Initialize the sorting subsystem so that we can order the sections // by rank, ascending, and get the proper ordering. if (!defined('SYS_SORTING')) { require_once BASE . 'subsystems/sorting.php'; } usort($sections, 'exponent_sorting_byRankAscending'); // Generate the Position dropdown array. $positions = array($i18n['position_top']); foreach ($sections as $section) { $positions[] = sprintf($i18n['position_after'], $section->name); } $form->register('rank', $i18n['rank'], new dropdowncontrol(count($positions) - 1, $positions)); } else { // If there are no siblings, the new section gets the first // slot, with a rank of 0. $form->meta('rank', 0); } // Store the section's parent in a hidden field, so that it comes through // when the form is submitted. $form->meta('parent', $object->parent); } else { if ($object->parent >= 0) { // Allow them to change parents, but not if the section is outside of the hiearchy (parent > 0) $form->register('parent', $i18n['parent'], new dropdowncontrol($object->parent, navigationmodule::levelDropdownControlArray(0, 0, array($object->id), 1))); } } $form->register('new_window', $i18n['new_window'], new checkboxcontrol($object->new_window, true)); // Return the form to the calling scope, which should always be a // member method of this class. return $form; }