예제 #1
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;
 }
예제 #2
0
 /**
  * Get the privilege for the specified module
  *
  * Returns the privilege for a module and the specified user.  If $user
  * is omitted, the current user id is used. Check TIP_Privilege to see how the
  * privileges are used.
  *
  * @param  string           $module The requesting module identifier
  * @param  mixed            $user   A user id
  * @return TIP_PRIVILEGE...         The requested privilege
  */
 public static function getPrivilege($module, $user = null)
 {
     static $privilege = false;
     if ($privilege === false) {
         $privilege =& TIP_Application::getSharedModule('privilege');
     }
     if ($privilege) {
         return $privilege->getPrivilege($module, $user);
     }
     return TIP::getDefaultPrivilege($module, $user);
 }
예제 #3
0
 /**
  * Constuctor
  */
 public function __construct()
 {
     $this->_user =& TIP_Application::getSharedModule('user');
 }
예제 #4
0
 /**
  * 'on_process' callback for unflag actions
  *
  * This is the reverse operation of _onFlag(), and set the
  * flag field to "no".
  *
  * @param  array &$row The row to flag
  * @return bool        true on success or false on errors
  */
 public function _onUnflag(&$old_row)
 {
     if (!isset($this->flag_field)) {
         // No flag field defined: silently returns true
         return true;
     }
     $flagger = @$old_row[$this->flagger_field];
     $flagged = @$old_row[$this->owner_field];
     $row[$this->flag_field] = 'no';
     if (!$this->data->updateRow($row, $old_row)) {
         return false;
     }
     $user = TIP_Application::getSharedModule('user');
     if (!$user) {
         // User module not available: no statistic update required
         return true;
     }
     // Update statistics of the flagging user
     if (isset($flagger, $this->unflaggee_field) && !is_null($view = $user->startDataView($user->getProperty('data')->rowFilter($flagger)))) {
         $row = $view->current();
         $user->endView();
         if (!is_null($row)) {
             $old_row = $row;
             ++$row[$this->unflaggee_field];
             $user->getProperty('data')->updateRow($row, $old_row);
         }
     }
     // Update statistics of the flagged user
     if (isset($flagged, $this->unflagged_field) && !is_null($view = $user->startDataView($user->getProperty('data')->rowFilter($flagged)))) {
         $row = $view->current();
         $user->endView();
         if (!is_null($row)) {
             $old_row = $row;
             ++$row[$this->unflagged_field];
             $user->getProperty('data')->updateRow($row, $old_row);
         }
     }
     return true;
 }