/** * Returns the number of entries * * @return integer */ public function getNumberOfEntries() { $query = sprintf(' SELECT id FROM %sfaqadminlog', SQLPREFIX); return $this->db->num_rows($this->db->query($query)); }
/** * Match a word against the stop words dictionary * * @param string $word * * @return boolean */ public function match($word) { $sql = "SELECT id FROM {$this->table_name} WHERE LOWER(stopword) = LOWER('%s') AND lang = '%s'"; $sql = sprintf($sql, $word, $this->language); $result = $this->db->query($sql); return $this->db->num_rows($result) > 0; }
/** * The main search function for the full text search * * @param string $searchterm Text/Number (solution id) * @param boolean $allLanguages true to search over all languages * @param boolean $hasMore true to disable the results paging * @param boolean $instantRespnse true to use it for Instant Response * @return array */ public function search($searchterm, $allLanguages = true, $hasMore = false, $instantResponse = false) { $fdTable = SQLPREFIX . 'faqdata'; $fcrTable = SQLPREFIX . 'faqcategoryrelations'; $condition = array($fdTable . '.active' => "'yes'"); // Search in all or one category? if (!is_null($this->categoryId)) { $selectedCategory = array($fcrTable . '.category_id' => $searchcategory); $condition = array_merge($selectedCategory, $condition); } if (!$allLanguages && !is_numeric($searchterm)) { $selectedLanguage = array($fdTable . '.lang' => "'" . $this->language . "'"); $condition = array_merge($selectedLanguage, $condition); } if (is_numeric($searchterm)) { // search for the solution_id $result = $this->db->search($fdTable, array($fdTable . '.id AS id', $fdTable . '.lang AS lang', $fdTable . '.solution_id AS solution_id', $fcrTable . '.category_id AS category_id', $fdTable . '.thema AS question', $fdTable . '.content AS answer'), $fcrTable, array($fdTable . '.id = ' . $fcrTable . '.record_id', $fdTable . '.lang = ' . $fcrTable . '.record_lang'), array($fdTable . '.solution_id'), $searchterm, $condition); } else { $result = $this->db->search($fdTable, array($fdTable . '.id AS id', $fdTable . '.lang AS lang', $fcrTable . '.category_id AS category_id', $fdTable . '.thema AS question', $fdTable . '.content AS answer'), $fcrTable, array($fdTable . '.id = ' . $fcrTable . '.record_id', $fdTable . '.lang = ' . $fcrTable . '.record_lang'), array($fdTable . '.thema', $fdTable . '.content', $fdTable . '.keywords'), $searchterm, $condition); } if ($result) { $num = $this->db->num_rows($result); } if ($num == 0) { return array(); } else { return $this->db->fetchAll($result); } }
/** * Prints the open questions as a XHTML table * * @return string * @access public * @since 2002-09-17 * @author Thorsten Rinne <*****@*****.**> */ function printOpenQuestions() { global $sids, $category; $query = sprintf("\n SELECT\n COUNT(*) AS num\n FROM\n %sfaqquestions\n WHERE\n is_visible != 'Y'", SQLPREFIX); $result = $this->db->query($query); $row = $this->db->fetch_object($result); $numOfInvisibles = $row->num; if ($numOfInvisibles > 0) { $extraout = sprintf('<tr><td colspan="3"><hr />%s%s</td></tr>', $this->pmf_lang['msgQuestionsWaiting'], $numOfInvisibles); } else { $extraout = ''; } $query = sprintf("\n SELECT\n id,\n ask_username,\n ask_usermail,\n ask_rubrik,\n ask_content,\n ask_date\n FROM\n %sfaqquestions\n WHERE\n is_visible = 'Y'\n ORDER BY\n ask_date ASC", SQLPREFIX); $result = $this->db->query($query); $output = ''; if ($this->db->num_rows($result) > 0) { while ($row = $this->db->fetch_object($result)) { $output .= '<tr class="openquestions">'; $output .= sprintf('<td valign="top" nowrap="nowrap">%s<br /><a href="mailto:%s">%s</a></td>', PMF_Date::createIsoDate($row->ask_date), safeEmail($row->ask_usermail), $row->ask_username); $output .= sprintf('<td valign="top"><strong>%s:</strong><br />%s</td>', $category->categoryName[$row->ask_rubrik]['name'], strip_tags($row->ask_content)); $output .= sprintf('<td valign="top"><a href="%s?%saction=add&question=%d&cat=%d">%s</a></td>', $_SERVER['PHP_SELF'], $sids, $row->id, $row->ask_rubrik, $this->pmf_lang['msg2answer']); $output .= '</tr>'; } } else { $output = sprintf('<tr><td colspan="3">%s</td></tr>', $this->pmf_lang['msgNoQuestionsAvailable']); } return $output . $extraout; }
/** * The main search function for the full text search * * @param string $searchterm Text/Number (solution id) * @param boolean $allLanguages true to search over all languages * * @return array */ public function search($searchterm, $allLanguages = true) { $fdTable = SQLPREFIX . 'faqdata'; $fcrTable = SQLPREFIX . 'faqcategoryrelations'; $condition = array($fdTable . '.active' => "'yes'"); $search = PMF_Search_Factory::create($this->language, array('database' => PMF_Db::getType())); // Search in all or one category? if (!is_null($this->categoryId) && 0 < $this->categoryId) { $selectedCategory = array($fcrTable . '.category_id' => $this->categoryId); $condition = array_merge($selectedCategory, $condition); } if (!$allLanguages && !is_numeric($searchterm)) { $selectedLanguage = array($fdTable . '.lang' => "'" . $this->language->getLanguage() . "'"); $condition = array_merge($selectedLanguage, $condition); } $search->setDatabaseHandle($this->db)->setTable($fdTable)->setResultColumns(array($fdTable . '.id AS id', $fdTable . '.lang AS lang', $fdTable . '.solution_id AS solution_id', $fcrTable . '.category_id AS category_id', $fdTable . '.thema AS question', $fdTable . '.content AS answer'))->setJoinedTable($fcrTable)->setJoinedColumns(array($fdTable . '.id = ' . $fcrTable . '.record_id', $fdTable . '.lang = ' . $fcrTable . '.record_lang'))->setConditions($condition); if (is_numeric($searchterm)) { $search->setMatchingColumns(array($fdTable . '.solution_id')); } else { $search->setMatchingColumns(array($fdTable . '.thema', $fdTable . '.content', $fdTable . '.keywords')); } $result = $search->search($searchterm); if (!$this->db->num_rows($result)) { return array(); } else { return $this->db->fetchAll($result); } }
/** * Returns all tags * * @param string $search Move the returned result set to be the result of a start-with search * @param boolean $limit Limit the returned result set * @return array */ public function getAllTags($search = null, $limit = false, $showInactive = false) { global $DB; $tags = $allTags = array(); // Hack: LIKE is case sensitive under PostgreSQL switch ($DB['type']) { case 'pgsql': $like = 'ILIKE'; break; default: $like = 'LIKE'; break; } $query = sprintf("\n SELECT\n t.tagging_id AS tagging_id, t.tagging_name AS tagging_name\n FROM\n %sfaqtags t\n LEFT JOIN\n %sfaqdata_tags dt\n ON\n dt.tagging_id = t.tagging_id\n LEFT JOIN\n %sfaqdata d\n ON\n d.id = dt.record_id\n WHERE\n 1=1\n %s\n %s\n ORDER BY tagging_name", SQLPREFIX, SQLPREFIX, SQLPREFIX, $showInactive ? '' : "AND d.active = 'yes'", isset($search) && $search != '' ? "AND tagging_name " . $like . " '" . $search . "%'" : ''); $result = $this->db->query($query); if ($result) { while ($row = $this->db->fetch_object($result)) { $allTags[$row->tagging_id] = $row->tagging_name; } } $numberOfItems = $limit ? PMF_TAGS_CLOUD_RESULT_SET_SIZE : $this->db->num_rows($result); if (isset($allTags) && $numberOfItems < count($allTags)) { $keys = array_keys($allTags); shuffle($keys); foreach ($keys as $current_key) { $tags[$current_key] = $allTags[$current_key]; } $tags = array_slice($tags, 0, $numberOfItems, true); } else { $tags = PMF_Utils::shuffleData($allTags); } return $tags; }
/** <<<<<<< HEAD ======= * Prints the open questions as a XHTML table * * @return string * @access public * @since 2002-09-17 * @author Thorsten Rinne <*****@*****.**> */ function printOpenQuestions() { global $sids, $category; if ($this->groupSupport) { $permPart = sprintf("AND ( fdg.group_id IN (%s))", implode(', ', $this->groups), $this->user, implode(', ', $this->groups)); $permPartLeftJoin = sprintf("LEFT JOIN %sfaqcategory_group AS fdg ON fq.ask_rubrik = fdg.category_id", $SQLPREFIX); } else { $permPart = ''; $permPartLeftJoin = ''; } $query = sprintf("\n SELECT\n COUNT(*) AS num\n FROM\n %sfaqquestions \n\t\t\t%s\n WHERE\n is_visible != 'Y'\n\t\t\t%s ", SQLPREFIX, $permPartLeftJoin, $permPart); $result = $this->db->query($query); $row = $this->db->fetch_object($result); $numOfInvisibles = $row->num; if ($numOfInvisibles > 0) { $extraout = sprintf('<tr><td colspan="3"><hr />%s%s</td></tr>', $this->pmf_lang['msgQuestionsWaiting'], $numOfInvisibles); } else { $extraout = ''; } $query = sprintf("\n SELECT\n fq.id,\n fq.ask_username,\n fq.ask_usermail,\n fq.ask_rubrik,\n fq.ask_content,\n fq.ask_date\n FROM\n %sfaqquestions as fq\n %s\n\t\t\tWHERE\n fq.is_visible = 'Y'\n\t\t\t %s\n\t\t\tORDER BY\n ask_date ASC", SQLPREFIX, $permPartLeftJoin, $permPart); $result = $this->db->query($query); $output = ''; if ($this->db->num_rows($result) > 0) { while ($row = $this->db->fetch_object($result)) { $output .= '<tr class="openquestions">'; $output .= sprintf('<td valign="top" nowrap="nowrap">%s<br /><a href="mailto:%s">%s</a></td>', PMF_Date::createIsoDate($row->created), PMF_Mail::safeEmail($row->email), $row->username); $output .= sprintf('<td valign="top"><strong>%s:</strong><br />%s</td>', isset($category->categoryName[$row->category_id]['name']) ? $category->categoryName[$row->category_id]['name'] : '', strip_tags($row->question)); $output .= sprintf('<td valign="top"><a href="?%saction=add&question=%d&cat=%d">%s</a></td>', $sids, $row->id, $row->category_id, $this->pmf_lang['msg2answer']); $output .= '</tr>'; } } else { $output = sprintf('<tr><td colspan="3">%s</td></tr>', $this->pmf_lang['msgNoQuestionsAvailable']); } return $output . $extraout; }
/** * Returns all comments with their categories * * @param string $type Type of comment: faq or news * @return array */ public function getAllComments($type = self::COMMENT_TYPE_FAQ) { $comments = array(); $query = sprintf("\n SELECT\n fc.id_comment AS comment_id,\n fc.id AS record_id,\n %s\n fc.usr AS username,\n fc.email AS email,\n fc.comment AS comment,\n fc.datum AS comment_date\n FROM\n %sfaqcomments fc\n %s\n WHERE\n type = '%s'", $type == self::COMMENT_TYPE_FAQ ? "fcg.category_id,\n" : '', SQLPREFIX, $type == self::COMMENT_TYPE_FAQ ? "LEFT JOIN\n " . SQLPREFIX . "faqcategoryrelations fcg\n ON\n fc.id = fcg.record_id\n" : '', $type); $result = $this->db->query($query); if ($this->db->num_rows($result) > 0) { while ($row = $this->db->fetch_object($result)) { $comments[] = array('comment_id' => $row->comment_id, 'record_id' => $row->record_id, 'category_id' => isset($row->category_id) ? $row->category_id : null, 'content' => $row->comment, 'date' => $row->comment_date, 'username' => $row->username, 'email' => $row->email); } } return $comments; }
/** * Checks the Session ID * * @param integer $sessionId Session ID * @param string $ip IP * * @return void */ public function checkSessionId($sessionId, $ip) { global $sid, $user; $query = sprintf("\n SELECT\n sid\n FROM\n %sfaqsessions\n WHERE\n sid = %d\n AND\n ip = '%s'\n AND\n time > %d", SQLPREFIX, $sessionId, $ip, $_SERVER['REQUEST_TIME'] - 86400); $result = $this->db->query($query); if ($this->db->num_rows($result) == 0) { $this->userTracking('old_session', $sessionId); } else { // Update global session id $sid = $sessionId; // Update db tracking $query = sprintf("\n UPDATE\n %sfaqsessions\n SET\n time = %d,\n user_id = %d\n WHERE\n sid = %d\n AND ip = '%s'", SQLPREFIX, $_SERVER['REQUEST_TIME'], $user ? $user->getUserId() : '-1', $sessionId, $ip); $this->db->query($query); } }
/** * Calculates the rating of the user votings * * @param integer $id * @return string * @access public * @since 2002-08-29 * @author Thorsten Rinne <*****@*****.**> */ function getVotingResult($id) { $query = sprintf('SELECT (vote/usr) as voting, usr FROM %sfaqvoting WHERE artikel = %d', SQLPREFIX, $id); $result = $this->db->query($query); if ($this->db->num_rows($result) > 0) { $row = $this->db->fetch_object($result); return sprintf(' %s %s 5 (' . $this->plr->GetMsg('plmsgVotes', $row->usr) . ')', round($row->voting, 2), $this->pmf_lang['msgVoteFrom']); } else { return sprintf(' 0 %s 5 (' . $this->plr->GetMsg('plmsgVotes', 0) . ')', $this->pmf_lang['msgVoteFrom']); } }
/** * Returns all tags * * @param string $search Move the returned result set to be the result of a start-with search * @param boolean $limit Limit the returned result set * @return array */ public function getAllTags($search = null, $limit = false) { global $DB; $tags = $allTags = array(); // Hack: LIKE is case sensitive under PostgreSQL switch ($DB['type']) { case 'pgsql': $like = 'ILIKE'; break; default: $like = 'LIKE'; break; } $query = sprintf("\n SELECT\n tagging_id, tagging_name\n FROM\n %sfaqtags\n %s\n ORDER BY tagging_name", SQLPREFIX, isset($search) && $search != '' ? "WHERE tagging_name " . $like . " '" . $search . "%'" : ''); $result = $this->db->query($query); if ($result) { while ($row = $this->db->fetch_object($result)) { $allTags[$row->tagging_id] = $row->tagging_name; } } $numberOfItems = $limit ? PMF_TAGS_CLOUD_RESULT_SET_SIZE : $this->db->num_rows($result); if (isset($allTags) && $numberOfItems < count($allTags)) { $keys = array_keys($allTags); for ($n = 0; $n < $numberOfItems; $n++) { $valid = false; while (!$valid) { $rand = array_rand($keys); if (isset($allTags[$rand])) { $valid = true; $tags[$rand] = $allTags[$rand]; unset($keys[$rand]); } } } } else { $tags = PMF_Utils::shuffleData($allTags); } return $tags; }