Image fu from Andy. fixes #1776

git-svn-id: http://svn.automattic.com/wordpress/trunk@2958 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-10-20 20:48:32 +00:00
parent 183593f333
commit 45fc6c1664
10 changed files with 252 additions and 79 deletions

View File

@ -669,6 +669,8 @@ function wp_create_thumbnail($file, $max_side, $effect = '') {
} }
} }
} else {
$error = __('File not found');
} }
if (!empty ($error)) { if (!empty ($error)) {

View File

@ -135,9 +135,16 @@ $imagedata['height'] = $imagesize['1'];
list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']); list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'"; $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
$imagedata['file'] = $file; $imagedata['file'] = $file;
$imagedata['thumb'] = "thumb-$filename";
if ( false == add_post_meta($id, 'imagedata', $imagedata) ) add_post_meta($id, 'imagedata', $imagedata);
die("failed to add_post_meta");
if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
$error = wp_create_thumbnail($file, 128);
elseif ( $imagedata['height'] > 96 )
$error = wp_create_thumbnail($file, 96);
}
header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&last=true"); header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&last=true");
die; die;
@ -192,24 +199,56 @@ $i = 0;
$uwidth_sum = 0; $uwidth_sum = 0;
$images_html = ''; $images_html = '';
$images_style = ''; $images_style = '';
$images_script = '';
if ( count($images) > 0 ) { if ( count($images) > 0 ) {
$images = array_slice( $images, 0, $num ); $images = array_slice( $images, 0, $num );
$__delete = __('DELETE');
$__subpost_on = __('SUBPOST <strong>ON</strong>');
$__subpost_off = __('SUBPOST <strong>OFF</strong>');
$__thumbnail_on = __('THUMBNAIL <strong>ON</strong>');
$__thumbnail_off = __('THUMBNAIL <strong>OFF</strong>');
$__no_thumbnail = __('<del>THUMBNAIL</del>');
$__close = __('CLOSE');
$__confirmdelete = __('Delete this photo from the server?');
$__nothumb = __('There is no thumbnail associated with this photo.');
$images_script .= "subposton = '$__subpost_on';\nsubpostoff = '$__subpost_off';\n";
$images_script .= "thumbnailon = '$__thumbnail_on';\nthumbnailoff = '$__thumbnail_off';\n";
foreach ( $images as $key => $image ) { foreach ( $images as $key => $image ) {
$image = array_merge($image, get_post_meta($image['ID'], 'imagedata', true) ); $meta = get_post_meta($image['ID'], 'imagedata', true);
if (!is_array($meta)) {
wp_delete_object($image['ID']);
continue;
}
$image = array_merge($image, $meta);
if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) {
$src = str_replace(basename($image['guid']), '', $image['guid']) . $image['thumb'];
$images_script .= "src".$i."a = '$src';\nsrc".$i."b = '".$image['guid']."';\n";
$thumb = 'true';
$thumbtext = $__thumbnail_on;
} else {
$src = $image['guid'];
$thumb = 'false';
$thumbtext = $__no_thumbnail;
}
list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']); list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
$uwidth_sum += 128; //$image['uwidth']; $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"';
$uwidth_sum += 128;
$xpadding = (128 - $image['uwidth']) / 2; $xpadding = (128 - $image['uwidth']) / 2;
$ypadding = (96 - $image['uheight']) / 2; $ypadding = (96 - $image['uheight']) / 2;
$object = $image['ID']; $object = $image['ID'];
$images_style .= "#target$i img { padding: {$ypadding}px {$xpadding}px; }\n"; $images_style .= "#target$i img { padding: {$ypadding}px {$xpadding}px; }\n";
$href = get_subpost_link($object);
$images_script .= "href".$i."a = '$href';\nhref".$i."b = '{$image['guid']}';\n";
$images_html .= <<<HERE $images_html .= <<<HERE
<div id='target$i' class='imagewrap left'> <div id='target$i' class='imagewrap left'>
<div id='popup$i' class='popup'> <div id='popup$i' class='popup'>
<a onclick='return confirm("Delete this photo from the server?")' href='image-uploading.php?action=delete&amp;object=$object&amp;all=$all&amp;start=$start&amp;post=$post'>DELETE</a> <a id="L$i" onclick="toggleLink($i);return false;" href="javascript:void();">$__subpost_on</a>
<a onclick="popup.style.display='none';return false;" href="javascript:void()">CANCEL</a> <a id="I$i" onclick="if($thumb)toggleImage($i);else alert('$__nothumb');return false;" href="javascript:void();">$thumbtext</a>
<a onclick="return confirm('$__confirmdelete')" href="image-uploading.php?action=delete&amp;object=$object&amp;all=$all&amp;start=$start&amp;post=$post">$__delete</a>
<a onclick="popup.style.display='none';return false;" href="javascript:void()">$__close</a>
</div> </div>
<a id='link$i' class='imagelink' href='{$image['guid']}' onclick='imagePopup($i);return false;' title='{$image['post_title']}'> <a id="link$i" class="imagelink" href="$href" onclick="imagePopup($i);return false;" title="{$image['post_title']}">
<img id='image$i' src='{$image['guid']}' alt='{$image['post_title']}' {$image['hwstring_small']} /> <img id='image$i' src='$src' alt='{$image['post_title']}' $height_width />
</a> </a>
</div> </div>
HERE; HERE;
@ -231,6 +270,9 @@ die('This script was not meant to be called directly.');
<head> <head>
<meta http-equiv="imagetoolbar" content="no" /> <meta http-equiv="imagetoolbar" content="no" />
<script type="text/javascript"> <script type="text/javascript">
/* Define any variables we'll need, such as alternate URLs. */
<?php echo $images_script; ?>
function validateImageName() { function validateImageName() {
/* This is more for convenience than security. Server-side validation is very thorough.*/ /* This is more for convenience than security. Server-side validation is very thorough.*/
obj = document.getElementById('upload'); obj = document.getElementById('upload');
@ -258,6 +300,28 @@ popup.style.display = 'block';
function init() { function init() {
popup = false; popup = false;
} }
function toggleLink(n) {
o=document.getElementById('link'+n);
oi=document.getElementById('L'+n);
if ( oi.innerHTML == subposton ) {
o.href = eval('href'+n+'b');
oi.innerHTML = subpostoff;
} else {
o.href = eval('href'+n+'a');
oi.innerHTML = subposton;
}
}
function toggleImage(n) {
o = document.getElementById('image'+n);
oi = document.getElementById('I'+n);
if ( oi.innerHTML == thumbnailon ) {
o.src = eval('src'+n+'b');
oi.innerHTML = thumbnailoff;
} else {
o.src = eval('src'+n+'a');
oi.innerHTML = thumbnailon;
}
}
</script> </script>
<style type="text/css"> <style type="text/css">
body { body {
@ -369,11 +433,11 @@ margin-top: 2px;
text-align: right; text-align: right;
} }
.popup { .popup {
margin: 23px 9px; margin: 4px 4px;
padding: 5px; padding: 3px;
position: absolute; position: absolute;
width: 100px; width: 114px;
height: 40px; height: 82px;
display: none; display: none;
background-color: rgb(223, 232, 241); background-color: rgb(223, 232, 241);
opacity: .90; opacity: .90;
@ -381,7 +445,6 @@ filter:alpha(opacity=90);
text-align: center; text-align: center;
} }
.popup a, .popup a:visited, .popup a:active { .popup a, .popup a:visited, .popup a:active {
margin-bottom: 3px;
background-color: transparent; background-color: transparent;
display: block; display: block;
width: 100%; width: 100%;
@ -389,7 +452,6 @@ text-decoration: none;
color: #246; color: #246;
} }
.popup a:hover { .popup a:hover {
margin-bottom: 3px;
background-color: #fff; background-color: #fff;
color: #000; color: #000;
} }

View File

@ -32,14 +32,14 @@ if (have_posts()) :
comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID, comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
$wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '$id' LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '$id'
AND $wpdb->comments.comment_approved = '1' AND ($wpdb->posts.post_status = 'publish' OR $wpdb->posts.post_status = 'static') AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status IN ('publish', 'static', 'object')
AND post_date < '".date("Y-m-d H:i:59")."' AND post_date < '".date("Y-m-d H:i:59")."'
ORDER BY comment_date DESC LIMIT " . get_settings('posts_per_rss') ); ORDER BY comment_date DESC LIMIT " . get_settings('posts_per_rss') );
} else { // if no post id passed in, we'll just ue the last 10 comments. } else { // if no post id passed in, we'll just ue the last 10 comments.
$comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email, $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email,
comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID, comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID,
$wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments
LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE ($wpdb->posts.post_status = 'publish' OR $wpdb->posts.post_status = 'static') LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status IN ('publish', 'static', 'object')
AND $wpdb->comments.comment_approved = '1' AND post_date < '".date("Y-m-d H:i:s")."' AND $wpdb->comments.comment_approved = '1' AND post_date < '".date("Y-m-d H:i:s")."'
ORDER BY comment_date DESC LIMIT " . get_settings('posts_per_rss') ); ORDER BY comment_date DESC LIMIT " . get_settings('posts_per_rss') );
} }

View File

@ -15,6 +15,6 @@
<?php /* "Just what do you think you're doing Dave?" */ ?> <?php /* "Just what do you think you're doing Dave?" */ ?>
<?php wp_footer(); ?> <?php wp_footer(); ?>
<?php echo $GLOBALS['dump_bot']; ?>
</body> </body>
</html> </html>

View File

@ -48,7 +48,7 @@
<?php wp_head(); ?> <?php wp_head(); ?>
</head> </head>
<body> <body>
<?php echo $GLOBALS['dump_top']; ?>
<div id="page"> <div id="page">

View File

@ -29,7 +29,7 @@ class WP_Query {
var $is_404 = false; var $is_404 = false;
var $is_comments_popup = false; var $is_comments_popup = false;
var $is_admin = false; var $is_admin = false;
var $is_object = false; var $is_subpost = false;
function init_query_flags() { function init_query_flags() {
$this->is_single = false; $this->is_single = false;
@ -49,7 +49,7 @@ class WP_Query {
$this->is_404 = false; $this->is_404 = false;
$this->is_paged = false; $this->is_paged = false;
$this->is_admin = false; $this->is_admin = false;
$this->is_object = false; $this->is_subpost = false;
} }
function init () { function init () {
@ -90,13 +90,18 @@ class WP_Query {
$qv['m'] = (int) $qv['m']; $qv['m'] = (int) $qv['m'];
$qv['p'] = (int) $qv['p']; $qv['p'] = (int) $qv['p'];
if ( ('' != $qv['subpost']) || $qv['subpost_id'] ) {
$this->is_single = true;
$this->is_subpost = true;
}
if ('' != $qv['name']) { if ('' != $qv['name']) {
$this->is_single = true; $this->is_single = true;
} elseif ( $qv['p'] ) { } elseif ( $qv['p'] ) {
$this->is_single = true; $this->is_single = true;
} elseif (('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day'])) { } elseif (('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day'])) {
// If year, month, day, hour, minute, and second are set, a single // If year, month, day, hour, minute, and second are set, a single
// post is being queried. // post is being queried.
$this->is_single = true; $this->is_single = true;
} elseif ('' != $qv['static'] || '' != $qv['pagename'] || '' != $qv['page_id']) { } elseif ('' != $qv['static'] || '' != $qv['pagename'] || '' != $qv['page_id']) {
$this->is_page = true; $this->is_page = true;
@ -208,7 +213,7 @@ class WP_Query {
$this->is_admin = true; $this->is_admin = true;
} }
if ( ! ($this->is_archive || $this->is_single || $this->is_page || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) { if ( ! ($this->is_subpost || $this->is_archive || $this->is_single || $this->is_page || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) {
$this->is_home = true; $this->is_home = true;
} }
@ -335,9 +340,12 @@ class WP_Query {
$q['pagename'] = sanitize_title(basename(str_replace('%2F', '/', urlencode($q['pagename'])))); $q['pagename'] = sanitize_title(basename(str_replace('%2F', '/', urlencode($q['pagename']))));
$q['name'] = $q['pagename']; $q['name'] = $q['pagename'];
$where .= " AND post_name = '" . $q['pagename'] . "'"; $where .= " AND post_name = '" . $q['pagename'] . "'";
} elseif ('' != $q['subpost']) {
$q['subpost'] = sanitize_title($q['subpost']);
$q['name'] = $q['subpost'];
$where .= " AND post_name = '" . $q['subpost'] . "'";
} }
if ( (int) $q['w'] ) { if ( (int) $q['w'] ) {
$q['w'] = ''.intval($q['w']); $q['w'] = ''.intval($q['w']);
$where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'"; $where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'";
@ -346,6 +354,10 @@ class WP_Query {
if ( intval($q['comments_popup']) ) if ( intval($q['comments_popup']) )
$q['p'] = intval($q['comments_popup']); $q['p'] = intval($q['comments_popup']);
// If a subpost is requested by number, let it supercede any post number.
if ( ($q['subpost_id'] != '') && (intval($q['subpost_id']) != 0) )
$q['p'] = (int) $q['subpost_id'];
// If a post number is specified, load that post // If a post number is specified, load that post
if (($q['p'] != '') && intval($q['p']) != 0) { if (($q['p'] != '') && intval($q['p']) != 0) {
$q['p'] = (int) $q['p']; $q['p'] = (int) $q['p'];
@ -516,7 +528,9 @@ class WP_Query {
$distinct = 'DISTINCT'; $distinct = 'DISTINCT';
} }
if ($this->is_page) { if ( $this->is_subpost ) {
$where .= ' AND (post_status = "object")';
} elseif ($this->is_page) {
$where .= ' AND (post_status = "static")'; $where .= ' AND (post_status = "static")';
} elseif ($this->is_single) { } elseif ($this->is_single) {
$where .= ' AND (post_status != "static")'; $where .= ' AND (post_status != "static")';
@ -529,7 +543,7 @@ class WP_Query {
$where .= ')'; $where .= ')';
} }
if (! $this->is_object ) if (! $this->is_subpost )
$where .= ' AND post_status != "object"'; $where .= ' AND post_status != "object"';
// Apply filters on where and join prior to paging so that any // Apply filters on where and join prior to paging so that any
@ -575,16 +589,17 @@ class WP_Query {
// Check post status to determine if post should be displayed. // Check post status to determine if post should be displayed.
if ($this->is_single) { if ($this->is_single) {
if ('publish' != $this->posts[0]->post_status) { $status = get_post_status($this->posts[0]);
if ('publish' != $status) {
if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) { if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) {
// User must be logged in to view unpublished posts. // User must be logged in to view unpublished posts.
$this->posts = array(); $this->posts = array();
} else { } else {
if ('draft' == $this->posts[0]->post_status) { if ('draft' == $status) {
// User must have edit permissions on the draft to preview. // User must have edit permissions on the draft to preview.
if (! user_can_edit_post($user_ID, $this->posts[0]->ID)) if (! user_can_edit_post($user_ID, $this->posts[0]->ID))
$this->posts = array(); $this->posts = array();
} elseif ('private' == $this->posts[0]->post_status) { } elseif ('private' == $status) {
if ($this->posts[0]->post_author != $user_ID) if ($this->posts[0]->post_author != $user_ID)
$this->posts = array(); $this->posts = array();
} }
@ -821,19 +836,19 @@ class WP_Rewrite {
var $queryreplace = var $queryreplace =
array ( array (
'year=', 'year=',
'monthnum=', 'monthnum=',
'day=', 'day=',
'hour=', 'hour=',
'minute=', 'minute=',
'second=', 'second=',
'name=', 'name=',
'p=', 'p=',
'category_name=', 'category_name=',
'author_name=', 'author_name=',
'pagename=', 'pagename=',
's=' 's='
); );
var $feeds = array ('feed', 'rdf', 'rss', 'rss2', 'atom'); var $feeds = array ('feed', 'rdf', 'rss', 'rss2', 'atom');
@ -845,16 +860,16 @@ class WP_Rewrite {
} }
function using_index_permalinks() { function using_index_permalinks() {
if (empty($this->permalink_structure)) { if (empty($this->permalink_structure)) {
return false; return false;
} }
// If the index is not in the permalink, we're using mod_rewrite. // If the index is not in the permalink, we're using mod_rewrite.
if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) { if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) {
return true; return true;
} }
return false; return false;
} }
function using_mod_rewrite_permalinks() { function using_mod_rewrite_permalinks() {
@ -865,15 +880,15 @@ class WP_Rewrite {
} }
function preg_index($number) { function preg_index($number) {
$match_prefix = '$'; $match_prefix = '$';
$match_suffix = ''; $match_suffix = '';
if (! empty($this->matches)) { if (! empty($this->matches)) {
$match_prefix = '$' . $this->matches . '['; $match_prefix = '$' . $this->matches . '[';
$match_suffix = ']'; $match_suffix = ']';
} }
return "$match_prefix$number$match_suffix"; return "$match_prefix$number$match_suffix";
} }
function page_rewrite_rules() { function page_rewrite_rules() {
@ -897,7 +912,7 @@ class WP_Rewrite {
return $this->date_structure; return $this->date_structure;
} }
if (empty($this->permalink_structure)) { if (empty($this->permalink_structure)) {
$this->date_structure = ''; $this->date_structure = '';
return false; return false;
} }
@ -973,7 +988,7 @@ class WP_Rewrite {
return $this->category_structure; return $this->category_structure;
} }
if (empty($this->permalink_structure)) { if (empty($this->permalink_structure)) {
$this->category_structure = ''; $this->category_structure = '';
return false; return false;
} }
@ -993,7 +1008,7 @@ class WP_Rewrite {
return $this->author_structure; return $this->author_structure;
} }
if (empty($this->permalink_structure)) { if (empty($this->permalink_structure)) {
$this->author_structure = ''; $this->author_structure = '';
return false; return false;
} }
@ -1008,7 +1023,7 @@ class WP_Rewrite {
return $this->search_structure; return $this->search_structure;
} }
if (empty($this->permalink_structure)) { if (empty($this->permalink_structure)) {
$this->search_structure = ''; $this->search_structure = '';
return false; return false;
} }
@ -1023,7 +1038,7 @@ class WP_Rewrite {
return $this->page_structure; return $this->page_structure;
} }
if (empty($this->permalink_structure)) { if (empty($this->permalink_structure)) {
$this->page_structure = ''; $this->page_structure = '';
return false; return false;
} }
@ -1038,7 +1053,7 @@ class WP_Rewrite {
return $this->feed_structure; return $this->feed_structure;
} }
if (empty($this->permalink_structure)) { if (empty($this->permalink_structure)) {
$this->feed_structure = ''; $this->feed_structure = '';
return false; return false;
} }
@ -1053,7 +1068,7 @@ class WP_Rewrite {
return $this->comment_feed_structure; return $this->comment_feed_structure;
} }
if (empty($this->permalink_structure)) { if (empty($this->permalink_structure)) {
$this->comment_feed_structure = ''; $this->comment_feed_structure = '';
return false; return false;
} }
@ -1158,6 +1173,20 @@ class WP_Rewrite {
$trackbackmatch = $match . $trackbackregex; $trackbackmatch = $match . $trackbackregex;
$trackbackquery = $trackbackindex . '?' . $query . '&tb=1'; $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
$match = rtrim($match, '/'); $match = rtrim($match, '/');
$submatchbase = str_replace(array('(',')'),'',$match);
$sub1 = $submatchbase . '/([^/]+)/';
$sub1tb = $sub1 . $trackbackregex;
$sub1feed = $sub1 . $feedregex;
$sub1feed2 = $sub1 . $feedregex2;
$sub1 .= '?$';
$sub2 = $submatchbase . '/subpost/([^/]+)/';
$sub2tb = $sub2 . $trackbackregex;
$sub2feed = $sub2 . $feedregex;
$sub2feed2 = $sub2 . $feedregex2;
$sub2 .= '?$';
$subquery = $index . '?subpost=' . $this->preg_index(1);
$subtbquery = $subquery . '&tb=1';
$subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
$match = $match . '(/[0-9]+)?/?$'; $match = $match . '(/[0-9]+)?/?$';
$query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1); $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1);
} else { } else {
@ -1168,7 +1197,9 @@ class WP_Rewrite {
$rewrite = $rewrite + array($match => $query); $rewrite = $rewrite + array($match => $query);
if ($post) { if ($post) {
$rewrite = array($trackbackmatch => $trackbackquery) + $rewrite; $rewrite = array($trackbackmatch => $trackbackquery) + $rewrite +
array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery) +
array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery);
} }
} }
@ -1231,6 +1262,7 @@ class WP_Rewrite {
do_action('generate_rewrite_rules', array(&$this)); do_action('generate_rewrite_rules', array(&$this));
$this->rules = apply_filters('rewrite_rules_array', $this->rules); $this->rules = apply_filters('rewrite_rules_array', $this->rules);
return $this->rules; return $this->rules;
} }
@ -1329,7 +1361,7 @@ class WP_Rewrite {
} }
class WP { class WP {
var $public_query_vars = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence', 'debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup'); var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'subpost', 'subpost_id');
var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging'); var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging');
@ -1397,8 +1429,9 @@ class WP {
foreach ($rewrite as $match => $query) { foreach ($rewrite as $match => $query) {
// If the requesting file is the anchor of the match, prepend it // If the requesting file is the anchor of the match, prepend it
// to the path info. // to the path info.
if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0)) { if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request)) {
$request_match = $req_uri . '/' . $request; $request_match = $req_uri . '/' . $request;
die("$request_match $match<br />");
} }
if (preg_match("!^$match!", $request_match, $matches)) { if (preg_match("!^$match!", $request_match, $matches)) {

View File

@ -1384,6 +1384,12 @@ function is_page ($page = '') {
return false; return false;
} }
function is_subpost () {
global $wp_query;
return $wp_query->is_subpost;
}
function is_archive () { function is_archive () {
global $wp_query; global $wp_query;
@ -1869,6 +1875,19 @@ function get_single_template() {
return get_query_template('single'); return get_query_template('single');
} }
function get_subpost_template() {
global $posts;
$type = explode('/', $posts[0]->post_type);
if ( $template = get_query_template($type[0]) )
return $template;
elseif ( $template = get_query_template($type[1]) )
return $template;
elseif ( $template = get_query_template("$type[0]_$type[1]") )
return $template;
else
return get_query_template('subpost');
}
function get_comments_popup_template() { function get_comments_popup_template() {
if ( file_exists( TEMPLATEPATH . '/comments-popup.php') ) if ( file_exists( TEMPLATEPATH . '/comments-popup.php') )
$template = TEMPLATEPATH . '/comments-popup.php'; $template = TEMPLATEPATH . '/comments-popup.php';

View File

@ -44,6 +44,8 @@ function get_permalink($id = 0) {
$post = &get_post($id); $post = &get_post($id);
if ( $post->post_status == 'static' ) if ( $post->post_status == 'static' )
return get_page_link($post->ID); return get_page_link($post->ID);
elseif ($post->post_status == 'object')
return get_subpost_link($post->ID);
$permalink = get_settings('permalink_structure'); $permalink = get_settings('permalink_structure');
@ -100,6 +102,30 @@ function get_page_link($id = false) {
return apply_filters('page_link', $link, $id); return apply_filters('page_link', $link, $id);
} }
function get_subpost_link($id = false) {
global $post, $wp_rewrite;
$link = false;
if (! $id) {
$id = $post->ID;
}
$object = get_post($id);
if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) ) {
$parent = get_post($object->post_parent);
$parentlink = get_permalink($object->post_parent);
if (! strstr($parentlink, '?') )
$link = trim($parentlink, '/') . '/' . $object->post_name . '/';
}
if (! $link ) {
$link = get_bloginfo('home') . "/?subpost_id=$id";
}
return apply_filters('object_link', $link, $id);
}
function get_year_link($year) { function get_year_link($year) {
global $wp_rewrite; global $wp_rewrite;
if ( !$year ) if ( !$year )
@ -183,8 +209,9 @@ function edit_post_link($link = 'Edit This', $before = '', $after = '') {
get_currentuserinfo(); get_currentuserinfo();
if ( !user_can_edit_post($user_ID, $post->ID) ) if ( !user_can_edit_post($user_ID, $post->ID) || is_subpost() ) {
return; return;
}
$location = get_settings('siteurl') . "/wp-admin/post.php?action=edit&amp;post=$post->ID"; $location = get_settings('siteurl') . "/wp-admin/post.php?action=edit&amp;post=$post->ID";
echo $before . "<a href=\"$location\">$link</a>" . $after; echo $before . "<a href=\"$location\">$link</a>" . $after;
@ -207,11 +234,11 @@ function edit_comment_link($link = 'Edit This', $before = '', $after = '') {
function get_previous_post($in_same_cat = false, $excluded_categories = '') { function get_previous_post($in_same_cat = false, $excluded_categories = '') {
global $post, $wpdb; global $post, $wpdb;
if ( !is_single() ) if( !is_single() || is_subpost() )
return null; return null;
$current_post_date = $post->post_date; $current_post_date = $post->post_date;
$join = ''; $join = '';
if ( $in_same_cat ) { if ( $in_same_cat ) {
$join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id "; $join = " INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id ";
@ -238,7 +265,7 @@ function get_previous_post($in_same_cat = false, $excluded_categories = '') {
function get_next_post($in_same_cat = false, $excluded_categories = '') { function get_next_post($in_same_cat = false, $excluded_categories = '') {
global $post, $wpdb; global $post, $wpdb;
if ( !is_single() ) if( !is_single() || is_subpost() )
return null; return null;
$current_post_date = $post->post_date; $current_post_date = $post->post_date;
@ -270,7 +297,13 @@ function get_next_post($in_same_cat = false, $excluded_categories = '') {
function previous_post_link($format='&laquo; %link', $link='%title', $in_same_cat = false, $excluded_categories = '') { function previous_post_link($format='&laquo; %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
$post = get_previous_post($in_same_cat, $excluded_categories); if ( is_subpost() ) {
$post = & get_post($GLOBALS['post']->post_parent);
$pre = __('Belongs to ');
} else {
$post = get_previous_post($in_same_cat, $excluded_categories);
$pre = '';
}
if ( !$post ) if ( !$post )
return; return;
@ -278,10 +311,10 @@ function previous_post_link($format='&laquo; %link', $link='%title', $in_same_ca
$title = apply_filters('the_title', $post->post_title, $post); $title = apply_filters('the_title', $post->post_title, $post);
$string = '<a href="'.get_permalink($post->ID).'">'; $string = '<a href="'.get_permalink($post->ID).'">';
$link = str_replace('%title', $title, $link); $link = str_replace('%title', $title, $link);
$link = $string . $link . '</a>'; $link = $pre . $string . $link . '</a>';
$format = str_replace('%link', $link, $format);
echo $format; $format = str_replace('%link', $link, $format);
echo $format;
} }
function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') { function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') {
@ -296,7 +329,7 @@ function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat =
$link = $string . $link . '</a>'; $link = $string . $link . '</a>';
$format = str_replace('%link', $link, $format); $format = str_replace('%link', $link, $format);
echo $format; echo $format;
} }
@ -491,4 +524,4 @@ function posts_nav_link($sep=' &#8212; ', $prelabel='&laquo; Previous Page', $nx
} }
} }
?> ?>

View File

@ -438,4 +438,22 @@ function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) {
return $output; return $output;
} }
?> function prepend_object($content) {
global $post;
$p = '<p class="subpostobject">';
if ( '' != $post->guid ) {
if ( substr($post->post_type, 0, 6) == 'image/' )
$p .= '<a href="' . $post->guid . '" title="Click for full-size image" ><img class="subpostimage" src="' . $post->guid . '" alt="' . $post->post_title . '" /></a>';
else
$p .= __('Attachment') . ' (' . $post->post_type . ')';
} else {
$p .= __('Missing attachment');
}
$p .= '</p>';
return "$p\n$content";
}
?>

View File

@ -1,5 +1,4 @@
<?php <?php
if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) { if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
do_action('template_redirect'); do_action('template_redirect');
if ( is_feed() ) { if ( is_feed() ) {
@ -17,10 +16,17 @@ if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
} else if ( is_home() && get_home_template() ) { } else if ( is_home() && get_home_template() ) {
include(get_home_template()); include(get_home_template());
exit; exit;
} else if ( is_subpost() && get_subpost_template() ) {
include(get_subpost_template());
exit;
} else if ( is_single() && get_single_template() ) { } else if ( is_single() && get_single_template() ) {
if ( is_subpost() )
add_filter('the_content', 'prepend_object');
include(get_single_template()); include(get_single_template());
exit; exit;
} else if ( is_page() && get_page_template() ) { } else if ( is_page() && get_page_template() ) {
if ( is_subpost() )
add_filter('the_content', 'prepend_object');
include(get_page_template()); include(get_page_template());
exit; exit;
} else if ( is_category() && get_category_template()) { } else if ( is_category() && get_category_template()) {
@ -56,4 +62,4 @@ if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
} }
} }
?> ?>