Exemplo n.º 1
0
 /**
  * Helper to get the paid content add/edit form controller response.
  *
  * @param array $paidContentItem
  *
  * @return XenForo_ControllerResponse_View
  */
 protected function _getPaidContentItemAddEditResponse(array $paidContentItem)
 {
     $paidContentItem = $this->_getPaidContentModel()->preparePaidContent($paidContentItem);
     $userGroups = $this->_getUserGroupModel()->getAllUserGroups();
     if (!empty($paidContentItem['paid_content_id'])) {
         $selUserGroupIds = explode(',', $paidContentItem['user_group_ids']);
         if (in_array(-1, $selUserGroupIds)) {
             $allUserGroups = true;
             $selUserGroupIds = array_keys($userGroups);
         } else {
             $allUserGroups = false;
         }
     } else {
         $allUserGroups = true;
         $selUserGroupIds = array_keys($userGroups);
     }
     if (empty($paidContentItem['start_date'])) {
         $paidContentItem['startDate'] = XenForo_Locale::date(XenForo_Application::$time, 'picker');
     }
     if (empty($paidContentItem['end_date'])) {
         $startTime = !empty($paidContentItem['start_date']) ? $paidContentItem['start_date'] : XenForo_Application::$time;
         $paidContentItem['endDate'] = XenForo_Locale::date($startTime + 7 * 24 * 60 * 60, 'picker');
     }
     $viewParams = array('paidContentItem' => $paidContentItem, 'allUserGroups' => $allUserGroups, 'selUserGroupIds' => $selUserGroupIds, 'userGroups' => $userGroups);
     return $this->responseView('ThemeHouse_PayForContent_ViewAdmin_PaidContentItem_Edit', 'th_paid_content_item_edit_payforcontent', $viewParams);
 }
Exemplo n.º 2
0
 public function createContent($tabId, $tabName, array $createCriteria, array $params)
 {
     if (!$createCriteria['resource_category_id']) {
         return $tabId;
     }
     /* @var $dw XenResource_DataWriter_Resource */
     $dw = XenForo_DataWriter::create('XenResource_DataWriter_Resource', XenForo_DataWriter::ERROR_SILENT);
     $dw->bulkSet(array('resource_category_id' => $createCriteria['resource_category_id'], 'title' => $params['title'], 'tag_line' => isset($params['tag_line']) ? $params['tag_line'] : new XenForo_Phrase('waindigo_resource_tag_line_create_tabs', $params, false), 'user_id' => $params['user_id'], 'username' => $params['username'], 'tab_id' => $tabId));
     $dw->setOption(Waindigo_Tabs_Extend_XenResource_DataWriter_Resource::OPTION_CHECK_TAB_RULES, false);
     $descriptionDw = $dw->getDescriptionDw();
     $descriptionDw->set('message', $params['message']);
     $versionDw = $dw->getVersionDw();
     $dw->set('is_fileless', 1);
     $versionDw->setOption(XenResource_DataWriter_Version::OPTION_IS_FILELESS, true);
     $versionDw->set('version_string', XenForo_Locale::date(XenForo_Application::$time, 'Y-m-d'));
     if ($dw->hasErrors()) {
         return $tabId;
     }
     if (!$tabId) {
         $tabId = $this->getTabId();
         $dw->set('tab_id', $tabId);
     }
     if (!$dw->save()) {
         return $tabId;
     }
     $this->insertTab($tabId, 'resource', $dw->get('resource_id'), $tabName);
     return $tabId;
 }
Exemplo n.º 3
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('position' => 0, 'batch' => 100, 'delete' => false), $data);
     $data['batch'] = max(1, $data['batch']);
     /* @var $statsModel XenForo_Model_Stats */
     $statsModel = XenForo_Model::create('XenForo_Model_Stats');
     if ($data['position'] == 0) {
         // delete old stats cache if required
         if (!empty($data['delete'])) {
             $statsModel->deleteStats();
         }
         // an appropriate date from which to start... first thread, or earliest user reg?
         $data['position'] = min(XenForo_Model::create('XenForo_Model_Thread')->getEarliestThreadDate(), XenForo_Model::create('XenForo_Model_User')->getEarliestRegistrationDate());
         // start on a 24 hour increment point
         $data['position'] = $data['position'] - $data['position'] % 86400;
     } else {
         if ($data['position'] > XenForo_Application::$time) {
             return true;
         }
     }
     $endPosition = $data['position'] + $data['batch'] * 86400;
     $statsModel->buildStatsData($data['position'], $endPosition);
     $data['position'] = $endPosition;
     $actionPhrase = new XenForo_Phrase('rebuilding');
     $typePhrase = new XenForo_Phrase('daily_statistics');
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::date($data['position'], 'absolute'));
     return $data;
 }
Exemplo n.º 4
0
 /**
  * @see XenForo_CacheRebuilder_DailyStats::rebuild()
  */
 public function rebuild($position = 0, array &$options = array(), &$detailedMessage = '')
 {
     $options['batch'] = isset($options['batch']) ? $options['batch'] : 28;
     $options['batch'] = max(1, $options['batch']);
     /* @var $userModel XenForo_Model_Stats */
     $statsModel = XenForo_Model::create('XenForo_Model_Stats');
     if ($position == 0) {
         // delete old stats cache if required
         if (!empty($options['delete'])) {
             $statsModel->deleteStats();
         }
         $xenOptions = XenForo_Application::get('options');
         // an appropriate date from which to start... first thread, or earliest user reg?
         if ($xenOptions->th_noForo_noForum) {
             $position = XenForo_Model::create('XenForo_Model_User')->getEarliestRegistrationDate();
         } else {
             $position = min(XenForo_Model::create('XenForo_Model_Thread')->getEarliestThreadDate(), XenForo_Model::create('XenForo_Model_User')->getEarliestRegistrationDate());
         }
         // start on a 24 hour increment point
         $position = $position - $position % 86400;
     } else {
         if ($position > XenForo_Application::$time) {
             return true;
         }
     }
     XenForo_Db::beginTransaction();
     $endPosition = $position + $options['batch'] * 86400;
     $data = $statsModel->buildStatsData($position, $endPosition);
     XenForo_Db::commit();
     $detailedMessage = XenForo_Locale::date($position, 'absolute');
     return $endPosition;
 }
Exemplo n.º 5
0
 /**
  * Splits an array into individual chunks of days, keyed by the midnight timestamp of the day specified by each item
  *
  * @param array $items
  * @param string $dateField
  *
  * @return array [$midnight] => $item
  */
 public static function dateSplit(array $items, $dateField)
 {
     $newItems = array();
     foreach ($items as $key => $value) {
         $newItems[XenForo_Locale::date($value[$dateField])][$key] = $value;
     }
     return $newItems;
 }
Exemplo n.º 6
0
 /**
  * Displays a form to do an advanced search.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionIndex()
 {
     $search = array('child_nodes' => true, 'order' => 'date');
     $searchId = $this->_input->filterSingle('search_id', XenForo_Input::UINT);
     if ($searchId) {
         if ($this->_input->filterSingle('searchform', XenForo_Input::UINT)) {
             $params = $this->_input->filter(array('q' => XenForo_Input::STRING, 't' => XenForo_Input::STRING, 'o' => XenForo_Input::STRING, 'g' => XenForo_Input::UINT, 'c' => XenForo_Input::ARRAY_SIMPLE));
             // allow this to pass through for the search type check later
             $this->_request->setParam('type', $params['t']);
             $users = '';
             if (!empty($params['c']['user'])) {
                 foreach ($this->_getUserModel()->getUsersByIds($params['c']['user']) as $user) {
                     $users .= $user['username'] . ', ';
                 }
                 $users = substr($users, 0, -2);
             }
             if (!empty($params['c']['node'])) {
                 $nodes = array_fill_keys(explode(' ', $params['c']['node']), true);
             } else {
                 $nodes = array();
             }
             if (!empty($params['c']['date'])) {
                 $date = XenForo_Locale::date(intval($params['c']['date']), 'picker');
             } else {
                 $date = '';
             }
             if (!empty($params['c']['user_content'])) {
                 $userContent = $params['c']['user_content'];
             } else {
                 $userContent = '';
             }
             $search = array_merge($search, array('keywords' => $params['q'], 'title_only' => !empty($params['c']['title_only']), 'users' => $users, 'user_content' => $userContent, 'date' => $date, 'nodes' => $nodes, 'child_nodes' => empty($nodes), 'order' => $params['o'], 'group_discussion' => $params['g'], 'existing' => true));
         } else {
             return $this->responseReroute(__CLASS__, 'results');
         }
     }
     if (!XenForo_Visitor::getInstance()->canSearch()) {
         throw $this->getNoPermissionResponseException();
     }
     $nodeId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
     if ($nodeId) {
         $search['nodes'][$nodeId] = true;
     }
     $viewParams = array('supportsRelevance' => XenForo_Search_SourceHandler_Abstract::getDefaultSourceHandler()->supportsRelevance(), 'nodes' => $this->_getNodeModel()->getViewableNodeList(null, true), 'search' => empty($search) ? array() : $search);
     $searchType = $this->_input->filterSingle('type', XenForo_Input::STRING);
     if ($searchType) {
         $typeHandler = $this->_getSearchModel()->getSearchDataHandler($searchType);
         if ($typeHandler) {
             $viewParams['searchType'] = $searchType;
             $response = $typeHandler->getSearchFormControllerResponse($this, $this->_input, $viewParams);
             if ($response) {
                 return $response;
             }
         }
     }
     $viewParams['searchType'] = '';
     return $this->responseView('XenForo_ViewPublic_Search_Form', 'search_form', $viewParams);
 }
Exemplo n.º 7
0
 public function verifyAndProcessingTimeinput(XenForo_Controller $controller, $sorttime = '', $datepicker)
 {
     $sorttime = array_map('intval', explode(":", $sorttime));
     if (count($sorttime) != 2) {
         throw new XenForo_Exception("Missing agrument for create/edit event.");
         return false;
     }
     $datepicker = XenForo_Locale::date($datepicker, 'd-m-Y');
     $datepicker = array_map('intval', explode('-', $datepicker));
     $gmmktime = gmmktime($sorttime[0], $sorttime[1], 0, $datepicker[1], $datepicker[0], $datepicker[2]);
     return $gmmktime - XenForo_Locale::getTimeZoneOffset();
 }
 /**
  *
  * @see XenForo_Model_UserGroupPromotion::promoteUser()
  */
 public function promoteUser(array $promotion, $userId, $state = 'automatic')
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $this->_getUserModel()->addUserGroupChange($userId, "ugPromotion{$promotion['promotion_id']}", $promotion['extra_user_group_ids']);
     $customFields = @unserialize($promotion['custom_fields_th']);
     if ($customFields) {
         foreach ($customFields as $customFieldId => $customFieldValue) {
             if (is_string($customFieldValue)) {
                 $replace = array('{now}' => XenForo_Application::$time, '{date}' => XenForo_Locale::date(XenForo_Application::$time, 'picker'));
                 $customFieldValue = strtr($customFieldValue, $replace);
             }
             $this->_getUserChangeTempModel()->applyTempUserChange($userId, 'custom_field', $customFieldId, $customFieldValue, null, "ugPromotion{$promotion['promotion_id']}{$customFieldId}");
         }
     }
     $this->insertPromotionLogEntry($promotion['promotion_id'], $userId, $state);
     XenForo_Db::commit($db);
 }
Exemplo n.º 9
0
 protected function _prepareDateField($value)
 {
     if ($value) {
         return XenForo_Locale::date($value);
     } else {
         return '';
     }
 }
Exemplo n.º 10
0
 public function getEventCalendarEntries(array $events)
 {
     $entries = array();
     $i = 0;
     foreach ($events as $eventId => $event) {
         $i++;
         $currentDate = XenForo_Locale::date($event['begin_date'], 'Y-m-d H:i:s');
         if ($event['end_date']) {
             $nextDate = XenForo_Locale::date($event['end_date'], 'Y-m-d H:i:s');
         } else {
             $nextDate = Date('Y-m-d', strtotime('+1 day', strtotime($currentDate)));
             $nextDate .= ' 00:00:00';
         }
         $entries[] = array('id' => $eventId, 'title' => XenForo_Helper_String::wholeWordTrim($event['event_title'], 25), 'start' => "{$currentDate}", 'url' => XenForo_Link::convertUriToAbsoluteUri(XenForo_Link::buildPublicLink(TEAM_ROUTE_ACTION . '/events', $event), true), 'allDay' => false, 'end' => "{$nextDate}", 'className' => 'eventEntry');
     }
     return $entries;
 }
Exemplo n.º 11
0
 /**
  * Determines if the given user matches the criteria. The provided
  * user should be a full user record; if fields are missing, an error
  * will not be thrown, and the criteria check will fail.
  *
  * @param array|string $criteria List of criteria, format: [] with keys rule and data; may be serialized
  * @param boolean $matchOnEmpty If true and there's no criteria, true is returned; otherwise, false
  * @param array|null $user Full user record to check against; if null, user visitor
  *
  * @return boolean
  */
 public static function userMatchesCriteria($criteria, $matchOnEmpty = false, array $user = null)
 {
     if (!($criteria = self::unserializeCriteria($criteria))) {
         return (bool) $matchOnEmpty;
     }
     if (!$user) {
         $user = XenForo_Visitor::getInstance()->toArray();
     }
     if (!isset($user['customFields'])) {
         $user['customFields'] = !empty($user['custom_fields']) ? @unserialize($user['custom_fields']) : array();
     }
     if (!isset($user['externalAuth'])) {
         $user['externalAuth'] = !empty($user['external_auth']) ? @unserialize($user['external_auth']) : array();
     }
     foreach ($criteria as $criterion) {
         $data = $criterion['data'];
         // custom user fields
         if (strpos($criterion['rule'], self::$_userFieldPrefix) === 0) {
             $userFieldId = substr($criterion['rule'], self::$_userFieldPrefixLength);
             if (!isset($user['customFields'][$userFieldId])) {
                 return false;
             }
             $userField = $user['customFields'][$userFieldId];
             // text fields - check that data exists within the text value
             if (isset($data['text'])) {
                 if (stripos($userField, $data['text']) === false) {
                     return false;
                 }
             } else {
                 if (isset($data['choices'])) {
                     // multi-choice
                     if (is_array($userField)) {
                         if (!array_intersect($userField, $data['choices'])) {
                             return false;
                         }
                     } else {
                         if (!in_array($userField, $data['choices'])) {
                             return false;
                         }
                     }
                 }
             }
         } else {
             switch ($criterion['rule']) {
                 // username
                 case 'username':
                     $names = preg_split('/\\s*,\\s*/', utf8_strtolower($data['names']), -1, PREG_SPLIT_NO_EMPTY);
                     if (!in_array(utf8_strtolower($user['username']), $names)) {
                         return false;
                     }
                     break;
                     // username-search
                 // username-search
                 case 'username_search':
                     if (self::_arrayStringSearch($data['needles'], $user['username']) === false) {
                         return false;
                     }
                     break;
                     // email-search
                 // email-search
                 case 'email_search':
                     if (self::_arrayStringSearch($data['needles'], $user['email']) === false) {
                         return false;
                     }
                     break;
                     // days since registration
                 // days since registration
                 case 'registered_days':
                     if (!isset($user['register_date'])) {
                         return false;
                     }
                     $daysRegistered = floor((XenForo_Application::$time - $user['register_date']) / 86400);
                     if ($daysRegistered < $data['days']) {
                         return false;
                     }
                     break;
                     // total messages posted
                 // total messages posted
                 case 'messages_posted':
                     if (!isset($user['message_count']) || $user['message_count'] < $data['messages']) {
                         return false;
                     }
                     break;
                     // maximum messages posted
                 // maximum messages posted
                 case 'messages_maximum':
                     if (!isset($user['message_count']) || $user['message_count'] > $data['messages']) {
                         return false;
                     }
                     break;
                     // total likes received
                 // total likes received
                 case 'like_count':
                     if (!isset($user['like_count']) || $user['like_count'] < $data['likes']) {
                         return false;
                     }
                     break;
                     // like:message ratio
                 // like:message ratio
                 case 'like_ratio':
                     if (empty($user['message_count']) || empty($user['like_count'])) {
                         return false;
                     }
                     if ($user['like_count'] / $user['message_count'] < $data['ratio']) {
                         return false;
                     }
                     break;
                     // total trophy points accumulated
                 // total trophy points accumulated
                 case 'trophy_points':
                     if (!isset($user['trophy_points']) || $user['trophy_points'] < $data['points']) {
                         return false;
                     }
                     break;
                     // days since last activity
                 // days since last activity
                 case 'inactive_days':
                     if (!isset($user['last_activity']) || empty($user['user_id'])) {
                         return false;
                     }
                     $daysInactive = floor((XenForo_Application::$time - $user['last_activity']) / 86400);
                     if ($daysInactive < $data['days']) {
                         return false;
                     }
                     break;
                     // current browsing style ID
                 // current browsing style ID
                 case 'style':
                     if (!isset($user['style_id'])) {
                         return false;
                     }
                     $styleId = empty($user['style_id']) ? XenForo_Application::get('options')->defaultStyleId : $user['style_id'];
                     if ($styleId != $data['style_id']) {
                         return false;
                     }
                     break;
                     // current browsing language ID
                 // current browsing language ID
                 case 'language':
                     if (!isset($user['language_id'])) {
                         return false;
                     }
                     $languageId = empty($user['language_id']) ? XenForo_Application::get('options')->defaultLanguageId : $user['language_id'];
                     if ($languageId != $data['language_id']) {
                         return false;
                     }
                     break;
                     // gender of user
                 // gender of user
                 case 'gender':
                     if (!isset($user['gender']) || $user['gender'] != $data['gender']) {
                         return false;
                     }
                     break;
                     // user is logged in
                 // user is logged in
                 case 'is_logged_in':
                     if (empty($user['user_id'])) {
                         return false;
                     }
                     break;
                     // user is a guest
                 // user is a guest
                 case 'is_guest':
                     if (!empty($user['user_id'])) {
                         return false;
                     }
                     break;
                     // user is a moderator
                 // user is a moderator
                 case 'is_moderator':
                     if (empty($user['is_moderator'])) {
                         return false;
                     }
                     break;
                     // user is an admin
                 // user is an admin
                 case 'is_admin':
                     if (empty($user['is_admin'])) {
                         return false;
                     }
                     break;
                     // user is banned
                 // user is banned
                 case 'is_banned':
                     if (empty($user['is_banned'])) {
                         return false;
                     }
                     break;
                     // search referer
                 // search referer
                 case 'from_search':
                     if (empty($user['from_search'])) {
                         return false;
                     }
                     break;
                     // associated with Facebook
                 // associated with Facebook
                 case 'facebook':
                     if (empty($user['externalAuth']['facebook'])) {
                         return false;
                     }
                     break;
                     // associated with Twitter
                 // associated with Twitter
                 case 'twitter':
                     if (empty($user['externalAuth']['twitter'])) {
                         return false;
                     }
                     break;
                     // associated with Google
                 // associated with Google
                 case 'google':
                     if (empty($user['externalAuth']['google'])) {
                         return false;
                     }
                     break;
                     // has no avatar (and is not a guest)
                 // has no avatar (and is not a guest)
                 case 'no_avatar':
                     if (empty($user['user_id']) || !empty($user['avatar_date']) || !empty($user['gravatar'])) {
                         return false;
                     }
                     break;
                     // user group membership
                 // user group membership
                 case 'user_groups':
                 case 'not_user_groups':
                     if (!isset($user['user_group_id'], $user['secondary_group_ids'])) {
                         return false;
                     }
                     $userGroups = $user['secondary_group_ids'] ? explode(',', $user['secondary_group_ids']) : array();
                     $matched = false;
                     if (!empty($data['user_group_ids'])) {
                         foreach ($data['user_group_ids'] as $matchUgId) {
                             if ($user['user_group_id'] == $matchUgId || in_array($matchUgId, $userGroups)) {
                                 $matched = true;
                                 break;
                             }
                         }
                     }
                     if ($criterion['rule'] == 'user_groups' && !$matched) {
                         // failed to match at least 1 group
                         return false;
                     } else {
                         if ($criterion['rule'] == 'not_user_groups' && $matched) {
                             // matched at least one group and shouldn't have
                             return false;
                         }
                     }
                     break;
                     // user state
                 // user state
                 case 'user_state':
                     if (!isset($user['user_state']) || $user['user_state'] != $data['state']) {
                         return false;
                     }
                     break;
                     // date criteria
                     // birthday
                 // date criteria
                 // birthday
                 case 'birthday':
                     if (empty($user['user_id']) || !isset($user['dob_day'], $user['dob_month'])) {
                         return false;
                     }
                     $today = XenForo_Locale::date(XenForo_Application::$time, 'j.n', null, isset($user['timezone']) ? $user['timezone'] : null);
                     if ("{$user['dob_day']}.{$user['dob_month']}" !== $today) {
                         return false;
                     }
                     break;
                     // before date / time
                 // before date / time
                 case 'before':
                     $datetime = new DateTime("{$data['ymd']} {$data['hh']}:{$data['mm']}", new DateTimeZone($data['user_tz'] ? $user['timezone'] : $data['timezone']));
                     if (XenForo_Application::$time >= $datetime->format('U')) {
                         return false;
                     }
                     break;
                     // after date / time
                 // after date / time
                 case 'after':
                     $datetime = new DateTime("{$data['ymd']} {$data['hh']}:{$data['mm']}", new DateTimeZone($data['user_tz'] ? $user['timezone'] : $data['timezone']));
                     if (XenForo_Application::$time < $datetime->format('U')) {
                         return false;
                     }
                     break;
                     // unknown criteria, assume failed unless something from a code event takes it
                 // unknown criteria, assume failed unless something from a code event takes it
                 default:
                     $eventReturnValue = false;
                     XenForo_CodeEvent::fire('criteria_user', array($criterion['rule'], $data, $user, &$eventReturnValue));
                     if ($eventReturnValue === false) {
                         return false;
                     }
             }
         }
     }
     return true;
 }
Exemplo n.º 12
0
 public function actionGetProfile()
 {
     $visitor = XenForo_Visitor::getInstance();
     $permissions = $visitor->getPermissions();
     $session_model = $this->getModelFromCache('XenForo_Model_Session');
     $userid = $this->_input->filterSingle('userid', XenForo_Input::UINT);
     if (!$userid) {
         $userid = XenForo_Visitor::getUserId();
     }
     try {
         $user = $this->getHelper('UserProfile')->assertUserProfileValidAndViewable($userid, array('join' => XenForo_Model_User::FETCH_LAST_ACTIVITY));
     } catch (Exception $e) {
         json_error($e->getControllerResponse()->errorText->render());
     }
     $online_info = $session_model->getSessionActivityRecords(array('user_id' => $user['user_id'], 'cutOff' => array('>', $session_model->getOnlineStatusTimeout())));
     $is_online = false;
     if (count($online_info) == 1) {
         $is_online = true;
     }
     $posts = $user['message_count'];
     $joindate = prepare_utf8_string(XenForo_Locale::date($user['register_date'], 'absolute'));
     $out = array('username' => prepare_utf8_string(strip_tags($user['username'])), 'posts' => $posts, 'joindate' => $joindate, 'online' => $is_online, 'avatar_upload' => $visitor->canUploadAvatar());
     $maxFileSize = XenForo_Permission::hasPermission($permissions, 'avatar', 'maxFileSize');
     if ($maxFileSize > 0) {
         $out['avatar_resize'] = true;
     }
     $avatarurl = process_avatarurl(XenForo_Template_Helper_Core::getAvatarUrl($user, 'm'));
     if (strpos($avatarurl, '/xenforo/avatars/avatar_') !== false) {
         $avatarurl = '';
     }
     if ($avatarurl != '') {
         $out['avatarurl'] = $avatarurl;
     }
     if ($visitor->hasAdminPermission('ban')) {
         $out['ban'] = true;
     }
     // New Profile Fields
     $groups = array();
     // About
     $out_group = array('name' => 'about', 'values' => array(array('name' => prepare_utf8_string(fr_get_phrase('messages')), 'value' => strval($posts)), array('name' => prepare_utf8_string(fr_get_phrase('joined')), 'value' => $joindate), array('name' => prepare_utf8_string(fr_get_phrase('likes_received')), 'value' => strval($user['like_count']))));
     $groups[] = $out_group;
     // Additional information
     $out_group = array('name' => 'additional');
     // Status
     if (!empty($user['status'])) {
         $out_group['values'][] = array('name' => prepare_utf8_string(fr_get_phrase('status')), 'value' => prepare_utf8_string($user['status']));
     }
     // Location
     if (!empty($user['location'])) {
         $out_group['values'][] = array('name' => prepare_utf8_string(fr_get_phrase('location')), 'value' => prepare_utf8_string($user['location']));
     }
     // Occupation
     if (!empty($user['occupation'])) {
         $out_group['values'][] = array('name' => prepare_utf8_string(fr_get_phrase('occupation')), 'value' => prepare_utf8_string($user['occupation']));
     }
     // About
     if (!empty($user['about'])) {
         $out_group['values'][] = array('name' => prepare_utf8_string(fr_get_phrase('about')), 'value' => prepare_utf8_string(remove_bbcode($user['about'], true, true)));
     }
     if (count($out_group['values'])) {
         $groups[] = $out_group;
     }
     $out['groups'] = $groups;
     return $out;
 }
Exemplo n.º 13
0
 /**
  * Date formatting. Format represents a string name of a format.
  *
  * @param integer Unix timestamp to format
  * @param string  Named format (name options TBD)
  *
  * @return string
  */
 public static function date($timestamp, $format = null)
 {
     return XenForo_Locale::date($timestamp, $format, self::$_language);
 }
Exemplo n.º 14
0
 public function preparePaidContent(array $paidContent)
 {
     if (!empty($paidContent['cost_amount']) && !isset($paidContent['currency_old'])) {
         if (isset($paidContent['currency'])) {
             $paidContent['currency_old'] = $paidContent['currency'];
         } else {
             $paidContent['currency_old'] = '';
         }
         $paidContent['currency'] = strtoupper($paidContent['cost_currency']);
     }
     if (!empty($paidContent['cost_amount'])) {
         if ($paidContent['cost_amount'] == '0.00') {
             $paidContent['costPhrase'] = new XenForo_Phrase('free');
         } else {
             $paidContent['costPhrase'] = XenForo_Locale::numberFormat($paidContent['cost_amount'], 2) . ' ' . $paidContent['currency'];
         }
     }
     if (!empty($paidContent['paid_content_id'])) {
         $paidContent['paid_content_title'] = new XenForo_Phrase($this->getPaidContentPhraseName($paidContent['paid_content_id']));
     }
     if (isset($paidContent['user_group_ids']) && $paidContent['user_group_ids'] != -1) {
         $paidContent['userGroupIds'] = explode(',', $paidContent['user_group_ids']);
     }
     if (!empty($paidContent['start_date'])) {
         $paidContent['startDate'] = XenForo_Locale::date($paidContent['start_date'], 'picker');
     }
     if (!empty($paidContent['end_date'])) {
         $paidContent['endDate'] = XenForo_Locale::date($paidContent['end_date'], 'picker');
     }
     return $paidContent;
 }
Exemplo n.º 15
0
 public function actionSave()
 {
     $this->_assertPostOnly();
     $categoryModel = $this->_getCategoryModel();
     if ($resourceId = $this->_input->filterSingle('resource_id', XenForo_Input::UINT)) {
         list($resource, $category) = $this->_getResourceHelper()->assertResourceValidAndViewable($resourceId);
         if (!$this->_getResourceModel()->canEditResource($resource, $category, $errorPhraseKey)) {
             throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
         }
         $categoryPermissions = $categoryModel->getCategoryPermCache(null, $category['resource_category_id']);
         $canEditCategory = XenForo_Permission::hasContentPermission($categoryPermissions, 'editAny');
     } else {
         $category = false;
         $resource = false;
         $canEditCategory = true;
     }
     $resourceData = $this->_input->filter(array('resource_category_id' => XenForo_Input::UINT, 'title' => XenForo_Input::STRING, 'tag_line' => XenForo_Input::STRING, 'external_url' => XenForo_Input::STRING, 'alt_support_url' => XenForo_Input::STRING, 'prefix_id' => XenForo_Input::UINT));
     if (!$resourceData['resource_category_id']) {
         return $this->responseError(new XenForo_Phrase('you_must_select_category'));
     }
     $newCategory = $category;
     if ($canEditCategory) {
         if (!$resource || $resource['resource_category_id'] != $resourceData['resource_category_id']) {
             // new resource or changing category - let's make sure we can do that
             $newCategory = $this->_getResourceHelper()->assertCategoryValidAndViewable($resourceData['resource_category_id']);
             if (!$categoryModel->canAddResource($newCategory, $key)) {
                 throw $this->getErrorOrNoPermissionResponseException($key);
             }
         }
         $categoryId = $resourceData['resource_category_id'];
     } else {
         $categoryId = $resource['resource_category_id'];
         unset($resourceData['resource_category_id']);
     }
     if (!$resource || $resource['prefix_id'] != $resourceData['prefix_id'] || $resource['resource_category_id'] != $categoryId) {
         if (!$this->_getPrefixModel()->verifyPrefixIsUsable($resourceData['prefix_id'], $categoryId)) {
             $resourceData['prefix_id'] = 0;
             // not usable, just blank it out
         }
     }
     /* @var $dw XenResource_DataWriter_Resource */
     $dw = XenForo_DataWriter::create('XenResource_DataWriter_Resource');
     if ($resourceId) {
         $dw->setExistingData($resource['resource_id']);
     } else {
         $visitor = XenForo_Visitor::getInstance();
         $dw->set('user_id', $visitor['user_id']);
         $dw->set('username', $visitor['username']);
     }
     $dw->bulkSet($resourceData);
     if (!$resourceId || $newCategory['resource_category_id'] != $category['resource_category_id']) {
         if ($newCategory['always_moderate_create'] && ($dw->get('resource_state') == 'visible' || !$resourceId) && !XenForo_Visitor::getInstance()->hasPermission('resource', 'approveUnapprove')) {
             $dw->set('resource_state', 'moderated');
         }
     }
     if (!$resourceId) {
         $watch = XenForo_Visitor::getInstance()->default_watch_state;
         if (!$watch) {
             $watch = 'watch_no_email';
         }
         $dw->setExtraData(XenResource_DataWriter_Resource::DATA_THREAD_WATCH_DEFAULT, $watch);
     }
     $customFields = $this->_getResourceHelper()->getCustomFieldValues($null, $shownCustomFields);
     $dw->setCustomFields($customFields, $shownCustomFields);
     $extraData = $this->_input->filter(array('attachment_hash' => XenForo_Input::STRING, 'file_hash' => XenForo_Input::STRING, 'version_string' => XenForo_Input::STRING, 'resource_file_type' => XenForo_Input::STRING, 'download_url' => XenForo_Input::STRING, 'price' => XenForo_Input::UNUM, 'currency' => XenForo_Input::STRING, 'external_purchase_url' => XenForo_Input::STRING));
     $message = $this->getHelper('Editor')->getMessageText('message', $this->_input);
     $message = XenForo_Helper_String::autoLinkBbCode($message);
     $descriptionDw = $dw->getDescriptionDw();
     $descriptionDw->set('message', $message);
     $descriptionDw->setExtraData(XenResource_DataWriter_Update::DATA_ATTACHMENT_HASH, $extraData['attachment_hash']);
     $versionDw = $dw->getVersionDw();
     if (!$resourceId) {
         switch ($extraData['resource_file_type']) {
             case 'file':
                 if ($newCategory['allow_local']) {
                     $versionDw->setExtraData(XenResource_DataWriter_Version::DATA_ATTACHMENT_HASH, $extraData['file_hash']);
                 }
                 break;
             case 'url':
                 if ($newCategory['allow_external']) {
                     if (!$extraData['download_url']) {
                         $versionDw->error(new XenForo_Phrase('please_enter_external_download_url'), 'download_url');
                     } else {
                         $versionDw->set('download_url', $extraData['download_url']);
                     }
                 }
                 break;
             case 'commercial_external':
                 if ($newCategory['allow_commercial_external']) {
                     if (!$extraData['price'] || !$extraData['currency'] || !$extraData['external_purchase_url']) {
                         $dw->error(new XenForo_Phrase('please_complete_required_fields'));
                     } else {
                         $dw->bulkSet(array('is_fileless' => 1, 'price' => $extraData['price'], 'currency' => $extraData['currency'], 'external_purchase_url' => $extraData['external_purchase_url']));
                         $versionDw->setOption(XenResource_DataWriter_Version::OPTION_IS_FILELESS, true);
                     }
                 }
                 break;
             case 'fileless':
                 if ($newCategory['allow_fileless']) {
                     $dw->set('is_fileless', 1);
                     $versionDw->setOption(XenResource_DataWriter_Version::OPTION_IS_FILELESS, true);
                 }
                 break;
         }
     } else {
         if ($resource['external_purchase_url']) {
             // already an external purchase
             if (!$extraData['price'] || !$extraData['currency'] || !$extraData['external_purchase_url']) {
                 $dw->error(new XenForo_Phrase('please_complete_required_fields'));
             } else {
                 $dw->bulkSet(array('price' => $extraData['price'], 'currency' => $extraData['currency'], 'external_purchase_url' => $extraData['external_purchase_url']));
                 $versionDw->setOption(XenResource_DataWriter_Version::OPTION_IS_FILELESS, true);
             }
         }
     }
     if ($extraData['version_string'] === '') {
         $extraData['version_string'] = XenForo_Locale::date(XenForo_Application::$time, 'Y-m-d');
     }
     $versionDw->set('version_string', $extraData['version_string']);
     $dw->preSave();
     // when editing, we can only do this check if not changing the category
     if ($newCategory['require_prefix'] && !$dw->get('prefix_id') && (!$resource || $resource['resource_category_id'] == $newCategory['resource_category_id'])) {
         $dw->error(new XenForo_Phrase('please_select_a_prefix'), 'prefix_id');
     }
     if (!$dw->hasErrors()) {
         $this->assertNotFlooding('post');
         // use the action of "posting" as the trigger
     }
     $dw->save();
     $resource = $dw->getMergedData();
     $update = $descriptionDw->getMergedData();
     if ($dw->isUpdate() && XenForo_Visitor::getUserId() != $resource['user_id']) {
         $basicLog = $this->_getLogChanges($dw);
         if ($basicLog) {
             XenForo_Model_Log::logModeratorAction('resource', $resource, 'edit', $basicLog);
         }
         $basicLog = $this->_getLogChanges($descriptionDw);
         if ($basicLog) {
             XenForo_Model_Log::logModeratorAction('resource_update', $update, 'edit', $basicLog, $resource);
         }
     }
     if ($dw->isInsert()) {
         $this->_getDraftModel()->deleteDraft("resource-category-{$categoryId}");
     }
     if ($this->_input->filterSingle('edit_icon', XenForo_Input::BOOLEAN)) {
         XenForo_Application::getSession()->set('autoClickTrigger', '#EditIconTrigger');
     }
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('resources', $resource));
 }
Exemplo n.º 16
0
 public function prepareGraphData(array $data, $grouping = 'daily')
 {
     $plot = array();
     $dateMap = array();
     $keys = array_keys($data);
     $date = reset($keys);
     $maxDate = end($keys);
     // stats are generated based on UTC
     $utcTz = new DateTimeZone('UTC');
     if ($grouping == 'monthly') {
         list($year, $month) = explode('/', gmdate("Y/m", $date));
         list($endYear, $endMonth) = explode('/', gmdate("Y/m", $maxDate));
         $year = intval($year);
         $month = intval($month);
         $endYear = intval($endYear);
         $endMonth = intval($endMonth);
         while ($year < $endYear || $year == $endYear && $month <= $endMonth) {
             $k = intval($year . sprintf("%02d", $month));
             $plot[$k] = array($k, 0);
             $dateMap[$k] = new XenForo_Phrase("month_{$month}_short") . " {$year}";
             $month++;
             if ($month > 12) {
                 $month = 1;
                 $year++;
             }
         }
         foreach ($data as $k => $v) {
             $newK = intval(gmdate("Ym", $k));
             $plot[$newK] = array($newK, floatval($v));
             $dateMap[$newK] = XenForo_Locale::date($k, 'M Y', null, $utcTz);
         }
     } else {
         if ($grouping == 'weekly') {
             list($year, $week) = explode('/', gmdate("o/W", $date));
             list($endYear, $endWeek) = explode('/', gmdate("o/W", $maxDate));
             $year = intval($year);
             $week = intval($week);
             $endYear = intval($endYear);
             $endWeek = intval($endWeek);
             $maxWeekNum = gmdate('W', gmmktime(12, 0, 0, 12, 31, $year));
             while ($year < $endYear || $year == $endYear && $week <= $endWeek) {
                 $weekPrint = sprintf("%02d", $week);
                 $k = intval($year . $weekPrint);
                 $plot[$k] = array($k, 0);
                 $dateMap[$k] = "W{$weekPrint} {$year}";
                 $week++;
                 if ($week > $maxWeekNum) {
                     $week = 1;
                     $year++;
                     $maxWeekNum = gmdate('W', gmmktime(12, 0, 0, 12, 31, $year));
                 }
             }
             foreach ($data as $k => $v) {
                 $newK = intval(gmdate("oW", $k));
                 $plot[$newK] = array($newK, floatval($v));
                 $dateMap[$newK] = gmdate('\\WW o', $k);
             }
         } else {
             while ($date <= $maxDate) {
                 $dateMap[$date] = XenForo_Locale::date($date, 'absolute', null, $utcTz);
                 $value = isset($data[$date]) ? $data[$date] : 0;
                 $plot[$date] = array($date * 1000, floatval($value));
                 $date += 86400;
             }
         }
     }
     ksort($plot);
     return array('plot' => array_values($plot), 'dateMap' => $dateMap);
 }
Exemplo n.º 17
0
    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;
    }
Exemplo n.º 18
0
 protected function _prepareFieldsForTemplate($fields)
 {
     $templateFields = array();
     foreach ($fields as $fieldId => $field) {
         if ($field['active']) {
             if ($field['field_type'] == 'checkbox' || $field['field_type'] == 'select' || $field['field_type'] == 'multiselect' || $field['field_type'] == 'radio' || $field['field_type'] == 'rating') {
                 if (!is_array($field['field_choices'])) {
                     $choices = unserialize($field['field_choices']);
                 }
                 if (is_array($field['field_value'])) {
                     $text = '';
                     foreach ($field['field_value'] as $choiceId) {
                         $text .= ', ' . $choices[$choiceId];
                     }
                     $templateFields[$field['field_name']]['value'] = substr($text, 2);
                 } else {
                     if ($field['field_type'] == 'rating' && $field['field_value'] != '') {
                         $templateFields[$field['field_name']]['value'] = $field['field_value'] . new XenForo_Phrase('lpsf_rating_separator') . XenForo_Application::getOptions()->lpsfRatingMax;
                     } else {
                         if (isset($choices[$field['field_value']])) {
                             $templateFields[$field['field_name']]['value'] = $choices[$field['field_value']];
                         } else {
                             $templateFields[$field['field_name']]['value'] = '';
                         }
                     }
                 }
             } else {
                 $templateFields[$field['field_name']]['value'] = htmlspecialchars_decode($field['field_value']);
                 if (($field['field_type'] == 'date' || $field['field_type'] == 'datetime') && $field['field_value'] != '') {
                     $dateTime = new DateTime($field['field_value'], XenForo_Locale::getDefaultTimeZone());
                 }
                 if ($field['field_type'] == 'date' && isset($dateTime)) {
                     $templateFields[$field['field_name']]['value'] = XenForo_Locale::date($dateTime, 'absolute');
                 }
                 if ($field['field_type'] == 'datetime' && isset($dateTime)) {
                     $templateFields[$field['field_name']]['value'] = XenForo_Locale::dateTime($dateTime, 'absolute');
                 }
             }
             $templateFields[$field['field_name']]['field_type'] = $field['field_type'];
             $templateFields[$field['field_name']]['title'] = $field['title']->render();
         }
     }
     return $templateFields;
 }
Exemplo n.º 19
0
 public function actionGetConversation()
 {
     $conversationid = $this->_input->filterSingle('conversationid', 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;
     }
     $conversation_model = $this->_getConversationModel();
     $session_model = $this->getModelFromCache('XenForo_Model_Session');
     try {
         $conversation_info = $this->_getConversationOrError($conversationid);
     } catch (Exception $e) {
         json_error($e->getControllerResponse()->errorText->render());
     }
     $gotomessageid = 0;
     if ($page == FR_LAST_POST) {
         if (!$conversation_info['last_read_date']) {
             $page = 1;
         } else {
             if ($conversation_info['last_read_date'] >= $conversation_info['last_message_date']) {
                 $first_unread = false;
             } else {
                 $first_unread = $conversation_model->getNextMessageInConversation($conversationid, $conversation_info['last_read_date']);
             }
             if (!$first_unread || $first_unread['message_id'] == $conversation_info['last_message_id']) {
                 $page = floor($conversation_info['reply_count'] / $perpage) + 1;
                 $gotomessageid = $conversation_info['last_message_id'];
             } else {
                 $before = $conversation_model->countMessagesBeforeDateInConversation($conversationid, $first_unread['message_date']);
                 $page = floor($before / $perpage) + 1;
                 $gotomessageid = $first_unread['message_id'];
             }
         }
     }
     $recipients = $conversation_model->getConversationRecipients($conversationid);
     $messages = $conversation_model->getConversationMessages($conversationid, array('page' => $page, 'perPage' => $perpage));
     $max = $conversation_model->getMaximumMessageDate($messages);
     if ($max > $conversation_info['last_read_date']) {
         $conversation_model->markConversationAsRead($conversationid, XenForo_Visitor::getUserId(), $max, $conversation_info['last_message_date']);
     }
     $messages = $conversation_model->prepareMessages($messages, $conversation_info);
     $user_model = $this->getModelFromCache('XenForo_Model_User');
     foreach ($messages as &$message) {
         $user = $user_model->getUserById($message['user_id']);
         $online_info = $session_model->getSessionActivityRecords(array('user_id' => $message['user_id'], 'cutOff' => array('>', $session_model->getOnlineStatusTimeout())));
         $is_online = false;
         if (count($online_info) == 1) {
             $is_online = true;
         }
         list($text, $nuked_quotes, $images) = parse_post(fr_strip_smilies($this, XenForo_Helper_String::censorString($message['message'])), true);
         $fr_images = array();
         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 = '';
             }
         }
         $out = array('post_id' => $message['message_id'], 'thread_id' => $message['conversation_id'], 'username' => prepare_utf8_string(strip_tags($message['username'])), 'joindate' => prepare_utf8_string(XenForo_Locale::date($message['register_date'], 'absolute')), 'usertitle' => XenForo_Template_Helper_Core::helperUserTitle($user), 'numposts' => $user ? $user['message_count'] : 0, 'userid' => $message['user_id'], 'online' => $is_online, 'post_timestamp' => prepare_utf8_string(XenForo_Locale::dateTime($message['message_date'], 'absolute')), 'fr_images' => $fr_images, 'text' => $text, 'quotable' => $nuked_quotes);
         if ($avatarurl != '') {
             $out['avatarurl'] = $avatarurl;
         }
         if ($signature) {
             $sig = trim(strip_tags(remove_bbcode($message['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);
         }
         $message_data[] = $out;
     }
     $out = array('posts' => $message_data, 'total_posts' => $conversation_info['reply_count'] + 1, 'page' => $page, 'canattach' => false, 'canpost' => true, 'title' => prepare_utf8_string(XenForo_Helper_String::censorString($conversation_info['title'])), 'thread_link' => process_avatarurl(XenForo_Link::buildPublicLink('conversations', $conversation_info)));
     if ($gotomessageid) {
         $out['gotopostid'] = $gotomessageid;
     }
     $r = array_values($conversation_model->getConversationRecipients($conversationid));
     $recipients = '';
     for ($i = 0; $i < count($r); $i++) {
         if ($i != 0) {
             $recipients .= ', ';
         }
         $recipients .= prepare_utf8_string(strip_tags($r[$i]['username']));
     }
     $out['recipients'] = $recipients;
     return $out;
 }
Exemplo n.º 20
0
 public function prepareCheckOut(array $checkOut, array $resource, array $category)
 {
     if (!$checkOut['check_in_user_id']) {
         $checkOut['checkedIn'] = false;
         $todayDate = XenForo_Locale::date(XenForo_Application::$time, 'picker');
         $visitor = XenForo_Visitor::getInstance();
         $checkOut['check_in_deposit_refund_amount'] = $checkOut['check_out_deposit_amount'];
         $checkOut['check_in_deposit_refund_method_id'] = $checkOut['check_out_deposit_payment_method_id'];
         $checkOut['check_in_condition_id'] = $resource['condition_id_th'];
         $checkOut['check_in_location_id'] = $checkOut['check_out_location_id'];
         $checkOut['check_in_date'] = $todayDate;
         $checkOut['check_in_username'] = $visitor['check_in_out_username'] ? $visitor['check_in_out_username'] : $visitor['username'];
         $checkOut['check_in_from_username'] = $checkOut['check_out_to_username'];
     } else {
         $checkOut['checkedIn'] = true;
     }
     return $checkOut;
 }
Exemplo n.º 21
0
 public function assertTeamValidAndViewable($teamIdOrName = null, array $teamFetchOptions = array(), array $categoryFetchOptions = array())
 {
     if (!isset($teamFetchOptions['join'])) {
         $teamFetchOptions['join'] = 0;
     }
     $teamFetchOptions['join'] |= Nobita_Teams_Model_Team::FETCH_PRIVACY | Nobita_Teams_Model_Team::FETCH_PROFILE | Nobita_Teams_Model_Team::FETCH_FEATURED;
     if ($this->_visitor->hasPermission('Teams', 'viewDeleted')) {
         $teamFetchOptions['join'] |= Nobita_Teams_Model_Team::FETCH_DELETION_LOG;
     }
     $visitor = XenForo_Visitor::getInstance();
     $teamFetchOptions['banUserId'] = $visitor['user_id'];
     $teamFetchOptions['memberUserId'] = $visitor['user_id'];
     $team = $this->getTeamOrError($teamIdOrName, $teamFetchOptions);
     $category = $this->assertCategoryValidAndViewable($team['team_category_id'], $categoryFetchOptions);
     $teamModel = $this->_controller->getModelFromCache('Nobita_Teams_Model_Team');
     if (!$teamModel->canViewTeam($team, $category, $errorPhraseKey)) {
         throw $this->_controller->getErrorOrNoPermissionResponseException($errorPhraseKey);
     }
     $team = $teamModel->prepareTeam($team, $category);
     $team = $teamModel->prepareTeamCustomFields($team, $category);
     if (!empty($team['ban_expired_date']) && $team['ban_expired_date'] > XenForo_Application::$time) {
         $banLift = new XenForo_Phrase('ban_will_be_automatically_lifted_on_x', array('date' => XenForo_Locale::date($team['ban_expired_date'])), false);
         throw $this->_controller->responseException($this->_controller->responseError($team['user_reason'] . '. ' . $banLift->render()));
     }
     return array($team, $category);
 }
Exemplo n.º 22
0
 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;
 }