/** * builds a WHERE clause for a query * * @private */ function buildWhere($blogid, $date = -1, $amount = -1, $categoryId = 0, $status = 0, $userId = 0, $maxDate = 0, $searchTerms = "") { $postStatus = $status; $prefix = $this->getPrefix(); if ($blogid == -1) { $query = "a.blog_id = a.blog_id"; } else { $query = "a.blog_id = " . Db::qstr($blogid); } if ($date != -1) { // consider the time difference $blogSettings = $this->blogs->getBlogSettings($blogid); $timeDifference = $blogSettings->getValue("time_offset"); $SecondsDiff = $timeDifference * 3600; $query .= " AND FROM_UNIXTIME(UNIX_TIMESTAMP(a.date)+{$SecondsDiff})+0 LIKE '{$date}%'"; } // the common part "c.id = a.category_id" is needed so that // we don't get one article row as many times as the amount of categories // we have... due to the sql 'join' operation we're carrying out if ($categoryId == -1) { $query .= " AND c.id = l.category_id AND a.id = l.article_id "; } else { if ($categoryId > 0) { $query .= " AND a.id = l.article_id AND l.category_id = {$categoryId} AND c.id = l.category_id"; } else { $query .= " AND c.id = l.category_id AND a.id = l.article_id AND c.in_main_page = 1"; } } if ($status > 0) { $query .= " AND a.status = '{$postStatus}'"; } if ($userId > 0) { $query .= " AND a.user_id = " . Db::qstr($userId); } if ($maxDate > 0) { $query .= " AND a.date <= '{$maxDate}'"; } // in case there were some search terms specified as parameters... if ($searchTerms != "") { // load the class dynamically so that we don't have to waste memory // if we're not going to need it! include_once PLOG_CLASS_PATH . "class/dao/searchengine.class.php"; $searchEngine = new SearchEngine(); // prepare the query string $searchTerms = $searchEngine->_adaptSearchString($searchTerms); $whereString = $searchEngine->_generateSearchArticlesWhereString($searchTerms); // and add it to the current search $query .= " AND {$whereString} "; } if ($categoryId <= 0) { $query .= " GROUP BY a.id "; } return $query; }