1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

Issue #933 - real SEF URLs added to forum. (work-in-progress)

This commit is contained in:
Cameron 2015-04-25 12:57:00 -07:00
parent 1e12220959
commit 542b30892f
8 changed files with 102 additions and 27 deletions

View File

@ -2616,9 +2616,27 @@ class e107
$tmp = e107::getAddonConfig('e_url');
$tp = e107::getParser();
if(varset($tmp[$plugin][$key]['sef']))
{
if(deftrue('e_MOD_REWRITE')) // Search-Engine-Friendly URLs active.
preg_match_all('#{([a-z_]*)}#', $tmp[$plugin][$key]['sef'],$matches);
$active = true;
foreach($matches[1] as $k=>$v) // check if a field value is missing, if so, revent to legacy url.
{
if(!isset($row[$v]))
{
e107::getMessage()->addDebug("Missing value for ".$v." in ".$plugin."/e_url.php - '".$key."'");
$active = false;
break;
}
}
if(deftrue('e_MOD_REWRITE') && ($active == true)) // Search-Engine-Friendly URLs active.
{
$rawUrl = $tp->simpleParse($tmp[$plugin][$key]['sef'], $row);
@ -2634,21 +2652,23 @@ class e107
else // Legacy URL.
{
preg_match_all('#({[a-z_]*})#', $tmp[$plugin][$key]['sef'],$matches);
$srch = array();
$repl = array();
foreach($matches[1] as $k=>$val)
foreach($matches[0] as $k=>$val)
{
$srch[] = '$'.($k+1);
$repl[] = $val;
}
$urlTemplate = str_replace($srch,$repl,$tmp[$plugin][$key]['redirect']);
$template = isset($tmp[$plugin][$key]['legacy']) ? $tmp[$plugin][$key]['legacy'] : $tmp[$plugin][$key]['redirect'];
$urlTemplate = str_replace($srch,$repl, $template);
$urlTemplate = $tp->replaceConstants($urlTemplate, $mode);
$legacyUrl = $tp->simpleParse($urlTemplate, $row);
$legacyUrl = preg_replace('/&?\$[\d]/i', "", $legacyUrl); // remove any left-over $x (including prefix of '&')
return $legacyUrl;
}

View File

@ -32,18 +32,18 @@ class forum_url // plugin-folder + '_url'
);
$config['topic'] = array(
'regex' => '^forum/(.*)/(.*)$',
'sef' => 'forum/{forum_sef}/{topic_sef}',
'redirect' => '{e_PLUGIN}forum/forum_viewtopic.php?id=$1'
'regex' => '^forum/(.*)/(\d*)-([\w-]*)/?\??(.*)',
'sef' => 'forum/{forum_sef}/{thread_id}-{thread_sef}',
'redirect' => '{e_PLUGIN}forum/forum_viewtopic.php?id=$2&$4'
);
$config['forum'] = array(
'regex' => '^forum/(.*)$',
'sef' => 'forum/{forum_sef}',
'redirect' => '{e_PLUGIN}forum/forum_viewforum.php?id=$1'
'redirect' => '{e_PLUGIN}forum/forum_viewforum.php?sef=$1',
'legacy' => '{e_PLUGIN}forum/forum_viewforum.php?id={forum_id}'
);
return $config;

View File

@ -335,8 +335,11 @@ function parse_forum($f, $restricted_string = '')
}
$f['forum_name'] = $tp->toHTML($f['forum_name'], true, 'no_hook');
$f['forum_description'] = $tp->toHTML($f['forum_description'], true, 'no_hook');
$fVars->FORUMNAME = "<a href='".$e107->url->create('forum/forum/view', $f)."'>{$f['forum_name']}</a>";
//$url= $e107->url->create('forum/forum/view', $f);
$url = e107::url('forum', 'forum', $f);
$fVars->FORUMNAME = "<a href='".$url."'>{$f['forum_name']}</a>";
$fVars->FORUMDESCRIPTION = $f['forum_description'].($restricted_string ? "<br /><span class='smalltext'><i>$restricted_string</i></span>" : "");
$fVars->THREADS = $f['forum_threads'];
$fVars->REPLIES = $f['forum_replies'];

View File

@ -126,8 +126,11 @@ if(deftrue('NEW_FORUMADMIN'))
protected $fields = array ( 'checkboxes' => array ( 'title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect', ),
'forum_id' => array ( 'title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'forum_name' => array ( 'title' => LAN_TITLE, 'type' => 'method', 'inline'=>true, 'data' => 'str', 'width' => '40%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'forum_description' => array ( 'title' => LAN_DESCRIPTION, 'type' => 'textarea', 'data' => 'str', 'width' => '30%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'forum_parent' => array ( 'title' => 'Parent', 'type' => 'dropdown', 'data' => 'int', 'width' => '10%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'forum_sef' => array ( 'title' => LAN_SEFURL, 'type' => 'text', 'inline'=>true, 'noedit'=>false, 'data' => 'str', 'width' => 'auto', 'help' => 'Leave blank to auto-generate it from the title above.', 'readParms' => '', 'writeParms' => 'size=xxlarge', 'class' => 'left', 'thclass' => 'left', ),
'forum_description' => array ( 'title' => LAN_DESCRIPTION, 'type' => 'textarea', 'data' => 'str', 'width' => '30%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'forum_parent' => array ( 'title' => 'Parent', 'type' => 'dropdown', 'data' => 'int', 'width' => '10%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'forum_sub' => array ( 'title' => 'SubForum of', 'type' => 'dropdown', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ),
'forum_moderators' => array ( 'title' => 'Moderators', 'type' => 'userclass', 'inline'=>true, 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => 'classlist=admin,main,classes', 'writeParms' => "classlist=admin,main,classes", 'class' => 'left', 'thclass' => 'left', ),
'forum_threads' => array ( 'title' => 'Threads', 'type' => 'number', 'data' => 'int', 'noedit'=>true, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ),
@ -143,7 +146,8 @@ if(deftrue('NEW_FORUMADMIN'))
// 'Sort' => array ( 'title' => 'Sort', 'type' => 'text', 'data' => 'str', 'noedit'=>true, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ),
'forum_options' => array ( 'title' => 'Options', 'type' => 'hidden', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ),
'options' => array ( 'title' => LAN_OPTIONS, 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1', 'sort'=>1 ),
'options' => array ( 'title' => LAN_OPTIONS, 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1', 'sort'=>1 ),
);
protected $fieldpref = array('forum_name', 'forum_parent', 'Sort', 'forum_description', 'forum_class', 'forum_postclass', 'forum_threadclass', 'forum_order');
@ -334,6 +338,12 @@ if(deftrue('NEW_FORUMADMIN'))
$parentOrder = $sql->retrieve('forum','forum_order','forum_id='.$new_data['forum_parent']." LIMIT 1");
$new_data['forum_order'] = $parentOrder + 50;
if(empty($new_data['forum_sef']))
{
$new_data['forum_sef'] = eHelper::title2sef($new_data['forum_name']);
}
return $new_data;
}
@ -352,7 +362,12 @@ if(deftrue('NEW_FORUMADMIN'))
public function beforeUpdate($new_data, $old_data, $id)
{
// return $new_data;
if(empty($new_data['forum_sef']))
{
$new_data['forum_sef'] = eHelper::title2sef($new_data['forum_name']);
}
return $new_data;
}
public function afterUpdate($new_data, $old_data, $id)

View File

@ -726,7 +726,12 @@ class e107forum
$e107 = e107::getInstance();
$info = array();
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$threadInfo['thread_sef'] = eHelper::title2sef($threadInfo['thread_name']);
$info['data'] = $threadInfo;
if($newThreadId = e107::getDb()->insert('forum_thread', $info))
{
e107::getEvent()->trigger('user_forum_topic_created', $info);
@ -782,6 +787,8 @@ class e107forum
function threadUpdate($threadId, $threadInfo)
{
$info = array();
$threadInfo['thread_sef'] = eHelper::title2sef($threadInfo['thread_name']);
$info['data'] = $threadInfo;
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$info['WHERE'] = 'thread_id = '.(int)$threadId;
@ -1530,15 +1537,22 @@ class e107forum
}
return $ret;
}
/**
* @param $forumId
* @param $from
* @param $view
* @return array
*/
function forumGetThreads($forumId, $from, $view)
{
$e107 = e107::getInstance();
$sql = e107::getDb();
$forumId = (int)$forumId;
$qry = "
SELECT t.*, u.user_name, lpu.user_name AS lastpost_username from `#forum_thread` as t
SELECT t.*, f.forum_id, f.forum_sef, u.user_name, lpu.user_name AS lastpost_username from `#forum_thread` as t
LEFT JOIN `#forum` AS f ON t.thread_forum_id = f.forum_id
LEFT JOIN `#user` AS u ON t.thread_user = u.user_id
LEFT JOIN `#user` AS lpu ON t.thread_lastuser = lpu.user_id
WHERE t.thread_forum_id = {$forumId}
@ -1876,14 +1890,14 @@ class e107forum
$forum_sub_parent = (substr($forumInfo['sub_parent'], 0, 1) == '*' ? substr($forumInfo['sub_parent'], 1) : $forumInfo['sub_parent']);
}
$breadcrumb[] = array('text'=>$tp->toHTML($forumInfo['parent_name']) , 'url'=> e107::getUrl()->create('forum/forum/main')."#".$frm->name2id($forumInfo['parent_name']));
$breadcrumb[] = array('text'=>$tp->toHTML($forumInfo['parent_name']) , 'url'=> e107::url('forum', 'index')."#".$frm->name2id($forumInfo['parent_name']));
if($forumInfo['forum_sub'])
{
$breadcrumb[] = array('text'=> ltrim($forumInfo['sub_parent'], '*') , 'url'=> e107::getUrl()->create('forum/forum/view', "id={$forumInfo['forum_sub']}"));
}
$breadcrumb[] = array('text'=>ltrim($forumInfo['forum_name'], '*') , 'url'=> (e_PAGE !='forum_viewforum.php') ? e107::getUrl()->create('forum/forum/view', $forumInfo) : null);
$breadcrumb[] = array('text'=>ltrim($forumInfo['forum_name'], '*') , 'url'=> (e_PAGE !='forum_viewforum.php') ? e107::url('forum', 'forum', $forumInfo) : null);
if(vartrue($forumInfo['thread_name']))
{

View File

@ -16,6 +16,7 @@ CREATE TABLE forum (
`forum_postclass` smallint(5) NOT NULL default '0',
`forum_threadclass` smallint(5) NOT NULL default '0',
`forum_options` text,
`forum_sef` varchar(250) default NULL,
PRIMARY KEY (`forum_id`),
KEY `forum_parent` (`forum_parent`),
KEY `forum_sub` (`forum_sub`)
@ -36,6 +37,7 @@ CREATE TABLE forum_thread (
`thread_lastuser_anon` varchar(30) default NULL,
`thread_total_replies` int(10) unsigned NOT NULL default '0',
`thread_options` text,
`thread_sef` varchar(250) default NULL,
PRIMARY KEY (`thread_id`),
KEY `thread_forum_id` (`thread_forum_id`),
KEY `thread_sticky` (`thread_sticky`),

View File

@ -10,7 +10,10 @@
*
*/
require_once('../../class2.php');
if(!defined('e107_INIT'))
{
require_once('../../class2.php');
}
$e107 = e107::getInstance();
if (!$e107->isInstalled('forum'))
{
@ -28,12 +31,17 @@ if (isset($_POST['fjsubmit']))
exit;
}
if (!e_QUERY)
if (!e_QUERY && empty($_GET))
{
header('Location:'.e107::getUrl()->create('forum/forum/main', array(), 'full=1&encode=0'));
exit;
}
if(!empty($_GET['sef']))
{
$_REQUEST['id'] = $sql->retrieve('forum', 'forum_id', "forum_sef= '".$tp->toDB($_GET['sef'])."' LIMIT 1");
}
require_once(e_PLUGIN.'forum/forum_class.php');
$forum = new e107forum;
@ -52,6 +60,7 @@ $fVars->REPLYTITLE = LAN_FORUM_0003;
$fVars->LASTPOSTITLE = LAN_FORUM_0004;
$fVars->VIEWTITLE = LAN_FORUM_1005;
$forumId = (int)$_REQUEST['id'];
if(!$forumId && e_QUERY) // BC Fix for old links.
@ -485,7 +494,14 @@ function parse_thread($thread_info)
{
$title = '';
}
$tVars->THREADNAME = "<a {$title} href='".e107::getUrl()->create('forum/thread/view', array('id' => $threadId, 'name' => $thread_name))."'>{$thread_name}</a>";
// $tVars->THREADNAME = "<a {$title} href='".e107::getUrl()->create('forum/thread/view', array('id' => $threadId, 'name' => $thread_name))."'>{$thread_name}</a>";
// $url = e107::getUrl()->create('forum/thread/view', array('id' => $threadId, 'name' => $thread_name));
$url = e107::url('forum','topic', $thread_info);
$tVars->THREADNAME = "<a {$title} href='".$url."'>{$thread_name}</a>";
// FIXME - pages -> convert to nextprev shortcode
$pages = ceil(($tVars->REPLIES)/$forum->prefs->get('postspage'));
$urlparms = $thread_info;

View File

@ -10,7 +10,11 @@
*
*/
require_once ('../../class2.php');
if(!defined('e107_INIT'))
{
require_once('../../class2.php');
}
define('NAVIGATION_ACTIVE','forum');
$e107 = e107::getInstance();
@ -197,7 +201,6 @@ if(is_array($FORUM_VIEWTOPIC_TEMPLATE) && deftrue('BOOTSTRAP',false))
}
// get info for main thread -------------------------------------------------------------------------------------------------------------------------------------------------------------------
$tVars = new e_vars;
$forum->set_crumb(true, '', $tVars); // Set $BREADCRUMB (and BACKLINK)
@ -242,7 +245,9 @@ $tVars->THREADSTATUS = (!$thread->threadInfo['thread_active'] ? LAN_FORUM_2004 :
if ($thread->pages > 1)
{
if(!$thread->page) $thread->page = 1;
$url = rawurlencode(e107::getUrl()->create('forum/thread/view', array('name' => $thread->threadInfo['thread_name'], 'id' => $thread->threadId, 'page' => '[FROM]')));
// $url = rawurlencode(e107::getUrl()->create('forum/thread/view', array('name' => $thread->threadInfo['thread_name'], 'id' => $thread->threadId, 'page' => '[FROM]')));
$url = e_REQUEST_SELF."?p=[FROM]"; // SEF URL Friendly.
$parms = "total={$thread->pages}&type=page&current={$thread->page}&url=".$url."&caption=off&tmpl=default&navcount=4&glyphs=1";
//XXX FIXME - pull-down template not practical here. Can we force another?