Beispiel #1
0
 protected static function checkOptions(&$options)
 {
     if (!parent::checkOptions($options) || !isset($options['master'])) {
         return false;
     }
     isset($options['statistics']) || ($options['statistics'] = array('_onAdd' => '_comments', '_onEdit' => null, '_onDelete' => '_deleted_comments'));
     if (is_string($options['master'])) {
         $options['master'] =& TIP_Type::getInstance($options['master']);
     } elseif (is_array($options['master'])) {
         $options['master'] =& TIP_Type::singleton($options['master']);
     }
     return $options['master'] instanceof TIP_Content;
 }
Beispiel #2
0
 protected static function checkOptions(&$options)
 {
     if (!parent::checkOptions($options)) {
         return false;
     }
     if (@is_string($options['master'])) {
         $options['master'] =& TIP_Type::getInstance($options['master']);
     } elseif (@is_array($options['master'])) {
         $options['master'] =& TIP_Type::singleton($options['master']);
     }
     if (isset($options['master']) && !$options['master'] instanceof TIP_Content) {
         return false;
     }
     isset($options['action']) || ($options['action'] = 'browse,-id-');
     return true;
 }
Beispiel #3
0
 protected static function checkOptions(&$options)
 {
     if (!parent::checkOptions($options) || !isset($options['master'])) {
         return false;
     }
     if (is_string($options['master'])) {
         $options['master'] =& TIP_Type::getInstance($options['master']);
     } elseif (is_array($options['master'])) {
         $options['master'] =& TIP_Type::singleton($options['master']);
     }
     if (!$options['master'] instanceof TIP_Content) {
         return false;
     }
     // Check if the master module has the same data engine:
     // this is required to be able to use transactions
     $master_data =& $options['master']->getProperty('data');
     $this_engine =& $options['data']->getProperty('engine');
     return $master_data->getProperty('engine') == $this_engine;
 }
Beispiel #4
0
 /**
  * The "main" function
  *
  * The starting point of the TIP system. This must be called somewhere from
  * your index.php.
  */
 public function go()
 {
     // Configure the locale
     $locale_module = $this->shared_modules['locale'];
     if (TIP::setLocaleId(TIP::getOption($locale_module, 'locale'))) {
         date_default_timezone_set(TIP::getOption($locale_module, 'timezone'));
     }
     // Executes the action
     if ($this->_request['module'] && $this->_request['action']) {
         if (is_null($module =& TIP_Type::getInstance($this->_request['module'], false))) {
             TIP::notifyError('module');
         } else {
             if (isset($this->_request['id'])) {
                 // Now the module is loaded: force id type casting
                 $id_type = $module->getProperty('id_type');
                 isset($id_type) || ($id_type = 'integer');
                 settype($this->_request['id'], $id_type);
                 $this->keys['ID'] = $this->_request['id'];
             }
             if (is_null($module->callAction($this->_request['action']))) {
                 TIP::notifyError(is_null(TIP::getUserId()) ? 'reserved' : 'denied');
             }
         }
     } elseif ($this->_request['module']) {
         TIP::notifyError('noaction');
     } elseif ($this->_request['action']) {
         TIP::notifyError('nomodule');
     } elseif (TIP_AHAH) {
         // AHAH request without module/action specified: perform a test
         $this->content = "<pre>\n" . TIP::toHtml(print_r($_SERVER, true)) . "\n</pre>\n";
     }
     if (TIP_AHAH) {
         // AHAH request: output the page and return
         header('Content-Type: application/xml');
         echo $this->content;
         return;
     }
     // Generates the page: body must be called before the head because
     // some head tags can be modified by body templates
     $body = $this->tagRun($this->body_template);
     echo str_replace('{locale}', TIP::getLocaleId('-'), $this->incipit);
     $this->run($this->head_template);
     echo $body . $this->explicit;
     $this->_session_started && HTTP_Session2::pause();
 }
Beispiel #5
0
 /**
  * General db action manager
  *
  * Internal method used by _onAdd(), _onEdit() and _onDelete().
  *
  * @param  string      $action  'Add', 'Edit' or 'Delete'
  * @param  array      &$row     The subject row
  * @param  array|null  $old_row The old row or null on no old row
  * @return bool                 true on success or false on error
  * @internal
  */
 private function _onDbAction($action, &$row, $old_row)
 {
     // Dispatch the signal to all children modules
     $callback = create_function('$a', 'return @$a[\'master\'] == \'' . $this->id . '\';');
     if (is_array($children = array_filter($GLOBALS['cfg'], $callback))) {
         $method = '_onMaster' . $action;
         foreach (array_keys($children) as $child_id) {
             $child = TIP_Type::getInstance($child_id);
             if (method_exists($child, $method) && !$child->{$method}($row, $old_row)) {
                 return false;
             }
         }
     }
     // Update user statistics, if the user module exists
     if (!is_null($field = @$this->user_statistic['_on' . $action]) && !is_null($user =& TIP_Application::getSharedModule('user'))) {
         $user->increment($field);
     }
     // Remove the feed, if it exists
     if (!is_null($template =& TIP_Type::singleton(array('type' => array('template'), 'path' => array($this->id, $this->atom_template)))) && !is_null($path = $this->engine->getCachePath($template)) && file_exists($path)) {
         unlink($path);
     }
     return true;
 }
Beispiel #6
0
 /**
  * Render to html the URI of a picasa album feed
  *
  * Creates a temporary picasa2 module with $uri as
  * data property and render the result by calling the
  * toHtmlAlbum() method.
  *
  * @param  string       $uri The uri of the album feed
  * @return string|false      The string to render or false on errors
  */
 public static function picasa2AlbumCallback($uri)
 {
     global $cfg;
     $id = 'picasa2::' . $uri;
     isset($cfg[$id]) || ($cfg[$id] = array('type' => array('module', 'content', 'picasa2'), 'data' => $uri));
     $instance = TIP_Type::getInstance($id);
     $output = $instance->toHtmlAlbum();
     return is_string($output) ? $output : false;
 }
Beispiel #7
0
 private function _populateHierarchy($id, $hierarchy_id)
 {
     $element =& $this->_form->getElement($id);
     $hierarchy =& TIP_Type::getInstance($hierarchy_id);
     if ($element->isFrozen()) {
         // No need to execute a complete query: get only the selected row(s)
         $selected = $element->getSelected();
         $items = $hierarchy->toRow($selected);
     } else {
         // Populate the option list, prepending an empty option
         $items = array(' ' => '&#160;');
         is_null($rows =& $hierarchy->toRows()) || ($items += $rows);
     }
     $element->loadArray($items);
 }
Beispiel #8
0
 /**
  * Get the child module
  *
  * Checks for the child module existence and caches the request.
  * If $class is not specified, no attempts are made to get the
  * child module: only the cache is returned or an error is raised.
  *
  * This method provides also a way to validate the data engine,
  * that **must** be shared between this module and the child one
  * to allow //transation protected// commits.
  *
  * @param  string|null            $class The class to use
  * @return TIP_Content|null|false        The requested child module,
  *                                       null if not needed or
  *                                       false on errors
  * @internal
  */
 private function &_getChildModule($class = null)
 {
     // The true value is used as "uncached" value
     static $child = true;
     // Check for cached result
     if ($child !== true) {
         return $child;
     }
     // Check for request without $class (no autodiscovering)
     if (is_null($class)) {
         TIP::error('No previous child request performed');
         $error = false;
         return $error;
     }
     // Check if the child module is required
     $child = TIP_Type::getInstance($this->id . '-' . $class, false);
     if (is_null($child)) {
         // No child module needed
         return $child;
     }
     // Get and check the child module
     $child_data = $child->getProperty('data');
     if (!$child_data instanceof TIP_Data) {
         TIP::error("the child module has no data (child = {$class})");
         $child = false;
     } elseif ($child_data->getProperty('engine') != $this->data->getProperty('engine')) {
         TIP::error("master and child data must share the same data engine (child = {$class})");
         $child = false;
     }
     return $child;
 }