Пример #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;
 }
Пример #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;
 }
Пример #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;
 }
Пример #4
0
 /**
  * Output some debug information
  *
  * Echoes some output and profiler information, useful in the developement
  * process. This works only if the current user has some privilege on the
  * application module.
  */
 protected function tagDebug($params)
 {
     if (!$this->keys['IS_TRUSTED']) {
         return '';
     }
     ob_start();
     // Show logged messages
     $logger =& $this->getSharedModule('logger');
     if (is_object($logger) && $logger->keys['IS_UNTRUSTED']) {
         $logger->dumpLogs();
     }
     if ($this->keys['IS_ADMIN']) {
         // Display profiling informations
         global $_tip_profiler;
         if (is_object($_tip_profiler)) {
             echo "<h1>Profiler</h1>\n";
             // Leave itsself, that is the tagDebug section
             $_tip_profiler->leaveSection('debug');
             $_tip_profiler->stop();
             $_tip_profiler->display('html');
             // This prevent further operation on $_tip_profiler
             $_tip_profiler = null;
         }
     }
     if ($this->keys['IS_MANAGER']) {
         // Dump the singleton register content
         echo "\n<h1>Register content</h1>\n<pre>\n";
         self::_dumpRegister(TIP_Type::singleton(), '  ');
         echo "</pre>\n";
     }
     return ob_get_clean();
 }
Пример #5
0
 protected function __construct($options)
 {
     parent::__construct($options);
 }
Пример #6
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;
 }
Пример #7
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;
 }
Пример #8
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);
 }
Пример #9
0
 /**
  * Constructor
  *
  * Initializes a TIP_View instance.
  *
  * @param array $options Properties values
  */
 protected function __construct($options)
 {
     parent::__construct($options);
     is_null($this->rows) && $this->fillRows();
 }
Пример #10
0
 /**
  * Type instantiation
  *
  * Gets the singleton of a configured object. $id could be any identifier
  * defined in $GLOBALS['cfg'].
  *
  * An internal register is mantained to avoid singleton() calls with the
  * same $id.
  *
  * @param  mixed    $id       Instance identifier
  * @param  bool     $required true if errors must be fatals
  * @return TIP_Type           The reference to the requested instance or
  *                            false on errors
  */
 public static function &getInstance($id, $required = true)
 {
     static $register = array();
     global $cfg;
     $id = strtolower($id);
     if (class_exists('TIP_Application')) {
         $namespace = TIP_Application::getGlobal('namespace');
         if (!empty($namespace) && isset($cfg[$namespace . '_' . $id])) {
             $id = $namespace . '_' . $id;
         }
     }
     if (array_key_exists($id, $register)) {
         return $register[$id];
     }
     if (isset($cfg[$id])) {
         $options = $cfg[$id];
         isset($options['id']) || ($options['id'] = $id);
         $instance =& TIP_Type::singleton($options);
     } else {
         $instance = null;
     }
     if (is_null($instance) && $required) {
         TIP::fatal("unable to instantiate the requested object ({$id})");
         exit;
     }
     $register[$id] =& $instance;
     return $instance;
 }
Пример #11
0
 /**
  * Try to execute a template file
  *
  * Parses and executes the specified file. Similar to run(),
  * but it does not raise any warning/error if $path is not found.
  *
  * @param  array|string $path The file path to run
  * @return bool               true on success or false on errors
  */
 public function tryRun($path)
 {
     is_string($path) && ($path = array($this->id, $path));
     $template =& TIP_Type::singleton(array('type' => array('template'), 'path' => $path, 'engine' => &$this->engine));
     return $template && $template->run($this);
 }
Пример #12
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;
 }
Пример #13
0
 /**
  * Refresh the current user
  *
  * Refreshes the user id cache of TIP::getUserId() and the privileges
  * of the yet loaded module.
  */
 private function _refreshUser()
 {
     // Refresh the new user id cache
     TIP::getUserId(true);
     // Refresh the privileges of the yet loaded modules
     $this->_refreshModule(TIP_Type::singleton('module'));
 }
Пример #14
0
 /**
  * Get a field type
  *
  * Gets the field type by updating the internal field structure and
  * searching for $id. If it is not found, a recursive search is
  * performed on the joined TIP_Data objects (if any).
  *
  * @param    mixed       $id A field identifier
  * @return   string|null     The requested field type or null on errors
  */
 public function getFieldType($id)
 {
     // Update the fields structure (no details needed)
     if (is_null($this->getFields(false))) {
         return null;
     }
     // Check if the field is found in the current structure
     if (array_key_exists($id, $this->_fields)) {
         return @$this->_fields[$id]['type'];
     }
     // Check if there are defined joins (the requested field could
     // be found in a joined table)
     if (!is_array($this->joins)) {
         return null;
     }
     // Recurse into the joined TIP_Data
     $options = array('type' => array('data'));
     foreach (array_keys($this->joins) as $path) {
         $options['path'] = $path;
         $data = TIP_Type::singleton($options);
         if (!is_null($type = $data->getFieldType($id))) {
             return $type;
         }
     }
     return null;
 }