From 22b6a31e372974b052d97527e58bb0ba5b1c84bb Mon Sep 17 00:00:00 2001 From: dcz Date: Mon, 8 Sep 2014 16:07:15 +0200 Subject: [PATCH 1/2] [ticket/37] Implement sync_url Add this in acp, which implies to add a mode which implies to add a migration file which implies to activate version check and puch version :O --- acp/usu.php | 125 ++++++++++++++++++++++++++++++-- acp/usu_info.php | 7 +- composer.json | 9 ++- core.php | 41 ----------- language/en/acp_usu.php | 2 +- language/en/info_acp_usu.php | 1 + language/fr/acp_usu.php | 2 +- language/fr/info_acp_usu.php | 1 + migrations/release_2_0_0_b2.php | 49 +++++++++++++ 9 files changed, 186 insertions(+), 51 deletions(-) create mode 100644 migrations/release_2_0_0_b2.php diff --git a/acp/usu.php b/acp/usu.php index 210a564..4885eb8 100644 --- a/acp/usu.php +++ b/acp/usu.php @@ -56,7 +56,7 @@ class usu function main($id, $mode) { global $config, $db, $user, $template, $request; - global $phpbb_root_path, $phpEx; + global $phpbb_root_path, $phpbb_admin_path, $phpEx; global $phpbb_container; $this->config = $config; @@ -73,7 +73,9 @@ function main($id, $mode) $action = $this->request->variable('action', ''); $submit = $this->request->is_set_post('submit'); - $form_key = 'acp_board'; + $cancel = $this->request->variable('cancel', ''); + + $form_key = 'acp_seo_usu'; add_form_key($form_key); $display_vars = array(); @@ -189,6 +191,7 @@ function main($id, $mode) } break; + case 'forum_url': // used for cache $this->write_type = 'forum'; @@ -306,6 +309,7 @@ function main($id, $mode) } break; + case 'htaccess': $this->write_type = 'htaccess'; $display_vars['title'] = 'ACP_HTACCESS'; @@ -340,6 +344,7 @@ function main($id, $mode) )); break; + case 'extended': $display_vars = array( 'title' => 'ACP_SEO_EXTENDED', @@ -415,6 +420,118 @@ function main($id, $mode) $this->new_config = $this->config; break; + + case 'sync_url': + $sync_url = $this->request->variable('sync', ''); + $redirect_url = "{$phpbb_admin_path}index.$phpEx?i=-phpbbseo-usu-acp-usu&mode=sync_url"; + $go = max(0, $this->request->variable('go', 0)); + + if ($cancel || !$go) + { + trigger_error($this->user->lang['SYNC_WARN'] . '

' . $this->user->lang['SYNC_TOPIC_URLS'] . '

' . $this->user->lang['SYNC_RESET_TOPIC_URLS'] . '
'); + } + + $starttime = microtime(true); + $start = max(0, $this->request->variable('start', 0)); + $limit = max(100, $this->request->variable('limit', 0)); + + // Do not go over 1000 topic in a row + $limit = min(1000, $limit); + + $poll_processed = 0; + $forum_data = array(); + $url_updated = 0; + + if ($sync_url === 'sync') + { + // get all forum info + $sql = 'SELECT forum_id, forum_name FROM ' . FORUMS_TABLE; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $forum_data[$row['forum_id']] = $row['forum_name']; + $this->core->set_url($row['forum_name'], $row['forum_id'], $this->core->seo_static['forum']); + } + $db->sql_freeresult($result); + + // let's work + $sql = 'SELECT * FROM ' . TOPICS_TABLE . ' + ORDER BY topic_id ASC'; + $result = $db->sql_query_limit($sql, $limit, $start); + while ($row = $db->sql_fetchrow($result)) + { + $forum_id = (int) $row['forum_id']; + $topic_id = (int) $row['topic_id']; + $_parent = $row['topic_type'] == POST_GLOBAL ? $this->core->seo_static['global_announce'] : $this->core->seo_url['forum'][$forum_id]; + if ( !$this->core->check_url('topic', $row['topic_url'], $_parent)) + { + if (!empty($row['topic_url'])) + { + // Here we get rid of the seo delim (-t) and put it back even in simple mod + // to be able to handle all cases at once + $_url = preg_replace('`' . $this->core->seo_delim['topic'] . '$`i', '', $row['topic_url']); + $_title = $this->core->get_url_info('topic', $_url . $this->core->seo_delim['topic'] . $topic_id, 'title'); + } + else + { + $_title = $this->core->modrtype > 2 ? censor_text($row['topic_title']) : ''; + } + unset($this->core->seo_url['topic'][$topic_id]); + $row['topic_url'] = $this->core->get_url_info('topic', $this->core->prepare_url( 'topic', $_title, $topic_id, $_parent, (( empty($_title) || ($_title == $this->core->seo_static['topic']) ) ? true : false) ), 'url'); + unset($this->core->seo_url['topic'][$topic_id]); + if ($row['topic_url']) + { + // Update the topic_url field for later re-use + $sql = "UPDATE " . TOPICS_TABLE . " SET topic_url = '" . $db->sql_escape($row['topic_url']) . "' + WHERE topic_id = $topic_id"; + $db->sql_query($sql); + $url_updated++; + } + } + } + $db->sql_freeresult($result); + $sql = 'SELECT count(topic_id) as topic_cnt FROM ' . TOPICS_TABLE; + $result = $db->sql_query($sql); + $cnt = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + if ($cnt['topic_cnt'] > ($start + $limit)) + { + $endtime = microtime(true); + $duration = $endtime - $starttime; + $speed = round($limit/$duration, 2); + $percent = round((($start + $limit) / $cnt['topic_cnt']) * 100, 2); + $message = sprintf($user->lang['SYNC_PROCESSING'], $percent, ($start + $limit), $cnt['topic_cnt'], $limit, $speed, round($duration, 2) , round((($cnt['topic_cnt'] - $start)/$speed)/60, 2)); + if ($url_updated) + { + $message.= sprintf($user->lang['SYNC_ITEM_UPDATED'], '
' . $url_updated); + } + $new_limit = ($duration < 10) ? $limit + 50 : $limit - 10; + meta_refresh(1, append_sid($redirect_url, 'go=1&start=' . ($start + $limit) . "&limit=$new_limit&sync=sync")); + trigger_error("$message
"); + } + else + { + trigger_error($user->lang['SYNC_COMPLETE'] . sprintf($user->lang['RETURN_INDEX'], '

', '')); + } + } + elseif ($sync_url === 'reset') + { + if (confirm_box(true)) + { + $sql = "UPDATE " . TOPICS_TABLE . " SET topic_url = ''"; + $db->sql_query($sql); + trigger_error($user->lang['SYNC_RESET_COMPLETE'] . '

' . $user->lang['SYNC_TOPIC_URLS'] . '

• ' . sprintf($user->lang['RETURN_INDEX'], '', '
')); + } + else + { + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('go' => '1', 'sync' => 'reset')), 'confirm_body.html'); + } + } + else + { + trigger_error($user->lang['SYNC_WARN'] . '

' . $user->lang['SYNC_TOPIC_URLS'] . '

' . $user->lang['SYNC_RESET_TOPIC_URLS'] . '
'); + } + break; default: trigger_error('NO_MODE', E_USER_ERROR); break; @@ -600,7 +717,7 @@ function main($id, $mode) $db_tools->sql_column_add(TOPICS_TABLE, 'topic_url', array('VCHAR:255', '')); } - $additional_notes = sprintf($this->user->lang['SYNC_TOPIC_URL_NOTE'], '', ''); + $additional_notes = sprintf($this->user->lang['SYNC_TOPIC_URL_NOTE'], '', ''); if ($db_tools->db->get_sql_error_triggered()) { @@ -671,8 +788,6 @@ function main($id, $mode) $this->tpl_name = 'acp_board'; $this->page_title = $display_vars['title']; - $this->core->seo_end(); - $l_title_explain = $this->user->lang[$display_vars['title'] . '_EXPLAIN']; if ($mode != 'extended') diff --git a/acp/usu_info.php b/acp/usu_info.php index d3a7cce..6f180d1 100644 --- a/acp/usu_info.php +++ b/acp/usu_info.php @@ -17,7 +17,7 @@ function module() return array( 'filename' => '\phpbbseo\usu\acp\usu', 'title' => 'ACP_CAT_PHPBB_SEO', - 'version' => '2.0.0-b1', + 'version' => '2.0.0-b2', 'modes' => array( 'settings' => array( 'title' => 'ACP_PHPBB_SEO_CLASS', @@ -39,6 +39,11 @@ function module() 'auth' => 'ext_phpbbseo/usu && acl_a_board', 'cat' => array('ACP_MOD_REWRITE') ), + 'sync_url' => array( + 'title' => 'ACP_SYNC_URL', + 'auth' => 'ext_phpbbseo/usu && acl_a_board', + 'cat' => array('ACP_MOD_REWRITE') + ), )); } } diff --git a/composer.json b/composer.json index a6be0a3..6a01e4c 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,8 @@ "description": "phpBB SEO Ultimate SEO URL for phpBB 3.1", "homepage": "http://www.phpbb-seo.com/", "keywords": ["phpbbSEO", "extension", "seo", "USU"], - "version": "2.0.0-b1", - "time": "2014-06-12", + "version": "2.0.0-b2", + "time": "2014-09-12", "license": "GPL-2.0", "authors": [ { @@ -28,6 +28,11 @@ "display-name": "phpBB SEO Ultimate SEO URL", "soft-require": { "phpbb/phpbb": ">=3.1.0-RC2" + }, + "version-check": { + "host": "version.phpbb-seo.com", + "directory": "/", + "filename": "usu.json" } } } diff --git a/core.php b/core.php index bb74646..07cb829 100644 --- a/core.php +++ b/core.php @@ -1109,47 +1109,6 @@ public function seo_req_uri() return $this->seo_path['uri']; } - /** - * seo_end() : The last touch function - * Note : This mod is going to help your site a lot in Search Engines - * We request that you keep this copyright notice as specified in the licence. - * If You really cannot put this link, you should at least provide us with one visible - * (can be small but visible) link on your home page or your forum Index using this code for example : - * phpBB SEO - */ - public function seo_end($return = false) - { - if (empty($this->seo_opt['copyrights']['title'])) - { - $this->seo_opt['copyrights']['title'] = strpos($this->config['default_lang'], 'fr') !== false ? 'Optimisation du Référencement' : 'Search Engine Optimization'; - } - - if (empty($this->seo_opt['copyrights']['txt'])) - { - $this->seo_opt['copyrights']['txt'] = 'phpBB SEO'; - } - - if ($this->seo_opt['copyrights']['img']) - { - $output = '
' . $this->seo_opt['copyrights']['txt'] . ''; - } - else - { - $output = '
' . $this->seo_opt['copyrights']['txt'] . ''; - } - - if ($return) - { - return $output; - } - else - { - $this->user->lang['TRANSLATION_INFO'] .= $output; - } - - return; - } - // -> Cache functions /** * forum_id(&$forum_id, $forum_uri = '') diff --git a/language/en/acp_usu.php b/language/en/acp_usu.php index adea200..59f2525 100644 --- a/language/en/acp_usu.php +++ b/language/en/acp_usu.php @@ -40,7 +40,7 @@ 'ACP_MOD_REWRITE' => 'URL Rewriting settings', // ACP phpBB seo class 'ACP_PHPBB_SEO_CLASS' => 'phpBB SEO Class settings', - 'ACP_PHPBB_SEO_CLASS_EXPLAIN' => 'Here you can set up various options of the phpBB SEO %1$s mod (%2$s).
The various default settings such as the delimiters and suffixes still must be set up in phpbb_seo/includes/setup_phpbb_seo.php, since changing these implies an .htaccess update and most likely appropriate redirections.%3$s', + 'ACP_PHPBB_SEO_CLASS_EXPLAIN' => 'Here you can set up various options of the phpBB SEO %1$s mod (%2$s).
The various default settings such as the delimiters and suffixes still must be set up in phpBB/ext/phpbbseo/usu/customise.php, since changing these implies an .htaccess update and most likely appropriate redirections.%3$s', 'ACP_PHPBB_SEO_VERSION' => 'Version', 'ACP_PHPBB_SEO_MODE' => 'Mode', 'ACP_SEO_SUPPORT_FORUM' => 'Support Forum', diff --git a/language/en/info_acp_usu.php b/language/en/info_acp_usu.php index 4c74f5f..6553617 100644 --- a/language/en/info_acp_usu.php +++ b/language/en/info_acp_usu.php @@ -41,6 +41,7 @@ 'ACP_FORUM_URL' => 'Forum URL Management', 'ACP_HTACCESS' => '.htaccess', 'ACP_SEO_EXTENDED' => 'Extended config', + 'ACP_SYNC_URL' => 'URL Synchronization', 'ACP_PREMOD_UPDATE' => '

Release announcement

This update does only concern the premod, not the phpBB core.

A new version of the phpBB SEO premod is thus available : %1$s
Make sure you visitthe release thread and update your installation.

', diff --git a/language/fr/acp_usu.php b/language/fr/acp_usu.php index 176a660..1655c6d 100644 --- a/language/fr/acp_usu.php +++ b/language/fr/acp_usu.php @@ -40,7 +40,7 @@ 'ACP_MOD_REWRITE' => 'Réécriture d’URL', // ACP phpbb seo class 'ACP_PHPBB_SEO_CLASS' => 'Configuration de la classe phpBB SEO', - 'ACP_PHPBB_SEO_CLASS_EXPLAIN' => 'Vous pouvez régler ici différentes options du mod phpBB SEO %1$s (%2$s).
Les réglages par défaut comme les délimiteurs et les extensions doivent toujours être configurés dans le fichier phpbb_seo/includes/setup_phpbb_seo.php, les modifier implique un changement de .htaccess ainsi que des redirections appropriées.%3$s', + 'ACP_PHPBB_SEO_CLASS_EXPLAIN' => 'Vous pouvez régler ici différentes options du mod phpBB SEO %1$s (%2$s).
Les réglages par défaut comme les délimiteurs et les extensions doivent toujours être configurés dans le fichier phpBB/ext/phpbbseo/usu/customise.php, les modifier implique un changement de .htaccess ainsi que des redirections appropriées.%3$s', 'ACP_PHPBB_SEO_VERSION' => 'Version', 'ACP_PHPBB_SEO_MODE' => 'Mode', 'ACP_SEO_SUPPORT_FORUM' => 'Forum de support', diff --git a/language/fr/info_acp_usu.php b/language/fr/info_acp_usu.php index e86f1fa..ae7ca35 100644 --- a/language/fr/info_acp_usu.php +++ b/language/fr/info_acp_usu.php @@ -41,6 +41,7 @@ 'ACP_FORUM_URL' => 'Configuration des URLs des forums', 'ACP_HTACCESS' => '.htaccess', 'ACP_SEO_EXTENDED' => 'Configuration additionnelle', + 'ACP_SYNC_URL' => 'Synchronisation des URLs', 'ACP_PREMOD_UPDATE' => '

Annonce de mise à jour

Cette mise à jour ne concerne que la premod, pas phpBB lui même.

Une nouvelle version de la premod phpBB SEO est donc disponible : %1$s
Veuillez vous rendre sur le sujet de mise à disposition pour procéder à la mise à jour.

', diff --git a/migrations/release_2_0_0_b2.php b/migrations/release_2_0_0_b2.php new file mode 100644 index 0000000..fa95c86 --- /dev/null +++ b/migrations/release_2_0_0_b2.php @@ -0,0 +1,49 @@ +config['seo_usu_version'])) + { + return version_compare($this->config['seo_usu_version'], '2.0.0-b2', '>='); + } + + return false; + } + + static public function depends_on() + { + return array('\phpbbseo\usu\migrations\release_2_0_0_b1'); + } + + public function update_data() + { + return array( + array('config.add', array('seo_usu_version', '2.0.0-b2')), + array( + 'module.add', + array( + 'acp', + 'ACP_MOD_REWRITE', + array( + 'module_basename' => '\phpbbseo\usu\acp\usu', + 'module_langname' => 'ACP_SYNC_URL', + 'module_mode' => 'sync_url', + 'module_auth' => 'ext_phpbbseo/usu && acl_a_board', + ), + ) + ), + ); + } +} From 8a75f1fe1d42d4b95c64718c1cd7ddfe1dd899ff Mon Sep 17 00:00:00 2001 From: dcz Date: Mon, 8 Sep 2014 16:16:13 +0200 Subject: [PATCH 2/2] [ticket/37] one elseif slept through ... --- acp/usu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acp/usu.php b/acp/usu.php index 4885eb8..e4cf0ce 100644 --- a/acp/usu.php +++ b/acp/usu.php @@ -514,7 +514,7 @@ function main($id, $mode) trigger_error($user->lang['SYNC_COMPLETE'] . sprintf($user->lang['RETURN_INDEX'], '

', '')); } } - elseif ($sync_url === 'reset') + else if ($sync_url === 'reset') { if (confirm_box(true)) {