public function __construct($nodeid, $nodetype = "", $user = "") { //unfortunately this has been used extensively in non node contexts //despite its name and cleaning that up is going to be it's own exercise. //so we hack around that here if (is_numeric($nodeid)) { $this->nodeid = $nodeid; if (!$nodetype) { $nodetype = 'node'; } if ($user) { parent::__construct('node_permission_user', array($nodeid, $nodetype, $user)); } else { parent::__construct('node_permission', array($nodeid, $nodetype)); } } else { $this->nodeid = 0; parent::__construct('node_permission_section', array($nodeid)); } }
public function get_exception() { $e = new vB_Exception_Api(); foreach ($this->errors as $error) { //this is intended to be used with the "array unprocessed" error mode. if (is_array($error)) { $phraseid = array_shift($error); $e->add_error($phraseid, $error); } else { $e->add_error('unexpected_error', $error); } } return $e; }
/** * Verifies and saves a signature for current logged in user. Returns the signature. * @param string $signature * @param array $filedataids * @return string */ public function saveSignature($signature, $filedataids = array()) { // This code is based on profile.php $options = vB::getDatastore()->getValue('options'); // *********************** CHECKS ********************** // ***************************************************** $userid = vB::getCurrentSession()->get('userid'); $userid = intval($userid); if ($userid <= 0) { throw new vB_Exception_Api('no_permission_logged_out'); } $userContext = vB::getUserContext($userid); if (!$userContext->hasPermission('genericpermissions', 'canusesignature') or !$userContext->hasPermission('genericpermissions', 'canmodifyprofile')) { throw new vB_Exception_Api('no_permission_signatures'); } if (!empty($filedataids)) { if (!$userContext->hasPermission('signaturepermissions', 'cansigpic')) { throw new vB_Exception_Api('no_permission_images'); } // Max number of images in the sig if imgs are allowed. if ($maxImages = $userContext->getLimit('sigmaximages')) { if (count($filedataids) > $maxImages) { throw new vB_Exception_Api('max_attachments_reached'); } } } // Count the raw characters in the signature if ($maxRawChars = $userContext->getLimit('sigmaxrawchars') and vB_String::vbStrlen($signature) > $maxRawChars) { throw new vB_Exception_Api('sigtoolong_includingbbcode', array($maxRawChars)); } // ***************************************************** //Convert signature to BBcode $bbcodeAPI = vB_Api::instanceInternal('bbcode'); $signature = $bbcodeAPI->parseWysiwygHtmlToBbcode($signature); //removing consecutive spaces $signature = preg_replace('# +#', ' ', $signature); $hasBbcode = $bbcodeAPI->hasBbcode($signature); if ($hasBbcode and !$userContext->hasPermission('signaturepermissions', 'canbbcode')) { throw new vB_Exception_Api('bbcode_not_allowed'); } // add # to color tags using hex if it's not there $signature = preg_replace('#\\[color=("|"|\'|)([a-f0-9]{6})\\1]#i', '[color=\\1#\\2\\1]', $signature); // Turn the text into bb code. if ($userContext->hasPermission('signaturepermissions', 'canbbcodelink')) { // Get the files we need require_once DIR . '/includes/functions_newpost.php'; $signature = convert_url_to_bbcode($signature); } // Create the parser with the users sig permissions require_once DIR . '/includes/class_sigparser.php'; $sig_parser = new vB_SignatureParser(vB::get_registry(), $bbcodeAPI->fetchTagList(), $userid); // Parse the signature $paresed = $sig_parser->parse($signature); if ($error_num = count($sig_parser->errors)) { $e = new vB_Exception_Api(); foreach ($sig_parser->errors as $tag => $error_phrase) { if (is_array($error_phrase)) { $phrase_name = key($error_phrase); $params = $error_phrase[$phrase_name]; $e->add_error($phrase_name, $params); } else { $e->add_error($error_phrase, array($tag)); } } throw $e; } unset($sig_parser); // Count the characters after stripping in the signature if ($maxChars = $userContext->getLimit('sigmaxchars') and vB_String::vbStrlen(vB_String::stripBbcode($signature, false, false, false)) > $maxChars) { throw new vB_Exception_Api('sigtoolong_excludingbbcode', array($maxChars)); } if (($maxLines = $userContext->getLimit('sigmaxlines')) > 0) { require_once DIR . '/includes/class_sigparser_char.php'; $char_counter = new vB_SignatureParser_CharCount(vB::get_registry(), $bbcodeAPI->fetchTagList(), $userid); $line_count_text = $char_counter->parse(trim($signature)); if ($options['softlinebreakchars'] > 0) { // implicitly wrap after X characters without a break //trim it to get rid of the trailing whitechars that are inserted by the replace $line_count_text = trim(preg_replace('#([^\\r\\n]{' . $options['softlinebreakchars'] . '})#', "\\1\n", $line_count_text)); } // + 1, since 0 linebreaks still means 1 line $line_count = substr_count($line_count_text, "\n") + 1; if ($line_count > $maxLines) { throw new vB_Exception_Api('sigtoomanylines', array($maxLines)); } } // ***************************************************** // Censored Words $signature = vB_String::fetchCensoredText($signature); // init user data manager $userinfo = vB_User::fetchUserInfo($userid); $userdata = new vB_Datamanager_User(vB_DataManager_Constants::ERRTYPE_STANDARD); $userdata->set_existing($userinfo); $userdata->set('signature', $signature); // Legacy Hook 'profile_updatesignature_complete' Removed // // Decresing the refcount for the images that were previously used in the signature if (!empty($userinfo['signature'])) { preg_match_all('#\\[ATTACH\\=CONFIG\\]n(\\d+)\\[/ATTACH\\]#si', $userinfo['signature'], $matches); if (!empty($matches[1])) { $attachmentids = implode(", ", $matches[1]); vB::getDbAssertor()->assertQuery('decrementFiledataRefcount', array('filedataid' => $attachmentids)); vB::getDbAssertor()->assertQuery('filedata', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'filedataid', 'value' => $attachmentids, 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'refcount', 'value' => 0, 'operator' => vB_dB_Query::OPERATOR_EQ)), 'publicview' => 0)); } } $userdata->save(); // I did not put this in the userdm as it only applies to saveSiganture // Clear autosave table of this items entry vB::getDbAssertor()->delete('vBForum:autosavetext', array('userid' => $userid, 'nodeid' => 0, 'parentid' => 0)); // update userinfo $this->library->clearUserInfo(array($userid)); return $bbcodeAPI->parseSignature($userid, $signature, true); }
protected function getExceptionFromErrors($errors) { $e = new vB_Exception_Api(); foreach ($errors as $error) { if (is_array($error)) { $phraseid = array_shift($error); $e->add_error($phraseid, $error); } else { $e->add_error($error, array()); } } return $e; }
/** * Check validity of data passed in and 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. */ protected function createChannel($input, $channelid, $channelConvTemplateid, $channelPgTemplateId, $ownerSystemGroupId) { // Check user is logged in $currentSession = vB::getCurrentSession(); $userid = $currentSession->get('userid'); $userid = intval($userid); if (!$channelid) { $channelid = $this->getBlogChannel(); } if ($userid <= 0 || !vB::getUserContext()->getChannelPermission('createpermissions', 'vBForum_Channel', $channelid)) { throw new vB_Exception_Api('no_permission'); } // Check input is valid $errors = array(); $input['title'] = isset($input['title']) ? trim($input['title']) : ''; $input['description'] = isset($input['description']) ? trim($input['description']) : ''; $input['parentid'] = $channelid; if (empty($input['title'])) { if (isset($this->sgChannel)) { $errors[] = 'content_no_title'; } else { $userInfo = $currentSession->fetch_userinfo(); $input['title'] = (string) new vB_Phrase('global', 'x_blog', $userInfo['username']); } } //blank title may have been auto-filled for Blog, so let's check for title again if (!empty($input['title'])) { if (empty($input['urlident'])) { $input['urlident'] = $this->toSeoFriendly($input['title']); } // verify prefixes do not collide $newPrefix = vB5_Route_Channel::createPrefix($channelid, $input['urlident'], true); if (vB5_Route::isPrefixUsed($newPrefix) !== FALSE) { $errors[] = isset($this->sgChannel) ? 'sg_title_exists' : 'blog_title_exists'; } } //Product says description is not required for Blogs if (empty($input['description']) and isset($this->sgChannel)) { $errors[] = 'content_no_description'; } if (!empty($errors)) { $e = new vB_Exception_Api(); foreach ($errors as $error) { $e->add_error($error); } throw $e; } vB_Api::instanceInternal('content_channel')->cleanInput($input, $channelid); $nodeid = $this->library->createChannel($input, $channelid, $channelConvTemplateid, $channelPgTemplateId, $ownerSystemGroupId); // Because "subscribe" in blogs is equivalent to "join AND subscribe" of a group, and because there is no interface for a group owner to // separately subscribe to a blog they created, we must subscribe the owner to the newly created blog. // Since social group API inherits the blog API, we can't just do that in the library's createChannel() function after it creates the groupintopic // record (look for vB_User::setGroupInTopic(...)) // So we check to see if the channel created is a blog (as opposed to a social group), and if so, create a subscription. if ($this->isBlogNode($nodeid)) { vB_Api::instanceInternal('follow')->add($nodeid, vB_Api_Follow::FOLLOWTYPE_CHANNELS, $userid, true); } return $nodeid; }