From c06a66dfda7b79ac697164c8064bd32147fe087f Mon Sep 17 00:00:00 2001 From: Tijn Kuyper Date: Wed, 2 Oct 2019 09:39:04 +0200 Subject: [PATCH] FAQ plugin - code clean-up Co-Authored-By: Jimako --- e107_plugins/faqs/faqs.php | 124 +++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 54 deletions(-) diff --git a/e107_plugins/faqs/faqs.php b/e107_plugins/faqs/faqs.php index abc08c4cb..9ccdc34f4 100644 --- a/e107_plugins/faqs/faqs.php +++ b/e107_plugins/faqs/faqs.php @@ -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."ren_help.php"); +require_once (e_HANDLER."ren_help.php"); // TODO - Remove outdated code require_once (e_HANDLER."comment_class.php"); +/* if (!vartrue($FAQ_VIEW_TEMPLATE)) { if (file_exists(THEME."faqs_template.php")) @@ -44,22 +45,25 @@ if (!vartrue($FAQ_VIEW_TEMPLATE)) // require_once (e_PLUGIN."faqs/templates/faqs_template.php"); } } - +*/ e107::css('faqs','faqs.css'); // require_once(HEADERF); // $pref['add_faq']=1; -$rs = new form; -$cobj = new comment; +$rs = new form; // TODO - Remove outdated code +$cobj = new comment; + +$tp = e107::getParser(); +$frm = e107::getForm(); if (!vartrue($_GET['elan']) && empty($_GET)) { - $qs = explode(".", e_QUERY); + $qs = explode(".", e_QUERY); $action = $qs[0]; - $id = $qs[1]; - $idx = $qs[2]; + $id = $qs[1]; + $idx = $qs[2]; } else { @@ -68,9 +72,6 @@ else - - - $from = (vartrue($from) ? $from : 0); $amount = 50; @@ -79,11 +80,14 @@ if (isset($_POST['faq_submit'])) $message = "-"; if ($_POST['faq_question'] != "" || $_POST['data'] != "") { - $faq_question = $aj->formtpa($_POST['faq_question'], "on"); - $data = $aj->formtpa($_POST['data'], "on"); - $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."' "); + $faq_question = $tp->toDB($_POST['faq_question']); + $data = $tp->toDB($_POST['data']); + $count = ($sql->db_Count("faqs", "(*)", "WHERE faq_parent='".intval($_POST['faq_parent'])."' ") + 1); + + $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; + unset($faq_question, $data); } else @@ -97,11 +101,13 @@ if (isset($_POST['faq_edit_submit'])) { if ($_POST['faq_question'] != "" || $_POST['data'] != "") { - $faq_question = $aj->formtpa($_POST['faq_question'], "on"); - $data = $aj->formtpa($_POST['data'], "on"); + $faq_question = $tp->toDB($_POST['faq_question']); + $data = $tp->toDB($_POST['data']); - $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."' "); + $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."' "); + $message = FAQ_ADLAN_29; + unset($faq_question, $data); } else @@ -180,7 +186,7 @@ if (isset($_POST['commentsubmit'])) $ftmp = $faq->view_faq($idx) ; define("e_PAGETITLE",LAN_FAQS_011." - ". $ftmp['title']); require_once(HEADERF); - $ns -> tablerender($ftmp['caption'], $ftmp['text']); + $ns->tablerender($ftmp['caption'], $ftmp['text']); } if ($action == "cat") @@ -193,7 +199,7 @@ if (isset($_POST['commentsubmit'])) } - if ((check_class($faqpref['add_faq']) || ADMIN) && ($action == "new" || $action == "edit")) + if((check_class($faqpref['add_faq']) || ADMIN) && ($action == "new" || $action == "edit")) { require_once (HEADERF); $faq->add_faq($action, $id, $idx); @@ -248,7 +254,7 @@ class faq 'faq_order' => 99999 ); - if($sql->insert('faqs',$insert)) + if($sql->insert('faqs', $insert)) { $message = !empty($this->pref['submit_question_acknowledgement']) ? e107::getParser()->toHTML($this->pref['submit_question_acknowledgement'],true, 'BODY') : LAN_FAQS_004; e107::getMessage()->addSuccess($message); @@ -461,12 +467,12 @@ class faq $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' "; - $sql->db_Select_gen($query); + $sql->gen($query); $sc->setVars($row); $text = $tp->parseTemplate($FAQ_LIST_START, true); - while ($rw = $sql->db_Fetch()) + while ($rw = $sql->fetch()) { $sc->setVars($rw); $text .= $tp->parseTemplate($FAQ_LIST_LOOP, true); @@ -508,8 +514,8 @@ class faq $text .= $FAQ_CAT_START; - $sql->db_Select_gen($qry); - while ($row = $sql->db_Fetch()) + $sql->gen($qry); + while ($row = $sql->fetch()) { $sc->setVars($row); @@ -546,14 +552,16 @@ class faq 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"); $sc = e107::getScBatch('faqs',TRUE); - $sql->db_Select("faqs", "*", "faq_id='$idx' LIMIT 1"); - $row = $sql->db_Fetch(); + $sql->select("faqs", "*", "faq_id='$idx' LIMIT 1"); + $row = $sql->fetch(); $sc->setVars($row); @@ -562,14 +570,14 @@ class faq // $text = $tp->toHTML($text, TRUE); - $ret['text'] = $text; - $ret['caption'] = $caption; - $ret['title'] = $row['faq_question']; - $ret['comments'] = $text; + $ret['text'] = $text; + $ret['caption'] = $caption; + $ret['title'] = $row['faq_question']; + $ret['comments'] = $text; return $ret; - $subject = (!$subject ? $aj->formtpa($faq_question) : $subject); + $subject = (!$subject ? $tp->toDB($faq_question) : $subject); if (check_class($row['faq_comment'])) { @@ -578,14 +586,15 @@ class 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"); unset($text); + if (!is_object($sql2)) { $sql2 = new db; } - if ($comment_total = $sql2->db_Select("comments", "*", $query)) + if ($comment_total = $sql2->select("comments", "*", $query)) { $width = 0; - while ($row = $sql2->db_Fetch()) + while ($row = $sql2->fetch()) { if ($pref['nested_comments']) { @@ -615,42 +624,47 @@ class faq 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 .= "

  [ ".LAN_FAQS_010." ]  "; if(check_class($faqpref['add_faq'])){ $text_menu .="[ ".LAN_FAQS_ASK_A_QUESTION." ]"; } + $text_menu .="
"; $text_menu .= "

".$tp->parseTemplate("{SEARCH=faqs}")."
"; - return $text_menu; + + return $text_menu; // require_once (FOOTERF); } function add_faq($action, $id, $idx) { - global $rs; + global $rs; // TODO - remove old code - $tp = e107::getParser(); - $sql = e107::getDb(); - $ns = e107::getRender(); + $tp = e107::getParser(); + $sql = e107::getDb(); + $ns = e107::getRender(); $userid = USERID; $text .= "
"; - $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 .= "
"; - while ($rw = $sql->db_Fetch()) + while ($rw = $sql->fetch()) { // list($pfaq_id, $pfaq_parent, $pfaq_question, $pfaq_answer, $pfaq_comment); $rw['faq_question'] = substr($rw['faq_question'], 0, 50)." ... "; @@ -666,11 +680,13 @@ class faq } $text .= "
".FAQ_ADLAN_49." ".LAN_SETTINGS."
"; + + // TODO - optimize if ($action == "edit") { - $sql->db_Select("faqs", "*", " faq_id = '$idx' "); - $row = $sql->db_Fetch(); - extract($row); + $sql->select("faqs", "*", " faq_id = '$idx' "); + $row = $sql->fetch(); + extract($row); // get rid of this $data = $faq_answer; } @@ -689,8 +705,8 @@ class faq
"; $text .= "