PageRenderTime 57ms CodeModel.GetById 18ms 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
  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 PROPERLY</b>' . "\n";
  793. $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} !-f' . "\n";
  794. $htaccess_tpl .= '<b style="color:green">RewriteCond</b> %{REQUEST_FILENAME} !-d' . "\n";
  795. $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&amp;start=$3 [QSA,L,NC]' . "\n";
  796. }
  797. // fix for dumb clients unable to deal with base href
  798. $htaccess_tpl .= '<b style="color:blue"># FIX RELATIVE PATHS : FILES</b>' . "\n";
  799. $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";
  800. $htaccess_tpl .= '<b style="color:blue"># FIX RELATIVE PATHS : IMAGES</b>' . "\n";
  801. $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";
  802. $htaccess_tpl .= '<b style="color:blue"># END PHPBB PAGES' . "\n";
  803. $htaccess_tpl .= '#####################################################</b>' . "\n\n";
  804. // mods .htaccess pos2
  805. if (!empty($mods_ht['pos2'])) {
  806. $htaccess_tpl .= $mods_ht['pos2'];
  807. }
  808. if ($gym_installed) {
  809. $htaccess_tpl .= '<b style="color:blue">#####################################################' . "\n";
  810. $htaccess_tpl .= '# GYM Sitemaps &amp; RSS</b>' . "\n";
  811. // HTML
  812. $htaccess_tpl .= '<b style="color:blue"># HTML Module additional modes</b>' . "\n";
  813. $htaccess_tpl .= $html_commpat_note;
  814. $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&amp;$1&amp;start=$6 [QSA,L,NC]' . $html_commpat_post . "\n";
  815. // RSS
  816. $htaccess_tpl .= '<b style="color:blue"># Main feeds &amp; channels</b>' . "\n";
  817. $htaccess_tpl .= $rss_commpat_note;
  818. $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&amp;$2&amp;$4&amp;$6&amp;gzip=$10 [QSA,L,NC]' . $rss_commpat_post . "\n";
  819. $htaccess_tpl .= '<b style="color:blue"># Module feeds</b>' . "\n";
  820. $htaccess_tpl .= $rss_commpat_note;
  821. $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&amp;$3&amp;$5&amp;$7&amp;gzip=$9 [QSA,L,NC]' . $rss_commpat_post . "\n";
  822. $htaccess_tpl .= '<b style="color:blue"># Module feeds without ids</b>' . "\n";
  823. $htaccess_tpl .= $rss_commpat_note;
  824. $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&amp;$3&amp;$5&amp;$7&amp;modulename=$8&amp;gzip=$9 [QSA,L,NC]' . $rss_commpat_post . "\n";
  825. // Google
  826. $htaccess_tpl .= '<b style="color:blue"># Google SitemapIndex</b>' . "\n";
  827. $htaccess_tpl .= $google_commpat_note;
  828. $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";
  829. $htaccess_tpl .= '<b style="color:blue"># Module cat sitemaps</b>' . "\n";
  830. $htaccess_tpl .= $google_commpat_note;
  831. $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&amp;module_sub=$2&amp;gzip=$3 [QSA,L,NC]' . $google_commpat_post . "\n";
  832. $htaccess_tpl .= '<b style="color:blue"># Module sitemaps</b>' . "\n";
  833. $htaccess_tpl .= $google_commpat_note;
  834. $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&amp;gzip=$3 [QSA,L,NC]' . $google_commpat_post . "\n";
  835. $htaccess_tpl .= '<b style="color:blue"># END GYM Sitemaps &amp; RSS' . "\n";
  836. $htaccess_tpl .= '#####################################################</b>' . "\n";
  837. }
  838. if (!empty($default_slash) && $this->new_config['more_options']) {
  839. $default_slash = '<b style="color:red">' . $default_slash . '</b>';
  840. }
  841. // The tpl array
  842. $htaccess_tpl_vars = array();
  843. // handle the suffixes proper in the RegEx
  844. // set up pagination reg ex
  845. // set up ext bits
  846. $seo_ext = array(
  847. // force '/' for both / and empty ext to add /? in RegEx (which allows both cases)
  848. 'pagination' => trim($phpbb_seo->seo_ext['pagination'], '/') ? str_replace('.', '\\.', $phpbb_seo->seo_ext['pagination']) : '/'
  849. );
  850. $reg_ex_page = sprintf($tpl['paginpage'], $phpbb_seo->seo_static['pagination'], $seo_ext['pagination'] . ($seo_ext['pagination'] === '/' ? '?' : '') );
  851. foreach ( $phpbb_seo->seo_ext as $type => $value) {
  852. $_value = trim($value, '/');
  853. // force '/' for both / and empty ext to add /? in RegEx (which allows both cases)
  854. $seo_ext[$type] = $_value ? str_replace('.', '\\.', $value) : '/';
  855. $htaccess_tpl_vars['{' . strtoupper($type) . '_PAGINATION}'] = $_value ? sprintf($tpl['pagin'], $phpbb_seo->seo_delim['start'], $seo_ext[$type]) : $reg_ex_page;
  856. // use url/? to allow both url and url/ to work as expected
  857. $htaccess_tpl_vars['{EXT_' . strtoupper($type) . '}'] = sprintf($tpl['ext'] , $seo_ext[$type]) . ($_value ? '' : '?');
  858. }
  859. $htaccess_tpl_vars['{PAGE_PAGINATION}'] = $reg_ex_page;
  860. // static bits
  861. foreach ( $phpbb_seo->seo_static as $type => $value) {
  862. if (!is_array($phpbb_seo->seo_static[$type])) {
  863. $htaccess_tpl_vars['{STATIC_' . strtoupper($type) . '}'] = sprintf($tpl['static'] , $phpbb_seo->seo_static[$type]);
  864. }
  865. }
  866. // delim bits
  867. foreach ( $phpbb_seo->seo_delim as $type => $value) {
  868. $htaccess_tpl_vars['{DELIM_' . strtoupper($type) . '}'] = sprintf($tpl['delim'] , $phpbb_seo->seo_delim[$type]);
  869. }
  870. // common .htaccess vars
  871. $htaccess_tpl_vars += array(
  872. '{REWRITEBASE}' => $rewritebase,
  873. '{PHP_EX}' => $phpEx,
  874. '{PHPBB_LPATH}' => ($this->new_config['rbase'] || $phpbb_seo->seo_opt['virtual_root']) ? '' : $phpbb_path,
  875. '{PHPBB_RPATH}' => $this->new_config['rbase'] ? '' : $phpbb_path,
  876. '{RSS_LPATH}' => $rss_path ? $rss_path . '/' : '',
  877. '{RSS_RPATH}' => $rss_path ? $rss_path . '/' : '',
  878. '{GOOGLE_LPATH}' => $google_path ? $google_path . '/' : '',
  879. '{GOOGLE_RPATH}' => $google_path ? $google_path . '/' : '',
  880. '{HTML_LPATH}' => $html_path ? $html_path . '/' : '',
  881. '{HTML_RPATH}' => $html_path ? $html_path . '/' : '',
  882. '{DEFAULT_SLASH}' => $default_slash,
  883. '{WIERD_SLASH}' => $wierd_slash,
  884. '{MOD_RTYPE}' => $modrtype[$modrtype['type']],
  885. );
  886. // Parse .htaccess
  887. $htaccess_code = str_replace(array_keys($htaccess_tpl_vars), array_values($htaccess_tpl_vars), $htaccess_tpl);
  888. } // else the .htaccess is already generated
  889. if ( $html ) { // HTML output
  890. $htaccess_output = "\n" . '<script type="text/javascript">' . "\n";
  891. $htaccess_output .= '// <![CDATA[' . "\n";
  892. $htaccess_output .= 'function selectCode(a) {' . "\n";
  893. $htaccess_output .= "\t" . 'var e = a.parentNode.parentNode.getElementsByTagName(\'CODE\')[0]; // Get ID of code block' . "\n";
  894. $htaccess_output .= "\t" . 'if (window.getSelection) { // Not IE' . "\n";
  895. $htaccess_output .= "\t\t" . 'var s = window.getSelection();' . "\n";
  896. $htaccess_output .= "\t\t" . 'if (s.setBaseAndExtent) { // Safari' . "\n";
  897. $htaccess_output .= "\t\t\t" . 's.setBaseAndExtent(e, 0, e, e.innerText.length - 1);' . "\n";
  898. $htaccess_output .= "\t\t" . '} else { // Firefox and Opera' . "\n";
  899. $htaccess_output .= "\t\t\t" . 'var r = document.createRange();' . "\n";
  900. $htaccess_output .= "\t\t\t" . 'r.selectNodeContents(e);' . "\n";
  901. $htaccess_output .= "\t\t\t" . 's.removeAllRanges();' . "\n";
  902. $htaccess_output .= "\t\t\t" . 's.addRange(r);' . "\n";
  903. $htaccess_output .= "\t\t" . '}' . "\n";
  904. $htaccess_output .= "\t" . '} else if (document.getSelection) { // Some older browsers' . "\n";
  905. $htaccess_output .= "\t\t" . 'var s = document.getSelection();' . "\n";
  906. $htaccess_output .= "\t\t" . 'var r = document.createRange();' . "\n";
  907. $htaccess_output .= "\t\t" . 'r.selectNodeContents(e);' . "\n";
  908. $htaccess_output .= "\t\t" . 's.removeAllRanges();' . "\n";
  909. $htaccess_output .= "\t\t" . 's.addRange(r);' . "\n";
  910. $htaccess_output .= "\t" . '} else if (document.selection) { // IE' . "\n";
  911. $htaccess_output .= "\t\t" . 'var r = document.body.createTextRange();' . "\n";
  912. $htaccess_output .= "\t\t" . 'r.moveToElementText(e);' . "\n";
  913. $htaccess_output .= "\t\t" . 'r.select();' . "\n";
  914. $htaccess_output .= "\t" . '}' . "\n";
  915. $htaccess_output .= '}' . "\n";
  916. $htaccess_output .= '// ]]>' . "\n";
  917. $htaccess_output .= '</script>' . "\n";
  918. // build location message
  919. if ($show_rewritebase_opt && $this->new_config['rbase']) {
  920. $msg_loc = sprintf($user->lang['SEO_HTACCESS_FOLDER_MSG'], '<em style="color:#000">' . $phpbb_seo->seo_path['phpbb_url'] . '</em>');
  921. } else {
  922. $msg_loc = sprintf($user->lang['SEO_HTACCESS_ROOT_MSG'], '<em style="color:#000">' . $phpbb_seo->seo_path['root_url'] . '</em>');
  923. }
  924. $htaccess_output .= '</p><div class="content"><hr/>' . "\n" . '<b style="color:red">&rArr;&nbsp;' . $msg_loc . '</b><br/><br/><hr/>' . "\n";
  925. $htaccess_output .= '<b>.htaccess :&nbsp;<a href="#" onclick="dE(\'htaccess_code\',1); return false;">' . $user->lang['SEO_SHOW'] . '</a>&nbsp;/&nbsp;<a href="#" onclick="dE(\'htaccess_code\',-1); return false;">' . $user->lang['SEO_HIDE'] . '</a></b>' . "\n";
  926. $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;">&nbsp;<a href="#" onclick="selectCode(this); return false;">' . $user->lang['SEO_SELECT_ALL'] . '</a></dt>' . "\n";
  927. $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";
  928. $htaccess_output .= '</dl>' . "\n";
  929. $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";
  930. $htaccess_output .= '<li style="color:blue">&nbsp;' . $user->lang['SEO_HTACCESS_CAPTION_COMMENT'] . '</li>' . "\n";
  931. $htaccess_output .= '<li style="color:#A020F0">&nbsp;' . $user->lang['SEO_HTACCESS_CAPTION_STATIC'] . '</li>' . "\n";
  932. $htaccess_output .= '<li style="color:#6A5ACD">&nbsp;' . $user->lang['SEO_HTACCESS_CAPTION_SUFFIX'] . '</li>' . "\n";
  933. $htaccess_output .= '<li style="color:#FF00FF">&nbsp;' . $user->lang['SEO_HTACCESS_CAPTION_DELIM'] . '</li>' . "\n";
  934. if ($this->new_config['more_options']) {
  935. $htaccess_output .= '<li style="color:red">&nbsp;' . $user->lang['SEO_HTACCESS_CAPTION_SLASH'] . '</li>&nbsp;' . "\n";
  936. }
  937. $htaccess_output .= '</ul></div>' . "\n" . '</div></div><p>' . "\n";
  938. } else { // File output
  939. $htaccess_output = str_replace(array('&lt;', '&gt;', '&amp;'), array('<', '>', '&'), strip_tags($htaccess_code));
  940. }
  941. return $htaccess_output;
  942. }
  943. /**
  944. * get_mods_ht Get all mods htaccess tpls
  945. */
  946. function get_mods_ht() {
  947. global $phpEx, $config, $phpbb_root_path, $phpbb_seo;
  948. $all_ht_tpl = array('pos1' => '', 'pos2' => '');
  949. $path = $phpbb_root_path . 'phpbb_seo/includes/htmods';
  950. if (!($dir = @opendir($path))) {
  951. return false;
  952. }
  953. while( ($file = @readdir($dir)) !== false ) {
  954. if (!trim($file, '. ')) {
  955. continue;
  956. }
  957. if(preg_match('`^ht_([a-z0-9_-]+)\.' . $phpEx . '$`i', $file, $match)) {
  958. $mode = $match[1];
  959. $class = 'ht_' . $mode;
  960. require_once("$path/$file");
  961. $module = new $class();
  962. if ($tpl = $module->get_tpl()) {
  963. if (!empty($tpl['pos1'])) {
  964. $all_ht_tpl['pos1'] .= $tpl['pos1'] . "\n";
  965. }
  966. if (!empty($tpl['pos2'])) {
  967. $all_ht_tpl['pos2'] .= $tpl['pos2'] . "\n";
  968. }
  969. }
  970. }
  971. }
  972. return !empty($all_ht_tpl['pos1']) || !empty($all_ht_tpl['pos2']) ? $all_ht_tpl : false;
  973. }
  974. /**
  975. * set_phpbb_seo_links Builds links to support threads
  976. */
  977. function set_phpbb_seo_links() {
  978. global $user, $phpbb_seo, $config;
  979. $modrtype_lang = array();
  980. $phpbb_seo->version = htmlspecialchars($phpbb_seo->version);
  981. $phpbb_seo->modrtype = intval($phpbb_seo->modrtype);
  982. if ($phpbb_seo->modrtype < 1 || $phpbb_seo->modrtype > 3) {
  983. $phpbb_seo->modrtype = 1;
  984. }
  985. $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']);
  986. $modrtype_lang['title'] = $modrtype_lang['titles'][$phpbb_seo->modrtype];
  987. $modrtype_lang['utitle'] = $modrtype_lang['titles']['u'];
  988. $modrtype_lang['types'] = array( 1 => 'SIMPLE', 2 => 'MIXED', 1 => 'SIMPLE', 3 => 'ADVANCED');
  989. $modrtype_lang['type'] = $modrtype_lang['types'][$phpbb_seo->modrtype];
  990. $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' );
  991. $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' );
  992. $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/' );
  993. $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/' );
  994. if (strpos($config['default_lang'], 'fr') !== false ) {
  995. $modrtype_lang['linkurl'] = $modrtype_lang['modrlinks_fr'][$phpbb_seo->modrtype];
  996. $modrtype_lang['forumlinkurl'] = $modrtype_lang['modrforumlinks_fr'][$phpbb_seo->modrtype];
  997. $modrtype_lang['ulinkurl'] = $modrtype_lang['modrlinks_fr']['u'];
  998. $modrtype_lang['uforumlinkurl'] = $modrtype_lang['modrforumlinks_fr']['u'];
  999. } else {
  1000. $modrtype_lang['linkurl'] = $modrtype_lang['modrlinks_en'][$phpbb_seo->modrtype];
  1001. $modrtype_lang['forumlinkurl'] = $modrtype_lang['modrforumlinks_en'][$phpbb_seo->modrtype];
  1002. $modrtype_lang['ulinkurl'] = $modrtype_lang['modrlinks_en']['u'];
  1003. $modrtype_lang['uforumlinkurl'] = $modrtype_lang['modrforumlinks_en']['u'];
  1004. }
  1005. $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>';
  1006. $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>';
  1007. $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>';
  1008. $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>';
  1009. return $modrtype_lang;
  1010. }
  1011. /**
  1012. * check_cache_folder Validates the cache folder status
  1013. */
  1014. function check_cache_folder($cache_dir, $msg = true) {
  1015. global $user, $phpEx;
  1016. $exists = $write = $inner_write = false;
  1017. $cache_msg = '';
  1018. if (file_exists($cache_dir) && is_dir($cache_dir)) {
  1019. $exists = true;
  1020. if (!is_writeable($cache_dir)) {
  1021. phpbb_chmod($cache_dir, CHMOD_READ | CHMOD_WRITE);
  1022. $fp = @fopen($cache_dir . 'test_lock', 'wb');
  1023. if ($fp !== false) {
  1024. $write = true;
  1025. }
  1026. @fclose($fp);
  1027. @unlink($phpbb_root_path . $dir . 'test_lock');
  1028. } else {
  1029. $write = true;
  1030. }
  1031. // check if the config cache file is here already and writeable
  1032. $check = $cache_dir . "phpbb_cache.$phpEx";
  1033. $checks = array("$check.old", "$check.current", "$cache_dir.htaccess", "$cache_dir.htaccess.old", "$cache_dir.htaccess.current");
  1034. // let's check all files
  1035. $inner_write = true;
  1036. foreach($checks as $check) {
  1037. if (file_exists($check)) {
  1038. if (!is_writeable($check)) {
  1039. $inner_write = false;
  1040. phpbb_chmod($check, CHMOD_READ | CHMOD_WRITE);
  1041. $fp = @fopen($check, 'wb');
  1042. if ($fp !== false) {
  1043. $inner_write = true;
  1044. }
  1045. @fclose($fp);
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if ($msg) {
  1051. $exists = ($exists) ? '<b style="color:green">' . $user->lang['SEO_CACHE_FOUND'] . '</b>' : '<b style="color:red">' . $user->lang['SEO_CACHE_NOT_FOUND'] . '</b>';
  1052. $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>' : '');
  1053. $inner_write = $inner_write ? '' : '<br/> <b style="color:red">' . $user->lang['SEO_CACHE_INNER_UNWRITABLE'] . '</b>';
  1054. $cache_msg = sprintf($user->lang['SEO_CACHE_STATUS'], $cache_dir) . '<br/>' . $exists . $write . $inner_write;
  1055. return '<br/><b>' . $user->lang['SEO_CACHE_FILE_TITLE'] . ':</b><br/>' . $cache_msg . '<br/><br/>';
  1056. } else {
  1057. return ($exists && $write);
  1058. }
  1059. }
  1060. /**
  1061. * write_cache( ) will write the cached file and keep backups.
  1062. */
  1063. function write_cache( $type = 'forum' ) {
  1064. global $phpbb_seo;
  1065. 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'])) {
  1066. return FALSE;
  1067. }
  1068. $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";
  1069. if ($type == 'forum') { // Add the phpbb_seo_config
  1070. $update = '$this->cache_config[\'settings\'] = ' . preg_replace('`[\s]+`', ' ', var_export($phpbb_seo->cache_config['settings'], true)) . ';'. "\n";
  1071. $update .= '$this->cache_config[\'forum\'] = ' . preg_replace('`[\s]+`', ' ', var_export($phpbb_seo->cache_config['forum'], true)) . ';'. "\n";
  1072. $update = $cache_tpl . $update . '?'.'>';
  1073. } elseif ($type == 'htaccess') { // .htaccess case
  1074. $update = $this->seo_htaccess(false);
  1075. } else { // Allow additional types
  1076. $update = '$this->cache_config[\'' . $type . '\'] = ' . preg_replace('`[\s]+`', ' ', var_export($phpbb_seo->cache_config[$type], true)) . ';'. "\n";
  1077. $update = $cache_tpl . $update . '?'.'>';
  1078. }
  1079. $file = SEO_CACHE_PATH . $phpbb_seo->cache_config['files'][$type];
  1080. // Keep a backup of the previous settings
  1081. @copy($file, $file . '.old');
  1082. $handle = @fopen($file, 'wb');
  1083. @fputs($handle, $update);
  1084. @fclose ($handle);
  1085. unset($update);
  1086. @umask(0000);
  1087. phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);
  1088. // Keep a backup of the current settings
  1089. @copy($file, $file . '.current');
  1090. return true;
  1091. }
  1092. /**
  1093. * select_multiple($value, $key, $select_ary)
  1094. */
  1095. function select_multiple($value, $key, $select_ary) {
  1096. $size = min(12,count($select_ary));
  1097. $html = '<select multiple="multiple" id="' . $key . '" name="multiple_' . $key . '[]" size="' . $size . '">';
  1098. foreach ($select_ary as $sel_key => $sel_data) {
  1099. if (empty($sel_data['disabled'])) {
  1100. $selected = array_search($sel_key, @$this->new_config[$key]) !== false ? 'selected="selected"' : '';
  1101. $disabled = '';
  1102. } else {
  1103. $disabled = 'disabled="disabled" class="disabled-option"';
  1104. $selected = '';
  1105. }
  1106. $sel_title = $sel_data['title'];
  1107. $html .= "<option value=\"$sel_key\" $disabled $selected>$sel_title</option>";
  1108. }
  1109. return $html . '</select>';
  1110. }
  1111. /**
  1112. * forum_select() // custom forum select setup
  1113. */
  1114. function forum_select($ignore_acl = true, $ignore_nonpost = false, $ignore_emptycat = false, $only_acl_post = false) {
  1115. $select_ary = make_forum_select(false, false, $ignore_acl, $ignore_nonpost, $ignore_emptycat, $only_acl_post, true);
  1116. foreach($select_ary as $f_id => $f_data) {
  1117. $select_ary[$f_id] = array(
  1118. 'title' => $f_data['padding'] . $f_data['forum_name'],
  1119. 'disabled' => $f_data['disabled'],
  1120. );
  1121. }
  1122. return $select_ary;
  1123. }
  1124. /**
  1125. * Pick a language, any language ... or no language
  1126. */
  1127. function language_select($default = '') {
  1128. global $user;
  1129. return '<option value="">' . $user->lang['DISABLED'] . '</option>' . language_select($default);
  1130. }
  1131. } // End of acp class
  1132. ?>