Changeset 2955 for trunk/wp-includes/template-functions-post.php
- Timestamp:
- 10/18/2005 10:42:02 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/template-functions-post.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/template-functions-post.php
r2686 r2955 2 2 3 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>7 </form>8 ';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> 7 </form> 8 '; 9 9 return $output; 10 10 } 11 11 12 12 13 function the_ID() { … … 14 15 echo $id; 15 16 } 17 16 18 17 19 function the_title($before = '', $after = '', $echo = true) { … … 19 21 if ( strlen($title) > 0 ) { 20 22 $title = apply_filters('the_title', $before . $title . $after, $before, $after); 21 if ( $echo)23 if ( $echo ) 22 24 echo $title; 23 25 else … … 26 28 } 27 29 30 28 31 function get_the_title($id = 0) { 29 32 $post = &get_post($id); 30 33 31 34 $title = $post->post_title; 32 if ( !empty($post->post_password))35 if ( !empty($post->post_password) ) 33 36 $title = sprintf(__('Protected: %s'), $title); 34 37 35 38 return $title; 36 39 } 40 37 41 38 42 function get_the_guid( $id = 0 ) { 39 43 $post = &get_post($id); 40 44 41 45 return apply_filters('get_the_guid', $post->guid); 42 46 } 47 43 48 44 49 function the_guid( $id = 0 ) { … … 48 53 49 54 function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') { 50 $content = get_the_content($more_link_text, $stripteaser, $more_file); 51 $content = apply_filters('the_content', $content); 52 $content = str_replace(']]>', ']]>', $content); 53 echo $content; 54 } 55 $content = get_the_content($more_link_text, $stripteaser, $more_file); 56 $content = apply_filters('the_content', $content); 57 $content = str_replace(']]>', ']]>', $content); 58 echo $content; 59 } 60 55 61 56 62 function get_the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') { 57 global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages;58 global $preview;59 global $pagenow;60 $output = '';61 62 if (!empty($post->post_password)) { // if there's a password63 if (stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {// and it doesn't match the cookie64 $output = get_the_password_form();65 return $output;66 }67 }68 69 if ($more_file != '') { 70 $file = $more_file;71 } else { 72 $file = $pagenow; //$_SERVER['PHP_SELF'];73 } 74 $content = $pages[$page-1];75 $content = explode('<!--more-->', $content, 2);76 if ((preg_match('/<!--noteaser-->/', $post->post_content) && ((!$multipage) || ($page==1))))77 $stripteaser = 1;78 $teaser = $content[0];79 if (($more) && ($stripteaser))80 $teaser = '';81 $output .= $teaser;82 if (count($content)>1) {83 if ($more) { 84 $output .= '<a id="more-'.$id.'"></a>'.$content[1];85 } else { 86 $output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>";87 }88 } 89 if ($preview) { // preview fix for javascript bug with foreign languages 90 $output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output); 91 } 92 return $output; 93 } 63 global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages; 64 global $preview; 65 global $pagenow; 66 $output = ''; 67 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(); 71 return $output; 72 } 73 } 74 75 if ( $more_file != '' ) 76 $file = $more_file; 77 else 78 $file = $pagenow; //$_SERVER['PHP_SELF']; 79 80 $content = $pages[$page-1]; 81 $content = explode('<!--more-->', $content, 2); 82 if ( (preg_match('/<!--noteaser-->/', $post->post_content) && ((!$multipage) || ($page==1))) ) 83 $stripteaser = 1; 84 $teaser = $content[0]; 85 if ( ($more) && ($stripteaser) ) 86 $teaser = ''; 87 $output .= $teaser; 88 if ( count($content) > 1 ) { 89 if ( $more ) 90 $output .= '<a id="more-'.$id.'"></a>'.$content[1]; 91 else 92 $output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>"; 93 } 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); 96 97 return $output; 98 } 99 94 100 95 101 function the_excerpt() { 96 102 echo apply_filters('the_excerpt', get_the_excerpt()); 97 103 } 104 98 105 99 106 function get_the_excerpt($fakeit = true) { … … 101 108 $output = ''; 102 109 $output = $post->post_excerpt; 103 if ( !empty($post->post_password)) { // if there's a password104 if ( $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie110 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 105 112 $output = __('There is no excerpt because this is a protected post.'); 106 113 return $output; … … 111 118 } 112 119 120 113 121 function wp_link_pages($args = '') { 114 122 parse_str($args, $r); 115 if (!isset($r['before'])) $r['before'] = '<p>' . __('Pages:'); 116 if (!isset($r['after'])) $r['after'] = '</p>'; 117 if (!isset($r['next_or_number'])) $r['next_or_number'] = 'number'; 118 if (!isset($r['nextpagelink'])) $r['nextpagelink'] = 'Next page'; 119 if (!isset($r['previouspagelink'])) $r['previouspagelink'] = 'Previous page'; 120 if (!isset($r['pagelink'])) $r['pagelink'] = '%'; 121 if (!isset($r['more_file'])) $r['more_file'] = ''; 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'] = ''; 137 122 138 link_pages($r['before'], $r['after'], $r['next_or_number'], $r['nextpagelink'], $r['previouspagelink'], $r['pagelink'], $r['more_file']); 123 139 } 124 140 141 125 142 function link_pages($before='<br />', $after='<br />', $next_or_number='number', $nextpagelink='next page', $previouspagelink='previous page', $pagelink='%', $more_file='') { 126 global $id, $page, $numpages, $multipage, $more; 127 global $pagenow; 128 if ($more_file != '') { 129 $file = $more_file; 130 } else { 131 $file = $pagenow; 132 } 133 if (($multipage)) { 134 if ($next_or_number=='number') { 135 echo $before; 136 for ($i = 1; $i < ($numpages+1); $i = $i + 1) { 137 $j=str_replace('%',"$i",$pagelink); 138 echo ' '; 139 if (($i != $page) || ((!$more) && ($page==1))) { 140 if ('' == get_settings('permalink_structure')) { 141 echo '<a href="' . get_permalink() . '&page=' . $i . '">'; 142 } else { 143 echo '<a href="' . trailingslashit( get_permalink() ) . $i . '/">'; 144 } 145 } 146 echo $j; 147 if (($i != $page) || ((!$more) && ($page==1))) 148 echo '</a>'; 149 } 150 echo $after; 151 } else { 152 if ($more) { 153 echo $before; 154 $i=$page-1; 155 if ($i && $more) { 156 if ('' == get_settings('permalink_structure')) { 157 echo '<a href="' . get_permalink() . '&page=' . $i . '">'.$previouspagelink.'</a>'; 158 } else { 159 echo '<a href="' . get_permalink() . $i . '/">'.$previouspagelink.'</a>'; 160 } 161 } 162 $i=$page+1; 163 if ($i<=$numpages && $more) { 164 if ('' == get_settings('permalink_structure')) { 165 echo '<a href="'.get_permalink() . '&page=' . $i . '">'.$nextpagelink.'</a>'; 166 } else { 167 echo '<a href="'.get_permalink().$i.'/">'.$nextpagelink.'</a>'; 168 } 169 } 170 echo $after; 171 } 172 } 173 } 174 } 143 global $id, $page, $numpages, $multipage, $more, $pagenow; 144 if ( $more_file != '' ) 145 $file = $more_file; 146 else 147 $file = $pagenow; 148 if ( $multipage ) { 149 if ( 'number' == $next_or_number ) { 150 echo $before; 151 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) { 152 $j = str_replace('%',"$i",$pagelink); 153 echo ' '; 154 if ( ($i != $page) || ((!$more) && ($page==1)) ) { 155 if ( '' == get_settings('permalink_structure') ) 156 echo '<a href="' . get_permalink() . '&page=' . $i . '">'; 157 else 158 echo '<a href="' . trailingslashit( get_permalink() ) . $i . '/">'; 159 } 160 echo $j; 161 if ( ($i != $page) || ((!$more) && ($page==1)) ) 162 echo '</a>'; 163 } 164 echo $after; 165 } else { 166 if ( $more ) { 167 echo $before; 168 $i = $page - 1; 169 if ( $i && $more ) { 170 if ( '' == get_settings('permalink_structure') ) 171 echo '<a href="' . get_permalink() . '&page=' . $i . '">'.$previouspagelink.'</a>'; 172 else 173 echo '<a href="' . get_permalink() . $i . '/">'.$previouspagelink.'</a>'; 174 } 175 $i = $page + 1; 176 if ( $i <= $numpages && $more ) { 177 if ( '' == get_settings('permalink_structure') ) 178 echo '<a href="'.get_permalink() . '&page=' . $i . '">'.$nextpagelink.'</a>'; 179 else 180 echo '<a href="'.get_permalink().$i.'/">'.$nextpagelink.'</a>'; 181 } 182 echo $after; 183 } 184 } 185 } 186 } 187 175 188 176 189 /* 177 * Post-meta: Custom per-post fields. 178 */ 179 190 Post-meta: Custom per-post fields. 191 */ 192 193 180 194 function get_post_custom( $post_id = 0 ) { 181 195 global $id, $post_meta_cache, $wpdb; … … 185 199 return $post_meta_cache[$id]; 186 200 } else { 187 if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmetaWHERE post_id = '$id' ORDER BY post_id, meta_key", ARRAY_A) ) {188 189 // Change from flat structure to hierarchical:190 $post_meta_cache = array();191 foreach ($meta_list as $metarow) {192 $mpid = $metarow['post_id'];193 $mkey = $metarow['meta_key'];194 $mval = $metarow['meta_value']; 195 196 // Force subkeys to be array type:197 if (!isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]))198 $post_meta_cache[$mpid] = array();199 if (!isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]))200 $post_meta_cache[$mpid]["$mkey"] = array(); 201 202 // Add a value to the current pid/key:203 $post_meta_cache[$mpid][$mkey][] = $mval;204 }205 return $post_meta_cache[$mpid];206 }207 }208 } 201 if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = '$id' ORDER BY post_id, meta_key", ARRAY_A) ) { 202 // Change from flat structure to hierarchical: 203 $post_meta_cache = array(); 204 foreach ( $meta_list as $metarow ) { 205 $mpid = $metarow['post_id']; 206 $mkey = $metarow['meta_key']; 207 $mval = $metarow['meta_value']; 208 209 // Force subkeys to be array type: 210 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) ) 211 $post_meta_cache[$mpid] = array(); 212 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) ) 213 $post_meta_cache[$mpid]["$mkey"] = array(); 214 215 // Add a value to the current pid/key: 216 $post_meta_cache[$mpid][$mkey][] = $mval; 217 } 218 return $post_meta_cache[$mpid]; 219 } 220 } 221 } 222 209 223 210 224 function get_post_custom_keys() { 211 225 global $id, $post_meta_cache; 212 213 if ( !is_array($post_meta_cache[$id]))226 227 if ( !is_array($post_meta_cache[$id]) ) 214 228 return; 215 if ( $keys = array_keys($post_meta_cache[$id]))229 if ( $keys = array_keys($post_meta_cache[$id]) ) 216 230 return $keys; 217 231 } 232 218 233 219 234 function get_post_custom_values($key='') { … … 223 238 } 224 239 240 225 241 function post_custom( $key = '' ) { 226 242 global $id, $post_meta_cache; 227 228 if ( 1 == count($post_meta_cache[$id][$key]) ) return $post_meta_cache[$id][$key][0]; 229 else return $post_meta_cache[$id][$key]; 230 } 243 244 if ( 1 == count($post_meta_cache[$id][$key]) ) 245 return $post_meta_cache[$id][$key][0]; 246 else 247 return $post_meta_cache[$id][$key]; 248 } 249 231 250 232 251 // this will probably change at some point... 233 252 function the_meta() { 234 253 global $id, $post_meta_cache; 235 236 if ( $keys = get_post_custom_keys()) {254 255 if ( $keys = get_post_custom_keys() ) { 237 256 echo "<ul class='post-meta'>\n"; 238 foreach ( $keys as $key) {257 foreach ( $keys as $key ) { 239 258 $values = array_map('trim',$post_meta_cache[$id][$key]); 240 259 $value = implode($values,', '); 241 242 260 echo "<li><span class='post-meta-key'>$key:</span> $value</li>\n"; 243 261 } … … 247 265 248 266 249 // 250 // Pages 251 // 267 /* 268 Pages 269 */ 270 252 271 253 272 function &get_page_children($page_id, $pages) { … … 258 277 259 278 $page_list = array(); 260 foreach ( $pages as $page) {261 if ( $page->post_parent == $page_id) {279 foreach ( $pages as $page ) { 280 if ( $page->post_parent == $page_id ) { 262 281 $page_list[] = $page; 263 if ( $children = get_page_children($page->ID, $pages) ) {282 if ( $children = get_page_children($page->ID, $pages) ) 264 283 $page_list = array_merge($page_list, $children); 265 }266 284 } 267 285 } … … 269 287 return $page_list; 270 288 } 289 271 290 272 291 function &get_pages($args = '') { … … 275 294 parse_str($args, $r); 276 295 277 if (!isset($r['child_of'])) $r['child_of'] = 0; 278 if (!isset($r['sort_column'])) $r['sort_column'] = 'post_title'; 279 if (!isset($r['sort_order'])) $r['sort_order'] = 'ASC'; 296 if ( !isset($r['child_of']) ) 297 $r['child_of'] = 0; 298 if ( !isset($r['sort_column']) ) 299 $r['sort_column'] = 'post_title'; 300 if ( !isset($r['sort_order']) ) 301 $r['sort_order'] = 'ASC'; 280 302 281 303 $exclusions = ''; 282 if ( !empty($r['exclude'])) {304 if ( !empty($r['exclude']) ) { 283 305 $expages = preg_split('/[\s,]+/',$r['exclude']); 284 if ( count($expages)) {285 foreach ( $expages as $expage) {306 if ( count($expages) ) { 307 foreach ( $expages as $expage ) { 286 308 $exclusions .= ' AND ID <> ' . intval($expage) . ' '; 287 309 } … … 290 312 291 313 $pages = $wpdb->get_results("SELECT * " . 292 "FROM $wpdb->posts " .293 "WHERE post_status = 'static' " .294 "$exclusions " .295 "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);314 "FROM $wpdb->posts " . 315 "WHERE post_status = 'static' " . 316 "$exclusions " . 317 "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']); 296 318 297 319 if ( empty($pages) ) … … 301 323 update_page_cache($pages); 302 324 303 if ( $r['child_of'])325 if ( $r['child_of'] ) 304 326 $pages = & get_page_children($r['child_of'], $pages); 305 327 306 328 return $pages; 307 329 } 330 308 331 309 332 function wp_list_pages($args = '') { 310 333 parse_str($args, $r); 311 if ( !isset($r['depth']) ) $r['depth'] = 0; 312 if ( !isset($r['show_date']) ) $r['show_date'] = ''; 313 if ( !isset($r['child_of']) ) $r['child_of'] = 0; 314 if ( !isset($r['title_li']) ) $r['title_li'] = __('Pages'); 315 if ( !isset($r['echo']) ) $r['echo'] = 1; 316 334 if ( !isset($r['depth']) ) 335 $r['depth'] = 0; 336 if ( !isset($r['show_date']) ) 337 $r['show_date'] = ''; 338 if ( !isset($r['child_of']) ) 339 $r['child_of'] = 0; 340 if ( !isset($r['title_li']) ) 341 $r['title_li'] = __('Pages'); 342 if ( !isset($r['echo']) ) 343 $r['echo'] = 1; 344 317 345 $output = ''; 318 346 319 347 // Query pages. 320 348 $pages = & get_pages($args); 321 if ( $pages ) : 322 323 if ( $r['title_li'] ) 324 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; 325 // Now loop over all pages that were selected 326 $page_tree = Array(); 327 foreach($pages as $page) { 328 // set the title for the current page 329 $page_tree[$page->ID]['title'] = $page->post_title; 330 $page_tree[$page->ID]['name'] = $page->post_name; 331 332 // set the selected date for the current page 333 // depending on the query arguments this is either 334 // the createtion date or the modification date 335 // as a unix timestamp. It will also always be in the 336 // ts field. 337 if (! empty($r['show_date'])) { 338 if ('modified' == $r['show_date']) 339 $page_tree[$page->ID]['ts'] = $page->post_modified; 340 else 341 $page_tree[$page->ID]['ts'] = $page->post_date; 342 } 343 344 // The tricky bit!! 345 // Using the parent ID of the current page as the 346 // array index we set the curent page as a child of that page. 347 // We can now start looping over the $page_tree array 348 // with any ID which will output the page links from that ID downwards. 349 if ( $page->post_parent != $page->ID) 350 $page_tree[$page->post_parent]['children'][] = $page->ID; 351 } 352 // Output of the pages starting with child_of as the root ID. 353 // child_of defaults to 0 if not supplied in the query. 354 $output .= _page_level_out($r['child_of'],$page_tree, $r, 0, false); 355 if ( $r['title_li'] ) 356 $output .= '</ul></li>'; 357 endif; 358 349 if ( $pages ) { 350 351 if ( $r['title_li'] ) 352 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; 353 354 // Now loop over all pages that were selected 355 $page_tree = Array(); 356 foreach ( $pages as $page ) { 357 // set the title for the current page 358 $page_tree[$page->ID]['title'] = $page->post_title; 359 $page_tree[$page->ID]['name'] = $page->post_name; 360 361 // set the selected date for the current page 362 // depending on the query arguments this is either 363 // the createtion date or the modification date 364 // as a unix timestamp. It will also always be in the 365 // ts field. 366 if ( !empty($r['show_date']) ) { 367 if ( 'modified' == $r['show_date'] ) 368 $page_tree[$page->ID]['ts'] = $page->post_modified; 369 else 370 $page_tree[$page->ID]['ts'] = $page->post_date; 371 } 372 373 // The tricky bit!! 374 // Using the parent ID of the current page as the 375 // array index we set the curent page as a child of that page. 376 // We can now start looping over the $page_tree array 377 // with any ID which will output the page links from that ID downwards. 378 if ( $page->post_parent != $page->ID) 379 $page_tree[$page->post_parent]['children'][] = $page->ID; 380 } 381 // Output of the pages starting with child_of as the root ID. 382 // child_of defaults to 0 if not supplied in the query. 383 $output .= _page_level_out($r['child_of'],$page_tree, $r, 0, false); 384 if ( $r['title_li'] ) 385 $output .= '</ul></li>'; 386 } 387 359 388 $output = apply_filters('wp_list_pages', $output); 360 389 361 390 if ( $r['echo'] ) 362 391 echo $output; 363 else 392 else 364 393 return $output; 365 394 } 395 366 396 367 397 function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) { 368 398 global $wp_query; 369 370 399 $queried_obj = $wp_query->get_queried_object(); 371 372 400 $output = ''; 373 401 374 if ($depth)402 if ( $depth ) 375 403 $indent = str_repeat("\t", $depth); 376 //$indent = join('', array_fill(0,$depth,"\t"));377 378 foreach ($page_tree[$parent]['children'] as $page_id) {404 //$indent = join('', array_fill(0,$depth,"\t")); 405 406 foreach ( $page_tree[$parent]['children'] as $page_id ) { 379 407 $cur_page = $page_tree[$page_id]; 380 408 $title = $cur_page['title']; 381 409 382 410 $css_class = 'page_item'; 383 if ( $page_id == $queried_obj->ID) {411 if ( $page_id == $queried_obj->ID ) 384 412 $css_class .= ' current_page_item'; 385 }386 413 387 414 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>'; 388 415 389 if (isset($cur_page['ts'])) {416 if ( isset($cur_page['ts']) ) { 390 417 $format = get_settings('date_format'); 391 if (isset($args['date_format']))418 if ( isset($args['date_format']) ) 392 419 $format = $args['date_format']; 393 420 $output .= " " . mysql2date($format, $cur_page['ts']); … … 395 422 $output .= "\n"; 396 423 397 if (isset($cur_page['children']) && is_array($cur_page['children'])) {424 if ( isset($cur_page['children']) && is_array($cur_page['children']) ) { 398 425 $new_depth = $depth + 1; 399 426 400 if (!$args['depth'] || $depth < ($args['depth']-1)) {427 if ( !$args['depth'] || $depth < ($args['depth']-1) ) { 401 428 $output .= "$indent<ul>\n"; 402 429 $output .= _page_level_out($page_id, $page_tree, $args, $new_depth, false);
Note: See TracChangeset
for help on using the changeset viewer.