PageRenderTime 77ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 1ms

/forum/includes/acp/acp_phpbb_seo.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 1144 lines | 1014 code | 12 blank | 118 comment | 205 complexity | 4db663564c21a9fcbb39bdda883f3129 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. *
  4. * @package Ultimate SEO URL phpBB SEO
  5. * @version $Id: acp_phpbb_seo.php 311 2011-06-20 07:14:09Z dcz $
  6. * @copyright (c) 2006 - 2010 www.phpbb-seo.com
  7. * @license http://www.opensource.org/licenses/rpl1.5.txt Reciprocal Public License 1.5
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB')) {
  14. exit;
  15. }
  16. /**
  17. * phpBB_SEO Class
  18. * www.phpBB-SEO.com
  19. * @package Ultimate SEO URL phpBB SEO
  20. */
  21. class acp_phpbb_seo {
  22. var $u_action;
  23. var $new_config = array();
  24. var $dyn_select = array();
  25. var $forum_ids = array();
  26. var $array_type_cfg = array();
  27. var $multiple_options = array();
  28. var $modrtype_lang = array();
  29. var $write_type = 'forum';
  30. var $lengh_limit = 20;
  31. var $word_limit = 3;
  32. var $seo_unset_opts = array();
  33. function main($id, $mode) {
  34. global $config, $db, $user, $auth, $template, $cache;
  35. global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $phpbb_seo;
  36. // Start the phpbb_seo class
  37. if ( empty($phpbb_seo) ) {
  38. include_once($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.' . $phpEx);
  39. $phpbb_seo = new phpbb_seo();
  40. }
  41. $user->add_lang('mods/acp_phpbb_seo');
  42. $action = request_var('action', '');
  43. $submit = (isset($_POST['submit'])) ? true : false;
  44. $form_key = 'acp_board';
  45. add_form_key($form_key);
  46. $display_vars = array();
  47. // --> Zero Dupe
  48. if (@isset($phpbb_seo->seo_opt['zero_dupe']) ) {
  49. $this->multiple_options['zero_dupe']['post_redir_values'] = array('off' => 'off', 'post' => 'post', 'guest' => 'guest', 'all' => 'all'); // do not change
  50. $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
  51. }
  52. // <-- Mod rewrite selector
  53. if ($phpbb_seo->modrtype == 1) {
  54. $this->seo_unset_opts = array('cache_layer', 'rem_ids');
  55. } elseif (!$phpbb_seo->seo_opt['cache_layer']) {
  56. $this->seo_unset_opts = array('rem_ids');
  57. }
  58. $this->modrtype_lang = $this->set_phpbb_seo_links();
  59. $this->multiple_options['modrtype_lang'] = $this->modrtype_lang['titles'];
  60. if (@isset($phpbb_seo->seo_opt['modrtype']) ) {
  61. $this->multiple_options['modrtype_values'] = array( 1 => 1, 2 => 2, 3 => 3 ); // do not change;
  62. }
  63. // <-- Mod rewrite selector
  64. foreach ( $this->seo_unset_opts as $opt ) {
  65. if ( $optkey = array_search($opt, $phpbb_seo->cache_config['dynamic_options']) ) {
  66. unset($phpbb_seo->cache_config['dynamic_options'][$optkey]);
  67. }
  68. }
  69. // We need shorter URLs with Virtual Folder Trick
  70. if ($phpbb_seo->seo_opt['virtual_folder']) {
  71. $this->lengh_limit = 20;
  72. $this->word_limit = 3;
  73. } else {
  74. $this->lengh_limit = 30;
  75. $this->word_limit = 5;
  76. }
  77. $related_installed = false;
  78. switch ($mode) {
  79. case 'settings':
  80. $this->write_type = 'forum';
  81. $display_vars['title'] = 'ACP_PHPBB_SEO_CLASS';
  82. $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>');
  83. $display_vars['vars'] = array();
  84. $i = 2;
  85. $display_vars['vars']['legend1'] = 'ACP_PHPBB_SEO_CLASS';
  86. foreach($phpbb_seo->cache_config['dynamic_options'] as $optionname => $optionvalue) {
  87. if ( @is_bool($phpbb_seo->seo_opt[$optionvalue]) ) {
  88. if ($optionvalue == 'virtual_root' && !$phpbb_seo->seo_path['phpbb_script']) {
  89. continue;
  90. }
  91. $display_vars['vars'][$optionvalue] = array('lang' => $optionvalue, 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'lang_explain' => $optionvalue . '_explain');
  92. $this->new_config[$optionvalue] = $phpbb_seo->seo_opt[$optionvalue];
  93. } elseif ( @isset($this->multiple_options[$optionvalue . '_values']) ) {
  94. $this->dyn_select[$optionvalue] = $this->multiple_options[$optionvalue . '_values'];
  95. $display_vars['vars'][$optionvalue] = array('lang' => $optionvalue, 'validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true, 'lang_explain' => $optionvalue . '_explain');
  96. $this->new_config[$optionvalue] = $phpbb_seo->seo_opt[$optionvalue];
  97. } elseif ( is_array($optionvalue)) {
  98. $display_vars['vars']['legend' . $i] = $optionname;
  99. $i++;
  100. foreach ($optionvalue as $key => $value) {
  101. $this->array_type_cfg[$optionname . '_' . $key] = array('main' => $optionname, 'sub' => $key);
  102. if ( is_bool($value) ) {
  103. $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain');
  104. $this->new_config[$optionname . '_' . $key] = $phpbb_seo->seo_opt[$optionname][$key];
  105. } elseif ( @isset($this->multiple_options[$optionname][$key . '_values'] )) {
  106. $this->dyn_select[$optionname . '_' . $key] = $this->multiple_options[$optionname][$key . '_values'];
  107. $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain');
  108. $this->new_config[$optionname . '_' . $key] = $phpbb_seo->seo_opt[$optionname][$key];
  109. } else {
  110. $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'string:0:50', 'type' => 'text:50:50', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain');
  111. $this->new_config[$optionname . '_' . $key] = $phpbb_seo->seo_opt[$optionname][$key];
  112. }
  113. }
  114. }
  115. }
  116. break;
  117. case 'forum_url':
  118. // used for cache
  119. $this->write_type = 'forum';
  120. $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']);
  121. if ( $phpbb_seo->modrtype == 1 || !$phpbb_seo->seo_opt['cache_layer'] ) {
  122. trigger_error($user->lang['ACP_NO_FORUM_URL'] . preg_replace('`(&amp;|&|\?)mode=forum_url`i', '', adm_back_link($this->u_action)));
  123. break;
  124. }
  125. $display_vars['title'] = 'ACP_FORUM_URL';
  126. $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>';
  127. $display_vars['vars'] = array();
  128. $display_vars['vars']['legend1'] = 'ACP_FORUM_URL';
  129. $sql = "SELECT forum_id, forum_name
  130. FROM " . FORUMS_TABLE . "
  131. ORDER BY left_id ASC";
  132. $result = $db->sql_query($sql);
  133. $forum_url_title = $error_cust = '';
  134. while( $row = $db->sql_fetchrow($result) ) {
  135. $this->forum_ids[$row['forum_id']] = $row['forum_name'];
  136. }
  137. $db->sql_freeresult($result);
  138. // take care of deleted forums
  139. foreach ($phpbb_seo->cache_config['forum'] as $fid => $null) {
  140. if (!isset($this->forum_ids[$fid])) {
  141. unset($phpbb_seo->cache_config['forum'][$fid]);
  142. }
  143. }
  144. foreach ($this->forum_ids as $forum_id => $forum_name) {
  145. $error_cust = '';
  146. // Is the URL cached already ?
  147. if ( empty($phpbb_seo->cache_config['forum'][$forum_id]) ) {
  148. // Suggest the one from the title
  149. $forum_url_title = $phpbb_seo->format_url($forum_name, $phpbb_seo->seo_static['forum']);
  150. if (!in_array($forum_url_title, $forbidden)) {
  151. if (array_search($forum_url_title, $phpbb_seo->cache_config['forum'])) {
  152. $this->new_config['forum_url' . $forum_id] = $forum_url_title . $phpbb_seo->seo_delim['forum'] . $forum_id;
  153. $error_cust = '<li>&nbsp;' . sprintf($user->lang['SEO_ADVICE_DUPE'], $forum_url_title) . '</li>';
  154. } else {
  155. $this->new_config['forum_url' . $forum_id] = $forum_url_title . (@$phpbb_seo->cache_config['settings']['rem_ids'] ? '': $phpbb_seo->seo_delim['forum'] . $forum_id);
  156. }
  157. } else {
  158. $this->new_config['forum_url' . $forum_id] = $forum_url_title . $phpbb_seo->seo_delim['forum'] . $forum_id;
  159. $error_cust = '<li>&nbsp;' . sprintf($user->lang['SEO_ADVICE_RESERVED'], $forum_url_title) . '</li>';
  160. }
  161. $title = '<b style="color:red">' . $forum_name . ' - ID ' . $forum_id . '</b>';
  162. $status_msg = '<b style="color:red">' . $user->lang['SEO_CACHE_URL_NOT_OK'] . '</b>';
  163. $status_msg .= '<br/><span style="color:red">' . $user->lang['SEO_CACHE_URL'] . '&nbsp;:</span>&nbsp;' . $this->new_config['forum_url' . $forum_id] . $phpbb_seo->seo_ext['forum'];
  164. $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));
  165. } else { // Cached
  166. $this->new_config['forum_url' . $forum_id] = $phpbb_seo->cache_config['forum'][$forum_id];
  167. $title = '<b style="color:green">' . $forum_name . ' - ID ' . $forum_id . '</b>';
  168. $status_msg = '<span style="color:green">' . $user->lang['SEO_CACHE_URL_OK'] . '&nbsp;:</span>&nbsp;<b style="color:green">' . $this->new_config['forum_url' . $forum_id] . '</b>';
  169. $status_msg .= '<br/><span style="color:green">' . $user->lang['SEO_CACHE_URL'] . '&nbsp;:</span>&nbsp;' . $this->new_config['forum_url' . $forum_id] . $phpbb_seo->seo_ext['forum'];
  170. $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));
  171. }
  172. }
  173. break;
  174. case 'htaccess':
  175. $this->write_type = 'htaccess';
  176. $display_vars['title'] = 'ACP_HTACCESS';
  177. $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>';
  178. $display_vars['vars'] = array();
  179. $display_vars['vars']['legend1'] = 'ACP_HTACCESS';
  180. $display_vars['vars']['save'] = array('lang' => 'SEO_HTACCESS_SAVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,);
  181. $display_vars['vars']['more_options'] = array('lang' => 'SEO_MORE_OPTION', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,);
  182. $this->new_config['save'] = false;
  183. $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config;
  184. $this->new_config['more_options'] = isset($cfg_array['more_options']) ? $cfg_array['more_options'] : false;
  185. $this->new_config['slash'] = isset($cfg_array['slash']) ? $cfg_array['slash'] : false;
  186. $this->new_config['wslash'] = isset($cfg_array['wslash']) ? $cfg_array['wslash'] : false;
  187. $this->new_config['rbase'] = isset($cfg_array['rbase']) ? $cfg_array['rbase'] : false;
  188. if ($this->new_config['more_options']) {
  189. $display_vars['vars']['slash'] = array('lang' => 'SEO_HTACCESS_SLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,);
  190. $display_vars['vars']['wslash'] = array('lang' => 'SEO_HTACCESS_WSLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,);
  191. if ($phpbb_seo->seo_path['phpbb_script'] && !$phpbb_seo->seo_opt['virtual_root']) {
  192. $display_vars['vars']['rbase'] = array('lang' => 'SEO_HTACCESS_RBASE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true,);
  193. }
  194. }
  195. // Dirty yet simple templating
  196. $user->lang['ACP_HTACCESS_EXPLAIN'] .= $this->seo_htaccess();
  197. break;
  198. case 'extended':
  199. $display_vars = array(
  200. 'title' => 'ACP_SEO_EXTENDED',
  201. 'vars' => array(
  202. 'legend1' => 'SEO_EXTERNAL_LINKS',
  203. 'seo_ext_links' => array('lang' => 'SEO_EXTERNAL_LINKS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 1),
  204. 'seo_ext_subdomain' => array('lang' => 'SEO_EXTERNAL_SUBDOMAIN', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0),
  205. 'seo_ext_classes' => array('lang' => 'SEO_EXTERNAL_CLASSES', 'validate' => 'string', 'type' => 'text:40:250', 'explain' => true, 'default' => ''),
  206. ),
  207. );
  208. // Related topics
  209. if (file_exists($phpbb_root_path . "phpbb_seo/phpbb_seo_related.$phpEx")) {
  210. $related_installed = true;
  211. $user->add_lang('mods/phpbb_seo_related_install');
  212. $display_vars['vars'] += array(
  213. 'legend2' => 'RELATED_TOPICS',
  214. '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),
  215. 'seo_related_check_ignore' => array('lang' => 'SEO_RELATED_CHECK_IGNORE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0),
  216. 'seo_related_limit' => array('lang' => 'SEO_RELATED_LIMIT', 'validate' => 'int:2:25', 'type' => 'text:3:4', 'explain' => true, 'default' => 5),
  217. 'seo_related_allforums' => array('lang' => 'SEO_RELATED_ALLFORUMS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0),
  218. );
  219. }
  220. // dynamic meta tag mod
  221. if (class_exists('seo_meta')) {
  222. $display_vars['vars'] += array(
  223. 'legend3' => 'SEO_META',
  224. 'seo_meta_title' => array('lang' => 'SEO_META_TITLE', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $config['sitename']),
  225. 'seo_meta_desc' => array('lang' => 'SEO_META_DESC', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $config['site_desc']),
  226. 'seo_meta_desc_limit' => array('lang' => 'SEO_META_DESC_LIMIT', 'validate' => 'int:5:40', 'type' => 'text:3:4', 'explain' => true, 'default' => 25),
  227. 'seo_meta_bbcode_filter' => array('lang' => 'SEO_META_BBCODE_FILTER', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => 'img|url|flash|code'),
  228. 'seo_meta_keywords' => array('lang' => 'SEO_META_KEYWORDS', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $config['site_desc']),
  229. 'seo_meta_keywords_limit' => array('lang' => 'SEO_META_KEYWORDS_LIMIT', 'validate' => 'int:5:40', 'type' => 'text:3:4', 'explain' => true, 'default' => 15),
  230. 'seo_meta_min_len' => array('lang' => 'SEO_META_MIN_LEN', 'validate' => 'int:0:10', 'type' => 'text:3:4', 'explain' => true, 'default' => 2),
  231. 'seo_meta_check_ignore' => array('lang' => 'SEO_META_CHECK_IGNORE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0),
  232. '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']),
  233. 'seo_meta_copy' => array('lang' => 'SEO_META_COPY', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $config['sitename']),
  234. 'seo_meta_file_filter' => array('lang' => 'SEO_META_FILE_FILTER', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => 'ucp'),
  235. 'seo_meta_get_filter' => array('lang' => 'SEO_META_GET_FILTER', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => 'style,hilit,sid'),
  236. 'seo_meta_robots' => array('lang' => 'SEO_META_ROBOTS', 'validate' => 'string:0:225', 'type' => 'text:25:150', 'explain' => true, 'default' => 'index,follow'),
  237. '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' => ''),
  238. );
  239. }
  240. // Optimal title
  241. if (isset($user->lang['Page'])) {
  242. $display_vars['vars'] += array(
  243. 'legend4' => 'SEO_PAGE_TITLES',
  244. 'seo_append_sitename' => array('lang' => 'SEO_APPEND_SITENAME', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0),
  245. );
  246. }
  247. // install if necessary
  248. foreach ($display_vars['vars'] as $config_name => $config_setup) {
  249. if (strpos($config_name, 'legend') !== false) {
  250. continue;
  251. }
  252. if (!isset($config[$config_name])) {
  253. set_config($config_name, $config_setup['default']);
  254. unset($display_vars['vars'][$config_name]['default']);
  255. }
  256. }
  257. $this->new_config = $config;
  258. break;
  259. default:
  260. trigger_error('NO_MODE', E_USER_ERROR);
  261. break;
  262. }
  263. $error = array();
  264. $seo_msg = array();
  265. $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config;
  266. if ($submit && !check_form_key($form_key)) {
  267. $error[] = $user->lang['FORM_INVALID'];
  268. }
  269. // We validate the complete config if whished
  270. validate_config_vars($display_vars['vars'], $cfg_array, $error);
  271. // Do not write values if there is an error
  272. if (!empty($error)) {
  273. $submit = false;
  274. }
  275. $additional_notes = '';
  276. // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
  277. foreach ($display_vars['vars'] as $config_name => $cfg_setup) {
  278. if ((!isset($cfg_array[$config_name]) && @$cfg_setup['method'] != 'select_multiple') || strpos($config_name, 'legend') !== false) {
  279. continue;
  280. }
  281. // Handle multiple select options
  282. if (!empty($cfg_setup['method']) && $cfg_setup['method'] == 'select_multiple') {
  283. if (isset($_POST['multiple_' . $config_name])) {
  284. $m_values = utf8_normalize_nfc(request_var('multiple_' . $config_name, array('' => '')));
  285. $validate_int = !empty($cfg_setup['multiple_validate']) && $cfg_setup['multiple_validate'] == 'int' ? true : false;
  286. foreach($m_values as $k => $v) {
  287. if ($validate_int) {
  288. $v = max(0, (int) $v);
  289. }
  290. if (empty($v)) {
  291. unset($m_values[$k]);
  292. } else {
  293. $m_values[$k] = $v;
  294. }
  295. }
  296. sort($m_values);
  297. $this->new_config[$config_name] = $m_values;
  298. $config_value = implode(',', $m_values);
  299. if ( strlen($config_value) > 255 ) {
  300. $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$cfg_setup['lang']], 255);
  301. }
  302. $submit = empty($error);
  303. } else {
  304. if ($submit) {
  305. $this->new_config[$config_name] = array();
  306. $config_value = '';
  307. } else {
  308. $config_value = $this->new_config[$config_name];
  309. $this->new_config[$config_name] = !empty($config_value) ? explode(',', $config_value) : array();
  310. }
  311. }
  312. } else {
  313. $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
  314. }
  315. if ($submit) {
  316. // In case we deal with forum URLs
  317. if ($mode == 'forum_url' && preg_match('`^forum_url([0-9]+)$`', $config_name, $matches)) {
  318. // Check if this is an actual forum_id
  319. if ( isset($this->forum_ids[$matches[1]]) ) {
  320. $forum_id = intval($matches[1]);
  321. $config_value = $phpbb_seo->format_url($config_value, $phpbb_seo->seo_static['forum']);
  322. // Remove delim if required
  323. while (preg_match('`^[a-z0-9_-]+' . $phpbb_seo->seo_delim['forum'] . '[0-9]+$`i', $config_value)) {
  324. $config_value = preg_replace('`^([a-z0-9_-]+)' . $phpbb_seo->seo_delim['forum'] . '[0-9]+$`i', '\\1', $config_value);
  325. if (@$phpbb_seo->cache_config['settings']['rem_ids']) {
  326. $seo_msg['SEO_ADVICE_DELIM_REM'] = '<li>&nbsp;' . $user->lang['SEO_ADVICE_DELIM_REM'] . '</li>';
  327. }
  328. }
  329. // Forums cannot end with the pagination param
  330. while (preg_match('`^[a-z0-9_-]+' . $phpbb_seo->seo_delim['start'] . '[0-9]+$`i', $config_value)) {
  331. $config_value = preg_replace('`^([a-z0-9_-]+)' . $phpbb_seo->seo_delim['start'] . '[0-9]+$`i', "\\1", $config_value);
  332. $seo_msg['SEO_ADVICE_START'] = '<li>&nbsp;' . $user->lang['SEO_ADVICE_START'] . '</li>';
  333. }
  334. // Only update if the value is not a static one for forums
  335. if (!in_array($config_value, $forbidden)) {
  336. // and updated (sic)
  337. if ($config_value != @$phpbb_seo->cache_config['forum'][$forum_id]) {
  338. // and if not already set
  339. if (!array_search($config_value, $phpbb_seo->cache_config['forum'])) {
  340. $phpbb_seo->cache_config['forum'][$forum_id] = $config_value . (@$phpbb_seo->cache_config['settings']['rem_ids'] ? '': $phpbb_seo->seo_delim['forum'] . $forum_id);
  341. } else {
  342. $seo_msg['SEO_ADVICE_DUPE_' . $forum_id] = '<li>&nbsp;' . sprintf($user->lang['SEO_ADVICE_DUPE'], $config_value) . '</li>';
  343. }
  344. }
  345. } else {
  346. $seo_msg['SEO_ADVICE_RESERVED_' . $forum_id] = '<li>&nbsp;' . sprintf($user->lang['SEO_ADVICE_RESERVED'], $config_value) . '</li>';
  347. }
  348. }
  349. } elseif ($mode == 'settings') {
  350. 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']])) {
  351. if ( is_bool($phpbb_seo->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']]) ) {
  352. $phpbb_seo->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = ($config_value == 1) ? true : false;
  353. } elseif (is_numeric($phpbb_seo->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) {
  354. $phpbb_seo->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = intval($config_value);
  355. } elseif (is_string($phpbb_seo->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) {
  356. $phpbb_seo->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = $config_value;
  357. }
  358. } elseif ( isset($phpbb_seo->seo_opt[$config_name]) ) {
  359. if ( is_bool($phpbb_seo->seo_opt[$config_name]) ) {
  360. $phpbb_seo->cache_config['settings'][$config_name] = ($config_value == 1) ? true : false;
  361. } elseif ( is_numeric($phpbb_seo->seo_opt[$config_name]) ) {
  362. $phpbb_seo->cache_config['settings'][$config_name] = intval($config_value);
  363. } elseif ( is_string($phpbb_seo->seo_opt[$config_name]) ) {
  364. $phpbb_seo->cache_config['settings'][$config_name] = $config_value;
  365. }
  366. }
  367. // Let's make sure that the proper field was added to the topic table
  368. if ($config_name === 'sql_rewrite' && $config_value == 1 && !$phpbb_seo->seo_opt['sql_rewrite']) {
  369. if (!class_exists('phpbb_db_tools')) {
  370. include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
  371. }
  372. $db_tools = new phpbb_db_tools($db);
  373. $db_tools->db->sql_return_on_error(true);
  374. if (!$db_tools->sql_column_exists(TOPICS_TABLE, 'topic_url')) {
  375. $db_tools->sql_column_add(TOPICS_TABLE, 'topic_url', array('VCHAR', ''));
  376. }
  377. $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>');
  378. if ($db_tools->db->sql_error_triggered) {
  379. $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;
  380. $submit = false;
  381. }
  382. $db_tools->db->sql_return_on_error(false);
  383. }
  384. // Let's make sure the proper index is added for the no dupe (in case it is installed and activated)
  385. if ($config_name === 'no_dupe_on' && $config_value == 1 && !$phpbb_seo->seo_opt['no_dupe']['on']) {
  386. if (!class_exists('phpbb_db_tools')) {
  387. include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
  388. }
  389. // in case we already started the phpbb_db_tools class above
  390. if (empty($db_tools)) {
  391. $db_tools = new phpbb_db_tools($db);
  392. }
  393. $db_tools->db->sql_return_on_error(true);
  394. $indexes = $db_tools->sql_list_index(TOPICS_TABLE);
  395. $drop_index_name = 'topic_last_post_id';
  396. $add_index_name = 'topic_lpid';
  397. if (in_array($drop_index_name, $indexes)) {
  398. $db_tools->sql_index_drop(TOPICS_TABLE, $drop_index_name);
  399. }
  400. if (!in_array($add_index_name, $indexes)) {
  401. // Try to override some limits - maybe it helps some...
  402. @set_time_limit(0);
  403. @ini_set('memory_limit', '128M');
  404. $db_tools->sql_create_index(TOPICS_TABLE, $add_index_name, array('topic_last_post_id'));
  405. }
  406. if ($db_tools->db->sql_error_triggered) {
  407. $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;
  408. $submit = false;
  409. }
  410. $db_tools->db->sql_return_on_error(false);
  411. }
  412. } elseif ($mode == 'extended') {
  413. if ($related_installed && $config_name === 'seo_related') {
  414. $fulltext = 0;
  415. $nothing_to_do = false;
  416. if ($db->sql_layer == 'mysql4' || $db->sql_layer == 'mysqli') {
  417. $add = $remove = $alter = false;
  418. if ($config_value && !$config['seo_related']) {
  419. $alter = $add = true;
  420. }
  421. if (!$config_value && $config['seo_related']) {
  422. $alter = $remove = true;
  423. }
  424. // let's go
  425. if ($alter) {
  426. // Try to override some limits - maybe it helps some...
  427. @set_time_limit(0);
  428. @ini_set('memory_limit', '128M');
  429. // use db_tools to check the index
  430. if (!class_exists('phpbb_db_tools')) {
  431. include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
  432. }
  433. if (empty($db_tools)) {
  434. $db_tools = new phpbb_db_tools($db);
  435. }
  436. $indexes = $db_tools->sql_list_index(TOPICS_TABLE);
  437. if (in_array('topic_tft', $indexes)) {
  438. $nothing_to_do = $add ? true : false;
  439. $fulltext = 1;
  440. } else {
  441. $nothing_to_do = $remove ? true : false;
  442. $fulltext = 0;
  443. }
  444. // do not use db_tools since it does not support to add FullText indexes
  445. if (!$nothing_to_do) {
  446. // Here we use quite a basic approach to make sure that the index is not refused for bad reasons
  447. if ($add) {
  448. $sql = 'ALTER TABLE ' . TOPICS_TABLE . '
  449. ADD FULLTEXT topic_tft (topic_title)';
  450. } else {
  451. $sql = 'ALTER TABLE ' . TOPICS_TABLE . '
  452. DROP INDEX topic_tft';
  453. }
  454. $db->sql_return_on_error(true);
  455. $db->sql_query($sql);
  456. if ($db->sql_error_triggered) {
  457. $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;
  458. $submit = false;
  459. $config_value = 0;
  460. }
  461. // make *sure* about the index !
  462. $indexes = $db_tools->sql_list_index(TOPICS_TABLE);
  463. $fulltext = in_array('topic_tft', $indexes) ? 1 : 0;
  464. $db->sql_return_on_error(false);
  465. }
  466. }
  467. }
  468. if ($alter) {
  469. set_config('seo_related_fulltext', $fulltext);
  470. }
  471. }
  472. set_config($config_name, $config_value);
  473. }
  474. }
  475. }
  476. if (sizeof($error)) {
  477. $submit = false;
  478. }
  479. if ($submit) {
  480. if ($mode == 'htaccess') {
  481. if ($this->new_config['save']) {
  482. $this->write_cache($this->write_type);
  483. add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode));
  484. }
  485. } elseif ($mode == 'extended') {
  486. add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode));
  487. trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
  488. } else {
  489. if ( $this->write_cache($this->write_type) ) {
  490. ksort($phpbb_seo->cache_config[$this->write_type]);
  491. add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode));
  492. $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 />' : '';
  493. global $msg_long_text;
  494. $msg_long_text = $user->lang['SEO_CACHE_MSG_OK'] . $msg . adm_back_link($this->u_action);
  495. if ($additional_notes) {
  496. $msg_long_text .= "<br/><br/>$additional_notes";
  497. }
  498. trigger_error(false);
  499. } else {
  500. trigger_error($user->lang['SEO_CACHE_MSG_FAIL'] . adm_back_link($this->u_action));
  501. }
  502. }
  503. }
  504. $this->tpl_name = 'acp_board';
  505. $this->page_title = $display_vars['title'];
  506. $phpbb_seo->seo_end();
  507. $l_title_explain = $user->lang[$display_vars['title'] . '_EXPLAIN'];
  508. if ($mode != 'extended') {
  509. $l_title_explain .= $mode == 'htaccess' ? '' : $this->check_cache_folder($phpbb_root_path . $phpbb_seo->seo_opt['cache_folder']);
  510. }
  511. $template->assign_vars(array(
  512. 'L_TITLE' => $user->lang[$display_vars['title']],
  513. 'L_TITLE_EXPLAIN' => $l_title_explain,
  514. 'S_ERROR' => (sizeof($error)) ? true : false,
  515. 'ERROR_MSG' => implode('<br />', $error),
  516. 'U_ACTION' => $this->u_action)
  517. );
  518. // Output relevant page
  519. foreach ($display_vars['vars'] as $config_key => $vars) {
  520. if (!is_array($vars) && strpos($config_key, 'legend') === false) {
  521. continue;
  522. }
  523. if (strpos($config_key, 'legend') !== false) {
  524. $template->assign_block_vars('options', array(
  525. 'S_LEGEND' => true,
  526. 'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
  527. );
  528. continue;
  529. }
  530. $type = explode(':', $vars['type']);
  531. $l_explain = '';
  532. if ($vars['explain'] && isset($vars['lang_explain'])) {
  533. $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
  534. } elseif ($vars['explain'] && isset($vars['lang_explain_custom'])) {
  535. $l_explain = $vars['lang_explain_custom'];
  536. } elseif ($vars['explain']) {
  537. $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
  538. }
  539. $template->assign_block_vars('options', array(
  540. 'KEY' => $config_key,
  541. 'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'],
  542. 'S_EXPLAIN' => $vars['explain'],
  543. 'TITLE_EXPLAIN' => $l_explain,
  544. 'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars),
  545. )
  546. );
  547. unset($display_vars['vars'][$config_key]);
  548. }
  549. }
  550. /**
  551. * forum_url_check validation
  552. */
  553. function forum_url_input($value, $key) {
  554. global $user, $phpbb_seo;
  555. return '<input id="' . $key . '" type="text" size="40" maxlength="255" name="config[' . $key . ']" value="' . $value . '" /> ';
  556. }
  557. /**
  558. * select_string custom select string
  559. */
  560. function select_string($value, $key) {
  561. global $phpbb_seo;
  562. $select_ary = $this->dyn_select[$key];
  563. $html = '';
  564. foreach ($select_ary as $sel_value) {
  565. if ( @isset($this->array_type_cfg[$key]) ) {
  566. $selected = ($sel_value == @$phpbb_seo->seo_opt[$this->array_type_cfg[$key]['main']][$this->array_type_cfg[$key]['sub']]) ? ' selected="selected"' : '';
  567. $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;
  568. } else {
  569. $selected = ($sel_value == @$phpbb_seo->cache_config['settings'][$key]) ? ' selected="selected"' : '';
  570. $sel_title = @isset($this->multiple_options[$key . '_lang'][$sel_value]) ? $this->multiple_options[$key . '_lang'][$sel_value] : $sel_value;
  571. }
  572. $html .= '<option value="' . $sel_value . '"' . $selected . '>' . $sel_title . '</option>';
  573. }
  574. return $html;
  575. }
  576. /**
  577. * seo_advices Always needed :-)
  578. */
  579. function seo_advices($url, $forum_id, $cached = FALSE, $error_cust = '') {
  580. global $phpbb_seo, $user;
  581. $seo_advice = '';
  582. // Check how well is the URL SEO wise
  583. if ( !empty($error_cust) ) {
  584. $seo_advice .= $error_cust;
  585. }
  586. if (strlen($url) > $this->lengh_limit) { // Size
  587. $seo_advice .= '<li>&nbsp;' . $user->lang['SEO_ADVICE_LENGTH'] . '</li>';
  588. }
  589. if (preg_match('`^[a-z0-9_-]+' . $phpbb_seo->seo_delim['forum'] . '[0-9]+$`i', $url)) { // With delimiter and id
  590. if (@$phpbb_seo->cache_config['settings']['rem_ids']) {
  591. $seo_advice .= '<li style="color:red">&nbsp;' . $user->lang['SEO_ADVICE_DELIM'] . '</li>';
  592. }
  593. }
  594. if ($phpbb_seo->seo_static['forum'] == $url) { // default
  595. $seo_advice .= '<li>&nbsp;' . $user->lang['SEO_ADVICE_DEFAULT'] . '</li>';
  596. }
  597. // Check the number of word
  598. $url_words = explode('-', $url);
  599. if (count($url_words) > $this->word_limit) {
  600. $seo_advice .= '<li>&nbsp;' . $user->lang['SEO_ADVICE_WORDS'] . '</li>';
  601. }
  602. return $seo_advice ? '<ul style="color:red">' . $seo_advice . '</ul>' : '';
  603. }
  604. /**
  605. * seo_htaccess The evil one ;-)
  606. */
  607. function seo_htaccess($html = true) {
  608. global $phpbb_seo, $user, $error, $phpEx, $config, $phpbb_root_path, $config, $phpbb_admin_path;
  609. static $htaccess_code = '';
  610. $htaccess_tpl = '';
  611. // GYM Sitemaps & RSS
  612. $gym_installed = (boolean) (!empty($config['gym_installed']) && file_exists($phpbb_root_path . 'gym_sitemaps/includes/gym_sitemaps.' . $phpEx));
  613. $rss_path = $google_path = $html_path = '';
  614. $rss_commpat_note = $google_commpat_note = $html_commpat_note = $compat_path_note = '';
  615. $rss_commpat_pre = $html_commpat_pre = $google_commpat_pre = '<b style="color:blue"># RewriteRule';
  616. $rss_commpat_post = $html_commpat_post = $google_commpat_post = '</b>';
  617. $google_comp_path = $rss_comp_path = $html_comp_path = false;
  618. if ($gym_installed) {
  619. $compat_path_note = '<b style="color:red"># NOTE : THE FOLLOWING REWRITERULE IS LEFT COMMENTED BECAUSE IT CANNOT' . "\n";
  620. $compat_path_note .= '# BE IMPLEMENTED IN THIS .HTACCESS, BUT RATHER IN AN ABOVE ONE' . "\n";
  621. $compat_path_note .= '# WITH PROPER SLASHES AND PATHS</b>' . "\n";
  622. $rss_commpat_note = $google_commpat_note = $html_commpat_note = $compat_path_note;
  623. require_once($phpbb_root_path . 'gym_sitemaps/includes/gym_common.' . $phpEx);
  624. obtain_gym_config('main', $gym_config);
  625. $google_url = trim($gym_config['google_url'], '/') . '/';
  626. if (utf8_strpos($google_url, $phpbb_seo->seo_path['phpbb_url']) !== false) {
  627. $google_path = trim(str_replace($phpbb_seo->seo_path['root_url'], '', $google_url), '/');
  628. $google_comp_path = true;
  629. $google_commpat_pre = '<b style="color:green">RewriteRule</b>';
  630. $google_commpat_post = $google_commpat_note = '';
  631. }
  632. $rss_url = trim($gym_config['rss_url'], '/') . '/';
  633. if (utf8_strpos($rss_url, $phpbb_seo->seo_path['phpbb_url']) !== false) {
  634. $rss_path = trim(str_replace($phpbb_seo->seo_path['root_url'], '', $rss_url), '/');
  635. $rss_comp_path = true;
  636. $rss_commpat_pre = '<b style="color:green">RewriteRule</b>';
  637. $rss_commpat_post = $rss_commpat_note = '';
  638. }
  639. $html_url = trim($gym_config['html_url'], '/') . '/';
  640. if (utf8_strpos($html_url, $phpbb_seo->seo_path['phpbb_url']) !== false) {
  641. $html_path = trim(str_replace($phpbb_seo->seo_path['root_url'], '', $html_url), '/');
  642. $html_comp_path = true;
  643. $html_commpat_pre = '<b style="color:green">RewriteRule</b>';
  644. $html_commpat_post = $html_commpat_note = '';
  645. }
  646. }
  647. if ( empty($htaccess_code) ) {
  648. // get mods .htaccess tpls
  649. $mods_ht = $this->get_mods_ht();
  650. $default_slash = '/';
  651. $wierd_slash = '';
  652. $phpbb_path = trim($phpbb_seo->seo_path['phpbb_script'], '/');
  653. $show_rewritebase_opt = false;
  654. $rewritebase = '';
  655. $wierd_slash = $this->new_config['wslash'] ? '<b style="color:red">/</b>' : '';
  656. $default_slash = $this->new_config['slash'] ? '' : '/';
  657. if (!empty($phpbb_path )) {
  658. $phpbb_path = $phpbb_path . '/';
  659. if ($this->new_config['rbase']) {
  660. $rewritebase = $phpbb_path;
  661. $default_slash = $this->new_config['slash'] ? '/' : '';
  662. }
  663. $rewritebase = $this->new_config['rbase'] ? $phpbb_path : '';
  664. $show_rewritebase_opt = $phpbb_seo->seo_opt['virtual_root'] ? false : true;
  665. }
  666. if (!empty($rewritebase)) {
  667. $rss_path = trim(str_replace(trim($phpbb_path, '/'), '', $rss_path), '/');
  668. $google_path = trim(str_replace(trim($phpbb_path, '/'), '', $google_path), '/');
  669. $html_path = trim(str_replace(trim($phpbb_path, '/'), '', $html_path), '/');
  670. }
  671. $colors = array( 'color' => '<b style="color:%1$s">%2$s</b>',
  672. 'static' => '#A020F0',
  673. 'ext' => '#6A5ACD',
  674. 'delim' => '#FF00FF',
  675. );
  676. $tpl = array('paginpage' => '/?(<b style="color:' . $colors['static'] . '">%1$s</b>([0-9]+)<b style="color:' . $colors['ext'] . '">%2$s</b>)?',
  677. 'pagin' => '(<b style="color:' . $colors['delim'] . '">%1$s</b>([0-9]+))?<b style="color:' . $colors['ext'] . '">%2$s</b>',
  678. 'static' => sprintf($colors['color'] , $colors['static'], '%1$s'),
  679. 'ext' => sprintf($colors['color'] , $colors['ext'], '%1$s'),
  680. 'delim' => sprintf($colors['color'] , $colors['delim'], '%1$s'),
  681. );
  682. $modrtype = array( 1 => 'SIMPLE', 2 => 'MIXED', 1 => 'SIMPLE', 3 => 'ADVANCED', 'type' => intval($phpbb_seo->modrtype));
  683. //
  684. $htaccess_tpl = '<b style="color:blue"># Lines That should already be in your .htacess</b>' . "\n";
  685. $htaccess_tpl .= '<b style="color:brown">&lt;Files</b> <b style="color:#FF00FF">"config.{PHP_EX}"</b><b style="color:brown">&gt;</b>' . "\n";
  686. $htaccess_tpl .= "\t" . 'Order Allow,Deny' . "\n";
  687. $htaccess_tpl .= "\t" . 'Deny from All' . "\n";
  688. $htaccess_tpl .= '<b style="color:brown">&lt;/Files&gt;</b>' . "\n";
  689. $htaccess_tpl .= '<b style="color:brown">&lt;Files</b> <b style="color:#FF00FF">"common.{PHP_EX}"</b><b style="color:brown">&gt;</b>' . "\n";
  690. $htaccess_tpl .= "\t" . 'Order Allow,Deny' . "\n";
  691. $htaccess_tpl .= "\t" . 'Deny from All' . "\n";
  692. $htaccess_tpl .= '<b style="color:brown">&lt;/Files&gt;</b>' . "\n\n";
  693. $htaccess_tpl .= '<b style="color:blue"># You may need to un-comment the following lines' . "\n";
  694. $htaccess_tpl .= '# Options +FollowSymlinks' . "\n";
  695. $htaccess_tpl .= '# To make sure that rewritten dir or file (/|.html) will not load dir.php in case it exist' . "\n";
  696. $htaccess_tpl .= '# Options -MultiViews' . "\n";
  697. $htaccess_tpl .= '# REMEBER YOU ONLY NEED TO STARD MOD REWRITE ONCE</b>' . "\n";
  698. $htaccess_tpl .= '<b style="color:green">RewriteEngine</b> <b style="color:#FF00FF">On</b>' . "\n";
  699. $htaccess_tpl .= '<b style="color:blue"># Uncomment the statement below if you want to make use of' . "\n";
  700. $htaccess_tpl .= '# HTTP authentication and it does not already work.' . "\n";
  701. $htaccess_tpl .= '# This could be required if you are for example using PHP via Apache CGI.' . "\n";
  702. $htaccess_tpl .= '# RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]</b>' . "\n";
  703. $htaccess_tpl .= '<b style="color:blue"># REWRITE BASE</b>' . "\n";
  704. $htaccess_tpl .= '<b style="color:green">RewriteBase</b> <b>/{REWRITEBASE}</b>' . "\n";
  705. $htaccess_tpl .= '<b style="color:blue"># HERE IS A GOOD PLACE TO FORCE CANONICAL DOMAIN</b>' . "\n";
  706. $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";
  707. $htaccess_tpl .= '<b style="color:blue"># RewriteRule ^(.*)$ ' . $phpbb_seo->seo_path['root_url'] . '{REWRITEBASE}$1 [QSA,L,R=301]</b>' . "\n\n";
  708. $htaccess_tpl .= '<b style="color:blue"># DO NOT GO FURTHER IF THE REQUESTED FILE / DIR DOES EXISTS</b>' . "\n";
  709. $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} -f [OR]' . "\n";
  710. $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} -d' . "\n";
  711. $htaccess_tpl .= '<b style="color:green">RewriteRule</b> . - [L]' . "\n";
  712. $htaccess_tpl .= '<b style="color:blue">#####################################################' . "\n";
  713. $htaccess_tpl .= '# PHPBB SEO REWRITE RULES ALL MODES' . "\n";
  714. $htaccess_tpl .= '#####################################################' . "\n";
  715. $htaccess_tpl .= '# AUTHOR : dcz www.phpbb-seo.com' . "\n";
  716. $htaccess_tpl .= '# STARTED : 01/2006' . "\n";
  717. $htaccess_tpl .= '#################################' . "\n";
  718. $htaccess_tpl .= '# FORUMS PAGES' . "\n";
  719. $htaccess_tpl .= '###############</b>' . "\n";
  720. if (!empty($phpbb_seo->seo_static['index'])) {
  721. $htaccess_tpl .= '<b style="color:blue"># FORUM INDEX</b>' . "\n";
  722. $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";
  723. } else {
  724. $htaccess_tpl .= '<b style="color:blue"># FORUM INDEX REWRITERULE WOULD STAND HERE IF USED. "forum" REQUIRES TO BE SET AS FORUM INDEX' . "\n";
  725. $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";
  726. }
  727. $htaccess_common_tpl = '<b style="color:blue"># PHPBB FILES ALL MODES</b>' . "\n";
  728. $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&amp;t=$1 [QSA,L,NC]' . "\n";
  729. if ( $phpbb_seo->seo_opt['profile_noids'] ) {
  730. $htaccess_common_tpl .= '<b style="color:blue"># PROFILES THROUGH USERNAME</b>' . "\n";
  731. $htaccess_common_tpl .= '<b style="color:green">RewriteRule</b> ^{WIERD_SLASH}{PHPBB_LPATH}{STATIC_USER}/([^/]+)/?$ {DEFAULT_SLASH}{PHPBB_RPATH}memberlist.{PHP_EX}?mode=viewprofile&amp;un=$1 [QSA,L,NC]' . "\n";
  732. $htaccess_common_tpl .= '<b style="color:blue"># USER MESSAGES THROUGH USERNAME</b>' . "\n";
  733. $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&amp;sr=$2&amp;start=$4 [QSA,L,NC]' . "\n";
  734. } else {
  735. $htaccess_common_tpl .= '<b style="color:blue"># PROFILES ALL MODES WITH ID</b>' . "\n";
  736. $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&amp;u=$2 [QSA,L,NC]' . "\n";
  737. $htaccess_common_tpl .= '<b style="color:blue"># USER MESSAGES ALL MODES WITH ID</b>' . "\n";
  738. $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&amp;sr=$3&amp;start=$5 [QSA,L,NC]' . "\n";
  739. }
  740. $htaccess_common_tpl .= '<b style="color:blue"># GROUPS ALL MODES</b>' . "\n";
  741. $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&amp;g=$2&amp;start=$4 [QSA,L,NC]' . "\n";
  742. $htaccess_common_tpl .= '<b style="color:blue"># POST</b>' . "\n";
  743. $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";
  744. $htaccess_common_tpl .= '<b style="color:blue"># ACTIVE TOPICS</b>' . "\n";
  745. $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&amp;start=$2&amp;sr=topics [QSA,L,NC]' . "\n";
  746. $htaccess_common_tpl .= '<b style="color:blue"># UNANSWERED TOPICS</b>' . "\n";
  747. $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&amp;start=$2&amp;sr=topics [QSA,L,NC]' . "\n";
  748. $htaccess_common_tpl .= '<b style="color:blue"># NEW POSTS</b>' . "\n";
  749. $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&amp;start=$2&amp;sr=topics [QSA,L,NC]' . "\n";
  750. $htaccess_common_tpl .= '<b style="color:blue"># UNREAD POSTS</b>' . "\n";
  751. $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&amp;start=$2 [QSA,L,NC]' . "\n";
  752. $htaccess_common_tpl .= '<b style="color:blue"># THE TEAM</b>' . "\n";
  753. $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";
  754. $htaccess_common_tpl .= '<b style="color:blue"># HERE IS A GOOD PLACE TO ADD OTHER PHPBB RELATED REWRITERULES</b>' . "\n\n";
  755. if ($gym_installed) {
  756. $htaccess_common_tpl .= '<b style="color:blue">#####################################################' . "\n";
  757. // RSS
  758. $htaccess_common_tpl .= '# GYM Sitemaps &amp; RSS' . "\n";
  759. $htaccess_common_tpl .= '# Global channels</b>' . "\n";
  760. $htaccess_common_tpl .= $rss_commpat_note;
  761. $htaccess_common_tpl .= $rss_commpat_pre . ' ^{WIERD_SLASH}{RSS_LPATH}rss(/(news)+)?(/(digest)+)?(/(short|long)+)?/?$ {DEFAULT_SLASH}{RSS_RPATH}gymrss.{PHP_EX}?channels&amp;$2&amp;$4&amp;$6 [QSA,L,NC]' . $rss_commpat_post . "\n";
  762. // HTML
  763. $htaccess_common_tpl .= '<b style="color:blue"># HTML Global news &amp; maps</b>' . "\n";
  764. $htaccess_common_tpl .= $html_commpat_note;
  765. $htaccess_common_tpl .= $html_commpat_pre . ' ^{WIERD_SLASH}{HTML_LPATH}(news|maps){PAGE_PAGINATION}$ {DEFAULT_SLASH}{HTML_RPATH}map.{PHP_EX}?$1&amp;start=$3 [QSA,L,NC]' . $html_commpat_post . "\n";
  766. $htaccess_common_tpl .= '<b style="color:blue"># END GYM Sitemaps &amp; RSS' . "\n";
  767. $htaccess_common_tpl .= '#####################################################</b>' . "\n\n";
  768. }
  769. // We now handle all modes at once (simple / mixed / advanced)
  770. $htaccess_tpl .= '<b style="color:blue"># FORUM ALL MODES</b>' . "\n";
  771. $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&amp;start=$4 [QSA,L,NC]' . "\n";
  772. $htaccess_tpl .= '<b style="color:blue"># TOPIC WITH VIRTUAL FOLDER ALL MODES</b>' . "\n";
  773. $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&amp;t=$4&amp;start=$6 [QSA,L,NC]' . "\n";
  774. // Not needed any more
  775. // $htaccess_tpl .= '<b style="color:blue"># GLOBAL ANNOUNCEMENTS WITH VIRTUAL FOLDER ALL MODES</b>' . "\n";
  776. // $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&amp;start=$4 [QSA,L,NC]' . "\n";
  777. $htaccess_tpl .= '<b style="color:blue"># TOPIC WITHOUT FORUM ID &amp; DELIM ALL MODES</b>' . "\n";
  778. $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&amp;t=$3&amp;start=$5 [QSA,L,NC]' . "\n";
  779. $htaccess_tpl .= $htaccess_common_tpl;
  780. // mods .htaccess pos1
  781. if (!empty($mods_ht['pos1'])) {
  782. $htaccess_tpl .= $mods_ht['pos1'];
  783. }
  784. $htaccess_tpl .= '<b style="color:blue"># FORUM WITHOUT ID &amp; DELIM ALL MODES</b>' . "\n";
  785. if (trim($phpbb_seo->seo_ext['forum'],'/')) {
  786. $htaccess_tpl .= '<b style="color:blue"># THESE FOUR LINES MUST BE LOCATED AT THE END OF YOUR HTACCESS TO WORK PROPERLY</b>' . "\n";
  787. $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} !-f' . "\n";
  788. $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&amp;start=$3 [QSA,L,NC]' . "\n";
  789. $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} !-f' . "\n";
  790. $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";
  791. } else {
  792. $htaccess_tpl .= '<b style="color:blue"># THESE THREE LINES MUST BE LOCATED AT THE END OF YOUR HTACCESS TO WORK…

Large files files are truncated, but you can click here to view the full file