当前位置: 首页>>代码示例>>PHP>>正文


PHP Utils::getIp方法代码示例

本文整理汇总了PHP中FeatherBB\Core\Utils::getIp方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::getIp方法的具体用法?PHP Utils::getIp怎么用?PHP Utils::getIp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FeatherBB\Core\Utils的用法示例。


在下文中一共展示了Utils::getIp方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load_mock_forum_data

 public static function load_mock_forum_data(array $data)
 {
     $cat_name = __('Test category');
     $subject = __('Test post');
     $message = __('Message');
     $forum_name = __('Test forum');
     $forum_desc = __('This is just a test forum');
     $now = time();
     $ip = Utils::getIp();
     return $mock_data = array('categories' => array('cat_name' => $cat_name, 'disp_position' => 1), 'forums' => array('forum_name' => $forum_name, 'forum_desc' => $forum_desc, 'num_topics' => 1, 'num_posts' => 1, 'last_post' => $now, 'last_post_id' => 1, 'last_poster' => $data['username'], 'disp_position' => 1, 'cat_id' => 1), 'topics' => array('poster' => $data['username'], 'subject' => $subject, 'posted' => $now, 'first_post_id' => 1, 'last_post' => $now, 'last_post_id' => 1, 'last_poster' => $data['username'], 'forum_id' => 1), 'posts' => array('poster' => $data['username'], 'poster_id' => 2, 'poster_ip' => $ip, 'message' => $message, 'posted' => $now, 'topic_id' => 1));
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:11,代码来源:Install.php

示例2: load_user

 public static function load_user($user_id)
 {
     $user_id = (int) $user_id;
     $result['select'] = array('u.*', 'g.*', 'o.logged', 'o.idle');
     $result['where'] = array('u.id' => $user_id);
     $result['join'] = $user_id == 1 ? Utils::getIp() : 'u.id';
     $escape = $user_id == 1 ? true : false;
     $result = DB::for_table('users')->table_alias('u')->select_many($result['select'])->inner_join('groups', array('u.group_id', '=', 'g.g_id'), 'g')->left_outer_join('online', array('o.user_id', '=', $result['join']), 'o', $escape)->where($result['where']);
     $result = $result->find_result_set();
     foreach ($result as $user) {
         return $user;
     }
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:13,代码来源:Auth.php

示例3: logout

 public function logout($req, $res, $args)
 {
     $token = Container::get('hooks')->fire('controller.logout', $args['token']);
     if (User::get()->is_guest || !isset($token) || $token != Random::hash(User::get()->id . Random::hash(Utils::getIp()))) {
         return Router::redirect(Router::pathFor('home'), 'Not logged in');
     }
     ModelAuth::delete_online_by_id(User::get()->id);
     // Update last_visit (make sure there's something to update it with)
     if (isset(User::get()->logged)) {
         ModelAuth::set_last_visit(User::get()->id, User::get()->logged);
     }
     ModelAuth::feather_setcookie('Bearer ', 1);
     Container::get('hooks')->fire('controller.logout_end');
     return Router::redirect(Router::pathFor('home'), __('Logout redirect'));
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:15,代码来源:Auth.php

示例4: insert_user

 public function insert_user($user)
 {
     $user = Container::get('hooks')->fire('model.register.insert_user_start', $user);
     // Insert the new user into the database. We do this now to get the last inserted ID for later use
     $now = time();
     $intial_group_id = ForumSettings::get('o_regs_verify') == '0' ? ForumSettings::get('o_default_user_group') : ForumEnv::get('FEATHER_UNVERIFIED');
     $password_hash = Random::hash($user['password1']);
     // Add the user
     $user['insert'] = array('username' => $user['username'], 'group_id' => $intial_group_id, 'password' => $password_hash, 'email' => $user['email1'], 'email_setting' => ForumSettings::get('o_default_email_setting'), 'timezone' => ForumSettings::get('o_default_timezone'), 'dst' => 0, 'language' => $user['language'], 'style' => ForumSettings::get('o_default_style'), 'registered' => $now, 'registration_ip' => Utils::getIp(), 'last_visit' => $now);
     $user = DB::for_table('users')->create()->set($user['insert']);
     $user = Container::get('hooks')->fireDB('model.register.insert_user_query', $user);
     $user = $user->save();
     $new_uid = DB::get_db()->lastInsertId(ForumSettings::get('db_prefix') . 'users');
     // If the mailing list isn't empty, we may need to send out some alerts
     if (ForumSettings::get('o_mailing_list') != '') {
         // If we previously found out that the email was banned
         if (isset($user['banned_email'])) {
             // Load the "banned email register" template
             $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/banned_email_register.tpl'));
             $mail_tpl = Container::get('hooks')->fire('model.register.insert_user_banned_mail_tpl', $mail_tpl);
             // The first row contains the subject
             $first_crlf = strpos($mail_tpl, "\n");
             $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8));
             $mail_subject = Container::get('hooks')->fire('model.register.insert_user_banned_mail_subject', $mail_subject);
             $mail_message = trim(substr($mail_tpl, $first_crlf));
             $mail_message = str_replace('<username>', $user['username'], $mail_message);
             $mail_message = str_replace('<email>', $user['email1'], $mail_message);
             $mail_message = str_replace('<profile_url>', Router::pathFor('userProfile', ['id' => $new_uid]), $mail_message);
             $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message);
             $mail_message = Container::get('hooks')->fire('model.register.insert_user_banned_mail_message', $mail_message);
             Container::get('email')->feather_mail(ForumSettings::get('o_mailing_list'), $mail_subject, $mail_message);
         }
         // If we previously found out that the email was a dupe
         if (!empty($dupe_list)) {
             // Load the "dupe email register" template
             $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/dupe_email_register.tpl'));
             $mail_tpl = Container::get('hooks')->fire('model.register.insert_user_dupe_mail_tpl', $mail_tpl);
             // The first row contains the subject
             $first_crlf = strpos($mail_tpl, "\n");
             $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8));
             $mail_subject = Container::get('hooks')->fire('model.register.insert_user_dupe_mail_subject', $mail_subject);
             $mail_message = trim(substr($mail_tpl, $first_crlf));
             $mail_message = str_replace('<username>', $user['username'], $mail_message);
             $mail_message = str_replace('<dupe_list>', implode(', ', $dupe_list), $mail_message);
             $mail_message = str_replace('<profile_url>', Router::pathFor('userProfile', ['id' => $new_uid]), $mail_message);
             $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message);
             $mail_message = Container::get('hooks')->fire('model.register.insert_user_dupe_mail_message', $mail_message);
             Container::get('email')->feather_mail(ForumSettings::get('o_mailing_list'), $mail_subject, $mail_message);
         }
         // Should we alert people on the admin mailing list that a new user has registered?
         if (ForumSettings::get('o_regs_report') == '1') {
             // Load the "new user" template
             $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/new_user.tpl'));
             $mail_tpl = Container::get('hooks')->fire('model.register.insert_user_new_mail_tpl', $mail_tpl);
             // The first row contains the subject
             $first_crlf = strpos($mail_tpl, "\n");
             $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8));
             $mail_subject = Container::get('hooks')->fire('model.register.insert_user_new_mail_subject', $mail_subject);
             $mail_message = trim(substr($mail_tpl, $first_crlf));
             $mail_message = str_replace('<username>', $user['username'], $mail_message);
             $mail_message = str_replace('<base_url>', Router::pathFor('home'), $mail_message);
             $mail_message = str_replace('<profile_url>', Router::pathFor('userProfile', ['id' => $new_uid]), $mail_message);
             $mail_message = str_replace('<admin_url>', Router::pathFor('profileSection', ['id' => $new_uid, 'section' => 'admin']), $mail_message);
             $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message);
             $mail_message = Container::get('hooks')->fire('model.register.insert_user_new_mail_message', $mail_message);
             Container::get('email')->feather_mail(ForumSettings::get('o_mailing_list'), $mail_subject, $mail_message);
         }
     }
     // Must the user verify the registration or do we log him/her in right now?
     if (ForumSettings::get('o_regs_verify') == '1') {
         // Load the "welcome" template
         $mail_tpl = trim(file_get_contents(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . User::get()->language . '/mail_templates/welcome.tpl'));
         $mail_tpl = Container::get('hooks')->fire('model.register.insert_user_welcome_mail_tpl', $mail_tpl);
         // The first row contains the subject
         $first_crlf = strpos($mail_tpl, "\n");
         $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8));
         $mail_subject = Container::get('hooks')->fire('model.register.insert_user_welcome_mail_subject', $mail_subject);
         $mail_message = trim(substr($mail_tpl, $first_crlf));
         $mail_subject = str_replace('<board_title>', ForumSettings::get('o_board_title'), $mail_subject);
         $mail_message = str_replace('<base_url>', Router::pathFor('home'), $mail_message);
         $mail_message = str_replace('<username>', $user['username'], $mail_message);
         $mail_message = str_replace('<password>', $user['password1'], $mail_message);
         $mail_message = str_replace('<login_url>', Router::pathFor('login'), $mail_message);
         $mail_message = str_replace('<board_mailer>', ForumSettings::get('o_board_title'), $mail_message);
         $mail_message = Container::get('hooks')->fire('model.register.insert_user_welcome_mail_message', $mail_message);
         Container::get('email')->feather_mail($user['email1'], $mail_subject, $mail_message);
         return Router::redirect(Router::pathFor('home'), __('Reg email') . ' <a href="mailto:' . Utils::escape(ForumSettings::get('o_admin_email')) . '">' . Utils::escape(ForumSettings::get('o_admin_email')) . '</a>.');
     }
     $user_object = new \stdClass();
     $user_object->id = $new_uid;
     $user_object->username = $user['username'];
     $expire = time() + ForumSettings::get('o_timeout_visit');
     $jwt = AuthModel::generate_jwt($user_object, $expire);
     AuthModel::feather_setcookie('Bearer ' . $jwt, $expire);
     // Refresh cache
     Container::get('cache')->store('users_info', Cache::get_users_info());
     Container::get('hooks')->fire('model.register.insert_user');
     return Router::redirect(Router::pathFor('home'), __('Reg complete'));
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:99,代码来源:Register.php

示例5: implode

}
if (ForumSettings::get('o_rules') == '1' && (!User::get()->is_guest || User::get()->g_read_board == '1' || ForumSettings::get('o_regs_allow') == '1')) {
    $navlinks[] = '<li id="navrules"' . ($active_page == 'rules' ? ' class="isactive"' : '') . '><a href="' . Router::pathFor('rules') . '">' . __('Rules') . '</a></li>';
}
if (User::get()->g_read_board == '1' && User::get()->g_search == '1') {
    $navlinks[] = '<li id="navsearch"' . ($active_page == 'search' ? ' class="isactive"' : '') . '><a href="' . Router::pathFor('search') . '">' . __('Search') . '</a></li>';
}
if (User::get()->is_guest) {
    $navlinks[] = '<li id="navregister"' . ($active_page == 'register' ? ' class="isactive"' : '') . '><a href="' . Router::pathFor('register') . '">' . __('Register') . '</a></li>';
    $navlinks[] = '<li id="navlogin"' . ($active_page == 'login' ? ' class="isactive"' : '') . '><a href="' . Router::pathFor('login') . '">' . __('Login') . '</a></li>';
} else {
    $navlinks[] = '<li id="navprofile"' . ($active_page == 'profile' ? ' class="isactive"' : '') . '><a href="' . Router::pathFor('userProfile', ['id' => User::get()->id]) . '">' . __('Profile') . '</a></li>';
    if (User::get()->is_admmod) {
        $navlinks[] = '<li id="navadmin"' . ($active_page == 'admin' ? ' class="isactive"' : '') . '><a href="' . Router::pathFor('adminIndex') . '">' . __('Admin') . '</a></li>';
    }
    $navlinks[] = '<li id="navlogout"><a href="' . Router::pathFor('logout', ['token' => Random::hash(User::get()->id . Random::hash(Utils::getIp()))]) . '">' . __('Logout') . '</a></li>';
}
// Are there any additional navlinks we should insert into the array before imploding it?
$hooksLinks = Container::get('hooks')->fire('view.header.navlinks', []);
$extraLinks = ForumSettings::get('o_additional_navlinks') . "\n" . implode("\n", $hooksLinks);
if (User::get()->g_read_board == '1' && $extraLinks != '') {
    if (preg_match_all('%([0-9]+)\\s*=\\s*(.*?)\\n%s', $extraLinks . "\n", $results)) {
        // Insert any additional links into the $links array (at the correct index)
        $num_links = count($results[1]);
        for ($i = 0; $i < $num_links; ++$i) {
            array_splice($navlinks, $results[1][$i], 0, array('<li id="navextra' . ($i + 1) . '"' . ($active_page == 'navextra' . ($i + 1) ? ' class="isactive"' : '') . '>' . $results[2][$i] . '</li>'));
        }
    }
}
echo "\t\t\t" . implode("\n\t\t\t", $navlinks);
?>
开发者ID:featherbb,项目名称:featherbb,代码行数:31,代码来源:header.php

示例6: set_default_user

function set_default_user()
{
    $remote_addr = Utils::getIp();
    // Fetch guest user
    $select_set_default_user = array('u.*', 'g.*', 'o.logged', 'o.last_post', 'o.last_search');
    $where_set_default_user = array('u.id' => '1');
    $result = \DB::for_table('users')->table_alias('u')->select_many($select_set_default_user)->inner_join('groups', array('u.group_id', '=', 'g.g_id'), 'g')->left_outer_join('online', array('o.ident', '=', $remote_addr), 'o', true)->where($where_set_default_user)->find_result_set();
    if (!$result) {
        exit('Unable to fetch guest information. Your database must contain both a guest user and a guest user group.');
    }
    foreach ($result as User::get()) {
    }
    // Update online list
    if (!User::get()->logged) {
        User::get()->logged = time();
        // With MySQL/MySQLi/SQLite, REPLACE INTO avoids a user having two rows in the online table
        switch (ForumSettings::get('db_type')) {
            case 'mysql':
            case 'mysqli':
            case 'mysql_innodb':
            case 'mysqli_innodb':
            case 'sqlite':
            case 'sqlite3':
                \DB::for_table('online')->raw_execute('REPLACE INTO ' . ForumSettings::get('db_prefix') . 'online (user_id, ident, logged) VALUES(1, :ident, :logged)', array(':ident' => $remote_addr, ':logged' => User::get()->logged));
                break;
            default:
                \DB::for_table('online')->raw_execute('INSERT INTO ' . ForumSettings::get('db_prefix') . 'online (user_id, ident, logged) SELECT 1, :ident, :logged WHERE NOT EXISTS (SELECT 1 FROM ' . ForumSettings::get('db_prefix') . 'online WHERE ident=:ident)', array(':ident' => $remote_addr, ':logged' => User::get()->logged));
                break;
        }
    } else {
        \DB::for_table('online')->where('ident', $remote_addr)->update_many('logged', time());
    }
    User::get()->disp_topics = ForumSettings::get('o_disp_topics_default');
    User::get()->disp_posts = ForumSettings::get('o_disp_posts_default');
    User::get()->timezone = ForumSettings::get('o_default_timezone');
    User::get()->dst = ForumSettings::get('o_default_dst');
    User::get()->language = ForumSettings::get('o_default_lang');
    User::get()->style = ForumSettings::get('o_default_style');
    User::get()->is_guest = true;
    User::get()->is_admmod = false;
}
开发者ID:featherbb,项目名称:featherbb,代码行数:41,代码来源:extern.php

示例7: increment_post_count

 public function increment_post_count($post, $new_tid)
 {
     Container::get('hooks')->fire('model.post.increment_post_count_start', $post, $new_tid);
     if (!User::get()->is_guest) {
         $increment = DB::for_table('users')->where('id', User::get()->id)->find_one()->set('last_post', $post['time'])->set_expr('num_posts', 'num_posts+1');
         $increment = Container::get('hooks')->fireDB('model.post.increment_post_count_query', $increment);
         $increment = $increment->save();
         // Promote this user to a new group if enabled
         if (User::get()->g_promote_next_group != 0 && User::get()->num_posts + 1 >= User::get()->g_promote_min_posts) {
             $new_group_id = User::get()->g_promote_next_group;
             $promote = DB::for_table('users')->where('id', User::get()->id)->find_one()->set('group_id', $new_group_id);
             $promote = Container::get('hooks')->fireDB('model.post.increment_post_count_query', $promote);
             $promote = $promote->save();
         }
         // Topic tracking stuff...
         $tracked_topics = Track::get_tracked_topics();
         $tracked_topics['topics'][$new_tid] = time();
         Track::set_tracked_topics($tracked_topics);
     } else {
         // Update the last_post field for guests
         $last_post = DB::for_table('online')->where('ident', Utils::getIp())->find_one()->set('last_post', $post['time']);
         $last_post = Container::get('hooks')->fireDB('model.post.increment_post_count_last_post', $last_post);
         $last_post = $last_post->save();
     }
     Container::get('hooks')->fire('model.post.increment_post_count');
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:26,代码来源:Post.php

示例8: __invoke

 public function __invoke($req, $res, $next)
 {
     $authCookie = Container::get('cookie')->get(ForumSettings::get('cookie_name'));
     if ($jwt = $this->get_cookie_data($authCookie)) {
         $user = AuthModel::load_user($jwt->data->userId);
         $expires = $jwt->exp > Container::get('now') + ForumSettings::get('o_timeout_visit') ? Container::get('now') + 1209600 : Container::get('now') + ForumSettings::get('o_timeout_visit');
         $user->is_guest = false;
         $user->is_admmod = $user->g_id == ForumEnv::get('FEATHER_ADMIN') || $user->g_moderator == '1';
         if (!$user->disp_topics) {
             $user->disp_topics = ForumSettings::get('o_disp_topics_default');
         }
         if (!$user->disp_posts) {
             $user->disp_posts = ForumSettings::get('o_disp_posts_default');
         }
         if (!file_exists(ForumEnv::get('FEATHER_ROOT') . 'featherbb/lang/' . $user->language)) {
             $user->language = ForumSettings::get('o_default_lang');
         }
         if (!file_exists(ForumEnv::get('FEATHER_ROOT') . 'style/themes/' . $user->style . '/style.css')) {
             $user->style = ForumSettings::get('o_default_style');
         }
         // Refresh cookie to avoid re-logging between idle
         $jwt = AuthModel::generate_jwt($user, $expires);
         AuthModel::feather_setcookie('Bearer ' . $jwt, $expires);
         // Add user to DIC
         Container::set('user', $user);
         $this->update_online();
     } else {
         $user = AuthModel::load_user(1);
         $user->disp_topics = ForumSettings::get('o_disp_topics_default');
         $user->disp_posts = ForumSettings::get('o_disp_posts_default');
         $user->timezone = ForumSettings::get('o_default_timezone');
         $user->dst = ForumSettings::get('o_default_dst');
         $user->language = ForumSettings::get('o_default_lang');
         $user->style = ForumSettings::get('o_default_style');
         $user->is_guest = true;
         $user->is_admmod = false;
         // Update online list
         if (!$user->logged) {
             $user->logged = time();
             // With MySQL/MySQLi/SQLite, REPLACE INTO avoids a user having two rows in the online table
             switch (ForumSettings::get('db_type')) {
                 case 'mysql':
                 case 'mysqli':
                 case 'mysql_innodb':
                 case 'mysqli_innodb':
                 case 'sqlite':
                 case 'sqlite3':
                     DB::for_table('online')->raw_execute('REPLACE INTO ' . ForumSettings::get('db_prefix') . 'online (user_id, ident, logged) VALUES(1, :ident, :logged)', array(':ident' => Utils::getIp(), ':logged' => $user->logged));
                     break;
                 default:
                     DB::for_table('online')->raw_execute('INSERT INTO ' . ForumSettings::get('db_prefix') . 'online (user_id, ident, logged) SELECT 1, :ident, :logged WHERE NOT EXISTS (SELECT 1 FROM ' . ForumSettings::get('db_prefix') . 'online WHERE ident=:ident)', array(':ident' => Utils::getIp(), ':logged' => $user->logged));
                     break;
             }
         } else {
             DB::for_table('online')->where('ident', Utils::getIp())->update_many('logged', time());
         }
         // $jwt = AuthModel::generate_jwt($user, Container::get('now') + 31536000);
         // AuthModel::feather_setcookie('Bearer '.$jwt, Container::get('now') + 31536000);
         // Add $user as guest to DIC
         Container::set('user', $user);
     }
     translate('common');
     // Load bans from cache
     if (!Container::get('cache')->isCached('bans')) {
         Container::get('cache')->store('bans', Cache::get_bans());
     }
     // Add bans to the container
     Container::set('bans', Container::get('cache')->retrieve('bans'));
     // Check if current user is banned
     $this->check_bans();
     // Update online list
     $this->update_users_online();
     return $next($req, $res);
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:74,代码来源:Auth.php

示例9: send

 public function send($req, $res, $args)
 {
     if (!isset($args['uid'])) {
         $args['uid'] = null;
     }
     if (!isset($args['tid'])) {
         $args['tid'] = null;
     }
     if (Request::isPost()) {
         // First raw validation
         $data = array_merge(array('username' => null, 'subject' => null, 'message' => null, 'smilies' => 0, 'preview' => null), Request::getParsedBody());
         $data = array_map(array('FeatherBB\\Core\\Utils', 'trim'), $data);
         $conv = false;
         if (!is_null($args['tid'])) {
             if ($args['tid'] < 1) {
                 throw new Error('Wrong conversation ID', 400);
             }
             if (!($conv = $this->model->getConversation($args['tid'], User::get()->id))) {
                 throw new Error('Unknown conversation ID', 400);
             }
         }
         // Preview message
         if (Input::post('preview')) {
             // Make breadcrumbs
             $this->crumbs[] = __('Reply', 'private_messages');
             $this->crumbs[] = __('Preview');
             Utils::generateBreadcrumbs($this->crumbs);
             Container::get('hooks')->fire('conversationsPlugin.send.preview');
             $msg = Container::get('parser')->parse_message($data['req_message'], $data['smilies']);
             View::setPageInfo(array('parsed_message' => $msg, 'username' => Utils::escape($data['username']), 'subject' => Utils::escape($data['subject']), 'message' => Utils::escape($data['req_message'])))->addTemplate('send.php')->display();
         } else {
             // Prevent flood
             if (!is_null($data['preview']) && User::get()['last_post'] != '' && Container::get('now') - User::get()['last_post'] < Container::get('prefs')->get(User::get(), 'post.min_interval')) {
                 throw new Error(sprintf(__('Flood start'), Container::get('prefs')->get(User::get(), 'post.min_interval'), Container::get('prefs')->get(User::get(), 'post.min_interval') - (Container::get('now') - User::get()['last_post'])), 429);
             }
             if (!$conv) {
                 // Validate username / TODO : allow multiple usernames
                 if (!($user = $this->model->isAllowed($data['username']))) {
                     throw new Error('You can\'t send an PM to ' . ($data['username'] ? $data['username'] : 'nobody'), 400);
                 }
                 // Avoid self messages
                 if ($user->id == User::get()->id) {
                     throw new Error('No self message', 403);
                 }
                 // Validate subject
                 if (ForumSettings::get('o_censoring') == '1') {
                     $data['subject'] = Utils::trim(Utils::censor($data['subject']));
                 }
                 if (empty($data['subject'])) {
                     throw new Error('No subject or censored subject', 400);
                 } else {
                     if (Utils::strlen($data['subject']) > 70) {
                         throw new Error('Too long subject', 400);
                     } else {
                         if (ForumSettings::get('p_subject_all_caps')['p_subject_all_caps'] == '0' && Utils::is_all_uppercase($data['subject']) && !User::get()->is_admmod) {
                             throw new Error('All caps subject forbidden', 400);
                         }
                     }
                 }
             }
             // TODO : inbox full
             // Validate message
             if (ForumSettings::get('o_censoring') == '1') {
                 $data['req_message'] = Utils::trim(Utils::censor($data['req_message']));
             }
             if (empty($data['req_message'])) {
                 throw new Error('No message or censored message', 400);
             } else {
                 if (Utils::strlen($data['req_message']) > ForumEnv::get('FEATHER_MAX_POSTSIZE')) {
                     throw new Error('Too long message', 400);
                 } else {
                     if (ForumSettings::get('p_subject_all_caps')['p_subject_all_caps'] == '0' && Utils::is_all_uppercase($data['subject']) && !User::get()->is_admmod) {
                         throw new Error('All caps message forbidden', 400);
                     }
                 }
             }
             // Send ... TODO : when perms will be ready
             // Check if the receiver has the PM enabled
             // Check if he has reached his max limit of PM
             // Block feature ?
             if (!$conv) {
                 $conv_data = array('subject' => $data['subject'], 'poster' => User::get()->username, 'poster_id' => User::get()->id, 'num_replies' => 0, 'last_post' => Container::get('now'), 'last_poster' => User::get()->username);
                 $args['tid'] = $this->model->addConversation($conv_data);
             }
             if ($args['tid']) {
                 $msg_data = array('poster' => User::get()->username, 'poster_id' => User::get()->id, 'poster_ip' => Utils::getIp(), 'message' => $data['req_message'], 'hide_smilies' => $data['smilies'], 'sent' => Container::get('now'));
                 if ($conv) {
                     // Reply to an existing conversation
                     if ($msg_id = $this->model->addMessage($msg_data, $args['tid'])) {
                         return Router::redirect(Router::pathFor('Conversations.home'), sprintf(__('Reply success', 'private_messages'), $conv->subject));
                     }
                 } else {
                     // Add message in conversation + add receiver (create new conversation)
                     if ($msg_id = $this->model->addMessage($msg_data, $args['tid'], array($user->id, User::get()->id))) {
                         return Router::redirect(Router::pathFor('Conversations.home'), sprintf(__('Send success', 'private_messages'), $user->username));
                     }
                 }
             } else {
                 throw new Error('Unable to create conversation');
             }
//.........这里部分代码省略.........
开发者ID:featherbb,项目名称:private-messages,代码行数:101,代码来源:PrivateMessages.php

示例10: get_search_results

 public function get_search_results()
 {
     $search = array();
     $search = Container::get('hooks')->fire('model.search.get_search_results_start', $search);
     $action = Input::query('action') ? Input::query('action') : null;
     $forums = Input::query('forums') ? is_array(Input::query('forums')) ? Input::query('forums') : array_filter(explode(',', Input::query('forums'))) : (Input::query('forums') ? array(Input::query('forums')) : array());
     $sort_dir = Input::query('sort_dir') && Input::query('sort_dir') == 'DESC' ? 'DESC' : 'ASC';
     $forums = array_map('intval', $forums);
     // Allow the old action names for backwards compatibility reasons
     if ($action == 'show_user') {
         $action = 'show_user_posts';
     } elseif ($action == 'show_24h') {
         $action = 'show_recent';
     }
     // If a search_id was supplied
     if (Input::query('search_id')) {
         $search_id = intval(Input::query('search_id'));
         if ($search_id < 1) {
             throw new Error(__('Bad request'), 400);
         }
     } elseif ($action == 'search') {
         $keywords = Input::query('keywords') ? utf8_strtolower(Utils::trim(Input::query('keywords'))) : null;
         $author = Input::query('author') ? utf8_strtolower(Utils::trim(Input::query('author'))) : null;
         if (preg_match('%^[\\*\\%]+$%', $keywords) || Utils::strlen(str_replace(array('*', '%'), '', $keywords)) < ForumEnv::get('FEATHER_SEARCH_MIN_WORD') && !$this->search->is_cjk($keywords)) {
             $keywords = '';
         }
         if (preg_match('%^[\\*\\%]+$%', $author) || Utils::strlen(str_replace(array('*', '%'), '', $author)) < 2) {
             $author = '';
         }
         if (!$keywords && !$author) {
             throw new Error(__('No terms'), 400);
         }
         if ($author) {
             $author = str_replace('*', '%', $author);
         }
         $show_as = Input::query('show_as') && Input::query('show_as') == 'topics' ? 'topics' : 'posts';
         $sort_by = Input::query('sort_by') ? intval(Input::query('sort_by')) : 0;
         $search_in = !Input::query('search_in') || Input::query('search_in') == '0' ? 0 : (Input::query('search_in') == '1' ? 1 : -1);
     } elseif ($action == 'show_user_posts' || $action == 'show_user_topics' || $action == 'show_subscriptions') {
         $user_id = Input::query('user_id') ? intval(Input::query('user_id')) : User::get()->id;
         if ($user_id < 2) {
             throw new Error(__('Bad request'), 404);
         }
         // Subscribed topics can only be viewed by admins, moderators and the users themselves
         if ($action == 'show_subscriptions' && !User::get()->is_admmod && $user_id != User::get()->id) {
             throw new Error(__('No permission'), 403);
         }
     } elseif ($action == 'show_recent') {
         $interval = Input::query('value') ? intval(Input::query('value')) : 86400;
     } elseif ($action == 'show_replies') {
         if (User::get()->is_guest) {
             throw new Error(__('Bad request'), 404);
         }
     } elseif ($action != 'show_new' && $action != 'show_unanswered') {
         throw new Error(__('Bad request'), 404);
     }
     // If a valid search_id was supplied we attempt to fetch the search results from the db
     if (isset($search_id)) {
         $ident = User::get()->is_guest ? Utils::getIp() : User::get()->username;
         $search_data = DB::for_table('search_cache')->where('id', $search_id)->where('ident', $ident);
         $search_data = Container::get('hooks')->fireDB('model.search.get_search_results_search_data_query', $search_data);
         $search_data = $search_data->find_one_col('search_data');
         if ($search_data) {
             $temp = unserialize($search_data);
             $temp = Container::get('hooks')->fire('model.search.get_search_results_temp', $temp);
             $search_ids = unserialize($temp['search_ids']);
             $num_hits = $temp['num_hits'];
             $sort_by = $temp['sort_by'];
             $sort_dir = $temp['sort_dir'];
             $show_as = $temp['show_as'];
             $search_type = $temp['search_type'];
             unset($temp);
         } else {
             throw new Error(__('No hits'), 404);
         }
     } else {
         $keyword_results = $author_results = array();
         // Search a specific forum?
         $forum_sql = !empty($forums) || empty($forums) && ForumSettings::get('o_search_all_forums') == '0' && !User::get()->is_admmod ? ' AND t.forum_id IN (' . implode(',', $forums) . ')' : '';
         if (!empty($author) || !empty($keywords)) {
             // Flood protection
             if (User::get()->last_search && time() - User::get()->last_search < User::get()->g_search_flood && time() - User::get()->last_search >= 0) {
                 throw new Error(sprintf(__('Search flood'), User::get()->g_search_flood, User::get()->g_search_flood - (time() - User::get()->last_search)), 429);
             }
             if (!User::get()->is_guest) {
                 $update_last_search = DB::for_table('users')->where('id', User::get()->id);
             } else {
                 $update_last_search = DB::for_table('online')->where('ident', Utils::getIp());
             }
             $update_last_search = Container::get('hooks')->fireDB('model.search.get_search_results_update_last_search', $update_last_search);
             $update_last_search = $update_last_search->update_many('last_search', time());
             switch ($sort_by) {
                 case 1:
                     $sort_by_sql = $show_as == 'topics' ? 't.poster' : 'p.poster';
                     $sort_type = SORT_STRING;
                     break;
                 case 2:
                     $sort_by_sql = 't.subject';
                     $sort_type = SORT_STRING;
                     break;
//.........这里部分代码省略.........
开发者ID:featherbb,项目名称:featherbb,代码行数:101,代码来源:Search.php


注:本文中的FeatherBB\Core\Utils::getIp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。