function listCommentsSearchResultGUI() { $table = listCommentsSearchService($_REQUEST['author']); $num_rows = getRowsAffected($table); h3("Søkte etter kommentarer skrevet av bruker " . $_REQUEST['author'] . ", " . $num_rows . " treff"); if ($table == NULL) { echo "Finner ingen kommentarer av valgt bruker."; } else { table_open(); while ($row = nextResultInTable($table)) { if (isArticleAndAlive($row['comment_to'])) { tr_open(); echo '<td style="width:80px">'; echo make_ddmmyy_date($row['date_posted']); td_close(); td_open(1); print_article_link($row['comment_to'], $row['title']); echo "(Kommentar til: "; print_parent_article_link($row['comment_to']); echo ")"; td_close(); tr_close(); } } table_close(); } }
function isArticleAndAlive($articleid) { $query = "SELECT * FROM articles WHERE articleid=" . $articleid . " AND comment_to IS NULL and is_deleted IS NULL AND is_draft IS NULL;"; $table = getTable($query); $numRows = getRowsAffected($table); if ($numRows == 0) { return false; } return true; }
function textSearchService($text, $partialmatch, $author, $checkcomments) { if (strlen($text) < 3) { return NULL; } $text = makeSafeForDAO($text); $selectfrom = "SELECT * FROM articles "; $where = "WHERE body LIKE '%" . $text . "%' AND is_deleted IS NULL AND is_draft IS NULL "; $orderby = " ORDER BY date_posted DESC, time_posted DESC;"; $findWordAlone = "| " . $text . "[ !?,.:;'/)]|i"; $findWordAnywhere = "|" . $text . "|i"; if ($partialmatch == 0) { $pattern = $findWordAlone; } else { $pattern = $findWordAnywhere; } if ($author == "0") { } else { $where .= " AND author_username = '******' "; } if ($checkcomments == "0") { $where .= " AND comment_to IS NULL"; } $query = $selectfrom . $where . $orderby; $newtable = array(); $table = getTable($query); $num_rows = getRowsAffected($table); if ($table && $num_rows > 0) { while ($row = getNextRow($table)) { if (preg_match($pattern, $row['body'])) { $newtable[] = $row; // Add row to array } } return $newtable; } else { return NULL; } }
function articlesInTable($table) { return getRowsAffected($table); }