Example #1
0
 /**
  * Remove a photo for a member
  * @param int $member_id
  * @return string
  */
 public function remove($member_id)
 {
     /* Fix up upload directory */
     $paths = $this->_getProfileUploadPaths();
     $upload_path = $paths['path'];
     $upload_dir = $paths['dir'];
     $memberData = IPSMember::load($member_id);
     $bwOptions = IPSBWOptions::thaw($memberData['fb_bwoptions'], 'facebook');
     $tcbwOptions = IPSBWOptions::thaw($memberData['tc_bwoptions'], 'twitter');
     $bwOptions['fbc_s_pic'] = 0;
     $tcbwOptions['tc_s_pic'] = 0;
     /* We should also disable Gravatar Bug #38739 */
     $memBitwise = IPSBWOptions::thaw($memberData['members_bitoptions'], 'members');
     $memBitwise['bw_disable_gravatar'] = 1;
     $memBitwise = IPSBWOptions::freeze($memBitwise, 'members');
     $this->removeUploadedPhotos($member_id, $upload_path);
     IPSMember::save($member_id, array('core' => array('members_bitoptions' => $memBitwise), 'extendedProfile' => array('pp_main_photo' => '', 'pp_main_width' => 0, 'pp_main_height' => 0, 'pp_thumb_photo' => '', 'pp_thumb_width' => 0, 'pp_thumb_height' => 0, 'pp_photo_type' => 'none', 'pp_gravatar' => '', 'fb_photo' => '', 'fb_photo_thumb' => '', 'fb_bwoptions' => IPSBWOptions::freeze($bwOptions, 'facebook'), 'tc_photo' => '', 'tc_bwoptions' => IPSBWOptions::freeze($tcbwOptions, 'twitter'))));
     return true;
 }
 /**
  * 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('.', '.', $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 #3
0
 /**
  * Completes the connection
  *
  * @access	public
  * @return	redirect
  */
 public function finishLogin()
 {
     /* From reg flag */
     if ($_REQUEST['code']) {
         /* Load oAuth */
         require_once IPS_KERNEL_PATH . 'facebook/facebookoauth.php';
         /*noLibHook*/
         $this->_oauth = new FacebookOAuth(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET, FACEBOOK_CALLBACK, $this->extendedPerms);
         /* Load API */
         require_once IPS_KERNEL_PATH . 'facebook/facebook.php';
         /*noLibHook*/
         $this->_api = new Facebook(array('appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_APP_SECRET, 'cookie' => true));
         /* Ensure URL is correct */
         $_urlExtra = '';
         if ($_REQUEST['key']) {
             $_urlExtra .= '&key=' . $_REQUEST['key'];
         }
         if ($_REQUEST['_reg']) {
             $_urlExtra .= '&_reg=1';
         }
         /* Update callback url */
         $this->_oauth->setCallBackUrl(FACEBOOK_CALLBACK . $_urlExtra);
         /* Generate oAuth token */
         $rToken = $this->_oauth->getAccessToken($_REQUEST['code']);
         if (is_string($rToken)) {
             try {
                 $_userData = $this->_api->api('me', array('access_token' => $rToken));
             } catch (Exception $e) {
                 /* Try re-authorising */
                 if (stristr($e->getMessage(), 'invalid')) {
                     $this->redirectToConnectPage();
                 }
             }
             /* A little gymnastics */
             $this->_userData = $_userData;
             $_userData = $this->fetchUserData($rToken);
             /* Got a member linked already? */
             $_member = IPSMember::load($_userData['id'], 'all', 'fb_uid');
             /* Not connected, check email address */
             if (!$_member['member_id'] and $_userData['email']) {
                 $_member = IPSMember::load($_userData['email'], 'all', 'email');
                 /* We do have an existing account, so trash email forcing user to sign up with new */
                 if ($_member['member_id']) {
                     /* Update row */
                     IPSMember::save($_member['member_id'], array('core' => array('fb_uid' => $_userData['id'], 'fb_token' => $rToken)));
                 }
             }
             if ($_member['member_id']) {
                 $memberData = $_member;
                 /* Ensure user's row is up to date */
                 IPSMember::save($memberData['member_id'], array('core' => array('fb_token' => $rToken)));
                 /* Here, so log us in!! */
                 /* changed by denchu 26/12/12 */
                 $r = $this->_login()->loginWithoutCheckingCredentials($memberData['member_id'], TRUE);
                 if (is_array($r)) {
                     if (isset($r[1])) {
                         $this->registry->getClass('output')->redirectScreen($r[0], $r[1]);
                         $this->registry->getClass('output')->silentRedirect($r[1]);
                     } else {
                         $this->registry->getClass('output')->silentRedirect($r[0]);
                     }
                 } elseif (!$r) {
                     throw new Exception('LINKED_MEMBER_LOGIN_FAIL');
                 } else {
                     $this->registry->getClass('output')->silentRedirect($this->settings['base_url']);
                 }
             } else {
                 /* No? Create a new member */
                 foreach (array('fbc_s_pic', 'fbc_s_status', 'fbc_s_aboutme') as $field) {
                     $toSave[$field] = 1;
                 }
                 $fb_bwoptions = IPSBWOptions::freeze($toSave, 'facebook');
                 $safeFBName = IPS_DOC_CHAR_SET != 'UTF-8' ? IPSText::utf8ToEntities($_userData['name']) : $_userData['name'];
                 /* Make sure usernames are safe */
                 if ($this->settings['username_characters']) {
                     $check_against = preg_quote($this->settings['username_characters'], "/");
                     $check_against = str_replace('\\-', '-', $check_against);
                     $safeFBName = preg_replace('/[^' . $check_against . ']+/i', '', $safeFBName);
                 }
                 /* Check ban filters? */
                 if (IPSMember::isBanned('email', $_userData['email']) or IPSMember::isBanned('name', $safeFBName)) {
                     $this->registry->output->showError('you_are_banned', 1090003);
                 }
                 $displayName = $this->settings['fb_realname'] == 'enforced' ? $safeFBName : '';
                 /* From reg, so create new account properly */
                 $toSave = array('core' => array('name' => IPSText::parseCleanValue($safeFBName), 'members_display_name' => IPSText::parseCleanValue($displayName), 'members_created_remote' => 1, 'member_group_id' => $this->settings['fbc_mgid'] ? $this->settings['fbc_mgid'] : $this->settings['member_group'], 'email' => $_userData['email'], 'fb_uid' => $_userData['id'], 'time_offset' => $_userData['timezone'], 'members_auto_dst' => 1, 'fb_token' => $rToken), 'extendedProfile' => array('pp_about_me' => IPSText::getTextClass('bbcode')->stripBadWords(IPSText::convertCharsets($_userData['about'], 'utf-8', IPS_DOC_CHAR_SET)), 'fb_bwoptions' => $fb_bwoptions));
                 $memberData = IPSMember::create($toSave, FALSE, FALSE, TRUE);
                 if (!$memberData['member_id']) {
                     throw new Exception('CREATION_FAIL');
                 }
                 /* Sync up photo */
                 $this->syncMember($memberData['member_id']);
                 $pmember = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'members_partial', 'where' => "partial_member_id=" . $memberData['member_id']));
                 if ($pmember['partial_member_id']) {
                     $this->registry->getClass('output')->silentRedirect($this->settings['base_url'] . 'app=core&module=global&section=register&do=complete_login&mid=' . $memberData['member_id'] . '&key=' . $pmember['partial_date']);
                 } else {
                     /* Already got a display name */
                     if ($displayName) {
                         /* Here, so log us in!! */
                         $r = $this->_login()->loginWithoutCheckingCredentials($memberData['member_id'], TRUE);
                         IPSLib::runMemberSync('onCompleteAccount', $memberData);
                         if ($this->settings['new_reg_notify']) {
                             $this->registry->class_localization->loadLanguageFile(array('public_register'), 'core');
                             IPSText::getTextClass('email')->setPlainTextTemplate(IPSText::getTextClass('email')->getTemplate("admin_newuser"));
                             IPSText::getTextClass('email')->buildMessage(array('DATE' => $this->registry->getClass('class_localization')->getDate(time(), 'LONG', 1), 'LOG_IN_NAME' => $safeFBName, 'EMAIL' => $_userData['email'], 'IP' => $this->member->ip_address, 'DISPLAY_NAME' => $displayName));
                             IPSText::getTextClass('email')->subject = sprintf($this->lang->words['new_registration_email'], $this->settings['board_name']);
                             IPSText::getTextClass('email')->to = $this->settings['email_in'];
                             IPSText::getTextClass('email')->sendMail();
                         }
                         if (is_array($r)) {
                             if (isset($r[1])) {
                                 $this->registry->getClass('output')->redirectScreen($r[0], $r[1]);
                                 $this->registry->getClass('output')->silentRedirect($r[1]);
                             } else {
                                 $this->registry->getClass('output')->silentRedirect($r[0]);
                             }
                         } elseif (!$r) {
                             throw new Exception('LINKED_MEMBER_LOGIN_FAIL');
                         } else {
                             $this->registry->getClass('output')->silentRedirect($this->settings['base_url']);
                         }
                     } else {
                         throw new Exception('CREATION_FAIL');
                     }
                 }
             }
         } else {
             throw new Exception('CREATION_FAIL');
         }
     } else {
         /* Need to re-auth */
     }
 }
Example #4
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;
 }
 /**
  * Uploads a new photo for the member [process]
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private 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;
     }
     $status = IPSMember::getFunction()->uploadPhoto(intval($this->request['member_id']));
     if ($status['status'] == 'fail') {
         switch ($status['error']) {
             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');
         $bwOptions['fbc_s_pic'] = 0;
         IPSMember::save($this->request['member_id'], array('extendedProfile' => array('pp_main_photo' => $status['final_location'], 'pp_main_width' => $status['final_width'], 'pp_main_height' => $status['final_height'], 'pp_thumb_photo' => $status['t_final_location'], 'pp_thumb_width' => $status['t_final_width'], 'pp_thumb_height' => $status['t_final_height'], 'fb_photo' => '', 'fb_photo_thumb' => '', 'fb_bwoptions' => IPSBWOptions::freeze($bwOptions, 'facebook'))));
         //-----------------------------------------
         // Redirect
         //-----------------------------------------
         $this->registry->output->doneScreen($this->lang->words['m_photoupdated'], $this->lang->words['m_search'], "{$this->form_code}&amp;do=viewmember&amp;member_id={$this->request['member_id']}", "redirect");
     }
 }
 /**
  * Add a moderator
  *
  * @return	@e void		[Outputs to screen]
  */
 public function addMod()
 {
     /* Set up our return forum */
     $return_id = intval($this->request['return_id']);
     $url_extra = $return_id ? "&f=" . $return_id : "";
     if (!is_array($this->request['forums']) or !count($this->request['forums'])) {
         $this->registry->output->showError($this->lang->words['mod_noforums'], 11320);
     }
     //-----------------------------------------
     // Build Mr Hash
     //-----------------------------------------
     $mr_hash = array('edit_post' => intval($this->request['edit_post']), 'edit_topic' => intval($this->request['edit_topic']), 'delete_post' => intval($this->request['delete_post']), 'delete_topic' => intval($this->request['delete_topic']), 'view_ip' => intval($this->request['view_ip']), 'open_topic' => intval($this->request['open_topic']), 'close_topic' => intval($this->request['close_topic']), 'mass_move' => intval($this->request['mass_move']), 'mass_prune' => intval($this->request['mass_prune']), 'move_topic' => intval($this->request['move_topic']), 'pin_topic' => intval($this->request['pin_topic']), 'unpin_topic' => intval($this->request['unpin_topic']), 'post_q' => intval($this->request['post_q']), 'topic_q' => intval($this->request['topic_q']), 'allow_warn' => intval($this->request['allow_warn']), 'split_merge' => intval($this->request['split_merge']), 'can_mm' => intval($this->request['can_mm']), 'mod_can_set_open_time' => intval($this->request['mod_can_set_open_time']), 'mod_can_set_close_time' => intval($this->request['mod_can_set_close_time']), 'forum_id' => ',' . implode(',', $this->request['forums']) . ',', 'mod_bitoptions' => IPSBWOptions::freeze($this->request, 'moderators', 'forums'));
     $forums = array();
     foreach ($this->request['forums'] as $forum_id) {
         $forums[$forum_id] = $forum_id;
     }
     //-----------------------------------------
     if ($this->request['mod_type'] == 'group') {
         if ($this->request['gid'] == "") {
             $this->registry->output->showError($this->lang->words['mod_gid'], 11322);
         }
         $this->DB->build(array('select' => 'g_id, g_title', 'from' => 'groups', 'where' => "g_id=" . intval($this->request['gid'])));
         $this->DB->execute();
         if (!($group = $this->DB->fetch())) {
             $this->registry->output->showError($this->lang->words['mod_gid'], 11323);
         }
         //-----------------------------------------
         // Already using this group on this forum?
         //-----------------------------------------
         foreach ($forums as $forum_id) {
             $this->DB->build(array('select' => '*', 'from' => 'moderators', 'where' => "forum_id LIKE '%,{$forum_id},%' and group_id=" . intval($this->request['gid'])));
             $this->DB->execute();
             while ($f = $this->DB->fetch()) {
                 $theseForums = explode(',', IPSText::cleanPermString($f['forum_id']));
                 foreach ($theseForums as $thisForumId) {
                     unset($forums[$thisForumId]);
                 }
             }
         }
         $mr_hash['member_name'] = '-1';
         $mr_hash['member_id'] = '-1';
         $mr_hash['group_id'] = $group['g_id'];
         $mr_hash['group_name'] = $group['g_title'];
         $mr_hash['is_group'] = 1;
         $ad_log = sprintf($this->lang->words['mod_addedgroup'], $group['g_title']);
     } else {
         if ($this->request['mem'] == "") {
             $this->registry->output->showError($this->lang->words['mod_nomember'], 11324);
         }
         $this->DB->build(array('select' => 'member_id, members_display_name', 'from' => 'members', 'where' => "member_id=" . intval($this->request['mem'])));
         $this->DB->execute();
         if (!($mem = $this->DB->fetch())) {
             $this->registry->output->showError($this->lang->words['mod_memid'], 11325);
         }
         //-----------------------------------------
         // Already using this member on this forum?
         //-----------------------------------------
         foreach ($forums as $forum_id) {
             $this->DB->build(array('select' => '*', 'from' => 'moderators', 'where' => "forum_id LIKE '%,{$forum_id},%' and member_id=" . intval($this->request['mem'])));
             $this->DB->execute();
             while ($f = $this->DB->fetch()) {
                 $theseForums = explode(',', IPSText::cleanPermString($f['forum_id']));
                 foreach ($theseForums as $thisForumId) {
                     unset($forums[$thisForumId]);
                 }
             }
         }
         $mr_hash['member_name'] = $mem['members_display_name'];
         $mr_hash['member_id'] = $mem['member_id'];
         $mr_hash['is_group'] = 0;
         $ad_log = sprintf($this->lang->words['mod_addedmem'], $mem['members_display_name']);
     }
     //-----------------------------------------
     // Check for legal forums
     //-----------------------------------------
     if (count($forums) == 0) {
         $this->registry->output->showError($this->lang->words['mod_nonewfor'], 11326);
     }
     //-----------------------------------------
     // Loopy loopy
     //-----------------------------------------
     $mr_has['forum_id'] = ',' . implode(',', $forums) . ',';
     $this->DB->setDataType('member_name', 'string');
     $this->DB->insert('moderators', $mr_hash);
     $this->registry->adminFunctions->saveAdminLog($ad_log);
     $this->rebuildModeratorCache();
     $this->registry->output->global_message = $this->lang->words['mod_added'];
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . '&module=forums&section=forums' . $url_extra);
 }
 /**
  * Save member
  *
  * @access	public
  * @param 	int		Member key: Either Array, ID or email address. If it's an array, it must be in the format:
  *					 array( 'core' => array( 'field' => 'member_id', 'value' => 1 ) ) - useful for passing custom fields through
  * @param 	array 	Fields to save in the following format: array( 'members'      => array( 'email'     => '*****@*****.**',
  *																				         'joined'   => time() ),
  *															   'extendedProfile' => array( 'signature' => 'My signature' ) );
  *					Tables: members, pfields_content, profile_portal.
  *					You can also use the aliases: 'core [members]', 'extendedProfile [profile_portal]', and 'customFields [pfields_content]'
  * @return	boolean	True if the save was successful
  *
  * Exception Error Codes:
  * NO_DATA 		  : No data to save
  * NO_VALID_KEY    : No valid key to save
  * NO_AUTO_LOAD    : Could not autoload the member as she does not exist
  * INCORRECT_TABLE : Table one is attempting to save to does not exist
  * NO_MEMBER_GROUP_ID: Member group ID is in the array but blank
  */
 public static function save($member_key, $save = array())
 {
     $member_id = 0;
     $member_email = '';
     $member_field = '';
     $_updated = 0;
     $bitWiseFields = ipsRegistry::fetchBitWiseOptions('global');
     $member_k_array = array('members' => array(), 'pfields_content' => array(), 'profile_portal' => array());
     $_tables = array_keys($save);
     $_MEMBERKEY = 'member_id';
     $_MEMBERVALUE = $member_key;
     //-----------------------------------------
     // Test...
     //-----------------------------------------
     if (!is_array($save) or !count($save)) {
         throw new Exception('NO_DATA');
     }
     //-----------------------------------------
     // ID or email?
     //-----------------------------------------
     if (!is_array($member_key)) {
         if (strstr($member_key, '@')) {
             $_MEMBERKEY = 'email';
             $member_k_array['members'] = array('field' => 'email', 'value' => "'" . ipsRegistry::instance()->DB()->addSlashes(strtolower($member_key)) . "'");
             //-----------------------------------------
             // Check to see if we've got more than the core
             // table to save on.
             //-----------------------------------------
             $_got_more_than_core = FALSE;
             foreach ($_tables as $table) {
                 if (isset(self::$remap[$table])) {
                     $table = self::$remap[$table];
                 }
                 if ($table != 'members') {
                     $_got_more_than_core = TRUE;
                     break;
                 }
             }
             if ($_got_more_than_core === TRUE) {
                 /* Get the ID */
                 $_memberTmp = self::load($member_key, 'core');
                 if ($_memberTmp['member_id']) {
                     $member_k_array['pfields_content'] = array('field' => 'member_id', 'value' => $_memberTmp['member_id']);
                     $member_k_array['profile_portal'] = array('field' => 'pp_member_id', 'value' => $_memberTmp['member_id']);
                 } else {
                     throw new Exception("NO_AUTO_LOAD");
                 }
             }
         } else {
             $member_k_array['members'] = array('field' => 'member_id', 'value' => intval($member_key));
             $member_k_array['pfields_content'] = array('field' => 'member_id', 'value' => intval($member_key));
             $member_k_array['profile_portal'] = array('field' => 'pp_member_id', 'value' => intval($member_key));
             self::_updateCache($member_key, $save);
         }
     } else {
         $_member_k_array = $member_k_array;
         foreach ($member_key as $table => $data) {
             if (isset(self::$remap[$table])) {
                 $table = self::$remap[$table];
             }
             if (!in_array($table, array_keys($_member_k_array))) {
                 throw new Exception('INCORRECT_TABLE');
             }
             $member_k_array[$table] = $data;
         }
     }
     //-----------------------------------------
     // Test...
     //-----------------------------------------
     if (!is_array($member_k_array) or !count($member_k_array)) {
         throw new Exception('NO_DATA');
     }
     //-----------------------------------------
     // Now save...
     //-----------------------------------------
     foreach ($save as $table => $data) {
         if (isset(self::$remap[$table])) {
             $table = self::$remap[$table];
         }
         if ($table == 'profile_portal') {
             $data[$member_k_array[$table]['field']] = $member_k_array[$table]['value'];
             //-----------------------------------------
             // Does row exist?
             //-----------------------------------------
             $check = ipsRegistry::DB()->buildAndFetch(array('select' => 'pp_member_id', 'from' => 'profile_portal', 'where' => 'pp_member_id=' . $data['pp_member_id']));
             if (!$check['pp_member_id']) {
                 ipsRegistry::DB()->insert($table, $data);
             } else {
                 ipsRegistry::DB()->update($table, $data, 'pp_member_id=' . $data['pp_member_id']);
             }
         } else {
             if ($table == 'pfields_content') {
                 $data[$member_k_array[$table]['field']] = $member_k_array[$table]['value'];
                 foreach ($data as $_k => $_v) {
                     ipsRegistry::DB()->force_data_type[$_k] = 'string';
                 }
                 //-----------------------------------------
                 // Does row exist?
                 //-----------------------------------------
                 $check = ipsRegistry::DB()->buildAndFetch(array('select' => 'member_id', 'from' => 'pfields_content', 'where' => 'member_id=' . $data['member_id']));
                 if (!$check['member_id']) {
                     ipsRegistry::DB()->insert($table, $data);
                 } else {
                     ipsRegistry::DB()->update($table, $data, 'member_id=' . $data['member_id']);
                 }
             } else {
                 if ($table == 'members') {
                     /* Make sure we have a value for member_group_id if passed */
                     if (isset($data['member_group_id']) and !$data['member_group_id']) {
                         throw new Exception("NO_MEMBER_GROUP_ID");
                     }
                     /* Some stuff that can end up  here */
                     unset($data['_canBeIgnored']);
                     /* Bitwise options */
                     if (is_array($bitWiseFields['members'])) {
                         $_freeze = array();
                         foreach ($bitWiseFields['members'] as $field) {
                             if (isset($data[$field])) {
                                 /* Add to freezeable array */
                                 $_freeze[$field] = $data[$field];
                                 /* Remove it from the fields to save to DB */
                                 unset($data[$field]);
                             }
                         }
                         if (count($_freeze)) {
                             $data['members_bitoptions'] = IPSBWOptions::freeze($_freeze, 'members', 'global');
                         }
                     }
                     ipsRegistry::DB()->force_data_type = array('name' => 'string', 'title' => 'string', 'members_l_username' => 'string', 'members_display_name' => 'string', 'members_l_display_name' => 'string', 'members_seo_name' => 'string', 'msg_count_total' => 'int', 'msg_count_new' => 'int', 'members_bitoptions' => 'int');
                 }
                 ipsRegistry::DB()->update($table, $data, $member_k_array[$table]['field'] . '=' . $member_k_array[$table]['value']);
             }
         }
         $_updated += ipsRegistry::instance()->DB()->getAffectedRows();
     }
     //-----------------------------------------
     // If member login key is updated during
     // session creation, this causes fatal error
     //-----------------------------------------
     if (is_object(ipsRegistry::member())) {
         $save[$_MEMBERKEY] = $_MEMBERVALUE;
         IPSLib::runMemberSync('onProfileUpdate', $save);
     }
     return $_updated > 0 ? TRUE : FALSE;
 }
Example #8
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']);
     }
 }
 /**
  * UserCP Save Form: Facebook
  *
  * @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_status', 'fbc_s_aboutme', 'fbc_si_status') as $field) {
         $toSave[$field] = intval($this->request[$field]);
     }
     $this->memberData['fb_bwoptions'] = IPSBWOptions::freeze($toSave, 'facebook');
     IPSMember::save($this->memberData['member_id'], array('extendedProfile' => array('fb_bwoptions' => $this->memberData['fb_bwoptions'])));
     //-----------------------------------------
     // Now sync
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/facebook/connect.php', 'facebook_connect');
     $facebook = new $classToLoad($this->registry);
     try {
         $facebook->syncMember($this->memberData);
     } catch (Exception $error) {
         $msg = $error->getMessage();
         switch ($msg) {
             case 'NOT_LINKED':
             case 'NO_MEMBER':
                 break;
         }
     }
     return TRUE;
 }
 /**
  * Flag an account as spammer
  *
  * @param	int|array	$member				Member Data
  * @param	array		$marker				The person marking this person a spammer
  * @param	bool		$resetLastMember	If FALSE skips resetting the last registered member
  * @return	void
  */
 public static function flagMemberAsSpammer($member, $marker = NULL, $resetLastMember = TRUE)
 {
     //-----------------------------------------
     // Init
     //-----------------------------------------
     /* Load Member */
     if (!is_array($member)) {
         $member = self::load($member);
     }
     /* Load moderator library (we'll need this to unapprove posts and log) */
     $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('forums') . '/sources/classes/moderate.php', 'moderatorLibrary', 'forums');
     $modLibrary = new $classToLoad(ipsRegistry::instance());
     //-----------------------------------------
     // Do it
     //-----------------------------------------
     $toSave = array();
     $toSave['core']['bw_is_spammer'] = TRUE;
     /* Shut off twitter/FB status importing */
     $bwOptions = IPSBWOptions::thaw($member['tc_bwoptions'], 'twitter');
     $bwOptions['tc_si_status'] = 0;
     $twitter = IPSBWOptions::freeze($bwOptions, 'twitter');
     $bwOptions = IPSBWOptions::thaw($member['fb_bwoptions'], 'facebook');
     $bwOptions['fbc_si_status'] = 0;
     $facebook = IPSBWOptions::freeze($bwOptions, 'facebook');
     $toSave['extendedProfile']['tc_bwoptions'] = $twitter;
     $toSave['extendedProfile']['fb_bwoptions'] = $facebook;
     /* Do any disabling, unapproving, banning - no breaks here since if we ban, we also want to unapprove posts, etc. */
     /* Note that there are DELIBERATELY no breaks in this switch since the options are cascading (if you ban, you also want to unapprove content) */
     switch (ipsRegistry::$settings['spm_option']) {
         /* Empty profile and ban account */
         case 'ban':
             // ban
             $toSave['core']['member_banned'] = TRUE;
             // wipe data
             $toSave['core']['title'] = '';
             $toSave['extendedProfile']['signature'] = '';
             $toSave['extendedProfile']['pp_about_me'] = '';
             // wipe photo
             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/member/photo.php', 'classes_member_photo');
             $photos = new $classToLoad(ipsRegistry::instance());
             $photos->remove($member['member_id']);
             // wipe custom fields
             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
             $fields = new $classToLoad();
             $fields->member_data = $member;
             $fields->initData('edit');
             $fields->parseToSave(array());
             if (count($fields->out_fields)) {
                 $toSave['customFields'] = $fields->out_fields;
             }
             // wipe signature
             IPSContentCache::update($member['member_id'], 'sig', '');
             /* Unapprove posts */
         /* Unapprove posts */
         case 'unapprove':
             $modLibrary->deleteMemberContent($member['member_id'], 'all', intval(ipsRegistry::$settings['spm_post_days']) * 24);
             /* Disable Post/PM permission */
         /* Disable Post/PM permission */
         case 'disable':
             $toSave['core']['restrict_post'] = 1;
             $toSave['core']['members_disable_pm'] = 2;
     }
     self::save($member['member_id'], $toSave);
     //-----------------------------------------
     // Run memberSync
     //-----------------------------------------
     IPSLib::runMemberSync('onSetAsSpammer', array_merge($member, $toSave));
     //-----------------------------------------
     // Let the admin know if necessary
     //-----------------------------------------
     if ($marker !== NULL and ipsRegistry::$settings['spm_notify'] and ipsRegistry::$settings['email_in'] != $marker['email']) {
         ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_mod'), 'forums');
         ipsRegistry::getClass('class_localization')->loadLanguageFile(array('admin_member'), 'members');
         IPSText::getTextClass('email')->getTemplate('possibleSpammer');
         IPSText::getTextClass('email')->buildMessage(array('DATE' => ipsRegistry::getClass('class_localization')->getDate($member['joined'], 'LONG', 1), 'MEMBER_NAME' => $member['members_display_name'], 'IP' => $member['ip_address'], 'EMAIL' => $member['email'], 'LINK' => ipsRegistry::getClass('output')->buildSEOUrl("showuser=" . $member['member_id'], 'public', $member['members_seo_name'], 'showuser')));
         IPSText::getTextClass('email')->subject = sprintf(ipsRegistry::getClass('class_localization')->words['new_registration_email_spammer'], ipsRegistry::$settings['board_name']);
         IPSText::getTextClass('email')->to = ipsRegistry::$settings['email_in'];
         IPSText::getTextClass('email')->sendMail();
     }
     /* Reset last member? */
     if ($resetLastMember) {
         self::resetLastRegisteredMember();
     }
     //-----------------------------------------
     // Let IPS know
     //-----------------------------------------
     if (ipsRegistry::$settings['spam_service_send_to_ips']) {
         self::querySpamService($member['email'], $member['ip_address'], 'markspam');
     }
     //-----------------------------------------
     // Log
     //-----------------------------------------
     ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_modcp'), 'core');
     $modLibrary->addModerateLog(0, 0, 0, 0, ipsRegistry::getClass('class_localization')->words['flag_spam_done'] . ': ' . $member['member_id'] . ' - ' . $member['email']);
 }
 /**
  * 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);
 }
Example #12
0
 /**
  * Mark a topic as 'answered'
  * @param mixed $topic
  * @param mixed $post
  */
 public function answerTopicSingle($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 for all other posts in this topic */
     $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, 'topic_id=' . $topic['tid'] . ' AND ' . $where, false, true);
     /* Update post */
     $post['bw_post_answered'] = 1;
     $this->DB->update('posts', array('post_bwoptions' => IPSBWOptions::freeze($post, 'posts', 'forums')), 'pid=' . $post['pid']);
     /* Update topic */
     $this->DB->update('topics', array('topic_answered_pid' => $post['pid']), 'tid=' . $topic['tid']);
     return true;
 }
Example #13
0
 /**
  * Completes the connection
  *
  * @access	public
  * @return	redirect
  * 
  */
 public function finishLogin()
 {
     /* From reg flag */
     $connectData = array('t_key' => '');
     if ($_REQUEST['key']) {
         $connectData = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'twitter_connect', 'where' => "t_key='" . IPSText::md5Clean($_REQUEST['key']) . "'"));
         if (!$connectData['t_key']) {
             throw new Exception("NO_KEY_FOUND");
         }
         /* Delete connect row */
         $this->DB->delete('twitter_connect', "t_key='" . IPSText::md5Clean($_REQUEST['key']) . "'");
         $member = array('twitter_token' => $connectData['t_token'], 'twitter_secret' => $connectData['t_secret']);
     }
     if ($_REQUEST['oauth_token']) {
         if ($member['twitter_token'] == $_REQUEST['oauth_token']) {
             /* Reset api to ensure user is not logged in */
             require_once IPS_KERNEL_PATH . 'twitter/twitteroauth.php';
             /*noLibHook*/
             $this->_api = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $member['twitter_token'], $member['twitter_secret']);
             /* Generate oAuth token */
             $rToken = $this->_api->getAccessToken($_REQUEST['oauth_verifier']);
             if ($rToken['oauth_token'] and $rToken['oauth_token_secret']) {
                 $_userData = $this->_api->get('account/verify_credentials');
                 /* From registration? */
                 if ($connectData['t_key']) {
                     /* Got a member linked already? */
                     $_member = IPSMember::load($_userData['id'], 'all', 'twitter_id');
                     if ($_member['member_id']) {
                         $memberData = array_merge($member, $_member);
                         /* Ensure user's row is up to date */
                         IPSMember::save($memberData['member_id'], array('core' => array('twitter_token' => $rToken['oauth_token'], 'twitter_secret' => $rToken['oauth_token_secret'])));
                         /* Check for partial member id */
                         $pmember = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'members_partial', 'where' => "partial_member_id=" . $memberData['member_id']));
                         if ($pmember['partial_member_id']) {
                             $this->registry->getClass('output')->silentRedirect($this->settings['base_url'] . 'app=core&module=global&section=register&do=complete_login&mid=' . $memberData['member_id'] . '&key=' . $pmember['partial_date']);
                         } else {
                             /* Here, so log us in!! */
                             /* changed by denchu 26/12/12 */
                             $r = $this->_login()->loginWithoutCheckingCredentials($memberData['member_id'], TRUE);
                             if (is_array($r)) {
                                 if (isset($r[1])) {
                                     $this->registry->getClass('output')->redirectScreen($r[0], $r[1]);
                                     $this->registry->getClass('output')->silentRedirect($r[1]);
                                 } else {
                                     $this->registry->getClass('output')->silentRedirect($r[0]);
                                 }
                             } elseif (!$r) {
                                 throw new Exception('LINKED_MEMBER_LOGIN_FAIL');
                             } else {
                                 $this->registry->getClass('output')->silentRedirect($this->settings['base_url']);
                             }
                         }
                     } else {
                         /* No? Create a new member */
                         /* Generate BW options */
                         foreach (array('tc_s_pic', 'tc_s_status', 'tc_s_aboutme', 'tc_si_status') as $field) {
                             $_toSave[$field] = 1;
                         }
                         $tc_bwoptions = IPSBWOptions::freeze($_toSave, 'twitter');
                         $safeFBName = str_replace(' ', '', IPSText::convertCharsets($_userData['screen_name'], 'utf-8', IPS_DOC_CHAR_SET));
                         /* Make sure usernames are safe */
                         if ($this->settings['username_characters']) {
                             $check_against = preg_quote($this->settings['username_characters'], "/");
                             $check_against = str_replace('\\-', '-', $check_against);
                             $safeFBName = preg_replace('/[^' . $check_against . ']+/i', '', $safeFBName);
                         }
                         $displayName = !$this->settings['auth_allow_dnames'] ? $safeFBName : FALSE;
                         /* From reg, so create new account properly */
                         $toSave = array('core' => array('name' => $safeFBName, 'members_display_name' => $displayName, 'members_created_remote' => 1, 'member_group_id' => $this->settings['tc_mgid'] ? $this->settings['tc_mgid'] : $this->settings['member_group'], 'email' => '', 'twitter_id' => $_userData['id'], 'twitter_token' => $rToken['oauth_token'], 'twitter_secret' => $rToken['oauth_token_secret']), 'extendedProfile' => array('pp_about_me' => IPSText::getTextClass('bbcode')->stripBadWords(IPSText::convertCharsets($_userData['description'], 'utf-8', IPS_DOC_CHAR_SET)), 'tc_bwoptions' => $tc_bwoptions));
                         $memberData = IPSMember::create($toSave, TRUE, FALSE, TRUE);
                         if (!$memberData['member_id']) {
                             throw new Exception('CREATION_FAIL');
                         }
                         /* Sync up photo */
                         $this->syncMember($memberData['member_id']);
                         $pmember = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'members_partial', 'where' => "partial_member_id=" . $memberData['member_id']));
                         if ($pmember['partial_member_id']) {
                             $this->registry->getClass('output')->silentRedirect($this->settings['base_url'] . 'app=core&module=global&section=register&do=complete_login&mid=' . $memberData['member_id'] . '&key=' . $pmember['partial_date']);
                         } else {
                             throw new Exception('CREATION_FAIL');
                         }
                     }
                 }
             }
         }
     }
 }
Example #14
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']);
 }
Example #15
0
 /**
  * Completes the connection
  *
  * @access	public
  * @return	redirect
  * 
  */
 public function finishLogin()
 {
     /* From reg flag */
     if ($_REQUEST['code']) {
         /* Reset api to ensure user is not logged in */
         $this->resetApi();
         /* Ensure URL is correct */
         $_urlExtra = '';
         if ($_REQUEST['key']) {
             $_urlExtra .= '&key=' . $_REQUEST['key'];
         }
         if ($_REQUEST['reg']) {
             $_urlExtra .= '&reg=1';
         }
         /* Update callback url */
         $this->_api->setVariable('authorize_callback_uri', VKONTAKTE_CALLBACK . $_urlExtra);
         /* Generate oAuth token */
         $rToken = $this->_api->getAccessToken();
         if (is_string($rToken)) {
             try {
                 $oAuthSession = $this->_api->getSession();
                 $r = $this->_api->api('getProfiles', 'GET', array('uids' => $oAuthSession['user_id'], 'fields' => 'uid,first_name,last_name,nickname,photo,photo_medium,photo_big,timezone,sex,nickname,activity'));
                 $_userData = array_pop($r['response']);
             } catch (Exception $e) {
             }
             /* A little gymnastics */
             $this->_userData = $_userData;
             $this->_userData['photo'] = $_userData['photo_big'];
             /* Got a member linked already? */
             $_member = IPSMember::load($_userData['uid'], 'all', 'vk_uid');
             if ($_member['member_id']) {
                 $memberData = $_member;
                 /* Ensure user's row is up to date */
                 IPSMember::save($memberData['member_id'], array('core' => array('vk_token' => $rToken)));
                 /* Here, so log us in!! */
                 /* changed by denchu 26/12/12 */
                 $r = $this->_login()->loginWithoutCheckingCredentials($memberData['member_id'], TRUE);
                 if (is_array($r)) {
                     if (isset($r[1])) {
                         $this->registry->getClass('output')->redirectScreen($r[0], $r[1]);
                         $this->registry->getClass('output')->silentRedirect($r[1]);
                     } else {
                         $this->registry->getClass('output')->silentRedirect($r[0]);
                     }
                 } elseif (!$r) {
                     throw new Exception('LINKED_MEMBER_LOGIN_FAIL');
                 } else {
                     $this->registry->getClass('output')->silentRedirect($this->settings['base_url']);
                 }
             } else {
                 /* No? Create a new member */
                 foreach (array('vc_s_pic', 'vc_s_status') as $field) {
                     $toSave[$field] = 1;
                 }
                 $vk_bwoptions = IPSBWOptions::freeze($toSave, 'vkontakte');
                 $safeName = IPSText::convertCharsets($_userData['first_name'] . ' ' . $_userData['last_name'], 'utf-8', IPS_DOC_CHAR_SET);
                 $displayName = $this->settings['fb_realname'] == 'enforced' ? $safeName : '';
                 //$displayName  = ( ! $this->settings['auth_allow_dnames'] ) ? $safeName : FALSE;
                 /* Make sure usernames are safe */
                 if ($this->settings['username_characters']) {
                     $check_against = preg_quote($this->settings['username_characters'], "/");
                     $check_against = str_replace('\\-', '-', $check_against);
                     $safeName = preg_replace('/[^' . $check_against . ']+/i', '', $safeName);
                 }
                 if (IPSText::mbstrlen($safeName) > $this->settings['max_user_name_length']) {
                     $safeName = mb_substr(IPSText::convertCharsets($_userData['last_name'], 'utf-8', IPS_DOC_CHAR_SET), 0, $this->settings['max_user_name_length'], 'UTF-8');
                 }
                 /* Check ban filters? */
                 if (IPSMember::isBanned('name', $safeName)) {
                     $this->registry->output->showError('you_are_banned', 1090003);
                 }
                 /* From reg, so create new account properly */
                 $toSave = array('core' => array('name' => $safeName, 'members_display_name' => $displayName, 'members_created_remote' => 1, 'member_group_id' => $this->settings['vk_mgid'] ? $this->settings['vk_mgid'] : $this->settings['member_group'], 'email' => '', 'vk_uid' => $_userData['uid'], 'time_offset' => $_userData['timezone'], 'vk_token' => $rToken), 'extendedProfile' => array('vk_bwoptions' => $vk_bwoptions));
                 $memberData = IPSMember::create($toSave, TRUE, FALSE, TRUE);
                 if (!$memberData['member_id']) {
                     throw new Exception('CREATION_FAIL');
                 }
                 /* Sync up photo */
                 $this->syncMember($memberData['member_id']);
                 $pmember = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'members_partial', 'where' => "partial_member_id=" . $memberData['member_id']));
                 if ($pmember['partial_member_id']) {
                     $this->registry->getClass('output')->silentRedirect($this->settings['base_url'] . 'app=core&module=global&section=register&do=complete_login&mid=' . $memberData['member_id'] . '&key=' . $pmember['partial_date']);
                 } else {
                     /* Already got a display name */
                     if ($displayName) {
                         /* Here, so log us in!! */
                         /* changed by denchu 26/12/12*/
                         $r = $this->_login()->loginWithoutCheckingCredentials($memberData['member_id'], TRUE);
                         IPSLib::runMemberSync('onCompleteAccount', $memberData);
                         if ($this->settings['new_reg_notify']) {
                             $this->registry->class_localization->loadLanguageFile(array('public_register'), 'core');
                             IPSText::getTextClass('email')->setPlainTextTemplate(IPSText::getTextClass('email')->getTemplate("admin_newuser"));
                             IPSText::getTextClass('email')->buildMessage(array('DATE' => $this->registry->getClass('class_localization')->getDate(time(), 'LONG', 1), 'LOG_IN_NAME' => $safeFBName, 'EMAIL' => $_userData['email'], 'IP' => $this->member->ip_address, 'DISPLAY_NAME' => $displayName));
                             IPSText::getTextClass('email')->subject = sprintf($this->lang->words['new_registration_email'], $this->settings['board_name']);
                             IPSText::getTextClass('email')->to = $this->settings['email_in'];
                             IPSText::getTextClass('email')->sendMail();
                         }
                         if (is_array($r)) {
                             if (isset($r[1])) {
                                 $this->registry->getClass('output')->redirectScreen($r[0], $r[1]);
                                 $this->registry->getClass('output')->silentRedirect($r[1]);
                             } else {
                                 $this->registry->getClass('output')->silentRedirect($r[0]);
                             }
                         } elseif (!$r) {
                             throw new Exception('LINKED_MEMBER_LOGIN_FAIL');
                         } else {
                             $this->registry->getClass('output')->silentRedirect($this->settings['base_url']);
                         }
                     } else {
                         throw new Exception('CREATION_FAIL');
                     }
                 }
             }
         } else {
             throw new Exception('CREATION_FAIL');
         }
     }
 }
 /**
  * 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;
 }