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

FAQs enhancements and fixes. FAQ search menu added.

This commit is contained in:
Cameron 2015-06-07 18:15:23 -07:00
parent 12ec43161b
commit 590df058b3
10 changed files with 240 additions and 87 deletions

View File

@ -1131,7 +1131,7 @@ class e_admin_dispatcher
return false;
}
if(!empty($this->perm) && is_array($this->perm) && !e107::getUser()->checkAdminPerms($this->perm[$route]))
if(is_array($this->perm) && !empty($this->perm[$route]) && !e107::getUser()->checkAdminPerms($this->perm[$route]))
{
return false;
}

View File

@ -50,7 +50,7 @@ class faq_admin extends e_admin_dispatcher
protected $perm = array(
'main/prefs' => '0'
// 'main/prefs' => '0'
);
protected $adminMenuAliases = array(
@ -74,10 +74,12 @@ class faq_admin extends e_admin_dispatcher
'main/create' => varset($pref['admin_faq_create'], e_UC_ADMIN),
'main/edit' => varset($pref['admin_faq_edit'], e_UC_ADMIN),
'main/delete' => varset($pref['admin_faq_delete'], e_UC_ADMIN),
'cat/list' => check_class($pref['admin_cat_create']) || check_class($pref['admin_cat_edit']) ? e_UC_ADMIN : e_UC_NOBODY,
'cat/create' => varset($pref['admin_cat_create'], e_UC_ADMIN),
'cat/edit' => varset($pref['admin_cat_edit'], e_UC_ADMIN),
'cat/delete' => varset($pref['admin_cat_delete'], e_UC_ADMIN),
);
}
}
@ -243,9 +245,12 @@ class faq_main_ui extends e_admin_ui
'classic_look' => array('title'=> LANA_FAQ_PREF_3,'tab'=>0, 'type'=>'boolean' ),
'list_type' => array('title'=> "List Type", 'tab'=>0,'type'=>'dropdown', 'writeParms'=>array('ul'=>'Unordered List', 'ol'=>'Ordered List') ),
'page_title' => array('title'=> "Page Title", 'tab'=>0,'type'=>'text', 'help'=>'Leave blank to use default' ),
'page_title' => array('title'=> "Page Title", 'tab'=>0,'type'=>'text', 'multilan'=>true, 'help'=>'Leave blank to use default' ),
'new' => array('title'=> "'New' FAQs are no more than", 'tab'=>0,'type'=>'number', 'writeParms'=>'size=mini&default=0&post=days old', 'help'=>'Leave blank to use default' ),
'display_total' => array('title'=> "Display FAQ total", 'tab'=>0,'type'=>'boolean' ),
'display_total' => array('title'=> "Display FAQ total", 'tab'=>0,'type'=>'boolean', 'data'=>'int' ),
'display_datestamp' => array('title'=> "Display Datestamp", 'tab'=>0,'type'=>'boolean', 'data'=>'int' ),
'display_social' => array('title'=> "Display Social buttons", 'tab'=>0,'type'=>'boolean', 'data'=>'int' ),
'orderby' => array('title'=> LAN_ORDER, 'tab'=>0,'type'=>'dropdown', 'writeParms'=>array('faq_order-ASC'=>"Specified Order", 'faq_id-ASC'=>'ID ASC', 'faq_id-DESC'=>'ID DESC', 'faq_datestamp-ASC'=>'Date ASC', 'faq_datestamp-DESC'=>'Date DESC')),
'admin_faq_create' => array('title'=> "Create FAQ", 'tab'=>1, 'type'=>'userclass', 'writeParms'=>'default=254&classlist=main,admin,classes,no-excludes' ),

View File

@ -17,7 +17,8 @@
if (!defined('e107_INIT')) { exit; }
// v2.x Standard - Simple mod-rewrite module.
// v2.x Standard - Simple mod-rewrite module.
// https://moz.com/blog/11-best-practices-for-urls
class faqs_url // plugin-folder + '_url'
{
@ -32,12 +33,28 @@ class faqs_url // plugin-folder + '_url'
);
$config['item'] = array(
'regex' => '^faqs/(\d*)-(.*)$$',
'sef' => 'faqs/{faq_id}-{faq_sef}', // {faq_info_sef} is substituted with database value when parsed by e107::url();
'redirect' => '{e_PLUGIN}faqs/faqs.php?id=$1'
);
$config['search'] = array(
'regex' => '^faqs/\?srch=(.*)$', // 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?srch=$1', // file-path of what to load when the regex returns true.
);
$config['tag'] = array(
'regex' => '^faqs/tag/(.*)$',
'sef' => 'faqs/tag/{tag}', // {faq_info_sef} is substituted with database value when parsed by e107::url();
'redirect' => '{e_PLUGIN}faqs/faqs.php?tag=$1'
);
$config['category'] = array(
'regex' => '^faqs/(.*)$',
'sef' => 'faqs/{faq_info_sef}', // {faq_info_sef} is substituted with database value when parsed by e107::url();

View File

@ -1,65 +1,77 @@
.faq-start {
.faq-start
{
}
.faq-submit-question-container
{
margin-top:20px;
margin-left:30px;
}
div.faq-tags { font-size: 80%; text-align:right }
.faq-submit-question-container {
margin-top: 20px;
margin-left: 30px;
}
a.faq-submit-question
{
text-align:right;
div.faq-extras {
text-align: right;
margin-top: 10px
}
div.faq-tags {
font-size: 80%;
display: inline-block;
padding-right: 10px;
}
div.faq-datestamp {
font-size: 80%;
display: inline-block;
padding-right: 15px;
}
div.faq-share {
display: inline-block;
}
a.faq-submit-question {
text-align: right;
float: right;
margin-top:-50px;
margin-bottom: 10px;
}
.faq-submit-question-form
{
margin-top:20px;
margin-bottom: 10px;
}
.faq-search
{
padding:20px;
}
.faq-listall-category
{
}
.faq-listall-container
{
}
li.faq-listall-loop
{
list-style: circle outside;
margin-bottom: 8px;
}
.faq-question
{
margin-top: -50px;
margin-bottom: 10px;
}
.faq-question.faq-new { font-weight: bold; }
.faq-submit-question-form {
margin-top: 20px;
margin-bottom: 10px;
.faq-answer
{
margin:20px 0px;
border:1px solid #DDDDDD;
background-color: #F5F5F5;
padding:10px;
border-radius: 5px;
}
.faq-search {
padding: 20px;
}
.faq-listall-category {
}
.faq-listall-container {
}
li.faq-listall-loop {
list-style: circle outside;
margin-bottom: 8px;
}
.faq-question {
}
.faq-question.faq-new {
font-weight: bold;
}
.faq-answer {
margin: 20px 0px;
border: 1px solid #DDDDDD;
background-color: #F5F5F5;
padding: 10px;
border-radius: 5px;
}

View File

@ -141,15 +141,38 @@ if (isset($_POST['commentsubmit']))
}
$pageTitle = '';
// define("e_PAGETITLE", $ftmp['caption']);
if (vartrue($faqpref['page_title']))
{
define("e_PAGETITLE", $faqpref['page_title']);
$pageTitle = $faqpref['page_title'][e_LANGUAGE];
}
else
{
define("e_PAGETITLE", $ftmp['caption']);
$pageTitle = $ftmp['caption'];
}
if(!empty($ftmp['pagetitle']))
{
$pageTitle .= ": ".$ftmp['pagetitle'];
}
e107::getMessage()->addDebug("TITLE: " . $pageTitle);
e107::meta('og:title', $pageTitle);
if(!empty($ftmp['pagedescription']))
{
e107::meta('og:description', $ftmp['pagedescription']);
}
define('e_PAGETITLE', $pageTitle);
require_once (HEADERF);
$ns->tablerender($ftmp['caption'], $ftmp['text']);
@ -192,6 +215,8 @@ class faq
var $pref = array();
protected $sc = null;
protected $template = null;
protected $pageTitle = null;
protected $pageDescription = null;
function __construct()
{
@ -266,15 +291,24 @@ class faq
$ret['title'] = FAQLAN_FAQ;
$ret['text'] = $text;
if (!empty($this->pref['page_title']))
if (!empty($this->pref['page_title'][e_LANGUAGE]))
{
$ret['caption'] = e107::getParser()->toHtml($this->pref['page_title'], true, 'TITLE');
$ret['caption'] = e107::getParser()->toHtml($this->pref['page_title'][e_LANGUAGE], true, 'TITLE');
}
else
{
$ret['caption'] = varset($template['caption']) ? $tp->parseTemplate($template['caption'], true, $this->sc) : LAN_PLUGIN_FAQS_FRONT_NAME;
}
if(!empty($this->pageTitle))
{
$ret['pagetitle'] = e107::getParser()->toText($this->pageTitle);
}
if(!empty($this->pageDescription))
{
$ret['pagedescription'] = e107::getParser()->toText($this->pageDescription,true,'RAWTEXT');
}
return $ret;
}
@ -288,12 +322,28 @@ class faq
$text = "";
$insert = "";
$insert = "";
$item = false;
$removeUrl = e107::url('faqs','index');
if(!empty($srch))
{
$srch = $tp->toDB($srch);
$insert = " AND (f.faq_question LIKE '%".$srch."%' OR FIND_IN_SET ('".$srch."', f.faq_tags) ) ";
$insert = " AND (f.faq_question LIKE '%".$srch."%' OR f.faq_answer LIKE '%".$srch."%' OR FIND_IN_SET ('".$srch."', f.faq_tags) ) ";
$message = "<span class='label label-lg label-info'>".$srch." <a class='e-tip' title='Remove' href='".$removeUrl."'>×</a></span>";
e107::getMessage()->setClose(false,E_MESSAGE_INFO)->setTitle(LAN_FAQS_FILTER_ACTIVE,E_MESSAGE_INFO)->addInfo($message);
$text = e107::getMessage()->render();
}
if(!empty($_GET['id'])) // pull out just one specific FAQ.
{
$srch = intval($_GET['id']);
// $insert = " AND (f.faq_id = ".$srch.") ";
$item = $srch;
}
if(!empty($_GET['cat']))
@ -309,7 +359,6 @@ class faq
$insert = " AND FIND_IN_SET ('".$srch."', f.faq_tags) ";
$removeUrl = e107::url('faqs','index');
$message = "<span class='label label-lg label-info'>".$srch." <a class='e-tip' title='Remove' href='".$removeUrl."'>×</a></span>";
e107::getMessage()->setClose(false,E_MESSAGE_INFO)->setTitle(LAN_FAQS_FILTER_ACTIVE,E_MESSAGE_INFO)->addInfo($message);
@ -323,7 +372,7 @@ class faq
if(!$sql->gen($query))
{
return "<div class='alert alert-warning alert-block'><b>".$srch."</b> was not found in search results.</div>" ; //TODO LAN
return "<div class='alert alert-warning alert-block'><b>".$srch."</b> was not found in search results. <a class='e-tip' title='Reset' href='".$removeUrl."'>Reset</a></div>" ; //TODO LAN
}
// -----------------
@ -336,6 +385,20 @@ class faq
$sc->tag = htmlspecialchars($tag, ENT_QUOTES, 'utf-8');
$sc->category = $category;
if(!empty($_GET['id'])) // expand one specific FAQ.
{
$sc->item =intval($_GET['id']);
$js = "
$( document ).ready(function() {
$('html, body').animate({ scrollTop: $('div#faq_".$sc->item."').offset().top - 300 }, 4000);
});
";
e107::js('footer-inline', $js);
}
// $text = $tp->parseTemplate($FAQ_START, true, $sc);
// $text = "";
@ -354,7 +417,15 @@ class faq
while ($rw = $sql->fetch())
{
$sc->setVars($rw);
$rw['faq_sef'] = eHelper::title2sef($rw['faq_question'],'dashl');
$sc->setVars($rw);
if($sc->item == $rw['faq_id'])
{
$this->pageTitle = $rw['faq_question'];
$this->pageDescription = $rw['faq_answer'];
}
if($rw['faq_info_order'] != $prevcat)
{

View File

@ -0,0 +1,13 @@
<?php
if (!defined('e107_INIT')) { exit; }
$sc = e107::getScBatch('faqs', true);
$text = $tp->parseTemplate("{FAQ_SEARCH}", true, $sc);
$ns->tablerender(LAN_PLUGIN_FAQS_SEARCH, $text, 'faqs-search-menu');
?>

View File

@ -24,6 +24,24 @@ if (!defined('e107_INIT')) { exit; }
class faqs_shortcodes extends e_shortcode
{
public $counter = 1;
public $item = false;
private $share = false;
private $datestamp = false;
function __construct()
{
$pref = e107::pref('faqs');
if(!empty($pref['display_social']) && e107::isInstalled('social')==true)
{
$this->share = true;
}
if(!empty($pref['display_datestamp']))
{
$this->datestamp = true;
}
}
// Simply FAQ count when needed.
function sc_faq_counter($parm='')
@ -47,17 +65,36 @@ class faqs_shortcodes extends e_shortcode
if($param == 'expand' && !empty($this->var['faq_answer']))
{
$tags = '';
$id = "faq_".$this->var['faq_id'];
$url = e107::url('faqs','item', $this->var, 'full');
$question = $tp->toHTML($this->var['faq_question'],true,'TITLE');
$hide = ($this->item != $this->var['faq_id']) ? 'e-hideme' : '';
$text = "
<a class='e-expandit faq-question{$faqNew}' href='#{$id}'>".$question."</a>
<div id='{$id}' class='".$hide." faq-answer faq_answer clearfix {$faqNew}'>";
$text .= $tp->toHTML($this->var['faq_answer'],true,'BODY');
$text .= "<div class='faq-extras'>";
if(vartrue($params['tags']) && $this->var['faq_tags'])
{
$tags = "<div class='faq-tags'>".LAN_FAQS_TAGS.": ".$this->sc_faq_tags()."</div>";
$text .= "<div class='faq-tags'>".LAN_FAQS_TAGS.": ".$this->sc_faq_tags()."</div>";
}
$id = "faq_".$this->var['faq_id'];
if($this->datestamp == true)
{
$text .= "<div class='faq-datestamp'>".$tp->toDate($this->var['faq_datestamp'])."</div>";
}
if($this->share == true)
{
$text .= "<div class='faq-share'>".$tp->parseTemplate("{SOCIALSHARE: size=xs&type=basic&url=".$url."&title=".$question."}",true)."</div>";
}
$text = "<a class='e-expandit faq-question{$faqNew}' href='#{$id}'>".$tp->toHTML($this->var['faq_question'],true,'TITLE')."</a>
<div id='{$id}' class='e-hideme faq-answer faq_answer clearfix {$faqNew}'>".$tp->toHTML($this->var['faq_answer'],true,'BODY').$tags."</div>
$text .= "</div></div>
";
}
@ -295,24 +332,20 @@ class faqs_shortcodes extends e_shortcode
function sc_faq_search($parm='')
{
if($parm == 'ajax') //TODo Ajax JS.
{
$frm = e107::getForm();
$tp = e107::getParser();
$target = e107::url('faqs','search');
$text = $frm->open('faq-search-form','get', e_REQUEST_SELF);
$text = $frm->open('faq-search-form','get', $target);
$text .= '<span class="input-group e-search">';
$text .= $frm->text('srch', $_GET['srch'], 20,'class=search-query&placeholder='.LAN_SEARCH).'
<span class="input-group-btn"><button class="btn btn-primary" type="submit">'.$tp->toGlyph('fa-search').'</button>';
$text .= '</span></span>';
$text .= $frm->close();
$text .= $frm->close();
return $text;
}
return ''; // UNDER CONSTRUCTION
// $tp = e107::getParser();
// return "<div style='text-align:center'><br />".$tp->parseTemplate("{SEARCH=faqs}")."</div>";
}

View File

@ -10,5 +10,6 @@ define("LAN_PLUGIN_FAQS_NAME", "FAQs");
define("LAN_PLUGIN_FAQS_DESCRIPTION", "A simple plugin to add Frequently Asked Questions to your website.");
define("LAN_PLUGIN_FAQS_FUNCTIONNAME", "FAQ Categories");
define("LAN_PLUGIN_FAQS_FRONT_NAME", "FAQ (Frequently Asked Questions)");
define("LAN_PLUGIN_FAQS_SEARCH", "FAQ Search");

View File

@ -22,5 +22,7 @@
<pref name="submit_question">255</pref>
<pref name="submit_question_limit">3</pref>
<pref name="classic_look">0</pref>
<pref name="display_social">1</pref>
<pref name="display_datestamp">1</pref>
</pluginPrefs>
</e107Plugin>

View File

@ -15,7 +15,6 @@ $FAQS_TEMPLATE['start'] = "
$FAQS_TEMPLATE['end'] = "
<div class='faq-submit-question'></div>
<div class='faq-search'>{FAQ_SEARCH}</div>
</div>
";
@ -25,7 +24,7 @@ $FAQS_TEMPLATE['all']['start'] = "
<ul class='faq-listall'>
";
$FAQS_TEMPLATE['all']['item'] = "
<li class='faq-listall'>{FAQ_QUESTION=expand|tags=1}</li>
<li class='faq-listall'>{FAQ_QUESTION=expand|tags=1|share=1}</li>
";
$FAQS_TEMPLATE['all']['end'] = "
</ul>