protected function postConstructor() { parent::postConstructor(); // This must be called here (not in checkOptions()) to avoid // buildActionUri() call before application instantiation isset($this->fatal_uri) || ($this->fatal_uri = TIP::buildActionUri($this->id, 'fatal')); $this->keys['TITLE'] =& $this->title; $this->keys['DESCRIPTION'] =& $this->description; $this->keys['KEYWORDS'] =& $this->keywords; $this->keys['ROOT'] = TIP::getRoot(); $this->keys['HOME'] = TIP::getHome(); $this->keys['REFERER'] = ''; // Set $_request $module = TIP::getGet('module', 'string'); $action = TIP::getGet('action', 'string'); if (!$action) { $module = TIP::getPost('module', 'string'); $action = TIP::getPost('action', 'string'); } $this->_request = array('uri' => @$_SERVER['REQUEST_URI'], 'module' => @strtolower($module), 'action' => @strtolower($action), 'id' => TIP::getGetOrPost('id', 'string')); $this->keys['REQUEST'] = $this->_request['uri']; $this->keys['MODULE'] = $this->_request['module']; $this->keys['ACTION'] = $this->_request['action']; // The ID global key will be assigned when the requested module // is loaded, so a type casting can be forced (because the id_type // of the module is known) $this->keys['ID'] = ''; // Start the session TIP_AHAH || $this->_startSession(); }
/** * Get a specific GET or POST value * * If $id is not specified, it defaults to the primary key of the binded * data. * * This is an high level method that notify errors to the user if $id is * not found. * * @param mixed $id The get/post id * @return mixed|null The get/post value or null if not found */ public function fromGetOrPost($id = null, $type = 'integer') { if (is_null($id)) { $id = 'id'; $type = $this->id_type; } if (is_null($value = TIP::getGet($id, $type)) && is_null($value = TIP::getPost($id, $type))) { TIP::warning("GET or POST not found ({$id})"); TIP::notifyError('noparams'); } return $value; }
/** * Get the value of a pair throught a "request" interface * * This method is usually used by the template engine interface methods * (the tag... functions) to access any pair information available * in the TIP system. * * A request can get the value of an item, a get, a post or a localized * text: the type of the request is obtained parsing the $request token. * Specify <code>item[...]</code> for items, <code>get[...]</code> for * gets, <code>post[...]</code> for posts and <code>locale[...]</code> for * localized text, specifying the id in place of the ellipsize. * * If no type is specified (that is, $request is directly an identifier), * the system will expand it in <code>item[...]</code>. * This means <code>getRequest('name')</code> is logically equivalent to * <code>getRequest('item[name]')</code>. * * @param string $request The item id * @return mixed|null The requested value or null if the request is invalid */ protected function getRequest($request) { $open_brace = strpos($request, '['); if ($open_brace === false) { $type = 'item'; $id = $request; } else { $close_brace = strrpos($request, ']'); if ($close_brace === false || $close_brace < $open_brace) { return null; } $type = strtolower(trim(substr($request, 0, $open_brace))); $id = substr($request, $open_brace + 1, $close_brace - $open_brace - 1); } switch ($type) { case 'item': return $this->getItem($id); case 'get': return TIP::getGet($id, 'string'); case 'post': return TIP::getPost($id, 'string'); case 'locale': return $this->getLocale($id); case 'label': if (strpos('.', $id) > 0) { return TIP::getLocale($id); } else { return $this->getLocale('label.' . $id); } } return null; }
/** * Add GET defaults to $this->defaults and merge them to $this->_defaults * * This default values will be merged to $this->defaults with * higher precedence. * * Default values provided by GET must be treated specially, * otherwise will be lost in a POST submission. A special hidden * input is used for such purpose. */ private function _addApplicationDefaults() { // Check for GET default values $get_defaults = array(); if ($this->_form->isSubmitted()) { // Get default values from the special POST (if present) $value = TIP::getPost('__tipd', 'string'); empty($value) || ($get_defaults = unserialize($value)); } else { // Check for default values provided via GET foreach ($this->fields as $id => &$field) { // Skip application specific GETs if ($id == 'module' || $id == 'action' || $id == 'id') { continue; } $type = isset($field['type']) ? $field['type'] : 'string'; $value = TIP::getGet($id, $type); isset($value) && ($get_defaults[$id] = $value); } $value = serialize($get_defaults); } if (!empty($get_defaults)) { // Merge GET defaults with explicitely set defaults if (is_array($this->defaults)) { $this->defaults = array_merge($this->defaults, $get_defaults); } else { $this->defaults = $get_defaults; } // Manage the __tipd special element if (!$this->_form->elementExists('__tipd')) { // No previous "__tipd" element found $this->_form->addElement('hidden', '__tipd', $value); } else { // The "__tipd" element is present: the new defaults // must be merged to its value with higher precedence $element =& $this->_form->getElement('__tipd'); $old_value = $element->getValue(); $old_defaults = unserialize($old_value); $get_defaults = array_merge($old_defaults, $get_defaults); $value = serialize($get_defaults); $element->setValue($value); // No needs to update $this->defaults: this must be // yet done by the previous operation that set '__tipd' } } // Finally merge the application defaults ($this->defaults) with // the global defaults ($this->_defaults) $this->_defaults = array_merge($this->_defaults, $this->defaults); }
/** * Get a specific row * * Overrides the default method to merge also the child row fields * to the returned array. * * @param mixed $id The row id * @param bool $end_view Whether to end the view or not * @return array|null The row or null on errors */ public function &fromRow($id = null, $end_view = true) { // Get the current "master" row if (is_null($row = parent::fromRow($id, $end_view))) { return $row; } // Try to get the child row, if possible: the class name is // retrieved from the post (if found) or from the current $row if (is_null($class = TIP::getPost($this->class_field, 'string'))) { $class = $row[$this->class_field]; } $child =& $this->_getChildModule($class); if ($child === false) { $row = null; } elseif ($child && !is_null($child_row = $child->fromRow($id, $end_view))) { $row = array_merge($child_row, $row); } return $row; }