コード例 #1
0
ファイル: text.php プロジェクト: cedwards-reisys/nexus-web
 /**
  * Gets the data the presentation layer needs to have to parse the rawtext.
  *
  * @param  mixed nodeId or array of nodeIds
  *
  * @return mixed array includes bbcodeoptions, attachments, and rawtext
  */
 public function getDataForParse($nodeIds)
 {
     if (is_int($nodeIds)) {
         $nodeIds = array($nodeIds);
     } else {
         if (!is_array($nodeIds)) {
             throw new vB_Exception_Api('invalid_data');
         }
     }
     $results = array();
     $bfMiscForumoptions = vB::getDatastore()->getValue('bf_misc_forumoptions');
     $pmType = vB_Types::instance()->getContentTypeID('vBForum_PrivateMessage');
     $galleryTypeid = vB_Types::instance()->getContentTypeId('vBForum_Gallery');
     $photoTypeid = vB_Types::instance()->getContentTypeId('vBForum_Photo');
     $userContext = vB::getUserContext();
     $channelTypes = vB::getDatastore()->getValue('vBChannelTypes');
     if (!empty($nodeIds)) {
         $nodes = $this->assertor->assertQuery('vBForum:getDataForParse', array('nodeid' => $nodeIds));
         foreach ($nodes as $node) {
             try {
                 if ($this->validate($node, self::ACTION_VIEW, $node['nodeid'], array($node))) {
                     $attachments = $this->nodeApi->getNodeAttachments($node['nodeid']);
                     // We don't need to show attachments for gallery. See VBV-6389.
                     // Or rather, we need to unset attachments that are part of a gallery, but want to show other attachments. See VBV-11058
                     if ($galleryTypeid == $node['contenttypeid']) {
                         foreach ($attachments as $key => &$attachment) {
                             // attachments have contenttype vBForum_Attach, while photos of a gallery have contenttype vBForum_Photo
                             if ($photoTypeid == $attachment['contenttypeid']) {
                                 unset($attachments[$key]);
                             }
                         }
                     }
                     if ($node['contenttypeid'] == $pmType) {
                         $bbCodeOptions = vB_Api::instance('content_privatemessage')->getBbcodeOptions();
                     } else {
                         if ($userContext->getChannelPermission('forumpermissions', 'canviewthreads', $node['nodeid'], false, $node['parentid'])) {
                             $bbCodeOptions = array();
                             foreach ($bfMiscForumoptions as $optionName => $optionVal) {
                                 $bbCodeOptions[$optionName] = (bool) ($node['options'] & $optionVal);
                             }
                         } else {
                             $bbCodeOptions = array();
                         }
                     }
                     $results[$node['nodeid']] = array('bbcodeoptions' => $bbCodeOptions, 'rawtext' => $node['rawtext'], 'previewtext' => $node['previewtext'], 'attachments' => $attachments, 'title' => $node['title'], 'channelid' => $node['channelid'], 'htmlstate' => $node['htmlstate'], 'disable_bbcode' => $node['nodeoptions'] & vB_Api_Node::OPTION_NODE_DISABLE_BBCODE);
                 } else {
                     if ($node['public_preview'] > 0) {
                         $results[$node['nodeid']] = array('bbcodeoptions' => array(), 'rawtext' => '', 'title' => $node['title'], 'channelid' => $node['channelid'], 'htmlstate' => 'off', 'preview_only' => 1, 'disable_bbcode' => $node['nodeoptions'] & vB_Api_Node::OPTION_NODE_DISABLE_BBCODE);
                         require_once DIR . '/includes/class_bbcode.php';
                         $tags = fetch_tag_list();
                         $registry = vB::get_registry();
                         $bbcode_parser = new vB_BbCodeParser($registry, $tags);
                         $previewBbcodeOptions = array('allowsmilies' => 1, 'allowbbcode', 'allowimagecode' => 1);
                         if ($node['htmlstate'] != 'off') {
                             $previewBbcodeOptions['allowhtml'] = 1;
                         }
                         if ($node['nodeid'] == $node['starter']) {
                             $channel = vB_Library::instance('node')->getNodeFullContent($node['parentid']);
                         } else {
                             $starter = $this->nodeApi->getNode($node['starter']);
                             $channel = vB_Library::instance('node')->getNodeFullContent($starter['parentid']);
                         }
                         $channel = array_pop($channel);
                         if ($channel['channeltype'] == 'article') {
                             $previewBbcodeOptions['allowPRBREAK'] = 1;
                         }
                         if (vB::getUserContext()->getChannelPermission('forumpermissions2', 'cangetimgattachment', $node['nodeid'])) {
                             $previewBbcodeOptions['allowimages'] = 1;
                         }
                         $results[$node['nodeid']]['previewtext'] = $bbcode_parser->getPreview($node['rawtext'], 0, FALSE, $node['htmlstate'] == 'on_nl2br', null, $previewBbcodeOptions);
                     } else {
                         $results[$node['nodeid']] = array('bbcodeoptions' => array(), 'rawtext' => '', 'previewtext' => '', 'title' => '', 'attachments' => array(), 'channelid' => $node['channelid'], 'htmlstate' => 'off', 'disable_bbcode' => $node['nodeoptions'] & vB_Api_Node::OPTION_NODE_DISABLE_BBCODE);
                         // not much point since there is no rawtext, but ensure that it's set.
                     }
                 }
                 //channeltype
                 if (isset($channelTypes[$node['channelid']])) {
                     $results[$node['nodeid']]['channeltype'] = $channelTypes[$node['channelid']];
                     if ($channelTypes[$node['channelid']] == 'article') {
                         $results[$node['nodeid']]['previewLength'] = vB::getDatastore()->getOption('def_cms_previewlength');
                         // VBV-12048 For articles, if preview break is present, use the length of the preview text instead of
                         // the global cms preview length
                         $prbreak = stripos($results[$node['nodeid']]['rawtext'], '[PRBREAK][/PRBREAK]');
                         if ($prbreak !== FALSE) {
                             $results[$node['nodeid']]['previewLength'] = $prbreak;
                         }
                     } else {
                         $results[$node['nodeid']]['previewLength'] = vB::getDatastore()->getOption('threadpreview');
                     }
                 } else {
                     $results[$node['nodeid']]['channeltype'] = '';
                 }
             } catch (exception $e) {
                 //probably a permission error. We can continue with whatever is valid.
             }
         }
     }
     return $results;
 }