public function renderJson() { $this->_params['urls'] = ThemeHouse_SocialGroups_Template_Helper_SocialForum::getAvatarUrls($this->_params['socialForum']); $this->_params['user_id'] = "sg-" . $this->_params['social_forum_id']; $output = XenForo_Application::arrayFilterKeys($this->_params, array('sizeCode', 'maxWidth', 'maxDimension', 'width', 'height', 'cropX', 'cropY', 'urls', 'user_id', 'logo_date', 'cropCss', 'message')); return XenForo_ViewRenderer_Json::jsonEncodeForOutput($output); }
/** * Prepare the array user in the notes */ public function prepareGames(array $games) { foreach ($games as &$game) { $game['user'] = XenForo_Application::arrayFilterKeys($game, array('user_id', 'username')); unset($game['user_id'], $game['username']); } return $games; }
protected function _preparePhotoForJson(array $photo, array $album) { $keys = array('content_data_id', 'upload_date', 'thumbnailUrl'); $template = $this->createTemplateObject('sonnb_xengallery_upload', array('content' => $photo, 'album' => $album)); $photo = XenForo_Application::arrayFilterKeys($photo, $keys); $photo['templateHtml'] = $template; return $photo; }
/** * Reduces down an array of attachment data into information we don't mind exposing, * and includes the attachment_editor_attachment template for each attachment. * * @param array $attachment * * @return array */ protected function _prepareAttachmentForJson(array $attachment) { $keys = array('attachment_id', 'attach_date', 'filename', 'thumbnailUrl', 'deleteUrl', 'viewUrl'); $template = $this->createTemplateObject('attachment_editor_attachment', array('attachment' => $attachment)); $attachment = XenForo_Application::arrayFilterKeys($attachment, $keys); $attachment['templateHtml'] = $template; return $attachment; }
public function prepareParams() { parent::prepareParams(); $this->_params['templates'] = array(); $keys = array('template_id', 'title', 'template', 'link', 'deleteLink'); foreach ($this->_params['templateData'] as $template) { $this->_params['templates'][$template['title']] = XenForo_Application::arrayFilterKeys($template, $keys); } }
/** * Gets report details from raw array of content (eg, a post record). * * @see XenForo_ReportHandler_Abstract::getReportDetailsFromContent() */ public function getReportDetailsFromContent(array $content) { /* @var $conversationModel XenForo_Model_Conversation */ $conversationModel = XenForo_Model::create('XenForo_Model_Conversation'); $message = $conversationModel->getConversationMessageById($content['message_id']); if (!$message) { return array(false, false, false); } if (empty($content['conversation'])) { $content['conversation'] = $conversationModel->getConversationMasterById($message['conversation_id']); } $conversation = XenForo_Application::arrayFilterKeys($content['conversation'], array('conversation_id', 'title', 'start_date', 'user_id', 'username', 'reply_count')); return array($content['message_id'], $content['user_id'], array('username' => $content['username'], 'message' => $content['message'], 'conversation' => $conversation, 'recipients' => $conversationModel->getConversationRecipients($conversation['conversation_id']))); }
/** * Reduces down an array of attachment data into information we don't mind exposing, * and includes the attachment_editor_attachment template for each attachment. * * @param array $attachment * * @return array */ protected function _prepareAttachmentForJson(array $attachment) { $attachment['mediaType'] = $this->_params['upload_type']; if (!empty($this->_params['customFields'])) { foreach ($this->_params['customFields'] as $fieldId => &$fields) { foreach ($fields as &$field) { if ($field['field_type'] == 'bbcode') { $field['editorTemplateHtml'] = XenForo_ViewPublic_Helper_Editor::getEditorTemplate($this, "{$attachment['mediaType']}[{$attachment['attachment_id']}][custom_fields][{$field['field_id']}]", isset($field['field_value']) ? $field['field_value'] : '', array('height' => '90px', 'extraClass' => 'NoAttachment NoAutoComplete')); } } } } $template = $this->createTemplateObject($this->_templateName, array('media' => $attachment) + $this->_params); $keys = array('attachment_id', 'attach_date', 'filename', 'thumbnailUrl', 'deleteUrl', 'mediaType'); $attachment = XenForo_Application::arrayFilterKeys($attachment, $keys); $attachment['templateHtml'] = $template; return $attachment; }
/** * Rebuilds the cache of resource field info for front-end display * * @return array */ public function rebuildResourceFieldCache() { $cache = array(); foreach ($this->getResourceFields() as $fieldId => $field) { $cache[$fieldId] = XenForo_Application::arrayFilterKeys($field, array('field_id', 'field_type', 'field_group_id')); } $this->_getDataRegistryModel()->set('resourceFieldsInfo', $cache); return $cache; }
/** * Rebuilds the cache of destination option info for front-end display * * @return array */ public function rebuildDestinationOptionCache() { $cache = array(); foreach ($this->getDestinationOptions() as $optionId => $destinationOption) { $cache[$optionId] = XenForo_Application::arrayFilterKeys($destinationOption, array('option_id', 'field_type')); foreach (array('display_template') as $optionalDestinationOption) { if (!empty($destinationOption[$optionalDestinationOption])) { $cache[$optionId][$optionalDestinationOption] = $destinationOption[$optionalDestinationOption]; } } } $this->_getDataRegistryModel()->set('destinationOptionsInfo', $cache); return $cache; }
private function _prepareSocialForumForCombination(array $socialForum) { return XenForo_Application::arrayFilterKeys($socialForum, array('social_forum_id', 'title', 'logo_date', 'logo_width', 'logo_height', 'logo_crop_x', 'logo_crop_y')); }
public function renderJson() { $this->_params['url'] = Nobita_Teams_Template_Helper_Core::getAvatarUrl($this->_params['team'], true); $output = XenForo_Application::arrayFilterKeys($this->_params, array('url', 'team_avatar_date', 'message', 'redirectUri')); return XenForo_ViewRenderer_Json::jsonEncodeForOutput($output); }
public function renderJson() { $this->_params['urls'] = XenForo_Template_Helper_Core::getAvatarUrls($this->_params['user']); $output = XenForo_Application::arrayFilterKeys($this->_params, array('sizeCode', 'maxWidth', 'maxDimension', 'width', 'height', 'cropX', 'cropY', 'urls', 'user_id', 'avatar_date', 'cropCss', 'message')); return XenForo_ViewRenderer_Json::jsonEncodeForOutput($output); }
/** * Rebuilds the cache of destination info for front-end display * * @return array */ public function rebuildDestinationCache() { $cache = array(); foreach ($this->getDestinations() as $destinationId => $destination) { $cache[$destinationId] = XenForo_Application::arrayFilterKeys($destination, array('destination_id', 'name')); } $this->_getDataRegistryModel()->set('destinationsInfo', $cache); return $cache; }
protected function _getPrivacyUsers($usernames, $serialize = true) { if (!is_array($usernames)) { $usernames = explode(',', $usernames); $usernames = array_filter($usernames); } $privacyUsers = array(); if (!empty($usernames)) { $users = $this->_getUserModel()->getUsersByNames($usernames); $userKeys = array('user_id', 'username'); foreach ($users as $key => $user) { $privacyUsers[$key] = XenForo_Application::arrayFilterKeys($user, $userKeys); } } if ($serialize) { $privacyUsers = serialize($privacyUsers); } return $privacyUsers; }
protected function _getTaggableUsers($usernames, $contentType, $contentId, $overwrite = false, $viewingUser = null) { $this->standardizeViewingUserReference($viewingUser); if (!is_array($usernames)) { $usernames = explode(',', $usernames); $usernames = array_filter($usernames); } $tagUsers = $alertUsers = $directUsers = array(); if (!empty($usernames)) { $userModel = $this->_getUserModel(); $users = $userModel->getUsersByNames($usernames, array('join' => XenForo_Model_User::FETCH_USER_PRIVACY | XenForo_Model_User::FETCH_USER_OPTION, 'followingUserId' => $viewingUser['user_id'])); $userKeys = array('user_id', 'username'); $taggedUsers = array(); if ($overwrite === false) { $taggedUsers = $this->getTagsByContentId($contentType, $contentId); } $excludeArray = array(); if ($taggedUsers) { foreach ($taggedUsers as $tagUser) { $excludeArray[] = $tagUser['user_id']; } } $xfContentType = ''; switch ($contentType) { case sonnb_XenGallery_Model_Album::$contentType: $xfContentType = sonnb_XenGallery_Model_Album::$xfContentType; break; case sonnb_XenGallery_Model_Photo::$contentType: $xfContentType = sonnb_XenGallery_Model_Photo::$xfContentType; break; } foreach ($users as $key => $user) { if (in_array($key, $excludeArray)) { continue; } $user = $userModel->prepareUser($user); if ($this->canTagUser($user, $errorPhraseKey, $viewingUser)) { $tagUsers[$key] = XenForo_Application::arrayFilterKeys($user, $userKeys); if ($this->canDirectTagging($user, $viewingUser)) { $directUsers[$key] = $user; } } if ($viewingUser['user_id'] != $user['user_id'] && !$userModel->isUserIgnored($user, $viewingUser['user_id']) && XenForo_Model_Alert::userReceivesAlert($user, $xfContentType, 'tag')) { $alertUsers[$key] = $user; } } } return array($tagUsers, $alertUsers, $directUsers); }
public function actionMiniStats() { $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT); $user = $this->getHelper('UserProfile')->assertUserProfileValidAndViewable($userId); $user = XenForo_Application::arrayFilterKeys($user, array('user_id', 'username', 'message_count', 'like_count', 'trophy_points', 'register_date')); $viewParams = array('user' => $user); return $this->responseView('XenForo_ViewPublic_Member_MiniStats', '', $viewParams); }
public function stepForums($start, array $options) { $sDb = $this->_sourceDb; $prefix = $this->_prefix; /* @var $model XenForo_Model_Import */ $model = $this->_importModel; if ($start > 0) { // after importing everything, rebuild the full permission cache so forums appear XenForo_Model::create('XenForo_Model_Node')->updateNestedSetInfo(); XenForo_Model::create('XenForo_Model_Permission')->rebuildPermissionCache(); return true; } $forums = $sDb->fetchAll(' SELECT * FROM ' . $prefix . 'boards ORDER BY id_board '); $categories = $sDb->fetchAll(' SELECT * FROM ' . $prefix . 'categories ORDER BY id_cat '); $nodes = array(); foreach ($forums as $key => $forum) { $forums[$key] = XenForo_Application::arrayFilterKeys($forum, array('id_board', 'id_cat', 'id_parent', 'board_order', 'name', 'member_groups', 'description', 'redirect', 'num_posts', 'num_topics', 'id_profile')); $nodes[intval($forum['id_board'])] = $forum['id_board']; } // Category / forum IDs can overlap. Map them. $categoryIdMap = array(0 => 0); foreach ($categories as $category) { $newId = intval($category['id_cat']); while (isset($nodes[$newId])) { $newId++; } $categoryIdMap[intval($category['id_cat'])] = $newId; $nodes[$newId] = $newId; $forums[] = array('id_board' => $newId, 'id_cat' => 0, 'id_parent' => 0, 'board_order' => $category['cat_order'], 'name' => $category['name'], 'description' => '', 'redirect' => '', 'num_posts' => 0, 'num_topics' => 0, 'id_profile' => 0, 'member_groups' => ''); } if (!$forums) { return true; } ksort($forums); $forumTree = array(); $forumPermissions = array(); foreach ($forums as $forum) { $parentId = $categoryIdMap[$forum['id_cat']]; $forumTree[$parentId][$forum['id_board']] = $forum; $forumPermissionSql = $sDb->query(' SELECT * FROM ' . $prefix . 'board_permissions WHERE id_profile = ? ', $forum['id_profile']); while ($forumPermission = $forumPermissionSql->fetch()) { $forumPermissions[$forum['id_board']][$forumPermission['id_group']][$forumPermission['permission']] = $forumPermission; } } XenForo_Db::beginTransaction(); $total = $this->_importForumTree(0, $forumTree, $forumPermissions, array(), array_flip($categoryIdMap)); XenForo_Db::commit(); $this->_session->incrementStepImportTotal($total); return array(1, array(), ''); }
/** * Inserts a new thread into this forum. * * @return XenForo_ControllerResponse_Abstract */ public function actionAddThread() { $this->_assertPostOnly(); $forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT); $forumName = $this->_input->filterSingle('node_name', XenForo_Input::STRING); $ftpHelper = $this->getHelper('ForumThreadPost'); $forum = $ftpHelper->assertForumValidAndViewable($forumId ? $forumId : $forumName); $forumId = $forum['node_id']; $this->_assertCanPostThreadInForum($forum); if (!XenForo_Captcha_Abstract::validateDefault($this->_input)) { return $this->responseCaptchaFailed(); } $visitor = XenForo_Visitor::getInstance(); $input = $this->_input->filter(array('title' => XenForo_Input::STRING, 'attachment_hash' => XenForo_Input::STRING, 'watch_thread_state' => XenForo_Input::UINT, 'watch_thread' => XenForo_Input::UINT, 'watch_thread_email' => XenForo_Input::UINT, '_set' => array(XenForo_Input::UINT, 'array' => true), 'discussion_open' => XenForo_Input::UINT, 'sticky' => XenForo_Input::UINT, 'poll' => XenForo_Input::ARRAY_SIMPLE)); $input['message'] = $this->getHelper('Editor')->getMessageText('message', $this->_input); $input['message'] = XenForo_Helper_String::autoLinkBbCode($input['message']); $pollInputHandler = new XenForo_Input($input['poll']); $pollInput = $pollInputHandler->filter(array('question' => XenForo_Input::STRING, 'responses' => array(XenForo_Input::STRING, 'array' => true), 'multiple' => XenForo_Input::UINT, 'public_votes' => XenForo_Input::UINT, 'close' => XenForo_Input::UINT, 'close_length' => XenForo_Input::UNUM, 'close_units' => XenForo_Input::STRING)); // note: assumes that the message dw will pick up the username issues $writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread'); $writer->set('user_id', $visitor['user_id']); $writer->set('username', $visitor['username']); $writer->set('title', $input['title']); $writer->set('node_id', $forumId); // discussion state changes instead of first message state $writer->set('discussion_state', $this->getModelFromCache('XenForo_Model_Post')->getPostInsertMessageState(array(), $forum)); // discussion open state - moderator permission required if (!empty($input['_set']['discussion_open']) && $this->_getForumModel()->canLockUnlockThreadInForum($forum)) { $writer->set('discussion_open', $input['discussion_open']); } // discussion sticky state - moderator permission required if (!empty($input['_set']['sticky']) && $this->_getForumModel()->canStickUnstickThreadInForum($forum)) { $writer->set('sticky', $input['sticky']); } $postWriter = $writer->getFirstMessageDw(); $postWriter->set('message', $input['message']); $postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage::DATA_ATTACHMENT_HASH, $input['attachment_hash']); $writer->preSave(); if ($pollInput['question'] !== '') { $pollWriter = XenForo_DataWriter::create('XenForo_DataWriter_Poll'); $pollWriter->bulkSet(XenForo_Application::arrayFilterKeys($pollInput, array('question', 'multiple', 'public_votes'))); $pollWriter->set('content_type', 'thread'); $pollWriter->set('content_id', 0); // changed before saving if ($pollInput['close']) { if (!$pollInput['close_length']) { $pollWriter->error(new XenForo_Phrase('please_enter_valid_length_of_time')); } else { $pollWriter->set('close_date', strtotime('+' . $pollInput['close_length'] . ' ' . $pollInput['close_units'])); } } $pollWriter->addResponses($pollInput['responses']); $pollWriter->preSave(); $writer->mergeErrors($pollWriter->getErrors()); $writer->set('discussion_type', 'poll', '', array('setAfterPreSave' => true)); } else { $pollWriter = false; foreach ($pollInput['responses'] as $response) { if ($response !== '') { $writer->error(new XenForo_Phrase('you_entered_poll_response_but_no_question')); break; } } } if (!$writer->hasErrors()) { $this->assertNotFlooding('post'); } $writer->save(); $thread = $writer->getMergedData(); if ($pollWriter) { $pollWriter->set('content_id', $thread['thread_id'], '', array('setAfterPreSave' => true)); $pollWriter->save(); } $this->_getThreadWatchModel()->setVisitorThreadWatchStateFromInput($thread['thread_id'], $input); $this->_getThreadModel()->markThreadRead($thread, $forum, XenForo_Application::$time, $visitor['user_id']); if (!$this->_getThreadModel()->canViewThread($thread, $forum)) { $return = XenForo_Link::buildPublicLink('forums', $forum, array('posted' => 1)); } else { $return = XenForo_Link::buildPublicLink('threads', $thread); } return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $return, new XenForo_Phrase('your_thread_has_been_posted')); }
/** * Rebuilds the cache of user field info for front-end display * * @return array */ public function rebuildUserFieldCache() { $cache = array(); foreach ($this->getUserFields() as $fieldId => $field) { $cache[$fieldId] = XenForo_Application::arrayFilterKeys($field, array('field_id', 'field_type', 'display_group')); foreach (array('display_template', 'viewable_profile', 'viewable_message') as $optionalField) { if (!empty($field[$optionalField])) { $cache[$fieldId][$optionalField] = $field[$optionalField]; } } } $this->_getDataRegistryModel()->set('userFieldsInfo', $cache); return $cache; }
/** * Wraps around the prepareX functions in the handler class for each content type. * Also does basic setup, moving user info to a sub-array. * * @param array $item * @param string $handlerClassName Name of alert handler class for this item * @param array $viewingUser Information about the viewing user (keys: user_id, permission_combination_id, permissions) * * @return array */ public function prepareAlert(array $item, $handlerClassName, array $viewingUser) { $item['user'] = XenForo_Application::arrayFilterKeys($item, array('user_id', 'username', 'gender', 'gravatar', 'avatar_date')); unset($item['user_id'], $item['username'], $item['gender'], $item['gravatar'], $item['avatar_date']); $item['new'] = $item['view_date'] === 0 || $item['view_date'] > XenForo_Application::$time - 600; $item['unviewed'] = $this->_isUnread($item); $handler = $this->_getAlertHandlerFromCache($item['content_type']); if ($handler) { $item = $handler->prepareAlert($item, $viewingUser); } return $item; }
/** * * @param string|array|null $addOnIds */ public static function getPrerequisites($addOnIds = null) { $prerequisites = $this->_prerequisites; if (!$addOnIds) { return $prerequisites; } else { if (is_array($addOnIds)) { return XenForo_Application::arrayFilterKeys($prerequisites, $addOnIds); } else { return isset($prerequisites[$addOnIds]) ? $prerequisites[$addOnIds] : array(); } } }
/** * Rebuilds the cache of gallery field info for front-end display * * @return array */ public function rebuildGalleryFieldCache() { $cache = array(); foreach ($this->getGalleryFields() as $fieldId => $field) { $cache[$fieldId] = XenForo_Application::arrayFilterKeys($field, array('field_id', 'field_type', 'display_group', 'album_use', 'display_add_media', 'required')); if (!empty($field['display_template'])) { $cache[$fieldId]['display_template'] = $field['display_template']; } } $this->_getDataRegistryModel()->set('xengalleryFieldsInfo', $cache); XenForo_Application::set('xengalleryFieldsInfo', $cache); return $cache; }