function search($terms, $where = false, $regexp = false) { # VERY crude search tool. Single arg # # FIXME: # Accept multiple needles # Allow limiting searches to title or content if (!$where) { $where = "content"; } $haystack = KArticles::listarticles(); $terms = explode(" ", $terms); $numberofterms = count($terms); foreach ($haystack as $date => $article) { $rel = 0; foreach ($terms as $null => $term) { if ($regexp != "yes") { $term = "/{$term}\\s/i"; } # default search regexp if ($hits = preg_match_all($term, $article[$where], $hits) and !$nonmatches[$date]) { $rel += $hits; $matches[$date] = array("title" => $article[title], "category" => $article[category], "relevance" => $rel); } else { $nonmatches[$date] = true; unset($matches[$date]); } } } $matching = array_search($term, $haystack); return $matches; }
if (!defined("KNIFE_PATH")) { define("KNIFE_PATH", dirname(__FILE__) . "/"); # Absolute path to current script } include_once KNIFE_PATH . '/inc/class.articles.php'; include_once KNIFE_PATH . '/inc/class.comments.php'; include_once KNIFE_PATH . '/inc/class.users.php'; # load userclass - can't live without include_once KNIFE_PATH . '/inc/class.settings.php'; include_once KNIFE_PATH . '/inc/class.parse.php'; include_once KNIFE_PATH . '/inc/functions.php'; include_once KNIFE_PATH . '/plugins/markdown.php'; $pathinfo_array = explode("/", $_SERVER[PATH_INFO]); $ACDB = new KComments(); $UserDB = new KUsers(); $AADB = new KArticles(); $Settings = new KSettings(); $Parser = new Parser(); $Settings->getCats(); # $Settings->getTemplates(); # Initialize settings $Settings->getConfig(); # $settingsdatabase = new SettingsStorage('settings'); $alltemplates = $Settings->te; $allcats = $Settings->ca; $Config = $Settings->co; $allusers = $UserDB->getusers(); # $null = $UserDB->verify(); include_once KNIFE_PATH . '/config.php';
$catarray = explode(", ", $article[category]); $catamount = count($catarray); if ($catamount == 1) { $catrowcontent = $allcats[$article[category]][name]; } else { # Replace the category numbers with their names foreach ($catarray as $null => $thiscatid) { $thiscatinfo = $allcats[$thiscatid]; $catarray[$null] = $thiscatinfo[name]; } $thiscatnamelisting = implode(", ", $catarray); $catrowcontent = "<acronym title=\"{$thiscatnamelisting}\">{$article['category']}</acronym>"; } $main_content .= "<tr id=\"editlist{$date}\" onmousedown=\"knife_bgc(this, true);\">\n\t\t\t<td onmousedown=\"document.getElementById('del{$date}').checked = (document.getElementById('del{$date}').checked ? false : true);\"><a href=\"?panel=edit&id={$date}\">{$one} {$article['title']}</a></td>\n\t\t\t<td onmousedown=\"document.getElementById('del{$date}').checked = (document.getElementById('del{$date}').checked ? false : true);\">" . date("d/m/y", $date) . "</td>\n\t\t\t<td onmousedown=\"document.getElementById('del{$date}').checked = (document.getElementById('del{$date}').checked ? false : true);\">" . count($KCclass->articlecomments($date)) . "</td>\n\t\t\t<td onmousedown=\"document.getElementById('del{$date}').checked = (document.getElementById('del{$date}').checked ? false : true);\">{$catrowcontent}</td>\n\t\t\t<td onmousedown=\"document.getElementById('del{$date}').checked = (document.getElementById('del{$date}').checked ? false : true);\" title=\"" . i18n("edit_lastedit") . " {$article['lastedit']}\">{$article['author']}</td>\n\t\t\t<td style=\"text-align: right;\"><span class=\"delete\"><a href=\"?panel=edit&id={$date}&action=delete\" title=\"" . i18n("edit_quickerase") . " {$article['title']} ?\">X</a></span> <input type=\"checkbox\" id=\"del{$date}\" name=\"id[]\" value=\"{$date}\" /></td>\n\t\t</tr>"; } $main_content .= "</table><div style=\"text-align: right;\"><br /><input type=\"submit\" name=\"editlist[submit]\" value=\"" . i18n("generic_do") . "\" /></div></form>"; } # # Delete # if ($_GET[action] == "delete" || $_POST[editlist]) { $moduletitle = "Delete article"; $KAclass = new KArticles(); if ($_GET[action] == "delete") { $id = $_GET[id]; $statusmessage = $KAclass->delete($id, false); } else { $id = $_POST[id]; $statusmessage = $KAclass->delete($id, true); } }
# Absolute path to current script } include_once KNIFE_PATH . '/config.php'; # load temporary config include_once KNIFE_PATH . '/inc/class.articles.php'; include_once KNIFE_PATH . '/inc/class.comments.php'; include_once KNIFE_PATH . '/inc/class.users.php'; # load userclass - can't live without include_once KNIFE_PATH . '/lang/nb_no.php'; # load a language include_once KNIFE_PATH . '/inc/functions.php'; include_once KNIFE_PATH . '/plugins/markdown.php'; $pathinfo_array = explode("/", $_SERVER[PATH_INFO]); $commentsclass = new KComments(); $Userclass = new KUsers(); $KAclass = new KArticles(); # # Reset some variables # $timestamp = 0; # # Display articles # $settingsdatabase = new SettingsStorage('settings'); $alltemplates = $settingsdatabase->settings['templates']; $allcats = $settingsdatabase->settings['categories']; $allusers = $Userclass->getusers(); if ($template) { $template = $alltemplates[$template]; } else { $template = $alltemplates[1];
if ($User->level < 2) { die(i18n("login_noaccess")); } # # Setup # $moduletitle = i18n("write_mainmodtitle"); $settingsclass = new SettingsStorage('settings'); $currentcats = $settingsclass->settings['categories']; include KNIFE_PATH . '/inc/class.articles.php'; # # If article submitted # if ($_POST[article] && !$_POST[preview]) { $KAclass = new KArticles(); $statusmessage = $KAclass->add($User->username); } # # If preview # if ($_POST[preview]) { include "plugins/markdown.php"; $main_content = ' <div id="article_preview_wrapper"> <div class="div_normal"> <fieldset> <legend>Article content preview:</legend> ' . Markdown($_POST[article][content]) . ' </fieldset>
<?php $moduletitle = i18n("dashboard_moduletitle"); $statusmessage = i18n("login_YouAre") . $User->nickname; include KNIFE_PATH . '/inc/class.comments.php'; include KNIFE_PATH . '/inc/class.articles.php'; $Commentclass = new KComments(); $Articleclass = new KArticles(); $templates = $settingsdatabase->settings['templates']; $articledatabase = new ArticleStorage('storage'); $allarticles = $articledatabase->settings['articles']; $configuration = $settingsdatabase->settings['configuration']; krsort($allarticles); $totalarticles = count($allarticles); $totalusers = count($users); $main_content = "\n\t<div id=\"dashboard_wrapper\">\n\t\t<div class=\"div_extended\">\n\t\t<fieldset>\n\t\t\t<legend>" . i18n("dashboard_Statistics") . "</legend>\n\t\t" . i18n("dashboard_Articles") . ": {$totalarticles}<br />\n\t\t" . i18n("dashboard_Users") . ": {$totalusers}<br />\n\t\t" . i18n("dashboard_ACS") . ": " . formatsize(filesize("./data/articles.php")) . "<br />\n\t\t\t<acronym title=\"" . i18n("templates") . ", " . i18n("users") . ", etc\">" . i18n("dashboard_SS") . "</acronym>: " . formatsize(filesize("./data/settings.php")) . "\n\t\t</div>"; # # TODO. Remove later. # $main_content .= "\n\t<div class=\"div_normal\">\n\t\t<fieldset>\n\t\t\t<legend>Todo</legend>\n\t\t<ol>\n\t\t\t<li>Users<ul><li><del>Add</del></li><li><del>Edit</del></li><li><del>Delete</del></li><li><del>Passwords encrypted sha1(md5(password+unique_id_generated_on_install))</del></li><li>Non-Admin Profiles</li></ul></li>\n\t\t\t<li>Options</li>\n\t\t\t<li>Templates<ul><li><del>Add template</del></li><li><del>Edit template</del></li><li><del>Delete template</del></li></ul></li>\n\t\t\t<li><del>Login system</del>\n\t\t\t\t<ul>\n\t\t\t\t\t<li>Access levels\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t<li>4 / Admin\n\t\t\t\t\t\t\t<ul><li>Can do anything including deleting other admins</li></ul></li>\n\t\t\t\t\t\t<li>3 / Editor\n\t\t\t\t\t\t\t<ul><li>Add posts</li>\n\t\t\t\t\t\t\t\t<li>Edit all posts</li>\n\t\t\t\t\t\t\t\t<li>Personal options</li>\n\t\t\t\t\t\t\t\t<li>Set up categories</li>\n\t\t\t\t\t\t\t</ul></li>\n\t\t\t\t\t\t<li>2 / Journalist\n\t\t\t\t\t\t\t<ul><li>Add posts</li>\n\t\t\t\t\t\t\t\t<li>Edit <strong>own</strong> posts</li>\n\t\t\t\t\t\t\t</ul></li>\n\t\t\t\t\t\t<li>4 / Commenter\n\t\t\t\t\t\t\t<ul><li>Nick will be registered for commenting</li>\n\t\t\t\t\t\t\t\t<li>Can view/edit personal options</li>\n\t\t\t\t\t\t\t</ul></li>\n\t\t\t\t\t</ul>\n\t\t\t\t\t</li>\n\t\t\t\t\t<li>Language selected on login, saved in expireless cookie?</li>\n\t\t\t\t</ul>\n\t\t\t</li>\n\t\t\t<li>Categories<ul><li>Add</li><li>Edit</li><li>Delete</li><li>Default template</li></ul></li>\n\t\t\t<li>Plugins</li>\n\t\t\t<li>Comments</li>\n\t\t\t<li><del>Write news</del><ul><li>Custom date</li></ul></li>\n\t\t\t<li><del>Edit news</del><ul><li>Custom date</li><li><del>Delete article</del></li><li><del>Delete articles</del></li></ul></li>\n\t\t\t<li>Generate archive</li>\n\t\t\t<li>Search!</li>\n\t\t\t<li>MySQL</li></ol>\n\t\t</fieldset>\n\t\t<fieldset>\n\t\t\t<legend>Musical drive</legend>\n\t\t<ol>\n\t\t\t<li>The Donnas ( Spend the night )</li>\n\t\t\t<li>Porcupine Tree ( In absentia )</li>\n\t\t\t<li>Ed Harcourt ( From every sphere )</li>\n\t\t\t<li>U2\n\t\t\t\t<ul><li>How to dismantle an atomic bomb</li>\n\t\t\t\t<li>All that you can't leave behind</li></ul></li>\n\t\t\t<li>Kent\n\t\t\t\t<ul><li>Hagnesta Hill</li><li>Isola</li></ul></li>\n\t\t\t<li>Kula Shaker ( K )</li>\n\t\t\t<li>Lisa Miskovsky<ul><li>Lisa Miskovsky</li><li>Fallingwater</li></ul></li>\n\t\t\t<li>Modest Mouse (Good news for people who love bad news)</li>\n\t\t\t</ol>\n\t\t\t</fieldset>\n\t\t</div>\n\t</div>"; $main_content .= '<div class="div_normal"><fieldset><legend>Latest comments</legend>'; $number = 5; $latestcomments = $Commentclass->latestcomments($number); foreach ($latestcomments as $commentid => $commentdata) { $article = $Articleclass->getarticle($commentdata[parent]); $title = $article[title]; $main_content .= date("d/m ", $commentid) . $commentdata[name] . " <small>commenting {$title}</small> <blockquote>" . $commentdata[content] . "</blockquote><br />"; } $main_content .= '</fieldset></div>';
function articleupdate($timestamp, $method, $modifier) { if ($method == "views") { # this method increments views by one # and returns the current amount of views if (defined("KNIFESQL")) { $dataclass = KArticles::connect(); $mysql_query = "SELECT views FROM articles WHERE articleid = {$timestamp}"; $result = mysql_query($mysql_query) or die("Failed: " . mysql_error()); $views = mysql_fetch_assoc($result); $views = $views[views]; if ($modifier == "update") { $views++; $mysql_query = "UPDATE articles SET views = {$views} WHERE articleid = {$timestamp}"; $result = mysql_query($mysql_query) or die("Failed: " . mysql_error()); } return $views; } else { $dataclass = KArticles::connect(); $views = $dataclass->settings['articles'][$timestamp][views]; if ($modifier == "update") { $views++; $dataclass->settings['articles'][$timestamp][views] = $views; $dataclass->save(); } return $views; } } }