1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-30 03:10:50 +02:00

FAQ plugin - code clean-up

Co-Authored-By: Jimako <jimmi08@users.noreply.github.com>
This commit is contained in:
Tijn Kuyper
2019-10-02 09:39:04 +02:00
parent ca74ff4460
commit c06a66dfda

View File

@@ -28,11 +28,12 @@ else
require_once (e_HANDLER."form_handler.php"); require_once (e_HANDLER."form_handler.php"); // TODO - Remove outdated code
require_once (e_HANDLER."userclass_class.php"); require_once (e_HANDLER."userclass_class.php");
require_once (e_HANDLER."ren_help.php"); require_once (e_HANDLER."ren_help.php"); // TODO - Remove outdated code
require_once (e_HANDLER."comment_class.php"); require_once (e_HANDLER."comment_class.php");
/*
if (!vartrue($FAQ_VIEW_TEMPLATE)) if (!vartrue($FAQ_VIEW_TEMPLATE))
{ {
if (file_exists(THEME."faqs_template.php")) if (file_exists(THEME."faqs_template.php"))
@@ -44,16 +45,19 @@ if (!vartrue($FAQ_VIEW_TEMPLATE))
// require_once (e_PLUGIN."faqs/templates/faqs_template.php"); // require_once (e_PLUGIN."faqs/templates/faqs_template.php");
} }
} }
*/
e107::css('faqs','faqs.css'); e107::css('faqs','faqs.css');
// require_once(HEADERF); // require_once(HEADERF);
// $pref['add_faq']=1; // $pref['add_faq']=1;
$rs = new form; $rs = new form; // TODO - Remove outdated code
$cobj = new comment; $cobj = new comment;
$tp = e107::getParser();
$frm = e107::getForm();
if (!vartrue($_GET['elan']) && empty($_GET)) if (!vartrue($_GET['elan']) && empty($_GET))
{ {
$qs = explode(".", e_QUERY); $qs = explode(".", e_QUERY);
@@ -68,9 +72,6 @@ else
$from = (vartrue($from) ? $from : 0); $from = (vartrue($from) ? $from : 0);
$amount = 50; $amount = 50;
@@ -79,11 +80,14 @@ if (isset($_POST['faq_submit']))
$message = "-"; $message = "-";
if ($_POST['faq_question'] != "" || $_POST['data'] != "") if ($_POST['faq_question'] != "" || $_POST['data'] != "")
{ {
$faq_question = $aj->formtpa($_POST['faq_question'], "on"); $faq_question = $tp->toDB($_POST['faq_question']);
$data = $aj->formtpa($_POST['data'], "on"); $data = $tp->toDB($_POST['data']);
$count = ($sql->db_Count("faqs", "(*)", "WHERE faq_parent='".intval($_POST['faq_parent'])."' ") + 1); $count = ($sql->db_Count("faqs", "(*)", "WHERE faq_parent='".intval($_POST['faq_parent'])."' ") + 1);
$sql->db_Insert("faqs", " 0, '".$_POST['faq_parent']."', '$faq_question', '$data', '".filter_var($_POST['faq_comment'], FILTER_SANITIZE_STRING)."', '".time()."', '".USERID."', '".$count."' ");
$sql->insert("faqs", " 0, '".$_POST['faq_parent']."', '$faq_question', '$data', '".filter_var($_POST['faq_comment'], FILTER_SANITIZE_STRING)."', '".time()."', '".USERID."', '".$count."' ");
$message = FAQ_ADLAN_32; $message = FAQ_ADLAN_32;
unset($faq_question, $data); unset($faq_question, $data);
} }
else else
@@ -97,11 +101,13 @@ if (isset($_POST['faq_edit_submit']))
{ {
if ($_POST['faq_question'] != "" || $_POST['data'] != "") if ($_POST['faq_question'] != "" || $_POST['data'] != "")
{ {
$faq_question = $aj->formtpa($_POST['faq_question'], "on"); $faq_question = $tp->toDB($_POST['faq_question']);
$data = $aj->formtpa($_POST['data'], "on"); $data = $tp->toDB($_POST['data']);
$sql->update("faqs", "faq_parent='".intval($_POST['faq_parent'])."', faq_question ='$faq_question', faq_answer='$data', faq_comment='".$_POST['faq_comment']."' WHERE faq_id='".$idx."' ");
$sql->db_Update("faqs", "faq_parent='".intval($_POST['faq_parent'])."', faq_question ='$faq_question', faq_answer='$data', faq_comment='".$_POST['faq_comment']."' WHERE faq_id='".$idx."' ");
$message = FAQ_ADLAN_29; $message = FAQ_ADLAN_29;
unset($faq_question, $data); unset($faq_question, $data);
} }
else else
@@ -461,12 +467,12 @@ class faq
$sc = e107::getScBatch('faqs',TRUE); $sc = e107::getScBatch('faqs',TRUE);
$query = "SELECT f.*,cat.* FROM #faqs AS f LEFT JOIN #faqs_info AS cat ON f.faq_parent = cat.faq_info_id WHERE f.faq_parent = '$id' "; $query = "SELECT f.*,cat.* FROM #faqs AS f LEFT JOIN #faqs_info AS cat ON f.faq_parent = cat.faq_info_id WHERE f.faq_parent = '$id' ";
$sql->db_Select_gen($query); $sql->gen($query);
$sc->setVars($row); $sc->setVars($row);
$text = $tp->parseTemplate($FAQ_LIST_START, true); $text = $tp->parseTemplate($FAQ_LIST_START, true);
while ($rw = $sql->db_Fetch()) while ($rw = $sql->fetch())
{ {
$sc->setVars($rw); $sc->setVars($rw);
$text .= $tp->parseTemplate($FAQ_LIST_LOOP, true); $text .= $tp->parseTemplate($FAQ_LIST_LOOP, true);
@@ -508,8 +514,8 @@ class faq
$text .= $FAQ_CAT_START; $text .= $FAQ_CAT_START;
$sql->db_Select_gen($qry); $sql->gen($qry);
while ($row = $sql->db_Fetch()) while ($row = $sql->fetch())
{ {
$sc->setVars($row); $sc->setVars($row);
@@ -546,14 +552,16 @@ class faq
function view_faq($idx) function view_faq($idx)
{ {
global $ns,$row,$sql,$aj,$pref,$cobj,$id,$tp,$FAQ_VIEW_TEMPLATE; global $row,$pref,$cobj,$id,$FAQ_VIEW_TEMPLATE;
$ns = e107::getRender();
$sql = e107::getDb();
$tp = e107::getParser();
//require_once (e_PLUGIN."faqs/faqs_shortcodes.php"); //require_once (e_PLUGIN."faqs/faqs_shortcodes.php");
$sc = e107::getScBatch('faqs',TRUE); $sc = e107::getScBatch('faqs',TRUE);
$sql->db_Select("faqs", "*", "faq_id='$idx' LIMIT 1"); $sql->select("faqs", "*", "faq_id='$idx' LIMIT 1");
$row = $sql->db_Fetch(); $row = $sql->fetch();
$sc->setVars($row); $sc->setVars($row);
@@ -569,7 +577,7 @@ class faq
return $ret; return $ret;
$subject = (!$subject ? $aj->formtpa($faq_question) : $subject); $subject = (!$subject ? $tp->toDB($faq_question) : $subject);
if (check_class($row['faq_comment'])) if (check_class($row['faq_comment']))
{ {
@@ -578,14 +586,15 @@ class faq
$table = "faq"; $table = "faq";
$query = ($pref['nested_comments'] ? "comment_item_id='$idx' AND (comment_type='$table' OR comment_type='3') AND comment_pid='0' ORDER BY comment_datestamp" : "comment_item_id='$idx' AND (comment_type='$table' OR comment_type='3') ORDER BY comment_datestamp"); $query = ($pref['nested_comments'] ? "comment_item_id='$idx' AND (comment_type='$table' OR comment_type='3') AND comment_pid='0' ORDER BY comment_datestamp" : "comment_item_id='$idx' AND (comment_type='$table' OR comment_type='3') ORDER BY comment_datestamp");
unset($text); unset($text);
if (!is_object($sql2)) if (!is_object($sql2))
{ {
$sql2 = new db; $sql2 = new db;
} }
if ($comment_total = $sql2->db_Select("comments", "*", $query)) if ($comment_total = $sql2->select("comments", "*", $query))
{ {
$width = 0; $width = 0;
while ($row = $sql2->db_Fetch()) while ($row = $sql2->fetch())
{ {
if ($pref['nested_comments']) if ($pref['nested_comments'])
{ {
@@ -615,16 +624,21 @@ class faq
function faq_footer($id='') function faq_footer($id='')
{ {
global $faqpref,$timing_start,$tp,$cust_footer, $CUSTOMPAGES, $CUSTOMHEADER, $CUSTOMHEADER; global $faqpref,$timing_start,$cust_footer, $CUSTOMPAGES, $CUSTOMHEADER, $CUSTOMHEADER;
$tp = e107::getParser();
$text_menu .= "<div style='text-align:center;' ><br /> $text_menu .= "<div style='text-align:center;' ><br />
&nbsp;&nbsp;[&nbsp;<a href='faqs.php?main'>".LAN_FAQS_010."</a>&nbsp;]&nbsp;&nbsp;"; &nbsp;&nbsp;[&nbsp;<a href='faqs.php?main'>".LAN_FAQS_010."</a>&nbsp;]&nbsp;&nbsp;";
if(check_class($faqpref['add_faq'])){ if(check_class($faqpref['add_faq'])){
$text_menu .="[&nbsp;<a href='faqs.php?new.$id'>".LAN_FAQS_ASK_A_QUESTION."</a>&nbsp;]"; $text_menu .="[&nbsp;<a href='faqs.php?new.$id'>".LAN_FAQS_ASK_A_QUESTION."</a>&nbsp;]";
} }
$text_menu .="</div>"; $text_menu .="</div>";
$text_menu .= "<div style='text-align:center'><br />".$tp->parseTemplate("{SEARCH=faqs}")."</div>"; $text_menu .= "<div style='text-align:center'><br />".$tp->parseTemplate("{SEARCH=faqs}")."</div>";
return $text_menu; return $text_menu;
// require_once (FOOTERF); // require_once (FOOTERF);
@@ -632,7 +646,7 @@ class faq
function add_faq($action, $id, $idx) function add_faq($action, $id, $idx)
{ {
global $rs; global $rs; // TODO - remove old code
$tp = e107::getParser(); $tp = e107::getParser();
$sql = e107::getDb(); $sql = e107::getDb();
@@ -643,14 +657,14 @@ class faq
$text .= "<table class='fborder' style=\"".USER_WIDTH."\" > $text .= "<table class='fborder' style=\"".USER_WIDTH."\" >
<tr> <tr>
<td colspan='2' class='forumheader3' style=\"width:80%; padding:0px\">"; <td colspan='2' class='forumheader3' style=\"width:80%; padding:0px\">";
$sql->db_Select("faqs", "*", "faq_parent='$id' AND faq_author = '$userid' ORDER BY faq_id ASC"); $sql->select("faqs", "*", "faq_parent='$id' AND faq_author = '$userid' ORDER BY faq_id ASC");
$text .= "<div style='width : auto; height : 110px; overflow : auto; '> $text .= "<div style='width : auto; height : 110px; overflow : auto; '>
<table class='fborder' style=\"width:100%\"> <table class='fborder' style=\"width:100%\">
<tr> <tr>
<td class='fcaption' style=\"width:70%\">".FAQ_ADLAN_49."</td> <td class='fcaption' style=\"width:70%\">".FAQ_ADLAN_49."</td>
<td class='fcaption' style='text-align:center'>".LAN_SETTINGS."</td></tr> <td class='fcaption' style='text-align:center'>".LAN_SETTINGS."</td></tr>
"; ";
while ($rw = $sql->db_Fetch()) while ($rw = $sql->fetch())
{ {
// list($pfaq_id, $pfaq_parent, $pfaq_question, $pfaq_answer, $pfaq_comment); // list($pfaq_id, $pfaq_parent, $pfaq_question, $pfaq_answer, $pfaq_comment);
$rw['faq_question'] = substr($rw['faq_question'], 0, 50)." ... "; $rw['faq_question'] = substr($rw['faq_question'], 0, 50)." ... ";
@@ -666,11 +680,13 @@ class faq
} }
$text .= "</table></div>"; $text .= "</table></div>";
// TODO - optimize
if ($action == "edit") if ($action == "edit")
{ {
$sql->db_Select("faqs", "*", " faq_id = '$idx' "); $sql->select("faqs", "*", " faq_id = '$idx' ");
$row = $sql->db_Fetch(); $row = $sql->fetch();
extract($row); extract($row); // get rid of this
$data = $faq_answer; $data = $faq_answer;
} }
@@ -689,8 +705,8 @@ class faq
<td class='forumheader3' style=\"width:80%\">"; <td class='forumheader3' style=\"width:80%\">";
$text .= "<select style='width:150px' class='tbox' id='faq_parent' name='faq_parent' >"; $text .= "<select style='width:150px' class='tbox' id='faq_parent' name='faq_parent' >";
$sql->db_Select("faqs_info", "*", "faq_info_parent !='0' "); $sql->select("faqs_info", "*", "faq_info_parent !='0' ");
while ($prow = $sql->db_Fetch()) while ($prow = $sql->fetch())
{ {
//extract($row); //extract($row);
$selected = $prow['faq_info_id'] == $id ? " selected='selected'" : ""; $selected = $prow['faq_info_id'] == $id ? " selected='selected'" : "";
@@ -758,9 +774,9 @@ class faq
if(varset($faq)) if(varset($faq))
{ {
$sql->db_Select("faqs_info", "*", "faq_info_id='$faq'"); $sql->select("faqs_info", "*", "faq_info_id='$faq'");
$row = $sql->db_Fetch(); $row = $sql->fetch();
extract($row); extract($row); // get rid of this
} }
$ns->tablerender(LAN_PLUGIN_FAQS_FRONT_NAME.$faq_info_title, "<div style='text-align:center'>".$text."</div>".$this->faq_footer()); $ns->tablerender(LAN_PLUGIN_FAQS_FRONT_NAME.$faq_info_title, "<div style='text-align:center'>".$text."</div>".$this->faq_footer());