Exemple #1
0
 /**
  * Build the SQL query for retrieving faq records according to the constraints provided
  *
  * @param   $QueryType
  * @param   $nCatid
  * @param   $bDownwards
  * @param   $lang
  * @param   $date
  * @param   $faqid
  * @return  array
  * @access  private
  * @since   2005-11-02
  * @author  Matteo Scaramuccia <*****@*****.**>
  */
 private function _getSQLQuery($QueryType, $nCatid, $bDownwards, $lang, $date, $faqid = 0)
 {
     $now = date('YmdHis');
     $query = sprintf("\n            SELECT\n                fd.id AS id,\n                fd.solution_id AS solution_id,\n                fd.revision_id AS revision_id,\n                fd.lang AS lang,\n                fcr.category_id AS category_id,\n                fd.active AS active,\n                fd.sticky AS sticky,\n                fd.keywords AS keywords,\n                fd.thema AS thema,\n                fd.content AS content,\n                fd.author AS author,\n                fd.email AS email,\n                fd.comment AS comment,\n                fd.datum AS datum,\n                fv.visits AS visits,\n                fv.last_visit AS last_visit\n            FROM\n                %sfaqdata fd,\n                %sfaqvisits fv,\n                %sfaqcategoryrelations fcr\n            WHERE\n                fd.id = fcr.record_id\n            AND\n                fd.lang = fcr.record_lang\n            AND\n                fd.date_start <= '%s'\n            AND\n                fd.date_end   >= '%s'\n            AND ", SQLPREFIX, SQLPREFIX, SQLPREFIX, $now, $now);
     // faqvisits data selection
     if (!empty($faqid)) {
         // Select ONLY the faq with the provided $faqid
         $query .= "fd.id = '" . $faqid . "' AND ";
     }
     $query .= "fd.id = fv.id\n            AND\n                fd.lang = fv.lang";
     $needAndOp = true;
     if (!empty($nCatid) && PMF_Utils::isInteger($nCatid) && $nCatid > 0) {
         if ($needAndOp) {
             $query .= " AND";
         }
         $query .= " (fcr.category_id = " . $nCatid;
         if ($bDownwards) {
             $query .= $this->_getCatidWhereSequence($nCatid, "OR");
         }
         $query .= ")";
         $needAndOp = true;
     }
     if (!empty($date) && PMF_Utils::isLikeOnPMFDate($date)) {
         if ($needAndOp) {
             $query .= " AND";
         }
         $query .= " fd.datum LIKE '" . $date . "'";
         $needAndOp = true;
     }
     if (!empty($lang) && PMF_Utils::isLanguage($lang)) {
         if ($needAndOp) {
             $query .= " AND";
         }
         $query .= " fd.lang = '" . $lang . "'";
         $needAndOp = true;
     }
     switch ($QueryType) {
         case FAQ_QUERY_TYPE_APPROVAL:
             if ($needAndOp) {
                 $query .= " AND";
             }
             $query .= " fd.active = '" . FAQ_SQL_ACTIVE_NO . "'";
             $needAndOp = true;
             break;
         case FAQ_QUERY_TYPE_EXPORT_DOCBOOK:
         case FAQ_QUERY_TYPE_EXPORT_PDF:
         case FAQ_QUERY_TYPE_EXPORT_XHTML:
         case FAQ_QUERY_TYPE_EXPORT_XML:
             if ($needAndOp) {
                 $query .= " AND";
             }
             $query .= " fd.active = '" . FAQ_SQL_ACTIVE_YES . "'";
             $needAndOp = true;
             break;
         default:
             if ($needAndOp) {
                 $query .= " AND";
             }
             $query .= " fd.active = '" . FAQ_SQL_ACTIVE_YES . "'";
             $needAndOp = true;
             break;
     }
     // Sort criteria
     switch ($QueryType) {
         case FAQ_QUERY_TYPE_EXPORT_DOCBOOK:
         case FAQ_QUERY_TYPE_EXPORT_PDF:
         case FAQ_QUERY_TYPE_EXPORT_XHTML:
         case FAQ_QUERY_TYPE_EXPORT_XML:
             // Preferred ordering: Sitemap-like
             // TODO: see if this sort is compatible with the current set of indexes
             $query .= "\nORDER BY fd.thema";
             break;
         case FAQ_QUERY_TYPE_RSS_LATEST:
             $query .= "\nORDER BY fd.datum DESC";
             break;
         default:
             // Normal ordering
             $query .= "\nORDER BY fcr.category_id, fd.id";
             break;
     }
     return $query;
 }
Exemple #2
0
 /**
  * Checks if a date is a phpMyFAQ valid date
  *
  * @param  integer $date Date
  * @return integer
  */
 public static function isLikeOnPMFDate($date)
 {
     // Test if the passed string is in the format: %YYYYMMDDhhmmss%
     $testdate = $date;
     // Suppress first occurence of '%'
     if (substr($testdate, 0, 1) == '%') {
         $testdate = substr($testdate, 1);
     }
     // Suppress last occurence of '%'
     if (substr($testdate, -1, 1) == '%') {
         $testdate = substr($testdate, 0, strlen($testdate) - 1);
     }
     // PMF date consists of numbers only: YYYYMMDDhhmmss
     return PMF_Utils::isInteger($testdate);
 }