本文整理汇总了PHP中vB_Cache::allCacheEvent方法的典型用法代码示例。如果您正苦于以下问题:PHP vB_Cache::allCacheEvent方法的具体用法?PHP vB_Cache::allCacheEvent怎么用?PHP vB_Cache::allCacheEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vB_Cache
的用法示例。
在下文中一共展示了vB_Cache::allCacheEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createChannel
/**
* Create a blog channel.
*
* @param array $input
* @param int $channelid
* @param int $channelConvTemplateid
* @param int $channelPgTemplateId
* @param int $ownerSystemGroupId
*
* @return int The nodeid of the new blog channel
*/
public function createChannel($input, $channelid, $channelConvTemplateid, $channelPgTemplateId, $ownerSystemGroupId)
{
$input['parentid'] = $channelid;
$input['inlist'] = 1;
// we don't want it to be shown in channel list, but we want to move them
$input['protected'] = 0;
if (empty($input['userid'])) {
$input['userid'] = vB::getCurrentSession()->get('userid');
}
if (!isset($input['publishdate'])) {
$input['publishdate'] = vB::getRequest()->getTimeNow();
}
$input['templates']['vB5_Route_Channel'] = $channelPgTemplateId;
$input['templates']['vB5_Route_Conversation'] = $channelConvTemplateid;
// add channel node
$channelLib = vB_Library::instance('content_channel');
$input['page_parentid'] = 0;
$result = $channelLib->add($input, array('skipFloodCheck' => true, 'skipDupCheck' => true));
//Make the current user the channel owner.
$userApi = vB_Api::instanceInternal('user');
$usergroup = vB::getDbAssertor()->getRow('usergroup', array('systemgroupid' => $ownerSystemGroupId));
if (empty($usergroup) or !empty($usergroup['errors'])) {
//This should never happen. It would mean an invalid parameter was passed
throw new vB_Exception_Api('invalid_request');
}
vB_User::setGroupInTopic($input['userid'], $result['nodeid'], $usergroup['usergroupid']);
vB_Cache::allCacheEvent(array('nodeChg_' . $this->blogChannel, "nodeChg_{$channelid}"));
vB::getUserContext()->rebuildGroupAccess();
vB_Channel::rebuildChannelTypes();
// clear follow cache
vB_Api::instanceInternal('follow')->clearFollowCache(array($input['userid']));
return $result['nodeid'];
}
示例2: createChannel
/**
* Create an article category channel. This function works basically like the blog library's version
*
* @param array $input data array, should have standard channel data like title, parentid,
* @param int $channelid parentid that the new channel should fall under.
* @param int $channelConvTemplateid "Conversation" level pagetemplate to use. Typically vB_Page::getArticleConversPageTemplate()
* @param int $channelPgTemplateId "Channel" level pagetemplate to use. Typically vB_Page::getArticleChannelPageTemplate()
* @param int $ownerSystemGroupId
*
* @return int The nodeid of the new blog channel
*/
public function createChannel($input, $channelid, $channelConvTemplateid, $channelPgTemplateId, $ownerSystemGroupId)
{
if (!isset($input['parentid']) or intval($input['parentid']) < 1) {
$input['parentid'] = $channelid;
}
$input['inlist'] = 1;
// we don't want it to be shown in channel list, but we want to move them
$input['protected'] = 0;
if (empty($input['userid'])) {
$input['userid'] = vB::getCurrentSession()->get('userid');
}
if (!isset($input['publishdate'])) {
$input['publishdate'] = vB::getRequest()->getTimeNow();
}
$input['templates']['vB5_Route_Channel'] = $channelPgTemplateId;
$input['templates']['vB5_Route_Article'] = $channelConvTemplateid;
$input['childroute'] = 'vB5_Route_Article';
// add channel node
$channelLib = vB_Library::instance('content_channel');
$input['page_parentid'] = 0;
$result = $channelLib->add($input, array('skipNotifications' => true, 'skipFloodCheck' => true, 'skipDupCheck' => true));
//Make the current user the channel owner.
$userApi = vB_Api::instanceInternal('user');
$usergroup = vB::getDbAssertor()->getRow('usergroup', array('systemgroupid' => $ownerSystemGroupId));
vB_Cache::allCacheEvent(array('nodeChg_' . $this->articleHomeChannel, "nodeChg_{$channelid}"));
vB::getUserContext()->rebuildGroupAccess();
vB_Channel::rebuildChannelTypes();
// clear follow cache
vB_Api::instanceInternal('follow')->clearFollowCache(array($input['userid']));
return $result['nodeid'];
}
示例3: clearFollowCache
/**
* Clears follow in class cache
*/
public function clearFollowCache($userIds)
{
foreach ($userIds as $user) {
unset($this->followers[$user]);
unset($this->userFollowers[$user]);
unset($this->userFollowing[$user]);
unset($this->subscriptions[$user]);
vB_Cache::allCacheEvent("followChg_{$user}");
}
$this->userListCache = array();
}
示例4: buildStyleDatastore
/**
* Rebuild the style datastore.
*/
public function buildStyleDatastore()
{
$this->setCssDate();
$stylecache = $this->fetchStyles(true, false, array('themes' => true));
foreach ($stylecache as $key => $style) {
// VBV-4174: we don't want stylevars in the datastore
if (isset($style['newstylevars'])) {
unset($stylecache[$key]['newstylevars']);
}
}
vB::getDatastore()->build('stylecache', serialize($stylecache), 1);
vB_Cache::allCacheEvent('vbCachedFullPage');
vB_Library::instance('template')->rebuildTextonlyDS();
return $stylecache;
}
示例5: post_save_once
/**
* Additional data to update after a save call (such as denormalized values in other tables).
* In batch updates, is executed once after all records are updated.
*
* @param boolean Do the query?
*/
function post_save_once($doquery = true)
{
parent::post_save_once($doquery);
if (!empty($this->moderator['userid'])) {
vB_Cache::allCacheEvent('userChg_' . $this->moderator['userid']);
}
vB::getUserContext()->rebuildGroupAccess();
}
示例6: undeleteNodes
/**
* Undelete a set of nodes
* @param array $nodeids
* @param boolean is rebuild needed
* @throws vB_Exception_Api
* @return array - the nodeids that have been deleted
*/
public function undeleteNodes($nodeids, $needRebuild = false)
{
if (empty($nodeids)) {
return false;
}
$errors = array();
$events = array();
$loginfo = array();
$counts = $updates = array();
$nodeids = array_unique($nodeids);
$assertor = vB::getDbAssertor();
$result = $assertor->assertQuery('vBForum:node', array('nodeid' => $nodeids, 'deleteuserid' => 0, 'deletereason' => '', 'unpublishdate' => 0, 'showpublished' => 1, vB_db_Query::TYPE_KEY => vB_db_Query::QUERY_UPDATE));
if (!empty($result['errors'])) {
$errors[] = $result['errors'];
}
$searchAPI = vB_Api::instanceInternal('Search');
foreach ($nodeids as $nodeid) {
$events[] = $nodeid;
$result = $this->publishChildren($nodeid);
if (!empty($result['errors'])) {
$errors[] = $result['errors'];
}
// Clear cache for this node or user post count won't update
vB_Cache::allCacheEvent('nodeChg_' . $nodeid);
$node = $this->getNode($nodeid);
// Update user post count (un(soft)delete)
vB_Library_Content::getContentLib($node['contenttypeid'])->incrementUserPostCount($node);
$loginfo[] = array('nodeid' => $node['nodeid'], 'nodetitle' => $node['title'], 'nodeusername' => $node['authorname'], 'nodeuserid' => $node['userid']);
$parents = $this->fetchClosureParent($nodeid);
foreach ($parents as $parent) {
$nodeInfo = $this->getNodeBare($parent['parent']);
if ($nodeInfo['contenttypeid'] == $this->channelTypeId) {
$result = $this->fixNodeLast($parent['parent']);
} else {
$result = $assertor->assertQuery('vBForum:updateLastData', array('parentid' => $parent['parent'], 'timenow' => vB::getRequest()->getTimeNow()));
}
if (!empty($result['errors'])) {
$errors[] = $result['errors'];
}
switch ($parent['depth']) {
case 0:
// Actual node.
vB_Node::fixNodeCount($parent['parent']);
break;
case 1:
// Immediate parent.
$parentinfo = $this->getNodeBare($parent['parent']);
$counts = array('totalcount' => $parentinfo['totalcount'], 'totalunpubcount' => $parentinfo['totalunpubcount']);
vB_Node::fixNodeCount($parent['parent']);
$parentinfo = $this->getNodeBare($parent['parent']);
$counts = array('totalcount' => $parentinfo['totalcount'] - $counts['totalcount'], 'totalunpubcount' => $parentinfo['totalunpubcount'] - $counts['totalunpubcount']);
break;
default:
// Higher parents.
$updates['totalcount'][$parent['parent']] = $counts['totalcount'];
$updates['totalunpubcount'][$parent['parent']] = $counts['totalunpubcount'];
break;
}
}
$assertor->assertQuery('vBForum:updateNodeTotals', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'updates' => $updates));
$searchAPI->attributeChanged($nodeid);
}
$searchAPI->purgeCacheForCurrentUser();
if ($needRebuild) {
vB::getUserContext()->rebuildGroupAccess();
vB_Channel::rebuildChannelTypes();
}
$this->clearCacheEvents($nodeids);
$this->clearChildCache($nodeids);
if (!empty($errors)) {
return array('errors' => $errors);
}
vB_Library_Admin::logModeratorAction($loginfo, 'node_restored_by_x');
return $nodeids;
}
示例7: setGroupInTopic
/** This grants a user additional permissions in a specific channel, by adding to the groupintopic table
*
* @param int
* @param mixed integer or array of integers
* @param int
*
* @return bool
***/
public static function setGroupInTopic($userid, $nodeids, $usergroupid)
{
//check the data.
if (!is_numeric($userid) or !is_numeric($usergroupid)) {
throw new vB_Exception_Api('invalid_data');
}
if (!is_array($nodeids)) {
$nodeids = array($nodeids);
} else {
$nodeids = array_unique($nodeids);
}
//We don't do a permission check. It's essential that the api's do that before calling here.
//let's get the current channels in which the user already is set for that group.
//Then remove any for which they already are set.
$assertor = vB::getDbAssertor();
$existing = $assertor->assertQuery('vBForum:groupintopic', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'userid' => $userid, 'groupid' => $usergroupid));
foreach ($existing as $permission) {
$index = array_search($permission['nodeid'], $nodeids);
if ($index !== false) {
unset($nodeids[$index]);
}
}
//and do the inserts
foreach ($nodeids as $nodeid) {
$assertor->assertQuery('vBForum:groupintopic', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_INSERT, 'userid' => $userid, 'nodeid' => $nodeid, 'groupid' => $usergroupid));
}
vB_Cache::allCacheEvent(array("userPerms_{$userid}", "userChg_{$userid}", "followChg_{$userid}", "sgMemberChg_{$userid}"));
vB_Api::instanceInternal('user')->clearChannelPerms($userid);
vB::getUserContext($userid)->reloadGroupInTopic();
vB::getUserContext()->clearChannelPermissions();
//if we got here all is well.
return true;
}
示例8: countInUserPostCount
/**
* Checks if the current node should be counted in the user post count for the author.
*
* @param array The node
* @param (unpublish|unapprove) The action that was just carried out on the node
*
* @return boolean Whether or not the node should be counted in user post count.
*/
protected function countInUserPostCount(array $node, $action = '')
{
// NOTICE: How we determine if a post counts in user post count here needs to
// match the criteria used in admincp/misc.php?do=updateposts
// If you update in one place, please update in the other
// check if this content type counts as a "post"
// We have to jump through a bunch of hoops to not count VMs, PMs,
// reports, and other items in user post count
// @todo - VMs and comments should probably be their own content types
// extended from the Text content type.
if (!$this->includeInUserPostCount or $this->isVisitorMessage($node['nodeid'])) {
return false;
}
if (!isset($node['starter'])) {
//force a reload
vB_Cache::allCacheEvent('nodeChg_' . $node['nodeid']);
$node = vB_Library::instance('node')->getNodeFullContent($node['nodeid'], $node['contenttypeid']);
}
return !$this->isComment($node['nodeid'], $node) and ($action == 'unapprove' or $node['approved']) and ($action == 'unpublish' or $node['showpublished'] and !$node['deleteuserid']);
}
示例9: updateContentRoute
protected static function updateContentRoute($oldRouteInfo, $newRouteInfo)
{
$db = vB::getDbAssertor();
$events = array();
// update redirect301 fields
$updateIds = $db->assertQuery('get_update_route_301', array('oldrouteid' => $oldRouteInfo['routeid']));
if (!empty($updateIds)) {
$routeIds = array();
foreach ($updateIds as $route) {
$routeid = $route['routeid'];
$events[] = "routeChg_{$routeid}";
$routeIds[] = $routeid;
}
$db->update('routenew', array('redirect301' => $newRouteInfo['routeid'], 'name' => vB_dB_Query::VALUE_ISNULL), array('routeid' => $routeIds));
}
// don't modify the routeid for default pages, as it will still be used
$updateIds = $db->assertQuery('page', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('pageid'), vB_dB_Query::CONDITIONS_KEY => array('routeid' => $oldRouteInfo['routeid'], 'pagetype' => vB_Page::TYPE_CUSTOM)));
if (!empty($updateIds)) {
$pageIds = array();
foreach ($updateIds as $page) {
$pageid = $page['pageid'];
$events[] = "pageChg_{$pageid}";
$pageIds[] = $pageid;
}
$db->update('page', array('routeid' => $newRouteInfo['routeid']), array('pageid' => $pageIds));
}
vB_Cache::allCacheEvent($events);
}
示例10: is_array
$pfcs[] = $pfc['profilefieldcategoryid'];
}
if (!in_array($vbulletin->GPC['profilefield']['profilefieldcategoryid'], $pfcs)) {
$vbulletin->GPC['profilefield']['profilefieldcategoryid'] = 0;
}
if (empty($vbulletin->GPC['profilefieldid'])) {
// insert
/*insert query*/
$vbulletin->GPC['profilefieldid'] = vB::getDbAssertor()->insert('vBForum:profilefield', $vbulletin->GPC['profilefield']);
$vbulletin->GPC['profilefieldid'] = is_array($vbulletin->GPC['profilefieldid']) ? array_pop($vbulletin->GPC['profilefieldid']) : $vbulletin->GPC['profilefieldid'];
$vbulletin->db->query_write("ALTER TABLE " . TABLE_PREFIX . "userfield ADD field{$vbulletin->GPC['profilefieldid']} MEDIUMTEXT NOT NULL");
$vbulletin->db->query_write("OPTIMIZE TABLE " . TABLE_PREFIX . "userfield");
} else {
vB::getDbAssertor()->update('vBForum:profilefield', $vbulletin->GPC['profilefield'], array('profilefieldid' => $vbulletin->GPC['profilefieldid']));
}
vB_Cache::allCacheEvent('vBProfileFieldsChg');
$vbulletin->db->query_write("\n\t\tREPLACE INTO " . TABLE_PREFIX . "phrase\n\t\t\t(languageid, fieldname, varname, text, product, username, dateline, version)\n\t\tVALUES\n\t\t\t(\n\t\t\t\t0,\n\t\t\t\t'cprofilefield',\n\t\t\t\t'field" . $vbulletin->db->escape_string($vbulletin->GPC['profilefieldid']) . "_title',\n\t\t\t\t'" . $vbulletin->db->escape_string($vbulletin->GPC['title']) . "',\n\t\t\t\t'vbulletin',\n\t\t\t\t'" . $vbulletin->db->escape_string($vbulletin->userinfo['username']) . "',\n\t\t\t\t" . TIMENOW . ",\n\t\t\t\t'" . $vbulletin->db->escape_string($vbulletin->options['templateversion']) . "'\n\t\t\t),\n\t\t\t(\n\t\t\t\t0,\n\t\t\t\t'cprofilefield',\n\t\t\t\t'field" . $vbulletin->db->escape_string($vbulletin->GPC['profilefieldid']) . "_desc',\n\t\t\t\t'" . $vbulletin->db->escape_string($vbulletin->GPC['description']) . "',\n\t\t\t\t'vbulletin',\n\t\t\t\t'" . $vbulletin->db->escape_string($vbulletin->userinfo['username']) . "',\n\t\t\t\t" . TIMENOW . ",\n\t\t\t\t'" . $vbulletin->db->escape_string($vbulletin->options['templateversion']) . "'\n\t\t\t)\n\t");
require_once DIR . '/includes/adminfunctions_language.php';
build_language();
build_profilefield_cache();
if ($vbulletin->GPC['modifyfields']) {
$args = array('do' => 'modifycheckbox', 'profilefieldid' => $vbulletin->GPC['profilefieldid']);
} else {
$args = array('do' => 'modify');
}
print_stop_message2(array('saved_x_successfully', htmlspecialchars_uni($vbulletin->GPC['title'])), 'profilefield', $args);
}
// ###################### Start add #######################
if ($_REQUEST['do'] == 'add' or $_REQUEST['do'] == 'edit') {
$vbulletin->input->clean_array_gpc('r', array('type' => vB_Cleaner::TYPE_STR));
if ($_REQUEST['do'] == 'add') {
示例11: updateDenormalizedUserData
/**
* Updates the user record with infractions, warnings, and ipoints
*
* @param int User id
*/
protected function updateDenormalizedUserData($userid)
{
$userInfractions = $this->getUserInfractions($userid, 0, 1);
$data = array('infractions' => $userInfractions ? intval($userInfractions['statistics']['total_infractions']) : 0, 'warnings' => $userInfractions ? intval($userInfractions['statistics']['total_warnings']) : 0, 'ipoints' => $userInfractions ? intval($userInfractions['statistics']['points']) : 0);
$conditions = array('userid' => $userid);
$changed = $this->assertor->update('user', $data, $conditions);
vB_Cache::allCacheEvent('userChg_' . $userid);
return $changed == 1;
}
示例12: updateContentRoute
protected static function updateContentRoute($oldRouteInfo, $newRouteInfo)
{
$db = vB::getDbAssertor();
$events = array();
$events[] = "vB_ChannelStructure_chg";
// invalidate vB_ChTree... record so that channels' routes are updated
// update redirect301 fields
$updateIds = $db->assertQuery('get_update_route_301', array('oldrouteid' => $oldRouteInfo['routeid']));
if (!empty($updateIds)) {
$routeIds = array();
foreach ($updateIds as $route) {
$routeid = $route['routeid'];
$events[] = "routeChg_{$routeid}";
$routeIds[] = $routeid;
}
$db->update('routenew', array('redirect301' => $newRouteInfo['routeid'], 'name' => vB_dB_Query::VALUE_ISNULL), array('routeid' => $routeIds));
}
// update routeid in nodes table
$updateIds = $db->assertQuery('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('nodeid'), vB_dB_Query::CONDITIONS_KEY => array('routeid' => $oldRouteInfo['routeid'])));
if (!empty($updateIds)) {
$nodeIds = array();
foreach ($updateIds as $node) {
$nodeid = $node['nodeid'];
// this does not affect parents, so we don't need to clear they cache
$events[] = "nodeChg_{$nodeid}";
$nodeIds[] = $nodeid;
}
$db->update('vBForum:node', array('routeid' => $newRouteInfo['routeid']), array('nodeid' => $nodeIds));
}
// don't modify the routeid for default pages, as it will still be used
$updateIds = $db->assertQuery('page', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('pageid'), vB_dB_Query::CONDITIONS_KEY => array('routeid' => $oldRouteInfo['routeid'], 'pagetype' => vB_Page::TYPE_CUSTOM)));
if (!empty($updateIds)) {
$pageIds = array();
foreach ($updateIds as $page) {
$pageid = $page['pageid'];
$events[] = "pageChg_{$pageid}";
$pageIds[] = $pageid;
}
$db->update('page', array('routeid' => $newRouteInfo['routeid']), array('pageid' => $pageIds));
}
/* The code below implies that multiple conversation routes could exist under a single channel. However, I don't know
* when this might be the case. When moving channels/topics, the routes are untouched. Topic redirects are handled by
* the redirect & node tables.
*/
// update conversation generic route
$routes = $db->getRows('routenew', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'class', 'value' => array('vB5_Route_Conversation', 'vB5_Route_Article')), array('field' => 'prefix', 'value' => $oldRouteInfo['prefix']), array('field' => 'contentid', 'value' => $oldRouteInfo['channelid']), array('field' => 'redirect301', 'operator' => vB_dB_Query::OPERATOR_ISNULL))));
foreach ($routes as $route) {
$events[] = "routeChg_{$route['routeid']}";
//if the old route has a name, clear it. Only one route should ever have a name and it belongs to the route
//we are about to create.
if ($route['name']) {
$db->update('routenew', array('name' => vB_dB_Query::VALUE_ISNULL), array('routeid' => $route['routeid']));
}
// create new conversation route using most of the old route's data
$newConversationRoute = $route;
unset($newConversationRoute['routeid']);
unset($newConversationRoute['redirect301']);
$newConversationRoute['prefix'] = $newRouteInfo['prefix'];
// special case, if prefix is empty (i.e. this is a new home page) then we must leave out the leading '/',
// or selectBestRoute will not be able to match the path (which never has a leading '/') to regex.
$newConversationRoute['regex'] = ($newRouteInfo['prefix'] === '' ? '' : preg_quote($newRouteInfo['prefix']) . '/') . vB5_Route_Conversation::REGEXP;
// save the new route. If you need to call validInput(), be sure to unset prefix first, otherwise it'll think it's
// a custom conversation url (as opposed to custom channel url, which this is)
$newConversationRouteid = vB5_Route_Conversation::saveRoute($newConversationRoute);
if (is_array($newConversationRouteid)) {
$newConversationRouteid = (int) array_pop($newConversationRouteid);
}
// then update old convo route's redirect301
$db->update('routenew', array('redirect301' => $newConversationRouteid), array('routeid' => $route['routeid']));
// update routeids for conversation nodes
// Copied from the channel node updates above.
$updateIds = $db->assertQuery('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('nodeid'), vB_dB_Query::CONDITIONS_KEY => array('routeid' => $route['routeid'])));
if (!empty($updateIds)) {
$nodeIds = array();
foreach ($updateIds as $node) {
$nodeid = $node['nodeid'];
// this does not affect parents, so we don't need to clear they cache
$events[] = "nodeChg_{$nodeid}";
$nodeIds[] = $nodeid;
}
// if there are ever cases of multiple conversation routes per channel, and they're sizable, it might be
// worth creating a method query to handle all node updates at once instead of per conversation route.
$db->update('vBForum:node', array('routeid' => $newConversationRouteid), array('nodeid' => $nodeIds));
}
}
vB_Cache::allCacheEvent($events);
}
示例13: clearUserInfo
/**
* Clear user cached info for given userids.
* There's currently cached info in several places (vB_Session, vB_User and vB_Cache implementations)
* this makes sure they all properly cleared.
*
* @param array List of users to clear cache.
*
* @param bool Cache was cleared or not.
**/
public function clearUserInfo($userids)
{
if (empty($userids) or !is_array($userids)) {
return false;
}
$events = array();
$userids = array_unique($userids);
$session = vB::getCurrentSession();
$currentuser = $session->get('userid');
$updatecurrent = false;
foreach ($userids as $userid) {
// update current user?
if ($currentuser == $userid) {
$updatecurrent = true;
}
vB_User::clearUsersCache($userid);
$events[] = 'userChg_' . $userid;
}
vB_Cache::allCacheEvent($events);
if ($updatecurrent) {
$session->clearUserInfo();
}
return true;
}
示例14: reloadUserPerms
/**
* Initializes the user context with the permissions for the selected user.
*
* This is used for the initial constructor and can be used to refresh permissions
* if they have changed.
*
* @param boolean $forceReload -- Do not use cached permissions
*
*/
public function reloadUserPerms($forceReload = false)
{
if (!$forceReload) {
$cached = vB_Cache::instance(vB_Cache::CACHE_LARGE)->read('vB_UserPerms' . $this->userid);
}
if (!empty($cached)) {
$this->groupInTopic = $cached['groupintopic'];
$this->usergroups = $cached['usergroups'];
$this->moderatorPerms = $cached['moderatorperms'];
$this->channelAccess = $cached['channelAccess'];
$this->permissionContext = new vB_PermissionContext($this->datastore, $cached['primary'], $cached['secondary'], $cached['infraction']);
$this->canModerate = $cached['canmoderate'];
$this->superMod = $cached['superMod'];
} else {
//make sure we clear the stored session data.
if ($forceReload) {
vB_Cache::allCacheEvent('userPerms_' . $this->userid);
}
$this->superMod = array('moderatorpermissions' => 0, 'moderatorpermissions2' => 0);
// fetch user groups
$userLib = vB_Library::instance('user');
if ($this->userid > 0) {
try {
$result = $userLib->fetchUserGroups($this->userid);
} catch (vB_Exception_Api $e) {
$errors = $e->get_errors();
if ($errors[0][0] == 'invalid_user_specified') {
//note that we can't get here on the second call because the userid is 0
//we need to make sure we don't infinitely recurse here
$this->userid = 0;
return $this->reloadUserPerms($forceReload);
}
throw $e;
}
} else {
$result = false;
}
if ($result) {
$primary_group_id = $result['groupid'];
$secondary_group_ids = $result['secondary'];
$infraction_group_ids = $result['infraction'];
} else {
$primary_group_id = self::USERGROUP_GUESTS;
$secondary_group_ids = array();
$infraction_group_ids = array();
}
//We can't call the user api function getGroupInTopic(), because that does a permission check. Which causes a recursion loop
//We have to do a try-catch block here. During an upgrade we check permissions although the groupintopic table doesn't exist.
try {
if ($this->userid > 0) {
$this->reloadGroupInTopic();
}
} catch (exception $e) {
//Nothing to do here. Just continue
}
// ignore secondary usergroups if allowmembergroups is set to "No"
$bf_ugp_genericoptions = $this->datastore->get_value('bf_ugp_genericoptions');
$usergroupCache = $this->datastore->get_value('usergroupcache');
//vB::getDatastore()->getValue('usergroupcache');
if (!($usergroupCache[$primary_group_id]['genericoptions'] & $bf_ugp_genericoptions['allowmembergroups'])) {
$this->usergroups = array($primary_group_id);
} else {
$this->usergroups = array_merge(array($primary_group_id), $secondary_group_ids);
}
$this->permissionContext = new vB_PermissionContext($this->datastore, $primary_group_id, $secondary_group_ids, $infraction_group_ids);
//Add any permissions from the moderator table.
if ($this->userid) {
// Since moderator perms are based on the moderator table, I'm leaving this independent of the usergroup option 'allowmembergroups'
$this->moderatorPerms = $userLib->fetchModerator($this->userid);
if ($this->hasPermission('adminpermissions', 'ismoderator') and !empty($this->moderatorPerms[0])) {
if (!isset($this->moderatorPerms[0]['permissions'])) {
$this->moderatorPerms[0]['permissions'] = 0;
}
if (!isset($this->moderatorPerms[0]['permissions2'])) {
$this->moderatorPerms[0]['permissions2'] = 0;
}
$this->superMod = array('moderatorpermissions' => $this->moderatorPerms[0]['permissions'], 'moderatorpermissions2' => $this->moderatorPerms[0]['permissions2']);
}
} else {
$this->moderatorPerms = array();
}
vB_Cache::instance(vB_Cache::CACHE_LARGE)->write('vB_UserPerms' . $this->userid, array('groupintopic' => $this->groupInTopic, 'usergroups' => $this->usergroups, 'moderatorperms' => $this->moderatorPerms, 'primary' => $primary_group_id, 'secondary' => $secondary_group_ids, 'infraction' => $infraction_group_ids, 'channelAccess' => $this->getAllChannelAccess(), 'canmoderate' => $this->getCanModerate(), 'superMod' => $this->superMod), 1440, array('userPerms_' . $this->userid, 'userChg_' . $this->userid, 'perms_changed', 'vB_ChannelStructure_chg'));
}
}
示例15: getVideoThumbnail
/**
* Extracts the thumbnail from og:image meta data
*
* @param string url of video
* @param int optional nodeid of video node
*
* @return mixed url string or false
*/
public function getVideoThumbnail($url, $nodeid = false)
{
//Note that this is called from the template, and often there will be no ndeid
if (!empty($nodeid)) {
$video = $this->getContent($nodeid);
if (!empty($video)) {
$video = array_pop($video);
}
}
if (empty($video)) {
//Try to get from cache first.
$cacheKey = 'vB_Vid' . md5($url);
$check = vB_Cache::instance(vB_Cache::CACHE_LARGE)->read($cacheKey);
if (!empty($check)) {
return $check;
}
$video = $this->assertor->getRow('vBForum:video', array('url' => $url));
}
//check if we have the thumbnail in the video
if (!empty($video) and !empty($video['thumbnail']) and !empty($video['thumbnail_date']) and $video['thumbnail_date'] >= vB::getRequest()->getTimeNow() - self::THUMBNAIL_TTL) {
return $video['thumbnail'];
}
$data = vB_Api::instance('content_link')->parsePage($url);
if (!empty($data['images'])) {
$thumbnail = $data['images'];
// only return the first image. May want to change this later after product audit?
if (is_array($thumbnail)) {
$thumbnail = $thumbnail[0];
}
//save the thumbnail so we don't have to fetch it next time it's needed
if (!empty($video)) {
//there is a video record. Put it there.
$this->assertor->update('vBForum:video', array('thumbnail' => $thumbnail, 'thumbnail_date' => vB::getRequest()->getTimeNow()), array('nodeid' => $video['nodeid']));
vB_Cache::allCacheEvent('nodeChg_' . $video['nodeid']);
} else {
//put into cache
if (empty($cacheKey)) {
$cacheKey = 'vB_Vid' . md5($url);
}
vB_Cache::instance(vB_Cache::CACHE_LARGE)->write($cacheKey, $thumbnail, self::THUMBNAIL_TTL);
}
return $thumbnail;
}
// we should probably have a default placeholder
// we can return in case no image is found..
return false;
}