Initial sub-categories code from Jason Verber

git-svn-id: https://develop.svn.wordpress.org/trunk@798 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2004-01-27 06:35:07 +00:00
parent 3ca7dad5d1
commit 4b4a1405f3
5 changed files with 1723 additions and 1598 deletions

View File

@ -9,11 +9,16 @@ function gethelp_link($this_file, $helptag) {
return $s;
}
if (!isset($use_cache)) $use_cache=1;
if (!isset($blogID)) $blog_ID=1;
if (!isset($debug)) $debug=0;
if (!isset($use_cache)) $use_cache=1;
if (!isset($blogID)) $blog_ID=1;
if (!isset($debug)) $debug=0;
timer_start();
$dogs = $wpdb->get_results("SELECT * FROM $tablecategories WHERE 1=1");
foreach ($dogs as $catt) {
$cache_categories[$catt->cat_ID] = $catt;
}
get_currentuserinfo();
$posts_per_page = get_settings('posts_per_page');
@ -27,22 +32,22 @@ $admin_area_charset = (!isset($admin_area_charset)) ? 'iso-8859-15' : $admin_are
// let's deactivate quicktags on IE Mac and Lynx, because they don't work there.
if (($is_macIE) || ($is_lynx))
$use_quicktags = 0;
$use_quicktags = 0;
$wpvarstoreset = array('profile','standalone','redirect','redirect_url','a','popuptitle','popupurl','text', 'trackback', 'pingback');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
if (!isset($$wpvar)) {
if (empty($HTTP_POST_VARS["$wpvar"])) {
if (empty($HTTP_GET_VARS["$wpvar"])) {
$$wpvar = '';
} else {
$$wpvar = $HTTP_GET_VARS["$wpvar"];
}
} else {
$$wpvar = $HTTP_POST_VARS["$wpvar"];
}
}
$wpvar = $wpvarstoreset[$i];
if (!isset($$wpvar)) {
if (empty($HTTP_POST_VARS["$wpvar"])) {
if (empty($HTTP_GET_VARS["$wpvar"])) {
$$wpvar = '';
} else {
$$wpvar = $HTTP_GET_VARS["$wpvar"];
}
} else {
$$wpvar = $HTTP_POST_VARS["$wpvar"];
}
}
}
if ($standalone == 0) {
@ -72,65 +77,65 @@ setTimeout("redirect();", 600);
<script language="javascript" type="text/javascript">
//<![CDATA[
function profile(userID) {
window.open ("profile.php?action=viewprofile&user="+userID, "Profile", "width=500, height=450, location=0, menubar=0, resizable=0, scrollbars=1, status=1, titlebar=0, toolbar=0, screenX=60, left=60, screenY=60, top=60");
}
function profile(userID) {
window.open ("profile.php?action=viewprofile&user="+userID, "Profile", "width=500, height=450, location=0, menubar=0, resizable=0, scrollbars=1, status=1, titlebar=0, toolbar=0, screenX=60, left=60, screenY=60, top=60");
}
function launchupload() {
window.open ("upload.php", "wpupload", "width=380,height=360,location=0,menubar=0,resizable=1,scrollbars=yes,status=1,toolbar=0");
}
function launchupload() {
window.open ("upload.php", "wpupload", "width=380,height=360,location=0,menubar=0,resizable=1,scrollbars=yes,status=1,toolbar=0");
}
function helpWindow(url) {
window.open(url, "Help", "width=640, height=450, location=0, menubar=0, resizable=0, scrollbars=1, status=1, titlebar=0, toolbar=0, screenX=60, left=60, screenY=60, top=60");
}
function GetElementsWithClassName(elementName, className) {
var allElements = document.getElementsByTagName(elementName);
var elemColl = new Array();
for (i = 0; i < allElements.length; i++) {
if (allElements[i].className == className) {
elemColl[elemColl.length] = allElements[i];
}
}
return elemColl;
}
function blurry() {
if (!document.getElementById) return;
var aInputs = document.getElementsByTagName('input');
for (var i = 0; i < aInputs.length; i++) {
aInputs[i].onclick = function() {
var inputColl = GetElementsWithClassName('input','valinp');
var rel = document.getElementById('rel');
var inputs = '';
for (i = 0; i < inputColl.length; i++) {
if (inputColl[i].checked) {
if (inputColl[i].value != '') inputs += inputColl[i].value + ' ';
}
}
inputs = inputs.substr(0,inputs.length - 1);
rel.value = inputs;
}
aInputs[i].onkeyup = function() {
var inputColl = GetElementsWithClassName('input','valinp');
var rel = document.getElementById('rel');
var inputs = '';
for (i = 0; i < inputColl.length; i++) {
if (inputColl[i].checked) {
inputs += inputColl[i].value + ' ';
}
}
inputs = inputs.substr(0,inputs.length - 1);
rel.value = inputs;
}
}
}
window.onload = blurry;
window.open(url, "Help", "width=640, height=450, location=0, menubar=0, resizable=0, scrollbars=1, status=1, titlebar=0, toolbar=0, screenX=60, left=60, screenY=60, top=60");
}
function GetElementsWithClassName(elementName, className) {
var allElements = document.getElementsByTagName(elementName);
var elemColl = new Array();
for (i = 0; i < allElements.length; i++) {
if (allElements[i].className == className) {
elemColl[elemColl.length] = allElements[i];
}
}
return elemColl;
}
function blurry() {
if (!document.getElementById) return;
var aInputs = document.getElementsByTagName('input');
for (var i = 0; i < aInputs.length; i++) {
aInputs[i].onclick = function() {
var inputColl = GetElementsWithClassName('input','valinp');
var rel = document.getElementById('rel');
var inputs = '';
for (i = 0; i < inputColl.length; i++) {
if (inputColl[i].checked) {
if (inputColl[i].value != '') inputs += inputColl[i].value + ' ';
}
}
inputs = inputs.substr(0,inputs.length - 1);
rel.value = inputs;
}
aInputs[i].onkeyup = function() {
var inputColl = GetElementsWithClassName('input','valinp');
var rel = document.getElementById('rel');
var inputs = '';
for (i = 0; i < inputColl.length; i++) {
if (inputColl[i].checked) {
inputs += inputColl[i].value + ' ';
}
}
inputs = inputs.substr(0,inputs.length - 1);
rel.value = inputs;
}
}
}
window.onload = blurry;
//]]>
</script>
</head>
@ -138,10 +143,10 @@ setTimeout("redirect();", 600);
<?php
if ($profile==0) {
include('menu.php');
include('menu.php');
}
?>
<?php
}
?>
?>

View File

@ -3,180 +3,188 @@ $title = 'Categories';
/* <Categories> */
function add_magic_quotes($array) {
foreach ($array as $k => $v) {
if (is_array($v)) {
$array[$k] = add_magic_quotes($v);
} else {
$array[$k] = addslashes($v);
}
}
return $array;
}
foreach ($array as $k => $v) {
if (is_array($v)) {
$array[$k] = add_magic_quotes($v);
} else {
$array[$k] = addslashes($v);
}
}
return $array;
}
if (!get_magic_quotes_gpc()) {
$HTTP_GET_VARS = add_magic_quotes($HTTP_GET_VARS);
$HTTP_POST_VARS = add_magic_quotes($HTTP_POST_VARS);
$HTTP_COOKIE_VARS = add_magic_quotes($HTTP_COOKIE_VARS);
$HTTP_GET_VARS = add_magic_quotes($HTTP_GET_VARS);
$HTTP_POST_VARS = add_magic_quotes($HTTP_POST_VARS);
$HTTP_COOKIE_VARS = add_magic_quotes($HTTP_COOKIE_VARS);
}
$wpvarstoreset = array('action','standalone','cat');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
if (!isset($$wpvar)) {
if (empty($HTTP_POST_VARS["$wpvar"])) {
if (empty($HTTP_GET_VARS["$wpvar"])) {
$$wpvar = '';
} else {
$$wpvar = $HTTP_GET_VARS["$wpvar"];
}
} else {
$$wpvar = $HTTP_POST_VARS["$wpvar"];
}
}
$wpvar = $wpvarstoreset[$i];
if (!isset($$wpvar)) {
if (empty($HTTP_POST_VARS["$wpvar"])) {
if (empty($HTTP_GET_VARS["$wpvar"])) {
$$wpvar = '';
} else {
$$wpvar = $HTTP_GET_VARS["$wpvar"];
}
} else {
$$wpvar = $HTTP_POST_VARS["$wpvar"];
}
}
}
switch($action) {
case 'addcat':
$standalone = 1;
require_once('admin-header.php');
if ($user_level < 3)
die ('Cheatin&#8217; uh?');
$cat_name= addslashes(stripslashes(stripslashes($HTTP_POST_VARS['cat_name'])));
$category_nicename = sanitize_title($cat_name);
$category_description = addslashes(stripslashes(stripslashes($HTTP_POST_VARS['category_description'])));
$wpdb->query("INSERT INTO $tablecategories (cat_ID, cat_name, category_nicename, category_description) VALUES ('0', '$cat_name', '$category_nicename', '$category_description')");
header('Location: categories.php');
$standalone = 1;
require_once('admin-header.php');
if ($user_level < 3)
die ('Cheatin&#8217; uh?');
$cat_name= addslashes(stripslashes(stripslashes($HTTP_POST_VARS['cat_name'])));
$category_nicename = sanitize_title($cat_name);
$category_description = addslashes(stripslashes(stripslashes($HTTP_POST_VARS['category_description'])));
$wpdb->query("INSERT INTO $tablecategories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', $cat)");
header('Location: categories.php');
break;
case 'Delete':
$standalone = 1;
require_once('admin-header.php');
$standalone = 1;
require_once('admin-header.php');
$cat_ID = intval($HTTP_GET_VARS["cat_ID"]);
$cat_name = get_catname($cat_ID);
$cat_name = addslashes($cat_name);
$cat_ID = intval($HTTP_GET_VARS["cat_ID"]);
$cat_name = get_catname($cat_ID);
$cat_name = addslashes($cat_name);
if (1 == $cat_ID)
die("Can't delete the <strong>$cat_name</strong> category: this is the default one");
if (1 == $cat_ID)
die("Can't delete the <strong>$cat_name</strong> category: this is the default one");
if ($user_level < 3)
die ('Cheatin&#8217; uh?');
if ($user_level < 3)
die ('Cheatin&#8217; uh?');
$wpdb->query("DELETE FROM $tablecategories WHERE cat_ID = $cat_ID");
$wpdb->query("UPDATE $tablepost2cat SET category_id='1' WHERE category_id='$cat_ID'");
$wpdb->query("DELETE FROM $tablecategories WHERE cat_ID = $cat_ID");
$wpdb->query("UPDATE $tablepost2cat SET category_id='1' WHERE category_id='$cat_ID'");
header('Location: categories.php');
header('Location: categories.php');
break;
case 'edit':
require_once ('admin-header.php');
$category = $wpdb->get_row("SELECT * FROM $tablecategories WHERE cat_ID = " . $HTTP_GET_VARS['cat_ID']);
$cat_name = stripslashes($category->cat_name);
?>
require_once ('admin-header.php');
$category = $wpdb->get_row("SELECT * FROM $tablecategories WHERE cat_ID = " . $HTTP_GET_VARS['cat_ID']);
$cat_name = stripslashes($category->cat_name);
?>
<div class="wrap">
<h2>Edit Category</h2>
<form name="editcat" action="categories.php" method="post">
<input type="hidden" name="action" value="editedcat" />
<input type="hidden" name="cat_ID" value="<?php echo $HTTP_GET_VARS['cat_ID'] ?>" />
<p>Category name:<br />
<input type="text" name="cat_name" value="<?php echo $cat_name; ?>" /></p>
<p>Description:<br />
<textarea name="category_description" rows="5" cols="50" style="width: 97%;"><?php echo htmlentities($category->category_description); ?></textarea></p>
<p><input type="submit" name="submit" value="Edit it!" class="search" /></p>
</form>
<h2>Edit Category</h2>
<form name="editcat" action="categories.php" method="post">
<input type="hidden" name="action" value="editedcat" />
<input type="hidden" name="cat_ID" value="<?php echo $HTTP_GET_VARS['cat_ID'] ?>" />
<p>Category name:<br />
<input type="text" name="cat_name" value="<?php echo $cat_name; ?>" /></p>
<p>Category parent:<br />
<?php dropdown_cats(FALSE, '', 'name', 'asc', FALSE, FALSE, FALSE, TRUE, $category->category_parent, $HTTP_GET_VARS['cat_ID']); ?></p>
<p>Description:<br />
<textarea name="category_description" rows="5" cols="50" style="width: 97%;"><?php echo htmlentities($category->category_description); ?></textarea></p>
<p><input type="submit" name="submit" value="Edit it!" class="search" /></p>
</form>
</div>
<?php
<?php
break;
case 'editedcat':
$standalone = 1;
require_once('admin-header.php');
$standalone = 1;
require_once('admin-header.php');
if ($user_level < 3)
die ('Cheatin&#8217; uh?');
$cat_name = addslashes(stripslashes(stripslashes($HTTP_POST_VARS['cat_name'])));
$cat_ID = addslashes($HTTP_POST_VARS['cat_ID']);
$category_nicename = sanitize_title($cat_name);
$category_description = $HTTP_POST_VARS['category_description'];
if ($user_level < 3)
die ('Cheatin&#8217; uh?');
$cat_name = addslashes(stripslashes(stripslashes($HTTP_POST_VARS['cat_name'])));
$cat_ID = addslashes($HTTP_POST_VARS['cat_ID']);
$category_nicename = sanitize_title($cat_name);
$category_description = $HTTP_POST_VARS['category_description'];
$wpdb->query("UPDATE $tablecategories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description' WHERE cat_ID = $cat_ID");
header('Location: categories.php');
$wpdb->query("UPDATE $tablecategories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = $cat WHERE cat_ID = $cat_ID");
header('Location: categories.php');
break;
default:
$standalone = 0;
require_once ('admin-header.php');
if ($user_level < 3) {
die("You have no right to edit the categories for this blog.<br />Ask for a promotion to your <a href='mailto:$admin_email'>blog admin</a>. :)");
}
?>
$standalone = 0;
require_once ('admin-header.php');
if ($user_level < 3) {
die("You have no right to edit the categories for this blog.<br />Ask for a promotion to your <a href='mailto:$admin_email'>blog admin</a>. :)");
}
?>
<div class="wrap">
<h2>Current Categories</h2>
<table width="100%" cellpadding="3" cellspacing="3">
<tr>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col"># Posts</th>
<th colspan="2">Action</th>
</tr>
<?php
$categories = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY cat_name");
foreach ($categories as $category) {
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $tablepost2cat WHERE category_id = $category->cat_ID");
$bgcolor = ('#eee' == $bgcolor) ? 'none' : '#eee';
echo "<tr style='background-color: $bgcolor'><td>$category->cat_name</td>
<td>$category->category_description</td>
<td>$count</td>
<td><a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>Edit</a></td><td><a href='categories.php?action=Delete&amp;cat_ID=$category->cat_ID' onclick=\"return confirm('You are about to delete the category \'". addslashes($category->cat_name) ."\' and all its posts will go to the default category.\\n \'OK\' to delete, \'Cancel\' to stop.')\" class='delete'>Delete</a></td>
</tr>";
}
?>
</table>
<h2>Current Categories</h2>
<table width="100%" cellpadding="3" cellspacing="3">
<tr>
<th scope="col">Name</th>
<th scope="col">Parent</th>
<th scope="col">Description</th>
<th scope="col"># Posts</th>
<th colspan="2">Action</th>
</tr>
<?php
$categories = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY cat_name");
foreach ($categories as $category) {
$parent = "None";
if ($category->category_parent) $parent = $wpdb->get_var("SELECT cat_name FROM $tablecategories WHERE cat_ID = $category->category_parent");
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $tablepost2cat WHERE category_id = $category->cat_ID");
$bgcolor = ('#eee' == $bgcolor) ? 'none' : '#eee';
echo "<tr style='background-color: $bgcolor'><td>$category->cat_name</td>
<td>$parent</td>
<td>$category->category_description</td>
<td>$count</td>
<td><a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>Edit</a></td><td><a href='categories.php?action=Delete&amp;cat_ID=$category->cat_ID' onclick=\"return confirm('You are about to delete the category \'". addslashes($category->cat_name) ."\' and all its posts will go to the default category.\\n \'OK\' to delete, \'Cancel\' to stop.')\" class='delete'>Delete</a></td>
</tr>";
}
?>
</table>
</div>
<div class="wrap">
<h2>Add New Category</h2>
<form name="addcat" action="categories.php" method="post">
<p>Name:<br />
<input type="text" name="cat_name" value="" /></p>
<p>Description: (optional) <br />
<textarea name="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p>
<p><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="Add" class="search" /></p>
</form>
<h2>Add New Category</h2>
<form name="addcat" action="categories.php" method="post">
<p>Name:<br />
<input type="text" name="cat_name" value="" /></p>
<p>Category parent:<br />
<?php dropdown_cats(FALSE, '', 'name', 'asc', FALSE, FALSE, FALSE, TRUE); ?></p>
<p>Description: (optional) <br />
<textarea name="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p>
<p><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="Add" class="search" /></p>
</form>
</div>
<div class="wrap">
<div class="wrap">
<p><strong>Note:</strong><br />
Deleting a category does not delete posts from that category, it will just
set them back to the default category <strong><?php echo get_catname(1) ?></strong>.
Deleting a category does not delete posts from that category, it will just
set them back to the default category <strong><?php echo get_catname(1) ?></strong>.
</p>
</div>
<?php
<?php
break;
}
/* </Categories> */
include('admin-footer.php');
?>
?>

View File

@ -6,35 +6,35 @@ $use_cache = 1; // No reason not to
$curpath = dirname(__FILE__).'/';
if (!file_exists($curpath . '/wp-config.php'))
die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='wp-admin/install-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.");
die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='wp-admin/install-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.");
require($curpath.'/wp-config.php');
$wpvarstoreset = array('m','p','posts','w','c', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'name', 'category_name');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
if (!isset($$wpvar)) {
if (empty($HTTP_POST_VARS[$wpvar])) {
if (empty($HTTP_GET_VARS[$wpvar])) {
$$wpvar = '';
} else {
$$wpvar = $HTTP_GET_VARS[$wpvar];
}
} else {
$$wpvar = $HTTP_POST_VARS[$wpvar];
}
}
}
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
if (!isset($$wpvar)) {
if (empty($HTTP_POST_VARS[$wpvar])) {
if (empty($HTTP_GET_VARS[$wpvar])) {
$$wpvar = '';
} else {
$$wpvar = $HTTP_GET_VARS[$wpvar];
}
} else {
$$wpvar = $HTTP_POST_VARS[$wpvar];
}
}
}
/* Sending HTTP headers */
// It is presumptious to think that WP is the only thing that might change on the page.
@header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
@header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
@header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
@header("Cache-Control: post-check=0, pre-check=0", false);
@header("Pragma: no-cache"); // HTTP/1.0
@header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
@header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
@header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
@header("Cache-Control: post-check=0, pre-check=0", false);
@header("Pragma: no-cache"); // HTTP/1.0
@header ("X-Pingback: $siteurl/xmlrpc.php");
/* Getting settings from db */
@ -62,103 +62,110 @@ if ($pagenow != 'post.php') { timer_start(); }
if (isset($showposts) && $showposts) {
$showposts = (int)$showposts;
$posts_per_page = $showposts;
$posts_per_page = $showposts;
}
// if a month is specified in the querystring, load that month
if ($m != '') {
$m = ''.intval($m);
$where .= ' AND YEAR(post_date)='.substr($m,0,4);
if (strlen($m)>5)
$where .= ' AND MONTH(post_date)='.substr($m,4,2);
if (strlen($m)>7)
$where .= ' AND DAYOFMONTH(post_date)='.substr($m,6,2);
if (strlen($m)>9)
$where .= ' AND HOUR(post_date)='.substr($m,8,2);
if (strlen($m)>11)
$where .= ' AND MINUTE(post_date)='.substr($m,10,2);
if (strlen($m)>13)
$where .= ' AND SECOND(post_date)='.substr($m,12,2);
$m = ''.intval($m);
$where .= ' AND YEAR(post_date)='.substr($m,0,4);
if (strlen($m)>5)
$where .= ' AND MONTH(post_date)='.substr($m,4,2);
if (strlen($m)>7)
$where .= ' AND DAYOFMONTH(post_date)='.substr($m,6,2);
if (strlen($m)>9)
$where .= ' AND HOUR(post_date)='.substr($m,8,2);
if (strlen($m)>11)
$where .= ' AND MINUTE(post_date)='.substr($m,10,2);
if (strlen($m)>13)
$where .= ' AND SECOND(post_date)='.substr($m,12,2);
}
if ($year != '') {
$year = '' . intval($year);
$where .= ' AND YEAR(post_date)=' . $year;
$year = '' . intval($year);
$where .= ' AND YEAR(post_date)=' . $year;
}
if ($monthnum != '') {
$monthnum = '' . intval($monthnum);
$where .= ' AND MONTH(post_date)=' . $monthnum;
$monthnum = '' . intval($monthnum);
$where .= ' AND MONTH(post_date)=' . $monthnum;
}
if ($day != '') {
$day = '' . intval($day);
$where .= ' AND DAYOFMONTH(post_date)=' . $day;
$day = '' . intval($day);
$where .= ' AND DAYOFMONTH(post_date)=' . $day;
}
if ($name != '') {
$name = preg_replace('/[^a-z0-9-]/', '', $name);
$where .= " AND post_name = '$name'";
$name = preg_replace('/[^a-z0-9-]/', '', $name);
$where .= " AND post_name = '$name'";
}
if ($w != '') {
$w = ''.intval($w);
$where .= ' AND WEEK(post_date, 1)=' . $w;
$w = ''.intval($w);
$where .= ' AND WEEK(post_date, 1)=' . $w;
}
// if a post number is specified, load that post
if (($p != '') && ($p != 'all')) {
$p = intval($p);
$where = ' AND ID = '.$p;
$p = intval($p);
$where = ' AND ID = '.$p;
}
// if a search pattern is specified, load the posts that match
if (!empty($s)) {
$s = addslashes_gpc($s);
$search = ' AND (';
// puts spaces instead of commas
$s = preg_replace('/, +/', '', $s);
$s = str_replace(',', ' ', $s);
$s = str_replace('"', ' ', $s);
$s = trim($s);
if ($exact) {
$n = '';
} else {
$n = '%';
}
if (!$sentence) {
$s_array = explode(' ',$s);
$search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))';
for ( $i = 1; $i < count($s_array); $i = $i + 1) {
$search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))';
}
$search .= ' OR (post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\')';
$search .= ')';
} else {
$search = ' AND ((post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\'))';
}
$s = addslashes_gpc($s);
$search = ' AND (';
// puts spaces instead of commas
$s = preg_replace('/, +/', '', $s);
$s = str_replace(',', ' ', $s);
$s = str_replace('"', ' ', $s);
$s = trim($s);
if ($exact) {
$n = '';
} else {
$n = '%';
}
if (!$sentence) {
$s_array = explode(' ',$s);
$search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))';
for ( $i = 1; $i < count($s_array); $i = $i + 1) {
$search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))';
}
$search .= ' OR (post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\')';
$search .= ')';
} else {
$search = ' AND ((post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\'))';
}
}
// category stuff
$dogs = $wpdb->get_results("SELECT * FROM $tablecategories WHERE 1=1");
foreach ($dogs as $catt) {
$cache_categories[$catt->cat_ID] = $catt;
}
if ((empty($cat)) || ($cat == 'all') || ($cat == '0')) {
$whichcat='';
$whichcat='';
} else {
$cat = ''.urldecode($cat).'';
$cat = addslashes_gpc($cat);
if (stristr($cat,'-')) {
$eq = '!=';
$andor = 'AND';
$cat = explode('-',$cat);
$cat = intval($cat[1]);
} else {
$eq = '=';
$andor = 'OR';
}
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) ";
$cat_array = explode(' ',$cat);
$cat = ''.urldecode($cat).'';
$cat = addslashes_gpc($cat);
if (stristr($cat,'-')) {
$eq = '!=';
$andor = 'AND';
$cat = explode('-',$cat);
$cat = intval($cat[1]);
} else {
$eq = '=';
$andor = 'OR';
}
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) ";
$cat_array = explode(' ',$cat);
$whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]);
$whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' ');
for ($i = 1; $i < (count($cat_array)); $i = $i + 1) {
$whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]);
$whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]);
$whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' ');
}
$whichcat .= ')';
}
@ -166,136 +173,146 @@ if ((empty($cat)) || ($cat == 'all') || ($cat == '0')) {
// Category stuff for nice URIs
if ('' != $category_name) {
$category_name = preg_replace('|[^a-z0-9-]|', '', $category_name);
$tables = ", $tablepost2cat, $tablecategories";
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) ";
$whichcat = " AND (category_nicename = '$category_name') ";
$cat = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE category_nicename = '$category_name'");
if (stristr($category_name,'/')) {
$category_name = explode('/',$category_name);
if ($category_name[count($category_name)-1]) {
$category_name = $category_name[count($category_name)-1];#no trailing slash
} else {
$category_name = $category_name[count($category_name)-2];#there was a trailling slash
}
}
$category_name = preg_replace('|[^a-z0-9-]|', '', $category_name);
$tables = ", $tablepost2cat, $tablecategories";
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) ";
$whichcat = " AND (category_nicename = '$category_name'";
$cat = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE category_nicename = '$category_name'");
$whichcat .= get_category_children($cat, " OR category_id = ");
$whichcat .= ")";
}
// author stuff
if ((empty($author)) || ($author == 'all') || ($author == '0')) {
$whichauthor='';
$whichauthor='';
} else {
$author = ''.urldecode($author).'';
$author = addslashes_gpc($author);
if (stristr($author, '-')) {
$eq = '!=';
$andor = 'AND';
$author = explode('-', $author);
$author = ''.intval($author[1]);
} else {
$eq = '=';
$andor = 'OR';
}
$author_array = explode(' ', $author);
$whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]);
for ($i = 1; $i < (count($author_array)); $i = $i + 1) {
$whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]);
}
$whichauthor .= ')';
$author = ''.urldecode($author).'';
$author = addslashes_gpc($author);
if (stristr($author, '-')) {
$eq = '!=';
$andor = 'AND';
$author = explode('-', $author);
$author = ''.intval($author[1]);
} else {
$eq = '=';
$andor = 'OR';
}
$author_array = explode(' ', $author);
$whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]);
for ($i = 1; $i < (count($author_array)); $i = $i + 1) {
$whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]);
}
$whichauthor .= ')';
}
$where .= $search.$whichcat.$whichauthor;
if ((empty($order)) || ((strtoupper($order) != 'ASC') && (strtoupper($order) != 'DESC'))) {
$order='DESC';
$order='DESC';
}
// order by stuff
if (empty($orderby)) {
$orderby='date '.$order;
$orderby='date '.$order;
} else {
// used to filter values
$allowed_keys = array('author','date','category','title');
$orderby = urldecode($orderby);
$orderby = addslashes_gpc($orderby);
$orderby_array = explode(' ',$orderby);
if (!in_array($orderby_array[0],$allowed_keys)) {
$orderby_array[0] = 'date';
}
$orderby = $orderby_array[0].' '.$order;
if (count($orderby_array)>1) {
for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) {
// Only allow certain values for safety
if (in_array($orderby_array[$i],$allowed_keys)) {
$orderby .= ',post_'.$orderby_array[$i].' '.$order;
}
}
}
// used to filter values
$allowed_keys = array('author','date','category','title');
$orderby = urldecode($orderby);
$orderby = addslashes_gpc($orderby);
$orderby_array = explode(' ',$orderby);
if (!in_array($orderby_array[0],$allowed_keys)) {
$orderby_array[0] = 'date';
}
$orderby = $orderby_array[0].' '.$order;
if (count($orderby_array)>1) {
for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) {
// Only allow certain values for safety
if (in_array($orderby_array[$i],$allowed_keys)) {
$orderby .= ',post_'.$orderby_array[$i].' '.$order;
}
}
}
}
if ((!$whichcat) && (!$m) && (!$p) && (!$w) && (!$s) && empty($poststart) && empty($postend)) {
if ($what_to_show == 'posts') {
$limits = ' LIMIT '.$posts_per_page;
} elseif ($what_to_show == 'days' && empty($monthnum) && empty($year) && empty($day)) {
$lastpostdate = get_lastpostdate();
$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
$lastpostdate = mysql2date('U',$lastpostdate);
$otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($posts_per_page-1) * 86400)));
$where .= ' AND post_date > \''.$otherdate.'\'';
}
if ($what_to_show == 'posts') {
$limits = ' LIMIT '.$posts_per_page;
} elseif ($what_to_show == 'days' && empty($monthnum) && empty($year) && empty($day)) {
$lastpostdate = get_lastpostdate();
$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
$lastpostdate = mysql2date('U',$lastpostdate);
$otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($posts_per_page-1) * 86400)));
$where .= ' AND post_date > \''.$otherdate.'\'';
}
}
if ( !empty($postend) && ($postend > $poststart) && (!$m) && empty($monthnum) && empty($year) && empty($day) &&(!$w) && (!$whichcat) && (!$s) && (!$p)) {
if ($what_to_show == 'posts' || ($what_to_show == 'paged' && (!$paged))) {
$poststart = intval($poststart);
$postend = intval($postend);
$limposts = $postend - $poststart;
$limits = ' LIMIT '.$poststart.','.$limposts;
} elseif ($what_to_show == 'days') {
$poststart = intval($poststart);
$postend = intval($postend);
$limposts = $postend - $poststart;
$lastpostdate = get_lastpostdate();
$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
$lastpostdate = mysql2date('U',$lastpostdate);
$startdate = date('Y-m-d H:i:s', ($lastpostdate - (($poststart -1) * 86400)));
$otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($postend -1) * 86400)));
$where .= ' AND post_date > \''.$otherdate.'\' AND post_date < \''.$startdate.'\'';
}
if ($what_to_show == 'posts' || ($what_to_show == 'paged' && (!$paged))) {
$poststart = intval($poststart);
$postend = intval($postend);
$limposts = $postend - $poststart;
$limits = ' LIMIT '.$poststart.','.$limposts;
} elseif ($what_to_show == 'days') {
$poststart = intval($poststart);
$postend = intval($postend);
$limposts = $postend - $poststart;
$lastpostdate = get_lastpostdate();
$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
$lastpostdate = mysql2date('U',$lastpostdate);
$startdate = date('Y-m-d H:i:s', ($lastpostdate - (($poststart -1) * 86400)));
$otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($postend -1) * 86400)));
$where .= ' AND post_date > \''.$otherdate.'\' AND post_date < \''.$startdate.'\'';
}
} else {
if (($what_to_show == 'paged') && (!$p) && (!$more)) {
if ($pagenow != 'post.php') {
$pgstrt = '';
if ($paged) {
$pgstrt = (intval($paged) -1) * $posts_per_page . ', ';
}
$limits = 'LIMIT '.$pgstrt.$posts_per_page;
} else {
if (($m) || ($p) || ($w) || ($s) || ($whichcat)) {
$limits = '';
} else {
$pgstrt = '';
if ($paged) {
$pgstrt = (intval($paged) -1) * $posts_per_page . ', ';
}
$limits = 'LIMIT '.$pgstrt.$posts_per_page;
}
}
}
elseif (($m) || ($p) || ($w) || ($s) || ($whichcat) || ($author) || $monthnum || $year || $day) {
$limits = '';
}
if (($what_to_show == 'paged') && (!$p) && (!$more)) {
if ($pagenow != 'post.php') {
$pgstrt = '';
if ($paged) {
$pgstrt = (intval($paged) -1) * $posts_per_page . ', ';
}
$limits = 'LIMIT '.$pgstrt.$posts_per_page;
} else {
if (($m) || ($p) || ($w) || ($s) || ($whichcat)) {
$limits = '';
} else {
$pgstrt = '';
if ($paged) {
$pgstrt = (intval($paged) -1) * $posts_per_page . ', ';
}
$limits = 'LIMIT '.$pgstrt.$posts_per_page;
}
}
}
elseif (($m) || ($p) || ($w) || ($s) || ($whichcat) || ($author) || $monthnum || $year || $day) {
$limits = '';
}
}
if ($p == 'all') {
$where = '';
$where = '';
}
$now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
if ($pagenow != 'post.php' && $pagenow != 'edit.php') {
if ((empty($poststart)) || (empty($postend)) || !($postend > $poststart)) {
$where .= ' AND post_date <= \''.$now.'\'';
}
if ((empty($poststart)) || (empty($postend)) || !($postend > $poststart)) {
$where .= ' AND post_date <= \''.$now.'\'';
}
$distinct = 'DISTINCT';
$distinct = 'DISTINCT';
if ($use_gzipcompression) {
// gzipping the output of the script
gzip_compression();
}
if ($use_gzipcompression) {
// gzipping the output of the script
gzip_compression();
}
}
$where .= ' AND (post_status = "publish"';
@ -309,12 +326,12 @@ $request = " SELECT $distinct * FROM $tableposts $join WHERE 1=1".$where." ORDER
if ($preview) {
$request = 'SELECT 1-1'; // dummy mysql query for the preview
// little funky fix for IEwin, rawk on that code
$is_winIE = ((preg_match('/MSIE/',$HTTP_USER_AGENT)) && (preg_match('/Win/',$HTTP_USER_AGENT)));
if (($is_winIE) && (!isset($IEWin_bookmarklet_fix))) {
$preview_content = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $preview_content);
}
$request = 'SELECT 1-1'; // dummy mysql query for the preview
// little funky fix for IEwin, rawk on that code
$is_winIE = ((preg_match('/MSIE/',$HTTP_USER_AGENT)) && (preg_match('/Win/',$HTTP_USER_AGENT)));
if (($is_winIE) && (!isset($IEWin_bookmarklet_fix))) {
$preview_content = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $preview_content);
}
}
// error_log("$request");
@ -325,39 +342,39 @@ $posts = $wpdb->get_results($request);
if ($posts) {
// Get the categories for all the posts
foreach ($posts as $post) {
$post_id_list[] = $post->ID;
$post_id_list[] = $post->ID;
}
$post_id_list = implode(',', $post_id_list);
$dogs = $wpdb->get_results("SELECT DISTINCT
ID, category_id, cat_name, category_nicename, category_description
FROM $tablecategories, $tablepost2cat, $tableposts
WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
$dogs = $wpdb->get_results("SELECT DISTINCT
ID, category_id, cat_name, category_nicename, category_description, category_parent
FROM $tablecategories, $tablepost2cat, $tableposts
WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
foreach ($dogs as $catt) {
$category_cache[$catt->ID][] = $catt;
$category_cache[$catt->ID][] = $catt;
}
// Do the same for comment numbers
$comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount
FROM $tableposts
LEFT JOIN $tablecomments ON ( comment_post_ID = ID AND comment_approved = '1')
WHERE post_status = 'publish' AND ID IN ($post_id_list)
GROUP BY ID");
foreach ($comment_counts as $comment_count) {
$comment_count_cache["$comment_count->ID"] = $comment_count->ccount;
}
$comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount
FROM $tableposts
LEFT JOIN $tablecomments ON ( comment_post_ID = ID AND comment_approved = '1')
WHERE post_status = 'publish' AND ID IN ($post_id_list)
GROUP BY ID");
foreach ($comment_counts as $comment_count) {
$comment_count_cache["$comment_count->ID"] = $comment_count->ccount;
}
if (1 == count($posts)) {
if ($p || $name) {
$more = 1;
$c = 1;
$single = 1;
}
if ($s && empty($paged)) { // If they were doing a search and got one result
header('Location: ' . get_permalink($posts[0]->ID));
}
if ($p || $name) {
$more = 1;
$c = 1;
$single = 1;
}
if ($s && empty($paged)) { // If they were doing a search and got one result
header('Location: ' . get_permalink($posts[0]->ID));
}
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -223,6 +223,11 @@ p, li, .feedback {
border-bottom: 1px solid #809080;
}
#menu ul ul ul.children {
padding-left:4px;
font-size:142%;
}
#wp-calendar {
border: 1px solid #ddd;
empty-cells: show;