diff options
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/acm/acm_memcache.php | 2 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_gym_sitemaps.php | 1255 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_phpbb_seo.php | 1140 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_profile.php | 2 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_update.php | 31 | ||||
-rw-r--r-- | phpBB/includes/acp/info/acp_gym_sitemaps.php | 39 | ||||
-rw-r--r-- | phpBB/includes/acp/info/acp_phpbb_seo.php | 37 | ||||
-rw-r--r-- | phpBB/includes/auth/auth_ldap.php | 8 | ||||
-rw-r--r-- | phpBB/includes/constants.php | 2 | ||||
-rw-r--r-- | phpBB/includes/db/dbal.php | 6 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 116 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 12 | ||||
-rw-r--r-- | phpBB/includes/functions_content.php | 43 | ||||
-rw-r--r-- | phpBB/includes/functions_display.php | 138 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 32 | ||||
-rw-r--r-- | phpBB/includes/search/fulltext_native.php | 20 | ||||
-rw-r--r-- | phpBB/includes/session.php | 8 | ||||
-rw-r--r-- | phpBB/includes/utf/utf_tools.php | 51 |
18 files changed, 2865 insertions, 77 deletions
diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php index e54fa36c38..f61f0a039e 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/acm/acm_memcache.php @@ -135,4 +135,4 @@ class acm extends acm_memory } } -?> +?>
\ No newline at end of file diff --git a/phpBB/includes/acp/acp_gym_sitemaps.php b/phpBB/includes/acp/acp_gym_sitemaps.php new file mode 100644 index 0000000000..a78ec9fbc0 --- /dev/null +++ b/phpBB/includes/acp/acp_gym_sitemaps.php @@ -0,0 +1,1255 @@ +<?php +/** +* +* @package phpBB SEO GYM Sitemaps +* @version $Id: acp_gym_sitemaps.php 272 2010-11-21 13:56:31Z dcz $ +* @copyright (c) 2006 - 2010 www.phpbb-seo.com +* @license http://opensource.org/osi3.0/licenses/lgpl-license.php GNU Lesser General Public License +* +*/ +/** +* phpBB_SEO Class +* www.phpBB-SEO.com +* @package Advanced phpBB3 SEO mod Rewrite +*/ +class acp_gym_sitemaps { + var $u_action; + var $new_config = array(); + var $dyn_select = array(); + var $gym_config = array(); + var $gym_modules = array(); + var $gym_modules_acp = array(); + var $mode = 'gym'; + var $modes = array(); + var $module = 'gym'; + var $action = 'main'; + var $maction = ''; + var $support_link = array(); + var $override = array(); + var $override_type = array(); + var $array_type_cfg = array(); + var $multiple_options = array(); + var $modrtype_lang = array(); + var $write_type = 'forum'; + var $lengh_limit = 20; + var $word_limit = 3; + var $seo_unset_opts = array(); + + /** + * Constructor + */ + function main($id, $mode) { + global $config, $db, $user, $auth, $template, $cache; + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $phpbb_seo, $_action_types; + require_once($phpbb_root_path . 'gym_sitemaps/includes/gym_common.' . $phpEx); + // Start the phpbb_seo class + if ( !is_object($phpbb_seo) ) { + if ( file_exists($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.' . $phpEx)) { + require_once($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.' . $phpEx); + } else { + require_once($phpbb_root_path . 'gym_sitemaps/includes/phpbb_seo_class_light.' . $phpEx); + } + $phpbb_seo = new phpbb_seo(); + } + $user->add_lang('gym_sitemaps/acp/gym_common'); + // action=(module|cache|modrewrite...)&module=(main|forum| ...) + $action = request_var('action', 'main'); + $module = request_var('module', 'main'); + // maction =(settings|maintenance|save)&action=(module|cache|modrewrite...)&module=(main|forum| ...) + $maction = request_var('maction', ''); + $mactions = array('settings', 'maintenance', 'install'); + $maction = in_array($maction, $mactions) ? $maction : ''; + $submit = (isset($_POST['submit'])) ? true : false; + $this->modes = $_action_types; + $this->override_type = $_override_types; + $this->override = array(); + // Filter allowed modes + $this->mode = $mode; + $this->module = $module; + $this->action = $action; + $this->maction = $maction; + $this->set_phpbb_seo_links(); + // Get gym config + obtain_gym_config('main', $this->gym_config); + $this->new_config = $this->gym_config; + // define common validation arrays + $this->dyn_select['modrtype'] = array( 0 => 'GYM_MODREWRITE_NONE', 1 => 'GYM_MODREWRITE_SIMPLE', 2 => 'GYM_MODREWRITE_MIXED', 3 => 'GYM_MODREWRITE_ADVANCED'); + $this->dyn_select['gzip_level'] = array( 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9); + $this->dyn_select['sort'] = array( 'DESC' => 'GYM_DESC', 'ASC' => 'GYM_ASC'); + $this->dyn_select['override'] = array( OVERRIDE_GLOBAL => 'GYM_OVERRIDE_GLOBAL', OVERRIDE_OTYPE => 'GYM_OVERRIDE_OTYPE', OVERRIDE_MODULE => 'GYM_OVERRIDE_MODULE'); + $this->dyn_select['sumarize_method'] = array( 'chars' => 'GYM_METHOD_CHARS', 'words' => 'GYM_METHOD_WORDS', 'lines' => 'GYM_METHOD_LINES'); + $this->dyn_select['gym_auth'] = array( + 'admin' => 'GYM_AUTH_ADMIN', + 'globalmod' => 'GYM_AUTH_GLOBALMOD', + 'reg' => 'GYM_AUTH_REG', + 'guest' => 'GYM_AUTH_GUEST', + 'all' => 'GYM_AUTH_ALL', + 'none' => 'GYM_AUTH_NONE', + ); + $this->dyn_select['rss_linking_types'] = array('n' => 'RSS_LINKING_NEWS', 'nd' => 'RSS_LINKING_NEWS_DIGEST', 'r' => 'RSS_LINKING_REGULAR', 'rd' => 'RSS_LINKING_REGULAR_DIGEST'); + // Get the module list + // Populate the $this->gym_modules[$mode][$module] array + $this->gym_get_modules($mode); + // Load the relevant modules acp options + // Populate the $this->gym_modules_acp[$mode][$module] array + $this->gym_module_acp($mode, $module); + // Acp options array for this case + $display_vars = $error = array(); + // salt the form + $form_key = 'acp_gym'; + add_form_key($form_key); + // check form salt + if ($submit && !check_form_key($form_key)) { + $error[] = $user->lang['FORM_INVALID']; + $submit = false; + } + // Cache management + if ($maction === 'maintenance') { + $display_vars = $this->gym_maintenance( $mode, $module, $action, $submit ); + $submit = false; + } elseif ($maction === 'settings') { // settings management + $display_vars = $this->gym_set_default( $mode, $module, $action, $submit ); + $submit = false; + } elseif ($maction === 'install') { // module install + $display_vars = $this->gym_install( $mode, $module, $action, $submit ); + $submit = false; + } else { + if ( !in_array($mode, $this->modes) || !in_array($module, $this->gym_modules[$mode])) { + trigger_error('NO_MODE', E_USER_ERROR); + } else { + $script_to_check = array(); + if (empty($this->gym_modules_acp[$mode][$module][$action]['display_vars'])) { + $action = $this->action = 'main'; + } + // here we'll check if the GYM script urls are consistent + if (!$submit) { + $this->check_scripts($error, $this->gym_config, $mode); + } + $display_vars = $this->gym_modules_acp[$mode][$module][$action]['display_vars']; + // Check if we do not have a new module needing a new config key + $clear_cache = false; + foreach ($display_vars['vars'] as $key => $value) { + if (!isset($this->gym_config[$key]) && strpos($key, 'legend') === false) { + $clear_cache = true; + if(isset($this->gym_modules_acp[$mode][$module][$action]['default'][$key])) { + $this->new_config[$key] = $this->gym_modules_acp[$mode][$module][$action]['default'][$key]; + set_gym_config($key, $this->new_config[$key], $mode, $this->gym_config); + } + } + } + if ($clear_cache) { + $this->remove_cache('config'); + } + } + } + // Load the module's language files + foreach ($this->gym_modules_acp[$mode] as $active_modules => $null) { + if (!empty($this->gym_modules_acp[$mode][$active_modules]['info']['lang_file'])) { + $user->add_lang('gym_sitemaps/acp/' . $this->gym_modules_acp[$mode][$active_modules]['info']['lang_file']); + } + } + $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config; + // We validate the complete config if whished + validate_config_vars($display_vars['vars'], $cfg_array, $error); + + // check script urls if necessary + if ($submit && isset($cfg_array[$mode . '_url'])) { + // will enforce trailing slashes automatically + $this->check_scripts($error, $cfg_array, $mode); + } + // Do not write values if there is an error + if (sizeof($error)) { + $submit = false; + } + // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... + foreach ($display_vars['vars'] as $config_name => $cfg_setup) { + if ( (!isset($cfg_array[$config_name]) && @$cfg_setup['method'] != 'select_multiple_string') || strpos($config_name, 'legend') !== false) { + continue; + } + // Handle multiple select options + if (!empty($cfg_setup['method']) && $cfg_setup['method'] == 'select_multiple_string') { + if (isset($_POST['multiple_' . $config_name])) { + $m_values = utf8_normalize_nfc(request_var('multiple_' . $config_name, array('' => ''))); + $validate_int = $cfg_setup['multiple_validate'] == 'int' ? true : false; + foreach($m_values as $k => $v) { + if ($validate_int) { + $v = (int) $v; + } + if (empty($v)) { + unset($m_values[$k]); + } else { + $m_values[$k] = $v; + } + } + sort($m_values); + $this->new_config[$config_name] = $m_values; + $config_value = implode(',', $m_values); + if ( strlen($config_value) > 255 ) { + $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$cfg_setup['lang']], 255); + } + $submit = empty($error); + } else { + if ($submit) { + $this->new_config[$config_name] = array(); + $config_value = ''; + } else { + $config_value = $this->new_config[$config_name]; + $this->new_config[$config_name] = !empty($config_value) ? explode(',', $config_value) : array(); + } + } + } else { + $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; + } + if ($submit) { + set_gym_config($config_name, $config_value, $mode, $this->gym_config); + } + } + if ($submit) { + $this->remove_cache('config'); + add_log('admin', 'GYM_LOG_CONFIG_' . strtoupper($mode)); + trigger_error($user->lang['CONFIG_UPDATED'] . $this->back_to_prev()); + } + $this->tpl_name = 'acp_gym_sitemaps'; + $this->page_title = $display_vars['title']; + // add the maitenance links + $maintenance_links = ''; + $maintenance_links .= '<a href="' . $this->u_action . '&maction=maintenance&action=' . $action . '&module=' . $module . '"><b style="color:red;">' . $user->lang['GYM_MAINTENANCE'] . '</b></a><b> • </b>'; + $maintenance_links .= '<a href="' . $this->u_action . '&maction=settings&action=' . $action . '&module=' . $module . '"><b style="color:red;">' . $user->lang['GYM_SETTINGS'] . '</b></a>'; + $install_link = ($mode !== 'main') ? '<b> • </b><a href="' . $this->u_action . '&maction=install&action=' . $action . '&module=' . $module . '"><b style="color:red;">' . $user->lang['GYM_INSTALL'] . '</b></a>' : ''; + if ($action === 'gzip') { + // Adjust language variable a bit + $user->lang['GYM_GZIP_EXPLAIN'] = sprintf( $user->lang['GYM_GZIP_EXPLAIN'], ($config['gzip_compress'] ? $user->lang['GYM_GZIP_FORCED'] : $user->lang['GYM_GZIP_CONFIGURABLE']) ); + } + $lang_key = 'GYM_' . strtoupper($mode); + $l_mode_title = $this->safe_lang($lang_key); + $l_mode_title_explain = $this->safe_lang($lang_key . '_EXPLAIN'); + $lang_key = $this->gym_modules_acp[$mode][$module]['info']['title_lang']; + $l_module_title = $this->safe_lang($lang_key); + $l_module_title_explain = $this->safe_lang($lang_key . '_EXPLAIN'); + $l_title = $this->safe_lang($display_vars['title']); + $l_title_explain = $this->safe_lang($display_vars['title'] . '_EXPLAIN'); + $l_title_explain .= ($action === 'cache' && $mode !== 'html') ? $this->check_cache_folder($phpbb_root_path . 'gym_sitemaps/cache') : ''; + $template->assign_vars(array( + 'L_MODE_TITLE' => $l_mode_title, + 'L_MODE_ITLE_EXPLAIN' => $l_mode_title_explain, + 'L_MODULE_TITLE' => $l_module_title, + 'L_MODULE_ITLE_EXPLAIN' => $l_module_title_explain, + 'L_TITLE' => $l_title, + 'L_TITLE_EXPLAIN' => $l_title_explain, + 'GYM_VERSION' => $this->gym_config['gym_version'], + 'INSTALL_LINK' => $install_link, + 'MAINTENANCE_LINKS' => $maintenance_links, + 'S_ERROR' => (sizeof($error)) ? true : false, + 'ERROR_MSG' => implode('<br />', $error), + 'S_SUBMIT_BUTTON' => !empty($this->gym_modules_acp[$mode][$module][$action]['default']), + 'U_ACTION' => $this->u_action . '&maction=' . $maction . '&action=' . $action . '&module=' . $module) + ); + + $this->gym_module_menu( $mode, $module, $action ); + + $this->gym_menu( $mode, $module, $action ); + // Output relevant page + foreach ($display_vars['vars'] as $config_key => $vars) { + if (!is_array($vars) && strpos($config_key, 'legend') === false) { + continue; + } + if (strpos($config_key, 'legend') !== false) { + $template->assign_block_vars('options', array( + 'S_LEGEND' => true, + 'LEGEND' => $this->safe_lang($vars)) + ); + continue; + } + $type = explode(':', $vars['type']); + $l_explain = ''; + if ($vars['explain'] && isset($vars['lang_explain'])) { + $l_explain = $this->safe_lang($vars['lang_explain']); + } elseif ($vars['explain']) { + $l_explain = $this->safe_lang($vars['lang'] . '_EXPLAIN'); + } + // Add overriding infos + $form = true; + if (isset($vars['overriding']) && $vars['overriding']) { + $vars['append'] = $this->is_overriden($mode, $module, $action, $config_key, $vars); + //$form = $vars['append'] == $this->safe_lang('GYM_COULD_OVERRIDE') ? true : false; + } + $content = ''; + $template->assign_block_vars('options', array( + 'KEY' => $config_key, + 'TITLE' => $this->safe_lang($vars['lang']), + 'S_EXPLAIN' => $vars['explain'], + 'TITLE_EXPLAIN' => $l_explain, + 'CONTENT' => $form ? build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars) : $vars['append'], + ) + ); + unset($display_vars['vars'][$config_key]); + } + } + /** + * gym_get_modules($mode). + * Populates $this->gym_modules[$mode][$module] + * with the acp modules list + */ + function gym_get_modules($mode) { + global $cache, $phpEx, $phpbb_root_path; + if (($this->gym_modules[$mode] = $cache->get('_gym_modules_' . $mode)) === false) { + $this->gym_modules[$mode] = array(); + $dir = @opendir( $phpbb_root_path . 'gym_sitemaps/acp' ); + while( ($file = @readdir($dir)) !== FALSE ) { + if(preg_match('`^' . $mode . '_([a-z0-9_-]+)\.' . $phpEx . '$`i', $file, $matches)) { + $module = trim(str_replace( $mode . '_', '' , str_replace('.' . $phpEx , '' ,$file)), "/"); + if ($matches[1] == 'main' || (file_exists($phpbb_root_path . 'gym_sitemaps/modules/' . $file) && !empty($this->gym_config[$mode . '_' . $module . '_installed'])) ) { + $this->gym_modules[$mode][$module] = $module; + } + } + } + @closedir($dir); + // Reorder a bit, put the main panel at the first position, others will keep + // the file system sorting + if (!empty($this->gym_modules[$mode]['main'])) { + $main = $this->gym_modules[$mode]['main']; + unset($this->gym_modules[$mode]['main']); + $this->gym_modules[$mode] = array('main' => $main) + $this->gym_modules[$mode]; + + } + $cache->put('_gym_modules_' . $mode, $this->gym_modules[$mode]); + } + if (!is_array($this->gym_modules[$mode]) || empty($this->gym_modules[$mode])) { + $this->remove_cache('acp', $mode); + } + } + /** + * gym_module_acp($mode, $module) + * loads acp module options in the $this->gym_modules_acp[$mode][$mode_module] array. + */ + function gym_module_acp($mode, $module) { + global $phpbb_root_path, $phpEx, $cache; + if (is_array($this->gym_modules[$mode]) && ($this->gym_modules_acp[$mode] = $cache->get('_gym_acp_' . $mode)) === false) { + foreach ($this->gym_modules[$mode] as $mode_module) { + $this->gym_pick_module($mode, $mode_module, $this->gym_modules_acp); + } + $cache->put('_gym_acp_' . $mode, $this->gym_modules_acp[$mode]); + } + if (!@is_array($this->gym_modules_acp[$mode]) || empty($this->gym_modules_acp[$mode])) { + $this->remove_cache('acp', $mode); + } + } + /** + * gym_pick_module( $mode, $module, $action) + * pick a given module data + */ + function gym_pick_module( $mode, $mode_module, &$return_array) { + global $phpbb_root_path, $phpEx; + $module_class = $mode . '_' . $mode_module; + $module_file = $phpbb_root_path . 'gym_sitemaps/acp/' . $module_class . '.' . $phpEx; + if ( file_exists($module_file) ) { + include_once($module_file); + if (class_exists($module_class)) { + $gym_module = new $module_class($this); + if ( method_exists($gym_module, 'acp_module')) { + $return_array[$mode][$mode_module] = $gym_module->acp_module(); + } + } + } + } + /** + * gym_menu( $mode, $module, $action) + * Builds the module action links + */ + function gym_menu( $mode, $module, $action) { + global $template, $user; + foreach ($this->gym_modules_acp[$mode][$module]['info']['actions'] as $module_action) { + $template->assign_block_vars('menu', array( + 'L_TITLE' => $this->safe_lang($this->gym_modules_acp[$mode][$module][$module_action]['display_vars']['title']), + 'S_SELECTED' => $action == $module_action ? true : false, + 'U_TITLE' => $this->u_action . '&action=' . $module_action . '&module=' . $module, + )); + } + $template->assign_vars(array('S_MENU' => empty($this->maction))); + return; + } + /** + * gym_module_menu( $mode, $module, $action) + * builds the module ACP links + */ + function gym_module_menu( $mode, $module, $action ) { + global $template, $user; + foreach ($this->gym_modules_acp[$mode] as $modules) { + $template->assign_block_vars('menu_module', array( + 'L_TITLE' => $this->safe_lang($modules['info']['title_lang']), + 'S_SELECTED' => ($module == @$modules['info']['module'] && $this->maction !== 'install') ? true : false, + 'U_TITLE' => $this->u_action . '&module=' . @$modules['info']['module'] . (!empty($action) ? "&action=$action" : ''), + )); + } + $template->assign_vars(array('S_MENU' => true)); + $template->assign_vars(array('S_MENU_MODULE' => true)); + return; + } + /** + * gym_install( $mode, $module, $action, $submit = false ) + * handle module install / un-install + */ + function gym_install( $mode, $module, $action, $submit = false ) { + global $user, $phpEx, $phpbb_root_path; + $post_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : array(); + if ($submit) { + $un_install = $install = array(); + foreach ($this->gym_modules[$mode] as $_module) { // check if we need to uninstall + $type_module = $mode . '_' . $_module; + if (isset($post_array[$type_module]) && !$post_array[$type_module] && !empty($this->gym_config[$type_module . '_installed'])) { // Uninstall + $un_install[$mode][$_module] = $type_module; + } + } + $dir = @opendir( $phpbb_root_path . 'gym_sitemaps/acp' ); + while( ($file = @readdir($dir)) !== false ) { // check if we need to install + if(preg_match('`^' . $mode . '_([a-z0-9_-]+)\.' . $phpEx . '$`i', $file, $matches)) { + $type_module = trim(str_replace('.' . $phpEx , '' ,$file), "/"); + $_module = str_replace($mode . '_', '', $type_module); + if ($matches[1] !== 'main' && file_exists($phpbb_root_path . 'gym_sitemaps/modules/' . $file) && !isset($this->gym_modules[$mode][$_module]) && !empty($post_array[$type_module])) { + $install[$mode][$_module] = $type_module; + } + } + } + // Now un-install + if (!empty($un_install)) { + foreach ($un_install[$mode] as $_module => $type_module) { + // In case we are uninstalling from this module + // we go back to main + if ($module == $this->module) { + $this->module = 'main'; + } + set_gym_config($type_module . '_installed', 0, 'main', $this->gym_config); + $this->gym_set_default( $mode, $_module, $action, true, true, true ); + } + } + // Now install + if (!empty($install)) { + foreach ($install[$mode] as $_module => $type_module) { + set_gym_config($type_module . '_installed', 1, 'main', $this->gym_config); + } + $this->remove_cache('config'); + $this->remove_cache('acp'); + $this->gym_get_modules($mode); + foreach ($install[$mode] as $_module => $type_module) { + $this->gym_set_default( $mode, $_module, $action, true, true ); + } + } + $this->remove_cache('config'); + $this->remove_cache('acp'); + trigger_error($user->lang['CONFIG_UPDATED'] . $this->back_to_prev()); + } + // Adjust language variable a bit + $user->lang['GYM_MODULE_INSTALL'] = sprintf($user->lang['GYM_MODULE_INSTALL'], $user->lang[strtoupper($mode)] ); + $user->lang['GYM_MODULE_INSTALL_EXPLAIN'] = sprintf($user->lang['GYM_MODULE_INSTALL_EXPLAIN'], $user->lang[strtoupper($mode)] ); + $display_vars = array( 'title' => 'GYM_MODULE_INSTALL'); + $display_vars['vars'] = array(); + $i = 1; + // Installed modules + $active = array(); + foreach ($this->gym_modules[$mode] as $_module) { + if ($_module !== 'main') { + $active[$mode][$_module] = $mode . '_' . $_module; + } + } + if (!empty($active)){ // Add the active module list + $display_vars['vars']['legend' . $i] = 'GYM_MODULES_INSTALLED'; + $i++; + foreach ($active[$mode] as $_module => $type_module) { // Installed modules + // Grabb the data + //$this->gym_module_acp($mode, $type_module); + $this->new_config[$type_module] = 1; + $display_vars['vars'][$type_module] = array('lang' => strtoupper($type_module), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false); + } + } + // now check if we have some module to install + $unactive = array(); + $dir = @opendir( $phpbb_root_path . 'gym_sitemaps/acp' ); + while( ($file = @readdir($dir)) !== FALSE ) { + if(preg_match('`^' . $mode . '_([a-z0-9_-]+)\.' . $phpEx . '$`i', $file, $matches)) { + $type_module = trim(str_replace('.' . $phpEx , '' ,$file), "/"); + $_module = str_replace($mode . '_', '', $type_module); + if ($matches[1] !== 'main' && file_exists($phpbb_root_path . 'gym_sitemaps/modules/' . $file) && !isset($this->gym_modules[$mode][$_module])) { + $unactive[$mode][$_module] = $type_module; + if ($_module != 'main' && !empty($this->gym_config[$type_module . '_installed'])) { + set_gym_config($type_module . '_installed', 0, 'main', $this->gym_config); + } + } + } + } + if (!empty($unactive)){ // Add the not active module list + $display_vars['vars']['legend' . $i] = 'GYM_MODULES_UNINSTALLED'; + $i++; + foreach ($unactive[$mode] as $_module => $type_module) { // Uninstalled modules + // Grabb the data + $this->gym_pick_module($mode, $_module, $module_data); + if (!empty($module_data[$mode][$_module]['info']['lang_file'])) { + $user->add_lang('gym_sitemaps/acp/' . $module_data[$mode][$_module]['info']['lang_file']); + } + $this->new_config[$type_module] = 0; + $display_vars['vars'][$type_module] = array('lang' => strtoupper($type_module), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false); + } + } + return $display_vars; + } + /** + * gym_set_default( $mode, $module, $action, $submit = false, $silent = false, $uninstall = false ) + * Set default values for modules + */ + function gym_set_default( $mode, $module, $action, $submit = false, $silent = false, $uninstall = false ) { + global $user, $phpbb_root_path, $phpEx; + $post_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : array(); + $this->new_config['reset_all'] = $reset_all = isset($post_array['reset_all']) ? $post_array['reset_all'] : false; + if ($silent) { + $reset_all = true; + } + if ($submit) { + if ($mode === 'main' ) { // Reset all seting for all output and all modules + foreach ($this->modes as $output_mode) { // List the output modes + $this->gym_get_modules($output_mode); + foreach ($this->gym_modules[$output_mode] as $type_module) { // List modules from each output mode + if (!empty($post_array[$output_mode . '_' . $type_module . '_reset']) || $reset_all) { + // Grabb the data + $this->gym_module_acp($output_mode, $type_module); + foreach($this->gym_modules_acp[$output_mode][$type_module]['info']['actions'] as $module_action) { + foreach ($this->gym_modules_acp[$output_mode][$type_module][$module_action]['default'] as $module_config => $default_value ) { // In the end list possible options for this module's option set + // Update config + if ($uninstall) { + rem_gym_config($module_config, $this->gym_config); + } else { + set_gym_config($module_config, $default_value, $output_mode, $this->gym_config); + } + } + } + } + } + } + } elseif ($module === 'main') { // Only looking for one output type modules + foreach ($this->gym_modules[$mode] as $type_module) { // add the output types modules + if (!empty($post_array[$mode . '_' . $type_module . '_reset']) || $reset_all) { + // Grabb the data + $this->gym_module_acp($mode, $type_module); + foreach($this->gym_modules_acp[$mode][$type_module]['info']['actions'] as $module_action) { + foreach ($this->gym_modules_acp[$mode][$type_module][$module_action]['default'] as $module_config => $default_value ) { + // Update config + if ($uninstall) { + rem_gym_config($module_config, $this->gym_config); + } else { + set_gym_config($module_config, $default_value, $mode, $this->gym_config); + } + } + } + } + } + } else { // Only reset this module config + $this->gym_module_acp($mode, $module); + // Allow modules with no acp + if (!empty($this->gym_modules_acp[$mode][$module]['info'])) { + foreach ($this->gym_modules_acp[$mode][$module]['info']['actions'] as $module_action ) { + foreach ($this->gym_modules_acp[$mode][$module][$module_action]['default'] as $module_config => $default_value ) { + if (!empty($post_array[$mode . '_' . $module . '_' . $module_action . '_reset']) || $reset_all) { + // Update config + if ($uninstall) { + rem_gym_config($module_config, $this->gym_config); + } else { + set_gym_config($module_config, $default_value, $mode, $this->gym_config); + } + } + } + } + } + } + $this->clear_all_cache(); + unset($post_array); + if (!$silent) { + trigger_error($user->lang['CONFIG_UPDATED'] . $this->back_to_prev()); + } else { + return; + } + } + // Adjust language variable a bit + $user->lang['GYM_RESET'] = sprintf($user->lang['GYM_RESET'], $user->lang[strtoupper($mode)] ); + $user->lang['GYM_RESET_EXPLAIN'] = sprintf($user->lang['GYM_RESET_EXPLAIN'], $user->lang[strtoupper($mode)] ); + $display_vars = array( 'title' => 'GYM_RESET'); + $i = 1; + if ($mode === 'main' ) { // Reset all seting for all output and all modules + foreach ($this->modes as $output_mode) { // List the output types modules + $this->gym_get_modules($output_mode); + $display_vars['vars']['legend' . $i] = strtoupper($output_mode); + $i++; + foreach ($this->gym_modules[$output_mode] as $type_module) { // Then the modules + // Grabb the data + $this->gym_module_acp($output_mode, $type_module); + // Then the associated language files if any + if (!empty($this->gym_modules_acp[$output_mode][$type_module]['info']['lang_file'])) { + $user->add_lang('gym_sitemaps/acp/' . $this->gym_modules_acp[$output_mode][$type_module]['info']['lang_file']); + } + $var_key = $output_mode . '_' . $type_module . '_reset'; + $this->new_config[$var_key] = 0; + $display_vars['vars'][$var_key] = array('lang' => strtoupper($var_key), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); + } + } + } elseif ($module === 'main') { // Only looking for one output type modules + + foreach ($this->gym_modules[$mode] as $type_module) { // add the output types modules + // Grabb the data + $this->gym_module_acp($mode, $type_module); + $display_vars['vars']['legend' . $i] = strtoupper($mode . '_' . $type_module); + $i++; + $var_key = $mode . '_' . $type_module . '_reset'; + $this->new_config[$var_key] = 0; + $display_vars['vars'][$var_key] = array('lang' => strtoupper($var_key), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); + } + } else { // Only reset this module config + $this->gym_module_acp($mode, $module); + $display_vars['vars']['legend' . $i] = strtoupper($mode . '_' . $module) . '_RESET'; + $i++; + // Grabb the data + foreach ($this->gym_modules_acp[$mode][$module]['info']['actions'] as $module_action ) { + if (!empty($this->gym_modules_acp[$mode][$module][$module_action]['display_vars']['vars'])) { + $var_key = $mode . '_' . $module . '_' . $module_action . '_reset'; + $this->new_config[$var_key] = 0; + $display_vars['vars'][$var_key] = array('lang' => strtoupper($var_key), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); + } + } + } + $display_vars['vars']['legend' . $i] = 'GYM_RESET_ALL'; + $i++; + $display_vars['vars']['reset_all'] = array('lang' => 'GYM_RESET_ALL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); + return $display_vars; + } + /** + * gym_maintenance( $mode, $module, $action, $submit = false ) + * handle cache (data + module's cache) clearing + */ + function gym_maintenance( $mode, $module, $action, $submit = false ) { + global $user, $phpbb_root_path, $phpEx; + $post_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : array(); + $this->new_config['cache_action'] = $cache_action = isset($post_array['cache_action']) ? $post_array['cache_action'] : 'all'; + $this->new_config['acp_modules'] = $acp_modules = isset($post_array['acp_modules']) ? $post_array['acp_modules'] : false; + unset($post_array); + $regexes = array( 'all' => '[a-z0-9_-]+', 'google' => 'google_', 'rss' => 'rss_', /*'html' => 'html_', 'yahoo' => 'yahoo_'*/); + + $cache_dir = $phpbb_root_path . 'gym_sitemaps/cache/'; + $cache_regex = $style_regex = $regexes['all']; + if ($cache_action == 'all') { + if ($mode != 'main') { + $cache_regex = $style_regex = $mode . '_'; + } + } else { + if ($mode != 'main') { // we are at the output type level + $cache_regex = $style_regex = $mode . '_'; + $cache_regex .= $cache_action . '_'; + } else { // At the global level, we only can delete complete output type cache at once + $cache_regex = isset($regexes[$cache_action]) ? $regexes[$cache_action] : $regexes['all']; + + } + } + if ($submit) { + $message = ''; + if ($acp_modules) { + $this->remove_cache('acp', $cache_action); + $message = $user->lang['MODULE_CACHE_CLEARED'] . '<br/><br/>'; + } + $accessed = false; + $deleted = ''; + $res = opendir($cache_dir); + if($res) { + $num_del = 0; + while(($file = readdir($res))) { + // includes CSS and XSL cache + if(preg_match('`^(style_' . $style_regex . '|' . $cache_regex . ')[a-z0-9_-]+\.(xml|xml\.gz|css|xsl)$`i', $file)) { + @unlink($cache_dir . $file); + $deleted .= "<li>$file</li>"; + $num_del++; + } + } + $accessed = true; + } + closedir($res); + if ($accessed) { + if ($deleted !='') { + $message .= $user->lang['GYM_CACHE_CLEARED'] . $cache_dir . '<br/><br/>'; + $message .= '<div align="left">' . $user->lang['GYM_FILE_CLEARED'] . " $num_del<ul>$deleted</ul></div>"; + } else { + $message .= $user->lang['GYM_CACHE_ACCESSED'] . $cache_dir; + } + } else { + $message .= $user->lang['GYM_CACHE_NOT_CLEARED'] . $cache_dir; + } + trigger_error($message . $this->back_to_prev()); + } + // Clear cache type + if ($mode === 'main') { + $cache_actions = array( 'gym' => $user->lang['ALL'], 'google' => $user->lang['GOOGLE'], 'rss' => $user->lang['RSS'], /*'yahoo' => $user->lang['YAHOO'], 'html' => $user->lang['HTML']*/); + } else { + $cache_actions = array(); + foreach ($this->gym_modules[$mode] as $mode_module) { + if ($mode_module === 'main') { + if ($module !== 'main') { + continue; + } + $mode_module = 'all'; + } + if (!empty($this->gym_modules_acp[$mode][$mode_module]['info']['lang_file'])) { + $user->add_lang('gym_sitemaps/acp/' . $this->gym_modules_acp[$mode][$mode_module]['info']['lang_file']); + } + $cache_actions[$mode_module] = $this->safe_lang(strtoupper($mode . '_' . $mode_module . '_reset')); + } + } + $this->gym_modules_acp[$this->mode][$this->module][$this->action]['select']['cache_action'] = $cache_actions; + // Adjust language variable a bit + $user->lang['GYM_MODULE_MAINTENANCE'] = sprintf($user->lang['GYM_CLEAR_CACHE'], $user->lang[strtoupper($mode)] ); + $user->lang['GYM_MODULE_MAINTENANCE_EXPLAIN'] = sprintf($user->lang['GYM_MODULE_MAINTENANCE_EXPLAIN'], $user->lang[strtoupper($mode)] ); + $user->lang['GYM_CLEAR_CACHE'] = sprintf($user->lang['GYM_CLEAR_CACHE'], $user->lang[strtoupper($mode)] ); + $user->lang['GYM_CLEAR_CACHE_EXPLAIN'] = sprintf($user->lang['GYM_CLEAR_CACHE_EXPLAIN'], $user->lang[strtoupper($mode)] ); + $user->lang['GYM_CLEAR_ACP_CACHE'] = sprintf($user->lang['GYM_CLEAR_ACP_CACHE'], $user->lang[strtoupper($mode)] ); + $user->lang['GYM_CLEAR_ACP_CACHE_EXPLAIN'] = sprintf($user->lang['GYM_CLEAR_ACP_CACHE_EXPLAIN'], $user->lang[strtoupper($mode)] ); + $display_vars = array( 'title' => 'GYM_MODULE_MAINTENANCE', + 'vars' => array( + 'legend1' => 'GYM_MODULE_MAINTENANCE', + 'cache_action' => array('lang' => 'GYM_CLEAR_CACHE','validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true,), + 'acp_modules' => array('lang' => 'GYM_CLEAR_ACP_CACHE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + ), + ); + return $display_vars; + } + /** + * is_overriden($mode, $module, $action, $config_key, $vars) + * tell if an option is overriden + */ + function is_overriden($mode, $module, $action, $config_key, $vars) { + global $user; + static $override_msg = array(); + if (empty($override_msg)) { + $override_msg = array( OVERRIDE_GLOBAL => 'GYM_OVERRIDED_GLOBAL', OVERRIDE_OTYPE => 'GYM_OVERRIDED_OTYPE', OVERRIDE_MODULE => 'GYM_OVERRIDED_MODULE'); + } + // Define overrides if needed + if (empty($this->override[$mode][$module])) { + foreach ($this->override_type as $_type) { + $this->override[$mode][$module][$_type] = $this->_set_override($mode, $module, $_type); + } + $this->override[$mode][$module][$mode] = $this->gym_config[$mode . '_override']; + } + $override = $overrided = $level = ''; + if ($mode != 'main') { + // We are setting up an output type + if ($module != 'main') { + $option = str_replace($mode . "_$module" . '_', '', $config_key); + $level = OVERRIDE_MODULE; + } else { // we are setting up a module + $option = str_replace($mode . '_', '', $config_key); + $level = OVERRIDE_OTYPE; + } + } else { // Main level + $option = str_replace('gym_', '', $config_key); + $level = OVERRIDE_GLOBAL; + } + if (in_array($action, $this->override_type)) { // Main overrides + $override = $this->override[$mode][$module][$action]; + } else { + $override = $this->override[$mode][$module][$mode]; + } + $overrided = $this->_overriden_type($mode, $module, $option, $override, $level); + if ($overrided['override'] == $level) { + return '<br/><i style="color:green">' . $this->safe_lang('GYM_COULD_OVERRIDE') . '</i>'; + } else { + $message = ''; + // Check if we should show the value used + if ($overrided['used_value'] !== 'current') { + // Check var type + if ($vars['validate'] == 'bool') { + $message = $overrided['used_value'] ? $user->lang['YES'] : $user->lang['NO']; + + } elseif (($vars['validate'] == 'int' || $vars['validate'] == 'string') && !@$vars['method'] == 'select_string') { + $message = htmlspecialchars($overrided['used_value']); + $message = $message == '' ? $user->lang['GYM_OVERRIDED_VALUE_NOTHING'] : $message; + + } elseif (@$vars['method'] == 'select_string') { + $select_ary = $this->gym_modules_acp[$mode][$module][$action]['select'][$config_key]; + $message = $this->safe_lang($select_ary[$overrided['used_value']]); + } + } + $message = !empty($message) ? '<br/>' . $user->lang['GYM_OVERRIDED_VALUE'] . $message : ''; + return '<br/><i style="color:red">' . $this->safe_lang($override_msg[$overrided['override']]) . $message . '</i>'; + } + } + + /** + * _overriden_type() + * helper for is_overriden() + */ + function _overriden_type($mode, $module, $option, $override, $level ) { + // module level + if ( ($override == OVERRIDE_MODULE) && @isset($this->gym_config[$mode . "_$module" . "_$option"])) { + return array('override' => OVERRIDE_MODULE); + } + // Output type level + if ( $override != OVERRIDE_GLOBAL && @isset($this->gym_config[$mode . "_$option"])) { + return array('override' => OVERRIDE_OTYPE, 'used_value' => ($level != OVERRIDE_OTYPE ? $this->gym_config[$mode . "_$option"] : 'current' ) ); + } + // Global level + if (isset($this->gym_config["gym_$option"])) { + return array('override' => OVERRIDE_GLOBAL, 'used_value' => ($level != OVERRIDE_GLOBAL ? $this->gym_config["gym_$option"] : 'current' ) ); + } elseif ( @isset($this->gym_config[$mode . "_$option"]) ) { + return array('override' => OVERRIDE_OTYPE, 'used_value' => ($level != OVERRIDE_OTYPE ? $this->gym_config[$mode . "_$option"] : 'current' ) ); + } elseif ( @isset($this->gym_config[$mode . "_$module" . "_$option"]) ) { + return array('override' => OVERRIDE_MODULE, 'used_value' => ($level != OVERRIDE_MODULE ? $this->gym_config[$mode . "_$module" . "_$option"] : 'current' ) ); + } else { + return null; + } + } + /** + * _set_override() + * helper for is_overriden() + */ + function _set_override($mode, $module, $type) { + $main_key = 'gym_override_' . $type; + $mode_key = $mode . '_override_' . $type; + // $module_key = $module != 'main' ? $mode . '_' . $module . '_override_' . $type : 0; + if ($this->gym_config['gym_override']) { + return ($this->gym_config[$main_key] != OVERRIDE_GLOBAL) ? ($this->gym_config[$mode_key] != OVERRIDE_GLOBAL ? $this->gym_config[$mode_key] : $this->gym_config[$main_key]) : OVERRIDE_GLOBAL; + } else { + return $this->gym_config[$mode_key]; + } + } + /** + * safe_lang($lang_key) + * Safely set a lang key + */ + function safe_lang($lang_key) { + global $user; + return isset($user->lang[$lang_key]) ? $user->lang[$lang_key] : htmlspecialchars($lang_key); + } + /** + * back_to_prev() + * Generate back link for acp pages + */ + function back_to_prev() { + global $user; + return '<br /><br /><a href="' . $this->u_action . '&maction=' . $this->maction . '&action=' . $this->action . '&module=' . $this->module . '">« ' . $user->lang['BACK_TO_PREV'] . '</a>'; + } + /** + * module_custom_select($value, $key) to grabb custom select function from modules + * In the $display_vars array : + * 'gym_config_key' => array('lang' => 'LANG_TITLE', 'validate' => 'int|bool|string', 'type' => 'custom', 'method' => 'module_custom_select', 'explain' => true), + * Will build the custom select unsing the module's select_gym_config_key($value, $key) method. + */ + function module_custom_select($value, $key) { + global $phpbb_root_path, $phpEx; + $method = 'select_' . $key; + $module_file = $phpbb_root_path . 'gym_sitemaps/acp/modules/' . $this->mode . '_' . $this->module . '.' . $phpEx; + if ( file_exists($module_file) ) { + include_once($module_file); + if (class_exists($module_class)) { + $gym_module = new $module_class($this); + if ( method_exists($gym_module, $method)) { + return $gym_module->$method($value, $key); + } + } + } + // Error + } + /** + * select_multiple_string($value, $key) custom select string + */ + function select_multiple_string($value, $key) { + $select_ary = $this->gym_modules_acp[$this->mode][$this->module][$this->action]['select'][$key]; + $size = min(12,count($select_ary)); + $html = '<select multiple="multiple" id="' . $key . '" name="multiple_' . $key . '[]" size="' . $size . '">'; + foreach ($select_ary as $sel_key => $sel_data) { + if (empty($sel_data['disabled'])) { + $selected = @array_search($sel_key, @$this->new_config[$key]) !== false ? 'selected="selected"' : ''; + $disabled = ''; + } else { + $disabled = 'disabled="disabled" class="disabled-option"'; + $selected = ''; + } + $sel_title = $sel_data['title']; + $html .= "<option value=\"$sel_key\" $disabled $selected>$sel_title</option>"; + } + return $html . '</select>'; + } + /** + * select_string($value, $key) custom select string + */ + function select_string($value, $key) { + $select_ary = $this->gym_modules_acp[$this->mode][$this->module][$this->action]['select'][$key]; + $html = ''; + foreach ($select_ary as $sel_key => $sel_lang) { + $selected = ($sel_key == @$this->new_config[$key]) ? ' selected="selected"' : ''; + $sel_title = $this->safe_lang($sel_lang); + $html .= '<option value="' . $sel_key . '"' . $selected . '>' . $sel_title . '</option>'; + } + return $html; + } + /** + * validate_num($value, $key, $num) validate num, 2.3255 + */ + function validate_num($value, $key, $float = 1, $min = 0 , $max = 4) { + $float = $float > 0 ? (int) $float : 0; + $min = $min > 0 ? $min : 0; + $max = $max > 0 ? $max : 4; + $value = ($value >= $min && $value <= $max) ? $value : ($max/2); + $value = $float > 0 ? sprintf('%.' . $float . 'f', $value) : (int) $value; + return '<input id="' . $key . '" type="text" size="' . (strlen($max) + $float + 1) . '" maxlength="' . (strlen($max) + $float + 1) . '" name="config[' . $key . ']" value="' . $value . '" />'; + } + /** + * forum_select() // custom forum select setup + */ + function forum_select() { + if (empty($this->dyn_select['forums'])) { + $this->dyn_select['forums'] = make_forum_select(false, false, true, true, true, false, true); + foreach($this->dyn_select['forums'] as $f_id => $f_data) { + $this->dyn_select['forums'][$f_id] = array( + 'title' => $f_data['padding'] . $f_data['forum_name'], + 'disabled' => $f_data['disabled'], + ); + } + } + } + /** + * clear_all_cache() + * Clears all the gym sitemaps cache ( acp modules, module lists and config ) + */ + function clear_all_cache($option = '') { + global $phpbb_root_path, $phpEx, $acm_type, $cache; + if ($acm_type !== 'file') { + // Apparently, we cannot loop through cached variable using cache class in such case, purge all for now + $cache->purge(); + return; + } + $dir = opendir( $cache->cache_dir ); + $action_from_file = ''; + while( ($file = @readdir($dir)) !== false ) { + if(preg_match('`^data_gym_' . $option . '[a-z0-9_-]+\.' . $phpEx . '$`i', $file)) { + @unlink($cache->cache_dir . $file); + } + } + @closedir($dir); + return; + } + /** + * remove_cache($cache_type, $file_type) + * Removes/unlinks config cache file(s) + */ + function remove_cache($type = 'config', $mode = '') { + global $phpbb_root_path, $phpEx, $acm_type; + if ($type == 'all' || $acm_type !== 'file') { + $this->clear_all_cache(); + return; + } + $RegEx = ($type === 'config') ? '(config|links|auth)' : ''; + $RegEx .= (!empty($mode) && in_array($mode, $this->modes) ? "_$mode" : ''); + $this->clear_all_cache($RegEx); + return; + } + /** + * set_phpbb_seo_links Builds links to support threads + */ + function set_phpbb_seo_links() { + global $config, $user, $template; + $this->support_link['links_en'] = array( 'release' => 'http://www.phpbb-seo.com/en/gym-sitemaps-rss/google-yahoo-msn-sitemaps-rss-t2734.html', 'support' => 'http://www.phpbb-seo.com/en/gym-sitemaps-rss/', 'seo_forum' => 'http://www.phpbb-seo.com/en/', 'subscribe' => 'http://www.phpbb-seo.com/en/gym-sitemaps-rss/google-yahoo-msn-sitemaps-rss-t2734.html' ); + $this->support_link['links_fr'] = array( 'release' => 'http://www.phpbb-seo.com/fr/gym-sitemaps-rss/sitemaps-rss-google-yahoo-msn-t3136.html', 'support' => 'http://www.phpbb-seo.com/fr/gym-sitemaps-rss/', 'seo_forum' => 'http://www.phpbb-seo.com/fr/', 'subscribe' => 'http://www.phpbb-seo.com/fr/gym-sitemaps-rss/sitemaps-rss-google-yahoo-msn-t3136.html' ); + if (strpos($config['default_lang'], 'fr') !== false ) { + $this->support_link['release'] = $this->support_link['links_fr']['release']; + $this->support_link['support'] = $this->support_link['links_fr']['support']; + $this->support_link['seo_forum'] = $this->support_link['links_fr']['seo_forum']; + $this->support_link['subscribe'] = $this->support_link['links_fr']['subscribe']; + } else { + $this->support_link['release'] = $this->support_link['links_en']['release']; + $this->support_link['support'] = $this->support_link['links_en']['support']; + $this->support_link['seo_forum'] = $this->support_link['links_en']['seo_forum']; + $this->support_link['subscribe'] = $this->support_link['links_en']['subscribe']; + } + $this->support_link['register'] = $this->support_link['seo_forum'] . 'profile.php?mode=register'; + $this->support_link['update_msg'] = sprintf($user->lang['ACP_SEO_REGISTER_MSG'], sprintf($user->lang['ACP_SEO_REGISTER_TITLE'],$this->support_link['register'] ), sprintf($user->lang['ACP_SEO_REGISTER_UPDATE'], $this->support_link['subscribe'] ) ); + $user->lang['TRANSLATION_INFO'] .= '<br/><a href="http://www.phpbb-seo.com/" title="' . ( strpos($config['default_lang'], 'fr') !== false ? 'Optimisation du Référencement' : 'Search Engine Optimization') . '">phpBB SEO</a>'; + $this->support_link['release_full'] = '<a href="' . $this->support_link['release'] . '" title="' . $user->lang['ACP_SEO_RELEASE_THREAD'] . '">' . $user->lang['ACP_SEO_RELEASE_THREAD'] . '</a>'; + $this->support_link['support_full'] = '<a href="' . $this->support_link['support'] . '" title="' . $user->lang['ACP_SEO_SUPPORT_FORUM'] . '">' . $user->lang['ACP_SEO_SUPPORT_FORUM'] . '</a>'; + $this->support_link['seo_forum_full'] = '<a href="' . $this->support_link['seo_forum'] . '" title ="phpBB SEO">phpBB SEO</a>'; + $template->assign_vars(array( + 'SUPPORT_LINKS' => '<p>' . $this->support_link['release_full'] . ' • ' . $this->support_link['support_full'] . ' • ' . $this->support_link['seo_forum_full'] . '</p>', + ) + ); + if ($this->mode === 'main' && $this->module === 'main' && $this->action === 'main') { + $user->lang['MAIN_MAIN_EXPLAIN'] = sprintf( $user->lang['MAIN_MAIN_EXPLAIN'], $this->support_link['release_full'], $this->support_link['support_full'], $this->support_link['seo_forum_full'], $this->support_link['update_msg'] ); + } + return; + } + /** + * check_scripts Validates GYM scripts (gymrss, sitemap & map) locations + */ + function check_scripts(&$error, &$cfg_array, $only_mode = '') { + global $phpbb_root_path, $phpEx, $user, $phpbb_seo, $phpbb_admin_path; + $allowed_protocols = array('http', 'https'/*, 'ftp', 'ftps'*/); + $error = is_array($error) ? $error : array(); + // check file_get_contents availability + $file_get = function_exists('file_get_contents'); + if (!$file_get) { + // file_get_contents is not available, we won't be able to check everything + // @TODO find out how (we won't thgouh an error just for this), + // and also if it would be useful, to warn user about this + } + $scripts = array( + 'rss' => array('file' => 'gymrss',), + 'google' => array('file' => 'sitemap',), + 'html' => array('file' => 'map',), + ); + $only_mode = $only_mode && isset($scripts[$only_mode]) ? $only_mode : false; + if ($only_mode) { + $scripts[$only_mode]['url_config'] = isset($cfg_array[$only_mode . '_url']) ? ($cfg_array[$only_mode . '_url'] = trim($cfg_array[$only_mode . '_url'], ' /') . '/') : ''; + $scripts = array($only_mode => $scripts[$only_mode]); + } else { + foreach ($scripts as $k => $v) { + if (isset($cfg_array[$k . '_url'])) { + $scripts[$k]['url_config'] = isset($cfg_array[$k . '_url']) ? ($cfg_array[$k . '_url'] = trim($cfg_array[$k . '_url'], ' /') . '/') : ''; + } else { + // do not check without a reference + unset($scripts[$k]); + } + } + } + // let's not show a warning for a proto matter (since they are dealt with runtime) + foreach ($scripts as $k => $v) { + $scripts[$k]['url_config'] = $scripts[$k]['url_config'] ? $phpbb_seo->sslify($scripts[$k]['url_config'], $phpbb_seo->ssl['use']) : ''; + } + $phpbb_url_config_url = append_sid($phpbb_admin_path . "index.$phpEx", "i=board&mode=server#force_server_vars"); + // all script should be placed in the same domain as phpBB + $root_url = $phpbb_seo->seo_path['root_url']; + if (($root_url_parts = @parse_url($root_url)) === false || empty($root_url_parts['scheme']) || !in_array($root_url_parts['scheme'], $allowed_protocols) || empty($root_url_parts['host'])) { + // the root url as set is wrong in phpbb config + $error[] = sprintf($user->lang['GYM_WRONG_PHPBB_URL'], $phpbb_url_config_url); + return false; + } + // deal with paths + $phpbb_url = $phpbb_seo->seo_path['phpbb_url']; + // the path from domain root to phpBB + $phpbb_clean_root_path = $phpbb_seo->seo_path['phpbb_script']; + $phpbb_root_path_parts = trim($phpbb_clean_root_path, '/ '); + $phpbb_root_path_parts = $phpbb_root_path_parts ? explode('/', $phpbb_root_path_parts) : false; + $phpbb_root_path_levels = 0; + if ($phpbb_root_path_parts) { + // the number of sub directory starting from domain's root + $phpbb_root_path_levels = count($phpbb_root_path_parts); + } + // form here to domain's root and then to domains root to phpBB directory should be a way to hit common.php + // from phpBB to domain's root + $phpbb_test_path = str_repeat('../', $phpbb_root_path_levels); + // from domain's root to phpBB + $phpbb_test_path .= $phpbb_clean_root_path; + if (!file_exists($phpbb_root_path . $phpbb_test_path)) { + // the root url as set is wrong in phpbb config + $error[] = sprintf($user->lang['GYM_WRONG_PHPBB_URL'], $phpbb_url_config_url); + return false; + } + foreach ($scripts as $mode => $setup) { + $error[$mode] = '<h2>' . $user->lang[strtoupper($mode) . '_URL'] . '</h2>'; + $url_config_url = append_sid($phpbb_admin_path . "index.$phpEx", "i=gym_sitemaps&mode=$mode#{$mode}_url"); + $script_file = $setup['file'] . ".$phpEx"; + if (($url_parts = @parse_url($setup['url_config'])) === false || empty($root_url_parts['scheme']) || !in_array($root_url_parts['scheme'], $allowed_protocols) || empty($root_url_parts['host'])) { + // the scritp url is wrong + $error[] = sprintf($user->lang['GYM_WRONG_SCRIPT_URL'], $user->lang[strtoupper($mode)], $script_file); + $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url); + continue; + } + if (strpos($setup['url_config'], $root_url) === false ) { + // the script domain is wrong + $error[] = sprintf($user->lang['GYM_WRONG_SCRIPT_DOMAIN'], $user->lang[strtoupper($mode)], $root_url, $script_file); + $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url); + continue; + } + // current gym script is configured in the phpBB domain + // let's check paths, start with something simple + if (strpos($setup['url_config'], $phpbb_url) !== false ) { + // script is (well should be) inside phpBB directory + $script_path = str_replace($phpbb_url, '', $setup['url_config']); + // if this is a sitemap, it would be wrong to put it within a sub directory inside the phpBB directory + if ($mode === 'google') { + if ($script_path) { + // sitemap is not usable for phpBB in there + $error[] = sprintf($user->lang['GYM_WRONG_SITEMAP_LOCATION'], $phpbb_url . $script_path, $root_url . $phpbb_clean_root_path); + $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url); + continue; + } + } + if (file_exists($phpbb_root_path . $script_path . $script_file)) { + // the script is where it should + if ($file_get) { + // let's go further and check $phpbb_root_path in the script + if ($content = @file_get_contents($phpbb_root_path . $script_path . $script_file)) { + // expected pattern : $phpbb_root_path = './(some/thing/|../)'; + if (preg_match('`^[\s]*\$phpbb_root_path[\s]*\=[\s]*(\'|")([a-z0-9_\./-]+)\1[\s]*\;[\s]*$`im', $content, $match)) { + // we have a match + $file_phpbb_root_path = $match[2]; + unset($match, $content); + // since we're here inside phpBB directory + $file_phpbb_root_path_valid = $file_phpbb_root_path === './' . $script_path ? true : false; + if (!$file_phpbb_root_path_valid) { + // file_phpbb_root_path is not valid + $error[] = sprintf($user->lang['GYM_WRONG_SCRIPT2_PHPBB'], $user->lang[strtoupper($mode)], $phpbb_url . $script_path, $script_file, './' . $script_path); + $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url); + continue; + } + } + } + } + } else { + // the script is not located where the config claims it is + $error[] = sprintf($user->lang['GYM_WRONG_SCRIPT_URL'], $user->lang[strtoupper($mode)], $script_file); + $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url); + continue; + } + + } else { + // The script is (well should be) somewhere outside the phpBB directory + $script_path = str_replace($root_url, '', $setup['url_config']); + $script_path_parts = trim($script_path, '/ '); + $script_path_parts = $script_path_parts ? explode('/', $script_path_parts) : false; + $script_path_levels = 0; + if ($script_path_parts) { + // the number of sub directory starting from domain's root + $script_path_levels = count($script_path_parts); + } + // path from here to the script + // from phpBB to root + $path_from_phpbb = str_repeat('../', $phpbb_root_path_levels); + // from root to script + $path_from_phpbb .= $script_path; + // and from adm + $path_from_here = $phpbb_root_path . $path_from_phpbb; + // if this is a sitemap, it would be wrong to put it where it would not be useful + // Example : example.com/phpBB/ or example.com/ with example.com/dir/sitemap.php + if ($mode === 'google') { + if ($script_path_levels > 1) { + // we are not in domain's root where everything is always ok + $script_path_is_ok = true; + if (!$phpbb_root_path_levels) { + // for sure, this is wrong + $script_path_is_ok = false; + } else { + // $script_path_parts should be < $phpbb_root_path_parts + if ($script_path_levels < $phpbb_root_path_levels) { + // check if path is ok, $phpbb_clean_root_path must contain $script_path + foreach ($script_path_parts as $k => $v) { + // must match all the way + if ($v !== $phpbb_root_path_parts[$k]) { + $script_path_is_ok = false; + break; + } + } + } else { + // script path configured is deeper than phpBB one + $script_path_is_ok = false; + } + } + if (!$script_path_is_ok) { + // sitemap is not usable for phpBB in there + $error[] = sprintf($user->lang['GYM_WRONG_SITEMAP_LOCATION'], $phpbb_url . $script_path, $root_url . $phpbb_clean_root_path); + $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url); + continue; + } + } + } + if (file_exists($path_from_here . $script_file)) { + // the script is where it should + if ($file_get) { + // let's go further and check $phpbb_root_path in the script + if ($content = @file_get_contents($path_from_here . $script_file)) { + // expected pattern : $phpbb_root_path = './(some/thing/|../)'; + if (preg_match('`^[\s]*\$phpbb_root_path[\s]*\=[\s]*(\'|")([a-z0-9_\./-]+)\1[\s]*\;[\s]*$`im', $content, $match)) { + // we have a match + $file_phpbb_root_path = $match[2]; + unset($match, $content); + // expected path + // we need to filter any common parts in paths + // eg for the *wierd* example.com/dir/phpBB/ with example.com/dir/otherdir/script.php case, + // $phpbb_root_path should not go all the way to domain's root in script.php + if ($phpbb_root_path_levels > 1 && $script_path_levels > 1) { + if ($phpbb_root_path_parts[0] == $script_path_parts[0]) { + // these two indeed share some parts + $_phpbb_root_path_parts = $phpbb_root_path_parts; + $_script_path_parts = $script_path_parts; + foreach ($_phpbb_root_path_parts as $k => $v) { + if ($v == $_script_path_parts[$k]) { + unset($_phpbb_root_path_parts[$k], $_script_path_parts[$k]); + } else { + break; + } + } + // since the script can only be outside phpBB directory here + $_script_path_levels = count($_script_path_parts); + $_phpbb_root_path_parts = count($_phpbb_root_path_parts); + // from script to first common dir + $path_from_script = str_repeat('../', $_script_path_levels); + // and from first common dir to phpBB + $path_from_script .= trim(implode('/', $_phpbb_root_path_parts), ' /') . '/'; + $file_phpbb_root_path_valid = $file_phpbb_root_path === './' . $path_from_script ? true : false; + if (!$file_phpbb_root_path_valid) { + // file_phpbb_root_path is not valid + $error[] = sprintf($user->lang['GYM_WRONG_SCRIPT2_PHPBB'], $user->lang[strtoupper($mode)], $root_url . $script_path, $script_file, './' . $path_from_script); + $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url); + continue; + } + // we're done here + continue; + } + } + // so we do not share paths ... + // from script to root + $path_from_script = str_repeat('../', $script_path_levels); + // and from root to phpBB + $path_from_script .= $phpbb_clean_root_path; + $file_phpbb_root_path_valid = $file_phpbb_root_path === './' . $path_from_script ? true : false; + if (!$file_phpbb_root_path_valid) { + // file_phpbb_root_path is not valid + $error[] = sprintf($user->lang['GYM_WRONG_SCRIPT2_PHPBB'], $user->lang[strtoupper($mode)], $root_url . $script_path, $script_file, './' . $path_from_script); + $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url); + continue; + } + } + } + } + } else { + // the script is not located where the config claims it is + $error[] = sprintf($user->lang['GYM_WRONG_SCRIPT_URL'], $user->lang[strtoupper($mode)], $script_file); + $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url); + continue; + } + } + // if we reach here, no error where found, unset the title + unset($error[$mode]); + } + } + /** + * check_cache_folder Validates the cache folder status + */ + function check_cache_folder($cache_dir, $msg = true) { + global $user; + $exists = $write = false; + $cache_msg = ''; + $cache_dir = rtrim($cache_dir, '/'); + if (file_exists($cache_dir) && is_dir($cache_dir)) { + $exists = true; + if (!is_writeable($cache_dir)) { + phpbb_chmod($cache_dir, CHMOD_READ | CHMOD_WRITE); + $fp = @fopen($cache_dir . 'test_lock', 'wb'); + if ($fp !== false) { + $write = true; + } + @fclose($fp); + @unlink($phpbb_root_path . $dir . 'test_lock'); + } else { + $write = true; + } + } + if ($msg) { + $exists = ($exists) ? '<b style="color:green">' . $user->lang['SEO_CACHE_FOUND'] . '</b>' : '<b style="color:red">' . $user->lang['SEO_CACHE_NOT_FOUND'] . '</b>'; + $write = ($write) ? '<br/> <b style="color:green">' . $user->lang['SEO_CACHE_WRITABLE'] . '</b>' : (($exists) ? '<br/> <b style="color:red">' . $user->lang['SEO_CACHE_UNWRITABLE'] . '</b>' : ''); + $cache_msg = sprintf($user->lang['SEO_CACHE_STATUS'], $cache_dir) . '<br/>' . $exists . $write; + return '<br/><br/><b>' . $user->lang['SEO_CACHE_FILE_TITLE'] . ':</b><ul>' . $cache_msg . '</ul><br/>'; + } else { + return ($exists && $write); + } + } +} // End of acp class +?>
\ No newline at end of file diff --git a/phpBB/includes/acp/acp_phpbb_seo.php b/phpBB/includes/acp/acp_phpbb_seo.php new file mode 100644 index 0000000000..1d55babc19 --- /dev/null +++ b/phpBB/includes/acp/acp_phpbb_seo.php @@ -0,0 +1,1140 @@ +<?php +/** +* +* @package Ultimate SEO URL phpBB SEO +* @version $Id: acp_phpbb_seo.php 277 2010-11-25 12:09:02Z dcz $ +* @copyright (c) 2006 - 2010 www.phpbb-seo.com +* @license http://www.opensource.org/licenses/rpl1.5.txt Reciprocal Public License 1.5 +* +*/ +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) { + exit; +} +/** +* phpBB_SEO Class +* www.phpBB-SEO.com +* @package Ultimate SEO URL phpBB SEO +*/ +class acp_phpbb_seo { + var $u_action; + var $new_config = array(); + var $dyn_select = array(); + var $forum_ids = array(); + var $array_type_cfg = array(); + var $multiple_options = array(); + var $modrtype_lang = array(); + var $write_type = 'forum'; + var $lengh_limit = 20; + var $word_limit = 3; + var $seo_unset_opts = array(); + + function main($id, $mode) { + global $config, $db, $user, $auth, $template, $cache; + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $phpbb_seo; + // Start the phpbb_seo class + if ( empty($phpbb_seo) ) { + include_once($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.' . $phpEx); + $phpbb_seo = new phpbb_seo(); + } + $user->add_lang('mods/acp_phpbb_seo'); + $action = request_var('action', ''); + $submit = (isset($_POST['submit'])) ? true : false; + $form_key = 'acp_board'; + add_form_key($form_key); + $display_vars = array(); + // --> Zero Dupe + if (@isset($phpbb_seo->seo_opt['zero_dupe']) ) { + $this->multiple_options['zero_dupe']['post_redir_values'] = array('off' => 'off', 'post' => 'post', 'guest' => 'guest', 'all' => 'all'); // do not change + $this->multiple_options['zero_dupe']['post_redir_lang'] = array('off' => $user->lang['ACP_ZERO_DUPE_OFF'], 'post' => $user->lang['ACP_ZERO_DUPE_MSG'], 'guest' => $user->lang['ACP_ZERO_DUPE_GUEST'], 'all' => $user->lang['ACP_ZERO_DUPE_ALL']); // do not change + } + // <-- Mod rewrite selector + if ($phpbb_seo->modrtype == 1) { + $this->seo_unset_opts = array('cache_layer', 'rem_ids'); + } elseif (!$phpbb_seo->seo_opt['cache_layer']) { + $this->seo_unset_opts = array('rem_ids'); + } + $this->modrtype_lang = $this->set_phpbb_seo_links(); + $this->multiple_options['modrtype_lang'] = $this->modrtype_lang['titles']; + if (@isset($phpbb_seo->seo_opt['modrtype']) ) { + $this->multiple_options['modrtype_values'] = array( 1 => 1, 2 => 2, 3 => 3 ); // do not change; + } + // <-- Mod rewrite selector + foreach ( $this->seo_unset_opts as $opt ) { + if ( $optkey = array_search($opt, $phpbb_seo->cache_config['dynamic_options']) ) { + unset($phpbb_seo->cache_config['dynamic_options'][$optkey]); + } + } + // We need shorter URLs with Virtual Folder Trick + if ($phpbb_seo->seo_opt['virtual_folder']) { + $this->lengh_limit = 20; + $this->word_limit = 3; + } else { + $this->lengh_limit = 30; + $this->word_limit = 5; + } + $related_installed = false; + switch ($mode) { + case 'settings': + $this->write_type = 'forum'; + $display_vars['title'] = 'ACP_PHPBB_SEO_CLASS'; + $user->lang['ACP_PHPBB_SEO_CLASS_EXPLAIN'] = sprintf($user->lang['ACP_PHPBB_SEO_CLASS_EXPLAIN'], $this->modrtype_lang['ulink'], $this->modrtype_lang['uforumlink'], '</p><hr/><p><b>' . $user->lang['ACP_PHPBB_SEO_MODE'] . ' : ' . $this->modrtype_lang['link'] . ' - ' . $phpbb_seo->version . ' ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><hr/><p>'); + $display_vars['vars'] = array(); + $i = 2; + $display_vars['vars']['legend1'] = 'ACP_PHPBB_SEO_CLASS'; + foreach($phpbb_seo->cache_config['dynamic_options'] as $optionname => $optionvalue) { + if ( @is_bool($phpbb_seo->seo_opt[$optionvalue]) ) { + if ($optionvalue == 'virtual_root' && !$phpbb_seo->seo_path['phpbb_script']) { + continue; + } + $display_vars['vars'][$optionvalue] = array('lang' => $optionvalue, 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'lang_explain' => $optionvalue . '_explain'); + $this->new_config[$optionvalue] = $phpbb_seo->seo_opt[$optionvalue]; + } elseif ( @isset($this->multiple_options[$optionvalue . '_values']) ) { + $this->dyn_select[$optionvalue] = $this->multiple_options[$optionvalue . '_values']; + $display_vars['vars'][$optionvalue] = array('lang' => $optionvalue, 'validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true, 'lang_explain' => $optionvalue . '_explain'); + $this->new_config[$optionvalue] = $phpbb_seo->seo_opt[$optionvalue]; + } elseif ( is_array($optionvalue)) { + $display_vars['vars']['legend' . $i] = $optionname; + $i++; + foreach ($optionvalue as $key => $value) { + $this->array_type_cfg[$optionname . '_' . $key] = array('main' => $optionname, 'sub' => $key); + if ( is_bool($value) ) { + $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain'); + $this->new_config[$optionname . '_' . $key] = $phpbb_seo->seo_opt[$optionname][$key]; + } elseif ( @isset($this->multiple_options[$optionname][$key . '_values'] )) { + $this->dyn_select[$optionname . '_' . $key] = $this->multiple_options[$optionname][$key . '_values']; + $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain'); + $this->new_config[$optionname . '_' . $key] = $phpbb_seo->seo_opt[$optionname][$key]; + } else { + $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'string:0:50', 'type' => 'text:50:50', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain'); + $this->new_config[$optionname . '_' . $key] = $phpbb_seo->seo_opt[$optionname][$key]; + } + + } + } + } + break; + case 'forum_url': + // used for cache + $this->write_type = 'forum'; + $forbidden = array($phpbb_seo->seo_static['forum'], $phpbb_seo->seo_static['global_announce'], $phpbb_seo->seo_static['user'], $phpbb_seo->seo_static['topic'], $phpbb_seo->seo_static['atopic'], $phpbb_seo->seo_static['utopic'], $phpbb_seo->seo_static['leaders'], $phpbb_seo->seo_static['post'], $phpbb_seo->seo_static['group'], $phpbb_seo->seo_static['npost'], $phpbb_seo->seo_static['index']); + if ( $phpbb_seo->modrtype == 1 || !$phpbb_seo->seo_opt['cache_layer'] ) { + trigger_error($user->lang['ACP_NO_FORUM_URL'] . preg_replace('`(&|&|\?)mode=forum_url`i', '', adm_back_link($this->u_action))); + break; + } + $display_vars['title'] = 'ACP_FORUM_URL'; + $user->lang['ACP_FORUM_URL_EXPLAIN'] .= '</p><hr/><p><b>' . $user->lang['ACP_PHPBB_SEO_VERSION'] . ' : ' . $this->modrtype_lang['link'] . ' - ' . $phpbb_seo->version . ' ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><hr/><p>'; + $display_vars['vars'] = array(); + $display_vars['vars']['legend1'] = 'ACP_FORUM_URL'; + $sql = "SELECT forum_id, forum_name + FROM " . FORUMS_TABLE . " + ORDER BY left_id ASC"; + $result = $db->sql_query($sql); + $forum_url_title = $error_cust = ''; + while( $row = $db->sql_fetchrow($result) ) { + $this->forum_ids[$row['forum_id']] = $row['forum_name']; + } + $db->sql_freeresult($result); + // take care of deleted forums + foreach ($phpbb_seo->cache_config['forum'] as $fid => $null) { + if (!isset($this->forum_ids[$fid])) { + unset($phpbb_seo->cache_config['forum'][$fid]); + } + } + foreach ($this->forum_ids as $forum_id => $forum_name) { + $error_cust = ''; + // Is the URL cached already ? + if ( empty($phpbb_seo->cache_config['forum'][$forum_id]) ) { + // Suggest the one from the title + $forum_url_title = $phpbb_seo->format_url($forum_name, $phpbb_seo->seo_static['forum']); + if (!in_array($forum_url_title, $forbidden)) { + if (array_search($forum_url_title, $phpbb_seo->cache_config['forum'])) { + $this->new_config['forum_url' . $forum_id] = $forum_url_title . $phpbb_seo->seo_delim['forum'] . $forum_id; + $error_cust = '<li> ' . sprintf($user->lang['SEO_ADVICE_DUPE'], $forum_url_title) . '</li>'; + } else { + $this->new_config['forum_url' . $forum_id] = $forum_url_title . (@$phpbb_seo->cache_config['settings']['rem_ids'] ? '': $phpbb_seo->seo_delim['forum'] . $forum_id); + } + } else { + $this->new_config['forum_url' . $forum_id] = $forum_url_title . $phpbb_seo->seo_delim['forum'] . $forum_id; + $error_cust = '<li> ' . sprintf($user->lang['SEO_ADVICE_RESERVED'], $forum_url_title) . '</li>'; + } + $title = '<b style="color:red">' . $forum_name . ' - ID ' . $forum_id . '</b>'; + $status_msg = '<b style="color:red">' . $user->lang['SEO_CACHE_URL_NOT_OK'] . '</b>'; + $status_msg .= '<br/><span style="color:red">' . $user->lang['SEO_CACHE_URL'] . ' :</span> ' . $this->new_config['forum_url' . $forum_id] . $phpbb_seo->seo_ext['forum']; + $display_vars['vars']['forum_url' . $forum_id] = array('lang' => $title, 'validate' => 'string', 'type' => 'custom', 'method' => 'forum_url_input', 'explain' => true, 'lang_explain_custom' => $status_msg, 'append' => $this->seo_advices($this->new_config['forum_url' . $forum_id], $forum_id, false, $error_cust)); + } else { // Cached + $this->new_config['forum_url' . $forum_id] = $phpbb_seo->cache_config['forum'][$forum_id]; + $title = '<b style="color:green">' . $forum_name . ' - ID ' . $forum_id . '</b>'; + $status_msg = '<span style="color:green">' . $user->lang['SEO_CACHE_URL_OK'] . ' :</span> <b style="color:green">' . $this->new_config['forum_url' . $forum_id] . '</b>'; + $status_msg .= '<br/><span style="color:green">' . $user->lang['SEO_CACHE_URL'] . ' :</span> ' . $this->new_config['forum_url' . $forum_id] . $phpbb_seo->seo_ext['forum']; + $display_vars['vars']['forum_url' . $forum_id] = array('lang' => $title, 'validate' => 'string:0:100', 'type' => 'custom', 'method' => 'forum_url_input', 'explain' => true, 'lang_explain_custom' => $status_msg,'append' => $this->seo_advices($this->new_config['forum_url' . $forum_id], $forum_id, true)); + } + } + break; + case 'htaccess': + $this->write_type = 'htaccess'; + $display_vars['title'] = 'ACP_HTACCESS'; + $user->lang['ACP_HTACCESS_EXPLAIN'] .= '</p><hr/><p><b>' . $user->lang['ACP_PHPBB_SEO_VERSION'] . ' : ' . $this->modrtype_lang['link'] . ' - ' . $phpbb_seo->version . ' ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><p>'; + $display_vars['vars'] = array(); + $display_vars['vars']['legend1'] = 'ACP_HTACCESS'; + $display_vars['vars']['save'] = array('lang' => 'SEO_HTACCESS_SAVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,); + $display_vars['vars']['more_options'] = array('lang' => 'SEO_MORE_OPTION', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,); + $this->new_config['save'] = false; + $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config; + $this->new_config['more_options'] = isset($cfg_array['more_options']) ? $cfg_array['more_options'] : false; + $this->new_config['slash'] = isset($cfg_array['slash']) ? $cfg_array['slash'] : false; + $this->new_config['wslash'] = isset($cfg_array['wslash']) ? $cfg_array['wslash'] : false; + $this->new_config['rbase'] = isset($cfg_array['rbase']) ? $cfg_array['rbase'] : false; + + if ($this->new_config['more_options']) { + $display_vars['vars']['slash'] = array('lang' => 'SEO_HTACCESS_SLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,); + $display_vars['vars']['wslash'] = array('lang' => 'SEO_HTACCESS_WSLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,); + if ($phpbb_seo->seo_path['phpbb_script'] && !$phpbb_seo->seo_opt['virtual_root']) { + $display_vars['vars']['rbase'] = array('lang' => 'SEO_HTACCESS_RBASE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,); + } + } + // Dirty yet simple templating + $user->lang['ACP_HTACCESS_EXPLAIN'] .= $this->seo_htaccess(); + + break; + case 'extended': + $display_vars = array( + 'title' => 'ACP_SEO_EXTENDED', + 'vars' => array( + 'legend1' => 'SEO_EXTERNAL_LINKS', + 'seo_ext_links' => array('lang' => 'SEO_EXTERNAL_LINKS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 1), + 'seo_ext_subdomain' => array('lang' => 'SEO_EXTERNAL_SUBDOMAIN', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0), + 'seo_ext_classes' => array('lang' => 'SEO_EXTERNAL_CLASSES', 'validate' => 'string', 'type' => 'text:25:150', 'explain' => true, 'default' => ''), + ), + ); + // Related topics + if (file_exists($phpbb_root_path . "phpbb_seo/phpbb_seo_related.$phpEx")) { + $related_installed = true; + $user->add_lang('mods/phpbb_seo_related_install'); + $display_vars['vars'] += array( + 'legend2' => 'RELATED_TOPICS', + 'seo_related' => array('lang' => 'SEO_RELATED', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'append' => !empty($config['seo_related']) ? '<br/>' . (!empty($config['seo_related_fulltext']) ? $user->lang['FULLTEXT_INSTALLED'] : $user->lang['FULLTEXT_NOT_INSTALLED']) : '', 'default' => 0), + 'seo_related_check_ignore' => array('lang' => 'SEO_RELATED_CHECK_IGNORE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0), + 'seo_related_limit' => array('lang' => 'SEO_RELATED_LIMIT', 'validate' => 'int:2:25', 'type' => 'text:3:4', 'explain' => true, 'default' => 5), + 'seo_related_allforums' => array('lang' => 'SEO_RELATED_ALLFORUMS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0), + ); + } + // dynamic meta tag mod + if (class_exists('seo_meta')) { + $display_vars['vars'] += array( + 'legend3' => 'SEO_META', + 'seo_meta_title' => array('lang' => 'SEO_META_TITLE', 'validate' => 'string:0:225', 'type' => 'text:25:150', 'explain' => true, 'default' => $config['sitename']), + 'seo_meta_desc' => array('lang' => 'SEO_META_DESC', 'validate' => 'string:0:225', 'type' => 'text:40:255', 'explain' => true, 'default' => $config['site_desc']), + 'seo_meta_desc_limit' => array('lang' => 'SEO_META_DESC_LIMIT', 'validate' => 'int:5:40', 'type' => 'text:3:4', 'explain' => true, 'default' => 25), + 'seo_meta_bbcode_filter' => array('lang' => 'SEO_META_BBCODE_FILTER', 'validate' => 'string:0:225', 'type' => 'text:25:150', 'explain' => true, 'default' => 'img|url|flash|code'), + 'seo_meta_keywords' => array('lang' => 'SEO_META_KEYWORDS', 'validate' => 'string:0:225', 'type' => 'text:40:150', 'explain' => true, 'default' => $config['site_desc']), + 'seo_meta_keywords_limit' => array('lang' => 'SEO_META_KEYWORDS_LIMIT', 'validate' => 'int:5:40', 'type' => 'text:3:4', 'explain' => true, 'default' => 15), + 'seo_meta_min_len' => array('lang' => 'SEO_META_MIN_LEN', 'validate' => 'int:0:10', 'type' => 'text:3:4', 'explain' => true, 'default' => 2), + 'seo_meta_check_ignore' => array('lang' => 'SEO_META_CHECK_IGNORE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0), + 'seo_meta_lang' => array('lang' => 'SEO_META_LANG', 'validate' => 'lang', 'type' => 'select', 'method' => 'language_select', 'params' => array('{CONFIG_VALUE}'), 'explain' => true, 'default' => $config['default_lang']), + 'seo_meta_copy' => array('lang' => 'SEO_META_COPY', 'validate' => 'string:0:225', 'type' => 'text:25:150', 'explain' => true, 'default' => $config['sitename']), + 'seo_meta_file_filter' => array('lang' => 'SEO_META_FILE_FILTER', 'validate' => 'string:0:225', 'type' => 'text:25:150', 'explain' => true, 'default' => 'ucp'), + 'seo_meta_get_filter' => array('lang' => 'SEO_META_GET_FILTER', 'validate' => 'string:0:225', 'type' => 'text:25:150', 'explain' => true, 'default' => 'style,hilit,sid'), + 'seo_meta_robots' => array('lang' => 'SEO_META_ROBOTS', 'validate' => 'string:0:225', 'type' => 'text:25:150', 'explain' => true, 'default' => 'index,follow'), + 'seo_meta_noarchive' => array('lang' => 'SEO_META_NOARCHIVE', 'validate' => 'string:0:225', 'multiple_validate' => 'int', 'type' => 'custom', 'method' => 'select_multiple', 'params' => array('{CONFIG_VALUE}', '{KEY}', $this->forum_select()), 'explain' => true, 'default' => ''), + ); + } + // Optimal title + if (isset($user->lang['Page'])) { + $display_vars['vars'] += array( + 'legend4' => 'SEO_PAGE_TITLES', + 'seo_append_sitename' => array('lang' => 'SEO_APPEND_SITENAME', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0), + ); + } + // install if necessary + foreach ($display_vars['vars'] as $config_name => $config_setup) { + if (strpos($config_name, 'legend') !== false) { + continue; + } + if (!isset($config[$config_name])) { + set_config($config_name, $config_setup['default']); + unset($display_vars['vars'][$config_name]['default']); + } + } + $this->new_config = $config; + break; + default: + trigger_error('NO_MODE', E_USER_ERROR); + break; + } + $error = array(); + $seo_msg = array(); + $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config; + if ($submit && !check_form_key($form_key)) { + $error[] = $user->lang['FORM_INVALID']; + } + // We validate the complete config if whished + validate_config_vars($display_vars['vars'], $cfg_array, $error); + // Do not write values if there is an error + if (!empty($error)) { + $submit = false; + } + $additional_notes = ''; + // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... + foreach ($display_vars['vars'] as $config_name => $cfg_setup) { + if ((!isset($cfg_array[$config_name]) && @$cfg_setup['method'] != 'select_multiple') || strpos($config_name, 'legend') !== false) { + continue; + } + // Handle multiple select options + if (!empty($cfg_setup['method']) && $cfg_setup['method'] == 'select_multiple') { + if (isset($_POST['multiple_' . $config_name])) { + $m_values = utf8_normalize_nfc(request_var('multiple_' . $config_name, array('' => ''))); + $validate_int = !empty($cfg_setup['multiple_validate']) && $cfg_setup['multiple_validate'] == 'int' ? true : false; + foreach($m_values as $k => $v) { + if ($validate_int) { + $v = max(0, (int) $v); + } + if (empty($v)) { + unset($m_values[$k]); + } else { + $m_values[$k] = $v; + } + } + sort($m_values); + $this->new_config[$config_name] = $m_values; + $config_value = implode(',', $m_values); + if ( strlen($config_value) > 255 ) { + $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$cfg_setup['lang']], 255); + } + $submit = empty($error); + } else { + if ($submit) { + $this->new_config[$config_name] = array(); + $config_value = ''; + } else { + $config_value = $this->new_config[$config_name]; + $this->new_config[$config_name] = !empty($config_value) ? explode(',', $config_value) : array(); + } + } + } else { + $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; + } + if ($submit) { + // In case we deal with forum URLs + if ($mode == 'forum_url' && preg_match('`^forum_url([0-9]+)$`', $config_name, $matches)) { + // Check if this is an actual forum_id + if ( isset($this->forum_ids[$matches[1]]) ) { + $forum_id = intval($matches[1]); + $config_value = $phpbb_seo->format_url($config_value, $phpbb_seo->seo_static['forum']); + // Remove delim if required + while (preg_match('`^[a-z0-9_-]+' . $phpbb_seo->seo_delim['forum'] . '[0-9]+$`i', $config_value)) { + $config_value = preg_replace('`^([a-z0-9_-]+)' . $phpbb_seo->seo_delim['forum'] . '[0-9]+$`i', '\\1', $config_value); + if (@$phpbb_seo->cache_config['settings']['rem_ids']) { + $seo_msg['SEO_ADVICE_DELIM_REM'] = '<li> ' . $user->lang['SEO_ADVICE_DELIM_REM'] . '</li>'; + } + } + // Forums cannot end with the pagination param + while (preg_match('`^[a-z0-9_-]+' . $phpbb_seo->seo_delim['start'] . '[0-9]+$`i', $config_value)) { + $config_value = preg_replace('`^([a-z0-9_-]+)' . $phpbb_seo->seo_delim['start'] . '[0-9]+$`i', "\\1", $config_value); + $seo_msg['SEO_ADVICE_START'] = '<li> ' . $user->lang['SEO_ADVICE_START'] . '</li>'; + } + // Only update if the value is not a static one for forums + if (!in_array($config_value, $forbidden)) { + // and updated (sic) + if ($config_value != @$phpbb_seo->cache_config['forum'][$forum_id]) { + // and if not already set + if (!array_search($config_value, $phpbb_seo->cache_config['forum'])) { + $phpbb_seo->cache_config['forum'][$forum_id] = $config_value . (@$phpbb_seo->cache_config['settings']['rem_ids'] ? '': $phpbb_seo->seo_delim['forum'] . $forum_id); + } else { + $seo_msg['SEO_ADVICE_DUPE_' . $forum_id] = '<li> ' . sprintf($user->lang['SEO_ADVICE_DUPE'], $config_value) . '</li>'; + } + } + } else { + $seo_msg['SEO_ADVICE_RESERVED_' . $forum_id] = '<li> ' . sprintf($user->lang['SEO_ADVICE_RESERVED'], $config_value) . '</li>'; + } + } + } elseif ($mode == 'settings') { + if (isset($this->array_type_cfg[$config_name]) && isset($phpbb_seo->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { + if ( is_bool($phpbb_seo->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']]) ) { + $phpbb_seo->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = ($config_value == 1) ? true : false; + } elseif (is_numeric($phpbb_seo->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { + $phpbb_seo->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = intval($config_value); + } elseif (is_string($phpbb_seo->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { + $phpbb_seo->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = $config_value; + } + } elseif ( isset($phpbb_seo->seo_opt[$config_name]) ) { + if ( is_bool($phpbb_seo->seo_opt[$config_name]) ) { + $phpbb_seo->cache_config['settings'][$config_name] = ($config_value == 1) ? true : false; + } elseif ( is_numeric($phpbb_seo->seo_opt[$config_name]) ) { + $phpbb_seo->cache_config['settings'][$config_name] = intval($config_value); + } elseif ( is_string($phpbb_seo->seo_opt[$config_name]) ) { + $phpbb_seo->cache_config['settings'][$config_name] = $config_value; + } + } + // Let's make sure that the proper field was added to the topic table + if ($config_name === 'sql_rewrite' && $config_value == 1 && !$phpbb_seo->seo_opt['sql_rewrite']) { + if (!class_exists('phpbb_db_tools')) { + include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + } + $db_tools = new phpbb_db_tools($db); + $db_tools->db->sql_return_on_error(true); + if (!$db_tools->sql_column_exists(TOPICS_TABLE, 'topic_url')) { + $db_tools->sql_column_add(TOPICS_TABLE, 'topic_url', array('VCHAR', '')); + } + $additional_notes = sprintf($user->lang['SYNC_TOPIC_URL_NOTE'], '<a href="' . $phpbb_seo->seo_path['phpbb_url'] . 'phpbb_seo/sync_url.' . $phpEx . '" onclick="window.open(this.href); return false;">', '</a>'); + if ($db_tools->db->sql_error_triggered) { + $error[] = '<b>' . $user->lang['sql_rewrite'] . '</b> : ' . $user->lang['SEO_SQL_ERROR'] . ' [ ' . $db_tools->db->sql_layer . ' ] : ' . $db_tools->db->sql_error_returned['message'] . ' [' . $db_tools->db->sql_error_returned['code'] . ']' . '<br/>' . $user->lang['SEO_SQL_TRY_MANUALLY'] . '<br/>' . $db_tools->db->sql_error_sql; + $submit = false; + } + $db_tools->db->sql_return_on_error(false); + } + // Let's make sure the proper index is added for the no dupe (in case it is installed and activated) + if ($config_name === 'no_dupe_on' && $config_value == 1 && !$phpbb_seo->seo_opt['no_dupe']['on']) { + if (!class_exists('phpbb_db_tools')) { + include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + } + // in case we already started the phpbb_db_tools class above + if (empty($db_tools)) { + $db_tools = new phpbb_db_tools($db); + } + $db_tools->db->sql_return_on_error(true); + $indexes = $db_tools->sql_list_index(TOPICS_TABLE); + $drop_index_name = 'topic_last_post_id'; + $add_index_name = 'topic_lpid'; + if (in_array($drop_index_name, $indexes)) { + $db_tools->sql_index_drop(TOPICS_TABLE, $drop_index_name); + } + if (!in_array($add_index_name, $indexes)) { + // Try to override some limits - maybe it helps some... + @set_time_limit(0); + @ini_set('memory_limit', '128M'); + $db_tools->sql_create_index(TOPICS_TABLE, $add_index_name, array('topic_last_post_id')); + } + if ($db_tools->db->sql_error_triggered) { + $error[] = '<b>' . $user->lang['no_dupe'] . '</b> : ' . $user->lang['SEO_SQL_ERROR'] . ' [ ' . $db_tools->db->sql_layer . ' ] : ' . $db_tools->db->sql_error_returned['message'] . ' [' . $db_tools->db->sql_error_returned['code'] . ']' . '<br/>' . $user->lang['SEO_SQL_TRY_MANUALLY'] . '<br/>' . $db_tools->db->sql_error_sql; + $submit = false; + } + $db_tools->db->sql_return_on_error(false); + } + } elseif ($mode == 'extended') { + if ($related_installed && $config_name === 'seo_related') { + $fulltext = 0; + $nothing_to_do = false; + if ($db->sql_layer == 'mysql4' || $db->sql_layer == 'mysqli') { + $add = $remove = $alter = false; + if ($config_value && !$config['seo_related']) { + $alter = $add = true; + } + if (!$config_value && $config['seo_related']) { + $alter = $remove = true; + } + // let's go + if ($alter) { + // Try to override some limits - maybe it helps some... + @set_time_limit(0); + @ini_set('memory_limit', '128M'); + // use db_tools to check the index + if (!class_exists('phpbb_db_tools')) { + include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + } + if (empty($db_tools)) { + $db_tools = new phpbb_db_tools($db); + } + $indexes = $db_tools->sql_list_index(TOPICS_TABLE); + if (in_array('topic_tft', $indexes)) { + $nothing_to_do = $add ? true : false; + $fulltext = 1; + } else { + $nothing_to_do = $remove ? true : false; + $fulltext = 0; + } + // do not use db_tools since it does not support to add FullText indexes + if (!$nothing_to_do) { + // Here we use quite a basic approach to make sure that the index is not refused for bad reasons + if ($add) { + $sql = 'ALTER TABLE ' . TOPICS_TABLE . ' + ADD FULLTEXT topic_tft (topic_title)'; + } else { + $sql = 'ALTER TABLE ' . TOPICS_TABLE . ' + DROP INDEX topic_tft'; + } + $db->sql_return_on_error(true); + $db->sql_query($sql); + if ($db->sql_error_triggered) { + $error[] = '<b>' . $user->lang['RELATED_TOPICS'] . '</b> : ' . $user->lang['SEO_SQL_ERROR'] . ' [ ' . $db->sql_layer . ' ] : ' . $db->sql_error_returned['message'] . ' [' . $db->sql_error_returned['code'] . ']' . '<br/>' . $user->lang['SEO_SQL_TRY_MANUALLY'] . '<br/>' . $db->sql_error_sql; + $submit = false; + $config_value = 0; + } + // make *sure* about the index ! + $indexes = $db_tools->sql_list_index(TOPICS_TABLE); + $fulltext = in_array('topic_tft', $indexes) ? 1 : 0; + $db->sql_return_on_error(false); + } + } + } + if ($alter) { + set_config('seo_related_fulltext', $fulltext); + } + } + set_config($config_name, $config_value); + } + } + } + if (sizeof($error)) { + $submit = false; + } + if ($submit) { + if ($mode == 'htaccess') { + if ($this->new_config['save']) { + $this->write_cache($this->write_type); + add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode)); + } + } elseif ($mode == 'extended') { + add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode)); + trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); + } else { + if ( $this->write_cache($this->write_type) ) { + ksort($phpbb_seo->cache_config[$this->write_type]); + add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode)); + $msg = !empty($seo_msg) ? '<br /><h1 style="color:red;text-align:left;">' . $user->lang['SEO_VALIDATE_INFO'] . '</h1><ul style="text-align:left;">' . implode(' ',$seo_msg) . '</ul><br />' : ''; + global $msg_long_text; + $msg_long_text = $user->lang['SEO_CACHE_MSG_OK'] . $msg . adm_back_link($this->u_action); + if ($additional_notes) { + $msg_long_text .= "<br/><br/>$additional_notes"; + } + trigger_error(false); + } else { + trigger_error($user->lang['SEO_CACHE_MSG_FAIL'] . adm_back_link($this->u_action)); + } + } + } + $this->tpl_name = 'acp_board'; + $this->page_title = $display_vars['title']; + $phpbb_seo->seo_end(); + $l_title_explain = $user->lang[$display_vars['title'] . '_EXPLAIN']; + if ($mode != 'extended') { + $l_title_explain .= $mode == 'htaccess' ? '' : $this->check_cache_folder($phpbb_root_path . $phpbb_seo->seo_opt['cache_folder']); + } + $template->assign_vars(array( + 'L_TITLE' => $user->lang[$display_vars['title']], + 'L_TITLE_EXPLAIN' => $l_title_explain, + + 'S_ERROR' => (sizeof($error)) ? true : false, + 'ERROR_MSG' => implode('<br />', $error), + + 'U_ACTION' => $this->u_action) + ); + // Output relevant page + foreach ($display_vars['vars'] as $config_key => $vars) { + if (!is_array($vars) && strpos($config_key, 'legend') === false) { + continue; + } + if (strpos($config_key, 'legend') !== false) { + $template->assign_block_vars('options', array( + 'S_LEGEND' => true, + 'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars) + ); + continue; + } + $type = explode(':', $vars['type']); + $l_explain = ''; + if ($vars['explain'] && isset($vars['lang_explain'])) { + $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain']; + } elseif ($vars['explain'] && isset($vars['lang_explain_custom'])) { + $l_explain = $vars['lang_explain_custom']; + } elseif ($vars['explain']) { + $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; + } + $template->assign_block_vars('options', array( + 'KEY' => $config_key, + 'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'], + 'S_EXPLAIN' => $vars['explain'], + 'TITLE_EXPLAIN' => $l_explain, + 'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars), + ) + ); + unset($display_vars['vars'][$config_key]); + } + } + /** + * forum_url_check validation + */ + function forum_url_input($value, $key) { + global $user, $phpbb_seo; + + return '<input id="' . $key . '" type="text" size="40" maxlength="255" name="config[' . $key . ']" value="' . $value . '" /> '; + } + /** + * select_string custom select string + */ + function select_string($value, $key) { + global $phpbb_seo; + $select_ary = $this->dyn_select[$key]; + $html = ''; + foreach ($select_ary as $sel_value) { + if ( @isset($this->array_type_cfg[$key]) ) { + $selected = ($sel_value == @$phpbb_seo->seo_opt[$this->array_type_cfg[$key]['main']][$this->array_type_cfg[$key]['sub']]) ? ' selected="selected"' : ''; + $sel_title = @isset($this->multiple_options[$this->array_type_cfg[$key]['main']][$this->array_type_cfg[$key]['sub'] . '_lang'][$sel_value]) ? $this->multiple_options[$this->array_type_cfg[$key]['main']][$this->array_type_cfg[$key]['sub'] . '_lang'][$sel_value] : $sel_value; + } else { + $selected = ($sel_value == @$phpbb_seo->cache_config['settings'][$key]) ? ' selected="selected"' : ''; + $sel_title = @isset($this->multiple_options[$key . '_lang'][$sel_value]) ? $this->multiple_options[$key . '_lang'][$sel_value] : $sel_value; + } + $html .= '<option value="' . $sel_value . '"' . $selected . '>' . $sel_title . '</option>'; + } + return $html; + } + /** + * seo_advices Always needed :-) + */ + function seo_advices($url, $forum_id, $cached = FALSE, $error_cust = '') { + global $phpbb_seo, $user; + $seo_advice = ''; + // Check how well is the URL SEO wise + if ( !empty($error_cust) ) { + $seo_advice .= $error_cust; + } + if (strlen($url) > $this->lengh_limit) { // Size + $seo_advice .= '<li> ' . $user->lang['SEO_ADVICE_LENGTH'] . '</li>'; + } + if (preg_match('`^[a-z0-9_-]+' . $phpbb_seo->seo_delim['forum'] . '[0-9]+$`i', $url)) { // With delimiter and id + if (@$phpbb_seo->cache_config['settings']['rem_ids']) { + $seo_advice .= '<li style="color:red"> ' . $user->lang['SEO_ADVICE_DELIM'] . '</li>'; + } + } + if ($phpbb_seo->seo_static['forum'] == $url) { // default + $seo_advice .= '<li> ' . $user->lang['SEO_ADVICE_DEFAULT'] . '</li>'; + } + // Check the number of word + $url_words = explode('-', $url); + if (count($url_words) > $this->word_limit) { + $seo_advice .= '<li> ' . $user->lang['SEO_ADVICE_WORDS'] . '</li>'; + } + return $seo_advice ? '<ul style="color:red">' . $seo_advice . '</ul>' : ''; + } + /** + * seo_htaccess The evil one ;-) + */ + function seo_htaccess($html = true) { + global $phpbb_seo, $user, $error, $phpEx, $config, $phpbb_root_path, $config, $phpbb_admin_path; + static $htaccess_code = ''; + $htaccess_tpl = ''; + // GYM Sitemaps & RSS + $gym_installed = (boolean) (!empty($config['gym_installed']) && file_exists($phpbb_root_path . 'gym_sitemaps/includes/gym_sitemaps.' . $phpEx)); + $rss_path = $google_path = $html_path = ''; + $rss_commpat_note = $google_commpat_note = $html_commpat_note = $compat_path_note = ''; + $rss_commpat_pre = $html_commpat_pre = $google_commpat_pre = '<b style="color:blue"># RewriteRule'; + $rss_commpat_post = $html_commpat_post = $google_commpat_post = '</b>'; + $google_comp_path = $rss_comp_path = $html_comp_path = false; + if ($gym_installed) { + $compat_path_note = '<b style="color:red"># NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT' . "\n"; + $compat_path_note .= '# BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE' . "\n"; + $compat_path_note .= '# WITH PROPER SLASHES AND PATHS</b>' . "\n"; + $rss_commpat_note = $google_commpat_note = $html_commpat_note = $compat_path_note; + require_once($phpbb_root_path . 'gym_sitemaps/includes/gym_common.' . $phpEx); + obtain_gym_config('main', $gym_config); + $google_url = trim($gym_config['google_url'], '/') . '/'; + if (utf8_strpos($google_url, $phpbb_seo->seo_path['phpbb_url']) !== false) { + $google_path = trim(str_replace($phpbb_seo->seo_path['root_url'], '', $google_url), '/'); + $google_comp_path = true; + $google_commpat_pre = '<b style="color:green">RewriteRule</b>'; + $google_commpat_post = $google_commpat_note = ''; + } + $rss_url = trim($gym_config['rss_url'], '/') . '/'; + if (utf8_strpos($rss_url, $phpbb_seo->seo_path['phpbb_url']) !== false) { + $rss_path = trim(str_replace($phpbb_seo->seo_path['root_url'], '', $rss_url), '/'); + $rss_comp_path = true; + $rss_commpat_pre = '<b style="color:green">RewriteRule</b>'; + $rss_commpat_post = $rss_commpat_note = ''; + } + $html_url = trim($gym_config['html_url'], '/') . '/'; + if (utf8_strpos($html_url, $phpbb_seo->seo_path['phpbb_url']) !== false) { + $html_path = trim(str_replace($phpbb_seo->seo_path['root_url'], '', $html_url), '/'); + $html_comp_path = true; + $html_commpat_pre = '<b style="color:green">RewriteRule</b>'; + $html_commpat_post = $html_commpat_note = ''; + } + } + if ( empty($htaccess_code) ) { + // get mods .htaccess tpls + $mods_ht = $this->get_mods_ht(); + $default_slash = '/'; + $wierd_slash = ''; + $phpbb_path = trim($phpbb_seo->seo_path['phpbb_script'], '/'); + $show_rewritebase_opt = false; + $rewritebase = ''; + $wierd_slash = $this->new_config['wslash'] ? '<b style="color:red">/</b>' : ''; + $default_slash = $this->new_config['slash'] ? '' : '/'; + + if (!empty($phpbb_path )) { + $phpbb_path = $phpbb_path . '/'; + if ($this->new_config['rbase']) { + $rewritebase = $phpbb_path; + $default_slash = $this->new_config['slash'] ? '/' : ''; + } + $rewritebase = $this->new_config['rbase'] ? $phpbb_path : ''; + $show_rewritebase_opt = $phpbb_seo->seo_opt['virtual_root'] ? false : true; + } + if (!empty($rewritebase)) { + $rss_path = trim(str_replace(trim($phpbb_path, '/'), '', $rss_path), '/'); + $google_path = trim(str_replace(trim($phpbb_path, '/'), '', $google_path), '/'); + $html_path = trim(str_replace(trim($phpbb_path, '/'), '', $html_path), '/'); + } + $colors = array( 'color' => '<b style="color:%1$s">%2$s</b>', + 'static' => '#A020F0', + 'ext' => '#6A5ACD', + 'delim' => '#FF00FF', + ); + $tpl = array('paginpage' => '/?(<b style="color:' . $colors['static'] . '">%1$s</b>([0-9]+)<b style="color:' . $colors['ext'] . '">%2$s</b>)?', + 'pagin' => '(<b style="color:' . $colors['delim'] . '">%1$s</b>([0-9]+))?<b style="color:' . $colors['ext'] . '">%2$s</b>', + 'static' => sprintf($colors['color'] , $colors['static'], '%1$s'), + 'ext' => sprintf($colors['color'] , $colors['ext'], '%1$s'), + 'delim' => sprintf($colors['color'] , $colors['delim'], '%1$s'), + ); + $modrtype = array( 1 => 'SIMPLE', 2 => 'MIXED', 1 => 'SIMPLE', 3 => 'ADVANCED', 'type' => intval($phpbb_seo->modrtype)); + // + $htaccess_tpl = '<b style="color:blue"># Lines That should already be in your .htacess</b>' . "\n"; + $htaccess_tpl .= '<b style="color:brown"><Files</b> <b style="color:#FF00FF">"config.{PHP_EX}"</b><b style="color:brown">></b>' . "\n"; + $htaccess_tpl .= "\t" . 'Order Allow,Deny' . "\n"; + $htaccess_tpl .= "\t" . 'Deny from All' . "\n"; + $htaccess_tpl .= '<b style="color:brown"></Files></b>' . "\n"; + $htaccess_tpl .= '<b style="color:brown"><Files</b> <b style="color:#FF00FF">"common.{PHP_EX}"</b><b style="color:brown">></b>' . "\n"; + $htaccess_tpl .= "\t" . 'Order Allow,Deny' . "\n"; + $htaccess_tpl .= "\t" . 'Deny from All' . "\n"; + $htaccess_tpl .= '<b style="color:brown"></Files></b>' . "\n\n"; + $htaccess_tpl .= '<b style="color:blue"># You may need to un-comment the following lines' . "\n"; + $htaccess_tpl .= '# Options +FollowSymlinks' . "\n"; + $htaccess_tpl .= '# To make sure that rewritten dir or file (/|.html) will not load dir.php in case it exist' . "\n"; + $htaccess_tpl .= '# Options -MultiViews' . "\n"; + $htaccess_tpl .= '# REMEBER YOU ONLY NEED TO STARD MOD REWRITE ONCE</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteEngine</b> <b style="color:#FF00FF">On</b>' . "\n"; + $htaccess_tpl .= '<b style="color:blue"># Uncomment the statement below if you want to make use of' . "\n"; + $htaccess_tpl .= '# HTTP authentication and it does not already work.' . "\n"; + $htaccess_tpl .= '# This could be required if you are for example using PHP via Apache CGI.' . "\n"; + $htaccess_tpl .= '# RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]</b>' . "\n"; + $htaccess_tpl .= '<b style="color:blue"># REWRITE BASE</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteBase</b> <b>/{REWRITEBASE}</b>' . "\n"; + $htaccess_tpl .= '<b style="color:blue"># HERE IS A GOOD PLACE TO FORCE CANONICAL DOMAIN</b>' . "\n"; + $htaccess_tpl .= '<b style="color:blue"># RewriteCond %{HTTP_HOST} !^' . str_replace(array('https://', 'http://', '.'), array('', '', '\\.'), trim($phpbb_seo->seo_path['root_url'], '/ ')) . '$ [NC]</b>' . "\n"; + $htaccess_tpl .= '<b style="color:blue"># RewriteRule ^(.*)$ ' . $phpbb_seo->seo_path['root_url'] . '{REWRITEBASE}$1 [QSA,L,R=301]</b>' . "\n\n"; + $htaccess_tpl .= '<b style="color:blue"># DO NOT GO FURTHER IF THE REQUESTED FILE / DIR DOES EXISTS</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} -f' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} -d' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> . - [L]' . "\n"; + $htaccess_tpl .= '<b style="color:blue">#####################################################' . "\n"; + $htaccess_tpl .= '# PHPBB SEO REWRITE RULES ALL MODES' . "\n"; + $htaccess_tpl .= '#####################################################' . "\n"; + $htaccess_tpl .= '# AUTHOR : dcz www.phpbb-seo.com' . "\n"; + $htaccess_tpl .= '# STARTED : 01/2006' . "\n"; + $htaccess_tpl .= '#################################' . "\n"; + $htaccess_tpl .= '# FORUMS PAGES' . "\n"; + $htaccess_tpl .= '###############</b>' . "\n"; + if (!empty($phpbb_seo->seo_static['index'])) { + $htaccess_tpl .= '<b style="color:blue"># FORUM INDEX</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_INDEX}{EXT_INDEX}$ {DEFAULT_SLASH}{PHPBB_RPATH}index.{PHP_EX} [QSA,L,NC]' . "\n"; + } else { + $htaccess_tpl .= '<b style="color:blue"># FORUM INDEX REWRITERULE WOULD STAND HERE IF USED. "forum" REQUIRES TO BE SET AS FORUM INDEX' . "\n"; + $htaccess_tpl .= '# RewriteRule ^{WIERD_SLASH}{PHPBB_LPATH}<b style="color:#A020F0">forum</b>\.<b style="color:#6A5ACD">html</b>$ {DEFAULT_SLASH}{PHPBB_RPATH}index.{PHP_EX} [QSA,L,NC]</b>' . "\n"; + } + $htaccess_common_tpl = '<b style="color:blue"># PHPBB FILES ALL MODES</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_FILE_INDEX}{DELIM_FILE}[a-z0-9_-]+{DELIM_FILE}({STATIC_THUMB}{DELIM_FILE})?([0-9]+)$ {DEFAULT_SLASH}{PHPBB_RPATH}download/file.{PHP_EX}?id=$2&t=$1 [QSA,L,NC]' . "\n"; + if ( $phpbb_seo->seo_opt['profile_noids'] ) { + $htaccess_common_tpl .= '<b style="color:blue"># PROFILES THROUGH USERNAME</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_USER}/([^/]+)/?$ {DEFAULT_SLASH}{PHPBB_RPATH}memberlist.{PHP_EX}?mode=viewprofile&un=$1 [QSA,L,NC]' . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># USER MESSAGES THROUGH USERNAME</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_USER}/([^/]+)/(topics|posts){USER_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}search.{PHP_EX}?author=$1&sr=$2&start=$4 [QSA,L,NC]' . "\n"; + } else { + $htaccess_common_tpl .= '<b style="color:blue"># PROFILES ALL MODES WITH ID</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}({STATIC_USER}|[a-z0-9_-]*{DELIM_USER})([0-9]+){EXT_USER}$ {DEFAULT_SLASH}{PHPBB_RPATH}memberlist.{PHP_EX}?mode=viewprofile&u=$2 [QSA,L,NC]' . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># USER MESSAGES ALL MODES WITH ID</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}({STATIC_USER}|[a-z0-9_-]*{DELIM_USER})([0-9]+){DELIM_SR}(topics|posts){USER_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}search.{PHP_EX}?author_id=$2&sr=$3&start=$5 [QSA,L,NC]' . "\n"; + } + $htaccess_common_tpl .= '<b style="color:blue"># GROUPS ALL MODES</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}({STATIC_GROUP}|[a-z0-9_-]*{DELIM_GROUP})([0-9]+){GROUP_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}memberlist.{PHP_EX}?mode=group&g=$2&start=$4 [QSA,L,NC]' . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># POST</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_POST}([0-9]+){EXT_POST}$ {DEFAULT_SLASH}{PHPBB_RPATH}viewtopic.{PHP_EX}?p=$1 [QSA,L,NC]' . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># ACTIVE TOPICS</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_ATOPIC}{ATOPIC_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}search.{PHP_EX}?search_id=active_topics&start=$2&sr=topics [QSA,L,NC]' . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># UNANSWERED TOPICS</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_UTOPIC}{UTOPIC_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}search.{PHP_EX}?search_id=unanswered&start=$2&sr=topics [QSA,L,NC]' . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># NEW POSTS</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_NPOST}{NPOST_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}search.{PHP_EX}?search_id=newposts&start=$2&sr=topics [QSA,L,NC]' . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># UNREAD POSTS</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_URPOST}{URPOST_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}search.{PHP_EX}?search_id=unreadposts&start=$2 [QSA,L,NC]' . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># THE TEAM</b>' . "\n"; + $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_LEADERS}{EXT_LEADERS}$ {DEFAULT_SLASH}{PHPBB_RPATH}memberlist.{PHP_EX}?mode=leaders [QSA,L,NC]' . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># HERE IS A GOOD PLACE TO ADD OTHER PHPBB RELATED REWRITERULES</b>' . "\n\n"; + if ($gym_installed) { + $htaccess_common_tpl .= '<b style="color:blue">#####################################################' . "\n"; + // RSS + $htaccess_common_tpl .= '# GYM Sitemaps & RSS' . "\n"; + $htaccess_common_tpl .= '# Global channels</b>' . "\n"; + $htaccess_common_tpl .= $rss_commpat_note; + $htaccess_common_tpl .= $rss_commpat_pre . ' ^{WIERD_SLASH}{RSS_LPATH}rss(/(news)+)?(/(digest)+)?(/(short|long)+)?/?$ {DEFAULT_SLASH}{RSS_RPATH}gymrss.{PHP_EX}?channels&$2&$4&$6 [QSA,L,NC]' . $rss_commpat_post . "\n"; + // HTML + $htaccess_common_tpl .= '<b style="color:blue"># HTML Global news & maps</b>' . "\n"; + $htaccess_common_tpl .= $html_commpat_note; + $htaccess_common_tpl .= $html_commpat_pre . ' ^{WIERD_SLASH}{HTML_LPATH}(news|maps){PAGE_PAGINATION}$ {DEFAULT_SLASH}{HTML_RPATH}map.{PHP_EX}?$1&start=$3 [QSA,L,NC]' . $html_commpat_post . "\n"; + $htaccess_common_tpl .= '<b style="color:blue"># END GYM Sitemaps & RSS' . "\n"; + $htaccess_common_tpl .= '#####################################################</b>' . "\n\n"; + } + // We now handle all modes at once (simple / mixed / advanced) + $htaccess_tpl .= '<b style="color:blue"># FORUM ALL MODES</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}({STATIC_FORUM}|[a-z0-9_-]*{DELIM_FORUM})([0-9]+){FORUM_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}viewforum.{PHP_EX}?f=$2&start=$4 [QSA,L,NC]' . "\n"; + $htaccess_tpl .= '<b style="color:blue"># TOPIC WITH VIRTUAL FOLDER ALL MODES</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}({STATIC_FORUM}|[a-z0-9_-]*{DELIM_FORUM})([0-9]+)/({STATIC_TOPIC}|[a-z0-9_-]*{DELIM_TOPIC})([0-9]+){TOPIC_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}viewtopic.{PHP_EX}?f=$2&t=$4&start=$6 [QSA,L,NC]' . "\n"; + // Not needed any more + // $htaccess_tpl .= '<b style="color:blue"># GLOBAL ANNOUNCEMENTS WITH VIRTUAL FOLDER ALL MODES</b>' . "\n"; + // $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_GLOBAL_ANNOUNCE}{EXT_GLOBAL_ANNOUNCE}({STATIC_TOPIC}|[a-z0-9_-]*{DELIM_TOPIC})([0-9]+){TOPIC_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}viewtopic.{PHP_EX}?t=$2&start=$4 [QSA,L,NC]' . "\n"; + $htaccess_tpl .= '<b style="color:blue"># TOPIC WITHOUT FORUM ID & DELIM ALL MODES</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}([a-z0-9_-]*)/?({STATIC_TOPIC}|[a-z0-9_-]*{DELIM_TOPIC})([0-9]+){TOPIC_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}viewtopic.{PHP_EX}?forum_uri=$1&t=$3&start=$5 [QSA,L,NC]' . "\n"; + $htaccess_tpl .= $htaccess_common_tpl; + // mods .htaccess pos1 + if (!empty($mods_ht['pos1'])) { + $htaccess_tpl .= $mods_ht['pos1']; + } + $htaccess_tpl .= '<b style="color:blue"># FORUM WITHOUT ID & DELIM ALL MODES</b>' . "\n"; + if ($phpbb_seo->seo_ext['forum'] != '/') { + $htaccess_tpl .= '<b style="color:blue"># THESE FOUR LINES MUST BE LOCATED AT THE END OF YOUR HTACCESS TO WORK PROPERLY</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} !-f' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}([a-z0-9_-]+)(-([0-9]+)){EXT_FORUM}$ {DEFAULT_SLASH}{PHPBB_RPATH}viewforum.{PHP_EX}?forum_uri=$1&start=$3 [QSA,L,NC]' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} !-f' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}([a-z0-9_-]+){EXT_FORUM}$ {DEFAULT_SLASH}{PHPBB_RPATH}viewforum.{PHP_EX}?forum_uri=$1 [QSA,L,NC]' . "\n"; + } else { + $htaccess_tpl .= '<b style="color:blue"># THESE THREE LINES MUST BE LOCATED AT THE END OF YOUR HTACCESS TO WORK PROPERLY</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} !-f' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} !-d' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}([a-z0-9_-]+){FORUM_PAGINATION}$ {DEFAULT_SLASH}{PHPBB_RPATH}viewforum.{PHP_EX}?forum_uri=$1&start=$3 [QSA,L,NC]' . "\n"; + } + // fix for dumb clients unable to deal with base href + $htaccess_tpl .= '<b style="color:blue"># FIX RELATIVE PATHS : FILES</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_RPATH}.+/(style\.{PHP_EX}|ucp\.{PHP_EX}|mcp\.{PHP_EX}|faq\.{PHP_EX}|download/file.{PHP_EX})$ {DEFAULT_SLASH}{PHPBB_RPATH}$1 [QSA,L,NC,R=301]' . "\n"; + $htaccess_tpl .= '<b style="color:blue"># FIX RELATIVE PATHS : IMAGES</b>' . "\n"; + $htaccess_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_RPATH}.+/(styles/.*|images/.*)/$ {DEFAULT_SLASH}{PHPBB_RPATH}$1 [QSA,L,NC,R=301]' . "\n"; + $htaccess_tpl .= '<b style="color:blue"># END PHPBB PAGES' . "\n"; + $htaccess_tpl .= '#####################################################</b>' . "\n\n"; + // mods .htaccess pos2 + if (!empty($mods_ht['pos2'])) { + $htaccess_tpl .= $mods_ht['pos2']; + } + if ($gym_installed) { + $htaccess_tpl .= '<b style="color:blue">#####################################################' . "\n"; + $htaccess_tpl .= '# GYM Sitemaps & RSS</b>' . "\n"; + // HTML + $htaccess_tpl .= '<b style="color:blue"># HTML Module additional modes</b>' . "\n"; + $htaccess_tpl .= $html_commpat_note; + $htaccess_tpl .= $html_commpat_pre . ' ^{WIERD_SLASH}{HTML_LPATH}(news|maps)/([a-z0-9_-]+)(/([a-z0-9_-]+))?{PAGE_PAGINATION}$ {DEFAULT_SLASH}{HTML_RPATH}map.{PHP_EX}?$2=$4&$1&start=$6 [QSA,L,NC]' . $html_commpat_post . "\n"; + // RSS + $htaccess_tpl .= '<b style="color:blue"># Main feeds & channels</b>' . "\n"; + $htaccess_tpl .= $rss_commpat_note; + $htaccess_tpl .= $rss_commpat_pre . ' ^{WIERD_SLASH}{RSS_LPATH}rss(/(news)+)?(/(digest)+)?(/(short|long)+)?(/([a-z0-9_-]+))?/([a-z0-9_]+)\.xml(\.gz)?$ {DEFAULT_SLASH}{RSS_RPATH}gymrss.{PHP_EX}?$9=$8&$2&$4&$6&gzip=$10 [QSA,L,NC]' . $rss_commpat_post . "\n"; + $htaccess_tpl .= '<b style="color:blue"># Module feeds</b>' . "\n"; + $htaccess_tpl .= $rss_commpat_note; + $htaccess_tpl .= $rss_commpat_pre . ' ^{WIERD_SLASH}{RSS_LPATH}[a-z0-9_-]*-[a-z]{1,2}([0-9]+)(/(news)+)?(/(digest)+)?(/(short|long)+)?/([a-z0-9_]+)\.xml(\.gz)?$ {DEFAULT_SLASH}{RSS_RPATH}gymrss.{PHP_EX}?$8=$1&$3&$5&$7&gzip=$9 [QSA,L,NC]' . $rss_commpat_post . "\n"; + $htaccess_tpl .= '<b style="color:blue"># Module feeds without ids</b>' . "\n"; + $htaccess_tpl .= $rss_commpat_note; + $htaccess_tpl .= $rss_commpat_pre . ' ^{WIERD_SLASH}{RSS_LPATH}([a-z0-9_-]+)(/(news)+)?(/(digest)+)?(/(short|long)+)?/([a-z0-9_]+)\.xml(\.gz)?$ {DEFAULT_SLASH}{RSS_RPATH}gymrss.{PHP_EX}?nametoid=$1&$3&$5&$7&modulename=$8&gzip=$9 [QSA,L,NC]' . $rss_commpat_post . "\n"; + // Google + $htaccess_tpl .= '<b style="color:blue"># Google SitemapIndex</b>' . "\n"; + $htaccess_tpl .= $google_commpat_note; + $htaccess_tpl .= $google_commpat_pre . ' ^{WIERD_SLASH}{GOOGLE_LPATH}sitemapindex\.xml(\.gz)?$ {DEFAULT_SLASH}{GOOGLE_RPATH}sitemap.{PHP_EX}?gzip=$1 [QSA,L,NC]' . $google_commpat_post . "\n"; + $htaccess_tpl .= '<b style="color:blue"># Module cat sitemaps</b>' . "\n"; + $htaccess_tpl .= $google_commpat_note; + $htaccess_tpl .= $google_commpat_pre . ' ^{WIERD_SLASH}{GOOGLE_LPATH}[a-z0-9_-]+-([a-z]{1,2})([0-9]+)\.xml(\.gz)?$ {DEFAULT_SLASH}{GOOGLE_RPATH}sitemap.{PHP_EX}?module_sep=$1&module_sub=$2&gzip=$3 [QSA,L,NC]' . $google_commpat_post . "\n"; + $htaccess_tpl .= '<b style="color:blue"># Module sitemaps</b>' . "\n"; + $htaccess_tpl .= $google_commpat_note; + $htaccess_tpl .= $google_commpat_pre . ' ^{WIERD_SLASH}{GOOGLE_LPATH}([a-z0-9_]+)-([a-z0-9_-]+)\.xml(\.gz)?$ {DEFAULT_SLASH}{GOOGLE_RPATH}sitemap.{PHP_EX}?$1=$2&gzip=$3 [QSA,L,NC]' . $google_commpat_post . "\n"; + $htaccess_tpl .= '<b style="color:blue"># END GYM Sitemaps & RSS' . "\n"; + $htaccess_tpl .= '#####################################################</b>' . "\n"; + } + + if (!empty($default_slash) && $this->new_config['more_options']) { + $default_slash = '<b style="color:red">' . $default_slash . '</b>'; + } + // The tpl array + $htaccess_tpl_vars = array(); + + // handle the suffixes proper in the RegEx + // set up pagination reg ex + // set up ext bits + $seo_ext = array('pagination' => str_replace('.', '\\.', $phpbb_seo->seo_ext['pagination'])); + $reg_ex_page = sprintf($tpl['paginpage'], $phpbb_seo->seo_static['pagination'], $seo_ext['pagination'] . ($seo_ext['pagination'] === '/' ? '?' : '') ); + foreach ( $phpbb_seo->seo_ext as $type => $value) { + $seo_ext[$type] = str_replace('.', '\\.', $value); + $htaccess_tpl_vars['{' . strtoupper($type) . '_PAGINATION}'] = ($value === '/') ? $reg_ex_page : sprintf($tpl['pagin'], $phpbb_seo->seo_delim['start'], $seo_ext[$type]); + // use url/? to allow both url and url/ to work as expected + $htaccess_tpl_vars['{EXT_' . strtoupper($type) . '}'] = sprintf($tpl['ext'] , $seo_ext[$type]) . ($value === '/' ? '?' : ''); + + } + $htaccess_tpl_vars['{PAGE_PAGINATION}'] = $reg_ex_page; + // static bits + foreach ( $phpbb_seo->seo_static as $type => $value) { + if (!is_array($phpbb_seo->seo_static[$type])) { + $htaccess_tpl_vars['{STATIC_' . strtoupper($type) . '}'] = sprintf($tpl['static'] , $phpbb_seo->seo_static[$type]); + } + } + // delim bits + foreach ( $phpbb_seo->seo_delim as $type => $value) { + $htaccess_tpl_vars['{DELIM_' . strtoupper($type) . '}'] = sprintf($tpl['delim'] , $phpbb_seo->seo_delim[$type]); + } + + // common .htaccess vars + $htaccess_tpl_vars += array( + '{REWRITEBASE}' => $rewritebase, + '{PHP_EX}' => $phpEx, + '{PHPBB_LPATH}' => ($this->new_config['rbase'] || $phpbb_seo->seo_opt['virtual_root']) ? '' : $phpbb_path, + '{PHPBB_RPATH}' => $this->new_config['rbase'] ? '' : $phpbb_path, + '{RSS_LPATH}' => $rss_path ? $rss_path . '/' : '', + '{RSS_RPATH}' => $rss_path ? $rss_path . '/' : '', + '{GOOGLE_LPATH}' => $google_path ? $google_path . '/' : '', + '{GOOGLE_RPATH}' => $google_path ? $google_path . '/' : '', + '{HTML_LPATH}' => $html_path ? $html_path . '/' : '', + '{HTML_RPATH}' => $html_path ? $html_path . '/' : '', + '{DEFAULT_SLASH}' => $default_slash, + '{WIERD_SLASH}' => $wierd_slash, + '{MOD_RTYPE}' => $modrtype[$modrtype['type']], + ); + // Parse .htaccess + $htaccess_code = str_replace(array_keys($htaccess_tpl_vars), array_values($htaccess_tpl_vars), $htaccess_tpl); + } // else the .htaccess is already generated + if ( $html ) { // HTML output + $htaccess_output = "\n" . '<script type="text/javascript">' . "\n"; + $htaccess_output .= '// <![CDATA[' . "\n"; + $htaccess_output .= 'function selectCode(a) {' . "\n"; + $htaccess_output .= "\t" . 'var e = a.parentNode.parentNode.getElementsByTagName(\'CODE\')[0]; // Get ID of code block' . "\n"; + $htaccess_output .= "\t" . 'if (window.getSelection) { // Not IE' . "\n"; + $htaccess_output .= "\t\t" . 'var s = window.getSelection();' . "\n"; + $htaccess_output .= "\t\t" . 'if (s.setBaseAndExtent) { // Safari' . "\n"; + $htaccess_output .= "\t\t\t" . 's.setBaseAndExtent(e, 0, e, e.innerText.length - 1);' . "\n"; + $htaccess_output .= "\t\t" . '} else { // Firefox and Opera' . "\n"; + $htaccess_output .= "\t\t\t" . 'var r = document.createRange();' . "\n"; + $htaccess_output .= "\t\t\t" . 'r.selectNodeContents(e);' . "\n"; + $htaccess_output .= "\t\t\t" . 's.removeAllRanges();' . "\n"; + $htaccess_output .= "\t\t\t" . 's.addRange(r);' . "\n"; + $htaccess_output .= "\t\t" . '}' . "\n"; + $htaccess_output .= "\t" . '} else if (document.getSelection) { // Some older browsers' . "\n"; + $htaccess_output .= "\t\t" . 'var s = document.getSelection();' . "\n"; + $htaccess_output .= "\t\t" . 'var r = document.createRange();' . "\n"; + $htaccess_output .= "\t\t" . 'r.selectNodeContents(e);' . "\n"; + $htaccess_output .= "\t\t" . 's.removeAllRanges();' . "\n"; + $htaccess_output .= "\t\t" . 's.addRange(r);' . "\n"; + $htaccess_output .= "\t" . '} else if (document.selection) { // IE' . "\n"; + $htaccess_output .= "\t\t" . 'var r = document.body.createTextRange();' . "\n"; + $htaccess_output .= "\t\t" . 'r.moveToElementText(e);' . "\n"; + $htaccess_output .= "\t\t" . 'r.select();' . "\n"; + $htaccess_output .= "\t" . '}' . "\n"; + $htaccess_output .= '}' . "\n"; + $htaccess_output .= '// ]]>' . "\n"; + $htaccess_output .= '</script>' . "\n"; + // build location message + if ($show_rewritebase_opt && $this->new_config['rbase']) { + $msg_loc = sprintf($user->lang['SEO_HTACCESS_FOLDER_MSG'], '<em style="color:#000">' . $phpbb_seo->seo_path['phpbb_url'] . '</em>'); + } else { + $msg_loc = sprintf($user->lang['SEO_HTACCESS_ROOT_MSG'], '<em style="color:#000">' . $phpbb_seo->seo_path['root_url'] . '</em>'); + } + $htaccess_output .= '</p><div class="content"><hr/>' . "\n" . '<b style="color:red">⇒ ' . $msg_loc . '</b><br/><br/><hr/>' . "\n"; + $htaccess_output .= '<b>.htaccess : <a href="#" onclick="dE(\'htaccess_code\',1); return false;">' . $user->lang['SEO_SHOW'] . '</a> / <a href="#" onclick="dE(\'htaccess_code\',-1); return false;">' . $user->lang['SEO_HIDE'] . '</a></b>' . "\n"; + $htaccess_output .= '<div id="htaccess_code"><dl style="padding:5px;background-color:#FFFFFF;border:1px solid #d8d8d8;font-size:12px;"><dt style="border-bottom:1px solid #CCCCCC;margin-bottom:3px;font-weight:bold;display:block;"> <a href="#" onclick="selectCode(this); return false;">' . $user->lang['SEO_SELECT_ALL'] . '</a></dt>' . "\n"; + $htaccess_output .= '<dd ><code style="padding-top:5px;line-height:1.3em;color:#8b8b8b;font-weight:bold"><br/><br/>' . str_replace( "\n", '<br/>', $htaccess_code) . '</code></dd>' . "\n"; + $htaccess_output .= '</dl>' . "\n"; + $htaccess_output .= '<div style="padding:5px;margin-top:10px;background-color:#FFFFFF;border:1px solid #d8d8d8;font-size:12px;"><b>' . $user->lang['SEO_HTACCESS_CAPTION'] . ':</b><ul style="margin-left:30px;margin-top:10px;font-weight:bold;font-size:12px;">' . "\n"; + $htaccess_output .= '<li style="color:blue"> ' . $user->lang['SEO_HTACCESS_CAPTION_COMMENT'] . '</li>' . "\n"; + $htaccess_output .= '<li style="color:#A020F0"> ' . $user->lang['SEO_HTACCESS_CAPTION_STATIC'] . '</li>' . "\n"; + $htaccess_output .= '<li style="color:#6A5ACD"> ' . $user->lang['SEO_HTACCESS_CAPTION_SUFFIX'] . '</li>' . "\n"; + $htaccess_output .= '<li style="color:#FF00FF"> ' . $user->lang['SEO_HTACCESS_CAPTION_DELIM'] . '</li>' . "\n"; + if ($this->new_config['more_options']) { + $htaccess_output .= '<li style="color:red"> ' . $user->lang['SEO_HTACCESS_CAPTION_SLASH'] . '</li> ' . "\n"; + } + $htaccess_output .= '</ul></div>' . "\n" . '</div></div><p>' . "\n"; + } else { // File output + $htaccess_output = str_replace(array('<', '>', '&'), array('<', '>', '&'), strip_tags($htaccess_code)); + } + return $htaccess_output; + } + /** + * get_mods_ht Get all mods htaccess tpls + */ + function get_mods_ht() { + global $phpEx, $config, $phpbb_root_path, $phpbb_seo; + $all_ht_tpl = array('pos1' => '', 'pos2' => ''); + $path = $phpbb_root_path . 'phpbb_seo/includes/htmods'; + if (!($dir = @opendir($path))) { + return false; + } + while( ($file = @readdir($dir)) !== false ) { + if (!trim($file, '. ')) { + continue; + } + if(preg_match('`^ht_([a-z0-9_-]+)\.' . $phpEx . '$`i', $file, $match)) { + $mode = $match[1]; + $class = 'ht_' . $mode; + require_once("$path/$file"); + $module = new $class(); + if ($tpl = $module->get_tpl()) { + if (!empty($tpl['pos1'])) { + $all_ht_tpl['pos1'] .= $tpl['pos1'] . "\n"; + } + if (!empty($tpl['pos2'])) { + $all_ht_tpl['pos2'] .= $tpl['pos2'] . "\n"; + } + } + } + } + return !empty($all_ht_tpl['pos1']) || !empty($all_ht_tpl['pos2']) ? $all_ht_tpl : false; + + } + /** + * set_phpbb_seo_links Builds links to support threads + */ + function set_phpbb_seo_links() { + global $user, $phpbb_seo, $config; + $modrtype_lang = array(); + $phpbb_seo->version = htmlspecialchars($phpbb_seo->version); + $phpbb_seo->modrtype = intval($phpbb_seo->modrtype); + if ($phpbb_seo->modrtype < 1 || $phpbb_seo->modrtype > 3) { + $phpbb_seo->modrtype = 1; + } + $modrtype_lang['titles'] = array( 1 => $user->lang['ACP_SEO_SIMPLE'], 2 => $user->lang['ACP_SEO_MIXED'], 3 => $user->lang['ACP_SEO_ADVANCED'], 'u' => $user->lang['ACP_ULTIMATE_SEO_URL']); + $modrtype_lang['title'] = $modrtype_lang['titles'][$phpbb_seo->modrtype]; + $modrtype_lang['utitle'] = $modrtype_lang['titles']['u']; + $modrtype_lang['types'] = array( 1 => 'SIMPLE', 2 => 'MIXED', 1 => 'SIMPLE', 3 => 'ADVANCED'); + $modrtype_lang['type'] = $modrtype_lang['types'][$phpbb_seo->modrtype]; + $modrtype_lang['modrlinks_en'] = array( 1 => 'http://www.phpbb-seo.com/en/simple-seo-url/simple-phpbb-seo-url-t1566.html', 2 => 'http://www.phpbb-seo.com/en/mixed-seo-url/mixed-phpbb-seo-url-t1565.html', 3 => 'http://www.phpbb-seo.com/en/advanced-seo-url/advanced-phpbb-seo-url-t1219.html', 'u' => 'http://www.phpbb-seo.com/en/phpbb-mod-rewrite/ultimate-seo-url-t4608.html' ); + $modrtype_lang['modrlinks_fr'] = array( 1 => 'http://www.phpbb-seo.com/fr/reecriture-url-simple/seo-url-phpbb-simple-t1945.html', 2 => 'http://www.phpbb-seo.com/fr/reecriture-url-intermediaire/seo-url-intermediaire-t1946.html', 3 => 'http://www.phpbb-seo.com/fr/reecriture-url-avancee/seo-url-phpbb-avance-t1501.html', 'u' => 'http://www.phpbb-seo.com/fr/mod-rewrite-phpbb/ultimate-seo-url-t4489.html' ); + $modrtype_lang['modrforumlinks_en'] = array( 1 => 'http://www.phpbb-seo.com/en/simple-seo-url/', 2 => 'http://www.phpbb-seo.com/en/mixed-seo-url/', 3 => 'http://www.phpbb-seo.com/en/advanced-seo-url/', 'u' => 'http://www.phpbb-seo.com/en/phpbb-mod-rewrite/' ); + $modrtype_lang['modrforumlinks_fr'] = array( 1 => 'http://www.phpbb-seo.com/fr/reecriture-url-simple/', 2 => 'http://www.phpbb-seo.com/fr/reecriture-url-intermediaire/', 3 => 'http://www.phpbb-seo.com/fr/reecriture-url-avancee/', 'u' => 'http://www.phpbb-seo.com/fr/mod-rewrite-phpbb/' ); + if (strpos($config['default_lang'], 'fr') !== false ) { + $modrtype_lang['linkurl'] = $modrtype_lang['modrlinks_fr'][$phpbb_seo->modrtype]; + $modrtype_lang['forumlinkurl'] = $modrtype_lang['modrforumlinks_fr'][$phpbb_seo->modrtype]; + $modrtype_lang['ulinkurl'] = $modrtype_lang['modrlinks_fr']['u']; + $modrtype_lang['uforumlinkurl'] = $modrtype_lang['modrforumlinks_fr']['u']; + } else { + $modrtype_lang['linkurl'] = $modrtype_lang['modrlinks_en'][$phpbb_seo->modrtype]; + $modrtype_lang['forumlinkurl'] = $modrtype_lang['modrforumlinks_en'][$phpbb_seo->modrtype]; + $modrtype_lang['ulinkurl'] = $modrtype_lang['modrlinks_en']['u']; + $modrtype_lang['uforumlinkurl'] = $modrtype_lang['modrforumlinks_en']['u']; + } + $modrtype_lang['link'] = '<a href="' . $modrtype_lang['linkurl'] . '" title="' . $user->lang['ACP_PHPBB_SEO_VERSION'] . ' ' . $modrtype_lang['title'] . '" onclick="window.open(this.href); return false;"><b>' . $modrtype_lang['title'] . '</b></a>'; + $modrtype_lang['forumlink'] = '<a href="' . $modrtype_lang['forumlinkurl'] . '" title="' . $user->lang['ACP_SEO_SUPPORT_FORUM'] . '" onclick="window.open(this.href); return false;"><b>' . $user->lang['ACP_SEO_SUPPORT_FORUM'] . '</b></a>'; + $modrtype_lang['ulink'] = '<a href="' . $modrtype_lang['ulinkurl'] . '" title="' . $user->lang['ACP_PHPBB_SEO_VERSION'] . ' ' . $modrtype_lang['utitle'] . '" onclick="window.open(this.href); return false;"><b>' . $modrtype_lang['utitle'] . '</b></a>'; + $modrtype_lang['uforumlink'] = '<a href="' . $modrtype_lang['uforumlinkurl'] . '" title="' . $user->lang['ACP_SEO_SUPPORT_FORUM'] . '" onclick="window.open(this.href); return false;"><b>' . $user->lang['ACP_SEO_SUPPORT_FORUM'] . '</b></a>'; + return $modrtype_lang; + } + /** + * check_cache_folder Validates the cache folder status + */ + function check_cache_folder($cache_dir, $msg = true) { + global $user, $phpEx; + $exists = $write = $inner_write = false; + $cache_msg = ''; + if (file_exists($cache_dir) && is_dir($cache_dir)) { + $exists = true; + if (!is_writeable($cache_dir)) { + phpbb_chmod($cache_dir, CHMOD_READ | CHMOD_WRITE); + $fp = @fopen($cache_dir . 'test_lock', 'wb'); + if ($fp !== false) { + $write = true; + } + @fclose($fp); + @unlink($phpbb_root_path . $dir . 'test_lock'); + } else { + $write = true; + } + // check if the config cache file is here already and writeable + $check = $cache_dir . "phpbb_cache.$phpEx"; + $checks = array("$check.old", "$check.current", "$cache_dir.htaccess", "$cache_dir.htaccess.old", "$cache_dir.htaccess.current"); + // let's check all files + $inner_write = true; + foreach($checks as $check) { + if (file_exists($check)) { + if (!is_writeable($check)) { + $inner_write = false; + phpbb_chmod($check, CHMOD_READ | CHMOD_WRITE); + $fp = @fopen($check, 'wb'); + if ($fp !== false) { + $inner_write = true; + } + @fclose($fp); + } + } + } + } + if ($msg) { + $exists = ($exists) ? '<b style="color:green">' . $user->lang['SEO_CACHE_FOUND'] . '</b>' : '<b style="color:red">' . $user->lang['SEO_CACHE_NOT_FOUND'] . '</b>'; + $write = ($write) ? '<br/> <b style="color:green">' . $user->lang['SEO_CACHE_WRITABLE'] . '</b>' : (($exists) ? '<br/> <b style="color:red">' . $user->lang['SEO_CACHE_UNWRITABLE'] . '</b>' : ''); + $inner_write = $inner_write ? '' : '<br/> <b style="color:red">' . $user->lang['SEO_CACHE_INNER_UNWRITABLE'] . '</b>'; + $cache_msg = sprintf($user->lang['SEO_CACHE_STATUS'], $cache_dir) . '<br/>' . $exists . $write . $inner_write; + return '<br/><b>' . $user->lang['SEO_CACHE_FILE_TITLE'] . ':</b><br/>' . $cache_msg . '<br/><br/>'; + } else { + return ($exists && $write); + } + } + /** + * write_cache( ) will write the cached file and keep backups. + */ + function write_cache( $type = 'forum' ) { + global $phpbb_seo; + if(!$phpbb_seo->cache_config['cache_enable'] || (!@is_array($phpbb_seo->cache_config[$type]) && $type != 'htaccess' ) || !array_key_exists($type, $phpbb_seo->cache_config['files'])) { + return FALSE; + } + $cache_tpl = '<'.'?php' . "\n" . '/**' . "\n" . '* phpBB_SEO Class' . "\n" . '* www.phpBB-SEO.com' . "\n" . '* @package Advanced phpBB3 SEO mod Rewrite' . "\n" . '*/' . "\n" . 'if (!defined(\'IN_PHPBB\')) {' . "\n\t" . 'exit;' . "\n" . '}' . "\n"; + if ($type == 'forum') { // Add the phpbb_seo_config + $update = '$this->cache_config[\'settings\'] = ' . preg_replace('`[\s]+`', ' ', var_export($phpbb_seo->cache_config['settings'], true)) . ';'. "\n"; + $update .= '$this->cache_config[\'forum\'] = ' . preg_replace('`[\s]+`', ' ', var_export($phpbb_seo->cache_config['forum'], true)) . ';'. "\n"; + $update = $cache_tpl . $update . '?'.'>'; + } elseif ($type == 'htaccess') { // .htaccess case + $update = $this->seo_htaccess(false); + } else { // Allow additional types + $update = '$this->cache_config[\'' . $type . '\'] = ' . preg_replace('`[\s]+`', ' ', var_export($phpbb_seo->cache_config[$type], true)) . ';'. "\n"; + $update = $cache_tpl . $update . '?'.'>'; + } + $file = SEO_CACHE_PATH . $phpbb_seo->cache_config['files'][$type]; + // Keep a backup of the previous settings + @copy($file, $file . '.old'); + $handle = @fopen($file, 'wb'); + @fputs($handle, $update); + @fclose ($handle); + unset($update); + @umask(0000); + phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE); + // Keep a backup of the current settings + @copy($file, $file . '.current'); + return true; + } + /** + * select_multiple($value, $key, $select_ary) + */ + function select_multiple($value, $key, $select_ary) { + $size = min(12,count($select_ary)); + $html = '<select multiple="multiple" id="' . $key . '" name="multiple_' . $key . '[]" size="' . $size . '">'; + foreach ($select_ary as $sel_key => $sel_data) { + if (empty($sel_data['disabled'])) { + $selected = array_search($sel_key, @$this->new_config[$key]) !== false ? 'selected="selected"' : ''; + $disabled = ''; + } else { + $disabled = 'disabled="disabled" class="disabled-option"'; + $selected = ''; + } + $sel_title = $sel_data['title']; + $html .= "<option value=\"$sel_key\" $disabled $selected>$sel_title</option>"; + } + return $html . '</select>'; + } + /** + * forum_select() // custom forum select setup + */ + function forum_select($ignore_acl = true, $ignore_nonpost = false, $ignore_emptycat = false, $only_acl_post = false) { + $select_ary = make_forum_select(false, false, $ignore_acl, $ignore_nonpost, $ignore_emptycat, $only_acl_post, true); + foreach($select_ary as $f_id => $f_data) { + $select_ary[$f_id] = array( + 'title' => $f_data['padding'] . $f_data['forum_name'], + 'disabled' => $f_data['disabled'], + ); + } + return $select_ary; + } + /** + * Pick a language, any language ... or no language + */ + function language_select($default = '') { + global $user; + return '<option value="">' . $user->lang['DISABLED'] . '</option>' . language_select($default); + } +} // End of acp class +?>
\ No newline at end of file diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 2288a0728b..f3e41b518f 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -1623,4 +1623,4 @@ class acp_profile } } -?> +?>
\ No newline at end of file diff --git a/phpBB/includes/acp/acp_update.php b/phpBB/includes/acp/acp_update.php index b0ce8f1084..fb2d20a6a4 100644 --- a/phpBB/includes/acp/acp_update.php +++ b/phpBB/includes/acp/acp_update.php @@ -50,14 +50,16 @@ class acp_update $announcement_url = trim($info[1]); $announcement_url = (strpos($announcement_url, '&') === false) ? str_replace('&', '&', $announcement_url) : $announcement_url; $update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update'); - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + // moved a little bellow // next feature release - $next_feature_version = $next_feature_announcement_url = false; + /*$next_feature_version = $next_feature_announcement_url = false; if (isset($info[2]) && trim($info[2]) !== '') { $next_feature_version = trim($info[2]); $next_feature_announcement_url = trim($info[3]); - } + }*/ + // www.phpBB-SEO.com SEO TOOLKIT BEGIN // Determine automatic update... $sql = 'SELECT config_value @@ -71,7 +73,28 @@ class acp_update $up_to_date_automatic = (version_compare(str_replace('rc', 'RC', strtolower($current_version)), str_replace('rc', 'RC', strtolower($latest_version)), '<')) ? false : true; $up_to_date = (version_compare(str_replace('rc', 'RC', strtolower($config['version'])), str_replace('rc', 'RC', strtolower($latest_version)), '<')) ? false : true; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + $phpbb_seo_update = ''; + if ($up_to_date) { + $phpbb_seo_update = trim(str_replace($current_version, '', $latest_version)); + } + $update_instruction = sprintf($user->lang['UPDATE_INSTRUCTIONS'], $announcement_url, $update_link); + if (!empty($phpbb_seo_update)) { + $auto_package = trim($info[2]); + $auto_update = $auto_package === 'auto_update:yes' ? true : false; + $up_to_date = ($latest_version === @$config['seo_premod_version']) ? true : false; + if (!$auto_update) { + $update_instruction = '<br/><br/><hr/>' . sprintf($user->lang['ACP_PREMOD_UPDATE'], $latest_version, $announcement_url) . '<br/><hr/>'; + } + } + // next feature release + $next_feature_version = $next_feature_announcement_url = false; + if (isset($info[3]) && trim($info[3]) !== '') + { + $next_feature_version = trim($info[3]); + $next_feature_announcement_url = trim($info[4]); + } + // www.phpBB-SEO.com SEO TOOLKIT END $template->assign_vars(array( 'S_UP_TO_DATE' => $up_to_date, 'S_UP_TO_DATE_AUTO' => $up_to_date_automatic, diff --git a/phpBB/includes/acp/info/acp_gym_sitemaps.php b/phpBB/includes/acp/info/acp_gym_sitemaps.php new file mode 100644 index 0000000000..aa6760d72c --- /dev/null +++ b/phpBB/includes/acp/info/acp_gym_sitemaps.php @@ -0,0 +1,39 @@ +<?php +/** +* +* @package phpBB SEO GYM Sitemaps +* @version $Id: acp_gym_sitemaps.php 112 2009-09-30 17:21:34Z dcz $ +* @copyright (c) 2006 - 2009 www.phpbb-seo.com +* @license http://opensource.org/osi3.0/licenses/lgpl-license.php GNU Lesser General Public License +* +*/ + +/** +* @package module_install +*/ +class acp_gym_sitemaps_info { + function module() { + return array( + 'filename' => 'gym_sitemaps', + 'title' => 'ACP_GYM_SITEMAPS', + 'version' => '2.0.0', + 'modes' => array( + 'main' => array('title' => 'ACP_GYM_MAIN', 'auth' => 'acl_a_board', 'cat' => array('ACP_GYM_SITEMAPS')), + 'google' => array('title' => 'ACP_GYM_GOOGLE_MAIN', 'auth' => 'acl_a_board', 'cat' => array('ACP_GYM_SITEMAPS')), + 'rss' => array('title' => 'ACP_GYM_RSS_MAIN', 'auth' => 'acl_a_board', 'cat' => array('ACP_GYM_SITEMAPS')), + //'yahoo' => array('title' => 'ACP_GYM_YAHOO_MAIN', 'auth' => 'acl_a_board', 'cat' => array('ACP_GYM_SITEMAPS')), + 'html' => array('title' => 'ACP_GYM_HTML_MAIN', 'auth' => 'acl_a_board', 'cat' => array('ACP_GYM_SITEMAPS')), + ), + ); + } + + function install() + { + } + + function uninstall() + { + } +} + +?>
\ No newline at end of file diff --git a/phpBB/includes/acp/info/acp_phpbb_seo.php b/phpBB/includes/acp/info/acp_phpbb_seo.php new file mode 100644 index 0000000000..482bcab41a --- /dev/null +++ b/phpBB/includes/acp/info/acp_phpbb_seo.php @@ -0,0 +1,37 @@ +<?php +/** +* +* @package Ultimate SEO URL phpBB SEO +* @version $Id: acp_phpbb_seo.php 131 2009-10-25 12:03:44Z dcz $ +* @copyright (c) 2006 - 2009 www.phpbb-seo.com +* @license http://www.opensource.org/licenses/rpl1.5.txt Reciprocal Public License 1.5 +* +*/ + +/** +* @package module_install +*/ +class acp_phpbb_seo_info { + function module() { + return array( + 'filename' => 'phpbb_seo', + 'title' => 'ACP_CAT_PHPBB_SEO', + 'version' => '0.6.0', + 'modes' => array( + 'settings' => array('title' => 'ACP_PHPBB_SEO_CLASS', 'auth' => 'acl_a_board', 'cat' => array('ACP_MOD_REWRITE')), + 'forum_url' => array('title' => 'ACP_FORUM_URL', 'auth' => 'acl_a_board', 'cat' => array('ACP_MOD_REWRITE')), + 'htaccess' => array('title' => 'ACP_HTACCESS', 'auth' => 'acl_a_board', 'cat' => array('ACP_MOD_REWRITE')), + 'extended' => array('title' => 'ACP_SEO_EXTENDED', 'auth' => 'acl_a_board', 'cat' => array('ACP_MOD_REWRITE')), + )); + } + + function install() + { + } + + function uninstall() + { + } +} + +?>
\ No newline at end of file diff --git a/phpBB/includes/auth/auth_ldap.php b/phpBB/includes/auth/auth_ldap.php index 33413094ef..e8c957aaa3 100644 --- a/phpBB/includes/auth/auth_ldap.php +++ b/phpBB/includes/auth/auth_ldap.php @@ -51,9 +51,6 @@ function init_ldap() @ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); @ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); - - /* Patch by maat */ - @ldap_start_tls($ldap); if ($config['ldap_user'] || $config['ldap_password']) { @@ -155,9 +152,6 @@ function login_ldap(&$username, &$password) @ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); @ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); - /* Patch by maat */ - @ldap_start_tls($ldap); - if ($config['ldap_user'] || $config['ldap_password']) { if (!@ldap_bind($ldap, htmlspecialchars_decode($config['ldap_user']), htmlspecialchars_decode($config['ldap_password']))) @@ -352,4 +346,4 @@ function acp_ldap(&$new) ); } -?> +?>
\ No newline at end of file diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index af2a6ebd24..b64eff4704 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -28,7 +28,7 @@ if (!defined('IN_PHPBB')) define('PHPBB_VERSION', '3.0.8'); // QA-related -// define('PHPBB_QA', 1); +// define('PHPBB_SEO_QA', 1); // User related define('ANONYMOUS', 1); diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index eeddf1f41b..fe30e209c4 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -711,7 +711,9 @@ class dbal function sql_report($mode, $query = '') { global $cache, $starttime, $phpbb_root_path, $user; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + // www.phpBB-SEO.com SEO TOOLKIT END if (empty($_REQUEST['explain'])) { return false; @@ -741,7 +743,7 @@ class dbal <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>SQL Report</title> - <link href="' . $phpbb_root_path . 'adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" /> + <link href="' . $phpbb_seo->seo_path['phpbb_url'] . 'adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body id="errorpage"> <div id="wrap"> diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 561a9906c4..fc9e3ae292 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2034,7 +2034,9 @@ function tracking_unserialize($string, $max_depth = 3) function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = false, $tpl_prefix = '') { global $template, $user; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo, $phpEx; + // www.phpBB-SEO.com SEO TOOLKIT END // Make sure $per_page is a valid value $per_page = ($per_page <= 0) ? 1 : $per_page; @@ -2098,15 +2100,56 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add } } + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + $prev = ($on_page == 1) ? '' : $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page); + $next = ($on_page == $total_pages) ? '' : $base_url . "{$url_delim}start=" . ($on_page * $per_page); + if (!empty($phpbb_seo->seo_opt['url_rewrite'])) { + static $pagin_find = array(); + static $pagin_replace = array(); + if (empty($pagin_replace)) { + $pagin_find = array('`(https?\://[a-z0-9_/\.-]+/[a-z0-9_\.-]+)(\.[a-z0-9]+)(\?[\w$%&~\-;:=,@+\.]+)?(#[a-z0-9_\.-]+)?(&|\?)start=([0-9]+)`i', '`(https?\://[a-z0-9_/\.-]+/[a-z0-9_\-]+)/(\?[\w$%&~\-;:=,@+\.]+)?(#[a-z0-9_\.-]+)?(&|\?)start=([0-9]+)`i'); + $pagin_replace = array( '\1' . $phpbb_seo->seo_delim['start'] . '\6\2\3\4', '\1/' . $phpbb_seo->seo_static['pagination'] . '\5' . $phpbb_seo->seo_ext['pagination'] . '\2\3'); + } + $rewrite_pagination = false; + // here we rewrite rewritten urls only, and they do hold the full url with http + if (preg_match('`^https?://[a-z0-9_\.-]+/(.*)$`i', $base_url, $match)) { + $rewrite_pagination = true; + if (!empty($match[1])) { + // though, we won't do it for .php files. + if (preg_match('`^.*\.' . $phpEx . '(|\?.*|#.*)$`i', trim($match[1]))) { + $rewrite_pagination = false; + + } + } + + } + // in all cases remove the start=0 dupe + $page_string = str_replace($url_delim . 'start=0', '', $page_string); + $prev = str_replace($url_delim . 'start=0', '', $prev); + if ($rewrite_pagination) { + $page_string = preg_replace($pagin_find, $pagin_replace, $page_string); + $prev = $prev ? preg_replace($pagin_find, $pagin_replace, $prev) : ''; + $next = $next ? preg_replace( $pagin_find, $pagin_replace, $next) : ''; + } else { + // take care about eventual hashes + if (strpos($base_url, '#') !== false) { + static $hash_find = '`((https?\://)?[a-z0-9_/\.-]+\.[a-z0-9]+)(\?[\w$%&~\-;:=,@+\.]+)?(#[a-z0-9_\.-]+)((&|\?)start=[0-9]+)`'; + static $hash_replace = '\1\3\5\4'; + $page_string = preg_replace($hash_find, $hash_replace, $page_string); + $prev = $prev ? preg_replace($hash_find, $hash_replace, $prev) : ''; + $next = $next ? preg_replace($hash_find, $hash_replace, $next) : ''; + } + } + } $template->assign_vars(array( - $tpl_prefix . 'BASE_URL' => $base_url, + $tpl_prefix . 'BASE_URL' => $base_url, 'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url), - $tpl_prefix . 'PER_PAGE' => $per_page, - - $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page), - $tpl_prefix . 'NEXT_PAGE' => ($on_page == $total_pages) ? '' : $base_url . "{$url_delim}start=" . ($on_page * $per_page), - $tpl_prefix . 'TOTAL_PAGES' => $total_pages, - )); + $tpl_prefix . 'PER_PAGE' => $per_page, + $tpl_prefix . 'PREVIOUS_PAGE' => $prev, + $tpl_prefix . 'NEXT_PAGE' => $next, + $tpl_prefix . 'TOTAL_PAGES' => $total_pages) + ); + // www.phpBB-SEO.com SEO TOOLKIT END return $page_string; } @@ -2153,7 +2196,13 @@ function on_page($num_items, $per_page, $start) function append_sid($url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL, $phpbb_hook; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + // We bypass the hook function here, the same effect as a standalone hook, which we want, but faster ;-) + global $phpbb_seo; + if (!empty($phpbb_seo->seo_opt['url_rewrite'])) { + return $phpbb_seo->url_rewrite($url, $params, $is_amp, $session_id); + } else + // www.phpBB-SEO.com SEO TOOLKIT END // Developers using the hook function need to globalise the $_SID and $_EXTRA_URL on their own and also handle it appropriately. // They could mimic most of what is within this function if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id)) @@ -4252,7 +4301,35 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 { return; } - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + $template->assign_vars( array( 'PHPBB_FULL_URL' => $phpbb_seo->seo_path['phpbb_url'], + 'SEO_BASE_HREF' => $phpbb_seo->seo_opt['seo_base_href'], + 'SEO_START_DELIM' => $phpbb_seo->seo_delim['start'], + 'SEO_SATIC_PAGE' => $phpbb_seo->seo_static['pagination'], + 'SEO_EXT_PAGE' => $phpbb_seo->seo_ext['pagination'], + 'SEO_CANONICAL_URL' => !empty($phpbb_seo->seo_opt['no_dupe']['on']) ? $phpbb_seo->get_canonical() : '', + 'SEO_EXTERNAL' => !empty($config['seo_ext_links']) ? 'true' : 'false', + 'SEO_EXTERNAL_SUB' => !empty($config['seo_ext_subdomain']) ? 'true' : 'false', + 'SEO_EXT_CLASSES' => !empty($config['seo_ext_classes']) ? "'" . preg_replace('`[^a-z0-9_|-]+`', '', str_replace(',', '|', trim($config['seo_ext_classes'], ', '))) . "'" : 'false', + 'SEO_HASHFIX' => $phpbb_seo->seo_opt['url_rewrite'] && $phpbb_seo->seo_opt['virtual_folder'] ? 'true' : 'false', + )); + if (isset($user->lang['Page']) && !empty($config['seo_append_sitename']) && !empty($config['sitename'])) { + $page_title = $page_title && strpos($page_title, $config['sitename']) === false ? $page_title . ' - ' . $config['sitename'] : $page_title; + } + // www.phpBB-SEO.com SEO TOOLKIT END + // www.phpBB-SEO.com SEO TOOLKIT BEGIN - META + global $seo_meta; + $seo_meta->build_meta($page_title); + // www.phpBB-SEO.com SEO TOOLKIT END - META + // www.phpBB-SEO.com SEO TOOLKIT BEGIN - GYM LINKS + if (!empty($config['gym_installed'])) { + if (!function_exists('obtain_gym_links')) { + require_once($phpbb_root_path . 'gym_sitemaps/includes/gym_common.' . $phpEx); + } + $gym_setup = obtain_gym_links(); + } + // www.phpBB-SEO.com SEO TOOLKIT END - GYM LINKS define('HEADER_INC', true); // gzip_compression @@ -4411,7 +4488,9 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'U_PRIVATEMSGS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox'), 'U_RETURN_INBOX' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox'), 'U_POPUP_PM' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=popup'), - 'UA_POPUP_PM' => addslashes(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=popup')), + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + 'UA_POPUP_PM' => addslashes(append_sid($phpbb_seo->seo_path['phpbb_url'] . "ucp.$phpEx", 'i=pm&mode=popup')), + // www.phpBB-SEO.com SEO TOOLKIT END 'U_MEMBERLIST' => append_sid("{$phpbb_root_path}memberlist.$phpEx"), 'U_VIEWONLINE' => ($auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel')) ? append_sid("{$phpbb_root_path}viewonline.$phpEx") : '', 'U_LOGIN_LOGOUT' => $u_login_logout, @@ -4517,7 +4596,12 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 function page_footer($run_cron = true) { global $db, $config, $template, $user, $auth, $cache, $starttime, $phpbb_root_path, $phpEx; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + if (!empty($phpbb_seo)) { + $phpbb_seo->seo_end(); + } + // www.phpBB-SEO.com SEO TOOLKIT END // Output page creation time if (defined('DEBUG')) { @@ -4685,5 +4769,11 @@ function phpbb_user_session_handler() return; } - +function nice_print($input) { + if (is_array($input) || is_object($input) ) { + echo '<pre>' . var_export($input, true) . '</pre>'; + } else { + echo '<pre>' . $input . '</pre>'; + } +} ?>
\ No newline at end of file diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 2aa12adb2e..283f1175ad 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3298,10 +3298,14 @@ function obtain_latest_version_info($force_update = false, $warn_fail = false, $ { $errstr = ''; $errno = 0; - - $info = get_remote_file('version.phpbb.com', '/phpbb', - ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $config; + $url = 'www.phpbb-seo.com'; + $dir = (strpos($config['default_lang'], 'fr') !== false ? '/fr' : '/en') . '/updatecheck'; + $info = get_remote_file($url, $dir, ((defined('PHPBB_SEO_QA')) ? 'test_30x.txt' : 'premod_30x.txt'), $errstr, $errno); + //$info = get_remote_file('version.phpbb.com', '/phpbb', + // ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); + // www.phpBB-SEO.com SEO TOOLKIT END if ($info === false) { $cache->destroy('versioncheck'); diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index faff9dd0de..086734eb1d 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -762,7 +762,9 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, global $template, $cache, $user; global $extensions, $config, $phpbb_root_path, $phpEx; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + // www.phpBB-SEO.com SEO TOOLKIT END // $compiled_attachments = array(); @@ -937,7 +939,25 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, $display_cat = ATTACHMENT_CATEGORY_NONE; } - $download_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $attachment['attach_id']); + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + //$download_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $attachment['attach_id']); + $download_link = "{$phpbb_root_path}download/file.$phpEx?id=" . $attachment['attach_id']; + $comment_clean = preg_replace('`<[^>]*>`Ui', ' ', $comment); + $block_array += array( + 'COMMENT_CLEAN' => $comment_clean, + ); + if (!empty($phpbb_seo->seo_opt['rewrite_files'])) { + if (empty($phpbb_seo->seo_url['file'][$attachment['attach_id']])) { + if (($_pos = utf8_strpos($comment, '<br')) !== false) { + $comment_url = strip_tags(utf8_substr($comment, 0, $_pos)); + } else { + $comment_url = $comment_clean; + } + $comment_url = utf8_strlen($comment_url) > 60 ? utf8_substr($comment_url, 0, 60) : $comment_url; + $phpbb_seo->seo_url['file'][$attachment['attach_id']] = $phpbb_seo->format_url($comment_url, $phpbb_seo->seo_static['file'][$display_cat]); + } + } + // www.phpBB-SEO.com SEO TOOLKIT END switch ($display_cat) { @@ -1013,7 +1033,9 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, 'S_FLASH_FILE' => true, 'WIDTH' => $width, 'HEIGHT' => $height, - 'U_VIEW_LINK' => $download_link . '&view=1', + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + 'U_VIEW_LINK' => append_sid($download_link . '&view=1'), + // www.phpBB-SEO.com SEO TOOLKIT END ); // Viewed/Heared File ... update the download count @@ -1028,7 +1050,9 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, ); break; } - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + $download_link = append_sid($download_link); + // www.phpBB-SEO.com SEO TOOLKIT END $l_download_count = (!isset($attachment['download_count']) || $attachment['download_count'] == 0) ? $user->lang[$l_downloaded_viewed . '_NONE'] : (($attachment['download_count'] == 1) ? sprintf($user->lang[$l_downloaded_viewed], $attachment['download_count']) : sprintf($user->lang[$l_downloaded_viewed . 'S'], $attachment['download_count'])); $block_array += array( @@ -1237,7 +1261,16 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', // For anonymous the link leads to a login page. if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile'))) { - $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&u=' . (int) $user_id : str_replace(array('={USER_ID}', '=%7BUSER_ID%7D'), '=' . (int) $user_id, $_profile_cache['base_url']); + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + // $profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&u=' . (int) $user_id : str_replace(array('={USER_ID}', '=%7BUSER_ID%7D'), '=' . (int) $user_id, $_profile_cache['base_url']); + global $phpbb_seo, $phpbb_root_path, $phpEx; + $phpbb_seo->set_user_url( $username, $user_id ); + if ($custom_profile_url !== false) { + $profile_url = reapply_sid($custom_profile_url . (strpos($custom_profile_url, '?') !== false ? '&' : '?' ) . 'u=' . (int) $user_id); + } else { + $profile_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . (int) $user_id); + } + // www.phpBB-SEO.com SEO TOOLKIT END } else { diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 2de7e1b169..de06c08058 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -23,7 +23,9 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod { global $db, $auth, $user, $template; global $phpbb_root_path, $phpEx, $config; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + // www.phpBB-SEO.com SEO TOOLKIT END $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array(); $parent_id = $visible_forums = 0; $sql_from = ''; @@ -87,7 +89,15 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $sql_array['SELECT'] .= ', fa.user_id'; } - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe + if (@$phpbb_seo->seo_opt['no_dupe']['on']) { + $sql_array['SELECT'] .= ', t.topic_id, t.topic_title, t.topic_replies, t.topic_replies_real, t.topic_status, t.topic_type, t.topic_moved_id' . (!empty($phpbb_seo->seo_opt['sql_rewrite']) ? ', t.topic_url ' : ' '); + $sql_array['LEFT_JOIN'][] = array( + 'FROM' => array(TOPICS_TABLE => 't'), + 'ON' => "f.forum_last_post_id = t.topic_last_post_id" + ); + } + // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe $sql = $db->sql_build_query('SELECT', array( 'SELECT' => $sql_array['SELECT'], 'FROM' => $sql_array['FROM'], @@ -118,7 +128,9 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod while ($row = $db->sql_fetchrow($result)) { $forum_id = $row['forum_id']; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + $phpbb_seo->set_url($row['forum_name'], $forum_id, 'forum'); + // www.phpBB-SEO.com SEO TOOLKIT END // Mark forums read? if ($mark_read == 'forums' || $mark_read == 'all') { @@ -169,7 +181,26 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod // Count the difference of real to public topics, so we can display an information to moderators $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0; - $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics']; + // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe + if (@$phpbb_seo->seo_opt['no_dupe']['on']) { + if ($row['topic_status'] == ITEM_MOVED) { + $row['topic_id'] = $row['topic_moved_id']; + } + $phpbb_seo->seo_opt['topic_forum_name'][$row['topic_id']] = $row['forum_name']; + if ($auth->acl_get('m_approve', $forum_id)) { + $row['forum_topics'] = $row['forum_topics_real']; + $replies = $row['topic_replies_real']; + } else { + $row['forum_topics'] = $row['forum_topics']; + $replies = $row['topic_replies']; + } + if (($replies + 1) > $phpbb_seo->seo_opt['topic_per_page']) { + $phpbb_seo->seo_opt['topic_last_page'][$row['topic_id']] = floor($replies / $phpbb_seo->seo_opt['topic_per_page']) * $phpbb_seo->seo_opt['topic_per_page']; + } + } else { + $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics']; + } + // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe // Display active topics from this forum? if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) @@ -249,6 +280,15 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name']; $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour']; $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id; + // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe + if (@$phpbb_seo->seo_opt['no_dupe']['on']) { + $forum_rows[$parent_id]['topic_id'] = $row['topic_id']; + $forum_rows[$parent_id]['topic_title'] = $row['topic_title']; + $forum_rows[$parent_id]['topic_type'] = $row['topic_type']; + $forum_rows[$parent_id]['forum_password'] = $row['forum_password']; + $forum_rows[$parent_id]['topic_url'] = isset($row['topic_url']) ? $row['topic_url'] : ''; + } + // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe } } } @@ -404,11 +444,25 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod { $last_post_subject = $row['forum_last_post_subject']; $last_post_time = $user->format_date($row['forum_last_post_time']); - $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id']; + // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe + if (@$phpbb_seo->seo_opt['no_dupe']['on'] && !$row['forum_password'] && $auth->acl_get('f_read', $row['forum_id_last_post'])) { + $phpbb_seo->prepare_iurl($row, 'topic', $row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$forum_id]); + $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&t=' . $row['topic_id'] . '&start=' . @intval($phpbb_seo->seo_opt['topic_last_page'][$row['topic_id']]) ) . '#p' . $row['forum_last_post_id']; + $topic_title = censor_text($row['topic_title']); + // Limit in chars for the last post link text. + $char_limit = 25; + // Limit topic text link to $char_limit, without breacking words + $topic_text_lilnk = $char_limit > 0 && ( ( $length = utf8_strlen($topic_title) ) > $char_limit ) ? ( utf8_strlen($fragment = utf8_substr($topic_title, 0, $char_limit + 1 - 4)) < $length + 1 ? preg_replace('`\s*\S*$`', '', $fragment) . ' ...' : $topic_title ) : $topic_title; + $last_post_link = '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&t=' . $row['topic_id']) . '" title="' . $topic_title . ' : ' . $phpbb_seo->seo_opt['topic_forum_name'][$row['topic_id']] . '">' . $topic_text_lilnk . '</a>'; + } else { + $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id']; + $last_post_link = ''; + } } else { - $last_post_subject = $last_post_time = $last_post_url = ''; + $last_post_subject = $last_post_time = $last_post_url = $last_post_link = ''; + // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe } // Output moderator listing ... if applicable @@ -483,6 +537,9 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'U_UNAPPROVED_TOPICS' => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=unapproved_topics&f=' . $row['forum_id_unapproved_topics']) : '', 'U_VIEWFORUM' => $u_viewforum, 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), + // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe + 'LAST_POST_LINK' => $last_post_link, + // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe 'U_LAST_POST' => $last_post_url) ); @@ -547,7 +604,9 @@ function generate_forum_nav(&$forum_data) { global $db, $user, $template, $auth, $config; global $phpEx, $phpbb_root_path; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + // www.phpBB-SEO.com SEO TOOLKIT END if (!$auth->acl_get('f_list', $forum_data['forum_id'])) { return; @@ -562,7 +621,9 @@ function generate_forum_nav(&$forum_data) foreach ($forum_parents as $parent_forum_id => $parent_data) { list($parent_name, $parent_type) = array_values($parent_data); - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + $phpbb_seo->set_url($parent_name, $parent_forum_id, 'forum'); + // www.phpBB-SEO.com SEO TOOLKIT END // Skip this parent if the user does not have the permission to view it if (!$auth->acl_get('f_list', $parent_forum_id)) { @@ -648,7 +709,9 @@ function get_forum_parents(&$forum_data) function topic_generate_pagination($replies, $url) { global $config, $user; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo, $phpEx; + // www.phpBB-SEO.com SEO TOOLKIT END // Make sure $per_page is a valid value $per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page']; @@ -675,6 +738,17 @@ function topic_generate_pagination($replies, $url) } $times++; } + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + if (!empty($phpbb_seo->seo_opt['url_rewrite'])) { + static $pagin_find = array(); + static $pagin_replace = array(); + if (empty($pagin_find)) { + $pagin_find = array('`(https?\://[a-z0-9_/\.-]+/[a-z0-9_\.-]+)(\.(?!' . $phpEx . ')[a-z0-9]+)(\?[\w\#$%&~\-;:=,@+\.]+)?(&|\?)start=([0-9]+)`i', '`(https?\://[a-z0-9_/\.-]+/[a-z0-9_\.-]+)/(\?[\w\#$%&~\-;:=,@+\.]+)?(&|\?)start=([0-9]+)`i' ); + $pagin_replace = array( '\1' . $phpbb_seo->seo_delim['start'] . '\5\2\3', '\1/' . $phpbb_seo->seo_static['pagination'] . '\4' . $phpbb_seo->seo_ext['pagination'] . '\2' ); + } + $pagination = preg_replace( $pagin_find, $pagin_replace, $pagination ); + } + // www.phpBB-SEO.com SEO TOOLKIT END } else { @@ -690,7 +764,9 @@ function topic_generate_pagination($replies, $url) function get_moderators(&$forum_moderators, $forum_id = false) { global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + // www.phpBB-SEO.com SEO TOOLKIT END $forum_id_ary = array(); if ($forum_id !== false) @@ -744,6 +820,9 @@ function get_moderators(&$forum_moderators, $forum_id = false) } else { + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + $phpbb_seo->prepare_url('group', $row['group_name'], $row['group_id']); + // www.phpBB-SEO.com SEO TOOLKIT END $group_name = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']); if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile')) @@ -946,7 +1025,9 @@ function display_user_activity(&$userdata) { global $auth, $template, $db, $user; global $phpbb_root_path, $phpEx; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + // www.phpBB-SEO.com SEO TOOLKIT END // Do not display user activity for users having more than 5000 posts... if ($userdata['user_posts'] > 5000) { @@ -1012,12 +1093,27 @@ function display_user_activity(&$userdata) if (!empty($active_t_row)) { - $sql = 'SELECT topic_title - FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . $active_t_row['topic_id']; - $result = $db->sql_query($sql); - $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title'); + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + $sql_array = array( + 'SELECT' => 't.topic_title, t.topic_type ' . (!empty($phpbb_seo->seo_opt['sql_rewrite']) ? ', t.topic_url' : '') . ', f.forum_id, f.forum_name', + 'FROM' => array( + TOPICS_TABLE => 't', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(FORUMS_TABLE => 'f'), + 'ON' => 'f.forum_id = t.forum_id', + ), + ), + 'WHERE' => 't.topic_id = ' . (int) $active_t_row['topic_id'] + ); + $result = $db->sql_query($db->sql_build_query('SELECT', $sql_array)); + $seo_active_t_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); + if ($seo_active_t_row) { + $active_t_row = array_merge($active_t_row, $seo_active_t_row); + } + // www.phpBB-SEO.com SEO TOOLKIT END } $userdata['active_t_row'] = $active_t_row; @@ -1030,6 +1126,9 @@ function display_user_activity(&$userdata) $active_f_id = $active_f_row['forum_id']; $active_f_count = $active_f_row['num_posts']; $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0; + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + $phpbb_seo->set_url($active_f_name, $active_f_id, 'forum'); + // www.phpBB-SEO.com SEO TOOLKIT END } $active_t_name = $active_t_id = $active_t_count = $active_t_pct = ''; @@ -1039,6 +1138,13 @@ function display_user_activity(&$userdata) $active_t_id = $active_t_row['topic_id']; $active_t_count = $active_t_row['num_posts']; $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0; + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + if (!empty($seo_active_t_row)) { + $active_t_forum_id = (int) $active_t_row['forum_id']; + $phpbb_seo->set_url($active_t_row['forum_name'], $active_t_forum_id, 'forum'); + $phpbb_seo->prepare_iurl($active_t_row, 'topic', $active_t_row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$active_t_forum_id]); + } + // www.phpBB-SEO.com SEO TOOLKIT END } $l_active_pct = ($userdata['user_id'] != ANONYMOUS && $userdata['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE']; diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6fd87db663..3fbd812a5d 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1319,13 +1319,18 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id $messenger->to($addr['email'], $addr['name']); $messenger->im($addr['jabber'], $addr['name']); + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + $phpbb_seo->set_url(htmlspecialchars_decode($forum_name), $forum_id, 'forum'); + $phpbb_seo->prepare_iurl(array('topic_id' => $topic_id, 'topic_title' => htmlspecialchars_decode($topic_title)), 'topic', $phpbb_seo->seo_url['forum'][$forum_id]); $messenger->assign_vars(array( 'USERNAME' => htmlspecialchars_decode($addr['name']), 'TOPIC_TITLE' => htmlspecialchars_decode($topic_title), 'FORUM_NAME' => htmlspecialchars_decode($forum_name), - 'U_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id", - 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id", + 'U_FORUM' => !empty($phpbb_seo->seo_opt['url_rewrite']) ? $phpbb_seo->drop_sid(append_sid("{$phpbb_root_path}viewforum.$phpEx?f=$forum_id")) : generate_board_url() . "/viewforum.$phpEx?f=$forum_id", + 'U_TOPIC' => !empty($phpbb_seo->seo_opt['url_rewrite']) ? $phpbb_seo->drop_sid(append_sid("{$phpbb_root_path}viewtopic.$phpEx?f=$forum_id&t=$topic_id")) : generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id", + // www.phpBB-SEO.com SEO TOOLKIT END 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id", 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?uid={$addr['user_id']}&f=$forum_id&t=$topic_id&unwatch=topic", 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.$phpEx?uid={$addr['user_id']}&f=$forum_id&unwatch=forum", @@ -1628,7 +1633,9 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + global $phpbb_seo; + // www.phpBB-SEO.com SEO TOOLKIT END // We do not handle erasing posts here if ($mode == 'delete') { @@ -1816,7 +1823,11 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, 'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : 0, ); - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + if (!empty($phpbb_seo->seo_opt['sql_rewrite'])) { + $sql_data[TOPICS_TABLE]['sql'] += array('topic_url' => isset($data['topic_url']) ? $data['topic_url'] : ''); + } + // www.phpBB-SEO.com SEO TOOLKIT END if (isset($poll['poll_options']) && !empty($poll['poll_options'])) { $poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time; @@ -1902,7 +1913,11 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0), ); - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + if (!empty($phpbb_seo->seo_opt['sql_rewrite'])) { + $sql_data[TOPICS_TABLE]['sql'] += array('topic_url' => isset($data['topic_url']) ? $data['topic_url'] : ''); + } + // www.phpBB-SEO.com SEO TOOLKIT END // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved if (!$post_approval && $data['topic_approved']) { @@ -2604,7 +2619,12 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { $params .= '&t=' . $data['topic_id']; } - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + $phpbb_seo->set_url($data['forum_name'], $data['forum_id'], 'forum'); + if ( $params ) { + $phpbb_seo->prepare_iurl($data, 'topic', $topic_type == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$data['forum_id']]); + } + // www.phpBB-SEO.com SEO TOOLKIT END $url = (!$params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx"; $url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor; diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 727e3aaffb..e4c11fd105 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -1137,7 +1137,13 @@ class fulltext_native extends search_backend // Split old and new post/subject to obtain array of 'words' $split_text = $this->split_message($message); $split_title = $this->split_message($subject); - + // www.phpBB-SEO.com SEO TOOLKIT BEGIN - Enable search_ignore_words + $this->filter_nums($split_text); + $this->filter_nums($split_title); + $this->get_ignore_words(); + $split_text = array_diff($split_text, $this->ignore_words); + $split_title = array_diff($split_title, $this->ignore_words); + // www.phpBB-SEO.com SEO TOOLKIT END - Enable search_ignore_words $cur_words = array('post' => array(), 'title' => array()); $words = array(); @@ -1753,6 +1759,18 @@ class fulltext_native extends search_backend 'config' => array('fulltext_native_load_upd' => 'bool', 'fulltext_native_min_chars' => 'integer:0:255', 'fulltext_native_max_chars' => 'integer:0:255', 'fulltext_native_common_thres' => 'double:0:100') ); } + // www.phpBB-SEO.com SEO TOOLKIT BEGIN - Enable search_ignore_words + /** + * Get rid of integers values in $input array + */ + function filter_nums(&$input) { + foreach ($input as $key => $word) { + if (preg_match('`^[0-9]+$`', $word)) { + unset($input[$key]); + } + } + } + // www.phpBB-SEO.com SEO TOOLKIT END - Enable search_ignore_words } ?>
\ No newline at end of file diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 5f5b39fe27..6189cf27f2 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -619,12 +619,16 @@ class session } else { + // www.phpBB-SEO.com SEO TOOLKIT BEGIN + // This part will be fixed in 3.0.9 (see http://tracker.phpbb.com/browse/PHPBB3-9908) + // But as is or updated, it will not mix well with USU and Zero Duplicate (which already removes them) // Bot user, if they have a SID in the Request URI we need to get rid of it // otherwise they'll index this page with the SID, duplicate content oh my! - if (isset($_GET['sid'])) + /*if (isset($_GET['sid'])) { redirect(build_url(array('sid'))); - } + }*/ + // www.phpBB-SEO.com SEO TOOLKIT END $this->data['session_last_visit'] = $this->time_now; } diff --git a/phpBB/includes/utf/utf_tools.php b/phpBB/includes/utf/utf_tools.php index 6f3ac93305..31ad5027fd 100644 --- a/phpBB/includes/utf/utf_tools.php +++ b/phpBB/includes/utf/utf_tools.php @@ -105,6 +105,10 @@ if (!extension_loaded('xml')) if (extension_loaded('mbstring')) { mb_internal_encoding('UTF-8'); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // ini_set is only used to try to make things better for mods using mbstring directly + // I know they're not supposed to, but you know they still could and the fix is costless + @ini_set("mbstring.internal_encoding", 'UTF-8'); /** * UTF-8 aware alternative to strrpos @@ -129,11 +133,15 @@ if (extension_loaded('mbstring')) if (is_null($offset)) { - return mb_strrpos($str, $needle); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + return mb_strrpos($str, $needle, 0, 'UTF-8'); } else { - return mb_strrpos($str, $needle, $offset); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + return mb_strrpos($str, $needle, $offset, 'UTF-8'); } } } @@ -153,8 +161,9 @@ if (extension_loaded('mbstring')) { return false; } - - return mb_strrpos($str, $needle); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + return mb_strrpos($str, $needle, 'UTF-8'); } else { @@ -163,10 +172,12 @@ if (extension_loaded('mbstring')) trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_ERROR); return false; } - - $str = mb_substr($str, $offset); - - if (false !== ($pos = mb_strrpos($str, $needle))) + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + $str = mb_substr($str, $offset, mb_strlen($str, 'UTF-8'), 'UTF-8'); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + if (false !== ($pos = mb_strrpos($str, $needle, 'UTF-8'))) { return $pos + $offset; } @@ -184,11 +195,15 @@ if (extension_loaded('mbstring')) { if (is_null($offset)) { - return mb_strpos($str, $needle); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + return mb_strpos($str, $needle, 0, 'UTF-8'); } else { - return mb_strpos($str, $needle, $offset); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + return mb_strpos($str, $needle, $offset, 'UTF-8'); } } @@ -198,7 +213,9 @@ if (extension_loaded('mbstring')) */ function utf8_strtolower($str) { - return mb_strtolower($str); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + return mb_strtolower($str, 'UTF-8'); } /** @@ -207,7 +224,9 @@ if (extension_loaded('mbstring')) */ function utf8_strtoupper($str) { - return mb_strtoupper($str); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + return mb_strtoupper($str, 'UTF-8'); } /** @@ -218,11 +237,15 @@ if (extension_loaded('mbstring')) { if (is_null($length)) { - return mb_substr($str, $offset); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + return mb_substr($str, $offset, mb_strlen($str, 'UTF-8'), 'UTF-8'); } else { - return mb_substr($str, $offset, $length); + // Fix for http://www.phpbb.com/bugs/phpbb3/52315 + // Explicit encoding + return mb_substr($str, $offset, $length, 'UTF-8'); } } |