Exemplo n.º 1
0
 /**
  * Create admin account
  *
  * @access	public
  * @return	@e void
  */
 public static function createAdminAccount()
 {
     /* Build Entry */
     $_mke_time = ipsRegistry::$settings['login_key_expire'] ? time() + intval(ipsRegistry::$settings['login_key_expire']) * 86400 : 0;
     $salt = IPSMember::generatePasswordSalt(5);
     $passhash = IPSMember::generateCompiledPasshash($salt, md5(IPSSetUp::getSavedData('admin_pass')));
     $_dname = IPSSetUp::getSavedData('admin_user');
     $member = array('name' => $_dname, 'members_l_username' => strtolower($_dname), 'members_display_name' => $_dname, 'members_l_display_name' => strtolower($_dname), 'members_seo_name' => IPSText::makeSeoTitle($_dname), 'member_login_key' => IPSMember::generateAutoLoginKey(), 'member_login_key_expire' => $_mke_time, 'title' => 'Administrator', 'email' => IPSSetUp::getSavedData('admin_email'), 'member_group_id' => 4, 'posts' => 1, 'joined' => time(), 'last_visit' => time(), 'last_activity' => time(), 'ip_address' => my_getenv('REMOTE_ADDR'), 'view_sigs' => 1, 'restrict_post' => 0, 'msg_show_notification' => 1, 'msg_count_total' => 0, 'msg_count_new' => 0, 'coppa_user' => 0, 'language' => IPSLib::getDefaultLanguage(), 'members_auto_dst' => 1, 'member_uploader' => 'flash', 'allow_admin_mails' => 0, 'members_pass_hash' => $passhash, 'members_pass_salt' => $salt, 'has_blog' => '', 'fb_token' => '', 'ignored_users' => '', 'members_cache' => '', 'failed_logins' => '', 'bday_day' => 0, 'bday_month' => 0, 'bday_year' => 0);
     /* Insert: MEMBERS */
     ipsRegistry::DB()->setDataType(array('name', 'members_display_name', 'members_l_username', 'members_l_display_name'), 'string');
     ipsRegistry::DB()->insert('members', $member);
     $member_id = ipsRegistry::DB()->getInsertId();
     $member['member_id'] = $member_id;
     /* Insert into the custom profile fields DB */
     ipsRegistry::DB()->insert('pfields_content', array('member_id' => $member_id));
     /* Insert into pp */
     ipsRegistry::DB()->insert('profile_portal', array('pp_member_id' => $member_id, 'pp_setting_count_friends' => 1, 'signature' => '', 'pconversation_filters' => '', 'pp_setting_count_comments' => 1, 'pp_setting_count_visitors' => 1));
 }
Exemplo n.º 2
0
 /**
 * Get variable values
 *
 * @param	array	Member information
 * @param	int		0 	All
 					1	Member Specific only
 					2	Global only
 * @retrun	array	key/value pairs
 */
 protected function _getVariableInformation($member, $type = 0, $html = TRUE)
 {
     $variables = array();
     if ($type == 0 or $type == 2) {
         $variables['board_name'] = str_replace("'", "'", $this->settings['board_name']);
         $variables['board_url'] = $this->settings['board_url'] . "/index." . $this->settings['php_ext'];
         $variables['reg_total'] = $this->caches['stats']['mem_count'];
         $variables['total_posts'] = $this->caches['stats']['total_topics'] + $this->caches['stats']['total_replies'];
         $variables['busy_count'] = $this->caches['stats']['most_count'];
         $variables['busy_time'] = ipsRegistry::getClass('class_localization')->getDate($this->caches['stats']['most_date'], 'SHORT');
     }
     if ($type == 0 or $type == 1) {
         $variables['member_id'] = $member['member_id'];
         $variables['member_name'] = $member['members_display_name'];
         $variables['member_joined'] = ipsRegistry::getClass('class_localization')->getDate($member['joined'], 'JOINED', TRUE);
         $variables['member_posts'] = $member['posts'];
         $variables['member_last_visit'] = ipsRegistry::getClass('class_localization')->getDate($member['last_visit'], 'JOINED', TRUE);
         $this->registry->class_localization->loadLanguageFile(array('public_global'), 'core', $member['language'] ? $member['language'] : IPSLib::getDefaultLanguage(), TRUE);
         $key = md5($member['email'] . ':' . $member['members_pass_hash']);
         $link = $this->registry->output->buildUrl("app=core&module=global&section=unsubscribe&member={$member['member_id']}&key={$key}", 'publicNoSession');
         $variables['unsubscribe'] = $html ? "<a href='{$link}'>" . $this->registry->class_localization->words['email_unsubscribe'] . '</a>' : "{$this->registry->class_localization->words['email_unsubscribe']}: {$link}";
     }
     return $variables;
 }
Exemplo n.º 3
0
 /**
  * Finish up conversion stuff
  * 
  * @return	@e void
  */
 public function finish()
 {
     $options = IPSSetUp::getSavedData('custom_options');
     $skipPms = $options['core'][30001]['skipPms'];
     $output = array();
     /* Emoticons */
     if (file_exists(DOC_IPS_ROOT_PATH . 'style_emoticons/default')) {
         try {
             foreach (new DirectoryIterator(DOC_IPS_ROOT_PATH . 'style_emoticons/default') as $file) {
                 if (!$file->isDot()) {
                     $_name = $file->getFileName();
                     /* Annoyingly, isDot doesn't match .svn, etc */
                     if (substr($_name, 0, 1) == '.') {
                         continue;
                     }
                     if (@copy(DOC_IPS_ROOT_PATH . 'style_emoticons/default/' . $_name, IPS_PUBLIC_PATH . 'style_emoticons/default/' . $_name)) {
                         $output[] = "Смайлики: скопирован {$_name}...";
                     } else {
                         $output[] = "Не удалось скопировать {$_name} - после обновления перенесите его самостоятельно";
                     }
                 }
             }
         } catch (Exception $e) {
         }
     }
     /* LOG IN METHODS */
     $this->DB->build(array('select' => '*', 'from' => 'login_methods'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $loginMethods[$row['login_folder_name']] = $row;
     }
     $count = 6;
     $recount = array('internal' => 1, 'ipconverge' => 2, 'ldap' => 3, 'external' => 4);
     /* Fetch XML */
     require_once IPS_KERNEL_PATH . 'classXML.php';
     /*noLibHook*/
     $xml = new classXML(IPSSetUp::charSet);
     $xml->load(IPS_ROOT_PATH . 'setup/xml/loginauth.xml');
     foreach ($xml->fetchElements('login_methods') as $xmlelement) {
         $data = $xml->fetchElementsFromRecord($xmlelement);
         $data['login_order'] = isset($recount[$data['login_folder_name']]) ? $recount[$data['login_folder_name']] : ++$count;
         unset($data['login_id']);
         if (!$loginMethods[$data['login_folder_name']]) {
             $this->DB->insert('login_methods', $data);
         } else {
             $this->DB->update('login_methods', array('login_order' => $data['login_order']), 'login_folder_name=\'' . $data['login_folder_name'] . '\'');
         }
     }
     /* Reset member languages and skins */
     $this->DB->update('members', array('language' => IPSLib::getDefaultLanguage(), 'skin' => 0));
     /* Empty caches */
     $this->DB->delete('cache_store', "cs_key='forum_cache'");
     $this->DB->delete('cache_store', "cs_key='skin_id_cache'");
     /* Empty other tables */
     $this->DB->delete('skin_cache');
     $this->DB->delete('skin_templates_cache');
     /* Reset admin permissions */
     $this->DB->update('admin_permission_rows', array('row_perm_cache' => ''));
     /* Drop Tables */
     $this->DB->dropTable('contacts');
     $this->DB->dropTable('skin_macro');
     $this->DB->dropTable('skin_template_links');
     $this->DB->dropTable('skin_templates_old');
     $this->DB->dropTable('skin_sets');
     $this->DB->dropTable('languages');
     $this->DB->dropTable('topics_read');
     $this->DB->dropTable('topic_markers');
     $this->DB->dropTable('acp_help');
     $this->DB->dropTable('members_converge');
     $this->DB->dropTable('member_extra');
     $this->DB->dropTable('custom_bbcode_old');
     $this->DB->dropTable('admin_sessions');
     $this->DB->dropTable('components');
     $this->DB->dropTable('admin_permission_keys');
     $this->DB->dropTable('conf_settings');
     $this->DB->dropTable('conf_settings_titles');
     $this->DB->dropTable('reg_antispam');
     if (!$skipPms) {
         $this->DB->dropTable('message_text');
         $this->DB->dropTable('message_topics_old');
     }
     $message = (is_array($output) and count($output)) ? implode("<br />", $output) . '<br />' : '';
     $this->registry->output->addMessage($message . "очистка SQL завершена...");
     /* Last function, so unset workact */
     $this->request['workact'] = '';
 }
Exemplo n.º 4
0
 /**
  * Send out quote notifications, yo.
  *
  * @param	array	$post			Post data
  * @param	array	$membersToSkip	List of member IDs to not send notifications to
  * @return	void
  */
 public function sendOutQuoteNotifications($post, $membersToSkip)
 {
     $seen = array();
     if (stristr($post['post'], '<blockquote') || stristr($post['post'], '[quote')) {
         if (preg_match_all('#(\\[quote|\\<blockquote)(?:[^\\]]+?)data-cid=(?:\'|"|&quot;|&\\#39;)(\\d+?)(?:\'|"|&quot;|&\\#39;)#', $post['post'], $quotes)) {
             $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications');
             $notifyLibrary = new $classToLoad($this->registry);
             $posts = $this->registry->getClass('topics')->getPosts(array('postId' => array_unique($quotes[2])));
             foreach ($posts as $pid => $_quoted) {
                 /* Try and make things a bit more readable */
                 $_toMember = $_quoted;
                 if (!$_toMember['member_id']) {
                     continue;
                 }
                 $topic = $this->registry->getClass('topics')->getTopicById($post['topic_id']);
                 /* Is the user being ignored? */
                 $ignored = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'ignored_users', 'where' => 'ignore_ignore_id=' . $this->memberData['member_id'] . ' AND ignore_owner_id=' . $_toMember['member_id'] . ' AND ignore_topics = 1'));
                 if ($this->registry->getClass('topics')->canView($topic, $_toMember) && !$ignored) {
                     if (!isset($seen[$_quoted['author_id']]) && $_quoted['author_id'] && $_quoted['author_id'] != $this->getAuthor('member_id') and !in_array($_quoted['author_id'], $membersToSkip)) {
                         $seen[$_quoted['author_id']] = true;
                         $_toMember['language'] = $_toMember['language'] == "" ? IPSLib::getDefaultLanguage() : $_toMember['language'];
                         IPSText::getTextClass('email')->getTemplate("post_was_quoted", $_toMember['language']);
                         IPSText::getTextClass('email')->buildMessage(array('MEMBER_NAME' => $this->getAuthor('members_display_name'), 'ORIGINAL_POST' => $this->registry->output->buildSEOUrl("showtopic={$_quoted['tid']}&amp;view=findpost&amp;p={$_quoted['pid']}", "publicNoSession", $_quoted['title_seo'], 'showtopic'), 'NEW_POST' => $this->registry->output->buildSEOUrl("showtopic={$post['topic_id']}&amp;view=findpost&amp;p={$post['pid']}", "publicNoSession", $topic['title_seo'], 'showtopic'), 'POST' => $post['post']));
                         IPSText::getTextClass('email')->subject = sprintf(IPSText::getTextClass('email')->subject, $this->registry->output->buildSEOUrl('showuser='******'member_id'), 'publicNoSession', $this->getAuthor('members_seo_name'), 'showuser'), $this->getAuthor('members_display_name'), $this->registry->output->buildSEOUrl("showtopic={$post['topic_id']}&amp;view=findpost&amp;p={$post['pid']}", "publicNoSession", $topic['title_seo'], 'showtopic'), $this->registry->output->buildSEOUrl("showtopic={$_quoted['tid']}&amp;view=findpost&amp;p={$_quoted['pid']}", "publicNoSession", $_quoted['title_seo'], 'showtopic'));
                         $notifyLibrary->setMember($_toMember);
                         $notifyLibrary->setFrom($this->memberData);
                         $notifyLibrary->setNotificationKey('post_quoted');
                         $notifyLibrary->setNotificationUrl($this->registry->output->buildSEOUrl("showtopic={$post['topic_id']}&amp;view=findpost&amp;p={$post['pid']}", "public", $topic['title_seo'], 'showtopic'));
                         $notifyLibrary->setNotificationText(IPSText::getTextClass('email')->message);
                         $notifyLibrary->setNotificationTitle(IPSText::getTextClass('email')->subject);
                         try {
                             $notifyLibrary->sendNotification();
                         } catch (Exception $e) {
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Create new member
  * Very basic functionality at this point.
  *
  * @access	public
  * @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]'
  * @param	bool	Flag to attempt to auto create a name if the desired is taken
  * @param	bool	Bypass custom field saving (if using the sso session integration this is required as member object isn't ready yet)
  * @return	array 	Final member Data including member_id
  *
  * EXCEPTION CODES
  * CUSTOM_FIELDS_EMPTY    - Custom fields were not populated
  * CUSTOM_FIELDS_INVALID  - Custom fields were invalid
  * CUSTOM_FIELDS_TOOBIG   - Custom fields too big
  */
 public static function create($tables = array(), $autoCreateName = FALSE, $bypassCfields = FALSE)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $finalTables = array();
     $password = '';
     $bitWiseFields = ipsRegistry::fetchBitWiseOptions('global');
     //-----------------------------------------
     // Remap tables if required
     //-----------------------------------------
     foreach ($tables as $table => $data) {
         $_name = isset(self::$remap[$table]) ? self::$remap[$table] : $table;
         if ($_name == 'members') {
             /* Magic password field */
             $password = isset($data['password']) ? trim($data['password']) : IPSLib::makePassword();
             $md_5_password = md5($password);
             unset($data['password']);
         }
         $finalTables[$_name] = $data;
     }
     //-----------------------------------------
     // Custom profile field stuff
     //-----------------------------------------
     if (!$bypassCfields) {
         require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
         $fields = new customProfileFields();
         if (is_array($finalTables['pfields_content']) and count($finalTables['pfields_content'])) {
             $fields->member_data = $finalTables['pfields_content'];
         }
         $_cfieldMode = 'normal';
         $fields->initData('edit');
         $fields->parseToSave($finalTables['pfields_content'], 'register');
         /* Check */
         if (count($fields->error_fields['empty'])) {
             //throw new Exception( 'CUSTOM_FIELDS_EMPTY' );
         }
         if (count($fields->error_fields['invalid'])) {
             //throw new Exception( 'CUSTOM_FIELDS_INVALID' );
         }
         if (count($fields->error_fields['toobig'])) {
             //throw new Exception( 'CUSTOM_FIELDS_TOOBIG' );
         }
     }
     //-----------------------------------------
     // Make sure the account doesn't exist
     //-----------------------------------------
     if ($finalTables['members']['email']) {
         $existing = IPSMember::load($finalTables['members']['email'], 'all');
         if ($existing['member_id']) {
             $existing['full'] = true;
             $existing['timenow'] = time();
             return $existing;
         }
     }
     //-----------------------------------------
     // Fix up usernames and display names
     //-----------------------------------------
     /* Ensure we have a display name */
     $finalTables['members']['members_display_name'] = $finalTables['members']['members_display_name'] ? $finalTables['members']['members_display_name'] : $finalTables['members']['name'];
     //-----------------------------------------
     // Clean up characters
     //-----------------------------------------
     if ($finalTables['members']['name']) {
         $userName = IPSMember::getFunction()->cleanAndCheckName($finalTables['members']['name'], array(), 'name');
         if ($userName['errors']) {
             $finalTables['members']['name'] = '';
         } else {
             $finalTables['members']['name'] = $userName['username'];
         }
     }
     if ($finalTables['members']['members_display_name']) {
         $displayName = IPSMember::getFunction()->cleanAndCheckName($finalTables['members']['members_display_name']);
         if ($displayName['errors']) {
             $finalTables['members']['members_display_name'] = '';
         } else {
             $finalTables['members']['members_display_name'] = $displayName['members_display_name'];
         }
     }
     //-----------------------------------------
     // Remove some basic HTML tags
     //-----------------------------------------
     $finalTables['members']['members_display_name'] = str_replace(array('<', '>', '"'), '', $finalTables['members']['members_display_name']);
     $finalTables['members']['name'] = str_replace(array('<', '>', '"'), '', $finalTables['members']['name']);
     //-----------------------------------------
     // Make sure the names are unique
     //-----------------------------------------
     if ($finalTables['members']['members_display_name']) {
         try {
             if (IPSMember::getFunction()->checkNameExists($finalTables['members']['members_display_name'], array(), 'members_display_name', true) === true) {
                 if ($autoCreateName === TRUE) {
                     /* Now, make sure we have a unique display name */
                     $max = ipsRegistry::DB()->buildAndFetch(array('select' => 'MAX(member_id) as max', 'from' => 'members', 'where' => "members_l_display_name LIKE '" . $this->DB->addSlashes(strtolower($finalTables['members']['members_display_name'])) . "%'"));
                     if ($max['max']) {
                         $_num = $max['max'] + 1;
                         $finalTables['members']['members_display_name'] = $finalTables['members']['members_display_name'] . '_' . $_num;
                     }
                 } else {
                     $finalTables['members']['members_display_name'] = '';
                 }
             }
         } catch (Exception $e) {
         }
     }
     if ($finalTables['members']['name']) {
         try {
             if (IPSMember::getFunction()->checkNameExists($finalTables['members']['name'], array(), 'name', true) === true) {
                 if ($autoCreateName === TRUE) {
                     /* Now, make sure we have a unique username */
                     $max = ipsRegistry::DB()->buildAndFetch(array('select' => 'MAX(member_id) as max', 'from' => 'members', 'where' => "members_l_username LIKE '" . $this->DB->addSlashes(strtolower($finalTables['members']['name'])) . "%'"));
                     if ($max['max']) {
                         $_num = $max['max'] + 1;
                         $finalTables['members']['name'] = $finalTables['members']['name'] . '_' . $_num;
                     }
                 } else {
                     $finalTables['members']['name'] = '';
                 }
             }
         } catch (Exception $e) {
         }
     }
     //-----------------------------------------
     // Populate member table(s)
     //-----------------------------------------
     $finalTables['members']['members_l_username'] = isset($finalTables['members']['name']) ? strtolower($finalTables['members']['name']) : '';
     $finalTables['members']['joined'] = $finalTables['members']['joined'] ? $finalTables['members']['joined'] : time();
     $finalTables['members']['email'] = $finalTables['members']['email'] ? $finalTables['members']['email'] : $finalTables['members']['name'] . '@' . $finalTables['members']['joined'];
     $finalTables['members']['member_group_id'] = $finalTables['members']['member_group_id'] ? $finalTables['members']['member_group_id'] : ipsRegistry::$settings['member_group'];
     $finalTables['members']['ip_address'] = $finalTables['members']['ip_address'] ? $finalTables['members']['ip_address'] : ipsRegistry::member()->ip_address;
     $finalTables['members']['members_created_remote'] = intval($finalTables['members']['members_created_remote']);
     $finalTables['members']['member_login_key'] = IPSMember::generateAutoLoginKey();
     $finalTables['members']['member_login_key_expire'] = ipsRegistry::$settings['login_key_expire'] ? time() + intval(ipsRegistry::$settings['login_key_expire']) * 86400 : 0;
     $finalTables['members']['view_sigs'] = 1;
     $finalTables['members']['email_pm'] = 1;
     $finalTables['members']['view_img'] = 1;
     $finalTables['members']['view_avs'] = 1;
     $finalTables['members']['restrict_post'] = intval($finalTables['members']['restrict_post']);
     $finalTables['members']['view_pop'] = 1;
     $finalTables['members']['msg_count_total'] = 0;
     $finalTables['members']['msg_count_new'] = 0;
     $finalTables['members']['msg_show_notification'] = 1;
     $finalTables['members']['coppa_user'] = 0;
     $finalTables['members']['auto_track'] = intval($finalTables['members']['auto_track']);
     $finalTables['members']['last_visit'] = $finalTables['members']['last_visit'] ? $finalTables['members']['last_visit'] : time();
     $finalTables['members']['last_activity'] = $finalTables['members']['last_activity'] ? $finalTables['members']['last_activity'] : time();
     $finalTables['members']['language'] = IPSLib::getDefaultLanguage();
     $finalTables['members']['members_editor_choice'] = ipsRegistry::$settings['ips_default_editor'];
     $finalTables['members']['members_pass_salt'] = IPSMember::generatePasswordSalt(5);
     $finalTables['members']['members_pass_hash'] = IPSMember::generateCompiledPasshash($finalTables['members']['members_pass_salt'], $md_5_password);
     $finalTables['members']['members_display_name'] = isset($finalTables['members']['members_display_name']) ? $finalTables['members']['members_display_name'] : '';
     $finalTables['members']['members_l_display_name'] = isset($finalTables['members']['members_display_name']) ? strtolower($finalTables['members']['members_display_name']) : '';
     $finalTables['members']['fb_uid'] = isset($finalTables['members']['fb_uid']) ? $finalTables['members']['fb_uid'] : 0;
     $finalTables['members']['fb_emailhash'] = isset($finalTables['members']['fb_emailhash']) ? strtolower($finalTables['members']['fb_emailhash']) : '';
     $finalTables['members']['members_seo_name'] = IPSText::makeSeoTitle($finalTables['members']['members_display_name']);
     $finalTables['members']['bw_is_spammer'] = intval($finalTables['members']['bw_is_spammer']);
     //-----------------------------------------
     // Insert: MEMBERS
     //-----------------------------------------
     ipsRegistry::DB()->force_data_type = array('name' => 'string', 'members_l_username' => 'string', 'members_display_name' => 'string', 'members_l_display_name' => 'string', 'members_seo_name' => 'string', 'email' => 'string');
     /* Bitwise options */
     if (is_array($bitWiseFields['members'])) {
         $_freeze = array();
         foreach ($bitWiseFields['members'] as $field) {
             if (isset($finalTables['members'][$field])) {
                 /* Add to freezeable array */
                 $_freeze[$field] = $finalTables['members'][$field];
                 /* Remove it from the fields to save to DB */
                 unset($finalTables['members'][$field]);
             }
         }
         if (count($_freeze)) {
             $finalTables['members']['members_bitoptions'] = IPSBWOptions::freeze($_freeze, 'members', 'global');
         }
     }
     ipsRegistry::DB()->insert('members', $finalTables['members']);
     //-----------------------------------------
     // Get the member id
     //-----------------------------------------
     $finalTables['members']['member_id'] = ipsRegistry::DB()->getInsertId();
     //-----------------------------------------
     // Insert: PROFILE PORTAL
     //-----------------------------------------
     $finalTables['profile_portal']['pp_member_id'] = $finalTables['members']['member_id'];
     $finalTables['profile_portal']['pp_setting_count_friends'] = 1;
     $finalTables['profile_portal']['pp_setting_count_comments'] = 1;
     ipsRegistry::DB()->insert('profile_portal', $finalTables['profile_portal']);
     //-----------------------------------------
     // Insert into the custom profile fields DB
     //-----------------------------------------
     if (!$bypassCfields) {
         $fields->out_fields['member_id'] = $finalTables['members']['member_id'];
         ipsRegistry::DB()->delete('pfields_content', 'member_id=' . $finalTables['members']['member_id']);
         ipsRegistry::DB()->insert('pfields_content', $fields->out_fields);
     } else {
         ipsRegistry::DB()->delete('pfields_content', 'member_id=' . $finalTables['members']['member_id']);
         ipsRegistry::DB()->insert('pfields_content', array('member_id' => $finalTables['members']['member_id']));
     }
     //-----------------------------------------
     // Insert into partial ID table
     //-----------------------------------------
     $full_account = false;
     if ($finalTables['members']['members_display_name'] and $finalTables['members']['name'] and $finalTables['members']['email'] != $finalTables['members']['name'] . '@' . $finalTables['members']['joined']) {
         $full_account = true;
     }
     if (!$full_account) {
         ipsRegistry::DB()->insert('members_partial', array('partial_member_id' => $finalTables['members']['member_id'], 'partial_date' => $finalTables['members']['joined'], 'partial_email_ok' => $finalTables['members']['email'] == $finalTables['members']['name'] . '@' . $finalTables['members']['joined'] ? 0 : 1));
     }
     //IPSMember::updateSearchIndex( $finalTables['members']['member_id'] );
     IPSLib::runMemberSync('onCreateAccount', $finalTables['members']);
     return array_merge($finalTables['members'], $finalTables['profile_portal'], !$bypassCfields ? $fields->out_fields : array(), array('timenow' => $finalTables['members']['joined'], 'full' => $full_account));
 }
Exemplo n.º 6
0
 /**
  * Add a member [process]
  *
  * @return	@e void
  */
 protected function _memberDoAdd()
 {
     /* Init vars */
     $in_username = trim($this->request['name']);
     $in_password = trim($this->request['password']);
     $in_email = trim(strtolower($this->request['email']));
     $members_display_name = $this->request['mirror_loginname'] ? $in_username : trim($this->request['members_display_name']);
     $this->registry->output->global_error = '';
     $this->registry->class_localization->loadLanguageFile(array('public_register'), 'core');
     /* Check erros */
     foreach (array('name', 'password', 'email', 'member_group_id') as $field) {
         if (!$_POST[$field]) {
             $this->registry->output->showError($this->lang->words['m_completeform'], 11238);
         }
     }
     //-----------------------------------------
     // Check
     //-----------------------------------------
     if (!IPSText::checkEmailAddress($in_email)) {
         $this->registry->output->global_error = $this->lang->words['m_emailinv'];
     }
     $userName = IPSMember::getFunction()->cleanAndCheckName($in_username, array(), 'name');
     $displayName = IPSMember::getFunction()->cleanAndCheckName($members_display_name, array(), 'members_display_name');
     if (count($userName['errors'])) {
         $_message = $this->lang->words[$userName['errors']['username']] ? $this->lang->words[$userName['errors']['username']] : $userName['errors']['username'];
         $this->registry->output->global_error .= '<p>' . $this->lang->words['sm_loginname'] . ': ' . $_message . '</p>';
     }
     if ($this->settings['auth_allow_dnames'] and count($displayName['errors'])) {
         $_message = $this->lang->words[$displayName['errors']['dname']] ? $this->lang->words[$displayName['errors']['dname']] : $displayName['errors']['dname'];
         $this->registry->output->global_error .= '<p>' . $this->lang->words['sm_display'] . ': ' . $_message . '</p>';
     }
     /* Errors? */
     if ($this->registry->output->global_error) {
         $this->_memberAddForm();
         return;
     }
     //-----------------------------------------
     // Load handler...
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/handlers/han_login.php', 'han_login');
     $this->han_login = new $classToLoad($this->registry);
     $this->han_login->init();
     //-----------------------------------------
     // Only check local, else a user being in Converge
     // means that you can't manually add the user to the board
     //-----------------------------------------
     $email_check = $this->DB->buildAndFetch(array('select' => 'member_id', 'from' => 'members', 'where' => "email='" . $in_email . "'"));
     if ($email_check['member_id']) {
         $this->registry->output->global_error = $this->lang->words['m_emailalready'];
         $this->_memberAddForm();
         return;
     }
     //$this->han_login->emailExistsCheck( $in_email );
     //if( $this->han_login->return_code AND $this->han_login->return_code != 'METHOD_NOT_DEFINED' AND $this->han_login->return_code != 'EMAIL_NOT_IN_USE' )
     //{
     //	$this->registry->output->global_message = $this->lang->words['m_emailalready'];
     //	$this->_memberAddForm();
     //	return;
     //}
     //-----------------------------------------
     // Allowed to add administrators?
     //-----------------------------------------
     if ($this->caches['group_cache'][intval($this->request['member_group_id'])]['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_add_admin')) {
         $this->registry->output->global_error = $this->lang->words['m_addadmin'];
         $this->_memberAddForm();
         return;
     }
     $member = array('name' => $in_username, 'members_display_name' => $members_display_name ? $members_display_name : $in_username, 'email' => $in_email, 'member_group_id' => intval($this->request['member_group_id']), 'joined' => time(), 'ip_address' => $this->member->ip_address, 'time_offset' => $this->settings['time_offset'], 'coppa_user' => intval($this->request['coppa']), 'allow_admin_mails' => 1, 'password' => $in_password, 'language' => IPSLib::getDefaultLanguage());
     //-----------------------------------------
     // Create the account
     //-----------------------------------------
     $member = IPSMember::create(array('members' => $member, 'pfields_content' => $this->request), FALSE, FALSE, FALSE);
     //-----------------------------------------
     // Login handler create account callback
     //-----------------------------------------
     $this->han_login->createAccount(array('email' => $in_email, 'joined' => $member['joined'], 'password' => $in_password, 'ip_address' => $member['ip_address'], 'username' => $member['members_display_name']));
     /*if( $this->han_login->return_code AND $this->han_login->return_code != 'METHOD_NOT_DEFINED' AND $this->han_login->return_code != 'SUCCESS' )
     		{
     			$this->registry->output->global_message = sprintf( $this->lang->words['m_cantadd'], $this->han_login->return_code ) . $this->han_login->return_details;
     			$this->_memberAddForm();
     			return;
     		}*/
     //-----------------------------------------
     // Restriction permissions stuff
     //-----------------------------------------
     if ($this->memberData['row_perm_cache']) {
         if ($this->caches['group_cache'][intval($this->request['member_group_id'])]['g_access_cp']) {
             //-----------------------------------------
             // Copy restrictions...
             //-----------------------------------------
             $this->DB->insert('admin_permission_rows', array('row_member_id' => $member['member_id'], 'row_perm_cache' => $this->memberData['row_perm_cache'], 'row_updated' => time()));
         }
     }
     //-----------------------------------------
     // Send teh email (I love 'teh' as much as !!11!!1)
     //-----------------------------------------
     if ($this->request['sendemail']) {
         IPSText::getTextClass('email')->setPlainTextTemplate(IPSText::getTextClass('email')->getTemplate("account_created"));
         IPSText::getTextClass('email')->buildMessage(array('NAME' => $member['name'], 'EMAIL' => $member['email'], 'PASSWORD' => $in_password));
         IPSText::getTextClass('email')->to = $member['email'];
         IPSText::getTextClass('email')->sendMail();
     }
     //-----------------------------------------
     // Stats
     //-----------------------------------------
     $this->cache->rebuildCache('stats', 'global');
     $this->cache->rebuildCache('birthdays', 'calendar');
     //-----------------------------------------
     // Log and bog?
     //-----------------------------------------
     ipsRegistry::getClass('adminFunctions')->saveAdminLog(sprintf($this->lang->words['m_createlog'], $this->request['name']));
     $this->registry->output->global_message = $this->lang->words['m_memadded'];
     $this->request['member_id'] = $member['member_id'];
     $this->_showAdminForm($member, array());
     $this->_memberView();
 }
 /**
  * Sends a new personal message. Very simple.
  *
  * @param	int				TO Member ID
  * @param	int				FROM Member ID
  * @param	array 			Array of InviteUser Names (display name)
  * @param	string			Message Title
  * @param	string			Message Content
  * @param	array 			Options array[ 'isSystem' (if true, then user will have no record of sending this PM) postKey, 'isDraft', 'sendMode' (invite/copy), 'topicID' ] If a topicID is passed, it's presumed that it was a draft....
  * @return	mixed			TRUE or FALSE or Exception
  *
  * <code>
  * Exception Codes:
  * TOPIC_ID_NOT_EXISTS:				Topic ID does not exist (re-sending a draft)
  * NOT_ALL_INVITE_USERS_EXIST: 		Not all invite users exist (check $this->exceptionData for a list of names)
  * NOT_ALL_INVITE_USERS_CAN_PM:		Not all invite users can PM (check $this->exceptionData for a list of names)
  * INVITE_USERS_BLOCKED:			Some invite users have been blocked (check $this->exceptionData for a list of names)
  * TO_USER_DOES_NOT_EXIST:		    The 'to' user ID does not exist
  * FROM_USER_DOES_NOT_EXIST:		The 'from' user ID does not exist
  * TO_USER_CANNOT_USE_PM:		    The 'to' user does not have access to PM system
  * TO_USER_FULL:					The 'to' user cannot accept any more PMs (inbox full)
  * FROM_USER_BLOCKED:			    The 'from' user has been blocked by the 'to' user
  * CANNOT_SAVE_TO_SENT_FOLDER:	    The 'from' user does not have space to store a copy of the message in their sent folder
  * MSG_TITLE_EMPTY:				    The 'msgTitle' variable is empty
  * MSG_CONTENT_EMPTY:			    The 'msgContent' varable is empty
  * CANT_SEND_TO_SELF:				The main recipient and sender are the same
  * CANT_INVITE_SELF:				The sender is in the invite list
  * CANT_INVITE_RECIPIENT:			The main recipient is in the invite list
  * FLOOD_STOP						Flood control will not allow this message to send
  * </code>
  */
 public function sendNewPersonalTopic($toMemberID, $fromMemberID, $inviteUsers, $msgTitle, $msgContent, $options = array())
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $toMemberData = array();
     $fromMemberData = array();
     $inviteUsersData = array();
     $isDraft = $options['isDraft'] ? TRUE : FALSE;
     $isCopyTo = $options['sendMode'] == 'copy' ? TRUE : FALSE;
     $isSystem = $options['isSystem'] === TRUE || $options['isSystem'] == 1 ? 1 : 0;
     $options['postKey'] = $options['postKey'] ? $options['postKey'] : md5(microtime());
     /* Set up force message*/
     $this->forceMessageToSend = $this->forceMessageToSend ? $this->forceMessageToSend : ($options['forcePm'] ? TRUE : FALSE);
     //-----------------------------------------
     // Check content
     //-----------------------------------------
     if ($toMemberID == $fromMemberID) {
         throw new Exception('CANT_SEND_TO_SELF');
     }
     if (!$msgTitle) {
         throw new Exception('MSG_TITLE_EMPTY');
     }
     if (!$msgContent) {
         throw new Exception('MSG_CONTENT_EMPTY');
     }
     //-----------------------------------------
     // Format content
     //-----------------------------------------
     try {
         $_originalMessageContent = $msgContent;
         $msgContent = $this->_formatMessageForSaving($msgContent);
     } catch (Exception $error) {
         throw new Exception($error->getMessage());
     }
     //-----------------------------------------
     // First off, load the to and from members
     //-----------------------------------------
     $_members = IPSMember::load(array($toMemberID, $fromMemberID), 'groups,extendedProfile');
     $toMemberData = $this->_setMaxMessages($_members[$toMemberID]);
     $fromMemberData = $this->_setMaxMessages($_members[$fromMemberID]);
     if (empty($toMemberData['member_id']) and $this->forceMessageToSend !== TRUE) {
         throw new Exception('TO_USER_DOES_NOT_EXIST');
     }
     if (empty($fromMemberData['member_id']) and $this->forceMessageToSend !== TRUE) {
         throw new Exception('FROM_USER_DOES_NOT_EXIST');
     }
     if ($this->floodControlCheck() !== TRUE) {
         throw new Exception('FLOOD_STOP');
     }
     //-----------------------------------------
     // Sort out invite users
     //-----------------------------------------
     if (is_array($inviteUsers) and count($inviteUsers)) {
         try {
             if ($fromMemberData['g_max_mass_pm'] > 0 or $this->forceMessageToSend === TRUE) {
                 $inviteUsersData = $this->checkAndReturnInvitedUsers($inviteUsers);
             }
         } catch (Exception $error) {
             if ($this->forceMessageToSend !== TRUE) {
                 throw new Exception($error->getMessage());
             }
         }
         if (isset($inviteUsersData[$fromMemberID])) {
             throw new Exception('CANT_INVITE_SELF');
         }
         if (isset($inviteUsersData[$toMemberID])) {
             throw new Exception('CANT_INVITE_RECIPIENT');
         }
     }
     //-----------------------------------------
     // Can the 'to' user accept a PM?
     //-----------------------------------------
     if ($this->canUsePMSystem($toMemberData) !== TRUE) {
         if ($this->forceMessageToSend !== TRUE) {
             throw new Exception('TO_USER_CANNOT_USE_PM');
         }
     }
     //-----------------------------------------
     // Does the 'to' user have enough space?
     //-----------------------------------------
     if ($this->withinPMQuota($toMemberData) !== TRUE) {
         if ($this->forceMessageToSend !== TRUE) {
             throw new Exception('TO_USER_FULL');
         }
     }
     //-----------------------------------------
     // Has the 'to' use blocked us?
     //-----------------------------------------
     if (count($this->blockedByUser($fromMemberData, $toMemberData))) {
         if ($this->forceMessageToSend !== TRUE) {
             throw new Exception('FROM_USER_BLOCKED');
         }
     }
     //-----------------------------------------
     // Is this simply a copy-to?
     //-----------------------------------------
     if ($isCopyTo === TRUE and !$isDraft) {
         /* Send out the main one */
         $this->sendNewPersonalTopic($toMemberID, $fromMemberID, array(), $msgTitle, $_originalMessageContent, array('postKey' => $options['postKey']));
         /* Send out copy-tos */
         foreach ($inviteUsersData as $id => $toMember) {
             $_newPostKey = md5(microtime());
             $_newContent = $_originalMessageContent;
             /* We need to duplicate the attachment record for each copy sent */
             $this->DB->build(array('select' => '*', 'from' => 'attachments', 'where' => "attach_post_key='{$options['postKey']}'"));
             $outer = $this->DB->execute();
             $idRemap = array();
             while ($attachData = $this->DB->fetch($outer)) {
                 $attachData['attach_post_key'] = $_newPostKey;
                 $_oldAttachId = $attachData['attach_id'];
                 unset($attachData['attach_id']);
                 $this->DB->insert('attachments', $attachData);
                 $idRemap[$_oldAttachId] = $this->DB->getInsertId();
             }
             if (count($idRemap)) {
                 foreach ($idRemap as $_oldId => $_newId) {
                     $_newContent = str_replace('=' . $_oldId . ':', '=' . $_newId . ':', $_newContent);
                 }
             }
             $this->sendNewPersonalTopic($toMember['member_id'], $fromMemberID, array(), $msgTitle, $_newContent, array('postKey' => $_newPostKey));
         }
         /* Done */
         return TRUE;
     }
     //-----------------------------------------
     // Insert the user data
     //-----------------------------------------
     $_count = count($inviteUsersData);
     //-----------------------------------------
     // Got a topic ID?
     //-----------------------------------------
     if ($options['topicID']) {
         /* Fetch topic data */
         $_topicData = $this->fetchTopicData($options['topicID']);
         if (!$_topicData['mt_id'] and $this->forceMessageToSend !== TRUE) {
             throw new Exception('TOPIC_ID_NOT_EXISTS');
         }
         $this->DB->setDataType('mt_title', 'string');
         /* First off, update message_topics and message_posts... */
         $this->DB->update('message_topics', array('mt_date' => time(), 'mt_title' => $msgTitle, 'mt_starter_id' => $fromMemberData['member_id'], 'mt_start_time' => time(), 'mt_last_post_time' => time(), 'mt_invited_members' => serialize(array_keys($inviteUsersData)), 'mt_to_count' => count(array_keys($inviteUsersData)) + 1, 'mt_to_member_id' => $toMemberData['member_id'], 'mt_is_draft' => intval($isDraft)), 'mt_id=' . $_topicData['mt_id']);
         /* Now the posts ... */
         $this->DB->update('message_posts', array('msg_date' => time(), 'msg_topic_id' => $_topicData['mt_id'], 'msg_post' => $msgContent, 'msg_author_id' => $fromMemberData['member_id'], 'msg_is_first_post' => 1, 'msg_ip_address' => $this->member->ip_address), 'msg_id=' . $_topicData['mt_first_msg_id']);
         /* Delete any current user mapping as this will be sorted out below */
         $this->DB->delete('message_topic_user_map', 'map_topic_id=' . $_topicData['mt_id']);
         /* Reset variable IDs */
         $msg_topic_id = $_topicData['mt_id'];
         $msg_id = $_topicData['mt_first_msg_id'];
     } else {
         $_messageTopicData = array('mt_date' => time(), 'mt_title' => $msgTitle, 'mt_starter_id' => $fromMemberData['member_id'], 'mt_start_time' => IPS_UNIX_TIME_NOW, 'mt_last_post_time' => IPS_UNIX_TIME_NOW, 'mt_invited_members' => serialize(array_keys($inviteUsersData)), 'mt_to_count' => count(array_keys($inviteUsersData)) + 1, 'mt_to_member_id' => $toMemberData['member_id'], 'mt_is_draft' => $isDraft ? 1 : 0, 'mt_is_system' => $isSystem, 'mt_replies' => 0);
         /* Create topic entry */
         $this->DB->setDataType('mt_title', 'string');
         /* Data Hook Location */
         IPSLib::doDataHooks($_messageTopicData, 'messengerSendTopicData');
         $this->DB->insert('message_topics', $_messageTopicData);
         $msg_topic_id = $this->DB->getInsertId();
         $_messagePostData = array('msg_date' => time(), 'msg_topic_id' => $msg_topic_id, 'msg_post' => $msgContent, 'msg_post_key' => $options['postKey'], 'msg_author_id' => $fromMemberData['member_id'], 'msg_is_first_post' => 1, 'msg_ip_address' => $this->member->ip_address);
         /* Data Hook Location */
         IPSLib::doDataHooks($_messagePostData, 'messengerSendTopicFirstPostData');
         $this->DB->insert('message_posts', $_messagePostData);
         $msg_id = $this->DB->getInsertId();
     }
     //-----------------------------------------
     // Update with last / first msg ID
     //-----------------------------------------
     $this->DB->update('message_topics', array('mt_last_msg_id' => $msg_id, 'mt_first_msg_id' => $msg_id, 'mt_hasattach' => intval($this->_makeAttachmentsPermanent($options['postKey'], $msg_id, $msg_topic_id))), 'mt_id=' . $msg_topic_id);
     //-----------------------------------------
     // Not a draft?
     //-----------------------------------------
     if ($isDraft !== TRUE) {
         //-----------------------------------------
         // Add in 'to user' and 'from user' to the cc array
         //-----------------------------------------
         $inviteUsersData[$toMemberData['member_id']] = $toMemberData;
         $inviteUsersData[$fromMemberData['member_id']] = $fromMemberData;
         //-----------------------------------------
         // Loop....
         //-----------------------------------------
         foreach ($inviteUsersData as $id => $toMember) {
             //-----------------------------------------
             // Enter the info into the DB
             // Target user side.
             //-----------------------------------------
             $_isStarter = $fromMemberData['member_id'] == $toMember['member_id'] ? 1 : 0;
             $_isSystem = ($fromMemberData['member_id'] == $toMember['member_id'] and $isSystem) ? 1 : 0;
             $_isActive = $_isSystem ? 0 : 1;
             /* Create user map entry */
             $this->DB->insert('message_topic_user_map', array('map_user_id' => $toMember['member_id'], 'map_topic_id' => $msg_topic_id, 'map_folder_id' => 'myconvo', 'map_user_active' => $_isActive, 'map_is_starter' => $fromMemberData['member_id'] == $toMember['member_id'] ? 1 : 0, 'map_has_unread' => $fromMemberData['member_id'] == $toMember['member_id'] ? 0 : 1, 'map_read_time' => $fromMemberData['member_id'] == $toMember['member_id'] ? IPS_UNIX_TIME_NOW : 0, 'map_is_system' => $_isSystem, 'map_user_banned' => 0, 'map_left_time' => 0, 'map_ignore_notification' => 0, 'map_last_topic_reply' => IPS_UNIX_TIME_NOW));
             //-----------------------------------------
             // Notifications library
             //-----------------------------------------
             if ($fromMemberData['member_id'] != $toMember['member_id']) {
                 $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications');
                 $notifyLibrary = new $classToLoad($this->registry);
                 $toMember['language'] = $toMember['language'] == "" ? IPSLib::getDefaultLanguage() : $toMember['language'];
                 $buildMessage = array('NAME' => $toMember['members_display_name'], 'POSTER' => $fromMemberData['members_display_name'], 'TITLE' => $msgTitle, 'TEXT' => $msgContent, 'LINK' => "?app=members&module=messaging&section=view&do=showConversation&topicID={$msg_topic_id}#msg{$msg_id}");
                 IPSText::getTextClass('email')->setPlainTextTemplate(IPSText::getTextClass('email')->getTemplate('personal_convo_new_convo', $toMember['language']));
                 IPSText::getTextClass('email')->buildPlainTextContent($buildMessage);
                 IPSText::getTextClass('email')->subject = sprintf(IPSText::getTextClass('email')->subject, $this->registry->output->buildSEOUrl('showuser='******'member_id'], 'public', $fromMemberData['members_seo_name'], 'showuser'), $fromMemberData['members_display_name'], $this->registry->output->buildUrl("app=members&module=messaging&section=view&do=showConversation&topicID={$msg_topic_id}#msg{$msg_id}", 'public'));
                 $notifyLibrary->setMember($toMember);
                 $notifyLibrary->setFrom($fromMemberData);
                 $notifyLibrary->setNotificationKey('new_private_message');
                 $notifyLibrary->setNotificationUrl($this->registry->output->buildUrl("app=members&module=messaging&section=view&do=showConversation&topicID={$msg_topic_id}#msg{$msg_id}", 'public'));
                 $notifyLibrary->setNotificationText(IPSText::getTextClass('email')->getPlainTextContent());
                 $notifyLibrary->setNotificationTitle(IPSText::getTextClass('email')->subject);
                 $notifyLibrary->setNotificationHtml(IPSText::getTextClass('email')->buildHtmlContent($buildMessage));
                 $notifyLibrary->setMetaData(array('meta_area' => 'pm', 'meta_id' => $msg_topic_id, 'meta_app' => 'members'));
                 try {
                     $notifyLibrary->sendNotification();
                 } catch (Exception $e) {
                 }
                 IPSMember::save($toMember['member_id'], array('core' => array('msg_count_total' => 'plus:1', 'msg_count_new' => 'plus:1', 'msg_count_reset' => 1)));
             } else {
                 IPSMember::save($toMember['member_id'], array('core' => array('msg_count_total' => 'plus:1')));
             }
         }
     } else {
         //-----------------------------------------
         // Is a draft
         //-----------------------------------------
         /* Create user map entry */
         $this->DB->insert('message_topic_user_map', array('map_user_id' => $fromMemberData['member_id'], 'map_topic_id' => $msg_topic_id, 'map_folder_id' => 'drafts', 'map_user_active' => 1, 'map_has_unread' => 0, 'map_user_banned' => 0, 'map_read_time' => 0, 'map_left_time' => 0, 'map_ignore_notification' => 0, 'map_last_topic_reply' => IPS_UNIX_TIME_NOW));
         if (!$options['topicID']) {
             //-----------------------------------------
             // Update profile
             //-----------------------------------------
             $this->rebuildFolderCount($fromMemberData['member_id'], array('drafts' => 'plus:1'), TRUE, array('core' => array('msg_count_total' => 'plus:1')));
         }
     }
     return TRUE;
 }
 /**
  * Sends a new personal message. Very simple.
  *
  * @access	public
  * @param	int				TO Member ID
  * @param	int				FROM Member ID
  * @param	array 			Array of InviteUser Names (display name)
  * @param	string			Message Title
  * @param	string			Message Content
  * @param	array 			Options array[ 'isSystem' (if true, then user will have no record of sending this PM) postKey, 'isDraft', 'sendMode' (invite/copy), 'topicID' ] If a topicID is passed, it's presumed that it was a draft....
  * @return	mixed			TRUE or FALSE or Exception
  *
  * <code>
  * Exception Codes:
  * TOPIC_ID_NOT_EXISTS:				Topic ID does not exist (re-sending a draft)
  * NOT_ALL_INVITE_USERS_EXIST: 		Not all invite users exist (check $this->exceptionData for a list of names)
  * NOT_ALL_INVITE_USERS_CAN_PM:		Not all invite users can PM (check $this->exceptionData for a list of names)
  * INVITE_USERS_BLOCKED:			Some invite users have been blocked (check $this->exceptionData for a list of names)
  * TO_USER_DOES_NOT_EXIST:		    The 'to' user ID does not exist
  * FROM_USER_DOES_NOT_EXIST:		The 'from' user ID does not exist
  * TO_USER_CANNOT_USE_PM:		    The 'to' user does not have access to PM system
  * TO_USER_FULL:					The 'to' user cannot accept any more PMs (inbox full)
  * FROM_USER_BLOCKED:			    The 'from' user has been blocked by the 'to' user
  * CANNOT_SAVE_TO_SENT_FOLDER:	    The 'from' user does not have space to store a copy of the message in their sent folder
  * MSG_TITLE_EMPTY:				    The 'msgTitle' variable is empty
  * MSG_CONTENT_EMPTY:			    The 'msgContent' varable is empty
  * CANT_SEND_TO_SELF:				The main recipient and sender are the same
  * CANT_INVITE_SELF:				The sender is in the invite list
  * CANT_INVITE_RECIPIENT:			The main recipient is in the invite list
  * FLOOD_STOP						Flood control will not allow this message to send
  * </code>
  */
 public function sendNewPersonalTopic($toMemberID, $fromMemberID, $inviteUsers, $msgTitle, $msgContent, $options = array())
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $toMemberData = array();
     $fromMemberData = array();
     $inviteUsersData = array();
     $isDraft = $options['isDraft'] ? TRUE : FALSE;
     $isCopyTo = $options['sendMode'] == 'copy' ? TRUE : FALSE;
     $isSystem = $options['isSystem'] === TRUE || $options['isSystem'] == 1 ? 1 : 0;
     $options['postKey'] = $options['postKey'] ? $options['postKey'] : md5(microtime());
     /* Set up force message*/
     $this->forceMessageToSend = $this->forceMessageToSend ? $this->forceMessageToSend : ($options['forcePm'] ? TRUE : FALSE);
     //-----------------------------------------
     // Check content
     //-----------------------------------------
     if ($toMemberID == $fromMemberID) {
         throw new Exception('CANT_SEND_TO_SELF');
     }
     if (!$msgTitle) {
         throw new Exception('MSG_TITLE_EMPTY');
     }
     if (!$msgContent) {
         throw new Exception('MSG_CONTENT_EMPTY');
     }
     //-----------------------------------------
     // Format content
     //-----------------------------------------
     try {
         $_originalMessageContent = $msgContent;
         $msgContent = $this->_formatMessageForSaving($msgContent);
     } catch (Exception $error) {
         throw new Exception($error->getMessage());
     }
     //-----------------------------------------
     // First off, load the to and from members
     //-----------------------------------------
     $_members = IPSMember::load(array($toMemberID, $fromMemberID), 'groups,extendedProfile');
     $toMemberData = $this->_setMaxMessages($_members[$toMemberID]);
     $fromMemberData = $this->_setMaxMessages($_members[$fromMemberID]);
     if (!$toMemberData['member_id'] and $this->forceMessageToSend !== TRUE) {
         throw new Exception('TO_USER_DOES_NOT_EXIST');
     }
     if (!$fromMemberData['member_id'] and $this->forceMessageToSend !== TRUE) {
         throw new Exception('FROM_USER_DOES_NOT_EXIST');
     }
     if ($this->floodControlCheck() !== TRUE and $this->forceMessageToSend !== TRUE) {
         throw new Exception('FLOOD_STOP');
     }
     //-----------------------------------------
     // Sort out invite users
     //-----------------------------------------
     if (is_array($inviteUsers) and count($inviteUsers)) {
         try {
             if ($fromMemberData['g_max_mass_pm'] > 0 or $this->forceMessageToSend === TRUE) {
                 $inviteUsersData = $this->checkAndReturnInvitedUsers($inviteUsers);
             }
         } catch (Exception $error) {
             if ($this->forceMessageToSend !== TRUE) {
                 throw new Exception($error->getMessage());
             }
         }
         if (isset($inviteUsersData[$fromMemberID])) {
             throw new Exception('CANT_INVITE_SELF');
         }
         if (isset($inviteUsersData[$toMemberID])) {
             throw new Exception('CANT_INVITE_RECIPIENT');
         }
     }
     //-----------------------------------------
     // Can the 'to' user accept a PM?
     //-----------------------------------------
     if ($this->canUsePMSystem($toMemberData) !== TRUE) {
         if ($this->forceMessageToSend !== TRUE) {
             throw new Exception('TO_USER_CANNOT_USE_PM');
         }
     }
     //-----------------------------------------
     // Does the 'to' user have enough space?
     //-----------------------------------------
     if ($this->withinPMQuota($toMemberData) !== TRUE) {
         if ($this->forceMessageToSend !== TRUE) {
             throw new Exception('TO_USER_FULL');
         }
     }
     //-----------------------------------------
     // Has the 'to' use blocked us?
     //-----------------------------------------
     if (count($this->blockedByUser($fromMemberData, $toMemberData))) {
         if ($this->forceMessageToSend !== TRUE) {
             throw new Exception('FROM_USER_BLOCKED');
         }
     }
     //-----------------------------------------
     // Is this simply a copy-to?
     //-----------------------------------------
     if ($isCopyTo === TRUE) {
         /* Send out the main one */
         $this->sendNewPersonalTopic($toMemberID, $fromMemberID, array(), $msgTitle, $_originalMessageContent, array());
         /* Send out copy-tos */
         foreach ($inviteUsersData as $id => $toMember) {
             $this->sendNewPersonalTopic($toMember['member_id'], $fromMemberID, array(), $msgTitle, $_originalMessageContent, array());
         }
         /* Done */
         return TRUE;
     }
     //-----------------------------------------
     // Insert the user data
     //-----------------------------------------
     $_count = count($inviteUsersData);
     //-----------------------------------------
     // Got a topic ID?
     //-----------------------------------------
     if ($options['topicID']) {
         /* Fetch topic data */
         $_topicData = $this->fetchTopicData($options['topicID']);
         if (!$_topicData['mt_id'] and $this->forceMessageToSend !== TRUE) {
             throw new Exception('TOPIC_ID_NOT_EXISTS');
         }
         $this->DB->force_data_type = array('mt_title' => 'string');
         /* First off, update message_topics and message_posts... */
         $this->DB->update('message_topics', array('mt_date' => time(), 'mt_title' => $msgTitle, 'mt_starter_id' => $fromMemberData['member_id'], 'mt_start_time' => time(), 'mt_last_post_time' => time(), 'mt_invited_members' => serialize(array_keys($inviteUsersData)), 'mt_to_count' => count(array_keys($inviteUsersData)) + 1, 'mt_to_member_id' => $toMemberData['member_id'], 'mt_is_draft' => $isDraft), 'mt_id=' . $_topicData['mt_id']);
         /* Now the posts ... */
         $this->DB->update('message_posts', array('msg_date' => time(), 'msg_topic_id' => $_topicData['mt_id'], 'msg_post' => IPSText::removeMacrosFromInput($msgContent), 'msg_author_id' => $fromMemberData['member_id'], 'msg_is_first_post' => 1, 'msg_ip_address' => $this->member->ip_address), 'msg_id=' . $_topicData['mt_first_msg_id']);
         /* Delete any current user mapping as this will be sorted out below */
         $this->DB->delete('message_topic_user_map', 'map_topic_id=' . $_topicData['mt_id']);
         /* Reset variable IDs */
         $msg_topic_id = $_topicData['mt_id'];
         $msg_id = $_topicData['mt_first_msg_id'];
         IPSMember::save($toMemberData['member_id'], array('core' => array('msg_count_new' => 'plus:1')));
     } else {
         /* Create topic entry */
         $this->DB->force_data_type = array('mt_title' => 'string');
         $this->DB->insert('message_topics', array('mt_date' => time(), 'mt_title' => $msgTitle, 'mt_starter_id' => $fromMemberData['member_id'], 'mt_start_time' => time(), 'mt_last_post_time' => time(), 'mt_invited_members' => serialize(array_keys($inviteUsersData)), 'mt_to_count' => count(array_keys($inviteUsersData)) + 1, 'mt_to_member_id' => $toMemberData['member_id'], 'mt_is_draft' => $isDraft ? 1 : 0, 'mt_is_system' => $isSystem, 'mt_replies' => 0));
         $msg_topic_id = $this->DB->getInsertId();
         $this->DB->insert('message_posts', array('msg_date' => time(), 'msg_topic_id' => $msg_topic_id, 'msg_post' => IPSText::removeMacrosFromInput($msgContent), 'msg_post_key' => $options['postKey'], 'msg_author_id' => $fromMemberData['member_id'], 'msg_is_first_post' => 1, 'msg_ip_address' => $this->member->ip_address));
         $msg_id = $this->DB->getInsertId();
         IPSMember::save($toMemberData['member_id'], array('core' => array('msg_count_new' => 'plus:1')));
     }
     //-----------------------------------------
     // Update with last / first msg ID
     //-----------------------------------------
     $this->DB->update('message_topics', array('mt_last_msg_id' => $msg_id, 'mt_first_msg_id' => $msg_id, 'mt_hasattach' => intval($this->_makeAttachmentsPermanent($options['postKey'], $msg_id, $msg_topic_id))), 'mt_id=' . $msg_topic_id);
     //-----------------------------------------
     // Not a draft?
     //-----------------------------------------
     if ($isDraft !== TRUE) {
         //-----------------------------------------
         // Add in 'to user' and 'from user' to the cc array
         //-----------------------------------------
         $inviteUsersData[$toMemberData['member_id']] = $toMemberData;
         $inviteUsersData[$fromMemberData['member_id']] = $fromMemberData;
         //-----------------------------------------
         // Loop....
         //-----------------------------------------
         foreach ($inviteUsersData as $id => $toMember) {
             //-----------------------------------------
             // Enter the info into the DB
             // Target user side.
             //-----------------------------------------
             $_isStarter = $fromMemberData['member_id'] == $toMember['member_id'] ? 1 : 0;
             $_isSystem = ($fromMemberData['member_id'] == $toMember['member_id'] and $isSystem) ? 1 : 0;
             $_isActive = $_isSystem ? 0 : 1;
             /* Create user map entry */
             $this->DB->insert('message_topic_user_map', array('map_user_id' => $toMember['member_id'], 'map_topic_id' => $msg_topic_id, 'map_folder_id' => 'myconvo', 'map_user_active' => $_isActive, 'map_is_starter' => $fromMemberData['member_id'] == $toMember['member_id'] ? 1 : 0, 'map_has_unread' => $fromMemberData['member_id'] == $toMember['member_id'] ? 0 : 1, 'map_read_time' => $fromMemberData['member_id'] == $toMember['member_id'] ? time() : 0, 'map_is_system' => $_isSystem));
             //-----------------------------------------
             // Update profile
             //-----------------------------------------
             if ($fromMemberData['member_id'] != $toMember['member_id']) {
                 IPSMember::save($toMember['member_id'], array('core' => array('msg_count_total' => 'plus:1', 'msg_show_notification' => $toMember['view_pop'], 'msg_count_reset' => 1)));
             } else {
                 IPSMember::save($fromMemberData['member_id'], array('core' => array('msg_count_total' => 'plus:1', 'msg_count_reset' => 1)));
             }
             //-----------------------------------------
             // Has this member requested a PM email nofity?
             //-----------------------------------------
             if ($toMember['email_pm'] == 1 and $fromMemberData['member_id'] != $toMember['member_id']) {
                 $toMember['language'] = $toMember['language'] == "" ? IPSLib::getDefaultLanguage() : $toMember['language'];
                 IPSText::getTextClass('email')->getTemplate("personal_convo_new_convo", $toMember['language']);
                 IPSText::getTextClass('email')->buildMessage(array('NAME' => $toMember['members_display_name'], 'POSTER' => $fromMemberData['members_display_name'], 'TITLE' => $msgTitle, 'TEXT' => IPSText::removeMacrosFromInput($msgContent), 'LINK' => "?app=members&module=messaging&section=view&do=showConversation&topicID={$msg_topic_id}#msg{$msg_id}"));
                 $this->DB->insert('mail_queue', array('mail_to' => $toMember['email'], 'mail_from' => '', 'mail_date' => time(), 'mail_subject' => IPSText::getTextClass('email')->subject, 'mail_content' => IPSText::getTextClass('email')->message));
                 $cache = $this->cache->getCache('systemvars');
                 $cache['mail_queue'] += 1;
                 $this->cache->setCache('systemvars', $cache, array('array' => 1, 'donow' => 1, 'deletefirst' => 0));
             }
         }
     } else {
         //-----------------------------------------
         // Is a draft
         //-----------------------------------------
         /* Create user map entry */
         $this->DB->insert('message_topic_user_map', array('map_user_id' => $fromMemberData['member_id'], 'map_topic_id' => $msg_topic_id, 'map_folder_id' => 'drafts', 'map_user_active' => 1, 'map_has_unread' => 0, 'map_read_time' => 0));
         if (!$options['topicID']) {
             //-----------------------------------------
             // Update profile
             //-----------------------------------------
             $this->rebuildFolderCount($fromMemberData['member_id'], array('drafts' => 'plus:1'), TRUE, array('core' => array('msg_count_total' => 'plus:1')));
         }
     }
     return TRUE;
 }
Exemplo n.º 9
0
 /**
  * Create new member
  * Very basic functionality at this point.
  *
  * @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]'
  * @param	bool	Flag to attempt to auto create a name if the desired is taken
  * @param	bool	Bypass custom field saving (if using the sso session integration this is required as member object isn't ready yet)
  * @param	bool	Whether or not to recache the stats so as to update the board's last member data
  * @return	array 	Final member Data including member_id
  *
  * EXCEPTION CODES
  * CUSTOM_FIELDS_EMPTY    - Custom fields were not populated
  * CUSTOM_FIELDS_INVALID  - Custom fields were invalid
  * CUSTOM_FIELDS_TOOBIG   - Custom fields too big
  */
 public static function create($tables = array(), $autoCreateName = FALSE, $bypassCfields = FALSE, $doStatsRecache = TRUE)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $finalTables = array();
     $password = '';
     $plainPassword = '';
     $bitWiseFields = ipsRegistry::fetchBitWiseOptions('global');
     $md_5_password = '';
     //-----------------------------------------
     // Remap tables if required
     //-----------------------------------------
     foreach ($tables as $table => $data) {
         $_name = isset(self::$remap[$table]) ? self::$remap[$table] : $table;
         if ($_name == 'members') {
             /* Magic password field */
             if (!empty($data['md5_hash_password'])) {
                 $md_5_password = trim($data['md5_hash_password']);
                 $plainPassword = null;
                 unset($data['md5_hash_password']);
             } else {
                 $password = isset($data['password']) ? trim($data['password']) : self::makePassword();
                 $plainPassword = $password;
                 $md_5_password = md5($password);
                 unset($data['password']);
             }
         }
         $finalTables[$_name] = $data;
     }
     //-----------------------------------------
     // Custom profile field stuff
     //-----------------------------------------
     if (!$bypassCfields) {
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
         $fields = new $classToLoad();
         if (is_array($finalTables['pfields_content']) and count($finalTables['pfields_content'])) {
             $fields->member_data = $finalTables['pfields_content'];
         }
         $fields->initData('edit');
         $fields->parseToSave($finalTables['pfields_content'], 'register');
         /* Check */
         /*if( count( $fields->error_fields['empty'] ) )
         		{
         			throw new Exception( 'CUSTOM_FIELDS_EMPTY' );
         		}
         		
         		if( count( $fields->error_fields['invalid'] ) )
         		{
         			throw new Exception( 'CUSTOM_FIELDS_INVALID' );
         		}
         		
         		if( count( $fields->error_fields['toobig'] ) )
         		{
         			throw new Exception( 'CUSTOM_FIELDS_TOOBIG' );
         		}*/
     }
     //-----------------------------------------
     // Make sure the account doesn't exist
     //-----------------------------------------
     if ($finalTables['members']['email']) {
         if (IPSText::mbstrlen($finalTables['members']['email']) > 150 or strstr($finalTables['members']['email'], ' ')) {
             /* Allow it to be auto created */
             $finalTables['members']['email'] = false;
         } else {
             $existing = IPSMember::load($finalTables['members']['email'], 'all');
             if ($existing['member_id']) {
                 $existing['full'] = true;
                 $existing['timenow'] = time();
                 return $existing;
             }
         }
     }
     //-----------------------------------------
     // Fix up usernames and display names
     //-----------------------------------------
     /* Ensure we have a display name */
     if ($autoCreateName and $finalTables['members']['members_display_name'] !== FALSE) {
         $finalTables['members']['members_display_name'] = $finalTables['members']['members_display_name'] ? $finalTables['members']['members_display_name'] : $finalTables['members']['name'];
     }
     //-----------------------------------------
     // Remove some basic HTML tags
     //-----------------------------------------
     if ($finalTables['members']['members_display_name']) {
         if (IPSText::mbstrlen($finalTables['members']['members_display_name']) > 255) {
             $finalTables['members']['members_display_name'] = false;
         }
         $finalTables['members']['members_display_name'] = str_replace(array('<', '>', '"'), '', $finalTables['members']['members_display_name']);
     }
     if ($finalTables['members']['name']) {
         if (IPSText::mbstrlen($finalTables['members']['name']) > 255) {
             $finalTables['members']['name'] = false;
         }
         $finalTables['members']['name'] = str_replace(array('<', '>', '"'), '', $finalTables['members']['name']);
     }
     //-----------------------------------------
     // Make sure the names are unique
     //-----------------------------------------
     /* Can specify display name of FALSE to force no entry to force partial member */
     if ($finalTables['members']['members_display_name'] !== FALSE) {
         try {
             if (IPSMember::getFunction()->checkNameExists($finalTables['members']['members_display_name'], array(), 'members_display_name', true) === true) {
                 if ($autoCreateName === TRUE) {
                     /* Now, make sure we have a unique display name */
                     $max = ipsRegistry::DB()->buildAndFetch(array('select' => 'MAX(member_id) as max', 'from' => 'members', 'where' => "members_l_display_name LIKE '" . ipsRegistry::DB()->addSlashes(strtolower($finalTables['members']['members_display_name'])) . "%'"));
                     if ($max['max']) {
                         $_num = $max['max'] + 1;
                         $finalTables['members']['members_display_name'] = $finalTables['members']['members_display_name'] . '_' . $_num;
                     }
                 } else {
                     $finalTables['members']['members_display_name'] = '';
                 }
             }
         } catch (Exception $e) {
         }
     }
     if ($finalTables['members']['name']) {
         try {
             if (IPSMember::getFunction()->checkNameExists($finalTables['members']['name'], array(), 'name', true) === true) {
                 if ($autoCreateName === TRUE) {
                     /* Now, make sure we have a unique username */
                     $max = ipsRegistry::DB()->buildAndFetch(array('select' => 'MAX(member_id) as max', 'from' => 'members', 'where' => "members_l_username LIKE '" . ipsRegistry::DB()->addSlashes(strtolower($finalTables['members']['name'])) . "%'"));
                     if ($max['max']) {
                         $_num = $max['max'] + 1;
                         $finalTables['members']['name'] = $finalTables['members']['name'] . '_' . $_num;
                     }
                 } else {
                     $finalTables['members']['name'] = '';
                 }
             }
         } catch (Exception $e) {
         }
     }
     //-----------------------------------------
     // Clean up characters
     //-----------------------------------------
     if ($finalTables['members']['name']) {
         $userName = IPSMember::getFunction()->cleanAndCheckName($finalTables['members']['name'], array(), 'name');
         if ($userName['errors']) {
             $finalTables['members']['name'] = $finalTables['members']['email'];
         } else {
             $finalTables['members']['name'] = $userName['username'];
         }
     }
     if ($finalTables['members']['members_display_name']) {
         $displayName = IPSMember::getFunction()->cleanAndCheckName($finalTables['members']['members_display_name']);
         if ($displayName['errors']) {
             $finalTables['members']['members_display_name'] = '';
         } else {
             $finalTables['members']['members_display_name'] = $displayName['members_display_name'];
         }
     }
     //-----------------------------------------
     // Populate member table(s)
     //-----------------------------------------
     $finalTables['members']['members_l_username'] = isset($finalTables['members']['name']) ? strtolower($finalTables['members']['name']) : '';
     $finalTables['members']['joined'] = $finalTables['members']['joined'] ? $finalTables['members']['joined'] : time();
     $finalTables['members']['email'] = $finalTables['members']['email'] ? $finalTables['members']['email'] : $finalTables['members']['name'] . '@' . $finalTables['members']['joined'];
     $finalTables['members']['member_group_id'] = $finalTables['members']['member_group_id'] ? $finalTables['members']['member_group_id'] : ipsRegistry::$settings['member_group'];
     $finalTables['members']['ip_address'] = $finalTables['members']['ip_address'] ? $finalTables['members']['ip_address'] : ipsRegistry::member()->ip_address;
     $finalTables['members']['members_created_remote'] = intval($finalTables['members']['members_created_remote']);
     $finalTables['members']['member_login_key'] = IPSMember::generateAutoLoginKey();
     $finalTables['members']['member_login_key_expire'] = ipsRegistry::$settings['login_key_expire'] ? time() + intval(ipsRegistry::$settings['login_key_expire']) * 86400 : 0;
     $finalTables['members']['view_sigs'] = 1;
     $finalTables['members']['bday_day'] = intval($finalTables['members']['bday_day']);
     $finalTables['members']['bday_month'] = intval($finalTables['members']['bday_month']);
     $finalTables['members']['bday_year'] = intval($finalTables['members']['bday_year']);
     $finalTables['members']['restrict_post'] = intval($finalTables['members']['restrict_post']);
     $finalTables['members']['auto_track'] = $finalTables['members']['auto_track'] ? $finalTables['members']['auto_track'] : ipsRegistry::$settings['auto_track_method'];
     $finalTables['members']['msg_count_total'] = 0;
     $finalTables['members']['msg_count_new'] = 0;
     $finalTables['members']['msg_show_notification'] = 1;
     $finalTables['members']['coppa_user'] = 0;
     $finalTables['members']['auto_track'] = substr($finalTables['members']['auto_track'], 0, 50);
     $finalTables['members']['last_visit'] = $finalTables['members']['last_visit'] ? $finalTables['members']['last_visit'] : time();
     $finalTables['members']['last_activity'] = $finalTables['members']['last_activity'] ? $finalTables['members']['last_activity'] : time();
     $finalTables['members']['language'] = $finalTables['members']['language'] ? $finalTables['members']['language'] : IPSLib::getDefaultLanguage();
     $finalTables['members']['member_uploader'] = ipsRegistry::$settings['uploadFormType'] ? 'flash' : 'default';
     $finalTables['members']['members_pass_salt'] = IPSMember::generatePasswordSalt(5);
     $finalTables['members']['members_pass_hash'] = IPSMember::generateCompiledPasshash($finalTables['members']['members_pass_salt'], $md_5_password);
     $finalTables['members']['members_display_name'] = isset($finalTables['members']['members_display_name']) ? $finalTables['members']['members_display_name'] : '';
     $finalTables['members']['members_l_display_name'] = isset($finalTables['members']['members_display_name']) ? strtolower($finalTables['members']['members_display_name']) : '';
     $finalTables['members']['fb_uid'] = isset($finalTables['members']['fb_uid']) ? $finalTables['members']['fb_uid'] : 0;
     $finalTables['members']['fb_emailhash'] = isset($finalTables['members']['fb_emailhash']) ? strtolower($finalTables['members']['fb_emailhash']) : '';
     $finalTables['members']['members_seo_name'] = IPSText::makeSeoTitle($finalTables['members']['members_display_name']);
     $finalTables['members']['bw_is_spammer'] = intval($finalTables['members']['bw_is_spammer']);
     //-----------------------------------------
     // Insert: MEMBERS
     //-----------------------------------------
     ipsRegistry::DB()->setDataType(array('name', 'members_l_username', 'members_display_name', 'members_l_display_name', 'members_seo_name', 'email'), 'string');
     /* Bitwise options */
     if (is_array($bitWiseFields['members'])) {
         $_freeze = array();
         foreach ($bitWiseFields['members'] as $field) {
             if (isset($finalTables['members'][$field])) {
                 /* Add to freezeable array */
                 $_freeze[$field] = $finalTables['members'][$field];
                 /* Remove it from the fields to save to DB */
                 unset($finalTables['members'][$field]);
             }
         }
         if (count($_freeze)) {
             $finalTables['members']['members_bitoptions'] = IPSBWOptions::freeze($_freeze, 'members', 'global');
         }
     }
     ipsRegistry::DB()->insert('members', $finalTables['members']);
     //-----------------------------------------
     // Get the member id
     //-----------------------------------------
     $finalTables['members']['member_id'] = ipsRegistry::DB()->getInsertId();
     //-----------------------------------------
     // Insert: PROFILE PORTAL
     //-----------------------------------------
     $finalTables['profile_portal']['pp_member_id'] = $finalTables['members']['member_id'];
     $finalTables['profile_portal']['pp_setting_count_friends'] = 1;
     $finalTables['profile_portal']['pp_setting_count_comments'] = 1;
     $finalTables['profile_portal']['pp_setting_count_visitors'] = 1;
     $finalTables['profile_portal']['pp_customization'] = serialize(array());
     foreach (array('pp_last_visitors', 'pp_about_me', 'signature', 'fb_photo', 'fb_photo_thumb', 'pconversation_filters') as $f) {
         $finalTables['profile_portal'][$f] = $finalTables['profile_portal'][$f] ? $finalTables['profile_portal'][$f] : '';
     }
     ipsRegistry::DB()->insert('profile_portal', $finalTables['profile_portal']);
     //-----------------------------------------
     // Insert into the custom profile fields DB
     //-----------------------------------------
     if (!$bypassCfields) {
         /* Check the website url field */
         $website_field = $fields->getFieldIDByKey('website');
         if ($website_field && $fields->out_fields['field_' . $website_field]) {
             if (stristr($fields->out_fields['field_' . $website_field], 'http://') === FALSE && stristr($fields->out_fields['field_' . $website_field], 'https://') === FALSE) {
                 $fields->out_fields['field_' . $website_field] = 'http://' . $fields->out_fields['field_' . $website_field];
             }
         }
         $fields->out_fields['member_id'] = $finalTables['members']['member_id'];
         ipsRegistry::DB()->delete('pfields_content', 'member_id=' . $finalTables['members']['member_id']);
         ipsRegistry::DB()->insert('pfields_content', $fields->out_fields);
     } else {
         ipsRegistry::DB()->delete('pfields_content', 'member_id=' . $finalTables['members']['member_id']);
         ipsRegistry::DB()->insert('pfields_content', array('member_id' => $finalTables['members']['member_id']));
     }
     //-----------------------------------------
     // Insert into partial ID table
     //-----------------------------------------
     $full_account = false;
     if ($finalTables['members']['members_display_name'] and $finalTables['members']['name'] and $finalTables['members']['email'] and $finalTables['members']['email'] != $finalTables['members']['name'] . '@' . $finalTables['members']['joined']) {
         $full_account = true;
     }
     if (!$full_account) {
         ipsRegistry::DB()->insert('members_partial', array('partial_member_id' => $finalTables['members']['member_id'], 'partial_date' => $finalTables['members']['joined'], 'partial_email_ok' => $finalTables['members']['email'] == $finalTables['members']['name'] . '@' . $finalTables['members']['joined'] ? 0 : 1));
     }
     /* Add plain password and run sync */
     $finalTables['members']['plainPassword'] = $plainPassword;
     IPSLib::runMemberSync('onCreateAccount', $finalTables['members']);
     /* Remove plain password */
     unset($finalTables['members']['plainPassword']);
     //-----------------------------------------
     // Recache our stats (Ticket 627608)
     //-----------------------------------------
     if ($doStatsRecache == TRUE) {
         ipsRegistry::cache()->rebuildCache('stats', 'global');
     }
     return array_merge($finalTables['members'], $finalTables['profile_portal'], !$bypassCfields ? $fields->out_fields : array(), array('timenow' => $finalTables['members']['joined'], 'full' => $full_account));
 }
 /**
  * Adds a rating to the index and updates caches
  *
  * @access	public
  * @param	string		$type		Type of content, ex; Post
  * @param	integer		$type_id	ID of the type, ex: pid
  * @param	integer		$rating		Either 1 or -1
  * @param	string		$message	Message associated with this rating
  * @param	integer		$member_id	Id of the owner of the content being rated
  * @param	string		[$app]		App for this content, by default the current application
  * @todo 	[Future] Move forum notifications to an onRep memberSync callback
  * @return	bool
  */
 public function addRate($type, $type_id, $rating, $message = '', $member_id = 0, $app = '')
 {
     $this->registry->getClass('class_localization')->loadLanguageFile(array('public_global'), 'core');
     /* Online? */
     if (!$this->rep_system_on) {
         $this->error_message = $this->lang->words['reputation_offline'];
         return false;
     }
     /* INIT */
     $app = $app ? $app : ipsRegistry::$current_application;
     $rating = intval($rating);
     if (!$this->memberData['member_id']) {
         $this->error_message = $this->lang->words['reputation_guest'];
         return false;
     }
     if ($rating != -1 && $rating != 1) {
         $this->error_message = $this->lang->words['reputation_invalid'];
         return false;
     }
     /* Does the rep item exist? */
     if (!$this->likeItemExists($app, $type, $type_id)) {
         /* See ticket #845557 - item may not exist when not in LIKE mode. Need to add functionalty so each app can return boolean if item exists in native tables */
         //$this->error_message = $this->lang->words['reputation_invalid'];
         //return false;
     }
     /* Check for existing rating */
     $currentRating = $this->getCurrentMemberRating(array('app' => $app, 'type' => $type, 'id' => $type_id, 'memberId' => $this->memberData['member_id']));
     /* Check the point types */
     if ($rating == -1 && IPSMember::canRepDown($currentRating, $this->memberData) === false) {
         $this->error_message = $this->lang->words['reputation_invalid'];
         return false;
     }
     if ($rating == 1 && IPSMember::canRepUp($currentRating, $this->memberData) === false) {
         $this->error_message = $this->lang->words['reputation_invalid'];
         return false;
     }
     /* Day Cutoff */
     $day_cutoff = time() - 86400;
     /* Check Max Positive Votes */
     if ($rating == 1) {
         if (intval($this->memberData['g_rep_max_positive']) === 0) {
             $this->error_message = $this->lang->words['reputation_quota_pos'];
             return false;
         }
         $total = $this->DB->buildAndFetch(array('select' => 'count(*) as votes', 'from' => 'reputation_index', 'where' => 'member_id=' . $this->memberData['member_id'] . ' AND rep_rating=1 AND rep_date > ' . $day_cutoff));
         if ($total['votes'] >= $this->memberData['g_rep_max_positive']) {
             $this->error_message = $this->lang->words['reputation_quota_pos'];
             return false;
         }
     }
     /* Check Max Negative Votes if not like mode */
     if ($rating == -1 and !$this->isLikeMode()) {
         if (intval($this->memberData['g_rep_max_negative']) === 0) {
             $this->error_message = $this->lang->words['reputation_quota_neg'];
             return false;
         }
         $total = $this->DB->buildAndFetch(array('select' => 'count(*) as votes', 'from' => 'reputation_index', 'where' => 'member_id=' . $this->memberData['member_id'] . ' AND rep_rating=-1 AND rep_date > ' . $day_cutoff));
         if ($total['votes'] >= $this->memberData['g_rep_max_negative']) {
             $this->error_message = $this->lang->words['reputation_quota_neg'];
             return false;
         }
     }
     /* If no member id was passed in, we have to query it using the config file */
     if (!$member_id) {
         /* Reputation Config */
         if (is_file(IPSLib::getAppDir($app) . '/extensions/reputation.php')) {
             $rep_author_config = array();
             require IPSLib::getAppDir($app) . '/extensions/reputation.php';
             /*maybeLibHook*/
         } else {
             $this->error_message = $this->lang->words['reputation_config'];
             return false;
         }
         if (!$rep_author_config[$type]['column'] || !$rep_author_config[$type]['table']) {
             $this->error_message = $this->lang->words['reputation_config'];
             return false;
         }
         $_col = $rep_author_config[$type]['id_field'] ? $rep_author_config[$type]['id_field'] : $type;
         /* Query the content author */
         $content_author = $this->DB->buildAndFetch(array('select' => "{$rep_author_config[$type]['column']} as id", 'from' => $rep_author_config[$type]['table'], 'where' => "{$_col}={$type_id}"));
         $member_id = $content_author['id'];
     }
     if (!ipsRegistry::$settings['reputation_can_self_vote'] && $member_id == $this->memberData['member_id']) {
         $this->error_message = $this->lang->words['reputation_yourown'];
         return false;
     }
     /* Query the member group */
     if (ipsRegistry::$settings['reputation_protected_groups']) {
         $member_group = $this->DB->buildAndFetch(array('select' => 'member_group_id', 'from' => 'members', 'where' => "member_id={$member_id}"));
         if (in_array($member_group['member_group_id'], explode(',', ipsRegistry::$settings['reputation_protected_groups']))) {
             $this->error_message = $this->lang->words['reputation_protected'];
             return false;
         }
     }
     /* Build the insert array */
     $db_insert = array('member_id' => $this->memberData['member_id'], 'app' => $app, 'type' => $type, 'type_id' => $type_id, 'rep_date' => time(), 'rep_msg' => $message, 'rep_rating' => $rating);
     /* Insert */
     if ($currentRating) {
         if ($rating == -1 && $this->isLikeMode()) {
             $this->DB->delete('reputation_index', "app='{$app}' AND type='{$type}' AND type_id={$type_id} AND member_id=" . $this->memberData['member_id']);
         }
     } else {
         $this->DB->replace('reputation_index', $db_insert, array('app', 'type', 'type_id', 'member_id'));
     }
     /* Update cache */
     $this->updateCache($app, $type, $type_id);
     /* Get authors current rep */
     $author_points = $this->DB->buildAndFetch(array('select' => 'pp_reputation_points', 'from' => 'profile_portal', 'where' => "pp_member_id=" . intval($member_id)));
     /* Figure out new rep */
     if ($currentRating['rep_rating'] == -1) {
         $author_points['pp_reputation_points'] += 1;
     } else {
         if ($currentRating['rep_rating'] == 1) {
             $author_points['pp_reputation_points'] -= 1;
         }
     }
     /* now add on new rating if we're not like mode-ing */
     if (!$this->isLikeMode() || empty($currentRating['rep_rating']) && $this->isLikeMode()) {
         $author_points['pp_reputation_points'] += $rating;
     }
     $this->DB->update('profile_portal', array('pp_reputation_points' => $author_points['pp_reputation_points']), "pp_member_id={$member_id}");
     /* Notification */
     if ($rating == 1 && $this->isLikeMode() && $app == 'forums' && $type == 'pid') {
         /* Check for class_forums */
         if (!$this->registry->isClassLoaded('class_forums')) {
             $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('forums') . "/sources/classes/forums/class_forums.php", 'class_forums', 'forums');
             $this->registry->setClass('class_forums', new $classToLoad($this->registry));
             $this->registry->strip_invisible = 0;
             $this->registry->class_forums->forumsInit();
         }
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications');
         $notifyLibrary = new $classToLoad($this->registry);
         if (!$this->registry->isClassLoaded('topics')) {
             $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('forums') . "/sources/classes/topics.php", 'app_forums_classes_topics', 'forums');
             $this->registry->setClass('topics', new $classToLoad($this->registry));
         }
         $post = $this->registry->getClass('topics')->getPostById($type_id);
         /* Set topic data */
         $this->registry->getClass('topics')->setTopicData($post);
         /* Quick check */
         if (!$post['author_id'] or $post['author_id'] == $this->memberData['member_id']) {
             return true;
         }
         $_toMember = IPSMember::load($post['author_id']);
         /* Set language */
         $_toMember['language'] = $_toMember['language'] == "" ? IPSLib::getDefaultLanguage() : $_toMember['language'];
         /* Quick permission check */
         if ($this->registry->getClass('topics')->canView() !== true) {
             return true;
         }
         $url = $this->registry->output->buildSEOUrl("showtopic={$post['topic_id']}&amp;view=findpost&amp;p={$post['pid']}", "publicNoSession", $post['title_seo'], 'showtopic');
         IPSText::getTextClass('email')->getTemplate("new_likes", $_toMember['language']);
         IPSText::getTextClass('email')->buildMessage(array('MEMBER_NAME' => $this->memberData['members_display_name'], 'SHORT_POST' => IPSText::truncate(IPSText::getTextClass('bbcode')->stripAllTags($post['post']), 300), 'URL' => $url));
         IPSText::getTextClass('email')->subject = sprintf(IPSText::getTextClass('email')->subject, $this->registry->output->buildSEOUrl('showuser='******'member_id'], 'publicNoSession', $this->memberData['members_seo_name'], 'showuser'), $this->memberData['members_display_name'], $url, $this->registry->output->buildSEOUrl("showtopic={$post['topic_id']}", "publicNoSession", $post['title_seo'], 'showtopic'), IPSText::truncate($post['topic_title'], 30));
         $notifyLibrary->setMember($_toMember);
         $notifyLibrary->setFrom($this->memberData);
         $notifyLibrary->setNotificationKey('new_likes');
         $notifyLibrary->setNotificationUrl($url);
         $notifyLibrary->setNotificationText(IPSText::getTextClass('email')->message);
         $notifyLibrary->setNotificationTitle(IPSText::getTextClass('email')->subject);
         try {
             $notifyLibrary->sendNotification();
         } catch (Exception $e) {
         }
     }
     return true;
 }
Exemplo n.º 11
0
 /**
  * Set email subject
  *
  * @param	array		$data			Subject data
  * @param	string		$language		Language to use
  * @param	string		$lang_file		Language file to load
  * @param	string		$app			Application of language file
  * @return	@e void
  */
 public function setEmailSubject($data, $language = '', $lang_file = 'public_email_content', $app = 'core')
 {
     if (!is_array($data) or !$data['key']) {
         return;
     }
     /* This is a bit hacky. Sorry */
     $tmp = $this->lang->words;
     if (!$language) {
         $language = IPSLib::getDefaultLanguage();
     }
     $this->registry->class_localization->loadLanguageFile(array($lang_file), $app, $language, TRUE);
     //-----------------------------------------
     // Stored KEY?
     //-----------------------------------------
     if (!isset($this->lang->words[$data['key']])) {
         if ($language != IPSLib::getDefaultLanguage()) {
             $this->registry->class_localization->loadLanguageFile(array($lang_file), $app, IPSLib::getDefaultLanguage(), TRUE);
         }
     }
     if (is_array($data['params'])) {
         foreach ($data['params'] as $p) {
             /* Each iteration should replace one %s */
             $this->_emailTitle = sprintf($this->lang->words[$data['key']], $p);
         }
     }
     /* Yeah */
     $this->lang->words = $tmp;
 }
Exemplo n.º 12
0
 /**
  * Legacy, generic method: builds an email from a template, replacing variables
  *
  * @deprecated
  * @param	array		Replacement keys to values
  * @param	bool		Do not "clean"
  * @param	bool		Raw HTML
  * @param	array		Member data - necessary if including unsubscribe link
  * @return	@e void
  */
 public function buildMessage($words, $noClean = false, $rawHtml = FALSE, $memberData = array())
 {
     /* Init */
     $ptWords = array();
     $htmlWords = array();
     $subjWords = array();
     /* Try this first */
     if (!$this->plainTextTemplate && !$this->htmlTemplate && $this->message) {
         $this->setPlainTextTemplate($this->message, true);
     }
     /* need to converge some stuff here */
     if (!$this->plainTextTemplate && $this->template) {
         /* Sniff, sniff */
         if (stristr($this->template, '<br')) {
             if (!$this->htmlTemplate) {
                 $this->setHtmlTemplate($this->template);
             }
             $this->setPlainTextTemplate(IPSText::br2nl($this->template));
         } else {
             if (!$this->htmlTemplate) {
                 $this->setHtmlTemplate(nl2br($this->template));
             }
             $this->setPlainTextTemplate($this->template);
         }
     }
     /* HTML enabled but no specific template: Auto convert */
     if ($this->html_email && !$this->htmlTemplate) {
         /* It will be dynamically updated at the end */
         $this->setHtmlTemplate($this->plainTextTemplate);
     }
     /* HTML email with HTML template but no plain text version */
     if ($this->htmlTemplate && !$this->plainTextTemplate) {
         $msg = $this->htmlTemplate;
         $msg = preg_replace('/<#(.+?)#>/', '{{{-\\1-}}}', $msg);
         $msg = str_replace("<br />", "\n", $msg);
         $msg = str_replace("<br>", "\n", $msg);
         $msg = IPSText::stripTags($msg);
         $msg = html_entity_decode($msg, ENT_QUOTES);
         $msg = str_replace('&#092;', '\\', $msg);
         $msg = str_replace('&#036;', '$', $msg);
         $msg = preg_replace('/\\{\\{\\{(.+?)\\}\\}\\}/', '<#\\1#>', $msg);
         $this->setPlainTextTemplate($msg);
     }
     if ($this->plainTextTemplate && !$this->template && ($this->html_email && !$this->htmlTemplate)) {
         $this->error++;
         $this->fatalError("Could not build the email message, no template assigned", "Make sure a template is assigned first.");
     }
     /* Bit more clean up */
     $this->plainTextTemplate = str_replace(array("\r\n", "\r", "\n"), "\n", $this->plainTextTemplate);
     $this->htmlTemplate = str_replace(array("\r\n", "\r", "\n"), "\n", $this->htmlTemplate);
     /* Apply HTML wrapper */
     $this->htmlTemplate = $this->applyHtmlWrapper($this->subject, $rawHtml ? $this->htmlTemplate : $this->convertTextEmailToHtmlEmail($this->htmlTemplate, $rawHtml));
     /* Add unsubscribe link */
     if ($this->unsubscribe and !empty($memberData)) {
         $this->registry->class_localization->loadLanguageFile(array('public_global'), 'core', $this->language ? $this->language : IPSLib::getDefaultLanguage(), TRUE);
         $key = md5($memberData['email'] . ':' . $memberData['members_pass_hash']);
         $link = $this->registry->output->buildUrl("app=core&amp;module=global&amp;section=unsubscribe&amp;member={$memberData['member_id']}&amp;key={$key}", 'publicNoSession');
         $this->plainTextTemplate = str_replace("<#UNSUBSCRIBE#>", "{$this->registry->class_localization->words['email_unsubscribe']}: {$link}", $this->plainTextTemplate);
         $this->htmlTemplate = str_replace("<#UNSUBSCRIBE#>", "<a href='{$link}'>" . $this->registry->class_localization->words['email_unsubscribe'] . '</a>', $this->htmlTemplate);
     }
     /* Add some default words */
     $words['BOARD_ADDRESS'] = $this->settings['board_url'] . '/index.' . $this->settings['php_ext'];
     $words['WEB_ADDRESS'] = $this->settings['home_url'];
     $words['BOARD_NAME'] = $this->settings['board_name'];
     $words['SIGNATURE'] = $this->settings['signature'] ? $this->settings['signature'] : '';
     /* Swap the words: 10.7.08 - Added replacements in subject */
     foreach ($words as $k => $v) {
         if (!$noClean) {
             $ptWords[$k] = $this->cleanMessage($v);
         }
         $subjWords[$k] = $this->cleanMessage($v, false, false);
         /* Convert over words too so links are linkified */
         $htmlWords[$k] = $rawHtml ? $v : $this->convertTextEmailToHtmlEmail($v, $rawHtml);
     }
     $this->_words = $ptWords;
     $this->plainTextTemplate = preg_replace_callback("/<#(.+?)#>/", array(&$this, '_swapWords'), $this->plainTextTemplate);
     $this->_words = $htmlWords;
     $this->htmlTemplate = preg_replace_callback("/<#(.+?)#>/", array(&$this, '_swapWords'), str_replace(array('&lt;#', '#&gt;'), array('<#', '#>'), $this->htmlTemplate));
     $this->_words = $subjWords;
     $this->subject = preg_replace_callback("/<#(.+?)#>/", array(&$this, '_swapWords'), $this->subject);
     $this->_words = array();
     /* Final touches */
     $this->htmlTemplate = preg_replace('#<!--hook\\.([^\\>]+?)-->#', '', $this->htmlTemplate);
     $this->htmlTemplate = $this->registry->getClass('output')->parseIPSTags($this->htmlTemplate);
     /* strip all tags if not HTML */
     if (!$this->settings['email_use_html']) {
         $this->plainTextTemplate = IPSText::stripTags($this->plainTextTemplate);
     }
     $this->plainTextTemplate = IPSText::stripTags(stripslashes($this->lang->words['email_header'])) . $this->plainTextTemplate . IPSText::stripTags(stripslashes($this->lang->words['email_footer']));
     /* Some older apps use $this->message, so give them plaintext */
     $this->message = $this->plainTextTemplate;
 }
 /**
  * Retrieve an email template
  *
  * @access	public
  * @param	string		Template key
  * @param	string		Language to use
  * @param	string		Language file to load
  * @param	string		Application of language file
  * @return	void
  */
 public function getTemplate($name, $language = "", $lang_file = 'public_email_content', $app = 'core')
 {
     //-----------------------------------------
     // Check..
     //-----------------------------------------
     if ($name == "") {
         $this->error++;
         $this->fatalError("A valid email template ID was not passed to the email library during template parsing", "");
     }
     //-----------------------------------------
     // Default?
     //-----------------------------------------
     if (!$language) {
         $language = IPSLib::getDefaultLanguage();
     }
     //-----------------------------------------
     // Check and get
     //-----------------------------------------
     $this->registry->class_localization->loadLanguageFile(array($lang_file), $app, $language);
     //-----------------------------------------
     // Stored KEY?
     //-----------------------------------------
     if (!isset($this->lang->words[$name])) {
         if ($language == IPSLib::getDefaultLanguage()) {
             $this->fatalError("Could not find an email template with an ID of '{$name}'", "");
         } else {
             $this->registry->class_localization->loadLanguageFile(array($lang_file), $app, IPSLib::getDefaultLanguage());
             if (!isset($this->lang->words[$name])) {
                 $this->fatalError("Could not find an email template with an ID of '{$name}'", "");
             }
         }
     }
     //-----------------------------------------
     // Subject?
     //-----------------------------------------
     if (isset($this->lang->words['subject__' . $name])) {
         $this->subject = stripslashes($this->lang->words['subject__' . $name]);
     }
     //-----------------------------------------
     // Return
     //-----------------------------------------
     $this->template = stripslashes($this->lang->words['email_header']) . stripslashes($this->lang->words[$name]) . stripslashes($this->lang->words['email_footer']);
 }