Ticket #11842: 11842.5.2.diff
File 11842.5.2.diff, 8.0 KB (added by , 14 years ago) |
---|
-
general-template.php
111 111 * search. To give a few examples of what it can be used for. 112 112 * 113 113 * @since 2.7.0 114 * @param boolean $echo Default to echo and not return the form. 114 115 */ 115 function get_search_form( ) {116 function get_search_form($echo = true) { 116 117 do_action( 'get_search_form' ); 117 118 118 119 $search_form_template = locate_template(array('searchform.php')); … … 128 129 </div> 129 130 </form>'; 130 131 131 echo apply_filters('get_search_form', $form); 132 if ( $echo ) 133 echo apply_filters('get_search_form', $form); 134 else 135 return apply_filters('get_search_form', $form); 132 136 } 133 137 134 138 /** … … 141 145 * @uses apply_filters() Calls 'loginout' hook on HTML link content. 142 146 * 143 147 * @param string $redirect Optional path to redirect to on login/logout. 148 * @param boolean $echo Default to echo and not return the link. 144 149 */ 145 function wp_loginout($redirect = '' ) {150 function wp_loginout($redirect = '', $echo = true) { 146 151 if ( ! is_user_logged_in() ) 147 152 $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>'; 148 153 else 149 154 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>'; 150 151 echo apply_filters('loginout', $link); 155 156 if ( $echo ) 157 echo apply_filters('loginout', $link); 158 else 159 return apply_filters('loginout', $link); 152 160 } 153 161 154 162 /** … … 280 288 * 281 289 * @param string $before Text to output before the link (defaults to <li>). 282 290 * @param string $after Text to output after the link (defaults to </li>). 291 * @param boolean $echo Default to echo and not return the link. 283 292 */ 284 function wp_register( $before = '<li>', $after = '</li>' ) {293 function wp_register( $before = '<li>', $after = '</li>', $echo = true ) { 285 294 286 295 if ( ! is_user_logged_in() ) { 287 296 if ( get_option('users_can_register') ) … … 291 300 } else { 292 301 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after; 293 302 } 294 295 echo apply_filters('register', $link); 303 304 if ( $echo ) 305 echo apply_filters('register', $link); 306 else 307 return apply_filters('register', $link); 296 308 } 297 309 298 310 /** … … 1001 1013 * @since 1.0.0 1002 1014 * 1003 1015 * @param bool $initial Optional, default is true. Use initial calendar names. 1016 * @param bool $echo Optional, default is true. Set to false for return. 1004 1017 */ 1005 function get_calendar($initial = true ) {1018 function get_calendar($initial = true, $echo = true) { 1006 1019 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; 1007 1020 1008 1021 $cache = array(); 1009 1022 $key = md5( $m . $monthnum . $year ); 1010 1023 if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) { 1011 if ( is_array($cache) && isset( $cache[ $key ] ) ) { 1012 echo $cache[ $key ]; 1013 return; 1024 if ( is_array($cache) && isset( $cache[ $key ] ) ) { 1025 if ( $echo ) 1026 echo apply_filters( 'get_calendar', $cache[$key] ); 1027 else 1028 return apply_filters( 'get_calendar', $cache[$key] ); 1014 1029 } 1015 1030 } 1016 1031 … … 1027 1042 } 1028 1043 } 1029 1044 1030 ob_start();1031 1045 if ( isset($_GET['w']) ) 1032 1046 $w = ''.intval($_GET['w']); 1033 1047 … … 1073 1087 1074 1088 /* translators: Calendar caption: 1: month name, 2: 4-digit year */ 1075 1089 $calendar_caption = _x('%1$s %2$s', 'calendar caption'); 1076 echo '<table id="wp-calendar">1090 $calendar_output .= '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '"> 1077 1091 <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption> 1078 1092 <thead> 1079 1093 <tr>'; … … 1087 1101 foreach ( $myweek as $wd ) { 1088 1102 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); 1089 1103 $wd = esc_attr($wd); 1090 echo"\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";1104 $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>"; 1091 1105 } 1092 1093 echo'1106 1107 $calendar_output .= ' 1094 1108 </tr> 1095 1109 </thead> 1096 1110 … … 1098 1112 <tr>'; 1099 1113 1100 1114 if ( $previous ) { 1101 echo "\n\t\t".'<td colspan="3" id="prev"><a href="' . 1102 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), 1103 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>'; 1115 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>'; 1104 1116 } else { 1105 echo"\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';1117 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>'; 1106 1118 } 1107 1119 1108 echo"\n\t\t".'<td class="pad"> </td>';1120 $calendar_output .= "\n\t\t".'<td class="pad"> </td>'; 1109 1121 1110 1122 if ( $next ) { 1111 echo "\n\t\t".'<td colspan="3" id="next"><a href="' . 1112 get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month) , 1113 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>'; 1123 $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>'; 1114 1124 } else { 1115 echo"\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';1125 $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>'; 1116 1126 } 1117 1127 1118 echo'1128 $calendar_output .= ' 1119 1129 </tr> 1120 1130 </tfoot> 1121 1131 … … 1167 1177 // See how much we should pad in the beginning 1168 1178 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins); 1169 1179 if ( 0 != $pad ) 1170 echo"\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad"> </td>';1180 $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad"> </td>'; 1171 1181 1172 1182 $daysinmonth = intval(date('t', $unixmonth)); 1173 1183 for ( $day = 1; $day <= $daysinmonth; ++$day ) { 1174 1184 if ( isset($newrow) && $newrow ) 1175 echo"\n\t</tr>\n\t<tr>\n\t\t";1185 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; 1176 1186 $newrow = false; 1177 1187 1178 1188 if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) ) 1179 echo'<td id="today">';1189 $calendar_output .= '<td id="today">'; 1180 1190 else 1181 echo'<td>';1191 $calendar_output .= '<td>'; 1182 1192 1183 1193 if ( in_array($day, $daywithpost) ) // any posts today? 1184 echo'<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";1194 $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>"; 1185 1195 else 1186 echo$day;1187 echo'</td>';1196 $calendar_output .= $day; 1197 $calendar_output .= '</td>'; 1188 1198 1189 1199 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) 1190 1200 $newrow = true; … … 1192 1202 1193 1203 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); 1194 1204 if ( $pad != 0 && $pad != 7 ) 1195 echo"\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'"> </td>';1205 $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'"> </td>'; 1196 1206 1197 echo"\n\t</tr>\n\t</tbody>\n\t</table>";1207 $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>"; 1198 1208 1199 $output = ob_get_contents();1200 ob_end_clean();1201 echo $output;1202 1209 $cache[ $key ] = $output; 1203 1210 wp_cache_set( 'get_calendar', $cache, 'calendar' ); 1211 1212 if ( $echo ) 1213 echo apply_filters( 'get_calendar', $calendar_output ); 1214 else 1215 return apply_filters( 'get_calendar', $calendar_output ); 1216 1204 1217 } 1205 1218 1206 1219 /**