1
0
mirror of https://github.com/e107inc/e107.git synced 2025-06-11 21:50:59 +02:00

FAQs now supports submitted questions from anonymous users and improved tag search/urls.

This commit is contained in:
Cameron
2015-03-31 06:26:06 -07:00
parent cae329a1f9
commit 24f2b22e6a
7 changed files with 124 additions and 41 deletions

View File

@ -40,6 +40,8 @@ class faq_admin extends e_admin_dispatcher
protected $adminMenu = array(
'main/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'),
'main/create' => array('caption'=> LAN_CREATE_ITEM, 'perm' => 'P'),
'main/followup' => array('caption'=> "Unanswered", 'perm' => 'P', 'uri'=>"admin_config.php?searchquery=&filter_options=faq_author__0&mode=main&action=list"),
'cat/list' => array('caption'=> LAN_CATEGORIES, 'perm' => 'P'),
'cat/create' => array('caption'=> LAN_CREATE_CATEGORY, 'perm' => 'P'),
'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => '0'),
@ -51,6 +53,8 @@ class faq_admin extends e_admin_dispatcher
);
protected $menuTitle = 'FAQs';
//
}
class faq_cat_ui extends e_admin_ui
@ -191,8 +195,10 @@ class faq_main_ui extends e_admin_ui
'faq_comment' => array('title'=> LANA_FAQ_COMMENT, 'tab' => 1, 'type' => 'userclass', 'data' => 'int', 'width' => 'auto', 'inline'=> true), // User id
'faq_datestamp' => array('title'=> LAN_DATE, 'tab' => 1, 'type' => 'datestamp', 'data'=> 'int','width' => 'auto', 'noedit' => false,'writeParms'=>'auto=1'),
'faq_author' => array('title'=> LAN_USER, 'tab' => 1, 'type' => 'user', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center', 'writeParms' => 'currentInit=1', 'filter' => true, 'batch' => true, 'nolist' => true ), // Photo
'u.user_name' => array('title'=> LANA_FAQ_UNAME, 'tab' => 1, 'type' => 'user', 'width' => 'auto', 'noedit' => true, 'readParms'=>'idField=faq_author&link=1'), // User name
'faq_author' => array('title'=> LAN_USER, 'tab' => 1, 'type' => 'user', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center', 'writeParms' => 'currentInit=1', 'filter' => true, 'batch' => true, 'nolist' => true ), // Photo
'faq_author_ip' => array('title'=> LAN_IP, 'tab' => 1, 'type' => 'ip', 'readonly'=>2, 'data'=> 'str', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center', 'writeParms' => 'currentInit=1', 'filter' => true, 'batch' => true, 'nolist' => true ), // Photo
'u.user_name' => array('title'=> LANA_FAQ_UNAME, 'tab' => 1, 'type' => 'user', 'width' => 'auto', 'noedit' => true, 'readParms'=>'idField=faq_author&link=1'), // User name
'u.user_loginname' => array('title'=> LANA_FAQ_ULOGINNAME, 'tab' => 1, 'type' => 'user', 'width' => 'auto', 'noedit' => true, 'readParms'=>'idField=faq_author&link=1'), // User login name
'faq_order' => array('title'=> LAN_ORDER, 'tab' => 1, 'type' => 'number', 'data'=> 'int','width' => '5%', 'thclass' => 'center','nolist' => false, 'noedit'=>false, 'readParms'=>'editable=1'),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center','readParms'=>'sort=1')

View File

@ -31,13 +31,21 @@ class faqs_url // plugin-folder + '_url'
'redirect' => '{e_PLUGIN}faqs/faqs.php', // 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();
'redirect' => '{e_PLUGIN}faqs/faqs.php?cat=$1'
);
return $config;
}

View File

@ -9,9 +9,14 @@
margin-top:20px;
margin-left:30px;
}
.faq-submit-question
div.faq-tags { font-size: 80%; text-align:right }
a.faq-submit-question
{
margin-top:20px;
text-align:right;
float: right;
margin-top:-50px;
margin-bottom: 10px;
}
@ -50,8 +55,9 @@ li.faq-listall-loop
.faq-answer
{
margin:20px;
border:1px solid silver;
background-color: #e3e3e3;
margin:20px 0px;
border:1px solid #DDDDDD;
background-color: #F5F5F5;
padding:10px;
border-radius: 5px;
}

View File

@ -27,7 +27,7 @@ if(file_exists(e_PLUGIN."faqs/controllers/list.php"))
}
else
{
include_lan(e_PLUGIN."faqs/languages/".e_LANGUAGE."/".e_LANGUAGE."_global.php");
e107::includeLan(e_PLUGIN."faqs/languages/".e_LANGUAGE."/".e_LANGUAGE."_front.php");
}
@ -49,6 +49,8 @@ if (!vartrue($FAQ_VIEW_TEMPLATE))
}
}
e107::css('faqs','faqs.css');
// require_once(HEADERF);
// $pref['add_faq']=1;
@ -135,7 +137,8 @@ if (isset($_POST['commentsubmit']))
{
$srch = vartrue($_GET['srch']);
$ftmp = $faq->view_all($srch);
$caption = FAQLAN_FAQ;
$caption = FAQLAN_FAQ;
}
if (vartrue($faqpref['faq_title']))
@ -196,8 +199,45 @@ class faq
$this->pref = e107::pref('faqs'); // Short version of e107::getPlugConfig('faqs')->getPref(); ;
$sc->pref = $this->pref;
if(!empty($_POST['submit_a_question']))
{
$sql = e107::getDb();
if($sql->select('faqs','faq_id',"faq_answer='' AND faq_author_ip = '".USERIP."' LIMIT 1"))
{
e107::getMessage()->setTitle('Sorry',E_MESSAGE_INFO)->addInfo("You may only ask another question once your other question has been answered.");
return;
}
$question = filter_input(INPUT_POST, 'ask_a_question', FILTER_SANITIZE_STRING);
$insert = array(
'faq_id' =>0,
'faq_parent' =>0,
'faq_question' => $question,
'faq_answer' => '',
'faq_comment' => 0,
'faq_datestamp' => time(),
'faq_author' => 0,
'faq_author_ip' => USERIP,
'faq_tags' => '',
'faq_order' => 99999
);
if($sql->insert('faqs',$insert))
{
e107::getMessage()->addSuccess('Thank you. Your question has been saved and will be answered as soon as possible.');
}
}
}
function view_all($srch) // new funtion to render all FAQs
{
$sql = e107::getDb();
@ -211,7 +251,7 @@ class faq
$this->sc = e107::getScBatch('faqs',TRUE);
$text = $tp->parseTemplate($template['start'], true, $this->sc);
$text = $tp->parseTemplate($template['start'], true, $this->sc); // header
// var_dump($sc);
@ -221,7 +261,7 @@ class faq
$text .= "</div>";
$text .= $tp->parseTemplate($template['end'], true, $this->sc);
$text .= $tp->parseTemplate($template['end'], true, $this->sc); // footer
@ -240,6 +280,8 @@ class faq
{
$sql = e107::getDb();
$tp = e107::getParser();
$text = "";
$insert = "";
@ -252,7 +294,21 @@ class faq
if(!empty($_GET['cat']))
{
$srch = $tp->toDB($_GET['cat']);
$insert = " AND (cat.faq_info_sef = '".$srch."') ";
$insert = " AND (cat.faq_info_sef = '".$srch."') ";
}
if(!empty($_GET['tag']))
{
$srch = $tp->toDB($_GET['tag']);
$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);
$text = e107::getMessage()->render();
}
$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 ";
@ -264,20 +320,18 @@ class faq
// -----------------
$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 = "";
$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);
// $text = $tp->parseTemplate($FAQ_START, true, $sc);
// $text = "";
while ($rw = $sql->fetch())
{
$sc->setVars($rw);
@ -298,8 +352,8 @@ class faq
$sc->counter++;
}
$text .= ($start) ? $tp->parseTemplate($FAQ_LISTALL['end'], true, $sc) : "";
$text .= $tp->parseTemplate($FAQ_END, true, $sc);
// $text .= $tp->parseTemplate($FAQ_END, true, $sc);
return $text;
}

View File

@ -44,7 +44,7 @@ class faqs_shortcodes extends e_shortcode
$tags = '';
if(vartrue($params['tags']) && $this->var['faq_tags'])
{
$tags = "<div class='faq-tags'>".$this->sc_faq_tags()."</div>";
$tags = "<div class='faq-tags'>".LAN_FAQS_TAGS.": ".$this->sc_faq_tags()."</div>";
}
$id = "faq_".$this->var['faq_id'];
$text = "<a class='e-expandit faq-question' href='#{$id}'>".$tp->toHTML($this->var['faq_question'],true)."</a>
@ -84,7 +84,8 @@ class faqs_shortcodes extends e_shortcode
foreach ($tags as $tag)
{
$urlparms['tag'] = $tag;
$url = e107::getUrl()->create('faqs/list/all', $urlparms);
// $url = e107::getUrl()->create('faqs/list/all', $urlparms);
$url = e107::url('faqs', 'tag',$urlparms);
$tag = htmlspecialchars($tag, ENT_QUOTES, 'utf-8');
$ret[] = '<a href="'.$url.'" title="'.$tag.'"><span class="label label-info">'.$tag.'</span></a>';
}
@ -181,22 +182,27 @@ class faqs_shortcodes extends e_shortcode
function sc_faq_submit_question()
{
return ''; // UNDER CONSTRUCTION
$faqpref = e107::getPlugConfig('faqs')->getPref();
$frm = e107::getForm();
if (check_class($faqpref['add_faq']))
$faqpref = e107::pref('faqs');
if (check_class($faqpref['submit_question']))
{
$text = "<div class='faq-submit-question-container'><a class='e-expandit faq-submit-question' href='faqs.php'>Submit a Question</a>
<div class='e-hideme faq-submit-question-form'>
<form method=\"post\" action=\"".e_SELF."?cat.$id.$idx\" id=\"dataform\">
<div>".$frm->textarea('ask_a_question','').'<br />'.$frm->submit('submit_a_question','Go')."</div>
</form>
</div>
</div>
";
$frm = e107::getForm();
$text = "<a class='btn btn-primary e-expandit faq-submit-question' href='#ask-a-question'>Ask a Question</a>
<div id='ask-a-question' class='alert alert-info alert-block e-hideme form-group faq-submit-question-form'>";
$text .= $frm->open('faq-ask-question','post');
$text .= "<div>".$frm->text('ask_a_question','',255,array('size'=>'xxlarge','placeholder'=>'Type your question here..')).'<br />'.$frm->submit('submit_a_question','Submit')."</div>";
$text .= $frm->close();
$text .= "</div>";
return $text;
}
}
}
function sc_faq_search($parm='')

View File

@ -6,6 +6,7 @@ CREATE TABLE faqs (
faq_comment tinyint(1) unsigned NOT NULL default '0',
faq_datestamp int(10) unsigned NOT NULL default '0',
faq_author int(10) unsigned default NULL,
faq_author_ip varchar(45) NOT NULL default '',
faq_tags varchar(255) NOT NULL default '',
faq_order int(6) unsigned NOT NULL default '0',
PRIMARY KEY (faq_id)

View File

@ -9,11 +9,11 @@
*/
$FAQS_TEMPLATE['start'] = "
<div class='faq-start'>
<div class='faq-start'>{FAQ_SUBMIT_QUESTION}
";
$FAQS_TEMPLATE['end'] = "
<div class='faq-submit-question'>{FAQ_SUBMIT_QUESTION}</div>
<div class='faq-submit-question'></div>
<div class='faq-search'>{FAQ_SEARCH}</div>
</div>
";
@ -31,3 +31,5 @@ $FAQS_TEMPLATE['all']['end'] = "
</div>
";