Esempio n. 1
0
 public static function instance()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
Esempio n. 2
0
 /** gets a gallery and returns in json format for slideshow presentation.
  *
  ***/
 public function actionGallery()
 {
     //We need a nodeid
     if (!empty($_REQUEST['nodeid'])) {
         $nodeid = $_REQUEST['nodeid'];
     } else {
         if (!empty($_REQUEST['id'])) {
             $nodeid = $_REQUEST['id'];
         } else {
             return '';
         }
     }
     //get the raw data.
     $api = Api_InterfaceAbstract::instance();
     $config = vB5_Config::instance();
     $phraseApi = vB5_Template_Phrase::instance();
     $gallery = array('photos' => array());
     switch (intval($nodeid)) {
         case 0:
         case -1:
             //All Videos
             throw new vB_Exception_Api('invalid_request');
         case -2:
             //All non-Album photos and attachments
             if ((empty($_REQUEST['userid']) or !intval($_REQUEST['userid'])) and (empty($_REQUEST['channelid']) or !intval($_REQUEST['channelid']))) {
                 throw new vB_Exception_Api('invalid_request');
             }
             $galleryData = $api->callApi('profile', 'getSlideshow', array(array('userid' => isset($_REQUEST['userid']) ? intval($_REQUEST['userid']) : 0, 'channelid' => isset($_REQUEST['channelid']) ? intval($_REQUEST['channelid']) : 0, 'dateFilter' => isset($_REQUEST['dateFilter']) ? $_REQUEST['dateFilter'] : '', 'searchlimit' => isset($_REQUEST['perpage']) ? $_REQUEST['perpage'] : '', 'startIndex' => isset($_REQUEST['startIndex']) ? $_REQUEST['startIndex'] : '')));
             if (empty($galleryData)) {
                 return array();
             }
             foreach ($galleryData as $photo) {
                 $titleVm = !empty($photo['parenttitle']) ? $photo['parenttitle'] : $photo['startertitle'];
                 $route = $photo['routeid'];
                 if ($photo['parenttitle'] == 'No Title' and $photo['parentsetfor'] > 0) {
                     $titleVm = $phraseApi->getPhrase('visitor_message_from_x', array($photo['authorname']));
                     $route = 'visitormessage';
                 }
                 $userLink = vB5_Template_Options::instance()->get('options.frontendurl') . $api->callApi('route', 'getUrl', array('route' => 'profile', 'data' => array('userid' => $photo['userid'], 'username' => $photo['authorname']), 'extra' => array()));
                 $topicLink = vB5_Template_Options::instance()->get('options.frontendurl') . '/' . $api->callApi('route', 'getUrl', array('route' => $route, 'data' => array('title' => $titleVm, 'nodeid' => $photo['parentnode']), 'extra' => array()));
                 $title = $photo['title'] != null ? $photo['title'] : '';
                 $htmltitle = $photo['htmltitle'] != null ? $photo['htmltitle'] : '';
                 $photoTypeid = vB_Types::instance()->getContentTypeID('vBForum_Photo');
                 $attachTypeid = vB_Types::instance()->getContentTypeID('vBForum_Attach');
                 if ($photo['contenttypeid'] === $photoTypeid) {
                     $queryVar = 'photoid';
                 } else {
                     if ($photo['contenttypeid'] === $attachTypeid) {
                         $queryVar = 'id';
                     }
                 }
                 $gallery['photos'][] = array('title' => $title, 'htmltitle' => $htmltitle, 'url' => vB5_Template_Options::instance()->get('options.frontendurl') . '/filedata/fetch?' . $queryVar . '=' . intval($photo['nodeid']), 'thumb' => vB5_Template_Options::instance()->get('options.frontendurl') . '/filedata/fetch?' . $queryVar . '=' . intval($photo['nodeid']) . "&thumb=1", 'links' => $phraseApi->getPhrase('photos_by_x_in_y_linked', array($userLink, $photo['authorname'], $topicLink, htmlspecialchars($titleVm))) . "<br />\n");
             }
             $this->sendAsJson($gallery);
             return;
         default:
             $galleryData = $api->callApi('content_gallery', 'getContent', array('nodeid' => $nodeid));
             if (!empty($galleryData) and !empty($galleryData[$nodeid]['photo'])) {
                 foreach ($galleryData[$nodeid]['photo'] as $photo) {
                     $userLink = vB5_Template_Options::instance()->get('options.frontendurl') . $api->callApi('route', 'getUrl', array('route' => 'profile', 'data' => array('userid' => $photo['userid'], 'username' => $photo['authorname']), 'extra' => array()));
                     $gallery['photos'][] = array('title' => $photo['title'], 'htmltitle' => $photo['htmltitle'], 'url' => vB5_Template_Options::instance()->get('options.frontendurl') . '/filedata/fetch?photoid=' . intval($photo['nodeid']), 'thumb' => vB5_Template_Options::instance()->get('options.frontendurl') . '/filedata/fetch?photoid=' . intval($photo['nodeid']) . "&thumb=1", 'links' => $phraseApi->getPhrase('photos_by_x_in_y_linked', array($userLink, $photo['authorname'], 'javascript:$(\'#slideshow-dialog\').dialog(\'close\');void(0);', htmlspecialchars($photo['startertitle']))) . "<br />\n");
                 }
                 $this->sendAsJson($gallery);
             }
             return;
     }
 }
 public function actionParseWysiwyg()
 {
     $options = array();
     $attachments = array();
     // if this is an existing node, we need to fetch attachments so converting from source mode to
     // wysiwyg mode displays attachments. If attachments are not passed, they won't be set in the
     // vB5_Template_BbCode_Wysiwyg instance. See vB5_Template_BbCode's setAttachments() function.
     if (isset($_POST['nodeid']) and intval($_POST['nodeid'])) {
         $attachments = Api_InterfaceAbstract::instance()->callApi('node', 'getNodeAttachments', array(intval($_POST['nodeid'])));
     }
     // eventually goes through vB5_Template_BbCode_Wysiwyg's doParse()
     $data = vB5_Frontend_Controller_Bbcode::parseWysiwyg($_POST['data'], $options, $attachments);
     /*
      *	we might have some placeholders from bbcode parser. Replace them before we send it back.
      *	I added this call because the parser was adding placeholders for the 'image_larger_version_x_y_z' phrase
      *	in the image alt texts for images that didn't get titles set, and ckeditor was having a field day with the
      *	placeholder, not to mention causing issues with wysiwyghtmlparser's parseUnmatchedTags() (the regex fails
      *	to match image tags if any attribute before src has a > character).
      *	While parseUnmatchedTags() will still have problems* if the alt text (or any attribute before src) contains
      *	a >, getting rid of the placeholder at least prevents the problem from being caused by the parser itself.
      *		* see VBV-12308
      */
     $phraseCache = vB5_Template_Phrase::instance();
     $phraseCache->replacePlaceholders($data);
     return $this->sendAsJson(array('data' => $data));
 }
Esempio n. 4
0
 public function actionKillActivation()
 {
     $data = array('u' => !empty($_GET['u']) ? intval($_GET['u']) : 0, 'i' => !empty($_GET['i']) ? trim($_GET['i']) : '');
     $api = Api_InterfaceAbstract::instance();
     $result = $api->callApi('user', 'killActivation', array('userid' => $data['u'], 'activateid' => $data['i']));
     $phraseController = vB5_Template_Phrase::instance();
     $phraseController->register('registration');
     if (!empty($result['errors']) and is_array($result['errors'])) {
         $phraseArgs = is_array($result['errors'][0]) ? $result['errors'][0] : array($result['errors'][0]);
     } else {
         $phraseArgs = is_array($result) ? $result : array($result);
     }
     $messagevar = call_user_func_array(array($phraseController, 'getPhrase'), $phraseArgs);
     vB5_ApplicationAbstract::showMsgPage($phraseController->getPhrase('registration'), $messagevar);
 }
Esempio n. 5
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);
 }
Esempio n. 6
0
 /**
  * Forgot password form action
  * Reset url = /auth/lostpw/?action=pwreset&userid=<n>&activationid=<xxxxx>
  */
 public function actionLostpw()
 {
     $input = array('email' => isset($_POST['email']) ? trim(strval($_POST['email'])) : '', 'hvinput' => isset($_POST['humanverify']) ? (array) $_POST['humanverify'] : array(), 'action' => isset($_REQUEST['action']) ? trim($_REQUEST['action']) : '', 'userid' => isset($_REQUEST['userid']) ? trim(strval($_REQUEST['userid'])) : '', 'activationid' => isset($_REQUEST['activationid']) ? trim($_REQUEST['activationid']) : '');
     if (isset($_POST['recaptcha_challenge_field']) and $_POST['recaptcha_challenge_field']) {
         $input['hvinput']['recaptcha_challenge_field'] = $_POST['recaptcha_challenge_field'];
     }
     if (isset($_POST['recaptcha_response_field']) and $_POST['recaptcha_response_field']) {
         $input['hvinput']['recaptcha_response_field'] = $_POST['recaptcha_response_field'];
     }
     $api = Api_InterfaceAbstract::instance();
     if ($input['action'] == 'pwreset') {
         $response = $api->callApi('user', 'resetPassword', array('userid' => $input['userid'], 'activationid' => $input['activationid']));
         if (isset($response['errors'])) {
             $phraseController = vB5_Template_Phrase::instance();
             $phraseController->register('error');
             //call message first so that we pull both phrases at the same time
             $message = call_user_func_array(array($phraseController, 'getPhrase'), $response['errors'][0]);
             $title = $phraseController->getPhrase('error');
         } else {
             $title = $response['password_reset'];
             $message = $response['resetpw_message'];
         }
         vB5_ApplicationAbstract::showMsgPage($title, $message);
     } else {
         $response = $api->callApi('user', 'emailPassword', array('userid' => 0, 'email' => $input['email'], 'hvinput' => $input['hvinput']));
         $this->sendAsJson(array('response' => $response));
     }
 }
Esempio n. 7
0
 protected function attachReplaceCallbackFinal($matches)
 {
     $attachmentid = false;
     // Same as before: are we looking at a legacy attachment?
     if (preg_match('#^n(\\d+)$#', $matches[2], $matches2)) {
         // if the id has 'n' as prefix, it's a nodeid
         $attachmentid = intval($matches2[1]);
     }
     if ($attachmentid) {
         // Belongs to another post so we know nothing about it ... or we are not displying images so always show a link
         return "<a href=\"" . vB5_Template_Options::instance()->get('options.frontendurl') . "/filedata/fetch?filedataid={$attachmentid}\">" . vB5_Template_Phrase::instance()->register(array('attachment')) . " </a>";
     } else {
         // We couldn't even get an attachmentid. It could've been a tempid but if so the default attachReplaceCallback() should've
         // handled it. I'm leaving this here just in case however.
         return $matches[0];
     }
 }
Esempio n. 8
0
 /**
  * Handle any delayed rendering. Currently delayed urls and node texts.
  *
  * @param	string
  * @param	boolean	true if we are rendering for a call to /ajax/render/ and we want CSS <link>s separate
  *
  * @return	string
  */
 protected function renderDelayed(&$final_rendered_orig, $isAjaxTemplateRender = false)
 {
     $javascript = vB5_Template_Javascript::instance();
     $javascript->insertJs($final_rendered_orig);
     $javascript->resetPending();
     $stylesheet = vB5_Template_Stylesheet::instance();
     $stylesheet->insertCss($final_rendered_orig, $isAjaxTemplateRender);
     $stylesheet->resetPending();
     $link = vB5_Template_Headlink::instance();
     $link->insertLinks($final_rendered_orig);
     $link->resetPending();
     $phrase = vB5_Template_Phrase::instance();
     $phrase->replacePlaceholders($final_rendered_orig);
     $phrase->resetPending();
     // we do not reset pending urls, since they may be required by nodetext
     vB5_Template_Url::instance()->replacePlaceholders($final_rendered_orig);
     $nodeText = vB5_Template_NodeText::instance();
     $nodeText->replacePlaceholders($final_rendered_orig);
     $nodeText->resetPending();
     $templateCache = vB5_Template_Cache::instance();
     $templateCache->replaceTextOnly($final_rendered_orig);
     //We should keep the debug info for truly last.
     if (vB5_Frontend_Controller_Bbcode::needDebug()) {
         $config = vB5_Config::instance();
         if (!$config->debug) {
             return $final_rendered_orig;
         }
         self::$renderedTemplateNames[] = 'debug_info';
         self::$renderedTemplates[] = array('templateName' => 'debug_info', 'isParentTemplate' => (bool) 0, 'indent' => str_repeat('|----', 2));
         $user = vB5_User::instance();
         $this->register('user', $user, true);
         extract(self::$globalRegistered, EXTR_SKIP | EXTR_REFS);
         extract($this->registered, EXTR_OVERWRITE | EXTR_REFS);
         $vboptions = vB5_Template_Options::instance()->getOptions();
         $vboptions = $vboptions['options'];
         $renderedTemplates = array('count' => count(self::$renderedTemplates), 'countUnique' => count(array_unique(self::$renderedTemplateNames)), 'templates' => self::$renderedTemplates, 'styleid' => vB5_Template_Stylevar::instance()->getPreferredStyleId());
         $cssDebugLog = vB5_Template_Stylesheet::getDebugLog();
         $jsDebugLog = vB5_Template_Javascript::instance()->getDebugLog();
         $templateCode = $templateCache->getTemplate('debug_info');
         if ($templateCache->isTemplateText()) {
             @eval($templateCode);
         } else {
             @(include $templateCode);
         }
         $phrase->replacePlaceholders($final_rendered);
         $phrase->resetPending();
         $final_rendered_orig = str_replace('<!-DebugInfo-->', $final_rendered, $final_rendered_orig);
     }
 }
Esempio n. 9
0
 public static function parseWysiwygForPreview($text, $options = array(), $attachments = array())
 {
     $api = Api_InterfaceAbstract::instance();
     $text = $api->callApi('bbcode', 'parseWysiwygHtmlToBbcode', array($text));
     $parser = new vB5_Template_BbCode();
     if (!isset($options['allowhtml'])) {
         $options['allowhtml'] = false;
     }
     if (!isset($options['allowsmilies'])) {
         $options['allowsmilies'] = true;
     }
     if (!isset($options['allowbbcode'])) {
         $options['allowbbcode'] = true;
     }
     if (!isset($options['allowimagebbcode'])) {
         $options['allowimagebbcode'] = true;
     }
     if (isset($options['userid'])) {
         $parser->setParseUserinfo($options['userid']);
     }
     $parser->setAttachments($attachments);
     $templateCache = vB5_Template_Cache::instance();
     $phraseCache = vB5_Template_Phrase::instance();
     // In BBCode parser, the templates of inner BBCode are registered first,
     // so they should be replaced after the outer BBCode templates. See VBV-4834.
     $templateCache->setRenderTemplatesInReverseOrder(true);
     // Parse the bbcode
     $result = $parser->doParse($text, $options['allowhtml'], $options['allowsmilies'], $options['allowbbcode'], $options['allowimagebbcode'], true, false, $options['htmlstate']);
     $templateCache->replacePlaceholders($result);
     $phraseCache->replacePlaceholders($result);
     $templateCache->setRenderTemplatesInReverseOrder(false);
     return $result;
 }
Esempio n. 10
0
 public static function parsePhrase($phraseName)
 {
     $phrase = vB5_Template_Phrase::instance();
     //allow the first paramter to be a phrase array	( array($phraseName, $arg1, $arg2, ...)
     //otherwise the parameter is the phraseName and the args list is the phrase array
     //this allows us to pass phrase arrays around and use them directly without unpacking them
     //in the templates (which is both difficult and inefficient in the template code)
     if (is_array($phraseName)) {
         return $phrase->register($phraseName);
     } else {
         return $phrase->register(func_get_args());
     }
 }