/** * Create new cpsession for the user and insert it into database or fetch current existing one * * @param bool $renew Whether to renew cpsession hash (Create a new one and drop the old one) * * @throws vB_Exception * @return string The new cpsession hash * */ public function fetchCpsessionHash($renew = false) { if (!$this->created) { throw new vB_Exception_User('session_not_created'); } if ($this->cpsessionHash) { if (!$renew) { return $this->cpsessionHash; } else { // Drop the old cp session record $this->dBAssertor->delete('cpsession', array('hash' => $this->cpsessionHash)); } } $this->cpsessionHash = $this->fetch_sessionhash(); $this->dBAssertor->insert('cpsession', array('userid' => $this->vars['userid'], 'hash' => $this->cpsessionHash, 'dateline' => vB::getRequest()->getTimeNow())); return $this->cpsessionHash; }
/** * Expires cache entries associated with triggered events. * * @return bool - Whether any events were triggered */ public function event($events) { if (empty($events)) { return; } if (!is_array($events)) { $events = array($events); } // Get affected cache entries $results = $this->assertor->getColumn('cacheevent', 'cacheid', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'event', 'value' => $events)))); foreach ($events as $event) { if (isset($this->pageEvents[$event])) { foreach ($this->pageEvents[$event] as $cacheid) { $results[] = $cacheid; unset($this->values_read[$cacheid]); $this->no_values[$cacheid] = $cacheid; unset($this->recordsToSave[$cacheid]); } } } $this->expire($results); $this->assertor->delete('cacheevent', array('event' => $events)); return true; }
/** * Saves the updated properties to the database. */ function save() { $bf_ugp_usercsspermissions = vB5_vB::get_datastore()->get_value('bf_ugp_usercsspermissions'); // First, we want to remove any properties they don't have access to. // This is in case they lost some permissions; // leaving them around leads to unexpected behavior. $prop_del = array(); foreach ($this->properties as $property => $propertyinfo) { if (!($this->permissions['usercsspermissions'] & $bf_ugp_usercsspermissions["{$propertyinfo['permission']}"])) { $prop_del[] = $property; } } if ($prop_del) { $this->assertor->delete('usercss', array('userid' => $this->userid, 'property' => $prop_del)); } // now go for any entries that we emptied -- these are being removed if (!empty($this->delete)) { foreach ($this->delete as $selector => $properties) { foreach ($properties as $property) { if (!empty($this->existing["{$selector}"]["{$property}"])) { $this->assertor->delete('usercss', array('userid' => $this->userid, 'selector' => $selector, 'property' => $property)); } unset($this->existing["{$selector}"]["{$property}"]); } } } // and for new/changed ones... if (!empty($this->store)) { $value = array(); foreach ($this->store as $selector => $properties) { foreach ($properties as $property => $value) { $values['userid'] = $this->userid; $values['selector'] = $selector; $values['property'] = $property; $values['value'] = $value; $this->assertor->delete('usercss', array('userid' => $this->userid, 'selector' => $selector, 'property' => $property)); } } if ($values) { $this->assertor->insert('usercss', $values); } } $this->update_css_cache(); }