public function validate_search_word($word, $idx) { static $stopwords; // If the word is a keyword we don't want to index it, but we do want to be allowed to search it if ($this->is_keyword($word)) { return !$idx; } if (!isset($stopwords)) { if (!$this->feather->cache->isCached('stopwords')) { $this->feather->cache->store('stopwords', \FeatherBB\Model\Cache::get_config(), '+1 week'); } $stopwords = $this->feather->cache->retrieve('stopwords'); } // If it is a stopword it isn't valid if (in_array($word, $stopwords)) { return false; } // If the word is CJK we don't want to index it, but we do want to be allowed to search it if ($this->is_cjk($word)) { return !$idx; } // Exclude % and * when checking whether current word is valid $word = str_replace(array('%', '*'), '', $word); // Check the word is within the min/max length $num_chars = Utils::strlen($word); return $num_chars >= $this->feather->forum_env['FEATHER_SEARCH_MIN_WORD'] && $num_chars <= $this->feather->forum_env['FEATHER_SEARCH_MAX_WORD']; }
public function update_permissions() { $form = array_map('intval', Input::post('form')); $form = Container::get('hooks')->fire('model.admin.permissions.update_permissions.form', $form); foreach ($form as $key => $input) { // Make sure the input is never a negative value if ($input < 0) { $input = 0; } // Only update values that have changed if (array_key_exists('p_' . $key, Container::get('forum_settings')) && ForumSettings::get('p_' . $key) != $input) { DB::for_table('config')->where('conf_name', 'p_' . $key)->update_many('conf_value', $input); } } // Regenerate the config cache Container::get('cache')->store('config', Cache::get_config()); // $this->clear_feed_cache(); return Router::redirect(Router::pathFor('adminPermissions'), __('Perms updated redirect')); }
public function update_permissions() { $form = array_map('intval', $this->request->post('form')); $form = $this->hook->fire('permissions.update_permissions.form', $form); foreach ($form as $key => $input) { // Make sure the input is never a negative value if ($input < 0) { $input = 0; } // Only update values that have changed if (array_key_exists('p_' . $key, $this->config) && $this->config['p_' . $key] != $input) { DB::for_table('config')->where('conf_name', 'p_' . $key)->update_many('conf_value', $input); } } // Regenerate the config cache $this->feather->cache->store('config', Cache::get_config()); // $this->clear_feed_cache(); Url::redirect($this->feather->urlFor('adminPermissions'), __('Perms updated redirect')); }
public function set_default_group($groups) { $group_id = intval(Input::post('default_group')); $group_id = Container::get('hooks')->fire('model.admin.groups.set_default_group.group_id', $group_id); // Make sure it's not the admin or guest groups if ($group_id == ForumEnv::get('FEATHER_ADMIN') || $group_id == ForumEnv::get('FEATHER_GUEST')) { throw new Error(__('Bad request'), 404); } // Make sure it's not a moderator group if ($groups[$group_id]['g_moderator'] != 0) { throw new Error(__('Bad request'), 404); } DB::for_table('config')->where('conf_name', 'o_default_user_group')->update_many('conf_value', $group_id); // Regenerate the config cache Container::get('cache')->store('config', Cache::get_config()); return Router::redirect(Router::pathFor('adminGroups'), __('Default group redirect')); }
public function __invoke($req, $res, $next) { // Set headers $res = $this->set_headers($res); // Block prefetch requests if (isset($this->app->environment['HTTP_X_MOZ']) && $this->app->environment['HTTP_X_MOZ'] == 'prefetch') { return $this->app->response->setStatus(403); // Send forbidden header } // Populate Slim object with forum_env vars Container::set('forum_env', $this->forum_env); // Load FeatherBB utils class Container::set('utils', function ($container) { return new Utils(); }); // Record start time Container::set('start', Utils::get_microtime()); // Define now var Container::set('now', function () { return time(); }); // Load FeatherBB cache Container::set('cache', function ($container) { $path = $this->forum_env['FORUM_CACHE_DIR']; return new \FeatherBB\Core\Cache(array('name' => 'feather', 'path' => $path, 'extension' => '.cache')); }); // Load FeatherBB permissions Container::set('perms', function ($container) { return new \FeatherBB\Core\Permissions(); }); // Load FeatherBB preferences Container::set('prefs', function ($container) { return new \FeatherBB\Core\Preferences(); }); // Load FeatherBB view Container::set('template', function ($container) { return new View(); }); // Load FeatherBB url class Container::set('url', function ($container) { return new Url(); }); // Load FeatherBB hooks Container::set('hooks', function ($container) { return new Hooks(); }); // Load FeatherBB email class Container::set('email', function ($container) { return new Email(); }); Container::set('parser', function ($container) { return new Parser(); }); // Set cookies Container::set('cookie', function ($container) { $request = $container->get('request'); return new \Slim\Http\Cookies($request->getCookieParams()); }); Container::set('flash', function ($c) { return new \Slim\Flash\Messages(); }); // This is the very first hook fired Container::get('hooks')->fire('core.start'); if (!is_file(ForumEnv::get('FORUM_CONFIG_FILE'))) { // Reset cache Container::get('cache')->flush(); $installer = new \FeatherBB\Controller\Install(); return $installer->run(); } // Load config from disk include ForumEnv::get('FORUM_CONFIG_FILE'); if (isset($featherbb_config) && is_array($featherbb_config)) { $this->forum_settings = array_merge(self::load_default_forum_settings(), $featherbb_config); } else { $this->app->response->setStatus(500); // Send forbidden header return $this->app->response->setBody('Wrong config file format'); } // Init DB and configure Slim self::init_db($this->forum_settings, ForumEnv::get('FEATHER_SHOW_INFO')); Config::set('displayErrorDetails', ForumEnv::get('FEATHER_DEBUG')); if (!Container::get('cache')->isCached('config')) { Container::get('cache')->store('config', \FeatherBB\Model\Cache::get_config()); } // Finalize forum_settings array $this->forum_settings = array_merge(Container::get('cache')->retrieve('config'), $this->forum_settings); Container::set('forum_settings', $this->forum_settings); // Set default style and assets Container::get('template')->setStyle(ForumSettings::get('o_default_style')); Container::get('template')->addAsset('js', 'style/themes/FeatherBB/phone.min.js'); // Run activated plugins self::loadPlugins(); // Define time formats and add them to the container Container::set('forum_time_formats', array(ForumSettings::get('o_time_format'), 'H:i:s', 'H:i', 'g:i:s a', 'g:i a')); Container::set('forum_date_formats', array(ForumSettings::get('o_date_format'), 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y')); // Call FeatherBBAuth middleware return $next($req, $res); }
public function call() { global $forum_time_formats, $forum_date_formats; // Legacy // Set headers $this->set_headers(); // Block prefetch requests if (isset($this->app->environment['HTTP_X_MOZ']) && $this->app->environment['HTTP_X_MOZ'] == 'prefetch') { return $this->app->response->setStatus(403); // Send forbidden header } // Populate Slim object with forum_env vars $this->hydrate('forum_env', $this->forum_env); // Load FeatherBB utils class $this->app->container->singleton('utils', function () { return new Utils(); }); // Record start time $this->app->start = Utils::get_microtime(); // Define now var $this->app->now = function () { return time(); }; // Load FeatherBB cache $this->app->container->singleton('cache', function ($container) { $path = $container->forum_env['FORUM_CACHE_DIR']; return new \FeatherBB\Core\Cache(array('name' => 'feather', 'path' => $path, 'extension' => '.cache')); }); // Load FeatherBB view $this->app->container->singleton('template', function () { return new \FeatherBB\Core\View(); }); // Load FeatherBB url class $this->app->container->singleton('url', function () { return new \FeatherBB\Core\Url(); }); // Load FeatherBB hooks $this->app->container->singleton('hooks', function () { return new \FeatherBB\Core\Hooks(); }); // Load FeatherBB email class $this->app->container->singleton('email', function () { return new \FeatherBB\Core\Email(); }); $this->app->container->singleton('parser', function () { return new \FeatherBB\Core\Parser(); }); // This is the very first hook fired $this->app->hooks->fire('core.start'); if (!is_file($this->forum_env['FORUM_CONFIG_FILE'])) { $installer = new \FeatherBB\Controller\Install(); $installer->run(); return; } // Load config from disk include $this->forum_env['FORUM_CONFIG_FILE']; if (isset($featherbb_config) && is_array($featherbb_config)) { $this->forum_settings = array_merge(self::load_default_forum_settings(), $featherbb_config); } else { $this->app->response->setStatus(500); // Send forbidden header return $this->app->response->setBody('Wrong config file format'); } // Init DB and configure Slim self::init_db($this->forum_settings, $this->forum_env['FEATHER_SHOW_INFO']); $this->app->config(array('debug' => $this->forum_env['FEATHER_DEBUG'], 'cookies.encrypt' => true, 'cookies.secret_key' => $this->forum_settings['cookie_seed'])); if (!$this->app->cache->isCached('config')) { $this->app->cache->store('config', \FeatherBB\Model\Cache::get_config()); } // Finalize forum_settings array $this->forum_settings = array_merge($this->app->cache->retrieve('config'), $this->forum_settings); // Set default style and assets $this->app->template->setStyle($this->forum_settings['o_default_style']); $this->app->template->addAsset('js', 'style/themes/FeatherBB/phone.min.js'); // Populate FeatherBB Slim object with forum_settings vars $this->hydrate('forum_settings', $this->forum_settings); $this->app->config = $this->forum_settings; // Legacy extract($this->forum_settings); // Legacy // Run activated plugins self::loadPlugins(); // Define time formats $forum_time_formats = array($this->forum_settings['o_time_format'], 'H:i:s', 'H:i', 'g:i:s a', 'g:i a'); $forum_date_formats = array($this->forum_settings['o_date_format'], 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y'); // Call FeatherBBAuth middleware $this->next->call(); }
public function update_options() { $form = array('board_title' => Utils::trim($this->request->post('form_board_title')), 'board_desc' => Utils::trim($this->request->post('form_board_desc')), 'base_url' => Utils::trim($this->request->post('form_base_url')), 'default_timezone' => floatval($this->request->post('form_default_timezone')), 'default_dst' => $this->request->post('form_default_dst') != '1' ? '0' : '1', 'default_lang' => Utils::trim($this->request->post('form_default_lang')), 'default_style' => Utils::trim($this->request->post('form_default_style')), 'time_format' => Utils::trim($this->request->post('form_time_format')), 'date_format' => Utils::trim($this->request->post('form_date_format')), 'timeout_visit' => intval($this->request->post('form_timeout_visit')) > 0 ? intval($this->request->post('form_timeout_visit')) : 1, 'timeout_online' => intval($this->request->post('form_timeout_online')) > 0 ? intval($this->request->post('form_timeout_online')) : 1, 'redirect_delay' => intval($this->request->post('form_redirect_delay')) >= 0 ? intval($this->request->post('form_redirect_delay')) : 0, 'show_version' => $this->request->post('form_show_version') != '1' ? '0' : '1', 'show_user_info' => $this->request->post('form_show_user_info') != '1' ? '0' : '1', 'show_post_count' => $this->request->post('form_show_post_count') != '1' ? '0' : '1', 'smilies' => $this->request->post('form_smilies') != '1' ? '0' : '1', 'smilies_sig' => $this->request->post('form_smilies_sig') != '1' ? '0' : '1', 'make_links' => $this->request->post('form_make_links') != '1' ? '0' : '1', 'topic_review' => intval($this->request->post('form_topic_review')) >= 0 ? intval($this->request->post('form_topic_review')) : 0, 'disp_topics_default' => intval($this->request->post('form_disp_topics_default')), 'disp_posts_default' => intval($this->request->post('form_disp_posts_default')), 'indent_num_spaces' => intval($this->request->post('form_indent_num_spaces')) >= 0 ? intval($this->request->post('form_indent_num_spaces')) : 0, 'quote_depth' => intval($this->request->post('form_quote_depth')) > 0 ? intval($this->request->post('form_quote_depth')) : 1, 'quickpost' => $this->request->post('form_quickpost') != '1' ? '0' : '1', 'users_online' => $this->request->post('form_users_online') != '1' ? '0' : '1', 'censoring' => $this->request->post('form_censoring') != '1' ? '0' : '1', 'signatures' => $this->request->post('form_signatures') != '1' ? '0' : '1', 'show_dot' => $this->request->post('form_show_dot') != '1' ? '0' : '1', 'topic_views' => $this->request->post('form_topic_views') != '1' ? '0' : '1', 'quickjump' => $this->request->post('form_quickjump') != '1' ? '0' : '1', 'gzip' => $this->request->post('form_gzip') != '1' ? '0' : '1', 'search_all_forums' => $this->request->post('form_search_all_forums') != '1' ? '0' : '1', 'additional_navlinks' => Utils::trim($this->request->post('form_additional_navlinks')), 'feed_type' => intval($this->request->post('form_feed_type')), 'feed_ttl' => intval($this->request->post('form_feed_ttl')), 'report_method' => intval($this->request->post('form_report_method')), 'mailing_list' => Utils::trim($this->request->post('form_mailing_list')), 'avatars' => $this->request->post('form_avatars') != '1' ? '0' : '1', 'avatars_dir' => Utils::trim($this->request->post('form_avatars_dir')), 'avatars_width' => intval($this->request->post('form_avatars_width')) > 0 ? intval($this->request->post('form_avatars_width')) : 1, 'avatars_height' => intval($this->request->post('form_avatars_height')) > 0 ? intval($this->request->post('form_avatars_height')) : 1, 'avatars_size' => intval($this->request->post('form_avatars_size')) > 0 ? intval($this->request->post('form_avatars_size')) : 1, 'admin_email' => strtolower(Utils::trim($this->request->post('form_admin_email'))), 'webmaster_email' => strtolower(Utils::trim($this->request->post('form_webmaster_email'))), 'forum_subscriptions' => $this->request->post('form_forum_subscriptions') != '1' ? '0' : '1', 'topic_subscriptions' => $this->request->post('form_topic_subscriptions') != '1' ? '0' : '1', 'smtp_host' => Utils::trim($this->request->post('form_smtp_host')), 'smtp_user' => Utils::trim($this->request->post('form_smtp_user')), 'smtp_ssl' => $this->request->post('form_smtp_ssl') != '1' ? '0' : '1', 'regs_allow' => $this->request->post('form_regs_allow') != '1' ? '0' : '1', 'regs_verify' => $this->request->post('form_regs_verify') != '1' ? '0' : '1', 'regs_report' => $this->request->post('form_regs_report') != '1' ? '0' : '1', 'rules' => $this->request->post('form_rules') != '1' ? '0' : '1', 'rules_message' => Utils::trim($this->request->post('form_rules_message')), 'default_email_setting' => intval($this->request->post('form_default_email_setting')), 'announcement' => $this->request->post('form_announcement') != '1' ? '0' : '1', 'announcement_message' => Utils::trim($this->request->post('form_announcement_message')), 'maintenance' => $this->request->post('form_maintenance') != '1' ? '0' : '1', 'maintenance_message' => Utils::trim($this->request->post('form_maintenance_message'))); $form = $this->hook->fire('options.update_options.form', $form); if ($form['board_title'] == '') { throw new Error(__('Must enter title message'), 400); } // Make sure base_url doesn't end with a slash if (substr($form['base_url'], -1) == '/') { $form['base_url'] = substr($form['base_url'], 0, -1); } // Convert IDN to Punycode if needed if (preg_match('/[^\\x00-\\x7F]/', $form['base_url'])) { if (!function_exists('idn_to_ascii')) { throw new Error(__('Base URL problem'), 400); } else { $form['base_url'] = idn_to_ascii($form['base_url']); } } $languages = \FeatherBB\Core\Lister::getLangs(); if (!in_array($form['default_lang'], $languages)) { throw new Error(__('Bad request'), 404); } $styles = \FeatherBB\Core\Lister::getStyles(); if (!in_array($form['default_style'], $styles)) { throw new Error(__('Bad request'), 404); } if ($form['time_format'] == '') { $form['time_format'] = 'H:i:s'; } if ($form['date_format'] == '') { $form['date_format'] = 'Y-m-d'; } if (!$this->email->is_valid_email($form['admin_email'])) { throw new Error(__('Invalid e-mail message'), 400); } if (!$this->email->is_valid_email($form['webmaster_email'])) { throw new Error(__('Invalid webmaster e-mail message'), 400); } if ($form['mailing_list'] != '') { $form['mailing_list'] = strtolower(preg_replace('%\\s%S', '', $form['mailing_list'])); } // Make sure avatars_dir doesn't end with a slash if (substr($form['avatars_dir'], -1) == '/') { $form['avatars_dir'] = substr($form['avatars_dir'], 0, -1); } if ($form['additional_navlinks'] != '') { $form['additional_navlinks'] = Utils::trim(Utils::linebreaks($form['additional_navlinks'])); } // Change or enter a SMTP password if ($this->request->post('form_smtp_change_pass')) { $smtp_pass1 = $this->request->post('form_smtp_pass1') ? Utils::trim($this->request->post('form_smtp_pass1')) : ''; $smtp_pass2 = $this->request->post('form_smtp_pass2') ? Utils::trim($this->request->post('form_smtp_pass2')) : ''; if ($smtp_pass1 == $smtp_pass2) { $form['smtp_pass'] = $smtp_pass1; } else { throw new Error(__('SMTP passwords did not match'), 400); } } if ($form['announcement_message'] != '') { $form['announcement_message'] = Utils::linebreaks($form['announcement_message']); } else { $form['announcement_message'] = __('Enter announcement here'); $form['announcement'] = '0'; } if ($form['rules_message'] != '') { $form['rules_message'] = Utils::linebreaks($form['rules_message']); } else { $form['rules_message'] = __('Enter rules here'); $form['rules'] = '0'; } if ($form['maintenance_message'] != '') { $form['maintenance_message'] = Utils::linebreaks($form['maintenance_message']); } else { $form['maintenance_message'] = __('Default maintenance message'); $form['maintenance'] = '0'; } // Make sure the number of displayed topics and posts is between 3 and 75 if ($form['disp_topics_default'] < 3) { $form['disp_topics_default'] = 3; } elseif ($form['disp_topics_default'] > 75) { $form['disp_topics_default'] = 75; } if ($form['disp_posts_default'] < 3) { $form['disp_posts_default'] = 3; } elseif ($form['disp_posts_default'] > 75) { $form['disp_posts_default'] = 75; } if ($form['feed_type'] < 0 || $form['feed_type'] > 2) { throw new Error(__('Bad request'), 400); } if ($form['feed_ttl'] < 0) { throw new Error(__('Bad request'), 400); } if ($form['report_method'] < 0 || $form['report_method'] > 2) { throw new Error(__('Bad request'), 400); } if ($form['default_email_setting'] < 0 || $form['default_email_setting'] > 2) { throw new Error(__('Bad request'), 400); } if ($form['timeout_online'] >= $form['timeout_visit']) { throw new Error(__('Timeout error message'), 400); } foreach ($form as $key => $input) { // Only update values that have changed if (array_key_exists('o_' . $key, $this->config) && $this->config['o_' . $key] != $input) { if ($input != '' || is_int($input)) { DB::for_table('config')->where('conf_name', 'o_' . $key)->update_many('conf_value', $input); } else { DB::for_table('config')->where('conf_name', 'o_' . $key)->update_many_expr('conf_value', 'NULL'); } } } // Regenerate the config cache $this->feather->cache->store('config', Cache::get_config()); $this->clear_feed_cache(); Url::redirect($this->feather->urlFor('adminOptions'), __('Options updated redirect')); }
public function set_default_group($groups) { $group_id = intval($this->request->post('default_group')); $group_id = $this->hook->fire('set_default_group.group_id', $group_id); // Make sure it's not the admin or guest groups if ($group_id == $this->feather->forum_env['FEATHER_ADMIN'] || $group_id == $this->feather->forum_env['FEATHER_GUEST']) { throw new Error(__('Bad request'), 404); } // Make sure it's not a moderator group if ($groups[$group_id]['g_moderator'] != 0) { throw new Error(__('Bad request'), 404); } DB::for_table('config')->where('conf_name', 'o_default_user_group')->update_many('conf_value', $group_id); // Regenerate the config cache $this->feather->cache->store('config', Cache::get_config()); Url::redirect($this->feather->urlFor('adminGroups'), __('Default group redirect')); }