Skip to content

Commit

Permalink
Merge pull request #38 from dcz/ticket/37
Browse files Browse the repository at this point in the history
[ticket/37] Implement sync_url
  • Loading branch information
dcz committed Sep 8, 2014
2 parents d716b98 + 8a75f1f commit 5d5ea9d
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 51 deletions.
125 changes: 120 additions & 5 deletions acp/usu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -189,6 +191,7 @@ function main($id, $mode)
}

break;

case 'forum_url':
// used for cache
$this->write_type = 'forum';
Expand Down Expand Up @@ -306,6 +309,7 @@ function main($id, $mode)
}

break;

case 'htaccess':
$this->write_type = 'htaccess';
$display_vars['title'] = 'ACP_HTACCESS';
Expand Down Expand Up @@ -340,6 +344,7 @@ function main($id, $mode)
));

break;

case 'extended':
$display_vars = array(
'title' => 'ACP_SEO_EXTENDED',
Expand Down Expand Up @@ -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'] . '<br/><br/><b> &bull; <a href="' . append_sid($redirect_url, "go=1&amp;sync=sync") . '">' . $this->user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> &bull; <a href="' . append_sid($redirect_url, "go=1&amp;sync=reset") . '" >' . $this->user->lang['SYNC_RESET_TOPIC_URLS'] . '</a></b>');
}

$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'], '<br/>' . $url_updated);
}
$new_limit = ($duration < 10) ? $limit + 50 : $limit - 10;
meta_refresh(1, append_sid($redirect_url, 'go=1&amp;start=' . ($start + $limit) . "&amp;limit=$new_limit&amp;sync=sync"));
trigger_error("$message<br/>");
}
else
{
trigger_error($user->lang['SYNC_COMPLETE'] . sprintf($user->lang['RETURN_INDEX'], '<br/><br/><a href="' . append_sid($redirect_url) . '" >', '</a>'));
}
}
else if ($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'] . '<br/><br/><b> &bull; <a href="' . append_sid($redirect_url, "go=1&amp;sync=sync") . '">' . $user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> &bull; ' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($redirect_url) . '" >', '</a></b>'));
}
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'] . '<br/><br/><b> &bull; <a href="' . append_sid($redirect_url, "go=1&amp;sync=sync") . '">' . $user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> &bull; <a href="' . append_sid($redirect_url, "go=1&amp;sync=reset") . '" >' . $user->lang['SYNC_RESET_TOPIC_URLS'] . '</a></b>');
}
break;
default:
trigger_error('NO_MODE', E_USER_ERROR);
break;
Expand Down Expand Up @@ -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'], '<a href="' . $this->core->seo_path['phpbb_url'] . 'phpbb_seo/sync_url.' . $this->php_ext . '" onclick="window.open(this.href); return false;">', '</a>');
$additional_notes = sprintf($this->user->lang['SYNC_TOPIC_URL_NOTE'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=-phpbbseo-usu-acp-usu&amp;mode=sync_url') . '">', '</a>');

if ($db_tools->db->get_sql_error_triggered())
{
Expand Down Expand Up @@ -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')
Expand Down
7 changes: 6 additions & 1 deletion acp/usu_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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')
),
));
}
}
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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"
}
}
}
41 changes: 0 additions & 41 deletions core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
* <a href="http://www.phpbb-seo.com/" title="Search Engine Optimization">phpBB SEO</a>
*/
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&eacute;f&eacute;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 = '<br /><a href="http://www.phpbb-seo.com/" title="' . $this->seo_opt['copyrights']['title'] . '"><img src="' . $this->seo_path['phpbb_url'] . 'images/phpbb-seo.png" alt="' . $this->seo_opt['copyrights']['txt'] . '"/></a>';
}
else
{
$output = '<br /><a href="http://www.phpbb-seo.com/" title="' . $this->seo_opt['copyrights']['title'] . '">' . $this->seo_opt['copyrights']['txt'] . '</a>';
}

if ($return)
{
return $output;
}
else
{
$this->user->lang['TRANSLATION_INFO'] .= $output;
}

return;
}

// -> Cache functions
/**
* forum_id(&$forum_id, $forum_uri = '')
Expand Down
2 changes: 1 addition & 1 deletion language/en/acp_usu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).<br/>The various default settings such as the delimiters and suffixes still must be set up in <b>phpbb_seo/includes/setup_phpbb_seo.php</b>, 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).<br/>The various default settings such as the delimiters and suffixes still must be set up in <b>phpBB/ext/phpbbseo/usu/customise.php</b>, 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',
Expand Down
1 change: 1 addition & 0 deletions language/en/info_acp_usu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<h1>Release announcement</h1>
<p>This update does only concern the premod, not the phpBB core.</p>
<p>A new version of the phpBB SEO premod is thus available : %1$s<br/>Make sure you visit<a href="%2$s" title="The release thread"><b>the release thread</b></a> and update your installation.</p>',
Expand Down
2 changes: 1 addition & 1 deletion language/fr/acp_usu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).<br/>Les réglages par défaut comme les délimiteurs et les extensions doivent toujours être configurés dans le fichier <b>phpbb_seo/includes/setup_phpbb_seo.php</b>, 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).<br/>Les réglages par défaut comme les délimiteurs et les extensions doivent toujours être configurés dans le fichier <b>phpBB/ext/phpbbseo/usu/customise.php</b>, 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',
Expand Down
1 change: 1 addition & 0 deletions language/fr/info_acp_usu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<h1>Annonce de mise à jour</h1>
<p>Cette mise à jour ne concerne que la premod, pas phpBB lui même.</p>
<p>Une nouvelle version de la premod phpBB SEO est donc disponible : %1$s<br/>Veuillez vous rendre sur <a href="%2$s" title="Le sujet de mise à disposition"><b>le sujet de mise à disposition</b></a> pour procéder à la mise à jour.</p>',
Expand Down
49 changes: 49 additions & 0 deletions migrations/release_2_0_0_b2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
*
* @package Ultimate SEO URL phpBB SEO
* @version $$
* @copyright (c) 2014 www.phpbb-seo.com
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

namespace phpbbseo\usu\migrations;

class release_2_0_0_b2 extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
if (!empty($this->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',
),
)
),
);
}
}

0 comments on commit 5d5ea9d

Please sign in to comment.