Пример #1
0
 /**
  * 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=(&quot;|"|\'|)([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);
 }
Пример #2
0
	if ($vbulletin->userinfo['permissions']['signaturepermissions'] & $vbulletin->bf_ugp_signaturepermissions['canbbcode'])
	{
		// Get the files we need
		require_once(DIR . '/includes/functions_newpost.php');

		// add # to color tags using hex if it's not there
		$signature = preg_replace('#\[color=(&quot;|"|\'|)([a-f0-9]{6})\\1]#i', '[color=\1#\2\1]', $signature);

		// Turn the text into bb code.
		if ($vbulletin->userinfo['permissions']['signaturepermissions'] & $vbulletin->bf_ugp_signaturepermissions['canbbcodelink'])
		{
			$signature = convert_url_to_bbcode($signature);
		}

		// Create the parser with the users sig permissions
		$sig_parser = new vB_SignatureParser($vbulletin, fetch_tag_list(), $vbulletin->userinfo['permissions'], $vbulletin->userinfo['userid']);

		// Parse the signature
		$previewmessage = $sig_parser->parse($signature);

		if ($error_num = count($sig_parser->errors))
		{
			foreach ($sig_parser->errors AS $tag => $error_phrase)
			{
				$errors[] = fetch_error($error_phrase, $tag);
			}
		}

		unset($sig_parser, $tag_list, $sig_tag_token_array, $results);
	}
 /**
  * Parses out specific white space before or after cetain tags and does nl2br.
  * This version of the parser doesn't use nl2br!
  *
  * @param	string	Text to process
  * @param	bool	Whether to translate newlines to <br /> tags -- ignored!
  *
  * @return	string	Processed text
  */
 function parse_whitespace_newlines($text, $do_nl2br = true)
 {
     // don't do new lines!
     return parent::parse_whitespace_newlines($text, false);
 }
Пример #4
0
 /**
  * Used by getSignatureInfo and parseSignatures to parse a signature
  *
  * @param  int          User ID
  * @param  string|false (Optional) Signature text or false if unknown
  * @param  bool         (Optional) Flag to control skipping the dupe check or not.
  *
  * @return array        Array containing the parsed signature:
  *                      <pre>
  *                      array(
  *                          signature => parsed signature
  *                          allowed => array of bbcode tags the user is allowed to use in their signature
  *                          disabled => array of bbcode tags the user is NOT allowed to use in their signature
  *                      )
  *                      </pre>
  */
 protected function doParseSignature($userid, $signature = false, $skipdupcheck = false)
 {
     if (empty($signature)) {
         $sigInfo = vB_Api::instanceInternal('user')->fetchSignature($userid);
         if (empty($sigInfo) or empty($sigInfo['raw'])) {
             $sigInfo['raw'] = '';
         }
         $signature = $sigInfo['raw'];
     }
     require_once DIR . '/includes/class_sigparser.php';
     $sig_parser = new vB_SignatureParser(vB::get_registry(), $this->fetchTagList(), $userid);
     $sig_parser->setSkipdupcheck($skipdupcheck);
     // Parse the signature
     $parsed = $sig_parser->parse($signature);
     $perms = $sig_parser->getPerms();
     //only cache the parsed signature if it came from the DB
     if (isset($sigInfo)) {
         $cacheKey = "vbSig_{$userid}";
         $cachePermKey = "vbSigPerm_{$userid}";
         $cache = vB_Cache::instance(vB_Cache::CACHE_STD);
         $cache->write($cacheKey, $parsed, 1440, "userChg_{$userid}");
         $cache->write($cachePermKey, $perms, 1440, "userChg_{$userid}");
     }
     return array('signature' => $parsed, 'allowed' => $perms['can'], 'disabled' => $perms['cant']);
 }