for those purposes. This was clearly stated in the page
you used to submit your note, please carefully re-read
those instructions before submitting future contributions.
Bug submissions and feature requests should be entered at
Showing $from - $to of $resultCount results.
';
}
if (isset($_REQUEST['keyword']) || isset($_REQUEST["view"])) {
// Pagination start
$page = isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 0;
$NextPage = isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 0;
$type = isset($_REQUEST["type"]) ? intval($_REQUEST["type"]) : 0;
if($page < 0) { $page = 0; }
if($NextPage < 0) { $NextPage = 0; }
$limit = $page * 10; $page++;
$limitVotes = $NextPage * 25; $NextPage++;
$PrevPage = ($NextPage - 2) > -1 ? $NextPage - 2 : 0;
// Pagination end
if(isset($_REQUEST['keyword'])) {
$query = new Query('SELECT SUM(votes.vote) AS up, (COUNT(votes.vote) - SUM(votes.vote)) AS down, note.*, UNIX_TIMESTAMP(note.ts) AS ts '.
'FROM note '.
'LEFT JOIN(votes) ON (note.id = votes.note_id) '.
'WHERE ');
if (is_numeric($_REQUEST['keyword'])) {
$search_heading = 'Search results for #' . (int) $_REQUEST['keyword'];
$query->add('note.id = ?', [$_REQUEST['keyword']]);
} elseif (substr($_REQUEST['keyword'], 0, 5) == 'sect:') {
$search_heading = 'Search results for ' . hsc($_REQUEST['keyword']) . '';
$section = str_replace('*', '%', substr($_REQUEST['keyword'], 5));
$query->add("note.sect LIKE ? GROUP BY note.id ORDER BY note.sect, note.ts LIMIT ?int, 10", [$section, $limit]);
} else {
$search_heading = 'Search results for ' . hsc($_REQUEST['keyword']) . '';
$query->add(
"note.note LIKE ? GROUP BY note.id LIMIT ?int, 10",
['%' . $_REQUEST['keyword'] . '%', $limit]);
}
$result = db_query_safe($query->get());
} else {
/* Added new voting information to be included in note from votes table. */
/* First notes */
if ($type == 1) {
$search_heading = 'First notes';
$result = db_query_safe("SELECT SUM(votes.vote) AS up, (COUNT(votes.vote) - SUM(votes.vote)) AS down, note.*, UNIX_TIMESTAMP(note.ts) AS ts ".
"FROM note ".
"LEFT JOIN(votes) ON (note.id = votes.note_id) ".
"GROUP BY note.id ORDER BY note.id ASC LIMIT ?int, 10", [$limit]);
/* Minor notes */
} else if ($type == 2) {
$search_heading = 'Minor notes';
$result = db_query_safe("SELECT SUM(votes.vote) AS up, (COUNT(votes.vote) - SUM(votes.vote)) AS down, note.*, UNIX_TIMESTAMP(note.ts) AS ts ".
"FROM note ".
"LEFT JOIN(votes) ON (note.id = votes.note_id) ".
"GROUP BY note.id ORDER BY LENGTH(note.note) ASC LIMIT ?int, 10", [$limit]);
/* Top rated notes */
} else if ($type == 3) {
$search_heading = 'Top rated notes';
$result = db_query_safe("SELECT SUM(votes.vote) AS up, (COUNT(votes.vote) - SUM(votes.vote)) AS down, ".
"ROUND((SUM(votes.vote) / COUNT(votes.vote)) * 100) AS rate, ".
"(SUM(votes.vote) - (COUNT(votes.vote) - SUM(votes.vote))) AS arating, ".
"note.id, note.sect, note.user, note.note, UNIX_TIMESTAMP(note.ts) AS ts ".
"FROM note ".
"JOIN(votes) ON (note.id = votes.note_id) ".
"GROUP BY note.id ORDER BY arating DESC, up DESC, rate DESC, down DESC LIMIT ?int, 10", [$limit]);
/* Bottom rated notes */
} else if ($type == 4) {
$search_heading = 'Bottom rated notes';
$result = db_query_safe("SELECT SUM(votes.vote) AS up, (COUNT(votes.vote) - SUM(votes.vote)) AS down, ".
"ROUND((SUM(votes.vote) / COUNT(votes.vote)) * 100) AS rate, ".
"(SUM(votes.vote) - (COUNT(votes.vote) - SUM(votes.vote))) AS arating, ".
"note.id, note.sect, note.user, note.note, UNIX_TIMESTAMP(note.ts) AS ts ".
"FROM note ".
"JOIN(votes) ON (note.id = votes.note_id) ".
"GROUP BY note.id ORDER BY arating ASC, up ASC, rate ASC, down DESC LIMIT ?int, 10", [$limit]);
/* Votes table view */
} else if ($type == 5) {
$search_votes = true; // set this only to change the output between votes table and notes table
if (!empty($_GET['votessearch'])) {
if (($iprange = wildcard_ip($_GET['votessearch'])) !== false) {
$search = html_entity_decode($_GET['votessearch'], ENT_QUOTES, 'UTF-8');
$start = $iprange[0];
$end = $iprange[1];
$resultCount = db_query_safe("SELECT count(votes.id) AS total_votes FROM votes JOIN (note) ON (votes.note_id = note.id) WHERE ".
"(hostip >= ? AND hostip <= ?) OR (ip >= ? AND ip <= ?)", [$start, $end, $start, $end]);
$resultCount = mysql_fetch_assoc($resultCount);
$resultCount = $resultCount['total_votes'];
$isSearch = '&votessearch=' . hsc($search);
$result = db_query_safe(
'SELECT votes.id, UNIX_TIMESTAMP(votes.ts) AS ts, votes.vote, votes.note_id, note.sect, votes.hostip, votes.ip '.
'FROM votes JOIN(note) ON (votes.note_id = note.id) '.
'WHERE (hostip >= ? AND hostip <= ?) OR (ip >= ? AND ip <= ?) '.
'ORDER BY votes.id DESC LIMIT ?int, 25',
[$start, $end, $start, $end, $limitVotes]);
} elseif (filter_var(html_entity_decode($_GET['votessearch'], ENT_QUOTES, 'UTF-8'), FILTER_VALIDATE_IP)) {
$searchip = (int) ip2long(filter_var(html_entity_decode($_GET['votessearch'], ENT_QUOTES, 'UTF-8'), FILTER_VALIDATE_IP));
$resultCount = db_query_safe("SELECT count(votes.id) AS total_votes FROM votes JOIN(note) ON (votes.note_id = note.id) WHERE hostip = ? OR ip = ?", [$searchip, $searchip]);
$resultCount = mysql_fetch_assoc($resultCount);
$resultCount = $resultCount['total_votes'];
$isSearch = '&votessearch=' . hsc(long2ip($searchip));
$result = db_query_safe(
"SELECT votes.id, UNIX_TIMESTAMP(votes.ts) AS ts, votes.vote, votes.note_id, note.sect, votes.hostip, votes.ip ".
"FROM votes JOIN(note) ON (votes.note_id = note.id) ".
"WHERE hostip = ? OR ip = ? ".
"ORDER BY votes.id DESC LIMIT ?int, 25",
[$searchip, $searchip, $limitVotes]);
} else {
$search = (int) html_entity_decode($_GET['votessearch'], ENT_QUOTES, 'UTF-8');
$resultCount = db_query_safe("SELECT count(votes.id) AS total_votes FROM votes JOIN(note) ON (votes.note_id = note.id) WHERE votes.note_id = ?", [$search]);
$resultCount = mysql_fetch_assoc($resultCount);
$resultCount = $resultCount['total_votes'];
$isSearch = '&votessearch=' . hsc($search);
$result = db_query_safe(
"SELECT votes.id, UNIX_TIMESTAMP(votes.ts) AS ts, votes.vote, votes.note_id, note.sect, votes.hostip, votes.ip ".
"FROM votes JOIN(note) ON (votes.note_id = note.id) ".
"WHERE votes.note_id = ? ".
"ORDER BY votes.id DESC LIMIT ?int, 25",
[$search, $limitVotes]);
}
} else {
$isSearch = null;
$resultCount = db_query_safe("SELECT COUNT(votes.id) AS total_votes FROM votes JOIN(note) ON (votes.note_id = note.id)");
$resultCount = mysql_fetch_assoc($resultCount);
$resultCount = $resultCount['total_votes'];
$result = db_query_safe(
"SELECT votes.id, UNIX_TIMESTAMP(votes.ts) AS ts, votes.vote, votes.note_id, note.sect, votes.hostip, votes.ip ".
"FROM votes JOIN(note) ON (votes.note_id = note.id) ".
"ORDER BY votes.id DESC LIMIT ?int, 25",
[$limitVotes]);
}
/* IPs with the most votes -- aggregated data */
} elseif ($type == 6) {
$votes_by_ip = true; // only set this get the table for top IPs with votes
$result = db_query_safe(
"SELECT DISTINCT(votes.ip), COUNT(votes.ip) as votes, COUNT(DISTINCT(votes.note_id)) as notes, ".
"INET_NTOA(votes.ip) AS ip, MIN(UNIX_TIMESTAMP(votes.ts)) AS `from`, MAX(UNIX_TIMESTAMP(votes.ts)) AS `to` ".
"FROM votes ".
"JOIN (note) ON (votes.note_id = note.id) GROUP BY votes.ip ORDER BY votes DESC LIMIT 100");
/* Last notes */
} else {
$search_heading = 'Last notes';
$result = db_query_safe(
"SELECT SUM(votes.vote) AS up, (COUNT(votes.vote) - SUM(votes.vote)) AS down, note.*, UNIX_TIMESTAMP(note.ts) AS ts ".
"FROM note LEFT JOIN(votes) ON (note.id = votes.note_id) ".
"GROUP BY note.id ORDER BY note.id DESC LIMIT ?int, 10",
[$limit]);
}
}
if ($result) {
/* This is a special table only used for viewing the most recent votes */
$t = (isset($_GET['type']) ? '&type=' . $_GET['type'] : null);
if (!empty($search_votes)) {
$from = $limitVotes + 1;
$to = $NextPage * 25;
$to = $to > $resultCount ? $resultCount : $to;
if ($resultCount) {
echo "
You have to fill-in curent section or notes IDs (or both).
\n"; } } } if ($step < 2) { ?>Change section of notes which fit these criteria:
Current section: | " size="30" maxlength="80" /> (filename without extension) |
---|---|
Notes IDs: | " size="30" maxlength="80" /> (comma separated list) |
Move to section: | " size="30" maxlength="80" /> |
",clean_note($note),
"
Section: | |
---|---|
email: | |
\nAre you sure you want to reset all votes for Note #". hsc($row['id']) ."? "; if ($action == 'resetall') { $out .= "This will permanently delete all ". hsc($row['up']) ." up votes and ". hsc($row['down']) ." down votes for this note.\n
\n". "Note ". hsc($id) ." does not exist!
"; } } } else { echo "Note id not supplied...
"; } foot(); exit; case 'deletevotes': /* Only those with privileges in allow_mass_change may use these options */ if (!allow_mass_change($cuser)) { die("You do not have access to use this feature!"); } /* Delete votes -- effectively deletes votes found in the votes table matching all supplied ids */ if (empty($_POST['deletevote']) || !is_array($_POST['deletevote'])) { die("No vote ids supplied!"); } $ids = []; foreach ($_POST['deletevote'] as $id) { $ids[] = (int) $id; } $ids = implode(',',$ids); // This is safe, because $ids is an array of integers. if (db_query_safe("DELETE FROM votes WHERE id IN ($ids)")) { header('Location: user-notes.php?id=1&view=notes&was=' . urlencode($action) . (isset($_REQUEST['type']) ? ('&type=' . urlencode($_REQUEST['type'])) : null) . (isset($_REQUEST['votessearch']) ? '&votessearch=' . urlencode($_REQUEST['votessearch']) : null) ); } exit; case 'sect': head('user notes'); ?>You can search notes within specified section of the PHP manual using form below or by prepending your query with sect: in regular search form (like sect:book.mysql).
You can use * as a wildcard, like mysql.*. Query like function.json-* should show all notes for JSON functions (use sect:function.json-* in case of generic form).
Go back to the notes management
'$action' is not a recognized action, or no id was specified."; foot(); } // ---------------------------------------------------------------------------------- // Use class names instead of colors ini_set('highlight.comment', 'comment'); ini_set('highlight.default', 'default'); ini_set('highlight.keyword', 'keyword'); ini_set('highlight.string', 'string'); ini_set('highlight.html', 'html'); // Copied over from phpweb (should be syncronised if changed) function clean_note($text) { // Highlight PHP source $text = highlight_php(trim($text), TRUE); // Turn urls into links $text = preg_replace( '!((mailto:|(http|ftp|nntp|news):\/\/).*?)(\s|<|\)|"|\\|\'|$)!', '\1\4', $text ); return $text; } // Highlight PHP code function highlight_php($code, $return = FALSE) { // Using OB, as highlight_string() only supports // returning the result from 4.2.0 ob_start(); highlight_string($code); $highlighted = ob_get_contents(); ob_end_clean(); // Fix output to use CSS classes and wrap well $highlighted = '