PageRenderTime 70ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/forum/includes/acp/acp_gym_sitemaps.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 1255 lines | 1011 code | 12 blank | 232 comment | 251 complexity | ae6f1432862e92c8839b328e02c35ee7 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 phpBB SEO GYM Sitemaps
  5. * @version $Id: acp_gym_sitemaps.php 272 2010-11-21 13:56:31Z dcz $
  6. * @copyright (c) 2006 - 2010 www.phpbb-seo.com
  7. * @license http://opensource.org/osi3.0/licenses/lgpl-license.php GNU Lesser General Public License
  8. *
  9. */
  10. /**
  11. * phpBB_SEO Class
  12. * www.phpBB-SEO.com
  13. * @package Advanced phpBB3 SEO mod Rewrite
  14. */
  15. class acp_gym_sitemaps {
  16. var $u_action;
  17. var $new_config = array();
  18. var $dyn_select = array();
  19. var $gym_config = array();
  20. var $gym_modules = array();
  21. var $gym_modules_acp = array();
  22. var $mode = 'gym';
  23. var $modes = array();
  24. var $module = 'gym';
  25. var $action = 'main';
  26. var $maction = '';
  27. var $support_link = array();
  28. var $override = array();
  29. var $override_type = array();
  30. var $array_type_cfg = array();
  31. var $multiple_options = array();
  32. var $modrtype_lang = array();
  33. var $write_type = 'forum';
  34. var $lengh_limit = 20;
  35. var $word_limit = 3;
  36. var $seo_unset_opts = array();
  37. /**
  38. * Constructor
  39. */
  40. function main($id, $mode) {
  41. global $config, $db, $user, $auth, $template, $cache;
  42. global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $phpbb_seo, $_action_types;
  43. require_once($phpbb_root_path . 'gym_sitemaps/includes/gym_common.' . $phpEx);
  44. // Start the phpbb_seo class
  45. if ( !is_object($phpbb_seo) ) {
  46. if ( file_exists($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.' . $phpEx)) {
  47. require_once($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.' . $phpEx);
  48. } else {
  49. require_once($phpbb_root_path . 'gym_sitemaps/includes/phpbb_seo_class_light.' . $phpEx);
  50. }
  51. $phpbb_seo = new phpbb_seo();
  52. }
  53. $user->add_lang('gym_sitemaps/acp/gym_common');
  54. // action=(module|cache|modrewrite...)&amp;module=(main|forum| ...)
  55. $action = request_var('action', 'main');
  56. $module = request_var('module', 'main');
  57. // maction =(settings|maintenance|save)&amp;action=(module|cache|modrewrite...)&amp;module=(main|forum| ...)
  58. $maction = request_var('maction', '');
  59. $mactions = array('settings', 'maintenance', 'install');
  60. $maction = in_array($maction, $mactions) ? $maction : '';
  61. $submit = (isset($_POST['submit'])) ? true : false;
  62. $this->modes = $_action_types;
  63. $this->override_type = $_override_types;
  64. $this->override = array();
  65. // Filter allowed modes
  66. $this->mode = $mode;
  67. $this->module = $module;
  68. $this->action = $action;
  69. $this->maction = $maction;
  70. $this->set_phpbb_seo_links();
  71. // Get gym config
  72. obtain_gym_config('main', $this->gym_config);
  73. $this->new_config = $this->gym_config;
  74. // define common validation arrays
  75. $this->dyn_select['modrtype'] = array( 0 => 'GYM_MODREWRITE_NONE', 1 => 'GYM_MODREWRITE_SIMPLE', 2 => 'GYM_MODREWRITE_MIXED', 3 => 'GYM_MODREWRITE_ADVANCED');
  76. $this->dyn_select['gzip_level'] = array( 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9);
  77. $this->dyn_select['sort'] = array( 'DESC' => 'GYM_DESC', 'ASC' => 'GYM_ASC');
  78. $this->dyn_select['override'] = array( OVERRIDE_GLOBAL => 'GYM_OVERRIDE_GLOBAL', OVERRIDE_OTYPE => 'GYM_OVERRIDE_OTYPE', OVERRIDE_MODULE => 'GYM_OVERRIDE_MODULE');
  79. $this->dyn_select['sumarize_method'] = array( 'chars' => 'GYM_METHOD_CHARS', 'words' => 'GYM_METHOD_WORDS', 'lines' => 'GYM_METHOD_LINES');
  80. $this->dyn_select['gym_auth'] = array(
  81. 'admin' => 'GYM_AUTH_ADMIN',
  82. 'globalmod' => 'GYM_AUTH_GLOBALMOD',
  83. 'reg' => 'GYM_AUTH_REG',
  84. 'guest' => 'GYM_AUTH_GUEST',
  85. 'all' => 'GYM_AUTH_ALL',
  86. 'none' => 'GYM_AUTH_NONE',
  87. );
  88. $this->dyn_select['rss_linking_types'] = array('n' => 'RSS_LINKING_NEWS', 'nd' => 'RSS_LINKING_NEWS_DIGEST', 'r' => 'RSS_LINKING_REGULAR', 'rd' => 'RSS_LINKING_REGULAR_DIGEST');
  89. // Get the module list
  90. // Populate the $this->gym_modules[$mode][$module] array
  91. $this->gym_get_modules($mode);
  92. // Load the relevant modules acp options
  93. // Populate the $this->gym_modules_acp[$mode][$module] array
  94. $this->gym_module_acp($mode, $module);
  95. // Acp options array for this case
  96. $display_vars = $error = array();
  97. // salt the form
  98. $form_key = 'acp_gym';
  99. add_form_key($form_key);
  100. // check form salt
  101. if ($submit && !check_form_key($form_key)) {
  102. $error[] = $user->lang['FORM_INVALID'];
  103. $submit = false;
  104. }
  105. // Cache management
  106. if ($maction === 'maintenance') {
  107. $display_vars = $this->gym_maintenance( $mode, $module, $action, $submit );
  108. $submit = false;
  109. } elseif ($maction === 'settings') { // settings management
  110. $display_vars = $this->gym_set_default( $mode, $module, $action, $submit );
  111. $submit = false;
  112. } elseif ($maction === 'install') { // module install
  113. $display_vars = $this->gym_install( $mode, $module, $action, $submit );
  114. $submit = false;
  115. } else {
  116. if ( !in_array($mode, $this->modes) || !in_array($module, $this->gym_modules[$mode])) {
  117. trigger_error('NO_MODE', E_USER_ERROR);
  118. } else {
  119. $script_to_check = array();
  120. if (empty($this->gym_modules_acp[$mode][$module][$action]['display_vars'])) {
  121. $action = $this->action = 'main';
  122. }
  123. // here we'll check if the GYM script urls are consistent
  124. if (!$submit) {
  125. $this->check_scripts($error, $this->gym_config, $mode);
  126. }
  127. $display_vars = $this->gym_modules_acp[$mode][$module][$action]['display_vars'];
  128. // Check if we do not have a new module needing a new config key
  129. $clear_cache = false;
  130. foreach ($display_vars['vars'] as $key => $value) {
  131. if (!isset($this->gym_config[$key]) && strpos($key, 'legend') === false) {
  132. $clear_cache = true;
  133. if(isset($this->gym_modules_acp[$mode][$module][$action]['default'][$key])) {
  134. $this->new_config[$key] = $this->gym_modules_acp[$mode][$module][$action]['default'][$key];
  135. set_gym_config($key, $this->new_config[$key], $mode, $this->gym_config);
  136. }
  137. }
  138. }
  139. if ($clear_cache) {
  140. $this->remove_cache('config');
  141. }
  142. }
  143. }
  144. // Load the module's language files
  145. foreach ($this->gym_modules_acp[$mode] as $active_modules => $null) {
  146. if (!empty($this->gym_modules_acp[$mode][$active_modules]['info']['lang_file'])) {
  147. $user->add_lang('gym_sitemaps/acp/' . $this->gym_modules_acp[$mode][$active_modules]['info']['lang_file']);
  148. }
  149. }
  150. $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config;
  151. // We validate the complete config if whished
  152. validate_config_vars($display_vars['vars'], $cfg_array, $error);
  153. // check script urls if necessary
  154. if ($submit && isset($cfg_array[$mode . '_url'])) {
  155. // will enforce trailing slashes automatically
  156. $this->check_scripts($error, $cfg_array, $mode);
  157. }
  158. // Do not write values if there is an error
  159. if (sizeof($error)) {
  160. $submit = false;
  161. }
  162. // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
  163. foreach ($display_vars['vars'] as $config_name => $cfg_setup) {
  164. if ( (!isset($cfg_array[$config_name]) && @$cfg_setup['method'] != 'select_multiple_string') || strpos($config_name, 'legend') !== false) {
  165. continue;
  166. }
  167. // Handle multiple select options
  168. if (!empty($cfg_setup['method']) && $cfg_setup['method'] == 'select_multiple_string') {
  169. if (isset($_POST['multiple_' . $config_name])) {
  170. $m_values = utf8_normalize_nfc(request_var('multiple_' . $config_name, array('' => '')));
  171. $validate_int = $cfg_setup['multiple_validate'] == 'int' ? true : false;
  172. foreach($m_values as $k => $v) {
  173. if ($validate_int) {
  174. $v = (int) $v;
  175. }
  176. if (empty($v)) {
  177. unset($m_values[$k]);
  178. } else {
  179. $m_values[$k] = $v;
  180. }
  181. }
  182. sort($m_values);
  183. $this->new_config[$config_name] = $m_values;
  184. $config_value = implode(',', $m_values);
  185. if ( strlen($config_value) > 255 ) {
  186. $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$cfg_setup['lang']], 255);
  187. }
  188. $submit = empty($error);
  189. } else {
  190. if ($submit) {
  191. $this->new_config[$config_name] = array();
  192. $config_value = '';
  193. } else {
  194. $config_value = $this->new_config[$config_name];
  195. $this->new_config[$config_name] = !empty($config_value) ? explode(',', $config_value) : array();
  196. }
  197. }
  198. } else {
  199. $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
  200. }
  201. if ($submit) {
  202. set_gym_config($config_name, $config_value, $mode, $this->gym_config);
  203. }
  204. }
  205. if ($submit) {
  206. $this->remove_cache('config');
  207. add_log('admin', 'GYM_LOG_CONFIG_' . strtoupper($mode));
  208. trigger_error($user->lang['CONFIG_UPDATED'] . $this->back_to_prev());
  209. }
  210. $this->tpl_name = 'acp_gym_sitemaps';
  211. $this->page_title = $display_vars['title'];
  212. // add the maitenance links
  213. $maintenance_links = '';
  214. $maintenance_links .= '<a href="' . $this->u_action . '&amp;maction=maintenance&amp;action=' . $action . '&amp;module=' . $module . '"><b style="color:red;">' . $user->lang['GYM_MAINTENANCE'] . '</b></a><b> &bull; </b>';
  215. $maintenance_links .= '<a href="' . $this->u_action . '&amp;maction=settings&amp;action=' . $action . '&amp;module=' . $module . '"><b style="color:red;">' . $user->lang['GYM_SETTINGS'] . '</b></a>';
  216. $install_link = ($mode !== 'main') ? '<b> &bull; </b><a href="' . $this->u_action . '&amp;maction=install&amp;action=' . $action . '&amp;module=' . $module . '"><b style="color:red;">' . $user->lang['GYM_INSTALL'] . '</b></a>' : '';
  217. if ($action === 'gzip') {
  218. // Adjust language variable a bit
  219. $user->lang['GYM_GZIP_EXPLAIN'] = sprintf( $user->lang['GYM_GZIP_EXPLAIN'], ($config['gzip_compress'] ? $user->lang['GYM_GZIP_FORCED'] : $user->lang['GYM_GZIP_CONFIGURABLE']) );
  220. }
  221. $lang_key = 'GYM_' . strtoupper($mode);
  222. $l_mode_title = $this->safe_lang($lang_key);
  223. $l_mode_title_explain = $this->safe_lang($lang_key . '_EXPLAIN');
  224. $lang_key = $this->gym_modules_acp[$mode][$module]['info']['title_lang'];
  225. $l_module_title = $this->safe_lang($lang_key);
  226. $l_module_title_explain = $this->safe_lang($lang_key . '_EXPLAIN');
  227. $l_title = $this->safe_lang($display_vars['title']);
  228. $l_title_explain = $this->safe_lang($display_vars['title'] . '_EXPLAIN');
  229. $l_title_explain .= ($action === 'cache' && $mode !== 'html') ? $this->check_cache_folder($phpbb_root_path . 'gym_sitemaps/cache') : '';
  230. $template->assign_vars(array(
  231. 'L_MODE_TITLE' => $l_mode_title,
  232. 'L_MODE_ITLE_EXPLAIN' => $l_mode_title_explain,
  233. 'L_MODULE_TITLE' => $l_module_title,
  234. 'L_MODULE_ITLE_EXPLAIN' => $l_module_title_explain,
  235. 'L_TITLE' => $l_title,
  236. 'L_TITLE_EXPLAIN' => $l_title_explain,
  237. 'GYM_VERSION' => $this->gym_config['gym_version'],
  238. 'INSTALL_LINK' => $install_link,
  239. 'MAINTENANCE_LINKS' => $maintenance_links,
  240. 'S_ERROR' => (sizeof($error)) ? true : false,
  241. 'ERROR_MSG' => implode('<br />', $error),
  242. 'S_SUBMIT_BUTTON' => !empty($this->gym_modules_acp[$mode][$module][$action]['default']),
  243. 'U_ACTION' => $this->u_action . '&amp;maction=' . $maction . '&amp;action=' . $action . '&amp;module=' . $module)
  244. );
  245. $this->gym_module_menu( $mode, $module, $action );
  246. $this->gym_menu( $mode, $module, $action );
  247. // Output relevant page
  248. foreach ($display_vars['vars'] as $config_key => $vars) {
  249. if (!is_array($vars) && strpos($config_key, 'legend') === false) {
  250. continue;
  251. }
  252. if (strpos($config_key, 'legend') !== false) {
  253. $template->assign_block_vars('options', array(
  254. 'S_LEGEND' => true,
  255. 'LEGEND' => $this->safe_lang($vars))
  256. );
  257. continue;
  258. }
  259. $type = explode(':', $vars['type']);
  260. $l_explain = '';
  261. if ($vars['explain'] && isset($vars['lang_explain'])) {
  262. $l_explain = $this->safe_lang($vars['lang_explain']);
  263. } elseif ($vars['explain']) {
  264. $l_explain = $this->safe_lang($vars['lang'] . '_EXPLAIN');
  265. }
  266. // Add overriding infos
  267. $form = true;
  268. if (isset($vars['overriding']) && $vars['overriding']) {
  269. $vars['append'] = $this->is_overriden($mode, $module, $action, $config_key, $vars);
  270. //$form = $vars['append'] == $this->safe_lang('GYM_COULD_OVERRIDE') ? true : false;
  271. }
  272. $content = '';
  273. $template->assign_block_vars('options', array(
  274. 'KEY' => $config_key,
  275. 'TITLE' => $this->safe_lang($vars['lang']),
  276. 'S_EXPLAIN' => $vars['explain'],
  277. 'TITLE_EXPLAIN' => $l_explain,
  278. 'CONTENT' => $form ? build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars) : $vars['append'],
  279. )
  280. );
  281. unset($display_vars['vars'][$config_key]);
  282. }
  283. }
  284. /**
  285. * gym_get_modules($mode).
  286. * Populates $this->gym_modules[$mode][$module]
  287. * with the acp modules list
  288. */
  289. function gym_get_modules($mode) {
  290. global $cache, $phpEx, $phpbb_root_path;
  291. if (($this->gym_modules[$mode] = $cache->get('_gym_modules_' . $mode)) === false) {
  292. $this->gym_modules[$mode] = array();
  293. $dir = @opendir( $phpbb_root_path . 'gym_sitemaps/acp' );
  294. while( ($file = @readdir($dir)) !== FALSE ) {
  295. if(preg_match('`^' . $mode . '_([a-z0-9_-]+)\.' . $phpEx . '$`i', $file, $matches)) {
  296. $module = trim(str_replace( $mode . '_', '' , str_replace('.' . $phpEx , '' ,$file)), "/");
  297. if ($matches[1] == 'main' || (file_exists($phpbb_root_path . 'gym_sitemaps/modules/' . $file) && !empty($this->gym_config[$mode . '_' . $module . '_installed'])) ) {
  298. $this->gym_modules[$mode][$module] = $module;
  299. }
  300. }
  301. }
  302. @closedir($dir);
  303. // Reorder a bit, put the main panel at the first position, others will keep
  304. // the file system sorting
  305. if (!empty($this->gym_modules[$mode]['main'])) {
  306. $main = $this->gym_modules[$mode]['main'];
  307. unset($this->gym_modules[$mode]['main']);
  308. $this->gym_modules[$mode] = array('main' => $main) + $this->gym_modules[$mode];
  309. }
  310. $cache->put('_gym_modules_' . $mode, $this->gym_modules[$mode]);
  311. }
  312. if (!is_array($this->gym_modules[$mode]) || empty($this->gym_modules[$mode])) {
  313. $this->remove_cache('acp', $mode);
  314. }
  315. }
  316. /**
  317. * gym_module_acp($mode, $module)
  318. * loads acp module options in the $this->gym_modules_acp[$mode][$mode_module] array.
  319. */
  320. function gym_module_acp($mode, $module) {
  321. global $phpbb_root_path, $phpEx, $cache;
  322. if (is_array($this->gym_modules[$mode]) && ($this->gym_modules_acp[$mode] = $cache->get('_gym_acp_' . $mode)) === false) {
  323. foreach ($this->gym_modules[$mode] as $mode_module) {
  324. $this->gym_pick_module($mode, $mode_module, $this->gym_modules_acp);
  325. }
  326. $cache->put('_gym_acp_' . $mode, $this->gym_modules_acp[$mode]);
  327. }
  328. if (!@is_array($this->gym_modules_acp[$mode]) || empty($this->gym_modules_acp[$mode])) {
  329. $this->remove_cache('acp', $mode);
  330. }
  331. }
  332. /**
  333. * gym_pick_module( $mode, $module, $action)
  334. * pick a given module data
  335. */
  336. function gym_pick_module( $mode, $mode_module, &$return_array) {
  337. global $phpbb_root_path, $phpEx;
  338. $module_class = $mode . '_' . $mode_module;
  339. $module_file = $phpbb_root_path . 'gym_sitemaps/acp/' . $module_class . '.' . $phpEx;
  340. if ( file_exists($module_file) ) {
  341. include_once($module_file);
  342. if (class_exists($module_class)) {
  343. $gym_module = new $module_class($this);
  344. if ( method_exists($gym_module, 'acp_module')) {
  345. $return_array[$mode][$mode_module] = $gym_module->acp_module();
  346. }
  347. }
  348. }
  349. }
  350. /**
  351. * gym_menu( $mode, $module, $action)
  352. * Builds the module action links
  353. */
  354. function gym_menu( $mode, $module, $action) {
  355. global $template, $user;
  356. foreach ($this->gym_modules_acp[$mode][$module]['info']['actions'] as $module_action) {
  357. $template->assign_block_vars('menu', array(
  358. 'L_TITLE' => $this->safe_lang($this->gym_modules_acp[$mode][$module][$module_action]['display_vars']['title']),
  359. 'S_SELECTED' => $action == $module_action ? true : false,
  360. 'U_TITLE' => $this->u_action . '&amp;action=' . $module_action . '&amp;module=' . $module,
  361. ));
  362. }
  363. $template->assign_vars(array('S_MENU' => empty($this->maction)));
  364. return;
  365. }
  366. /**
  367. * gym_module_menu( $mode, $module, $action)
  368. * builds the module ACP links
  369. */
  370. function gym_module_menu( $mode, $module, $action ) {
  371. global $template, $user;
  372. foreach ($this->gym_modules_acp[$mode] as $modules) {
  373. $template->assign_block_vars('menu_module', array(
  374. 'L_TITLE' => $this->safe_lang($modules['info']['title_lang']),
  375. 'S_SELECTED' => ($module == @$modules['info']['module'] && $this->maction !== 'install') ? true : false,
  376. 'U_TITLE' => $this->u_action . '&amp;module=' . @$modules['info']['module'] . (!empty($action) ? "&amp;action=$action" : ''),
  377. ));
  378. }
  379. $template->assign_vars(array('S_MENU' => true));
  380. $template->assign_vars(array('S_MENU_MODULE' => true));
  381. return;
  382. }
  383. /**
  384. * gym_install( $mode, $module, $action, $submit = false )
  385. * handle module install / un-install
  386. */
  387. function gym_install( $mode, $module, $action, $submit = false ) {
  388. global $user, $phpEx, $phpbb_root_path;
  389. $post_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : array();
  390. if ($submit) {
  391. $un_install = $install = array();
  392. foreach ($this->gym_modules[$mode] as $_module) { // check if we need to uninstall
  393. $type_module = $mode . '_' . $_module;
  394. if (isset($post_array[$type_module]) && !$post_array[$type_module] && !empty($this->gym_config[$type_module . '_installed'])) { // Uninstall
  395. $un_install[$mode][$_module] = $type_module;
  396. }
  397. }
  398. $dir = @opendir( $phpbb_root_path . 'gym_sitemaps/acp' );
  399. while( ($file = @readdir($dir)) !== false ) { // check if we need to install
  400. if(preg_match('`^' . $mode . '_([a-z0-9_-]+)\.' . $phpEx . '$`i', $file, $matches)) {
  401. $type_module = trim(str_replace('.' . $phpEx , '' ,$file), "/");
  402. $_module = str_replace($mode . '_', '', $type_module);
  403. if ($matches[1] !== 'main' && file_exists($phpbb_root_path . 'gym_sitemaps/modules/' . $file) && !isset($this->gym_modules[$mode][$_module]) && !empty($post_array[$type_module])) {
  404. $install[$mode][$_module] = $type_module;
  405. }
  406. }
  407. }
  408. // Now un-install
  409. if (!empty($un_install)) {
  410. foreach ($un_install[$mode] as $_module => $type_module) {
  411. // In case we are uninstalling from this module
  412. // we go back to main
  413. if ($module == $this->module) {
  414. $this->module = 'main';
  415. }
  416. set_gym_config($type_module . '_installed', 0, 'main', $this->gym_config);
  417. $this->gym_set_default( $mode, $_module, $action, true, true, true );
  418. }
  419. }
  420. // Now install
  421. if (!empty($install)) {
  422. foreach ($install[$mode] as $_module => $type_module) {
  423. set_gym_config($type_module . '_installed', 1, 'main', $this->gym_config);
  424. }
  425. $this->remove_cache('config');
  426. $this->remove_cache('acp');
  427. $this->gym_get_modules($mode);
  428. foreach ($install[$mode] as $_module => $type_module) {
  429. $this->gym_set_default( $mode, $_module, $action, true, true );
  430. }
  431. }
  432. $this->remove_cache('config');
  433. $this->remove_cache('acp');
  434. trigger_error($user->lang['CONFIG_UPDATED'] . $this->back_to_prev());
  435. }
  436. // Adjust language variable a bit
  437. $user->lang['GYM_MODULE_INSTALL'] = sprintf($user->lang['GYM_MODULE_INSTALL'], $user->lang[strtoupper($mode)] );
  438. $user->lang['GYM_MODULE_INSTALL_EXPLAIN'] = sprintf($user->lang['GYM_MODULE_INSTALL_EXPLAIN'], $user->lang[strtoupper($mode)] );
  439. $display_vars = array( 'title' => 'GYM_MODULE_INSTALL');
  440. $display_vars['vars'] = array();
  441. $i = 1;
  442. // Installed modules
  443. $active = array();
  444. foreach ($this->gym_modules[$mode] as $_module) {
  445. if ($_module !== 'main') {
  446. $active[$mode][$_module] = $mode . '_' . $_module;
  447. }
  448. }
  449. if (!empty($active)){ // Add the active module list
  450. $display_vars['vars']['legend' . $i] = 'GYM_MODULES_INSTALLED';
  451. $i++;
  452. foreach ($active[$mode] as $_module => $type_module) { // Installed modules
  453. // Grabb the data
  454. //$this->gym_module_acp($mode, $type_module);
  455. $this->new_config[$type_module] = 1;
  456. $display_vars['vars'][$type_module] = array('lang' => strtoupper($type_module), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false);
  457. }
  458. }
  459. // now check if we have some module to install
  460. $unactive = array();
  461. $dir = @opendir( $phpbb_root_path . 'gym_sitemaps/acp' );
  462. while( ($file = @readdir($dir)) !== FALSE ) {
  463. if(preg_match('`^' . $mode . '_([a-z0-9_-]+)\.' . $phpEx . '$`i', $file, $matches)) {
  464. $type_module = trim(str_replace('.' . $phpEx , '' ,$file), "/");
  465. $_module = str_replace($mode . '_', '', $type_module);
  466. if ($matches[1] !== 'main' && file_exists($phpbb_root_path . 'gym_sitemaps/modules/' . $file) && !isset($this->gym_modules[$mode][$_module])) {
  467. $unactive[$mode][$_module] = $type_module;
  468. if ($_module != 'main' && !empty($this->gym_config[$type_module . '_installed'])) {
  469. set_gym_config($type_module . '_installed', 0, 'main', $this->gym_config);
  470. }
  471. }
  472. }
  473. }
  474. if (!empty($unactive)){ // Add the not active module list
  475. $display_vars['vars']['legend' . $i] = 'GYM_MODULES_UNINSTALLED';
  476. $i++;
  477. foreach ($unactive[$mode] as $_module => $type_module) { // Uninstalled modules
  478. // Grabb the data
  479. $this->gym_pick_module($mode, $_module, $module_data);
  480. if (!empty($module_data[$mode][$_module]['info']['lang_file'])) {
  481. $user->add_lang('gym_sitemaps/acp/' . $module_data[$mode][$_module]['info']['lang_file']);
  482. }
  483. $this->new_config[$type_module] = 0;
  484. $display_vars['vars'][$type_module] = array('lang' => strtoupper($type_module), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false);
  485. }
  486. }
  487. return $display_vars;
  488. }
  489. /**
  490. * gym_set_default( $mode, $module, $action, $submit = false, $silent = false, $uninstall = false )
  491. * Set default values for modules
  492. */
  493. function gym_set_default( $mode, $module, $action, $submit = false, $silent = false, $uninstall = false ) {
  494. global $user, $phpbb_root_path, $phpEx;
  495. $post_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : array();
  496. $this->new_config['reset_all'] = $reset_all = isset($post_array['reset_all']) ? $post_array['reset_all'] : false;
  497. if ($silent) {
  498. $reset_all = true;
  499. }
  500. if ($submit) {
  501. if ($mode === 'main' ) { // Reset all seting for all output and all modules
  502. foreach ($this->modes as $output_mode) { // List the output modes
  503. $this->gym_get_modules($output_mode);
  504. foreach ($this->gym_modules[$output_mode] as $type_module) { // List modules from each output mode
  505. if (!empty($post_array[$output_mode . '_' . $type_module . '_reset']) || $reset_all) {
  506. // Grabb the data
  507. $this->gym_module_acp($output_mode, $type_module);
  508. foreach($this->gym_modules_acp[$output_mode][$type_module]['info']['actions'] as $module_action) {
  509. foreach ($this->gym_modules_acp[$output_mode][$type_module][$module_action]['default'] as $module_config => $default_value ) { // In the end list possible options for this module's option set
  510. // Update config
  511. if ($uninstall) {
  512. rem_gym_config($module_config, $this->gym_config);
  513. } else {
  514. set_gym_config($module_config, $default_value, $output_mode, $this->gym_config);
  515. }
  516. }
  517. }
  518. }
  519. }
  520. }
  521. } elseif ($module === 'main') { // Only looking for one output type modules
  522. foreach ($this->gym_modules[$mode] as $type_module) { // add the output types modules
  523. if (!empty($post_array[$mode . '_' . $type_module . '_reset']) || $reset_all) {
  524. // Grabb the data
  525. $this->gym_module_acp($mode, $type_module);
  526. foreach($this->gym_modules_acp[$mode][$type_module]['info']['actions'] as $module_action) {
  527. foreach ($this->gym_modules_acp[$mode][$type_module][$module_action]['default'] as $module_config => $default_value ) {
  528. // Update config
  529. if ($uninstall) {
  530. rem_gym_config($module_config, $this->gym_config);
  531. } else {
  532. set_gym_config($module_config, $default_value, $mode, $this->gym_config);
  533. }
  534. }
  535. }
  536. }
  537. }
  538. } else { // Only reset this module config
  539. $this->gym_module_acp($mode, $module);
  540. // Allow modules with no acp
  541. if (!empty($this->gym_modules_acp[$mode][$module]['info'])) {
  542. foreach ($this->gym_modules_acp[$mode][$module]['info']['actions'] as $module_action ) {
  543. foreach ($this->gym_modules_acp[$mode][$module][$module_action]['default'] as $module_config => $default_value ) {
  544. if (!empty($post_array[$mode . '_' . $module . '_' . $module_action . '_reset']) || $reset_all) {
  545. // Update config
  546. if ($uninstall) {
  547. rem_gym_config($module_config, $this->gym_config);
  548. } else {
  549. set_gym_config($module_config, $default_value, $mode, $this->gym_config);
  550. }
  551. }
  552. }
  553. }
  554. }
  555. }
  556. $this->clear_all_cache();
  557. unset($post_array);
  558. if (!$silent) {
  559. trigger_error($user->lang['CONFIG_UPDATED'] . $this->back_to_prev());
  560. } else {
  561. return;
  562. }
  563. }
  564. // Adjust language variable a bit
  565. $user->lang['GYM_RESET'] = sprintf($user->lang['GYM_RESET'], $user->lang[strtoupper($mode)] );
  566. $user->lang['GYM_RESET_EXPLAIN'] = sprintf($user->lang['GYM_RESET_EXPLAIN'], $user->lang[strtoupper($mode)] );
  567. $display_vars = array( 'title' => 'GYM_RESET');
  568. $i = 1;
  569. if ($mode === 'main' ) { // Reset all seting for all output and all modules
  570. foreach ($this->modes as $output_mode) { // List the output types modules
  571. $this->gym_get_modules($output_mode);
  572. $display_vars['vars']['legend' . $i] = strtoupper($output_mode);
  573. $i++;
  574. foreach ($this->gym_modules[$output_mode] as $type_module) { // Then the modules
  575. // Grabb the data
  576. $this->gym_module_acp($output_mode, $type_module);
  577. // Then the associated language files if any
  578. if (!empty($this->gym_modules_acp[$output_mode][$type_module]['info']['lang_file'])) {
  579. $user->add_lang('gym_sitemaps/acp/' . $this->gym_modules_acp[$output_mode][$type_module]['info']['lang_file']);
  580. }
  581. $var_key = $output_mode . '_' . $type_module . '_reset';
  582. $this->new_config[$var_key] = 0;
  583. $display_vars['vars'][$var_key] = array('lang' => strtoupper($var_key), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
  584. }
  585. }
  586. } elseif ($module === 'main') { // Only looking for one output type modules
  587. foreach ($this->gym_modules[$mode] as $type_module) { // add the output types modules
  588. // Grabb the data
  589. $this->gym_module_acp($mode, $type_module);
  590. $display_vars['vars']['legend' . $i] = strtoupper($mode . '_' . $type_module);
  591. $i++;
  592. $var_key = $mode . '_' . $type_module . '_reset';
  593. $this->new_config[$var_key] = 0;
  594. $display_vars['vars'][$var_key] = array('lang' => strtoupper($var_key), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
  595. }
  596. } else { // Only reset this module config
  597. $this->gym_module_acp($mode, $module);
  598. $display_vars['vars']['legend' . $i] = strtoupper($mode . '_' . $module) . '_RESET';
  599. $i++;
  600. // Grabb the data
  601. foreach ($this->gym_modules_acp[$mode][$module]['info']['actions'] as $module_action ) {
  602. if (!empty($this->gym_modules_acp[$mode][$module][$module_action]['display_vars']['vars'])) {
  603. $var_key = $mode . '_' . $module . '_' . $module_action . '_reset';
  604. $this->new_config[$var_key] = 0;
  605. $display_vars['vars'][$var_key] = array('lang' => strtoupper($var_key), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
  606. }
  607. }
  608. }
  609. $display_vars['vars']['legend' . $i] = 'GYM_RESET_ALL';
  610. $i++;
  611. $display_vars['vars']['reset_all'] = array('lang' => 'GYM_RESET_ALL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
  612. return $display_vars;
  613. }
  614. /**
  615. * gym_maintenance( $mode, $module, $action, $submit = false )
  616. * handle cache (data + module's cache) clearing
  617. */
  618. function gym_maintenance( $mode, $module, $action, $submit = false ) {
  619. global $user, $phpbb_root_path, $phpEx;
  620. $post_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : array();
  621. $this->new_config['cache_action'] = $cache_action = isset($post_array['cache_action']) ? $post_array['cache_action'] : 'all';
  622. $this->new_config['acp_modules'] = $acp_modules = isset($post_array['acp_modules']) ? $post_array['acp_modules'] : false;
  623. unset($post_array);
  624. $regexes = array( 'all' => '[a-z0-9_-]+', 'google' => 'google_', 'rss' => 'rss_', /*'html' => 'html_', 'yahoo' => 'yahoo_'*/);
  625. $cache_dir = $phpbb_root_path . 'gym_sitemaps/cache/';
  626. $cache_regex = $style_regex = $regexes['all'];
  627. if ($cache_action == 'all') {
  628. if ($mode != 'main') {
  629. $cache_regex = $style_regex = $mode . '_';
  630. }
  631. } else {
  632. if ($mode != 'main') { // we are at the output type level
  633. $cache_regex = $style_regex = $mode . '_';
  634. $cache_regex .= $cache_action . '_';
  635. } else { // At the global level, we only can delete complete output type cache at once
  636. $cache_regex = isset($regexes[$cache_action]) ? $regexes[$cache_action] : $regexes['all'];
  637. }
  638. }
  639. if ($submit) {
  640. $message = '';
  641. if ($acp_modules) {
  642. $this->remove_cache('acp', $cache_action);
  643. $message = $user->lang['MODULE_CACHE_CLEARED'] . '<br/><br/>';
  644. }
  645. $accessed = false;
  646. $deleted = '';
  647. $res = opendir($cache_dir);
  648. if($res) {
  649. $num_del = 0;
  650. while(($file = readdir($res))) {
  651. // includes CSS and XSL cache
  652. if(preg_match('`^(style_' . $style_regex . '|' . $cache_regex . ')[a-z0-9_-]+\.(xml|xml\.gz|css|xsl)$`i', $file)) {
  653. @unlink($cache_dir . $file);
  654. $deleted .= "<li>$file</li>";
  655. $num_del++;
  656. }
  657. }
  658. $accessed = true;
  659. }
  660. closedir($res);
  661. if ($accessed) {
  662. if ($deleted !='') {
  663. $message .= $user->lang['GYM_CACHE_CLEARED'] . $cache_dir . '<br/><br/>';
  664. $message .= '<div align="left">' . $user->lang['GYM_FILE_CLEARED'] . " $num_del<ul>$deleted</ul></div>";
  665. } else {
  666. $message .= $user->lang['GYM_CACHE_ACCESSED'] . $cache_dir;
  667. }
  668. } else {
  669. $message .= $user->lang['GYM_CACHE_NOT_CLEARED'] . $cache_dir;
  670. }
  671. trigger_error($message . $this->back_to_prev());
  672. }
  673. // Clear cache type
  674. if ($mode === 'main') {
  675. $cache_actions = array( 'gym' => $user->lang['ALL'], 'google' => $user->lang['GOOGLE'], 'rss' => $user->lang['RSS'], /*'yahoo' => $user->lang['YAHOO'], 'html' => $user->lang['HTML']*/);
  676. } else {
  677. $cache_actions = array();
  678. foreach ($this->gym_modules[$mode] as $mode_module) {
  679. if ($mode_module === 'main') {
  680. if ($module !== 'main') {
  681. continue;
  682. }
  683. $mode_module = 'all';
  684. }
  685. if (!empty($this->gym_modules_acp[$mode][$mode_module]['info']['lang_file'])) {
  686. $user->add_lang('gym_sitemaps/acp/' . $this->gym_modules_acp[$mode][$mode_module]['info']['lang_file']);
  687. }
  688. $cache_actions[$mode_module] = $this->safe_lang(strtoupper($mode . '_' . $mode_module . '_reset'));
  689. }
  690. }
  691. $this->gym_modules_acp[$this->mode][$this->module][$this->action]['select']['cache_action'] = $cache_actions;
  692. // Adjust language variable a bit
  693. $user->lang['GYM_MODULE_MAINTENANCE'] = sprintf($user->lang['GYM_CLEAR_CACHE'], $user->lang[strtoupper($mode)] );
  694. $user->lang['GYM_MODULE_MAINTENANCE_EXPLAIN'] = sprintf($user->lang['GYM_MODULE_MAINTENANCE_EXPLAIN'], $user->lang[strtoupper($mode)] );
  695. $user->lang['GYM_CLEAR_CACHE'] = sprintf($user->lang['GYM_CLEAR_CACHE'], $user->lang[strtoupper($mode)] );
  696. $user->lang['GYM_CLEAR_CACHE_EXPLAIN'] = sprintf($user->lang['GYM_CLEAR_CACHE_EXPLAIN'], $user->lang[strtoupper($mode)] );
  697. $user->lang['GYM_CLEAR_ACP_CACHE'] = sprintf($user->lang['GYM_CLEAR_ACP_CACHE'], $user->lang[strtoupper($mode)] );
  698. $user->lang['GYM_CLEAR_ACP_CACHE_EXPLAIN'] = sprintf($user->lang['GYM_CLEAR_ACP_CACHE_EXPLAIN'], $user->lang[strtoupper($mode)] );
  699. $display_vars = array( 'title' => 'GYM_MODULE_MAINTENANCE',
  700. 'vars' => array(
  701. 'legend1' => 'GYM_MODULE_MAINTENANCE',
  702. 'cache_action' => array('lang' => 'GYM_CLEAR_CACHE','validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true,),
  703. 'acp_modules' => array('lang' => 'GYM_CLEAR_ACP_CACHE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
  704. ),
  705. );
  706. return $display_vars;
  707. }
  708. /**
  709. * is_overriden($mode, $module, $action, $config_key, $vars)
  710. * tell if an option is overriden
  711. */
  712. function is_overriden($mode, $module, $action, $config_key, $vars) {
  713. global $user;
  714. static $override_msg = array();
  715. if (empty($override_msg)) {
  716. $override_msg = array( OVERRIDE_GLOBAL => 'GYM_OVERRIDED_GLOBAL', OVERRIDE_OTYPE => 'GYM_OVERRIDED_OTYPE', OVERRIDE_MODULE => 'GYM_OVERRIDED_MODULE');
  717. }
  718. // Define overrides if needed
  719. if (empty($this->override[$mode][$module])) {
  720. foreach ($this->override_type as $_type) {
  721. $this->override[$mode][$module][$_type] = $this->_set_override($mode, $module, $_type);
  722. }
  723. $this->override[$mode][$module][$mode] = $this->gym_config[$mode . '_override'];
  724. }
  725. $override = $overrided = $level = '';
  726. if ($mode != 'main') {
  727. // We are setting up an output type
  728. if ($module != 'main') {
  729. $option = str_replace($mode . "_$module" . '_', '', $config_key);
  730. $level = OVERRIDE_MODULE;
  731. } else { // we are setting up a module
  732. $option = str_replace($mode . '_', '', $config_key);
  733. $level = OVERRIDE_OTYPE;
  734. }
  735. } else { // Main level
  736. $option = str_replace('gym_', '', $config_key);
  737. $level = OVERRIDE_GLOBAL;
  738. }
  739. if (in_array($action, $this->override_type)) { // Main overrides
  740. $override = $this->override[$mode][$module][$action];
  741. } else {
  742. $override = $this->override[$mode][$module][$mode];
  743. }
  744. $overrided = $this->_overriden_type($mode, $module, $option, $override, $level);
  745. if ($overrided['override'] == $level) {
  746. return '<br/><i style="color:green">' . $this->safe_lang('GYM_COULD_OVERRIDE') . '</i>';
  747. } else {
  748. $message = '';
  749. // Check if we should show the value used
  750. if ($overrided['used_value'] !== 'current') {
  751. // Check var type
  752. if ($vars['validate'] == 'bool') {
  753. $message = $overrided['used_value'] ? $user->lang['YES'] : $user->lang['NO'];
  754. } elseif (($vars['validate'] == 'int' || $vars['validate'] == 'string') && !@$vars['method'] == 'select_string') {
  755. $message = htmlspecialchars($overrided['used_value']);
  756. $message = $message == '' ? $user->lang['GYM_OVERRIDED_VALUE_NOTHING'] : $message;
  757. } elseif (@$vars['method'] == 'select_string') {
  758. $select_ary = $this->gym_modules_acp[$mode][$module][$action]['select'][$config_key];
  759. $message = $this->safe_lang($select_ary[$overrided['used_value']]);
  760. }
  761. }
  762. $message = !empty($message) ? '<br/>' . $user->lang['GYM_OVERRIDED_VALUE'] . $message : '';
  763. return '<br/><i style="color:red">' . $this->safe_lang($override_msg[$overrided['override']]) . $message . '</i>';
  764. }
  765. }
  766. /**
  767. * _overriden_type()
  768. * helper for is_overriden()
  769. */
  770. function _overriden_type($mode, $module, $option, $override, $level ) {
  771. // module level
  772. if ( ($override == OVERRIDE_MODULE) && @isset($this->gym_config[$mode . "_$module" . "_$option"])) {
  773. return array('override' => OVERRIDE_MODULE);
  774. }
  775. // Output type level
  776. if ( $override != OVERRIDE_GLOBAL && @isset($this->gym_config[$mode . "_$option"])) {
  777. return array('override' => OVERRIDE_OTYPE, 'used_value' => ($level != OVERRIDE_OTYPE ? $this->gym_config[$mode . "_$option"] : 'current' ) );
  778. }
  779. // Global level
  780. if (isset($this->gym_config["gym_$option"])) {
  781. return array('override' => OVERRIDE_GLOBAL, 'used_value' => ($level != OVERRIDE_GLOBAL ? $this->gym_config["gym_$option"] : 'current' ) );
  782. } elseif ( @isset($this->gym_config[$mode . "_$option"]) ) {
  783. return array('override' => OVERRIDE_OTYPE, 'used_value' => ($level != OVERRIDE_OTYPE ? $this->gym_config[$mode . "_$option"] : 'current' ) );
  784. } elseif ( @isset($this->gym_config[$mode . "_$module" . "_$option"]) ) {
  785. return array('override' => OVERRIDE_MODULE, 'used_value' => ($level != OVERRIDE_MODULE ? $this->gym_config[$mode . "_$module" . "_$option"] : 'current' ) );
  786. } else {
  787. return null;
  788. }
  789. }
  790. /**
  791. * _set_override()
  792. * helper for is_overriden()
  793. */
  794. function _set_override($mode, $module, $type) {
  795. $main_key = 'gym_override_' . $type;
  796. $mode_key = $mode . '_override_' . $type;
  797. // $module_key = $module != 'main' ? $mode . '_' . $module . '_override_' . $type : 0;
  798. if ($this->gym_config['gym_override']) {
  799. return ($this->gym_config[$main_key] != OVERRIDE_GLOBAL) ? ($this->gym_config[$mode_key] != OVERRIDE_GLOBAL ? $this->gym_config[$mode_key] : $this->gym_config[$main_key]) : OVERRIDE_GLOBAL;
  800. } else {
  801. return $this->gym_config[$mode_key];
  802. }
  803. }
  804. /**
  805. * safe_lang($lang_key)
  806. * Safely set a lang key
  807. */
  808. function safe_lang($lang_key) {
  809. global $user;
  810. return isset($user->lang[$lang_key]) ? $user->lang[$lang_key] : htmlspecialchars($lang_key);
  811. }
  812. /**
  813. * back_to_prev()
  814. * Generate back link for acp pages
  815. */
  816. function back_to_prev() {
  817. global $user;
  818. return '<br /><br /><a href="' . $this->u_action . '&amp;maction=' . $this->maction . '&amp;action=' . $this->action . '&amp;module=' . $this->module . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>';
  819. }
  820. /**
  821. * module_custom_select($value, $key) to grabb custom select function from modules
  822. * In the $display_vars array :
  823. * 'gym_config_key' => array('lang' => 'LANG_TITLE', 'validate' => 'int|bool|string', 'type' => 'custom', 'method' => 'module_custom_select', 'explain' => true),
  824. * Will build the custom select unsing the module's select_gym_config_key($value, $key) method.
  825. */
  826. function module_custom_select($value, $key) {
  827. global $phpbb_root_path, $phpEx;
  828. $method = 'select_' . $key;
  829. $module_file = $phpbb_root_path . 'gym_sitemaps/acp/modules/' . $this->mode . '_' . $this->module . '.' . $phpEx;
  830. if ( file_exists($module_file) ) {
  831. include_once($module_file);
  832. if (class_exists($module_class)) {
  833. $gym_module = new $module_class($this);
  834. if ( method_exists($gym_module, $method)) {
  835. return $gym_module->$method($value, $key);
  836. }
  837. }
  838. }
  839. // Error
  840. }
  841. /**
  842. * select_multiple_string($value, $key) custom select string
  843. */
  844. function select_multiple_string($value, $key) {
  845. $select_ary = $this->gym_modules_acp[$this->mode][$this->module][$this->action]['select'][$key];
  846. $size = min(12,count($select_ary));
  847. $html = '<select multiple="multiple" id="' . $key . '" name="multiple_' . $key . '[]" size="' . $size . '">';
  848. foreach ($select_ary as $sel_key => $sel_data) {
  849. if (empty($sel_data['disabled'])) {
  850. $selected = @array_search($sel_key, @$this->new_config[$key]) !== false ? 'selected="selected"' : '';
  851. $disabled = '';
  852. } else {
  853. $disabled = 'disabled="disabled" class="disabled-option"';
  854. $selected = '';
  855. }
  856. $sel_title = $sel_data['title'];
  857. $html .= "<option value=\"$sel_key\" $disabled $selected>$sel_title</option>";
  858. }
  859. return $html . '</select>';
  860. }
  861. /**
  862. * select_string($value, $key) custom select string
  863. */
  864. function select_string($value, $key) {
  865. $select_ary = $this->gym_modules_acp[$this->mode][$this->module][$this->action]['select'][$key];
  866. $html = '';
  867. foreach ($select_ary as $sel_key => $sel_lang) {
  868. $selected = ($sel_key == @$this->new_config[$key]) ? ' selected="selected"' : '';
  869. $sel_title = $this->safe_lang($sel_lang);
  870. $html .= '<option value="' . $sel_key . '"' . $selected . '>' . $sel_title . '</option>';
  871. }
  872. return $html;
  873. }
  874. /**
  875. * validate_num($value, $key, $num) validate num, 2.3255
  876. */
  877. function validate_num($value, $key, $float = 1, $min = 0 , $max = 4) {
  878. $float = $float > 0 ? (int) $float : 0;
  879. $min = $min > 0 ? $min : 0;
  880. $max = $max > 0 ? $max : 4;
  881. $value = ($value >= $min && $value <= $max) ? $value : ($max/2);
  882. $value = $float > 0 ? sprintf('%.' . $float . 'f', $value) : (int) $value;
  883. return '<input id="' . $key . '" type="text" size="' . (strlen($max) + $float + 1) . '" maxlength="' . (strlen($max) + $float + 1) . '" name="config[' . $key . ']" value="' . $value . '" />';
  884. }
  885. /**
  886. * forum_select() // custom forum select setup
  887. */
  888. function forum_select() {
  889. if (empty($this->dyn_select['forums'])) {
  890. $this->dyn_select['forums'] = make_forum_select(false, false, true, true, true, false, true);
  891. foreach($this->dyn_select['forums'] as $f_id => $f_data) {
  892. $this->dyn_select['forums'][$f_id] = array(
  893. 'title' => $f_data['padding'] . $f_data['forum_name'],
  894. 'disabled' => $f_data['disabled'],
  895. );
  896. }
  897. }
  898. }
  899. /**
  900. * clear_all_cache()
  901. * Clears all the gym sitemaps cache ( acp modules, module lists and config )
  902. */
  903. function clear_all_cache($option = '') {
  904. global $phpbb_root_path, $phpEx, $acm_type, $cache;
  905. if ($acm_type !== 'file') {
  906. // Apparently, we cannot loop through cached variable using cache class in such case, purge all for now
  907. $cache->purge();
  908. return;
  909. }
  910. $dir = opendir( $cache->cache_dir );
  911. $action_from_file = '';
  912. while( ($file = @readdir($dir)) !== false ) {
  913. if(preg_match('`^data_gym_' . $option . '[a-z0-9_-]+\.' . $phpEx . '$`i', $file)) {
  914. @unlink($cache->cache_dir . $file);
  915. }
  916. }
  917. @closedir($dir);
  918. return;
  919. }
  920. /**
  921. * remove_cache($cache_type, $file_type)
  922. * Removes/unlinks config cache file(s)
  923. */
  924. function remove_cache($type = 'config', $mode = '') {
  925. global $phpbb_root_path, $phpEx, $acm_type;
  926. if ($type == 'all' || $acm_type !== 'file') {
  927. $this->clear_all_cache();
  928. return;
  929. }
  930. $RegEx = ($type === 'config') ? '(config|links|auth)' : '';
  931. $RegEx .= (!empty($mode) && in_array($mode, $this->modes) ? "_$mode" : '');
  932. $this->clear_all_cache($RegEx);
  933. return;
  934. }
  935. /**
  936. * set_phpbb_seo_links Builds links to support threads
  937. */
  938. function set_phpbb_seo_links() {
  939. global $config, $user, $template;
  940. $this->support_link['links_en'] = array( 'release' => 'http://www.phpbb-seo.com/en/gym-sitemaps-rss/google-yahoo-msn-sitemaps-rss-t2734.html', 'support' => 'http://www.phpbb-seo.com/en/gym-sitemaps-rss/', 'seo_forum' => 'http://www.phpbb-seo.com/en/', 'subscribe' => 'http://www.phpbb-seo.com/en/gym-sitemaps-rss/google-yahoo-msn-sitemaps-rss-t2734.html' );
  941. $this->support_link['links_fr'] = array( 'release' => 'http://www.phpbb-seo.com/fr/gym-sitemaps-rss/sitemaps-rss-google-yahoo-msn-t3136.html', 'support' => 'http://www.phpbb-seo.com/fr/gym-sitemaps-rss/', 'seo_forum' => 'http://www.phpbb-seo.com/fr/', 'subscribe' => 'http://www.phpbb-seo.com/fr/gym-sitemaps-rss/sitemaps-rss-google-yahoo-msn-t3136.html' );
  942. if (strpos($config['default_lang'], 'fr') !== false ) {
  943. $this->support_link['release'] = $this->support_link['links_fr']['release'];
  944. $this->support_link['support'] = $this->support_link['links_fr']['support'];
  945. $this->support_link['seo_forum'] = $this->support_link['links_fr']['seo_forum'];
  946. $this->support_link['subscribe'] = $this->support_link['links_fr']['subscribe'];
  947. } else {
  948. $this->support_link['release'] = $this->support_link['links_en']['release'];
  949. $this->support_link['support'] = $this->support_link['links_en']['support'];
  950. $this->support_link['seo_forum'] = $this->support_link['links_en']['seo_forum'];
  951. $this->support_link['subscribe'] = $this->support_link['links_en']['subscribe'];
  952. }
  953. $this->support_link['register'] = $this->support_link['seo_forum'] . 'profile.php?mode=register';
  954. $this->support_link['update_msg'] = sprintf($user->lang['ACP_SEO_REGISTER_MSG'], sprintf($user->lang['ACP_SEO_REGISTER_TITLE'],$this->support_link['register'] ), sprintf($user->lang['ACP_SEO_REGISTER_UPDATE'], $this->support_link['subscribe'] ) );
  955. $user->lang['TRANSLATION_INFO'] .= '<br/><a href="http://www.phpbb-seo.com/" title="' . ( strpos($config['default_lang'], 'fr') !== false ? 'Optimisation du R&eacute;f&eacute;rencement' : 'Search Engine Optimization') . '">phpBB SEO</a>';
  956. $this->support_link['release_full'] = '<a href="' . $this->support_link['release'] . '" title="' . $user->lang['ACP_SEO_RELEASE_THREAD'] . '">' . $user->lang['ACP_SEO_RELEASE_THREAD'] . '</a>';
  957. $this->support_link['support_full'] = '<a href="' . $this->support_link['support'] . '" title="' . $user->lang['ACP_SEO_SUPPORT_FORUM'] . '">' . $user->lang['ACP_SEO_SUPPORT_FORUM'] . '</a>';
  958. $this->support_link['seo_forum_full'] = '<a href="' . $this->support_link['seo_forum'] . '" title ="phpBB SEO">phpBB SEO</a>';
  959. $template->assign_vars(array(
  960. 'SUPPORT_LINKS' => '<p>' . $this->support_link['release_full'] . '&nbsp;&bull;&nbsp;' . $this->support_link['support_full'] . '&nbsp;&bull;&nbsp;' . $this->support_link['seo_forum_full'] . '</p>',
  961. )
  962. );
  963. if ($this->mode === 'main' && $this->module === 'main' && $this->action === 'main') {
  964. $user->lang['MAIN_MAIN_EXPLAIN'] = sprintf( $user->lang['MAIN_MAIN_EXPLAIN'], $this->support_link['release_full'], $this->support_link['support_full'], $this->support_link['seo_forum_full'], $this->support_link['update_msg'] );
  965. }
  966. return;
  967. }
  968. /**
  969. * check_scripts Validates GYM scripts (gymrss, sitemap & map) locations
  970. */
  971. function check_scripts(&$error, &$cfg_array, $only_mode = '') {
  972. global $phpbb_root_path, $phpEx, $user, $phpbb_seo, $phpbb_admin_path;
  973. $allowed_protocols = array('http', 'https'/*, 'ftp', 'ftps'*/);
  974. $error = is_array($error) ? $error : array();
  975. // check file_get_contents availability
  976. $file_get = function_exists('file_get_contents');
  977. if (!$file_get) {
  978. // file_get_contents is not available, we won't be able to check everything
  979. // @TODO find out how (we won't thgouh an error just for this),
  980. // and also if it would be useful, to warn user about this
  981. }
  982. $scripts = array(
  983. 'rss' => array('file' => 'gymrss',),
  984. 'google' => array('file' => 'sitemap',),
  985. 'html' => array('file' => 'map',),
  986. );
  987. $only_mode = $only_mode && isset($scripts[$only_mode]) ? $only_mode : false;
  988. if ($only_mode) {
  989. $scripts[$only_mode]['url_config'] = isset($cfg_array[$only_mode . '_url']) ? ($cfg_array[$only_mode . '_url'] = trim($cfg_array[$only_mode . '_url'], ' /') . '/') : '';
  990. $scripts = array($only_mode => $scripts[$only_mode]);
  991. } else {
  992. foreach ($scripts as $k => $v) {
  993. if (isset($cfg_array[$k . '_url'])) {
  994. $scripts[$k]['url_config'] = isset($cfg_array[$k . '_url']) ? ($cfg_array[$k . '_url'] = trim($cfg_array[$k . '_url'], ' /') . '/') : '';
  995. } else {
  996. // do not check without a reference
  997. unset($scripts[$k]);
  998. }
  999. }
  1000. }
  1001. // let's not show a warning for a proto matter (since they are dealt with runtime)
  1002. foreach ($scripts as $k => $v) {
  1003. $scripts[$k]['url_config'] = $scripts[$k]['url_config'] ? $phpbb_seo->sslify($scripts[$k]['url_config'], $phpbb_seo->ssl['use']) : '';
  1004. }
  1005. $phpbb_url_config_url = append_sid($phpbb_admin_path . "index.$phpEx", "i=board&amp;mode=server#force_server_vars");
  1006. // all script should be placed in the same domain as phpBB
  1007. $root_url = $phpbb_seo->seo_path['root_url'];
  1008. if (($root_url_parts = @parse_url($root_url)) === false || empty($root_url_parts['scheme']) || !in_array($root_url_parts['scheme'], $allowed_protocols) || empty($root_url_parts['host'])) {
  1009. // the root url as set is wrong in phpbb config
  1010. $error[] = sprintf($user->lang['GYM_WRONG_PHPBB_URL'], $phpbb_url_config_url);
  1011. return false;
  1012. }
  1013. // deal with paths
  1014. $phpbb_url = $phpbb_seo->seo_path['phpbb_url'];
  1015. // the path from domain root to phpBB
  1016. $phpbb_clean_root_path = $phpbb_seo->seo_path['phpbb_script'];
  1017. $phpbb_root_path_parts = trim($phpbb_clean_root_path, '/ ');
  1018. $phpbb_root_path_parts = $phpbb_root_path_parts ? explode('/', $phpbb_root_path_parts) : false;
  1019. $phpbb_root_path_levels = 0;
  1020. if ($phpbb_root_path_parts) {
  1021. // the number of sub directory starting from domain's root
  1022. $phpbb_root_path_levels = count($phpbb_root_path_parts);
  1023. }
  1024. // form here to domain's root and then to domains root to phpBB directory should be a way to hit common.php
  1025. // from phpBB to domain's root
  1026. $phpbb_test_path = str_repeat('../', $phpbb_root_path_levels);
  1027. // from domain's root to phpBB
  1028. $phpbb_test_path .= $phpbb_clean_root_path;
  1029. if (!file_exists($phpbb_root_path . $phpbb_test_path)) {
  1030. // the root url as set is wrong in phpbb config
  1031. $error[] = sprintf($user->lang['GYM_WRONG_PHPBB_URL'], $phpbb_url_config_url);
  1032. return false;
  1033. }
  1034. foreach ($scripts as $mode => $setup) {
  1035. $error[$mode] = '<h2>' . $user->lang[strtoupper($mode) . '_URL'] . '</h2>';
  1036. $url_config_url = append_sid($phpbb_admin_path . "index.$phpEx", "i=gym_sitemaps&amp;mode=$mode#{$mode}_url");
  1037. $script_file = $setup['file'] . ".$phpEx";
  1038. if (($url_parts = @parse_url($setup['url_config'])) === false || empty($root_url_parts['scheme']) || !in_array($root_url_parts['scheme'], $allowed_protocols) || empty($root_url_parts['host'])) {
  1039. // the scritp url is wrong
  1040. $error[] = sprintf($user->lang['GYM_WRONG_SCRIPT_URL'], $user->lang[strtoupper($mode)], $script_file);
  1041. $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url);
  1042. continue;
  1043. }
  1044. if (strpos($setup['url_config'], $root_url) === false ) {
  1045. // the script domain is wrong
  1046. $error[] = sprintf($user->lang['GYM_WRONG_SCRIPT_DOMAIN'], $user->lang[strtoupper($mode)], $root_url, $script_file);
  1047. $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url);
  1048. continue;
  1049. }
  1050. // current gym script is configured in the phpBB domain
  1051. // let's check paths, start with something simple
  1052. if (strpos($setup['url_config'], $phpbb_url) !== false ) {
  1053. // script is (well should be) inside phpBB directory
  1054. $script_path = str_replace($phpbb_url, '', $setup['url_config']);
  1055. // if this is a sitemap, it would be wrong to put it within a sub directory inside the phpBB directory
  1056. if ($mode === 'google') {
  1057. if ($script_path) {
  1058. // sitemap is not usable for phpBB in there
  1059. $error[] = sprintf($user->lang['GYM_WRONG_SITEMAP_LOCATION'], $phpbb_url . $script_path, $root_url . $phpbb_clean_root_path);
  1060. $error[] = sprintf($user->lang['GYM_GO_CONFIG_SCRIPT_URL'], $user->lang[strtoupper($mode) . '_URL'], $url_config_url);
  1061. continue;
  1062. }
  1063. }
  1064. if (file_exists($phpbb_root_path . $script_path . $script_file)) {
  1065. // the script is where it should
  1066. if ($file

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