Exemple #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);
 }
Exemple #2
0
	if ($vbulletin->userinfo['permissions']['sigmaxrawchars'] AND vbstrlen($signature) > $vbulletin->userinfo['permissions']['sigmaxrawchars'])
	{
		$vbulletin->GPC['preview'] = true;
		$errors[] = fetch_error('sigtoolong_includingbbcode', $vbulletin->userinfo['permissions']['sigmaxrawchars']);
	}
	// Count the characters after stripping in the signature
	else if ($vbulletin->userinfo['permissions']['sigmaxchars'] AND (vbstrlen(strip_bbcode($signature, false, false, false)) > $vbulletin->userinfo['permissions']['sigmaxchars']))
	{
		$vbulletin->GPC['preview'] = true;
		$errors[] = fetch_error('sigtoolong_excludingbbcode', $vbulletin->userinfo['permissions']['sigmaxchars']);
	}

	if ($vbulletin->userinfo['permissions']['sigmaxlines'] > 0)
	{
		require_once(DIR . '/includes/class_sigparser_char.php');
		$char_counter = new vB_SignatureParser_CharCount($vbulletin, fetch_tag_list(), $vbulletin->userinfo['permissions'], $vbulletin->userinfo['userid']);
		$line_count_text = $char_counter->parse(trim($signature));

		if ($vbulletin->options['softlinebreakchars'] > 0)
		{
			// implicitly wrap after X characters without a break
			$line_count_text = preg_replace('#([^\r\n]{' . $vbulletin->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 > $vbulletin->userinfo['permissions']['sigmaxlines'])
		{
			$vbulletin->GPC['preview'] = true;
			$errors[] = fetch_error('sigtoomanylines', $vbulletin->userinfo['permissions']['sigmaxlines']);