Ejemplo n.º 1
0
 function getPreview($text, $length = 100)
 {
     return strip_tags(vB_String::unHtmlSpecialChars(substr(vB_String::stripBbcode($text, true, false, false, true, false), 0, $length)));
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 /**
  * Sets or unsets the approved field
  * @param array $nodeids
  * @param boolean $approved - set or unset the approved field
  * @throws vB_Exception_Api
  * @return array - the nodeids that have the permission to be changed
  */
 public function setApproved($approveNodeIds, $approved = true)
 {
     if (empty($approveNodeIds)) {
         return false;
     }
     $loginfo = array();
     $nodeIds = array();
     foreach ($approveNodeIds as $idx => $id) {
         $nodeInfo = $this->getNode($id);
         if ($nodeInfo['deleteuserid']) {
             // Do not do approve/unapprove actions on deleted posts
             continue;
         }
         if (!empty($nodeInfo['errors'])) {
             continue;
         }
         if (!$nodeInfo['approved'] and !$approved) {
             continue;
         }
         if ($nodeInfo['approved'] and $approved) {
             continue;
         }
         $nodeIds[] = $nodeInfo['nodeid'];
         $loginfo[] = array('nodeid' => $nodeInfo['nodeid'], 'nodetitle' => $nodeInfo['title'], 'nodeusername' => $nodeInfo['authorname'], 'nodeuserid' => $nodeInfo['userid']);
     }
     if (empty($nodeIds)) {
         return false;
     }
     $errors = array();
     $assertor = vB::getDbAssertor();
     $result = $assertor->update('vBForum:node', array('approved' => $approved), array('nodeid' => $nodeIds));
     if (!empty($result['errors'])) {
         $errors[] = $result['errors'];
     }
     $method = empty($approved) ? 'unapproveNode' : 'approveNode';
     $result = $assertor->assertQuery('vBForum:' . $method, array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'nodeid' => $nodeIds));
     // Report as ham if this node was spam..
     if ($method == 'approveNode') {
         $vboptions = vB::getDatastore()->getValue('options');
         if ($vboptions['vb_antispam_type'] and $vboptions['vb_antispam_key']) {
             $spamids = array();
             $spamcheck = $assertor->getRows('spamlog', array('nodeid' => $nodeIds));
             foreach ($spamcheck as $spam) {
                 $spamids[] = $spam['nodeid'];
             }
             if ($spamids) {
                 $nodes = $this->getContentforNodes($spamids);
                 $akismet = vB_Akismet::instance();
                 foreach ($nodes as $node) {
                     if ($node['content']['rawtext']) {
                         $text = vB_String::stripBbcode($node['content']['rawtext'], true);
                         $akismet->markAsHam(array('comment_type' => 'comment', 'comment_author' => $node['content']['authorname'], 'comment_content' => $text, 'user_ip' => $node['content']['ipaddress']));
                     }
                 }
                 $assertor->delete('spamlog', array('nodeid' => $spamids));
             }
         }
     }
     if (!empty($result['errors'])) {
         $errors[] = $result['errors'];
     }
     $nodeIds = array_unique($nodeIds);
     $searchAPI = vB_Api::instanceInternal('Search');
     foreach ($nodeIds as $nodeid) {
         $node = $this->getNode($nodeid);
         $parent = $this->getNodeBare($node['parentid']);
         if ($node['showpublished']) {
             $nodeUpdates = $this->publishChildren($node['nodeid']);
         } else {
             $nodeUpdates = $this->unpublishChildren($node['nodeid']);
         }
         //we must update the last nodes for the subtree before handling the parents, otherwise it won't work.
         $this->updateLastForSubtree($nodeid);
         $this->updateChangedNodeParentCounts($node, $nodeUpdates);
         //$assertor->assertQuery('vBForum:updateLastData', array('parentid' => $nodeid, 'timenow' => vB::getRequest()->getTimeNow()));
         // Update the user post count (approve / unapprove)
         vB_Cache::allCacheEvent('nodeChg_' . $nodeid);
         if ($approved) {
             vB_Library_Content::getContentLib($node['contenttypeid'])->incrementUserPostCount($node);
         } else {
             vB_Library_Content::getContentLib($node['contenttypeid'])->decrementUserPostCount($node, 'unapprove');
         }
         $searchAPI->attributeChanged($node['nodeid']);
     }
     $this->clearCacheEvents($nodeIds);
     $this->clearChildCache($nodeIds);
     if (!empty($errors)) {
         return array('errors' => $errors);
     }
     vB_Library_Admin::logModeratorAction($loginfo, $approved ? 'node_approved_by_x' : 'node_unapproved_by_x');
     return $nodeIds;
 }
Ejemplo n.º 4
0
 /**
  * @param $textDataArray
  * @param $nodeId
  * @param $bbcodeOptions
  * @return array
  */
 protected function parseNode($textDataArray, $nodeId, $bbcodeOptions)
 {
     $textData = $textDataArray[$nodeId];
     $skipBbCodeParsing = $textData['disable_bbcode'];
     // if disable_bbcode is set (static pages), just use the rawtext
     $parser = new vB5_Template_BbCode();
     $parser->setRenderImmediate(true);
     $parser->setMultiPageRender($textData['channeltype'] == 'article');
     if (isset($textData['attachments'])) {
         $parser->setAttachments($textData['attachments']);
     }
     if (isset($textData['attachments']) and empty($textData['attachments'])) {
         $parser->getAndSetAttachments($nodeId);
     }
     //make sure we have values for all the necessary options
     foreach (array('allowimages', 'allowimagebbcode', 'allowbbcode', 'allowsmilies') as $option) {
         if (!empty($bbcodeOptions) and isset($bbcodeOptions[$option])) {
             $textData['bbcodeoptions'][$option] = $bbcodeOptions[$option];
         } else {
             if (!isset($textData['bbcodeoptions'][$option])) {
                 $textData['bbcodeoptions'][$option] = false;
             }
         }
     }
     /*
     	bbcodeOptions['allowhtml'] comes from channel.options & 256 (bf_misc_forumoptions.allowhtml),
     	except for public_preview > 0 articles that the user can't view... (see function vB_Api_Content_Text->getDataForParse() & queryef vBForum:getDataForParse)
     	so we should actually be ignoring that, and using htmlstate only.
     	Unfortunately, we can't just ignore it in the parser's doParse() function, because there is at least 1 other thing that seems to use allowhtml: announcements. I'm placing
     	the change here instead of the parser in order to minimize risk.
     	Alternatively, we could just make sure that every single channel is created with allowhtml set, but that'd also mean we're keeping this option, and adding
     	an upgrade step to fix all old channels that may have been created with allowhtml unset.
     */
     $textData['bbcodeoptions']['allowhtml'] = in_array($textData['htmlstate'], array('on', 'on_nl2br'));
     $allowimages = false;
     if (!empty($bbcodeOptions) and !empty($bbcodeOptions['allowimages'])) {
         $allowimages = $bbcodeOptions['allowimages'];
     } else {
         if (!empty($bbcodeOptions['cangetimgattachment'])) {
             $allowimages = $bbcodeOptions['cangetimgattachment'];
         } else {
             if (!empty($textData['bbcodeoptions']['allowimages'])) {
                 $allowimages = $textData['bbcodeoptions']['allowimages'];
             } else {
                 if (!empty($textData['bbcodeoptions']['allowimagecode'])) {
                     $allowimages = $textData['bbcodeoptions']['allowimagecode'];
                 }
             }
         }
     }
     if ($textData['channeltype'] == 'article') {
         if (!$skipBbCodeParsing) {
             //If it's paginated we parse it here.
             $matches = array();
             $check = preg_match_all('#\\[page\\].*\\[\\/page\\]#siU', $textData['rawtext'], $matches, PREG_OFFSET_CAPTURE);
             $start = 0;
             $title = $textData['title'];
             $parsed = array();
             // If [page] is at the beginning of the text, use it for the first page title
             // instead of using the article title for the first one.
             $hasFirstPageTitle = (bool) preg_match('#^\\s*\\[PAGE\\]#siU', $textData['rawtext']);
             if (!empty($matches[0])) {
                 foreach ($matches[0] as $match) {
                     if ($hasFirstPageTitle) {
                         $hasFirstPageTitle = false;
                         $start = strlen($match[0]) + $match[1];
                         $title = vB_String::stripBbcode($match[0]);
                         continue;
                     }
                     $rawtext = substr($textData['rawtext'], $start, $match[1] - $start);
                     $currentText = $parser->doParse($rawtext, $textData['bbcodeoptions']['allowhtml'], $textData['bbcodeoptions']['allowsmilies'], $textData['bbcodeoptions']['allowbbcode'], $allowimages, true, false, $textData['htmlstate'], false, $textData['rawtext']);
                     $parsed[] = array('title' => $title, 'pageText' => $currentText);
                     $start = strlen($match[0]) + $match[1];
                     $title = vB_String::stripBbcode($match[0]);
                 }
                 if (!empty($start) and $start < strlen($textData['rawtext'])) {
                     $rawtext = substr($textData['rawtext'], $start);
                     $currentText = $parser->doParse($rawtext, $textData['bbcodeoptions']['allowhtml'], $textData['bbcodeoptions']['allowsmilies'], $textData['bbcodeoptions']['allowbbcode'], $allowimages, true, false, $textData['htmlstate'], false, $textData['rawtext']);
                     $parsed[] = array('title' => $title, 'pageText' => $currentText);
                 }
             }
             $paging = array();
             $pageNo = 1;
             $phrases = vB5_Template_Phrase::instance();
             foreach ($parsed as $page) {
                 if (empty($page['title'])) {
                     $page['title'] = $phrases->getPhrase('page_x', $pageNo);
                 }
                 $paging[$pageNo] = $page['title'];
                 $pageNo++;
             }
             Api_InterfaceAbstract::instance()->cacheInstance(0)->write($this->getPagingCacheKey($nodeId), $paging, 1440, 'nodeChg_' . $nodeId);
         } else {
             $parsed = $textData['rawtext'];
             $matches[0] = 1;
             // skip re-parsing below.
         }
     }
     if (empty($matches[0])) {
         // Get full text
         $parsed = $parser->doParse($textData['rawtext'], $textData['bbcodeoptions']['allowhtml'], $textData['bbcodeoptions']['allowsmilies'], $textData['bbcodeoptions']['allowbbcode'], $allowimages, true, false, $textData['htmlstate']);
     }
     // Get preview text
     if (empty($this->previewLength)) {
         if (isset($textData['previewLength'])) {
             $this->previewLength = $textData['previewLength'];
         } else {
             $options = Api_InterfaceAbstract::instance()->callApiStatic('options', 'fetchStatic', array('previewLength'));
             $this->previewLength = $options['previewLength'];
         }
     }
     // if textData has previewLength set, we always want to use it (articles)
     if (isset($textData['previewLength'])) {
         $previewLength = $textData['previewLength'];
     } else {
         $previewLength = $this->previewLength;
     }
     if ($skipBbCodeParsing) {
         // static pages from vb4 should always have text.previewtext set, taken from cms_nodeconfig.value where name = 'previewtext'
         // As such, we should always set the previewtext for static pages created in vB5.
         $previewText = $textData['previewtext'];
     } else {
         $previewText = $parser->get_preview($textData['rawtext'], $previewLength, $textData['bbcodeoptions']['allowhtml'], true, $textData['htmlstate'], array('do_smilies' => $textData['bbcodeoptions']['allowsmilies'], 'allowPRBREAK' => !empty($textData['disableBBCodes']['prbreak'])));
     }
     if (is_array($parsed)) {
         // for multi-paged articles, $parsed is an array, let's check the length
         // of the first page of that article for purposes of appending the ellipsis
         $parsedLength = strlen($parsed[0]['pageText']);
     } else {
         $parsedLength = strlen($parsed);
     }
     // Append ellipsis if preview text is shorter than parsed full text.
     // One special case to note is if previewText has 0 length. This could happen if the previewText is entirely composed of bbcodes that are stripped via parsing
     // If we want special behavior, we should check for that case here and not append the ellipsis
     if ($parsedLength > strlen($previewText)) {
         $previewText .= '...';
     }
     return array($previewText, $parsed);
 }
Ejemplo n.º 5
0
 /**
  * Publish this node to facebook feed
  *
  * @param array $node -- the $node array
  * @param boolean $explicit -- is this message explicitly shared? See
  *		https://developers.facebook.com/docs/opengraph/using-actions/v2.2#explicitsharing
  * @return bool
  */
 public function publishNode($node, $explicit)
 {
     if (!$this->userIsLoggedIn()) {
         return false;
     }
     $options = vB::getDatastore()->getValue('options');
     // is the node published/visible/public in vB?
     if ($node['showpublished'] != 1 or $node['approved'] != 1) {
         return false;
     }
     $isStarter = $node['nodeid'] == $node['starter'];
     // can new discussion, photo, link, poll etc be published?
     if ($isStarter and !$options['fbfeednewthread']) {
         return false;
     }
     // can replies to discussion, photo, link, poll etc be published?
     if (!$isStarter and !$options['fbfeedpostreply']) {
         return false;
     }
     // get node URL
     $extra = array();
     $anchor = '';
     if (!$isStarter) {
         $extra['p'] = $node['nodeid'];
         $anchor = 'post' . $node['nodeid'];
     }
     $nodeUrl = vB5_Route::buildUrl($node['routeid'] . '|fullurl', $node, $extra, $anchor);
     // $message should *really* be set by the plaintext parser, which hasn't been
     // brought over from vB4
     $message = vB_String::stripBbcode($node['content']['rawtext'], false, false, false, true);
     $previewtext = vB_String::getPreviewText($message);
     //we need a title otherwise it just doesn't look good
     $title = $node['title'];
     if (!$title and !empty($node['content']['startertitle'])) {
         $title = $node['content']['startertitle'];
     }
     $image_url = '';
     if (!empty($node['content']['previewimage'])) {
         $image_url = $node['content']['previewimage'];
         if (is_numeric($image_url)) {
             $image_url = $options['frontendurl'] . "/filedata/fetch?id={$image_url}&type=thumb";
         }
     }
     return $this->publishMessage('', $title, $nodeUrl, $previewtext, $image_url, $explicit);
 }
Ejemplo n.º 6
0
 /**
  * Builds description tag content used in RSS outputs.
  *
  * 	@param 		String 	Text to build description from.
  *	@param 		Array 	Options to consider building description.
  *
  * 	@return 	String 	Description.
  *
  */
 protected function getItemDescription($text, $options)
 {
     // @TODO VBV-11108 description should be plain text only, replace this to use plain text parser when implemented
     if (!empty($options['fulldesc'])) {
         $description = vB_String::htmlSpecialCharsUni(vB_String::fetchCensoredText(vB_String::stripBbcode($text, true, false, true, true)));
     } else {
         $description = vB_String::htmlSpecialCharsUni(vB_String::fetchCensoredText(vB_String::fetchTrimmedTitle(vB_String::stripBbcode($text, true, false, true, true), vB::getDatastore()->getOption('threadpreview'))));
     }
     return $description;
 }
Ejemplo n.º 7
0
 public function parseAndStrip($text)
 {
     if (!empty($text)) {
         // We can ignore autoparselinks setting here since the tags will be stripped anyway
         $bbOptions = array('autoparselinks' => false);
         $text = vB_Api::instanceInternal('bbcode')->convertWysiwygTextToBbcode($text, $bbOptions);
         $options = vB::getDatastore()->get_value('options');
         return trim(vB_String::stripBbcode($text, $options['ignorequotechars']));
     }
     return '';
 }