public function hasAdminPermission($permission) { // if user is super admin if ($this->userIsSuperAdmin) { return true; } $full_admin = $this->basicAdminControl(); if ($full_admin !== 0) { return $full_admin > 0; } $bf_ugp_adminpermissions = $this->datastore->get_value('bf_ugp_adminpermissions'); if (!isset($this->admin_info)) { $result = $this->assertor->assertQuery('vBForum:administrator', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'userid' => $this->userid)); if ($result->valid()) { $this->admin_info = $result->current(); //two "admin" permissions are actually stored at the usergroup level. Copy them here. if ($this->permissionContext->hasPermission('adminpermissions', 'cancontrolpanel')) { $this->admin_info['adminpermissions'] |= $bf_ugp_adminpermissions['cancontrolpanel']; } if ($this->permissionContext->hasPermission('adminpermissions', 'ismoderator')) { $this->admin_info['adminpermissions'] |= $bf_ugp_adminpermissions['ismoderator']; } } else { return false; } } return (bool) ($this->admin_info['adminpermissions'] & $bf_ugp_adminpermissions[$permission]); }
public function getChannelPerm($usergroupid, $permissiongroup, $permission, $channelid) { if ($permissiongroup == 'moderatorpermissions') { $bf_ugp = $this->datastore->getValue('bf_misc_' . $permissiongroup); } else { $bf_ugp = $this->datastore->getValue('bf_ugp_' . $permissiongroup); } if (!isset($this->channelPermissions[$usergroupid])) { $this->loadChannelPermissions($usergroupid); $this->validateInfractionPermissions($usergroupid, $channelid); } if (empty($this->permissionsFrom)) { $this->permissionsFrom = vB::getDatastore()->getValue('vBUgChannelPermissionsFrom'); } // We might have gotten an integer; if (is_numeric($permission)) { $permission = strtolower(vB_Types::instance()->getContentTypePackage($permission) . '_' . vB_Types::instance()->getContentTypeClass($permission)); } else { $permission = strtolower($permission); } if (!isset($this->channelPermissions[$usergroupid][$channelid]) and isset($this->permissionsFrom[$usergroupid]) and isset($this->permissionsFrom[$usergroupid][$channelid])) { $channelid = $this->permissionsFrom[$usergroupid][$channelid]; } if (isset($bf_ugp[$permission]) and isset($this->channelPermissions[$usergroupid][$channelid])) { switch ($permissiongroup) { case 'forumpermissions': return $bf_ugp[$permission] & $this->channelPermissions[$usergroupid][$channelid]['forumpermissions']; break; case 'forumpermissions2': return $bf_ugp[$permission] & $this->channelPermissions[$usergroupid][$channelid]['forumpermissions2']; break; case 'createpermissions': //We might have gotten an integer; if (is_numeric($permission)) { $permission = strtolower(vB_Types::instance()->getContentTypePackage($permission) . '_' . vB_Types::instance()->getContentTypeClass($permission)); } else { $permission = strtolower($permission); } return $bf_ugp[$permission] & $this->channelPermissions[$usergroupid][$channelid]['createpermissions']; break; case 'moderatorpermissions': if ($usergroupid == 1) { return false; } return $bf_ugp[$permission] & intval($this->channelPermissions[$usergroupid][$channelid]['moderatorpermissions']); break; default: return false; } // switch } else { $permFields = vB_ChannelPermission::fetchPermFields(); if (isset($permFields[$permission]) and $permFields[$permission] != vB_ChannelPermission::TYPE_BITMAP and isset($this->channelPermissions[$usergroupid][$channelid])) { return $this->channelPermissions[$usergroupid][$channelid][$permission]; } return false; } }
/** * Updates the last visit and last activity times for guests and registered users (differently). * Last visit is set to the last activity time (before it's updated) only when a certain * time has lapsed. Last activity is always set to the specified time. * * @param integer Time stamp for last visit time (guest only) * @param integer Time stamp for last activity time (guest only) * @return array Updated values for setting cookies (guest only) */ public function doLastVisitUpdate($lastvisit = 0, $lastactivity = 0) { $options = $this->datastore->getValue('options'); $request = vB::getRequest(); $timeNow = $request->getTimeNow(); $cookies = array(); // update last visit/activity stuff if ($this->vars['userid'] == 0) { // guest -- emulate last visit/activity for registered users by cookies if ($lastvisit) { // we've been here before $this->userinfo['lastactivity'] = $lastactivity ? intval($lastactivity) : intval($lastvisit); // here's the emulation if ($timeNow - $this->userinfo['lastactivity'] > $options['cookietimeout']) { // update lastvisit $this->userinfo['lastvisit'] = $this->userinfo['lastactivity']; $cookies['lastvisit'] = $this->userinfo['lastactivity']; } else { // keep lastvisit value $this->userinfo['lastvisit'] = intval($lastvisit); } } else { // first visit! $this->userinfo['lastvisit'] = $timeNow; $cookies['lastvisit'] = $timeNow; } // lastactivity is always now $this->userinfo['lastactivity'] = $timeNow; $cookies['lastactivity'] = $timeNow; return $cookies; } else { // registered user if (!SESSION_BYPASS) { if ($timeNow - $this->userinfo['lastactivity'] > $options['cookietimeout']) { // see if session has 'expired' and if new post indicators need resetting $this->dBAssertor->shutdownQuery('updateLastVisit', array('timenow' => $timeNow, 'userid' => $this->userinfo['userid']), 'lastvisit'); $this->userinfo['lastvisit'] = $this->userinfo['lastactivity']; } else { // if this line is removed (say to be replaced by a cron job, you will need to change all of the 'online' // status indicators as they use $userinfo['lastactivity'] to determine if a user is online which relies // on this to be updated in real time. $this->dBAssertor->update('user', array('lastactivity' => $timeNow), array('userid' => $this->userinfo['userid']), 'lastvisit'); } } // we don't need to set cookies for registered users return null; } }
/** * Constructor - Checks for necessity of registry object * * Note that this method will accept only the $errtype parameter (via some magic checking of the parameters) * and this is the preferred way of calling the datamanager functions. The registry object is deprecated * and will be created internally for those managers that still need it. * * @param vB_Registry $registry -- Instance of the vBulletin data registry object - expected to have the * database object as one of its $this->db member. * @param integer $errtype --One of the ERRTYPE_x constants */ public function __construct($registry = NULL, $errtype = NULL) { if (is_object($registry)) { $this->registry =& $registry; } else { if ($this->needRegistry) { $this->registry = vB::get_registry(); } } if (is_int($registry) and $errtype === NULL) { //This allows us to function as either vb3/4 style with $vbulletin, // or vb5-style with no global variables $errtype = $registry; } else { if ($errtype === NULL) { $errtype = vB_DataManager_Constants::ERRTYPE_STANDARD; } } $this->assertor = vB::getDbAssertor(); $this->session = vB::getCurrentSession(); $this->userinfo = $this->session->fetch_userinfo(); $this->datastore = vB::getDatastore(); $this->options = $this->datastore->get_value('options'); $this->setErrorHandler($errtype); if (is_array($this->bitfields)) { foreach ($this->bitfields as $key => $val) { //set this to bitfields array directly and unset if bad. if we try to set this to a interim //variable we end up getting the references crossed so that every element of the array is //the same as the last value loaded (this is a bit of a problem). We could not use references //but I'd like to avoid copying static arrays more than I need to. $this->bitfields["{$key}"] = $this->datastore->get_value($val); if (!$this->bitfields["{$key}"]) { unset($this->bitfields["{$key}"]); trigger_error("Please check the <em>\$bitfields</em> array in the <strong>" . get_class($this) . "</strong> class definition - <em>\$vbulletin->{$val}</em> is not a valid bitfield.<br />", E_USER_ERROR); } } } /* Legacy Hook $this->hook_start Removed */ }
/** * Fetches the contents of the datastore from cache files * * @param array Array of items to fetch from the datastore * * @return void */ function fetch($itemarray) { $include_return = @(include_once DATASTORE . '/datastore_cache.php'); if ($include_return === false) { if (VB_AREA == 'AdminCP') { trigger_error('Datastore cache file does not exist. Please reupload includes/datastore/datastore_cache.php from the original download.', E_USER_ERROR); } else { parent::fetch($itemarray); return; } } $itemlist = array(); foreach ($this->cacheableitems as $item) { if (${$item} === '' or !isset(${$item})) { if (VB_AREA == 'AdminCP') { ${$item} = $this->fetch_build($item); } else { $itemlist[] = "'" . $this->dbobject->escape_string($item) . "'"; continue; } } if ($this->register($item, ${$item}) === false) { trigger_error('Unable to register some datastore items', E_USER_ERROR); } unset(${$item}); } foreach ($this->defaultitems as $item) { if (!in_array($item, $this->cacheableitems)) { $itemlist[] = "'" . $this->dbobject->escape_string($item) . "'"; } } if (is_array($itemarray)) { foreach ($itemarray as $item) { $itemlist[] = "'" . $this->dbobject->escape_string($item) . "'"; } } if (!empty($itemlist)) { $this->do_db_fetch(implode(',', $itemlist)); } $this->check_options(); // set the version number variable $this->registry->versionnumber =& $this->registry->options['templateversion']; }
/** * Updates the appropriate cache file * * @param string title of the datastore item * @param mixed The data associated with the title * * @return void */ public function build($title = '', $data = '', $unserialize = 0) { parent::build($title, $data, $unserialize); $this->storeEAccelerator($title, $data); }
/** * Updates the appropriate cache file * * @param string title of the datastore item * @param mixed The data associated with the title * * @return void */ public function build($title = '', $data = '', $unserialize = 0) { parent::build($title, $data, $unserialize); $this->storeWinCache($title, $data); }
/** * Fetches the contents of the datastore from cache files * * @param array Array of items to fetch from the datastore * * @return void */ function fetch($items) { $include_return = @(include_once DATASTORE . '/datastore_cache.php'); if ($include_return === false) { if (VB_AREA == 'AdminCP') { trigger_error('Datastore cache file does not exist. Please reupload includes/datastore/datastore_cache.php from the original download.', E_USER_ERROR); } else { parent::fetch($items); return; } } // Ensure $this->cacheableitems are always fetched $unfetched_items = array(); foreach ($this->cacheableitems as $item) { if (!vB_DataStore::$registered[$item]) { if (${$item} === '' or !isset(${$item})) { if (VB_AREA == 'AdminCP') { ${$item} = $this->fetch_build($item); } else { $unfetched_items[] = $item; continue; } } if ($this->register($item, ${$item}) === false) { trigger_error('Unable to register some datastore items', E_USER_ERROR); } unset(${$item}); } } // fetch anything remaining $items = $items ? array_merge($items, $unfetched_items) : $unfetched_items; if ($items = $this->prepare_itemlist($items, true)) { if (!($result = $this->do_db_fetch($items))) { return false; } } $this->check_options(); return true; }
/** * This method is intended only for unit testing. Do NOT use it in other context. * Clear all the cache class vars, useful to calculate every value again. */ public function clearValues() { if (!defined('VB_UNITTEST')) { throw new Exception('This method should be called only from unit tests'); } else { $this->memcache_set = true; $this->store_result = false; $this->memcache->flush(); parent::clearValues(); } }
/** * Updates the appropriate cache file * * @param string title of the datastore item * @param mixed The data associated with the title * * @return void */ public function build($title = '', $data = '', $unserialize = 0) { parent::build($title, $data, $unserialize); if (!in_array($title, $this->cacheableitems)) { return; } if (!file_exists($this->datastoreLocation . '/datastore_cache.php')) { // file doesn't exist so don't try to write to it return; } $data_code = var_export(unserialize(trim($data)), true); if ($this->lock()) { $cache = file_get_contents($this->datastoreLocation . '/datastore_cache.php'); // this is equivalent to the old preg_match system, but doesn't have problems with big files (#23186) $open_match = strpos($cache, "### start {$title} ###"); if ($open_match) { // matched and not at the beginning $preceding = $cache[$open_match - 1]; if ($preceding != "\n" and $preceding != "\r") { $open_match = false; } } if ($open_match) { $close_match = strpos($cache, "### end {$title} ###", $open_match); if ($close_match) { // matched and not at the beginning $preceding = $cache[$close_match - 1]; if ($preceding != "\n" and $preceding != "\r") { $close_match = false; } } } // if we matched the beginning and end, then update the cache if (!empty($open_match) and !empty($close_match)) { $replace_start = $open_match - 1; // include the \n $replace_end = $close_match + strlen("### end {$title} ###"); $cache = substr_replace($cache, "\n### start {$title} ###\n\${$title} = {$data_code};\n### end {$title} ###", $replace_start, $replace_end - $replace_start); } // try an atomic operation first, if that fails go for the old method $atomic = false; if ($fp = @fopen($this->datastoreLocation . '/datastore_cache_atomic.php', 'w')) { fwrite($fp, $cache); fclose($fp); $atomic = $this->atomic_move($this->datastoreLocation . '/datastore_cache_atomic.php', $this->datastoreLocation . '/datastore_cache.php'); } if (!$atomic and $fp = @fopen($this->datastoreLocation . '/datastore_cache.php', 'w')) { fwrite($fp, $cache); fclose($fp); } $this->unlock(); // /* insert query */ $this->db_assertor->assertQuery('replace_adminutil', array('text' => $cache)); } else { trigger_error('Could not obtain file lock', E_USER_ERROR); } }