Esempio n. 1
0
 /**
  * Remove votes
  *
  * @return	@e void
  */
 public function topicDeletePollVotes()
 {
     //-----------------------------------------
     // Permissions check
     //-----------------------------------------
     if (!$this->settings['poll_allow_vdelete'] and !$this->memberData['g_is_supmod']) {
         $this->registry->output->showError('topic_cannot_vote', 103147, null, null, 403);
     }
     //-----------------------------------------
     // What did we vote for?
     //-----------------------------------------
     $voter = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'voters', 'where' => "tid=" . $this->topic['tid'] . " and member_id=" . $this->memberData['member_id']));
     if (!$voter) {
         $this->registry->output->redirectScreen($this->lang->words['poll_vote_deleted'], $this->settings['base_url'] . "showtopic={$this->topic['tid']}&st=" . $this->request['st'], $this->topic['title_seo'], 'showtopic');
     }
     //-----------------------------------------
     // Ok, we're here.. delete the votes
     //-----------------------------------------
     $this->DB->delete('voters', "tid=" . $this->topic['tid'] . " and member_id=" . $this->memberData['member_id']);
     //-----------------------------------------
     // Remove our votes
     //-----------------------------------------
     $myVotes = IPSLib::safeUnserialize($voter['member_choices']);
     $pollData = IPSLib::safeUnserialize(stripslashes($this->topic['choices']));
     if (is_array($myVotes) and is_array($pollData)) {
         foreach ($myVotes as $_questionID => $data) {
             foreach ($data as $_choice) {
                 $pollData[$_questionID]['votes'][$_choice]--;
                 $pollData[$_questionID]['votes'][$_choice] = $pollData[$_questionID]['votes'][$_choice] < 0 ? 0 : $pollData[$_questionID]['votes'][$_choice];
             }
         }
     }
     //-----------------------------------------
     // Update
     //-----------------------------------------
     $update['votes'] = $this->topic['votes'] - 1;
     $update['votes'] = $update['votes'] < 0 ? 0 : $update['votes'];
     $update['choices'] = serialize($pollData);
     $this->DB->update('polls', $update, "tid=" . $this->topic['tid']);
     /* done */
     $this->registry->output->redirectScreen($this->lang->words['poll_vote_deleted'], $this->settings['base_url'] . "showtopic={$this->topic['tid']}&amp;st=" . $this->request['st'], $this->topic['title_seo'], 'showtopic');
 }
Esempio n. 2
0
 /**
  * Edit a post
  *
  * Usage:
  * $post->setForumID(1);
  * $post->setTopicID(5);
  * $post->setPostID(100);
  * $post->setAuthor( $member );
  * 
  * $post->setPostContent( "Hello [b]there![/b]" );
  * # Optional: No bbcode, etc parsing will take place
  * # $post->setPostContentPreFormatted( "Hello <b>there!</b>" );
  * $post->editPost();
  *
  * Exception Error Codes:
  * NO_POSTING_PPD       : No post ID set
  * NO_CONTENT        : No post content set
  * CONTENT_TOO_LONG  : Post is too long
  *
  * @return	mixed
  */
 public function editPost()
 {
     //-----------------------------------------
     // Global checks and functions
     //-----------------------------------------
     try {
         $this->globalSetUp();
     } catch (Exception $error) {
         $e = $error->getMessage();
         if ($e != 'NO_POSTING_PPD') {
             $this->_postErrors = $error->getMessage();
         }
     }
     if ($this->_bypassPermChecks !== TRUE && IPSMember::isOnModQueue($this->getAuthor()) === NULL) {
         $this->_postErrors = 'warnings_restrict_post_perm';
     }
     if (!$this->getPostContent() and !$this->getPostContentPreFormatted()) {
         $this->_postErrors = 'NO_CONTENT';
     }
     //-----------------------------------------
     // Get topic
     //-----------------------------------------
     try {
         $topic = $this->editSetUp();
     } catch (Exception $error) {
         $this->_postErrors = $error->getMessage();
     }
     //-----------------------------------------
     // Parse the post, and check for any errors.
     //-----------------------------------------
     $post = $this->compilePostData();
     //-----------------------------------------
     // Do we have a valid post?
     //-----------------------------------------
     if (strlen(trim(IPSText::removeControlCharacters(IPSText::br2nl($post['post'])))) < 1) {
         $this->_postErrors = 'NO_CONTENT';
     }
     if (IPSText::mbstrlen($post['post']) > $this->settings['max_post_length'] * 1024) {
         $this->_postErrors = 'CONTENT_TOO_LONG';
     }
     if ($this->_postErrors != "") {
         //-----------------------------------------
         // Show the form again
         //-----------------------------------------
         return FALSE;
     }
     //-----------------------------------------
     // Ajax specifics
     //-----------------------------------------
     if ($this->getIsAjax() === TRUE) {
         # Prevent polls from being edited
         $this->can_add_poll = 0;
         # Prevent titles from being edited
         $this->edit_title = 0;
         # Prevent open time from being edited
         $this->can_set_open_time = 0;
         # Prevent close time from being edited
         $this->can_set_close_time = 0;
         # Set Settings
         $this->setSettings(array('enableSignature' => $this->_originalPost['use_sig'] ? 1 : 0, 'enableEmoticons' => $this->_originalPost['use_emo'] ? 1 : 0, 'post_htmlstatus' => $this->getSettings('post_htmlstatus')));
         if (!$this->getAuthor('g_append_edit')) {
             $this->request['add_edit'] = ($this->_originalPost['append_edit'] or !$this->getAuthor('g_append_edit') ? 1 : 0);
         }
     }
     //-----------------------------------------
     // Compile the poll
     //-----------------------------------------
     if ($this->can_add_poll) {
         //-----------------------------------------
         // Load the poll from the DB
         //-----------------------------------------
         $this->poll_data = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'polls', 'where' => "tid=" . intval($topic['tid'])));
         $this->poll_answers = !empty($this->poll_data['choices']) && IPSLib::isSerialized($this->poll_data['choices']) ? IPSLib::safeUnserialize(stripslashes($this->poll_data['choices'])) : array();
     }
     //-----------------------------------------
     // Compile the poll
     //-----------------------------------------
     $this->poll_questions = $this->compilePollData();
     if ($this->_postErrors != "" or $this->getIsPreview() === TRUE) {
         //-----------------------------------------
         // Show the form again
         //-----------------------------------------
         return FALSE;
     }
     /* Got a topics table to update? */
     $updateTopicTable = array();
     //-----------------------------------------
     // Reset some data
     //-----------------------------------------
     $post['ip_address'] = $this->_originalPost['ip_address'];
     $post['topic_id'] = $this->_originalPost['topic_id'];
     $post['author_id'] = $this->_originalPost['author_id'];
     $post['post_date'] = $this->_originalPost['post_date'];
     $post['author_name'] = $this->_originalPost['author_name'];
     $post['queued'] = $this->_originalPost['queued'];
     $post['edit_time'] = $this->getDate() ? $this->getDate() : IPS_UNIX_TIME_NOW;
     $post['edit_name'] = $this->getAuthor('members_display_name');
     if ($this->_originalPost['new_topic'] == 1) {
         /* Tagging */
         if (isset($_POST['ipsTags'])) {
             $this->registry->tags->replace($_POST['ipsTags'], array('meta_id' => $topic['tid'], 'meta_parent_id' => $topic['forum_id'], 'member_id' => $this->memberData['member_id'], 'meta_visible' => $topic['approved']));
         }
         /* Like if not ajax edit */
         if (!IPS_IS_AJAX) {
             $this->addTopicToTracker($topic['tid']);
         }
         //-----------------------------------------
         // Update open and close times
         //-----------------------------------------
         if ($this->can_set_open_time and $this->times['open']) {
             $updateTopicTable['topic_open_time'] = intval($this->times['open']);
             if ($topic['topic_open_time'] and $this->times['open']) {
                 $updateTopicTable['state'] = 'closed';
                 if (IPS_UNIX_TIME_NOW > $topic['topic_open_time']) {
                     if (IPS_UNIX_TIME_NOW < $topic['topic_close_time']) {
                         $updateTopicTable['state'] = 'open';
                     }
                 }
             }
             if (!$this->times['open'] and $topic['topic_open_time']) {
                 if ($topic['state'] == 'closed') {
                     $updateTopicTable['state'] = 'open';
                 }
             }
         } else {
             if ($this->can_set_open_time and $topic['topic_open_time']) {
                 $updateTopicTable['topic_open_time'] = 0;
             }
         }
         if ($this->can_set_close_time and $this->times['close']) {
             $updateTopicTable['topic_close_time'] = intval($this->times['close']);
             //-----------------------------------------
             // Was a close time, but not now?
             //-----------------------------------------
             if (!$this->times['close'] and $topic['topic_close_time']) {
                 if ($topic['state'] == 'closed') {
                     $updateTopicTable['state'] = 'open';
                 }
             }
         } else {
             if ($this->can_set_close_time and $topic['topic_close_time']) {
                 $updateTopicTable['topic_close_time'] = 0;
             }
         }
         if ($this->edit_title) {
             if ($this->getForumID() != $topic['forum_id']) {
                 $updateTopicTable['forum_id'] = $this->getForumID();
             }
         }
     }
     //-----------------------------------------
     // Update poll
     //-----------------------------------------
     if ($this->can_add_poll) {
         if (is_array($this->poll_questions) and count($this->poll_questions)) {
             $poll_only = 0;
             if ($this->settings['ipb_poll_only'] and $this->request['poll_only'] == 1) {
                 $poll_only = 1;
             }
             $poll_view_voters = !$this->poll_data['votes'] ? $this->request['poll_view_voters'] : $this->poll_data['poll_view_voters'];
             if ($topic['poll_state']) {
                 $_pollData = array('votes' => intval($this->poll_total_votes), 'choices' => addslashes(serialize($this->poll_questions)), 'poll_question' => IPSText::stripAttachTag($this->request['poll_question']), 'poll_only' => $poll_only, 'poll_view_voters' => intval($poll_view_voters));
                 /* Data Hook Location */
                 IPSLib::doDataHooks($_pollData, 'editPostUpdatePoll');
                 $this->DB->update('polls', $_pollData, 'tid=' . $topic['tid']);
                 if ($this->poll_data['choices'] != serialize($this->poll_questions) or $this->poll_data['votes'] != intval($this->poll_total_votes)) {
                     $this->DB->insert('moderator_logs', array('forum_id' => $this->getForumData('id'), 'topic_id' => $topic['tid'], 'post_id' => $this->_originalPost['pid'], 'member_id' => $this->getAuthor('member_id'), 'member_name' => $this->getAuthor('members_display_name'), 'ip_address' => $this->ip_address, 'http_referer' => htmlspecialchars(my_getenv('HTTP_REFERER')), 'ctime' => IPS_UNIX_TIME_NOW, 'topic_title' => $topic['title'], 'action' => $this->lang->words['edited_poll'], 'query_string' => htmlspecialchars(my_getenv('QUERY_STRING'))));
                 }
             } else {
                 $_pollData = array('tid' => $topic['tid'], 'forum_id' => $this->getForumData('id'), 'start_date' => IPS_UNIX_TIME_NOW, 'choices' => addslashes(serialize($this->poll_questions)), 'starter_id' => $this->getAuthor('member_id'), 'votes' => 0, 'poll_question' => IPSText::stripAttachTag($this->request['poll_question']), 'poll_only' => $poll_only, 'poll_view_voters' => intval($poll_view_voters));
                 /* Data Hook Location */
                 IPSLib::doDataHooks($_pollData, 'editPostAddPoll');
                 $this->DB->insert('polls', $_pollData);
                 $this->DB->insert('moderator_logs', array('forum_id' => $this->getForumData('id'), 'topic_id' => $topic['tid'], 'post_id' => $this->_originalPost['pid'], 'member_id' => $this->getAuthor('member_id'), 'member_name' => $this->getAuthor('members_display_name'), 'ip_address' => $this->ip_address, 'http_referer' => htmlspecialchars(my_getenv('HTTP_REFERER')), 'ctime' => IPS_UNIX_TIME_NOW, 'topic_title' => $topic['title'], 'action' => sprintf($this->lang->words['added_poll'], $this->request['poll_question']), 'query_string' => htmlspecialchars(my_getenv('QUERY_STRING'))));
                 /* Update topics table later */
                 $updateTopicTable['poll_state'] = 1;
                 $updateTopicTable['last_vote'] = 0;
             }
         } else {
             /* Remove the poll */
             $this->DB->delete('polls', 'tid=' . $topic['tid']);
             $this->DB->delete('voters', 'tid=' . $topic['tid']);
             /* Update topics table later */
             $updateTopicTable['poll_state'] = 0;
             $updateTopicTable['last_vote'] = 0;
         }
     }
     //-----------------------------------------
     // Update topic title?
     //-----------------------------------------
     if ($this->edit_title == 1) {
         //-----------------------------------------
         // Update topic title
         //-----------------------------------------
         if ($this->_topicTitle != "") {
             if ($this->_topicTitle != $topic['title'] or !$topic['title_seo']) {
                 $updateTopicTable['title'] = $this->_topicTitle;
                 $updateTopicTable['title_seo'] = IPSText::makeSeoTitle($this->_topicTitle);
                 $_forumUpdate = array();
                 if ($topic['tid'] == $this->getForumData('last_id')) {
                     $_forumUpdate['last_title'] = $updateTopicTable['title'];
                     $_forumUpdate['seo_last_title'] = $updateTopicTable['title_seo'];
                 }
                 if ($topic['tid'] == $this->getForumData('newest_id')) {
                     $_forumUpdate['newest_title'] = $updateTopicTable['title'];
                 }
                 if (count($_forumUpdate)) {
                     $this->DB->update('forums', $_forumUpdate, 'id=' . $this->getForumData('id'));
                 }
                 if ($this->moderator['edit_topic'] == 1 or $this->getAuthor('g_is_supmod') == 1) {
                     $this->DB->insert('moderator_logs', array('forum_id' => $this->getForumData('id'), 'topic_id' => $topic['tid'], 'post_id' => $this->_originalPost['pid'], 'member_id' => $this->getAuthor('member_id'), 'member_name' => $this->getAuthor('members_display_name'), 'ip_address' => $this->ip_address, 'http_referer' => htmlspecialchars(my_getenv('HTTP_REFERER')), 'ctime' => IPS_UNIX_TIME_NOW, 'topic_title' => $topic['title'], 'action' => sprintf($this->lang->words['edited_topic_title'], $topic['title'], $this->_topicTitle), 'query_string' => htmlspecialchars(my_getenv('QUERY_STRING'))));
                 }
             }
         }
     }
     //-----------------------------------------
     // Reason for edit?
     //-----------------------------------------
     if ($this->_bypassPermChecks or isset($this->moderator['edit_post']) && $this->moderator['edit_post'] or $this->getAuthor('g_is_supmod')) {
         $post['post_edit_reason'] = trim($this->request['post_edit_reason']);
     }
     //-----------------------------------------
     // Update the database (ib_forum_post)
     //-----------------------------------------
     $post['append_edit'] = 1;
     if ($this->_bypassPermChecks or $this->getAuthor('g_append_edit')) {
         if ($this->request['add_edit'] != 1) {
             $post['append_edit'] = 0;
         }
     }
     /* HTML Status */
     $post['post_htmlstate'] = $this->getSettings('post_htmlstatus');
     /* Typecast */
     $this->DB->setDataType('post_edit_reason', 'string');
     /* Data Hook Location */
     IPSLib::doDataHooks($post, 'editPostData');
     $this->DB->update('posts', $post, 'pid=' . $this->_originalPost['pid']);
     /* Got a topic to update? */
     $updateTopicTable['post_data'] = $post;
     $updateTopicTable['forum_data'] = $this->getForumData();
     IPSLib::doDataHooks($updateTopicTable, 'editPostTopicData');
     unset($updateTopicTable['post_data'], $updateTopicTable['forum_data']);
     // Remove added data
     if (count($updateTopicTable)) {
         $this->DB->update('topics', $updateTopicTable, 'tid=' . $topic['tid']);
     }
     /* remove saved content */
     if ($this->memberData['member_id']) {
         $this->editor->removeAutoSavedContent(array('member_id' => $this->memberData['member_id'], 'autoSaveKey' => 'edit-' . intval($this->_originalPost['pid'])));
     }
     /* Add to cache */
     IPSContentCache::update($this->_originalPost['pid'], 'post', $this->formatPostForCache($post['post']));
     /* Upload Attachments */
     $this->uploadAttachments($this->post_key, $this->_originalPost['pid']);
     //-----------------------------------------
     // Make attachments "permanent"
     //-----------------------------------------
     $this->makeAttachmentsPermanent($this->post_key, $this->_originalPost['pid'], 'post', array('topic_id' => $topic['tid']));
     //-----------------------------------------
     // Make sure paperclip symbol is OK
     //-----------------------------------------
     $this->recountTopicAttachments($topic['tid']);
     //-----------------------------------------
     // Leave data for other apps
     //-----------------------------------------
     $this->setTopicData($topic);
     $this->setPostData(array_merge($this->_originalPost, $post));
     return TRUE;
 }
Esempio n. 3
0
 /**
  * UserCP Save Form: Customize
  *
  * @return	array	Errors
  */
 public function saveCustomize()
 {
     /* Init */
     $errors = array();
     $custom = array();
     $bg_nix = trim($this->request['bg_nix']);
     $bg_url = trim($this->request['bg_url']);
     $bg_tile = intval($this->request['bg_tile']);
     $bg_color = trim(str_replace('#', '', $this->request['bg_color']));
     /* reset custom */
     $custom = IPSLib::safeUnserialize($this->memberData['pp_customization']);
     /* Bug #21578 */
     if (!$bg_color && $custom['bg_color']) {
         $bg_color = $custom['bg_color'];
     }
     /* Delete all? */
     if ($bg_nix) {
         /* reset array */
         $custom = array('bg_url' => '', 'type' => '', 'bg_color' => '', 'bg_tile' => '');
         /* remove bg images */
         IPSMember::getFunction()->removeUploadedBackgroundImages($this->memberData['member_id']);
     } else {
         if ($bg_url and $this->memberData['gbw_allow_url_bgimage']) {
             /* Check */
             if (!stristr($bg_url, 'http://') or preg_match('#\\(\\*#', $bg_url)) {
                 return array(0 => $this->lang->words['pp_bgimg_url_bad']);
             }
             $image_extension = strtolower(pathinfo($bg_url, PATHINFO_EXTENSION));
             if (!in_array($image_extension, array('png', 'jpg', 'gif', 'jpeg'))) {
                 return array(0 => $this->lang->words['pp_bgimg_ext_bad']);
             }
             $custom['bg_url'] = $bg_url;
             $custom['type'] = 'url';
         } else {
             if ($this->memberData['gbw_allow_upload_bgimage']) {
                 /* Load more lang strings */
                 $this->registry->class_localization->loadLanguageFile(array('public_profile'), 'members');
                 /* Upload img */
                 $img = IPSMember::getFunction()->uploadBackgroundImage();
                 if ($img['status'] == 'fail') {
                     return array(0 => sprintf($this->lang->words['pp_' . $img['error']], $img['maxSize']));
                 } else {
                     if ($img['final_location']) {
                         $custom['bg_url'] = $img['final_location'];
                         $custom['type'] = 'upload';
                     }
                 }
             }
         }
     }
     /* BG color */
     $custom['bg_color'] = $bg_nix ? '' : IPSText::alphanumericalClean($bg_color);
     /* Tile */
     $custom['bg_tile'] = $bg_nix ? '' : $bg_tile;
     /* Save it */
     if (!$this->memberData['bw_disable_customization'] and $this->memberData['gbw_allow_customization']) {
         IPSMember::save($this->memberData['member_id'], array('extendedProfile' => array('pp_profile_update' => IPS_UNIX_TIME_NOW, 'pp_customization' => serialize($custom))));
     }
     return TRUE;
 }
 /**
  * Parse a member for display
  *
  * @param	mixed	Either array of member data, or member ID to self load
  * @param	array 	Array of flags to parse: 'signature', 'customFields', 'warn'
  * @return	array 	Parsed member data
  */
 public static function buildDisplayData($member, $_parseFlags = array())
 {
     $_NOW = IPSDebug::getMemoryDebugFlag();
     /* test to see if member_title has been passed */
     if (isset($member['member_title'])) {
         $member['title'] = $member['member_title'];
     }
     //-----------------------------------------
     // Figure out parse flags
     //-----------------------------------------
     $parseFlags = array('signature' => isset($_parseFlags['signature']) ? $_parseFlags['signature'] : 0, 'customFields' => isset($_parseFlags['customFields']) ? $_parseFlags['customFields'] : 0, 'reputation' => isset($_parseFlags['reputation']) ? $_parseFlags['reputation'] : 1, 'warn' => isset($_parseFlags['warn']) ? $_parseFlags['warn'] : 1, 'cfSkinGroup' => isset($_parseFlags['cfSkinGroup']) ? $_parseFlags['cfSkinGroup'] : '', 'cfGetGroupData' => isset($_parseFlags['cfGetGroupData']) ? $_parseFlags['cfGetGroupData'] : '', 'cfLocation' => isset($_parseFlags['cfLocation']) ? $_parseFlags['cfLocation'] : '', 'checkFormat' => isset($_parseFlags['checkFormat']) ? $_parseFlags['checkFormat'] : 0, 'photoTagSize' => isset($_parseFlags['photoTagSize']) ? $_parseFlags['photoTagSize'] : false, 'spamStatus' => isset($_parseFlags['spamStatus']) ? $_parseFlags['spamStatus'] : 0);
     if (isset($_parseFlags['__all__'])) {
         foreach ($parseFlags as $k => $v) {
             if (in_array($k, array('cfSkinGroup', 'cfGetGroupData', 'photoTagSize'))) {
                 continue;
             }
             $parseFlags[$k] = 1;
         }
         $parseFlags['spamStatus'] = !empty($parseFlags['spamStatus']) ? 1 : 0;
     }
     //-----------------------------------------
     // Load the member?
     //-----------------------------------------
     if (!is_array($member) and ($member == intval($member) and $member > 0)) {
         $member = self::load($member, 'all');
     }
     //-----------------------------------------
     // Caching
     //-----------------------------------------
     static $buildMembers = array();
     $_key = $member['member_id'];
     $_arr = serialize($member);
     foreach ($parseFlags as $_flag => $_value) {
         $_key .= $_flag . $_value;
     }
     $_key = md5($_key . $_arr);
     if (isset($buildMembers[$_key])) {
         IPSDebug::setMemoryDebugFlag("IPSMember::buildDisplayData: " . $member['member_id'] . " - CACHED", $_NOW);
         return $buildMembers[$_key];
     }
     //-----------------------------------------
     // Basics
     //-----------------------------------------
     if (!$member['member_group_id']) {
         $member['member_group_id'] = ipsRegistry::$settings['guest_group'];
     }
     /* Unpack bitwise if required */
     if (!isset($member['bw_is_spammer'])) {
         $member = self::buildBitWiseOptions($member);
     }
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $rank_cache = ipsRegistry::cache()->getCache('ranks');
     $group_cache = ipsRegistry::cache()->getCache('group_cache');
     $group_name = self::makeNameFormatted($group_cache[$member['member_group_id']]['g_title'], $member['member_group_id']);
     $pips = 0;
     $topic_id = intval(isset(ipsRegistry::$request['t']) ? ipsRegistry::$request['t'] : 0);
     $forum_id = intval(isset(ipsRegistry::$request['f']) ? ipsRegistry::$request['f'] : 0);
     //-----------------------------------------
     // SEO Name
     //-----------------------------------------
     $member['members_seo_name'] = self::fetchSeoName($member);
     $member['_group_formatted'] = $group_name;
     //-----------------------------------------
     // Ranks
     //-----------------------------------------
     if (is_array($rank_cache) and count($rank_cache)) {
         foreach ($rank_cache as $k => $v) {
             if ($member['posts'] >= $v['POSTS']) {
                 if (empty($member['title'])) {
                     $member['title'] = $v['TITLE'];
                 }
                 $pips = $v['PIPS'];
                 break;
             }
         }
     }
     //-----------------------------------------
     // Group image
     //-----------------------------------------
     $member['member_rank_img'] = '';
     $member['member_rank_img_i'] = '';
     if ($group_cache[$member['member_group_id']]['g_icon']) {
         $_img = $group_cache[$member['member_group_id']]['g_icon'];
         if (substr($_img, 0, 4) != 'http' and strpos($_img, '{style_images_url}') === false) {
             $_img = ipsRegistry::$settings['_original_base_url'] . '/' . ltrim($_img, '/');
         }
         $member['member_rank_img_i'] = 'img';
         $member['member_rank_img'] = $_img;
     } else {
         if ($pips and $member['member_id']) {
             if (is_numeric($pips)) {
                 for ($i = 1; $i <= $pips; ++$i) {
                     $member['member_rank_img_i'] = 'pips';
                     $member['member_rank_img'] = $member['member_rank_img'] . ipsRegistry::getClass('output')->getReplacement('pip_pip');
                 }
             } else {
                 $member['member_rank_img_i'] = 'img';
                 $member['member_rank_img'] = ipsRegistry::$settings['public_dir'] . 'style_extra/team_icons/' . $pips;
             }
         }
     }
     //-----------------------------------------
     // Moderator data
     //-----------------------------------------
     if (($parseFlags['spamStatus'] or $parseFlags['warn']) and $member['member_id']) {
         /* Possible forums class isn't init at this point */
         if (!ipsRegistry::isClassLoaded('class_forums')) {
             try {
                 $viewingMember = IPSMember::setUpModerator(ipsRegistry::member()->fetchMemberData());
                 ipsRegistry::member()->setProperty('forumsModeratorData', $viewingMember['forumsModeratorData']);
             } catch (Exception $error) {
                 IPS_exception_error($error);
             }
         }
         $moderator = ipsRegistry::member()->getProperty('forumsModeratorData');
     }
     $forum_id = isset(ipsRegistry::$request['f']) ? intval(ipsRegistry::$request['f']) : 0;
     //-----------------------------------------
     // Spammer status
     //-----------------------------------------
     if ($parseFlags['spamStatus'] and $member['member_id'] and ipsRegistry::member()->getProperty('member_id')) {
         /* Defaults */
         $member['spamStatus'] = NULL;
         $member['spamImage'] = NULL;
         if (!empty($moderator[$forum_id]['bw_flag_spammers']) or ipsRegistry::member()->getProperty('g_is_supmod')) {
             if (!ipsRegistry::$settings['warn_on'] or !IPSMember::isInGroup($member, explode(',', ipsRegistry::$settings['warn_protected']))) {
                 if ($member['bw_is_spammer']) {
                     $member['spamStatus'] = TRUE;
                 } else {
                     $member['spamStatus'] = FALSE;
                 }
             }
         }
     }
     //-----------------------------------------
     // Warny porny?
     //-----------------------------------------
     $member['show_warn'] = FALSE;
     if ($parseFlags['warn'] and $member['member_id']) {
         if (ipsRegistry::$settings['warn_on'] and !IPSMember::isInGroup($member, explode(',', ipsRegistry::$settings['warn_protected']))) {
             /* Warnings */
             if (!empty($moderator[$forum_id]['allow_warn']) or ipsRegistry::member()->getProperty('g_is_supmod') or ipsRegistry::$settings['warn_show_own'] and ipsRegistry::member()->getProperty('member_id') == $member['member_id']) {
                 $member['show_warn'] = TRUE;
             } else {
                 if (is_array($moderator) && count($moderator) && !$forum_id) {
                     foreach ($moderator as $forum) {
                         if ($forum['allow_warn']) {
                             $member['show_warn'] = TRUE;
                             break;
                         }
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Profile fields stuff
     //-----------------------------------------
     $member['custom_fields'] = "";
     if ($parseFlags['customFields'] == 1 and $member['member_id']) {
         if (isset(self::$_parsedCustomFields[$member['member_id']])) {
             $member['custom_fields'] = self::$_parsedCustomFields[$member['member_id']];
             if ($parseFlags['cfGetGroupData'] and isset(self::$_parsedCustomGroups[$member['member_id']]) and is_array(self::$_parsedCustomGroups[$member['member_id']])) {
                 $member['custom_field_groups'] = self::$_parsedCustomGroups[$member['member_id']];
             } else {
                 if ($parseFlags['cfGetGroupData']) {
                     $member['custom_field_groups'] = self::$custom_fields_class->fetchGroupTitles();
                     self::$_parsedCustomGroups[$member['member_id']] = $member['custom_field_groups'];
                 }
             }
         } else {
             if (!is_object(self::$custom_fields_class)) {
                 $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
                 self::$custom_fields_class = new $classToLoad();
             }
             if (self::$custom_fields_class) {
                 self::$custom_fields_class->member_data = $member;
                 self::$custom_fields_class->skinGroup = $parseFlags['cfSkinGroup'];
                 self::$custom_fields_class->initData();
                 self::$custom_fields_class->parseToView($parseFlags['checkFormat'], $parseFlags['cfLocation']);
                 $member['custom_fields'] = self::$custom_fields_class->out_fields;
                 self::$_parsedCustomFields[$member['member_id']] = $member['custom_fields'];
                 if ($parseFlags['cfGetGroupData']) {
                     $member['custom_field_groups'] = self::$custom_fields_class->fetchGroupTitles();
                     self::$_parsedCustomGroups[$member['member_id']] = $member['custom_field_groups'];
                 }
             }
         }
     }
     //-----------------------------------------
     // Profile photo
     //-----------------------------------------
     $member = self::buildProfilePhoto($member);
     if (!empty($parseFlags['photoTagSize'])) {
         $parseFlags['photoTagSize'] = is_array($parseFlags['photoTagSize']) ? $parseFlags['photoTagSize'] : array($parseFlags['photoTagSize']);
         foreach ($parseFlags['photoTagSize'] as $size) {
             $member['photoTag' . ucfirst($size)] = self::buildPhotoTag($member, $size);
         }
     }
     //-----------------------------------------
     // Signature bbcode
     //-----------------------------------------
     if (!empty($member['signature']) and $parseFlags['signature']) {
         if (isset(self::$_parsedSignatures[$member['member_id']])) {
             $member['signature'] = self::$_parsedSignatures[$member['member_id']];
         } else {
             if ($member['cache_content']) {
                 $member['signature'] = '<!--signature-cached-' . gmdate('r', $member['cache_updated']) . '-->' . $member['cache_content'];
             } else {
                 /* Grab the parser file */
                 if (self::$_sigParser === null) {
                     /* Load parser */
                     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
                     self::$_sigParser = new $classToLoad();
                 }
                 /* set up parser */
                 self::$_sigParser->set(array('memberData' => $member, 'parseBBCode' => 1, 'parseHtml' => $group_cache[$member['member_group_id']]['g_dohtml'] && $member['bw_html_sig'], 'parseEmoticons' => 1, 'parseArea' => 'signatures'));
                 $member['signature'] = self::$_sigParser->display($member['signature']);
                 IPSContentCache::update($member['member_id'], 'sig', $member['signature']);
             }
             self::$_parsedSignatures[$member['member_id']] = $member['signature'];
         }
     }
     //-----------------------------------------
     // If current session, reset last_activity
     //-----------------------------------------
     if (!empty($member['running_time'])) {
         $member['last_activity'] = $member['running_time'] > $member['last_activity'] ? $member['running_time'] : $member['last_activity'];
     }
     //-----------------------------------------
     // Online?
     //-----------------------------------------
     $time_limit = time() - ipsRegistry::$settings['au_cutoff'] * 60;
     $member['_online'] = 0;
     $bypass_anon = ipsRegistry::member()->getProperty('g_access_cp') ? 1 : 0;
     list($be_anon, $loggedin) = explode('&', empty($member['login_anonymous']) ? '0&0' : $member['login_anonymous']);
     /* Is not anon but the group might be forced to? */
     if (empty($be_anon) && self::isLoggedInAnon($member)) {
         $be_anon = 1;
     }
     /* Finally set the online flag */
     if (($member['last_visit'] > $time_limit or $member['last_activity'] > $time_limit) and ($be_anon != 1 or $bypass_anon == 1) and $loggedin == 1) {
         $member['_online'] = 1;
     }
     //-----------------------------------------
     // Last Active
     //-----------------------------------------
     $member['_last_active'] = ipsRegistry::getClass('class_localization')->getDate($member['last_activity'], 'SHORT');
     // Member last logged in anonymous ?
     if ($be_anon == 1 && !ipsRegistry::member()->getProperty('g_access_cp')) {
         $member['_last_active'] = ipsRegistry::getClass('class_localization')->words['private'];
     }
     //-----------------------------------------
     // Rating
     //-----------------------------------------
     $member['_pp_rating_real'] = intval($member['pp_rating_real']);
     //-----------------------------------------
     // Display name formatted
     //-----------------------------------------
     $member['members_display_name_formatted'] = self::makeNameFormatted($member['members_display_name'], $member['member_id'] ? $member['member_group_id'] : ipsRegistry::$settings['guest_group']);
     //-----------------------------------------
     // Long display names
     //-----------------------------------------
     $member['members_display_name_short'] = IPSText::truncate($member['members_display_name'], 16);
     //-----------------------------------------
     // Reputation
     //-----------------------------------------
     $member['pp_reputation_points'] = $member['pp_reputation_points'] ? $member['pp_reputation_points'] : 0;
     if ($parseFlags['reputation'] and $member['member_id']) {
         if (!ipsRegistry::isClassLoaded('repCache')) {
             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/class_reputation_cache.php', 'classReputationCache');
             ipsRegistry::setClass('repCache', new $classToLoad());
         }
         $member['author_reputation'] = ipsRegistry::getClass('repCache')->getReputation($member['pp_reputation_points']);
     }
     //-----------------------------------------
     // Other stuff not worthy of individual comments
     //-----------------------------------------
     $member['members_profile_views'] = isset($member['members_profile_views']) ? $member['members_profile_views'] : 0;
     /* BG customization */
     if ($member['pp_customization'] and !empty($member['gbw_allow_customization']) and !$member['bw_disable_customization']) {
         $member['customization'] = IPSLib::safeUnserialize($member['pp_customization']);
         if (is_array($member['customization'])) {
             /* Figure out BG URL */
             if ($member['customization']['type'] == 'url' and $member['customization']['bg_url'] and $member['gbw_allow_url_bgimage']) {
                 $member['customization']['_bgUrl'] = $member['customization']['bg_url'];
             } else {
                 if ($member['customization']['type'] == 'upload' and $member['customization']['bg_url'] and $member['gbw_allow_upload_bgimage']) {
                     $member['customization']['_bgUrl'] = ipsRegistry::$settings['upload_url'] . '/' . $member['customization']['bg_url'];
                 } else {
                     if ($member['customization']['bg_color']) {
                         $member['customization']['type'] = 'bgColor';
                     }
                 }
             }
         }
     }
     /* Title is ambigious */
     $member['member_title'] = $member['title'];
     IPSDebug::setMemoryDebugFlag("IPSMember::buildDisplayData: " . $member['member_id'] . " - Completed", $_NOW);
     $buildMembers[$_key] = $member;
     return $member;
 }
 /**
  * Generates the poll box
  *
  * @param	string	Form type (new/edit/reply)
  * @return	string	HTML
  * @author	MattMecham
  */
 protected function _generatePollBox($formType)
 {
     if ($this->can_add_poll) {
         //-----------------------------------------
         // Did someone hit preview / do we have
         // post info?
         //-----------------------------------------
         $poll_questions = array();
         $poll_question = "";
         $poll_view_voters = 0;
         $poll_choices = array();
         $show_open = 0;
         $is_mod = 0;
         $poll_votes = array();
         $poll_only = 0;
         $poll_multi = array();
         if ($this->settings['ipb_poll_only'] and ipsRegistry::$request['poll_only'] and ipsRegistry::$request['poll_only'] == 1) {
             $poll_only = 1;
         }
         if (isset($_POST['question']) and is_array($_POST['question']) and count($_POST['question'])) {
             foreach ($_POST['question'] as $id => $question) {
                 $poll_questions[$id] = IPSText::parseCleanValue($question);
             }
             $poll_question = ipsRegistry::$request['poll_question'];
             $show_open = 1;
         }
         if (isset($_POST['multi']) and is_array($_POST['multi']) and count($_POST['multi'])) {
             foreach ($_POST['multi'] as $id => $checked) {
                 $poll_multi[$id] = $checked;
             }
         }
         if (isset($_POST['choice']) and is_array($_POST['choice']) and count($_POST['choice'])) {
             foreach ($_POST['choice'] as $id => $choice) {
                 $poll_choices[$id] = IPSText::parseCleanValue($choice);
             }
         }
         if ($formType == 'edit') {
             if (isset($_POST['votes']) && is_array($_POST['votes']) and count($_POST['votes'])) {
                 foreach ($_POST['votes'] as $id => $vote) {
                     $poll_votes[$id] = $vote;
                 }
             }
         }
         if ($formType == 'edit' and (!isset($_POST['question']) or !is_array($_POST['question']) or !count($_POST['question']) or $this->getIsPreview())) {
             //-----------------------------------------
             // Load the poll from the DB
             //-----------------------------------------
             $this->poll_data = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'polls', 'where' => "tid=" . $this->getTopicID()));
             $this->poll_answers = IPSLib::safeUnserialize(stripslashes($this->poll_data['choices']));
             if (!is_array($this->poll_answers) or !count($this->poll_answers)) {
                 $this->poll_answers = IPSLib::safeUnserialize(preg_replace('!s:(\\d+):"(.*?)";!se', "'s:'.strlen('\$2').':\"\$2\";'", stripslashes($this->poll_data['choices'])));
             }
             if (!is_array($this->poll_answers) or !count($this->poll_answers)) {
                 $this->poll_answers = array();
             }
             //-----------------------------------------
             // Lezz go
             //-----------------------------------------
             foreach ($this->poll_answers as $question_id => $data) {
                 if (!$data['question'] or !is_array($data['choice'])) {
                     continue;
                 }
                 $poll_questions[$question_id] = $data['question'];
                 $poll_multi[$question_id] = isset($data['multi']) ? intval($data['multi']) : 0;
                 foreach ($data['choice'] as $choice_id => $text) {
                     $poll_choices[$question_id . '_' . $choice_id] = stripslashes($text);
                     $poll_votes[$question_id . '_' . $choice_id] = intval($data['votes'][$choice_id]);
                 }
             }
             $poll_only = 0;
             if ($this->settings['ipb_poll_only'] and $this->poll_data['poll_only'] == 1) {
                 $poll_only = 1;
             }
             $poll_view_voters = $this->poll_data['poll_view_voters'];
             $poll_question = $this->poll_data['poll_question'];
             $show_open = $this->poll_data['choices'] ? 1 : 0;
             $is_mod = $this->can_add_poll_mod;
         } else {
             $poll_view_voters = $this->request['poll_view_voters'];
         }
         return $this->registry->getClass('output')->getTemplate('post')->pollBox(array('max_poll_questions' => $this->max_poll_questions, 'max_poll_choices' => $this->max_poll_choices_per_question, 'poll_questions' => IPSText::simpleJsonEncode($poll_questions), 'poll_choices' => IPSText::simpleJsonEncode($poll_choices), 'poll_votes' => IPSText::simpleJsonEncode($poll_votes), 'show_open' => $show_open, 'poll_question' => $poll_question, 'is_mod' => $is_mod, 'poll_multi' => json_encode($poll_multi), 'poll_only' => $poll_only, 'poll_view_voters' => $poll_view_voters, 'poll_total_votes' => intval($this->poll_data['votes']), 'poll_data' => $this->poll_data, 'poll_answers' => $this->poll_answers));
     }
     return '';
 }
Esempio n. 6
0
 /**
  * Generate the Poll output
  *
  * @return	string
  */
 public function _generatePollOutput()
 {
     /* Init */
     $topicData = $this->registry->getClass('topics')->getTopicData();
     $forumData = $this->forumClass->getForumById($topicData['forum_id']);
     $showResults = 0;
     $pollData = array();
     //-----------------------------------------
     // Get the poll information...
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'polls', 'where' => 'tid=' . $topicData['tid']));
     $this->DB->execute();
     $poll = $this->DB->fetch();
     //-----------------------------------------
     // check we have a poll
     //-----------------------------------------
     if (!$poll['pid']) {
         return array('html' => '', 'poll' => '');
     }
     //-----------------------------------------
     // Do we have a poll question?
     //-----------------------------------------
     if (!$poll['poll_question']) {
         $poll['poll_question'] = $topicData['title'];
     }
     //-----------------------------------------
     // Poll only?
     //-----------------------------------------
     if ($poll['poll_only'] == 1) {
         $this->registry->getClass('topics')->setTopicData('poll_only', true);
     }
     //-----------------------------------------
     // Additional Poll Vars
     //-----------------------------------------
     $poll['_totalVotes'] = 0;
     $poll['_memberVoted'] = 0;
     $memberChoices = array();
     //-----------------------------------------
     // Have we voted in this poll?
     //-----------------------------------------
     /* Save a join @link http://community.invisionpower.com/tracker/issue-35773-pollsvoters-voters-table-joining-to-million-plus-rows/ */
     if ($poll['poll_view_voters'] and $this->settings['poll_allow_public']) {
         $this->DB->build(array('select' => 'v.*', 'from' => array('voters' => 'v'), 'where' => 'v.tid=' . $topicData['tid'], 'add_join' => array(array('select' => 'm.*', 'from' => array('members' => 'm'), 'where' => 'm.member_id=v.member_id', 'type' => 'left'))));
     } else {
         $this->DB->build(array('select' => '*', 'from' => 'voters', 'where' => 'tid=' . $topicData['tid']));
     }
     $this->DB->execute();
     while ($voter = $this->DB->fetch()) {
         $poll['_totalVotes']++;
         if ($voter['member_id'] == $this->memberData['member_id']) {
             $poll['_memberVoted'] = 1;
         }
         /* Member choices */
         if ($voter['member_choices'] and ($poll['poll_view_voters'] and $this->settings['poll_allow_public'] or $voter['member_id'] == $this->memberData['member_id'])) {
             $_choices = IPSLib::safeUnserialize($voter['member_choices']);
             if (is_array($_choices) and count($_choices)) {
                 $memberData = array('member_id' => $voter['member_id'], 'members_seo_name' => $voter['member_id'] == $this->memberData['member_id'] ? $this->memberData['members_seo_name'] : $voter['members_seo_name'], 'members_display_name' => $voter['member_id'] == $this->memberData['member_id'] ? $this->memberData['members_display_name'] : $voter['members_display_name'], 'members_colored_name' => str_replace('"', '\\"', $voter['member_id'] == $this->memberData['member_id'] ? IPSMember::makeNameFormatted($this->memberData['members_display_name'], $this->memberData['member_group_id']) : IPSMember::makeNameFormatted($voter['members_display_name'], $voter['member_group_id'])), '_last' => 0);
                 foreach ($_choices as $_questionID => $data) {
                     foreach ($data as $_choice) {
                         $memberChoices[$_questionID][$_choice][$voter['member_id']] = $memberData;
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Already Voted
     //-----------------------------------------
     if ($poll['_memberVoted']) {
         $showResults = 1;
     }
     //-----------------------------------------
     // Created poll and can't vote in it
     //-----------------------------------------
     if ($poll['starter_id'] == $this->memberData['member_id'] and $this->settings['allow_creator_vote'] != 1) {
         $showResults = 1;
     }
     //-----------------------------------------
     // Guest, but can view results without voting
     //-----------------------------------------
     if (!$this->memberData['member_id'] and $this->settings['allow_result_view']) {
         $showResults = 1;
     }
     //-----------------------------------------
     // is the topic locked?
     //-----------------------------------------
     if ($topicData['state'] == 'closed') {
         $showResults = 1;
     }
     //-----------------------------------------
     // Can we see the poll before voting?
     //-----------------------------------------
     if ($this->settings['allow_result_view'] == 1 and $this->request['mode'] == 'show') {
         $showResults = 1;
     }
     //-----------------------------------------
     // Stop the parser killing images
     // 'cos there are too many
     //-----------------------------------------
     $tmp_max_images = $this->settings['max_images'];
     $this->settings['max_images'] = 0;
     //-----------------------------------------
     // Parse it
     //-----------------------------------------
     $poll_answers = IPSLib::safeUnserialize(stripslashes($poll['choices']));
     if (!is_array($poll_answers) or !count($poll_answers)) {
         $poll_answers = IPSLib::safeUnserialize(preg_replace('!s:(\\d+):"(.*?)";!se', "'s:'.strlen('\$2').':\"\$2\";'", stripslashes($poll['choices'])));
     }
     if (!is_array($poll_answers) or !count($poll_answers)) {
         $poll_answers = '';
     }
     reset($poll_answers);
     foreach ($poll_answers as $id => $data) {
         if (!is_array($data['choice']) or !count($data['choice'])) {
             continue;
         }
         //-----------------------------------------
         // Get the question
         //-----------------------------------------
         $pollData[$id]['question'] = $data['question'];
         $tv_poll = 0;
         # Get total votes for this question
         if (is_array($poll_answers[$id]['votes']) and count($poll_answers[$id]['votes'])) {
             foreach ($poll_answers[$id]['votes'] as $number) {
                 $tv_poll += intval($number);
             }
         }
         //-----------------------------------------
         // Get the choices for this question
         //-----------------------------------------
         foreach ($data['choice'] as $choice_id => $text) {
             $choiceData = array();
             $choice = $text;
             $voters = array();
             # Get total votes for this question -> choice
             $votes = intval($data['votes'][$choice_id]);
             if (strlen($choice) < 1) {
                 continue;
             }
             if (stristr($choice, '[img') || stristr($choice, '[url') || stristr($text, '[sharedmedia')) {
                 if (!is_object($this->_textParser)) {
                     /* Load parser */
                     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
                     $this->_textParser = new $classToLoad();
                 }
                 $choice = $this->_textParser->parsePollTags($choice);
             }
             if ($showResults) {
                 $percent = $votes == 0 ? 0 : $votes / $tv_poll * 100;
                 $percent = sprintf('%.2F', $percent);
                 $width = $percent > 0 ? intval($percent * 2) : 0;
                 /* Voters */
                 if ($memberChoices[$id][$choice_id]) {
                     $voters = $memberChoices[$id][$choice_id];
                     $_tmp = $voters;
                     $lastDude = array_pop($_tmp);
                     $voters[$lastDude['member_id']]['_last'] = 1;
                 }
                 $pollData[$id]['choices'][$choice_id] = array('votes' => $votes, 'choice' => $choice, 'percent' => $percent, 'width' => $width, 'voters' => $voters);
             } else {
                 $pollData[$id]['choices'][$choice_id] = array('type' => !empty($data['multi']) ? 'multi' : 'single', 'votes' => $votes, 'choice' => $choice);
             }
         }
     }
     $_editPoll = $this->registry->getClass('topics')->canEditPost(array('member_id' => $topicData['starter_id'], 'post_date' => $topicData['start_date']));
     $html = $this->registry->output->getTemplate('topic')->pollDisplay($poll, $topicData, $forumData, $pollData, $showResults, $_editPoll);
     $this->settings['max_images'] = $tmp_max_images;
     return array('html' => $html, 'poll' => $poll);
 }