function handle_url($action, $attributes, $content, $params, $node_object) { global $nuke_quotes; if (!isset($attributes['default'])) { $url = $content; $text = $content; } else { $url = $attributes['default']; $text = $content; } if ($action == 'validate') { if (substr($url, 0, 5) == 'data:' || substr($url, 0, 5) == 'file:' || substr($url, 0, 11) == 'javascript:' || substr($url, 0, 4) == 'jar:') { return false; } return true; } $url = trim(str_replace(""", "", $url)); if ($nuke_quotes) { if ($text != '') { return '[URL="' . $url . '"]' . $text . '[/URL]'; } else { return '[URL]' . $url . '[/URL]'; } } if (is_vb()) { global $vbulletin; $bburl = trim($vbulletin->options['bburl'], '/'); $url_parts = @parse_url($url); $bburl_parts = @parse_url($bburl); $bburl_noscheme = $bburl_parts['host'] . $url_parts['path']; $url_noscheme = $url_parts['host'] . $url_parts['path']; if ($url_parts !== false) { $ours = false; if (!$url_parts['host']) { $ours = true; } else { if (strpos($url_noscheme, $bburl_noscheme) !== false) { $ours = true; } } $new_url = ''; $threadid = $postid = $forumid = -1; if ($ours) { // First, check for override if (function_exists('fr_vbseo_parseurl')) { list($new_url, $forumid, $threadid, $postid) = fr_vbseo_parseurl($url); } else { if (strpos($url, 'showthread.php') !== false || strpos($url, 'forumdisplay.php') !== false) { // Now, check for standard vBulletin $args = preg_split('/&/', $url_parts['query']); if (is_array($args)) { foreach ($args as $arg) { if (preg_match('/(t|threadid|p|postid|f|forumid)=(\\d+)/', $arg, $matches)) { if ($matches[1] == 't' || $matches[1] == 'threadid') { $new_url = 'tt://threadTableView/'; $threadid = $matches[2]; break; } else { if ($matches[1] == 'p' || $matches[1] == 'postid') { $new_url = 'tt://threadTableView/'; $postid = $matches[2]; } else { if ($matches[1] == 'f' || $matches[1] == 'forumid') { $new_url = 'tt://forumTableView/'; $forumid = $matches[2]; } } } } } } } } if ($threadid > -1 || $postid > -1) { $postjoin = $where = ''; if ($postid != -1) { $postjoin = "\n LEFT JOIN " . TABLE_PREFIX . "post AS post ON post.threadid = thread.threadid\n "; $where = "\n WHERE post.postid = {$postid}\n "; } else { $where = "\n WHERE thread.threadid = {$threadid}\n "; } $thread = $vbulletin->db->query_first_slave("\n SELECT thread.title, thread.threadid\n FROM " . TABLE_PREFIX . "thread AS thread\n {$postjoin}\n {$where}\n "); if ($text == $url) { if ($thread['title']) { $text = prepare_utf8_string(htmlentities($thread['title'])); } else { $text = 'Thread Link'; } } $new_url .= $thread['threadid']; if ($postid > -1) { $new_url .= '?gotopost=' . $postid; } } else { if ($forumid > -1) { $forum = fetch_foruminfo($forumid); if ($text == $url) { if ($forum['title']) { $text = prepare_utf8_string(htmlentities($forum['title'])); } else { $text = 'Forum Link'; } } $new_url .= $forum['forumid']; } } if ($new_url != '') { $url = $new_url; } } } } else { if (is_xen()) { // Parse XenForo SEO URLs $bburl = trim(fr_get_xenforo_bburl(), '/'); $url_parts = @parse_url($url); $bburl_parts = @parse_url($bburl); $bburl_noscheme = $bburl_parts['host'] . $url_parts['path']; $url_noscheme = $url_parts['host'] . $url_parts['path']; if ($url_parts !== false) { $ours = false; if (!$url_parts['host']) { $ours = true; } else { if (strpos($url_noscheme, $bburl_noscheme) !== false) { $ours = true; } } $new_url = ''; $threadid = $forumid = -1; if ($ours) { // First, check for standard XenForo if (strpos($url, 'threads/') !== false || strpos($url, 'forums/') !== false) { if (preg_match('#threads/.*?\\.(\\d+)/#i', $url, $matches)) { $threadid = $matches[1]; $new_url = 'tt://threadTableView/' . $threadid; } else { if (preg_match('#forums/.*?\\.(\\d+)/#i', $url, $matches)) { $forumid = $matches[1]; $new_url = 'tt://forumTableView/' . $forumid; } } } $db = XenForo_Application::get('db'); if ($threadid > -1) { $thread = $db->fetchRow("\n SELECT thread.title\n FROM xf_thread AS thread\n WHERE thread.thread_id = ?\n ", $threadid); if ($url == $text) { if ($thread['title']) { $text = prepare_utf8_string($thread['title']); } else { $text = 'Thread Link'; } } } else { if ($forumid > -1) { $forum = $db->fetchRow("\n SELECT node.title\n FROM xf_node AS node\n WHERE node.node_id = ?\n ", $forumid); if ($url == $text) { if ($forum['title']) { $text = prepare_utf8_string($forum['title']); } else { $text = 'Forum Link'; } } } } if ($new_url != '') { $url = $new_url; } } } } } $text = preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $text); return '<a href="' . $url . '">' . $text . '</a>'; }
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; }
public function actionGetThread() { $threadid = $this->_input->filterSingle('threadid', XenForo_Input::UINT); $postid = $this->_input->filterSingle('postid', XenForo_Input::UINT); $signature = $this->_input->filterSingle('signature', 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')->messagesPerPage; } $visitor = XenForo_Visitor::getInstance(); $user_model = $this->getModelFromCache('XenForo_Model_User'); $thread_model = $this->_getThreadModel(); $post_model = $this->_getPostModel(); $forum_model = $this->_getForumModel(); $session_model = $this->getModelFromCache('XenForo_Model_Session'); $helper = $this->getHelper('ForumThreadPost'); $post_helper = new ForumRunner_ControllerHelper_Post($this); try { list($thread_info, $forum_info) = $helper->assertThreadValidAndViewable($threadid, array('readUserId' => $visitor['user_id'], 'watchUserId' => $visitor['user_id']), array('readUserId' => $visitor['user_id'])); } catch (Exception $e) { json_error($e->getControllerResponse()->errorText->render()); } $gotopostid = 0; if ($page == FR_LAST_POST) { // Figure out our last post page and post id $options = $post_model->getPermissionBasedPostFetchOptions($thread_info, $forum_info); $read_date = $thread_model->getMaxThreadReadDate($thread_info, $forum_info); $first_unread = $post_model->getNextPostInThread($threadid, $read_date, $options); if (!$first_unread) { $first_unread = $post_model->getLastPostInThread($threadid, $options); } if ($first_unread) { $page = floor($first_unread['position'] / $perpage) + 1; $gotopostid = $first_unread['post_id']; } else { $page = 1; } } else { if ($postid) { try { list($tpost, $tthread, $tforum) = $helper->assertPostValidAndViewable($postid); } catch (Exception $e) { json_error($e->getControllerResponse()->errorText->render()); } $page = floor($tpost['position'] / $perpage) + 1; $gotopostid = $postid; } } if ($thread_model->isRedirect($thread_info)) { // Redirect thread! XXX RKJ } $this->canonicalizePageNumber($page, $perpage, $thread_info['reply_count'] + 1, 'threads', $thread_info); $post_options = array_merge($post_model->getPermissionBasedPostFetchOptions($thread_info, $forum_info), array('perPage' => $perpage, 'page' => $page, 'join' => XenForo_Model_Post::FETCH_USER | XenForo_Model_Post::FETCH_USER_PROFILE | XenForo_Model_Post::FETCH_FORUM, 'likeUserId' => $visitor['user_id'])); if (!empty($post_options['deleted'])) { $post_options['join'] |= XenForo_Model_Post::FETCH_DELETION_LOG; } $posts = $post_model->getPostsInThread($threadid, $post_options); $posts = $post_model->getAndMergeAttachmentsIntoPosts($posts); $mod = array(); $perms = $visitor->getNodePermissions($thread_info['node_id']); $thread_mod = $thread_model->addInlineModOptionToThread($thread_info, $forum_info, $perms); $max_post_date = $first_unread = $deleted = $moderated = 0; foreach ($posts as &$post) { $post_mod = $post_model->addInlineModOptionToPost($post, $thread_info, $forum_info, $perms); $mod = array_merge($mod, $post_mod); $post = $post_model->preparePost($post, $thread_info, $forum_info, $perms); if ($post['post_date'] > $max_post_date) { $max_post_date = $post['post_date']; } if ($post['isDeleted']) { $deleted++; } if ($post['isModerated']) { $moderated++; } if (!$first_unread && $post['isNew']) { $first_unread = $post['post_id']; } } $thread_model->markThreadRead($thread_info, $forum_info, $max_post_date, $visitor['user_id']); fr_update_subsent($thread_info['thread_id'], $max_post_date); $thread_model->logThreadView($threadid); $post_data = array(); foreach ($posts as &$post) { $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; } $fr_images = $docattach = array(); if (isset($post['attachments']) && is_array($post['attachments'])) { foreach ($post['attachments'] as $attachment) { $ext = strtolower($attachment['extension']); $link = XenForo_Link::buildPublicLink('attachments', $attachment); if ($ext == 'jpe' || $ext == 'jpeg' || $ext == 'png' || $ext == 'gif' || $ext == 'jpg') { $data = array('img' => fr_get_xenforo_bburl() . '/' . $link); if ($attachment['thumbnailUrl']) { $data['tmb'] = fr_get_xenforo_bburl() . '/' . $attachment['thumbnailUrl']; } $fr_images[] = $data; } else { if ($ext == 'pdf') { $docattach[] = fr_get_xenforo_bburl() . '/' . $link; } } } } list($text, $nuked_quotes, $images) = parse_post(fr_strip_smilies($this, XenForo_Helper_String::censorString($post['message'])), true); if (count($fr_images) > 0) { $text .= "<br/>"; foreach ($fr_images as $attachment) { $text .= "<img src=\"{$attachment['img']}\"/>"; } } foreach ($images as $image) { $fr_images[] = array('img' => $image); } $avatarurl = ''; if ($user !== false) { $avatarurl = process_avatarurl(XenForo_Template_Helper_Core::getAvatarUrl($user, 'm')); if (strpos($avatarurl, '/xenforo/avatars/avatar_') !== false) { $avatarurl = ''; } } $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' => strip_tags(XenForo_Template_Helper_Core::helperUserTitle($user)), 'numposts' => $user ? $user['message_count'] : 0, 'userid' => $post['user_id'], 'canlike' => $post['canLike'] ? true : false, 'likes' => $post['like_date'] > 0 ? true : false, 'title' => prepare_utf8_string(XenForo_Helper_String::censorString($post['title'])), 'online' => $is_online, 'post_timestamp' => prepare_utf8_string(XenForo_Locale::dateTime($post['post_date'], 'absolute')), 'post_link' => fr_get_xenforo_bburl() . '/' . XenForo_Link::buildPublicLink('threads', $thread_info, array('page' => $post_page)) . '#post-' . $post['post_id'], 'fr_images' => $fr_images); if ($post['canDelete']) { $out['candelete'] = true; } if ($post['likes']) { $out['likestext'] = prepare_utf8_string($post_helper->likesHtml($post['post_id'], $post['likes'], $post['like_date'], $post['likeUsers'])); $like_users = ''; for ($i = 0; $i < count($post['likeUsers']); $i++) { if ($i != 0) { $like_users .= ', '; } $like_users .= $post['likeUsers'][$i]['username']; } $out['likesusers'] = prepare_utf8_string($like_users); } if ($avatarurl != '') { $out['avatarurl'] = $avatarurl; } if ($post['message_state'] == 'deleted') { $out += array('deleted' => true, 'del_username' => prepare_utf8_string(strip_tags($post['delete_username']))); if ($post['delete_reason']) { $out['del_reason'] = prepare_utf8_string($post['delete_reason']); } } else { if ($post['canEdit']) { $out += array('canedit' => $post['canEdit']); } $out += array('text' => $text, 'quotable' => $nuked_quotes, 'edittext' => prepare_utf8_string($post['message'])); } if (count($docattach)) { $out['docattach'] = $docattach; } if ($signature) { $sig = trim(strip_tags(remove_bbcode($post['signature'], true, true), '<a>')); $sig = str_replace(array("\t", "\r"), array('', ''), $sig); $sig = str_replace("\n\n", "\n", $sig); $out['sig'] = prepare_utf8_string($sig); } $post_data[] = $out; } $out = array('posts' => $post_data, 'total_posts' => $thread_info['reply_count'] + 1, 'page' => $page, 'canpost' => $thread_model->canReplyToThread($thread_info, $forum_info), 'canattach' => $forum_model->canUploadAndManageAttachment($forum_info), 'title' => prepare_utf8_string(XenForo_Helper_String::censorString($thread_info['title'])), 'thread_link' => process_avatarurl(XenForo_Link::buildPublicLink('threads', $thread_info, array('page' => $page))), 'subscribed' => $thread_info['thread_is_watched'] ? 1 : 0); if ($gotopostid) { $out['gotopostid'] = $gotopostid; } if ($thread_info['discussion_type'] == 'poll') { $poll_model = $this->_getPollModel(); $poll = $poll_model->getPollByContent('thread', $threadid); if ($poll) { $out['pollid'] = $poll['poll_id']; } } $modbit = 0; if (isset($mod['delete']) && $mod['delete']) { $modbit |= MOD_DELETEPOST; } if ($thread_info['sticky'] && isset($thread_mod['unstick']) && $thread_mod['unstick']) { $modbit |= MOD_UNSTICK; } if (!$thread_info['sticky'] && isset($thread_mod['stick']) && $thread_mod['stick']) { $modbit |= MOD_STICK; } if (isset($thread_mod['delete']) && $thread_mod['delete']) { $modbit |= MOD_DELETETHREAD; } XenForo_Application::setDebugMode(true); if ($thread_info['discussion_open'] && isset($thread_mod['lock']) && $thread_mod['lock']) { $modbit |= MOD_CLOSE; } if (!$thread_info['discussion_open'] && isset($thread_mod['unlock']) && $thread_mod['unlock']) { $modbit |= MOD_OPEN; } if (isset($thread_mod['move']) && $thread_mod['move']) { $modbit |= MOD_MOVETHREAD; } if (XenForo_Permission::hasPermission($visitor['permissions'], 'general', 'cleanSpam')) { $modbit |= MOD_SPAM_CONTROLS; } $out['mod'] = $modbit; return $out; }