public function autoLinkTag(array $tag, array $rendererStates) { $text = parent::autoLinkTag($tag, $rendererStates); if ($tag['tag'] == 'verse') { $bibleId = null; $option = explode(',', $tag['option']); $xenOptions = XenForo_Application::get('options'); $verse = ''; $version = null; if (count($option) > 1) { $verse = $option[0]; $version = strtoupper($option[1]); } elseif ($option[0]) { if (preg_match('#^[A-z]+$#', $tag['option'])) { $verse = ''; $version = strtoupper($tag['option']); } else { $verse = $tag['option']; $version = strtoupper($xenOptions->th_bible_defaultBible); } } if (in_array(strtolower($version), $xenOptions->th_bible_bbCodeBibles)) { $bibleId = strtolower($version); } elseif ($verse) { return $text; } else { $bibleId = null; } /* @var $verseModel ThemeHouse_Bible_Model_Verse */ $verseModel = XenForo_Model::create('ThemeHouse_Bible_Model_Verse'); if (!$verse) { $verse = XenForo_Helper_String::bbCodeStrip($text); } $verseText = $verseModel->getVerseFromText($verse, $bibleId); if ($verseText) { $verseTextStripped = XenForo_Helper_String::bbCodeStrip(str_ireplace('versenum', 'quote', $verseText), true); $textStripped = XenForo_Helper_String::bbCodeStrip(str_ireplace('versenum', 'quote', $text), true); $verseTextStripped = strtolower(preg_replace('!\\s+!', ' ', $verseTextStripped)); // remove square brackets (i.e., extra comments) $textStripped = preg_replace('/\\[[^\\]]*\\]/', '', $textStripped); // remove double spaces, line breaks, etc. $textStripped = strtolower(preg_replace('!\\s+!', ' ', $textStripped)); // split at elipsis $textStrippedSplit = preg_split("#(?:…)|(?:\\.\\.\\.)#", $textStripped); foreach ($textStrippedSplit as $_textStripped) { if (!trim($_textStripped)) { continue; } $strPos = strpos($verseTextStripped, $_textStripped); if ($strPos === false) { return '[VERSE=' . $verse . ',' . strtoupper($bibleId) . ']' . $verseText . '[/VERSE]'; } else { $verseTextStripped = substr($verseTextStripped, $strPos + strlen($_textStripped)); } } } } return $text; }
/** * Help render the HTML output. * * @return mixed */ public function renderHtml() { foreach ($this->_params['socialForums'] as &$forum) { $forum['urls'] = ThemeHouse_SocialGroups_Template_Helper_SocialForum::getAvatarUrls($forum); $forum['description'] = XenForo_Helper_String::bbCodeStrip($forum['description'], true); } unset($forum); $this->_params['renderedSocialForums'] = ThemeHouse_SocialGroups_ViewPublic_Helper::renderSocialForumsListFromDisplayArray($this, $this->_params['socialForums']); }
/** * Help render the HTML output. * * @return mixed */ public function renderHtml() { foreach ($this->_params['socialForums'] as &$forum) { $forum['urls'] = ThemeHouse_SocialGroups_Template_Helper_SocialForum::getAvatarUrls($forum); $forum['description'] = XenForo_Helper_String::bbCodeStrip($forum['description'], true); } foreach ($this->_params['stickySocialForums'] as &$forum) { $forum['urls'] = ThemeHouse_SocialGroups_Template_Helper_SocialForum::getAvatarUrls($forum); $forum['description'] = XenForo_Helper_String::bbCodeStrip($forum['description'], true); } unset($forum); $xenOptions = XenForo_Application::get('options'); if (!$xenOptions->th_socialGroups_showChildNodesInCategory) { $this->_params['renderedNodes'] = XenForo_ViewPublic_Helper_Node::renderNodeTreeFromDisplayArray($this, $this->_params['nodeList'], 2); } $this->_params['renderedSocialForums'] = ThemeHouse_SocialGroups_ViewPublic_Helper::renderSocialForumsListFromDisplayArray($this, array_merge($this->_params['stickySocialForums'], $this->_params['socialForums'])); }
public function actionGetConversations() { $visitor = XenForo_Visitor::getInstance(); $conversation_model = $this->_getConversationModel(); $page = max($this->_input->filterSingle('page', XenForo_Input::UINT), 1); $perpage = $this->_input->filterSingle('perpage', XenForo_Input::UINT); if (!$perpage) { $perpage = XenForo_Application::get('options')->discussionsPerPage; } $previewtype = $this->_input->filterSingle('previewtype', XenForo_Input::UINT); if (!$previewtype) { $previewtype = 2; } $total = $conversation_model->countConversationsForUser($visitor['user_id']); $conversations = $conversation_model->getConversationsForUser($visitor['user_id'], array(), array('page' => $page, 'perPage' => $perpage)); $conversation_data = array(); $user_model = $this->getModelFromCache('XenForo_Model_User'); $preview_length = XenForo_Application::get('options')->discussionPreviewLength; foreach ($conversations as $conv) { $out = array('conversation_id' => $conv['conversation_id'], 'new_posts' => $conv['is_unread'], 'total_messages' => $conv['reply_count'] + 1, 'title' => prepare_utf8_string(strip_tags($conv['title'])), 'lastmessagetime' => prepare_utf8_string(XenForo_Locale::dateTime($conv['last_message_date'], 'absolute'))); if ($previewtype == 1) { $out += array('username' => prepare_utf8_string(strip_tags($conv['username'])), 'userid' => $conv['user_id']); } else { $out += array('username' => prepare_utf8_string(strip_tags($conv['last_message_username'])), 'userid' => $conv['last_message_user_id']); } $message = $conversation_model->getConversationMessageById($conv[$previewtype == 1 ? 'first_message_id' : 'last_message_id']); $avatarurl = process_avatarurl(XenForo_Template_Helper_Core::getAvatarUrl($message, 'm')); if (strpos($avatarurl, '/xenforo/avatars/avatar_') !== false) { $avatarurl = ''; } if ($avatarurl != '') { $out['avatarurl'] = $avatarurl; } $preview = ''; if ($preview_length) { $preview = preview_chop(XenForo_Helper_String::bbCodeStrip(XenForo_Helper_String::censorString($message['message']), true), $preview_length); } if ($preview != '') { $out['preview'] = prepare_utf8_string(html_entity_decode($preview)); } $conversation_data[] = $out; } return array('conversations' => $conversation_data, 'total_conversations' => $total, 'canstart' => $conversation_model->canStartConversations()); }
public function buildRSSbyMedia($document, $media, $local = false) { $itm_node = $document->createElement('item'); $itm_node->appendChild($document->createElement('pubDate', date("r", $media['media_date']))); $itm_node->appendChild($document->createElement('title', substr(htmlspecialchars($media['media_title']), 0, 100))); $itm_node->appendChild($document->createElement('description', substr(htmlspecialchars(XenForo_Helper_String::bbCodeStrip(str_replace("\n", " ", $media['media_description']))), 0, 2048))); $itm_node->appendChild($document->createElement('link', XenForo_Link::buildPublicLink('full:media', $media))); $itm_node->appendChild($document->createElement('guid', XenForo_Link::buildPublicLink('full:media', $media))); $itm_node->appendChild($document->createElement('comments', XenForo_Link::buildPublicLink('full:media/comments', $media))); $itm_node->appendChild($cat_node = $document->createElement('category', htmlspecialchars('+' . $media['category_name']))); $cat_node->appendChild($dom_node = $document->createAttribute('domain')); $dom_node->appendChild($document->createTextNode(XenForo_Link::buildPublicLink('full:media/category', $media))); $itm_node->appendChild($usr_node = $document->createElement('category', htmlspecialchars('+' . $media['username']))); $usr_node->appendChild($dom_node = $document->createAttribute('domain')); $dom_node->appendChild($document->createTextNode(XenForo_Link::buildPublicLink('full:media/user', $media))); if (trim($media['media_keywords'])) { foreach (explode(',', $media['media_keywords']) as $tag) { $itm_node->appendChild($tag_node = $document->createElement('category', htmlspecialchars(trim($tag)))); $tag_node->appendChild($dom_node = $document->createAttribute('domain')); $dom_node->appendChild($document->createTextNode(XenForo_Link::buildPublicLink('full:media/keyword', array('keyword_text' => trim($tag))))); } } if ($local && $media['service_feed'] == 'null') { $itm_node->appendChild($thu_node = $document->createElement('enclosure')); $thu_node->appendChild($url_node = $document->createAttribute('url')); $url_node->appendChild($document->createTextNode($media['content_loc'])); $thu_node->appendChild($len_node = $document->createAttribute('length')); $len_node->appendChild($document->createTextNode(intval(@filesize(XenForo_Helper_File::getExternalDataPath() . '/local/' . $media['service_value'])))); } else { $itm_node->appendChild($thu_node = $document->createElement('enclosure')); $thu_node->appendChild($url_node = $document->createAttribute('url')); $url_node->appendChild($document->createTextNode(XenForo_Application::get('options')->boardUrl . '/data/media/' . $media['media_id'] . '.jpg')); $thu_node->appendChild($len_node = $document->createAttribute('length')); $len_node->appendChild($document->createTextNode(intval(@filesize(XenForo_Helper_File::getExternalDataPath() . '/media/' . $media['thumbnail'])))); $thu_node->appendChild($typ_node = $document->createAttribute('type')); $typ_node->appendChild($document->createTextNode('image/jpeg')); } $itm_node->appendChild($document->createElement('dc:creator', htmlspecialchars($media['username']))); return $itm_node; }
public function actionGetPost() { // Whole function is an ugly hack. Revisit later. global $dependencies, $zresponse; $postid = $this->_input->filterSingle('postid', XenForo_Input::UINT); $type = $this->_input->filterSingle('type', XenForo_Input::STRING); $signature = $this->_input->filterSingle('signature', XenForo_Input::UINT); if (!$type || $type == '') { $type = 'html'; } $user_model = $this->getModelFromCache('XenForo_Model_User'); $session_model = $this->getModelFromCache('XenForo_Model_Session'); $thread_model = $this->getModelFromCache('XenForo_Model_Thread'); $forum_model = $this->getModelFromCache('XenForo_Model_Forum'); $attachment_model = $this->getModelFromCache('XenForo_Model_Attachment'); $helper = $this->getHelper('ForumThreadPost'); try { list($post, $thread, $forum) = $helper->assertPostValidAndViewable($postid); } catch (Exception $e) { json_error($e->getControllerResponse()->errorText->render()); } $post_model = $this->_getPostModel(); $post = $post_model->getPostById($postid, array('join' => XenForo_Model_Post::FETCH_THREAD | XenForo_Model_Post::FETCH_FORUM | XenForo_Model_Post::FETCH_USER | XenForo_Model_Post::FETCH_USER_PROFILE)); $user = $user_model->getUserById($post['user_id']); $online_info = $session_model->getSessionActivityRecords(array('user_id' => $post['user_id'], 'cutOff' => array('>', $session_model->getOnlineStatusTimeout()))); $is_online = false; if (count($online_info) == 1) { $is_online = true; } $avatarurl = ''; if ($user !== false) { $avatarurl = process_avatarurl(XenForo_Template_Helper_Core::getAvatarUrl($user, 'm')); if (strpos($avatarurl, '/xenforo/avatars/avatar_') !== false) { $avatarurl = ''; } } $attachments = $attachment_model->getAttachmentsByContentId('post', $postid); $message = fr_strip_smilies($this, $post['message']); list($text, $nuked_quotes, $images) = parse_post($message, true, array()); $image = ''; if ($type == 'html') { $css = <<<EOF <style type="text/css"> body { margin: 0; padding: 3; font: 13px Arial, Helvetica, sans-serif; } .alt2 { background-color: #e6edf5; font: 13px Arial, Helvetica, sans-serif; } html { -webkit-text-size-adjust: none; } </style> EOF; $formatter = XenForo_BbCode_Formatter_Base::create('ForumRunner_BbCode_Formatter_BbCode_Post', array('smilies' => XenForo_Application::get('smilies'))); $parser = new XenForo_BbCode_Parser($formatter); $html = $css . $parser->render($message); if ($signature && $post['signature']) { $html .= '<div style="border-top: 1px dashed grey; font-size: 9pt; margin-top: 5px; padding: 5px 0 0;">' . $parser->render(fr_strip_smilies($this, $post['signature'])) . '</div>'; } } else { if ($type == 'facebook') { $html = XenForo_Helper_String::censorString(XenForo_Helper_String::bbCodeStrip($message, true)); if (count($attachments)) { $attachments = array_values($attachments); $link = XenForo_Link::buildPublicLink('attachments', $attachments[0]); $image = fr_get_xenforo_bburl() . '/' . $link; } } } $post_page = floor($post['position'] / XenForo_Application::get('options')->messagesPerPage) + 1; $out = array('post_id' => $post['post_id'], 'thread_id' => $post['thread_id'], 'forum_id' => $post['node_id'], 'forum_title' => prepare_utf8_string(strip_tags($post['node_title'])), 'username' => prepare_utf8_string(strip_tags($post['username'])), 'joindate' => prepare_utf8_string(XenForo_Locale::date($post['register_date'], 'absolute')), 'usertitle' => XenForo_Template_Helper_Core::helperUserTitle($user), 'numposts' => $user ? $user['message_count'] : 0, 'userid' => $post['user_id'], 'title' => prepare_utf8_string($post['title']), 'online' => $is_online, 'post_timestamp' => prepare_utf8_string(XenForo_Locale::dateTime($post['post_date'], 'absolute')), 'html' => prepare_utf8_string($html), 'quotable' => $nuked_quotes, 'canpost' => $thread_model->canReplyToThread($thread, $forum), 'canattach' => $forum_model->canUploadAndManageAttachment($forum), 'post_link' => fr_get_xenforo_bburl() . '/' . XenForo_Link::buildPublicLink('threads', $thread, array('page' => $post_page)) . '#post-' . $post['post_id']); if ($image != '') { $out['image'] = $image; } if ($avatarurl != '') { $out['avatarurl'] = $avatarurl; } return $out; }
/** * Strips BB Code from a string and word-trims it to a given max length around an optional search term * * @param string $string Input text (bb code) * @param integer $maxLength * @param array $options Key-value options * * @return string HTML */ public static function helperSnippet($string, $maxLength = 0, array $options = array()) { $options = array_merge(array('term' => '', 'emClass' => '', 'stripQuote' => false), $options); $string = XenForo_Helper_String::bbCodeStrip($string, $options['stripQuote']); if ($maxLength) { $string = XenForo_Helper_String::wholeWordTrimAroundSearchTerm($string, $maxLength, $options['term']); } $string = trim($string); $string = XenForo_Helper_String::censorString($string); if ($options['term'] && $options['emClass']) { return XenForo_Helper_String::highlightSearchTerm($string, $options['term'], $options['emClass']); } else { return htmlspecialchars($string); } }
public function actionFindNew() { $do = $this->_input->filterSingle('do', XenForo_Input::STRING); $days = $this->_input->filterSingle('days', XenForo_Input::UINT); $page = max($this->_input->filterSingle('page', XenForo_Input::UINT), 1); $perpage = $this->_input->filterSingle('perpage', XenForo_Input::UINT); if (!$perpage) { $perpage = XenForo_Application::get('options')->discussionsPerPage; } $previewtype = $this->_input->filterSingle('previewtype', XenForo_Input::UINT); if (!$previewtype) { $previewtype = 2; } $thread_model = $this->_getThreadModel(); $search_model = $this->_getSearchModel(); $post_model = $this->getModelFromCache('XenForo_Model_Post'); $user_model = $this->getModelFromCache('XenForo_Model_User'); $node_model = $this->getModelFromCache('XenForo_Model_Node'); $userid = XenForo_Visitor::getUserId(); $options = array('limit' => XenForo_Application::get('options')->maximumSearchResults); if ($do == 'getdaily') { if ($days < 0 || $days > 30) { $days = 3; } $search_options = $options + array('order' => 'last_post_date', 'orderDirection' => 'desc'); $threadids = array_keys($thread_model->getThreads(array('last_post_date' => array('>', XenForo_Application::$time - 86400 * $days), 'deleted' => false, 'moderated' => false), $search_options)); $search_type = 'recent-threads'; } else { $threadids = $thread_model->getUnreadThreadIds($userid, $options); $search_type = 'new-threads'; } $exclude = XenForo_Application::get('options')->forumrunnerExcludeForums; if (!$exclude) { $exclude = array(); } $forums = $node_model->getViewableNodeList(null, true); foreach ($exclude as $remove) { fr_remove_node_and_children($forums, $remove); } $forums = array_keys($forums); $results = array(); foreach ($threadids as $threadid) { $thread = $thread_model->getThreadById($threadid); if (!in_array($thread['node_id'], $forums)) { continue; } $results[] = array(XenForo_Model_Search::CONTENT_TYPE => 'thread', XenForo_Model_Search::CONTENT_ID => $threadid); } $results = $search_model->getViewableSearchResults($results); if (!$results) { return $this->noResults(); } $search = $search_model->insertSearch($results, $search_type, '', array(), 'date', false); $search_id = $search['search_id']; $resultids = $search_model->sliceSearchResultsToPage($search, $page, $perpage); $results = $search_model->getSearchResultsForDisplay($resultids); if (!$results) { return $this->noResults(); } $thread_data = array(); $preview_length = XenForo_Application::get('options')->discussionPreviewLength; foreach ($results['results'] as $result) { $thread = $result['content']; $post = $post_model->getPostById($thread[$previewtype == 1 ? 'first_post_id' : 'last_post_id'], array('join' => XenForo_Model_Post::FETCH_USER)); $preview = ''; if ($preview_length) { $preview = preview_chop(XenForo_Helper_String::bbCodeStrip(XenForo_Helper_String::censorString($post['message']), true), $preview_length); } $out = array('thread_id' => $thread['thread_id'], 'new_posts' => $thread['isNew'], 'forum_id' => $thread['node_id'], 'total_posts' => $thread['reply_count'] + 1, 'forum_title' => prepare_utf8_string(strip_tags($thread['node_title'])), 'thread_title' => prepare_utf8_string(XenForo_Helper_String::censorString($thread['title'])), 'post_lastposttime' => prepare_utf8_string(XenForo_Locale::dateTime($thread['last_post_date'], 'absolute'))); if ($previewtype == 1) { $out['post_username'] = prepare_utf8_string(strip_tags($thread['username'])); $out['post_userid'] = $thread['user_id']; } else { $out['post_username'] = prepare_utf8_string(strip_tags($thread['last_post_username'])); $out['post_userid'] = $thread['last_post_user_id']; } $user = $user_model->getUserById($out['post_userid']); if ($user !== false) { $avatarurl = process_avatarurl(XenForo_Template_Helper_Core::getAvatarUrl($user, 'm')); if (strpos($avatarurl, '/xenforo/avatars/avatar_') !== false) { $avatarurl = ''; } if ($avatarurl != '') { $out['avatarurl'] = $avatarurl; } } if ($preview != '') { $out['thread_preview'] = prepare_utf8_string(html_entity_decode($preview)); } if ($thread['discussion_type'] == 'poll') { $out['poll'] = true; } if ($thread['prefix_id']) { $phrase = new XenForo_Phrase('thread_prefix_' . $thread['prefix_id']); $out['prefix'] = prepare_utf8_string(strip_tags($phrase->render(false))); } $thread_data[] = $out; } $out = array('threads' => $thread_data, 'total_threads' => $search['result_count'], 'searchid' => $search_id); return $out; }
protected function _importMedia(array $item, array $options) { $model = $this->_getMediaGalleryImportersModel(); $categoryId = $model->mapCategoryId($item['category_id']); $mediaUrl = str_replace('{serviceVAL}', $item['service_value'], $item['service_url']); if (strstr($item['service_url'], 'metacafe')) { //The default XenForo BB Code Media Site appears to be bugged // Ref: http://xenforo.com/community/threads/66019/ $mediaUrl .= '/'; } $mediaTag = XenForo_Helper_Media::convertMediaLinkToEmbedHtml($mediaUrl); if (!$mediaTag) { return false; } $xengalleryMedia = array('media_title' => $this->_convertToUtf8($item['media_title'], true), 'media_description' => XenForo_Helper_String::bbCodeStrip($item['media_description'], true), 'media_date' => $item['media_date'], 'last_edit_date' => XenForo_Application::$time, 'last_comment_date' => $item['last_comment_date'], 'media_type' => 'video_embed', 'media_tag' => $mediaTag, 'media_embed_url' => $mediaUrl, 'media_state' => $item['media_state'], 'album_id' => 0, 'category_id' => $categoryId, 'media_privacy' => 'category', 'attachment_id' => 0, 'user_id' => $item['user_id'], 'username' => $item['username'], 'ip_id' => $model->getLatestIpIdFromUserId($item['user_id']), 'likes' => $item['media_likes'], 'like_users' => unserialize($item['media_like_users']), 'comment_count' => $item['media_comments'], 'rating_count' => 0, 'media_view_count' => $item['media_views']); $importedMediaId = $model->importMedia($item['media_id'], '', 'media', $xengalleryMedia); return $importedMediaId; }
protected function _importAlbum(array $album, array $options) { $model = $this->_getMediaGalleryImportersModel(); $sDb = $this->_sourceDb; $user = $sDb->fetchRow(' SELECT user_id, username FROM xf_user WHERE user_id = ? ', $album['user_id']); if (!$user) { return false; } $shareUsers = array(); $albumPrivacy = $album['album_type'] == 'global' ? 'public' : $album['album_type']; if ($albumPrivacy == 'followed' || $albumPrivacy == 'selected') { $userIds = array(); if ($albumPrivacy == 'selected' && !empty($album['selected_users']) && is_array($album['selected_users'])) { $albumPrivacy = 'shared'; $userIds = explode(',', $album['selected_users']); } /** @var $userModel XenForo_Model_User */ $userModel = XenForo_Model::create('XenForo_Model_User'); if ($albumPrivacy == 'followed') { $followedUsers = $userModel->getFollowedUserProfiles($album['user_id'], 0, 'user.user_id'); $userIds = array_keys($followedUsers); } $shareUsers = $userModel->getUsersByIds($userIds); } $xengalleryAlbum = array('album_title' => $album['title'], 'album_description' => XenForo_Helper_String::bbCodeStrip($album['description'], true), 'album_create_date' => $album['createdate'], 'last_update_date' => $album['last_image_date'], 'media_cache' => array(), 'album_state' => $album['moderation'] ? 'moderated' : 'visible', 'album_user_id' => $album['user_id'], 'album_username' => $model->getUsernameByUserId($album['user_id']), 'ip_id' => $model->getLatestIpIdFromUserId($album['user_id']), 'album_likes' => $album['likes'], 'album_like_users' => unserialize($album['like_users']), 'album_media_count' => $album['image_count'], 'album_view_count' => $album['view_count']); $importedAlbumId = $model->importAlbum($album['album_id'], $xengalleryAlbum, $albumPrivacy, 'xfr_useralbum', $shareUsers); return $importedAlbumId; }
/** * Strips BB Code from a string and word-trims it to a given max length around an optional search term * * @param string $string Input text (bb code) * @param integer $maxLength * @param array $options Key-value options * * @return string HTML */ public static function helperSnippet($string, $maxLength = 0, array $options = array()) { $options = array_merge(array('term' => '', 'fromStart' => 0, 'emClass' => '', 'stripQuote' => false, 'stripHtml' => false, 'stripPlainTag' => false), $options); if ($options['stripHtml']) { $string = strip_tags($string); } else { if ($options['stripPlainTag']) { $string = preg_replace('#(?<=^|\\s|[\\](,]|--|@)@\\[(\\d+):(\'|"|"|)(.*)\\2\\]#iU', '\\3', $string); } else { $string = XenForo_Helper_String::bbCodeStrip($string, $options['stripQuote']); } } if ($maxLength) { if ($options['fromStart']) { $string = XenForo_Helper_String::wholeWordTrim($string, $maxLength); } else { $string = XenForo_Helper_String::wholeWordTrimAroundSearchTerm($string, $maxLength, $options['term']); } } $string = trim($string); $string = XenForo_Helper_String::censorString($string); if ($options['term'] && $options['emClass']) { return XenForo_Helper_String::highlightSearchTerm($string, $options['term'], $options['emClass']); } else { return htmlspecialchars($string); } }
public static function stripBbCodes($string, $stripHtmlTags = false, $regexMethod = true) { if ($stripHtmlTags) { $string = strip_tags($string); } if ($regexMethod) { //Seems to use less memory return XenForo_Helper_String::bbCodeStrip($string, true); } $formatter = XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_Strip', false); $formatter->stripAllBbCode(true, 0); $parser = XenForo_BbCode_Parser::create($formatter); return $parser->render($string); }
private function processSearch(&$search) { $vals = $this->_input->filter(array('page' => XenForo_Input::UINT, 'perpage' => XenForo_Input::UINT, 'previewtype' => XenForo_Input::UINT, 'starteronly' => XenForo_Input::UINT)); $vals['page'] = max($vals['page'], 1); $vals['perpage'] = min(XenForo_Application::get('options')->discussionsPerPage, $vals['perpage']); if (!$vals['perpage']) { $vals['perpage'] = XenForo_Application::get('options')->discussionsPerPage; } if (!$vals['previewtype']) { $vals['previewtype'] = 2; } if ($vals['starteronly']) { $vals['previewtype'] = 1; } $search_model = $this->_getSearchModel(); $search_id = $search['search_id']; $resultids = $search_model->sliceSearchResultsToPage($search, $vals['page'], $vals['perpage']); $results = $search_model->getSearchResultsForDisplay($resultids); if (!$results) { return $this->sendError(new XenForo_Phrase('no_results_found')); } $post_model = $this->getModelFromCache('XenForo_Model_Post'); $user_model = $this->getModelFromCache('XenForo_Model_User'); $thread_data = array(); $preview_length = XenForo_Application::get('options')->discussionPreviewLength; foreach ($results['results'] as $result) { $thread = $result['content']; $is_post = $result['content_type'] == 'post'; if ($is_post) { $post = $post_model->getPostById($thread['post_id'], array('join' => XenForo_Model_Post::FETCH_USER)); } else { $post = $post_model->getPostById($thread[$vals['previewtype'] == 1 ? 'first_post_id' : 'last_post_id'], array('join' => XenForo_Model_Post::FETCH_USER)); } $preview = ''; if ($preview_length) { $preview = preview_chop(XenForo_Helper_String::bbCodeStrip(XenForo_Helper_String::censorString($thread['message']), true), $preview_length); } $out = array('thread_id' => $thread['thread_id'], 'new_posts' => $thread['isNew'], 'forum_id' => $thread['node_id'], 'total_posts' => $thread['reply_count'] + 1, 'forum_title' => prepare_utf8_string(strip_tags($thread['node_title'])), 'thread_title' => prepare_utf8_string(XenForo_Helper_String::censorString($thread['title']))); if ($is_post) { $out += array('post_id' => $thread['post_id'], 'jump_to_post' => 1, 'post_username' => prepare_utf8_string(strip_tags($thread['username'])), 'post_userid' => $thread['user_id'], 'post_lastposttime' => prepare_utf8_string(XenForo_Locale::dateTime($thread['post_date'], 'absolute'))); } else { if ($vals['previewtype'] == 1) { $out += array('post_username' => prepare_utf8_string(strip_tags($thread['username'])), 'post_userid' => $thread['user_id']); } else { $out += array('post_username' => prepare_utf8_string(strip_tags($thread['last_post_username'])), 'post_userid' => $thread['last_post_user_id']); } $out['post_lastposttime'] = prepare_utf8_string(XenForo_Locale::dateTime($thread['last_post_date'], 'absolute')); } $user = $user_model->getUserById($out['post_userid']); if ($user !== false) { $avatarurl = process_avatarurl(XenForo_Template_Helper_Core::getAvatarUrl($user, 'm')); if (strpos($avatarurl, '/xenforo/avatars/avatar_') !== false) { $avatarurl = ''; } if ($avatarurl != '') { $out['avatarurl'] = $avatarurl; } } if ($preview != '') { $out['thread_preview'] = prepare_utf8_string(html_entity_decode($preview)); } if ($thread['discussion_type'] == 'poll') { $out['poll'] = true; } if ($thread['prefix_id']) { $phrase = new XenForo_Phrase('thread_prefix_' . $thread['prefix_id']); $out['prefix'] = prepare_utf8_string(strip_tags($phrase->render(false))); } $thread_data[] = $out; } $out = array('threads' => $thread_data, 'total_threads' => $search['result_count'], 'searchid' => $search_id); return $out; }
private function processThreads(&$threads, $previewtype) { $thread_data = array(); $thread_model = $this->_getThreadModel(); $post_model = $this->getModelFromCache('XenForo_Model_Post'); $preview_length = XenForo_Application::get('options')->discussionPreviewLength; foreach ($threads as &$thread) { // For each thread, get the first post/last post information as requested by user if ($thread_model->isRedirect($thread)) { // Redirect thread XXX RKJ continue; } $out = array('thread_id' => $thread['thread_id'], 'new_posts' => $thread['isNew'], 'forum_id' => $thread['node_id'], 'total_posts' => $thread['reply_count'] + 1, 'thread_title' => prepare_utf8_string(strip_tags($thread['title'])), 'post_lastposttime' => prepare_utf8_string(XenForo_Locale::dateTime($thread['last_post_date']))); if ($previewtype == 1) { $out += array('post_username' => prepare_utf8_string(strip_tags($thread['username'])), 'post_userid' => $thread['user_id']); } else { $out += array('post_username' => prepare_utf8_string(strip_tags($thread['last_post_username'])), 'post_userid' => $thread['last_post_user_id']); } $post = $post_model->getPostById($thread[$previewtype == 1 ? 'first_post_id' : 'last_post_id'], array('join' => XenForo_Model_Post::FETCH_USER)); $avatarurl = process_avatarurl(XenForo_Template_Helper_Core::getAvatarUrl($post, 'm')); if (strpos($avatarurl, '/xenforo/avatars/avatar_') !== false) { $avatarurl = ''; } if ($avatarurl != '') { $out['avatarurl'] = $avatarurl; } $preview = ''; if ($preview_length) { $preview = preview_chop(XenForo_Helper_String::bbCodeStrip($post['message'], true), $preview_length); } if ($preview != '') { $out['thread_preview'] = prepare_utf8_string(html_entity_decode($preview)); } if ($thread['discussion_type'] == 'poll') { $out['poll'] = true; } if ($thread['prefix_id'] && isset($this->_prefixes[$thread['prefix_id']])) { $out['prefix'] = prepare_utf8_string(strip_tags($this->_prefixes[$thread['prefix_id']])); } $thread_data[] = $out; } return $thread_data; }
public function addVideo(&$document, &$sub_node, $media) { $sub_node->appendChild($url_node = $document->createElement('url')); $url_node->appendChild($document->createElement('loc', XenForo_Link::buildPublicLink('canonical:media/media', $media))); $url_node->appendChild($vid_node = $document->createElement('video:video')); $vid_node->appendChild($document->createElement('video:thumbnail_loc', XenForo_Application::get('options')->boardUrl . '/data/media/' . $media['media_id'] . '.jpg')); $vid_node->appendChild($document->createElement('video:title', htmlspecialchars(substr($media['media_title'], 0, 90)))); $vid_node->appendChild($document->createElement('video:description', htmlspecialchars(substr(XenForo_Helper_String::bbCodeStrip($media['media_description']), 0, 2000)))); $vid_node->appendChild($document->createElement('video:duration', $media['media_duration'])); $vid_node->appendChild($document->createElement('video:view_count', $media['media_views'])); $vid_node->appendChild($document->createElement('video:publication_date', date('c', $media['media_date']))); foreach (explode(',', $media['media_keywords']) as $tag) { $vid_node->appendChild($tag_node = $document->createElement('video:tag', htmlspecialchars(trim($tag)))); $tag_node->appendChild($inf_node = $document->createAttribute('info')); $inf_node->appendChild($document->createTextNode(XenForo_Link::buildPublicLink('canonical:media/keyword', array('keyword_text' => trim($tag))))); } $vid_node->appendChild($cat_node = $document->createElement('video:category', htmlspecialchars($media['category_name']))); $cat_node->appendChild($inf_node = $document->createAttribute('info')); $inf_node->appendChild($document->createTextNode(XenForo_Link::buildPublicLink('canonical:media/category', $media))); $vid_node->appendChild($upl_node = $document->createElement('video:uploader', $media['username'])); $upl_node->appendChild($inf_node = $document->createAttribute('info')); $inf_node->appendChild($document->createTextNode(XenForo_Link::buildPublicLink('canonical:members', $media))); return true; }
public function actionContentLoader() { $mediaModel = $this->_getMediaModel(); $albumModel = $this->_getAlbumModel(); $categoryModel = $this->_getCategoryModel(); $commentsModel = $this->_getCommentModel(); $items = $this->_input->filterSingle('items', XenForo_Input::ARRAY_SIMPLE); $albumIds = array(); $albums = array(); $mediaIds = array(); $mediaArray = array(); foreach ($items as $item) { if ($item['type'] == 'album') { $albumIds[] = intval($item['id']); } if ($item['type'] == 'media') { $mediaIds[] = intval($item['id']); } } $visitor = XenForo_Visitor::getInstance(); if ($albumIds) { $albumConditions = array('privacyUserId' => $visitor->user_id, 'album_id' => $albumIds); $albumFetchOptions = array('join' => XenGallery_Model_Album::FETCH_PRIVACY | XenGallery_Model_Album::FETCH_USER); $albums = $albumModel->getAlbums($albumConditions, $albumFetchOptions); $albums = $albumModel->prepareAlbums($albums); } if ($mediaIds) { $mediaConditions = array('media_id' => $mediaIds, 'deleted' => XenForo_Permission::hasPermission($visitor->permissions, 'xengallery', 'viewDeleted'), 'privacyUserId' => $visitor->user_id, 'viewAlbums' => XenForo_Permission::hasPermission($visitor->permissions, 'xengallery', 'viewAlbums'), 'viewCategoryIds' => $mediaModel->getViewableCategoriesForVisitor($visitor->toArray())); $mediaFetchOptions = array('join' => XenGallery_Model_Media::FETCH_USER | XenGallery_Model_Media::FETCH_ALBUM | XenGallery_Model_Media::FETCH_CATEGORY | XenGallery_Model_Media::FETCH_PRIVACY | XenGallery_Model_Media::FETCH_ATTACHMENT); $media = $mediaModel->getMedia($mediaConditions, $mediaFetchOptions); $media = $mediaModel->prepareMediaItems($media); foreach ($media as $mediaId => $item) { $canViewMedia = $mediaModel->canViewMediaItem($item); $canViewAlbum = true; if ($item['album_id'] > 0) { $item = $albumModel->prepareAlbumWithPermissions($item); $canViewAlbum = $albumModel->canViewAlbum($item); } $canViewCategory = true; if ($item['category_id'] > 0) { $canViewCategory = $categoryModel->canViewCategory($item); } if (!$canViewMedia || !$canViewAlbum || !$canViewCategory) { unset($media[$mediaId]); } } $commentConditions = array('media_id' => $mediaIds, 'comment_state' => 'visible'); $commentFetchOptions = array('limit' => 10, 'order' => 'comment_date', 'join' => XenGallery_Model_Comment::FETCH_USER); $comments = $commentsModel->getComments($commentConditions, $commentFetchOptions); $groupedComments = array(); foreach ($comments as $commentId => &$comment) { $comment = $commentsModel->prepareComments($comment); $comment['message'] = XenForo_Helper_String::bbCodeStrip($comment['message']); $groupedComments[$comment['content_id']][$commentId] = $comment; } foreach ($media as &$_media) { if (!empty($groupedComments[$_media['media_id']])) { $_media['comments'] = $groupedComments[$_media['media_id']]; } $_media = $mediaModel->prepareMediaExifData($_media); } $mediaArray = array(); foreach ($mediaIds as $mediaId) { if (isset($media[$mediaId])) { $mediaArray[] = $media[$mediaId]; } } } $viewParams = array('albums' => array(), 'media' => $mediaArray); return $this->responseView('XenGallery_ViewPublic_Media_BbCode', '', $viewParams); }