Exemple #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;
 }
Exemple #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;
 }
Exemple #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;
 }
Exemple #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();
 }
Exemple #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;
 }
Exemple #6
0
 private function _converterPlaceholder(&$row, $field_id)
 {
     if (!empty($row[$field_id])) {
         return;
     }
     $dummy_row = array();
     $data =& TIP_Type::singleton(array('type' => array('data'), 'path' => $this->fields[$field_id]['widget_args']));
     if (is_null($data) || !$data->putRow($dummy_row)) {
         return false;
     }
     $row[$field_id] = $data->getLastId();
     return true;
 }
Exemple #7
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;
 }
Exemple #8
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);
 }
Exemple #9
0
 /**
  * Perform a delete action
  *
  * Overrides the default delete action by showing a merged form
  * between master and child data.
  *
  * @param  mixed $id      The identifier of the row to delete
  * @param  array $options Options to pass to the form() call
  * @return bool           true on success or false on errors
  */
 protected function actionDelete($id, $options = array())
 {
     // Merge the argument options with the configuration options, if found
     // The argument options have higher priority...
     if (@is_array($this->form_options['delete'])) {
         $options = array_merge($this->form_options['delete'], $options);
     }
     TIP::arrayDefault($options, 'on_process', array(&$this, '_onDelete'));
     // Populate "defaults" with master and child values
     if (is_null($row = $this->fromRow($id))) {
         return false;
     }
     if (@is_array($options['defaults'])) {
         $options['defaults'] = array_merge($row, $options['defaults']);
     } else {
         $options['defaults'] =& $row;
     }
     $options['type'] = array('module', 'form');
     $options['master'] =& $this;
     $options['action'] = TIP_FORM_ACTION_DELETE;
     $form =& TIP_Type::singleton($options);
     $valid = $form->validate();
     // On delete, the child form is chained-up also if $valid==false:
     // this module was already retrieved by fromRow()
     $child =& $this->_getChildModule();
     if ($child === false) {
         // Errors on child module
         return false;
     } elseif ($child) {
         // Child module found and valid: chain-up the child form
         $valid = $form->validateAlso($child);
     }
     if ($valid) {
         $form->process();
     }
     return $form->render($valid);
 }
Exemple #10
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'));
 }
Exemple #11
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;
 }