예제 #1
0
 public function update_profile($id, $info, $section)
 {
     $info = Container::get('hooks')->fire('model.profile.update_profile_start', $info, $id, $section);
     $username_updated = false;
     $section = Container::get('hooks')->fire('model.profile.update_profile_section', $section, $id, $info);
     // Validate input depending on section
     switch ($section) {
         case 'essentials':
             $form = array('timezone' => floatval(Input::post('form_timezone')), 'dst' => Input::post('form_dst') ? '1' : '0', 'time_format' => intval(Input::post('form_time_format')), 'date_format' => intval(Input::post('form_date_format')));
             // Make sure we got a valid language string
             if (Input::post('form_language')) {
                 $languages = \FeatherBB\Core\Lister::getLangs();
                 $form['language'] = Utils::trim(Input::post('form_language'));
                 if (!in_array($form['language'], $languages)) {
                     throw new Error(__('Bad request'), 404);
                 }
             }
             if (User::get()->is_admmod) {
                 $form['admin_note'] = Utils::trim(Input::post('admin_note'));
                 // Are we allowed to change usernames?
                 if (User::get()->g_id == ForumEnv::get('FEATHER_ADMIN') || User::get()->g_moderator == '1' && User::get()->g_mod_rename_users == '1') {
                     $form['username'] = Utils::trim(Input::post('req_username'));
                     if ($form['username'] != $info['old_username']) {
                         $errors = '';
                         $errors = $this->check_username($form['username'], $errors, $id);
                         if (!empty($errors)) {
                             throw new Error($errors[0]);
                         }
                         $username_updated = true;
                     }
                 }
                 // We only allow administrators to update the post count
                 if (User::get()->g_id == ForumEnv::get('FEATHER_ADMIN')) {
                     $form['num_posts'] = intval(Input::post('num_posts'));
                 }
             }
             if (ForumSettings::get('o_regs_verify') == '0' || User::get()->is_admmod) {
                 // Validate the email address
                 $form['email'] = strtolower(Utils::trim(Input::post('req_email')));
                 if (!Container::get('email')->is_valid_email($form['email'])) {
                     throw new Error(__('Invalid email'));
                 }
             }
             break;
         case 'personal':
             $form = array('realname' => Input::post('form_realname') ? Utils::trim(Input::post('form_realname')) : '', 'url' => Input::post('form_url') ? Utils::trim(Input::post('form_url')) : '', 'location' => Input::post('form_location') ? Utils::trim(Input::post('form_location')) : '');
             // Add http:// if the URL doesn't contain it already (while allowing https://, too)
             if (User::get()->g_post_links == '1') {
                 if ($form['url'] != '') {
                     $url = Url::is_valid($form['url']);
                     if ($url === false) {
                         throw new Error(__('Invalid website URL'));
                     }
                     $form['url'] = $url['url'];
                 }
             } else {
                 if (!empty($form['url'])) {
                     throw new Error(__('Website not allowed'));
                 }
                 $form['url'] = '';
             }
             if (User::get()->g_id == ForumEnv::get('FEATHER_ADMIN')) {
                 $form['title'] = Utils::trim(Input::post('title'));
             } elseif (User::get()->g_set_title == '1') {
                 $form['title'] = Utils::trim(Input::post('title'));
                 if ($form['title'] != '') {
                     // A list of words that the title may not contain
                     // If the language is English, there will be some duplicates, but it's not the end of the world
                     $forbidden = array('member', 'moderator', 'administrator', 'banned', 'guest', utf8_strtolower(__('Member')), utf8_strtolower(__('Moderator')), utf8_strtolower(__('Administrator')), utf8_strtolower(__('Banned')), utf8_strtolower(__('Guest')));
                     if (in_array(utf8_strtolower($form['title']), $forbidden)) {
                         throw new Error(__('Forbidden title'));
                     }
                 }
             }
             break;
         case 'messaging':
             $form = array('jabber' => Utils::trim(Input::post('form_jabber')), 'icq' => Utils::trim(Input::post('form_icq')), 'msn' => Utils::trim(Input::post('form_msn')), 'aim' => Utils::trim(Input::post('form_aim')), 'yahoo' => Utils::trim(Input::post('form_yahoo')));
             // If the ICQ UIN contains anything other than digits it's invalid
             if (preg_match('%[^0-9]%', $form['icq'])) {
                 throw new Error(__('Bad ICQ'));
             }
             break;
         case 'personality':
             $form = array();
             // Clean up signature from POST
             if (ForumSettings::get('o_signatures') == '1') {
                 $form['signature'] = Utils::linebreaks(Utils::trim(Input::post('signature')));
                 // Validate signature
                 if (Utils::strlen($form['signature']) > ForumSettings::get('p_sig_length')) {
                     throw new Error(sprintf(__('Sig too long'), ForumSettings::get('p_sig_length'), Utils::strlen($form['signature']) - ForumSettings::get('p_sig_length')));
                 } elseif (substr_count($form['signature'], "\n") > ForumSettings::get('p_sig_lines') - 1) {
                     throw new Error(sprintf(__('Sig too many lines'), ForumSettings::get('p_sig_lines')));
                 } elseif ($form['signature'] && ForumSettings::get('p_sig_all_caps') == '0' && Utils::is_all_uppercase($form['signature']) && !User::get()->is_admmod) {
                     $form['signature'] = utf8_ucwords(utf8_strtolower($form['signature']));
                 }
                 // Validate BBCode syntax
                 if (ForumSettings::get('p_sig_bbcode') == '1') {
                     $errors = array();
                     $form['signature'] = Container::get('parser')->preparse_bbcode($form['signature'], $errors, true);
                     if (count($errors) > 0) {
                         throw new Error('<ul><li>' . implode('</li><li>', $errors) . '</li></ul>');
                     }
                 }
             }
             break;
         case 'display':
             $form = array('disp_topics' => Utils::trim(Input::post('form_disp_topics')), 'disp_posts' => Utils::trim(Input::post('form_disp_posts')), 'show_smilies' => Input::post('form_show_smilies') ? '1' : '0', 'show_img' => Input::post('form_show_img') ? '1' : '0', 'show_img_sig' => Input::post('form_show_img_sig') ? '1' : '0', 'show_avatars' => Input::post('form_show_avatars') ? '1' : '0', 'show_sig' => Input::post('form_show_sig') ? '1' : '0');
             if ($form['disp_topics'] != '') {
                 $form['disp_topics'] = intval($form['disp_topics']);
                 if ($form['disp_topics'] < 3) {
                     $form['disp_topics'] = 3;
                 } elseif ($form['disp_topics'] > 75) {
                     $form['disp_topics'] = 75;
                 }
             }
             if ($form['disp_posts'] != '') {
                 $form['disp_posts'] = intval($form['disp_posts']);
                 if ($form['disp_posts'] < 3) {
                     $form['disp_posts'] = 3;
                 } elseif ($form['disp_posts'] > 75) {
                     $form['disp_posts'] = 75;
                 }
             }
             // Make sure we got a valid style string
             if (Input::post('form_style')) {
                 $styles = \FeatherBB\Core\Lister::getStyles();
                 $form['style'] = Utils::trim(Input::post('form_style'));
                 if (!in_array($form['style'], $styles)) {
                     throw new Error(__('Bad request'), 404);
                 }
             }
             break;
         case 'privacy':
             $form = array('email_setting' => intval(Input::post('form_email_setting')), 'notify_with_post' => Input::post('form_notify_with_post') ? '1' : '0', 'auto_notify' => Input::post('form_auto_notify') ? '1' : '0');
             if ($form['email_setting'] < 0 || $form['email_setting'] > 2) {
                 $form['email_setting'] = ForumSettings::get('o_default_email_setting');
             }
             break;
         default:
             throw new Error(__('Bad request'), 404);
     }
     $form = Container::get('hooks')->fire('model.profile.update_profile_form', $form, $section, $id, $info);
     // Single quotes around non-empty values and nothing for empty values
     $temp = array();
     foreach ($form as $key => $input) {
         $temp[$key] = $input;
     }
     if (empty($temp)) {
         throw new Error(__('Bad request'), 404);
     }
     $update_user = DB::for_table('users')->where('id', $id)->find_one()->set($temp);
     $update_user = Container::get('hooks')->fireDB('model.profile.update_profile_query', $update_user);
     $update_user = $update_user->save();
     // If we changed the username we have to update some stuff
     if ($username_updated) {
         $bans_updated = DB::for_table('bans')->where('username', $info['old_username']);
         $bans_updated = Container::get('hooks')->fireDB('model.profile.update_profile_bans_updated', $bans_updated);
         $bans_updated = $bans_updated->update_many('username', $form['username']);
         $update_poster_id = DB::for_table('posts')->where('poster_id', $id);
         $update_poster_id = Container::get('hooks')->fireDB('model.profile.update_profile_poster_id', $update_poster_id);
         $update_poster_id = $update_poster_id->update_many('poster', $form['username']);
         $update_posts = DB::for_table('posts')->where('edited_by', $info['old_username']);
         $update_posts = Container::get('hooks')->fireDB('model.profile.update_profile_posts', $update_posts);
         $update_posts = $update_posts->update_many('edited_by', $form['username']);
         $update_topics_poster = DB::for_table('topics')->where('poster', $info['old_username']);
         $update_topics_poster = Container::get('hooks')->fireDB('model.profile.update_profile_topics_poster', $update_topics_poster);
         $update_topics_poster = $update_topics_poster->update_many('poster', $form['username']);
         $update_topics_last_poster = DB::for_table('topics')->where('last_poster', $info['old_username']);
         $update_topics_last_poster = Container::get('hooks')->fireDB('model.profile.update_profile_topics_last_poster', $update_topics_last_poster);
         $update_topics_last_poster = $update_topics_last_poster->update_many('last_poster', $form['username']);
         $update_forums = DB::for_table('forums')->where('last_poster', $info['old_username']);
         $update_forums = Container::get('hooks')->fireDB('model.profile.update_profile_forums', $update_forums);
         $update_forums = $update_forums->update_many('last_poster', $form['username']);
         $update_online = DB::for_table('online')->where('ident', $info['old_username']);
         $update_online = Container::get('hooks')->fireDB('model.profile.update_profile_online', $update_online);
         $update_online = $update_online->update_many('ident', $form['username']);
         // If the user is a moderator or an administrator we have to update the moderator lists
         $group_id = DB::for_table('users')->where('id', $id);
         // TODO: restore hook
         // $group_id = Container::get('hooks')->fireDB('model.profile.update_profile_group_id', $update_online);
         $group_id = $group_id->find_one_col('group_id');
         $group_mod = DB::for_table('groups')->where('g_id', $group_id);
         $group_mod = Container::get('hooks')->fireDB('model.profile.update_profile_group_mod', $group_mod);
         $group_mod = $group_mod->find_one_col('g_moderator');
         if ($group_id == ForumEnv::get('FEATHER_ADMIN') || $group_mod == '1') {
             // Loop through all forums
             $result = $this->loop_mod_forums();
             foreach ($result as $cur_forum) {
                 $cur_moderators = $cur_forum['moderators'] != '' ? unserialize($cur_forum['moderators']) : array();
                 if (in_array($id, $cur_moderators)) {
                     unset($cur_moderators[$info['old_username']]);
                     $cur_moderators[$form['username']] = $id;
                     uksort($cur_moderators, 'utf8_strcasecmp');
                     $update_mods = DB::for_table('forums')->where('id', $cur_forum['id'])->find_one()->set('moderators', serialize($cur_moderators));
                     $update_mods = Container::get('hooks')->fireDB('model.profile.update_profile_mods', $update_mods);
                     $update_mods = $update_mods->save();
                 }
             }
         }
         // Regenerate the users info cache
         if (!Container::get('cache')->isCached('users_info')) {
             Container::get('cache')->store('users_info', Cache::get_users_info());
         }
         $stats = Container::get('cache')->retrieve('users_info');
         // Check if the bans table was updated and regenerate the bans cache when needed
         if ($bans_updated) {
             Container::get('cache')->store('bans', Cache::get_bans());
         }
     }
     $section = Container::get('hooks')->fireDB('model.profile.update_profile', $section, $id);
     return Router::redirect(Router::pathFor('profileSection', array('id' => $id, 'section' => $section)), __('Profile redirect'));
 }
예제 #2
0
</span></h2>
    <div class="box">
        <form id="profile5" method="post" action="<?php 
echo Router::pathFor('profileSection', ['id' => $id, 'section' => 'display']);
?>
">
            <input type="hidden" name="csrf_name" value="<?php 
echo $csrf_name;
?>
"><input type="hidden" name="csrf_value" value="<?php 
echo $csrf_value;
?>
">
            <div><input type="hidden" name="form_sent" value="1" /></div>
<?php 
$styles = \FeatherBB\Core\Lister::getStyles();
// Only display the style selection box if there's more than one style available
if (count($styles) == 1) {
    echo "\t\t\t" . '<div><input type="hidden" name="form_style" value="' . $styles[0] . '" /></div>' . "\n";
} elseif (count($styles) > 1) {
    ?>
            <div class="inform">
                <fieldset>
                    <legend><?php 
    _e('Style legend');
    ?>
</legend>
                    <div class="infldset">
                        <label><?php 
    _e('Styles');
    ?>
예제 #3
0
 public function get_styles()
 {
     $styles = \FeatherBB\Core\Lister::getStyles();
     $styles = $this->hook->fire('options.get_styles.styles', $styles);
     $output = '';
     foreach ($styles as $temp) {
         if ($this->config['o_default_style'] == $temp) {
             $output .= "\t\t\t\t\t\t\t\t\t\t\t" . '<option value="' . $temp . '" selected="selected">' . str_replace('_', ' ', $temp) . '</option>' . "\n";
         } else {
             $output .= "\t\t\t\t\t\t\t\t\t\t\t" . '<option value="' . $temp . '">' . str_replace('_', ' ', $temp) . '</option>' . "\n";
         }
     }
     $output = $this->hook->fire('options.get_styles.output', $output);
     return $output;
 }
예제 #4
0
 public function get_styles()
 {
     $styles = \FeatherBB\Core\Lister::getStyles();
     $styles = Container::get('hooks')->fire('model.admin.options.get_styles.styles', $styles);
     $output = '';
     foreach ($styles as $temp) {
         if (ForumSettings::get('o_default_style') == $temp) {
             $output .= "\t\t\t\t\t\t\t\t\t\t\t" . '<option value="' . $temp . '" selected="selected">' . str_replace('_', ' ', $temp) . '</option>' . "\n";
         } else {
             $output .= "\t\t\t\t\t\t\t\t\t\t\t" . '<option value="' . $temp . '">' . str_replace('_', ' ', $temp) . '</option>' . "\n";
         }
     }
     $output = Container::get('hooks')->fire('model.admin.options.get_styles.output', $output);
     return $output;
 }