Example #1
0
 /**
  * Feturn HTML block
  *
  * @param	array		Member information
  * @return	string		HTML block
  */
 public function return_html_block($member = array())
 {
     //-----------------------------------------
     // Got a member?
     //-----------------------------------------
     if (!is_array($member) or !count($member)) {
         return $this->registry->getClass('output')->getTemplate('profile')->tabNoContent('err_no_aboutme_to_show');
     }
     $friends = array();
     //-----------------------------------------
     // Grab the friends
     //-----------------------------------------
     /* How many friends do we have? */
     $count = $this->DB->buildAndFetch(array('select' => 'count(*) as dracula', 'from' => 'profile_friends', 'where' => 'friends_member_id=' . $member['member_id'] . ' AND friends_approved=1'));
     /* Sort out pagination */
     $st = intval($this->request['st']) >= 0 ? intval($this->request['st']) : 0;
     $pagination = $this->registry->output->generatePagination(array('totalItems' => $count['dracula'], 'itemsPerPage' => self::FRIENDS_PER_PAGE, 'currentStartValue' => $st, 'baseUrl' => "showuser={$member['member_id']}&tab=friends", 'seoTemplate' => 'showuser', 'seoTitle' => $member['members_seo_name']));
     /* Get em! */
     $queryData = array('select' => 'f.*', 'from' => array('profile_friends' => 'f'), 'where' => 'f.friends_member_id=' . $member['member_id'] . ' AND f.friends_approved=1 AND m.member_banned=0 AND ( ! ' . IPSBWOptions::sql('bw_is_spammer', 'members_bitoptions', 'members', 'global', 'has') . ')', 'add_join' => array(1 => array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=f.friends_friend_id', 'type' => 'left'), 2 => array('select' => 'm.*', 'from' => array('members' => 'm'), 'where' => 'm.member_id=f.friends_friend_id', 'type' => 'left')));
     // Ordering is bad because it causes a filesort, but if they have more than 100 members, we're going to have
     // to order so we can paginate
     if ($count['dracula'] > self::FRIENDS_PER_PAGE) {
         $queryData['order'] = 'm.members_display_name';
         $queryData['limit'] = array($st, self::FRIENDS_PER_PAGE);
     }
     $this->DB->build($queryData);
     $outer = $this->DB->execute();
     //-----------------------------------------
     // Get and store...
     //-----------------------------------------
     while ($row = $this->DB->fetch($outer)) {
         if ($row['member_id']) {
             $friends[IPSText::mbstrtolower($row['members_display_name'])] = IPSMember::buildDisplayData($row, 0);
         }
     }
     ksort($friends);
     $content = $this->registry->getClass('output')->getTemplate('profile')->tabFriends($friends, $member, $pagination);
     //-----------------------------------------
     // Macros...
     //-----------------------------------------
     $content = $this->registry->output->replaceMacros($content);
     //-----------------------------------------
     // Return content..
     //-----------------------------------------
     return $content ? $content : $this->registry->getClass('output')->getTemplate('profile')->tabNoContent('err_no_aboutme_to_show');
 }
 /**
  * Show the add/edit form
  *
  * @param	string		[add|edit]
  * @return	@e void		[Outputs to screen]
  */
 public function modForm($type = 'add')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $group = array();
     if ($type == 'add') {
         /* Form Data */
         $mod_type = $this->request['group'] ? 'group' : 'name';
         $mod = array();
         $names = array();
         $forum_id = explode(',', $this->request['fid']);
         //-----------------------------------------
         // Start proper
         //-----------------------------------------
         $button = $this->lang->words['mod_addthis'];
         $form_code = 'doadd';
         if ($this->request['group']) {
             $this->DB->build(array('select' => 'g_id, g_title', 'from' => 'groups', 'where' => "g_id=" . intval($this->request['group'])));
             $this->DB->execute();
             if (!($group = $this->DB->fetch())) {
                 $this->registry->output->showError($this->lang->words['mod_nogroup'], 11327);
             }
         } else {
             if (!$this->request['member_id']) {
                 $this->registry->output->showError($this->lang->words['mod_memid'], 11328);
             } else {
                 $this->DB->build(array('select' => 'members_display_name, member_id', 'from' => 'members', 'where' => 'member_id=' . intval($this->request['member_id'])));
                 $this->DB->execute();
                 if (!($mem = $this->DB->fetch())) {
                     $this->registry->output->showError($this->lang->words['mod_memid'], 11329);
                 }
                 $member_id = $mem['member_id'];
                 $member_name = $mem['members_display_name'];
             }
         }
         //-----------------------------------------
         // Are they already a moderator?
         //-----------------------------------------
         $existingForums = array();
         $existingForumsByRecord = array();
         $this->DB->build(array('select' => '*', 'from' => 'moderators', 'where' => isset($member_id) ? "member_id={$member_id}" : "group_id={$group['g_id']}"));
         $this->DB->execute();
         while ($row = $this->DB->fetch()) {
             $exploded = array_filter(explode(',', $row['forum_id']), create_function('$v', 'return (bool) $v;'));
             $existingForums = array_merge($existingForums, $exploded);
             foreach ($exploded as $fid) {
                 $existingForumsByRecord[$fid] = $row['mid'];
             }
         }
         $alreadyAMod = array_intersect($forum_id, $existingForums);
         $notCurrentlyAMod = array_diff($forum_id, $existingForums);
         if (!empty($alreadyAMod) and empty($notCurrentlyAMod)) {
             // All of the forums we have selected we are already a moderator of
             // Are they all in the same record?
             $recordId = NULL;
             foreach ($forum_id as $fid) {
                 if ($recordId === NULL or $recordId == $existingForumsByRecord[$fid]) {
                     $recordId = $existingForumsByRecord[$fid];
                 } else {
                     $this->registry->output->showError('mod_all_selected_mod_already', 11332);
                     return;
                 }
             }
             $this->registry->output->silentRedirect($this->settings['base_url'] . "app=forums&section=moderator&act=mod&do=edit&mid={$recordId}&return_id={$recordId}");
         } elseif (!empty($alreadyAMod)) {
             $_alreadyAMod = array();
             $_alreadyAModByRecord = array();
             foreach ($alreadyAMod as $id) {
                 $_alreadyAMod[$id] = $this->registry->class_forums->forum_by_id[$id]['name'];
                 $_alreadyAModByRecord[$existingForumsByRecord[$id]][$id] = $this->registry->class_forums->forum_by_id[$id]['name'];
             }
             $_notCurrentlyAMod = array();
             foreach ($notCurrentlyAMod as $id) {
                 $_notCurrentlyAMod[$id] = $this->registry->class_forums->forum_by_id[$id]['name'];
             }
             $this->registry->output->html .= $this->html->moderatorDuplicateForm($mod_type, $mod_type == 'name' ? IPSMember::load($member_id) : $group, $_alreadyAMod, $_notCurrentlyAMod, $_alreadyAModByRecord);
             return;
         }
     } else {
         /* Check the moderator */
         if ($this->request['mid'] == "") {
             $this->registry->output->showError($this->lang->words['mod_valid'], 11330);
         }
         /* Form bits */
         $button = $this->lang->words['mod_edithis'];
         $form_code = "doedit";
         /* Moderator Info */
         $this->DB->build(array('select' => '*', 'from' => 'moderators', 'where' => "mid=" . intval($this->request['mid'])));
         $this->DB->execute();
         if (!($mod = $this->DB->fetch())) {
             $this->registry->output->showError($this->lang->words['mod_mid'], 11331);
         }
         /* BW Options */
         $_tmp = IPSBWOptions::thaw($mod['mod_bitoptions'], 'moderators', 'forums');
         if (count($_tmp)) {
             foreach ($_tmp as $k => $v) {
                 $mod[$k] = $v;
             }
         }
         /* Other */
         $forum_id = explode(',', IPSText::cleanPermString($mod['forum_id']));
         $member_id = $mod['member_id'];
         $member_name = $mod['member_name'];
         $mod_type = $mod['is_group'] ? 'group' : 'name';
     }
     /* Form Fields */
     $mod['edit_post'] = $this->registry->output->formYesNo('edit_post', $mod['edit_post']);
     $mod['edit_topic'] = $this->registry->output->formYesNo('edit_topic', $mod['edit_topic']);
     $mod['delete_post'] = $this->registry->output->formYesNo('delete_post', $mod['delete_post']);
     $mod['delete_topic'] = $this->registry->output->formYesNo('delete_topic', $mod['delete_topic']);
     $mod['view_ip'] = $this->registry->output->formYesNo('view_ip', $mod['view_ip']);
     $mod['open_topic'] = $this->registry->output->formYesNo('open_topic', $mod['open_topic']);
     $mod['close_topic'] = $this->registry->output->formYesNo('close_topic', $mod['close_topic']);
     $mod['move_topic'] = $this->registry->output->formYesNo('move_topic', $mod['move_topic']);
     $mod['pin_topic'] = $this->registry->output->formYesNo('pin_topic', $mod['pin_topic']);
     $mod['unpin_topic'] = $this->registry->output->formYesNo('unpin_topic', $mod['unpin_topic']);
     $mod['split_merge'] = $this->registry->output->formYesNo('split_merge', $mod['split_merge']);
     $mod['mod_can_set_open_time'] = $this->registry->output->formYesNo('mod_can_set_open_time', $mod['mod_can_set_open_time']);
     $mod['mod_can_set_close_time'] = $this->registry->output->formYesNo('mod_can_set_close_time', $mod['mod_can_set_close_time']);
     $mod['mass_move'] = $this->registry->output->formYesNo('mass_move', $mod['mass_move']);
     $mod['mass_prune'] = $this->registry->output->formYesNo('mass_prune', $mod['mass_prune']);
     $mod['topic_q'] = $this->registry->output->formYesNo('topic_q', $mod['topic_q']);
     $mod['post_q'] = $this->registry->output->formYesNo('post_q', $mod['post_q']);
     $mod['allow_warn'] = $this->registry->output->formYesNo('allow_warn', $mod['allow_warn']);
     $mod['can_mm'] = $this->registry->output->formYesNo('can_mm', $mod['can_mm']);
     $mod['bw_flag_spammers'] = $this->registry->output->formYesNo('bw_flag_spammers', $mod['bw_flag_spammers']);
     $mod['bw_can_toggle_answered_post'] = $this->registry->output->formYesNo('bw_can_toggle_answered_post', $mod['bw_can_toggle_answered_post']);
     $mod['forums'] = $this->registry->output->formMultiDropdown('forums[]', $this->registry->getClass('class_forums')->adForumsForumList(1), $forum_id);
     $mod['bw_mod_soft_delete'] = $this->registry->output->formYesNo("bw_mod_soft_delete", $mod['bw_mod_soft_delete']);
     $mod['bw_mod_un_soft_delete'] = $this->registry->output->formYesNo("bw_mod_un_soft_delete", $mod['bw_mod_un_soft_delete']);
     $mod['bw_mod_soft_delete_see'] = $this->registry->output->formYesNo("bw_mod_soft_delete_see", $mod['bw_mod_soft_delete_see']);
     /* Output */
     $this->registry->output->extra_nav[] = array('', $this->lang->words['mod_' . $type]);
     $this->registry->output->html .= $this->html->moderatorPermissionForm($mod, $form_code, $mod['mid'], $member_id, $mod_type, $group['g_id'], $group['g_name'], $button);
 }
 /**
  * UserCP Save Form: Signature
  *
  * @return	array	Errors
  */
 public function saveSignature()
 {
     /* Load editor stuff */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite');
     $this->editor = new $classToLoad();
     $this->editor->setLegacyMode(false);
     $isHtml = intval($this->request['sig_htmlstatus']);
     //-----------------------------------------
     // Check to make sure that we can edit profiles..
     //-----------------------------------------
     $sig_restrictions = explode(':', $this->memberData['g_signature_limits']);
     if (!$this->memberData['g_edit_profile'] or $sig_restrictions[0] and !$this->memberData['g_sig_unit']) {
         $this->registry->getClass('output')->showError('members_profile_disabled', 1028, null, null, 403);
     }
     //-----------------------------------------
     // Post process the editor
     // Now we have safe HTML and bbcode
     //-----------------------------------------
     /* Set content in editor */
     $this->editor->setAllowBbcode(true);
     $this->editor->setAllowSmilies(true);
     $this->editor->setIsHtml($this->memberData['g_dohtml'] && $isHtml);
     $this->editor->setBbcodeSection('signatures');
     $this->editor->setContent($this->memberData['signature']);
     $signature = $this->editor->process($_POST['Post']);
     //-----------------------------------------
     // Parse post
     //-----------------------------------------
     /* Load parser */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
     $parser = new $classToLoad();
     $parser->testForParsingLimits($signature, array('quote', 'emoticons', 'urls'));
     if (is_array($parser->getErrors()) && count($parser->getErrors())) {
         $this->lang->loadLanguageFile(array('public_post'), 'forums');
         $_error = array_pop($parser->getErrors());
         $this->registry->getClass('output')->showError($_error, 10210);
     }
     //-----------------------------------------
     // Signature restrictions...
     //-----------------------------------------
     $sig_errors = array();
     //-----------------------------------------
     // Max number of images...
     //-----------------------------------------
     if (isset($sig_restrictions[1]) and $sig_restrictions[1] !== '') {
         if ($parser->getImageCount($signature) > $sig_restrictions[1]) {
             $sig_errors[] = sprintf($this->lang->words['sig_toomanyimages'], $sig_restrictions[1]);
         }
     }
     //-----------------------------------------
     // Max number of urls...
     //-----------------------------------------
     if (isset($sig_restrictions[4]) and $sig_restrictions[4] !== '') {
         if ($parser->getUrlCount($signature) > $sig_restrictions[4]) {
             $sig_errors[] = sprintf($this->lang->words['sig_toomanyurls'], $sig_restrictions[4]);
         } else {
             preg_match_all('#(^|\\s|>)((http|https|news|ftp)://\\w+[^\\s\\[\\]\\<]+)#is', $signature, $matches);
             if (count($matches[1]) > $sig_restrictions[4]) {
                 $sig_errors[] = sprintf($this->lang->words['sig_toomanyurls'], $sig_restrictions[4]);
             }
         }
     }
     $this->settings['signature_line_length'] = $this->settings['signature_line_length'] > 0 ? $this->settings['signature_line_length'] : 200;
     /* You can't wordwrap on HTML http://community.invisionpower.com/resources/bugs.html/_/ip-board/signature-url-bbcode-r41254 */
     //$signature	= wordwrap( $signature, $this->settings['signature_line_length'], '</p>', true );
     // http://community.invisionpower.com/tracker/issue-35105-signature-restriction-minor-bug
     $signature = preg_replace('#^\\s*(</p>)+#i', '', $signature);
     $signature = preg_replace('#(</p>)+?\\s*$#i', '', $signature);
     //-----------------------------------------
     // Max number of lines of text...
     //-----------------------------------------
     if (isset($sig_restrictions[5]) and $sig_restrictions[5] !== '') {
         $lineCount = substr_count($signature, "</p>") + substr_count($signature, "br>");
         if ($lineCount >= $sig_restrictions[5]) {
             $sig_errors[] = sprintf($this->lang->words['sig_toomanylines'], $sig_restrictions[5]);
         }
     }
     //-----------------------------------------
     // Now the crappy part..
     //-----------------------------------------
     if (isset($sig_restrictions[2]) and $sig_restrictions[2] !== '' and isset($sig_restrictions[3]) and $sig_restrictions[3] !== '') {
         preg_match_all('/\\<img([^>]+?)>/i', $signature, $allImages);
         if (count($allImages[1])) {
             foreach ($allImages[1] as $foundImage) {
                 preg_match('#src=[\'"]([^\'"]+?)[\'"]#i', $foundImage, $url);
                 $imageProperties = @getimagesize($url[1]);
                 if (is_array($imageProperties) and count($imageProperties)) {
                     if ($imageProperties[0] > $sig_restrictions[2] or $imageProperties[1] > $sig_restrictions[3]) {
                         $sig_errors[] = sprintf($this->lang->words['sig_imagetoobig'], $url[1], $sig_restrictions[2], $sig_restrictions[3]);
                     }
                 } else {
                     $sig_errors[] = $this->lang->words['sig_imagenotretrievable'];
                 }
             }
         }
     }
     if (count($sig_errors)) {
         $this->registry->getClass('output')->showError(implode('<br />', $sig_errors), 10211);
     }
     /* Save HTML status */
     $members_bitoptions = IPSBWOptions::thaw($this->memberData['members_bitoptions'], 'members', 'global');
     $members_bitoptions['bw_html_sig'] = $isHtml;
     //-----------------------------------------
     // Write it to the DB.
     //-----------------------------------------
     IPSMember::save($this->memberData['member_id'], array('members' => $members_bitoptions, 'extendedProfile' => array('signature' => $signature)));
     /* Update cache */
     IPSContentCache::update($this->memberData['member_id'], 'sig', $parser->display($signature));
     return TRUE;
 }
Example #4
0
 /**
  * Function to resync a member's Vkontakte data
  *
  * @access	public
  * @param	mixed		Member Data in an array form (result of IPSMember::load( $id, 'all' ) ) or a member ID
  * @return	array 		Updated member data	
  *
  * EXCEPTION CODES:
  * NO_MEMBER		Member ID does not exist
  * NOT_LINKED		Member ID or data specified is not linked to a FB profile
  */
 public function syncMember($memberData)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $exProfile = array();
     /* Do we need to load a member? */
     if (!is_array($memberData)) {
         $memberData = IPSMember::load(intval($memberData), 'all');
     }
     /* Got a member? */
     if (!$memberData['member_id']) {
         throw new Exception('NO_MEMBER');
     }
     /* Linked account? */
     if (!$memberData['vk_uid']) {
         throw new Exception('NOT_LINKED');
     }
     /* Not completed sign up ( no display name ) 
     		if ( $memberData['member_group_id'] == $this->settings['auth_group'] )
     		{
     			return false;
     		}
     		*/
     /* Thaw Options */
     $bwOptions = IPSBWOptions::thaw($memberData['vk_bwoptions'], 'vkontakte');
     /* Grab the data */
     try {
         $this->resetApi($memberData['vk_token'], $memberData['vk_uid']);
         if ($this->isConnected()) {
             $user = $this->fetchUserData();
             /* Load library */
             if ($bwOptions['vc_s_pic']) {
                 $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/photo.php', 'classes_member_photo');
                 $photo = new $classToLoad($this->registry);
                 $photo->save($memberData, 'vkontakte');
             }
         }
     } catch (Exception $e) {
     }
     return $memberData;
 }
Example #5
0
 /**
  * List all current friends.
  *
  * @return	@e void		[Prints to screen]
  * @since	IPB 2.2.0.2006-08-08
  */
 protected function _viewList()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $friends = array();
     $tab = substr(IPSText::alphanumericalClean($this->request['tab']), 0, 20);
     $per_page = 25;
     $start = intval($this->request['st']);
     //-----------------------------------------
     // Check we're a member
     //-----------------------------------------
     if (!$this->memberData['member_id']) {
         $this->registry->output->showError('no_friend_mid', 10267, null, null, 404);
     }
     //-----------------------------------------
     // To what are we doing to whom?
     //-----------------------------------------
     if ($tab == 'pending') {
         $query = 'f.friends_approved=0 AND f.friends_friend_id=' . $this->memberData['member_id'];
         $joinKey = 'f.friends_member_id';
     } else {
         $query = 'f.friends_approved=1 AND f.friends_member_id=' . $this->memberData['member_id'];
         $joinKey = 'f.friends_friend_id';
     }
     /* Not banned or spammed */
     $query .= ' AND m.member_banned=0 AND ( ! ' . IPSBWOptions::sql('bw_is_spammer', 'members_bitoptions', 'members', 'global', 'has') . ')';
     //-----------------------------------------
     // Get count...
     //-----------------------------------------
     $count = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => array('profile_friends' => 'f'), 'where' => $query, 'add_join' => array(array('select' => '', 'from' => array('members' => 'm'), 'where' => 'm.member_id=' . $joinKey, 'type' => 'inner'))));
     //-----------------------------------------
     // Pages...
     //-----------------------------------------
     $pages = $this->registry->output->generatePagination(array('totalItems' => intval($count['count']), 'noDropdown' => 1, 'itemsPerPage' => $per_page, 'currentStartValue' => $start, 'baseUrl' => 'app=members&amp;module=profile&amp;section=friends&amp;do=list&amp;tab=' . $tab));
     //-----------------------------------------
     // Get current friends...
     //-----------------------------------------
     $this->DB->build(array('select' => 'f.*', 'from' => array('profile_friends' => 'f'), 'where' => $query, 'order' => 'm.members_l_display_name ASC', 'limit' => array($start, $per_page), 'add_join' => array(array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=' . $joinKey, 'type' => 'left'), array('select' => 'm.*', 'from' => array('members' => 'm'), 'where' => 'm.member_id=' . $joinKey, 'type' => 'left'))));
     $q = $this->DB->execute();
     //-----------------------------------------
     // Get and store...
     //-----------------------------------------
     while ($row = $this->DB->fetch($q)) {
         $row = IPSMember::buildDisplayData($row, array('warn' => 0));
         $friends[] = $row;
     }
     //-----------------------------------------
     // Show...
     //-----------------------------------------
     $content = $this->registry->getClass('output')->getTemplate('profile')->friendsList($friends, $pages);
     $this->registry->output->setTitle($this->lang->words['m_title_friends'] . ' - ' . ipsRegistry::$settings['board_name']);
     $this->registry->output->addNavigation($this->lang->words['m_title_friends'], '');
     $this->registry->getClass('output')->addContent($content);
     $this->registry->getClass('output')->sendOutput();
 }
Example #6
0
 /**
  * Class entry point
  *
  * @param	object		Registry reference
  * @return	@e void		[Outputs to screen/redirects]
  */
 public function doExecute(ipsRegistry $registry)
 {
     //-----------------------------------------
     // Get HTML and skin
     //-----------------------------------------
     $this->registry->class_localization->loadLanguageFile(array('public_list'), 'members');
     //-----------------------------------------
     // Can we access?
     //-----------------------------------------
     if (!$this->memberData['g_mem_info']) {
         $this->registry->output->showError('cannot_view_memberlist', 10221, null, null, 403);
     }
     //-----------------------------------------
     // Init variables
     //-----------------------------------------
     $see_groups = array();
     $the_filter = array('ALL' => $this->lang->words['show_all']);
     $the_members = array();
     $query = array("m.members_l_display_name !='' AND m.members_l_display_name " . $this->DB->buildIsNull(false));
     $url = array();
     $pp_rating_real = isset($this->request['pp_rating_real']) ? intval($this->request['pp_rating_real']) : 0;
     $this->first = isset($this->request['st']) ? intval($this->request['st']) : 0;
     $this->max_results = !empty($this->request['max_results']) ? $this->request['max_results'] : $this->max_results;
     $this->sort_key = !empty($this->request['sort_key']) ? $this->request['sort_key'] : 'members_display_name';
     $this->sort_order = !empty($this->request['sort_order']) ? $this->request['sort_order'] : 'asc';
     $this->filter = !empty($this->request['filter']) ? $this->request['filter'] == 'ALL' ? 'ALL' : intval($this->request['filter']) : 'ALL';
     $this->request['showall'] = isset($this->request['showall']) ? intval($this->request['showall']) : 0;
     $this->request['name_box'] = isset($this->request['name_box']) ? $this->request['name_box'] : '';
     $this->request['quickjump'] = isset($this->request['quickjump']) ? $this->request['quickjump'] : 0;
     $_queryPP = false;
     //-----------------------------------------
     // Set some of the URL params
     //-----------------------------------------
     if ($this->request['quickjump']) {
         $this->request['name_box'] = 'begins';
         $this->request['name'] = $this->request['quickjump'];
     }
     $url['app'] = "app=members&amp;module=list";
     $url['showall'] = 'showall=' . $this->request['showall'];
     $url['sort_key'] = "sort_key={$this->sort_key}";
     $url['sort_order'] = "sort_order={$this->sort_order}";
     $url['max_results'] = "max_results={$this->max_results}";
     $url['quickjump'] = "quickjump={$this->request['quickjump']}";
     $url['name_box'] = 'name_box=' . $this->request['name_box'];
     $url['name'] = isset($this->request['name']) ? "name={$this->request['name']}" : "name=";
     //-----------------------------------------
     // Sort the member group info
     //-----------------------------------------
     foreach ($this->caches['group_cache'] as $row) {
         if ($row['g_hide_from_list']) {
             if (!($this->memberData['g_access_cp'] and $this->request['showall'])) {
                 $hide_ids[] = $row['g_id'];
                 continue;
             }
         }
         $see_groups[] = $row['g_id'];
         $this->mem_groups[$row['g_id']] = array('TITLE' => $row['g_title'], 'ICON' => $row['g_icon']);
         if ($row['g_id'] == $this->settings['guest_group']) {
             continue;
         }
         $the_filter[$row['g_id']] = $row['g_title'];
     }
     //-----------------------------------------
     // Init some arrays
     //-----------------------------------------
     $the_sort_key = array('members_l_display_name' => 'sort_by_name', 'posts' => 'pcount', 'joined' => 'sort_by_joined', 'members_profile_views' => 'm_dd_views');
     $the_max_results = array(10 => '10', 20 => '20', 40 => '40', 60 => '60');
     $the_sort_order = array('desc' => 'descending_order', 'asc' => 'ascending_order');
     $dropdowns = array('filter' => $the_filter, 'sort_key' => $the_sort_key, 'sort_order' => $the_sort_order, 'max_results' => $the_max_results);
     $defaults = array('filter' => $this->filter, 'sort_key' => $this->sort_key, 'sort_order' => $this->sort_order, 'max_results' => $this->max_results, 'photoonly' => !empty($this->request['photoonly']) ? 1 : 0);
     //-----------------------------------------
     // Final vars for query
     //-----------------------------------------
     $this->sort_key = isset($the_sort_key[$this->sort_key]) ? $this->sort_key : 'members_l_display_name';
     $this->sort_order = isset($the_sort_order[$this->sort_order]) ? $this->sort_order : 'asc';
     $this->filter = isset($the_filter[$this->filter]) ? $this->filter : 'ALL';
     $this->max_results = isset($the_max_results[$this->max_results]) ? $this->max_results : 20;
     //-----------------------------------------
     // Get custom profile information
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
     $this->custom_fields = new $classToLoad();
     $this->custom_fields->initData('edit', 1);
     $this->custom_fields->parseToEdit('mlist');
     //-----------------------------------------
     // Member Groups...
     //-----------------------------------------
     if ($this->filter != 'ALL') {
         if (!in_array($this->filter, $see_groups)) {
             $query[] = 'm.member_group_id IN(' . implode(',', $see_groups) . ')';
         } else {
             $query[] = 'm.member_group_id=' . $this->filter;
         }
         $url['filter'] = 'filter=' . $this->filter;
     }
     //-----------------------------------------
     // NOT IN Member Groups...
     //-----------------------------------------
     if (count($hide_ids)) {
         $query[] = "m.member_group_id NOT IN(" . implode(",", $hide_ids) . ")";
     }
     /* Not banned */
     $query[] = "m.member_banned=0";
     /* Not a spammer */
     $query[] = '( ! ' . IPSBWOptions::sql('bw_is_spammer', 'members_bitoptions', 'members', 'global', 'has') . ')';
     //-----------------------------------------
     // Build query
     //-----------------------------------------
     $dates = array('lastpost', 'lastvisit', 'joined');
     $mapit = array('posts' => 'm.posts', 'joined' => 'm.joined', 'lastpost' => 'm.last_post', 'lastvisit' => 'm.last_visit', 'signature' => 'pp.signature', 'name' => 'm.members_display_name', 'photoonly' => 'pp.pp_main_photo');
     //-----------------------------------------
     // Do search
     //-----------------------------------------
     foreach ($mapit as $in => $tbl) {
         /**
          * Leave isset && != '', can't use empty or 0 values are skipped as well
          * @link	http://community.invisionpower.com/tracker/issue-37350-sorting-members-by-post-count/
          */
         $this->request[$in] = isset($this->request[$in]) && $this->request[$in] != '' ? $this->request[$in] : '';
         $inbit = $this->request[$in] = IPSText::parseCleanValue(trim(urldecode(IPSText::stripslashes($this->request[$in]))));
         $url[$in] = $in . '=' . urlencode($this->request[$in]);
         //-----------------------------------------
         // Name...
         //-----------------------------------------
         if ($in == 'name' and $inbit != "") {
             if ($this->request['name_box'] == 'begins') {
                 $query[] = "m.members_l_display_name LIKE '" . strtolower($inbit) . "%'";
             } else {
                 $query[] = "m.members_l_display_name LIKE '%" . strtolower($inbit) . "%'";
             }
         } else {
             if ($in == 'posts' and is_numeric($inbit) and intval($inbit) > -1) {
                 $ltmt = $this->request[$in . '_ltmt'] == 'lt' ? '<' : '>';
                 $query[] = $tbl . ' ' . $ltmt . ' ' . intval($inbit);
                 $url[$in] = $in . '_ltmt=' . $this->request[$in . '_ltmt'] . '&posts=' . intval($inbit);
             } else {
                 if (in_array($in, $dates) and $inbit) {
                     if (preg_match('/\\d{2}-\\d{2}-\\d{4}/', $this->request[$in])) {
                         $_tmp = explode('-', $this->request[$in]);
                         $time_int = mktime(23, 59, 59, $_tmp[0], $_tmp[1], $_tmp[2]);
                     } else {
                         $time_int = strtotime($inbit);
                     }
                     if ($time_int) {
                         $ltmt = $this->request[$in . '_ltmt'] == 'lt' ? '<' : '>';
                         $query[] = $tbl . ' ' . $ltmt . ' ' . $time_int;
                         $url[$in . '_ltmt'] = $in . '_ltmt=' . $this->request[$in . '_ltmt'];
                     }
                 } else {
                     if ($in == 'photoonly') {
                         if ($this->request['photoonly'] == 1) {
                             $_queryPP = true;
                             $query[] = $tbl . "<> ''";
                             $url[] = 'photoonly=1';
                         }
                     } else {
                         if ($inbit != "" and $in != 'posts') {
                             $_queryPP = true;
                             $query[] = $tbl . " LIKE '%{$inbit}%'";
                         }
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Custom fields?
     //-----------------------------------------
     if (count($this->custom_fields->out_fields)) {
         foreach ($this->custom_fields->out_fields as $id => $data) {
             if (!empty($this->request['field_' . $id])) {
                 $_queryPP = true;
                 if (is_array($this->request['field_' . $id])) {
                     foreach ($this->request['field_' . $id] as $k => $v) {
                         $this->request['field_' . $id][$k] = urldecode($v);
                         $url['field_' . $id] = "field_{$id}[{$k}]=" . $v;
                     }
                 } else {
                     $url['field_' . $id] = "field_{$id}=" . $this->request['field_' . $id];
                     $this->request['field_' . $id] = urldecode($this->request['field_' . $id]);
                 }
                 if ($this->custom_fields->cache_data[$id]['pf_type'] == 'drop') {
                     $query[] = "p.field_{$id}='" . $this->request['field_' . $id] . "'";
                 } else {
                     if ($this->custom_fields->cache_data[$id]['pf_type'] == 'cbox') {
                         if (count($this->request['field_' . $id])) {
                             foreach ($this->request['field_' . $id] as $k => $v) {
                                 $query[] = "p.field_{$id} LIKE '%|{$k}|%'";
                             }
                         }
                     } else {
                         $query[] = $this->custom_fields->cache_data[$id]['pf_search_type'] == 'loose' ? "p.field_{$id} LIKE '%" . $this->request['field_' . $id] . "%'" : "p.field_{$id} = '" . $this->request['field_' . $id] . "'";
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Rating..
     //-----------------------------------------
     if ($pp_rating_real) {
         $_queryPP = true;
         $query[] = "pp.pp_rating_real > " . $pp_rating_real;
         $url['pp_rating_real'] = "pp_rating_real=" . $pp_rating_real;
     }
     //-----------------------------------------
     // Finish query
     //-----------------------------------------
     //$query[] = "m.members_l_display_name != ''";
     $joins = array();
     if ($_queryPP) {
         $joins[] = array('from' => array('pfields_content' => 'p'), 'where' => 'p.member_id=m.member_id', 'type' => 'left');
         $joins[] = array('from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left');
     }
     //-----------------------------------------
     // Reputation
     //-----------------------------------------
     if (!ipsRegistry::isClassLoaded('repCache')) {
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/class_reputation_cache.php', 'classReputationCache');
         ipsRegistry::setClass('repCache', new $classToLoad());
     }
     //-----------------------------------------
     // START THE LISTING
     //-----------------------------------------
     $notInMembers = 0;
     foreach ($query as $q) {
         if (!strstr($q, 'm.')) {
             $notInMembers++;
         }
     }
     /* Get the count */
     if ($notInMembers > 0 or $this->sort_key != 'members_l_display_name' or $this->request['request_method'] == 'post') {
         $_max = $this->DB->buildAndFetch(array('select' => 'COUNT( * ) as cnt', 'from' => array('members' => 'm'), 'where' => implode(" AND ", $query), 'add_join' => $joins));
         $this->DB->build(array('select' => ' m.member_id', 'from' => array('members' => 'm'), 'where' => implode(" AND ", $query), 'order' => 'm.' . $this->sort_key . ' ' . $this->sort_order, 'limit' => array($this->first, $this->max_results), 'add_join' => $joins));
     } else {
         $_max = $this->DB->buildAndFetch(array('select' => 'COUNT( * ) as cnt', 'from' => 'members m', 'where' => implode(" AND ", $query)));
         $this->DB->build(array('select' => 'm.member_id', 'from' => array('members' => 'm'), 'where' => implode(" AND ", $query), 'order' => 'm.' . $this->sort_key . ' ' . $this->sort_order, 'limit' => array($this->first, $this->max_results)));
     }
     /* Fetch IDs */
     $mids = array();
     $this->DB->execute();
     while ($m = $this->DB->fetch()) {
         if ($m['member_id']) {
             $mids[] = $m['member_id'];
         }
     }
     if (count($mids)) {
         $members = array();
         $_members = IPSMember::load($mids, 'all');
         /* Make sure that we keep the ordering from the query */
         foreach ($mids as $id) {
             $members[$id] = $_members[$id];
         }
     }
     $max = $_max['cnt'];
     if (is_array($members) and count($members)) {
         foreach ($members as $id => $member) {
             /* Damn SQL thing with member_id */
             if (!$member['member_id']) {
                 $member['member_id'] = $member['member_table_id'];
             }
             $member['members_display_name'] = $member['members_display_name'] ? $member['members_display_name'] : $member['name'];
             $member['members_seo_name'] = IPSMember::fetchSeoName($member);
             $member['group'] = $this->mem_groups[$member['member_group_id']]['TITLE'];
             $member = IPSMember::buildProfilePhoto($member);
             $member['pp_reputation_points'] = $member['pp_reputation_points'] ? $member['pp_reputation_points'] : 0;
             $member['author_reputation'] = ipsRegistry::getClass('repCache')->getReputation($member['pp_reputation_points']);
             /* Reputation */
             if ($this->settings['reputation_protected_groups']) {
                 if (in_array($member['member_group_id'], explode(",", $this->settings['reputation_protected_groups']))) {
                     $member['pp_reputation_points'] = null;
                     $member['author_reputation'] = null;
                 }
             }
             $the_members[] = $member;
         }
     }
     /* make sure URL doesn't contain empty params */
     $_url = $url;
     $url = array();
     foreach ($_url as $key => $bit) {
         if (strrpos($bit, '=') + 1 == strlen($bit)) {
             continue;
         }
         $url[] = $bit;
     }
     $pages = $this->registry->output->generatePagination(array('totalItems' => $max, 'itemsPerPage' => $this->max_results, 'currentStartValue' => $this->first, 'seoTitle' => "false", 'seoTemplate' => 'members_list', 'baseUrl' => implode('&amp;', $url)));
     //-----------------------------------------
     // Print...
     //-----------------------------------------
     $this->output .= $this->registry->getClass('output')->getTemplate('mlist')->member_list_show($the_members, $pages, $dropdowns, $defaults, $this->custom_fields, implode('&amp;', $url));
     //-----------------------------------------
     // Push to print handler
     //-----------------------------------------
     $this->registry->output->addContent($this->output);
     $this->registry->output->setTitle($this->lang->words['page_title'] . ' - ' . ipsRegistry::$settings['board_name']);
     $this->registry->output->addNavigation($this->lang->words['page_title'], 'app=members', "false", 'members_list');
     $this->registry->output->sendOutput();
 }
 /**
  * Get the WHERE part of the SQL query
  *
  * @return	string	SQL WHERE string
  */
 public function getWhereClause()
 {
     //-----------------------------------------
     // Ignore filters?
     //-----------------------------------------
     if ($this->showAllMembers) {
         return '';
     }
     //-----------------------------------------
     // Init
     //-----------------------------------------
     $data = $this->generateFilterBoxes();
     $_sql = array();
     //print_r($data);exit;
     //-----------------------------------------
     // Filters
     //-----------------------------------------
     if ($data['member_contains_text']) {
         $_field = '';
         $_text = $this->DB->addSlashes($data['member_contains_text']);
         switch ($data['member_contains']) {
             default:
             case 'member_id':
                 $_field = 'm.member_id';
                 break;
             case 'name':
                 $_field = 'm.members_l_username';
                 $_text = strtolower($_text);
                 break;
             case 'members_display_name':
                 $_field = 'm.members_l_display_name';
                 $_text = strtolower($_text);
                 break;
             case 'email':
                 $_field = 'm.email';
                 break;
             case 'ip_address':
                 $_field = 'm.ip_address';
                 break;
             case 'signature':
                 $_field = 'pp.signature';
                 break;
         }
         switch ($data['member_contains_type']) {
             default:
             case 'contains':
                 $_sql[] = $this->DB->buildCast($_field, 'VARCHAR') . " LIKE '%" . $_text . "%'";
                 break;
             case 'begins':
                 $_sql[] = $this->DB->buildCast($_field, 'VARCHAR') . " LIKE '" . $_text . "%'";
                 break;
             case 'ends':
                 $_sql[] = $this->DB->buildCast($_field, 'VARCHAR') . " LIKE '%" . $_text . "'";
                 break;
             case 'equals':
                 $_sql[] = $this->DB->buildCast($_field, 'VARCHAR') . " = '" . $_text . "'";
                 break;
         }
     }
     //-----------------------------------------
     // "Simple" all-in-one search
     //-----------------------------------------
     if ($data['member_string'] and strlen($data['member_string']) >= 3) {
         /* Fix from ticket 766094 */
         $_text = $this->DB->addSlashes(IPSText::convertCharsets($data['member_string'], 'utf-8', IPS_DOC_CHAR_SET));
         $_sql[] = '(' . $this->DB->buildCast('m.name', 'VARCHAR') . " LIKE '%" . $_text . "%' OR " . $this->DB->buildCast('m.members_display_name', 'VARCHAR') . " LIKE '%" . $_text . "%' OR " . $this->DB->buildCast('m.email', 'VARCHAR') . " LIKE '%" . $_text . "%' OR " . $this->DB->buildCast('m.ip_address', 'VARCHAR') . " LIKE '%" . $_text . "%')";
     }
     //-----------------------------------------
     // Group limiting
     //-----------------------------------------
     if ($data['primary_group']) {
         if ($data['include_secondary']) {
             $_sql[] = "( m.member_group_id=" . intval($data['primary_group']) . " OR " . "m.mgroup_others LIKE '%," . intval($data['primary_group']) . ",%' OR " . "m.mgroup_others LIKE '" . intval($data['primary_group']) . ",%' OR " . "m.mgroup_others LIKE '%," . intval($data['primary_group']) . "' OR " . "m.mgroup_others='" . intval($data['primary_group']) . "' )";
         } else {
             $_sql[] = "m.member_group_id=" . intval($data['primary_group']);
         }
     }
     if ($data['secondary_group']) {
         $_sql[] = "( m.mgroup_others LIKE '%," . $data['secondary_group'] . ",%' OR " . "m.mgroup_others LIKE '" . $data['secondary_group'] . ",%' OR " . "m.mgroup_others LIKE '%," . $data['secondary_group'] . "' OR " . "m.mgroup_others='" . $data['secondary_group'] . "' )";
     }
     //-----------------------------------------
     // Post count
     //-----------------------------------------
     if (($data['post_count'] or $data['post_count'] == '0') and $data['post_count_type']) {
         $_type = '';
         if ($data['post_count_type'] == 'gt') {
             $_type = '>';
         } else {
             if ($data['post_count_type'] == 'lt') {
                 $_type = '<';
             } else {
                 if ($data['post_count_type'] == 'eq') {
                     $_type = '=';
                 }
             }
         }
         if ($_type) {
             $_sql[] = "m.posts" . $_type . intval($data['post_count']);
         }
     }
     //-----------------------------------------
     // Date filters
     //-----------------------------------------
     foreach (array('reg', 'post', 'active') as $_bit) {
         foreach (array('from', 'to') as $_when) {
             $bit = 'date_' . $_bit . '_' . $_when;
             if ($data[$bit]) {
                 //-----------------------------------------
                 // mm/dd/yyyy instead of mm-dd-yyyy
                 //-----------------------------------------
                 $data[$bit] = str_replace('/', '-', $data[$bit]);
                 list($month, $day, $year) = explode('-', $data[$bit]);
                 if (!checkdate($month, $day, $year)) {
                     $this->registry->output->global_message = sprintf($this->lang->words['m_daterange'], $month, $day, $year);
                 } else {
                     /* Bug #24067 */
                     /* Original fix caused this bug: http://community.invisionpower.com/tracker/issue-24416-search-dates-invalid-acp/
                     			Changed to just verify the result is an int, as that is all that's needed to prevent DB error */
                     $time_int = mktime(0, 0, 0, $month, $day, $year);
                     if (!is_int($time_int)) {
                         $this->registry->output->global_message = sprintf($this->lang->words['m_daterange'], $month, $day, $year);
                     } else {
                         switch ($_bit) {
                             case 'reg':
                                 $field = 'joined';
                                 break;
                             case 'post':
                                 $field = 'last_post';
                                 break;
                             case 'active':
                                 $field = 'last_activity';
                                 break;
                         }
                         if ($_when == 'from') {
                             $_sql[] = 'm.' . $field . ' > ' . $time_int;
                         } else {
                             $_sql[] = 'm.' . $field . ' < ' . $time_int;
                         }
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Custom fields...
     //-----------------------------------------
     if (is_array($data['custom_fields']) and count($data['custom_fields'])) {
         foreach ($data['custom_fields'] as $id => $value) {
             if ($value) {
                 if ($this->caches['profilefields'][$id]['pf_type'] == 'drop') {
                     $_sql[] = "p.field_{$id}='" . $this->DB->addSlashes($value) . "'";
                 } else {
                     if ($this->caches['profilefields'][$id]['pf_type'] == 'cbox') {
                         if (count($value)) {
                             foreach (explode(',', $value) as $k) {
                                 $_sql[] = "p.field_{$id} LIKE '%|" . $this->DB->addSlashes($k) . "|%'";
                             }
                         }
                     } else {
                         $_sql[] = $this->caches['profilefields'][$id]['pf_search_type'] == 'loose' ? "p.field_{$id} LIKE '%" . $this->DB->addSlashes($value) . "%'" : "p.field_{$id} = '" . $this->DB->addSlashes($value) . "'";
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Search member status type
     //-----------------------------------------
     if ($data['member_status']) {
         switch ($data['member_status']) {
             case 'banned':
                 $_sql[] = "(m.member_banned=1)";
                 break;
             case 'spam':
                 $_sql[] = '(' . IPSBWOptions::sql('bw_is_spammer', 'm.members_bitoptions', 'members', 'global', 'has') . ' OR val.spam_flag=1)';
                 break;
             case 'validating':
                 $_sql[] = "(val.lost_pass=0 AND val.vid " . $this->DB->buildIsNull(false) . ")";
                 break;
             case 'incomplete':
                 $_sql[] = "par.partial_member_id " . $this->DB->buildIsNull(false);
                 break;
             case 'locked':
                 if ($this->settings['ipb_bruteforce_attempts'] > 0) {
                     $_sql[] = "m.failed_login_count >= " . intval($this->settings['ipb_bruteforce_attempts']);
                 } else {
                     $_sql[] = "m.failed_login_count > 0";
                 }
                 break;
             default:
             case 'all':
                 //-----------------------------------------
                 // Hide partial members if showing 'all', and
                 // we did not explicitly search
                 //-----------------------------------------
                 if (!count($_sql)) {
                     $_sql[] = "par.partial_member_id " . $this->DB->buildIsNull();
                 }
                 break;
         }
     }
     //-----------------------------------------
     // Return search string
     //-----------------------------------------
     return count($_sql) ? implode(" AND ", $_sql) : '';
 }
Example #8
0
 /**
  * Compiles all the incoming information into an array which is returned to the accessor
  *
  * @return	array
  */
 protected function compilePostData()
 {
     //-----------------------------------------
     // Sort out post content
     //-----------------------------------------
     if ($this->getPostContentPreFormatted()) {
         $postContent = $this->getPostContentPreFormatted();
     } else {
         $postContent = $this->formatPost($this->getPostContent());
     }
     //-----------------------------------------
     // Need to format the post?
     //-----------------------------------------
     $bw = array();
     if (!empty($this->_originalPost['pid'])) {
         $_tmp = IPSBWOptions::thaw($this->_originalPost['post_bwoptions'], 'posts', 'forums');
         if (count($_tmp)) {
             foreach ($_tmp as $k => $v) {
                 $bw[$k] = $v;
             }
         }
     }
     $bw['bw_post_from_mobile'] = intval($this->member->isMobileApp);
     $post = array('author_id' => $this->getAuthor('member_id') ? $this->getAuthor('member_id') : 0, 'use_sig' => intval($this->getSettings('enableSignature')), 'use_emo' => intval($this->getSettings('enableEmoticons')), 'ip_address' => $this->member->ip_address, 'post_date' => $this->getDate() ? $this->getDate() : IPS_UNIX_TIME_NOW, 'post' => $postContent, 'author_name' => $this->getAuthor('member_id') ? $this->getAuthor('members_display_name') : (empty($this->request['UserName']) ? $this->getAuthor('members_display_name') : $this->request['UserName']), 'topic_id' => 0, 'queued' => $this->getPublished() ? 0 : 1, 'post_htmlstate' => intval($this->getSettings('post_htmlstatus')), 'post_bwoptions' => IPSBWOptions::freeze($bw, 'posts', 'forums'));
     //-----------------------------------------
     // If we had any errors, parse them back to this class
     // so we can track them later.
     //-----------------------------------------
     if ($post['post_htmlstate'] != 1 && is_array($this->editor->getParsingErrors()) && count($this->editor->getParsingErrors())) {
         /* Should extend this to accept many */
         $errors = $this->editor->getParsingErrors();
         $this->_postErrors = array_pop($errors);
     }
     return $post;
 }
 /**
  * Show the add/edit form
  *
  * @access	public
  * @param	string		[add|edit]
  * @return	void		[Outputs to screen]
  */
 public function modForm($type = 'add')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $group = array();
     if ($type == 'add') {
         /* Form Data */
         $mod_type = $this->request['group'] ? 'group' : 'name';
         $mod = array();
         $names = array();
         $forum_id = explode(',', $this->request['fid']);
         //-----------------------------------------
         // Start proper
         //-----------------------------------------
         $button = $this->lang->words['mod_addthis'];
         $form_code = 'doadd';
         if ($this->request['group']) {
             $this->DB->build(array('select' => 'g_id, g_title', 'from' => 'groups', 'where' => "g_id=" . intval($this->request['group'])));
             $this->DB->execute();
             if (!($group = $this->DB->fetch())) {
                 $this->registry->output->showError($this->lang->words['mod_nogroup'], 11327);
             }
         } else {
             if (!$this->request['member_id']) {
                 $this->registry->output->showError($this->lang->words['mod_memid'], 11328);
             } else {
                 $this->DB->build(array('select' => 'members_display_name, member_id', 'from' => 'members', 'where' => 'member_id=' . intval($this->request['member_id'])));
                 $this->DB->execute();
                 if (!($mem = $this->DB->fetch())) {
                     $this->registry->output->showError($this->lang->words['mod_memid'], 11329);
                 }
                 $member_id = $mem['member_id'];
                 $member_name = $mem['members_display_name'];
             }
         }
     } else {
         /* Check the moderator */
         if ($this->request['mid'] == "") {
             $this->registry->output->showError($this->lang->words['mod_valid'], 11330);
         }
         /* Form bits */
         $button = $this->lang->words['mod_edithis'];
         $form_code = "doedit";
         /* Moderator Info */
         $this->DB->build(array('select' => '*', 'from' => 'moderators', 'where' => "mid=" . intval($this->request['mid'])));
         $this->DB->execute();
         if (!($mod = $this->DB->fetch())) {
             $this->registry->output->showError($this->lang->words['mod_mid'], 11331);
         }
         /* BW Options */
         $_tmp = IPSBWOptions::thaw($mod['mod_bitoptions'], 'moderators', 'forums');
         if (count($_tmp)) {
             foreach ($_tmp as $k => $v) {
                 $mod[$k] = $v;
             }
         }
         /* Other */
         $forum_id = explode(',', IPSText::cleanPermString($mod['forum_id']));
         $member_id = $mod['member_id'];
         $member_name = $mod['member_name'];
         $mod_type = $mod['is_group'] ? 'group' : 'name';
     }
     /* Form Fields */
     $mod['edit_post'] = $this->registry->output->formYesNo('edit_post', $mod['edit_post']);
     $mod['edit_topic'] = $this->registry->output->formYesNo('edit_topic', $mod['edit_topic']);
     $mod['delete_post'] = $this->registry->output->formYesNo('delete_post', $mod['delete_post']);
     $mod['delete_topic'] = $this->registry->output->formYesNo('delete_topic', $mod['delete_topic']);
     $mod['view_ip'] = $this->registry->output->formYesNo('view_ip', $mod['view_ip']);
     $mod['open_topic'] = $this->registry->output->formYesNo('open_topic', $mod['open_topic']);
     $mod['close_topic'] = $this->registry->output->formYesNo('close_topic', $mod['close_topic']);
     $mod['move_topic'] = $this->registry->output->formYesNo('move_topic', $mod['move_topic']);
     $mod['pin_topic'] = $this->registry->output->formYesNo('pin_topic', $mod['pin_topic']);
     $mod['unpin_topic'] = $this->registry->output->formYesNo('unpin_topic', $mod['unpin_topic']);
     $mod['split_merge'] = $this->registry->output->formYesNo('split_merge', $mod['split_merge']);
     $mod['mod_can_set_open_time'] = $this->registry->output->formYesNo('mod_can_set_open_time', $mod['mod_can_set_open_time']);
     $mod['mod_can_set_close_time'] = $this->registry->output->formYesNo('mod_can_set_close_time', $mod['mod_can_set_close_time']);
     $mod['mass_move'] = $this->registry->output->formYesNo('mass_move', $mod['mass_move']);
     $mod['mass_prune'] = $this->registry->output->formYesNo('mass_prune', $mod['mass_prune']);
     $mod['topic_q'] = $this->registry->output->formYesNo('topic_q', $mod['topic_q']);
     $mod['post_q'] = $this->registry->output->formYesNo('post_q', $mod['post_q']);
     $mod['allow_warn'] = $this->registry->output->formYesNo('allow_warn', $mod['allow_warn']);
     $mod['can_mm'] = $this->registry->output->formYesNo('can_mm', $mod['can_mm']);
     $mod['bw_flag_spammers'] = $this->registry->output->formYesNo('bw_flag_spammers', $mod['bw_flag_spammers']);
     $mod['forums'] = $this->registry->output->formMultiDropdown('forums[]', $this->registry->getClass('class_forums')->adForumsForumList(1), $forum_id);
     /* Output */
     $this->registry->output->html .= $this->html->moderatorPermissionForm($mod, $form_code, $mod['mid'], $member_id, $mod_type, $group['g_id'], $group['g_name'], $button);
 }
 /**
  * Resets the last registered member
  *
  * @param	bool	$return		If TRUE returns the value instead of updating it
  * @return	@e mixed
  */
 public static function resetLastRegisteredMember($return = false)
 {
     /* Init vsrs */
     $groups = array();
     $_extra = '';
     $update = array('last_mem_id' => 0, 'last_mem_name' => '', 'last_mem_name_seo' => '');
     /* Exclude certain groups */
     foreach (ipsRegistry::cache()->getCache('group_cache') as $_gid => $_gdata) {
         if ($_gdata['g_hide_online_list'] || $_gid == ipsRegistry::$settings['auth_group']) {
             $groups[] = $_gid;
         }
     }
     /* Groups to skip? */
     $_extra = count($groups) ? "member_group_id NOT IN (" . implode(',', $groups) . ") AND " : '';
     $r = ipsRegistry::DB()->buildAndFetch(array('select' => 'member_id, members_display_name, members_seo_name', 'from' => 'members', 'where' => "{$_extra} members_display_name != '' AND members_display_name " . ipsRegistry::DB()->buildIsNull(false) . " AND member_banned=0 AND ( ! " . IPSBWOptions::sql('bw_is_spammer', 'members_bitoptions', 'members', 'global', 'has') . ")", 'order' => "member_id DESC", 'limit' => array(0, 1)));
     $update['last_mem_id'] = intval($r['member_id']);
     $update['last_mem_name'] = trim($r['members_display_name']);
     $update['last_mem_name_seo'] = trim($r['members_seo_name']);
     /* Update our stats or return? */
     if ($return) {
         return $update;
     } else {
         $stats = ipsRegistry::cache()->getCache('stats');
         $stats = array_merge($stats, $update);
         ipsRegistry::cache()->setCache('stats', $stats, array('array' => 1));
     }
 }
Example #11
0
 /**
  * Mark a topic as 'unAnswered'
  * @param mixed $topic
  * @param mixed $post
  */
 public function unAnswerTopicSingle($post, $topic = null)
 {
     if (is_numeric($post)) {
         $post = $this->getPostById($post);
     }
     if ($topic === null) {
         $topic = $post['topic_id'];
     }
     if (is_numeric($topic)) {
         $topic = $this->getTopicById($topic);
     }
     if (!$topic['tid'] || !$post['pid']) {
         throw new Exception('missing_data');
     }
     if ($this->canAnswerTopic($topic) !== true) {
         throw new Exception('no_permission');
     }
     /* Remove flag this post */
     $sql = IPSBWOptions::sql('bw_post_answered', 'post_bwoptions', 'posts', 'forums', 'invert');
     $where = IPSBWOptions::sql('bw_post_answered', 'post_bwoptions', 'posts', 'forums', 'has');
     $this->DB->update('posts', 'post_bwoptions=' . $sql, 'pid=' . $post['pid'] . ' AND ' . $where, false, true);
     /* Update topic */
     $this->DB->update('topics', array('topic_answered_pid' => 0), 'tid=' . $topic['tid']);
     return true;
 }
 /**
  * View queues (validating, locked, banned)
  *
  * @access	private
  * @param 	string		Queue to view [validating, locked, banned]
  * @return	void		[Outputs to screen]
  */
 private function _viewQueue($type = 'validating')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $this->request['ord'] = $this->request['ord'] ? $this->request['ord'] : '';
     $st = intval($this->request['st']) >= 0 ? intval($this->request['st']) : 0;
     $ord = $this->request['ord'] == 'asc' ? 'asc' : 'desc';
     $new_ord = $ord == 'asc' ? 'desc' : 'asc';
     $filter = $this->request['filter'] ? $this->request['filter'] : '';
     $q_extra = "";
     $content = "";
     //-----------------------------------------
     // Run teh query
     //-----------------------------------------
     switch ($type) {
         case 'validating':
             switch ($filter) {
                 case 'reg_user_validate':
                     if ($this->settings['reg_auth_type'] != 'admin') {
                         $q_extra = " AND v.new_reg=1 AND v.user_verified=0";
                     }
                     break;
                 case 'reg_admin_validate':
                     if ($this->settings['reg_auth_type'] == 'admin') {
                         $q_extra = " AND v.new_reg=1";
                     } else {
                         $q_extra = " AND v.new_reg=1 AND v.user_verified=1";
                     }
                     break;
                 case 'email_chg':
                     $q_extra = " AND v.email_chg=1";
                     break;
                 case 'coppa':
                     $q_extra = " AND v.coppa_user=1";
                     break;
             }
             $row = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as queue', 'from' => array('validating' => 'v'), 'where' => "v.lost_pass=0 AND m.member_group_id=" . $this->settings['auth_group'] . $q_extra, 'add_join' => array(array('from' => array('members' => 'm'), 'where' => 'm.member_id=v.member_id', 'type' => 'left'))));
             break;
         case 'locked':
             if ($this->settings['ipb_bruteforce_attempts']) {
                 $row = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as queue', 'from' => 'members', 'where' => "failed_login_count >= " . intval($this->settings['ipb_bruteforce_attempts'])));
             } else {
                 $row['queue'] = 0;
             }
             break;
         case 'banned':
             $row = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as queue', 'from' => 'members', 'where' => "member_banned=1"));
             break;
         case 'spam':
             $row = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as queue', 'from' => 'members', 'where' => IPSBWOptions::sql('bw_is_spammer', 'members_bitoptions', 'members', 'global', 'has')));
             break;
     }
     $cnt = intval($row['queue']);
     //-----------------------------------------
     // Grab default sorting
     //-----------------------------------------
     switch ($type) {
         case 'validating':
             $col = 'v.entry_date';
             break;
         case 'locked':
             $col = 'm.members_display_name';
             break;
         case 'banned':
             $col = 'm.members_display_name';
             break;
         case 'spam':
             $col = 'm.joined';
             break;
     }
     //-----------------------------------------
     // And actual sorting..
     //-----------------------------------------
     switch ($this->request['sort']) {
         case 'mem':
             $col = 'm.members_display_name';
             break;
         case 'email':
             $col = 'm.email';
             break;
         case 'sent':
             if ($type == 'validating') {
                 $col = 'v.entry_date';
             }
             break;
         case 'failed':
             if ($type == 'locked') {
                 $col = 'm.failed_login_count';
             }
             break;
         case 'group':
             if ($type == 'banned') {
                 $col = 'g.g_title';
             }
             break;
         case 'posts':
             $col = 'm.posts';
             break;
         case 'joined':
             $col = 'm.joined';
             break;
     }
     //-----------------------------------------
     // Pages...
     //-----------------------------------------
     $links = $this->registry->output->generatePagination(array('totalItems' => $cnt, 'itemsPerPage' => 75, 'currentStartValue' => $st, 'baseUrl' => $this->settings['base_url'] . "&amp;{$this->form_code}&amp;do={$type}&amp;ord={$ord}&amp;filter={$filter}"));
     //-----------------------------------------
     // Print...
     //-----------------------------------------
     if ($cnt > 0) {
         switch ($type) {
             case 'validating':
                 $this->DB->build(array('select' => 'v.*', 'from' => array('validating' => 'v'), 'where' => "v.lost_pass=0 AND m.member_group_id=" . $this->settings['auth_group'] . $q_extra, 'order' => $col . ' ' . $ord, 'limit' => array($st, 75), 'add_join' => array(array('select' => 'm.name, m.member_group_id, m.members_display_name, m.ip_address, m.member_id, m.email, m.posts, m.joined', 'from' => array('members' => 'm'), 'where' => 'm.member_id=v.member_id', 'type' => 'left'))));
                 break;
             case 'locked':
                 $this->DB->build(array('select' => 'm.member_group_id, m.members_display_name, m.ip_address, m.member_id, m.email, m.posts, m.joined, m.failed_logins, m.failed_login_count', 'from' => 'members m', 'where' => "m.failed_login_count >= " . intval($this->settings['ipb_bruteforce_attempts']), 'order' => $col . ' ' . $ord, 'limit' => array($st, 75)));
                 break;
             case 'banned':
                 $this->DB->build(array('select' => 'm.member_group_id, m.members_display_name, m.ip_address, m.member_id, m.email, m.posts, m.joined, m.failed_logins, m.failed_login_count', 'from' => array('members' => 'm'), 'where' => "m.member_banned=1", 'order' => $col . ' ' . $ord, 'limit' => array($st, 75), 'add_join' => array(array('select' => 'g.g_title', 'from' => array('groups' => 'g'), 'where' => 'g.g_id=m.member_group_id', 'type' => 'left'))));
                 break;
             case 'spam':
                 $this->DB->build(array('select' => 'm.*', 'from' => array('members' => 'm'), 'where' => IPSBWOptions::sql('bw_is_spammer', 'm.members_bitoptions', 'members', 'global', 'has'), 'order' => $col . ' ' . $ord, 'limit' => array($st, 75), 'add_join' => array(array('select' => 'g.g_title', 'from' => array('groups' => 'g'), 'where' => 'g.g_id=m.member_group_id', 'type' => 'left'))));
                 break;
         }
         $this->DB->execute();
         while ($r = $this->DB->fetch()) {
             $r['_joined'] = ipsRegistry::getClass('class_localization')->getDate($r['joined'], 'TINY');
             $r['members_display_name'] = $r['members_display_name'] ? $r['members_display_name'] : $this->lang->words['t_deletedmem'];
             $r['group_title'] = IPSLib::makeNameFormatted($this->caches['group_cache'][$r['member_group_id']]['g_title'], $r['member_group_id']);
             switch ($type) {
                 case 'validating':
                     $r['_coppa'] = $r['coppa_user'] ? $this->lang->words['t_coppa'] : '';
                     //-----------------------------------------
                     // Sort out 'where'
                     //-----------------------------------------
                     $r['_where'] = $r['lost_pass'] ? $this->lang->words['t_lostpass'] : ($r['new_reg'] ? $this->lang->words['t_userval'] : ($r['email_chg'] ? $this->lang->words['t_emailchange'] : $this->lang->words['t_na']));
                     if (isset($r['email_chg']) and $r['email_chg']) {
                         $r['_where'] .= " (<a href='" . $this->settings['base_url'] . "{$this->form_code}&amp;do=unappemail&amp;mid={$r['member_id']}'>{$this->lang->words['t_unapprove']}</a>)";
                     }
                     if ($r['new_reg'] and ($r['user_verified'] == 1 or $this->settings['reg_auth_type'] == 'admin')) {
                         $r['_where'] = $this->lang->words['t_adminval'];
                     }
                     //-----------------------------------------
                     // How long ago did this start?
                     //-----------------------------------------
                     $r['_hours'] = floor((time() - $r['entry_date']) / 3600);
                     $r['_days'] = intval($r['_hours'] / 24);
                     $r['_rhours'] = intval($r['_hours'] - $r['_days'] * 24);
                     //-----------------------------------------
                     // Format time
                     //-----------------------------------------
                     $r['_entry'] = ipsRegistry::getClass('class_localization')->getDate($r['entry_date'], 'TINY');
                     break;
                 case 'locked':
                     //-----------------------------------------
                     // Sort out lovely locked info
                     //-----------------------------------------
                     $used_ips = array();
                     $this_attempt = array();
                     $oldest = 0;
                     $newest = 0;
                     if ($r['failed_logins']) {
                         $failed_logins = explode(",", IPSText::cleanPermString($r['failed_logins']));
                         if (is_array($failed_logins) and count($failed_logins)) {
                             sort($failed_logins);
                             foreach ($failed_logins as $attempt) {
                                 $this_attempt = explode("-", $attempt);
                                 $used_ips[] = $this_attempt[1];
                             }
                             $oldest = array_shift($failed_logins);
                             $newest = array_pop($failed_logins);
                         }
                     }
                     $newest = explode("-", $newest);
                     $oldest = explode("-", $oldest);
                     $r['oldest_fail'] = ipsRegistry::getClass('class_localization')->getDate($oldest[0], 'SHORT');
                     $r['newest_fail'] = ipsRegistry::getClass('class_localization')->getDate($newest[0], 'SHORT');
                     //-----------------------------------------
                     // Some nice IP address info
                     //-----------------------------------------
                     $r['ip_addresses'] = "";
                     $used_ips = array_unique($used_ips);
                     foreach ($used_ips as $ip_address) {
                         $r['ip_addresses'] .= "{$this->lang->words['t_ipcolon']} <a href='" . $this->settings['base_url'] . "&amp;module=members&amp;section=tools&amp;do=learn_ip&amp;ip={$ip_address}'>{$ip_address}</a><br />";
                     }
                     break;
             }
             //-----------------------------------------
             // Print row
             //-----------------------------------------
             $function = $type . 'Row';
             $content .= $this->html->{$function}($r);
         }
     } else {
         $content = $this->html->queueNoRows(sprintf($this->lang->words['t_notype'], $this->lang->words['t_rowtype_' . $type]));
     }
     //-----------------------------------------
     // Output
     //-----------------------------------------
     $this->registry->output->html .= $this->html->queueWrapper($type, $content, $st, $new_ord, $links);
     //-----------------------------------------
     // Extra navigation
     //-----------------------------------------
     switch ($type) {
         case 'validating':
             $this->registry->output->extra_nav[] = array('', $this->lang->words['t_validating']);
             break;
         case 'locked':
             $this->registry->output->extra_nav[] = array('', $this->lang->words['t_locked']);
             break;
         case 'banned':
             $this->registry->output->extra_nav[] = array('', $this->lang->words['t_banned']);
             break;
     }
 }
Example #13
0
 /**
  * Function to resync a member's Twitter data
  *
  * @access	public
  * @param	mixed		Member Data in an array form (result of IPSMember::load( $id, 'all' ) ) or a member ID
  * @return	array 		Updated member data	
  *
  * EXCEPTION CODES:
  * NO_MEMBER		Member ID does not exist
  * NOT_LINKED		Member ID or data specified is not linked to a FB profile
  */
 public function syncMember($memberData)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $exProfile = array();
     /* Do we need to load a member? */
     if (!is_array($memberData)) {
         $memberData = IPSMember::load(intval($memberData), 'all');
     }
     /* Got a member? */
     if (!$memberData['member_id']) {
         throw new Exception('NO_MEMBER');
     }
     /* Linked account? */
     if (!$memberData['twitter_id']) {
         throw new Exception('NOT_LINKED');
     }
     /* Not completed sign up ( no display name ) */
     if ($memberData['member_group_id'] == $this->settings['auth_group']) {
         return false;
     }
     /* Thaw Options */
     $bwOptions = IPSBWOptions::thaw($memberData['tc_bwoptions'], 'twitter');
     /* Grab the data */
     try {
         $this->resetApi($memberData['twitter_token'], $memberData['twitter_secret']);
         if ($this->isConnected()) {
             $user = $this->fetchUserData();
             /* Load library */
             if ($bwOptions['tc_s_pic']) {
                 $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/photo.php', 'classes_member_photo');
                 $photo = new $classToLoad($this->registry);
                 $photo->save($memberData, 'twitter');
             }
             if ($bwOptions['tc_s_aboutme']) {
                 $exProfile['pp_about_me'] = IPSText::getTextClass('bbcode')->stripBadWords(IPSText::convertCharsets($user['description'], 'utf-8', IPS_DOC_CHAR_SET));
             }
             if ($bwOptions['tc_si_status'] and (isset($memberData['gbw_no_status_import']) and !$memberData['gbw_no_status_import']) and !$memberData['bw_no_status_update']) {
                 /* Fetch timeline */
                 $memberData['tc_last_sid_import'] = $memberData['tc_last_sid_import'] < 1 ? 100 : $memberData['tc_last_sid_import'];
                 $_updates = $this->fetchUserTimeline($user['id'], $memberData['tc_last_sid_import'], true);
                 /* Got any? */
                 if (count($_updates)) {
                     $update = array_shift($_updates);
                     if (is_array($update) and isset($update['text'])) {
                         /* Load status class */
                         if (!$this->registry->isClassLoaded('memberStatus')) {
                             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/status.php', 'memberStatus');
                             $this->registry->setClass('memberStatus', new $classToLoad(ipsRegistry::instance()));
                         }
                         /* Set Author */
                         $this->registry->getClass('memberStatus')->setAuthor($memberData);
                         $this->registry->getClass('memberStatus')->setStatusOwner($memberData);
                         /* Convert if need be */
                         if (IPS_DOC_CHAR_SET != 'UTF-8') {
                             $update['text'] = IPSText::utf8ToEntities($update['text']);
                         }
                         /* Set Content */
                         $this->registry->getClass('memberStatus')->setContent(trim(IPSText::getTextClass('bbcode')->stripBadWords($update['text'])));
                         /* Set as imported */
                         $this->registry->getClass('memberStatus')->setIsImport(1);
                         /* Set creator */
                         $this->registry->getClass('memberStatus')->setCreator('twitter');
                         /* Can we reply? */
                         if ($this->registry->getClass('memberStatus')->canCreate()) {
                             $this->registry->getClass('memberStatus')->create();
                             $exProfile['tc_last_sid_import'] = $update['id'];
                         }
                     }
                 }
             }
             /* Allowed profile customization? */
             if ($bwOptions['tc_s_bgimg'] and ($user['profile_background_image_url'] or $user['profile_background_color']) and ($this->memberData['gbw_allow_customization'] and !$this->memberData['bw_disable_customization'])) {
                 /* remove bg images */
                 IPSMember::getFunction()->removeUploadedBackgroundImages($memberData['member_id']);
                 $exProfile['pp_customization'] = serialize(array('bg_url' => $user['profile_background_image_url'], 'type' => $user['profile_background_image_url'] ? 'url' : 'color', 'bg_color' => IPSText::alphanumericalClean($user['profile_background_color']), 'bg_tile' => intval($user['profile_background_tile'])));
             }
             /* Update member */
             IPSMember::save($memberData['member_id'], array('core' => array('tc_lastsync' => time()), 'extendedProfile' => $exProfile));
             /* merge and return */
             $memberData['tc_lastsync'] = time();
             $memberData = array_merge($memberData, $exProfile);
         }
     } catch (Exception $e) {
     }
     return $memberData;
 }
 /**
  * UserCP Save Form: Ignore Users
  *
  * @access	public
  * @return	array	Errors
  */
 public function saveFacebook()
 {
     if (!IPSLib::fbc_enabled()) {
         $this->registry->getClass('output')->showError('fbc_disabled', 1005);
     }
     //-----------------------------------------
     // Data
     //-----------------------------------------
     $toSave = IPSBWOptions::thaw($this->memberData['members_bitoptions'], 'members');
     //-----------------------------------------
     // Loop and save... simple
     //-----------------------------------------
     foreach (array('fbc_s_pic', 'fbc_s_avatar', 'fbc_s_status', 'fbc_s_aboutme') as $field) {
         $toSave[$field] = intval($this->request[$field]);
     }
     IPSMember::save($this->memberData['member_id'], array('extendedProfile' => array('fb_bwoptions' => IPSBWOptions::freeze($toSave, 'facebook'))));
     //-----------------------------------------
     // Now sync
     //-----------------------------------------
     require_once IPS_ROOT_PATH . 'sources/classes/facebook/connect.php';
     $facebook = new facebook_connect($this->registry);
     try {
         $facebook->syncMember($this->memberData);
     } catch (Exception $error) {
         $msg = $error->getMessage();
         switch ($msg) {
             case 'NOT_LINKED':
             case 'NO_MEMBER':
                 break;
         }
     }
     return TRUE;
 }
Example #15
0
 /**
  * Save the member updates
  *
  * @return	@e void
  * @todo 	[Future] Determine what items should be editable and allow moderators to edit them
  */
 protected function _doEditMember()
 {
     $this->loadData();
     //-----------------------------------------
     // Check permissions
     //-----------------------------------------
     if (!$this->memberData['g_is_supmod']) {
         $this->registry->output->showError('mod_only_supermods', 10370, true, null, 403);
     }
     if (!$this->memberData['g_access_cp'] and $this->warn_member['g_access_cp']) {
         $this->registry->output->showError('mod_admin_edit', 3032, true, null, 403);
     }
     if ($this->request['auth_key'] != $this->member->form_hash) {
         $this->registry->output->showError('no_permission', 3032.1, null, null, 403);
     }
     //-----------------------------------------
     // Init
     //-----------------------------------------
     $editable = array();
     $isHtml = intval($this->request['sig_htmlstatus']);
     //-----------------------------------------
     // Signature and about me
     //-----------------------------------------
     /* Load parser */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
     $parser = new $classToLoad();
     $this->editor->setLegacyMode(false);
     //-----------------------------------------
     // Parse signature
     //-----------------------------------------
     /* Set content in editor */
     $this->editor->setAllowBbcode(true);
     $this->editor->setAllowSmilies(false);
     $this->editor->setIsHtml($this->caches['group_cache'][$this->warn_member['member_group_id']]['g_dohtml'] && $isHtml);
     $this->editor->setBbcodeSection('signatures');
     $signature = $this->editor->process($_POST['Post']);
     /* About Me */
     $aboutme = $this->editor->process($_POST['aboutme']);
     //-----------------------------------------
     // Add to array to save
     //-----------------------------------------
     $save['extendedProfile'] = array('signature' => $signature, 'pp_about_me' => $aboutme);
     $save['members'] = array('title' => $this->request['title']);
     //-----------------------------------------
     // Removing photo?
     //-----------------------------------------
     if ($this->request['photo'] == 1) {
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/photo.php', 'classes_member_photo');
         $photos = new $classToLoad($this->registry);
         $photos->remove($this->warn_member['member_id']);
     }
     //-----------------------------------------
     // Removing Restrictions?
     //-----------------------------------------
     if ($this->request['modpreview'] == 1) {
         $save['core']['mod_posts'] = 0;
     }
     if ($this->request['postingrestriction'] == 1) {
         $save['core']['restrict_post'] = 0;
     }
     if ($this->request['remove_suspension'] == 1) {
         $save['core']['temp_ban'] = 0;
     }
     //-----------------------------------------
     // Profile fields
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
     $fields = new $classToLoad();
     $fields->member_data = $this->warn_member;
     $fields->initData('edit');
     $fields->parseToSave($_POST);
     if (count($fields->out_fields)) {
         $save['customFields'] = $fields->out_fields;
     }
     //-----------------------------------------
     // Bitwise
     //-----------------------------------------
     if (isset($this->request['status_updates'])) {
         $bw = IPSBWOptions::thaw($this->warn_member['members_bitoptions'], 'members');
         $bw['bw_no_status_update'] = $this->request['status_updates'] ? 0 : 1;
         $save['core']['members_bitoptions'] = IPSBWOptions::freeze($bw, 'members');
     }
     //-----------------------------------------
     // Write it to the DB.
     //-----------------------------------------
     IPSMember::save($this->warn_member['member_id'], $save);
     //-----------------------------------------
     // Update signature content cache
     //-----------------------------------------
     /* Update cache */
     IPSContentCache::update($this->warn_member['member_id'], 'sig', $parser->display($signature));
     //-----------------------------------------
     // Add a mod log entry and redirect
     //-----------------------------------------
     $this->getModLibrary()->addModerateLog(0, 0, 0, 0, $this->lang->words['acp_edited_profile'] . " " . $this->warn_member['members_display_name']);
     $this->_redirect($this->lang->words['acp_edited_profile'] . " " . $this->warn_member['members_display_name']);
 }
 /**
  * Returns a list of all forums
  *
  * @return	array
  */
 public function getForumList()
 {
     /* Get the forums */
     $this->DB->build(array('select' => 'f.*', 'from' => array('forums' => 'f'), 'add_join' => array(array('select' => 'p.*', 'from' => array('permission_index' => 'p'), 'where' => "p.perm_type='forum' AND p.app='forums' AND p.perm_type_id=f.id", 'type' => 'left'), $this->registry->classItemMarking->getSqlJoin(array('item_app_key_1' => 'f.id')))));
     $q = $this->DB->execute();
     /* Loop through and build an array of forums */
     $forums_list = array();
     $update_seo = array();
     $tempForums = array();
     while ($f = $this->DB->fetch($q)) {
         $tempForums[$f['parent_id'] . '.' . $f['position'] . '.' . $f['id']] = $f;
     }
     /* Sort in PHP */
     $tempForums = IPSLib::knatsort($tempForums);
     foreach ($tempForums as $posData => $f) {
         $fr = array();
         /* Add back into topic markers */
         $f = $this->registry->classItemMarking->setFromSqlJoin($f, 'forums');
         /**
          * This is here in case the SEO name isn't stored for some reason.
          * We'll parse it and then update the forums table - should only happen once
          */
         if (!$f['name_seo']) {
             /* SEO name */
             $f['name_seo'] = IPSText::makeSeoTitle($f['name']);
             $update_seo[$f['id']] = $f['name_seo'];
         }
         /* Reformat the array for a category */
         if ($f['parent_id'] == -1) {
             $fr = $f;
             $fr['parent_id'] = 'root';
             $fr['hide_last_info'] = 0;
             $fr['can_view_others'] = 0;
         } else {
             $fr = $f;
             $fr['description'] = isset($f['description']) ? $f['description'] : '';
         }
         $fr = array_merge($fr, $this->registry->permissions->parse($f));
         /* Unpack bitwise fields */
         $_tmp = IPSBWOptions::thaw($fr['forums_bitoptions'], 'forums', 'forums');
         if (count($_tmp)) {
             foreach ($_tmp as $k => $v) {
                 /* Trigger notice if we have DB field */
                 if (isset($fr[$k])) {
                     trigger_error("Thawing bitwise options for FORUMS: Bitwise field '{$k}' has overwritten DB field '{$k}'", E_USER_WARNING);
                 }
                 $fr[$k] = $v;
             }
         }
         /* Add... */
         $forums_list[$fr['id']] = $fr;
     }
     $this->allForums = $forums_list;
     /**
      * Update forums table if SEO name wasn't cached yet
      */
     if (count($update_seo)) {
         foreach ($update_seo as $k => $v) {
             $this->DB->update('forums', array('name_seo' => $v), 'id=' . $k);
         }
     }
     return $forums_list;
 }
 /**
  * Build member's bitwise field
  *
  * @access	public
  * @param	mixed		Either an array of member data or a member ID
  * @return	array
  */
 public static function buildBitWiseOptions($member)
 {
     //-----------------------------------------
     // Load the member?
     //-----------------------------------------
     if (!is_array($member) and $member == intval($member)) {
         $member = self::load($member, 'core,extendedProfile');
     }
     /* Unpack bitwise fields */
     $_tmp = IPSBWOptions::thaw($member['members_bitoptions'], 'members', 'global');
     if (count($_tmp)) {
         foreach ($_tmp as $k => $v) {
             /* Trigger notice if we have DB field */
             if (isset($member[$k])) {
                 trigger_error("Thawing bitwise options for MEMBERS: Bitwise field '{$k}' has overwritten DB field '{$k}'", E_USER_WARNING);
             }
             $member[$k] = $v;
         }
     }
     return $member;
 }
 /**
  * Log in and create a brand new forum account
  *
  * @access	public
  * @return	mixed		On success, an array containing a message and redirect URL
  *
  * EXCEPTION CODES:
  * NO_FACEBOOK_USER_LOGGED_IN		System cannot detect a logged in facebook user
  * NO_FB_EMAIL						Could not locate a facebook proxy email
  * CREATION_FAIL					Account creation failed
  * ALREADY_LINKED_MEMBER			The facebook UID is already linked to another IPB account
  */
 public function loginWithNewAccount()
 {
     $loggedInUser = $this->FB()->get_loggedin_user();
     if (!$loggedInUser) {
         throw new Exception('NO_FACEBOOK_USER_LOGGED_IN');
     }
     /* Ensure that there is not already a linked account */
     /* Now get the linked user */
     $_member = IPSMember::load($loggedInUser, 'all', 'fb_uid');
     if ($_member['member_id']) {
         throw new Exception('ALREADY_LINKED_MEMBER');
     }
     /* Now fetch more data */
     $_fbData = $this->API()->users_getInfo($loggedInUser, array('name', 'proxied_email', 'timezone', 'pic', 'pic_square', 'pic_square_with_logo', 'about_me'));
     $fbData = $_fbData[0];
     if (!$fbData['proxied_email']) {
         throw new Exception('NO_FB_EMAIL');
     }
     /* Generate BW options */
     foreach (array('fbc_s_pic', 'fbc_s_avatar', 'fbc_s_status', 'fbc_s_aboutme') as $field) {
         $toSave[$field] = 1;
     }
     $fb_bwoptions = IPSBWOptions::freeze($toSave, 'facebook');
     /* Generate FB hash */
     $hash = $this->generateEmailHash($fbData['proxied_email']);
     $memberData = IPSMember::create(array('core' => array('name' => IPSText::convertCharsets($fbData['name'], 'utf-8', IPS_DOC_CHAR_SET), 'members_display_name' => IPSText::convertCharsets($fbData['name'], 'utf-8', IPS_DOC_CHAR_SET), 'members_created_remote' => 1, 'member_group_id' => $this->settings['fbc_mgid'] ? $this->settings['fbc_mgid'] : $this->settings['member_group'], 'email' => $fbData['proxied_email'], 'time_offset' => $fbData['timezone'], 'fb_uid' => $loggedInUser, 'fb_emailhash' => $hash), 'extendedProfile' => array('pp_about_me' => IPSText::convertCharsets($fbData['about_me'], 'utf-8', IPS_DOC_CHAR_SET), 'fb_photo' => $fbData['pic'], 'fb_photo_thumb' => $fbData['pic_square_with_logo'], 'fb_bwoptions' => $fb_bwoptions, 'avatar_location' => $fbData['pic_square'], 'avatar_type' => 'facebook')), TRUE);
     if (!$memberData['member_id']) {
         throw new Exception('CREATION_FAIL');
     }
     /* Register with Facebook */
     try {
         $reg = $this->API()->connect_registerUsers(json_encode(array(array('email_hash' => $hash, 'account_id' => $memberData['member_id']))));
     } catch (Exception $error) {
         //print $error->getMessage(); exit();
     }
     //-----------------------------------------
     // Update Stats
     //-----------------------------------------
     $cache = $this->cache->getCache('stats');
     if ($memberData['members_display_name'] and $memberData['member_id']) {
         $cache['last_mem_name'] = $memberData['members_display_name'];
         $cache['last_mem_id'] = $memberData['member_id'];
     }
     $cache['mem_count'] += 1;
     $this->cache->setCache('stats', $cache, array('array' => 1, 'deletefirst' => 0));
     //-----------------------------------------
     // New registration emails
     //-----------------------------------------
     if ($this->settings['new_reg_notify']) {
         $this->lang->loadLanguageFile(array('public_register'), 'core');
         $date = $this->registry->class_localization->getDate(time(), 'LONG', 1);
         IPSText::getTextClass('email')->getTemplate('admin_newuser');
         IPSText::getTextClass('email')->buildMessage(array('DATE' => $date, 'MEMBER_NAME' => $memberData['members_display_name']));
         IPSText::getTextClass('email')->subject = $this->lang->words['new_registration_email1'] . $this->settings['board_name'];
         IPSText::getTextClass('email')->to = $this->settings['email_in'];
         IPSText::getTextClass('email')->sendMail();
     }
     /* Here, so log us in!! */
     return $this->_login()->loginWithoutCheckingCredentials($memberData['member_id'], TRUE);
 }
 /**
  * List members
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private function _memberList()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $data = $this->_generateFilterBoxes();
     $_sql = array();
     $st = intval($this->request['st']);
     $members = array();
     $perpage = 20;
     //-----------------------------------------
     // FILTERS
     //-----------------------------------------
     if ($data['member_contains_text']) {
         $_field = '';
         $_text = $this->DB->addSlashes($data['member_contains_text']);
         switch ($data['member_contains']) {
             default:
             case 'member_id':
                 $_field = 'm.member_id';
                 break;
             case 'name':
                 $_field = 'm.name';
                 break;
             case 'members_display_name':
                 $_field = 'm.members_display_name';
                 break;
             case 'email':
                 $_field = 'm.email';
                 break;
             case 'ip_address':
                 $_field = 'm.ip_address';
                 break;
             case 'signature':
                 $_field = 'pp.signature';
                 break;
         }
         switch ($data['member_contains_type']) {
             default:
             case 'contains':
                 $_sql[] = $_field . " LIKE '%" . $_text . "%'";
                 break;
             case 'begins':
                 $_sql[] = $_field . " LIKE '" . $_text . "%'";
                 break;
             case 'ends':
                 $_sql[] = $_field . " LIKE '%" . $_text . "'";
                 break;
             case 'equals':
                 $_sql[] = $_field . " = '" . $_text . "'";
                 break;
         }
     }
     if ($data['member_type']) {
         switch ($data['member_type']) {
             case 'suspended':
                 $_sql[] = "m.temp_ban > 0";
                 break;
             case 'notsuspended':
                 $_sql[] = "( m.temp_ban < 1 or m.temp_ban='' or m.temp_ban " . $this->DB->buildIsNull(true) . " )";
                 break;
         }
     }
     /* Banned status */
     if ($data['banned_type']) {
         switch ($data['banned_type']) {
             case 'banned':
                 $_sql[] = "m.member_banned=1";
                 break;
             case 'notbanned':
                 $_sql[] = "m.member_banned=0";
                 break;
         }
     }
     /* Spam status */
     if ($data['spam_type']) {
         switch ($data['spam_type']) {
             case 'spam':
                 $_sql[] = IPSBWOptions::sql('bw_is_spammer', 'm.members_bitoptions', 'members', 'global', 'has');
                 break;
             case 'notspam':
                 $_sql[] = "NOT (" . IPSBWOptions::sql('bw_is_spammer', 'm.members_bitoptions', 'members', 'global', 'has') . ")";
                 break;
         }
     }
     if ($data['primary_group']) {
         $_sql[] = "m.member_group_id=" . intval($data['primary_group']);
     }
     if ($data['post_count'] and $data['post_count_type']) {
         $_type = '';
         if ($data['post_count_type'] == 'gt') {
             $_type = '>';
         } else {
             if ($data['post_count_type'] == 'lt') {
                 $_type = '<';
             } else {
                 if ($data['post_count_type'] == 'eq') {
                     $_type = '=';
                 }
             }
         }
         if ($_type) {
             $_sql[] = "m.posts" . $_type . intval($data['post_count']);
         }
     }
     if ($data['secondary_group']) {
         $_sql[] = "( m.mgroup_others LIKE '%," . $data['secondary_group'] . ",%' OR " . "m.mgroup_others LIKE '" . $data['secondary_group'] . ",%' OR " . "m.mgroup_others LIKE '%," . $data['secondary_group'] . "' OR " . "m.mgroup_others='" . $data['secondary_group'] . "' )";
     }
     foreach (array('reg', 'post', 'active') as $_bit) {
         foreach (array('from', 'to') as $_when) {
             $bit = 'date_' . $_bit . '_' . $_when;
             if ($data[$bit]) {
                 //-----------------------------------------
                 // mm/dd/yyyy instead of mm-dd-yyyy
                 //-----------------------------------------
                 $data[$bit] = str_replace('/', '-', $data[$bit]);
                 list($month, $day, $year) = explode('-', $data[$bit]);
                 if (!checkdate($month, $day, $year)) {
                     $this->registry->output->global_message = sprintf($this->lang->words['m_daterange'], $month, $day, $year);
                 } else {
                     $time_int = mktime(0, 0, 0, $month, $day, $year);
                     switch ($_bit) {
                         case 'reg':
                             $field = 'joined';
                             break;
                         case 'post':
                             $field = 'last_post';
                             break;
                         case 'active':
                             $field = 'last_activity';
                             break;
                     }
                     if ($_when == 'from') {
                         $_sql[] = 'm.' . $field . ' > ' . $time_int;
                     } else {
                         $_sql[] = 'm.' . $field . ' < ' . $time_int;
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Check we have correct fields
     //-----------------------------------------
     switch ($data['order_direction']) {
         case 'asc':
             $order_direction = 'asc';
             break;
         default:
         case 'desc':
             $order_direction = 'desc';
             break;
     }
     switch ($data['order_by']) {
         default:
         case 'joined':
             $order_by = 'm.joined';
             break;
         case 'members_l_username':
             $order_by = 'm.members_l_username';
             break;
         case 'members_l_display_name':
             $order_by = 'm.members_l_display_name';
             break;
         case 'email':
             $order_by = 'm.email';
             break;
     }
     //-----------------------------------------
     // Custom fields...
     //-----------------------------------------
     if (is_array($data['custom_fields']) and count($data['custom_fields'])) {
         foreach ($data['custom_fields'] as $id => $value) {
             if ($value) {
                 $_sql[] = 'p.field_' . $id . " LIKE '%" . $value . "%'";
             }
         }
     }
     //-----------------------------------------
     // get 'owt?
     //-----------------------------------------
     $real_query = count($_sql) ? implode(" AND ", $_sql) : '';
     //-----------------------------------------
     // Get the number of results
     //-----------------------------------------
     $count = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => array('members' => 'm'), 'where' => $real_query, 'add_join' => array(0 => array('from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), 1 => array('from' => array('pfields_content' => 'p'), 'where' => 'p.member_id=m.member_id', 'type' => 'left'))));
     if ($count['count'] < 1) {
         $this->registry->output->global_message = $this->lang->words['m_nomembers'];
         // Reset the filter
         $real_query = '';
         // And reset the cookie so we don't get the message on every page view
         ipsRegistry::getClass('adminFunctions')->staffSaveCookie('memberFilter', array());
         $count = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'members'));
     }
     $pages = $this->registry->output->generatePagination(array('totalItems' => $count['count'], 'itemsPerPage' => $perpage, 'currentStartValue' => $st, 'baseUrl' => $this->settings['base_url'] . "&{$this->form_code}&do=" . $this->request['do']));
     //-----------------------------------------
     // Run the query
     //-----------------------------------------
     $this->DB->build(array('select' => 'm.*, m.member_id as mem_id', 'from' => array('members' => 'm'), 'where' => $real_query, 'order' => $order_by . ' ' . $order_direction, 'limit' => array($st, $perpage), 'add_join' => array(1 => array('select' => 'p.*', 'from' => array('pfields_content' => 'p'), 'where' => 'p.member_id=m.member_id', 'type' => 'left'), 2 => array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'))));
     $outer = $this->DB->execute();
     while ($r = $this->DB->fetch($outer)) {
         $r['member_id'] = $r['mem_id'];
         $r['_joined'] = $this->registry->class_localization->getDate($r['joined'], 'JOINED');
         $r['group_title'] = $this->caches['group_cache'][$r['member_group_id']]['g_title'];
         $members[] = IPSMember::buildDisplayData($r);
     }
     //-----------------------------------------
     // Prune you fookers?
     //-----------------------------------------
     if ($data['search_type'] == 'delete') {
         $this->_memberPruneForm($count['count']);
         return;
     } else {
         if ($data['search_type'] == 'move') {
             $this->_memberMoveForm($count['count']);
             return;
         }
     }
     $this->registry->output->extra_nav[] = array('', $this->lang->words['m_viewlist']);
     $this->registry->output->html .= $this->html->members_list($members, $pages);
 }
Example #20
0
 /**
  * Get 12 random friends
  *
  * @param	array 	$member	Member data
  * @return	@e array
  */
 protected function _getRandomFriends($member)
 {
     # Get random number from member's friend cache... grab 10 random. array_rand( array, no.)
     # also fall back on last 10 if no cache
     $_member_ids = array();
     $friends = array();
     if ($member['pp_setting_count_friends'] > 0 && $this->settings['friends_enabled']) {
         $member['_cache'] = IPSMember::unpackMemberCache($member['members_cache']);
         if (is_array($member['_cache']['friends']) and count($member['_cache']['friends'])) {
             foreach ($member['_cache']['friends'] as $id => $approved) {
                 $id = intval($id);
                 if ($approved and $id) {
                     $_member_ids[] = $id;
                 }
             }
             $member['_total_approved_friends'] = count($_member_ids);
             if (is_array($_member_ids) and $member['_total_approved_friends']) {
                 $_max = $member['_total_approved_friends'] > 12 ? 12 : $member['_total_approved_friends'];
                 $_rand = array_rand($_member_ids, $_max);
                 $_final = array();
                 # If viewing member is in list, let's show em
                 if (in_array($this->memberData['member_id'], $_member_ids)) {
                     $_final[] = $this->memberData['member_id'];
                     $new_mids = array();
                     foreach ($_member_ids as $mid) {
                         if ($mid == $this->memberData['member_id']) {
                             continue;
                         }
                         $new_mids[] = $mid;
                     }
                     $_member_ids = $new_mids;
                     unset($new_mids);
                     if (is_array($_rand)) {
                         if (count($_rand) >= 12) {
                             array_pop($_rand);
                         }
                     }
                 }
                 if (is_array($_rand) and count($_rand)) {
                     foreach ($_rand as $_id) {
                         $_final[] = $_member_ids[$_id];
                     }
                 }
                 if (count($_final)) {
                     $sql_extra = ' AND friends_friend_id IN (' . IPSText::cleanPermString(implode(',', $_final)) . ')';
                 }
             }
         }
         /* Fetch friends */
         $_memberIds = array();
         $_members = array();
         $_friends = array();
         $this->DB->build(array('select' => 'f.*', 'from' => array('profile_friends' => 'f'), 'add_join' => array(array('from' => array('members' => 'm'), 'where' => 'm.member_id=f.friends_friend_id')), 'where' => 'friends_member_id=' . $member['member_id'] . ' AND friends_approved=1' . ' AND m.member_banned=0 AND ( ! ' . IPSBWOptions::sql('bw_is_spammer', 'members_bitoptions', 'members', 'global', 'has') . ')' . $sql_extra, 'limit' => array(0, 12), 'order' => 'friends_approved DESC'));
         $this->DB->execute();
         while ($row = $this->DB->fetch()) {
             $_memberIds[] = $row['friends_friend_id'];
             $_friends[] = $row;
         }
         /* Got members? */
         $_members = IPSMember::load($_memberIds, 'core,extendedProfile');
         foreach ($_friends as $row) {
             if (!isset($_members[$row['friends_friend_id']])) {
                 continue;
             }
             $row = array_merge($row, $_members[$row['friends_friend_id']]);
             $row['_friends_added'] = ipsRegistry::getClass('class_localization')->getDate($row['friends_added'], 'SHORT');
             $row = IPSMember::buildProfilePhoto($row);
             $friends[] = $row;
         }
     }
     return $friends;
 }
 /**
  * Upload personal photo function
  * Assumes all security checks have been performed by this point
  *
  * @access	public
  * @param	integer		[Optional] member id instead of current member
  * @return 	array  		[ error (error message), status (status message [ok/fail] ) ]
  */
 public function uploadPhoto($member_id = 0)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $return = array('error' => '', 'status' => '', 'final_location' => '', 'final_width' => '', 'final_height' => '', 't_final_location' => '', 't_final_width' => '', 't_final_height' => '');
     $delete_photo = intval($_POST['delete_photo']);
     $member_id = $member_id ? intval($member_id) : intval($this->memberData['member_id']);
     $real_name = '';
     $upload_dir = '';
     $final_location = '';
     $final_width = '';
     $final_height = '';
     $t_final_location = '';
     $t_final_width = '';
     $t_final_height = '';
     $t_real_name = '';
     $t_height = 50;
     $t_width = 50;
     if (!$member_id) {
         return array('status' => 'cannot_find_member');
     }
     list($p_max, $p_width, $p_height) = explode(":", $this->memberData['g_photo_max_vars']);
     $this->settings['disable_ipbsize'] = 0;
     //-----------------------------------------
     // Sort out upload dir
     //-----------------------------------------
     /* Fix for bug 5075 */
     $this->settings['upload_dir'] = str_replace('&#46;', '.', $this->settings['upload_dir']);
     $upload_path = $this->settings['upload_dir'];
     # Preserve original path
     $_upload_path = $this->settings['upload_dir'];
     //-----------------------------------------
     // Already a dir?
     //-----------------------------------------
     if (!file_exists($upload_path . "/profile")) {
         if (@mkdir($upload_path . "/profile", 0777)) {
             @file_put_contents($upload_path . '/profile/index.html', '');
             @chmod($upload_path . "/profile", 0777);
             # Set path and dir correct
             $upload_path .= "/profile";
             $upload_dir = "profile/";
         } else {
             # Set path and dir correct
             $upload_dir = "";
         }
     } else {
         # Set path and dir correct
         $upload_path .= "/profile";
         $upload_dir = "profile/";
     }
     //-----------------------------------------
     // Deleting the photo?
     //-----------------------------------------
     if ($delete_photo) {
         $memberData = IPSMember::load($member_id);
         $bwOptions = IPSBWOptions::thaw($memberData['fb_bwoptions'], 'facebook');
         $bwOptions['fbc_s_pic'] = 0;
         $this->removeUploadedPhotos($member_id, $upload_path);
         IPSMember::save($member_id, array('extendedProfile' => array('pp_main_photo' => '', 'pp_main_width' => 0, 'pp_main_height' => 0, 'pp_thumb_photo' => '', 'pp_thumb_width' => 0, 'pp_thumb_height' => 0, 'fb_photo' => '', 'fb_photo_thumb' => '', 'fb_bwoptions' => IPSBWOptions::freeze($bwOptions, 'facebook'))));
         $return['status'] = 'deleted';
         return $return;
     }
     //-----------------------------------------
     // Lets check for an uploaded photo..
     //-----------------------------------------
     if ($_FILES['upload_photo']['name'] != "" and $_FILES['upload_photo']['name'] != "none") {
         //-----------------------------------------
         // Are we allowed to upload this photo?
         //-----------------------------------------
         if ($p_max < 0) {
             $return['status'] = 'fail';
             $return['error'] = 'no_photo_upload_permission';
         }
         //-----------------------------------------
         // Remove any uploaded photos...
         //-----------------------------------------
         $this->removeUploadedPhotos($member_id, $upload_path);
         $real_name = 'photo-' . $member_id;
         //-----------------------------------------
         // Load the library
         //-----------------------------------------
         require_once IPS_KERNEL_PATH . 'classUpload.php';
         $upload = new classUpload();
         //-----------------------------------------
         // Set up the variables
         //-----------------------------------------
         $upload->out_file_name = 'photo-' . $member_id;
         $upload->out_file_dir = $upload_path;
         $upload->max_file_size = $p_max * 1024 * 8;
         // Allow xtra for compression
         $upload->upload_form_field = 'upload_photo';
         //-----------------------------------------
         // Populate allowed extensions
         //-----------------------------------------
         if (is_array($this->cache->getCache('attachtypes')) and count($this->cache->getCache('attachtypes'))) {
             foreach ($this->cache->getCache('attachtypes') as $data) {
                 if ($data['atype_photo']) {
                     if ($data['atype_extension'] == 'swf' and $this->settings['disable_flash']) {
                         continue;
                     }
                     $upload->allowed_file_ext[] = $data['atype_extension'];
                 }
             }
         }
         //-----------------------------------------
         // Upload...
         //-----------------------------------------
         $upload->process();
         //-----------------------------------------
         // Error?
         //-----------------------------------------
         if ($upload->error_no) {
             switch ($upload->error_no) {
                 case 1:
                     // No upload
                     $return['status'] = 'fail';
                     $return['error'] = 'upload_failed';
                     break;
                 case 2:
                     // Invalid file ext
                     $return['status'] = 'fail';
                     $return['error'] = 'invalid_file_extension';
                     break;
                 case 3:
                     // Too big...
                     $return['status'] = 'fail';
                     $return['error'] = 'upload_to_big';
                     break;
                 case 4:
                     // Cannot move uploaded file
                     $return['status'] = 'fail';
                     $return['error'] = 'upload_failed';
                     break;
                 case 5:
                     // Possible XSS attack (image isn't an image)
                     $return['status'] = 'fail';
                     $return['error'] = 'upload_failed';
                     break;
             }
             return $return;
         }
         //-----------------------------------------
         // Still here?
         //-----------------------------------------
         $real_name = $upload->parsed_file_name;
         $t_real_name = $upload->parsed_file_name;
         //-----------------------------------------
         // Check image size...
         //-----------------------------------------
         if (!$this->settings['disable_ipbsize']) {
             $imageDimensions = getimagesize($upload_path . '/' . $real_name);
             if ($imageDimensions[0] > $p_width or $imageDimensions[1] > $p_height) {
                 //-----------------------------------------
                 // Main photo
                 //-----------------------------------------
                 require_once IPS_KERNEL_PATH . "classImage.php";
                 require_once IPS_KERNEL_PATH . "classImageGd.php";
                 $image = new classImageGd();
                 $image->init(array('image_path' => $upload_path, 'image_file' => $real_name));
                 $return = $image->resizeImage($p_width, $p_height);
                 $image->writeImage($upload_path . '/' . 'photo-' . $member_id . '.' . $upload->file_extension);
                 $t_real_name = $return['thumb_location'] ? $return['thumb_location'] : $real_name;
                 $im['img_width'] = $return['newWidth'] ? $return['newWidth'] : $image->cur_dimensions['width'];
                 $im['img_height'] = $return['newHeight'] ? $return['newHeight'] : $image->cur_dimensions['height'];
                 //-----------------------------------------
                 // MINI photo
                 //-----------------------------------------
                 $image->init(array('image_path' => $upload_path, 'image_file' => $t_real_name));
                 $return = $image->resizeImage($t_width, $t_height);
                 $image->writeImage($upload_path . '/' . 'photo-thumb-' . $member_id . '.' . $upload->file_extension);
                 $t_im['img_width'] = $return['newWidth'];
                 $t_im['img_height'] = $return['newHeight'];
                 $t_im['img_location'] = count($return) ? 'photo-thumb-' . $member_id . '.' . $upload->file_extension : $real_name;
             } else {
                 $im['img_width'] = $imageDimensions[0];
                 $im['img_height'] = $imageDimensions[1];
                 //-----------------------------------------
                 // Mini photo
                 //-----------------------------------------
                 $_data = IPSLib::scaleImage(array('max_height' => $t_height, 'max_width' => $t_width, 'cur_width' => $im['img_width'], 'cur_height' => $im['img_height']));
                 $t_im['img_width'] = $_data['img_width'];
                 $t_im['img_height'] = $_data['img_height'];
                 $t_im['img_location'] = $real_name;
             }
         } else {
             //-----------------------------------------
             // Main photo
             //-----------------------------------------
             $w = intval($this->request['man_width']) ? intval($this->request['man_width']) : $p_width;
             $h = intval($this->request['man_height']) ? intval($this->request['man_height']) : $p_height;
             $im['img_width'] = $w > $p_width ? $p_width : $w;
             $im['img_height'] = $h > $p_height ? $p_height : $h;
             //-----------------------------------------
             // Mini photo
             //-----------------------------------------
             $_data = IPSLib::scaleImage(array('max_height' => $t_height, 'max_width' => $t_width, 'cur_width' => $im['img_width'], 'cur_height' => $im['img_height']));
             $t_im['img_width'] = $_data['img_width'];
             $t_im['img_height'] = $_data['img_height'];
             $t_im['img_location'] = $real_name;
         }
         //-----------------------------------------
         // Check the file size (after compression)
         //-----------------------------------------
         if (filesize($upload_path . "/" . $real_name) > $p_max * 1024) {
             @unlink($upload_path . "/" . $real_name);
             // Too big...
             $return['status'] = 'fail';
             $return['error'] = 'upload_to_big';
             return $return;
         }
         //-----------------------------------------
         // Main photo
         //-----------------------------------------
         $final_location = $upload_dir . $real_name;
         $final_width = $im['img_width'];
         $final_height = $im['img_height'];
         //-----------------------------------------
         // Mini photo
         //-----------------------------------------
         $t_final_location = $upload_dir . $t_im['img_location'];
         $t_final_width = $t_im['img_width'];
         $t_final_height = $t_im['img_height'];
     } else {
         $return['status'] = 'ok';
         return $return;
     }
     //-----------------------------------------
     // Return...
     //-----------------------------------------
     $return['final_location'] = $final_location;
     $return['final_width'] = $final_width;
     $return['final_height'] = $final_height;
     $return['t_final_location'] = $t_final_location;
     $return['t_final_width'] = $t_final_width;
     $return['t_final_height'] = $t_final_height;
     $return['status'] = 'ok';
     return $return;
 }
Example #22
0
 /**
  * Uploads a new photo for the member [process]
  *
  * @return	@e void
  */
 protected function _memberNewPhoto()
 {
     if (!$this->request['member_id']) {
         $this->registry->output->showError($this->lang->words['m_specify'], 11224);
     }
     $member = IPSMember::load($this->request['member_id']);
     //-----------------------------------------
     // Allowed to upload pics for administrators?
     //-----------------------------------------
     if ($member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_photo_admin')) {
         $this->registry->output->global_message = $this->lang->words['m_noupload'];
         $this->_memberView();
         return;
     }
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/photo.php', 'classes_member_photo');
     $photos = new $classToLoad($this->registry);
     $status = $photos->uploadPhoto(intval($this->request['member_id']));
     if ($status['status'] == 'fail') {
         switch ($status['error']) {
             default:
             case 'upload_failed':
                 $this->registry->output->showError($this->lang->words['m_upfailed'], 11225);
                 break;
             case 'invalid_file_extension':
                 $this->registry->output->showError($this->lang->words['m_invfileext'], 11226);
                 break;
             case 'upload_to_big':
                 $this->registry->output->showError($this->lang->words['m_thatswhatshesaid'], 11227);
                 break;
         }
     } else {
         $bwOptions = IPSBWOptions::thaw($member['fb_bwoptions'], 'facebook');
         $tcbwOptions = IPSBWOptions::thaw($member['tc_bwoptions'], 'twitter');
         $bwOptions['fbc_s_pic'] = 0;
         $tcbwOptions['tc_s_pic'] = 0;
         IPSMember::save($this->request['member_id'], array('extendedProfile' => array('pp_main_photo' => $status['final_location'], 'pp_main_width' => intval($status['final_width']), 'pp_main_height' => intval($status['final_height']), 'pp_thumb_photo' => $status['t_final_location'], 'pp_thumb_width' => intval($status['t_final_width']), 'pp_thumb_height' => intval($status['t_final_height']), 'pp_photo_type' => 'custom', 'pp_profile_update' => IPS_UNIX_TIME_NOW, 'fb_photo' => '', 'fb_photo_thumb' => '', 'fb_bwoptions' => IPSBWOptions::freeze($bwOptions, 'facebook'), 'tc_photo' => '', 'tc_bwoptions' => IPSBWOptions::freeze($tcbwOptions, 'twitter'))));
         //-----------------------------------------
         // Redirect
         //-----------------------------------------
         $this->registry->output->global_message = $this->lang->words['m_photoupdated'];
         $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&amp;do=viewmember&amp;member_id=' . $this->request['member_id']);
     }
 }
Example #23
0
 /**
  * Function to resync a member's Facebook data
  *
  * @access	public
  * @param	mixed		Member Data in an array form (result of IPSMember::load( $id, 'all' ) ) or a member ID
  * @return	array 		Updated member data	
  *
  * EXCEPTION CODES:
  * NO_MEMBER		Member ID does not exist
  * NOT_LINKED		Member ID or data specified is not linked to a FB profile
  */
 public function syncMember($memberData)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $exProfile = array();
     /* Do we need to load a member? */
     if (!is_array($memberData)) {
         $memberData = IPSMember::load(intval($memberData), 'all');
     }
     /* Got a member? */
     if (!$memberData['member_id']) {
         throw new Exception('NO_MEMBER');
     }
     /* Linked account? */
     if (!$memberData['fb_uid']) {
         throw new Exception('NOT_LINKED');
     }
     /* Thaw Options */
     $bwOptions = IPSBWOptions::thaw($memberData['fb_bwoptions'], 'facebook');
     /* Grab the data */
     try {
         $this->resetApi($memberData['fb_token'], $memberData['fb_uid']);
         if ($this->isConnected()) {
             $user = $this->fetchUserData();
             /* Load library */
             if ($bwOptions['fbc_s_pic']) {
                 $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/photo.php', 'classes_member_photo');
                 $photo = new $classToLoad($this->registry);
                 $photo->save($memberData, 'facebook');
             }
             if ($bwOptions['fbc_si_status'] and (isset($memberData['gbw_no_status_import']) and !$memberData['gbw_no_status_import']) and !$memberData['bw_no_status_update']) {
                 /* Fetch timeline */
                 //$memberData['tc_last_sid_import'] = ( $memberData['tc_last_sid_import'] < 1 ) ? 100 : $memberData['tc_last_sid_import'];
                 $_updates = $this->fetchUserTimeline($user['id'], 0, true);
                 /* Got any? */
                 if (count($_updates)) {
                     $update = array_shift($_updates);
                     if (is_array($update) and isset($update['message'])) {
                         /* @link	http://community.invisionpower.com/tracker/issue-27746-video-in-facebook-status */
                         $update['message'] = strip_tags($update['message']);
                         /* Load status class */
                         if (!$this->registry->isClassLoaded('memberStatus')) {
                             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/status.php', 'memberStatus');
                             $this->registry->setClass('memberStatus', new $classToLoad(ipsRegistry::instance()));
                         }
                         /* Set Author */
                         $this->registry->getClass('memberStatus')->setAuthor($memberData);
                         $this->registry->getClass('memberStatus')->setStatusOwner($memberData);
                         /* Convert if need be */
                         if (IPS_DOC_CHAR_SET != 'UTF-8') {
                             $update['message'] = IPSText::utf8ToEntities($update['message']);
                         }
                         /* Set Content */
                         $this->registry->getClass('memberStatus')->setContent(trim(IPSText::getTextClass('bbcode')->stripBadWords($update['message'])));
                         /* Set as imported */
                         $this->registry->getClass('memberStatus')->setIsImport(1);
                         /* Set creator */
                         $this->registry->getClass('memberStatus')->setCreator('facebook');
                         /* Can we reply? */
                         if ($this->registry->getClass('memberStatus')->canCreate()) {
                             $this->registry->getClass('memberStatus')->create();
                             //$exProfile['tc_last_sid_import'] = $update['id'];
                         }
                     }
                 }
             }
             /* Update member */
             IPSMember::save($memberData['member_id'], array('core' => array('fb_lastsync' => time()), 'extendedProfile' => $exProfile));
             /* merge and return */
             $memberData['fb_lastsync'] = time();
             $memberData = array_merge($memberData, $exProfile);
         } else {
             /* Update member even if it failed so it's not selected on next task run */
             IPSMember::save($memberData['member_id'], array('core' => array('fb_lastsync' => time())));
         }
     } catch (Exception $e) {
         /* Update member even if it failed so it's not selected on next task run */
         IPSMember::save($memberData['member_id'], array('core' => array('fb_lastsync' => time())));
         $this->registry->output->logErrorMessage($e->getMessage(), 'FB-EXCEPTION');
     }
     return $memberData;
 }
Example #24
0
 /**
  * Rebuild upcoming events cache
  *
  * @return	@e void
  */
 public function rebuildCalendarEventsCache()
 {
     //-----------------------------------------
     // Ensure calendar is installed
     //-----------------------------------------
     if (!$this->DB->checkForTable('cal_calendars')) {
         return;
     }
     if (!IPSLib::appIsInstalled('calendar')) {
         $this->cache->setCache('calendar_events', array(), array('array' => 1));
         $this->cache->setCache('birthdays', array(), array('array' => 1));
         return;
     }
     //-----------------------------------------
     // Init
     //-----------------------------------------
     $this->settings['calendar_limit'] = (intval($this->settings['calendar_limit']) < 2 ? 1 : intval($this->settings['calendar_limit'])) + 1;
     $birthdays = array();
     $events = array();
     $calendars = $this->cache->getCache('calendars');
     $seenids = array();
     //--------------------------------------------
     // Set time stuff
     //--------------------------------------------
     $startTime = gmmktime(0, 0, 0, gmstrftime('%m'), 1);
     $endTime = gmmktime(0, 0, 0, gmstrftime('%m'), gmstrftime('%d') + $this->settings['calendar_limit']);
     $nowTime = gmmktime(0, 0, 0, gmstrftime('%m'), gmstrftime('%d') - 1);
     list($month, $day, $year) = explode('-', gmstrftime('%m-%d-%Y'));
     list($last_month, $last_day, $last_year) = explode('-', gmstrftime('%m-%d-%Y', $nowTime));
     list($next_month, $next_day, $next_year) = explode('-', gmstrftime('%m-%d-%Y', gmmktime(0, 0, 0, gmstrftime('%m'), gmstrftime('%d') + 1)));
     //--------------------------------------------
     // Get classes
     //--------------------------------------------
     $classToLoad = IPSLib::loadActionOverloader(IPSLib::getAppDir('calendar') . '/modules_public/calendar/view.php', 'public_calendar_calendar_view');
     $calendar = new $classToLoad($this->registry);
     $calendar->makeRegistryShortcuts($this->registry);
     if (!$calendar->initCalendar(true, true)) {
         $this->cache->setCache('calendar_events', array(), array('array' => 1));
         $this->cache->setCache('birthdays', array(), array('array' => 1));
         return;
     }
     //--------------------------------------------
     // Load the events
     //--------------------------------------------
     $calendar->calendarGetEventsSQL($month, $year, array('timenow' => $startTime, 'timethen' => $endTime, 'minimal' => true, 'no_date_convert' => true));
     //--------------------------------------------
     // Loop through events and cache
     //--------------------------------------------
     for ($i = 0; $i <= $this->settings['calendar_limit']; $i++) {
         list($_month, $_day, $_year) = explode('-', gmstrftime('%m-%d-%Y', $nowTime));
         $eventcache = $calendar->calendarGetDayEvents($_month, $_day, $_year);
         foreach ($eventcache as $event) {
             if ($event['event_approved'] and !in_array($event['event_id'], $seenids)) {
                 if (!$event['event_recurring'] or $calendar->checkRecurring($event, $_month, $_day, $_year)) {
                     unset($event['event_content'], $event['event_smilies']);
                     $event['perm_view'] = $calendars[$event['event_calendar_id']]['perm_view'];
                     $events[$event['event_id']] = $event;
                 }
                 $seenids[$event['event_id']] = $event['event_id'];
             }
         }
         $nowTime += 86400;
     }
     //-----------------------------------------
     // Grab birthdays
     //-----------------------------------------
     $append_string = "";
     if (!gmdate("L")) {
         if ($month == 2 and $day > 26) {
             $append_string = " OR ( bday_month=2 AND bday_day=29 )";
         }
     }
     $_days = array();
     $this->DB->build(array('select' => 'member_id, members_seo_name, members_display_name, member_group_id, bday_day, bday_month, bday_year', 'from' => 'members', 'where' => "member_banned=0 AND ( !" . IPSBWOptions::sql('bw_is_spammer', 'members_bitoptions', 'members', 'global', 'has') . ")\r\n\t\t\t\t\t\t\t\t\t\t\t\tAND ( ( bday_day={$last_day} AND bday_month={$last_month} )\r\n\t\t\t\t\t\t\t\t\t\t\t\tOR ( bday_day={$day} AND bday_month={$month} )\r\n\t\t\t\t\t\t\t\t\t\t\t\tOR ( bday_day={$next_day} AND bday_month={$next_month} ) {$append_string} )"));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         /* Only allow 6 per day, then the "upcoming birthdays" can display 5 and know there are more to display */
         $_days[$r['bday_month'] . '.' . $r['bday_day']]++;
         if ($_days[$r['bday_month'] . '.' . $r['bday_day']] > 6) {
             continue;
         }
         $birthdays[$r['member_id']] = $r;
     }
     //--------------------------------------------
     // Update calendar array
     //--------------------------------------------
     $this->cache->setCache('calendar_events', $events, array('array' => 1));
     $this->cache->setCache('birthdays', $birthdays, array('array' => 1));
 }
Example #25
0
 /**
  * Get photo type - mostly here to help legacy / upgrades
  * @param	mixed	INT or Array
  */
 public function getPhotoType($member)
 {
     if (is_integer($member)) {
         $member = IPSMember::load($member, 'all');
     } else {
         if (isset($member['member_id']) && !isset($member['pp_photo_type'])) {
             $member = IPSMember::load($member['member_id'], 'all');
         }
     }
     if (!empty($member['pp_photo_type'])) {
         return $member['pp_photo_type'];
     } else {
         $bwOptions = IPSBWOptions::thaw($member['fb_bwoptions'], 'facebook');
         $tcbwOptions = IPSBWOptions::thaw($member['tc_bwoptions'], 'twitter');
         if (!empty($member['pp_main_photo']) and (strpos($member['pp_main_photo'], 'http://') === false or strpos($member['pp_main_photo'], $this->settings['original_base_url']))) {
             return 'custom';
         }
         if ($bwOptions['fbc_s_pic']) {
             return 'facebook';
         }
         if ($tcbwOptions['tc_s_pic']) {
             return 'twitter';
         }
         if ($member['pp_gravatar']) {
             return 'gravatar';
         }
         return 'none';
     }
 }
 /**
  * UserCP Save Form: Settings
  *
  * @access	public
  * @param	array	Array of member / core_sys_login information (if we're editing)
  * @return	mixed	Array of errors / boolean true
  */
 public function saveFormSettings($member = array())
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $timeZone = IPSText::alphanumericalClean($this->request['timeZone'], '+.');
     $dst_correct = intval($this->request['dst_correct']);
     //-----------------------------------------
     // RTE
     //-----------------------------------------
     if (!$this->settings['posting_allow_rte']) {
         $this->request['editorChoice'] = 0;
     }
     //-----------------------------------------
     // PM Settings: 2 means admin says no.
     //-----------------------------------------
     if ($this->memberData['members_disable_pm'] == 2) {
         $this->member->setProperty('members_disable_pm', 2);
     } else {
         $this->member->setProperty('members_disable_pm', intval($this->request['disableMessenger']));
     }
     //-----------------------------------------
     // Only one account per identity url
     //-----------------------------------------
     if ($this->request['identity_url']) {
         $account = $this->DB->buildAndFetch(array('select' => 'member_id', 'from' => 'members', 'where' => "identity_url='" . trim($this->request['identity_url']) . "' AND member_id<>" . $this->memberData['member_id']));
         if ($account['member_id']) {
             return array(0 => $this->lang->words['identity_url_assoc']);
         }
         //-----------------------------------------
         // Need to clean up identity URL a little
         //-----------------------------------------
         $identityUrl = trim($this->request['identity_url']);
         $identityUrl = rtrim($identityUrl, "/");
         if (!strpos($identityUrl, 'http://') === 0 and !strpos($identityUrl, 'https://') === 0) {
             $identityUrl = 'http://' . $identityUrl;
         }
     }
     /* Figure out BW options */
     $toSave = IPSBWOptions::thaw($this->memberData['members_bitoptions'], 'members');
     foreach (array('bw_vnc_type', 'bw_forum_result_type') as $field) {
         $toSave[$field] = intval($this->request[$field]);
     }
     IPSMember::save($this->memberData['member_id'], array('core' => array('hide_email' => intval($this->request['hide_email']), 'email_pm' => intval($this->request['pm_reminder']), 'allow_admin_mails' => intval($this->request['admin_send']), 'time_offset' => $timeZone, 'dst_in_use' => ($this->request['dstOption'] and intval($this->request['dstCheck']) == 0) ? intval($this->request['dstOption']) : 0, 'members_auto_dst' => intval($this->request['dstCheck']), 'members_disable_pm' => intval($this->memberData['members_disable_pm']), 'members_editor_choice' => $this->request['editorChoice'] ? 'rte' : 'std', 'member_uploader' => $this->request['member_uploader'] ? 'flash' : 'default', 'view_pop' => intval($this->request['showPMPopUp']), 'identity_url' => $identityUrl, 'members_bitoptions' => IPSBWOptions::freeze($toSave, 'members'))));
     return TRUE;
 }