Changeset 6705 for trunk/wp-includes/widgets.php
- Timestamp:
- 02/02/2008 07:57:51 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/widgets.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/widgets.php
r6687 r6705 222 222 $did_one = false; 223 223 foreach ( $sidebars_widgets[$index] as $id ) { 224 $callback = $wp_registered_widgets[$id]['callback']; 225 226 $params = array_merge(array($sidebar), (array) $wp_registered_widgets[$id]['params']); 224 $params = array_merge( 225 array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ), 226 (array) $wp_registered_widgets[$id]['params'] 227 ); 227 228 228 229 // Substitute HTML id and class attributes into before_widget … … 236 237 $classname_ = ltrim($classname_, '_'); 237 238 $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); 239 240 $params = apply_filters( 'dynamic_sidebar_params', $params ); 241 242 $callback = $wp_registered_widgets[$id]['callback']; 238 243 239 244 if ( is_callable($callback) ) { … … 1004 1009 return; 1005 1010 1006 $num_items = (int) $options[$number]['items'];1007 $show_summary = $options[$number]['show_summary'];1008 if ( empty($num_items) || $num_items < 1 || $num_items > 10 ) $num_items = 10;1009 1011 $url = $options[$number]['url']; 1010 1012 while ( strstr($url, 'http') != $url ) … … 1033 1035 $icon = get_option('siteurl').'/wp-includes/images/rss.png'; 1034 1036 $title = "<a class='rsswidget' href='$url' title='" . attribute_escape(__('Syndicate this content')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>"; 1035 ?> 1036 <?php echo $before_widget; ?> 1037 <?php $title ? print($before_title . $title . $after_title) : null; ?> 1038 <?php 1037 1038 echo $before_widget; 1039 echo $before_title . $title . $after_title; 1040 1041 wp_widget_rss_output( $rss, $options[$number] ); 1042 1043 echo $after_widget; 1044 } 1045 1046 function wp_widget_rss_output( $rss, $args = null ) { 1047 if ( is_string( $rss ) ) { 1048 require_once(ABSPATH . WPINC . '/rss.php'); 1049 if ( !$rss = fetch_rss($rss) ) 1050 return; 1051 } elseif ( is_array($rss) && isset($rss['url']) ) { 1052 require_once(ABSPATH . WPINC . '/rss.php'); 1053 $args = $rss; 1054 if ( !$rss = fetch_rss($rss['url']) ) 1055 return; 1056 } elseif ( !is_object($rss) ) { 1057 return; 1058 } 1059 1060 extract( $args, EXTR_SKIP ); 1061 1062 $items = (int) $items; 1063 if ( $items < 1 || 20 < $items ) 1064 $items = 10; 1065 $show_summary = (int) $show_summary; 1066 $show_author = (int) $show_author; 1067 $show_date = (int) $show_date; 1068 1039 1069 if ( is_array( $rss->items ) && !empty( $rss->items ) ) { 1040 $rss->items = array_slice($rss->items, 0, $ num_items);1070 $rss->items = array_slice($rss->items, 0, $items); 1041 1071 echo '<ul>'; 1042 1072 foreach ($rss->items as $item ) { … … 1048 1078 $title = __('Untitled'); 1049 1079 $desc = ''; 1050 if ( $show_summary ) {1051 $summary = '<div class="rssSummary">' . $item['description'] . '</div>';1052 } else {1053 1080 if ( isset( $item['description'] ) && is_string( $item['description'] ) ) 1054 1081 $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['description'], ENT_QUOTES)))); 1082 elseif ( isset( $item['summary'] ) && is_string( $item['summary'] ) ) 1083 $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['summary'], ENT_QUOTES)))); 1084 1085 $summary = ''; 1086 if ( isset( $item['description'] ) && is_string( $item['description'] ) ) 1087 $summary = $item['description']; 1088 elseif ( isset( $item['summary'] ) && is_string( $item['summary'] ) ) 1089 $summary = $item['summary']; 1090 1091 $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($summary, ENT_QUOTES)))); 1092 1093 if ( $show_summary ) { 1094 $desc = ''; 1095 $summary = wp_specialchars( $summary ); 1096 $summary = "<div class='rssSummary'>$summary</div>"; 1097 } else { 1055 1098 $summary = ''; 1056 1099 } 1057 echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>$summary</li>"; 1100 1101 $date = ''; 1102 if ( $show_date ) { 1103 if ( isset($item['pubdate']) ) 1104 $date = $item['pubdate']; 1105 elseif ( isset($item['published']) ) 1106 $date = $item['published']; 1107 1108 if ( $date ) { 1109 if ( $date_stamp = strtotime( $date ) ) 1110 $date = '<span class="rss-date">' . gmdate( get_option( 'date_format' ), $date_stamp ) . '</span>'; 1111 else 1112 $date = ''; 1113 } 1114 } 1115 1116 $author = ''; 1117 if ( $show_author ) { 1118 if ( isset($item['dc']['creator']) ) 1119 $author = ' <cite>' . wp_specialchars( strip_tags( $item['dc']['creator'] ) ) . '</cite>'; 1120 elseif ( isset($item['author_name']) ) 1121 $author = ' <cite>' . wp_specialchars( strip_tags( $item['author_name'] ) ) . '</cite>'; 1122 } 1123 1124 echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>"; 1058 1125 } 1059 1126 echo '</ul>'; … … 1061 1128 echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>'; 1062 1129 } 1063 1064 echo $after_widget;1065 1130 } 1066 1131 … … 1083 1148 $urls[$option['url']] = true; 1084 1149 1085 if ( !$updated && !empty($_POST['sidebar']) ) {1150 if ( !$updated && 'POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['sidebar']) ) { 1086 1151 $sidebar = (string) $_POST['sidebar']; 1087 1152 … … 1100 1165 1101 1166 foreach( (array) $_POST['widget-rss'] as $widget_number => $widget_rss ) { 1102 $items = (int) $widget_rss['items']; 1103 if ( $items < 1 ) 1104 $items = 10; 1105 $url = sanitize_url(strip_tags(stripslashes($widget_rss['url']))); 1106 $title = trim(strip_tags(stripslashes($widget_rss['title']))); 1107 1108 if ( !isset($urls[$url]) ) { 1109 require_once(ABSPATH . WPINC . '/rss.php'); 1110 $rss = fetch_rss($url); 1111 $error = false; 1112 if ( !is_object($rss) ) { 1113 $url = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1); 1114 $error = sprintf(__('Error in RSS %1$d'), $widget_number ); 1115 } 1116 } 1117 $options[$widget_number] = compact( 'title', 'url', 'items', 'error' ); 1167 $widget_rss = stripslashes_deep( $widget_rss ); 1168 $url = sanitize_url(strip_tags($widget_rss['url'])); 1169 $options[$widget_number] = wp_widget_rss_process( $widget_rss, !isset($urls[$url]) ); 1118 1170 } 1119 1171 … … 1128 1180 $error = false; 1129 1181 $number = '%i%'; 1182 $show_summary = 0; 1183 $show_author = 0; 1184 $show_date = 0; 1130 1185 } else { 1131 $title = attribute_escape($options[$number]['title']); 1132 $url = attribute_escape($options[$number]['url']); 1133 $items = (int) $options[$number]['items']; 1134 if ( $items < 1 ) 1135 $items = 10; 1136 $error = $options[$number]['error']; 1137 } 1138 1139 ?> 1140 <p> 1141 <label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?> 1142 <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /> 1143 </label> 1144 </p> 1145 <p> 1146 <label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?> 1147 <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /> 1148 </label> 1149 </p> 1150 <p> 1151 <label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?> 1152 <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]"> 1153 <?php 1154 for ( $i = 1; $i <= 10; ++$i ) 1155 echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>"; 1156 ?> 1157 </select> 1158 </label> 1159 </p> 1160 <input type="hidden" id="rss-submit-<?php echo $number; ?>" name="rss-submit-<?php echo $number; ?>" value="1" /> 1161 <?php 1186 extract( $options[$number] ); 1187 } 1188 1189 wp_widget_rss_form( compact( 'number', 'title', 'url', 'items', 'error', 'show_summary', 'show_author', 'show_date' ) ); 1190 } 1191 1192 function wp_widget_rss_form( $args, $inputs = null ) { 1193 $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true ); 1194 $inputs = wp_parse_args( $inputs, $default_inputs ); 1195 extract( $args ); 1196 $number = attribute_escape( $number ); 1197 $title = attribute_escape( $title ); 1198 $url = attribute_escape( $url ); 1199 $items = (int) $items; 1200 if ( $items < 1 || 20 < $items ) 1201 $items = 10; 1202 $show_summary = (int) $show_summary; 1203 $show_author = (int) $show_author; 1204 $show_date = (int) $show_date; 1205 1206 if ( $inputs['url'] ) : 1207 ?> 1208 <p> 1209 <label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?> 1210 <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /> 1211 </label> 1212 </p> 1213 <?php endif; if ( $inputs['title'] ) : ?> 1214 <p> 1215 <label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?> 1216 <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /> 1217 </label> 1218 </p> 1219 <?php endif; if ( $inputs['items'] ) : ?> 1220 <p> 1221 <label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?> 1222 <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]"> 1223 <?php 1224 for ( $i = 1; $i <= 20; ++$i ) 1225 echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>"; 1226 ?> 1227 </select> 1228 </label> 1229 </p> 1230 <?php endif; if ( $inputs['show_summary'] ) : ?> 1231 <p> 1232 <label for="rss-show-summary-<?php echo $number; ?>"> 1233 <input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/> 1234 <?php _e('Display item content?'); ?> 1235 </label> 1236 </p> 1237 <?php endif; if ( $inputs['show_author'] ) : ?> 1238 <p> 1239 <label for="rss-show-author-<?php echo $number; ?>"> 1240 <input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/> 1241 <?php _e('Display item author if available?'); ?> 1242 </label> 1243 </p> 1244 <?php endif; if ( $inputs['show_date'] ) : ?> 1245 <p> 1246 <label for="rss-show-date-<?php echo $number; ?>"> 1247 <input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/> 1248 <?php _e('Display item date?'); ?> 1249 </label> 1250 </p> 1251 <input type="hidden" id="rss-submit-<?php echo $number; ?>" name="rss-submit-<?php echo $number; ?>" value="1" /> 1252 <?php 1253 endif; 1254 foreach ( array_keys($default_inputs) as $input ) : 1255 if ( 'hidden' === $inputs[$input] ) : 1256 $id = str_replace( '_', '-', $input ); 1257 ?> 1258 <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" /> 1259 <?php 1260 endif; 1261 endforeach; 1262 } 1263 1264 // Expects unescaped data 1265 function wp_widget_rss_process( $widget_rss, $check_feed = true ) { 1266 $items = (int) $widget_rss['items']; 1267 if ( $items < 1 || 20 < $items ) 1268 $items = 10; 1269 $url = sanitize_url(strip_tags( $widget_rss['url'] )); 1270 $title = trim(strip_tags( $widget_rss['title'] )); 1271 $show_summary = (int) $widget_rss['show_summary']; 1272 $show_author = (int) $widget_rss['show_author']; 1273 $show_date = (int) $widget_rss['show_date']; 1274 1275 if ( $check_feed ) { 1276 require_once(ABSPATH . WPINC . '/rss.php'); 1277 $rss = fetch_rss($url); 1278 $error = false; 1279 $link = ''; 1280 if ( !is_object($rss) ) { 1281 $url = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1); 1282 $error = sprintf(__('Error in RSS %1$d'), $widget_number ); 1283 } else { 1284 $link = clean_url(strip_tags($rss->channel['link'])); 1285 while ( strstr($link, 'http') != $link ) 1286 $link = substr($link, 1); 1287 } 1288 } 1289 1290 return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); 1162 1291 } 1163 1292
Note: See TracChangeset
for help on using the changeset viewer.