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 if ( $page > count($pages) ) // if the requested page doesn't exist
81 $page = count($pages); // give them the highest numbered page that DOES exist
83 $content = $pages[$page-1];
84 $content = explode('<!--more-->', $content, 2);
85 if ( (preg_match('/<!--noteaser-->/', $post->post_content) && ((!$multipage) || ($page==1))) )
87 $teaser = $content[0];
88 if ( ($more) && ($stripteaser) )
91 if ( count($content) > 1 ) {
93 $output .= '<a id="more-'.$id.'"></a>'.$content[1];
95 $output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>";
97 if ( $preview ) // preview fix for javascript bug with foreign languages
98 $output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output);
104 function the_excerpt() {
105 echo apply_filters('the_excerpt', get_the_excerpt());
109 function get_the_excerpt($fakeit = true) {
112 $output = $post->post_excerpt;
113 if ( !empty($post->post_password) ) { // if there's a password
114 if ( $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password ) { // and it doesn't match the cookie
115 $output = __('There is no excerpt because this is a protected post.');
120 return apply_filters('get_the_excerpt', $output);
124 function wp_link_pages($args = '') {
125 parse_str($args, $r);
126 if ( !isset($r['before']) )
127 $r['before'] = '<p>' . __('Pages:');
128 if ( !isset($r['after']) )
129 $r['after'] = '</p>';
130 if ( !isset($r['next_or_number']) )
131 $r['next_or_number'] = 'number';
132 if ( !isset($r['nextpagelink']) )
133 $r['nextpagelink'] = 'Next page';
134 if ( !isset($r['previouspagelink']) )
135 $r['previouspagelink'] = 'Previous page';
136 if ( !isset($r['pagelink']) )
137 $r['pagelink'] = '%';
138 if ( !isset($r['more_file']) )
139 $r['more_file'] = '';
141 link_pages($r['before'], $r['after'], $r['next_or_number'], $r['nextpagelink'], $r['previouspagelink'], $r['pagelink'], $r['more_file']);
145 function link_pages($before='<br />', $after='<br />', $next_or_number='number', $nextpagelink='next page', $previouspagelink='previous page', $pagelink='%', $more_file='') {
146 global $id, $page, $numpages, $multipage, $more, $pagenow;
147 if ( $more_file != '' )
152 if ( 'number' == $next_or_number ) {
154 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
155 $j = str_replace('%',"$i",$pagelink);
157 if ( ($i != $page) || ((!$more) && ($page==1)) ) {
158 if ( '' == get_settings('permalink_structure') )
159 echo '<a href="' . get_permalink() . '&page=' . $i . '">';
161 echo '<a href="' . trailingslashit(get_permalink()) . $i . '/">';
164 if ( ($i != $page) || ((!$more) && ($page==1)) )
173 if ( '' == get_settings('permalink_structure') )
174 echo '<a href="' . get_permalink() . '&page=' . $i . '">'.$previouspagelink.'</a>';
176 echo '<a href="' . get_permalink() . $i . '/">' . $previouspagelink . '</a>';
179 if ( $i <= $numpages && $more ) {
180 if ( '' == get_settings('permalink_structure') )
181 echo '<a href="' . get_permalink() . '&page=' . $i . '">' . $nextpagelink . '</a>';
183 echo '<a href="' . trailingslashit(get_permalink()) . $i . '/">' . $nextpagelink . '</a>';
193 Post-meta: Custom per-post fields.
197 function get_post_custom( $post_id = 0 ) {
198 global $id, $post_meta_cache, $wpdb;
203 $post_id = (int) $post_id;
205 if ( isset($post_meta_cache[$post_id]) )
206 return $post_meta_cache[$post_id];
208 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) ) {
209 // Change from flat structure to hierarchical:
210 $post_meta_cache = array();
211 foreach ( $meta_list as $metarow ) {
212 $mpid = (int) $metarow['post_id'];
213 $mkey = $metarow['meta_key'];
214 $mval = $metarow['meta_value'];
216 // Force subkeys to be array type:
217 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) )
218 $post_meta_cache[$mpid] = array();
220 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) )
221 $post_meta_cache[$mpid]["$mkey"] = array();
223 // Add a value to the current pid/key:
224 $post_meta_cache[$mpid][$mkey][] = $mval;
226 return $post_meta_cache[$mpid];
231 function get_post_custom_keys() {
232 $custom = get_post_custom();
234 if ( ! is_array($custom) )
237 if ( $keys = array_keys($custom) )
242 function get_post_custom_values( $key = '' ) {
243 $custom = get_post_custom();
245 return $custom[$key];
249 function post_custom( $key = '' ) {
250 $custom = get_post_custom();
252 if ( 1 == count($custom[$key]) )
253 return $custom[$key][0];
255 return $custom[$key];
259 // this will probably change at some point...
260 function the_meta() {
263 if ( $keys = get_post_custom_keys() ) {
264 echo "<ul class='post-meta'>\n";
265 foreach ( $keys as $key ) {
267 if ( '_' == $keyt{0} )
269 $values = array_map('trim', get_post_custom_values($key));
270 $value = implode($values,', ');
271 echo "<li><span class='post-meta-key'>$key:</span> $value</li>\n";
283 function &get_page_children($page_id, $pages) {
287 $pages = &$page_cache;
289 $page_list = array();
290 foreach ( $pages as $page ) {
291 if ( $page->post_parent == $page_id ) {
292 $page_list[] = $page;
293 if ( $children = get_page_children($page->ID, $pages) )
294 $page_list = array_merge($page_list, $children);
301 function &get_pages($args = '') {
304 parse_str($args, $r);
306 if ( !isset($r['child_of']) )
308 if ( !isset($r['sort_column']) )
309 $r['sort_column'] = 'post_title';
310 if ( !isset($r['sort_order']) )
311 $r['sort_order'] = 'ASC';
314 if ( !empty($r['exclude']) ) {
315 $expages = preg_split('/[\s,]+/',$r['exclude']);
316 if ( count($expages) ) {
317 foreach ( $expages as $expage ) {
318 $exclusions .= ' AND ID <> ' . intval($expage) . ' ';
323 $pages = $wpdb->get_results("SELECT * " .
324 "FROM $wpdb->posts " .
325 "WHERE post_status = 'static' " .
327 "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
333 update_page_cache($pages);
335 if ( $r['child_of'] )
336 $pages = & get_page_children($r['child_of'], $pages);
342 function wp_list_pages($args = '') {
343 parse_str($args, $r);
344 if ( !isset($r['depth']) )
346 if ( !isset($r['show_date']) )
347 $r['show_date'] = '';
348 if ( !isset($r['child_of']) )
350 if ( !isset($r['title_li']) )
351 $r['title_li'] = __('Pages');
352 if ( !isset($r['echo']) )
358 $pages = & get_pages($args);
361 if ( $r['title_li'] )
362 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
364 // Now loop over all pages that were selected
365 $page_tree = Array();
366 foreach ( $pages as $page ) {
367 // set the title for the current page
368 $page_tree[$page->ID]['title'] = $page->post_title;
369 $page_tree[$page->ID]['name'] = $page->post_name;
371 // set the selected date for the current page
372 // depending on the query arguments this is either
373 // the createtion date or the modification date
374 // as a unix timestamp. It will also always be in the
376 if ( !empty($r['show_date']) ) {
377 if ( 'modified' == $r['show_date'] )
378 $page_tree[$page->ID]['ts'] = $page->post_modified;
380 $page_tree[$page->ID]['ts'] = $page->post_date;
384 // Using the parent ID of the current page as the
385 // array index we set the curent page as a child of that page.
386 // We can now start looping over the $page_tree array
387 // with any ID which will output the page links from that ID downwards.
388 if ( $page->post_parent != $page->ID)
389 $page_tree[$page->post_parent]['children'][] = $page->ID;
391 // Output of the pages starting with child_of as the root ID.
392 // child_of defaults to 0 if not supplied in the query.
393 $output .= _page_level_out($r['child_of'],$page_tree, $r, 0, false);
394 if ( $r['title_li'] )
395 $output .= '</ul></li>';
398 $output = apply_filters('wp_list_pages', $output);
407 function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) {
409 $queried_obj = $wp_query->get_queried_object();
413 $indent = str_repeat("\t", $depth);
414 //$indent = join('', array_fill(0,$depth,"\t"));
416 if ( !is_array($page_tree[$parent]['children']) )
419 foreach ( $page_tree[$parent]['children'] as $page_id ) {
420 $cur_page = $page_tree[$page_id];
421 $title = attribute_escape($cur_page['title']);
423 $css_class = 'page_item';
424 if ( $page_id == $queried_obj->ID )
425 $css_class .= ' current_page_item';
427 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . $title . '">' . $title . '</a>';
429 if ( isset($cur_page['ts']) ) {
430 $format = get_settings('date_format');
431 if ( isset($args['date_format']) )
432 $format = $args['date_format'];
433 $output .= " " . mysql2date($format, $cur_page['ts']);
436 if ( isset($cur_page['children']) && is_array($cur_page['children']) ) {
437 $new_depth = $depth + 1;
439 if ( !$args['depth'] || $depth < ($args['depth']-1) ) {
440 $output .= "$indent<ul>\n";
441 $output .= _page_level_out($page_id, $page_tree, $args, $new_depth, false);
442 $output .= "$indent</ul>\n";
445 $output .= "$indent</li>\n";
453 function the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {
454 echo get_the_attachment_link($id, $fullsize, $max_dims);
457 function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false) {
459 $_post = & get_post($id);
461 if ( ('attachment' != $_post->post_status) || ('' == $_post->guid) )
462 return __('Missing Attachment');
464 if (! empty($_post->guid) ) {
465 $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
467 return "<a href=\"{$_post->guid}\" title=\"{$_post->post_title}\" >{$innerHTML}</a>";
470 $p .= __('Missing attachment');
475 function get_attachment_icon($id = 0, $fullsize = false, $max_dims = false) {
477 $post = & get_post($id);
479 $mime = $post->post_mime_type;
481 $imagedata = get_post_meta($post->ID, '_wp_attachment_metadata', true);
483 $file = get_post_meta($post->ID, '_wp_attached_file', true);
485 if ( !$fullsize && !empty($imagedata['thumb'])
486 && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file))
487 && file_exists($thumbfile) ) {
489 // We have a thumbnail desired, specified and existing
491 $src = str_replace(basename($post->guid), $imagedata['thumb'], $post->guid);
492 $src_file = $thumbfile;
493 $class = 'attachmentthumb';
495 } elseif ( substr($mime, 0, 6) == 'image/'
496 && file_exists($file) ) {
498 // We have an image without a thumbnail
502 $class = 'attachmentimage';
503 } elseif (! empty($mime) ) {
505 // No thumb, no image. We'll look for a mime-related icon instead.
506 $icon_dir = apply_filters('icon_dir', get_template_directory().'/images');
507 $icon_dir_uri = apply_filters('icon_dir_uri', get_template_directory_uri().'/images');
509 $types = array(substr($mime, 0, strpos($mime, '/')), substr($mime, strpos($mime, '/') + 1), str_replace('/', '_', $mime));
510 $exts = array('jpg', 'gif', 'png');
511 foreach ($types as $type) {
512 foreach ($exts as $ext) {
513 $src_file = "$icon_dir/$type.$ext";
514 if ( file_exists($src_file) ) {
515 $src = "$icon_dir_uri/$type.$ext";
525 // Do we need to constrain the image?
526 if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {
528 $imagesize = getimagesize($src_file);
530 if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
531 $actual_aspect = $imagesize[0] / $imagesize[1];
532 $desired_aspect = $max_dims[0] / $max_dims[1];
534 if ( $actual_aspect >= $desired_aspect ) {
535 $height = $actual_aspect * $max_dims[0];
536 $constraint = "width=\"{$max_dims[0]}\" ";
537 $post->iconsize = array($max_dims[0], $height);
539 $width = $max_dims[1] / $actual_aspect;
540 $constraint = "height=\"{$max_dims[1]}\" ";
541 $post->iconsize = array($width, $max_dims[1]);
544 $post->iconsize = array($imagesize[0], $imagesize[1]);
548 $icon = "<img src=\"{$src}\" title=\"{$post->post_title}\" alt=\"{$post->post_title}\" {$constraint}/>";
550 return apply_filters('attachment_icon', $icon, $post->ID);
553 function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {
556 if ( $innerHTML = get_attachment_icon($id, $fullsize, $max_dims))
559 $post = & get_post($id);
561 $innerHTML = $post->post_title;
563 return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);
566 function prepend_attachment($content) {
567 $p = '<p class="attachment">';
568 $p .= get_the_attachment_link(false, true, array(400, 300));
570 $p = apply_filters('prepend_attachment', $p);
572 return "$p\n$content";