/** * Returns a list of the most recent declarations of this person. * * @param {String} $query The query we are looking for. * @param {Number} $start Where to start the results from. * @param {Number} $count The number of declarations that we need. * @param {Boolean} $full_text Whether we want to return just snippets or * the full text for each of the results. * @param {String} $restrict The category of declarations that I am looking * for. Acceptable values for this are 'all', 'important' or 'mine'. * @return {Array} The array of results. */ public function searchDeclarations($query, $start, $count, $full_text, $restrict, $justDeclarationId = 0) { $navigationalRestrict = $justDeclarationId ? "AND d.id={$justDeclarationId}" : ""; if ($restrict == 'all') { $s = mysql_query("\n SELECT d.id, d.source, d.declaration, d.time\n FROM people_declarations AS d\n WHERE d.idperson = {$this->id} AND\n d.declaration LIKE '%{$query}%'\n {$navigationalRestrict}\n ORDER BY d.time DESC\n LIMIT {$start}, {$count}\n "); } else { if ($restrict == 'important') { $sql = "\n SELECT d.id, h.source, d.declaration, d.time\n FROM people_declarations AS d\n LEFT JOIN people_declarations_highlights AS h ON h.source = d.source\n WHERE idperson = {$this->id}\n {$navigationalRestrict}\n GROUP BY h.source\n ORDER BY time DESC\n LIMIT {$start}, {$count}\n "; $s = mysql_query($sql); } else { if ($restrict == 'mine') { $uid = is_user_logged_in() ? wp_get_current_user()->ID : 0; $sql = "\n SELECT d.id, h.source, d.declaration, d.time\n FROM people_declarations AS d\n LEFT JOIN people_declarations_highlights AS h ON h.source = d.source\n WHERE\n idperson = {$this->id} AND\n h.user_id={$uid}\n {$navigationalRestrict}\n GROUP BY h.source\n ORDER BY time DESC\n LIMIT {$start}, {$count}\n "; $s = mysql_query($sql); } else { return array(); } } } $results = array(); while ($r = mysql_fetch_array($s)) { if (!$r['source']) { continue; } // HACK: Because I know that the transcripts from cdep.ro have only this // one tag in them, I will manually replace it. $r['declaration'] = preg_replace('/<p align="justify">/', ' ', $r['declaration']); $r['declaration'] = strip_tags($r['declaration']); $r['declaration'] = stripslashes($r['declaration']); $r['snippet'] = $full_text ? $r['declaration'] : getSnippet($r['declaration'], $query, $full_text); $r['snippet'] = markDownTextBlock($r['snippet'], ""); if ($query != '') { $r['snippet'] = highlightStr($r['snippet'], $query); } $results[] = $r; } return $results; }
/** * Highlights a list of words inside a string. * @param $haystack * @param $needles * @return mixed|string */ function highlightWords($haystack, $needles) { foreach ($needles as $needle) { $haystack = highlightStr($haystack, $needle); } return $haystack; }