3 function get_the_password_form() {
4 $output = '<form action="' . get_settings('siteurl') . '/wp-pass.php" method="post">
5 <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
6 <p><label>' . __("Password:") . ' <input name="post_password" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . __("Submit") . '" /></p>
19 function the_title($before = '', $after = '', $echo = true) {
20 $title = get_the_title();
21 if ( strlen($title) > 0 ) {
22 $title = apply_filters('the_title', $before . $title . $after, $before, $after);
31 function get_the_title($id = 0) {
32 $post = &get_post($id);
34 $title = $post->post_title;
35 if ( !empty($post->post_password) )
36 $title = sprintf(__('Protected: %s'), $title);
42 function get_the_guid( $id = 0 ) {
43 $post = &get_post($id);
45 return apply_filters('get_the_guid', $post->guid);
49 function the_guid( $id = 0 ) {
50 echo get_the_guid($id);
54 function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
55 $content = get_the_content($more_link_text, $stripteaser, $more_file);
56 $content = apply_filters('the_content', $content);
57 $content = str_replace(']]>', ']]>', $content);
62 function get_the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
63 global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages;
68 if ( !empty($post->post_password) ) { // if there's a password
69 if ( stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password ) { // and it doesn't match the cookie
70 $output = get_the_password_form();
75 if ( $more_file != '' )
78 $file = $pagenow; //$_SERVER['PHP_SELF'];
80 $content = $pages[$page-1];
81 $content = explode('<!--more-->', $content, 2);
82 if ( (preg_match('/<!--noteaser-->/', $post->post_content) && ((!$multipage) || ($page==1))) )
84 $teaser = $content[0];
85 if ( ($more) && ($stripteaser) )
88 if ( count($content) > 1 ) {
90 $output .= '<a id="more-'.$id.'"></a>'.$content[1];
92 $output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>";
94 if ( $preview ) // preview fix for javascript bug with foreign languages
95 $output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output);
101 function the_excerpt() {
102 echo apply_filters('the_excerpt', get_the_excerpt());
106 function get_the_excerpt($fakeit = true) {
109 $output = $post->post_excerpt;
110 if ( !empty($post->post_password) ) { // if there's a password
111 if ( $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password ) { // and it doesn't match the cookie
112 $output = __('There is no excerpt because this is a protected post.');
117 return apply_filters('get_the_excerpt', $output);
121 function wp_link_pages($args = '') {
122 parse_str($args, $r);
123 if ( !isset($r['before']) )
124 $r['before'] = '<p>' . __('Pages:');
125 if ( !isset($r['after']) )
126 $r['after'] = '</p>';
127 if ( !isset($r['next_or_number']) )
128 $r['next_or_number'] = 'number';
129 if ( !isset($r['nextpagelink']) )
130 $r['nextpagelink'] = 'Next page';
131 if ( !isset($r['previouspagelink']) )
132 $r['previouspagelink'] = 'Previous page';
133 if ( !isset($r['pagelink']) )
134 $r['pagelink'] = '%';
135 if ( !isset($r['more_file']) )
136 $r['more_file'] = '';
138 link_pages($r['before'], $r['after'], $r['next_or_number'], $r['nextpagelink'], $r['previouspagelink'], $r['pagelink'], $r['more_file']);
142 function link_pages($before='<br />', $after='<br />', $next_or_number='number', $nextpagelink='next page', $previouspagelink='previous page', $pagelink='%', $more_file='') {
143 global $id, $page, $numpages, $multipage, $more, $pagenow;
144 if ( $more_file != '' )
149 if ( 'number' == $next_or_number ) {
151 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
152 $j = str_replace('%',"$i",$pagelink);
154 if ( ($i != $page) || ((!$more) && ($page==1)) ) {
155 if ( '' == get_settings('permalink_structure') )
156 echo '<a href="' . get_permalink() . '&page=' . $i . '">';
158 echo '<a href="' . trailingslashit( get_permalink() ) . $i . '/">';
161 if ( ($i != $page) || ((!$more) && ($page==1)) )
170 if ( '' == get_settings('permalink_structure') )
171 echo '<a href="' . get_permalink() . '&page=' . $i . '">'.$previouspagelink.'</a>';
173 echo '<a href="' . get_permalink() . $i . '/">'.$previouspagelink.'</a>';
176 if ( $i <= $numpages && $more ) {
177 if ( '' == get_settings('permalink_structure') )
178 echo '<a href="'.get_permalink() . '&page=' . $i . '">'.$nextpagelink.'</a>';
180 echo '<a href="'.get_permalink().$i.'/">'.$nextpagelink.'</a>';
190 Post-meta: Custom per-post fields.
194 function get_post_custom( $post_id = 0 ) {
195 global $id, $post_meta_cache, $wpdb;
200 if ( isset($post_meta_cache[$post_id]) )
201 return $post_meta_cache[$post_id];
203 if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = '$post_id' ORDER BY post_id, meta_key", ARRAY_A) ) {
204 // Change from flat structure to hierarchical:
205 $post_meta_cache = array();
206 foreach ( $meta_list as $metarow ) {
207 $mpid = $metarow['post_id'];
208 $mkey = $metarow['meta_key'];
209 $mval = $metarow['meta_value'];
211 // Force subkeys to be array type:
212 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) )
213 $post_meta_cache[$mpid] = array();
215 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) )
216 $post_meta_cache[$mpid]["$mkey"] = array();
218 // Add a value to the current pid/key:
219 $post_meta_cache[$mpid][$mkey][] = $mval;
221 return $post_meta_cache[$mpid];
226 function get_post_custom_keys() {
227 $custom = get_post_custom();
229 if ( ! is_array($custom) )
232 if ( $keys = array_keys($custom) )
237 function get_post_custom_values( $key = '' ) {
238 $custom = get_post_custom();
240 return $custom[$key];
244 function post_custom( $key = '' ) {
245 $custom = get_post_custom();
247 if ( 1 == count($custom[$key]) )
248 return $custom[$key][0];
250 return $custom[$key];
254 // this will probably change at some point...
255 function the_meta() {
256 global $id, $post_meta_cache;
258 if ( $keys = get_post_custom_keys() ) {
259 echo "<ul class='post-meta'>\n";
260 foreach ( $keys as $key ) {
261 $values = array_map('trim', get_post_custom_values($key));
262 $value = implode($values,', ');
263 echo "<li><span class='post-meta-key'>$key:</span> $value</li>\n";
275 function &get_page_children($page_id, $pages) {
279 $pages = &$page_cache;
281 $page_list = array();
282 foreach ( $pages as $page ) {
283 if ( $page->post_parent == $page_id ) {
284 $page_list[] = $page;
285 if ( $children = get_page_children($page->ID, $pages) )
286 $page_list = array_merge($page_list, $children);
293 function &get_pages($args = '') {
296 parse_str($args, $r);
298 if ( !isset($r['child_of']) )
300 if ( !isset($r['sort_column']) )
301 $r['sort_column'] = 'post_title';
302 if ( !isset($r['sort_order']) )
303 $r['sort_order'] = 'ASC';
306 if ( !empty($r['exclude']) ) {
307 $expages = preg_split('/[\s,]+/',$r['exclude']);
308 if ( count($expages) ) {
309 foreach ( $expages as $expage ) {
310 $exclusions .= ' AND ID <> ' . intval($expage) . ' ';
315 $pages = $wpdb->get_results("SELECT * " .
316 "FROM $wpdb->posts " .
317 "WHERE post_status = 'static' " .
319 "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
325 update_page_cache($pages);
327 if ( $r['child_of'] )
328 $pages = & get_page_children($r['child_of'], $pages);
334 function wp_list_pages($args = '') {
335 parse_str($args, $r);
336 if ( !isset($r['depth']) )
338 if ( !isset($r['show_date']) )
339 $r['show_date'] = '';
340 if ( !isset($r['child_of']) )
342 if ( !isset($r['title_li']) )
343 $r['title_li'] = __('Pages');
344 if ( !isset($r['echo']) )
350 $pages = & get_pages($args);
353 if ( $r['title_li'] )
354 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
356 // Now loop over all pages that were selected
357 $page_tree = Array();
358 foreach ( $pages as $page ) {
359 // set the title for the current page
360 $page_tree[$page->ID]['title'] = $page->post_title;
361 $page_tree[$page->ID]['name'] = $page->post_name;
363 // set the selected date for the current page
364 // depending on the query arguments this is either
365 // the createtion date or the modification date
366 // as a unix timestamp. It will also always be in the
368 if ( !empty($r['show_date']) ) {
369 if ( 'modified' == $r['show_date'] )
370 $page_tree[$page->ID]['ts'] = $page->post_modified;
372 $page_tree[$page->ID]['ts'] = $page->post_date;
376 // Using the parent ID of the current page as the
377 // array index we set the curent page as a child of that page.
378 // We can now start looping over the $page_tree array
379 // with any ID which will output the page links from that ID downwards.
380 if ( $page->post_parent != $page->ID)
381 $page_tree[$page->post_parent]['children'][] = $page->ID;
383 // Output of the pages starting with child_of as the root ID.
384 // child_of defaults to 0 if not supplied in the query.
385 $output .= _page_level_out($r['child_of'],$page_tree, $r, 0, false);
386 if ( $r['title_li'] )
387 $output .= '</ul></li>';
390 $output = apply_filters('wp_list_pages', $output);
399 function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) {
401 $queried_obj = $wp_query->get_queried_object();
405 $indent = str_repeat("\t", $depth);
406 //$indent = join('', array_fill(0,$depth,"\t"));
408 if ( !is_array($page_tree[$parent]['children']) )
411 foreach ( $page_tree[$parent]['children'] as $page_id ) {
412 $cur_page = $page_tree[$page_id];
413 $title = $cur_page['title'];
415 $css_class = 'page_item';
416 if ( $page_id == $queried_obj->ID )
417 $css_class .= ' current_page_item';
419 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>';
421 if ( isset($cur_page['ts']) ) {
422 $format = get_settings('date_format');
423 if ( isset($args['date_format']) )
424 $format = $args['date_format'];
425 $output .= " " . mysql2date($format, $cur_page['ts']);
428 if ( isset($cur_page['children']) && is_array($cur_page['children']) ) {
429 $new_depth = $depth + 1;
431 if ( !$args['depth'] || $depth < ($args['depth']-1) ) {
432 $output .= "$indent<ul>\n";
433 $output .= _page_level_out($page_id, $page_tree, $args, $new_depth, false);
434 $output .= "$indent</ul>\n";
437 $output .= "$indent</li>\n";
445 function the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {
446 echo get_the_attachment_link($id, $fullsize, $max_dims);
449 function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {
451 $_post = & get_post($id);
453 if ( ('attachment' != $_post->post_status) || ('' == $_post->guid) )
454 return __('Missing Attachment');
456 if (! empty($_post->guid) ) {
457 $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
459 return "<a href=\"{$_post->guid}\" title=\"{$_post->post_title}\" >{$innerHTML}</a>";
462 $p .= __('Missing attachment');
467 function get_attachment_icon($id = 0, $fullsize = false, $max_dims = false) {
469 $post = & get_post($id);
471 $mime = $post->post_mime_type;
473 $imagedata = get_post_meta($post->ID, '_wp_attachment_metadata', true);
475 $file = get_post_meta($post->ID, '_wp_attached_file', true);
477 if ( !$fullsize && !empty($imagedata['thumb'])
478 && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file))
479 && file_exists($thumbfile) ) {
481 // We have a thumbnail desired, specified and existing
483 $src = str_replace(basename($post->guid), $imagedata['thumb'], $post->guid);
484 $src_file = $thumbfile;
485 $class = 'attachmentthumb';
487 } elseif ( substr($mime, 0, 6) == 'image/'
488 && file_exists($file) ) {
490 // We have an image without a thumbnail
494 $class = 'attachmentimage';
495 } elseif (! empty($mime) ) {
497 // No thumb, no image. We'll look for a mime-related icon instead.
498 $icon_dir = apply_filters('icon_dir', get_template_directory().'/images');
499 $icon_dir_uri = apply_filters('icon_dir_uri', get_template_directory_uri().'/images');
501 $types = array(substr($mime, 0, strpos($mime, '/')), substr($mime, strpos($mime, '/') + 1), str_replace('/', '_', $mime));
502 $exts = array('jpg', 'gif', 'png');
503 foreach ($types as $type) {
504 foreach ($exts as $ext) {
505 $src_file = "$icon_dir/$type.$ext";
506 if ( file_exists($src_file) ) {
507 $src = "$icon_dir_uri/$type.$ext";
517 // Do we need to constrain the image?
518 if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {
520 $imagesize = getimagesize($src_file);
522 if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
523 $actual_aspect = $imagesize[0] / $imagesize[1];
524 $desired_aspect = $max_dims[0] / $max_dims[1];
526 if ( $actual_aspect >= $desired_aspect ) {
527 $height = $actual_aspect * $max_dims[0];
528 $constraint = "width=\"{$max_dims[0]}\" ";
529 $post->iconsize = array($max_dims[0], $height);
531 $width = $max_dims[1] / $actual_aspect;
532 $constraint = "height=\"{$max_dims[1]}\" ";
533 $post->iconsize = array($width, $max_dims[1]);
536 $post->iconsize = array($imagesize[0], $imagesize[1]);
540 $icon = "<img src=\"{$src}\" title=\"{$post->post_title}\" alt=\"{$post->post_title}\" {$constraint}/>";
542 return apply_filters('attachment_icon', $icon, $post->ID);
545 function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {
548 if ( $innerHTML = get_attachment_icon($id, $fullsize, $max_dims))
551 $post = & get_post($id);
553 $innerHTML = $post->post_title;
555 return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);
558 function prepend_attachment($content) {
559 $p = '<p class="attachment">';
560 $p .= get_the_attachment_link(false, true, array(400, 300));
562 $p = apply_filters('prepend_attachment', $p);
564 return "$p\n$content";