1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 04:38:27 +01:00

FAQs enhancement and support for faq-category SEF urls. (work in progress)

This commit is contained in:
Cameron 2015-01-28 02:29:26 -08:00
parent fb22dc7b11
commit 05c8f263d1
7 changed files with 73 additions and 39 deletions

View File

@ -2578,20 +2578,24 @@ class e107
/**
* Experimental static (easy) sef-url creation method (works with e_url.php @see /index.php)
*/
public static function url($plugin='',$key)
public static function url($plugin='',$key, $row=array())
{
$tmp = e107::getAddonConfig('e_url');
$tp = e107::getParser();
if(varset($tmp[$plugin][$key]['sef']))
{
return e_HTTP.$tmp[$plugin][$key]['sef'];
$rawUrl = $tp->simpleParse($tmp[$plugin][$key]['sef'], $row);
return e_HTTP.$rawUrl;
}
/*
elseif(varset($tmp[$plugin][$key]['redirect']))
{
return self::getParser()->replaceConstants($tmp[$plugin][$key]['redirect'],'full');
}
return;
* */
}

View File

@ -72,7 +72,9 @@ class faq_cat_ui extends e_admin_ui
'faq_info_parent' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'width' => '5%', 'writeParms'=>''),
'faq_info_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int', 'inline'=>true),
'faq_info_metad' => array('title'=> LANA_FAQ_METAD, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readParms'=>'editable=1'),
'faq_info_metak' => array('title'=> LANA_FAQ_METAK, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readParms'=>'editable=1'),
'faq_info_metak' => array('title'=> LANA_FAQ_METAK, 'type' => 'tags', 'width' => 'auto', 'thclass' => 'left', 'readParms'=>'editable=1'),
'faq_info_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'inline'=>true, 'writeParms'=>'size=xxlarge'),
'faq_info_order' => array('title'=> LAN_ORDER, 'type' => 'number', 'width' => '5%', 'thclass' => 'left' ),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center','readParms'=>'sort=1')
);

View File

@ -25,12 +25,22 @@ class faqs_url // plugin-folder + '_url'
{
$config = array();
$config[] = array(
'regex' => '^faqs/?$',
'redirect' => '{e_PLUGIN}faqs/faqs.php',
$config['index'] = array(
'regex' => '^faqs/?$', // matched against url, and if true, redirected to 'redirect' below.
'sef' => 'faqs', // used by e107::url(); to create a url from the db table.
'redirect' => '{e_PLUGIN}faqs/faqs.php', // file-path of what to load when the regex returns true.
);
$config['category'] = array(
'regex' => '^faqs/(.*)$',
'sef' => 'faqs/{faq_info_sef}', // {faq_info_sef} is substituted with database value when parsed by e107::url();
'redirect' => '{e_PLUGIN}faqs/faqs.php?cat=$1'
);
return $config;
}
}

View File

@ -193,9 +193,9 @@ class faq
function __construct()
{
$sc = e107::getScBatch('faqs',TRUE);
$this->pref = e107::getPlugConfig('faqs')->getPref();
$this->pref = e107::pref('faqs'); // Short version of e107::getPlugConfig('faqs')->getPref(); ;
$sc->pref = $this->pref;
// setScVar('faqs_shortcodes', 'pref', $this->pref);
}
function view_all($srch) // new funtion to render all FAQs
@ -206,21 +206,6 @@ class faq
$template = e107::getTemplate('faqs');
$this->template = $template;
// print_a($template);
global $FAQ_START, $FAQ_END, $FAQ_LISTALL_START,$FAQ_LISTALL_LOOP,$FAQ_LISTALL_END;
if($FAQ_START)
{
}
//require_once (e_PLUGIN."faqs/faqs_shortcodes.php");
$prevcat = "";
@ -238,6 +223,8 @@ class faq
$text .= $tp->parseTemplate($template['end'], true, $this->sc);
$ret['title'] = FAQLAN_FAQ;
$ret['text'] = $text;
$ret['caption'] = varset($template['caption']) ? $tp->parseTemplate($template['caption'], true, $this->sc) : LAN_PLUGIN_FAQS_FRONT_NAME;
@ -254,14 +241,18 @@ class faq
$sql = e107::getDb();
$tp = e107::getParser();
$insert = "";
if(!empty($srch))
{
$srch = $tp->toDB($srch);
$insert = " AND (f.faq_question LIKE '%".$srch."%' OR FIND_IN_SET ('".$srch."', f.faq_tags) ) ";
}
else
if(!empty($_GET['cat']))
{
$insert = "";
$srch = $tp->toDB($_GET['cat']);
$insert = " AND (cat.faq_info_sef = '".$srch."') ";
}
$query = "SELECT f.*,cat.* FROM #faqs AS f LEFT JOIN #faqs_info AS cat ON f.faq_parent = cat.faq_info_id WHERE cat.faq_info_class IN (".USERCLASS_LIST.") ".$insert." ORDER BY cat.faq_info_order,f.faq_order ";
@ -270,32 +261,45 @@ class faq
{
return "<div class='alert alert-warning alert-block'><b>".$srch."</b> was not found in search results.</div>" ; //TODO LAN
}
$text = '';
// -----------------
$FAQ_START = e107::getTemplate('faqs', true, 'start');
$FAQ_END = e107::getTemplate('faqs', true, 'end');
$FAQ_LISTALL = e107::getTemplate('faqs', true, 'all');
$FAQ_CAPTION = e107::getTemplate('faqs', true, 'caption');
$prevcat = "";
$sc = e107::getScBatch('faqs', true);
$sc->counter = 1;
$sc->tag = htmlspecialchars($tag, ENT_QUOTES, 'utf-8');
$sc->category = $category;
$text = $tp->parseTemplate($FAQ_START, true, $sc);
while ($rw = $sql->fetch())
{
$this->sc->setVars($rw);
$sc->setVars($rw);
if($rw['faq_info_order'] != $prevcat)
{
if($prevcat !='')
{
$text .= $tp->parseTemplate($template['all']['end'], true, $this->sc);
$text .= $tp->parseTemplate($FAQ_LISTALL['end'], true, $sc);
}
$text .= "\n\n<!-- FAQ Start ".$rw['faq_info_order']."-->\n\n";
$text .= $tp->parseTemplate($this->template['all']['start'], true, $this->sc);
$text .= $tp->parseTemplate($FAQ_LISTALL['start'], true, $sc);
$start = TRUE;
}
$text .= $tp->parseTemplate($this->template['all']['item'], true, $this->sc);
$text .= $tp->parseTemplate($FAQ_LISTALL['item'], true, $sc);
$prevcat = $rw['faq_info_order'];
$sc->counter++;
}
$text .= $tp->parseTemplate($this->template['all']['end'], true, $this->sc);
$text .= ($start) ? $tp->parseTemplate($FAQ_LISTALL['end'], true, $sc) : "";
$text .= $tp->parseTemplate($FAQ_END, true, $sc);
return $text;
}

View File

@ -121,6 +121,19 @@ class faqs_shortcodes extends e_shortcode
function sc_faq_category($parm = '')
{
// $tp = e107::getParser();
// return $tp->toHTML($this->var['faq_info_title']);
$tp = e107::getParser();
$url = e107::url('faqs','category', $this->var); //@See faqs/e_url.php
return "<a href='".$url."'>".$tp->toHTML($this->var['faq_info_title'])."</a>";
return "<a href='".e107::getUrl()->create('faqs/list/all', array('category' => $this->var['faq_info_id']))."'>".$tp->toHTML($this->var['faq_info_title'])."</a>";
$tp = e107::getParser();
if($parm == 'extend' && $this->tag)
{

View File

@ -21,6 +21,7 @@ CREATE TABLE faqs_info (
faq_info_icon varchar(255) NOT NULL default '',
faq_info_metad varchar(255) NOT NULL default '',
faq_info_metak varchar(255) NOT NULL default '',
faq_info_sef varchar(255) NOT NULL default '',
PRIMARY KEY (faq_info_id)
) ENGINE=MyISAM;

View File

@ -120,7 +120,7 @@
parse_str($query,$_GET);
}
e107::getMessage()->addDebug('e_URL in <b>'.$plug.'</b> matched <b>'.$v['regex'].'</b> and included: <b>'.$file.'</b> with $_GET: '.print_a($_GET,true));
e107::getMessage()->addDebug('e_URL in <b>'.$plug.'</b> with key: <b>'.$k.'</b> matched <b>'.$v['regex'].'</b> and included: <b>'.$file.'</b> with $_GET: '.print_a($_GET,true));
if(file_exists($file))
{