@@ -506,7 +506,7 @@ |
||
| 506 | 506 | * |
| 507 | 507 | * @global wpdb $wpdb |
| 508 | 508 | * |
| 509 | - * @param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB. |
|
| 509 | + * @param integer $id User's ID, a WP_User object, or a user object from the DB. |
|
| 510 | 510 | * @param string $name Optional. User's username |
| 511 | 511 | * @param int $blog_id Optional Blog ID, defaults to current blog. |
| 512 | 512 | */ |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * WordPress Roles and Capabilities. |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage User |
|
| 7 | - */ |
|
| 3 | + * WordPress Roles and Capabilities. |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage User |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * WordPress User Roles. |
@@ -1123,162 +1123,162 @@ discard block |
||
| 1123 | 1123 | $caps = array(); |
| 1124 | 1124 | |
| 1125 | 1125 | switch ( $cap ) { |
| 1126 | - case 'remove_user': |
|
| 1127 | - $caps[] = 'remove_users'; |
|
| 1128 | - break; |
|
| 1129 | - case 'promote_user': |
|
| 1130 | - $caps[] = 'promote_users'; |
|
| 1131 | - break; |
|
| 1132 | - case 'edit_user': |
|
| 1133 | - case 'edit_users': |
|
| 1134 | - // Allow user to edit itself |
|
| 1135 | - if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) |
|
| 1126 | + case 'remove_user': |
|
| 1127 | + $caps[] = 'remove_users'; |
|
| 1136 | 1128 | break; |
| 1129 | + case 'promote_user': |
|
| 1130 | + $caps[] = 'promote_users'; |
|
| 1131 | + break; |
|
| 1132 | + case 'edit_user': |
|
| 1133 | + case 'edit_users': |
|
| 1134 | + // Allow user to edit itself |
|
| 1135 | + if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) |
|
| 1136 | + break; |
|
| 1137 | 1137 | |
| 1138 | - // If multisite these caps are allowed only for super admins. |
|
| 1139 | - if ( is_multisite() && !is_super_admin( $user_id ) ) |
|
| 1140 | - $caps[] = 'do_not_allow'; |
|
| 1141 | - else |
|
| 1142 | - $caps[] = 'edit_users'; // edit_user maps to edit_users. |
|
| 1143 | - break; |
|
| 1144 | - case 'delete_post': |
|
| 1145 | - case 'delete_page': |
|
| 1146 | - $post = get_post( $args[0] ); |
|
| 1147 | - |
|
| 1148 | - if ( 'revision' == $post->post_type ) { |
|
| 1149 | - $post = get_post( $post->post_parent ); |
|
| 1150 | - } |
|
| 1138 | + // If multisite these caps are allowed only for super admins. |
|
| 1139 | + if ( is_multisite() && !is_super_admin( $user_id ) ) |
|
| 1140 | + $caps[] = 'do_not_allow'; |
|
| 1141 | + else |
|
| 1142 | + $caps[] = 'edit_users'; // edit_user maps to edit_users. |
|
| 1143 | + break; |
|
| 1144 | + case 'delete_post': |
|
| 1145 | + case 'delete_page': |
|
| 1146 | + $post = get_post( $args[0] ); |
|
| 1147 | + |
|
| 1148 | + if ( 'revision' == $post->post_type ) { |
|
| 1149 | + $post = get_post( $post->post_parent ); |
|
| 1150 | + } |
|
| 1151 | 1151 | |
| 1152 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 1152 | + $post_type = get_post_type_object( $post->post_type ); |
|
| 1153 | 1153 | |
| 1154 | - if ( ! $post_type->map_meta_cap ) { |
|
| 1155 | - $caps[] = $post_type->cap->$cap; |
|
| 1156 | - // Prior to 3.1 we would re-call map_meta_cap here. |
|
| 1157 | - if ( 'delete_post' == $cap ) |
|
| 1158 | - $cap = $post_type->cap->$cap; |
|
| 1159 | - break; |
|
| 1160 | - } |
|
| 1154 | + if ( ! $post_type->map_meta_cap ) { |
|
| 1155 | + $caps[] = $post_type->cap->$cap; |
|
| 1156 | + // Prior to 3.1 we would re-call map_meta_cap here. |
|
| 1157 | + if ( 'delete_post' == $cap ) |
|
| 1158 | + $cap = $post_type->cap->$cap; |
|
| 1159 | + break; |
|
| 1160 | + } |
|
| 1161 | 1161 | |
| 1162 | - // If the post author is set and the user is the author... |
|
| 1163 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
| 1164 | - // If the post is published... |
|
| 1165 | - if ( 'publish' == $post->post_status ) { |
|
| 1166 | - $caps[] = $post_type->cap->delete_published_posts; |
|
| 1167 | - } elseif ( 'trash' == $post->post_status ) { |
|
| 1168 | - if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) { |
|
| 1162 | + // If the post author is set and the user is the author... |
|
| 1163 | + if ( $post->post_author && $user_id == $post->post_author ) { |
|
| 1164 | + // If the post is published... |
|
| 1165 | + if ( 'publish' == $post->post_status ) { |
|
| 1169 | 1166 | $caps[] = $post_type->cap->delete_published_posts; |
| 1167 | + } elseif ( 'trash' == $post->post_status ) { |
|
| 1168 | + if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) { |
|
| 1169 | + $caps[] = $post_type->cap->delete_published_posts; |
|
| 1170 | + } |
|
| 1171 | + } else { |
|
| 1172 | + // If the post is draft... |
|
| 1173 | + $caps[] = $post_type->cap->delete_posts; |
|
| 1170 | 1174 | } |
| 1171 | 1175 | } else { |
| 1172 | - // If the post is draft... |
|
| 1173 | - $caps[] = $post_type->cap->delete_posts; |
|
| 1174 | - } |
|
| 1175 | - } else { |
|
| 1176 | - // The user is trying to edit someone else's post. |
|
| 1177 | - $caps[] = $post_type->cap->delete_others_posts; |
|
| 1178 | - // The post is published, extra cap required. |
|
| 1179 | - if ( 'publish' == $post->post_status ) { |
|
| 1180 | - $caps[] = $post_type->cap->delete_published_posts; |
|
| 1181 | - } elseif ( 'private' == $post->post_status ) { |
|
| 1182 | - $caps[] = $post_type->cap->delete_private_posts; |
|
| 1176 | + // The user is trying to edit someone else's post. |
|
| 1177 | + $caps[] = $post_type->cap->delete_others_posts; |
|
| 1178 | + // The post is published, extra cap required. |
|
| 1179 | + if ( 'publish' == $post->post_status ) { |
|
| 1180 | + $caps[] = $post_type->cap->delete_published_posts; |
|
| 1181 | + } elseif ( 'private' == $post->post_status ) { |
|
| 1182 | + $caps[] = $post_type->cap->delete_private_posts; |
|
| 1183 | + } |
|
| 1183 | 1184 | } |
| 1184 | - } |
|
| 1185 | - break; |
|
| 1186 | - // edit_post breaks down to edit_posts, edit_published_posts, or |
|
| 1187 | - // edit_others_posts |
|
| 1188 | - case 'edit_post': |
|
| 1189 | - case 'edit_page': |
|
| 1190 | - $post = get_post( $args[0] ); |
|
| 1191 | - if ( empty( $post ) ) { |
|
| 1192 | - $caps[] = 'do_not_allow'; |
|
| 1193 | 1185 | break; |
| 1194 | - } |
|
| 1186 | + // edit_post breaks down to edit_posts, edit_published_posts, or |
|
| 1187 | + // edit_others_posts |
|
| 1188 | + case 'edit_post': |
|
| 1189 | + case 'edit_page': |
|
| 1190 | + $post = get_post( $args[0] ); |
|
| 1191 | + if ( empty( $post ) ) { |
|
| 1192 | + $caps[] = 'do_not_allow'; |
|
| 1193 | + break; |
|
| 1194 | + } |
|
| 1195 | 1195 | |
| 1196 | - if ( 'revision' == $post->post_type ) { |
|
| 1197 | - $post = get_post( $post->post_parent ); |
|
| 1198 | - } |
|
| 1196 | + if ( 'revision' == $post->post_type ) { |
|
| 1197 | + $post = get_post( $post->post_parent ); |
|
| 1198 | + } |
|
| 1199 | 1199 | |
| 1200 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 1200 | + $post_type = get_post_type_object( $post->post_type ); |
|
| 1201 | 1201 | |
| 1202 | - if ( ! $post_type->map_meta_cap ) { |
|
| 1203 | - $caps[] = $post_type->cap->$cap; |
|
| 1204 | - // Prior to 3.1 we would re-call map_meta_cap here. |
|
| 1205 | - if ( 'edit_post' == $cap ) |
|
| 1206 | - $cap = $post_type->cap->$cap; |
|
| 1207 | - break; |
|
| 1208 | - } |
|
| 1202 | + if ( ! $post_type->map_meta_cap ) { |
|
| 1203 | + $caps[] = $post_type->cap->$cap; |
|
| 1204 | + // Prior to 3.1 we would re-call map_meta_cap here. |
|
| 1205 | + if ( 'edit_post' == $cap ) |
|
| 1206 | + $cap = $post_type->cap->$cap; |
|
| 1207 | + break; |
|
| 1208 | + } |
|
| 1209 | 1209 | |
| 1210 | - // If the post author is set and the user is the author... |
|
| 1211 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
| 1212 | - // If the post is published... |
|
| 1213 | - if ( 'publish' == $post->post_status ) { |
|
| 1214 | - $caps[] = $post_type->cap->edit_published_posts; |
|
| 1215 | - } elseif ( 'trash' == $post->post_status ) { |
|
| 1216 | - if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) { |
|
| 1210 | + // If the post author is set and the user is the author... |
|
| 1211 | + if ( $post->post_author && $user_id == $post->post_author ) { |
|
| 1212 | + // If the post is published... |
|
| 1213 | + if ( 'publish' == $post->post_status ) { |
|
| 1217 | 1214 | $caps[] = $post_type->cap->edit_published_posts; |
| 1215 | + } elseif ( 'trash' == $post->post_status ) { |
|
| 1216 | + if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) { |
|
| 1217 | + $caps[] = $post_type->cap->edit_published_posts; |
|
| 1218 | + } |
|
| 1219 | + } else { |
|
| 1220 | + // If the post is draft... |
|
| 1221 | + $caps[] = $post_type->cap->edit_posts; |
|
| 1218 | 1222 | } |
| 1219 | 1223 | } else { |
| 1220 | - // If the post is draft... |
|
| 1221 | - $caps[] = $post_type->cap->edit_posts; |
|
| 1224 | + // The user is trying to edit someone else's post. |
|
| 1225 | + $caps[] = $post_type->cap->edit_others_posts; |
|
| 1226 | + // The post is published, extra cap required. |
|
| 1227 | + if ( 'publish' == $post->post_status ) { |
|
| 1228 | + $caps[] = $post_type->cap->edit_published_posts; |
|
| 1229 | + } elseif ( 'private' == $post->post_status ) { |
|
| 1230 | + $caps[] = $post_type->cap->edit_private_posts; |
|
| 1231 | + } |
|
| 1222 | 1232 | } |
| 1223 | - } else { |
|
| 1224 | - // The user is trying to edit someone else's post. |
|
| 1225 | - $caps[] = $post_type->cap->edit_others_posts; |
|
| 1226 | - // The post is published, extra cap required. |
|
| 1227 | - if ( 'publish' == $post->post_status ) { |
|
| 1228 | - $caps[] = $post_type->cap->edit_published_posts; |
|
| 1229 | - } elseif ( 'private' == $post->post_status ) { |
|
| 1230 | - $caps[] = $post_type->cap->edit_private_posts; |
|
| 1233 | + break; |
|
| 1234 | + case 'read_post': |
|
| 1235 | + case 'read_page': |
|
| 1236 | + $post = get_post( $args[0] ); |
|
| 1237 | + |
|
| 1238 | + if ( 'revision' == $post->post_type ) { |
|
| 1239 | + $post = get_post( $post->post_parent ); |
|
| 1231 | 1240 | } |
| 1232 | - } |
|
| 1233 | - break; |
|
| 1234 | - case 'read_post': |
|
| 1235 | - case 'read_page': |
|
| 1236 | - $post = get_post( $args[0] ); |
|
| 1237 | 1241 | |
| 1238 | - if ( 'revision' == $post->post_type ) { |
|
| 1239 | - $post = get_post( $post->post_parent ); |
|
| 1240 | - } |
|
| 1242 | + $post_type = get_post_type_object( $post->post_type ); |
|
| 1241 | 1243 | |
| 1242 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 1244 | + if ( ! $post_type->map_meta_cap ) { |
|
| 1245 | + $caps[] = $post_type->cap->$cap; |
|
| 1246 | + // Prior to 3.1 we would re-call map_meta_cap here. |
|
| 1247 | + if ( 'read_post' == $cap ) |
|
| 1248 | + $cap = $post_type->cap->$cap; |
|
| 1249 | + break; |
|
| 1250 | + } |
|
| 1243 | 1251 | |
| 1244 | - if ( ! $post_type->map_meta_cap ) { |
|
| 1245 | - $caps[] = $post_type->cap->$cap; |
|
| 1246 | - // Prior to 3.1 we would re-call map_meta_cap here. |
|
| 1247 | - if ( 'read_post' == $cap ) |
|
| 1248 | - $cap = $post_type->cap->$cap; |
|
| 1249 | - break; |
|
| 1250 | - } |
|
| 1252 | + $status_obj = get_post_status_object( $post->post_status ); |
|
| 1253 | + if ( $status_obj->public ) { |
|
| 1254 | + $caps[] = $post_type->cap->read; |
|
| 1255 | + break; |
|
| 1256 | + } |
|
| 1251 | 1257 | |
| 1252 | - $status_obj = get_post_status_object( $post->post_status ); |
|
| 1253 | - if ( $status_obj->public ) { |
|
| 1254 | - $caps[] = $post_type->cap->read; |
|
| 1258 | + if ( $post->post_author && $user_id == $post->post_author ) { |
|
| 1259 | + $caps[] = $post_type->cap->read; |
|
| 1260 | + } elseif ( $status_obj->private ) { |
|
| 1261 | + $caps[] = $post_type->cap->read_private_posts; |
|
| 1262 | + } else { |
|
| 1263 | + $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
| 1264 | + } |
|
| 1255 | 1265 | break; |
| 1256 | - } |
|
| 1266 | + case 'publish_post': |
|
| 1267 | + $post = get_post( $args[0] ); |
|
| 1268 | + $post_type = get_post_type_object( $post->post_type ); |
|
| 1257 | 1269 | |
| 1258 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
| 1259 | - $caps[] = $post_type->cap->read; |
|
| 1260 | - } elseif ( $status_obj->private ) { |
|
| 1261 | - $caps[] = $post_type->cap->read_private_posts; |
|
| 1262 | - } else { |
|
| 1270 | + $caps[] = $post_type->cap->publish_posts; |
|
| 1271 | + break; |
|
| 1272 | + case 'edit_post_meta': |
|
| 1273 | + case 'delete_post_meta': |
|
| 1274 | + case 'add_post_meta': |
|
| 1275 | + $post = get_post( $args[0] ); |
|
| 1263 | 1276 | $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
| 1264 | - } |
|
| 1265 | - break; |
|
| 1266 | - case 'publish_post': |
|
| 1267 | - $post = get_post( $args[0] ); |
|
| 1268 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 1269 | - |
|
| 1270 | - $caps[] = $post_type->cap->publish_posts; |
|
| 1271 | - break; |
|
| 1272 | - case 'edit_post_meta': |
|
| 1273 | - case 'delete_post_meta': |
|
| 1274 | - case 'add_post_meta': |
|
| 1275 | - $post = get_post( $args[0] ); |
|
| 1276 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
| 1277 | - |
|
| 1278 | - $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; |
|
| 1279 | - |
|
| 1280 | - if ( $meta_key && has_filter( "auth_post_meta_{$meta_key}" ) ) { |
|
| 1281 | - /** |
|
| 1277 | + |
|
| 1278 | + $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; |
|
| 1279 | + |
|
| 1280 | + if ( $meta_key && has_filter( "auth_post_meta_{$meta_key}" ) ) { |
|
| 1281 | + /** |
|
| 1282 | 1282 | * Filter whether the user is allowed to add post meta to a post. |
| 1283 | 1283 | * |
| 1284 | 1284 | * The dynamic portion of the hook name, `$meta_key`, refers to the |
@@ -1293,127 +1293,127 @@ discard block |
||
| 1293 | 1293 | * @param string $cap Capability name. |
| 1294 | 1294 | * @param array $caps User capabilities. |
| 1295 | 1295 | */ |
| 1296 | - $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps ); |
|
| 1297 | - if ( ! $allowed ) |
|
| 1296 | + $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps ); |
|
| 1297 | + if ( ! $allowed ) |
|
| 1298 | + $caps[] = $cap; |
|
| 1299 | + } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) { |
|
| 1298 | 1300 | $caps[] = $cap; |
| 1299 | - } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) { |
|
| 1300 | - $caps[] = $cap; |
|
| 1301 | - } |
|
| 1302 | - break; |
|
| 1303 | - case 'edit_comment': |
|
| 1304 | - $comment = get_comment( $args[0] ); |
|
| 1305 | - if ( empty( $comment ) ) |
|
| 1301 | + } |
|
| 1306 | 1302 | break; |
| 1307 | - $post = get_post( $comment->comment_post_ID ); |
|
| 1303 | + case 'edit_comment': |
|
| 1304 | + $comment = get_comment( $args[0] ); |
|
| 1305 | + if ( empty( $comment ) ) |
|
| 1306 | + break; |
|
| 1307 | + $post = get_post( $comment->comment_post_ID ); |
|
| 1308 | 1308 | |
| 1309 | - /* |
|
| 1309 | + /* |
|
| 1310 | 1310 | * If the post doesn't exist, we have an orphaned comment. |
| 1311 | 1311 | * Fall back to the edit_posts capability, instead. |
| 1312 | 1312 | */ |
| 1313 | - if ( $post ) { |
|
| 1314 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
| 1315 | - } else { |
|
| 1316 | - $caps = map_meta_cap( 'edit_posts', $user_id ); |
|
| 1317 | - } |
|
| 1318 | - break; |
|
| 1319 | - case 'unfiltered_upload': |
|
| 1320 | - if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) |
|
| 1321 | - $caps[] = $cap; |
|
| 1322 | - else |
|
| 1323 | - $caps[] = 'do_not_allow'; |
|
| 1324 | - break; |
|
| 1325 | - case 'unfiltered_html' : |
|
| 1326 | - // Disallow unfiltered_html for all users, even admins and super admins. |
|
| 1327 | - if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) |
|
| 1328 | - $caps[] = 'do_not_allow'; |
|
| 1329 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1330 | - $caps[] = 'do_not_allow'; |
|
| 1331 | - else |
|
| 1332 | - $caps[] = $cap; |
|
| 1333 | - break; |
|
| 1334 | - case 'edit_files': |
|
| 1335 | - case 'edit_plugins': |
|
| 1336 | - case 'edit_themes': |
|
| 1337 | - // Disallow the file editors. |
|
| 1338 | - if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) |
|
| 1339 | - $caps[] = 'do_not_allow'; |
|
| 1340 | - elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) |
|
| 1341 | - $caps[] = 'do_not_allow'; |
|
| 1342 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1343 | - $caps[] = 'do_not_allow'; |
|
| 1344 | - else |
|
| 1345 | - $caps[] = $cap; |
|
| 1346 | - break; |
|
| 1347 | - case 'update_plugins': |
|
| 1348 | - case 'delete_plugins': |
|
| 1349 | - case 'install_plugins': |
|
| 1350 | - case 'upload_plugins': |
|
| 1351 | - case 'update_themes': |
|
| 1352 | - case 'delete_themes': |
|
| 1353 | - case 'install_themes': |
|
| 1354 | - case 'upload_themes': |
|
| 1355 | - case 'update_core': |
|
| 1356 | - // Disallow anything that creates, deletes, or updates core, plugin, or theme files. |
|
| 1357 | - // Files in uploads are excepted. |
|
| 1358 | - if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
|
| 1359 | - $caps[] = 'do_not_allow'; |
|
| 1360 | - } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
| 1361 | - $caps[] = 'do_not_allow'; |
|
| 1362 | - } elseif ( 'upload_themes' === $cap ) { |
|
| 1363 | - $caps[] = 'install_themes'; |
|
| 1364 | - } elseif ( 'upload_plugins' === $cap ) { |
|
| 1365 | - $caps[] = 'install_plugins'; |
|
| 1366 | - } else { |
|
| 1367 | - $caps[] = $cap; |
|
| 1368 | - } |
|
| 1369 | - break; |
|
| 1370 | - case 'activate_plugins': |
|
| 1371 | - $caps[] = $cap; |
|
| 1372 | - if ( is_multisite() ) { |
|
| 1373 | - // update_, install_, and delete_ are handled above with is_super_admin(). |
|
| 1374 | - $menu_perms = get_site_option( 'menu_items', array() ); |
|
| 1375 | - if ( empty( $menu_perms['plugins'] ) ) |
|
| 1376 | - $caps[] = 'manage_network_plugins'; |
|
| 1377 | - } |
|
| 1378 | - break; |
|
| 1379 | - case 'delete_user': |
|
| 1380 | - case 'delete_users': |
|
| 1381 | - // If multisite only super admins can delete users. |
|
| 1382 | - if ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1383 | - $caps[] = 'do_not_allow'; |
|
| 1384 | - else |
|
| 1385 | - $caps[] = 'delete_users'; // delete_user maps to delete_users. |
|
| 1386 | - break; |
|
| 1387 | - case 'create_users': |
|
| 1388 | - if ( !is_multisite() ) |
|
| 1389 | - $caps[] = $cap; |
|
| 1390 | - elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) |
|
| 1391 | - $caps[] = $cap; |
|
| 1392 | - else |
|
| 1393 | - $caps[] = 'do_not_allow'; |
|
| 1394 | - break; |
|
| 1395 | - case 'manage_links' : |
|
| 1396 | - if ( get_option( 'link_manager_enabled' ) ) |
|
| 1313 | + if ( $post ) { |
|
| 1314 | + $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
| 1315 | + } else { |
|
| 1316 | + $caps = map_meta_cap( 'edit_posts', $user_id ); |
|
| 1317 | + } |
|
| 1318 | + break; |
|
| 1319 | + case 'unfiltered_upload': |
|
| 1320 | + if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) |
|
| 1321 | + $caps[] = $cap; |
|
| 1322 | + else |
|
| 1323 | + $caps[] = 'do_not_allow'; |
|
| 1324 | + break; |
|
| 1325 | + case 'unfiltered_html' : |
|
| 1326 | + // Disallow unfiltered_html for all users, even admins and super admins. |
|
| 1327 | + if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) |
|
| 1328 | + $caps[] = 'do_not_allow'; |
|
| 1329 | + elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1330 | + $caps[] = 'do_not_allow'; |
|
| 1331 | + else |
|
| 1332 | + $caps[] = $cap; |
|
| 1333 | + break; |
|
| 1334 | + case 'edit_files': |
|
| 1335 | + case 'edit_plugins': |
|
| 1336 | + case 'edit_themes': |
|
| 1337 | + // Disallow the file editors. |
|
| 1338 | + if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) |
|
| 1339 | + $caps[] = 'do_not_allow'; |
|
| 1340 | + elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) |
|
| 1341 | + $caps[] = 'do_not_allow'; |
|
| 1342 | + elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1343 | + $caps[] = 'do_not_allow'; |
|
| 1344 | + else |
|
| 1345 | + $caps[] = $cap; |
|
| 1346 | + break; |
|
| 1347 | + case 'update_plugins': |
|
| 1348 | + case 'delete_plugins': |
|
| 1349 | + case 'install_plugins': |
|
| 1350 | + case 'upload_plugins': |
|
| 1351 | + case 'update_themes': |
|
| 1352 | + case 'delete_themes': |
|
| 1353 | + case 'install_themes': |
|
| 1354 | + case 'upload_themes': |
|
| 1355 | + case 'update_core': |
|
| 1356 | + // Disallow anything that creates, deletes, or updates core, plugin, or theme files. |
|
| 1357 | + // Files in uploads are excepted. |
|
| 1358 | + if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
|
| 1359 | + $caps[] = 'do_not_allow'; |
|
| 1360 | + } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
| 1361 | + $caps[] = 'do_not_allow'; |
|
| 1362 | + } elseif ( 'upload_themes' === $cap ) { |
|
| 1363 | + $caps[] = 'install_themes'; |
|
| 1364 | + } elseif ( 'upload_plugins' === $cap ) { |
|
| 1365 | + $caps[] = 'install_plugins'; |
|
| 1366 | + } else { |
|
| 1367 | + $caps[] = $cap; |
|
| 1368 | + } |
|
| 1369 | + break; |
|
| 1370 | + case 'activate_plugins': |
|
| 1397 | 1371 | $caps[] = $cap; |
| 1398 | - else |
|
| 1399 | - $caps[] = 'do_not_allow'; |
|
| 1400 | - break; |
|
| 1401 | - case 'customize' : |
|
| 1402 | - $caps[] = 'edit_theme_options'; |
|
| 1403 | - break; |
|
| 1404 | - case 'delete_site': |
|
| 1405 | - $caps[] = 'manage_options'; |
|
| 1406 | - break; |
|
| 1407 | - default: |
|
| 1408 | - // Handle meta capabilities for custom post types. |
|
| 1409 | - $post_type_meta_caps = _post_type_meta_capabilities(); |
|
| 1410 | - if ( isset( $post_type_meta_caps[ $cap ] ) ) { |
|
| 1411 | - $args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args ); |
|
| 1412 | - return call_user_func_array( 'map_meta_cap', $args ); |
|
| 1413 | - } |
|
| 1372 | + if ( is_multisite() ) { |
|
| 1373 | + // update_, install_, and delete_ are handled above with is_super_admin(). |
|
| 1374 | + $menu_perms = get_site_option( 'menu_items', array() ); |
|
| 1375 | + if ( empty( $menu_perms['plugins'] ) ) |
|
| 1376 | + $caps[] = 'manage_network_plugins'; |
|
| 1377 | + } |
|
| 1378 | + break; |
|
| 1379 | + case 'delete_user': |
|
| 1380 | + case 'delete_users': |
|
| 1381 | + // If multisite only super admins can delete users. |
|
| 1382 | + if ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1383 | + $caps[] = 'do_not_allow'; |
|
| 1384 | + else |
|
| 1385 | + $caps[] = 'delete_users'; // delete_user maps to delete_users. |
|
| 1386 | + break; |
|
| 1387 | + case 'create_users': |
|
| 1388 | + if ( !is_multisite() ) |
|
| 1389 | + $caps[] = $cap; |
|
| 1390 | + elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) |
|
| 1391 | + $caps[] = $cap; |
|
| 1392 | + else |
|
| 1393 | + $caps[] = 'do_not_allow'; |
|
| 1394 | + break; |
|
| 1395 | + case 'manage_links' : |
|
| 1396 | + if ( get_option( 'link_manager_enabled' ) ) |
|
| 1397 | + $caps[] = $cap; |
|
| 1398 | + else |
|
| 1399 | + $caps[] = 'do_not_allow'; |
|
| 1400 | + break; |
|
| 1401 | + case 'customize' : |
|
| 1402 | + $caps[] = 'edit_theme_options'; |
|
| 1403 | + break; |
|
| 1404 | + case 'delete_site': |
|
| 1405 | + $caps[] = 'manage_options'; |
|
| 1406 | + break; |
|
| 1407 | + default: |
|
| 1408 | + // Handle meta capabilities for custom post types. |
|
| 1409 | + $post_type_meta_caps = _post_type_meta_capabilities(); |
|
| 1410 | + if ( isset( $post_type_meta_caps[ $cap ] ) ) { |
|
| 1411 | + $args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args ); |
|
| 1412 | + return call_user_func_array( 'map_meta_cap', $args ); |
|
| 1413 | + } |
|
| 1414 | 1414 | |
| 1415 | - // If no meta caps match, return the original cap. |
|
| 1416 | - $caps[] = $cap; |
|
| 1415 | + // If no meta caps match, return the original cap. |
|
| 1416 | + $caps[] = $cap; |
|
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | /** |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | * @param array $arguments Arguments to pass when calling. |
| 90 | 90 | * @return mixed|false Return value of the callback, false otherwise. |
| 91 | 91 | */ |
| 92 | - public function __call( $name, $arguments ) { |
|
| 93 | - if ( '_init' === $name ) { |
|
| 94 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
| 92 | + public function __call($name, $arguments) { |
|
| 93 | + if ('_init' === $name) { |
|
| 94 | + return call_user_func_array(array($this, $name), $arguments); |
|
| 95 | 95 | } |
| 96 | 96 | return false; |
| 97 | 97 | } |
@@ -111,21 +111,21 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | protected function _init() { |
| 113 | 113 | global $wpdb, $wp_user_roles; |
| 114 | - $this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; |
|
| 115 | - if ( ! empty( $wp_user_roles ) ) { |
|
| 114 | + $this->role_key = $wpdb->get_blog_prefix().'user_roles'; |
|
| 115 | + if ( ! empty($wp_user_roles)) { |
|
| 116 | 116 | $this->roles = $wp_user_roles; |
| 117 | 117 | $this->use_db = false; |
| 118 | 118 | } else { |
| 119 | - $this->roles = get_option( $this->role_key ); |
|
| 119 | + $this->roles = get_option($this->role_key); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if ( empty( $this->roles ) ) |
|
| 122 | + if (empty($this->roles)) |
|
| 123 | 123 | return; |
| 124 | 124 | |
| 125 | 125 | $this->role_objects = array(); |
| 126 | - $this->role_names = array(); |
|
| 127 | - foreach ( array_keys( $this->roles ) as $role ) { |
|
| 128 | - $this->role_objects[$role] = new WP_Role( $role, $this->roles[$role]['capabilities'] ); |
|
| 126 | + $this->role_names = array(); |
|
| 127 | + foreach (array_keys($this->roles) as $role) { |
|
| 128 | + $this->role_objects[$role] = new WP_Role($role, $this->roles[$role]['capabilities']); |
|
| 129 | 129 | $this->role_names[$role] = $this->roles[$role]['name']; |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -143,21 +143,21 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | public function reinit() { |
| 145 | 145 | // There is no need to reinit if using the wp_user_roles global. |
| 146 | - if ( ! $this->use_db ) |
|
| 146 | + if ( ! $this->use_db) |
|
| 147 | 147 | return; |
| 148 | 148 | |
| 149 | 149 | global $wpdb; |
| 150 | 150 | |
| 151 | 151 | // Duplicated from _init() to avoid an extra function call. |
| 152 | - $this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; |
|
| 153 | - $this->roles = get_option( $this->role_key ); |
|
| 154 | - if ( empty( $this->roles ) ) |
|
| 152 | + $this->role_key = $wpdb->get_blog_prefix().'user_roles'; |
|
| 153 | + $this->roles = get_option($this->role_key); |
|
| 154 | + if (empty($this->roles)) |
|
| 155 | 155 | return; |
| 156 | 156 | |
| 157 | 157 | $this->role_objects = array(); |
| 158 | - $this->role_names = array(); |
|
| 159 | - foreach ( array_keys( $this->roles ) as $role ) { |
|
| 160 | - $this->role_objects[$role] = new WP_Role( $role, $this->roles[$role]['capabilities'] ); |
|
| 158 | + $this->role_names = array(); |
|
| 159 | + foreach (array_keys($this->roles) as $role) { |
|
| 160 | + $this->role_objects[$role] = new WP_Role($role, $this->roles[$role]['capabilities']); |
|
| 161 | 161 | $this->role_names[$role] = $this->roles[$role]['name']; |
| 162 | 162 | } |
| 163 | 163 | } |
@@ -178,17 +178,17 @@ discard block |
||
| 178 | 178 | * @param array $capabilities List of role capabilities in the above format. |
| 179 | 179 | * @return WP_Role|void WP_Role object, if role is added. |
| 180 | 180 | */ |
| 181 | - public function add_role( $role, $display_name, $capabilities = array() ) { |
|
| 182 | - if ( isset( $this->roles[$role] ) ) |
|
| 181 | + public function add_role($role, $display_name, $capabilities = array()) { |
|
| 182 | + if (isset($this->roles[$role])) |
|
| 183 | 183 | return; |
| 184 | 184 | |
| 185 | 185 | $this->roles[$role] = array( |
| 186 | 186 | 'name' => $display_name, |
| 187 | 187 | 'capabilities' => $capabilities |
| 188 | 188 | ); |
| 189 | - if ( $this->use_db ) |
|
| 190 | - update_option( $this->role_key, $this->roles ); |
|
| 191 | - $this->role_objects[$role] = new WP_Role( $role, $capabilities ); |
|
| 189 | + if ($this->use_db) |
|
| 190 | + update_option($this->role_key, $this->roles); |
|
| 191 | + $this->role_objects[$role] = new WP_Role($role, $capabilities); |
|
| 192 | 192 | $this->role_names[$role] = $display_name; |
| 193 | 193 | return $this->role_objects[$role]; |
| 194 | 194 | } |
@@ -201,19 +201,19 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @param string $role Role name. |
| 203 | 203 | */ |
| 204 | - public function remove_role( $role ) { |
|
| 205 | - if ( ! isset( $this->role_objects[$role] ) ) |
|
| 204 | + public function remove_role($role) { |
|
| 205 | + if ( ! isset($this->role_objects[$role])) |
|
| 206 | 206 | return; |
| 207 | 207 | |
| 208 | - unset( $this->role_objects[$role] ); |
|
| 209 | - unset( $this->role_names[$role] ); |
|
| 210 | - unset( $this->roles[$role] ); |
|
| 208 | + unset($this->role_objects[$role]); |
|
| 209 | + unset($this->role_names[$role]); |
|
| 210 | + unset($this->roles[$role]); |
|
| 211 | 211 | |
| 212 | - if ( $this->use_db ) |
|
| 213 | - update_option( $this->role_key, $this->roles ); |
|
| 212 | + if ($this->use_db) |
|
| 213 | + update_option($this->role_key, $this->roles); |
|
| 214 | 214 | |
| 215 | - if ( get_option( 'default_role' ) == $role ) |
|
| 216 | - update_option( 'default_role', 'subscriber' ); |
|
| 215 | + if (get_option('default_role') == $role) |
|
| 216 | + update_option('default_role', 'subscriber'); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -226,13 +226,13 @@ discard block |
||
| 226 | 226 | * @param string $cap Capability name. |
| 227 | 227 | * @param bool $grant Optional, default is true. Whether role is capable of performing capability. |
| 228 | 228 | */ |
| 229 | - public function add_cap( $role, $cap, $grant = true ) { |
|
| 230 | - if ( ! isset( $this->roles[$role] ) ) |
|
| 229 | + public function add_cap($role, $cap, $grant = true) { |
|
| 230 | + if ( ! isset($this->roles[$role])) |
|
| 231 | 231 | return; |
| 232 | 232 | |
| 233 | 233 | $this->roles[$role]['capabilities'][$cap] = $grant; |
| 234 | - if ( $this->use_db ) |
|
| 235 | - update_option( $this->role_key, $this->roles ); |
|
| 234 | + if ($this->use_db) |
|
| 235 | + update_option($this->role_key, $this->roles); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -244,13 +244,13 @@ discard block |
||
| 244 | 244 | * @param string $role Role name. |
| 245 | 245 | * @param string $cap Capability name. |
| 246 | 246 | */ |
| 247 | - public function remove_cap( $role, $cap ) { |
|
| 248 | - if ( ! isset( $this->roles[$role] ) ) |
|
| 247 | + public function remove_cap($role, $cap) { |
|
| 248 | + if ( ! isset($this->roles[$role])) |
|
| 249 | 249 | return; |
| 250 | 250 | |
| 251 | - unset( $this->roles[$role]['capabilities'][$cap] ); |
|
| 252 | - if ( $this->use_db ) |
|
| 253 | - update_option( $this->role_key, $this->roles ); |
|
| 251 | + unset($this->roles[$role]['capabilities'][$cap]); |
|
| 252 | + if ($this->use_db) |
|
| 253 | + update_option($this->role_key, $this->roles); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -262,8 +262,8 @@ discard block |
||
| 262 | 262 | * @param string $role Role name. |
| 263 | 263 | * @return WP_Role|null WP_Role object if found, null if the role does not exist. |
| 264 | 264 | */ |
| 265 | - public function get_role( $role ) { |
|
| 266 | - if ( isset( $this->role_objects[$role] ) ) |
|
| 265 | + public function get_role($role) { |
|
| 266 | + if (isset($this->role_objects[$role])) |
|
| 267 | 267 | return $this->role_objects[$role]; |
| 268 | 268 | else |
| 269 | 269 | return null; |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * @param string $role Role name to look up. |
| 291 | 291 | * @return bool |
| 292 | 292 | */ |
| 293 | - public function is_role( $role ) { |
|
| 294 | - return isset( $this->role_names[$role] ); |
|
| 293 | + public function is_role($role) { |
|
| 294 | + return isset($this->role_names[$role]); |
|
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * @param string $role Role name. |
| 334 | 334 | * @param array $capabilities List of capabilities. |
| 335 | 335 | */ |
| 336 | - public function __construct( $role, $capabilities ) { |
|
| 336 | + public function __construct($role, $capabilities) { |
|
| 337 | 337 | $this->name = $role; |
| 338 | 338 | $this->capabilities = $capabilities; |
| 339 | 339 | } |
@@ -347,9 +347,9 @@ discard block |
||
| 347 | 347 | * @param string $cap Capability name. |
| 348 | 348 | * @param bool $grant Whether role has capability privilege. |
| 349 | 349 | */ |
| 350 | - public function add_cap( $cap, $grant = true ) { |
|
| 350 | + public function add_cap($cap, $grant = true) { |
|
| 351 | 351 | $this->capabilities[$cap] = $grant; |
| 352 | - wp_roles()->add_cap( $this->name, $cap, $grant ); |
|
| 352 | + wp_roles()->add_cap($this->name, $cap, $grant); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -365,9 +365,9 @@ discard block |
||
| 365 | 365 | * |
| 366 | 366 | * @param string $cap Capability name. |
| 367 | 367 | */ |
| 368 | - public function remove_cap( $cap ) { |
|
| 369 | - unset( $this->capabilities[$cap] ); |
|
| 370 | - wp_roles()->remove_cap( $this->name, $cap ); |
|
| 368 | + public function remove_cap($cap) { |
|
| 369 | + unset($this->capabilities[$cap]); |
|
| 370 | + wp_roles()->remove_cap($this->name, $cap); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | * @param string $cap Capability name. |
| 385 | 385 | * @return bool True, if user has capability. False, if doesn't have capability. |
| 386 | 386 | */ |
| 387 | - public function has_cap( $cap ) { |
|
| 387 | + public function has_cap($cap) { |
|
| 388 | 388 | /** |
| 389 | 389 | * Filter which capabilities a role has. |
| 390 | 390 | * |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | * @param string $cap Capability name. |
| 395 | 395 | * @param string $name Role name. |
| 396 | 396 | */ |
| 397 | - $capabilities = apply_filters( 'role_has_cap', $this->capabilities, $cap, $this->name ); |
|
| 398 | - if ( !empty( $capabilities[$cap] ) ) |
|
| 397 | + $capabilities = apply_filters('role_has_cap', $this->capabilities, $cap, $this->name); |
|
| 398 | + if ( ! empty($capabilities[$cap])) |
|
| 399 | 399 | return $capabilities[$cap]; |
| 400 | 400 | else |
| 401 | 401 | return false; |
@@ -510,40 +510,40 @@ discard block |
||
| 510 | 510 | * @param string $name Optional. User's username |
| 511 | 511 | * @param int $blog_id Optional Blog ID, defaults to current blog. |
| 512 | 512 | */ |
| 513 | - public function __construct( $id = 0, $name = '', $blog_id = '' ) { |
|
| 514 | - if ( ! isset( self::$back_compat_keys ) ) { |
|
| 513 | + public function __construct($id = 0, $name = '', $blog_id = '') { |
|
| 514 | + if ( ! isset(self::$back_compat_keys)) { |
|
| 515 | 515 | $prefix = $GLOBALS['wpdb']->prefix; |
| 516 | 516 | self::$back_compat_keys = array( |
| 517 | 517 | 'user_firstname' => 'first_name', |
| 518 | 518 | 'user_lastname' => 'last_name', |
| 519 | 519 | 'user_description' => 'description', |
| 520 | - 'user_level' => $prefix . 'user_level', |
|
| 521 | - $prefix . 'usersettings' => $prefix . 'user-settings', |
|
| 522 | - $prefix . 'usersettingstime' => $prefix . 'user-settings-time', |
|
| 520 | + 'user_level' => $prefix.'user_level', |
|
| 521 | + $prefix.'usersettings' => $prefix.'user-settings', |
|
| 522 | + $prefix.'usersettingstime' => $prefix.'user-settings-time', |
|
| 523 | 523 | ); |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - if ( $id instanceof WP_User ) { |
|
| 527 | - $this->init( $id->data, $blog_id ); |
|
| 526 | + if ($id instanceof WP_User) { |
|
| 527 | + $this->init($id->data, $blog_id); |
|
| 528 | 528 | return; |
| 529 | - } elseif ( is_object( $id ) ) { |
|
| 530 | - $this->init( $id, $blog_id ); |
|
| 529 | + } elseif (is_object($id)) { |
|
| 530 | + $this->init($id, $blog_id); |
|
| 531 | 531 | return; |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - if ( ! empty( $id ) && ! is_numeric( $id ) ) { |
|
| 534 | + if ( ! empty($id) && ! is_numeric($id)) { |
|
| 535 | 535 | $name = $id; |
| 536 | 536 | $id = 0; |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - if ( $id ) { |
|
| 540 | - $data = self::get_data_by( 'id', $id ); |
|
| 539 | + if ($id) { |
|
| 540 | + $data = self::get_data_by('id', $id); |
|
| 541 | 541 | } else { |
| 542 | - $data = self::get_data_by( 'login', $name ); |
|
| 542 | + $data = self::get_data_by('login', $name); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - if ( $data ) { |
|
| 546 | - $this->init( $data, $blog_id ); |
|
| 545 | + if ($data) { |
|
| 546 | + $this->init($data, $blog_id); |
|
| 547 | 547 | } else { |
| 548 | 548 | $this->data = new stdClass; |
| 549 | 549 | } |
@@ -555,11 +555,11 @@ discard block |
||
| 555 | 555 | * @param object $data User DB row object |
| 556 | 556 | * @param int $blog_id Optional. The blog id to initialize for |
| 557 | 557 | */ |
| 558 | - public function init( $data, $blog_id = '' ) { |
|
| 558 | + public function init($data, $blog_id = '') { |
|
| 559 | 559 | $this->data = $data; |
| 560 | 560 | $this->ID = (int) $data->ID; |
| 561 | 561 | |
| 562 | - $this->for_blog( $blog_id ); |
|
| 562 | + $this->for_blog($blog_id); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
@@ -575,25 +575,25 @@ discard block |
||
| 575 | 575 | * @param string|int $value The field value |
| 576 | 576 | * @return object|false Raw user object |
| 577 | 577 | */ |
| 578 | - public static function get_data_by( $field, $value ) { |
|
| 578 | + public static function get_data_by($field, $value) { |
|
| 579 | 579 | global $wpdb; |
| 580 | 580 | |
| 581 | - if ( 'id' == $field ) { |
|
| 581 | + if ('id' == $field) { |
|
| 582 | 582 | // Make sure the value is numeric to avoid casting objects, for example, |
| 583 | 583 | // to int 1. |
| 584 | - if ( ! is_numeric( $value ) ) |
|
| 584 | + if ( ! is_numeric($value)) |
|
| 585 | 585 | return false; |
| 586 | - $value = intval( $value ); |
|
| 587 | - if ( $value < 1 ) |
|
| 586 | + $value = intval($value); |
|
| 587 | + if ($value < 1) |
|
| 588 | 588 | return false; |
| 589 | 589 | } else { |
| 590 | - $value = trim( $value ); |
|
| 590 | + $value = trim($value); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - if ( !$value ) |
|
| 593 | + if ( ! $value) |
|
| 594 | 594 | return false; |
| 595 | 595 | |
| 596 | - switch ( $field ) { |
|
| 596 | + switch ($field) { |
|
| 597 | 597 | case 'id': |
| 598 | 598 | $user_id = $value; |
| 599 | 599 | $db_field = 'ID'; |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | $db_field = 'user_email'; |
| 608 | 608 | break; |
| 609 | 609 | case 'login': |
| 610 | - $value = sanitize_user( $value ); |
|
| 610 | + $value = sanitize_user($value); |
|
| 611 | 611 | $user_id = wp_cache_get($value, 'userlogins'); |
| 612 | 612 | $db_field = 'user_login'; |
| 613 | 613 | break; |
@@ -615,17 +615,17 @@ discard block |
||
| 615 | 615 | return false; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - if ( false !== $user_id ) { |
|
| 619 | - if ( $user = wp_cache_get( $user_id, 'users' ) ) |
|
| 618 | + if (false !== $user_id) { |
|
| 619 | + if ($user = wp_cache_get($user_id, 'users')) |
|
| 620 | 620 | return $user; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - if ( !$user = $wpdb->get_row( $wpdb->prepare( |
|
| 623 | + if ( ! $user = $wpdb->get_row($wpdb->prepare( |
|
| 624 | 624 | "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value |
| 625 | - ) ) ) |
|
| 625 | + ))) |
|
| 626 | 626 | return false; |
| 627 | 627 | |
| 628 | - update_user_caches( $user ); |
|
| 628 | + update_user_caches($user); |
|
| 629 | 629 | |
| 630 | 630 | return $user; |
| 631 | 631 | } |
@@ -640,9 +640,9 @@ discard block |
||
| 640 | 640 | * @param array $arguments Arguments to pass when calling. |
| 641 | 641 | * @return mixed|false Return value of the callback, false otherwise. |
| 642 | 642 | */ |
| 643 | - public function __call( $name, $arguments ) { |
|
| 644 | - if ( '_init_caps' === $name ) { |
|
| 645 | - return call_user_func_array( array( $this, $name ), $arguments ); |
|
| 643 | + public function __call($name, $arguments) { |
|
| 644 | + if ('_init_caps' === $name) { |
|
| 645 | + return call_user_func_array(array($this, $name), $arguments); |
|
| 646 | 646 | } |
| 647 | 647 | return false; |
| 648 | 648 | } |
@@ -654,19 +654,19 @@ discard block |
||
| 654 | 654 | * @param string $key |
| 655 | 655 | * @return bool |
| 656 | 656 | */ |
| 657 | - public function __isset( $key ) { |
|
| 658 | - if ( 'id' == $key ) { |
|
| 659 | - _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) ); |
|
| 657 | + public function __isset($key) { |
|
| 658 | + if ('id' == $key) { |
|
| 659 | + _deprecated_argument('WP_User->id', '2.1', __('Use <code>WP_User->ID</code> instead.')); |
|
| 660 | 660 | $key = 'ID'; |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - if ( isset( $this->data->$key ) ) |
|
| 663 | + if (isset($this->data->$key)) |
|
| 664 | 664 | return true; |
| 665 | 665 | |
| 666 | - if ( isset( self::$back_compat_keys[ $key ] ) ) |
|
| 667 | - $key = self::$back_compat_keys[ $key ]; |
|
| 666 | + if (isset(self::$back_compat_keys[$key])) |
|
| 667 | + $key = self::$back_compat_keys[$key]; |
|
| 668 | 668 | |
| 669 | - return metadata_exists( 'user', $this->ID, $key ); |
|
| 669 | + return metadata_exists('user', $this->ID, $key); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | /** |
@@ -676,22 +676,22 @@ discard block |
||
| 676 | 676 | * @param string $key |
| 677 | 677 | * @return mixed |
| 678 | 678 | */ |
| 679 | - public function __get( $key ) { |
|
| 680 | - if ( 'id' == $key ) { |
|
| 681 | - _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) ); |
|
| 679 | + public function __get($key) { |
|
| 680 | + if ('id' == $key) { |
|
| 681 | + _deprecated_argument('WP_User->id', '2.1', __('Use <code>WP_User->ID</code> instead.')); |
|
| 682 | 682 | return $this->ID; |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - if ( isset( $this->data->$key ) ) { |
|
| 685 | + if (isset($this->data->$key)) { |
|
| 686 | 686 | $value = $this->data->$key; |
| 687 | 687 | } else { |
| 688 | - if ( isset( self::$back_compat_keys[ $key ] ) ) |
|
| 689 | - $key = self::$back_compat_keys[ $key ]; |
|
| 690 | - $value = get_user_meta( $this->ID, $key, true ); |
|
| 688 | + if (isset(self::$back_compat_keys[$key])) |
|
| 689 | + $key = self::$back_compat_keys[$key]; |
|
| 690 | + $value = get_user_meta($this->ID, $key, true); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | - if ( $this->filter ) { |
|
| 694 | - $value = sanitize_user_field( $key, $value, $this->ID, $this->filter ); |
|
| 693 | + if ($this->filter) { |
|
| 694 | + $value = sanitize_user_field($key, $value, $this->ID, $this->filter); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | return $value; |
@@ -702,9 +702,9 @@ discard block |
||
| 702 | 702 | * |
| 703 | 703 | * @since 3.3.0 |
| 704 | 704 | */ |
| 705 | - public function __set( $key, $value ) { |
|
| 706 | - if ( 'id' == $key ) { |
|
| 707 | - _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) ); |
|
| 705 | + public function __set($key, $value) { |
|
| 706 | + if ('id' == $key) { |
|
| 707 | + _deprecated_argument('WP_User->id', '2.1', __('Use <code>WP_User->ID</code> instead.')); |
|
| 708 | 708 | $this->ID = $value; |
| 709 | 709 | return; |
| 710 | 710 | } |
@@ -721,7 +721,7 @@ discard block |
||
| 721 | 721 | * @return bool True if user exists in the database, false if not. |
| 722 | 722 | */ |
| 723 | 723 | public function exists() { |
| 724 | - return ! empty( $this->ID ); |
|
| 724 | + return ! empty($this->ID); |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | /** |
@@ -734,8 +734,8 @@ discard block |
||
| 734 | 734 | * @param string $key Property |
| 735 | 735 | * @return mixed |
| 736 | 736 | */ |
| 737 | - public function get( $key ) { |
|
| 738 | - return $this->__get( $key ); |
|
| 737 | + public function get($key) { |
|
| 738 | + return $this->__get($key); |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | /** |
@@ -748,8 +748,8 @@ discard block |
||
| 748 | 748 | * @param string $key Property |
| 749 | 749 | * @return bool |
| 750 | 750 | */ |
| 751 | - public function has_prop( $key ) { |
|
| 752 | - return $this->__isset( $key ); |
|
| 751 | + public function has_prop($key) { |
|
| 752 | + return $this->__isset($key); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | /** |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | * @return array Array representation. |
| 761 | 761 | */ |
| 762 | 762 | public function to_array() { |
| 763 | - return get_object_vars( $this->data ); |
|
| 763 | + return get_object_vars($this->data); |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | /** |
@@ -778,17 +778,17 @@ discard block |
||
| 778 | 778 | * |
| 779 | 779 | * @param string $cap_key Optional capability key |
| 780 | 780 | */ |
| 781 | - protected function _init_caps( $cap_key = '' ) { |
|
| 781 | + protected function _init_caps($cap_key = '') { |
|
| 782 | 782 | global $wpdb; |
| 783 | 783 | |
| 784 | - if ( empty($cap_key) ) |
|
| 785 | - $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; |
|
| 784 | + if (empty($cap_key)) |
|
| 785 | + $this->cap_key = $wpdb->get_blog_prefix().'capabilities'; |
|
| 786 | 786 | else |
| 787 | 787 | $this->cap_key = $cap_key; |
| 788 | 788 | |
| 789 | - $this->caps = get_user_meta( $this->ID, $this->cap_key, true ); |
|
| 789 | + $this->caps = get_user_meta($this->ID, $this->cap_key, true); |
|
| 790 | 790 | |
| 791 | - if ( ! is_array( $this->caps ) ) |
|
| 791 | + if ( ! is_array($this->caps)) |
|
| 792 | 792 | $this->caps = array(); |
| 793 | 793 | |
| 794 | 794 | $this->get_role_caps(); |
@@ -811,16 +811,16 @@ discard block |
||
| 811 | 811 | $wp_roles = wp_roles(); |
| 812 | 812 | |
| 813 | 813 | //Filter out caps that are not role names and assign to $this->roles |
| 814 | - if ( is_array( $this->caps ) ) |
|
| 815 | - $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) ); |
|
| 814 | + if (is_array($this->caps)) |
|
| 815 | + $this->roles = array_filter(array_keys($this->caps), array($wp_roles, 'is_role')); |
|
| 816 | 816 | |
| 817 | 817 | //Build $allcaps from role caps, overlay user's $caps |
| 818 | 818 | $this->allcaps = array(); |
| 819 | - foreach ( (array) $this->roles as $role ) { |
|
| 820 | - $the_role = $wp_roles->get_role( $role ); |
|
| 821 | - $this->allcaps = array_merge( (array) $this->allcaps, (array) $the_role->capabilities ); |
|
| 819 | + foreach ((array) $this->roles as $role) { |
|
| 820 | + $the_role = $wp_roles->get_role($role); |
|
| 821 | + $this->allcaps = array_merge((array) $this->allcaps, (array) $the_role->capabilities); |
|
| 822 | 822 | } |
| 823 | - $this->allcaps = array_merge( (array) $this->allcaps, (array) $this->caps ); |
|
| 823 | + $this->allcaps = array_merge((array) $this->allcaps, (array) $this->caps); |
|
| 824 | 824 | |
| 825 | 825 | return $this->allcaps; |
| 826 | 826 | } |
@@ -835,9 +835,9 @@ discard block |
||
| 835 | 835 | * |
| 836 | 836 | * @param string $role Role name. |
| 837 | 837 | */ |
| 838 | - public function add_role( $role ) { |
|
| 838 | + public function add_role($role) { |
|
| 839 | 839 | $this->caps[$role] = true; |
| 840 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
| 840 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
| 841 | 841 | $this->get_role_caps(); |
| 842 | 842 | $this->update_user_level_from_caps(); |
| 843 | 843 | |
@@ -849,7 +849,7 @@ discard block |
||
| 849 | 849 | * @param int $user_id The user ID. |
| 850 | 850 | * @param string $role The new role. |
| 851 | 851 | */ |
| 852 | - do_action( 'add_user_role', $this->ID, $role ); |
|
| 852 | + do_action('add_user_role', $this->ID, $role); |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | /** |
@@ -860,11 +860,11 @@ discard block |
||
| 860 | 860 | * |
| 861 | 861 | * @param string $role Role name. |
| 862 | 862 | */ |
| 863 | - public function remove_role( $role ) { |
|
| 864 | - if ( !in_array($role, $this->roles) ) |
|
| 863 | + public function remove_role($role) { |
|
| 864 | + if ( ! in_array($role, $this->roles)) |
|
| 865 | 865 | return; |
| 866 | - unset( $this->caps[$role] ); |
|
| 867 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
| 866 | + unset($this->caps[$role]); |
|
| 867 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
| 868 | 868 | $this->get_role_caps(); |
| 869 | 869 | $this->update_user_level_from_caps(); |
| 870 | 870 | |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | * @param int $user_id The user ID. |
| 877 | 877 | * @param string $role The removed role. |
| 878 | 878 | */ |
| 879 | - do_action( 'remove_user_role', $this->ID, $role ); |
|
| 879 | + do_action('remove_user_role', $this->ID, $role); |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | /** |
@@ -891,21 +891,21 @@ discard block |
||
| 891 | 891 | * |
| 892 | 892 | * @param string $role Role name. |
| 893 | 893 | */ |
| 894 | - public function set_role( $role ) { |
|
| 895 | - if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) |
|
| 894 | + public function set_role($role) { |
|
| 895 | + if (1 == count($this->roles) && $role == current($this->roles)) |
|
| 896 | 896 | return; |
| 897 | 897 | |
| 898 | - foreach ( (array) $this->roles as $oldrole ) |
|
| 899 | - unset( $this->caps[$oldrole] ); |
|
| 898 | + foreach ((array) $this->roles as $oldrole) |
|
| 899 | + unset($this->caps[$oldrole]); |
|
| 900 | 900 | |
| 901 | 901 | $old_roles = $this->roles; |
| 902 | - if ( !empty( $role ) ) { |
|
| 902 | + if ( ! empty($role)) { |
|
| 903 | 903 | $this->caps[$role] = true; |
| 904 | - $this->roles = array( $role => true ); |
|
| 904 | + $this->roles = array($role => true); |
|
| 905 | 905 | } else { |
| 906 | 906 | $this->roles = false; |
| 907 | 907 | } |
| 908 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
| 908 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
| 909 | 909 | $this->get_role_caps(); |
| 910 | 910 | $this->update_user_level_from_caps(); |
| 911 | 911 | |
@@ -919,7 +919,7 @@ discard block |
||
| 919 | 919 | * @param string $role The new role. |
| 920 | 920 | * @param array $old_roles An array of the user's previous roles. |
| 921 | 921 | */ |
| 922 | - do_action( 'set_user_role', $this->ID, $role, $old_roles ); |
|
| 922 | + do_action('set_user_role', $this->ID, $role, $old_roles); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | /** |
@@ -941,10 +941,10 @@ discard block |
||
| 941 | 941 | * @param string $item Level capability name. |
| 942 | 942 | * @return int Max Level. |
| 943 | 943 | */ |
| 944 | - public function level_reduction( $max, $item ) { |
|
| 945 | - if ( preg_match( '/^level_(10|[0-9])$/i', $item, $matches ) ) { |
|
| 946 | - $level = intval( $matches[1] ); |
|
| 947 | - return max( $max, $level ); |
|
| 944 | + public function level_reduction($max, $item) { |
|
| 945 | + if (preg_match('/^level_(10|[0-9])$/i', $item, $matches)) { |
|
| 946 | + $level = intval($matches[1]); |
|
| 947 | + return max($max, $level); |
|
| 948 | 948 | } else { |
| 949 | 949 | return $max; |
| 950 | 950 | } |
@@ -964,8 +964,8 @@ discard block |
||
| 964 | 964 | */ |
| 965 | 965 | public function update_user_level_from_caps() { |
| 966 | 966 | global $wpdb; |
| 967 | - $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 ); |
|
| 968 | - update_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level', $this->user_level ); |
|
| 967 | + $this->user_level = array_reduce(array_keys($this->allcaps), array($this, 'level_reduction'), 0); |
|
| 968 | + update_user_meta($this->ID, $wpdb->get_blog_prefix().'user_level', $this->user_level); |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -977,9 +977,9 @@ discard block |
||
| 977 | 977 | * @param string $cap Capability name. |
| 978 | 978 | * @param bool $grant Whether to grant capability to user. |
| 979 | 979 | */ |
| 980 | - public function add_cap( $cap, $grant = true ) { |
|
| 980 | + public function add_cap($cap, $grant = true) { |
|
| 981 | 981 | $this->caps[$cap] = $grant; |
| 982 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
| 982 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
| 983 | 983 | $this->get_role_caps(); |
| 984 | 984 | $this->update_user_level_from_caps(); |
| 985 | 985 | } |
@@ -992,12 +992,12 @@ discard block |
||
| 992 | 992 | * |
| 993 | 993 | * @param string $cap Capability name. |
| 994 | 994 | */ |
| 995 | - public function remove_cap( $cap ) { |
|
| 996 | - if ( ! isset( $this->caps[ $cap ] ) ) { |
|
| 995 | + public function remove_cap($cap) { |
|
| 996 | + if ( ! isset($this->caps[$cap])) { |
|
| 997 | 997 | return; |
| 998 | 998 | } |
| 999 | - unset( $this->caps[ $cap ] ); |
|
| 1000 | - update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
|
| 999 | + unset($this->caps[$cap]); |
|
| 1000 | + update_user_meta($this->ID, $this->cap_key, $this->caps); |
|
| 1001 | 1001 | $this->get_role_caps(); |
| 1002 | 1002 | $this->update_user_level_from_caps(); |
| 1003 | 1003 | } |
@@ -1013,8 +1013,8 @@ discard block |
||
| 1013 | 1013 | public function remove_all_caps() { |
| 1014 | 1014 | global $wpdb; |
| 1015 | 1015 | $this->caps = array(); |
| 1016 | - delete_user_meta( $this->ID, $this->cap_key ); |
|
| 1017 | - delete_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level' ); |
|
| 1016 | + delete_user_meta($this->ID, $this->cap_key); |
|
| 1017 | + delete_user_meta($this->ID, $wpdb->get_blog_prefix().'user_level'); |
|
| 1018 | 1018 | $this->get_role_caps(); |
| 1019 | 1019 | } |
| 1020 | 1020 | |
@@ -1031,19 +1031,19 @@ discard block |
||
| 1031 | 1031 | * @param string|int $cap Capability or role name to search. |
| 1032 | 1032 | * @return bool True, if user has capability; false, if user does not have capability. |
| 1033 | 1033 | */ |
| 1034 | - public function has_cap( $cap ) { |
|
| 1035 | - if ( is_numeric( $cap ) ) { |
|
| 1036 | - _deprecated_argument( __FUNCTION__, '2.0', __('Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead.') ); |
|
| 1037 | - $cap = $this->translate_level_to_cap( $cap ); |
|
| 1034 | + public function has_cap($cap) { |
|
| 1035 | + if (is_numeric($cap)) { |
|
| 1036 | + _deprecated_argument(__FUNCTION__, '2.0', __('Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead.')); |
|
| 1037 | + $cap = $this->translate_level_to_cap($cap); |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | - $args = array_slice( func_get_args(), 1 ); |
|
| 1041 | - $args = array_merge( array( $cap, $this->ID ), $args ); |
|
| 1042 | - $caps = call_user_func_array( 'map_meta_cap', $args ); |
|
| 1040 | + $args = array_slice(func_get_args(), 1); |
|
| 1041 | + $args = array_merge(array($cap, $this->ID), $args); |
|
| 1042 | + $caps = call_user_func_array('map_meta_cap', $args); |
|
| 1043 | 1043 | |
| 1044 | 1044 | // Multisite super admin has all caps by definition, Unless specifically denied. |
| 1045 | - if ( is_multisite() && is_super_admin( $this->ID ) ) { |
|
| 1046 | - if ( in_array('do_not_allow', $caps) ) |
|
| 1045 | + if (is_multisite() && is_super_admin($this->ID)) { |
|
| 1046 | + if (in_array('do_not_allow', $caps)) |
|
| 1047 | 1047 | return false; |
| 1048 | 1048 | return true; |
| 1049 | 1049 | } |
@@ -1060,10 +1060,10 @@ discard block |
||
| 1060 | 1060 | * @param WP_User $user The user object. |
| 1061 | 1061 | */ |
| 1062 | 1062 | // Must have ALL requested caps |
| 1063 | - $capabilities = apply_filters( 'user_has_cap', $this->allcaps, $caps, $args, $this ); |
|
| 1063 | + $capabilities = apply_filters('user_has_cap', $this->allcaps, $caps, $args, $this); |
|
| 1064 | 1064 | $capabilities['exist'] = true; // Everyone is allowed to exist |
| 1065 | - foreach ( (array) $caps as $cap ) { |
|
| 1066 | - if ( empty( $capabilities[ $cap ] ) ) |
|
| 1065 | + foreach ((array) $caps as $cap) { |
|
| 1066 | + if (empty($capabilities[$cap])) |
|
| 1067 | 1067 | return false; |
| 1068 | 1068 | } |
| 1069 | 1069 | |
@@ -1081,8 +1081,8 @@ discard block |
||
| 1081 | 1081 | * @param int $level Level number, 1 to 10. |
| 1082 | 1082 | * @return string |
| 1083 | 1083 | */ |
| 1084 | - public function translate_level_to_cap( $level ) { |
|
| 1085 | - return 'level_' . $level; |
|
| 1084 | + public function translate_level_to_cap($level) { |
|
| 1085 | + return 'level_'.$level; |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | /** |
@@ -1094,13 +1094,13 @@ discard block |
||
| 1094 | 1094 | * |
| 1095 | 1095 | * @param int $blog_id Optional Blog ID, defaults to current blog. |
| 1096 | 1096 | */ |
| 1097 | - public function for_blog( $blog_id = '' ) { |
|
| 1097 | + public function for_blog($blog_id = '') { |
|
| 1098 | 1098 | global $wpdb; |
| 1099 | - if ( ! empty( $blog_id ) ) |
|
| 1100 | - $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; |
|
| 1099 | + if ( ! empty($blog_id)) |
|
| 1100 | + $cap_key = $wpdb->get_blog_prefix($blog_id).'capabilities'; |
|
| 1101 | 1101 | else |
| 1102 | 1102 | $cap_key = ''; |
| 1103 | - $this->_init_caps( $cap_key ); |
|
| 1103 | + $this->_init_caps($cap_key); |
|
| 1104 | 1104 | } |
| 1105 | 1105 | } |
| 1106 | 1106 | |
@@ -1118,11 +1118,11 @@ discard block |
||
| 1118 | 1118 | * @param int $user_id User ID. |
| 1119 | 1119 | * @return array Actual capabilities for meta capability. |
| 1120 | 1120 | */ |
| 1121 | -function map_meta_cap( $cap, $user_id ) { |
|
| 1122 | - $args = array_slice( func_get_args(), 2 ); |
|
| 1121 | +function map_meta_cap($cap, $user_id) { |
|
| 1122 | + $args = array_slice(func_get_args(), 2); |
|
| 1123 | 1123 | $caps = array(); |
| 1124 | 1124 | |
| 1125 | - switch ( $cap ) { |
|
| 1125 | + switch ($cap) { |
|
| 1126 | 1126 | case 'remove_user': |
| 1127 | 1127 | $caps[] = 'remove_users'; |
| 1128 | 1128 | break; |
@@ -1132,40 +1132,40 @@ discard block |
||
| 1132 | 1132 | case 'edit_user': |
| 1133 | 1133 | case 'edit_users': |
| 1134 | 1134 | // Allow user to edit itself |
| 1135 | - if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) |
|
| 1135 | + if ('edit_user' == $cap && isset($args[0]) && $user_id == $args[0]) |
|
| 1136 | 1136 | break; |
| 1137 | 1137 | |
| 1138 | 1138 | // If multisite these caps are allowed only for super admins. |
| 1139 | - if ( is_multisite() && !is_super_admin( $user_id ) ) |
|
| 1139 | + if (is_multisite() && ! is_super_admin($user_id)) |
|
| 1140 | 1140 | $caps[] = 'do_not_allow'; |
| 1141 | 1141 | else |
| 1142 | 1142 | $caps[] = 'edit_users'; // edit_user maps to edit_users. |
| 1143 | 1143 | break; |
| 1144 | 1144 | case 'delete_post': |
| 1145 | 1145 | case 'delete_page': |
| 1146 | - $post = get_post( $args[0] ); |
|
| 1146 | + $post = get_post($args[0]); |
|
| 1147 | 1147 | |
| 1148 | - if ( 'revision' == $post->post_type ) { |
|
| 1149 | - $post = get_post( $post->post_parent ); |
|
| 1148 | + if ('revision' == $post->post_type) { |
|
| 1149 | + $post = get_post($post->post_parent); |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 1152 | + $post_type = get_post_type_object($post->post_type); |
|
| 1153 | 1153 | |
| 1154 | - if ( ! $post_type->map_meta_cap ) { |
|
| 1154 | + if ( ! $post_type->map_meta_cap) { |
|
| 1155 | 1155 | $caps[] = $post_type->cap->$cap; |
| 1156 | 1156 | // Prior to 3.1 we would re-call map_meta_cap here. |
| 1157 | - if ( 'delete_post' == $cap ) |
|
| 1157 | + if ('delete_post' == $cap) |
|
| 1158 | 1158 | $cap = $post_type->cap->$cap; |
| 1159 | 1159 | break; |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | // If the post author is set and the user is the author... |
| 1163 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
| 1163 | + if ($post->post_author && $user_id == $post->post_author) { |
|
| 1164 | 1164 | // If the post is published... |
| 1165 | - if ( 'publish' == $post->post_status ) { |
|
| 1165 | + if ('publish' == $post->post_status) { |
|
| 1166 | 1166 | $caps[] = $post_type->cap->delete_published_posts; |
| 1167 | - } elseif ( 'trash' == $post->post_status ) { |
|
| 1168 | - if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) { |
|
| 1167 | + } elseif ('trash' == $post->post_status) { |
|
| 1168 | + if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true)) { |
|
| 1169 | 1169 | $caps[] = $post_type->cap->delete_published_posts; |
| 1170 | 1170 | } |
| 1171 | 1171 | } else { |
@@ -1176,9 +1176,9 @@ discard block |
||
| 1176 | 1176 | // The user is trying to edit someone else's post. |
| 1177 | 1177 | $caps[] = $post_type->cap->delete_others_posts; |
| 1178 | 1178 | // The post is published, extra cap required. |
| 1179 | - if ( 'publish' == $post->post_status ) { |
|
| 1179 | + if ('publish' == $post->post_status) { |
|
| 1180 | 1180 | $caps[] = $post_type->cap->delete_published_posts; |
| 1181 | - } elseif ( 'private' == $post->post_status ) { |
|
| 1181 | + } elseif ('private' == $post->post_status) { |
|
| 1182 | 1182 | $caps[] = $post_type->cap->delete_private_posts; |
| 1183 | 1183 | } |
| 1184 | 1184 | } |
@@ -1187,33 +1187,33 @@ discard block |
||
| 1187 | 1187 | // edit_others_posts |
| 1188 | 1188 | case 'edit_post': |
| 1189 | 1189 | case 'edit_page': |
| 1190 | - $post = get_post( $args[0] ); |
|
| 1191 | - if ( empty( $post ) ) { |
|
| 1190 | + $post = get_post($args[0]); |
|
| 1191 | + if (empty($post)) { |
|
| 1192 | 1192 | $caps[] = 'do_not_allow'; |
| 1193 | 1193 | break; |
| 1194 | 1194 | } |
| 1195 | 1195 | |
| 1196 | - if ( 'revision' == $post->post_type ) { |
|
| 1197 | - $post = get_post( $post->post_parent ); |
|
| 1196 | + if ('revision' == $post->post_type) { |
|
| 1197 | + $post = get_post($post->post_parent); |
|
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 1200 | + $post_type = get_post_type_object($post->post_type); |
|
| 1201 | 1201 | |
| 1202 | - if ( ! $post_type->map_meta_cap ) { |
|
| 1202 | + if ( ! $post_type->map_meta_cap) { |
|
| 1203 | 1203 | $caps[] = $post_type->cap->$cap; |
| 1204 | 1204 | // Prior to 3.1 we would re-call map_meta_cap here. |
| 1205 | - if ( 'edit_post' == $cap ) |
|
| 1205 | + if ('edit_post' == $cap) |
|
| 1206 | 1206 | $cap = $post_type->cap->$cap; |
| 1207 | 1207 | break; |
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | // If the post author is set and the user is the author... |
| 1211 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
| 1211 | + if ($post->post_author && $user_id == $post->post_author) { |
|
| 1212 | 1212 | // If the post is published... |
| 1213 | - if ( 'publish' == $post->post_status ) { |
|
| 1213 | + if ('publish' == $post->post_status) { |
|
| 1214 | 1214 | $caps[] = $post_type->cap->edit_published_posts; |
| 1215 | - } elseif ( 'trash' == $post->post_status ) { |
|
| 1216 | - if ( 'publish' == get_post_meta( $post->ID, '_wp_trash_meta_status', true ) ) { |
|
| 1215 | + } elseif ('trash' == $post->post_status) { |
|
| 1216 | + if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true)) { |
|
| 1217 | 1217 | $caps[] = $post_type->cap->edit_published_posts; |
| 1218 | 1218 | } |
| 1219 | 1219 | } else { |
@@ -1224,60 +1224,60 @@ discard block |
||
| 1224 | 1224 | // The user is trying to edit someone else's post. |
| 1225 | 1225 | $caps[] = $post_type->cap->edit_others_posts; |
| 1226 | 1226 | // The post is published, extra cap required. |
| 1227 | - if ( 'publish' == $post->post_status ) { |
|
| 1227 | + if ('publish' == $post->post_status) { |
|
| 1228 | 1228 | $caps[] = $post_type->cap->edit_published_posts; |
| 1229 | - } elseif ( 'private' == $post->post_status ) { |
|
| 1229 | + } elseif ('private' == $post->post_status) { |
|
| 1230 | 1230 | $caps[] = $post_type->cap->edit_private_posts; |
| 1231 | 1231 | } |
| 1232 | 1232 | } |
| 1233 | 1233 | break; |
| 1234 | 1234 | case 'read_post': |
| 1235 | 1235 | case 'read_page': |
| 1236 | - $post = get_post( $args[0] ); |
|
| 1236 | + $post = get_post($args[0]); |
|
| 1237 | 1237 | |
| 1238 | - if ( 'revision' == $post->post_type ) { |
|
| 1239 | - $post = get_post( $post->post_parent ); |
|
| 1238 | + if ('revision' == $post->post_type) { |
|
| 1239 | + $post = get_post($post->post_parent); |
|
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 1242 | + $post_type = get_post_type_object($post->post_type); |
|
| 1243 | 1243 | |
| 1244 | - if ( ! $post_type->map_meta_cap ) { |
|
| 1244 | + if ( ! $post_type->map_meta_cap) { |
|
| 1245 | 1245 | $caps[] = $post_type->cap->$cap; |
| 1246 | 1246 | // Prior to 3.1 we would re-call map_meta_cap here. |
| 1247 | - if ( 'read_post' == $cap ) |
|
| 1247 | + if ('read_post' == $cap) |
|
| 1248 | 1248 | $cap = $post_type->cap->$cap; |
| 1249 | 1249 | break; |
| 1250 | 1250 | } |
| 1251 | 1251 | |
| 1252 | - $status_obj = get_post_status_object( $post->post_status ); |
|
| 1253 | - if ( $status_obj->public ) { |
|
| 1252 | + $status_obj = get_post_status_object($post->post_status); |
|
| 1253 | + if ($status_obj->public) { |
|
| 1254 | 1254 | $caps[] = $post_type->cap->read; |
| 1255 | 1255 | break; |
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | - if ( $post->post_author && $user_id == $post->post_author ) { |
|
| 1258 | + if ($post->post_author && $user_id == $post->post_author) { |
|
| 1259 | 1259 | $caps[] = $post_type->cap->read; |
| 1260 | - } elseif ( $status_obj->private ) { |
|
| 1260 | + } elseif ($status_obj->private) { |
|
| 1261 | 1261 | $caps[] = $post_type->cap->read_private_posts; |
| 1262 | 1262 | } else { |
| 1263 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
| 1263 | + $caps = map_meta_cap('edit_post', $user_id, $post->ID); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | break; |
| 1266 | 1266 | case 'publish_post': |
| 1267 | - $post = get_post( $args[0] ); |
|
| 1268 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 1267 | + $post = get_post($args[0]); |
|
| 1268 | + $post_type = get_post_type_object($post->post_type); |
|
| 1269 | 1269 | |
| 1270 | 1270 | $caps[] = $post_type->cap->publish_posts; |
| 1271 | 1271 | break; |
| 1272 | 1272 | case 'edit_post_meta': |
| 1273 | 1273 | case 'delete_post_meta': |
| 1274 | 1274 | case 'add_post_meta': |
| 1275 | - $post = get_post( $args[0] ); |
|
| 1276 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
| 1275 | + $post = get_post($args[0]); |
|
| 1276 | + $caps = map_meta_cap('edit_post', $user_id, $post->ID); |
|
| 1277 | 1277 | |
| 1278 | - $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; |
|
| 1278 | + $meta_key = isset($args[1]) ? $args[1] : false; |
|
| 1279 | 1279 | |
| 1280 | - if ( $meta_key && has_filter( "auth_post_meta_{$meta_key}" ) ) { |
|
| 1280 | + if ($meta_key && has_filter("auth_post_meta_{$meta_key}")) { |
|
| 1281 | 1281 | /** |
| 1282 | 1282 | * Filter whether the user is allowed to add post meta to a post. |
| 1283 | 1283 | * |
@@ -1293,40 +1293,40 @@ discard block |
||
| 1293 | 1293 | * @param string $cap Capability name. |
| 1294 | 1294 | * @param array $caps User capabilities. |
| 1295 | 1295 | */ |
| 1296 | - $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps ); |
|
| 1297 | - if ( ! $allowed ) |
|
| 1296 | + $allowed = apply_filters("auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps); |
|
| 1297 | + if ( ! $allowed) |
|
| 1298 | 1298 | $caps[] = $cap; |
| 1299 | - } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) { |
|
| 1299 | + } elseif ($meta_key && is_protected_meta($meta_key, 'post')) { |
|
| 1300 | 1300 | $caps[] = $cap; |
| 1301 | 1301 | } |
| 1302 | 1302 | break; |
| 1303 | 1303 | case 'edit_comment': |
| 1304 | - $comment = get_comment( $args[0] ); |
|
| 1305 | - if ( empty( $comment ) ) |
|
| 1304 | + $comment = get_comment($args[0]); |
|
| 1305 | + if (empty($comment)) |
|
| 1306 | 1306 | break; |
| 1307 | - $post = get_post( $comment->comment_post_ID ); |
|
| 1307 | + $post = get_post($comment->comment_post_ID); |
|
| 1308 | 1308 | |
| 1309 | 1309 | /* |
| 1310 | 1310 | * If the post doesn't exist, we have an orphaned comment. |
| 1311 | 1311 | * Fall back to the edit_posts capability, instead. |
| 1312 | 1312 | */ |
| 1313 | - if ( $post ) { |
|
| 1314 | - $caps = map_meta_cap( 'edit_post', $user_id, $post->ID ); |
|
| 1313 | + if ($post) { |
|
| 1314 | + $caps = map_meta_cap('edit_post', $user_id, $post->ID); |
|
| 1315 | 1315 | } else { |
| 1316 | - $caps = map_meta_cap( 'edit_posts', $user_id ); |
|
| 1316 | + $caps = map_meta_cap('edit_posts', $user_id); |
|
| 1317 | 1317 | } |
| 1318 | 1318 | break; |
| 1319 | 1319 | case 'unfiltered_upload': |
| 1320 | - if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) |
|
| 1320 | + if (defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( ! is_multisite() || is_super_admin($user_id))) |
|
| 1321 | 1321 | $caps[] = $cap; |
| 1322 | 1322 | else |
| 1323 | 1323 | $caps[] = 'do_not_allow'; |
| 1324 | 1324 | break; |
| 1325 | 1325 | case 'unfiltered_html' : |
| 1326 | 1326 | // Disallow unfiltered_html for all users, even admins and super admins. |
| 1327 | - if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) |
|
| 1327 | + if (defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML) |
|
| 1328 | 1328 | $caps[] = 'do_not_allow'; |
| 1329 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1329 | + elseif (is_multisite() && ! is_super_admin($user_id)) |
|
| 1330 | 1330 | $caps[] = 'do_not_allow'; |
| 1331 | 1331 | else |
| 1332 | 1332 | $caps[] = $cap; |
@@ -1335,11 +1335,11 @@ discard block |
||
| 1335 | 1335 | case 'edit_plugins': |
| 1336 | 1336 | case 'edit_themes': |
| 1337 | 1337 | // Disallow the file editors. |
| 1338 | - if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) |
|
| 1338 | + if (defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) |
|
| 1339 | 1339 | $caps[] = 'do_not_allow'; |
| 1340 | - elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) |
|
| 1340 | + elseif (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) |
|
| 1341 | 1341 | $caps[] = 'do_not_allow'; |
| 1342 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1342 | + elseif (is_multisite() && ! is_super_admin($user_id)) |
|
| 1343 | 1343 | $caps[] = 'do_not_allow'; |
| 1344 | 1344 | else |
| 1345 | 1345 | $caps[] = $cap; |
@@ -1355,13 +1355,13 @@ discard block |
||
| 1355 | 1355 | case 'update_core': |
| 1356 | 1356 | // Disallow anything that creates, deletes, or updates core, plugin, or theme files. |
| 1357 | 1357 | // Files in uploads are excepted. |
| 1358 | - if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
|
| 1358 | + if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { |
|
| 1359 | 1359 | $caps[] = 'do_not_allow'; |
| 1360 | - } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
| 1360 | + } elseif (is_multisite() && ! is_super_admin($user_id)) { |
|
| 1361 | 1361 | $caps[] = 'do_not_allow'; |
| 1362 | - } elseif ( 'upload_themes' === $cap ) { |
|
| 1362 | + } elseif ('upload_themes' === $cap) { |
|
| 1363 | 1363 | $caps[] = 'install_themes'; |
| 1364 | - } elseif ( 'upload_plugins' === $cap ) { |
|
| 1364 | + } elseif ('upload_plugins' === $cap) { |
|
| 1365 | 1365 | $caps[] = 'install_plugins'; |
| 1366 | 1366 | } else { |
| 1367 | 1367 | $caps[] = $cap; |
@@ -1369,31 +1369,31 @@ discard block |
||
| 1369 | 1369 | break; |
| 1370 | 1370 | case 'activate_plugins': |
| 1371 | 1371 | $caps[] = $cap; |
| 1372 | - if ( is_multisite() ) { |
|
| 1372 | + if (is_multisite()) { |
|
| 1373 | 1373 | // update_, install_, and delete_ are handled above with is_super_admin(). |
| 1374 | - $menu_perms = get_site_option( 'menu_items', array() ); |
|
| 1375 | - if ( empty( $menu_perms['plugins'] ) ) |
|
| 1374 | + $menu_perms = get_site_option('menu_items', array()); |
|
| 1375 | + if (empty($menu_perms['plugins'])) |
|
| 1376 | 1376 | $caps[] = 'manage_network_plugins'; |
| 1377 | 1377 | } |
| 1378 | 1378 | break; |
| 1379 | 1379 | case 'delete_user': |
| 1380 | 1380 | case 'delete_users': |
| 1381 | 1381 | // If multisite only super admins can delete users. |
| 1382 | - if ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1382 | + if (is_multisite() && ! is_super_admin($user_id)) |
|
| 1383 | 1383 | $caps[] = 'do_not_allow'; |
| 1384 | 1384 | else |
| 1385 | 1385 | $caps[] = 'delete_users'; // delete_user maps to delete_users. |
| 1386 | 1386 | break; |
| 1387 | 1387 | case 'create_users': |
| 1388 | - if ( !is_multisite() ) |
|
| 1388 | + if ( ! is_multisite()) |
|
| 1389 | 1389 | $caps[] = $cap; |
| 1390 | - elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) |
|
| 1390 | + elseif (is_super_admin($user_id) || get_site_option('add_new_users')) |
|
| 1391 | 1391 | $caps[] = $cap; |
| 1392 | 1392 | else |
| 1393 | 1393 | $caps[] = 'do_not_allow'; |
| 1394 | 1394 | break; |
| 1395 | 1395 | case 'manage_links' : |
| 1396 | - if ( get_option( 'link_manager_enabled' ) ) |
|
| 1396 | + if (get_option('link_manager_enabled')) |
|
| 1397 | 1397 | $caps[] = $cap; |
| 1398 | 1398 | else |
| 1399 | 1399 | $caps[] = 'do_not_allow'; |
@@ -1407,9 +1407,9 @@ discard block |
||
| 1407 | 1407 | default: |
| 1408 | 1408 | // Handle meta capabilities for custom post types. |
| 1409 | 1409 | $post_type_meta_caps = _post_type_meta_capabilities(); |
| 1410 | - if ( isset( $post_type_meta_caps[ $cap ] ) ) { |
|
| 1411 | - $args = array_merge( array( $post_type_meta_caps[ $cap ], $user_id ), $args ); |
|
| 1412 | - return call_user_func_array( 'map_meta_cap', $args ); |
|
| 1410 | + if (isset($post_type_meta_caps[$cap])) { |
|
| 1411 | + $args = array_merge(array($post_type_meta_caps[$cap], $user_id), $args); |
|
| 1412 | + return call_user_func_array('map_meta_cap', $args); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | 1415 | // If no meta caps match, return the original cap. |
@@ -1426,7 +1426,7 @@ discard block |
||
| 1426 | 1426 | * @param int $user_id The user ID. |
| 1427 | 1427 | * @param array $args Adds the context to the cap. Typically the object ID. |
| 1428 | 1428 | */ |
| 1429 | - return apply_filters( 'map_meta_cap', $caps, $cap, $user_id, $args ); |
|
| 1429 | + return apply_filters('map_meta_cap', $caps, $cap, $user_id, $args); |
|
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | /** |
@@ -1437,16 +1437,16 @@ discard block |
||
| 1437 | 1437 | * @param string $capability Capability or role name. |
| 1438 | 1438 | * @return bool |
| 1439 | 1439 | */ |
| 1440 | -function current_user_can( $capability ) { |
|
| 1440 | +function current_user_can($capability) { |
|
| 1441 | 1441 | $current_user = wp_get_current_user(); |
| 1442 | 1442 | |
| 1443 | - if ( empty( $current_user ) ) |
|
| 1443 | + if (empty($current_user)) |
|
| 1444 | 1444 | return false; |
| 1445 | 1445 | |
| 1446 | - $args = array_slice( func_get_args(), 1 ); |
|
| 1447 | - $args = array_merge( array( $capability ), $args ); |
|
| 1446 | + $args = array_slice(func_get_args(), 1); |
|
| 1447 | + $args = array_merge(array($capability), $args); |
|
| 1448 | 1448 | |
| 1449 | - return call_user_func_array( array( $current_user, 'has_cap' ), $args ); |
|
| 1449 | + return call_user_func_array(array($current_user, 'has_cap'), $args); |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | /** |
@@ -1458,24 +1458,24 @@ discard block |
||
| 1458 | 1458 | * @param string $capability Capability or role name. |
| 1459 | 1459 | * @return bool |
| 1460 | 1460 | */ |
| 1461 | -function current_user_can_for_blog( $blog_id, $capability ) { |
|
| 1462 | - $switched = is_multisite() ? switch_to_blog( $blog_id ) : false; |
|
| 1461 | +function current_user_can_for_blog($blog_id, $capability) { |
|
| 1462 | + $switched = is_multisite() ? switch_to_blog($blog_id) : false; |
|
| 1463 | 1463 | |
| 1464 | 1464 | $current_user = wp_get_current_user(); |
| 1465 | 1465 | |
| 1466 | - if ( empty( $current_user ) ) { |
|
| 1467 | - if ( $switched ) { |
|
| 1466 | + if (empty($current_user)) { |
|
| 1467 | + if ($switched) { |
|
| 1468 | 1468 | restore_current_blog(); |
| 1469 | 1469 | } |
| 1470 | 1470 | return false; |
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | - $args = array_slice( func_get_args(), 2 ); |
|
| 1474 | - $args = array_merge( array( $capability ), $args ); |
|
| 1473 | + $args = array_slice(func_get_args(), 2); |
|
| 1474 | + $args = array_merge(array($capability), $args); |
|
| 1475 | 1475 | |
| 1476 | - $can = call_user_func_array( array( $current_user, 'has_cap' ), $args ); |
|
| 1476 | + $can = call_user_func_array(array($current_user, 'has_cap'), $args); |
|
| 1477 | 1477 | |
| 1478 | - if ( $switched ) { |
|
| 1478 | + if ($switched) { |
|
| 1479 | 1479 | restore_current_blog(); |
| 1480 | 1480 | } |
| 1481 | 1481 | |
@@ -1491,19 +1491,19 @@ discard block |
||
| 1491 | 1491 | * @param string $capability Capability or role name. |
| 1492 | 1492 | * @return bool |
| 1493 | 1493 | */ |
| 1494 | -function author_can( $post, $capability ) { |
|
| 1495 | - if ( !$post = get_post($post) ) |
|
| 1494 | +function author_can($post, $capability) { |
|
| 1495 | + if ( ! $post = get_post($post)) |
|
| 1496 | 1496 | return false; |
| 1497 | 1497 | |
| 1498 | - $author = get_userdata( $post->post_author ); |
|
| 1498 | + $author = get_userdata($post->post_author); |
|
| 1499 | 1499 | |
| 1500 | - if ( ! $author ) |
|
| 1500 | + if ( ! $author) |
|
| 1501 | 1501 | return false; |
| 1502 | 1502 | |
| 1503 | - $args = array_slice( func_get_args(), 2 ); |
|
| 1504 | - $args = array_merge( array( $capability ), $args ); |
|
| 1503 | + $args = array_slice(func_get_args(), 2); |
|
| 1504 | + $args = array_merge(array($capability), $args); |
|
| 1505 | 1505 | |
| 1506 | - return call_user_func_array( array( $author, 'has_cap' ), $args ); |
|
| 1506 | + return call_user_func_array(array($author, 'has_cap'), $args); |
|
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | /** |
@@ -1515,17 +1515,17 @@ discard block |
||
| 1515 | 1515 | * @param string $capability Capability or role name. |
| 1516 | 1516 | * @return bool |
| 1517 | 1517 | */ |
| 1518 | -function user_can( $user, $capability ) { |
|
| 1519 | - if ( ! is_object( $user ) ) |
|
| 1520 | - $user = get_userdata( $user ); |
|
| 1518 | +function user_can($user, $capability) { |
|
| 1519 | + if ( ! is_object($user)) |
|
| 1520 | + $user = get_userdata($user); |
|
| 1521 | 1521 | |
| 1522 | - if ( ! $user || ! $user->exists() ) |
|
| 1522 | + if ( ! $user || ! $user->exists()) |
|
| 1523 | 1523 | return false; |
| 1524 | 1524 | |
| 1525 | - $args = array_slice( func_get_args(), 2 ); |
|
| 1526 | - $args = array_merge( array( $capability ), $args ); |
|
| 1525 | + $args = array_slice(func_get_args(), 2); |
|
| 1526 | + $args = array_merge(array($capability), $args); |
|
| 1527 | 1527 | |
| 1528 | - return call_user_func_array( array( $user, 'has_cap' ), $args ); |
|
| 1528 | + return call_user_func_array(array($user, 'has_cap'), $args); |
|
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | /** |
@@ -1540,7 +1540,7 @@ discard block |
||
| 1540 | 1540 | function wp_roles() { |
| 1541 | 1541 | global $wp_roles; |
| 1542 | 1542 | |
| 1543 | - if ( ! isset( $wp_roles ) ) { |
|
| 1543 | + if ( ! isset($wp_roles)) { |
|
| 1544 | 1544 | $wp_roles = new WP_Roles(); |
| 1545 | 1545 | } |
| 1546 | 1546 | return $wp_roles; |
@@ -1554,8 +1554,8 @@ discard block |
||
| 1554 | 1554 | * @param string $role Role name. |
| 1555 | 1555 | * @return WP_Role|null WP_Role object if found, null if the role does not exist. |
| 1556 | 1556 | */ |
| 1557 | -function get_role( $role ) { |
|
| 1558 | - return wp_roles()->get_role( $role ); |
|
| 1557 | +function get_role($role) { |
|
| 1558 | + return wp_roles()->get_role($role); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | /** |
@@ -1568,8 +1568,8 @@ discard block |
||
| 1568 | 1568 | * @param array $capabilities List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false ); |
| 1569 | 1569 | * @return WP_Role|null WP_Role object if role is added, null if already exists. |
| 1570 | 1570 | */ |
| 1571 | -function add_role( $role, $display_name, $capabilities = array() ) { |
|
| 1572 | - return wp_roles()->add_role( $role, $display_name, $capabilities ); |
|
| 1571 | +function add_role($role, $display_name, $capabilities = array()) { |
|
| 1572 | + return wp_roles()->add_role($role, $display_name, $capabilities); |
|
| 1573 | 1573 | } |
| 1574 | 1574 | |
| 1575 | 1575 | /** |
@@ -1579,8 +1579,8 @@ discard block |
||
| 1579 | 1579 | * |
| 1580 | 1580 | * @param string $role Role name. |
| 1581 | 1581 | */ |
| 1582 | -function remove_role( $role ) { |
|
| 1583 | - wp_roles()->remove_role( $role ); |
|
| 1582 | +function remove_role($role) { |
|
| 1583 | + wp_roles()->remove_role($role); |
|
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | 1586 | /** |
@@ -1595,10 +1595,10 @@ discard block |
||
| 1595 | 1595 | function get_super_admins() { |
| 1596 | 1596 | global $super_admins; |
| 1597 | 1597 | |
| 1598 | - if ( isset($super_admins) ) |
|
| 1598 | + if (isset($super_admins)) |
|
| 1599 | 1599 | return $super_admins; |
| 1600 | 1600 | else |
| 1601 | - return get_site_option( 'site_admins', array('admin') ); |
|
| 1601 | + return get_site_option('site_admins', array('admin')); |
|
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | 1604 | /** |
@@ -1609,21 +1609,21 @@ discard block |
||
| 1609 | 1609 | * @param int $user_id (Optional) The ID of a user. Defaults to the current user. |
| 1610 | 1610 | * @return bool True if the user is a site admin. |
| 1611 | 1611 | */ |
| 1612 | -function is_super_admin( $user_id = false ) { |
|
| 1613 | - if ( ! $user_id || $user_id == get_current_user_id() ) |
|
| 1612 | +function is_super_admin($user_id = false) { |
|
| 1613 | + if ( ! $user_id || $user_id == get_current_user_id()) |
|
| 1614 | 1614 | $user = wp_get_current_user(); |
| 1615 | 1615 | else |
| 1616 | - $user = get_userdata( $user_id ); |
|
| 1616 | + $user = get_userdata($user_id); |
|
| 1617 | 1617 | |
| 1618 | - if ( ! $user || ! $user->exists() ) |
|
| 1618 | + if ( ! $user || ! $user->exists()) |
|
| 1619 | 1619 | return false; |
| 1620 | 1620 | |
| 1621 | - if ( is_multisite() ) { |
|
| 1621 | + if (is_multisite()) { |
|
| 1622 | 1622 | $super_admins = get_super_admins(); |
| 1623 | - if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) ) |
|
| 1623 | + if (is_array($super_admins) && in_array($user->user_login, $super_admins)) |
|
| 1624 | 1624 | return true; |
| 1625 | 1625 | } else { |
| 1626 | - if ( $user->has_cap('delete_users') ) |
|
| 1626 | + if ($user->has_cap('delete_users')) |
|
| 1627 | 1627 | return true; |
| 1628 | 1628 | } |
| 1629 | 1629 | |
@@ -119,8 +119,9 @@ discard block |
||
| 119 | 119 | $this->roles = get_option( $this->role_key ); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if ( empty( $this->roles ) ) |
|
| 123 | - return; |
|
| 122 | + if ( empty( $this->roles ) ) { |
|
| 123 | + return; |
|
| 124 | + } |
|
| 124 | 125 | |
| 125 | 126 | $this->role_objects = array(); |
| 126 | 127 | $this->role_names = array(); |
@@ -143,16 +144,18 @@ discard block |
||
| 143 | 144 | */ |
| 144 | 145 | public function reinit() { |
| 145 | 146 | // There is no need to reinit if using the wp_user_roles global. |
| 146 | - if ( ! $this->use_db ) |
|
| 147 | - return; |
|
| 147 | + if ( ! $this->use_db ) { |
|
| 148 | + return; |
|
| 149 | + } |
|
| 148 | 150 | |
| 149 | 151 | global $wpdb; |
| 150 | 152 | |
| 151 | 153 | // Duplicated from _init() to avoid an extra function call. |
| 152 | 154 | $this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; |
| 153 | 155 | $this->roles = get_option( $this->role_key ); |
| 154 | - if ( empty( $this->roles ) ) |
|
| 155 | - return; |
|
| 156 | + if ( empty( $this->roles ) ) { |
|
| 157 | + return; |
|
| 158 | + } |
|
| 156 | 159 | |
| 157 | 160 | $this->role_objects = array(); |
| 158 | 161 | $this->role_names = array(); |
@@ -179,15 +182,17 @@ discard block |
||
| 179 | 182 | * @return WP_Role|void WP_Role object, if role is added. |
| 180 | 183 | */ |
| 181 | 184 | public function add_role( $role, $display_name, $capabilities = array() ) { |
| 182 | - if ( isset( $this->roles[$role] ) ) |
|
| 183 | - return; |
|
| 185 | + if ( isset( $this->roles[$role] ) ) { |
|
| 186 | + return; |
|
| 187 | + } |
|
| 184 | 188 | |
| 185 | 189 | $this->roles[$role] = array( |
| 186 | 190 | 'name' => $display_name, |
| 187 | 191 | 'capabilities' => $capabilities |
| 188 | 192 | ); |
| 189 | - if ( $this->use_db ) |
|
| 190 | - update_option( $this->role_key, $this->roles ); |
|
| 193 | + if ( $this->use_db ) { |
|
| 194 | + update_option( $this->role_key, $this->roles ); |
|
| 195 | + } |
|
| 191 | 196 | $this->role_objects[$role] = new WP_Role( $role, $capabilities ); |
| 192 | 197 | $this->role_names[$role] = $display_name; |
| 193 | 198 | return $this->role_objects[$role]; |
@@ -202,18 +207,21 @@ discard block |
||
| 202 | 207 | * @param string $role Role name. |
| 203 | 208 | */ |
| 204 | 209 | public function remove_role( $role ) { |
| 205 | - if ( ! isset( $this->role_objects[$role] ) ) |
|
| 206 | - return; |
|
| 210 | + if ( ! isset( $this->role_objects[$role] ) ) { |
|
| 211 | + return; |
|
| 212 | + } |
|
| 207 | 213 | |
| 208 | 214 | unset( $this->role_objects[$role] ); |
| 209 | 215 | unset( $this->role_names[$role] ); |
| 210 | 216 | unset( $this->roles[$role] ); |
| 211 | 217 | |
| 212 | - if ( $this->use_db ) |
|
| 213 | - update_option( $this->role_key, $this->roles ); |
|
| 218 | + if ( $this->use_db ) { |
|
| 219 | + update_option( $this->role_key, $this->roles ); |
|
| 220 | + } |
|
| 214 | 221 | |
| 215 | - if ( get_option( 'default_role' ) == $role ) |
|
| 216 | - update_option( 'default_role', 'subscriber' ); |
|
| 222 | + if ( get_option( 'default_role' ) == $role ) { |
|
| 223 | + update_option( 'default_role', 'subscriber' ); |
|
| 224 | + } |
|
| 217 | 225 | } |
| 218 | 226 | |
| 219 | 227 | /** |
@@ -227,12 +235,14 @@ discard block |
||
| 227 | 235 | * @param bool $grant Optional, default is true. Whether role is capable of performing capability. |
| 228 | 236 | */ |
| 229 | 237 | public function add_cap( $role, $cap, $grant = true ) { |
| 230 | - if ( ! isset( $this->roles[$role] ) ) |
|
| 231 | - return; |
|
| 238 | + if ( ! isset( $this->roles[$role] ) ) { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 232 | 241 | |
| 233 | 242 | $this->roles[$role]['capabilities'][$cap] = $grant; |
| 234 | - if ( $this->use_db ) |
|
| 235 | - update_option( $this->role_key, $this->roles ); |
|
| 243 | + if ( $this->use_db ) { |
|
| 244 | + update_option( $this->role_key, $this->roles ); |
|
| 245 | + } |
|
| 236 | 246 | } |
| 237 | 247 | |
| 238 | 248 | /** |
@@ -245,12 +255,14 @@ discard block |
||
| 245 | 255 | * @param string $cap Capability name. |
| 246 | 256 | */ |
| 247 | 257 | public function remove_cap( $role, $cap ) { |
| 248 | - if ( ! isset( $this->roles[$role] ) ) |
|
| 249 | - return; |
|
| 258 | + if ( ! isset( $this->roles[$role] ) ) { |
|
| 259 | + return; |
|
| 260 | + } |
|
| 250 | 261 | |
| 251 | 262 | unset( $this->roles[$role]['capabilities'][$cap] ); |
| 252 | - if ( $this->use_db ) |
|
| 253 | - update_option( $this->role_key, $this->roles ); |
|
| 263 | + if ( $this->use_db ) { |
|
| 264 | + update_option( $this->role_key, $this->roles ); |
|
| 265 | + } |
|
| 254 | 266 | } |
| 255 | 267 | |
| 256 | 268 | /** |
@@ -263,10 +275,11 @@ discard block |
||
| 263 | 275 | * @return WP_Role|null WP_Role object if found, null if the role does not exist. |
| 264 | 276 | */ |
| 265 | 277 | public function get_role( $role ) { |
| 266 | - if ( isset( $this->role_objects[$role] ) ) |
|
| 267 | - return $this->role_objects[$role]; |
|
| 268 | - else |
|
| 269 | - return null; |
|
| 278 | + if ( isset( $this->role_objects[$role] ) ) { |
|
| 279 | + return $this->role_objects[$role]; |
|
| 280 | + } else { |
|
| 281 | + return null; |
|
| 282 | + } |
|
| 270 | 283 | } |
| 271 | 284 | |
| 272 | 285 | /** |
@@ -395,10 +408,11 @@ discard block |
||
| 395 | 408 | * @param string $name Role name. |
| 396 | 409 | */ |
| 397 | 410 | $capabilities = apply_filters( 'role_has_cap', $this->capabilities, $cap, $this->name ); |
| 398 | - if ( !empty( $capabilities[$cap] ) ) |
|
| 399 | - return $capabilities[$cap]; |
|
| 400 | - else |
|
| 401 | - return false; |
|
| 411 | + if ( !empty( $capabilities[$cap] ) ) { |
|
| 412 | + return $capabilities[$cap]; |
|
| 413 | + } else { |
|
| 414 | + return false; |
|
| 415 | + } |
|
| 402 | 416 | } |
| 403 | 417 | |
| 404 | 418 | } |
@@ -581,17 +595,20 @@ discard block |
||
| 581 | 595 | if ( 'id' == $field ) { |
| 582 | 596 | // Make sure the value is numeric to avoid casting objects, for example, |
| 583 | 597 | // to int 1. |
| 584 | - if ( ! is_numeric( $value ) ) |
|
| 585 | - return false; |
|
| 598 | + if ( ! is_numeric( $value ) ) { |
|
| 599 | + return false; |
|
| 600 | + } |
|
| 586 | 601 | $value = intval( $value ); |
| 587 | - if ( $value < 1 ) |
|
| 588 | - return false; |
|
| 602 | + if ( $value < 1 ) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 589 | 605 | } else { |
| 590 | 606 | $value = trim( $value ); |
| 591 | 607 | } |
| 592 | 608 | |
| 593 | - if ( !$value ) |
|
| 594 | - return false; |
|
| 609 | + if ( !$value ) { |
|
| 610 | + return false; |
|
| 611 | + } |
|
| 595 | 612 | |
| 596 | 613 | switch ( $field ) { |
| 597 | 614 | case 'id': |
@@ -616,14 +633,16 @@ discard block |
||
| 616 | 633 | } |
| 617 | 634 | |
| 618 | 635 | if ( false !== $user_id ) { |
| 619 | - if ( $user = wp_cache_get( $user_id, 'users' ) ) |
|
| 620 | - return $user; |
|
| 636 | + if ( $user = wp_cache_get( $user_id, 'users' ) ) { |
|
| 637 | + return $user; |
|
| 638 | + } |
|
| 621 | 639 | } |
| 622 | 640 | |
| 623 | 641 | if ( !$user = $wpdb->get_row( $wpdb->prepare( |
| 624 | 642 | "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value |
| 625 | - ) ) ) |
|
| 626 | - return false; |
|
| 643 | + ) ) ) { |
|
| 644 | + return false; |
|
| 645 | + } |
|
| 627 | 646 | |
| 628 | 647 | update_user_caches( $user ); |
| 629 | 648 | |
@@ -660,11 +679,13 @@ discard block |
||
| 660 | 679 | $key = 'ID'; |
| 661 | 680 | } |
| 662 | 681 | |
| 663 | - if ( isset( $this->data->$key ) ) |
|
| 664 | - return true; |
|
| 682 | + if ( isset( $this->data->$key ) ) { |
|
| 683 | + return true; |
|
| 684 | + } |
|
| 665 | 685 | |
| 666 | - if ( isset( self::$back_compat_keys[ $key ] ) ) |
|
| 667 | - $key = self::$back_compat_keys[ $key ]; |
|
| 686 | + if ( isset( self::$back_compat_keys[ $key ] ) ) { |
|
| 687 | + $key = self::$back_compat_keys[ $key ]; |
|
| 688 | + } |
|
| 668 | 689 | |
| 669 | 690 | return metadata_exists( 'user', $this->ID, $key ); |
| 670 | 691 | } |
@@ -685,8 +706,9 @@ discard block |
||
| 685 | 706 | if ( isset( $this->data->$key ) ) { |
| 686 | 707 | $value = $this->data->$key; |
| 687 | 708 | } else { |
| 688 | - if ( isset( self::$back_compat_keys[ $key ] ) ) |
|
| 689 | - $key = self::$back_compat_keys[ $key ]; |
|
| 709 | + if ( isset( self::$back_compat_keys[ $key ] ) ) { |
|
| 710 | + $key = self::$back_compat_keys[ $key ]; |
|
| 711 | + } |
|
| 690 | 712 | $value = get_user_meta( $this->ID, $key, true ); |
| 691 | 713 | } |
| 692 | 714 | |
@@ -781,15 +803,17 @@ discard block |
||
| 781 | 803 | protected function _init_caps( $cap_key = '' ) { |
| 782 | 804 | global $wpdb; |
| 783 | 805 | |
| 784 | - if ( empty($cap_key) ) |
|
| 785 | - $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; |
|
| 786 | - else |
|
| 787 | - $this->cap_key = $cap_key; |
|
| 806 | + if ( empty($cap_key) ) { |
|
| 807 | + $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; |
|
| 808 | + } else { |
|
| 809 | + $this->cap_key = $cap_key; |
|
| 810 | + } |
|
| 788 | 811 | |
| 789 | 812 | $this->caps = get_user_meta( $this->ID, $this->cap_key, true ); |
| 790 | 813 | |
| 791 | - if ( ! is_array( $this->caps ) ) |
|
| 792 | - $this->caps = array(); |
|
| 814 | + if ( ! is_array( $this->caps ) ) { |
|
| 815 | + $this->caps = array(); |
|
| 816 | + } |
|
| 793 | 817 | |
| 794 | 818 | $this->get_role_caps(); |
| 795 | 819 | } |
@@ -811,8 +835,9 @@ discard block |
||
| 811 | 835 | $wp_roles = wp_roles(); |
| 812 | 836 | |
| 813 | 837 | //Filter out caps that are not role names and assign to $this->roles |
| 814 | - if ( is_array( $this->caps ) ) |
|
| 815 | - $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) ); |
|
| 838 | + if ( is_array( $this->caps ) ) { |
|
| 839 | + $this->roles = array_filter( array_keys( $this->caps ), array( $wp_roles, 'is_role' ) ); |
|
| 840 | + } |
|
| 816 | 841 | |
| 817 | 842 | //Build $allcaps from role caps, overlay user's $caps |
| 818 | 843 | $this->allcaps = array(); |
@@ -861,8 +886,9 @@ discard block |
||
| 861 | 886 | * @param string $role Role name. |
| 862 | 887 | */ |
| 863 | 888 | public function remove_role( $role ) { |
| 864 | - if ( !in_array($role, $this->roles) ) |
|
| 865 | - return; |
|
| 889 | + if ( !in_array($role, $this->roles) ) { |
|
| 890 | + return; |
|
| 891 | + } |
|
| 866 | 892 | unset( $this->caps[$role] ); |
| 867 | 893 | update_user_meta( $this->ID, $this->cap_key, $this->caps ); |
| 868 | 894 | $this->get_role_caps(); |
@@ -892,11 +918,13 @@ discard block |
||
| 892 | 918 | * @param string $role Role name. |
| 893 | 919 | */ |
| 894 | 920 | public function set_role( $role ) { |
| 895 | - if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) |
|
| 896 | - return; |
|
| 921 | + if ( 1 == count( $this->roles ) && $role == current( $this->roles ) ) { |
|
| 922 | + return; |
|
| 923 | + } |
|
| 897 | 924 | |
| 898 | - foreach ( (array) $this->roles as $oldrole ) |
|
| 899 | - unset( $this->caps[$oldrole] ); |
|
| 925 | + foreach ( (array) $this->roles as $oldrole ) { |
|
| 926 | + unset( $this->caps[$oldrole] ); |
|
| 927 | + } |
|
| 900 | 928 | |
| 901 | 929 | $old_roles = $this->roles; |
| 902 | 930 | if ( !empty( $role ) ) { |
@@ -1043,8 +1071,9 @@ discard block |
||
| 1043 | 1071 | |
| 1044 | 1072 | // Multisite super admin has all caps by definition, Unless specifically denied. |
| 1045 | 1073 | if ( is_multisite() && is_super_admin( $this->ID ) ) { |
| 1046 | - if ( in_array('do_not_allow', $caps) ) |
|
| 1047 | - return false; |
|
| 1074 | + if ( in_array('do_not_allow', $caps) ) { |
|
| 1075 | + return false; |
|
| 1076 | + } |
|
| 1048 | 1077 | return true; |
| 1049 | 1078 | } |
| 1050 | 1079 | |
@@ -1063,8 +1092,9 @@ discard block |
||
| 1063 | 1092 | $capabilities = apply_filters( 'user_has_cap', $this->allcaps, $caps, $args, $this ); |
| 1064 | 1093 | $capabilities['exist'] = true; // Everyone is allowed to exist |
| 1065 | 1094 | foreach ( (array) $caps as $cap ) { |
| 1066 | - if ( empty( $capabilities[ $cap ] ) ) |
|
| 1067 | - return false; |
|
| 1095 | + if ( empty( $capabilities[ $cap ] ) ) { |
|
| 1096 | + return false; |
|
| 1097 | + } |
|
| 1068 | 1098 | } |
| 1069 | 1099 | |
| 1070 | 1100 | return true; |
@@ -1096,10 +1126,11 @@ discard block |
||
| 1096 | 1126 | */ |
| 1097 | 1127 | public function for_blog( $blog_id = '' ) { |
| 1098 | 1128 | global $wpdb; |
| 1099 | - if ( ! empty( $blog_id ) ) |
|
| 1100 | - $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; |
|
| 1101 | - else |
|
| 1102 | - $cap_key = ''; |
|
| 1129 | + if ( ! empty( $blog_id ) ) { |
|
| 1130 | + $cap_key = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; |
|
| 1131 | + } else { |
|
| 1132 | + $cap_key = ''; |
|
| 1133 | + } |
|
| 1103 | 1134 | $this->_init_caps( $cap_key ); |
| 1104 | 1135 | } |
| 1105 | 1136 | } |
@@ -1132,14 +1163,17 @@ discard block |
||
| 1132 | 1163 | case 'edit_user': |
| 1133 | 1164 | case 'edit_users': |
| 1134 | 1165 | // Allow user to edit itself |
| 1135 | - if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) |
|
| 1136 | - break; |
|
| 1166 | + if ( 'edit_user' == $cap && isset( $args[0] ) && $user_id == $args[0] ) { |
|
| 1167 | + break; |
|
| 1168 | + } |
|
| 1137 | 1169 | |
| 1138 | 1170 | // If multisite these caps are allowed only for super admins. |
| 1139 | - if ( is_multisite() && !is_super_admin( $user_id ) ) |
|
| 1140 | - $caps[] = 'do_not_allow'; |
|
| 1141 | - else |
|
| 1142 | - $caps[] = 'edit_users'; // edit_user maps to edit_users. |
|
| 1171 | + if ( is_multisite() && !is_super_admin( $user_id ) ) { |
|
| 1172 | + $caps[] = 'do_not_allow'; |
|
| 1173 | + } else { |
|
| 1174 | + $caps[] = 'edit_users'; |
|
| 1175 | + } |
|
| 1176 | + // edit_user maps to edit_users. |
|
| 1143 | 1177 | break; |
| 1144 | 1178 | case 'delete_post': |
| 1145 | 1179 | case 'delete_page': |
@@ -1154,8 +1188,9 @@ discard block |
||
| 1154 | 1188 | if ( ! $post_type->map_meta_cap ) { |
| 1155 | 1189 | $caps[] = $post_type->cap->$cap; |
| 1156 | 1190 | // Prior to 3.1 we would re-call map_meta_cap here. |
| 1157 | - if ( 'delete_post' == $cap ) |
|
| 1158 | - $cap = $post_type->cap->$cap; |
|
| 1191 | + if ( 'delete_post' == $cap ) { |
|
| 1192 | + $cap = $post_type->cap->$cap; |
|
| 1193 | + } |
|
| 1159 | 1194 | break; |
| 1160 | 1195 | } |
| 1161 | 1196 | |
@@ -1202,8 +1237,9 @@ discard block |
||
| 1202 | 1237 | if ( ! $post_type->map_meta_cap ) { |
| 1203 | 1238 | $caps[] = $post_type->cap->$cap; |
| 1204 | 1239 | // Prior to 3.1 we would re-call map_meta_cap here. |
| 1205 | - if ( 'edit_post' == $cap ) |
|
| 1206 | - $cap = $post_type->cap->$cap; |
|
| 1240 | + if ( 'edit_post' == $cap ) { |
|
| 1241 | + $cap = $post_type->cap->$cap; |
|
| 1242 | + } |
|
| 1207 | 1243 | break; |
| 1208 | 1244 | } |
| 1209 | 1245 | |
@@ -1244,8 +1280,9 @@ discard block |
||
| 1244 | 1280 | if ( ! $post_type->map_meta_cap ) { |
| 1245 | 1281 | $caps[] = $post_type->cap->$cap; |
| 1246 | 1282 | // Prior to 3.1 we would re-call map_meta_cap here. |
| 1247 | - if ( 'read_post' == $cap ) |
|
| 1248 | - $cap = $post_type->cap->$cap; |
|
| 1283 | + if ( 'read_post' == $cap ) { |
|
| 1284 | + $cap = $post_type->cap->$cap; |
|
| 1285 | + } |
|
| 1249 | 1286 | break; |
| 1250 | 1287 | } |
| 1251 | 1288 | |
@@ -1294,16 +1331,18 @@ discard block |
||
| 1294 | 1331 | * @param array $caps User capabilities. |
| 1295 | 1332 | */ |
| 1296 | 1333 | $allowed = apply_filters( "auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps ); |
| 1297 | - if ( ! $allowed ) |
|
| 1298 | - $caps[] = $cap; |
|
| 1334 | + if ( ! $allowed ) { |
|
| 1335 | + $caps[] = $cap; |
|
| 1336 | + } |
|
| 1299 | 1337 | } elseif ( $meta_key && is_protected_meta( $meta_key, 'post' ) ) { |
| 1300 | 1338 | $caps[] = $cap; |
| 1301 | 1339 | } |
| 1302 | 1340 | break; |
| 1303 | 1341 | case 'edit_comment': |
| 1304 | 1342 | $comment = get_comment( $args[0] ); |
| 1305 | - if ( empty( $comment ) ) |
|
| 1306 | - break; |
|
| 1343 | + if ( empty( $comment ) ) { |
|
| 1344 | + break; |
|
| 1345 | + } |
|
| 1307 | 1346 | $post = get_post( $comment->comment_post_ID ); |
| 1308 | 1347 | |
| 1309 | 1348 | /* |
@@ -1317,32 +1356,35 @@ discard block |
||
| 1317 | 1356 | } |
| 1318 | 1357 | break; |
| 1319 | 1358 | case 'unfiltered_upload': |
| 1320 | - if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) |
|
| 1321 | - $caps[] = $cap; |
|
| 1322 | - else |
|
| 1323 | - $caps[] = 'do_not_allow'; |
|
| 1359 | + if ( defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && ( !is_multisite() || is_super_admin( $user_id ) ) ) { |
|
| 1360 | + $caps[] = $cap; |
|
| 1361 | + } else { |
|
| 1362 | + $caps[] = 'do_not_allow'; |
|
| 1363 | + } |
|
| 1324 | 1364 | break; |
| 1325 | 1365 | case 'unfiltered_html' : |
| 1326 | 1366 | // Disallow unfiltered_html for all users, even admins and super admins. |
| 1327 | - if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) |
|
| 1328 | - $caps[] = 'do_not_allow'; |
|
| 1329 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1330 | - $caps[] = 'do_not_allow'; |
|
| 1331 | - else |
|
| 1332 | - $caps[] = $cap; |
|
| 1367 | + if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) { |
|
| 1368 | + $caps[] = 'do_not_allow'; |
|
| 1369 | + } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
| 1370 | + $caps[] = 'do_not_allow'; |
|
| 1371 | + } else { |
|
| 1372 | + $caps[] = $cap; |
|
| 1373 | + } |
|
| 1333 | 1374 | break; |
| 1334 | 1375 | case 'edit_files': |
| 1335 | 1376 | case 'edit_plugins': |
| 1336 | 1377 | case 'edit_themes': |
| 1337 | 1378 | // Disallow the file editors. |
| 1338 | - if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) |
|
| 1339 | - $caps[] = 'do_not_allow'; |
|
| 1340 | - elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) |
|
| 1341 | - $caps[] = 'do_not_allow'; |
|
| 1342 | - elseif ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1343 | - $caps[] = 'do_not_allow'; |
|
| 1344 | - else |
|
| 1345 | - $caps[] = $cap; |
|
| 1379 | + if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) { |
|
| 1380 | + $caps[] = 'do_not_allow'; |
|
| 1381 | + } elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { |
|
| 1382 | + $caps[] = 'do_not_allow'; |
|
| 1383 | + } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
| 1384 | + $caps[] = 'do_not_allow'; |
|
| 1385 | + } else { |
|
| 1386 | + $caps[] = $cap; |
|
| 1387 | + } |
|
| 1346 | 1388 | break; |
| 1347 | 1389 | case 'update_plugins': |
| 1348 | 1390 | case 'delete_plugins': |
@@ -1372,31 +1414,36 @@ discard block |
||
| 1372 | 1414 | if ( is_multisite() ) { |
| 1373 | 1415 | // update_, install_, and delete_ are handled above with is_super_admin(). |
| 1374 | 1416 | $menu_perms = get_site_option( 'menu_items', array() ); |
| 1375 | - if ( empty( $menu_perms['plugins'] ) ) |
|
| 1376 | - $caps[] = 'manage_network_plugins'; |
|
| 1417 | + if ( empty( $menu_perms['plugins'] ) ) { |
|
| 1418 | + $caps[] = 'manage_network_plugins'; |
|
| 1419 | + } |
|
| 1377 | 1420 | } |
| 1378 | 1421 | break; |
| 1379 | 1422 | case 'delete_user': |
| 1380 | 1423 | case 'delete_users': |
| 1381 | 1424 | // If multisite only super admins can delete users. |
| 1382 | - if ( is_multisite() && ! is_super_admin( $user_id ) ) |
|
| 1383 | - $caps[] = 'do_not_allow'; |
|
| 1384 | - else |
|
| 1385 | - $caps[] = 'delete_users'; // delete_user maps to delete_users. |
|
| 1425 | + if ( is_multisite() && ! is_super_admin( $user_id ) ) { |
|
| 1426 | + $caps[] = 'do_not_allow'; |
|
| 1427 | + } else { |
|
| 1428 | + $caps[] = 'delete_users'; |
|
| 1429 | + } |
|
| 1430 | + // delete_user maps to delete_users. |
|
| 1386 | 1431 | break; |
| 1387 | 1432 | case 'create_users': |
| 1388 | - if ( !is_multisite() ) |
|
| 1389 | - $caps[] = $cap; |
|
| 1390 | - elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) |
|
| 1391 | - $caps[] = $cap; |
|
| 1392 | - else |
|
| 1393 | - $caps[] = 'do_not_allow'; |
|
| 1433 | + if ( !is_multisite() ) { |
|
| 1434 | + $caps[] = $cap; |
|
| 1435 | + } elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) { |
|
| 1436 | + $caps[] = $cap; |
|
| 1437 | + } else { |
|
| 1438 | + $caps[] = 'do_not_allow'; |
|
| 1439 | + } |
|
| 1394 | 1440 | break; |
| 1395 | 1441 | case 'manage_links' : |
| 1396 | - if ( get_option( 'link_manager_enabled' ) ) |
|
| 1397 | - $caps[] = $cap; |
|
| 1398 | - else |
|
| 1399 | - $caps[] = 'do_not_allow'; |
|
| 1442 | + if ( get_option( 'link_manager_enabled' ) ) { |
|
| 1443 | + $caps[] = $cap; |
|
| 1444 | + } else { |
|
| 1445 | + $caps[] = 'do_not_allow'; |
|
| 1446 | + } |
|
| 1400 | 1447 | break; |
| 1401 | 1448 | case 'customize' : |
| 1402 | 1449 | $caps[] = 'edit_theme_options'; |
@@ -1440,8 +1487,9 @@ discard block |
||
| 1440 | 1487 | function current_user_can( $capability ) { |
| 1441 | 1488 | $current_user = wp_get_current_user(); |
| 1442 | 1489 | |
| 1443 | - if ( empty( $current_user ) ) |
|
| 1444 | - return false; |
|
| 1490 | + if ( empty( $current_user ) ) { |
|
| 1491 | + return false; |
|
| 1492 | + } |
|
| 1445 | 1493 | |
| 1446 | 1494 | $args = array_slice( func_get_args(), 1 ); |
| 1447 | 1495 | $args = array_merge( array( $capability ), $args ); |
@@ -1492,13 +1540,15 @@ discard block |
||
| 1492 | 1540 | * @return bool |
| 1493 | 1541 | */ |
| 1494 | 1542 | function author_can( $post, $capability ) { |
| 1495 | - if ( !$post = get_post($post) ) |
|
| 1496 | - return false; |
|
| 1543 | + if ( !$post = get_post($post) ) { |
|
| 1544 | + return false; |
|
| 1545 | + } |
|
| 1497 | 1546 | |
| 1498 | 1547 | $author = get_userdata( $post->post_author ); |
| 1499 | 1548 | |
| 1500 | - if ( ! $author ) |
|
| 1501 | - return false; |
|
| 1549 | + if ( ! $author ) { |
|
| 1550 | + return false; |
|
| 1551 | + } |
|
| 1502 | 1552 | |
| 1503 | 1553 | $args = array_slice( func_get_args(), 2 ); |
| 1504 | 1554 | $args = array_merge( array( $capability ), $args ); |
@@ -1516,11 +1566,13 @@ discard block |
||
| 1516 | 1566 | * @return bool |
| 1517 | 1567 | */ |
| 1518 | 1568 | function user_can( $user, $capability ) { |
| 1519 | - if ( ! is_object( $user ) ) |
|
| 1520 | - $user = get_userdata( $user ); |
|
| 1569 | + if ( ! is_object( $user ) ) { |
|
| 1570 | + $user = get_userdata( $user ); |
|
| 1571 | + } |
|
| 1521 | 1572 | |
| 1522 | - if ( ! $user || ! $user->exists() ) |
|
| 1523 | - return false; |
|
| 1573 | + if ( ! $user || ! $user->exists() ) { |
|
| 1574 | + return false; |
|
| 1575 | + } |
|
| 1524 | 1576 | |
| 1525 | 1577 | $args = array_slice( func_get_args(), 2 ); |
| 1526 | 1578 | $args = array_merge( array( $capability ), $args ); |
@@ -1595,11 +1647,12 @@ discard block |
||
| 1595 | 1647 | function get_super_admins() { |
| 1596 | 1648 | global $super_admins; |
| 1597 | 1649 | |
| 1598 | - if ( isset($super_admins) ) |
|
| 1599 | - return $super_admins; |
|
| 1600 | - else |
|
| 1601 | - return get_site_option( 'site_admins', array('admin') ); |
|
| 1602 | -} |
|
| 1650 | + if ( isset($super_admins) ) { |
|
| 1651 | + return $super_admins; |
|
| 1652 | + } else { |
|
| 1653 | + return get_site_option( 'site_admins', array('admin') ); |
|
| 1654 | + } |
|
| 1655 | + } |
|
| 1603 | 1656 | |
| 1604 | 1657 | /** |
| 1605 | 1658 | * Determine if user is a site admin. |
@@ -1610,21 +1663,25 @@ discard block |
||
| 1610 | 1663 | * @return bool True if the user is a site admin. |
| 1611 | 1664 | */ |
| 1612 | 1665 | function is_super_admin( $user_id = false ) { |
| 1613 | - if ( ! $user_id || $user_id == get_current_user_id() ) |
|
| 1614 | - $user = wp_get_current_user(); |
|
| 1615 | - else |
|
| 1616 | - $user = get_userdata( $user_id ); |
|
| 1666 | + if ( ! $user_id || $user_id == get_current_user_id() ) { |
|
| 1667 | + $user = wp_get_current_user(); |
|
| 1668 | + } else { |
|
| 1669 | + $user = get_userdata( $user_id ); |
|
| 1670 | + } |
|
| 1617 | 1671 | |
| 1618 | - if ( ! $user || ! $user->exists() ) |
|
| 1619 | - return false; |
|
| 1672 | + if ( ! $user || ! $user->exists() ) { |
|
| 1673 | + return false; |
|
| 1674 | + } |
|
| 1620 | 1675 | |
| 1621 | 1676 | if ( is_multisite() ) { |
| 1622 | 1677 | $super_admins = get_super_admins(); |
| 1623 | - if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) ) |
|
| 1624 | - return true; |
|
| 1678 | + if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) ) { |
|
| 1679 | + return true; |
|
| 1680 | + } |
|
| 1625 | 1681 | } else { |
| 1626 | - if ( $user->has_cap('delete_users') ) |
|
| 1627 | - return true; |
|
| 1682 | + if ( $user->has_cap('delete_users') ) { |
|
| 1683 | + return true; |
|
| 1684 | + } |
|
| 1628 | 1685 | } |
| 1629 | 1686 | |
| 1630 | 1687 | return false; |
@@ -686,7 +686,7 @@ |
||
| 686 | 686 | * Default topic count scaling for tag links |
| 687 | 687 | * |
| 688 | 688 | * @param int $count number of posts with that tag |
| 689 | - * @return int scaled count |
|
| 689 | + * @return double scaled count |
|
| 690 | 690 | */ |
| 691 | 691 | function default_topic_count_scale( $count ) { |
| 692 | 692 | return round(log10($count + 1) * 100); |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Category Template Tags and API. |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage Template |
|
| 7 | - */ |
|
| 3 | + * Category Template Tags and API. |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage Template |
|
| 7 | + */ |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Retrieve category link URL. |
@@ -15,13 +15,13 @@ discard block |
||
| 15 | 15 | * @param int|object $category Category ID or object. |
| 16 | 16 | * @return string Link on success, empty string if category does not exist. |
| 17 | 17 | */ |
| 18 | -function get_category_link( $category ) { |
|
| 19 | - if ( ! is_object( $category ) ) |
|
| 18 | +function get_category_link($category) { |
|
| 19 | + if ( ! is_object($category)) |
|
| 20 | 20 | $category = (int) $category; |
| 21 | 21 | |
| 22 | - $category = get_term_link( $category, 'category' ); |
|
| 22 | + $category = get_term_link($category, 'category'); |
|
| 23 | 23 | |
| 24 | - if ( is_wp_error( $category ) ) |
|
| 24 | + if (is_wp_error($category)) |
|
| 25 | 25 | return ''; |
| 26 | 26 | |
| 27 | 27 | return $category; |
@@ -39,24 +39,24 @@ discard block |
||
| 39 | 39 | * @param array $visited Optional. Already linked to categories to prevent duplicates. |
| 40 | 40 | * @return string|WP_Error A list of category parents on success, WP_Error on failure. |
| 41 | 41 | */ |
| 42 | -function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) { |
|
| 42 | +function get_category_parents($id, $link = false, $separator = '/', $nicename = false, $visited = array()) { |
|
| 43 | 43 | $chain = ''; |
| 44 | - $parent = get_term( $id, 'category' ); |
|
| 45 | - if ( is_wp_error( $parent ) ) |
|
| 44 | + $parent = get_term($id, 'category'); |
|
| 45 | + if (is_wp_error($parent)) |
|
| 46 | 46 | return $parent; |
| 47 | 47 | |
| 48 | - if ( $nicename ) |
|
| 48 | + if ($nicename) |
|
| 49 | 49 | $name = $parent->slug; |
| 50 | 50 | else |
| 51 | 51 | $name = $parent->name; |
| 52 | 52 | |
| 53 | - if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) { |
|
| 53 | + if ($parent->parent && ($parent->parent != $parent->term_id) && ! in_array($parent->parent, $visited)) { |
|
| 54 | 54 | $visited[] = $parent->parent; |
| 55 | - $chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited ); |
|
| 55 | + $chain .= get_category_parents($parent->parent, $link, $separator, $nicename, $visited); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if ( $link ) |
|
| 59 | - $chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">'.$name.'</a>' . $separator; |
|
| 58 | + if ($link) |
|
| 59 | + $chain .= '<a href="'.esc_url(get_category_link($parent->term_id)).'">'.$name.'</a>'.$separator; |
|
| 60 | 60 | else |
| 61 | 61 | $chain .= $name.$separator; |
| 62 | 62 | return $chain; |
@@ -75,15 +75,15 @@ discard block |
||
| 75 | 75 | * @param int $id Optional, default to current post ID. The post ID. |
| 76 | 76 | * @return array Array of objects, one for each category assigned to the post. |
| 77 | 77 | */ |
| 78 | -function get_the_category( $id = false ) { |
|
| 79 | - $categories = get_the_terms( $id, 'category' ); |
|
| 80 | - if ( ! $categories || is_wp_error( $categories ) ) |
|
| 78 | +function get_the_category($id = false) { |
|
| 79 | + $categories = get_the_terms($id, 'category'); |
|
| 80 | + if ( ! $categories || is_wp_error($categories)) |
|
| 81 | 81 | $categories = array(); |
| 82 | 82 | |
| 83 | - $categories = array_values( $categories ); |
|
| 83 | + $categories = array_values($categories); |
|
| 84 | 84 | |
| 85 | - foreach ( array_keys( $categories ) as $key ) { |
|
| 86 | - _make_cat_compat( $categories[$key] ); |
|
| 85 | + foreach (array_keys($categories) as $key) { |
|
| 86 | + _make_cat_compat($categories[$key]); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @param array $categories An array of categories to return for the post. |
| 95 | 95 | */ |
| 96 | - return apply_filters( 'get_the_categories', $categories ); |
|
| 96 | + return apply_filters('get_the_categories', $categories); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | * @param object $b |
| 110 | 110 | * @return int |
| 111 | 111 | */ |
| 112 | -function _usort_terms_by_name( $a, $b ) { |
|
| 113 | - return strcmp( $a->name, $b->name ); |
|
| 112 | +function _usort_terms_by_name($a, $b) { |
|
| 113 | + return strcmp($a->name, $b->name); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -126,10 +126,10 @@ discard block |
||
| 126 | 126 | * @param object $b |
| 127 | 127 | * @return int |
| 128 | 128 | */ |
| 129 | -function _usort_terms_by_ID( $a, $b ) { |
|
| 130 | - if ( $a->term_id > $b->term_id ) |
|
| 129 | +function _usort_terms_by_ID($a, $b) { |
|
| 130 | + if ($a->term_id > $b->term_id) |
|
| 131 | 131 | return 1; |
| 132 | - elseif ( $a->term_id < $b->term_id ) |
|
| 132 | + elseif ($a->term_id < $b->term_id) |
|
| 133 | 133 | return -1; |
| 134 | 134 | else |
| 135 | 135 | return 0; |
@@ -143,14 +143,14 @@ discard block |
||
| 143 | 143 | * @param int $cat_ID Category ID. |
| 144 | 144 | * @return string|WP_Error Category name on success, WP_Error on failure. |
| 145 | 145 | */ |
| 146 | -function get_the_category_by_ID( $cat_ID ) { |
|
| 146 | +function get_the_category_by_ID($cat_ID) { |
|
| 147 | 147 | $cat_ID = (int) $cat_ID; |
| 148 | - $category = get_term( $cat_ID, 'category' ); |
|
| 148 | + $category = get_term($cat_ID, 'category'); |
|
| 149 | 149 | |
| 150 | - if ( is_wp_error( $category ) ) |
|
| 150 | + if (is_wp_error($category)) |
|
| 151 | 151 | return $category; |
| 152 | 152 | |
| 153 | - return ( $category ) ? $category->name : ''; |
|
| 153 | + return ($category) ? $category->name : ''; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -165,64 +165,64 @@ discard block |
||
| 165 | 165 | * @param int $post_id Optional. Post ID to retrieve categories. |
| 166 | 166 | * @return string |
| 167 | 167 | */ |
| 168 | -function get_the_category_list( $separator = '', $parents='', $post_id = false ) { |
|
| 168 | +function get_the_category_list($separator = '', $parents = '', $post_id = false) { |
|
| 169 | 169 | global $wp_rewrite; |
| 170 | - if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) { |
|
| 170 | + if ( ! is_object_in_taxonomy(get_post_type($post_id), 'category')) { |
|
| 171 | 171 | /** This filter is documented in wp-includes/category-template.php */ |
| 172 | - return apply_filters( 'the_category', '', $separator, $parents ); |
|
| 172 | + return apply_filters('the_category', '', $separator, $parents); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - $categories = get_the_category( $post_id ); |
|
| 176 | - if ( empty( $categories ) ) { |
|
| 175 | + $categories = get_the_category($post_id); |
|
| 176 | + if (empty($categories)) { |
|
| 177 | 177 | /** This filter is documented in wp-includes/category-template.php */ |
| 178 | - return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents ); |
|
| 178 | + return apply_filters('the_category', __('Uncategorized'), $separator, $parents); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"'; |
|
| 181 | + $rel = (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) ? 'rel="category tag"' : 'rel="category"'; |
|
| 182 | 182 | |
| 183 | 183 | $thelist = ''; |
| 184 | - if ( '' == $separator ) { |
|
| 184 | + if ('' == $separator) { |
|
| 185 | 185 | $thelist .= '<ul class="post-categories">'; |
| 186 | - foreach ( $categories as $category ) { |
|
| 186 | + foreach ($categories as $category) { |
|
| 187 | 187 | $thelist .= "\n\t<li>"; |
| 188 | - switch ( strtolower( $parents ) ) { |
|
| 188 | + switch (strtolower($parents)) { |
|
| 189 | 189 | case 'multiple': |
| 190 | - if ( $category->parent ) |
|
| 191 | - $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 192 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
|
| 190 | + if ($category->parent) |
|
| 191 | + $thelist .= get_category_parents($category->parent, true, $separator); |
|
| 192 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'.$category->name.'</a></li>'; |
|
| 193 | 193 | break; |
| 194 | 194 | case 'single': |
| 195 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
|
| 196 | - if ( $category->parent ) |
|
| 197 | - $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 195 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'; |
|
| 196 | + if ($category->parent) |
|
| 197 | + $thelist .= get_category_parents($category->parent, false, $separator); |
|
| 198 | 198 | $thelist .= $category->name.'</a></li>'; |
| 199 | 199 | break; |
| 200 | 200 | case '': |
| 201 | 201 | default: |
| 202 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
|
| 202 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'.$category->name.'</a></li>'; |
|
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | $thelist .= '</ul>'; |
| 206 | 206 | } else { |
| 207 | 207 | $i = 0; |
| 208 | - foreach ( $categories as $category ) { |
|
| 209 | - if ( 0 < $i ) |
|
| 208 | + foreach ($categories as $category) { |
|
| 209 | + if (0 < $i) |
|
| 210 | 210 | $thelist .= $separator; |
| 211 | - switch ( strtolower( $parents ) ) { |
|
| 211 | + switch (strtolower($parents)) { |
|
| 212 | 212 | case 'multiple': |
| 213 | - if ( $category->parent ) |
|
| 214 | - $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 215 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
|
| 213 | + if ($category->parent) |
|
| 214 | + $thelist .= get_category_parents($category->parent, true, $separator); |
|
| 215 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'.$category->name.'</a>'; |
|
| 216 | 216 | break; |
| 217 | 217 | case 'single': |
| 218 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
|
| 219 | - if ( $category->parent ) |
|
| 220 | - $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 218 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'; |
|
| 219 | + if ($category->parent) |
|
| 220 | + $thelist .= get_category_parents($category->parent, false, $separator); |
|
| 221 | 221 | $thelist .= "$category->name</a>"; |
| 222 | 222 | break; |
| 223 | 223 | case '': |
| 224 | 224 | default: |
| 225 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
|
| 225 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'.$category->name.'</a>'; |
|
| 226 | 226 | } |
| 227 | 227 | ++$i; |
| 228 | 228 | } |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * @param string $parents How to display the category parents. Accepts 'multiple', |
| 239 | 239 | * 'single', or empty. |
| 240 | 240 | */ |
| 241 | - return apply_filters( 'the_category', $thelist, $separator, $parents ); |
|
| 241 | + return apply_filters('the_category', $thelist, $separator, $parents); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -259,11 +259,11 @@ discard block |
||
| 259 | 259 | * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0) |
| 260 | 260 | * @return bool True if the current post is in any of the given categories. |
| 261 | 261 | */ |
| 262 | -function in_category( $category, $post = null ) { |
|
| 263 | - if ( empty( $category ) ) |
|
| 262 | +function in_category($category, $post = null) { |
|
| 263 | + if (empty($category)) |
|
| 264 | 264 | return false; |
| 265 | 265 | |
| 266 | - return has_category( $category, $post ); |
|
| 266 | + return has_category($category, $post); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | * @param string $parents Optional. How to display the parents. |
| 276 | 276 | * @param int $post_id Optional. Post ID to retrieve categories. |
| 277 | 277 | */ |
| 278 | -function the_category( $separator = '', $parents='', $post_id = false ) { |
|
| 279 | - echo get_the_category_list( $separator, $parents, $post_id ); |
|
| 278 | +function the_category($separator = '', $parents = '', $post_id = false) { |
|
| 279 | + echo get_the_category_list($separator, $parents, $post_id); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | * @param int $category Optional. Category ID. Will use global category ID by default. |
| 288 | 288 | * @return string Category description, available. |
| 289 | 289 | */ |
| 290 | -function category_description( $category = 0 ) { |
|
| 291 | - return term_description( $category, 'category' ); |
|
| 290 | +function category_description($category = 0) { |
|
| 291 | + return term_description($category, 'category'); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | * } |
| 342 | 342 | * @return string HTML content only if 'echo' argument is 0. |
| 343 | 343 | */ |
| 344 | -function wp_dropdown_categories( $args = '' ) { |
|
| 344 | +function wp_dropdown_categories($args = '') { |
|
| 345 | 345 | $defaults = array( |
| 346 | 346 | 'show_option_all' => '', 'show_option_none' => '', |
| 347 | 347 | 'orderby' => 'id', 'order' => 'ASC', |
@@ -356,43 +356,43 @@ discard block |
||
| 356 | 356 | 'value_field' => 'term_id', |
| 357 | 357 | ); |
| 358 | 358 | |
| 359 | - $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0; |
|
| 359 | + $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0; |
|
| 360 | 360 | |
| 361 | 361 | // Back compat. |
| 362 | - if ( isset( $args['type'] ) && 'link' == $args['type'] ) { |
|
| 363 | - _deprecated_argument( __FUNCTION__, '3.0', '' ); |
|
| 362 | + if (isset($args['type']) && 'link' == $args['type']) { |
|
| 363 | + _deprecated_argument(__FUNCTION__, '3.0', ''); |
|
| 364 | 364 | $args['taxonomy'] = 'link_category'; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - $r = wp_parse_args( $args, $defaults ); |
|
| 367 | + $r = wp_parse_args($args, $defaults); |
|
| 368 | 368 | $option_none_value = $r['option_none_value']; |
| 369 | 369 | |
| 370 | - if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) { |
|
| 370 | + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { |
|
| 371 | 371 | $r['pad_counts'] = true; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | $tab_index = $r['tab_index']; |
| 375 | 375 | |
| 376 | 376 | $tab_index_attribute = ''; |
| 377 | - if ( (int) $tab_index > 0 ) { |
|
| 377 | + if ((int) $tab_index > 0) { |
|
| 378 | 378 | $tab_index_attribute = " tabindex=\"$tab_index\""; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | // Avoid clashes with the 'name' param of get_terms(). |
| 382 | 382 | $get_terms_args = $r; |
| 383 | - unset( $get_terms_args['name'] ); |
|
| 384 | - $categories = get_terms( $r['taxonomy'], $get_terms_args ); |
|
| 383 | + unset($get_terms_args['name']); |
|
| 384 | + $categories = get_terms($r['taxonomy'], $get_terms_args); |
|
| 385 | 385 | |
| 386 | - $name = esc_attr( $r['name'] ); |
|
| 387 | - $class = esc_attr( $r['class'] ); |
|
| 388 | - $id = $r['id'] ? esc_attr( $r['id'] ) : $name; |
|
| 386 | + $name = esc_attr($r['name']); |
|
| 387 | + $class = esc_attr($r['class']); |
|
| 388 | + $id = $r['id'] ? esc_attr($r['id']) : $name; |
|
| 389 | 389 | |
| 390 | - if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) { |
|
| 390 | + if ( ! $r['hide_if_empty'] || ! empty($categories)) { |
|
| 391 | 391 | $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; |
| 392 | 392 | } else { |
| 393 | 393 | $output = ''; |
| 394 | 394 | } |
| 395 | - if ( empty( $categories ) && ! $r['hide_if_empty'] && ! empty( $r['show_option_none'] ) ) { |
|
| 395 | + if (empty($categories) && ! $r['hide_if_empty'] && ! empty($r['show_option_none'])) { |
|
| 396 | 396 | |
| 397 | 397 | /** |
| 398 | 398 | * Filter a taxonomy drop-down display element. |
@@ -408,37 +408,37 @@ discard block |
||
| 408 | 408 | * |
| 409 | 409 | * @param string $element Taxonomy element to list. |
| 410 | 410 | */ |
| 411 | - $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] ); |
|
| 412 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n"; |
|
| 411 | + $show_option_none = apply_filters('list_cats', $r['show_option_none']); |
|
| 412 | + $output .= "\t<option value='".esc_attr($option_none_value)."' selected='selected'>$show_option_none</option>\n"; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - if ( ! empty( $categories ) ) { |
|
| 415 | + if ( ! empty($categories)) { |
|
| 416 | 416 | |
| 417 | - if ( $r['show_option_all'] ) { |
|
| 417 | + if ($r['show_option_all']) { |
|
| 418 | 418 | |
| 419 | 419 | /** This filter is documented in wp-includes/category-template.php */ |
| 420 | - $show_option_all = apply_filters( 'list_cats', $r['show_option_all'] ); |
|
| 421 | - $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : ''; |
|
| 420 | + $show_option_all = apply_filters('list_cats', $r['show_option_all']); |
|
| 421 | + $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; |
|
| 422 | 422 | $output .= "\t<option value='0'$selected>$show_option_all</option>\n"; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - if ( $r['show_option_none'] ) { |
|
| 425 | + if ($r['show_option_none']) { |
|
| 426 | 426 | |
| 427 | 427 | /** This filter is documented in wp-includes/category-template.php */ |
| 428 | - $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] ); |
|
| 429 | - $selected = selected( $option_none_value, $r['selected'], false ); |
|
| 430 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n"; |
|
| 428 | + $show_option_none = apply_filters('list_cats', $r['show_option_none']); |
|
| 429 | + $selected = selected($option_none_value, $r['selected'], false); |
|
| 430 | + $output .= "\t<option value='".esc_attr($option_none_value)."'$selected>$show_option_none</option>\n"; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if ( $r['hierarchical'] ) { |
|
| 434 | - $depth = $r['depth']; // Walk the full depth. |
|
| 433 | + if ($r['hierarchical']) { |
|
| 434 | + $depth = $r['depth']; // Walk the full depth. |
|
| 435 | 435 | } else { |
| 436 | 436 | $depth = -1; // Flat. |
| 437 | 437 | } |
| 438 | - $output .= walk_category_dropdown_tree( $categories, $depth, $r ); |
|
| 438 | + $output .= walk_category_dropdown_tree($categories, $depth, $r); |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | - if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) { |
|
| 441 | + if ( ! $r['hide_if_empty'] || ! empty($categories)) { |
|
| 442 | 442 | $output .= "</select>\n"; |
| 443 | 443 | } |
| 444 | 444 | /** |
@@ -449,9 +449,9 @@ discard block |
||
| 449 | 449 | * @param string $output HTML output. |
| 450 | 450 | * @param array $r Arguments used to build the drop-down. |
| 451 | 451 | */ |
| 452 | - $output = apply_filters( 'wp_dropdown_cats', $output, $r ); |
|
| 452 | + $output = apply_filters('wp_dropdown_cats', $output, $r); |
|
| 453 | 453 | |
| 454 | - if ( $r['echo'] ) { |
|
| 454 | + if ($r['echo']) { |
|
| 455 | 455 | echo $output; |
| 456 | 456 | } |
| 457 | 457 | return $output; |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | * @param string|array $args Optional. Override default arguments. |
| 489 | 489 | * @return false|string HTML content only if 'echo' argument is 0. |
| 490 | 490 | */ |
| 491 | -function wp_list_categories( $args = '' ) { |
|
| 491 | +function wp_list_categories($args = '') { |
|
| 492 | 492 | $defaults = array( |
| 493 | 493 | 'show_option_all' => '', 'show_option_none' => __('No categories'), |
| 494 | 494 | 'orderby' => 'name', 'order' => 'ASC', |
@@ -498,93 +498,93 @@ discard block |
||
| 498 | 498 | 'feed' => '', 'feed_type' => '', |
| 499 | 499 | 'feed_image' => '', 'exclude' => '', |
| 500 | 500 | 'exclude_tree' => '', 'current_category' => 0, |
| 501 | - 'hierarchical' => true, 'title_li' => __( 'Categories' ), |
|
| 501 | + 'hierarchical' => true, 'title_li' => __('Categories'), |
|
| 502 | 502 | 'echo' => 1, 'depth' => 0, |
| 503 | 503 | 'taxonomy' => 'category' |
| 504 | 504 | ); |
| 505 | 505 | |
| 506 | - $r = wp_parse_args( $args, $defaults ); |
|
| 506 | + $r = wp_parse_args($args, $defaults); |
|
| 507 | 507 | |
| 508 | - if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) |
|
| 508 | + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) |
|
| 509 | 509 | $r['pad_counts'] = true; |
| 510 | 510 | |
| 511 | - if ( true == $r['hierarchical'] ) { |
|
| 511 | + if (true == $r['hierarchical']) { |
|
| 512 | 512 | $r['exclude_tree'] = $r['exclude']; |
| 513 | 513 | $r['exclude'] = ''; |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - if ( ! isset( $r['class'] ) ) |
|
| 517 | - $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy']; |
|
| 516 | + if ( ! isset($r['class'])) |
|
| 517 | + $r['class'] = ('category' == $r['taxonomy']) ? 'categories' : $r['taxonomy']; |
|
| 518 | 518 | |
| 519 | - if ( ! taxonomy_exists( $r['taxonomy'] ) ) { |
|
| 519 | + if ( ! taxonomy_exists($r['taxonomy'])) { |
|
| 520 | 520 | return false; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | $show_option_all = $r['show_option_all']; |
| 524 | 524 | $show_option_none = $r['show_option_none']; |
| 525 | 525 | |
| 526 | - $categories = get_categories( $r ); |
|
| 526 | + $categories = get_categories($r); |
|
| 527 | 527 | |
| 528 | 528 | $output = ''; |
| 529 | - if ( $r['title_li'] && 'list' == $r['style'] ) { |
|
| 530 | - $output = '<li class="' . esc_attr( $r['class'] ) . '">' . $r['title_li'] . '<ul>'; |
|
| 529 | + if ($r['title_li'] && 'list' == $r['style']) { |
|
| 530 | + $output = '<li class="'.esc_attr($r['class']).'">'.$r['title_li'].'<ul>'; |
|
| 531 | 531 | } |
| 532 | - if ( empty( $categories ) ) { |
|
| 533 | - if ( ! empty( $show_option_none ) ) { |
|
| 534 | - if ( 'list' == $r['style'] ) { |
|
| 535 | - $output .= '<li class="cat-item-none">' . $show_option_none . '</li>'; |
|
| 532 | + if (empty($categories)) { |
|
| 533 | + if ( ! empty($show_option_none)) { |
|
| 534 | + if ('list' == $r['style']) { |
|
| 535 | + $output .= '<li class="cat-item-none">'.$show_option_none.'</li>'; |
|
| 536 | 536 | } else { |
| 537 | 537 | $output .= $show_option_none; |
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | } else { |
| 541 | - if ( ! empty( $show_option_all ) ) { |
|
| 541 | + if ( ! empty($show_option_all)) { |
|
| 542 | 542 | |
| 543 | 543 | $posts_page = ''; |
| 544 | 544 | |
| 545 | 545 | // For taxonomies that belong only to custom post types, point to a valid archive. |
| 546 | - $taxonomy_object = get_taxonomy( $r['taxonomy'] ); |
|
| 547 | - if ( ! in_array( 'post', $taxonomy_object->object_type ) && ! in_array( 'page', $taxonomy_object->object_type ) ) { |
|
| 548 | - foreach ( $taxonomy_object->object_type as $object_type ) { |
|
| 549 | - $_object_type = get_post_type_object( $object_type ); |
|
| 546 | + $taxonomy_object = get_taxonomy($r['taxonomy']); |
|
| 547 | + if ( ! in_array('post', $taxonomy_object->object_type) && ! in_array('page', $taxonomy_object->object_type)) { |
|
| 548 | + foreach ($taxonomy_object->object_type as $object_type) { |
|
| 549 | + $_object_type = get_post_type_object($object_type); |
|
| 550 | 550 | |
| 551 | 551 | // Grab the first one. |
| 552 | - if ( ! empty( $_object_type->has_archive ) ) { |
|
| 553 | - $posts_page = get_post_type_archive_link( $object_type ); |
|
| 552 | + if ( ! empty($_object_type->has_archive)) { |
|
| 553 | + $posts_page = get_post_type_archive_link($object_type); |
|
| 554 | 554 | break; |
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | // Fallback for the 'All' link is the front page. |
| 560 | - if ( ! $posts_page ) { |
|
| 561 | - $posts_page = 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' ); |
|
| 560 | + if ( ! $posts_page) { |
|
| 561 | + $posts_page = 'page' == get_option('show_on_front') && get_option('page_for_posts') ? get_permalink(get_option('page_for_posts')) : home_url('/'); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | - $posts_page = esc_url( $posts_page ); |
|
| 565 | - if ( 'list' == $r['style'] ) { |
|
| 564 | + $posts_page = esc_url($posts_page); |
|
| 565 | + if ('list' == $r['style']) { |
|
| 566 | 566 | $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>"; |
| 567 | 567 | } else { |
| 568 | 568 | $output .= "<a href='$posts_page'>$show_option_all</a>"; |
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | - if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) { |
|
| 572 | + if (empty($r['current_category']) && (is_category() || is_tax() || is_tag())) { |
|
| 573 | 573 | $current_term_object = get_queried_object(); |
| 574 | - if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) { |
|
| 574 | + if ($current_term_object && $r['taxonomy'] === $current_term_object->taxonomy) { |
|
| 575 | 575 | $r['current_category'] = get_queried_object_id(); |
| 576 | 576 | } |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - if ( $r['hierarchical'] ) { |
|
| 579 | + if ($r['hierarchical']) { |
|
| 580 | 580 | $depth = $r['depth']; |
| 581 | 581 | } else { |
| 582 | 582 | $depth = -1; // Flat. |
| 583 | 583 | } |
| 584 | - $output .= walk_category_tree( $categories, $depth, $r ); |
|
| 584 | + $output .= walk_category_tree($categories, $depth, $r); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | - if ( $r['title_li'] && 'list' == $r['style'] ) |
|
| 587 | + if ($r['title_li'] && 'list' == $r['style']) |
|
| 588 | 588 | $output .= '</ul></li>'; |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -595,9 +595,9 @@ discard block |
||
| 595 | 595 | * @param string $output HTML output. |
| 596 | 596 | * @param array $args An array of taxonomy-listing arguments. |
| 597 | 597 | */ |
| 598 | - $html = apply_filters( 'wp_list_categories', $output, $args ); |
|
| 598 | + $html = apply_filters('wp_list_categories', $output, $args); |
|
| 599 | 599 | |
| 600 | - if ( $r['echo'] ) { |
|
| 600 | + if ($r['echo']) { |
|
| 601 | 601 | echo $html; |
| 602 | 602 | } else { |
| 603 | 603 | return $html; |
@@ -639,32 +639,32 @@ discard block |
||
| 639 | 639 | * @return void|array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. |
| 640 | 640 | * Otherwise, this function outputs the tag cloud. |
| 641 | 641 | */ |
| 642 | -function wp_tag_cloud( $args = '' ) { |
|
| 642 | +function wp_tag_cloud($args = '') { |
|
| 643 | 643 | $defaults = array( |
| 644 | 644 | 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, |
| 645 | 645 | 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', |
| 646 | 646 | 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true |
| 647 | 647 | ); |
| 648 | - $args = wp_parse_args( $args, $defaults ); |
|
| 648 | + $args = wp_parse_args($args, $defaults); |
|
| 649 | 649 | |
| 650 | - $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags |
|
| 650 | + $tags = get_terms($args['taxonomy'], array_merge($args, array('orderby' => 'count', 'order' => 'DESC'))); // Always query top tags |
|
| 651 | 651 | |
| 652 | - if ( empty( $tags ) || is_wp_error( $tags ) ) |
|
| 652 | + if (empty($tags) || is_wp_error($tags)) |
|
| 653 | 653 | return; |
| 654 | 654 | |
| 655 | - foreach ( $tags as $key => $tag ) { |
|
| 656 | - if ( 'edit' == $args['link'] ) |
|
| 657 | - $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] ); |
|
| 655 | + foreach ($tags as $key => $tag) { |
|
| 656 | + if ('edit' == $args['link']) |
|
| 657 | + $link = get_edit_term_link($tag->term_id, $tag->taxonomy, $args['post_type']); |
|
| 658 | 658 | else |
| 659 | - $link = get_term_link( intval($tag->term_id), $tag->taxonomy ); |
|
| 660 | - if ( is_wp_error( $link ) ) |
|
| 659 | + $link = get_term_link(intval($tag->term_id), $tag->taxonomy); |
|
| 660 | + if (is_wp_error($link)) |
|
| 661 | 661 | return; |
| 662 | 662 | |
| 663 | - $tags[ $key ]->link = $link; |
|
| 664 | - $tags[ $key ]->id = $tag->term_id; |
|
| 663 | + $tags[$key]->link = $link; |
|
| 664 | + $tags[$key]->id = $tag->term_id; |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args |
|
| 667 | + $return = wp_generate_tag_cloud($tags, $args); // Here's where those top tags get sorted according to $args |
|
| 668 | 668 | |
| 669 | 669 | /** |
| 670 | 670 | * Filter the tag cloud output. |
@@ -674,9 +674,9 @@ discard block |
||
| 674 | 674 | * @param string $return HTML output of the tag cloud. |
| 675 | 675 | * @param array $args An array of tag cloud arguments. |
| 676 | 676 | */ |
| 677 | - $return = apply_filters( 'wp_tag_cloud', $return, $args ); |
|
| 677 | + $return = apply_filters('wp_tag_cloud', $return, $args); |
|
| 678 | 678 | |
| 679 | - if ( 'array' == $args['format'] || empty($args['echo']) ) |
|
| 679 | + if ('array' == $args['format'] || empty($args['echo'])) |
|
| 680 | 680 | return $return; |
| 681 | 681 | |
| 682 | 682 | echo $return; |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | * @param int $count number of posts with that tag |
| 689 | 689 | * @return int scaled count |
| 690 | 690 | */ |
| 691 | -function default_topic_count_scale( $count ) { |
|
| 691 | +function default_topic_count_scale($count) { |
|
| 692 | 692 | return round(log10($count + 1) * 100); |
| 693 | 693 | } |
| 694 | 694 | |
@@ -726,7 +726,7 @@ discard block |
||
| 726 | 726 | * @param string|array $args Optional, override default arguments. |
| 727 | 727 | * @return string|array Tag cloud as a string or an array, depending on 'format' argument. |
| 728 | 728 | */ |
| 729 | -function wp_generate_tag_cloud( $tags, $args = '' ) { |
|
| 729 | +function wp_generate_tag_cloud($tags, $args = '') { |
|
| 730 | 730 | $defaults = array( |
| 731 | 731 | 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, |
| 732 | 732 | 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', |
@@ -734,31 +734,31 @@ discard block |
||
| 734 | 734 | 'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1, |
| 735 | 735 | ); |
| 736 | 736 | |
| 737 | - $args = wp_parse_args( $args, $defaults ); |
|
| 737 | + $args = wp_parse_args($args, $defaults); |
|
| 738 | 738 | |
| 739 | - $return = ( 'array' === $args['format'] ) ? array() : ''; |
|
| 739 | + $return = ('array' === $args['format']) ? array() : ''; |
|
| 740 | 740 | |
| 741 | - if ( empty( $tags ) ) { |
|
| 741 | + if (empty($tags)) { |
|
| 742 | 742 | return $return; |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | // Juggle topic count tooltips: |
| 746 | - if ( isset( $args['topic_count_text'] ) ) { |
|
| 746 | + if (isset($args['topic_count_text'])) { |
|
| 747 | 747 | // First look for nooped plural support via topic_count_text. |
| 748 | 748 | $translate_nooped_plural = $args['topic_count_text']; |
| 749 | - } elseif ( ! empty( $args['topic_count_text_callback'] ) ) { |
|
| 749 | + } elseif ( ! empty($args['topic_count_text_callback'])) { |
|
| 750 | 750 | // Look for the alternative callback style. Ignore the previous default. |
| 751 | - if ( $args['topic_count_text_callback'] === 'default_topic_count_text' ) { |
|
| 752 | - $translate_nooped_plural = _n_noop( '%s topic', '%s topics' ); |
|
| 751 | + if ($args['topic_count_text_callback'] === 'default_topic_count_text') { |
|
| 752 | + $translate_nooped_plural = _n_noop('%s topic', '%s topics'); |
|
| 753 | 753 | } else { |
| 754 | 754 | $translate_nooped_plural = false; |
| 755 | 755 | } |
| 756 | - } elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { |
|
| 756 | + } elseif (isset($args['single_text']) && isset($args['multiple_text'])) { |
|
| 757 | 757 | // If no callback exists, look for the old-style single_text and multiple_text arguments. |
| 758 | - $translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] ); |
|
| 758 | + $translate_nooped_plural = _n_noop($args['single_text'], $args['multiple_text']); |
|
| 759 | 759 | } else { |
| 760 | 760 | // This is the default for when no callback, plural, or argument is passed in. |
| 761 | - $translate_nooped_plural = _n_noop( '%s topic', '%s topics' ); |
|
| 761 | + $translate_nooped_plural = _n_noop('%s topic', '%s topics'); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | /** |
@@ -769,62 +769,62 @@ discard block |
||
| 769 | 769 | * @param array $tags Ordered array of terms. |
| 770 | 770 | * @param array $args An array of tag cloud arguments. |
| 771 | 771 | */ |
| 772 | - $tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args ); |
|
| 773 | - if ( empty( $tags_sorted ) ) { |
|
| 772 | + $tags_sorted = apply_filters('tag_cloud_sort', $tags, $args); |
|
| 773 | + if (empty($tags_sorted)) { |
|
| 774 | 774 | return $return; |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - if ( $tags_sorted !== $tags ) { |
|
| 777 | + if ($tags_sorted !== $tags) { |
|
| 778 | 778 | $tags = $tags_sorted; |
| 779 | - unset( $tags_sorted ); |
|
| 779 | + unset($tags_sorted); |
|
| 780 | 780 | } else { |
| 781 | - if ( 'RAND' === $args['order'] ) { |
|
| 782 | - shuffle( $tags ); |
|
| 781 | + if ('RAND' === $args['order']) { |
|
| 782 | + shuffle($tags); |
|
| 783 | 783 | } else { |
| 784 | 784 | // SQL cannot save you; this is a second (potentially different) sort on a subset of data. |
| 785 | - if ( 'name' === $args['orderby'] ) { |
|
| 786 | - uasort( $tags, '_wp_object_name_sort_cb' ); |
|
| 785 | + if ('name' === $args['orderby']) { |
|
| 786 | + uasort($tags, '_wp_object_name_sort_cb'); |
|
| 787 | 787 | } else { |
| 788 | - uasort( $tags, '_wp_object_count_sort_cb' ); |
|
| 788 | + uasort($tags, '_wp_object_count_sort_cb'); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | - if ( 'DESC' === $args['order'] ) { |
|
| 792 | - $tags = array_reverse( $tags, true ); |
|
| 791 | + if ('DESC' === $args['order']) { |
|
| 792 | + $tags = array_reverse($tags, true); |
|
| 793 | 793 | } |
| 794 | 794 | } |
| 795 | 795 | } |
| 796 | 796 | |
| 797 | - if ( $args['number'] > 0 ) |
|
| 798 | - $tags = array_slice( $tags, 0, $args['number'] ); |
|
| 797 | + if ($args['number'] > 0) |
|
| 798 | + $tags = array_slice($tags, 0, $args['number']); |
|
| 799 | 799 | |
| 800 | 800 | $counts = array(); |
| 801 | 801 | $real_counts = array(); // For the alt tag |
| 802 | - foreach ( (array) $tags as $key => $tag ) { |
|
| 803 | - $real_counts[ $key ] = $tag->count; |
|
| 804 | - $counts[ $key ] = call_user_func( $args['topic_count_scale_callback'], $tag->count ); |
|
| 802 | + foreach ((array) $tags as $key => $tag) { |
|
| 803 | + $real_counts[$key] = $tag->count; |
|
| 804 | + $counts[$key] = call_user_func($args['topic_count_scale_callback'], $tag->count); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | - $min_count = min( $counts ); |
|
| 808 | - $spread = max( $counts ) - $min_count; |
|
| 809 | - if ( $spread <= 0 ) |
|
| 807 | + $min_count = min($counts); |
|
| 808 | + $spread = max($counts) - $min_count; |
|
| 809 | + if ($spread <= 0) |
|
| 810 | 810 | $spread = 1; |
| 811 | 811 | $font_spread = $args['largest'] - $args['smallest']; |
| 812 | - if ( $font_spread < 0 ) |
|
| 812 | + if ($font_spread < 0) |
|
| 813 | 813 | $font_spread = 1; |
| 814 | 814 | $font_step = $font_spread / $spread; |
| 815 | 815 | |
| 816 | 816 | // Assemble the data that will be used to generate the tag cloud markup. |
| 817 | 817 | $tags_data = array(); |
| 818 | - foreach ( $tags as $key => $tag ) { |
|
| 819 | - $tag_id = isset( $tag->id ) ? $tag->id : $key; |
|
| 818 | + foreach ($tags as $key => $tag) { |
|
| 819 | + $tag_id = isset($tag->id) ? $tag->id : $key; |
|
| 820 | 820 | |
| 821 | - $count = $counts[ $key ]; |
|
| 822 | - $real_count = $real_counts[ $key ]; |
|
| 821 | + $count = $counts[$key]; |
|
| 822 | + $real_count = $real_counts[$key]; |
|
| 823 | 823 | |
| 824 | - if ( $translate_nooped_plural ) { |
|
| 825 | - $title = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) ); |
|
| 824 | + if ($translate_nooped_plural) { |
|
| 825 | + $title = sprintf(translate_nooped_plural($translate_nooped_plural, $real_count), number_format_i18n($real_count)); |
|
| 826 | 826 | } else { |
| 827 | - $title = call_user_func( $args['topic_count_text_callback'], $real_count, $tag, $args ); |
|
| 827 | + $title = call_user_func($args['topic_count_text_callback'], $real_count, $tag, $args); |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | $tags_data[] = array( |
@@ -834,8 +834,8 @@ discard block |
||
| 834 | 834 | 'title' => $title, |
| 835 | 835 | 'slug' => $tag->slug, |
| 836 | 836 | 'real_count' => $real_count, |
| 837 | - 'class' => 'tag-link-' . $tag_id, |
|
| 838 | - 'font_size' => $args['smallest'] + ( $count - $min_count ) * $font_step, |
|
| 837 | + 'class' => 'tag-link-'.$tag_id, |
|
| 838 | + 'font_size' => $args['smallest'] + ($count - $min_count) * $font_step, |
|
| 839 | 839 | ); |
| 840 | 840 | } |
| 841 | 841 | |
@@ -846,30 +846,30 @@ discard block |
||
| 846 | 846 | * |
| 847 | 847 | * @param array $tags_data An array of term data for term used to generate the tag cloud. |
| 848 | 848 | */ |
| 849 | - $tags_data = apply_filters( 'wp_generate_tag_cloud_data', $tags_data ); |
|
| 849 | + $tags_data = apply_filters('wp_generate_tag_cloud_data', $tags_data); |
|
| 850 | 850 | |
| 851 | 851 | $a = array(); |
| 852 | 852 | |
| 853 | 853 | // generate the output links array |
| 854 | - foreach ( $tags_data as $key => $tag_data ) { |
|
| 855 | - $a[] = "<a href='" . esc_url( $tag_data['url'] ) . "' class='" . esc_attr( $tag_data['class'] ) . "' title='" . esc_attr( $tag_data['title'] ) . "' style='font-size: " . esc_attr( str_replace( ',', '.', $tag_data['font_size'] ) . $args['unit'] ) . ";'>" . esc_html( $tag_data['name'] ) . "</a>"; |
|
| 854 | + foreach ($tags_data as $key => $tag_data) { |
|
| 855 | + $a[] = "<a href='".esc_url($tag_data['url'])."' class='".esc_attr($tag_data['class'])."' title='".esc_attr($tag_data['title'])."' style='font-size: ".esc_attr(str_replace(',', '.', $tag_data['font_size']).$args['unit']).";'>".esc_html($tag_data['name'])."</a>"; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | - switch ( $args['format'] ) { |
|
| 858 | + switch ($args['format']) { |
|
| 859 | 859 | case 'array' : |
| 860 | - $return =& $a; |
|
| 860 | + $return = & $a; |
|
| 861 | 861 | break; |
| 862 | 862 | case 'list' : |
| 863 | 863 | $return = "<ul class='wp-tag-cloud'>\n\t<li>"; |
| 864 | - $return .= join( "</li>\n\t<li>", $a ); |
|
| 864 | + $return .= join("</li>\n\t<li>", $a); |
|
| 865 | 865 | $return .= "</li>\n</ul>\n"; |
| 866 | 866 | break; |
| 867 | 867 | default : |
| 868 | - $return = join( $args['separator'], $a ); |
|
| 868 | + $return = join($args['separator'], $a); |
|
| 869 | 869 | break; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | - if ( $args['filter'] ) { |
|
| 872 | + if ($args['filter']) { |
|
| 873 | 873 | /** |
| 874 | 874 | * Filter the generated output of a tag cloud. |
| 875 | 875 | * |
@@ -886,7 +886,7 @@ discard block |
||
| 886 | 886 | * @param array $tags An array of terms used in the tag cloud. |
| 887 | 887 | * @param array $args An array of wp_generate_tag_cloud() arguments. |
| 888 | 888 | */ |
| 889 | - return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args ); |
|
| 889 | + return apply_filters('wp_generate_tag_cloud', $return, $tags, $args); |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | else |
@@ -900,8 +900,8 @@ discard block |
||
| 900 | 900 | * @access private |
| 901 | 901 | * @return int |
| 902 | 902 | */ |
| 903 | -function _wp_object_name_sort_cb( $a, $b ) { |
|
| 904 | - return strnatcasecmp( $a->name, $b->name ); |
|
| 903 | +function _wp_object_name_sort_cb($a, $b) { |
|
| 904 | + return strnatcasecmp($a->name, $b->name); |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -911,8 +911,8 @@ discard block |
||
| 911 | 911 | * @access private |
| 912 | 912 | * @return bool |
| 913 | 913 | */ |
| 914 | -function _wp_object_count_sort_cb( $a, $b ) { |
|
| 915 | - return ( $a->count > $b->count ); |
|
| 914 | +function _wp_object_count_sort_cb($a, $b) { |
|
| 915 | + return ($a->count > $b->count); |
|
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | // |
@@ -930,12 +930,12 @@ discard block |
||
| 930 | 930 | function walk_category_tree() { |
| 931 | 931 | $args = func_get_args(); |
| 932 | 932 | // the user's options are the third parameter |
| 933 | - if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) { |
|
| 933 | + if (empty($args[2]['walker']) || ! ($args[2]['walker'] instanceof Walker)) { |
|
| 934 | 934 | $walker = new Walker_Category; |
| 935 | 935 | } else { |
| 936 | 936 | $walker = $args[2]['walker']; |
| 937 | 937 | } |
| 938 | - return call_user_func_array( array( $walker, 'walk' ), $args ); |
|
| 938 | + return call_user_func_array(array($walker, 'walk'), $args); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
@@ -949,12 +949,12 @@ discard block |
||
| 949 | 949 | function walk_category_dropdown_tree() { |
| 950 | 950 | $args = func_get_args(); |
| 951 | 951 | // the user's options are the third parameter |
| 952 | - if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) { |
|
| 952 | + if (empty($args[2]['walker']) || ! ($args[2]['walker'] instanceof Walker)) { |
|
| 953 | 953 | $walker = new Walker_CategoryDropdown; |
| 954 | 954 | } else { |
| 955 | 955 | $walker = $args[2]['walker']; |
| 956 | 956 | } |
| 957 | - return call_user_func_array( array( $walker, 'walk' ), $args ); |
|
| 957 | + return call_user_func_array(array($walker, 'walk'), $args); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | * @todo Decouple this |
| 983 | 983 | * @var array |
| 984 | 984 | */ |
| 985 | - public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); |
|
| 985 | + public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); |
|
| 986 | 986 | |
| 987 | 987 | /** |
| 988 | 988 | * Starts the list before the elements are added. |
@@ -996,8 +996,8 @@ discard block |
||
| 996 | 996 | * @param array $args An array of arguments. Will only append content if style argument value is 'list'. |
| 997 | 997 | * @see wp_list_categories() |
| 998 | 998 | */ |
| 999 | - public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
| 1000 | - if ( 'list' != $args['style'] ) |
|
| 999 | + public function start_lvl(&$output, $depth = 0, $args = array()) { |
|
| 1000 | + if ('list' != $args['style']) |
|
| 1001 | 1001 | return; |
| 1002 | 1002 | |
| 1003 | 1003 | $indent = str_repeat("\t", $depth); |
@@ -1016,8 +1016,8 @@ discard block |
||
| 1016 | 1016 | * @param array $args An array of arguments. Will only append content if style argument value is 'list'. |
| 1017 | 1017 | * @wsee wp_list_categories() |
| 1018 | 1018 | */ |
| 1019 | - public function end_lvl( &$output, $depth = 0, $args = array() ) { |
|
| 1020 | - if ( 'list' != $args['style'] ) |
|
| 1019 | + public function end_lvl(&$output, $depth = 0, $args = array()) { |
|
| 1020 | + if ('list' != $args['style']) |
|
| 1021 | 1021 | return; |
| 1022 | 1022 | |
| 1023 | 1023 | $indent = str_repeat("\t", $depth); |
@@ -1037,21 +1037,21 @@ discard block |
||
| 1037 | 1037 | * @param array $args An array of arguments. @see wp_list_categories() |
| 1038 | 1038 | * @param int $id ID of the current category. |
| 1039 | 1039 | */ |
| 1040 | - public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
|
| 1040 | + public function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0) { |
|
| 1041 | 1041 | /** This filter is documented in wp-includes/category-template.php */ |
| 1042 | 1042 | $cat_name = apply_filters( |
| 1043 | 1043 | 'list_cats', |
| 1044 | - esc_attr( $category->name ), |
|
| 1044 | + esc_attr($category->name), |
|
| 1045 | 1045 | $category |
| 1046 | 1046 | ); |
| 1047 | 1047 | |
| 1048 | 1048 | // Don't generate an element if the category name is empty. |
| 1049 | - if ( ! $cat_name ) { |
|
| 1049 | + if ( ! $cat_name) { |
|
| 1050 | 1050 | return; |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | - $link = '<a href="' . esc_url( get_term_link( $category ) ) . '" '; |
|
| 1054 | - if ( $args['use_desc_for_title'] && ! empty( $category->description ) ) { |
|
| 1053 | + $link = '<a href="'.esc_url(get_term_link($category)).'" '; |
|
| 1054 | + if ($args['use_desc_for_title'] && ! empty($category->description)) { |
|
| 1055 | 1055 | /** |
| 1056 | 1056 | * Filter the category description for display. |
| 1057 | 1057 | * |
@@ -1060,58 +1060,58 @@ discard block |
||
| 1060 | 1060 | * @param string $description Category description. |
| 1061 | 1061 | * @param object $category Category object. |
| 1062 | 1062 | */ |
| 1063 | - $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"'; |
|
| 1063 | + $link .= 'title="'.esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))).'"'; |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | $link .= '>'; |
| 1067 | - $link .= $cat_name . '</a>'; |
|
| 1067 | + $link .= $cat_name.'</a>'; |
|
| 1068 | 1068 | |
| 1069 | - if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) { |
|
| 1069 | + if ( ! empty($args['feed_image']) || ! empty($args['feed'])) { |
|
| 1070 | 1070 | $link .= ' '; |
| 1071 | 1071 | |
| 1072 | - if ( empty( $args['feed_image'] ) ) { |
|
| 1072 | + if (empty($args['feed_image'])) { |
|
| 1073 | 1073 | $link .= '('; |
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | - $link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"'; |
|
| 1076 | + $link .= '<a href="'.esc_url(get_term_feed_link($category->term_id, $category->taxonomy, $args['feed_type'])).'"'; |
|
| 1077 | 1077 | |
| 1078 | - if ( empty( $args['feed'] ) ) { |
|
| 1079 | - $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"'; |
|
| 1078 | + if (empty($args['feed'])) { |
|
| 1079 | + $alt = ' alt="'.sprintf(__('Feed for all posts filed under %s'), $cat_name).'"'; |
|
| 1080 | 1080 | } else { |
| 1081 | - $alt = ' alt="' . $args['feed'] . '"'; |
|
| 1081 | + $alt = ' alt="'.$args['feed'].'"'; |
|
| 1082 | 1082 | $name = $args['feed']; |
| 1083 | - $link .= empty( $args['title'] ) ? '' : $args['title']; |
|
| 1083 | + $link .= empty($args['title']) ? '' : $args['title']; |
|
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | $link .= '>'; |
| 1087 | 1087 | |
| 1088 | - if ( empty( $args['feed_image'] ) ) { |
|
| 1088 | + if (empty($args['feed_image'])) { |
|
| 1089 | 1089 | $link .= $name; |
| 1090 | 1090 | } else { |
| 1091 | - $link .= "<img src='" . $args['feed_image'] . "'$alt" . ' />'; |
|
| 1091 | + $link .= "<img src='".$args['feed_image']."'$alt".' />'; |
|
| 1092 | 1092 | } |
| 1093 | 1093 | $link .= '</a>'; |
| 1094 | 1094 | |
| 1095 | - if ( empty( $args['feed_image'] ) ) { |
|
| 1095 | + if (empty($args['feed_image'])) { |
|
| 1096 | 1096 | $link .= ')'; |
| 1097 | 1097 | } |
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | - if ( ! empty( $args['show_count'] ) ) { |
|
| 1101 | - $link .= ' (' . number_format_i18n( $category->count ) . ')'; |
|
| 1100 | + if ( ! empty($args['show_count'])) { |
|
| 1101 | + $link .= ' ('.number_format_i18n($category->count).')'; |
|
| 1102 | 1102 | } |
| 1103 | - if ( 'list' == $args['style'] ) { |
|
| 1103 | + if ('list' == $args['style']) { |
|
| 1104 | 1104 | $output .= "\t<li"; |
| 1105 | 1105 | $css_classes = array( |
| 1106 | 1106 | 'cat-item', |
| 1107 | - 'cat-item-' . $category->term_id, |
|
| 1107 | + 'cat-item-'.$category->term_id, |
|
| 1108 | 1108 | ); |
| 1109 | 1109 | |
| 1110 | - if ( ! empty( $args['current_category'] ) ) { |
|
| 1111 | - $_current_category = get_term( $args['current_category'], $category->taxonomy ); |
|
| 1112 | - if ( $category->term_id == $args['current_category'] ) { |
|
| 1110 | + if ( ! empty($args['current_category'])) { |
|
| 1111 | + $_current_category = get_term($args['current_category'], $category->taxonomy); |
|
| 1112 | + if ($category->term_id == $args['current_category']) { |
|
| 1113 | 1113 | $css_classes[] = 'current-cat'; |
| 1114 | - } elseif ( $category->term_id == $_current_category->parent ) { |
|
| 1114 | + } elseif ($category->term_id == $_current_category->parent) { |
|
| 1115 | 1115 | $css_classes[] = 'current-cat-parent'; |
| 1116 | 1116 | } |
| 1117 | 1117 | } |
@@ -1128,9 +1128,9 @@ discard block |
||
| 1128 | 1128 | * @param int $depth Depth of page, used for padding. |
| 1129 | 1129 | * @param array $args An array of wp_list_categories() arguments. |
| 1130 | 1130 | */ |
| 1131 | - $css_classes = implode( ' ', apply_filters( 'category_css_class', $css_classes, $category, $depth, $args ) ); |
|
| 1131 | + $css_classes = implode(' ', apply_filters('category_css_class', $css_classes, $category, $depth, $args)); |
|
| 1132 | 1132 | |
| 1133 | - $output .= ' class="' . $css_classes . '"'; |
|
| 1133 | + $output .= ' class="'.$css_classes.'"'; |
|
| 1134 | 1134 | $output .= ">$link\n"; |
| 1135 | 1135 | } else { |
| 1136 | 1136 | $output .= "\t$link<br />\n"; |
@@ -1149,8 +1149,8 @@ discard block |
||
| 1149 | 1149 | * @param int $depth Depth of category. Not used. |
| 1150 | 1150 | * @param array $args An array of arguments. Only uses 'list' for whether should append to output. @see wp_list_categories() |
| 1151 | 1151 | */ |
| 1152 | - public function end_el( &$output, $page, $depth = 0, $args = array() ) { |
|
| 1153 | - if ( 'list' != $args['style'] ) |
|
| 1152 | + public function end_el(&$output, $page, $depth = 0, $args = array()) { |
|
| 1153 | + if ('list' != $args['style']) |
|
| 1154 | 1154 | return; |
| 1155 | 1155 | |
| 1156 | 1156 | $output .= "</li>\n"; |
@@ -1179,7 +1179,7 @@ discard block |
||
| 1179 | 1179 | * @todo Decouple this |
| 1180 | 1180 | * @var array |
| 1181 | 1181 | */ |
| 1182 | - public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); |
|
| 1182 | + public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); |
|
| 1183 | 1183 | |
| 1184 | 1184 | /** |
| 1185 | 1185 | * Start the element output. |
@@ -1193,26 +1193,26 @@ discard block |
||
| 1193 | 1193 | * @param array $args Uses 'selected', 'show_count', and 'value_field' keys, if they exist. |
| 1194 | 1194 | * See {@see wp_dropdown_categories()}. |
| 1195 | 1195 | */ |
| 1196 | - public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
|
| 1196 | + public function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0) { |
|
| 1197 | 1197 | $pad = str_repeat(' ', $depth * 3); |
| 1198 | 1198 | |
| 1199 | 1199 | /** This filter is documented in wp-includes/category-template.php */ |
| 1200 | - $cat_name = apply_filters( 'list_cats', $category->name, $category ); |
|
| 1200 | + $cat_name = apply_filters('list_cats', $category->name, $category); |
|
| 1201 | 1201 | |
| 1202 | - if ( isset( $args['value_field'] ) && isset( $category->{$args['value_field']} ) ) { |
|
| 1202 | + if (isset($args['value_field']) && isset($category->{$args['value_field']} )) { |
|
| 1203 | 1203 | $value_field = $args['value_field']; |
| 1204 | 1204 | } else { |
| 1205 | 1205 | $value_field = 'term_id'; |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | - $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . "\""; |
|
| 1208 | + $output .= "\t<option class=\"level-$depth\" value=\"".esc_attr($category->{$value_field} )."\""; |
|
| 1209 | 1209 | |
| 1210 | - if ( $category->{$value_field} == $args['selected'] ) |
|
| 1210 | + if ($category->{$value_field} == $args['selected']) |
|
| 1211 | 1211 | $output .= ' selected="selected"'; |
| 1212 | 1212 | $output .= '>'; |
| 1213 | 1213 | $output .= $pad.$cat_name; |
| 1214 | - if ( $args['show_count'] ) |
|
| 1215 | - $output .= ' ('. number_format_i18n( $category->count ) .')'; |
|
| 1214 | + if ($args['show_count']) |
|
| 1215 | + $output .= ' ('.number_format_i18n($category->count).')'; |
|
| 1216 | 1216 | $output .= "</option>\n"; |
| 1217 | 1217 | } |
| 1218 | 1218 | } |
@@ -1230,13 +1230,13 @@ discard block |
||
| 1230 | 1230 | * @param int|object $tag Tag ID or object. |
| 1231 | 1231 | * @return string Link on success, empty string if tag does not exist. |
| 1232 | 1232 | */ |
| 1233 | -function get_tag_link( $tag ) { |
|
| 1234 | - if ( ! is_object( $tag ) ) |
|
| 1233 | +function get_tag_link($tag) { |
|
| 1234 | + if ( ! is_object($tag)) |
|
| 1235 | 1235 | $tag = (int) $tag; |
| 1236 | 1236 | |
| 1237 | - $tag = get_term_link( $tag, 'post_tag' ); |
|
| 1237 | + $tag = get_term_link($tag, 'post_tag'); |
|
| 1238 | 1238 | |
| 1239 | - if ( is_wp_error( $tag ) ) |
|
| 1239 | + if (is_wp_error($tag)) |
|
| 1240 | 1240 | return ''; |
| 1241 | 1241 | |
| 1242 | 1242 | return $tag; |
@@ -1250,7 +1250,7 @@ discard block |
||
| 1250 | 1250 | * @param int $id Post ID. |
| 1251 | 1251 | * @return array|false|WP_Error Array of tag objects on success, false on failure. |
| 1252 | 1252 | */ |
| 1253 | -function get_the_tags( $id = 0 ) { |
|
| 1253 | +function get_the_tags($id = 0) { |
|
| 1254 | 1254 | |
| 1255 | 1255 | /** |
| 1256 | 1256 | * Filter the array of tags for the given post. |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | * |
| 1262 | 1262 | * @param array $terms An array of tags for the given post. |
| 1263 | 1263 | */ |
| 1264 | - return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) ); |
|
| 1264 | + return apply_filters('get_the_tags', get_the_terms($id, 'post_tag')); |
|
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | /** |
@@ -1275,7 +1275,7 @@ discard block |
||
| 1275 | 1275 | * @param int $id Optional. Post ID. Defaults to the current post. |
| 1276 | 1276 | * @return string|false|WP_Error A list of tags on success, false if there are no terms, WP_Error on failure. |
| 1277 | 1277 | */ |
| 1278 | -function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) { |
|
| 1278 | +function get_the_tag_list($before = '', $sep = '', $after = '', $id = 0) { |
|
| 1279 | 1279 | |
| 1280 | 1280 | /** |
| 1281 | 1281 | * Filter the tags list for a given post. |
@@ -1288,7 +1288,7 @@ discard block |
||
| 1288 | 1288 | * @param string $after String to use after tags. |
| 1289 | 1289 | * @param int $id Post ID. |
| 1290 | 1290 | */ |
| 1291 | - return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id ); |
|
| 1291 | + return apply_filters('the_tags', get_the_term_list($id, 'post_tag', $before, $sep, $after), $before, $sep, $after, $id); |
|
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | /** |
@@ -1300,8 +1300,8 @@ discard block |
||
| 1300 | 1300 | * @param string $sep Optional. Separate items using this. |
| 1301 | 1301 | * @param string $after Optional. After list. |
| 1302 | 1302 | */ |
| 1303 | -function the_tags( $before = null, $sep = ', ', $after = '' ) { |
|
| 1304 | - if ( null === $before ) |
|
| 1303 | +function the_tags($before = null, $sep = ', ', $after = '') { |
|
| 1304 | + if (null === $before) |
|
| 1305 | 1305 | $before = __('Tags: '); |
| 1306 | 1306 | echo get_the_tag_list($before, $sep, $after); |
| 1307 | 1307 | } |
@@ -1314,8 +1314,8 @@ discard block |
||
| 1314 | 1314 | * @param int $tag Optional. Tag ID. Will use global tag ID by default. |
| 1315 | 1315 | * @return string Tag description, available. |
| 1316 | 1316 | */ |
| 1317 | -function tag_description( $tag = 0 ) { |
|
| 1318 | - return term_description( $tag ); |
|
| 1317 | +function tag_description($tag = 0) { |
|
| 1318 | + return term_description($tag); |
|
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | 1321 | /** |
@@ -1327,16 +1327,16 @@ discard block |
||
| 1327 | 1327 | * @param string $taxonomy Optional taxonomy name. Defaults to 'post_tag'. |
| 1328 | 1328 | * @return string Term description, available. |
| 1329 | 1329 | */ |
| 1330 | -function term_description( $term = 0, $taxonomy = 'post_tag' ) { |
|
| 1331 | - if ( ! $term && ( is_tax() || is_tag() || is_category() ) ) { |
|
| 1330 | +function term_description($term = 0, $taxonomy = 'post_tag') { |
|
| 1331 | + if ( ! $term && (is_tax() || is_tag() || is_category())) { |
|
| 1332 | 1332 | $term = get_queried_object(); |
| 1333 | - if ( $term ) { |
|
| 1333 | + if ($term) { |
|
| 1334 | 1334 | $taxonomy = $term->taxonomy; |
| 1335 | 1335 | $term = $term->term_id; |
| 1336 | 1336 | } |
| 1337 | 1337 | } |
| 1338 | - $description = get_term_field( 'description', $term, $taxonomy ); |
|
| 1339 | - return is_wp_error( $description ) ? '' : $description; |
|
| 1338 | + $description = get_term_field('description', $term, $taxonomy); |
|
| 1339 | + return is_wp_error($description) ? '' : $description; |
|
| 1340 | 1340 | } |
| 1341 | 1341 | |
| 1342 | 1342 | /** |
@@ -1349,14 +1349,14 @@ discard block |
||
| 1349 | 1349 | * @return array|false|WP_Error Array of term objects on success, false if there are no terms |
| 1350 | 1350 | * or the post does not exist, WP_Error on failure. |
| 1351 | 1351 | */ |
| 1352 | -function get_the_terms( $post, $taxonomy ) { |
|
| 1353 | - if ( ! $post = get_post( $post ) ) |
|
| 1352 | +function get_the_terms($post, $taxonomy) { |
|
| 1353 | + if ( ! $post = get_post($post)) |
|
| 1354 | 1354 | return false; |
| 1355 | 1355 | |
| 1356 | - $terms = get_object_term_cache( $post->ID, $taxonomy ); |
|
| 1357 | - if ( false === $terms ) { |
|
| 1358 | - $terms = wp_get_object_terms( $post->ID, $taxonomy ); |
|
| 1359 | - wp_cache_add($post->ID, $terms, $taxonomy . '_relationships'); |
|
| 1356 | + $terms = get_object_term_cache($post->ID, $taxonomy); |
|
| 1357 | + if (false === $terms) { |
|
| 1358 | + $terms = wp_get_object_terms($post->ID, $taxonomy); |
|
| 1359 | + wp_cache_add($post->ID, $terms, $taxonomy.'_relationships'); |
|
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | 1362 | /** |
@@ -1368,9 +1368,9 @@ discard block |
||
| 1368 | 1368 | * @param int $post_id Post ID. |
| 1369 | 1369 | * @param string $taxonomy Name of the taxonomy. |
| 1370 | 1370 | */ |
| 1371 | - $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy ); |
|
| 1371 | + $terms = apply_filters('get_the_terms', $terms, $post->ID, $taxonomy); |
|
| 1372 | 1372 | |
| 1373 | - if ( empty( $terms ) ) |
|
| 1373 | + if (empty($terms)) |
|
| 1374 | 1374 | return false; |
| 1375 | 1375 | |
| 1376 | 1376 | return $terms; |
@@ -1388,23 +1388,23 @@ discard block |
||
| 1388 | 1388 | * @param string $after Optional. After list. |
| 1389 | 1389 | * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure. |
| 1390 | 1390 | */ |
| 1391 | -function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { |
|
| 1392 | - $terms = get_the_terms( $id, $taxonomy ); |
|
| 1391 | +function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '') { |
|
| 1392 | + $terms = get_the_terms($id, $taxonomy); |
|
| 1393 | 1393 | |
| 1394 | - if ( is_wp_error( $terms ) ) |
|
| 1394 | + if (is_wp_error($terms)) |
|
| 1395 | 1395 | return $terms; |
| 1396 | 1396 | |
| 1397 | - if ( empty( $terms ) ) |
|
| 1397 | + if (empty($terms)) |
|
| 1398 | 1398 | return false; |
| 1399 | 1399 | |
| 1400 | 1400 | $links = array(); |
| 1401 | 1401 | |
| 1402 | - foreach ( $terms as $term ) { |
|
| 1403 | - $link = get_term_link( $term, $taxonomy ); |
|
| 1404 | - if ( is_wp_error( $link ) ) { |
|
| 1402 | + foreach ($terms as $term) { |
|
| 1403 | + $link = get_term_link($term, $taxonomy); |
|
| 1404 | + if (is_wp_error($link)) { |
|
| 1405 | 1405 | return $link; |
| 1406 | 1406 | } |
| 1407 | - $links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; |
|
| 1407 | + $links[] = '<a href="'.esc_url($link).'" rel="tag">'.$term->name.'</a>'; |
|
| 1408 | 1408 | } |
| 1409 | 1409 | |
| 1410 | 1410 | /** |
@@ -1417,9 +1417,9 @@ discard block |
||
| 1417 | 1417 | * |
| 1418 | 1418 | * @param array $links An array of term links. |
| 1419 | 1419 | */ |
| 1420 | - $term_links = apply_filters( "term_links-$taxonomy", $links ); |
|
| 1420 | + $term_links = apply_filters("term_links-$taxonomy", $links); |
|
| 1421 | 1421 | |
| 1422 | - return $before . join( $sep, $term_links ) . $after; |
|
| 1422 | + return $before.join($sep, $term_links).$after; |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1434,10 +1434,10 @@ discard block |
||
| 1434 | 1434 | * @param string $after Optional. After list. |
| 1435 | 1435 | * @return false|void False on WordPress error. |
| 1436 | 1436 | */ |
| 1437 | -function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) { |
|
| 1438 | - $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after ); |
|
| 1437 | +function the_terms($id, $taxonomy, $before = '', $sep = ', ', $after = '') { |
|
| 1438 | + $term_list = get_the_term_list($id, $taxonomy, $before, $sep, $after); |
|
| 1439 | 1439 | |
| 1440 | - if ( is_wp_error( $term_list ) ) |
|
| 1440 | + if (is_wp_error($term_list)) |
|
| 1441 | 1441 | return false; |
| 1442 | 1442 | |
| 1443 | 1443 | /** |
@@ -1451,7 +1451,7 @@ discard block |
||
| 1451 | 1451 | * @param string $sep String to use between the terms. |
| 1452 | 1452 | * @param string $after String to use after the terms. |
| 1453 | 1453 | */ |
| 1454 | - echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after ); |
|
| 1454 | + echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | /** |
@@ -1463,8 +1463,8 @@ discard block |
||
| 1463 | 1463 | * @param int|object $post Optional. Post to check instead of the current post. |
| 1464 | 1464 | * @return bool True if the current post has any of the given categories (or any category, if no category specified). |
| 1465 | 1465 | */ |
| 1466 | -function has_category( $category = '', $post = null ) { |
|
| 1467 | - return has_term( $category, 'category', $post ); |
|
| 1466 | +function has_category($category = '', $post = null) { |
|
| 1467 | + return has_term($category, 'category', $post); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | 1470 | /** |
@@ -1484,8 +1484,8 @@ discard block |
||
| 1484 | 1484 | * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0) |
| 1485 | 1485 | * @return bool True if the current post has any of the given tags (or any tag, if no tag specified). |
| 1486 | 1486 | */ |
| 1487 | -function has_tag( $tag = '', $post = null ) { |
|
| 1488 | - return has_term( $tag, 'post_tag', $post ); |
|
| 1487 | +function has_tag($tag = '', $post = null) { |
|
| 1488 | + return has_term($tag, 'post_tag', $post); |
|
| 1489 | 1489 | } |
| 1490 | 1490 | |
| 1491 | 1491 | /** |
@@ -1502,14 +1502,14 @@ discard block |
||
| 1502 | 1502 | * @param int|object $post Optional. Post to check instead of the current post. |
| 1503 | 1503 | * @return bool True if the current post has any of the given tags (or any tag, if no tag specified). |
| 1504 | 1504 | */ |
| 1505 | -function has_term( $term = '', $taxonomy = '', $post = null ) { |
|
| 1505 | +function has_term($term = '', $taxonomy = '', $post = null) { |
|
| 1506 | 1506 | $post = get_post($post); |
| 1507 | 1507 | |
| 1508 | - if ( !$post ) |
|
| 1508 | + if ( ! $post) |
|
| 1509 | 1509 | return false; |
| 1510 | 1510 | |
| 1511 | - $r = is_object_in_term( $post->ID, $taxonomy, $term ); |
|
| 1512 | - if ( is_wp_error( $r ) ) |
|
| 1511 | + $r = is_object_in_term($post->ID, $taxonomy, $term); |
|
| 1512 | + if (is_wp_error($r)) |
|
| 1513 | 1513 | return false; |
| 1514 | 1514 | |
| 1515 | 1515 | return $r; |
@@ -16,13 +16,15 @@ discard block |
||
| 16 | 16 | * @return string Link on success, empty string if category does not exist. |
| 17 | 17 | */ |
| 18 | 18 | function get_category_link( $category ) { |
| 19 | - if ( ! is_object( $category ) ) |
|
| 20 | - $category = (int) $category; |
|
| 19 | + if ( ! is_object( $category ) ) { |
|
| 20 | + $category = (int) $category; |
|
| 21 | + } |
|
| 21 | 22 | |
| 22 | 23 | $category = get_term_link( $category, 'category' ); |
| 23 | 24 | |
| 24 | - if ( is_wp_error( $category ) ) |
|
| 25 | - return ''; |
|
| 25 | + if ( is_wp_error( $category ) ) { |
|
| 26 | + return ''; |
|
| 27 | + } |
|
| 26 | 28 | |
| 27 | 29 | return $category; |
| 28 | 30 | } |
@@ -42,23 +44,26 @@ discard block |
||
| 42 | 44 | function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) { |
| 43 | 45 | $chain = ''; |
| 44 | 46 | $parent = get_term( $id, 'category' ); |
| 45 | - if ( is_wp_error( $parent ) ) |
|
| 46 | - return $parent; |
|
| 47 | + if ( is_wp_error( $parent ) ) { |
|
| 48 | + return $parent; |
|
| 49 | + } |
|
| 47 | 50 | |
| 48 | - if ( $nicename ) |
|
| 49 | - $name = $parent->slug; |
|
| 50 | - else |
|
| 51 | - $name = $parent->name; |
|
| 51 | + if ( $nicename ) { |
|
| 52 | + $name = $parent->slug; |
|
| 53 | + } else { |
|
| 54 | + $name = $parent->name; |
|
| 55 | + } |
|
| 52 | 56 | |
| 53 | 57 | if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) { |
| 54 | 58 | $visited[] = $parent->parent; |
| 55 | 59 | $chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited ); |
| 56 | 60 | } |
| 57 | 61 | |
| 58 | - if ( $link ) |
|
| 59 | - $chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">'.$name.'</a>' . $separator; |
|
| 60 | - else |
|
| 61 | - $chain .= $name.$separator; |
|
| 62 | + if ( $link ) { |
|
| 63 | + $chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">'.$name.'</a>' . $separator; |
|
| 64 | + } else { |
|
| 65 | + $chain .= $name.$separator; |
|
| 66 | + } |
|
| 62 | 67 | return $chain; |
| 63 | 68 | } |
| 64 | 69 | |
@@ -77,8 +82,9 @@ discard block |
||
| 77 | 82 | */ |
| 78 | 83 | function get_the_category( $id = false ) { |
| 79 | 84 | $categories = get_the_terms( $id, 'category' ); |
| 80 | - if ( ! $categories || is_wp_error( $categories ) ) |
|
| 81 | - $categories = array(); |
|
| 85 | + if ( ! $categories || is_wp_error( $categories ) ) { |
|
| 86 | + $categories = array(); |
|
| 87 | + } |
|
| 82 | 88 | |
| 83 | 89 | $categories = array_values( $categories ); |
| 84 | 90 | |
@@ -127,13 +133,14 @@ discard block |
||
| 127 | 133 | * @return int |
| 128 | 134 | */ |
| 129 | 135 | function _usort_terms_by_ID( $a, $b ) { |
| 130 | - if ( $a->term_id > $b->term_id ) |
|
| 131 | - return 1; |
|
| 132 | - elseif ( $a->term_id < $b->term_id ) |
|
| 133 | - return -1; |
|
| 134 | - else |
|
| 135 | - return 0; |
|
| 136 | -} |
|
| 136 | + if ( $a->term_id > $b->term_id ) { |
|
| 137 | + return 1; |
|
| 138 | + } elseif ( $a->term_id < $b->term_id ) { |
|
| 139 | + return -1; |
|
| 140 | + } else { |
|
| 141 | + return 0; |
|
| 142 | + } |
|
| 143 | + } |
|
| 137 | 144 | |
| 138 | 145 | /** |
| 139 | 146 | * Retrieve category name based on category ID. |
@@ -147,8 +154,9 @@ discard block |
||
| 147 | 154 | $cat_ID = (int) $cat_ID; |
| 148 | 155 | $category = get_term( $cat_ID, 'category' ); |
| 149 | 156 | |
| 150 | - if ( is_wp_error( $category ) ) |
|
| 151 | - return $category; |
|
| 157 | + if ( is_wp_error( $category ) ) { |
|
| 158 | + return $category; |
|
| 159 | + } |
|
| 152 | 160 | |
| 153 | 161 | return ( $category ) ? $category->name : ''; |
| 154 | 162 | } |
@@ -187,14 +195,16 @@ discard block |
||
| 187 | 195 | $thelist .= "\n\t<li>"; |
| 188 | 196 | switch ( strtolower( $parents ) ) { |
| 189 | 197 | case 'multiple': |
| 190 | - if ( $category->parent ) |
|
| 191 | - $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 198 | + if ( $category->parent ) { |
|
| 199 | + $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 200 | + } |
|
| 192 | 201 | $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
| 193 | 202 | break; |
| 194 | 203 | case 'single': |
| 195 | 204 | $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
| 196 | - if ( $category->parent ) |
|
| 197 | - $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 205 | + if ( $category->parent ) { |
|
| 206 | + $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 207 | + } |
|
| 198 | 208 | $thelist .= $category->name.'</a></li>'; |
| 199 | 209 | break; |
| 200 | 210 | case '': |
@@ -206,18 +216,21 @@ discard block |
||
| 206 | 216 | } else { |
| 207 | 217 | $i = 0; |
| 208 | 218 | foreach ( $categories as $category ) { |
| 209 | - if ( 0 < $i ) |
|
| 210 | - $thelist .= $separator; |
|
| 219 | + if ( 0 < $i ) { |
|
| 220 | + $thelist .= $separator; |
|
| 221 | + } |
|
| 211 | 222 | switch ( strtolower( $parents ) ) { |
| 212 | 223 | case 'multiple': |
| 213 | - if ( $category->parent ) |
|
| 214 | - $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 224 | + if ( $category->parent ) { |
|
| 225 | + $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 226 | + } |
|
| 215 | 227 | $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
| 216 | 228 | break; |
| 217 | 229 | case 'single': |
| 218 | 230 | $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
| 219 | - if ( $category->parent ) |
|
| 220 | - $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 231 | + if ( $category->parent ) { |
|
| 232 | + $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 233 | + } |
|
| 221 | 234 | $thelist .= "$category->name</a>"; |
| 222 | 235 | break; |
| 223 | 236 | case '': |
@@ -260,8 +273,9 @@ discard block |
||
| 260 | 273 | * @return bool True if the current post is in any of the given categories. |
| 261 | 274 | */ |
| 262 | 275 | function in_category( $category, $post = null ) { |
| 263 | - if ( empty( $category ) ) |
|
| 264 | - return false; |
|
| 276 | + if ( empty( $category ) ) { |
|
| 277 | + return false; |
|
| 278 | + } |
|
| 265 | 279 | |
| 266 | 280 | return has_category( $category, $post ); |
| 267 | 281 | } |
@@ -505,16 +519,18 @@ discard block |
||
| 505 | 519 | |
| 506 | 520 | $r = wp_parse_args( $args, $defaults ); |
| 507 | 521 | |
| 508 | - if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) |
|
| 509 | - $r['pad_counts'] = true; |
|
| 522 | + if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) { |
|
| 523 | + $r['pad_counts'] = true; |
|
| 524 | + } |
|
| 510 | 525 | |
| 511 | 526 | if ( true == $r['hierarchical'] ) { |
| 512 | 527 | $r['exclude_tree'] = $r['exclude']; |
| 513 | 528 | $r['exclude'] = ''; |
| 514 | 529 | } |
| 515 | 530 | |
| 516 | - if ( ! isset( $r['class'] ) ) |
|
| 517 | - $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy']; |
|
| 531 | + if ( ! isset( $r['class'] ) ) { |
|
| 532 | + $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy']; |
|
| 533 | + } |
|
| 518 | 534 | |
| 519 | 535 | if ( ! taxonomy_exists( $r['taxonomy'] ) ) { |
| 520 | 536 | return false; |
@@ -584,8 +600,9 @@ discard block |
||
| 584 | 600 | $output .= walk_category_tree( $categories, $depth, $r ); |
| 585 | 601 | } |
| 586 | 602 | |
| 587 | - if ( $r['title_li'] && 'list' == $r['style'] ) |
|
| 588 | - $output .= '</ul></li>'; |
|
| 603 | + if ( $r['title_li'] && 'list' == $r['style'] ) { |
|
| 604 | + $output .= '</ul></li>'; |
|
| 605 | + } |
|
| 589 | 606 | |
| 590 | 607 | /** |
| 591 | 608 | * Filter the HTML output of a taxonomy list. |
@@ -649,16 +666,19 @@ discard block |
||
| 649 | 666 | |
| 650 | 667 | $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags |
| 651 | 668 | |
| 652 | - if ( empty( $tags ) || is_wp_error( $tags ) ) |
|
| 653 | - return; |
|
| 669 | + if ( empty( $tags ) || is_wp_error( $tags ) ) { |
|
| 670 | + return; |
|
| 671 | + } |
|
| 654 | 672 | |
| 655 | 673 | foreach ( $tags as $key => $tag ) { |
| 656 | - if ( 'edit' == $args['link'] ) |
|
| 657 | - $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] ); |
|
| 658 | - else |
|
| 659 | - $link = get_term_link( intval($tag->term_id), $tag->taxonomy ); |
|
| 660 | - if ( is_wp_error( $link ) ) |
|
| 661 | - return; |
|
| 674 | + if ( 'edit' == $args['link'] ) { |
|
| 675 | + $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] ); |
|
| 676 | + } else { |
|
| 677 | + $link = get_term_link( intval($tag->term_id), $tag->taxonomy ); |
|
| 678 | + } |
|
| 679 | + if ( is_wp_error( $link ) ) { |
|
| 680 | + return; |
|
| 681 | + } |
|
| 662 | 682 | |
| 663 | 683 | $tags[ $key ]->link = $link; |
| 664 | 684 | $tags[ $key ]->id = $tag->term_id; |
@@ -676,8 +696,9 @@ discard block |
||
| 676 | 696 | */ |
| 677 | 697 | $return = apply_filters( 'wp_tag_cloud', $return, $args ); |
| 678 | 698 | |
| 679 | - if ( 'array' == $args['format'] || empty($args['echo']) ) |
|
| 680 | - return $return; |
|
| 699 | + if ( 'array' == $args['format'] || empty($args['echo']) ) { |
|
| 700 | + return $return; |
|
| 701 | + } |
|
| 681 | 702 | |
| 682 | 703 | echo $return; |
| 683 | 704 | } |
@@ -794,8 +815,9 @@ discard block |
||
| 794 | 815 | } |
| 795 | 816 | } |
| 796 | 817 | |
| 797 | - if ( $args['number'] > 0 ) |
|
| 798 | - $tags = array_slice( $tags, 0, $args['number'] ); |
|
| 818 | + if ( $args['number'] > 0 ) { |
|
| 819 | + $tags = array_slice( $tags, 0, $args['number'] ); |
|
| 820 | + } |
|
| 799 | 821 | |
| 800 | 822 | $counts = array(); |
| 801 | 823 | $real_counts = array(); // For the alt tag |
@@ -806,11 +828,13 @@ discard block |
||
| 806 | 828 | |
| 807 | 829 | $min_count = min( $counts ); |
| 808 | 830 | $spread = max( $counts ) - $min_count; |
| 809 | - if ( $spread <= 0 ) |
|
| 810 | - $spread = 1; |
|
| 831 | + if ( $spread <= 0 ) { |
|
| 832 | + $spread = 1; |
|
| 833 | + } |
|
| 811 | 834 | $font_spread = $args['largest'] - $args['smallest']; |
| 812 | - if ( $font_spread < 0 ) |
|
| 813 | - $font_spread = 1; |
|
| 835 | + if ( $font_spread < 0 ) { |
|
| 836 | + $font_spread = 1; |
|
| 837 | + } |
|
| 814 | 838 | $font_step = $font_spread / $spread; |
| 815 | 839 | |
| 816 | 840 | // Assemble the data that will be used to generate the tag cloud markup. |
@@ -887,11 +911,10 @@ discard block |
||
| 887 | 911 | * @param array $args An array of wp_generate_tag_cloud() arguments. |
| 888 | 912 | */ |
| 889 | 913 | return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args ); |
| 914 | + } else { |
|
| 915 | + return $return; |
|
| 916 | + } |
|
| 890 | 917 | } |
| 891 | - |
|
| 892 | - else |
|
| 893 | - return $return; |
|
| 894 | -} |
|
| 895 | 918 | |
| 896 | 919 | /** |
| 897 | 920 | * Callback for comparing objects based on name |
@@ -997,8 +1020,9 @@ discard block |
||
| 997 | 1020 | * @see wp_list_categories() |
| 998 | 1021 | */ |
| 999 | 1022 | public function start_lvl( &$output, $depth = 0, $args = array() ) { |
| 1000 | - if ( 'list' != $args['style'] ) |
|
| 1001 | - return; |
|
| 1023 | + if ( 'list' != $args['style'] ) { |
|
| 1024 | + return; |
|
| 1025 | + } |
|
| 1002 | 1026 | |
| 1003 | 1027 | $indent = str_repeat("\t", $depth); |
| 1004 | 1028 | $output .= "$indent<ul class='children'>\n"; |
@@ -1017,8 +1041,9 @@ discard block |
||
| 1017 | 1041 | * @wsee wp_list_categories() |
| 1018 | 1042 | */ |
| 1019 | 1043 | public function end_lvl( &$output, $depth = 0, $args = array() ) { |
| 1020 | - if ( 'list' != $args['style'] ) |
|
| 1021 | - return; |
|
| 1044 | + if ( 'list' != $args['style'] ) { |
|
| 1045 | + return; |
|
| 1046 | + } |
|
| 1022 | 1047 | |
| 1023 | 1048 | $indent = str_repeat("\t", $depth); |
| 1024 | 1049 | $output .= "$indent</ul>\n"; |
@@ -1150,8 +1175,9 @@ discard block |
||
| 1150 | 1175 | * @param array $args An array of arguments. Only uses 'list' for whether should append to output. @see wp_list_categories() |
| 1151 | 1176 | */ |
| 1152 | 1177 | public function end_el( &$output, $page, $depth = 0, $args = array() ) { |
| 1153 | - if ( 'list' != $args['style'] ) |
|
| 1154 | - return; |
|
| 1178 | + if ( 'list' != $args['style'] ) { |
|
| 1179 | + return; |
|
| 1180 | + } |
|
| 1155 | 1181 | |
| 1156 | 1182 | $output .= "</li>\n"; |
| 1157 | 1183 | } |
@@ -1207,12 +1233,14 @@ discard block |
||
| 1207 | 1233 | |
| 1208 | 1234 | $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$value_field} ) . "\""; |
| 1209 | 1235 | |
| 1210 | - if ( $category->{$value_field} == $args['selected'] ) |
|
| 1211 | - $output .= ' selected="selected"'; |
|
| 1236 | + if ( $category->{$value_field} == $args['selected'] ) { |
|
| 1237 | + $output .= ' selected="selected"'; |
|
| 1238 | + } |
|
| 1212 | 1239 | $output .= '>'; |
| 1213 | 1240 | $output .= $pad.$cat_name; |
| 1214 | - if ( $args['show_count'] ) |
|
| 1215 | - $output .= ' ('. number_format_i18n( $category->count ) .')'; |
|
| 1241 | + if ( $args['show_count'] ) { |
|
| 1242 | + $output .= ' ('. number_format_i18n( $category->count ) .')'; |
|
| 1243 | + } |
|
| 1216 | 1244 | $output .= "</option>\n"; |
| 1217 | 1245 | } |
| 1218 | 1246 | } |
@@ -1231,13 +1259,15 @@ discard block |
||
| 1231 | 1259 | * @return string Link on success, empty string if tag does not exist. |
| 1232 | 1260 | */ |
| 1233 | 1261 | function get_tag_link( $tag ) { |
| 1234 | - if ( ! is_object( $tag ) ) |
|
| 1235 | - $tag = (int) $tag; |
|
| 1262 | + if ( ! is_object( $tag ) ) { |
|
| 1263 | + $tag = (int) $tag; |
|
| 1264 | + } |
|
| 1236 | 1265 | |
| 1237 | 1266 | $tag = get_term_link( $tag, 'post_tag' ); |
| 1238 | 1267 | |
| 1239 | - if ( is_wp_error( $tag ) ) |
|
| 1240 | - return ''; |
|
| 1268 | + if ( is_wp_error( $tag ) ) { |
|
| 1269 | + return ''; |
|
| 1270 | + } |
|
| 1241 | 1271 | |
| 1242 | 1272 | return $tag; |
| 1243 | 1273 | } |
@@ -1301,8 +1331,9 @@ discard block |
||
| 1301 | 1331 | * @param string $after Optional. After list. |
| 1302 | 1332 | */ |
| 1303 | 1333 | function the_tags( $before = null, $sep = ', ', $after = '' ) { |
| 1304 | - if ( null === $before ) |
|
| 1305 | - $before = __('Tags: '); |
|
| 1334 | + if ( null === $before ) { |
|
| 1335 | + $before = __('Tags: '); |
|
| 1336 | + } |
|
| 1306 | 1337 | echo get_the_tag_list($before, $sep, $after); |
| 1307 | 1338 | } |
| 1308 | 1339 | |
@@ -1350,8 +1381,9 @@ discard block |
||
| 1350 | 1381 | * or the post does not exist, WP_Error on failure. |
| 1351 | 1382 | */ |
| 1352 | 1383 | function get_the_terms( $post, $taxonomy ) { |
| 1353 | - if ( ! $post = get_post( $post ) ) |
|
| 1354 | - return false; |
|
| 1384 | + if ( ! $post = get_post( $post ) ) { |
|
| 1385 | + return false; |
|
| 1386 | + } |
|
| 1355 | 1387 | |
| 1356 | 1388 | $terms = get_object_term_cache( $post->ID, $taxonomy ); |
| 1357 | 1389 | if ( false === $terms ) { |
@@ -1370,8 +1402,9 @@ discard block |
||
| 1370 | 1402 | */ |
| 1371 | 1403 | $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy ); |
| 1372 | 1404 | |
| 1373 | - if ( empty( $terms ) ) |
|
| 1374 | - return false; |
|
| 1405 | + if ( empty( $terms ) ) { |
|
| 1406 | + return false; |
|
| 1407 | + } |
|
| 1375 | 1408 | |
| 1376 | 1409 | return $terms; |
| 1377 | 1410 | } |
@@ -1391,11 +1424,13 @@ discard block |
||
| 1391 | 1424 | function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { |
| 1392 | 1425 | $terms = get_the_terms( $id, $taxonomy ); |
| 1393 | 1426 | |
| 1394 | - if ( is_wp_error( $terms ) ) |
|
| 1395 | - return $terms; |
|
| 1427 | + if ( is_wp_error( $terms ) ) { |
|
| 1428 | + return $terms; |
|
| 1429 | + } |
|
| 1396 | 1430 | |
| 1397 | - if ( empty( $terms ) ) |
|
| 1398 | - return false; |
|
| 1431 | + if ( empty( $terms ) ) { |
|
| 1432 | + return false; |
|
| 1433 | + } |
|
| 1399 | 1434 | |
| 1400 | 1435 | $links = array(); |
| 1401 | 1436 | |
@@ -1437,8 +1472,9 @@ discard block |
||
| 1437 | 1472 | function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) { |
| 1438 | 1473 | $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after ); |
| 1439 | 1474 | |
| 1440 | - if ( is_wp_error( $term_list ) ) |
|
| 1441 | - return false; |
|
| 1475 | + if ( is_wp_error( $term_list ) ) { |
|
| 1476 | + return false; |
|
| 1477 | + } |
|
| 1442 | 1478 | |
| 1443 | 1479 | /** |
| 1444 | 1480 | * Filter the list of terms to display. |
@@ -1505,12 +1541,14 @@ discard block |
||
| 1505 | 1541 | function has_term( $term = '', $taxonomy = '', $post = null ) { |
| 1506 | 1542 | $post = get_post($post); |
| 1507 | 1543 | |
| 1508 | - if ( !$post ) |
|
| 1509 | - return false; |
|
| 1544 | + if ( !$post ) { |
|
| 1545 | + return false; |
|
| 1546 | + } |
|
| 1510 | 1547 | |
| 1511 | 1548 | $r = is_object_in_term( $post->ID, $taxonomy, $term ); |
| 1512 | - if ( is_wp_error( $r ) ) |
|
| 1513 | - return false; |
|
| 1549 | + if ( is_wp_error( $r ) ) { |
|
| 1550 | + return false; |
|
| 1551 | + } |
|
| 1514 | 1552 | |
| 1515 | 1553 | return $r; |
| 1516 | 1554 | } |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | * @since 2.7.0 |
| 453 | 453 | * |
| 454 | 454 | * @param string $strResponse The full response string |
| 455 | - * @return array Array with 'headers' and 'body' keys. |
|
| 455 | + * @return string Array with 'headers' and 'body' keys. |
|
| 456 | 456 | */ |
| 457 | 457 | public static function processResponse($strResponse) { |
| 458 | 458 | $res = explode("\r\n\r\n", $strResponse, 2); |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | * |
| 473 | 473 | * @param string|array $headers |
| 474 | 474 | * @param string $url The URL that was requested |
| 475 | - * @return array Processed string headers. If duplicate headers are encountered, |
|
| 475 | + * @return string Processed string headers. If duplicate headers are encountered, |
|
| 476 | 476 | * Then a numbered array is returned as the value of that header-key. |
| 477 | 477 | */ |
| 478 | 478 | public static function processHeaders( $headers, $url = '' ) { |
@@ -2106,7 +2106,7 @@ discard block |
||
| 2106 | 2106 | * @param string $raw String to compress. |
| 2107 | 2107 | * @param int $level Optional, default is 9. Compression level, 9 is highest. |
| 2108 | 2108 | * @param string $supports Optional, not used. When implemented it will choose the right compression based on what the server supports. |
| 2109 | - * @return string|false False on failure. |
|
| 2109 | + * @return string False on failure. |
|
| 2110 | 2110 | */ |
| 2111 | 2111 | public static function compress( $raw, $level = 9, $supports = null ) { |
| 2112 | 2112 | return gzdeflate( $raw, $level ); |
@@ -1,16 +1,16 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Simple and uniform HTTP request API. |
|
| 4 | - * |
|
| 5 | - * Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk |
|
| 6 | - * decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations. |
|
| 7 | - * |
|
| 8 | - * @link https://core.trac.wordpress.org/ticket/4779 HTTP API Proposal |
|
| 9 | - * |
|
| 10 | - * @package WordPress |
|
| 11 | - * @subpackage HTTP |
|
| 12 | - * @since 2.7.0 |
|
| 13 | - */ |
|
| 3 | + * Simple and uniform HTTP request API. |
|
| 4 | + * |
|
| 5 | + * Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk |
|
| 6 | + * decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations. |
|
| 7 | + * |
|
| 8 | + * @link https://core.trac.wordpress.org/ticket/4779 HTTP API Proposal |
|
| 9 | + * |
|
| 10 | + * @package WordPress |
|
| 11 | + * @subpackage HTTP |
|
| 12 | + * @since 2.7.0 |
|
| 13 | + */ |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * WordPress HTTP Class for managing HTTP Transports and making HTTP requests. |
@@ -1871,18 +1871,18 @@ discard block |
||
| 1871 | 1871 | } |
| 1872 | 1872 | } |
| 1873 | 1873 | /** |
| 1874 | - * Internal representation of a single cookie. |
|
| 1875 | - * |
|
| 1876 | - * Returned cookies are represented using this class, and when cookies are set, if they are not |
|
| 1877 | - * already a WP_Http_Cookie() object, then they are turned into one. |
|
| 1878 | - * |
|
| 1879 | - * @todo The WordPress convention is to use underscores instead of camelCase for function and method |
|
| 1880 | - * names. Need to switch to use underscores instead for the methods. |
|
| 1881 | - * |
|
| 1882 | - * @package WordPress |
|
| 1883 | - * @subpackage HTTP |
|
| 1884 | - * @since 2.8.0 |
|
| 1885 | - */ |
|
| 1874 | + * Internal representation of a single cookie. |
|
| 1875 | + * |
|
| 1876 | + * Returned cookies are represented using this class, and when cookies are set, if they are not |
|
| 1877 | + * already a WP_Http_Cookie() object, then they are turned into one. |
|
| 1878 | + * |
|
| 1879 | + * @todo The WordPress convention is to use underscores instead of camelCase for function and method |
|
| 1880 | + * names. Need to switch to use underscores instead for the methods. |
|
| 1881 | + * |
|
| 1882 | + * @package WordPress |
|
| 1883 | + * @subpackage HTTP |
|
| 1884 | + * @since 2.8.0 |
|
| 1885 | + */ |
|
| 1886 | 1886 | class WP_Http_Cookie { |
| 1887 | 1887 | |
| 1888 | 1888 | /** |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. |
| 83 | 83 | * A WP_Error instance upon error. |
| 84 | 84 | */ |
| 85 | - public function request( $url, $args = array() ) { |
|
| 85 | + public function request($url, $args = array()) { |
|
| 86 | 86 | global $wp_version; |
| 87 | 87 | |
| 88 | 88 | $defaults = array( |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @param int $timeout_value Time in seconds until a request times out. |
| 96 | 96 | * Default 5. |
| 97 | 97 | */ |
| 98 | - 'timeout' => apply_filters( 'http_request_timeout', 5 ), |
|
| 98 | + 'timeout' => apply_filters('http_request_timeout', 5), |
|
| 99 | 99 | /** |
| 100 | 100 | * Filter the number of redirects allowed during an HTTP request. |
| 101 | 101 | * |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @param int $redirect_count Number of redirects allowed. Default 5. |
| 105 | 105 | */ |
| 106 | - 'redirection' => apply_filters( 'http_request_redirection_count', 5 ), |
|
| 106 | + 'redirection' => apply_filters('http_request_redirection_count', 5), |
|
| 107 | 107 | /** |
| 108 | 108 | * Filter the version of the HTTP protocol used in a request. |
| 109 | 109 | * |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @param string $version Version of HTTP used. Accepts '1.0' and '1.1'. |
| 113 | 113 | * Default '1.0'. |
| 114 | 114 | */ |
| 115 | - 'httpversion' => apply_filters( 'http_request_version', '1.0' ), |
|
| 115 | + 'httpversion' => apply_filters('http_request_version', '1.0'), |
|
| 116 | 116 | /** |
| 117 | 117 | * Filter the user agent value sent with an HTTP request. |
| 118 | 118 | * |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @param string $user_agent WordPress user agent string. |
| 122 | 122 | */ |
| 123 | - 'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ), |
|
| 123 | + 'user-agent' => apply_filters('http_headers_useragent', 'WordPress/'.$wp_version.'; '.get_bloginfo('url')), |
|
| 124 | 124 | /** |
| 125 | 125 | * Filter whether to pass URLs through wp_http_validate_url() in an HTTP request. |
| 126 | 126 | * |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * @param bool $pass_url Whether to pass URLs through wp_http_validate_url(). |
| 130 | 130 | * Default false. |
| 131 | 131 | */ |
| 132 | - 'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ), |
|
| 132 | + 'reject_unsafe_urls' => apply_filters('http_request_reject_unsafe_urls', false), |
|
| 133 | 133 | 'blocking' => true, |
| 134 | 134 | 'headers' => array(), |
| 135 | 135 | 'cookies' => array(), |
@@ -137,20 +137,20 @@ discard block |
||
| 137 | 137 | 'compress' => false, |
| 138 | 138 | 'decompress' => true, |
| 139 | 139 | 'sslverify' => true, |
| 140 | - 'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt', |
|
| 140 | + 'sslcertificates' => ABSPATH.WPINC.'/certificates/ca-bundle.crt', |
|
| 141 | 141 | 'stream' => false, |
| 142 | 142 | 'filename' => null, |
| 143 | 143 | 'limit_response_size' => null, |
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | 146 | // Pre-parse for the HEAD checks. |
| 147 | - $args = wp_parse_args( $args ); |
|
| 147 | + $args = wp_parse_args($args); |
|
| 148 | 148 | |
| 149 | 149 | // By default, Head requests do not cause redirections. |
| 150 | - if ( isset($args['method']) && 'HEAD' == $args['method'] ) |
|
| 150 | + if (isset($args['method']) && 'HEAD' == $args['method']) |
|
| 151 | 151 | $defaults['redirection'] = 0; |
| 152 | 152 | |
| 153 | - $r = wp_parse_args( $args, $defaults ); |
|
| 153 | + $r = wp_parse_args($args, $defaults); |
|
| 154 | 154 | /** |
| 155 | 155 | * Filter the arguments used in an HTTP request. |
| 156 | 156 | * |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | * @param array $r An array of HTTP request arguments. |
| 160 | 160 | * @param string $url The request URL. |
| 161 | 161 | */ |
| 162 | - $r = apply_filters( 'http_request_args', $r, $url ); |
|
| 162 | + $r = apply_filters('http_request_args', $r, $url); |
|
| 163 | 163 | |
| 164 | 164 | // The transports decrement this, store a copy of the original value for loop purposes. |
| 165 | - if ( ! isset( $r['_redirection'] ) ) |
|
| 165 | + if ( ! isset($r['_redirection'])) |
|
| 166 | 166 | $r['_redirection'] = $r['redirection']; |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -177,25 +177,25 @@ discard block |
||
| 177 | 177 | * @param array $r HTTP request arguments. |
| 178 | 178 | * @param string $url The request URL. |
| 179 | 179 | */ |
| 180 | - $pre = apply_filters( 'pre_http_request', false, $r, $url ); |
|
| 181 | - if ( false !== $pre ) |
|
| 180 | + $pre = apply_filters('pre_http_request', false, $r, $url); |
|
| 181 | + if (false !== $pre) |
|
| 182 | 182 | return $pre; |
| 183 | 183 | |
| 184 | - if ( function_exists( 'wp_kses_bad_protocol' ) ) { |
|
| 185 | - if ( $r['reject_unsafe_urls'] ) |
|
| 186 | - $url = wp_http_validate_url( $url ); |
|
| 187 | - if ( $url ) { |
|
| 188 | - $url = wp_kses_bad_protocol( $url, array( 'http', 'https', 'ssl' ) ); |
|
| 184 | + if (function_exists('wp_kses_bad_protocol')) { |
|
| 185 | + if ($r['reject_unsafe_urls']) |
|
| 186 | + $url = wp_http_validate_url($url); |
|
| 187 | + if ($url) { |
|
| 188 | + $url = wp_kses_bad_protocol($url, array('http', 'https', 'ssl')); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $arrURL = @parse_url( $url ); |
|
| 192 | + $arrURL = @parse_url($url); |
|
| 193 | 193 | |
| 194 | - if ( empty( $url ) || empty( $arrURL['scheme'] ) ) |
|
| 194 | + if (empty($url) || empty($arrURL['scheme'])) |
|
| 195 | 195 | return new WP_Error('http_request_failed', __('A valid URL was not provided.')); |
| 196 | 196 | |
| 197 | - if ( $this->block_request( $url ) ) |
|
| 198 | - return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); |
|
| 197 | + if ($this->block_request($url)) |
|
| 198 | + return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.')); |
|
| 199 | 199 | |
| 200 | 200 | /* |
| 201 | 201 | * Determine if this is a https call and pass that on to the transport functions |
@@ -204,88 +204,88 @@ discard block |
||
| 204 | 204 | $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl'; |
| 205 | 205 | |
| 206 | 206 | // Determine if this request is to OUR install of WordPress. |
| 207 | - $homeURL = parse_url( get_bloginfo( 'url' ) ); |
|
| 208 | - $r['local'] = 'localhost' == $arrURL['host'] || ( isset( $homeURL['host'] ) && $homeURL['host'] == $arrURL['host'] ); |
|
| 209 | - unset( $homeURL ); |
|
| 207 | + $homeURL = parse_url(get_bloginfo('url')); |
|
| 208 | + $r['local'] = 'localhost' == $arrURL['host'] || (isset($homeURL['host']) && $homeURL['host'] == $arrURL['host']); |
|
| 209 | + unset($homeURL); |
|
| 210 | 210 | |
| 211 | 211 | /* |
| 212 | 212 | * If we are streaming to a file but no filename was given drop it in the WP temp dir |
| 213 | 213 | * and pick its name using the basename of the $url. |
| 214 | 214 | */ |
| 215 | - if ( $r['stream'] && empty( $r['filename'] ) ) { |
|
| 216 | - $r['filename'] = get_temp_dir() . wp_unique_filename( get_temp_dir(), basename( $url ) ); |
|
| 215 | + if ($r['stream'] && empty($r['filename'])) { |
|
| 216 | + $r['filename'] = get_temp_dir().wp_unique_filename(get_temp_dir(), basename($url)); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /* |
| 220 | 220 | * Force some settings if we are streaming to a file and check for existence and perms |
| 221 | 221 | * of destination directory. |
| 222 | 222 | */ |
| 223 | - if ( $r['stream'] ) { |
|
| 223 | + if ($r['stream']) { |
|
| 224 | 224 | $r['blocking'] = true; |
| 225 | - if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) |
|
| 226 | - return new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); |
|
| 225 | + if ( ! wp_is_writable(dirname($r['filename']))) |
|
| 226 | + return new WP_Error('http_request_failed', __('Destination directory for file streaming does not exist or is not writable.')); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if ( is_null( $r['headers'] ) ) |
|
| 229 | + if (is_null($r['headers'])) |
|
| 230 | 230 | $r['headers'] = array(); |
| 231 | 231 | |
| 232 | - if ( ! is_array( $r['headers'] ) ) { |
|
| 233 | - $processedHeaders = self::processHeaders( $r['headers'], $url ); |
|
| 232 | + if ( ! is_array($r['headers'])) { |
|
| 233 | + $processedHeaders = self::processHeaders($r['headers'], $url); |
|
| 234 | 234 | $r['headers'] = $processedHeaders['headers']; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if ( isset( $r['headers']['User-Agent'] ) ) { |
|
| 237 | + if (isset($r['headers']['User-Agent'])) { |
|
| 238 | 238 | $r['user-agent'] = $r['headers']['User-Agent']; |
| 239 | - unset( $r['headers']['User-Agent'] ); |
|
| 239 | + unset($r['headers']['User-Agent']); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if ( isset( $r['headers']['user-agent'] ) ) { |
|
| 242 | + if (isset($r['headers']['user-agent'])) { |
|
| 243 | 243 | $r['user-agent'] = $r['headers']['user-agent']; |
| 244 | - unset( $r['headers']['user-agent'] ); |
|
| 244 | + unset($r['headers']['user-agent']); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - if ( '1.1' == $r['httpversion'] && !isset( $r['headers']['connection'] ) ) { |
|
| 247 | + if ('1.1' == $r['httpversion'] && ! isset($r['headers']['connection'])) { |
|
| 248 | 248 | $r['headers']['connection'] = 'close'; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // Construct Cookie: header if any cookies are set. |
| 252 | - self::buildCookieHeader( $r ); |
|
| 252 | + self::buildCookieHeader($r); |
|
| 253 | 253 | |
| 254 | 254 | // Avoid issues where mbstring.func_overload is enabled. |
| 255 | 255 | mbstring_binary_safe_encoding(); |
| 256 | 256 | |
| 257 | - if ( ! isset( $r['headers']['Accept-Encoding'] ) ) { |
|
| 258 | - if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) ) |
|
| 257 | + if ( ! isset($r['headers']['Accept-Encoding'])) { |
|
| 258 | + if ($encoding = WP_Http_Encoding::accept_encoding($url, $r)) |
|
| 259 | 259 | $r['headers']['Accept-Encoding'] = $encoding; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if ( ( ! is_null( $r['body'] ) && '' != $r['body'] ) || 'POST' == $r['method'] || 'PUT' == $r['method'] ) { |
|
| 263 | - if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { |
|
| 264 | - $r['body'] = http_build_query( $r['body'], null, '&' ); |
|
| 262 | + if (( ! is_null($r['body']) && '' != $r['body']) || 'POST' == $r['method'] || 'PUT' == $r['method']) { |
|
| 263 | + if (is_array($r['body']) || is_object($r['body'])) { |
|
| 264 | + $r['body'] = http_build_query($r['body'], null, '&'); |
|
| 265 | 265 | |
| 266 | - if ( ! isset( $r['headers']['Content-Type'] ) ) |
|
| 267 | - $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ); |
|
| 266 | + if ( ! isset($r['headers']['Content-Type'])) |
|
| 267 | + $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset='.get_option('blog_charset'); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - if ( '' === $r['body'] ) |
|
| 270 | + if ('' === $r['body']) |
|
| 271 | 271 | $r['body'] = null; |
| 272 | 272 | |
| 273 | - if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) ) |
|
| 274 | - $r['headers']['Content-Length'] = strlen( $r['body'] ); |
|
| 273 | + if ( ! isset($r['headers']['Content-Length']) && ! isset($r['headers']['content-length'])) |
|
| 274 | + $r['headers']['Content-Length'] = strlen($r['body']); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $response = $this->_dispatch_request( $url, $r ); |
|
| 277 | + $response = $this->_dispatch_request($url, $r); |
|
| 278 | 278 | |
| 279 | 279 | reset_mbstring_encoding(); |
| 280 | 280 | |
| 281 | - if ( is_wp_error( $response ) ) |
|
| 281 | + if (is_wp_error($response)) |
|
| 282 | 282 | return $response; |
| 283 | 283 | |
| 284 | 284 | // Append cookies that were used in this request to the response |
| 285 | - if ( ! empty( $r['cookies'] ) ) { |
|
| 286 | - $cookies_set = wp_list_pluck( $response['cookies'], 'name' ); |
|
| 287 | - foreach ( $r['cookies'] as $cookie ) { |
|
| 288 | - if ( ! in_array( $cookie->name, $cookies_set ) && $cookie->test( $url ) ) { |
|
| 285 | + if ( ! empty($r['cookies'])) { |
|
| 286 | + $cookies_set = wp_list_pluck($response['cookies'], 'name'); |
|
| 287 | + foreach ($r['cookies'] as $cookie) { |
|
| 288 | + if ( ! in_array($cookie->name, $cookies_set) && $cookie->test($url)) { |
|
| 289 | 289 | $response['cookies'][] = $cookie; |
| 290 | 290 | } |
| 291 | 291 | } |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | * |
| 306 | 306 | * @return string|false Class name for the first transport that claims to support the request. False if no transport claims to support the request. |
| 307 | 307 | */ |
| 308 | - public function _get_first_available_transport( $args, $url = null ) { |
|
| 308 | + public function _get_first_available_transport($args, $url = null) { |
|
| 309 | 309 | /** |
| 310 | 310 | * Filter which HTTP transports are available and in what order. |
| 311 | 311 | * |
@@ -316,14 +316,14 @@ discard block |
||
| 316 | 316 | * @param array $args HTTP request arguments. |
| 317 | 317 | * @param string $url The URL to request. |
| 318 | 318 | */ |
| 319 | - $request_order = apply_filters( 'http_api_transports', array( 'curl', 'streams' ), $args, $url ); |
|
| 319 | + $request_order = apply_filters('http_api_transports', array('curl', 'streams'), $args, $url); |
|
| 320 | 320 | |
| 321 | 321 | // Loop over each transport on each HTTP request looking for one which will serve this request's needs. |
| 322 | - foreach ( $request_order as $transport ) { |
|
| 323 | - $class = 'WP_HTTP_' . $transport; |
|
| 322 | + foreach ($request_order as $transport) { |
|
| 323 | + $class = 'WP_HTTP_'.$transport; |
|
| 324 | 324 | |
| 325 | 325 | // Check to see if this transport is a possibility, calls the transport statically. |
| 326 | - if ( !call_user_func( array( $class, 'test' ), $args, $url ) ) |
|
| 326 | + if ( ! call_user_func(array($class, 'test'), $args, $url)) |
|
| 327 | 327 | continue; |
| 328 | 328 | |
| 329 | 329 | return $class; |
@@ -349,18 +349,18 @@ discard block |
||
| 349 | 349 | * @param array $args Request arguments |
| 350 | 350 | * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error |
| 351 | 351 | */ |
| 352 | - private function _dispatch_request( $url, $args ) { |
|
| 352 | + private function _dispatch_request($url, $args) { |
|
| 353 | 353 | static $transports = array(); |
| 354 | 354 | |
| 355 | - $class = $this->_get_first_available_transport( $args, $url ); |
|
| 356 | - if ( !$class ) |
|
| 357 | - return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); |
|
| 355 | + $class = $this->_get_first_available_transport($args, $url); |
|
| 356 | + if ( ! $class) |
|
| 357 | + return new WP_Error('http_failure', __('There are no HTTP transports available which can complete the requested request.')); |
|
| 358 | 358 | |
| 359 | 359 | // Transport claims to support request, instantiate it and give it a whirl. |
| 360 | - if ( empty( $transports[$class] ) ) |
|
| 360 | + if (empty($transports[$class])) |
|
| 361 | 361 | $transports[$class] = new $class; |
| 362 | 362 | |
| 363 | - $response = $transports[$class]->request( $url, $args ); |
|
| 363 | + $response = $transports[$class]->request($url, $args); |
|
| 364 | 364 | |
| 365 | 365 | /** |
| 366 | 366 | * Fires after an HTTP API response is received and before the response is returned. |
@@ -373,9 +373,9 @@ discard block |
||
| 373 | 373 | * @param array $args HTTP request arguments. |
| 374 | 374 | * @param string $url The request URL. |
| 375 | 375 | */ |
| 376 | - do_action( 'http_api_debug', $response, 'response', $class, $args, $url ); |
|
| 376 | + do_action('http_api_debug', $response, 'response', $class, $args, $url); |
|
| 377 | 377 | |
| 378 | - if ( is_wp_error( $response ) ) |
|
| 378 | + if (is_wp_error($response)) |
|
| 379 | 379 | return $response; |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | * @param array $args HTTP request arguments. |
| 388 | 388 | * @param string $url The request URL. |
| 389 | 389 | */ |
| 390 | - return apply_filters( 'http_response', $response, $args, $url ); |
|
| 390 | + return apply_filters('http_response', $response, $args, $url); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | /** |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | */ |
| 405 | 405 | public function post($url, $args = array()) { |
| 406 | 406 | $defaults = array('method' => 'POST'); |
| 407 | - $r = wp_parse_args( $args, $defaults ); |
|
| 407 | + $r = wp_parse_args($args, $defaults); |
|
| 408 | 408 | return $this->request($url, $r); |
| 409 | 409 | } |
| 410 | 410 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | */ |
| 423 | 423 | public function get($url, $args = array()) { |
| 424 | 424 | $defaults = array('method' => 'GET'); |
| 425 | - $r = wp_parse_args( $args, $defaults ); |
|
| 425 | + $r = wp_parse_args($args, $defaults); |
|
| 426 | 426 | return $this->request($url, $r); |
| 427 | 427 | } |
| 428 | 428 | |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | */ |
| 441 | 441 | public function head($url, $args = array()) { |
| 442 | 442 | $defaults = array('method' => 'HEAD'); |
| 443 | - $r = wp_parse_args( $args, $defaults ); |
|
| 443 | + $r = wp_parse_args($args, $defaults); |
|
| 444 | 444 | return $this->request($url, $r); |
| 445 | 445 | } |
| 446 | 446 | |
@@ -475,9 +475,9 @@ discard block |
||
| 475 | 475 | * @return array Processed string headers. If duplicate headers are encountered, |
| 476 | 476 | * Then a numbered array is returned as the value of that header-key. |
| 477 | 477 | */ |
| 478 | - public static function processHeaders( $headers, $url = '' ) { |
|
| 478 | + public static function processHeaders($headers, $url = '') { |
|
| 479 | 479 | // Split headers, one per array element. |
| 480 | - if ( is_string($headers) ) { |
|
| 480 | + if (is_string($headers)) { |
|
| 481 | 481 | // Tolerate line terminator: CRLF = LF (RFC 2616 19.3). |
| 482 | 482 | $headers = str_replace("\r\n", "\n", $headers); |
| 483 | 483 | /* |
@@ -495,8 +495,8 @@ discard block |
||
| 495 | 495 | * If a redirection has taken place, The headers for each page request may have been passed. |
| 496 | 496 | * In this case, determine the final HTTP header and parse from there. |
| 497 | 497 | */ |
| 498 | - for ( $i = count($headers)-1; $i >= 0; $i-- ) { |
|
| 499 | - if ( !empty($headers[$i]) && false === strpos($headers[$i], ':') ) { |
|
| 498 | + for ($i = count($headers) - 1; $i >= 0; $i--) { |
|
| 499 | + if ( ! empty($headers[$i]) && false === strpos($headers[$i], ':')) { |
|
| 500 | 500 | $headers = array_splice($headers, $i); |
| 501 | 501 | break; |
| 502 | 502 | } |
@@ -504,35 +504,35 @@ discard block |
||
| 504 | 504 | |
| 505 | 505 | $cookies = array(); |
| 506 | 506 | $newheaders = array(); |
| 507 | - foreach ( (array) $headers as $tempheader ) { |
|
| 508 | - if ( empty($tempheader) ) |
|
| 507 | + foreach ((array) $headers as $tempheader) { |
|
| 508 | + if (empty($tempheader)) |
|
| 509 | 509 | continue; |
| 510 | 510 | |
| 511 | - if ( false === strpos($tempheader, ':') ) { |
|
| 511 | + if (false === strpos($tempheader, ':')) { |
|
| 512 | 512 | $stack = explode(' ', $tempheader, 3); |
| 513 | 513 | $stack[] = ''; |
| 514 | - list( , $response['code'], $response['message']) = $stack; |
|
| 514 | + list(, $response['code'], $response['message']) = $stack; |
|
| 515 | 515 | continue; |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | list($key, $value) = explode(':', $tempheader, 2); |
| 519 | 519 | |
| 520 | - $key = strtolower( $key ); |
|
| 521 | - $value = trim( $value ); |
|
| 520 | + $key = strtolower($key); |
|
| 521 | + $value = trim($value); |
|
| 522 | 522 | |
| 523 | - if ( isset( $newheaders[ $key ] ) ) { |
|
| 524 | - if ( ! is_array( $newheaders[ $key ] ) ) |
|
| 525 | - $newheaders[$key] = array( $newheaders[ $key ] ); |
|
| 526 | - $newheaders[ $key ][] = $value; |
|
| 523 | + if (isset($newheaders[$key])) { |
|
| 524 | + if ( ! is_array($newheaders[$key])) |
|
| 525 | + $newheaders[$key] = array($newheaders[$key]); |
|
| 526 | + $newheaders[$key][] = $value; |
|
| 527 | 527 | } else { |
| 528 | - $newheaders[ $key ] = $value; |
|
| 528 | + $newheaders[$key] = $value; |
|
| 529 | 529 | } |
| 530 | - if ( 'set-cookie' == $key ) |
|
| 531 | - $cookies[] = new WP_Http_Cookie( $value, $url ); |
|
| 530 | + if ('set-cookie' == $key) |
|
| 531 | + $cookies[] = new WP_Http_Cookie($value, $url); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | // Cast the Response Code to an int |
| 535 | - $response['code'] = intval( $response['code'] ); |
|
| 535 | + $response['code'] = intval($response['code']); |
|
| 536 | 536 | |
| 537 | 537 | return array('response' => $response, 'headers' => $newheaders, 'cookies' => $cookies); |
| 538 | 538 | } |
@@ -550,20 +550,20 @@ discard block |
||
| 550 | 550 | * |
| 551 | 551 | * @param array $r Full array of args passed into ::request() |
| 552 | 552 | */ |
| 553 | - public static function buildCookieHeader( &$r ) { |
|
| 554 | - if ( ! empty($r['cookies']) ) { |
|
| 553 | + public static function buildCookieHeader(&$r) { |
|
| 554 | + if ( ! empty($r['cookies'])) { |
|
| 555 | 555 | // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances. |
| 556 | - foreach ( $r['cookies'] as $name => $value ) { |
|
| 557 | - if ( ! is_object( $value ) ) |
|
| 558 | - $r['cookies'][ $name ] = new WP_HTTP_Cookie( array( 'name' => $name, 'value' => $value ) ); |
|
| 556 | + foreach ($r['cookies'] as $name => $value) { |
|
| 557 | + if ( ! is_object($value)) |
|
| 558 | + $r['cookies'][$name] = new WP_HTTP_Cookie(array('name' => $name, 'value' => $value)); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | $cookies_header = ''; |
| 562 | - foreach ( (array) $r['cookies'] as $cookie ) { |
|
| 563 | - $cookies_header .= $cookie->getHeaderValue() . '; '; |
|
| 562 | + foreach ((array) $r['cookies'] as $cookie) { |
|
| 563 | + $cookies_header .= $cookie->getHeaderValue().'; '; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - $cookies_header = substr( $cookies_header, 0, -2 ); |
|
| 566 | + $cookies_header = substr($cookies_header, 0, -2); |
|
| 567 | 567 | $r['headers']['cookie'] = $cookies_header; |
| 568 | 568 | } |
| 569 | 569 | } |
@@ -582,9 +582,9 @@ discard block |
||
| 582 | 582 | * @param string $body Body content |
| 583 | 583 | * @return string Chunked decoded body on success or raw body on failure. |
| 584 | 584 | */ |
| 585 | - public static function chunkTransferDecode( $body ) { |
|
| 585 | + public static function chunkTransferDecode($body) { |
|
| 586 | 586 | // The body is not chunked encoded or is malformed. |
| 587 | - if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) |
|
| 587 | + if ( ! preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($body))) |
|
| 588 | 588 | return $body; |
| 589 | 589 | |
| 590 | 590 | $parsed_body = ''; |
@@ -592,22 +592,22 @@ discard block |
||
| 592 | 592 | // We'll be altering $body, so need a backup in case of error. |
| 593 | 593 | $body_original = $body; |
| 594 | 594 | |
| 595 | - while ( true ) { |
|
| 596 | - $has_chunk = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $body, $match ); |
|
| 597 | - if ( ! $has_chunk || empty( $match[1] ) ) |
|
| 595 | + while (true) { |
|
| 596 | + $has_chunk = (bool) preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', $body, $match); |
|
| 597 | + if ( ! $has_chunk || empty($match[1])) |
|
| 598 | 598 | return $body_original; |
| 599 | 599 | |
| 600 | - $length = hexdec( $match[1] ); |
|
| 601 | - $chunk_length = strlen( $match[0] ); |
|
| 600 | + $length = hexdec($match[1]); |
|
| 601 | + $chunk_length = strlen($match[0]); |
|
| 602 | 602 | |
| 603 | 603 | // Parse out the chunk of data. |
| 604 | - $parsed_body .= substr( $body, $chunk_length, $length ); |
|
| 604 | + $parsed_body .= substr($body, $chunk_length, $length); |
|
| 605 | 605 | |
| 606 | 606 | // Remove the chunk from the raw data. |
| 607 | - $body = substr( $body, $length + $chunk_length ); |
|
| 607 | + $body = substr($body, $length + $chunk_length); |
|
| 608 | 608 | |
| 609 | 609 | // End of the document. |
| 610 | - if ( '0' === trim( $body ) ) |
|
| 610 | + if ('0' === trim($body)) |
|
| 611 | 611 | return $parsed_body; |
| 612 | 612 | } |
| 613 | 613 | } |
@@ -636,17 +636,17 @@ discard block |
||
| 636 | 636 | */ |
| 637 | 637 | public function block_request($uri) { |
| 638 | 638 | // We don't need to block requests, because nothing is blocked. |
| 639 | - if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) |
|
| 639 | + if ( ! defined('WP_HTTP_BLOCK_EXTERNAL') || ! WP_HTTP_BLOCK_EXTERNAL) |
|
| 640 | 640 | return false; |
| 641 | 641 | |
| 642 | 642 | $check = parse_url($uri); |
| 643 | - if ( ! $check ) |
|
| 643 | + if ( ! $check) |
|
| 644 | 644 | return true; |
| 645 | 645 | |
| 646 | - $home = parse_url( get_option('siteurl') ); |
|
| 646 | + $home = parse_url(get_option('siteurl')); |
|
| 647 | 647 | |
| 648 | 648 | // Don't block requests back to ourselves by default. |
| 649 | - if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) { |
|
| 649 | + if ('localhost' == $check['host'] || (isset($home['host']) && $home['host'] == $check['host'])) { |
|
| 650 | 650 | /** |
| 651 | 651 | * Filter whether to block local requests through the proxy. |
| 652 | 652 | * |
@@ -655,29 +655,29 @@ discard block |
||
| 655 | 655 | * @param bool $block Whether to block local requests through proxy. |
| 656 | 656 | * Default false. |
| 657 | 657 | */ |
| 658 | - return apply_filters( 'block_local_requests', false ); |
|
| 658 | + return apply_filters('block_local_requests', false); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | - if ( !defined('WP_ACCESSIBLE_HOSTS') ) |
|
| 661 | + if ( ! defined('WP_ACCESSIBLE_HOSTS')) |
|
| 662 | 662 | return true; |
| 663 | 663 | |
| 664 | 664 | static $accessible_hosts = null; |
| 665 | 665 | static $wildcard_regex = array(); |
| 666 | - if ( null === $accessible_hosts ) { |
|
| 666 | + if (null === $accessible_hosts) { |
|
| 667 | 667 | $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS); |
| 668 | 668 | |
| 669 | - if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) { |
|
| 669 | + if (false !== strpos(WP_ACCESSIBLE_HOSTS, '*')) { |
|
| 670 | 670 | $wildcard_regex = array(); |
| 671 | - foreach ( $accessible_hosts as $host ) |
|
| 672 | - $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
| 673 | - $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; |
|
| 671 | + foreach ($accessible_hosts as $host) |
|
| 672 | + $wildcard_regex[] = str_replace('\*', '.+', preg_quote($host, '/')); |
|
| 673 | + $wildcard_regex = '/^('.implode('|', $wildcard_regex).')$/i'; |
|
| 674 | 674 | } |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | - if ( !empty($wildcard_regex) ) |
|
| 678 | - return !preg_match($wildcard_regex, $check['host']); |
|
| 677 | + if ( ! empty($wildcard_regex)) |
|
| 678 | + return ! preg_match($wildcard_regex, $check['host']); |
|
| 679 | 679 | else |
| 680 | - return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it. |
|
| 680 | + return ! in_array($check['host'], $accessible_hosts); //Inverse logic, If it's in the array, then we can't access it. |
|
| 681 | 681 | |
| 682 | 682 | } |
| 683 | 683 | |
@@ -700,25 +700,25 @@ discard block |
||
| 700 | 700 | * @return bool|array False on failure; Array of URL components on success; |
| 701 | 701 | * See parse_url()'s return values. |
| 702 | 702 | */ |
| 703 | - protected static function parse_url( $url ) { |
|
| 704 | - $parts = @parse_url( $url ); |
|
| 705 | - if ( ! $parts ) { |
|
| 703 | + protected static function parse_url($url) { |
|
| 704 | + $parts = @parse_url($url); |
|
| 705 | + if ( ! $parts) { |
|
| 706 | 706 | // < PHP 5.4.7 compat, trouble with relative paths including a scheme break in the path |
| 707 | - if ( '/' == $url[0] && false !== strpos( $url, '://' ) ) { |
|
| 707 | + if ('/' == $url[0] && false !== strpos($url, '://')) { |
|
| 708 | 708 | // Since we know it's a relative path, prefix with a scheme/host placeholder and try again |
| 709 | - if ( ! $parts = @parse_url( 'placeholder://placeholder' . $url ) ) { |
|
| 709 | + if ( ! $parts = @parse_url('placeholder://placeholder'.$url)) { |
|
| 710 | 710 | return $parts; |
| 711 | 711 | } |
| 712 | 712 | // Remove the placeholder values |
| 713 | - unset( $parts['scheme'], $parts['host'] ); |
|
| 713 | + unset($parts['scheme'], $parts['host']); |
|
| 714 | 714 | } else { |
| 715 | 715 | return $parts; |
| 716 | 716 | } |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | // < PHP 5.4.7 compat, doesn't detect schemeless URL's host field |
| 720 | - if ( '//' == substr( $url, 0, 2 ) && ! isset( $parts['host'] ) ) { |
|
| 721 | - list( $parts['host'], $slashless_path ) = explode( '/', substr( $parts['path'], 2 ), 2 ); |
|
| 720 | + if ('//' == substr($url, 0, 2) && ! isset($parts['host'])) { |
|
| 721 | + list($parts['host'], $slashless_path) = explode('/', substr($parts['path'], 2), 2); |
|
| 722 | 722 | $parts['path'] = "/{$slashless_path}"; |
| 723 | 723 | } |
| 724 | 724 | |
@@ -739,65 +739,65 @@ discard block |
||
| 739 | 739 | * @param string $url The URL which $maybe_relative_path is relative to |
| 740 | 740 | * @return string An Absolute URL, in a failure condition where the URL cannot be parsed, the relative URL will be returned. |
| 741 | 741 | */ |
| 742 | - public static function make_absolute_url( $maybe_relative_path, $url ) { |
|
| 743 | - if ( empty( $url ) ) |
|
| 742 | + public static function make_absolute_url($maybe_relative_path, $url) { |
|
| 743 | + if (empty($url)) |
|
| 744 | 744 | return $maybe_relative_path; |
| 745 | 745 | |
| 746 | - if ( ! $url_parts = WP_HTTP::parse_url( $url ) ) { |
|
| 746 | + if ( ! $url_parts = WP_HTTP::parse_url($url)) { |
|
| 747 | 747 | return $maybe_relative_path; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - if ( ! $relative_url_parts = WP_HTTP::parse_url( $maybe_relative_path ) ) { |
|
| 750 | + if ( ! $relative_url_parts = WP_HTTP::parse_url($maybe_relative_path)) { |
|
| 751 | 751 | return $maybe_relative_path; |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | // Check for a scheme on the 'relative' url |
| 755 | - if ( ! empty( $relative_url_parts['scheme'] ) ) { |
|
| 755 | + if ( ! empty($relative_url_parts['scheme'])) { |
|
| 756 | 756 | return $maybe_relative_path; |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | - $absolute_path = $url_parts['scheme'] . '://'; |
|
| 759 | + $absolute_path = $url_parts['scheme'].'://'; |
|
| 760 | 760 | |
| 761 | 761 | // Schemeless URL's will make it this far, so we check for a host in the relative url and convert it to a protocol-url |
| 762 | - if ( isset( $relative_url_parts['host'] ) ) { |
|
| 762 | + if (isset($relative_url_parts['host'])) { |
|
| 763 | 763 | $absolute_path .= $relative_url_parts['host']; |
| 764 | - if ( isset( $relative_url_parts['port'] ) ) |
|
| 765 | - $absolute_path .= ':' . $relative_url_parts['port']; |
|
| 764 | + if (isset($relative_url_parts['port'])) |
|
| 765 | + $absolute_path .= ':'.$relative_url_parts['port']; |
|
| 766 | 766 | } else { |
| 767 | 767 | $absolute_path .= $url_parts['host']; |
| 768 | - if ( isset( $url_parts['port'] ) ) |
|
| 769 | - $absolute_path .= ':' . $url_parts['port']; |
|
| 768 | + if (isset($url_parts['port'])) |
|
| 769 | + $absolute_path .= ':'.$url_parts['port']; |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | // Start off with the Absolute URL path. |
| 773 | - $path = ! empty( $url_parts['path'] ) ? $url_parts['path'] : '/'; |
|
| 773 | + $path = ! empty($url_parts['path']) ? $url_parts['path'] : '/'; |
|
| 774 | 774 | |
| 775 | 775 | // If it's a root-relative path, then great. |
| 776 | - if ( ! empty( $relative_url_parts['path'] ) && '/' == $relative_url_parts['path'][0] ) { |
|
| 776 | + if ( ! empty($relative_url_parts['path']) && '/' == $relative_url_parts['path'][0]) { |
|
| 777 | 777 | $path = $relative_url_parts['path']; |
| 778 | 778 | |
| 779 | 779 | // Else it's a relative path. |
| 780 | - } elseif ( ! empty( $relative_url_parts['path'] ) ) { |
|
| 780 | + } elseif ( ! empty($relative_url_parts['path'])) { |
|
| 781 | 781 | // Strip off any file components from the absolute path. |
| 782 | - $path = substr( $path, 0, strrpos( $path, '/' ) + 1 ); |
|
| 782 | + $path = substr($path, 0, strrpos($path, '/') + 1); |
|
| 783 | 783 | |
| 784 | 784 | // Build the new path. |
| 785 | 785 | $path .= $relative_url_parts['path']; |
| 786 | 786 | |
| 787 | 787 | // Strip all /path/../ out of the path. |
| 788 | - while ( strpos( $path, '../' ) > 1 ) { |
|
| 789 | - $path = preg_replace( '![^/]+/\.\./!', '', $path ); |
|
| 788 | + while (strpos($path, '../') > 1) { |
|
| 789 | + $path = preg_replace('![^/]+/\.\./!', '', $path); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | // Strip any final leading ../ from the path. |
| 793 | - $path = preg_replace( '!^/(\.\./)+!', '', $path ); |
|
| 793 | + $path = preg_replace('!^/(\.\./)+!', '', $path); |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | // Add the Query string. |
| 797 | - if ( ! empty( $relative_url_parts['query'] ) ) |
|
| 798 | - $path .= '?' . $relative_url_parts['query']; |
|
| 797 | + if ( ! empty($relative_url_parts['query'])) |
|
| 798 | + $path .= '?'.$relative_url_parts['query']; |
|
| 799 | 799 | |
| 800 | - return $absolute_path . '/' . ltrim( $path, '/' ); |
|
| 800 | + return $absolute_path.'/'.ltrim($path, '/'); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
@@ -812,42 +812,42 @@ discard block |
||
| 812 | 812 | * @param array $response The Response of the HTTP request. |
| 813 | 813 | * @return false|object False if no redirect is present, a WP_HTTP or WP_Error result otherwise. |
| 814 | 814 | */ |
| 815 | - public static function handle_redirects( $url, $args, $response ) { |
|
| 815 | + public static function handle_redirects($url, $args, $response) { |
|
| 816 | 816 | // If no redirects are present, or, redirects were not requested, perform no action. |
| 817 | - if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) |
|
| 817 | + if ( ! isset($response['headers']['location']) || 0 === $args['_redirection']) |
|
| 818 | 818 | return false; |
| 819 | 819 | |
| 820 | 820 | // Only perform redirections on redirection http codes. |
| 821 | - if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) |
|
| 821 | + if ($response['response']['code'] > 399 || $response['response']['code'] < 300) |
|
| 822 | 822 | return false; |
| 823 | 823 | |
| 824 | 824 | // Don't redirect if we've run out of redirects. |
| 825 | - if ( $args['redirection']-- <= 0 ) |
|
| 826 | - return new WP_Error( 'http_request_failed', __('Too many redirects.') ); |
|
| 825 | + if ($args['redirection']-- <= 0) |
|
| 826 | + return new WP_Error('http_request_failed', __('Too many redirects.')); |
|
| 827 | 827 | |
| 828 | 828 | $redirect_location = $response['headers']['location']; |
| 829 | 829 | |
| 830 | 830 | // If there were multiple Location headers, use the last header specified. |
| 831 | - if ( is_array( $redirect_location ) ) |
|
| 832 | - $redirect_location = array_pop( $redirect_location ); |
|
| 831 | + if (is_array($redirect_location)) |
|
| 832 | + $redirect_location = array_pop($redirect_location); |
|
| 833 | 833 | |
| 834 | - $redirect_location = WP_HTTP::make_absolute_url( $redirect_location, $url ); |
|
| 834 | + $redirect_location = WP_HTTP::make_absolute_url($redirect_location, $url); |
|
| 835 | 835 | |
| 836 | 836 | // POST requests should not POST to a redirected location. |
| 837 | - if ( 'POST' == $args['method'] ) { |
|
| 838 | - if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) |
|
| 837 | + if ('POST' == $args['method']) { |
|
| 838 | + if (in_array($response['response']['code'], array(302, 303))) |
|
| 839 | 839 | $args['method'] = 'GET'; |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | // Include valid cookies in the redirect process. |
| 843 | - if ( ! empty( $response['cookies'] ) ) { |
|
| 844 | - foreach ( $response['cookies'] as $cookie ) { |
|
| 845 | - if ( $cookie->test( $redirect_location ) ) |
|
| 843 | + if ( ! empty($response['cookies'])) { |
|
| 844 | + foreach ($response['cookies'] as $cookie) { |
|
| 845 | + if ($cookie->test($redirect_location)) |
|
| 846 | 846 | $args['cookies'][] = $cookie; |
| 847 | 847 | } |
| 848 | 848 | } |
| 849 | 849 | |
| 850 | - return wp_remote_request( $redirect_location, $args ); |
|
| 850 | + return wp_remote_request($redirect_location, $args); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
@@ -866,11 +866,11 @@ discard block |
||
| 866 | 866 | * @param string $maybe_ip A suspected IP address |
| 867 | 867 | * @return integer|bool Upon success, '4' or '6' to represent a IPv4 or IPv6 address, false upon failure |
| 868 | 868 | */ |
| 869 | - public static function is_ip_address( $maybe_ip ) { |
|
| 870 | - if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) |
|
| 869 | + public static function is_ip_address($maybe_ip) { |
|
| 870 | + if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip)) |
|
| 871 | 871 | return 4; |
| 872 | 872 | |
| 873 | - if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) |
|
| 873 | + if (false !== strpos($maybe_ip, ':') && preg_match('/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim($maybe_ip, ' []'))) |
|
| 874 | 874 | return 6; |
| 875 | 875 | |
| 876 | 876 | return false; |
@@ -906,26 +906,26 @@ discard block |
||
| 906 | 906 | 'headers' => array(), 'body' => null, 'cookies' => array() |
| 907 | 907 | ); |
| 908 | 908 | |
| 909 | - $r = wp_parse_args( $args, $defaults ); |
|
| 909 | + $r = wp_parse_args($args, $defaults); |
|
| 910 | 910 | |
| 911 | - if ( isset( $r['headers']['User-Agent'] ) ) { |
|
| 911 | + if (isset($r['headers']['User-Agent'])) { |
|
| 912 | 912 | $r['user-agent'] = $r['headers']['User-Agent']; |
| 913 | - unset( $r['headers']['User-Agent'] ); |
|
| 914 | - } elseif ( isset( $r['headers']['user-agent'] ) ) { |
|
| 913 | + unset($r['headers']['User-Agent']); |
|
| 914 | + } elseif (isset($r['headers']['user-agent'])) { |
|
| 915 | 915 | $r['user-agent'] = $r['headers']['user-agent']; |
| 916 | - unset( $r['headers']['user-agent'] ); |
|
| 916 | + unset($r['headers']['user-agent']); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | // Construct Cookie: header if any cookies are set. |
| 920 | - WP_Http::buildCookieHeader( $r ); |
|
| 920 | + WP_Http::buildCookieHeader($r); |
|
| 921 | 921 | |
| 922 | 922 | $arrURL = parse_url($url); |
| 923 | 923 | |
| 924 | 924 | $connect_host = $arrURL['host']; |
| 925 | 925 | |
| 926 | - $secure_transport = ( $arrURL['scheme'] == 'ssl' || $arrURL['scheme'] == 'https' ); |
|
| 927 | - if ( ! isset( $arrURL['port'] ) ) { |
|
| 928 | - if ( $arrURL['scheme'] == 'ssl' || $arrURL['scheme'] == 'https' ) { |
|
| 926 | + $secure_transport = ($arrURL['scheme'] == 'ssl' || $arrURL['scheme'] == 'https'); |
|
| 927 | + if ( ! isset($arrURL['port'])) { |
|
| 928 | + if ($arrURL['scheme'] == 'ssl' || $arrURL['scheme'] == 'https') { |
|
| 929 | 929 | $arrURL['port'] = 443; |
| 930 | 930 | $secure_transport = true; |
| 931 | 931 | } else { |
@@ -934,16 +934,16 @@ discard block |
||
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | // Always pass a Path, defaulting to the root in cases such as http://example.com |
| 937 | - if ( ! isset( $arrURL['path'] ) ) { |
|
| 937 | + if ( ! isset($arrURL['path'])) { |
|
| 938 | 938 | $arrURL['path'] = '/'; |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | - if ( isset( $r['headers']['Host'] ) || isset( $r['headers']['host'] ) ) { |
|
| 942 | - if ( isset( $r['headers']['Host'] ) ) |
|
| 941 | + if (isset($r['headers']['Host']) || isset($r['headers']['host'])) { |
|
| 942 | + if (isset($r['headers']['Host'])) |
|
| 943 | 943 | $arrURL['host'] = $r['headers']['Host']; |
| 944 | 944 | else |
| 945 | 945 | $arrURL['host'] = $r['headers']['host']; |
| 946 | - unset( $r['headers']['Host'], $r['headers']['host'] ); |
|
| 946 | + unset($r['headers']['Host'], $r['headers']['host']); |
|
| 947 | 947 | } |
| 948 | 948 | |
| 949 | 949 | /* |
@@ -951,14 +951,14 @@ discard block |
||
| 951 | 951 | * to ::1, which fails when the server is not set up for it. For compatibility, always |
| 952 | 952 | * connect to the IPv4 address. |
| 953 | 953 | */ |
| 954 | - if ( 'localhost' == strtolower( $connect_host ) ) |
|
| 954 | + if ('localhost' == strtolower($connect_host)) |
|
| 955 | 955 | $connect_host = '127.0.0.1'; |
| 956 | 956 | |
| 957 | - $connect_host = $secure_transport ? 'ssl://' . $connect_host : 'tcp://' . $connect_host; |
|
| 957 | + $connect_host = $secure_transport ? 'ssl://'.$connect_host : 'tcp://'.$connect_host; |
|
| 958 | 958 | |
| 959 | - $is_local = isset( $r['local'] ) && $r['local']; |
|
| 960 | - $ssl_verify = isset( $r['sslverify'] ) && $r['sslverify']; |
|
| 961 | - if ( $is_local ) { |
|
| 959 | + $is_local = isset($r['local']) && $r['local']; |
|
| 960 | + $ssl_verify = isset($r['sslverify']) && $r['sslverify']; |
|
| 961 | + if ($is_local) { |
|
| 962 | 962 | /** |
| 963 | 963 | * Filter whether SSL should be verified for local requests. |
| 964 | 964 | * |
@@ -966,8 +966,8 @@ discard block |
||
| 966 | 966 | * |
| 967 | 967 | * @param bool $ssl_verify Whether to verify the SSL connection. Default true. |
| 968 | 968 | */ |
| 969 | - $ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify ); |
|
| 970 | - } elseif ( ! $is_local ) { |
|
| 969 | + $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); |
|
| 970 | + } elseif ( ! $is_local) { |
|
| 971 | 971 | /** |
| 972 | 972 | * Filter whether SSL should be verified for non-local requests. |
| 973 | 973 | * |
@@ -975,12 +975,12 @@ discard block |
||
| 975 | 975 | * |
| 976 | 976 | * @param bool $ssl_verify Whether to verify the SSL connection. Default true. |
| 977 | 977 | */ |
| 978 | - $ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify ); |
|
| 978 | + $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); |
|
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | $proxy = new WP_HTTP_Proxy(); |
| 982 | 982 | |
| 983 | - $context = stream_context_create( array( |
|
| 983 | + $context = stream_context_create(array( |
|
| 984 | 984 | 'ssl' => array( |
| 985 | 985 | 'verify_peer' => $ssl_verify, |
| 986 | 986 | //'CN_match' => $arrURL['host'], // This is handled by self::verify_ssl_certificate() |
@@ -989,11 +989,11 @@ discard block |
||
| 989 | 989 | 'cafile' => $r['sslcertificates'], |
| 990 | 990 | 'allow_self_signed' => ! $ssl_verify, |
| 991 | 991 | ) |
| 992 | - ) ); |
|
| 992 | + )); |
|
| 993 | 993 | |
| 994 | - $timeout = (int) floor( $r['timeout'] ); |
|
| 994 | + $timeout = (int) floor($r['timeout']); |
|
| 995 | 995 | $utimeout = $timeout == $r['timeout'] ? 0 : 1000000 * $r['timeout'] % 1000000; |
| 996 | - $connect_timeout = max( $timeout, 1 ); |
|
| 996 | + $connect_timeout = max($timeout, 1); |
|
| 997 | 997 | |
| 998 | 998 | // Store error number. |
| 999 | 999 | $connection_error = null; |
@@ -1001,159 +1001,159 @@ discard block |
||
| 1001 | 1001 | // Store error string. |
| 1002 | 1002 | $connection_error_str = null; |
| 1003 | 1003 | |
| 1004 | - if ( !WP_DEBUG ) { |
|
| 1004 | + if ( ! WP_DEBUG) { |
|
| 1005 | 1005 | // In the event that the SSL connection fails, silence the many PHP Warnings. |
| 1006 | - if ( $secure_transport ) |
|
| 1006 | + if ($secure_transport) |
|
| 1007 | 1007 | $error_reporting = error_reporting(0); |
| 1008 | 1008 | |
| 1009 | - if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) |
|
| 1010 | - $handle = @stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1009 | + if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) |
|
| 1010 | + $handle = @stream_socket_client('tcp://'.$proxy->host().':'.$proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context); |
|
| 1011 | 1011 | else |
| 1012 | - $handle = @stream_socket_client( $connect_host . ':' . $arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1012 | + $handle = @stream_socket_client($connect_host.':'.$arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context); |
|
| 1013 | 1013 | |
| 1014 | - if ( $secure_transport ) |
|
| 1015 | - error_reporting( $error_reporting ); |
|
| 1014 | + if ($secure_transport) |
|
| 1015 | + error_reporting($error_reporting); |
|
| 1016 | 1016 | |
| 1017 | 1017 | } else { |
| 1018 | - if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) |
|
| 1019 | - $handle = stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1018 | + if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) |
|
| 1019 | + $handle = stream_socket_client('tcp://'.$proxy->host().':'.$proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context); |
|
| 1020 | 1020 | else |
| 1021 | - $handle = stream_socket_client( $connect_host . ':' . $arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1021 | + $handle = stream_socket_client($connect_host.':'.$arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context); |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | - if ( false === $handle ) { |
|
| 1024 | + if (false === $handle) { |
|
| 1025 | 1025 | // SSL connection failed due to expired/invalid cert, or, OpenSSL configuration is broken. |
| 1026 | - if ( $secure_transport && 0 === $connection_error && '' === $connection_error_str ) |
|
| 1027 | - return new WP_Error( 'http_request_failed', __( 'The SSL certificate for the host could not be verified.' ) ); |
|
| 1026 | + if ($secure_transport && 0 === $connection_error && '' === $connection_error_str) |
|
| 1027 | + return new WP_Error('http_request_failed', __('The SSL certificate for the host could not be verified.')); |
|
| 1028 | 1028 | |
| 1029 | - return new WP_Error('http_request_failed', $connection_error . ': ' . $connection_error_str ); |
|
| 1029 | + return new WP_Error('http_request_failed', $connection_error.': '.$connection_error_str); |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | // Verify that the SSL certificate is valid for this request. |
| 1033 | - if ( $secure_transport && $ssl_verify && ! $proxy->is_enabled() ) { |
|
| 1034 | - if ( ! self::verify_ssl_certificate( $handle, $arrURL['host'] ) ) |
|
| 1035 | - return new WP_Error( 'http_request_failed', __( 'The SSL certificate for the host could not be verified.' ) ); |
|
| 1033 | + if ($secure_transport && $ssl_verify && ! $proxy->is_enabled()) { |
|
| 1034 | + if ( ! self::verify_ssl_certificate($handle, $arrURL['host'])) |
|
| 1035 | + return new WP_Error('http_request_failed', __('The SSL certificate for the host could not be verified.')); |
|
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | - stream_set_timeout( $handle, $timeout, $utimeout ); |
|
| 1038 | + stream_set_timeout($handle, $timeout, $utimeout); |
|
| 1039 | 1039 | |
| 1040 | - if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) //Some proxies require full URL in this field. |
|
| 1040 | + if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) //Some proxies require full URL in this field. |
|
| 1041 | 1041 | $requestPath = $url; |
| 1042 | 1042 | else |
| 1043 | - $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); |
|
| 1043 | + $requestPath = $arrURL['path'].(isset($arrURL['query']) ? '?'.$arrURL['query'] : ''); |
|
| 1044 | 1044 | |
| 1045 | - $strHeaders = strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n"; |
|
| 1045 | + $strHeaders = strtoupper($r['method']).' '.$requestPath.' HTTP/'.$r['httpversion']."\r\n"; |
|
| 1046 | 1046 | |
| 1047 | 1047 | $include_port_in_host_header = ( |
| 1048 | - ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) || |
|
| 1049 | - ( 'http' == $arrURL['scheme'] && 80 != $arrURL['port'] ) || |
|
| 1050 | - ( 'https' == $arrURL['scheme'] && 443 != $arrURL['port'] ) |
|
| 1048 | + ($proxy->is_enabled() && $proxy->send_through_proxy($url)) || |
|
| 1049 | + ('http' == $arrURL['scheme'] && 80 != $arrURL['port']) || |
|
| 1050 | + ('https' == $arrURL['scheme'] && 443 != $arrURL['port']) |
|
| 1051 | 1051 | ); |
| 1052 | 1052 | |
| 1053 | - if ( $include_port_in_host_header ) { |
|
| 1054 | - $strHeaders .= 'Host: ' . $arrURL['host'] . ':' . $arrURL['port'] . "\r\n"; |
|
| 1053 | + if ($include_port_in_host_header) { |
|
| 1054 | + $strHeaders .= 'Host: '.$arrURL['host'].':'.$arrURL['port']."\r\n"; |
|
| 1055 | 1055 | } else { |
| 1056 | - $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n"; |
|
| 1056 | + $strHeaders .= 'Host: '.$arrURL['host']."\r\n"; |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | - if ( isset($r['user-agent']) ) |
|
| 1060 | - $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n"; |
|
| 1059 | + if (isset($r['user-agent'])) |
|
| 1060 | + $strHeaders .= 'User-agent: '.$r['user-agent']."\r\n"; |
|
| 1061 | 1061 | |
| 1062 | - if ( is_array($r['headers']) ) { |
|
| 1063 | - foreach ( (array) $r['headers'] as $header => $headerValue ) |
|
| 1064 | - $strHeaders .= $header . ': ' . $headerValue . "\r\n"; |
|
| 1062 | + if (is_array($r['headers'])) { |
|
| 1063 | + foreach ((array) $r['headers'] as $header => $headerValue) |
|
| 1064 | + $strHeaders .= $header.': '.$headerValue."\r\n"; |
|
| 1065 | 1065 | } else { |
| 1066 | 1066 | $strHeaders .= $r['headers']; |
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | - if ( $proxy->use_authentication() ) |
|
| 1070 | - $strHeaders .= $proxy->authentication_header() . "\r\n"; |
|
| 1069 | + if ($proxy->use_authentication()) |
|
| 1070 | + $strHeaders .= $proxy->authentication_header()."\r\n"; |
|
| 1071 | 1071 | |
| 1072 | 1072 | $strHeaders .= "\r\n"; |
| 1073 | 1073 | |
| 1074 | - if ( ! is_null($r['body']) ) |
|
| 1074 | + if ( ! is_null($r['body'])) |
|
| 1075 | 1075 | $strHeaders .= $r['body']; |
| 1076 | 1076 | |
| 1077 | 1077 | fwrite($handle, $strHeaders); |
| 1078 | 1078 | |
| 1079 | - if ( ! $r['blocking'] ) { |
|
| 1080 | - stream_set_blocking( $handle, 0 ); |
|
| 1081 | - fclose( $handle ); |
|
| 1082 | - return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); |
|
| 1079 | + if ( ! $r['blocking']) { |
|
| 1080 | + stream_set_blocking($handle, 0); |
|
| 1081 | + fclose($handle); |
|
| 1082 | + return array('headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array()); |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | $strResponse = ''; |
| 1086 | 1086 | $bodyStarted = false; |
| 1087 | 1087 | $keep_reading = true; |
| 1088 | 1088 | $block_size = 4096; |
| 1089 | - if ( isset( $r['limit_response_size'] ) ) |
|
| 1090 | - $block_size = min( $block_size, $r['limit_response_size'] ); |
|
| 1089 | + if (isset($r['limit_response_size'])) |
|
| 1090 | + $block_size = min($block_size, $r['limit_response_size']); |
|
| 1091 | 1091 | |
| 1092 | 1092 | // If streaming to a file setup the file handle. |
| 1093 | - if ( $r['stream'] ) { |
|
| 1094 | - if ( ! WP_DEBUG ) |
|
| 1095 | - $stream_handle = @fopen( $r['filename'], 'w+' ); |
|
| 1093 | + if ($r['stream']) { |
|
| 1094 | + if ( ! WP_DEBUG) |
|
| 1095 | + $stream_handle = @fopen($r['filename'], 'w+'); |
|
| 1096 | 1096 | else |
| 1097 | - $stream_handle = fopen( $r['filename'], 'w+' ); |
|
| 1098 | - if ( ! $stream_handle ) |
|
| 1099 | - return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) ); |
|
| 1097 | + $stream_handle = fopen($r['filename'], 'w+'); |
|
| 1098 | + if ( ! $stream_handle) |
|
| 1099 | + return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $r['filename'])); |
|
| 1100 | 1100 | |
| 1101 | 1101 | $bytes_written = 0; |
| 1102 | - while ( ! feof($handle) && $keep_reading ) { |
|
| 1103 | - $block = fread( $handle, $block_size ); |
|
| 1104 | - if ( ! $bodyStarted ) { |
|
| 1102 | + while ( ! feof($handle) && $keep_reading) { |
|
| 1103 | + $block = fread($handle, $block_size); |
|
| 1104 | + if ( ! $bodyStarted) { |
|
| 1105 | 1105 | $strResponse .= $block; |
| 1106 | - if ( strpos( $strResponse, "\r\n\r\n" ) ) { |
|
| 1107 | - $process = WP_Http::processResponse( $strResponse ); |
|
| 1106 | + if (strpos($strResponse, "\r\n\r\n")) { |
|
| 1107 | + $process = WP_Http::processResponse($strResponse); |
|
| 1108 | 1108 | $bodyStarted = true; |
| 1109 | 1109 | $block = $process['body']; |
| 1110 | - unset( $strResponse ); |
|
| 1110 | + unset($strResponse); |
|
| 1111 | 1111 | $process['body'] = ''; |
| 1112 | 1112 | } |
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | - $this_block_size = strlen( $block ); |
|
| 1115 | + $this_block_size = strlen($block); |
|
| 1116 | 1116 | |
| 1117 | - if ( isset( $r['limit_response_size'] ) && ( $bytes_written + $this_block_size ) > $r['limit_response_size'] ) { |
|
| 1118 | - $this_block_size = ( $r['limit_response_size'] - $bytes_written ); |
|
| 1119 | - $block = substr( $block, 0, $this_block_size ); |
|
| 1117 | + if (isset($r['limit_response_size']) && ($bytes_written + $this_block_size) > $r['limit_response_size']) { |
|
| 1118 | + $this_block_size = ($r['limit_response_size'] - $bytes_written); |
|
| 1119 | + $block = substr($block, 0, $this_block_size); |
|
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | - $bytes_written_to_file = fwrite( $stream_handle, $block ); |
|
| 1122 | + $bytes_written_to_file = fwrite($stream_handle, $block); |
|
| 1123 | 1123 | |
| 1124 | - if ( $bytes_written_to_file != $this_block_size ) { |
|
| 1125 | - fclose( $handle ); |
|
| 1126 | - fclose( $stream_handle ); |
|
| 1127 | - return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) ); |
|
| 1124 | + if ($bytes_written_to_file != $this_block_size) { |
|
| 1125 | + fclose($handle); |
|
| 1126 | + fclose($stream_handle); |
|
| 1127 | + return new WP_Error('http_request_failed', __('Failed to write request to temporary file.')); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | $bytes_written += $bytes_written_to_file; |
| 1131 | 1131 | |
| 1132 | - $keep_reading = !isset( $r['limit_response_size'] ) || $bytes_written < $r['limit_response_size']; |
|
| 1132 | + $keep_reading = ! isset($r['limit_response_size']) || $bytes_written < $r['limit_response_size']; |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | - fclose( $stream_handle ); |
|
| 1135 | + fclose($stream_handle); |
|
| 1136 | 1136 | |
| 1137 | 1137 | } else { |
| 1138 | 1138 | $header_length = 0; |
| 1139 | - while ( ! feof( $handle ) && $keep_reading ) { |
|
| 1140 | - $block = fread( $handle, $block_size ); |
|
| 1139 | + while ( ! feof($handle) && $keep_reading) { |
|
| 1140 | + $block = fread($handle, $block_size); |
|
| 1141 | 1141 | $strResponse .= $block; |
| 1142 | - if ( ! $bodyStarted && strpos( $strResponse, "\r\n\r\n" ) ) { |
|
| 1143 | - $header_length = strpos( $strResponse, "\r\n\r\n" ) + 4; |
|
| 1142 | + if ( ! $bodyStarted && strpos($strResponse, "\r\n\r\n")) { |
|
| 1143 | + $header_length = strpos($strResponse, "\r\n\r\n") + 4; |
|
| 1144 | 1144 | $bodyStarted = true; |
| 1145 | 1145 | } |
| 1146 | - $keep_reading = ( ! $bodyStarted || !isset( $r['limit_response_size'] ) || strlen( $strResponse ) < ( $header_length + $r['limit_response_size'] ) ); |
|
| 1146 | + $keep_reading = ( ! $bodyStarted || ! isset($r['limit_response_size']) || strlen($strResponse) < ($header_length + $r['limit_response_size'])); |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | - $process = WP_Http::processResponse( $strResponse ); |
|
| 1150 | - unset( $strResponse ); |
|
| 1149 | + $process = WP_Http::processResponse($strResponse); |
|
| 1150 | + unset($strResponse); |
|
| 1151 | 1151 | |
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | - fclose( $handle ); |
|
| 1154 | + fclose($handle); |
|
| 1155 | 1155 | |
| 1156 | - $arrHeaders = WP_Http::processHeaders( $process['headers'], $url ); |
|
| 1156 | + $arrHeaders = WP_Http::processHeaders($process['headers'], $url); |
|
| 1157 | 1157 | |
| 1158 | 1158 | $response = array( |
| 1159 | 1159 | 'headers' => $arrHeaders['headers'], |
@@ -1165,18 +1165,18 @@ discard block |
||
| 1165 | 1165 | ); |
| 1166 | 1166 | |
| 1167 | 1167 | // Handle redirects. |
| 1168 | - if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) |
|
| 1168 | + if (false !== ($redirect_response = WP_HTTP::handle_redirects($url, $r, $response))) |
|
| 1169 | 1169 | return $redirect_response; |
| 1170 | 1170 | |
| 1171 | 1171 | // If the body was chunk encoded, then decode it. |
| 1172 | - if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] ) |
|
| 1172 | + if ( ! empty($process['body']) && isset($arrHeaders['headers']['transfer-encoding']) && 'chunked' == $arrHeaders['headers']['transfer-encoding']) |
|
| 1173 | 1173 | $process['body'] = WP_Http::chunkTransferDecode($process['body']); |
| 1174 | 1174 | |
| 1175 | - if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($arrHeaders['headers']) ) |
|
| 1176 | - $process['body'] = WP_Http_Encoding::decompress( $process['body'] ); |
|
| 1175 | + if (true === $r['decompress'] && true === WP_Http_Encoding::should_decode($arrHeaders['headers'])) |
|
| 1176 | + $process['body'] = WP_Http_Encoding::decompress($process['body']); |
|
| 1177 | 1177 | |
| 1178 | - if ( isset( $r['limit_response_size'] ) && strlen( $process['body'] ) > $r['limit_response_size'] ) |
|
| 1179 | - $process['body'] = substr( $process['body'], 0, $r['limit_response_size'] ); |
|
| 1178 | + if (isset($r['limit_response_size']) && strlen($process['body']) > $r['limit_response_size']) |
|
| 1179 | + $process['body'] = substr($process['body'], 0, $r['limit_response_size']); |
|
| 1180 | 1180 | |
| 1181 | 1181 | $response['body'] = $process['body']; |
| 1182 | 1182 | |
@@ -1200,51 +1200,51 @@ discard block |
||
| 1200 | 1200 | * @param string $host The hostname being requested |
| 1201 | 1201 | * @return bool If the cerficiate presented in $stream is valid for $host |
| 1202 | 1202 | */ |
| 1203 | - public static function verify_ssl_certificate( $stream, $host ) { |
|
| 1204 | - $context_options = stream_context_get_options( $stream ); |
|
| 1203 | + public static function verify_ssl_certificate($stream, $host) { |
|
| 1204 | + $context_options = stream_context_get_options($stream); |
|
| 1205 | 1205 | |
| 1206 | - if ( empty( $context_options['ssl']['peer_certificate'] ) ) |
|
| 1206 | + if (empty($context_options['ssl']['peer_certificate'])) |
|
| 1207 | 1207 | return false; |
| 1208 | 1208 | |
| 1209 | - $cert = openssl_x509_parse( $context_options['ssl']['peer_certificate'] ); |
|
| 1210 | - if ( ! $cert ) |
|
| 1209 | + $cert = openssl_x509_parse($context_options['ssl']['peer_certificate']); |
|
| 1210 | + if ( ! $cert) |
|
| 1211 | 1211 | return false; |
| 1212 | 1212 | |
| 1213 | 1213 | /* |
| 1214 | 1214 | * If the request is being made to an IP address, we'll validate against IP fields |
| 1215 | 1215 | * in the cert (if they exist) |
| 1216 | 1216 | */ |
| 1217 | - $host_type = ( WP_HTTP::is_ip_address( $host ) ? 'ip' : 'dns' ); |
|
| 1217 | + $host_type = (WP_HTTP::is_ip_address($host) ? 'ip' : 'dns'); |
|
| 1218 | 1218 | |
| 1219 | 1219 | $certificate_hostnames = array(); |
| 1220 | - if ( ! empty( $cert['extensions']['subjectAltName'] ) ) { |
|
| 1221 | - $match_against = preg_split( '/,\s*/', $cert['extensions']['subjectAltName'] ); |
|
| 1222 | - foreach ( $match_against as $match ) { |
|
| 1223 | - list( $match_type, $match_host ) = explode( ':', $match ); |
|
| 1224 | - if ( $host_type == strtolower( trim( $match_type ) ) ) // IP: or DNS: |
|
| 1225 | - $certificate_hostnames[] = strtolower( trim( $match_host ) ); |
|
| 1220 | + if ( ! empty($cert['extensions']['subjectAltName'])) { |
|
| 1221 | + $match_against = preg_split('/,\s*/', $cert['extensions']['subjectAltName']); |
|
| 1222 | + foreach ($match_against as $match) { |
|
| 1223 | + list($match_type, $match_host) = explode(':', $match); |
|
| 1224 | + if ($host_type == strtolower(trim($match_type))) // IP: or DNS: |
|
| 1225 | + $certificate_hostnames[] = strtolower(trim($match_host)); |
|
| 1226 | 1226 | } |
| 1227 | - } elseif ( !empty( $cert['subject']['CN'] ) ) { |
|
| 1227 | + } elseif ( ! empty($cert['subject']['CN'])) { |
|
| 1228 | 1228 | // Only use the CN when the certificate includes no subjectAltName extension. |
| 1229 | - $certificate_hostnames[] = strtolower( $cert['subject']['CN'] ); |
|
| 1229 | + $certificate_hostnames[] = strtolower($cert['subject']['CN']); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | // Exact hostname/IP matches. |
| 1233 | - if ( in_array( strtolower( $host ), $certificate_hostnames ) ) |
|
| 1233 | + if (in_array(strtolower($host), $certificate_hostnames)) |
|
| 1234 | 1234 | return true; |
| 1235 | 1235 | |
| 1236 | 1236 | // IP's can't be wildcards, Stop processing. |
| 1237 | - if ( 'ip' == $host_type ) |
|
| 1237 | + if ('ip' == $host_type) |
|
| 1238 | 1238 | return false; |
| 1239 | 1239 | |
| 1240 | 1240 | // Test to see if the domain is at least 2 deep for wildcard support. |
| 1241 | - if ( substr_count( $host, '.' ) < 2 ) |
|
| 1241 | + if (substr_count($host, '.') < 2) |
|
| 1242 | 1242 | return false; |
| 1243 | 1243 | |
| 1244 | 1244 | // Wildcard subdomains certs (*.example.com) are valid for a.example.com but not a.b.example.com. |
| 1245 | - $wildcard_host = preg_replace( '/^[^.]+\./', '*.', $host ); |
|
| 1245 | + $wildcard_host = preg_replace('/^[^.]+\./', '*.', $host); |
|
| 1246 | 1246 | |
| 1247 | - return in_array( strtolower( $wildcard_host ), $certificate_hostnames ); |
|
| 1247 | + return in_array(strtolower($wildcard_host), $certificate_hostnames); |
|
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | /** |
@@ -1257,16 +1257,16 @@ discard block |
||
| 1257 | 1257 | * |
| 1258 | 1258 | * @return bool False means this class can not be used, true means it can. |
| 1259 | 1259 | */ |
| 1260 | - public static function test( $args = array() ) { |
|
| 1261 | - if ( ! function_exists( 'stream_socket_client' ) ) |
|
| 1260 | + public static function test($args = array()) { |
|
| 1261 | + if ( ! function_exists('stream_socket_client')) |
|
| 1262 | 1262 | return false; |
| 1263 | 1263 | |
| 1264 | - $is_ssl = isset( $args['ssl'] ) && $args['ssl']; |
|
| 1264 | + $is_ssl = isset($args['ssl']) && $args['ssl']; |
|
| 1265 | 1265 | |
| 1266 | - if ( $is_ssl ) { |
|
| 1267 | - if ( ! extension_loaded( 'openssl' ) ) |
|
| 1266 | + if ($is_ssl) { |
|
| 1267 | + if ( ! extension_loaded('openssl')) |
|
| 1268 | 1268 | return false; |
| 1269 | - if ( ! function_exists( 'openssl_x509_parse' ) ) |
|
| 1269 | + if ( ! function_exists('openssl_x509_parse')) |
|
| 1270 | 1270 | return false; |
| 1271 | 1271 | } |
| 1272 | 1272 | |
@@ -1278,7 +1278,7 @@ discard block |
||
| 1278 | 1278 | * @param bool $use_class Whether the class can be used. Default true. |
| 1279 | 1279 | * @param array $args Request arguments. |
| 1280 | 1280 | */ |
| 1281 | - return apply_filters( 'use_streams_transport', true, $args ); |
|
| 1281 | + return apply_filters('use_streams_transport', true, $args); |
|
| 1282 | 1282 | } |
| 1283 | 1283 | } |
| 1284 | 1284 | |
@@ -1371,125 +1371,125 @@ discard block |
||
| 1371 | 1371 | 'headers' => array(), 'body' => null, 'cookies' => array() |
| 1372 | 1372 | ); |
| 1373 | 1373 | |
| 1374 | - $r = wp_parse_args( $args, $defaults ); |
|
| 1374 | + $r = wp_parse_args($args, $defaults); |
|
| 1375 | 1375 | |
| 1376 | - if ( isset( $r['headers']['User-Agent'] ) ) { |
|
| 1376 | + if (isset($r['headers']['User-Agent'])) { |
|
| 1377 | 1377 | $r['user-agent'] = $r['headers']['User-Agent']; |
| 1378 | - unset( $r['headers']['User-Agent'] ); |
|
| 1379 | - } elseif ( isset( $r['headers']['user-agent'] ) ) { |
|
| 1378 | + unset($r['headers']['User-Agent']); |
|
| 1379 | + } elseif (isset($r['headers']['user-agent'])) { |
|
| 1380 | 1380 | $r['user-agent'] = $r['headers']['user-agent']; |
| 1381 | - unset( $r['headers']['user-agent'] ); |
|
| 1381 | + unset($r['headers']['user-agent']); |
|
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | 1384 | // Construct Cookie: header if any cookies are set. |
| 1385 | - WP_Http::buildCookieHeader( $r ); |
|
| 1385 | + WP_Http::buildCookieHeader($r); |
|
| 1386 | 1386 | |
| 1387 | 1387 | $handle = curl_init(); |
| 1388 | 1388 | |
| 1389 | 1389 | // cURL offers really easy proxy support. |
| 1390 | 1390 | $proxy = new WP_HTTP_Proxy(); |
| 1391 | 1391 | |
| 1392 | - if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { |
|
| 1392 | + if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) { |
|
| 1393 | 1393 | |
| 1394 | - curl_setopt( $handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP ); |
|
| 1395 | - curl_setopt( $handle, CURLOPT_PROXY, $proxy->host() ); |
|
| 1396 | - curl_setopt( $handle, CURLOPT_PROXYPORT, $proxy->port() ); |
|
| 1394 | + curl_setopt($handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); |
|
| 1395 | + curl_setopt($handle, CURLOPT_PROXY, $proxy->host()); |
|
| 1396 | + curl_setopt($handle, CURLOPT_PROXYPORT, $proxy->port()); |
|
| 1397 | 1397 | |
| 1398 | - if ( $proxy->use_authentication() ) { |
|
| 1399 | - curl_setopt( $handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY ); |
|
| 1400 | - curl_setopt( $handle, CURLOPT_PROXYUSERPWD, $proxy->authentication() ); |
|
| 1398 | + if ($proxy->use_authentication()) { |
|
| 1399 | + curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY); |
|
| 1400 | + curl_setopt($handle, CURLOPT_PROXYUSERPWD, $proxy->authentication()); |
|
| 1401 | 1401 | } |
| 1402 | 1402 | } |
| 1403 | 1403 | |
| 1404 | 1404 | $is_local = isset($r['local']) && $r['local']; |
| 1405 | 1405 | $ssl_verify = isset($r['sslverify']) && $r['sslverify']; |
| 1406 | - if ( $is_local ) { |
|
| 1406 | + if ($is_local) { |
|
| 1407 | 1407 | /** This filter is documented in wp-includes/class-http.php */ |
| 1408 | - $ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify ); |
|
| 1409 | - } elseif ( ! $is_local ) { |
|
| 1408 | + $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); |
|
| 1409 | + } elseif ( ! $is_local) { |
|
| 1410 | 1410 | /** This filter is documented in wp-includes/class-http.php */ |
| 1411 | - $ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify ); |
|
| 1411 | + $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); |
|
| 1412 | 1412 | } |
| 1413 | 1413 | |
| 1414 | 1414 | /* |
| 1415 | 1415 | * CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT expect integers. Have to use ceil since. |
| 1416 | 1416 | * a value of 0 will allow an unlimited timeout. |
| 1417 | 1417 | */ |
| 1418 | - $timeout = (int) ceil( $r['timeout'] ); |
|
| 1419 | - curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout ); |
|
| 1420 | - curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout ); |
|
| 1418 | + $timeout = (int) ceil($r['timeout']); |
|
| 1419 | + curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, $timeout); |
|
| 1420 | + curl_setopt($handle, CURLOPT_TIMEOUT, $timeout); |
|
| 1421 | 1421 | |
| 1422 | - curl_setopt( $handle, CURLOPT_URL, $url); |
|
| 1423 | - curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true ); |
|
| 1424 | - curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, ( $ssl_verify === true ) ? 2 : false ); |
|
| 1425 | - curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify ); |
|
| 1426 | - curl_setopt( $handle, CURLOPT_CAINFO, $r['sslcertificates'] ); |
|
| 1427 | - curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] ); |
|
| 1422 | + curl_setopt($handle, CURLOPT_URL, $url); |
|
| 1423 | + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); |
|
| 1424 | + curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, ($ssl_verify === true) ? 2 : false); |
|
| 1425 | + curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify); |
|
| 1426 | + curl_setopt($handle, CURLOPT_CAINFO, $r['sslcertificates']); |
|
| 1427 | + curl_setopt($handle, CURLOPT_USERAGENT, $r['user-agent']); |
|
| 1428 | 1428 | |
| 1429 | 1429 | /* |
| 1430 | 1430 | * The option doesn't work with safe mode or when open_basedir is set, and there's |
| 1431 | 1431 | * a bug #17490 with redirected POST requests, so handle redirections outside Curl. |
| 1432 | 1432 | */ |
| 1433 | - curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false ); |
|
| 1434 | - if ( defined( 'CURLOPT_PROTOCOLS' ) ) // PHP 5.2.10 / cURL 7.19.4 |
|
| 1435 | - curl_setopt( $handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS ); |
|
| 1433 | + curl_setopt($handle, CURLOPT_FOLLOWLOCATION, false); |
|
| 1434 | + if (defined('CURLOPT_PROTOCOLS')) // PHP 5.2.10 / cURL 7.19.4 |
|
| 1435 | + curl_setopt($handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
|
| 1436 | 1436 | |
| 1437 | - switch ( $r['method'] ) { |
|
| 1437 | + switch ($r['method']) { |
|
| 1438 | 1438 | case 'HEAD': |
| 1439 | - curl_setopt( $handle, CURLOPT_NOBODY, true ); |
|
| 1439 | + curl_setopt($handle, CURLOPT_NOBODY, true); |
|
| 1440 | 1440 | break; |
| 1441 | 1441 | case 'POST': |
| 1442 | - curl_setopt( $handle, CURLOPT_POST, true ); |
|
| 1443 | - curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
| 1442 | + curl_setopt($handle, CURLOPT_POST, true); |
|
| 1443 | + curl_setopt($handle, CURLOPT_POSTFIELDS, $r['body']); |
|
| 1444 | 1444 | break; |
| 1445 | 1445 | case 'PUT': |
| 1446 | - curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, 'PUT' ); |
|
| 1447 | - curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
| 1446 | + curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
| 1447 | + curl_setopt($handle, CURLOPT_POSTFIELDS, $r['body']); |
|
| 1448 | 1448 | break; |
| 1449 | 1449 | default: |
| 1450 | - curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] ); |
|
| 1451 | - if ( ! is_null( $r['body'] ) ) |
|
| 1452 | - curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
| 1450 | + curl_setopt($handle, CURLOPT_CUSTOMREQUEST, $r['method']); |
|
| 1451 | + if ( ! is_null($r['body'])) |
|
| 1452 | + curl_setopt($handle, CURLOPT_POSTFIELDS, $r['body']); |
|
| 1453 | 1453 | break; |
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | - if ( true === $r['blocking'] ) { |
|
| 1457 | - curl_setopt( $handle, CURLOPT_HEADERFUNCTION, array( $this, 'stream_headers' ) ); |
|
| 1458 | - curl_setopt( $handle, CURLOPT_WRITEFUNCTION, array( $this, 'stream_body' ) ); |
|
| 1456 | + if (true === $r['blocking']) { |
|
| 1457 | + curl_setopt($handle, CURLOPT_HEADERFUNCTION, array($this, 'stream_headers')); |
|
| 1458 | + curl_setopt($handle, CURLOPT_WRITEFUNCTION, array($this, 'stream_body')); |
|
| 1459 | 1459 | } |
| 1460 | 1460 | |
| 1461 | - curl_setopt( $handle, CURLOPT_HEADER, false ); |
|
| 1461 | + curl_setopt($handle, CURLOPT_HEADER, false); |
|
| 1462 | 1462 | |
| 1463 | - if ( isset( $r['limit_response_size'] ) ) |
|
| 1464 | - $this->max_body_length = intval( $r['limit_response_size'] ); |
|
| 1463 | + if (isset($r['limit_response_size'])) |
|
| 1464 | + $this->max_body_length = intval($r['limit_response_size']); |
|
| 1465 | 1465 | else |
| 1466 | 1466 | $this->max_body_length = false; |
| 1467 | 1467 | |
| 1468 | 1468 | // If streaming to a file open a file handle, and setup our curl streaming handler. |
| 1469 | - if ( $r['stream'] ) { |
|
| 1470 | - if ( ! WP_DEBUG ) |
|
| 1471 | - $this->stream_handle = @fopen( $r['filename'], 'w+' ); |
|
| 1469 | + if ($r['stream']) { |
|
| 1470 | + if ( ! WP_DEBUG) |
|
| 1471 | + $this->stream_handle = @fopen($r['filename'], 'w+'); |
|
| 1472 | 1472 | else |
| 1473 | - $this->stream_handle = fopen( $r['filename'], 'w+' ); |
|
| 1474 | - if ( ! $this->stream_handle ) |
|
| 1475 | - return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) ); |
|
| 1473 | + $this->stream_handle = fopen($r['filename'], 'w+'); |
|
| 1474 | + if ( ! $this->stream_handle) |
|
| 1475 | + return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $r['filename'])); |
|
| 1476 | 1476 | } else { |
| 1477 | 1477 | $this->stream_handle = false; |
| 1478 | 1478 | } |
| 1479 | 1479 | |
| 1480 | - if ( !empty( $r['headers'] ) ) { |
|
| 1480 | + if ( ! empty($r['headers'])) { |
|
| 1481 | 1481 | // cURL expects full header strings in each element. |
| 1482 | 1482 | $headers = array(); |
| 1483 | - foreach ( $r['headers'] as $name => $value ) { |
|
| 1483 | + foreach ($r['headers'] as $name => $value) { |
|
| 1484 | 1484 | $headers[] = "{$name}: $value"; |
| 1485 | 1485 | } |
| 1486 | - curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers ); |
|
| 1486 | + curl_setopt($handle, CURLOPT_HTTPHEADER, $headers); |
|
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | - if ( $r['httpversion'] == '1.0' ) |
|
| 1490 | - curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); |
|
| 1489 | + if ($r['httpversion'] == '1.0') |
|
| 1490 | + curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
|
| 1491 | 1491 | else |
| 1492 | - curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); |
|
| 1492 | + curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
| 1493 | 1493 | |
| 1494 | 1494 | /** |
| 1495 | 1495 | * Fires before the cURL request is executed. |
@@ -1503,27 +1503,27 @@ discard block |
||
| 1503 | 1503 | * @param array $r The HTTP request arguments. |
| 1504 | 1504 | * @param string $url The request URL. |
| 1505 | 1505 | */ |
| 1506 | - do_action_ref_array( 'http_api_curl', array( &$handle, $r, $url ) ); |
|
| 1506 | + do_action_ref_array('http_api_curl', array(&$handle, $r, $url)); |
|
| 1507 | 1507 | |
| 1508 | 1508 | // We don't need to return the body, so don't. Just execute request and return. |
| 1509 | - if ( ! $r['blocking'] ) { |
|
| 1510 | - curl_exec( $handle ); |
|
| 1509 | + if ( ! $r['blocking']) { |
|
| 1510 | + curl_exec($handle); |
|
| 1511 | 1511 | |
| 1512 | - if ( $curl_error = curl_error( $handle ) ) { |
|
| 1513 | - curl_close( $handle ); |
|
| 1514 | - return new WP_Error( 'http_request_failed', $curl_error ); |
|
| 1512 | + if ($curl_error = curl_error($handle)) { |
|
| 1513 | + curl_close($handle); |
|
| 1514 | + return new WP_Error('http_request_failed', $curl_error); |
|
| 1515 | 1515 | } |
| 1516 | - if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) { |
|
| 1517 | - curl_close( $handle ); |
|
| 1518 | - return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); |
|
| 1516 | + if (in_array(curl_getinfo($handle, CURLINFO_HTTP_CODE), array(301, 302))) { |
|
| 1517 | + curl_close($handle); |
|
| 1518 | + return new WP_Error('http_request_failed', __('Too many redirects.')); |
|
| 1519 | 1519 | } |
| 1520 | 1520 | |
| 1521 | - curl_close( $handle ); |
|
| 1522 | - return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); |
|
| 1521 | + curl_close($handle); |
|
| 1522 | + return array('headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array()); |
|
| 1523 | 1523 | } |
| 1524 | 1524 | |
| 1525 | - curl_exec( $handle ); |
|
| 1526 | - $theHeaders = WP_Http::processHeaders( $this->headers, $url ); |
|
| 1525 | + curl_exec($handle); |
|
| 1526 | + $theHeaders = WP_Http::processHeaders($this->headers, $url); |
|
| 1527 | 1527 | $theBody = $this->body; |
| 1528 | 1528 | $bytes_written_total = $this->bytes_written_total; |
| 1529 | 1529 | |
@@ -1531,37 +1531,37 @@ discard block |
||
| 1531 | 1531 | $this->body = ''; |
| 1532 | 1532 | $this->bytes_written_total = 0; |
| 1533 | 1533 | |
| 1534 | - $curl_error = curl_errno( $handle ); |
|
| 1534 | + $curl_error = curl_errno($handle); |
|
| 1535 | 1535 | |
| 1536 | 1536 | // If an error occurred, or, no response. |
| 1537 | - if ( $curl_error || ( 0 == strlen( $theBody ) && empty( $theHeaders['headers'] ) ) ) { |
|
| 1538 | - if ( CURLE_WRITE_ERROR /* 23 */ == $curl_error ) { |
|
| 1539 | - if ( ! $this->max_body_length || $this->max_body_length != $bytes_written_total ) { |
|
| 1540 | - if ( $r['stream'] ) { |
|
| 1541 | - curl_close( $handle ); |
|
| 1542 | - fclose( $this->stream_handle ); |
|
| 1543 | - return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) ); |
|
| 1537 | + if ($curl_error || (0 == strlen($theBody) && empty($theHeaders['headers']))) { |
|
| 1538 | + if (CURLE_WRITE_ERROR /* 23 */ == $curl_error) { |
|
| 1539 | + if ( ! $this->max_body_length || $this->max_body_length != $bytes_written_total) { |
|
| 1540 | + if ($r['stream']) { |
|
| 1541 | + curl_close($handle); |
|
| 1542 | + fclose($this->stream_handle); |
|
| 1543 | + return new WP_Error('http_request_failed', __('Failed to write request to temporary file.')); |
|
| 1544 | 1544 | } else { |
| 1545 | - curl_close( $handle ); |
|
| 1546 | - return new WP_Error( 'http_request_failed', curl_error( $handle ) ); |
|
| 1545 | + curl_close($handle); |
|
| 1546 | + return new WP_Error('http_request_failed', curl_error($handle)); |
|
| 1547 | 1547 | } |
| 1548 | 1548 | } |
| 1549 | 1549 | } else { |
| 1550 | - if ( $curl_error = curl_error( $handle ) ) { |
|
| 1551 | - curl_close( $handle ); |
|
| 1552 | - return new WP_Error( 'http_request_failed', $curl_error ); |
|
| 1550 | + if ($curl_error = curl_error($handle)) { |
|
| 1551 | + curl_close($handle); |
|
| 1552 | + return new WP_Error('http_request_failed', $curl_error); |
|
| 1553 | 1553 | } |
| 1554 | 1554 | } |
| 1555 | - if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) { |
|
| 1556 | - curl_close( $handle ); |
|
| 1557 | - return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); |
|
| 1555 | + if (in_array(curl_getinfo($handle, CURLINFO_HTTP_CODE), array(301, 302))) { |
|
| 1556 | + curl_close($handle); |
|
| 1557 | + return new WP_Error('http_request_failed', __('Too many redirects.')); |
|
| 1558 | 1558 | } |
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | - curl_close( $handle ); |
|
| 1561 | + curl_close($handle); |
|
| 1562 | 1562 | |
| 1563 | - if ( $r['stream'] ) |
|
| 1564 | - fclose( $this->stream_handle ); |
|
| 1563 | + if ($r['stream']) |
|
| 1564 | + fclose($this->stream_handle); |
|
| 1565 | 1565 | |
| 1566 | 1566 | $response = array( |
| 1567 | 1567 | 'headers' => $theHeaders['headers'], |
@@ -1572,11 +1572,11 @@ discard block |
||
| 1572 | 1572 | ); |
| 1573 | 1573 | |
| 1574 | 1574 | // Handle redirects. |
| 1575 | - if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) |
|
| 1575 | + if (false !== ($redirect_response = WP_HTTP::handle_redirects($url, $r, $response))) |
|
| 1576 | 1576 | return $redirect_response; |
| 1577 | 1577 | |
| 1578 | - if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) ) |
|
| 1579 | - $theBody = WP_Http_Encoding::decompress( $theBody ); |
|
| 1578 | + if (true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers'])) |
|
| 1579 | + $theBody = WP_Http_Encoding::decompress($theBody); |
|
| 1580 | 1580 | |
| 1581 | 1581 | $response['body'] = $theBody; |
| 1582 | 1582 | |
@@ -1592,9 +1592,9 @@ discard block |
||
| 1592 | 1592 | * @access private |
| 1593 | 1593 | * @return int |
| 1594 | 1594 | */ |
| 1595 | - private function stream_headers( $handle, $headers ) { |
|
| 1595 | + private function stream_headers($handle, $headers) { |
|
| 1596 | 1596 | $this->headers .= $headers; |
| 1597 | - return strlen( $headers ); |
|
| 1597 | + return strlen($headers); |
|
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | 1600 | /** |
@@ -1607,16 +1607,16 @@ discard block |
||
| 1607 | 1607 | * @access private |
| 1608 | 1608 | * @return int |
| 1609 | 1609 | */ |
| 1610 | - private function stream_body( $handle, $data ) { |
|
| 1611 | - $data_length = strlen( $data ); |
|
| 1610 | + private function stream_body($handle, $data) { |
|
| 1611 | + $data_length = strlen($data); |
|
| 1612 | 1612 | |
| 1613 | - if ( $this->max_body_length && ( $this->bytes_written_total + $data_length ) > $this->max_body_length ) { |
|
| 1614 | - $data_length = ( $this->max_body_length - $this->bytes_written_total ); |
|
| 1615 | - $data = substr( $data, 0, $data_length ); |
|
| 1613 | + if ($this->max_body_length && ($this->bytes_written_total + $data_length) > $this->max_body_length) { |
|
| 1614 | + $data_length = ($this->max_body_length - $this->bytes_written_total); |
|
| 1615 | + $data = substr($data, 0, $data_length); |
|
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | - if ( $this->stream_handle ) { |
|
| 1619 | - $bytes_written = fwrite( $this->stream_handle, $data ); |
|
| 1618 | + if ($this->stream_handle) { |
|
| 1619 | + $bytes_written = fwrite($this->stream_handle, $data); |
|
| 1620 | 1620 | } else { |
| 1621 | 1621 | $this->body .= $data; |
| 1622 | 1622 | $bytes_written = $data_length; |
@@ -1636,16 +1636,16 @@ discard block |
||
| 1636 | 1636 | * |
| 1637 | 1637 | * @return bool False means this class can not be used, true means it can. |
| 1638 | 1638 | */ |
| 1639 | - public static function test( $args = array() ) { |
|
| 1640 | - if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) |
|
| 1639 | + public static function test($args = array()) { |
|
| 1640 | + if ( ! function_exists('curl_init') || ! function_exists('curl_exec')) |
|
| 1641 | 1641 | return false; |
| 1642 | 1642 | |
| 1643 | - $is_ssl = isset( $args['ssl'] ) && $args['ssl']; |
|
| 1643 | + $is_ssl = isset($args['ssl']) && $args['ssl']; |
|
| 1644 | 1644 | |
| 1645 | - if ( $is_ssl ) { |
|
| 1645 | + if ($is_ssl) { |
|
| 1646 | 1646 | $curl_version = curl_version(); |
| 1647 | 1647 | // Check whether this cURL version support SSL requests. |
| 1648 | - if ( ! (CURL_VERSION_SSL & $curl_version['features']) ) |
|
| 1648 | + if ( ! (CURL_VERSION_SSL & $curl_version['features'])) |
|
| 1649 | 1649 | return false; |
| 1650 | 1650 | } |
| 1651 | 1651 | |
@@ -1657,7 +1657,7 @@ discard block |
||
| 1657 | 1657 | * @param bool $use_class Whether the class can be used. Default true. |
| 1658 | 1658 | * @param array $args An array of request arguments. |
| 1659 | 1659 | */ |
| 1660 | - return apply_filters( 'use_curl_transport', true, $args ); |
|
| 1660 | + return apply_filters('use_curl_transport', true, $args); |
|
| 1661 | 1661 | } |
| 1662 | 1662 | } |
| 1663 | 1663 | |
@@ -1730,7 +1730,7 @@ discard block |
||
| 1730 | 1730 | * @return string |
| 1731 | 1731 | */ |
| 1732 | 1732 | public function host() { |
| 1733 | - if ( defined('WP_PROXY_HOST') ) |
|
| 1733 | + if (defined('WP_PROXY_HOST')) |
|
| 1734 | 1734 | return WP_PROXY_HOST; |
| 1735 | 1735 | |
| 1736 | 1736 | return ''; |
@@ -1744,7 +1744,7 @@ discard block |
||
| 1744 | 1744 | * @return string |
| 1745 | 1745 | */ |
| 1746 | 1746 | public function port() { |
| 1747 | - if ( defined('WP_PROXY_PORT') ) |
|
| 1747 | + if (defined('WP_PROXY_PORT')) |
|
| 1748 | 1748 | return WP_PROXY_PORT; |
| 1749 | 1749 | |
| 1750 | 1750 | return ''; |
@@ -1758,7 +1758,7 @@ discard block |
||
| 1758 | 1758 | * @return string |
| 1759 | 1759 | */ |
| 1760 | 1760 | public function username() { |
| 1761 | - if ( defined('WP_PROXY_USERNAME') ) |
|
| 1761 | + if (defined('WP_PROXY_USERNAME')) |
|
| 1762 | 1762 | return WP_PROXY_USERNAME; |
| 1763 | 1763 | |
| 1764 | 1764 | return ''; |
@@ -1772,7 +1772,7 @@ discard block |
||
| 1772 | 1772 | * @return string |
| 1773 | 1773 | */ |
| 1774 | 1774 | public function password() { |
| 1775 | - if ( defined('WP_PROXY_PASSWORD') ) |
|
| 1775 | + if (defined('WP_PROXY_PASSWORD')) |
|
| 1776 | 1776 | return WP_PROXY_PASSWORD; |
| 1777 | 1777 | |
| 1778 | 1778 | return ''; |
@@ -1786,7 +1786,7 @@ discard block |
||
| 1786 | 1786 | * @return string |
| 1787 | 1787 | */ |
| 1788 | 1788 | public function authentication() { |
| 1789 | - return $this->username() . ':' . $this->password(); |
|
| 1789 | + return $this->username().':'.$this->password(); |
|
| 1790 | 1790 | } |
| 1791 | 1791 | |
| 1792 | 1792 | /** |
@@ -1797,7 +1797,7 @@ discard block |
||
| 1797 | 1797 | * @return string |
| 1798 | 1798 | */ |
| 1799 | 1799 | public function authentication_header() { |
| 1800 | - return 'Proxy-Authorization: Basic ' . base64_encode( $this->authentication() ); |
|
| 1800 | + return 'Proxy-Authorization: Basic '.base64_encode($this->authentication()); |
|
| 1801 | 1801 | } |
| 1802 | 1802 | |
| 1803 | 1803 | /** |
@@ -1815,7 +1815,7 @@ discard block |
||
| 1815 | 1815 | * @param string $uri URI to check. |
| 1816 | 1816 | * @return bool True, to send through the proxy and false if, the proxy should not be used. |
| 1817 | 1817 | */ |
| 1818 | - public function send_through_proxy( $uri ) { |
|
| 1818 | + public function send_through_proxy($uri) { |
|
| 1819 | 1819 | /* |
| 1820 | 1820 | * parse_url() only handles http, https type URLs, and will emit E_WARNING on failure. |
| 1821 | 1821 | * This will be displayed on blogs, which is not reasonable. |
@@ -1823,10 +1823,10 @@ discard block |
||
| 1823 | 1823 | $check = @parse_url($uri); |
| 1824 | 1824 | |
| 1825 | 1825 | // Malformed URL, can not process, but this could mean ssl, so let through anyway. |
| 1826 | - if ( $check === false ) |
|
| 1826 | + if ($check === false) |
|
| 1827 | 1827 | return true; |
| 1828 | 1828 | |
| 1829 | - $home = parse_url( get_option('siteurl') ); |
|
| 1829 | + $home = parse_url(get_option('siteurl')); |
|
| 1830 | 1830 | |
| 1831 | 1831 | /** |
| 1832 | 1832 | * Filter whether to preempt sending the request through the proxy server. |
@@ -1841,33 +1841,33 @@ discard block |
||
| 1841 | 1841 | * @param array $check Associative array result of parsing the URI. |
| 1842 | 1842 | * @param array $home Associative array result of parsing the site URL. |
| 1843 | 1843 | */ |
| 1844 | - $result = apply_filters( 'pre_http_send_through_proxy', null, $uri, $check, $home ); |
|
| 1845 | - if ( ! is_null( $result ) ) |
|
| 1844 | + $result = apply_filters('pre_http_send_through_proxy', null, $uri, $check, $home); |
|
| 1845 | + if ( ! is_null($result)) |
|
| 1846 | 1846 | return $result; |
| 1847 | 1847 | |
| 1848 | - if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) |
|
| 1848 | + if ('localhost' == $check['host'] || (isset($home['host']) && $home['host'] == $check['host'])) |
|
| 1849 | 1849 | return false; |
| 1850 | 1850 | |
| 1851 | - if ( !defined('WP_PROXY_BYPASS_HOSTS') ) |
|
| 1851 | + if ( ! defined('WP_PROXY_BYPASS_HOSTS')) |
|
| 1852 | 1852 | return true; |
| 1853 | 1853 | |
| 1854 | 1854 | static $bypass_hosts = null; |
| 1855 | 1855 | static $wildcard_regex = array(); |
| 1856 | - if ( null === $bypass_hosts ) { |
|
| 1856 | + if (null === $bypass_hosts) { |
|
| 1857 | 1857 | $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS); |
| 1858 | 1858 | |
| 1859 | - if ( false !== strpos(WP_PROXY_BYPASS_HOSTS, '*') ) { |
|
| 1859 | + if (false !== strpos(WP_PROXY_BYPASS_HOSTS, '*')) { |
|
| 1860 | 1860 | $wildcard_regex = array(); |
| 1861 | - foreach ( $bypass_hosts as $host ) |
|
| 1862 | - $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
| 1863 | - $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; |
|
| 1861 | + foreach ($bypass_hosts as $host) |
|
| 1862 | + $wildcard_regex[] = str_replace('\*', '.+', preg_quote($host, '/')); |
|
| 1863 | + $wildcard_regex = '/^('.implode('|', $wildcard_regex).')$/i'; |
|
| 1864 | 1864 | } |
| 1865 | 1865 | } |
| 1866 | 1866 | |
| 1867 | - if ( !empty($wildcard_regex) ) |
|
| 1868 | - return !preg_match($wildcard_regex, $check['host']); |
|
| 1867 | + if ( ! empty($wildcard_regex)) |
|
| 1868 | + return ! preg_match($wildcard_regex, $check['host']); |
|
| 1869 | 1869 | else |
| 1870 | - return !in_array( $check['host'], $bypass_hosts ); |
|
| 1870 | + return ! in_array($check['host'], $bypass_hosts); |
|
| 1871 | 1871 | } |
| 1872 | 1872 | } |
| 1873 | 1873 | /** |
@@ -1947,54 +1947,54 @@ discard block |
||
| 1947 | 1947 | * @param string $requested_url The URL which the cookie was set on, used for default $domain |
| 1948 | 1948 | * and $port values. |
| 1949 | 1949 | */ |
| 1950 | - public function __construct( $data, $requested_url = '' ) { |
|
| 1951 | - if ( $requested_url ) |
|
| 1952 | - $arrURL = @parse_url( $requested_url ); |
|
| 1953 | - if ( isset( $arrURL['host'] ) ) |
|
| 1950 | + public function __construct($data, $requested_url = '') { |
|
| 1951 | + if ($requested_url) |
|
| 1952 | + $arrURL = @parse_url($requested_url); |
|
| 1953 | + if (isset($arrURL['host'])) |
|
| 1954 | 1954 | $this->domain = $arrURL['host']; |
| 1955 | - $this->path = isset( $arrURL['path'] ) ? $arrURL['path'] : '/'; |
|
| 1956 | - if ( '/' != substr( $this->path, -1 ) ) |
|
| 1957 | - $this->path = dirname( $this->path ) . '/'; |
|
| 1955 | + $this->path = isset($arrURL['path']) ? $arrURL['path'] : '/'; |
|
| 1956 | + if ('/' != substr($this->path, -1)) |
|
| 1957 | + $this->path = dirname($this->path).'/'; |
|
| 1958 | 1958 | |
| 1959 | - if ( is_string( $data ) ) { |
|
| 1959 | + if (is_string($data)) { |
|
| 1960 | 1960 | // Assume it's a header string direct from a previous request. |
| 1961 | - $pairs = explode( ';', $data ); |
|
| 1961 | + $pairs = explode(';', $data); |
|
| 1962 | 1962 | |
| 1963 | 1963 | // Special handling for first pair; name=value. Also be careful of "=" in value. |
| 1964 | - $name = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) ); |
|
| 1965 | - $value = substr( $pairs[0], strpos( $pairs[0], '=' ) + 1 ); |
|
| 1964 | + $name = trim(substr($pairs[0], 0, strpos($pairs[0], '='))); |
|
| 1965 | + $value = substr($pairs[0], strpos($pairs[0], '=') + 1); |
|
| 1966 | 1966 | $this->name = $name; |
| 1967 | - $this->value = urldecode( $value ); |
|
| 1967 | + $this->value = urldecode($value); |
|
| 1968 | 1968 | |
| 1969 | 1969 | // Removes name=value from items. |
| 1970 | - array_shift( $pairs ); |
|
| 1970 | + array_shift($pairs); |
|
| 1971 | 1971 | |
| 1972 | 1972 | // Set everything else as a property. |
| 1973 | - foreach ( $pairs as $pair ) { |
|
| 1973 | + foreach ($pairs as $pair) { |
|
| 1974 | 1974 | $pair = rtrim($pair); |
| 1975 | 1975 | |
| 1976 | 1976 | // Handle the cookie ending in ; which results in a empty final pair. |
| 1977 | - if ( empty($pair) ) |
|
| 1977 | + if (empty($pair)) |
|
| 1978 | 1978 | continue; |
| 1979 | 1979 | |
| 1980 | - list( $key, $val ) = strpos( $pair, '=' ) ? explode( '=', $pair ) : array( $pair, '' ); |
|
| 1981 | - $key = strtolower( trim( $key ) ); |
|
| 1982 | - if ( 'expires' == $key ) |
|
| 1983 | - $val = strtotime( $val ); |
|
| 1980 | + list($key, $val) = strpos($pair, '=') ? explode('=', $pair) : array($pair, ''); |
|
| 1981 | + $key = strtolower(trim($key)); |
|
| 1982 | + if ('expires' == $key) |
|
| 1983 | + $val = strtotime($val); |
|
| 1984 | 1984 | $this->$key = $val; |
| 1985 | 1985 | } |
| 1986 | 1986 | } else { |
| 1987 | - if ( !isset( $data['name'] ) ) |
|
| 1987 | + if ( ! isset($data['name'])) |
|
| 1988 | 1988 | return; |
| 1989 | 1989 | |
| 1990 | 1990 | // Set properties based directly on parameters. |
| 1991 | - foreach ( array( 'name', 'value', 'path', 'domain', 'port' ) as $field ) { |
|
| 1992 | - if ( isset( $data[ $field ] ) ) |
|
| 1993 | - $this->$field = $data[ $field ]; |
|
| 1991 | + foreach (array('name', 'value', 'path', 'domain', 'port') as $field) { |
|
| 1992 | + if (isset($data[$field])) |
|
| 1993 | + $this->$field = $data[$field]; |
|
| 1994 | 1994 | } |
| 1995 | 1995 | |
| 1996 | - if ( isset( $data['expires'] ) ) |
|
| 1997 | - $this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] ); |
|
| 1996 | + if (isset($data['expires'])) |
|
| 1997 | + $this->expires = is_int($data['expires']) ? $data['expires'] : strtotime($data['expires']); |
|
| 1998 | 1998 | else |
| 1999 | 1999 | $this->expires = null; |
| 2000 | 2000 | } |
@@ -2011,37 +2011,37 @@ discard block |
||
| 2011 | 2011 | * @param string $url URL you intend to send this cookie to |
| 2012 | 2012 | * @return bool true if allowed, false otherwise. |
| 2013 | 2013 | */ |
| 2014 | - public function test( $url ) { |
|
| 2015 | - if ( is_null( $this->name ) ) |
|
| 2014 | + public function test($url) { |
|
| 2015 | + if (is_null($this->name)) |
|
| 2016 | 2016 | return false; |
| 2017 | 2017 | |
| 2018 | 2018 | // Expires - if expired then nothing else matters. |
| 2019 | - if ( isset( $this->expires ) && time() > $this->expires ) |
|
| 2019 | + if (isset($this->expires) && time() > $this->expires) |
|
| 2020 | 2020 | return false; |
| 2021 | 2021 | |
| 2022 | 2022 | // Get details on the URL we're thinking about sending to. |
| 2023 | - $url = parse_url( $url ); |
|
| 2024 | - $url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' == $url['scheme'] ? 443 : 80 ); |
|
| 2025 | - $url['path'] = isset( $url['path'] ) ? $url['path'] : '/'; |
|
| 2023 | + $url = parse_url($url); |
|
| 2024 | + $url['port'] = isset($url['port']) ? $url['port'] : ('https' == $url['scheme'] ? 443 : 80); |
|
| 2025 | + $url['path'] = isset($url['path']) ? $url['path'] : '/'; |
|
| 2026 | 2026 | |
| 2027 | 2027 | // Values to use for comparison against the URL. |
| 2028 | - $path = isset( $this->path ) ? $this->path : '/'; |
|
| 2029 | - $port = isset( $this->port ) ? $this->port : null; |
|
| 2030 | - $domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] ); |
|
| 2031 | - if ( false === stripos( $domain, '.' ) ) |
|
| 2028 | + $path = isset($this->path) ? $this->path : '/'; |
|
| 2029 | + $port = isset($this->port) ? $this->port : null; |
|
| 2030 | + $domain = isset($this->domain) ? strtolower($this->domain) : strtolower($url['host']); |
|
| 2031 | + if (false === stripos($domain, '.')) |
|
| 2032 | 2032 | $domain .= '.local'; |
| 2033 | 2033 | |
| 2034 | 2034 | // Host - very basic check that the request URL ends with the domain restriction (minus leading dot). |
| 2035 | - $domain = substr( $domain, 0, 1 ) == '.' ? substr( $domain, 1 ) : $domain; |
|
| 2036 | - if ( substr( $url['host'], -strlen( $domain ) ) != $domain ) |
|
| 2035 | + $domain = substr($domain, 0, 1) == '.' ? substr($domain, 1) : $domain; |
|
| 2036 | + if (substr($url['host'], -strlen($domain)) != $domain) |
|
| 2037 | 2037 | return false; |
| 2038 | 2038 | |
| 2039 | 2039 | // Port - supports "port-lists" in the format: "80,8000,8080". |
| 2040 | - if ( !empty( $port ) && !in_array( $url['port'], explode( ',', $port) ) ) |
|
| 2040 | + if ( ! empty($port) && ! in_array($url['port'], explode(',', $port))) |
|
| 2041 | 2041 | return false; |
| 2042 | 2042 | |
| 2043 | 2043 | // Path - request path must start with path restriction. |
| 2044 | - if ( substr( $url['path'], 0, strlen( $path ) ) != $path ) |
|
| 2044 | + if (substr($url['path'], 0, strlen($path)) != $path) |
|
| 2045 | 2045 | return false; |
| 2046 | 2046 | |
| 2047 | 2047 | return true; |
@@ -2056,7 +2056,7 @@ discard block |
||
| 2056 | 2056 | * @return string Header encoded cookie name and value. |
| 2057 | 2057 | */ |
| 2058 | 2058 | public function getHeaderValue() { |
| 2059 | - if ( ! isset( $this->name ) || ! isset( $this->value ) ) |
|
| 2059 | + if ( ! isset($this->name) || ! isset($this->value)) |
|
| 2060 | 2060 | return ''; |
| 2061 | 2061 | |
| 2062 | 2062 | /** |
@@ -2067,7 +2067,7 @@ discard block |
||
| 2067 | 2067 | * @param string $value The cookie value. |
| 2068 | 2068 | * @param string $name The cookie name. |
| 2069 | 2069 | */ |
| 2070 | - return $this->name . '=' . apply_filters( 'wp_http_cookie_value', $this->value, $this->name ); |
|
| 2070 | + return $this->name.'='.apply_filters('wp_http_cookie_value', $this->value, $this->name); |
|
| 2071 | 2071 | } |
| 2072 | 2072 | |
| 2073 | 2073 | /** |
@@ -2079,7 +2079,7 @@ discard block |
||
| 2079 | 2079 | * @return string |
| 2080 | 2080 | */ |
| 2081 | 2081 | public function getFullHeader() { |
| 2082 | - return 'Cookie: ' . $this->getHeaderValue(); |
|
| 2082 | + return 'Cookie: '.$this->getHeaderValue(); |
|
| 2083 | 2083 | } |
| 2084 | 2084 | } |
| 2085 | 2085 | |
@@ -2108,8 +2108,8 @@ discard block |
||
| 2108 | 2108 | * @param string $supports Optional, not used. When implemented it will choose the right compression based on what the server supports. |
| 2109 | 2109 | * @return string|false False on failure. |
| 2110 | 2110 | */ |
| 2111 | - public static function compress( $raw, $level = 9, $supports = null ) { |
|
| 2112 | - return gzdeflate( $raw, $level ); |
|
| 2111 | + public static function compress($raw, $level = 9, $supports = null) { |
|
| 2112 | + return gzdeflate($raw, $level); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | 2115 | /** |
@@ -2128,24 +2128,24 @@ discard block |
||
| 2128 | 2128 | * @param int $length The optional length of the compressed data. |
| 2129 | 2129 | * @return string|bool False on failure. |
| 2130 | 2130 | */ |
| 2131 | - public static function decompress( $compressed, $length = null ) { |
|
| 2131 | + public static function decompress($compressed, $length = null) { |
|
| 2132 | 2132 | |
| 2133 | - if ( empty($compressed) ) |
|
| 2133 | + if (empty($compressed)) |
|
| 2134 | 2134 | return $compressed; |
| 2135 | 2135 | |
| 2136 | - if ( false !== ( $decompressed = @gzinflate( $compressed ) ) ) |
|
| 2136 | + if (false !== ($decompressed = @gzinflate($compressed))) |
|
| 2137 | 2137 | return $decompressed; |
| 2138 | 2138 | |
| 2139 | - if ( false !== ( $decompressed = self::compatible_gzinflate( $compressed ) ) ) |
|
| 2139 | + if (false !== ($decompressed = self::compatible_gzinflate($compressed))) |
|
| 2140 | 2140 | return $decompressed; |
| 2141 | 2141 | |
| 2142 | - if ( false !== ( $decompressed = @gzuncompress( $compressed ) ) ) |
|
| 2142 | + if (false !== ($decompressed = @gzuncompress($compressed))) |
|
| 2143 | 2143 | return $decompressed; |
| 2144 | 2144 | |
| 2145 | - if ( function_exists('gzdecode') ) { |
|
| 2146 | - $decompressed = @gzdecode( $compressed ); |
|
| 2145 | + if (function_exists('gzdecode')) { |
|
| 2146 | + $decompressed = @gzdecode($compressed); |
|
| 2147 | 2147 | |
| 2148 | - if ( false !== $decompressed ) |
|
| 2148 | + if (false !== $decompressed) |
|
| 2149 | 2149 | return $decompressed; |
| 2150 | 2150 | } |
| 2151 | 2151 | |
@@ -2177,29 +2177,29 @@ discard block |
||
| 2177 | 2177 | public static function compatible_gzinflate($gzData) { |
| 2178 | 2178 | |
| 2179 | 2179 | // Compressed data might contain a full header, if so strip it for gzinflate(). |
| 2180 | - if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) { |
|
| 2180 | + if (substr($gzData, 0, 3) == "\x1f\x8b\x08") { |
|
| 2181 | 2181 | $i = 10; |
| 2182 | - $flg = ord( substr($gzData, 3, 1) ); |
|
| 2183 | - if ( $flg > 0 ) { |
|
| 2184 | - if ( $flg & 4 ) { |
|
| 2185 | - list($xlen) = unpack('v', substr($gzData, $i, 2) ); |
|
| 2182 | + $flg = ord(substr($gzData, 3, 1)); |
|
| 2183 | + if ($flg > 0) { |
|
| 2184 | + if ($flg & 4) { |
|
| 2185 | + list($xlen) = unpack('v', substr($gzData, $i, 2)); |
|
| 2186 | 2186 | $i = $i + 2 + $xlen; |
| 2187 | 2187 | } |
| 2188 | - if ( $flg & 8 ) |
|
| 2188 | + if ($flg & 8) |
|
| 2189 | 2189 | $i = strpos($gzData, "\0", $i) + 1; |
| 2190 | - if ( $flg & 16 ) |
|
| 2190 | + if ($flg & 16) |
|
| 2191 | 2191 | $i = strpos($gzData, "\0", $i) + 1; |
| 2192 | - if ( $flg & 2 ) |
|
| 2192 | + if ($flg & 2) |
|
| 2193 | 2193 | $i = $i + 2; |
| 2194 | 2194 | } |
| 2195 | - $decompressed = @gzinflate( substr($gzData, $i, -8) ); |
|
| 2196 | - if ( false !== $decompressed ) |
|
| 2195 | + $decompressed = @gzinflate(substr($gzData, $i, -8)); |
|
| 2196 | + if (false !== $decompressed) |
|
| 2197 | 2197 | return $decompressed; |
| 2198 | 2198 | } |
| 2199 | 2199 | |
| 2200 | 2200 | // Compressed data from java.util.zip.Deflater amongst others. |
| 2201 | - $decompressed = @gzinflate( substr($gzData, 2) ); |
|
| 2202 | - if ( false !== $decompressed ) |
|
| 2201 | + $decompressed = @gzinflate(substr($gzData, 2)); |
|
| 2202 | + if (false !== $decompressed) |
|
| 2203 | 2203 | return $decompressed; |
| 2204 | 2204 | |
| 2205 | 2205 | return false; |
@@ -2216,25 +2216,25 @@ discard block |
||
| 2216 | 2216 | * @param array $args |
| 2217 | 2217 | * @return string Types of encoding to accept. |
| 2218 | 2218 | */ |
| 2219 | - public static function accept_encoding( $url, $args ) { |
|
| 2219 | + public static function accept_encoding($url, $args) { |
|
| 2220 | 2220 | $type = array(); |
| 2221 | 2221 | $compression_enabled = self::is_available(); |
| 2222 | 2222 | |
| 2223 | - if ( ! $args['decompress'] ) // Decompression specifically disabled. |
|
| 2223 | + if ( ! $args['decompress']) // Decompression specifically disabled. |
|
| 2224 | 2224 | $compression_enabled = false; |
| 2225 | - elseif ( $args['stream'] ) // Disable when streaming to file. |
|
| 2225 | + elseif ($args['stream']) // Disable when streaming to file. |
|
| 2226 | 2226 | $compression_enabled = false; |
| 2227 | - elseif ( isset( $args['limit_response_size'] ) ) // If only partial content is being requested, we won't be able to decompress it. |
|
| 2227 | + elseif (isset($args['limit_response_size'])) // If only partial content is being requested, we won't be able to decompress it. |
|
| 2228 | 2228 | $compression_enabled = false; |
| 2229 | 2229 | |
| 2230 | - if ( $compression_enabled ) { |
|
| 2231 | - if ( function_exists( 'gzinflate' ) ) |
|
| 2230 | + if ($compression_enabled) { |
|
| 2231 | + if (function_exists('gzinflate')) |
|
| 2232 | 2232 | $type[] = 'deflate;q=1.0'; |
| 2233 | 2233 | |
| 2234 | - if ( function_exists( 'gzuncompress' ) ) |
|
| 2234 | + if (function_exists('gzuncompress')) |
|
| 2235 | 2235 | $type[] = 'compress;q=0.5'; |
| 2236 | 2236 | |
| 2237 | - if ( function_exists( 'gzdecode' ) ) |
|
| 2237 | + if (function_exists('gzdecode')) |
|
| 2238 | 2238 | $type[] = 'gzip;q=0.5'; |
| 2239 | 2239 | } |
| 2240 | 2240 | |
@@ -2248,7 +2248,7 @@ discard block |
||
| 2248 | 2248 | * @param string $url URL of the HTTP request. |
| 2249 | 2249 | * @param array $args HTTP request arguments. |
| 2250 | 2250 | */ |
| 2251 | - $type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args ); |
|
| 2251 | + $type = apply_filters('wp_http_accept_encoding', $type, $url, $args); |
|
| 2252 | 2252 | |
| 2253 | 2253 | return implode(', ', $type); |
| 2254 | 2254 | } |
@@ -2277,11 +2277,11 @@ discard block |
||
| 2277 | 2277 | * @return bool |
| 2278 | 2278 | */ |
| 2279 | 2279 | public static function should_decode($headers) { |
| 2280 | - if ( is_array( $headers ) ) { |
|
| 2281 | - if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) ) |
|
| 2280 | + if (is_array($headers)) { |
|
| 2281 | + if (array_key_exists('content-encoding', $headers) && ! empty($headers['content-encoding'])) |
|
| 2282 | 2282 | return true; |
| 2283 | - } elseif ( is_string( $headers ) ) { |
|
| 2284 | - return ( stripos($headers, 'content-encoding:') !== false ); |
|
| 2283 | + } elseif (is_string($headers)) { |
|
| 2284 | + return (stripos($headers, 'content-encoding:') !== false); |
|
| 2285 | 2285 | } |
| 2286 | 2286 | |
| 2287 | 2287 | return false; |
@@ -2301,6 +2301,6 @@ discard block |
||
| 2301 | 2301 | * @return bool |
| 2302 | 2302 | */ |
| 2303 | 2303 | public static function is_available() { |
| 2304 | - return ( function_exists('gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate') ); |
|
| 2304 | + return (function_exists('gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate')); |
|
| 2305 | 2305 | } |
| 2306 | 2306 | } |
@@ -147,8 +147,9 @@ discard block |
||
| 147 | 147 | $args = wp_parse_args( $args ); |
| 148 | 148 | |
| 149 | 149 | // By default, Head requests do not cause redirections. |
| 150 | - if ( isset($args['method']) && 'HEAD' == $args['method'] ) |
|
| 151 | - $defaults['redirection'] = 0; |
|
| 150 | + if ( isset($args['method']) && 'HEAD' == $args['method'] ) { |
|
| 151 | + $defaults['redirection'] = 0; |
|
| 152 | + } |
|
| 152 | 153 | |
| 153 | 154 | $r = wp_parse_args( $args, $defaults ); |
| 154 | 155 | /** |
@@ -162,8 +163,9 @@ discard block |
||
| 162 | 163 | $r = apply_filters( 'http_request_args', $r, $url ); |
| 163 | 164 | |
| 164 | 165 | // The transports decrement this, store a copy of the original value for loop purposes. |
| 165 | - if ( ! isset( $r['_redirection'] ) ) |
|
| 166 | - $r['_redirection'] = $r['redirection']; |
|
| 166 | + if ( ! isset( $r['_redirection'] ) ) { |
|
| 167 | + $r['_redirection'] = $r['redirection']; |
|
| 168 | + } |
|
| 167 | 169 | |
| 168 | 170 | /** |
| 169 | 171 | * Filter whether to preempt an HTTP request's return. |
@@ -178,12 +180,14 @@ discard block |
||
| 178 | 180 | * @param string $url The request URL. |
| 179 | 181 | */ |
| 180 | 182 | $pre = apply_filters( 'pre_http_request', false, $r, $url ); |
| 181 | - if ( false !== $pre ) |
|
| 182 | - return $pre; |
|
| 183 | + if ( false !== $pre ) { |
|
| 184 | + return $pre; |
|
| 185 | + } |
|
| 183 | 186 | |
| 184 | 187 | if ( function_exists( 'wp_kses_bad_protocol' ) ) { |
| 185 | - if ( $r['reject_unsafe_urls'] ) |
|
| 186 | - $url = wp_http_validate_url( $url ); |
|
| 188 | + if ( $r['reject_unsafe_urls'] ) { |
|
| 189 | + $url = wp_http_validate_url( $url ); |
|
| 190 | + } |
|
| 187 | 191 | if ( $url ) { |
| 188 | 192 | $url = wp_kses_bad_protocol( $url, array( 'http', 'https', 'ssl' ) ); |
| 189 | 193 | } |
@@ -191,11 +195,13 @@ discard block |
||
| 191 | 195 | |
| 192 | 196 | $arrURL = @parse_url( $url ); |
| 193 | 197 | |
| 194 | - if ( empty( $url ) || empty( $arrURL['scheme'] ) ) |
|
| 195 | - return new WP_Error('http_request_failed', __('A valid URL was not provided.')); |
|
| 198 | + if ( empty( $url ) || empty( $arrURL['scheme'] ) ) { |
|
| 199 | + return new WP_Error('http_request_failed', __('A valid URL was not provided.')); |
|
| 200 | + } |
|
| 196 | 201 | |
| 197 | - if ( $this->block_request( $url ) ) |
|
| 198 | - return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); |
|
| 202 | + if ( $this->block_request( $url ) ) { |
|
| 203 | + return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); |
|
| 204 | + } |
|
| 199 | 205 | |
| 200 | 206 | /* |
| 201 | 207 | * Determine if this is a https call and pass that on to the transport functions |
@@ -222,12 +228,14 @@ discard block |
||
| 222 | 228 | */ |
| 223 | 229 | if ( $r['stream'] ) { |
| 224 | 230 | $r['blocking'] = true; |
| 225 | - if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) |
|
| 226 | - return new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); |
|
| 231 | + if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) { |
|
| 232 | + return new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); |
|
| 233 | + } |
|
| 227 | 234 | } |
| 228 | 235 | |
| 229 | - if ( is_null( $r['headers'] ) ) |
|
| 230 | - $r['headers'] = array(); |
|
| 236 | + if ( is_null( $r['headers'] ) ) { |
|
| 237 | + $r['headers'] = array(); |
|
| 238 | + } |
|
| 231 | 239 | |
| 232 | 240 | if ( ! is_array( $r['headers'] ) ) { |
| 233 | 241 | $processedHeaders = self::processHeaders( $r['headers'], $url ); |
@@ -255,31 +263,36 @@ discard block |
||
| 255 | 263 | mbstring_binary_safe_encoding(); |
| 256 | 264 | |
| 257 | 265 | if ( ! isset( $r['headers']['Accept-Encoding'] ) ) { |
| 258 | - if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) ) |
|
| 259 | - $r['headers']['Accept-Encoding'] = $encoding; |
|
| 266 | + if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) ) { |
|
| 267 | + $r['headers']['Accept-Encoding'] = $encoding; |
|
| 268 | + } |
|
| 260 | 269 | } |
| 261 | 270 | |
| 262 | 271 | if ( ( ! is_null( $r['body'] ) && '' != $r['body'] ) || 'POST' == $r['method'] || 'PUT' == $r['method'] ) { |
| 263 | 272 | if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { |
| 264 | 273 | $r['body'] = http_build_query( $r['body'], null, '&' ); |
| 265 | 274 | |
| 266 | - if ( ! isset( $r['headers']['Content-Type'] ) ) |
|
| 267 | - $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ); |
|
| 275 | + if ( ! isset( $r['headers']['Content-Type'] ) ) { |
|
| 276 | + $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ); |
|
| 277 | + } |
|
| 268 | 278 | } |
| 269 | 279 | |
| 270 | - if ( '' === $r['body'] ) |
|
| 271 | - $r['body'] = null; |
|
| 280 | + if ( '' === $r['body'] ) { |
|
| 281 | + $r['body'] = null; |
|
| 282 | + } |
|
| 272 | 283 | |
| 273 | - if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) ) |
|
| 274 | - $r['headers']['Content-Length'] = strlen( $r['body'] ); |
|
| 284 | + if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) ) { |
|
| 285 | + $r['headers']['Content-Length'] = strlen( $r['body'] ); |
|
| 286 | + } |
|
| 275 | 287 | } |
| 276 | 288 | |
| 277 | 289 | $response = $this->_dispatch_request( $url, $r ); |
| 278 | 290 | |
| 279 | 291 | reset_mbstring_encoding(); |
| 280 | 292 | |
| 281 | - if ( is_wp_error( $response ) ) |
|
| 282 | - return $response; |
|
| 293 | + if ( is_wp_error( $response ) ) { |
|
| 294 | + return $response; |
|
| 295 | + } |
|
| 283 | 296 | |
| 284 | 297 | // Append cookies that were used in this request to the response |
| 285 | 298 | if ( ! empty( $r['cookies'] ) ) { |
@@ -323,8 +336,9 @@ discard block |
||
| 323 | 336 | $class = 'WP_HTTP_' . $transport; |
| 324 | 337 | |
| 325 | 338 | // Check to see if this transport is a possibility, calls the transport statically. |
| 326 | - if ( !call_user_func( array( $class, 'test' ), $args, $url ) ) |
|
| 327 | - continue; |
|
| 339 | + if ( !call_user_func( array( $class, 'test' ), $args, $url ) ) { |
|
| 340 | + continue; |
|
| 341 | + } |
|
| 328 | 342 | |
| 329 | 343 | return $class; |
| 330 | 344 | } |
@@ -353,12 +367,14 @@ discard block |
||
| 353 | 367 | static $transports = array(); |
| 354 | 368 | |
| 355 | 369 | $class = $this->_get_first_available_transport( $args, $url ); |
| 356 | - if ( !$class ) |
|
| 357 | - return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); |
|
| 370 | + if ( !$class ) { |
|
| 371 | + return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); |
|
| 372 | + } |
|
| 358 | 373 | |
| 359 | 374 | // Transport claims to support request, instantiate it and give it a whirl. |
| 360 | - if ( empty( $transports[$class] ) ) |
|
| 361 | - $transports[$class] = new $class; |
|
| 375 | + if ( empty( $transports[$class] ) ) { |
|
| 376 | + $transports[$class] = new $class; |
|
| 377 | + } |
|
| 362 | 378 | |
| 363 | 379 | $response = $transports[$class]->request( $url, $args ); |
| 364 | 380 | |
@@ -375,8 +391,9 @@ discard block |
||
| 375 | 391 | */ |
| 376 | 392 | do_action( 'http_api_debug', $response, 'response', $class, $args, $url ); |
| 377 | 393 | |
| 378 | - if ( is_wp_error( $response ) ) |
|
| 379 | - return $response; |
|
| 394 | + if ( is_wp_error( $response ) ) { |
|
| 395 | + return $response; |
|
| 396 | + } |
|
| 380 | 397 | |
| 381 | 398 | /** |
| 382 | 399 | * Filter the HTTP API response immediately before the response is returned. |
@@ -505,8 +522,9 @@ discard block |
||
| 505 | 522 | $cookies = array(); |
| 506 | 523 | $newheaders = array(); |
| 507 | 524 | foreach ( (array) $headers as $tempheader ) { |
| 508 | - if ( empty($tempheader) ) |
|
| 509 | - continue; |
|
| 525 | + if ( empty($tempheader) ) { |
|
| 526 | + continue; |
|
| 527 | + } |
|
| 510 | 528 | |
| 511 | 529 | if ( false === strpos($tempheader, ':') ) { |
| 512 | 530 | $stack = explode(' ', $tempheader, 3); |
@@ -521,14 +539,16 @@ discard block |
||
| 521 | 539 | $value = trim( $value ); |
| 522 | 540 | |
| 523 | 541 | if ( isset( $newheaders[ $key ] ) ) { |
| 524 | - if ( ! is_array( $newheaders[ $key ] ) ) |
|
| 525 | - $newheaders[$key] = array( $newheaders[ $key ] ); |
|
| 542 | + if ( ! is_array( $newheaders[ $key ] ) ) { |
|
| 543 | + $newheaders[$key] = array( $newheaders[ $key ] ); |
|
| 544 | + } |
|
| 526 | 545 | $newheaders[ $key ][] = $value; |
| 527 | 546 | } else { |
| 528 | 547 | $newheaders[ $key ] = $value; |
| 529 | 548 | } |
| 530 | - if ( 'set-cookie' == $key ) |
|
| 531 | - $cookies[] = new WP_Http_Cookie( $value, $url ); |
|
| 549 | + if ( 'set-cookie' == $key ) { |
|
| 550 | + $cookies[] = new WP_Http_Cookie( $value, $url ); |
|
| 551 | + } |
|
| 532 | 552 | } |
| 533 | 553 | |
| 534 | 554 | // Cast the Response Code to an int |
@@ -554,8 +574,9 @@ discard block |
||
| 554 | 574 | if ( ! empty($r['cookies']) ) { |
| 555 | 575 | // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances. |
| 556 | 576 | foreach ( $r['cookies'] as $name => $value ) { |
| 557 | - if ( ! is_object( $value ) ) |
|
| 558 | - $r['cookies'][ $name ] = new WP_HTTP_Cookie( array( 'name' => $name, 'value' => $value ) ); |
|
| 577 | + if ( ! is_object( $value ) ) { |
|
| 578 | + $r['cookies'][ $name ] = new WP_HTTP_Cookie( array( 'name' => $name, 'value' => $value ) ); |
|
| 579 | + } |
|
| 559 | 580 | } |
| 560 | 581 | |
| 561 | 582 | $cookies_header = ''; |
@@ -584,8 +605,9 @@ discard block |
||
| 584 | 605 | */ |
| 585 | 606 | public static function chunkTransferDecode( $body ) { |
| 586 | 607 | // The body is not chunked encoded or is malformed. |
| 587 | - if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) |
|
| 588 | - return $body; |
|
| 608 | + if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) { |
|
| 609 | + return $body; |
|
| 610 | + } |
|
| 589 | 611 | |
| 590 | 612 | $parsed_body = ''; |
| 591 | 613 | |
@@ -594,8 +616,9 @@ discard block |
||
| 594 | 616 | |
| 595 | 617 | while ( true ) { |
| 596 | 618 | $has_chunk = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $body, $match ); |
| 597 | - if ( ! $has_chunk || empty( $match[1] ) ) |
|
| 598 | - return $body_original; |
|
| 619 | + if ( ! $has_chunk || empty( $match[1] ) ) { |
|
| 620 | + return $body_original; |
|
| 621 | + } |
|
| 599 | 622 | |
| 600 | 623 | $length = hexdec( $match[1] ); |
| 601 | 624 | $chunk_length = strlen( $match[0] ); |
@@ -607,8 +630,9 @@ discard block |
||
| 607 | 630 | $body = substr( $body, $length + $chunk_length ); |
| 608 | 631 | |
| 609 | 632 | // End of the document. |
| 610 | - if ( '0' === trim( $body ) ) |
|
| 611 | - return $parsed_body; |
|
| 633 | + if ( '0' === trim( $body ) ) { |
|
| 634 | + return $parsed_body; |
|
| 635 | + } |
|
| 612 | 636 | } |
| 613 | 637 | } |
| 614 | 638 | |
@@ -636,12 +660,14 @@ discard block |
||
| 636 | 660 | */ |
| 637 | 661 | public function block_request($uri) { |
| 638 | 662 | // We don't need to block requests, because nothing is blocked. |
| 639 | - if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) |
|
| 640 | - return false; |
|
| 663 | + if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) { |
|
| 664 | + return false; |
|
| 665 | + } |
|
| 641 | 666 | |
| 642 | 667 | $check = parse_url($uri); |
| 643 | - if ( ! $check ) |
|
| 644 | - return true; |
|
| 668 | + if ( ! $check ) { |
|
| 669 | + return true; |
|
| 670 | + } |
|
| 645 | 671 | |
| 646 | 672 | $home = parse_url( get_option('siteurl') ); |
| 647 | 673 | |
@@ -658,8 +684,9 @@ discard block |
||
| 658 | 684 | return apply_filters( 'block_local_requests', false ); |
| 659 | 685 | } |
| 660 | 686 | |
| 661 | - if ( !defined('WP_ACCESSIBLE_HOSTS') ) |
|
| 662 | - return true; |
|
| 687 | + if ( !defined('WP_ACCESSIBLE_HOSTS') ) { |
|
| 688 | + return true; |
|
| 689 | + } |
|
| 663 | 690 | |
| 664 | 691 | static $accessible_hosts = null; |
| 665 | 692 | static $wildcard_regex = array(); |
@@ -668,16 +695,19 @@ discard block |
||
| 668 | 695 | |
| 669 | 696 | if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) { |
| 670 | 697 | $wildcard_regex = array(); |
| 671 | - foreach ( $accessible_hosts as $host ) |
|
| 672 | - $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
| 698 | + foreach ( $accessible_hosts as $host ) { |
|
| 699 | + $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
| 700 | + } |
|
| 673 | 701 | $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; |
| 674 | 702 | } |
| 675 | 703 | } |
| 676 | 704 | |
| 677 | - if ( !empty($wildcard_regex) ) |
|
| 678 | - return !preg_match($wildcard_regex, $check['host']); |
|
| 679 | - else |
|
| 680 | - return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it. |
|
| 705 | + if ( !empty($wildcard_regex) ) { |
|
| 706 | + return !preg_match($wildcard_regex, $check['host']); |
|
| 707 | + } else { |
|
| 708 | + return !in_array( $check['host'], $accessible_hosts ); |
|
| 709 | + } |
|
| 710 | + //Inverse logic, If it's in the array, then we can't access it. |
|
| 681 | 711 | |
| 682 | 712 | } |
| 683 | 713 | |
@@ -740,8 +770,9 @@ discard block |
||
| 740 | 770 | * @return string An Absolute URL, in a failure condition where the URL cannot be parsed, the relative URL will be returned. |
| 741 | 771 | */ |
| 742 | 772 | public static function make_absolute_url( $maybe_relative_path, $url ) { |
| 743 | - if ( empty( $url ) ) |
|
| 744 | - return $maybe_relative_path; |
|
| 773 | + if ( empty( $url ) ) { |
|
| 774 | + return $maybe_relative_path; |
|
| 775 | + } |
|
| 745 | 776 | |
| 746 | 777 | if ( ! $url_parts = WP_HTTP::parse_url( $url ) ) { |
| 747 | 778 | return $maybe_relative_path; |
@@ -761,12 +792,14 @@ discard block |
||
| 761 | 792 | // Schemeless URL's will make it this far, so we check for a host in the relative url and convert it to a protocol-url |
| 762 | 793 | if ( isset( $relative_url_parts['host'] ) ) { |
| 763 | 794 | $absolute_path .= $relative_url_parts['host']; |
| 764 | - if ( isset( $relative_url_parts['port'] ) ) |
|
| 765 | - $absolute_path .= ':' . $relative_url_parts['port']; |
|
| 795 | + if ( isset( $relative_url_parts['port'] ) ) { |
|
| 796 | + $absolute_path .= ':' . $relative_url_parts['port']; |
|
| 797 | + } |
|
| 766 | 798 | } else { |
| 767 | 799 | $absolute_path .= $url_parts['host']; |
| 768 | - if ( isset( $url_parts['port'] ) ) |
|
| 769 | - $absolute_path .= ':' . $url_parts['port']; |
|
| 800 | + if ( isset( $url_parts['port'] ) ) { |
|
| 801 | + $absolute_path .= ':' . $url_parts['port']; |
|
| 802 | + } |
|
| 770 | 803 | } |
| 771 | 804 | |
| 772 | 805 | // Start off with the Absolute URL path. |
@@ -794,8 +827,9 @@ discard block |
||
| 794 | 827 | } |
| 795 | 828 | |
| 796 | 829 | // Add the Query string. |
| 797 | - if ( ! empty( $relative_url_parts['query'] ) ) |
|
| 798 | - $path .= '?' . $relative_url_parts['query']; |
|
| 830 | + if ( ! empty( $relative_url_parts['query'] ) ) { |
|
| 831 | + $path .= '?' . $relative_url_parts['query']; |
|
| 832 | + } |
|
| 799 | 833 | |
| 800 | 834 | return $absolute_path . '/' . ltrim( $path, '/' ); |
| 801 | 835 | } |
@@ -814,36 +848,42 @@ discard block |
||
| 814 | 848 | */ |
| 815 | 849 | public static function handle_redirects( $url, $args, $response ) { |
| 816 | 850 | // If no redirects are present, or, redirects were not requested, perform no action. |
| 817 | - if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) |
|
| 818 | - return false; |
|
| 851 | + if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) { |
|
| 852 | + return false; |
|
| 853 | + } |
|
| 819 | 854 | |
| 820 | 855 | // Only perform redirections on redirection http codes. |
| 821 | - if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) |
|
| 822 | - return false; |
|
| 856 | + if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) { |
|
| 857 | + return false; |
|
| 858 | + } |
|
| 823 | 859 | |
| 824 | 860 | // Don't redirect if we've run out of redirects. |
| 825 | - if ( $args['redirection']-- <= 0 ) |
|
| 826 | - return new WP_Error( 'http_request_failed', __('Too many redirects.') ); |
|
| 861 | + if ( $args['redirection']-- <= 0 ) { |
|
| 862 | + return new WP_Error( 'http_request_failed', __('Too many redirects.') ); |
|
| 863 | + } |
|
| 827 | 864 | |
| 828 | 865 | $redirect_location = $response['headers']['location']; |
| 829 | 866 | |
| 830 | 867 | // If there were multiple Location headers, use the last header specified. |
| 831 | - if ( is_array( $redirect_location ) ) |
|
| 832 | - $redirect_location = array_pop( $redirect_location ); |
|
| 868 | + if ( is_array( $redirect_location ) ) { |
|
| 869 | + $redirect_location = array_pop( $redirect_location ); |
|
| 870 | + } |
|
| 833 | 871 | |
| 834 | 872 | $redirect_location = WP_HTTP::make_absolute_url( $redirect_location, $url ); |
| 835 | 873 | |
| 836 | 874 | // POST requests should not POST to a redirected location. |
| 837 | 875 | if ( 'POST' == $args['method'] ) { |
| 838 | - if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) |
|
| 839 | - $args['method'] = 'GET'; |
|
| 876 | + if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) { |
|
| 877 | + $args['method'] = 'GET'; |
|
| 878 | + } |
|
| 840 | 879 | } |
| 841 | 880 | |
| 842 | 881 | // Include valid cookies in the redirect process. |
| 843 | 882 | if ( ! empty( $response['cookies'] ) ) { |
| 844 | 883 | foreach ( $response['cookies'] as $cookie ) { |
| 845 | - if ( $cookie->test( $redirect_location ) ) |
|
| 846 | - $args['cookies'][] = $cookie; |
|
| 884 | + if ( $cookie->test( $redirect_location ) ) { |
|
| 885 | + $args['cookies'][] = $cookie; |
|
| 886 | + } |
|
| 847 | 887 | } |
| 848 | 888 | } |
| 849 | 889 | |
@@ -867,11 +907,13 @@ discard block |
||
| 867 | 907 | * @return integer|bool Upon success, '4' or '6' to represent a IPv4 or IPv6 address, false upon failure |
| 868 | 908 | */ |
| 869 | 909 | public static function is_ip_address( $maybe_ip ) { |
| 870 | - if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) |
|
| 871 | - return 4; |
|
| 910 | + if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) { |
|
| 911 | + return 4; |
|
| 912 | + } |
|
| 872 | 913 | |
| 873 | - if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) |
|
| 874 | - return 6; |
|
| 914 | + if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) { |
|
| 915 | + return 6; |
|
| 916 | + } |
|
| 875 | 917 | |
| 876 | 918 | return false; |
| 877 | 919 | } |
@@ -939,10 +981,11 @@ discard block |
||
| 939 | 981 | } |
| 940 | 982 | |
| 941 | 983 | if ( isset( $r['headers']['Host'] ) || isset( $r['headers']['host'] ) ) { |
| 942 | - if ( isset( $r['headers']['Host'] ) ) |
|
| 943 | - $arrURL['host'] = $r['headers']['Host']; |
|
| 944 | - else |
|
| 945 | - $arrURL['host'] = $r['headers']['host']; |
|
| 984 | + if ( isset( $r['headers']['Host'] ) ) { |
|
| 985 | + $arrURL['host'] = $r['headers']['Host']; |
|
| 986 | + } else { |
|
| 987 | + $arrURL['host'] = $r['headers']['host']; |
|
| 988 | + } |
|
| 946 | 989 | unset( $r['headers']['Host'], $r['headers']['host'] ); |
| 947 | 990 | } |
| 948 | 991 | |
@@ -951,8 +994,9 @@ discard block |
||
| 951 | 994 | * to ::1, which fails when the server is not set up for it. For compatibility, always |
| 952 | 995 | * connect to the IPv4 address. |
| 953 | 996 | */ |
| 954 | - if ( 'localhost' == strtolower( $connect_host ) ) |
|
| 955 | - $connect_host = '127.0.0.1'; |
|
| 997 | + if ( 'localhost' == strtolower( $connect_host ) ) { |
|
| 998 | + $connect_host = '127.0.0.1'; |
|
| 999 | + } |
|
| 956 | 1000 | |
| 957 | 1001 | $connect_host = $secure_transport ? 'ssl://' . $connect_host : 'tcp://' . $connect_host; |
| 958 | 1002 | |
@@ -1003,44 +1047,52 @@ discard block |
||
| 1003 | 1047 | |
| 1004 | 1048 | if ( !WP_DEBUG ) { |
| 1005 | 1049 | // In the event that the SSL connection fails, silence the many PHP Warnings. |
| 1006 | - if ( $secure_transport ) |
|
| 1007 | - $error_reporting = error_reporting(0); |
|
| 1050 | + if ( $secure_transport ) { |
|
| 1051 | + $error_reporting = error_reporting(0); |
|
| 1052 | + } |
|
| 1008 | 1053 | |
| 1009 | - if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) |
|
| 1010 | - $handle = @stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1011 | - else |
|
| 1012 | - $handle = @stream_socket_client( $connect_host . ':' . $arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1054 | + if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { |
|
| 1055 | + $handle = @stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1056 | + } else { |
|
| 1057 | + $handle = @stream_socket_client( $connect_host . ':' . $arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1058 | + } |
|
| 1013 | 1059 | |
| 1014 | - if ( $secure_transport ) |
|
| 1015 | - error_reporting( $error_reporting ); |
|
| 1060 | + if ( $secure_transport ) { |
|
| 1061 | + error_reporting( $error_reporting ); |
|
| 1062 | + } |
|
| 1016 | 1063 | |
| 1017 | 1064 | } else { |
| 1018 | - if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) |
|
| 1019 | - $handle = stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1020 | - else |
|
| 1021 | - $handle = stream_socket_client( $connect_host . ':' . $arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1065 | + if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { |
|
| 1066 | + $handle = stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1067 | + } else { |
|
| 1068 | + $handle = stream_socket_client( $connect_host . ':' . $arrURL['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); |
|
| 1069 | + } |
|
| 1022 | 1070 | } |
| 1023 | 1071 | |
| 1024 | 1072 | if ( false === $handle ) { |
| 1025 | 1073 | // SSL connection failed due to expired/invalid cert, or, OpenSSL configuration is broken. |
| 1026 | - if ( $secure_transport && 0 === $connection_error && '' === $connection_error_str ) |
|
| 1027 | - return new WP_Error( 'http_request_failed', __( 'The SSL certificate for the host could not be verified.' ) ); |
|
| 1074 | + if ( $secure_transport && 0 === $connection_error && '' === $connection_error_str ) { |
|
| 1075 | + return new WP_Error( 'http_request_failed', __( 'The SSL certificate for the host could not be verified.' ) ); |
|
| 1076 | + } |
|
| 1028 | 1077 | |
| 1029 | 1078 | return new WP_Error('http_request_failed', $connection_error . ': ' . $connection_error_str ); |
| 1030 | 1079 | } |
| 1031 | 1080 | |
| 1032 | 1081 | // Verify that the SSL certificate is valid for this request. |
| 1033 | 1082 | if ( $secure_transport && $ssl_verify && ! $proxy->is_enabled() ) { |
| 1034 | - if ( ! self::verify_ssl_certificate( $handle, $arrURL['host'] ) ) |
|
| 1035 | - return new WP_Error( 'http_request_failed', __( 'The SSL certificate for the host could not be verified.' ) ); |
|
| 1083 | + if ( ! self::verify_ssl_certificate( $handle, $arrURL['host'] ) ) { |
|
| 1084 | + return new WP_Error( 'http_request_failed', __( 'The SSL certificate for the host could not be verified.' ) ); |
|
| 1085 | + } |
|
| 1036 | 1086 | } |
| 1037 | 1087 | |
| 1038 | 1088 | stream_set_timeout( $handle, $timeout, $utimeout ); |
| 1039 | 1089 | |
| 1040 | - if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) //Some proxies require full URL in this field. |
|
| 1090 | + if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { |
|
| 1091 | + //Some proxies require full URL in this field. |
|
| 1041 | 1092 | $requestPath = $url; |
| 1042 | - else |
|
| 1043 | - $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); |
|
| 1093 | + } else { |
|
| 1094 | + $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); |
|
| 1095 | + } |
|
| 1044 | 1096 | |
| 1045 | 1097 | $strHeaders = strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n"; |
| 1046 | 1098 | |
@@ -1056,23 +1108,27 @@ discard block |
||
| 1056 | 1108 | $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n"; |
| 1057 | 1109 | } |
| 1058 | 1110 | |
| 1059 | - if ( isset($r['user-agent']) ) |
|
| 1060 | - $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n"; |
|
| 1111 | + if ( isset($r['user-agent']) ) { |
|
| 1112 | + $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n"; |
|
| 1113 | + } |
|
| 1061 | 1114 | |
| 1062 | 1115 | if ( is_array($r['headers']) ) { |
| 1063 | - foreach ( (array) $r['headers'] as $header => $headerValue ) |
|
| 1064 | - $strHeaders .= $header . ': ' . $headerValue . "\r\n"; |
|
| 1116 | + foreach ( (array) $r['headers'] as $header => $headerValue ) { |
|
| 1117 | + $strHeaders .= $header . ': ' . $headerValue . "\r\n"; |
|
| 1118 | + } |
|
| 1065 | 1119 | } else { |
| 1066 | 1120 | $strHeaders .= $r['headers']; |
| 1067 | 1121 | } |
| 1068 | 1122 | |
| 1069 | - if ( $proxy->use_authentication() ) |
|
| 1070 | - $strHeaders .= $proxy->authentication_header() . "\r\n"; |
|
| 1123 | + if ( $proxy->use_authentication() ) { |
|
| 1124 | + $strHeaders .= $proxy->authentication_header() . "\r\n"; |
|
| 1125 | + } |
|
| 1071 | 1126 | |
| 1072 | 1127 | $strHeaders .= "\r\n"; |
| 1073 | 1128 | |
| 1074 | - if ( ! is_null($r['body']) ) |
|
| 1075 | - $strHeaders .= $r['body']; |
|
| 1129 | + if ( ! is_null($r['body']) ) { |
|
| 1130 | + $strHeaders .= $r['body']; |
|
| 1131 | + } |
|
| 1076 | 1132 | |
| 1077 | 1133 | fwrite($handle, $strHeaders); |
| 1078 | 1134 | |
@@ -1086,17 +1142,20 @@ discard block |
||
| 1086 | 1142 | $bodyStarted = false; |
| 1087 | 1143 | $keep_reading = true; |
| 1088 | 1144 | $block_size = 4096; |
| 1089 | - if ( isset( $r['limit_response_size'] ) ) |
|
| 1090 | - $block_size = min( $block_size, $r['limit_response_size'] ); |
|
| 1145 | + if ( isset( $r['limit_response_size'] ) ) { |
|
| 1146 | + $block_size = min( $block_size, $r['limit_response_size'] ); |
|
| 1147 | + } |
|
| 1091 | 1148 | |
| 1092 | 1149 | // If streaming to a file setup the file handle. |
| 1093 | 1150 | if ( $r['stream'] ) { |
| 1094 | - if ( ! WP_DEBUG ) |
|
| 1095 | - $stream_handle = @fopen( $r['filename'], 'w+' ); |
|
| 1096 | - else |
|
| 1097 | - $stream_handle = fopen( $r['filename'], 'w+' ); |
|
| 1098 | - if ( ! $stream_handle ) |
|
| 1099 | - return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) ); |
|
| 1151 | + if ( ! WP_DEBUG ) { |
|
| 1152 | + $stream_handle = @fopen( $r['filename'], 'w+' ); |
|
| 1153 | + } else { |
|
| 1154 | + $stream_handle = fopen( $r['filename'], 'w+' ); |
|
| 1155 | + } |
|
| 1156 | + if ( ! $stream_handle ) { |
|
| 1157 | + return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) ); |
|
| 1158 | + } |
|
| 1100 | 1159 | |
| 1101 | 1160 | $bytes_written = 0; |
| 1102 | 1161 | while ( ! feof($handle) && $keep_reading ) { |
@@ -1165,18 +1224,22 @@ discard block |
||
| 1165 | 1224 | ); |
| 1166 | 1225 | |
| 1167 | 1226 | // Handle redirects. |
| 1168 | - if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) |
|
| 1169 | - return $redirect_response; |
|
| 1227 | + if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) { |
|
| 1228 | + return $redirect_response; |
|
| 1229 | + } |
|
| 1170 | 1230 | |
| 1171 | 1231 | // If the body was chunk encoded, then decode it. |
| 1172 | - if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] ) |
|
| 1173 | - $process['body'] = WP_Http::chunkTransferDecode($process['body']); |
|
| 1232 | + if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] ) { |
|
| 1233 | + $process['body'] = WP_Http::chunkTransferDecode($process['body']); |
|
| 1234 | + } |
|
| 1174 | 1235 | |
| 1175 | - if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($arrHeaders['headers']) ) |
|
| 1176 | - $process['body'] = WP_Http_Encoding::decompress( $process['body'] ); |
|
| 1236 | + if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($arrHeaders['headers']) ) { |
|
| 1237 | + $process['body'] = WP_Http_Encoding::decompress( $process['body'] ); |
|
| 1238 | + } |
|
| 1177 | 1239 | |
| 1178 | - if ( isset( $r['limit_response_size'] ) && strlen( $process['body'] ) > $r['limit_response_size'] ) |
|
| 1179 | - $process['body'] = substr( $process['body'], 0, $r['limit_response_size'] ); |
|
| 1240 | + if ( isset( $r['limit_response_size'] ) && strlen( $process['body'] ) > $r['limit_response_size'] ) { |
|
| 1241 | + $process['body'] = substr( $process['body'], 0, $r['limit_response_size'] ); |
|
| 1242 | + } |
|
| 1180 | 1243 | |
| 1181 | 1244 | $response['body'] = $process['body']; |
| 1182 | 1245 | |
@@ -1203,12 +1266,14 @@ discard block |
||
| 1203 | 1266 | public static function verify_ssl_certificate( $stream, $host ) { |
| 1204 | 1267 | $context_options = stream_context_get_options( $stream ); |
| 1205 | 1268 | |
| 1206 | - if ( empty( $context_options['ssl']['peer_certificate'] ) ) |
|
| 1207 | - return false; |
|
| 1269 | + if ( empty( $context_options['ssl']['peer_certificate'] ) ) { |
|
| 1270 | + return false; |
|
| 1271 | + } |
|
| 1208 | 1272 | |
| 1209 | 1273 | $cert = openssl_x509_parse( $context_options['ssl']['peer_certificate'] ); |
| 1210 | - if ( ! $cert ) |
|
| 1211 | - return false; |
|
| 1274 | + if ( ! $cert ) { |
|
| 1275 | + return false; |
|
| 1276 | + } |
|
| 1212 | 1277 | |
| 1213 | 1278 | /* |
| 1214 | 1279 | * If the request is being made to an IP address, we'll validate against IP fields |
@@ -1221,8 +1286,10 @@ discard block |
||
| 1221 | 1286 | $match_against = preg_split( '/,\s*/', $cert['extensions']['subjectAltName'] ); |
| 1222 | 1287 | foreach ( $match_against as $match ) { |
| 1223 | 1288 | list( $match_type, $match_host ) = explode( ':', $match ); |
| 1224 | - if ( $host_type == strtolower( trim( $match_type ) ) ) // IP: or DNS: |
|
| 1289 | + if ( $host_type == strtolower( trim( $match_type ) ) ) { |
|
| 1290 | + // IP: or DNS: |
|
| 1225 | 1291 | $certificate_hostnames[] = strtolower( trim( $match_host ) ); |
| 1292 | + } |
|
| 1226 | 1293 | } |
| 1227 | 1294 | } elseif ( !empty( $cert['subject']['CN'] ) ) { |
| 1228 | 1295 | // Only use the CN when the certificate includes no subjectAltName extension. |
@@ -1230,16 +1297,19 @@ discard block |
||
| 1230 | 1297 | } |
| 1231 | 1298 | |
| 1232 | 1299 | // Exact hostname/IP matches. |
| 1233 | - if ( in_array( strtolower( $host ), $certificate_hostnames ) ) |
|
| 1234 | - return true; |
|
| 1300 | + if ( in_array( strtolower( $host ), $certificate_hostnames ) ) { |
|
| 1301 | + return true; |
|
| 1302 | + } |
|
| 1235 | 1303 | |
| 1236 | 1304 | // IP's can't be wildcards, Stop processing. |
| 1237 | - if ( 'ip' == $host_type ) |
|
| 1238 | - return false; |
|
| 1305 | + if ( 'ip' == $host_type ) { |
|
| 1306 | + return false; |
|
| 1307 | + } |
|
| 1239 | 1308 | |
| 1240 | 1309 | // Test to see if the domain is at least 2 deep for wildcard support. |
| 1241 | - if ( substr_count( $host, '.' ) < 2 ) |
|
| 1242 | - return false; |
|
| 1310 | + if ( substr_count( $host, '.' ) < 2 ) { |
|
| 1311 | + return false; |
|
| 1312 | + } |
|
| 1243 | 1313 | |
| 1244 | 1314 | // Wildcard subdomains certs (*.example.com) are valid for a.example.com but not a.b.example.com. |
| 1245 | 1315 | $wildcard_host = preg_replace( '/^[^.]+\./', '*.', $host ); |
@@ -1258,16 +1328,19 @@ discard block |
||
| 1258 | 1328 | * @return bool False means this class can not be used, true means it can. |
| 1259 | 1329 | */ |
| 1260 | 1330 | public static function test( $args = array() ) { |
| 1261 | - if ( ! function_exists( 'stream_socket_client' ) ) |
|
| 1262 | - return false; |
|
| 1331 | + if ( ! function_exists( 'stream_socket_client' ) ) { |
|
| 1332 | + return false; |
|
| 1333 | + } |
|
| 1263 | 1334 | |
| 1264 | 1335 | $is_ssl = isset( $args['ssl'] ) && $args['ssl']; |
| 1265 | 1336 | |
| 1266 | 1337 | if ( $is_ssl ) { |
| 1267 | - if ( ! extension_loaded( 'openssl' ) ) |
|
| 1268 | - return false; |
|
| 1269 | - if ( ! function_exists( 'openssl_x509_parse' ) ) |
|
| 1270 | - return false; |
|
| 1338 | + if ( ! extension_loaded( 'openssl' ) ) { |
|
| 1339 | + return false; |
|
| 1340 | + } |
|
| 1341 | + if ( ! function_exists( 'openssl_x509_parse' ) ) { |
|
| 1342 | + return false; |
|
| 1343 | + } |
|
| 1271 | 1344 | } |
| 1272 | 1345 | |
| 1273 | 1346 | /** |
@@ -1431,8 +1504,10 @@ discard block |
||
| 1431 | 1504 | * a bug #17490 with redirected POST requests, so handle redirections outside Curl. |
| 1432 | 1505 | */ |
| 1433 | 1506 | curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false ); |
| 1434 | - if ( defined( 'CURLOPT_PROTOCOLS' ) ) // PHP 5.2.10 / cURL 7.19.4 |
|
| 1507 | + if ( defined( 'CURLOPT_PROTOCOLS' ) ) { |
|
| 1508 | + // PHP 5.2.10 / cURL 7.19.4 |
|
| 1435 | 1509 | curl_setopt( $handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS ); |
| 1510 | + } |
|
| 1436 | 1511 | |
| 1437 | 1512 | switch ( $r['method'] ) { |
| 1438 | 1513 | case 'HEAD': |
@@ -1448,8 +1523,9 @@ discard block |
||
| 1448 | 1523 | break; |
| 1449 | 1524 | default: |
| 1450 | 1525 | curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] ); |
| 1451 | - if ( ! is_null( $r['body'] ) ) |
|
| 1452 | - curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
| 1526 | + if ( ! is_null( $r['body'] ) ) { |
|
| 1527 | + curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); |
|
| 1528 | + } |
|
| 1453 | 1529 | break; |
| 1454 | 1530 | } |
| 1455 | 1531 | |
@@ -1460,19 +1536,22 @@ discard block |
||
| 1460 | 1536 | |
| 1461 | 1537 | curl_setopt( $handle, CURLOPT_HEADER, false ); |
| 1462 | 1538 | |
| 1463 | - if ( isset( $r['limit_response_size'] ) ) |
|
| 1464 | - $this->max_body_length = intval( $r['limit_response_size'] ); |
|
| 1465 | - else |
|
| 1466 | - $this->max_body_length = false; |
|
| 1539 | + if ( isset( $r['limit_response_size'] ) ) { |
|
| 1540 | + $this->max_body_length = intval( $r['limit_response_size'] ); |
|
| 1541 | + } else { |
|
| 1542 | + $this->max_body_length = false; |
|
| 1543 | + } |
|
| 1467 | 1544 | |
| 1468 | 1545 | // If streaming to a file open a file handle, and setup our curl streaming handler. |
| 1469 | 1546 | if ( $r['stream'] ) { |
| 1470 | - if ( ! WP_DEBUG ) |
|
| 1471 | - $this->stream_handle = @fopen( $r['filename'], 'w+' ); |
|
| 1472 | - else |
|
| 1473 | - $this->stream_handle = fopen( $r['filename'], 'w+' ); |
|
| 1474 | - if ( ! $this->stream_handle ) |
|
| 1475 | - return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) ); |
|
| 1547 | + if ( ! WP_DEBUG ) { |
|
| 1548 | + $this->stream_handle = @fopen( $r['filename'], 'w+' ); |
|
| 1549 | + } else { |
|
| 1550 | + $this->stream_handle = fopen( $r['filename'], 'w+' ); |
|
| 1551 | + } |
|
| 1552 | + if ( ! $this->stream_handle ) { |
|
| 1553 | + return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) ); |
|
| 1554 | + } |
|
| 1476 | 1555 | } else { |
| 1477 | 1556 | $this->stream_handle = false; |
| 1478 | 1557 | } |
@@ -1486,10 +1565,11 @@ discard block |
||
| 1486 | 1565 | curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers ); |
| 1487 | 1566 | } |
| 1488 | 1567 | |
| 1489 | - if ( $r['httpversion'] == '1.0' ) |
|
| 1490 | - curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); |
|
| 1491 | - else |
|
| 1492 | - curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); |
|
| 1568 | + if ( $r['httpversion'] == '1.0' ) { |
|
| 1569 | + curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); |
|
| 1570 | + } else { |
|
| 1571 | + curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); |
|
| 1572 | + } |
|
| 1493 | 1573 | |
| 1494 | 1574 | /** |
| 1495 | 1575 | * Fires before the cURL request is executed. |
@@ -1560,8 +1640,9 @@ discard block |
||
| 1560 | 1640 | |
| 1561 | 1641 | curl_close( $handle ); |
| 1562 | 1642 | |
| 1563 | - if ( $r['stream'] ) |
|
| 1564 | - fclose( $this->stream_handle ); |
|
| 1643 | + if ( $r['stream'] ) { |
|
| 1644 | + fclose( $this->stream_handle ); |
|
| 1645 | + } |
|
| 1565 | 1646 | |
| 1566 | 1647 | $response = array( |
| 1567 | 1648 | 'headers' => $theHeaders['headers'], |
@@ -1572,11 +1653,13 @@ discard block |
||
| 1572 | 1653 | ); |
| 1573 | 1654 | |
| 1574 | 1655 | // Handle redirects. |
| 1575 | - if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) |
|
| 1576 | - return $redirect_response; |
|
| 1656 | + if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) { |
|
| 1657 | + return $redirect_response; |
|
| 1658 | + } |
|
| 1577 | 1659 | |
| 1578 | - if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) ) |
|
| 1579 | - $theBody = WP_Http_Encoding::decompress( $theBody ); |
|
| 1660 | + if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) ) { |
|
| 1661 | + $theBody = WP_Http_Encoding::decompress( $theBody ); |
|
| 1662 | + } |
|
| 1580 | 1663 | |
| 1581 | 1664 | $response['body'] = $theBody; |
| 1582 | 1665 | |
@@ -1637,16 +1720,18 @@ discard block |
||
| 1637 | 1720 | * @return bool False means this class can not be used, true means it can. |
| 1638 | 1721 | */ |
| 1639 | 1722 | public static function test( $args = array() ) { |
| 1640 | - if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) |
|
| 1641 | - return false; |
|
| 1723 | + if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) { |
|
| 1724 | + return false; |
|
| 1725 | + } |
|
| 1642 | 1726 | |
| 1643 | 1727 | $is_ssl = isset( $args['ssl'] ) && $args['ssl']; |
| 1644 | 1728 | |
| 1645 | 1729 | if ( $is_ssl ) { |
| 1646 | 1730 | $curl_version = curl_version(); |
| 1647 | 1731 | // Check whether this cURL version support SSL requests. |
| 1648 | - if ( ! (CURL_VERSION_SSL & $curl_version['features']) ) |
|
| 1649 | - return false; |
|
| 1732 | + if ( ! (CURL_VERSION_SSL & $curl_version['features']) ) { |
|
| 1733 | + return false; |
|
| 1734 | + } |
|
| 1650 | 1735 | } |
| 1651 | 1736 | |
| 1652 | 1737 | /** |
@@ -1730,8 +1815,9 @@ discard block |
||
| 1730 | 1815 | * @return string |
| 1731 | 1816 | */ |
| 1732 | 1817 | public function host() { |
| 1733 | - if ( defined('WP_PROXY_HOST') ) |
|
| 1734 | - return WP_PROXY_HOST; |
|
| 1818 | + if ( defined('WP_PROXY_HOST') ) { |
|
| 1819 | + return WP_PROXY_HOST; |
|
| 1820 | + } |
|
| 1735 | 1821 | |
| 1736 | 1822 | return ''; |
| 1737 | 1823 | } |
@@ -1744,8 +1830,9 @@ discard block |
||
| 1744 | 1830 | * @return string |
| 1745 | 1831 | */ |
| 1746 | 1832 | public function port() { |
| 1747 | - if ( defined('WP_PROXY_PORT') ) |
|
| 1748 | - return WP_PROXY_PORT; |
|
| 1833 | + if ( defined('WP_PROXY_PORT') ) { |
|
| 1834 | + return WP_PROXY_PORT; |
|
| 1835 | + } |
|
| 1749 | 1836 | |
| 1750 | 1837 | return ''; |
| 1751 | 1838 | } |
@@ -1758,8 +1845,9 @@ discard block |
||
| 1758 | 1845 | * @return string |
| 1759 | 1846 | */ |
| 1760 | 1847 | public function username() { |
| 1761 | - if ( defined('WP_PROXY_USERNAME') ) |
|
| 1762 | - return WP_PROXY_USERNAME; |
|
| 1848 | + if ( defined('WP_PROXY_USERNAME') ) { |
|
| 1849 | + return WP_PROXY_USERNAME; |
|
| 1850 | + } |
|
| 1763 | 1851 | |
| 1764 | 1852 | return ''; |
| 1765 | 1853 | } |
@@ -1772,8 +1860,9 @@ discard block |
||
| 1772 | 1860 | * @return string |
| 1773 | 1861 | */ |
| 1774 | 1862 | public function password() { |
| 1775 | - if ( defined('WP_PROXY_PASSWORD') ) |
|
| 1776 | - return WP_PROXY_PASSWORD; |
|
| 1863 | + if ( defined('WP_PROXY_PASSWORD') ) { |
|
| 1864 | + return WP_PROXY_PASSWORD; |
|
| 1865 | + } |
|
| 1777 | 1866 | |
| 1778 | 1867 | return ''; |
| 1779 | 1868 | } |
@@ -1823,8 +1912,9 @@ discard block |
||
| 1823 | 1912 | $check = @parse_url($uri); |
| 1824 | 1913 | |
| 1825 | 1914 | // Malformed URL, can not process, but this could mean ssl, so let through anyway. |
| 1826 | - if ( $check === false ) |
|
| 1827 | - return true; |
|
| 1915 | + if ( $check === false ) { |
|
| 1916 | + return true; |
|
| 1917 | + } |
|
| 1828 | 1918 | |
| 1829 | 1919 | $home = parse_url( get_option('siteurl') ); |
| 1830 | 1920 | |
@@ -1842,14 +1932,17 @@ discard block |
||
| 1842 | 1932 | * @param array $home Associative array result of parsing the site URL. |
| 1843 | 1933 | */ |
| 1844 | 1934 | $result = apply_filters( 'pre_http_send_through_proxy', null, $uri, $check, $home ); |
| 1845 | - if ( ! is_null( $result ) ) |
|
| 1846 | - return $result; |
|
| 1935 | + if ( ! is_null( $result ) ) { |
|
| 1936 | + return $result; |
|
| 1937 | + } |
|
| 1847 | 1938 | |
| 1848 | - if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) |
|
| 1849 | - return false; |
|
| 1939 | + if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) { |
|
| 1940 | + return false; |
|
| 1941 | + } |
|
| 1850 | 1942 | |
| 1851 | - if ( !defined('WP_PROXY_BYPASS_HOSTS') ) |
|
| 1852 | - return true; |
|
| 1943 | + if ( !defined('WP_PROXY_BYPASS_HOSTS') ) { |
|
| 1944 | + return true; |
|
| 1945 | + } |
|
| 1853 | 1946 | |
| 1854 | 1947 | static $bypass_hosts = null; |
| 1855 | 1948 | static $wildcard_regex = array(); |
@@ -1858,16 +1951,18 @@ discard block |
||
| 1858 | 1951 | |
| 1859 | 1952 | if ( false !== strpos(WP_PROXY_BYPASS_HOSTS, '*') ) { |
| 1860 | 1953 | $wildcard_regex = array(); |
| 1861 | - foreach ( $bypass_hosts as $host ) |
|
| 1862 | - $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
| 1954 | + foreach ( $bypass_hosts as $host ) { |
|
| 1955 | + $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
| 1956 | + } |
|
| 1863 | 1957 | $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; |
| 1864 | 1958 | } |
| 1865 | 1959 | } |
| 1866 | 1960 | |
| 1867 | - if ( !empty($wildcard_regex) ) |
|
| 1868 | - return !preg_match($wildcard_regex, $check['host']); |
|
| 1869 | - else |
|
| 1870 | - return !in_array( $check['host'], $bypass_hosts ); |
|
| 1961 | + if ( !empty($wildcard_regex) ) { |
|
| 1962 | + return !preg_match($wildcard_regex, $check['host']); |
|
| 1963 | + } else { |
|
| 1964 | + return !in_array( $check['host'], $bypass_hosts ); |
|
| 1965 | + } |
|
| 1871 | 1966 | } |
| 1872 | 1967 | } |
| 1873 | 1968 | /** |
@@ -1948,13 +2043,16 @@ discard block |
||
| 1948 | 2043 | * and $port values. |
| 1949 | 2044 | */ |
| 1950 | 2045 | public function __construct( $data, $requested_url = '' ) { |
| 1951 | - if ( $requested_url ) |
|
| 1952 | - $arrURL = @parse_url( $requested_url ); |
|
| 1953 | - if ( isset( $arrURL['host'] ) ) |
|
| 1954 | - $this->domain = $arrURL['host']; |
|
| 2046 | + if ( $requested_url ) { |
|
| 2047 | + $arrURL = @parse_url( $requested_url ); |
|
| 2048 | + } |
|
| 2049 | + if ( isset( $arrURL['host'] ) ) { |
|
| 2050 | + $this->domain = $arrURL['host']; |
|
| 2051 | + } |
|
| 1955 | 2052 | $this->path = isset( $arrURL['path'] ) ? $arrURL['path'] : '/'; |
| 1956 | - if ( '/' != substr( $this->path, -1 ) ) |
|
| 1957 | - $this->path = dirname( $this->path ) . '/'; |
|
| 2053 | + if ( '/' != substr( $this->path, -1 ) ) { |
|
| 2054 | + $this->path = dirname( $this->path ) . '/'; |
|
| 2055 | + } |
|
| 1958 | 2056 | |
| 1959 | 2057 | if ( is_string( $data ) ) { |
| 1960 | 2058 | // Assume it's a header string direct from a previous request. |
@@ -1974,29 +2072,34 @@ discard block |
||
| 1974 | 2072 | $pair = rtrim($pair); |
| 1975 | 2073 | |
| 1976 | 2074 | // Handle the cookie ending in ; which results in a empty final pair. |
| 1977 | - if ( empty($pair) ) |
|
| 1978 | - continue; |
|
| 2075 | + if ( empty($pair) ) { |
|
| 2076 | + continue; |
|
| 2077 | + } |
|
| 1979 | 2078 | |
| 1980 | 2079 | list( $key, $val ) = strpos( $pair, '=' ) ? explode( '=', $pair ) : array( $pair, '' ); |
| 1981 | 2080 | $key = strtolower( trim( $key ) ); |
| 1982 | - if ( 'expires' == $key ) |
|
| 1983 | - $val = strtotime( $val ); |
|
| 2081 | + if ( 'expires' == $key ) { |
|
| 2082 | + $val = strtotime( $val ); |
|
| 2083 | + } |
|
| 1984 | 2084 | $this->$key = $val; |
| 1985 | 2085 | } |
| 1986 | 2086 | } else { |
| 1987 | - if ( !isset( $data['name'] ) ) |
|
| 1988 | - return; |
|
| 2087 | + if ( !isset( $data['name'] ) ) { |
|
| 2088 | + return; |
|
| 2089 | + } |
|
| 1989 | 2090 | |
| 1990 | 2091 | // Set properties based directly on parameters. |
| 1991 | 2092 | foreach ( array( 'name', 'value', 'path', 'domain', 'port' ) as $field ) { |
| 1992 | - if ( isset( $data[ $field ] ) ) |
|
| 1993 | - $this->$field = $data[ $field ]; |
|
| 2093 | + if ( isset( $data[ $field ] ) ) { |
|
| 2094 | + $this->$field = $data[ $field ]; |
|
| 2095 | + } |
|
| 1994 | 2096 | } |
| 1995 | 2097 | |
| 1996 | - if ( isset( $data['expires'] ) ) |
|
| 1997 | - $this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] ); |
|
| 1998 | - else |
|
| 1999 | - $this->expires = null; |
|
| 2098 | + if ( isset( $data['expires'] ) ) { |
|
| 2099 | + $this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] ); |
|
| 2100 | + } else { |
|
| 2101 | + $this->expires = null; |
|
| 2102 | + } |
|
| 2000 | 2103 | } |
| 2001 | 2104 | } |
| 2002 | 2105 | |
@@ -2012,12 +2115,14 @@ discard block |
||
| 2012 | 2115 | * @return bool true if allowed, false otherwise. |
| 2013 | 2116 | */ |
| 2014 | 2117 | public function test( $url ) { |
| 2015 | - if ( is_null( $this->name ) ) |
|
| 2016 | - return false; |
|
| 2118 | + if ( is_null( $this->name ) ) { |
|
| 2119 | + return false; |
|
| 2120 | + } |
|
| 2017 | 2121 | |
| 2018 | 2122 | // Expires - if expired then nothing else matters. |
| 2019 | - if ( isset( $this->expires ) && time() > $this->expires ) |
|
| 2020 | - return false; |
|
| 2123 | + if ( isset( $this->expires ) && time() > $this->expires ) { |
|
| 2124 | + return false; |
|
| 2125 | + } |
|
| 2021 | 2126 | |
| 2022 | 2127 | // Get details on the URL we're thinking about sending to. |
| 2023 | 2128 | $url = parse_url( $url ); |
@@ -2028,21 +2133,25 @@ discard block |
||
| 2028 | 2133 | $path = isset( $this->path ) ? $this->path : '/'; |
| 2029 | 2134 | $port = isset( $this->port ) ? $this->port : null; |
| 2030 | 2135 | $domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] ); |
| 2031 | - if ( false === stripos( $domain, '.' ) ) |
|
| 2032 | - $domain .= '.local'; |
|
| 2136 | + if ( false === stripos( $domain, '.' ) ) { |
|
| 2137 | + $domain .= '.local'; |
|
| 2138 | + } |
|
| 2033 | 2139 | |
| 2034 | 2140 | // Host - very basic check that the request URL ends with the domain restriction (minus leading dot). |
| 2035 | 2141 | $domain = substr( $domain, 0, 1 ) == '.' ? substr( $domain, 1 ) : $domain; |
| 2036 | - if ( substr( $url['host'], -strlen( $domain ) ) != $domain ) |
|
| 2037 | - return false; |
|
| 2142 | + if ( substr( $url['host'], -strlen( $domain ) ) != $domain ) { |
|
| 2143 | + return false; |
|
| 2144 | + } |
|
| 2038 | 2145 | |
| 2039 | 2146 | // Port - supports "port-lists" in the format: "80,8000,8080". |
| 2040 | - if ( !empty( $port ) && !in_array( $url['port'], explode( ',', $port) ) ) |
|
| 2041 | - return false; |
|
| 2147 | + if ( !empty( $port ) && !in_array( $url['port'], explode( ',', $port) ) ) { |
|
| 2148 | + return false; |
|
| 2149 | + } |
|
| 2042 | 2150 | |
| 2043 | 2151 | // Path - request path must start with path restriction. |
| 2044 | - if ( substr( $url['path'], 0, strlen( $path ) ) != $path ) |
|
| 2045 | - return false; |
|
| 2152 | + if ( substr( $url['path'], 0, strlen( $path ) ) != $path ) { |
|
| 2153 | + return false; |
|
| 2154 | + } |
|
| 2046 | 2155 | |
| 2047 | 2156 | return true; |
| 2048 | 2157 | } |
@@ -2056,8 +2165,9 @@ discard block |
||
| 2056 | 2165 | * @return string Header encoded cookie name and value. |
| 2057 | 2166 | */ |
| 2058 | 2167 | public function getHeaderValue() { |
| 2059 | - if ( ! isset( $this->name ) || ! isset( $this->value ) ) |
|
| 2060 | - return ''; |
|
| 2168 | + if ( ! isset( $this->name ) || ! isset( $this->value ) ) { |
|
| 2169 | + return ''; |
|
| 2170 | + } |
|
| 2061 | 2171 | |
| 2062 | 2172 | /** |
| 2063 | 2173 | * Filter the header-encoded cookie value. |
@@ -2130,23 +2240,28 @@ discard block |
||
| 2130 | 2240 | */ |
| 2131 | 2241 | public static function decompress( $compressed, $length = null ) { |
| 2132 | 2242 | |
| 2133 | - if ( empty($compressed) ) |
|
| 2134 | - return $compressed; |
|
| 2243 | + if ( empty($compressed) ) { |
|
| 2244 | + return $compressed; |
|
| 2245 | + } |
|
| 2135 | 2246 | |
| 2136 | - if ( false !== ( $decompressed = @gzinflate( $compressed ) ) ) |
|
| 2137 | - return $decompressed; |
|
| 2247 | + if ( false !== ( $decompressed = @gzinflate( $compressed ) ) ) { |
|
| 2248 | + return $decompressed; |
|
| 2249 | + } |
|
| 2138 | 2250 | |
| 2139 | - if ( false !== ( $decompressed = self::compatible_gzinflate( $compressed ) ) ) |
|
| 2140 | - return $decompressed; |
|
| 2251 | + if ( false !== ( $decompressed = self::compatible_gzinflate( $compressed ) ) ) { |
|
| 2252 | + return $decompressed; |
|
| 2253 | + } |
|
| 2141 | 2254 | |
| 2142 | - if ( false !== ( $decompressed = @gzuncompress( $compressed ) ) ) |
|
| 2143 | - return $decompressed; |
|
| 2255 | + if ( false !== ( $decompressed = @gzuncompress( $compressed ) ) ) { |
|
| 2256 | + return $decompressed; |
|
| 2257 | + } |
|
| 2144 | 2258 | |
| 2145 | 2259 | if ( function_exists('gzdecode') ) { |
| 2146 | 2260 | $decompressed = @gzdecode( $compressed ); |
| 2147 | 2261 | |
| 2148 | - if ( false !== $decompressed ) |
|
| 2149 | - return $decompressed; |
|
| 2262 | + if ( false !== $decompressed ) { |
|
| 2263 | + return $decompressed; |
|
| 2264 | + } |
|
| 2150 | 2265 | } |
| 2151 | 2266 | |
| 2152 | 2267 | return $compressed; |
@@ -2185,22 +2300,27 @@ discard block |
||
| 2185 | 2300 | list($xlen) = unpack('v', substr($gzData, $i, 2) ); |
| 2186 | 2301 | $i = $i + 2 + $xlen; |
| 2187 | 2302 | } |
| 2188 | - if ( $flg & 8 ) |
|
| 2189 | - $i = strpos($gzData, "\0", $i) + 1; |
|
| 2190 | - if ( $flg & 16 ) |
|
| 2191 | - $i = strpos($gzData, "\0", $i) + 1; |
|
| 2192 | - if ( $flg & 2 ) |
|
| 2193 | - $i = $i + 2; |
|
| 2303 | + if ( $flg & 8 ) { |
|
| 2304 | + $i = strpos($gzData, "\0", $i) + 1; |
|
| 2305 | + } |
|
| 2306 | + if ( $flg & 16 ) { |
|
| 2307 | + $i = strpos($gzData, "\0", $i) + 1; |
|
| 2308 | + } |
|
| 2309 | + if ( $flg & 2 ) { |
|
| 2310 | + $i = $i + 2; |
|
| 2311 | + } |
|
| 2194 | 2312 | } |
| 2195 | 2313 | $decompressed = @gzinflate( substr($gzData, $i, -8) ); |
| 2196 | - if ( false !== $decompressed ) |
|
| 2197 | - return $decompressed; |
|
| 2314 | + if ( false !== $decompressed ) { |
|
| 2315 | + return $decompressed; |
|
| 2316 | + } |
|
| 2198 | 2317 | } |
| 2199 | 2318 | |
| 2200 | 2319 | // Compressed data from java.util.zip.Deflater amongst others. |
| 2201 | 2320 | $decompressed = @gzinflate( substr($gzData, 2) ); |
| 2202 | - if ( false !== $decompressed ) |
|
| 2203 | - return $decompressed; |
|
| 2321 | + if ( false !== $decompressed ) { |
|
| 2322 | + return $decompressed; |
|
| 2323 | + } |
|
| 2204 | 2324 | |
| 2205 | 2325 | return false; |
| 2206 | 2326 | } |
@@ -2220,22 +2340,29 @@ discard block |
||
| 2220 | 2340 | $type = array(); |
| 2221 | 2341 | $compression_enabled = self::is_available(); |
| 2222 | 2342 | |
| 2223 | - if ( ! $args['decompress'] ) // Decompression specifically disabled. |
|
| 2343 | + if ( ! $args['decompress'] ) { |
|
| 2344 | + // Decompression specifically disabled. |
|
| 2224 | 2345 | $compression_enabled = false; |
| 2225 | - elseif ( $args['stream'] ) // Disable when streaming to file. |
|
| 2346 | + } elseif ( $args['stream'] ) { |
|
| 2347 | + // Disable when streaming to file. |
|
| 2226 | 2348 | $compression_enabled = false; |
| 2227 | - elseif ( isset( $args['limit_response_size'] ) ) // If only partial content is being requested, we won't be able to decompress it. |
|
| 2349 | + } elseif ( isset( $args['limit_response_size'] ) ) { |
|
| 2350 | + // If only partial content is being requested, we won't be able to decompress it. |
|
| 2228 | 2351 | $compression_enabled = false; |
| 2352 | + } |
|
| 2229 | 2353 | |
| 2230 | 2354 | if ( $compression_enabled ) { |
| 2231 | - if ( function_exists( 'gzinflate' ) ) |
|
| 2232 | - $type[] = 'deflate;q=1.0'; |
|
| 2355 | + if ( function_exists( 'gzinflate' ) ) { |
|
| 2356 | + $type[] = 'deflate;q=1.0'; |
|
| 2357 | + } |
|
| 2233 | 2358 | |
| 2234 | - if ( function_exists( 'gzuncompress' ) ) |
|
| 2235 | - $type[] = 'compress;q=0.5'; |
|
| 2359 | + if ( function_exists( 'gzuncompress' ) ) { |
|
| 2360 | + $type[] = 'compress;q=0.5'; |
|
| 2361 | + } |
|
| 2236 | 2362 | |
| 2237 | - if ( function_exists( 'gzdecode' ) ) |
|
| 2238 | - $type[] = 'gzip;q=0.5'; |
|
| 2363 | + if ( function_exists( 'gzdecode' ) ) { |
|
| 2364 | + $type[] = 'gzip;q=0.5'; |
|
| 2365 | + } |
|
| 2239 | 2366 | } |
| 2240 | 2367 | |
| 2241 | 2368 | /** |
@@ -2278,8 +2405,9 @@ discard block |
||
| 2278 | 2405 | */ |
| 2279 | 2406 | public static function should_decode($headers) { |
| 2280 | 2407 | if ( is_array( $headers ) ) { |
| 2281 | - if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) ) |
|
| 2282 | - return true; |
|
| 2408 | + if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) ) { |
|
| 2409 | + return true; |
|
| 2410 | + } |
|
| 2283 | 2411 | } elseif ( is_string( $headers ) ) { |
| 2284 | 2412 | return ( stripos($headers, 'content-encoding:') !== false ); |
| 2285 | 2413 | } |
@@ -1048,6 +1048,12 @@ |
||
| 1048 | 1048 | self::__construct(); |
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | + /** |
|
| 1052 | + * @param string $method |
|
| 1053 | + * @param string $callback |
|
| 1054 | + * @param string[] $args |
|
| 1055 | + * @param string $help |
|
| 1056 | + */ |
|
| 1051 | 1057 | function addCallback($method, $callback, $args, $help) |
| 1052 | 1058 | { |
| 1053 | 1059 | $this->callbacks[$method] = $callback; |
@@ -1,43 +1,43 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * IXR - The Incutio XML-RPC Library |
|
| 4 | - * |
|
| 5 | - * Copyright (c) 2010, Incutio Ltd. |
|
| 6 | - * All rights reserved. |
|
| 7 | - * |
|
| 8 | - * Redistribution and use in source and binary forms, with or without |
|
| 9 | - * modification, are permitted provided that the following conditions are met: |
|
| 10 | - * |
|
| 11 | - * - Redistributions of source code must retain the above copyright notice, |
|
| 12 | - * this list of conditions and the following disclaimer. |
|
| 13 | - * - Redistributions in binary form must reproduce the above copyright |
|
| 14 | - * notice, this list of conditions and the following disclaimer in the |
|
| 15 | - * documentation and/or other materials provided with the distribution. |
|
| 16 | - * - Neither the name of Incutio Ltd. nor the names of its contributors |
|
| 17 | - * may be used to endorse or promote products derived from this software |
|
| 18 | - * without specific prior written permission. |
|
| 19 | - * |
|
| 20 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|
| 21 | - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
| 22 | - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
| 23 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
| 24 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
| 25 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
| 26 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
| 27 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
| 28 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
| 29 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
|
| 30 | - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
| 31 | - * |
|
| 32 | - * @package IXR |
|
| 33 | - * @since 1.5.0 |
|
| 34 | - * |
|
| 35 | - * @copyright Incutio Ltd 2010 (http://www.incutio.com) |
|
| 36 | - * @version 1.7.4 7th September 2010 |
|
| 37 | - * @author Simon Willison |
|
| 38 | - * @link http://scripts.incutio.com/xmlrpc/ Site/manual |
|
| 39 | - * @license http://www.opensource.org/licenses/bsd-license.php BSD |
|
| 40 | - */ |
|
| 3 | + * IXR - The Incutio XML-RPC Library |
|
| 4 | + * |
|
| 5 | + * Copyright (c) 2010, Incutio Ltd. |
|
| 6 | + * All rights reserved. |
|
| 7 | + * |
|
| 8 | + * Redistribution and use in source and binary forms, with or without |
|
| 9 | + * modification, are permitted provided that the following conditions are met: |
|
| 10 | + * |
|
| 11 | + * - Redistributions of source code must retain the above copyright notice, |
|
| 12 | + * this list of conditions and the following disclaimer. |
|
| 13 | + * - Redistributions in binary form must reproduce the above copyright |
|
| 14 | + * notice, this list of conditions and the following disclaimer in the |
|
| 15 | + * documentation and/or other materials provided with the distribution. |
|
| 16 | + * - Neither the name of Incutio Ltd. nor the names of its contributors |
|
| 17 | + * may be used to endorse or promote products derived from this software |
|
| 18 | + * without specific prior written permission. |
|
| 19 | + * |
|
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|
| 21 | + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
| 22 | + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
| 23 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
| 24 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
| 25 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
| 26 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
| 27 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
| 28 | + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
| 29 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
|
| 30 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
| 31 | + * |
|
| 32 | + * @package IXR |
|
| 33 | + * @since 1.5.0 |
|
| 34 | + * |
|
| 35 | + * @copyright Incutio Ltd 2010 (http://www.incutio.com) |
|
| 36 | + * @version 1.7.4 7th September 2010 |
|
| 37 | + * @author Simon Willison |
|
| 38 | + * @link http://scripts.incutio.com/xmlrpc/ Site/manual |
|
| 39 | + * @license http://www.opensource.org/licenses/bsd-license.php BSD |
|
| 40 | + */ |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * IXR_Value |
@@ -46,31 +46,31 @@ discard block |
||
| 46 | 46 | * @since 1.5.0 |
| 47 | 47 | */ |
| 48 | 48 | class IXR_Value { |
| 49 | - var $data; |
|
| 50 | - var $type; |
|
| 49 | + var $data; |
|
| 50 | + var $type; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * PHP5 constructor. |
| 54 | 54 | */ |
| 55 | 55 | function __construct( $data, $type = false ) |
| 56 | - { |
|
| 57 | - $this->data = $data; |
|
| 58 | - if (!$type) { |
|
| 59 | - $type = $this->calculateType(); |
|
| 60 | - } |
|
| 61 | - $this->type = $type; |
|
| 62 | - if ($type == 'struct') { |
|
| 63 | - // Turn all the values in the array in to new IXR_Value objects |
|
| 64 | - foreach ($this->data as $key => $value) { |
|
| 65 | - $this->data[$key] = new IXR_Value($value); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - if ($type == 'array') { |
|
| 69 | - for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
| 70 | - $this->data[$i] = new IXR_Value($this->data[$i]); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 56 | + { |
|
| 57 | + $this->data = $data; |
|
| 58 | + if (!$type) { |
|
| 59 | + $type = $this->calculateType(); |
|
| 60 | + } |
|
| 61 | + $this->type = $type; |
|
| 62 | + if ($type == 'struct') { |
|
| 63 | + // Turn all the values in the array in to new IXR_Value objects |
|
| 64 | + foreach ($this->data as $key => $value) { |
|
| 65 | + $this->data[$key] = new IXR_Value($value); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + if ($type == 'array') { |
|
| 69 | + for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
| 70 | + $this->data[$i] = new IXR_Value($this->data[$i]); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * PHP4 constructor. |
@@ -79,102 +79,102 @@ discard block |
||
| 79 | 79 | self::__construct( $data, $type ); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - function calculateType() |
|
| 83 | - { |
|
| 84 | - if ($this->data === true || $this->data === false) { |
|
| 85 | - return 'boolean'; |
|
| 86 | - } |
|
| 87 | - if (is_integer($this->data)) { |
|
| 88 | - return 'int'; |
|
| 89 | - } |
|
| 90 | - if (is_double($this->data)) { |
|
| 91 | - return 'double'; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // Deal with IXR object types base64 and date |
|
| 95 | - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
| 96 | - return 'date'; |
|
| 97 | - } |
|
| 98 | - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
| 99 | - return 'base64'; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // If it is a normal PHP object convert it in to a struct |
|
| 103 | - if (is_object($this->data)) { |
|
| 104 | - $this->data = get_object_vars($this->data); |
|
| 105 | - return 'struct'; |
|
| 106 | - } |
|
| 107 | - if (!is_array($this->data)) { |
|
| 108 | - return 'string'; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // We have an array - is it an array or a struct? |
|
| 112 | - if ($this->isStruct($this->data)) { |
|
| 113 | - return 'struct'; |
|
| 114 | - } else { |
|
| 115 | - return 'array'; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - function getXml() |
|
| 120 | - { |
|
| 121 | - // Return XML for this value |
|
| 122 | - switch ($this->type) { |
|
| 123 | - case 'boolean': |
|
| 124 | - return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; |
|
| 125 | - break; |
|
| 126 | - case 'int': |
|
| 127 | - return '<int>'.$this->data.'</int>'; |
|
| 128 | - break; |
|
| 129 | - case 'double': |
|
| 130 | - return '<double>'.$this->data.'</double>'; |
|
| 131 | - break; |
|
| 132 | - case 'string': |
|
| 133 | - return '<string>'.htmlspecialchars($this->data).'</string>'; |
|
| 134 | - break; |
|
| 135 | - case 'array': |
|
| 136 | - $return = '<array><data>'."\n"; |
|
| 137 | - foreach ($this->data as $item) { |
|
| 138 | - $return .= ' <value>'.$item->getXml()."</value>\n"; |
|
| 139 | - } |
|
| 140 | - $return .= '</data></array>'; |
|
| 141 | - return $return; |
|
| 142 | - break; |
|
| 143 | - case 'struct': |
|
| 144 | - $return = '<struct>'."\n"; |
|
| 145 | - foreach ($this->data as $name => $value) { |
|
| 82 | + function calculateType() |
|
| 83 | + { |
|
| 84 | + if ($this->data === true || $this->data === false) { |
|
| 85 | + return 'boolean'; |
|
| 86 | + } |
|
| 87 | + if (is_integer($this->data)) { |
|
| 88 | + return 'int'; |
|
| 89 | + } |
|
| 90 | + if (is_double($this->data)) { |
|
| 91 | + return 'double'; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // Deal with IXR object types base64 and date |
|
| 95 | + if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
| 96 | + return 'date'; |
|
| 97 | + } |
|
| 98 | + if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
| 99 | + return 'base64'; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // If it is a normal PHP object convert it in to a struct |
|
| 103 | + if (is_object($this->data)) { |
|
| 104 | + $this->data = get_object_vars($this->data); |
|
| 105 | + return 'struct'; |
|
| 106 | + } |
|
| 107 | + if (!is_array($this->data)) { |
|
| 108 | + return 'string'; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // We have an array - is it an array or a struct? |
|
| 112 | + if ($this->isStruct($this->data)) { |
|
| 113 | + return 'struct'; |
|
| 114 | + } else { |
|
| 115 | + return 'array'; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + function getXml() |
|
| 120 | + { |
|
| 121 | + // Return XML for this value |
|
| 122 | + switch ($this->type) { |
|
| 123 | + case 'boolean': |
|
| 124 | + return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; |
|
| 125 | + break; |
|
| 126 | + case 'int': |
|
| 127 | + return '<int>'.$this->data.'</int>'; |
|
| 128 | + break; |
|
| 129 | + case 'double': |
|
| 130 | + return '<double>'.$this->data.'</double>'; |
|
| 131 | + break; |
|
| 132 | + case 'string': |
|
| 133 | + return '<string>'.htmlspecialchars($this->data).'</string>'; |
|
| 134 | + break; |
|
| 135 | + case 'array': |
|
| 136 | + $return = '<array><data>'."\n"; |
|
| 137 | + foreach ($this->data as $item) { |
|
| 138 | + $return .= ' <value>'.$item->getXml()."</value>\n"; |
|
| 139 | + } |
|
| 140 | + $return .= '</data></array>'; |
|
| 141 | + return $return; |
|
| 142 | + break; |
|
| 143 | + case 'struct': |
|
| 144 | + $return = '<struct>'."\n"; |
|
| 145 | + foreach ($this->data as $name => $value) { |
|
| 146 | 146 | $name = htmlspecialchars($name); |
| 147 | - $return .= " <member><name>$name</name><value>"; |
|
| 148 | - $return .= $value->getXml()."</value></member>\n"; |
|
| 149 | - } |
|
| 150 | - $return .= '</struct>'; |
|
| 151 | - return $return; |
|
| 152 | - break; |
|
| 153 | - case 'date': |
|
| 154 | - case 'base64': |
|
| 155 | - return $this->data->getXml(); |
|
| 156 | - break; |
|
| 157 | - } |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Checks whether or not the supplied array is a struct or not |
|
| 163 | - * |
|
| 164 | - * @param array $array |
|
| 165 | - * @return bool |
|
| 166 | - */ |
|
| 167 | - function isStruct($array) |
|
| 168 | - { |
|
| 169 | - $expected = 0; |
|
| 170 | - foreach ($array as $key => $value) { |
|
| 171 | - if ((string)$key != (string)$expected) { |
|
| 172 | - return true; |
|
| 173 | - } |
|
| 174 | - $expected++; |
|
| 175 | - } |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 147 | + $return .= " <member><name>$name</name><value>"; |
|
| 148 | + $return .= $value->getXml()."</value></member>\n"; |
|
| 149 | + } |
|
| 150 | + $return .= '</struct>'; |
|
| 151 | + return $return; |
|
| 152 | + break; |
|
| 153 | + case 'date': |
|
| 154 | + case 'base64': |
|
| 155 | + return $this->data->getXml(); |
|
| 156 | + break; |
|
| 157 | + } |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Checks whether or not the supplied array is a struct or not |
|
| 163 | + * |
|
| 164 | + * @param array $array |
|
| 165 | + * @return bool |
|
| 166 | + */ |
|
| 167 | + function isStruct($array) |
|
| 168 | + { |
|
| 169 | + $expected = 0; |
|
| 170 | + foreach ($array as $key => $value) { |
|
| 171 | + if ((string)$key != (string)$expected) { |
|
| 172 | + return true; |
|
| 173 | + } |
|
| 174 | + $expected++; |
|
| 175 | + } |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -186,31 +186,31 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | class IXR_Message |
| 188 | 188 | { |
| 189 | - var $message; |
|
| 190 | - var $messageType; // methodCall / methodResponse / fault |
|
| 191 | - var $faultCode; |
|
| 192 | - var $faultString; |
|
| 193 | - var $methodName; |
|
| 194 | - var $params; |
|
| 195 | - |
|
| 196 | - // Current variable stacks |
|
| 197 | - var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 198 | - var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
| 199 | - var $_currentStructName = array(); // A stack as well |
|
| 200 | - var $_param; |
|
| 201 | - var $_value; |
|
| 202 | - var $_currentTag; |
|
| 203 | - var $_currentTagContents; |
|
| 204 | - // The XML parser |
|
| 205 | - var $_parser; |
|
| 189 | + var $message; |
|
| 190 | + var $messageType; // methodCall / methodResponse / fault |
|
| 191 | + var $faultCode; |
|
| 192 | + var $faultString; |
|
| 193 | + var $methodName; |
|
| 194 | + var $params; |
|
| 195 | + |
|
| 196 | + // Current variable stacks |
|
| 197 | + var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 198 | + var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
| 199 | + var $_currentStructName = array(); // A stack as well |
|
| 200 | + var $_param; |
|
| 201 | + var $_value; |
|
| 202 | + var $_currentTag; |
|
| 203 | + var $_currentTagContents; |
|
| 204 | + // The XML parser |
|
| 205 | + var $_parser; |
|
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * PHP5 constructor. |
| 209 | 209 | */ |
| 210 | - function __construct( $message ) |
|
| 211 | - { |
|
| 212 | - $this->message =& $message; |
|
| 213 | - } |
|
| 210 | + function __construct( $message ) |
|
| 211 | + { |
|
| 212 | + $this->message =& $message; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | 216 | * PHP4 constructor. |
@@ -219,178 +219,178 @@ discard block |
||
| 219 | 219 | self::__construct( $message ); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - function parse() |
|
| 223 | - { |
|
| 224 | - // first remove the XML declaration |
|
| 225 | - // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
|
| 226 | - $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); |
|
| 227 | - $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) ); |
|
| 228 | - if ( '' == $this->message ) { |
|
| 229 | - return false; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Then remove the DOCTYPE |
|
| 233 | - $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 ); |
|
| 234 | - $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) ); |
|
| 235 | - if ( '' == $this->message ) { |
|
| 236 | - return false; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - // Check that the root tag is valid |
|
| 240 | - $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) ); |
|
| 241 | - if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) { |
|
| 242 | - return false; |
|
| 243 | - } |
|
| 244 | - if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) { |
|
| 245 | - return false; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // Bail if there are too many elements to parse |
|
| 249 | - $element_limit = 30000; |
|
| 250 | - if ( function_exists( 'apply_filters' ) ) { |
|
| 251 | - /** |
|
| 252 | - * Filter the number of elements to parse in an XML-RPC response. |
|
| 253 | - * |
|
| 254 | - * @since 4.0.0 |
|
| 255 | - * |
|
| 256 | - * @param int $element_limit Default elements limit. |
|
| 257 | - */ |
|
| 258 | - $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit ); |
|
| 259 | - } |
|
| 260 | - if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) { |
|
| 261 | - return false; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $this->_parser = xml_parser_create(); |
|
| 265 | - // Set XML parser to take the case of tags in to account |
|
| 266 | - xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 267 | - // Set XML parser callback functions |
|
| 268 | - xml_set_object($this->_parser, $this); |
|
| 269 | - xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
| 270 | - xml_set_character_data_handler($this->_parser, 'cdata'); |
|
| 271 | - $chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages |
|
| 272 | - $final = false; |
|
| 273 | - do { |
|
| 274 | - if (strlen($this->message) <= $chunk_size) { |
|
| 275 | - $final = true; |
|
| 276 | - } |
|
| 277 | - $part = substr($this->message, 0, $chunk_size); |
|
| 278 | - $this->message = substr($this->message, $chunk_size); |
|
| 279 | - if (!xml_parse($this->_parser, $part, $final)) { |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 282 | - if ($final) { |
|
| 283 | - break; |
|
| 284 | - } |
|
| 285 | - } while (true); |
|
| 286 | - xml_parser_free($this->_parser); |
|
| 287 | - |
|
| 288 | - // Grab the error messages, if any |
|
| 289 | - if ($this->messageType == 'fault') { |
|
| 290 | - $this->faultCode = $this->params[0]['faultCode']; |
|
| 291 | - $this->faultString = $this->params[0]['faultString']; |
|
| 292 | - } |
|
| 293 | - return true; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - function tag_open($parser, $tag, $attr) |
|
| 297 | - { |
|
| 298 | - $this->_currentTagContents = ''; |
|
| 299 | - $this->currentTag = $tag; |
|
| 300 | - switch($tag) { |
|
| 301 | - case 'methodCall': |
|
| 302 | - case 'methodResponse': |
|
| 303 | - case 'fault': |
|
| 304 | - $this->messageType = $tag; |
|
| 305 | - break; |
|
| 306 | - /* Deal with stacks of arrays and structs */ |
|
| 307 | - case 'data': // data is to all intents and puposes more interesting than array |
|
| 308 | - $this->_arraystructstypes[] = 'array'; |
|
| 309 | - $this->_arraystructs[] = array(); |
|
| 310 | - break; |
|
| 311 | - case 'struct': |
|
| 312 | - $this->_arraystructstypes[] = 'struct'; |
|
| 313 | - $this->_arraystructs[] = array(); |
|
| 314 | - break; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - function cdata($parser, $cdata) |
|
| 319 | - { |
|
| 320 | - $this->_currentTagContents .= $cdata; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - function tag_close($parser, $tag) |
|
| 324 | - { |
|
| 325 | - $valueFlag = false; |
|
| 326 | - switch($tag) { |
|
| 327 | - case 'int': |
|
| 328 | - case 'i4': |
|
| 329 | - $value = (int)trim($this->_currentTagContents); |
|
| 330 | - $valueFlag = true; |
|
| 331 | - break; |
|
| 332 | - case 'double': |
|
| 333 | - $value = (double)trim($this->_currentTagContents); |
|
| 334 | - $valueFlag = true; |
|
| 335 | - break; |
|
| 336 | - case 'string': |
|
| 337 | - $value = (string)trim($this->_currentTagContents); |
|
| 338 | - $valueFlag = true; |
|
| 339 | - break; |
|
| 340 | - case 'dateTime.iso8601': |
|
| 341 | - $value = new IXR_Date(trim($this->_currentTagContents)); |
|
| 342 | - $valueFlag = true; |
|
| 343 | - break; |
|
| 344 | - case 'value': |
|
| 345 | - // "If no type is indicated, the type is string." |
|
| 346 | - if (trim($this->_currentTagContents) != '') { |
|
| 347 | - $value = (string)$this->_currentTagContents; |
|
| 348 | - $valueFlag = true; |
|
| 349 | - } |
|
| 350 | - break; |
|
| 351 | - case 'boolean': |
|
| 352 | - $value = (boolean)trim($this->_currentTagContents); |
|
| 353 | - $valueFlag = true; |
|
| 354 | - break; |
|
| 355 | - case 'base64': |
|
| 356 | - $value = base64_decode($this->_currentTagContents); |
|
| 357 | - $valueFlag = true; |
|
| 358 | - break; |
|
| 359 | - /* Deal with stacks of arrays and structs */ |
|
| 360 | - case 'data': |
|
| 361 | - case 'struct': |
|
| 362 | - $value = array_pop($this->_arraystructs); |
|
| 363 | - array_pop($this->_arraystructstypes); |
|
| 364 | - $valueFlag = true; |
|
| 365 | - break; |
|
| 366 | - case 'member': |
|
| 367 | - array_pop($this->_currentStructName); |
|
| 368 | - break; |
|
| 369 | - case 'name': |
|
| 370 | - $this->_currentStructName[] = trim($this->_currentTagContents); |
|
| 371 | - break; |
|
| 372 | - case 'methodName': |
|
| 373 | - $this->methodName = trim($this->_currentTagContents); |
|
| 374 | - break; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - if ($valueFlag) { |
|
| 378 | - if (count($this->_arraystructs) > 0) { |
|
| 379 | - // Add value to struct or array |
|
| 380 | - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
| 381 | - // Add to struct |
|
| 382 | - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
| 383 | - } else { |
|
| 384 | - // Add to array |
|
| 385 | - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
| 386 | - } |
|
| 387 | - } else { |
|
| 388 | - // Just add as a parameter |
|
| 389 | - $this->params[] = $value; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - $this->_currentTagContents = ''; |
|
| 393 | - } |
|
| 222 | + function parse() |
|
| 223 | + { |
|
| 224 | + // first remove the XML declaration |
|
| 225 | + // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
|
| 226 | + $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); |
|
| 227 | + $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) ); |
|
| 228 | + if ( '' == $this->message ) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Then remove the DOCTYPE |
|
| 233 | + $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 ); |
|
| 234 | + $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) ); |
|
| 235 | + if ( '' == $this->message ) { |
|
| 236 | + return false; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + // Check that the root tag is valid |
|
| 240 | + $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) ); |
|
| 241 | + if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) { |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | + if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) { |
|
| 245 | + return false; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // Bail if there are too many elements to parse |
|
| 249 | + $element_limit = 30000; |
|
| 250 | + if ( function_exists( 'apply_filters' ) ) { |
|
| 251 | + /** |
|
| 252 | + * Filter the number of elements to parse in an XML-RPC response. |
|
| 253 | + * |
|
| 254 | + * @since 4.0.0 |
|
| 255 | + * |
|
| 256 | + * @param int $element_limit Default elements limit. |
|
| 257 | + */ |
|
| 258 | + $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit ); |
|
| 259 | + } |
|
| 260 | + if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) { |
|
| 261 | + return false; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $this->_parser = xml_parser_create(); |
|
| 265 | + // Set XML parser to take the case of tags in to account |
|
| 266 | + xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 267 | + // Set XML parser callback functions |
|
| 268 | + xml_set_object($this->_parser, $this); |
|
| 269 | + xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
| 270 | + xml_set_character_data_handler($this->_parser, 'cdata'); |
|
| 271 | + $chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages |
|
| 272 | + $final = false; |
|
| 273 | + do { |
|
| 274 | + if (strlen($this->message) <= $chunk_size) { |
|
| 275 | + $final = true; |
|
| 276 | + } |
|
| 277 | + $part = substr($this->message, 0, $chunk_size); |
|
| 278 | + $this->message = substr($this->message, $chunk_size); |
|
| 279 | + if (!xml_parse($this->_parser, $part, $final)) { |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | + if ($final) { |
|
| 283 | + break; |
|
| 284 | + } |
|
| 285 | + } while (true); |
|
| 286 | + xml_parser_free($this->_parser); |
|
| 287 | + |
|
| 288 | + // Grab the error messages, if any |
|
| 289 | + if ($this->messageType == 'fault') { |
|
| 290 | + $this->faultCode = $this->params[0]['faultCode']; |
|
| 291 | + $this->faultString = $this->params[0]['faultString']; |
|
| 292 | + } |
|
| 293 | + return true; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + function tag_open($parser, $tag, $attr) |
|
| 297 | + { |
|
| 298 | + $this->_currentTagContents = ''; |
|
| 299 | + $this->currentTag = $tag; |
|
| 300 | + switch($tag) { |
|
| 301 | + case 'methodCall': |
|
| 302 | + case 'methodResponse': |
|
| 303 | + case 'fault': |
|
| 304 | + $this->messageType = $tag; |
|
| 305 | + break; |
|
| 306 | + /* Deal with stacks of arrays and structs */ |
|
| 307 | + case 'data': // data is to all intents and puposes more interesting than array |
|
| 308 | + $this->_arraystructstypes[] = 'array'; |
|
| 309 | + $this->_arraystructs[] = array(); |
|
| 310 | + break; |
|
| 311 | + case 'struct': |
|
| 312 | + $this->_arraystructstypes[] = 'struct'; |
|
| 313 | + $this->_arraystructs[] = array(); |
|
| 314 | + break; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + function cdata($parser, $cdata) |
|
| 319 | + { |
|
| 320 | + $this->_currentTagContents .= $cdata; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + function tag_close($parser, $tag) |
|
| 324 | + { |
|
| 325 | + $valueFlag = false; |
|
| 326 | + switch($tag) { |
|
| 327 | + case 'int': |
|
| 328 | + case 'i4': |
|
| 329 | + $value = (int)trim($this->_currentTagContents); |
|
| 330 | + $valueFlag = true; |
|
| 331 | + break; |
|
| 332 | + case 'double': |
|
| 333 | + $value = (double)trim($this->_currentTagContents); |
|
| 334 | + $valueFlag = true; |
|
| 335 | + break; |
|
| 336 | + case 'string': |
|
| 337 | + $value = (string)trim($this->_currentTagContents); |
|
| 338 | + $valueFlag = true; |
|
| 339 | + break; |
|
| 340 | + case 'dateTime.iso8601': |
|
| 341 | + $value = new IXR_Date(trim($this->_currentTagContents)); |
|
| 342 | + $valueFlag = true; |
|
| 343 | + break; |
|
| 344 | + case 'value': |
|
| 345 | + // "If no type is indicated, the type is string." |
|
| 346 | + if (trim($this->_currentTagContents) != '') { |
|
| 347 | + $value = (string)$this->_currentTagContents; |
|
| 348 | + $valueFlag = true; |
|
| 349 | + } |
|
| 350 | + break; |
|
| 351 | + case 'boolean': |
|
| 352 | + $value = (boolean)trim($this->_currentTagContents); |
|
| 353 | + $valueFlag = true; |
|
| 354 | + break; |
|
| 355 | + case 'base64': |
|
| 356 | + $value = base64_decode($this->_currentTagContents); |
|
| 357 | + $valueFlag = true; |
|
| 358 | + break; |
|
| 359 | + /* Deal with stacks of arrays and structs */ |
|
| 360 | + case 'data': |
|
| 361 | + case 'struct': |
|
| 362 | + $value = array_pop($this->_arraystructs); |
|
| 363 | + array_pop($this->_arraystructstypes); |
|
| 364 | + $valueFlag = true; |
|
| 365 | + break; |
|
| 366 | + case 'member': |
|
| 367 | + array_pop($this->_currentStructName); |
|
| 368 | + break; |
|
| 369 | + case 'name': |
|
| 370 | + $this->_currentStructName[] = trim($this->_currentTagContents); |
|
| 371 | + break; |
|
| 372 | + case 'methodName': |
|
| 373 | + $this->methodName = trim($this->_currentTagContents); |
|
| 374 | + break; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + if ($valueFlag) { |
|
| 378 | + if (count($this->_arraystructs) > 0) { |
|
| 379 | + // Add value to struct or array |
|
| 380 | + if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
| 381 | + // Add to struct |
|
| 382 | + $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
| 383 | + } else { |
|
| 384 | + // Add to array |
|
| 385 | + $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
| 386 | + } |
|
| 387 | + } else { |
|
| 388 | + // Just add as a parameter |
|
| 389 | + $this->params[] = $value; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + $this->_currentTagContents = ''; |
|
| 393 | + } |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -401,25 +401,25 @@ discard block |
||
| 401 | 401 | */ |
| 402 | 402 | class IXR_Server |
| 403 | 403 | { |
| 404 | - var $data; |
|
| 405 | - var $callbacks = array(); |
|
| 406 | - var $message; |
|
| 407 | - var $capabilities; |
|
| 404 | + var $data; |
|
| 405 | + var $callbacks = array(); |
|
| 406 | + var $message; |
|
| 407 | + var $capabilities; |
|
| 408 | 408 | |
| 409 | 409 | /** |
| 410 | 410 | * PHP5 constructor. |
| 411 | 411 | */ |
| 412 | - function __construct( $callbacks = false, $data = false, $wait = false ) |
|
| 413 | - { |
|
| 414 | - $this->setCapabilities(); |
|
| 415 | - if ($callbacks) { |
|
| 416 | - $this->callbacks = $callbacks; |
|
| 417 | - } |
|
| 418 | - $this->setCallbacks(); |
|
| 419 | - if (!$wait) { |
|
| 420 | - $this->serve($data); |
|
| 421 | - } |
|
| 422 | - } |
|
| 412 | + function __construct( $callbacks = false, $data = false, $wait = false ) |
|
| 413 | + { |
|
| 414 | + $this->setCapabilities(); |
|
| 415 | + if ($callbacks) { |
|
| 416 | + $this->callbacks = $callbacks; |
|
| 417 | + } |
|
| 418 | + $this->setCallbacks(); |
|
| 419 | + if (!$wait) { |
|
| 420 | + $this->serve($data); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | 424 | /** |
| 425 | 425 | * PHP4 constructor. |
@@ -428,46 +428,46 @@ discard block |
||
| 428 | 428 | self::__construct( $callbacks, $data, $wait ); |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - function serve($data = false) |
|
| 432 | - { |
|
| 433 | - if (!$data) { |
|
| 434 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
|
| 435 | - if ( function_exists( 'status_header' ) ) { |
|
| 436 | - status_header( 405 ); // WP #20986 |
|
| 437 | - header( 'Allow: POST' ); |
|
| 438 | - } |
|
| 439 | - header('Content-Type: text/plain'); // merged from WP #9093 |
|
| 440 | - die('XML-RPC server accepts POST requests only.'); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - global $HTTP_RAW_POST_DATA; |
|
| 444 | - if (empty($HTTP_RAW_POST_DATA)) { |
|
| 445 | - // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
|
| 446 | - $data = file_get_contents('php://input'); |
|
| 447 | - } else { |
|
| 448 | - $data =& $HTTP_RAW_POST_DATA; |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - $this->message = new IXR_Message($data); |
|
| 452 | - if (!$this->message->parse()) { |
|
| 453 | - $this->error(-32700, 'parse error. not well formed'); |
|
| 454 | - } |
|
| 455 | - if ($this->message->messageType != 'methodCall') { |
|
| 456 | - $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
| 457 | - } |
|
| 458 | - $result = $this->call($this->message->methodName, $this->message->params); |
|
| 459 | - |
|
| 460 | - // Is the result an error? |
|
| 461 | - if (is_a($result, 'IXR_Error')) { |
|
| 462 | - $this->error($result); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - // Encode the result |
|
| 466 | - $r = new IXR_Value($result); |
|
| 467 | - $resultxml = $r->getXml(); |
|
| 468 | - |
|
| 469 | - // Create the XML |
|
| 470 | - $xml = <<<EOD |
|
| 431 | + function serve($data = false) |
|
| 432 | + { |
|
| 433 | + if (!$data) { |
|
| 434 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
|
| 435 | + if ( function_exists( 'status_header' ) ) { |
|
| 436 | + status_header( 405 ); // WP #20986 |
|
| 437 | + header( 'Allow: POST' ); |
|
| 438 | + } |
|
| 439 | + header('Content-Type: text/plain'); // merged from WP #9093 |
|
| 440 | + die('XML-RPC server accepts POST requests only.'); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + global $HTTP_RAW_POST_DATA; |
|
| 444 | + if (empty($HTTP_RAW_POST_DATA)) { |
|
| 445 | + // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
|
| 446 | + $data = file_get_contents('php://input'); |
|
| 447 | + } else { |
|
| 448 | + $data =& $HTTP_RAW_POST_DATA; |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + $this->message = new IXR_Message($data); |
|
| 452 | + if (!$this->message->parse()) { |
|
| 453 | + $this->error(-32700, 'parse error. not well formed'); |
|
| 454 | + } |
|
| 455 | + if ($this->message->messageType != 'methodCall') { |
|
| 456 | + $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
| 457 | + } |
|
| 458 | + $result = $this->call($this->message->methodName, $this->message->params); |
|
| 459 | + |
|
| 460 | + // Is the result an error? |
|
| 461 | + if (is_a($result, 'IXR_Error')) { |
|
| 462 | + $this->error($result); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + // Encode the result |
|
| 466 | + $r = new IXR_Value($result); |
|
| 467 | + $resultxml = $r->getXml(); |
|
| 468 | + |
|
| 469 | + // Create the XML |
|
| 470 | + $xml = <<<EOD |
|
| 471 | 471 | <methodResponse> |
| 472 | 472 | <params> |
| 473 | 473 | <param> |
@@ -479,143 +479,143 @@ discard block |
||
| 479 | 479 | </methodResponse> |
| 480 | 480 | |
| 481 | 481 | EOD; |
| 482 | - // Send it |
|
| 483 | - $this->output($xml); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - function call($methodname, $args) |
|
| 487 | - { |
|
| 488 | - if (!$this->hasMethod($methodname)) { |
|
| 489 | - return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
|
| 490 | - } |
|
| 491 | - $method = $this->callbacks[$methodname]; |
|
| 492 | - |
|
| 493 | - // Perform the callback and send the response |
|
| 494 | - if (count($args) == 1) { |
|
| 495 | - // If only one parameter just send that instead of the whole array |
|
| 496 | - $args = $args[0]; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // Are we dealing with a function or a method? |
|
| 500 | - if (is_string($method) && substr($method, 0, 5) == 'this:') { |
|
| 501 | - // It's a class method - check it exists |
|
| 502 | - $method = substr($method, 5); |
|
| 503 | - if (!method_exists($this, $method)) { |
|
| 504 | - return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - //Call the method |
|
| 508 | - $result = $this->$method($args); |
|
| 509 | - } else { |
|
| 510 | - // It's a function - does it exist? |
|
| 511 | - if (is_array($method)) { |
|
| 512 | - if (!is_callable(array($method[0], $method[1]))) { |
|
| 513 | - return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
|
| 514 | - } |
|
| 515 | - } else if (!function_exists($method)) { |
|
| 516 | - return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - // Call the function |
|
| 520 | - $result = call_user_func($method, $args); |
|
| 521 | - } |
|
| 522 | - return $result; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - function error($error, $message = false) |
|
| 526 | - { |
|
| 527 | - // Accepts either an error object or an error code and message |
|
| 528 | - if ($message && !is_object($error)) { |
|
| 529 | - $error = new IXR_Error($error, $message); |
|
| 530 | - } |
|
| 531 | - $this->output($error->getXml()); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - function output($xml) |
|
| 535 | - { |
|
| 536 | - $charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
|
| 537 | - if ($charset) |
|
| 538 | - $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
| 539 | - else |
|
| 540 | - $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
| 541 | - $length = strlen($xml); |
|
| 542 | - header('Connection: close'); |
|
| 543 | - header('Content-Length: '.$length); |
|
| 544 | - if ($charset) |
|
| 545 | - header('Content-Type: text/xml; charset='.$charset); |
|
| 546 | - else |
|
| 547 | - header('Content-Type: text/xml'); |
|
| 548 | - header('Date: '.date('r')); |
|
| 549 | - echo $xml; |
|
| 550 | - exit; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - function hasMethod($method) |
|
| 554 | - { |
|
| 555 | - return in_array($method, array_keys($this->callbacks)); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - function setCapabilities() |
|
| 559 | - { |
|
| 560 | - // Initialises capabilities array |
|
| 561 | - $this->capabilities = array( |
|
| 562 | - 'xmlrpc' => array( |
|
| 563 | - 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
| 564 | - 'specVersion' => 1 |
|
| 565 | - ), |
|
| 566 | - 'faults_interop' => array( |
|
| 567 | - 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
| 568 | - 'specVersion' => 20010516 |
|
| 569 | - ), |
|
| 570 | - 'system.multicall' => array( |
|
| 571 | - 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
| 572 | - 'specVersion' => 1 |
|
| 573 | - ), |
|
| 574 | - ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - function getCapabilities($args) |
|
| 578 | - { |
|
| 579 | - return $this->capabilities; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - function setCallbacks() |
|
| 583 | - { |
|
| 584 | - $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
| 585 | - $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
| 586 | - $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - function listMethods($args) |
|
| 590 | - { |
|
| 591 | - // Returns a list of methods - uses array_reverse to ensure user defined |
|
| 592 | - // methods are listed before server defined methods |
|
| 593 | - return array_reverse(array_keys($this->callbacks)); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - function multiCall($methodcalls) |
|
| 597 | - { |
|
| 598 | - // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
| 599 | - $return = array(); |
|
| 600 | - foreach ($methodcalls as $call) { |
|
| 601 | - $method = $call['methodName']; |
|
| 602 | - $params = $call['params']; |
|
| 603 | - if ($method == 'system.multicall') { |
|
| 604 | - $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
| 605 | - } else { |
|
| 606 | - $result = $this->call($method, $params); |
|
| 607 | - } |
|
| 608 | - if (is_a($result, 'IXR_Error')) { |
|
| 609 | - $return[] = array( |
|
| 610 | - 'faultCode' => $result->code, |
|
| 611 | - 'faultString' => $result->message |
|
| 612 | - ); |
|
| 613 | - } else { |
|
| 614 | - $return[] = array($result); |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - return $return; |
|
| 618 | - } |
|
| 482 | + // Send it |
|
| 483 | + $this->output($xml); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + function call($methodname, $args) |
|
| 487 | + { |
|
| 488 | + if (!$this->hasMethod($methodname)) { |
|
| 489 | + return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
|
| 490 | + } |
|
| 491 | + $method = $this->callbacks[$methodname]; |
|
| 492 | + |
|
| 493 | + // Perform the callback and send the response |
|
| 494 | + if (count($args) == 1) { |
|
| 495 | + // If only one parameter just send that instead of the whole array |
|
| 496 | + $args = $args[0]; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // Are we dealing with a function or a method? |
|
| 500 | + if (is_string($method) && substr($method, 0, 5) == 'this:') { |
|
| 501 | + // It's a class method - check it exists |
|
| 502 | + $method = substr($method, 5); |
|
| 503 | + if (!method_exists($this, $method)) { |
|
| 504 | + return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + //Call the method |
|
| 508 | + $result = $this->$method($args); |
|
| 509 | + } else { |
|
| 510 | + // It's a function - does it exist? |
|
| 511 | + if (is_array($method)) { |
|
| 512 | + if (!is_callable(array($method[0], $method[1]))) { |
|
| 513 | + return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
|
| 514 | + } |
|
| 515 | + } else if (!function_exists($method)) { |
|
| 516 | + return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + // Call the function |
|
| 520 | + $result = call_user_func($method, $args); |
|
| 521 | + } |
|
| 522 | + return $result; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + function error($error, $message = false) |
|
| 526 | + { |
|
| 527 | + // Accepts either an error object or an error code and message |
|
| 528 | + if ($message && !is_object($error)) { |
|
| 529 | + $error = new IXR_Error($error, $message); |
|
| 530 | + } |
|
| 531 | + $this->output($error->getXml()); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + function output($xml) |
|
| 535 | + { |
|
| 536 | + $charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
|
| 537 | + if ($charset) |
|
| 538 | + $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
| 539 | + else |
|
| 540 | + $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
| 541 | + $length = strlen($xml); |
|
| 542 | + header('Connection: close'); |
|
| 543 | + header('Content-Length: '.$length); |
|
| 544 | + if ($charset) |
|
| 545 | + header('Content-Type: text/xml; charset='.$charset); |
|
| 546 | + else |
|
| 547 | + header('Content-Type: text/xml'); |
|
| 548 | + header('Date: '.date('r')); |
|
| 549 | + echo $xml; |
|
| 550 | + exit; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + function hasMethod($method) |
|
| 554 | + { |
|
| 555 | + return in_array($method, array_keys($this->callbacks)); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + function setCapabilities() |
|
| 559 | + { |
|
| 560 | + // Initialises capabilities array |
|
| 561 | + $this->capabilities = array( |
|
| 562 | + 'xmlrpc' => array( |
|
| 563 | + 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
| 564 | + 'specVersion' => 1 |
|
| 565 | + ), |
|
| 566 | + 'faults_interop' => array( |
|
| 567 | + 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
| 568 | + 'specVersion' => 20010516 |
|
| 569 | + ), |
|
| 570 | + 'system.multicall' => array( |
|
| 571 | + 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
| 572 | + 'specVersion' => 1 |
|
| 573 | + ), |
|
| 574 | + ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + function getCapabilities($args) |
|
| 578 | + { |
|
| 579 | + return $this->capabilities; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + function setCallbacks() |
|
| 583 | + { |
|
| 584 | + $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
| 585 | + $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
| 586 | + $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + function listMethods($args) |
|
| 590 | + { |
|
| 591 | + // Returns a list of methods - uses array_reverse to ensure user defined |
|
| 592 | + // methods are listed before server defined methods |
|
| 593 | + return array_reverse(array_keys($this->callbacks)); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + function multiCall($methodcalls) |
|
| 597 | + { |
|
| 598 | + // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
| 599 | + $return = array(); |
|
| 600 | + foreach ($methodcalls as $call) { |
|
| 601 | + $method = $call['methodName']; |
|
| 602 | + $params = $call['params']; |
|
| 603 | + if ($method == 'system.multicall') { |
|
| 604 | + $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
| 605 | + } else { |
|
| 606 | + $result = $this->call($method, $params); |
|
| 607 | + } |
|
| 608 | + if (is_a($result, 'IXR_Error')) { |
|
| 609 | + $return[] = array( |
|
| 610 | + 'faultCode' => $result->code, |
|
| 611 | + 'faultString' => $result->message |
|
| 612 | + ); |
|
| 613 | + } else { |
|
| 614 | + $return[] = array($result); |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + return $return; |
|
| 618 | + } |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -626,32 +626,32 @@ discard block |
||
| 626 | 626 | */ |
| 627 | 627 | class IXR_Request |
| 628 | 628 | { |
| 629 | - var $method; |
|
| 630 | - var $args; |
|
| 631 | - var $xml; |
|
| 629 | + var $method; |
|
| 630 | + var $args; |
|
| 631 | + var $xml; |
|
| 632 | 632 | |
| 633 | 633 | /** |
| 634 | 634 | * PHP5 constructor. |
| 635 | 635 | */ |
| 636 | - function __construct($method, $args) |
|
| 637 | - { |
|
| 638 | - $this->method = $method; |
|
| 639 | - $this->args = $args; |
|
| 640 | - $this->xml = <<<EOD |
|
| 636 | + function __construct($method, $args) |
|
| 637 | + { |
|
| 638 | + $this->method = $method; |
|
| 639 | + $this->args = $args; |
|
| 640 | + $this->xml = <<<EOD |
|
| 641 | 641 | <?xml version="1.0"?> |
| 642 | 642 | <methodCall> |
| 643 | 643 | <methodName>{$this->method}</methodName> |
| 644 | 644 | <params> |
| 645 | 645 | |
| 646 | 646 | EOD; |
| 647 | - foreach ($this->args as $arg) { |
|
| 648 | - $this->xml .= '<param><value>'; |
|
| 649 | - $v = new IXR_Value($arg); |
|
| 650 | - $this->xml .= $v->getXml(); |
|
| 651 | - $this->xml .= "</value></param>\n"; |
|
| 652 | - } |
|
| 653 | - $this->xml .= '</params></methodCall>'; |
|
| 654 | - } |
|
| 647 | + foreach ($this->args as $arg) { |
|
| 648 | + $this->xml .= '<param><value>'; |
|
| 649 | + $v = new IXR_Value($arg); |
|
| 650 | + $this->xml .= $v->getXml(); |
|
| 651 | + $this->xml .= "</value></param>\n"; |
|
| 652 | + } |
|
| 653 | + $this->xml .= '</params></methodCall>'; |
|
| 654 | + } |
|
| 655 | 655 | |
| 656 | 656 | /** |
| 657 | 657 | * PHP4 constructor. |
@@ -660,15 +660,15 @@ discard block |
||
| 660 | 660 | self::__construct( $method, $args ); |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - function getLength() |
|
| 664 | - { |
|
| 665 | - return strlen($this->xml); |
|
| 666 | - } |
|
| 663 | + function getLength() |
|
| 664 | + { |
|
| 665 | + return strlen($this->xml); |
|
| 666 | + } |
|
| 667 | 667 | |
| 668 | - function getXml() |
|
| 669 | - { |
|
| 670 | - return $this->xml; |
|
| 671 | - } |
|
| 668 | + function getXml() |
|
| 669 | + { |
|
| 670 | + return $this->xml; |
|
| 671 | + } |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -680,47 +680,47 @@ discard block |
||
| 680 | 680 | */ |
| 681 | 681 | class IXR_Client |
| 682 | 682 | { |
| 683 | - var $server; |
|
| 684 | - var $port; |
|
| 685 | - var $path; |
|
| 686 | - var $useragent; |
|
| 687 | - var $response; |
|
| 688 | - var $message = false; |
|
| 689 | - var $debug = false; |
|
| 690 | - var $timeout; |
|
| 691 | - var $headers = array(); |
|
| 692 | - |
|
| 693 | - // Storage place for an error message |
|
| 694 | - var $error = false; |
|
| 683 | + var $server; |
|
| 684 | + var $port; |
|
| 685 | + var $path; |
|
| 686 | + var $useragent; |
|
| 687 | + var $response; |
|
| 688 | + var $message = false; |
|
| 689 | + var $debug = false; |
|
| 690 | + var $timeout; |
|
| 691 | + var $headers = array(); |
|
| 692 | + |
|
| 693 | + // Storage place for an error message |
|
| 694 | + var $error = false; |
|
| 695 | 695 | |
| 696 | 696 | /** |
| 697 | 697 | * PHP5 constructor. |
| 698 | 698 | */ |
| 699 | - function __construct( $server, $path = false, $port = 80, $timeout = 15 ) |
|
| 700 | - { |
|
| 701 | - if (!$path) { |
|
| 702 | - // Assume we have been given a URL instead |
|
| 703 | - $bits = parse_url($server); |
|
| 704 | - $this->server = $bits['host']; |
|
| 705 | - $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
| 706 | - $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
| 707 | - |
|
| 708 | - // Make absolutely sure we have a path |
|
| 709 | - if (!$this->path) { |
|
| 710 | - $this->path = '/'; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - if ( ! empty( $bits['query'] ) ) { |
|
| 714 | - $this->path .= '?' . $bits['query']; |
|
| 715 | - } |
|
| 716 | - } else { |
|
| 717 | - $this->server = $server; |
|
| 718 | - $this->path = $path; |
|
| 719 | - $this->port = $port; |
|
| 720 | - } |
|
| 721 | - $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
| 722 | - $this->timeout = $timeout; |
|
| 723 | - } |
|
| 699 | + function __construct( $server, $path = false, $port = 80, $timeout = 15 ) |
|
| 700 | + { |
|
| 701 | + if (!$path) { |
|
| 702 | + // Assume we have been given a URL instead |
|
| 703 | + $bits = parse_url($server); |
|
| 704 | + $this->server = $bits['host']; |
|
| 705 | + $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
| 706 | + $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
| 707 | + |
|
| 708 | + // Make absolutely sure we have a path |
|
| 709 | + if (!$this->path) { |
|
| 710 | + $this->path = '/'; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + if ( ! empty( $bits['query'] ) ) { |
|
| 714 | + $this->path .= '?' . $bits['query']; |
|
| 715 | + } |
|
| 716 | + } else { |
|
| 717 | + $this->server = $server; |
|
| 718 | + $this->path = $path; |
|
| 719 | + $this->port = $port; |
|
| 720 | + } |
|
| 721 | + $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
| 722 | + $this->timeout = $timeout; |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | 725 | /** |
| 726 | 726 | * PHP4 constructor. |
@@ -729,111 +729,111 @@ discard block |
||
| 729 | 729 | self::__construct( $server, $path, $port, $timeout ); |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - function query() |
|
| 733 | - { |
|
| 734 | - $args = func_get_args(); |
|
| 735 | - $method = array_shift($args); |
|
| 736 | - $request = new IXR_Request($method, $args); |
|
| 737 | - $length = $request->getLength(); |
|
| 738 | - $xml = $request->getXml(); |
|
| 739 | - $r = "\r\n"; |
|
| 740 | - $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 741 | - |
|
| 742 | - // Merged from WP #8145 - allow custom headers |
|
| 743 | - $this->headers['Host'] = $this->server; |
|
| 744 | - $this->headers['Content-Type'] = 'text/xml'; |
|
| 745 | - $this->headers['User-Agent'] = $this->useragent; |
|
| 746 | - $this->headers['Content-Length']= $length; |
|
| 747 | - |
|
| 748 | - foreach( $this->headers as $header => $value ) { |
|
| 749 | - $request .= "{$header}: {$value}{$r}"; |
|
| 750 | - } |
|
| 751 | - $request .= $r; |
|
| 752 | - |
|
| 753 | - $request .= $xml; |
|
| 754 | - |
|
| 755 | - // Now send the request |
|
| 756 | - if ($this->debug) { |
|
| 757 | - echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - if ($this->timeout) { |
|
| 761 | - $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
| 762 | - } else { |
|
| 763 | - $fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
|
| 764 | - } |
|
| 765 | - if (!$fp) { |
|
| 766 | - $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
| 767 | - return false; |
|
| 768 | - } |
|
| 769 | - fputs($fp, $request); |
|
| 770 | - $contents = ''; |
|
| 771 | - $debugContents = ''; |
|
| 772 | - $gotFirstLine = false; |
|
| 773 | - $gettingHeaders = true; |
|
| 774 | - while (!feof($fp)) { |
|
| 775 | - $line = fgets($fp, 4096); |
|
| 776 | - if (!$gotFirstLine) { |
|
| 777 | - // Check line for '200' |
|
| 778 | - if (strstr($line, '200') === false) { |
|
| 779 | - $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
| 780 | - return false; |
|
| 781 | - } |
|
| 782 | - $gotFirstLine = true; |
|
| 783 | - } |
|
| 784 | - if (trim($line) == '') { |
|
| 785 | - $gettingHeaders = false; |
|
| 786 | - } |
|
| 787 | - if (!$gettingHeaders) { |
|
| 788 | - // merged from WP #12559 - remove trim |
|
| 789 | - $contents .= $line; |
|
| 790 | - } |
|
| 791 | - if ($this->debug) { |
|
| 792 | - $debugContents .= $line; |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - if ($this->debug) { |
|
| 796 | - echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - // Now parse what we've got back |
|
| 800 | - $this->message = new IXR_Message($contents); |
|
| 801 | - if (!$this->message->parse()) { |
|
| 802 | - // XML error |
|
| 803 | - $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
| 804 | - return false; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - // Is the message a fault? |
|
| 808 | - if ($this->message->messageType == 'fault') { |
|
| 809 | - $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
| 810 | - return false; |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - // Message must be OK |
|
| 814 | - return true; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - function getResponse() |
|
| 818 | - { |
|
| 819 | - // methodResponses can only have one param - return that |
|
| 820 | - return $this->message->params[0]; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - function isError() |
|
| 824 | - { |
|
| 825 | - return (is_object($this->error)); |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - function getErrorCode() |
|
| 829 | - { |
|
| 830 | - return $this->error->code; |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - function getErrorMessage() |
|
| 834 | - { |
|
| 835 | - return $this->error->message; |
|
| 836 | - } |
|
| 732 | + function query() |
|
| 733 | + { |
|
| 734 | + $args = func_get_args(); |
|
| 735 | + $method = array_shift($args); |
|
| 736 | + $request = new IXR_Request($method, $args); |
|
| 737 | + $length = $request->getLength(); |
|
| 738 | + $xml = $request->getXml(); |
|
| 739 | + $r = "\r\n"; |
|
| 740 | + $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 741 | + |
|
| 742 | + // Merged from WP #8145 - allow custom headers |
|
| 743 | + $this->headers['Host'] = $this->server; |
|
| 744 | + $this->headers['Content-Type'] = 'text/xml'; |
|
| 745 | + $this->headers['User-Agent'] = $this->useragent; |
|
| 746 | + $this->headers['Content-Length']= $length; |
|
| 747 | + |
|
| 748 | + foreach( $this->headers as $header => $value ) { |
|
| 749 | + $request .= "{$header}: {$value}{$r}"; |
|
| 750 | + } |
|
| 751 | + $request .= $r; |
|
| 752 | + |
|
| 753 | + $request .= $xml; |
|
| 754 | + |
|
| 755 | + // Now send the request |
|
| 756 | + if ($this->debug) { |
|
| 757 | + echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + if ($this->timeout) { |
|
| 761 | + $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
| 762 | + } else { |
|
| 763 | + $fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
|
| 764 | + } |
|
| 765 | + if (!$fp) { |
|
| 766 | + $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
| 767 | + return false; |
|
| 768 | + } |
|
| 769 | + fputs($fp, $request); |
|
| 770 | + $contents = ''; |
|
| 771 | + $debugContents = ''; |
|
| 772 | + $gotFirstLine = false; |
|
| 773 | + $gettingHeaders = true; |
|
| 774 | + while (!feof($fp)) { |
|
| 775 | + $line = fgets($fp, 4096); |
|
| 776 | + if (!$gotFirstLine) { |
|
| 777 | + // Check line for '200' |
|
| 778 | + if (strstr($line, '200') === false) { |
|
| 779 | + $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
| 780 | + return false; |
|
| 781 | + } |
|
| 782 | + $gotFirstLine = true; |
|
| 783 | + } |
|
| 784 | + if (trim($line) == '') { |
|
| 785 | + $gettingHeaders = false; |
|
| 786 | + } |
|
| 787 | + if (!$gettingHeaders) { |
|
| 788 | + // merged from WP #12559 - remove trim |
|
| 789 | + $contents .= $line; |
|
| 790 | + } |
|
| 791 | + if ($this->debug) { |
|
| 792 | + $debugContents .= $line; |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + if ($this->debug) { |
|
| 796 | + echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + // Now parse what we've got back |
|
| 800 | + $this->message = new IXR_Message($contents); |
|
| 801 | + if (!$this->message->parse()) { |
|
| 802 | + // XML error |
|
| 803 | + $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
| 804 | + return false; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + // Is the message a fault? |
|
| 808 | + if ($this->message->messageType == 'fault') { |
|
| 809 | + $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + // Message must be OK |
|
| 814 | + return true; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + function getResponse() |
|
| 818 | + { |
|
| 819 | + // methodResponses can only have one param - return that |
|
| 820 | + return $this->message->params[0]; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + function isError() |
|
| 824 | + { |
|
| 825 | + return (is_object($this->error)); |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + function getErrorCode() |
|
| 829 | + { |
|
| 830 | + return $this->error->code; |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + function getErrorMessage() |
|
| 834 | + { |
|
| 835 | + return $this->error->message; |
|
| 836 | + } |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | |
@@ -845,17 +845,17 @@ discard block |
||
| 845 | 845 | */ |
| 846 | 846 | class IXR_Error |
| 847 | 847 | { |
| 848 | - var $code; |
|
| 849 | - var $message; |
|
| 848 | + var $code; |
|
| 849 | + var $message; |
|
| 850 | 850 | |
| 851 | 851 | /** |
| 852 | 852 | * PHP5 constructor. |
| 853 | 853 | */ |
| 854 | - function __construct( $code, $message ) |
|
| 855 | - { |
|
| 856 | - $this->code = $code; |
|
| 857 | - $this->message = htmlspecialchars($message); |
|
| 858 | - } |
|
| 854 | + function __construct( $code, $message ) |
|
| 855 | + { |
|
| 856 | + $this->code = $code; |
|
| 857 | + $this->message = htmlspecialchars($message); |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | 860 | /** |
| 861 | 861 | * PHP4 constructor. |
@@ -864,9 +864,9 @@ discard block |
||
| 864 | 864 | self::__construct( $code, $message ); |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | - function getXml() |
|
| 868 | - { |
|
| 869 | - $xml = <<<EOD |
|
| 867 | + function getXml() |
|
| 868 | + { |
|
| 869 | + $xml = <<<EOD |
|
| 870 | 870 | <methodResponse> |
| 871 | 871 | <fault> |
| 872 | 872 | <value> |
@@ -885,8 +885,8 @@ discard block |
||
| 885 | 885 | </methodResponse> |
| 886 | 886 | |
| 887 | 887 | EOD; |
| 888 | - return $xml; |
|
| 889 | - } |
|
| 888 | + return $xml; |
|
| 889 | + } |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | /** |
@@ -896,26 +896,26 @@ discard block |
||
| 896 | 896 | * @since 1.5.0 |
| 897 | 897 | */ |
| 898 | 898 | class IXR_Date { |
| 899 | - var $year; |
|
| 900 | - var $month; |
|
| 901 | - var $day; |
|
| 902 | - var $hour; |
|
| 903 | - var $minute; |
|
| 904 | - var $second; |
|
| 905 | - var $timezone; |
|
| 899 | + var $year; |
|
| 900 | + var $month; |
|
| 901 | + var $day; |
|
| 902 | + var $hour; |
|
| 903 | + var $minute; |
|
| 904 | + var $second; |
|
| 905 | + var $timezone; |
|
| 906 | 906 | |
| 907 | 907 | /** |
| 908 | 908 | * PHP5 constructor. |
| 909 | 909 | */ |
| 910 | - function __construct( $time ) |
|
| 911 | - { |
|
| 912 | - // $time can be a PHP timestamp or an ISO one |
|
| 913 | - if (is_numeric($time)) { |
|
| 914 | - $this->parseTimestamp($time); |
|
| 915 | - } else { |
|
| 916 | - $this->parseIso($time); |
|
| 917 | - } |
|
| 918 | - } |
|
| 910 | + function __construct( $time ) |
|
| 911 | + { |
|
| 912 | + // $time can be a PHP timestamp or an ISO one |
|
| 913 | + if (is_numeric($time)) { |
|
| 914 | + $this->parseTimestamp($time); |
|
| 915 | + } else { |
|
| 916 | + $this->parseIso($time); |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | 919 | |
| 920 | 920 | /** |
| 921 | 921 | * PHP4 constructor. |
@@ -924,42 +924,42 @@ discard block |
||
| 924 | 924 | self::__construct( $time ); |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | - function parseTimestamp($timestamp) |
|
| 928 | - { |
|
| 929 | - $this->year = date('Y', $timestamp); |
|
| 930 | - $this->month = date('m', $timestamp); |
|
| 931 | - $this->day = date('d', $timestamp); |
|
| 932 | - $this->hour = date('H', $timestamp); |
|
| 933 | - $this->minute = date('i', $timestamp); |
|
| 934 | - $this->second = date('s', $timestamp); |
|
| 935 | - $this->timezone = ''; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - function parseIso($iso) |
|
| 939 | - { |
|
| 940 | - $this->year = substr($iso, 0, 4); |
|
| 941 | - $this->month = substr($iso, 4, 2); |
|
| 942 | - $this->day = substr($iso, 6, 2); |
|
| 943 | - $this->hour = substr($iso, 9, 2); |
|
| 944 | - $this->minute = substr($iso, 12, 2); |
|
| 945 | - $this->second = substr($iso, 15, 2); |
|
| 946 | - $this->timezone = substr($iso, 17); |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - function getIso() |
|
| 950 | - { |
|
| 951 | - return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - function getXml() |
|
| 955 | - { |
|
| 956 | - return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - function getTimestamp() |
|
| 960 | - { |
|
| 961 | - return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
| 962 | - } |
|
| 927 | + function parseTimestamp($timestamp) |
|
| 928 | + { |
|
| 929 | + $this->year = date('Y', $timestamp); |
|
| 930 | + $this->month = date('m', $timestamp); |
|
| 931 | + $this->day = date('d', $timestamp); |
|
| 932 | + $this->hour = date('H', $timestamp); |
|
| 933 | + $this->minute = date('i', $timestamp); |
|
| 934 | + $this->second = date('s', $timestamp); |
|
| 935 | + $this->timezone = ''; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + function parseIso($iso) |
|
| 939 | + { |
|
| 940 | + $this->year = substr($iso, 0, 4); |
|
| 941 | + $this->month = substr($iso, 4, 2); |
|
| 942 | + $this->day = substr($iso, 6, 2); |
|
| 943 | + $this->hour = substr($iso, 9, 2); |
|
| 944 | + $this->minute = substr($iso, 12, 2); |
|
| 945 | + $this->second = substr($iso, 15, 2); |
|
| 946 | + $this->timezone = substr($iso, 17); |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + function getIso() |
|
| 950 | + { |
|
| 951 | + return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + function getXml() |
|
| 955 | + { |
|
| 956 | + return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + function getTimestamp() |
|
| 960 | + { |
|
| 961 | + return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
| 962 | + } |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -970,15 +970,15 @@ discard block |
||
| 970 | 970 | */ |
| 971 | 971 | class IXR_Base64 |
| 972 | 972 | { |
| 973 | - var $data; |
|
| 973 | + var $data; |
|
| 974 | 974 | |
| 975 | 975 | /** |
| 976 | 976 | * PHP5 constructor. |
| 977 | 977 | */ |
| 978 | - function __construct( $data ) |
|
| 979 | - { |
|
| 980 | - $this->data = $data; |
|
| 981 | - } |
|
| 978 | + function __construct( $data ) |
|
| 979 | + { |
|
| 980 | + $this->data = $data; |
|
| 981 | + } |
|
| 982 | 982 | |
| 983 | 983 | /** |
| 984 | 984 | * PHP4 constructor. |
@@ -987,10 +987,10 @@ discard block |
||
| 987 | 987 | self::__construct( $data ); |
| 988 | 988 | } |
| 989 | 989 | |
| 990 | - function getXml() |
|
| 991 | - { |
|
| 992 | - return '<base64>'.base64_encode($this->data).'</base64>'; |
|
| 993 | - } |
|
| 990 | + function getXml() |
|
| 991 | + { |
|
| 992 | + return '<base64>'.base64_encode($this->data).'</base64>'; |
|
| 993 | + } |
|
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | /** |
@@ -1001,45 +1001,45 @@ discard block |
||
| 1001 | 1001 | */ |
| 1002 | 1002 | class IXR_IntrospectionServer extends IXR_Server |
| 1003 | 1003 | { |
| 1004 | - var $signatures; |
|
| 1005 | - var $help; |
|
| 1004 | + var $signatures; |
|
| 1005 | + var $help; |
|
| 1006 | 1006 | |
| 1007 | 1007 | /** |
| 1008 | 1008 | * PHP5 constructor. |
| 1009 | 1009 | */ |
| 1010 | - function __construct() |
|
| 1011 | - { |
|
| 1012 | - $this->setCallbacks(); |
|
| 1013 | - $this->setCapabilities(); |
|
| 1014 | - $this->capabilities['introspection'] = array( |
|
| 1015 | - 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
| 1016 | - 'specVersion' => 1 |
|
| 1017 | - ); |
|
| 1018 | - $this->addCallback( |
|
| 1019 | - 'system.methodSignature', |
|
| 1020 | - 'this:methodSignature', |
|
| 1021 | - array('array', 'string'), |
|
| 1022 | - 'Returns an array describing the return type and required parameters of a method' |
|
| 1023 | - ); |
|
| 1024 | - $this->addCallback( |
|
| 1025 | - 'system.getCapabilities', |
|
| 1026 | - 'this:getCapabilities', |
|
| 1027 | - array('struct'), |
|
| 1028 | - 'Returns a struct describing the XML-RPC specifications supported by this server' |
|
| 1029 | - ); |
|
| 1030 | - $this->addCallback( |
|
| 1031 | - 'system.listMethods', |
|
| 1032 | - 'this:listMethods', |
|
| 1033 | - array('array'), |
|
| 1034 | - 'Returns an array of available methods on this server' |
|
| 1035 | - ); |
|
| 1036 | - $this->addCallback( |
|
| 1037 | - 'system.methodHelp', |
|
| 1038 | - 'this:methodHelp', |
|
| 1039 | - array('string', 'string'), |
|
| 1040 | - 'Returns a documentation string for the specified method' |
|
| 1041 | - ); |
|
| 1042 | - } |
|
| 1010 | + function __construct() |
|
| 1011 | + { |
|
| 1012 | + $this->setCallbacks(); |
|
| 1013 | + $this->setCapabilities(); |
|
| 1014 | + $this->capabilities['introspection'] = array( |
|
| 1015 | + 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
| 1016 | + 'specVersion' => 1 |
|
| 1017 | + ); |
|
| 1018 | + $this->addCallback( |
|
| 1019 | + 'system.methodSignature', |
|
| 1020 | + 'this:methodSignature', |
|
| 1021 | + array('array', 'string'), |
|
| 1022 | + 'Returns an array describing the return type and required parameters of a method' |
|
| 1023 | + ); |
|
| 1024 | + $this->addCallback( |
|
| 1025 | + 'system.getCapabilities', |
|
| 1026 | + 'this:getCapabilities', |
|
| 1027 | + array('struct'), |
|
| 1028 | + 'Returns a struct describing the XML-RPC specifications supported by this server' |
|
| 1029 | + ); |
|
| 1030 | + $this->addCallback( |
|
| 1031 | + 'system.listMethods', |
|
| 1032 | + 'this:listMethods', |
|
| 1033 | + array('array'), |
|
| 1034 | + 'Returns an array of available methods on this server' |
|
| 1035 | + ); |
|
| 1036 | + $this->addCallback( |
|
| 1037 | + 'system.methodHelp', |
|
| 1038 | + 'this:methodHelp', |
|
| 1039 | + array('string', 'string'), |
|
| 1040 | + 'Returns a documentation string for the specified method' |
|
| 1041 | + ); |
|
| 1042 | + } |
|
| 1043 | 1043 | |
| 1044 | 1044 | /** |
| 1045 | 1045 | * PHP4 constructor. |
@@ -1048,122 +1048,122 @@ discard block |
||
| 1048 | 1048 | self::__construct(); |
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | - function addCallback($method, $callback, $args, $help) |
|
| 1052 | - { |
|
| 1053 | - $this->callbacks[$method] = $callback; |
|
| 1054 | - $this->signatures[$method] = $args; |
|
| 1055 | - $this->help[$method] = $help; |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - function call($methodname, $args) |
|
| 1059 | - { |
|
| 1060 | - // Make sure it's in an array |
|
| 1061 | - if ($args && !is_array($args)) { |
|
| 1062 | - $args = array($args); |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - // Over-rides default call method, adds signature check |
|
| 1066 | - if (!$this->hasMethod($methodname)) { |
|
| 1067 | - return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); |
|
| 1068 | - } |
|
| 1069 | - $method = $this->callbacks[$methodname]; |
|
| 1070 | - $signature = $this->signatures[$methodname]; |
|
| 1071 | - $returnType = array_shift($signature); |
|
| 1072 | - |
|
| 1073 | - // Check the number of arguments |
|
| 1074 | - if (count($args) != count($signature)) { |
|
| 1075 | - return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - // Check the argument types |
|
| 1079 | - $ok = true; |
|
| 1080 | - $argsbackup = $args; |
|
| 1081 | - for ($i = 0, $j = count($args); $i < $j; $i++) { |
|
| 1082 | - $arg = array_shift($args); |
|
| 1083 | - $type = array_shift($signature); |
|
| 1084 | - switch ($type) { |
|
| 1085 | - case 'int': |
|
| 1086 | - case 'i4': |
|
| 1087 | - if (is_array($arg) || !is_int($arg)) { |
|
| 1088 | - $ok = false; |
|
| 1089 | - } |
|
| 1090 | - break; |
|
| 1091 | - case 'base64': |
|
| 1092 | - case 'string': |
|
| 1093 | - if (!is_string($arg)) { |
|
| 1094 | - $ok = false; |
|
| 1095 | - } |
|
| 1096 | - break; |
|
| 1097 | - case 'boolean': |
|
| 1098 | - if ($arg !== false && $arg !== true) { |
|
| 1099 | - $ok = false; |
|
| 1100 | - } |
|
| 1101 | - break; |
|
| 1102 | - case 'float': |
|
| 1103 | - case 'double': |
|
| 1104 | - if (!is_float($arg)) { |
|
| 1105 | - $ok = false; |
|
| 1106 | - } |
|
| 1107 | - break; |
|
| 1108 | - case 'date': |
|
| 1109 | - case 'dateTime.iso8601': |
|
| 1110 | - if (!is_a($arg, 'IXR_Date')) { |
|
| 1111 | - $ok = false; |
|
| 1112 | - } |
|
| 1113 | - break; |
|
| 1114 | - } |
|
| 1115 | - if (!$ok) { |
|
| 1116 | - return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
| 1117 | - } |
|
| 1118 | - } |
|
| 1119 | - // It passed the test - run the "real" method call |
|
| 1120 | - return parent::call($methodname, $argsbackup); |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - function methodSignature($method) |
|
| 1124 | - { |
|
| 1125 | - if (!$this->hasMethod($method)) { |
|
| 1126 | - return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); |
|
| 1127 | - } |
|
| 1128 | - // We should be returning an array of types |
|
| 1129 | - $types = $this->signatures[$method]; |
|
| 1130 | - $return = array(); |
|
| 1131 | - foreach ($types as $type) { |
|
| 1132 | - switch ($type) { |
|
| 1133 | - case 'string': |
|
| 1134 | - $return[] = 'string'; |
|
| 1135 | - break; |
|
| 1136 | - case 'int': |
|
| 1137 | - case 'i4': |
|
| 1138 | - $return[] = 42; |
|
| 1139 | - break; |
|
| 1140 | - case 'double': |
|
| 1141 | - $return[] = 3.1415; |
|
| 1142 | - break; |
|
| 1143 | - case 'dateTime.iso8601': |
|
| 1144 | - $return[] = new IXR_Date(time()); |
|
| 1145 | - break; |
|
| 1146 | - case 'boolean': |
|
| 1147 | - $return[] = true; |
|
| 1148 | - break; |
|
| 1149 | - case 'base64': |
|
| 1150 | - $return[] = new IXR_Base64('base64'); |
|
| 1151 | - break; |
|
| 1152 | - case 'array': |
|
| 1153 | - $return[] = array('array'); |
|
| 1154 | - break; |
|
| 1155 | - case 'struct': |
|
| 1156 | - $return[] = array('struct' => 'struct'); |
|
| 1157 | - break; |
|
| 1158 | - } |
|
| 1159 | - } |
|
| 1160 | - return $return; |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - function methodHelp($method) |
|
| 1164 | - { |
|
| 1165 | - return $this->help[$method]; |
|
| 1166 | - } |
|
| 1051 | + function addCallback($method, $callback, $args, $help) |
|
| 1052 | + { |
|
| 1053 | + $this->callbacks[$method] = $callback; |
|
| 1054 | + $this->signatures[$method] = $args; |
|
| 1055 | + $this->help[$method] = $help; |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + function call($methodname, $args) |
|
| 1059 | + { |
|
| 1060 | + // Make sure it's in an array |
|
| 1061 | + if ($args && !is_array($args)) { |
|
| 1062 | + $args = array($args); |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + // Over-rides default call method, adds signature check |
|
| 1066 | + if (!$this->hasMethod($methodname)) { |
|
| 1067 | + return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); |
|
| 1068 | + } |
|
| 1069 | + $method = $this->callbacks[$methodname]; |
|
| 1070 | + $signature = $this->signatures[$methodname]; |
|
| 1071 | + $returnType = array_shift($signature); |
|
| 1072 | + |
|
| 1073 | + // Check the number of arguments |
|
| 1074 | + if (count($args) != count($signature)) { |
|
| 1075 | + return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + // Check the argument types |
|
| 1079 | + $ok = true; |
|
| 1080 | + $argsbackup = $args; |
|
| 1081 | + for ($i = 0, $j = count($args); $i < $j; $i++) { |
|
| 1082 | + $arg = array_shift($args); |
|
| 1083 | + $type = array_shift($signature); |
|
| 1084 | + switch ($type) { |
|
| 1085 | + case 'int': |
|
| 1086 | + case 'i4': |
|
| 1087 | + if (is_array($arg) || !is_int($arg)) { |
|
| 1088 | + $ok = false; |
|
| 1089 | + } |
|
| 1090 | + break; |
|
| 1091 | + case 'base64': |
|
| 1092 | + case 'string': |
|
| 1093 | + if (!is_string($arg)) { |
|
| 1094 | + $ok = false; |
|
| 1095 | + } |
|
| 1096 | + break; |
|
| 1097 | + case 'boolean': |
|
| 1098 | + if ($arg !== false && $arg !== true) { |
|
| 1099 | + $ok = false; |
|
| 1100 | + } |
|
| 1101 | + break; |
|
| 1102 | + case 'float': |
|
| 1103 | + case 'double': |
|
| 1104 | + if (!is_float($arg)) { |
|
| 1105 | + $ok = false; |
|
| 1106 | + } |
|
| 1107 | + break; |
|
| 1108 | + case 'date': |
|
| 1109 | + case 'dateTime.iso8601': |
|
| 1110 | + if (!is_a($arg, 'IXR_Date')) { |
|
| 1111 | + $ok = false; |
|
| 1112 | + } |
|
| 1113 | + break; |
|
| 1114 | + } |
|
| 1115 | + if (!$ok) { |
|
| 1116 | + return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
| 1117 | + } |
|
| 1118 | + } |
|
| 1119 | + // It passed the test - run the "real" method call |
|
| 1120 | + return parent::call($methodname, $argsbackup); |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + function methodSignature($method) |
|
| 1124 | + { |
|
| 1125 | + if (!$this->hasMethod($method)) { |
|
| 1126 | + return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); |
|
| 1127 | + } |
|
| 1128 | + // We should be returning an array of types |
|
| 1129 | + $types = $this->signatures[$method]; |
|
| 1130 | + $return = array(); |
|
| 1131 | + foreach ($types as $type) { |
|
| 1132 | + switch ($type) { |
|
| 1133 | + case 'string': |
|
| 1134 | + $return[] = 'string'; |
|
| 1135 | + break; |
|
| 1136 | + case 'int': |
|
| 1137 | + case 'i4': |
|
| 1138 | + $return[] = 42; |
|
| 1139 | + break; |
|
| 1140 | + case 'double': |
|
| 1141 | + $return[] = 3.1415; |
|
| 1142 | + break; |
|
| 1143 | + case 'dateTime.iso8601': |
|
| 1144 | + $return[] = new IXR_Date(time()); |
|
| 1145 | + break; |
|
| 1146 | + case 'boolean': |
|
| 1147 | + $return[] = true; |
|
| 1148 | + break; |
|
| 1149 | + case 'base64': |
|
| 1150 | + $return[] = new IXR_Base64('base64'); |
|
| 1151 | + break; |
|
| 1152 | + case 'array': |
|
| 1153 | + $return[] = array('array'); |
|
| 1154 | + break; |
|
| 1155 | + case 'struct': |
|
| 1156 | + $return[] = array('struct' => 'struct'); |
|
| 1157 | + break; |
|
| 1158 | + } |
|
| 1159 | + } |
|
| 1160 | + return $return; |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + function methodHelp($method) |
|
| 1164 | + { |
|
| 1165 | + return $this->help[$method]; |
|
| 1166 | + } |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | /** |
@@ -1174,16 +1174,16 @@ discard block |
||
| 1174 | 1174 | */ |
| 1175 | 1175 | class IXR_ClientMulticall extends IXR_Client |
| 1176 | 1176 | { |
| 1177 | - var $calls = array(); |
|
| 1177 | + var $calls = array(); |
|
| 1178 | 1178 | |
| 1179 | 1179 | /** |
| 1180 | 1180 | * PHP5 constructor. |
| 1181 | 1181 | */ |
| 1182 | - function __construct( $server, $path = false, $port = 80 ) |
|
| 1183 | - { |
|
| 1184 | - parent::IXR_Client($server, $path, $port); |
|
| 1185 | - $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
| 1186 | - } |
|
| 1182 | + function __construct( $server, $path = false, $port = 80 ) |
|
| 1183 | + { |
|
| 1184 | + parent::IXR_Client($server, $path, $port); |
|
| 1185 | + $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
| 1186 | + } |
|
| 1187 | 1187 | |
| 1188 | 1188 | /** |
| 1189 | 1189 | * PHP4 constructor. |
@@ -1192,20 +1192,20 @@ discard block |
||
| 1192 | 1192 | self::__construct( $server, $path, $port ); |
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | - function addCall() |
|
| 1196 | - { |
|
| 1197 | - $args = func_get_args(); |
|
| 1198 | - $methodName = array_shift($args); |
|
| 1199 | - $struct = array( |
|
| 1200 | - 'methodName' => $methodName, |
|
| 1201 | - 'params' => $args |
|
| 1202 | - ); |
|
| 1203 | - $this->calls[] = $struct; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - function query() |
|
| 1207 | - { |
|
| 1208 | - // Prepare multicall, then call the parent::query() method |
|
| 1209 | - return parent::query('system.multicall', $this->calls); |
|
| 1210 | - } |
|
| 1195 | + function addCall() |
|
| 1196 | + { |
|
| 1197 | + $args = func_get_args(); |
|
| 1198 | + $methodName = array_shift($args); |
|
| 1199 | + $struct = array( |
|
| 1200 | + 'methodName' => $methodName, |
|
| 1201 | + 'params' => $args |
|
| 1202 | + ); |
|
| 1203 | + $this->calls[] = $struct; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + function query() |
|
| 1207 | + { |
|
| 1208 | + // Prepare multicall, then call the parent::query() method |
|
| 1209 | + return parent::query('system.multicall', $this->calls); |
|
| 1210 | + } |
|
| 1211 | 1211 | } |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * PHP5 constructor. |
| 54 | 54 | */ |
| 55 | - function __construct( $data, $type = false ) |
|
| 55 | + function __construct($data, $type = false) |
|
| 56 | 56 | { |
| 57 | 57 | $this->data = $data; |
| 58 | - if (!$type) { |
|
| 58 | + if ( ! $type) { |
|
| 59 | 59 | $type = $this->calculateType(); |
| 60 | 60 | } |
| 61 | 61 | $this->type = $type; |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | /** |
| 76 | 76 | * PHP4 constructor. |
| 77 | 77 | */ |
| 78 | - public function IXR_Value( $data, $type = false ) { |
|
| 79 | - self::__construct( $data, $type ); |
|
| 78 | + public function IXR_Value($data, $type = false) { |
|
| 79 | + self::__construct($data, $type); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | function calculateType() |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $this->data = get_object_vars($this->data); |
| 105 | 105 | return 'struct'; |
| 106 | 106 | } |
| 107 | - if (!is_array($this->data)) { |
|
| 107 | + if ( ! is_array($this->data)) { |
|
| 108 | 108 | return 'string'; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | { |
| 169 | 169 | $expected = 0; |
| 170 | 170 | foreach ($array as $key => $value) { |
| 171 | - if ((string)$key != (string)$expected) { |
|
| 171 | + if ((string) $key != (string) $expected) { |
|
| 172 | 172 | return true; |
| 173 | 173 | } |
| 174 | 174 | $expected++; |
@@ -187,16 +187,16 @@ discard block |
||
| 187 | 187 | class IXR_Message |
| 188 | 188 | { |
| 189 | 189 | var $message; |
| 190 | - var $messageType; // methodCall / methodResponse / fault |
|
| 190 | + var $messageType; // methodCall / methodResponse / fault |
|
| 191 | 191 | var $faultCode; |
| 192 | 192 | var $faultString; |
| 193 | 193 | var $methodName; |
| 194 | 194 | var $params; |
| 195 | 195 | |
| 196 | 196 | // Current variable stacks |
| 197 | - var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 197 | + var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 198 | 198 | var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
| 199 | - var $_currentStructName = array(); // A stack as well |
|
| 199 | + var $_currentStructName = array(); // A stack as well |
|
| 200 | 200 | var $_param; |
| 201 | 201 | var $_value; |
| 202 | 202 | var $_currentTag; |
@@ -207,47 +207,47 @@ discard block |
||
| 207 | 207 | /** |
| 208 | 208 | * PHP5 constructor. |
| 209 | 209 | */ |
| 210 | - function __construct( $message ) |
|
| 210 | + function __construct($message) |
|
| 211 | 211 | { |
| 212 | - $this->message =& $message; |
|
| 212 | + $this->message = & $message; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | 216 | * PHP4 constructor. |
| 217 | 217 | */ |
| 218 | - public function IXR_Message( $message ) { |
|
| 219 | - self::__construct( $message ); |
|
| 218 | + public function IXR_Message($message) { |
|
| 219 | + self::__construct($message); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | function parse() |
| 223 | 223 | { |
| 224 | 224 | // first remove the XML declaration |
| 225 | 225 | // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
| 226 | - $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); |
|
| 227 | - $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) ); |
|
| 228 | - if ( '' == $this->message ) { |
|
| 226 | + $header = preg_replace('/<\?xml.*?\?'.'>/s', '', substr($this->message, 0, 100), 1); |
|
| 227 | + $this->message = trim(substr_replace($this->message, $header, 0, 100)); |
|
| 228 | + if ('' == $this->message) { |
|
| 229 | 229 | return false; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // Then remove the DOCTYPE |
| 233 | - $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 ); |
|
| 234 | - $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) ); |
|
| 235 | - if ( '' == $this->message ) { |
|
| 233 | + $header = preg_replace('/^<!DOCTYPE[^>]*+>/i', '', substr($this->message, 0, 200), 1); |
|
| 234 | + $this->message = trim(substr_replace($this->message, $header, 0, 200)); |
|
| 235 | + if ('' == $this->message) { |
|
| 236 | 236 | return false; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // Check that the root tag is valid |
| 240 | - $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) ); |
|
| 241 | - if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) { |
|
| 240 | + $root_tag = substr($this->message, 0, strcspn(substr($this->message, 0, 20), "> \t\r\n")); |
|
| 241 | + if ('<!DOCTYPE' === strtoupper($root_tag)) { |
|
| 242 | 242 | return false; |
| 243 | 243 | } |
| 244 | - if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) { |
|
| 244 | + if ( ! in_array($root_tag, array('<methodCall', '<methodResponse', '<fault'))) { |
|
| 245 | 245 | return false; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Bail if there are too many elements to parse |
| 249 | 249 | $element_limit = 30000; |
| 250 | - if ( function_exists( 'apply_filters' ) ) { |
|
| 250 | + if (function_exists('apply_filters')) { |
|
| 251 | 251 | /** |
| 252 | 252 | * Filter the number of elements to parse in an XML-RPC response. |
| 253 | 253 | * |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * |
| 256 | 256 | * @param int $element_limit Default elements limit. |
| 257 | 257 | */ |
| 258 | - $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit ); |
|
| 258 | + $element_limit = apply_filters('xmlrpc_element_limit', $element_limit); |
|
| 259 | 259 | } |
| 260 | - if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) { |
|
| 260 | + if ($element_limit && 2 * $element_limit < substr_count($this->message, '<')) { |
|
| 261 | 261 | return false; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | } |
| 277 | 277 | $part = substr($this->message, 0, $chunk_size); |
| 278 | 278 | $this->message = substr($this->message, $chunk_size); |
| 279 | - if (!xml_parse($this->_parser, $part, $final)) { |
|
| 279 | + if ( ! xml_parse($this->_parser, $part, $final)) { |
|
| 280 | 280 | return false; |
| 281 | 281 | } |
| 282 | 282 | if ($final) { |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | { |
| 298 | 298 | $this->_currentTagContents = ''; |
| 299 | 299 | $this->currentTag = $tag; |
| 300 | - switch($tag) { |
|
| 300 | + switch ($tag) { |
|
| 301 | 301 | case 'methodCall': |
| 302 | 302 | case 'methodResponse': |
| 303 | 303 | case 'fault': |
@@ -323,18 +323,18 @@ discard block |
||
| 323 | 323 | function tag_close($parser, $tag) |
| 324 | 324 | { |
| 325 | 325 | $valueFlag = false; |
| 326 | - switch($tag) { |
|
| 326 | + switch ($tag) { |
|
| 327 | 327 | case 'int': |
| 328 | 328 | case 'i4': |
| 329 | - $value = (int)trim($this->_currentTagContents); |
|
| 329 | + $value = (int) trim($this->_currentTagContents); |
|
| 330 | 330 | $valueFlag = true; |
| 331 | 331 | break; |
| 332 | 332 | case 'double': |
| 333 | - $value = (double)trim($this->_currentTagContents); |
|
| 333 | + $value = (double) trim($this->_currentTagContents); |
|
| 334 | 334 | $valueFlag = true; |
| 335 | 335 | break; |
| 336 | 336 | case 'string': |
| 337 | - $value = (string)trim($this->_currentTagContents); |
|
| 337 | + $value = (string) trim($this->_currentTagContents); |
|
| 338 | 338 | $valueFlag = true; |
| 339 | 339 | break; |
| 340 | 340 | case 'dateTime.iso8601': |
@@ -344,12 +344,12 @@ discard block |
||
| 344 | 344 | case 'value': |
| 345 | 345 | // "If no type is indicated, the type is string." |
| 346 | 346 | if (trim($this->_currentTagContents) != '') { |
| 347 | - $value = (string)$this->_currentTagContents; |
|
| 347 | + $value = (string) $this->_currentTagContents; |
|
| 348 | 348 | $valueFlag = true; |
| 349 | 349 | } |
| 350 | 350 | break; |
| 351 | 351 | case 'boolean': |
| 352 | - $value = (boolean)trim($this->_currentTagContents); |
|
| 352 | + $value = (boolean) trim($this->_currentTagContents); |
|
| 353 | 353 | $valueFlag = true; |
| 354 | 354 | break; |
| 355 | 355 | case 'base64': |
@@ -377,12 +377,12 @@ discard block |
||
| 377 | 377 | if ($valueFlag) { |
| 378 | 378 | if (count($this->_arraystructs) > 0) { |
| 379 | 379 | // Add value to struct or array |
| 380 | - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
| 380 | + if ($this->_arraystructstypes[count($this->_arraystructstypes) - 1] == 'struct') { |
|
| 381 | 381 | // Add to struct |
| 382 | - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
| 382 | + $this->_arraystructs[count($this->_arraystructs) - 1][$this->_currentStructName[count($this->_currentStructName) - 1]] = $value; |
|
| 383 | 383 | } else { |
| 384 | 384 | // Add to array |
| 385 | - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
| 385 | + $this->_arraystructs[count($this->_arraystructs) - 1][] = $value; |
|
| 386 | 386 | } |
| 387 | 387 | } else { |
| 388 | 388 | // Just add as a parameter |
@@ -409,14 +409,14 @@ discard block |
||
| 409 | 409 | /** |
| 410 | 410 | * PHP5 constructor. |
| 411 | 411 | */ |
| 412 | - function __construct( $callbacks = false, $data = false, $wait = false ) |
|
| 412 | + function __construct($callbacks = false, $data = false, $wait = false) |
|
| 413 | 413 | { |
| 414 | 414 | $this->setCapabilities(); |
| 415 | 415 | if ($callbacks) { |
| 416 | 416 | $this->callbacks = $callbacks; |
| 417 | 417 | } |
| 418 | 418 | $this->setCallbacks(); |
| 419 | - if (!$wait) { |
|
| 419 | + if ( ! $wait) { |
|
| 420 | 420 | $this->serve($data); |
| 421 | 421 | } |
| 422 | 422 | } |
@@ -424,17 +424,17 @@ discard block |
||
| 424 | 424 | /** |
| 425 | 425 | * PHP4 constructor. |
| 426 | 426 | */ |
| 427 | - public function IXR_Server( $callbacks = false, $data = false, $wait = false ) { |
|
| 428 | - self::__construct( $callbacks, $data, $wait ); |
|
| 427 | + public function IXR_Server($callbacks = false, $data = false, $wait = false) { |
|
| 428 | + self::__construct($callbacks, $data, $wait); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | function serve($data = false) |
| 432 | 432 | { |
| 433 | - if (!$data) { |
|
| 433 | + if ( ! $data) { |
|
| 434 | 434 | if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
| 435 | - if ( function_exists( 'status_header' ) ) { |
|
| 436 | - status_header( 405 ); // WP #20986 |
|
| 437 | - header( 'Allow: POST' ); |
|
| 435 | + if (function_exists('status_header')) { |
|
| 436 | + status_header(405); // WP #20986 |
|
| 437 | + header('Allow: POST'); |
|
| 438 | 438 | } |
| 439 | 439 | header('Content-Type: text/plain'); // merged from WP #9093 |
| 440 | 440 | die('XML-RPC server accepts POST requests only.'); |
@@ -445,11 +445,11 @@ discard block |
||
| 445 | 445 | // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
| 446 | 446 | $data = file_get_contents('php://input'); |
| 447 | 447 | } else { |
| 448 | - $data =& $HTTP_RAW_POST_DATA; |
|
| 448 | + $data = & $HTTP_RAW_POST_DATA; |
|
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | $this->message = new IXR_Message($data); |
| 452 | - if (!$this->message->parse()) { |
|
| 452 | + if ( ! $this->message->parse()) { |
|
| 453 | 453 | $this->error(-32700, 'parse error. not well formed'); |
| 454 | 454 | } |
| 455 | 455 | if ($this->message->messageType != 'methodCall') { |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | |
| 486 | 486 | function call($methodname, $args) |
| 487 | 487 | { |
| 488 | - if (!$this->hasMethod($methodname)) { |
|
| 488 | + if ( ! $this->hasMethod($methodname)) { |
|
| 489 | 489 | return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
| 490 | 490 | } |
| 491 | 491 | $method = $this->callbacks[$methodname]; |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | if (is_string($method) && substr($method, 0, 5) == 'this:') { |
| 501 | 501 | // It's a class method - check it exists |
| 502 | 502 | $method = substr($method, 5); |
| 503 | - if (!method_exists($this, $method)) { |
|
| 503 | + if ( ! method_exists($this, $method)) { |
|
| 504 | 504 | return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
| 505 | 505 | } |
| 506 | 506 | |
@@ -509,10 +509,10 @@ discard block |
||
| 509 | 509 | } else { |
| 510 | 510 | // It's a function - does it exist? |
| 511 | 511 | if (is_array($method)) { |
| 512 | - if (!is_callable(array($method[0], $method[1]))) { |
|
| 512 | + if ( ! is_callable(array($method[0], $method[1]))) { |
|
| 513 | 513 | return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
| 514 | 514 | } |
| 515 | - } else if (!function_exists($method)) { |
|
| 515 | + } else if ( ! function_exists($method)) { |
|
| 516 | 516 | return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
| 517 | 517 | } |
| 518 | 518 | |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | function error($error, $message = false) |
| 526 | 526 | { |
| 527 | 527 | // Accepts either an error object or an error code and message |
| 528 | - if ($message && !is_object($error)) { |
|
| 528 | + if ($message && ! is_object($error)) { |
|
| 529 | 529 | $error = new IXR_Error($error, $message); |
| 530 | 530 | } |
| 531 | 531 | $this->output($error->getXml()); |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | /** |
| 657 | 657 | * PHP4 constructor. |
| 658 | 658 | */ |
| 659 | - public function IXR_Request( $method, $args ) { |
|
| 660 | - self::__construct( $method, $args ); |
|
| 659 | + public function IXR_Request($method, $args) { |
|
| 660 | + self::__construct($method, $args); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | function getLength() |
@@ -696,9 +696,9 @@ discard block |
||
| 696 | 696 | /** |
| 697 | 697 | * PHP5 constructor. |
| 698 | 698 | */ |
| 699 | - function __construct( $server, $path = false, $port = 80, $timeout = 15 ) |
|
| 699 | + function __construct($server, $path = false, $port = 80, $timeout = 15) |
|
| 700 | 700 | { |
| 701 | - if (!$path) { |
|
| 701 | + if ( ! $path) { |
|
| 702 | 702 | // Assume we have been given a URL instead |
| 703 | 703 | $bits = parse_url($server); |
| 704 | 704 | $this->server = $bits['host']; |
@@ -706,12 +706,12 @@ discard block |
||
| 706 | 706 | $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
| 707 | 707 | |
| 708 | 708 | // Make absolutely sure we have a path |
| 709 | - if (!$this->path) { |
|
| 709 | + if ( ! $this->path) { |
|
| 710 | 710 | $this->path = '/'; |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - if ( ! empty( $bits['query'] ) ) { |
|
| 714 | - $this->path .= '?' . $bits['query']; |
|
| 713 | + if ( ! empty($bits['query'])) { |
|
| 714 | + $this->path .= '?'.$bits['query']; |
|
| 715 | 715 | } |
| 716 | 716 | } else { |
| 717 | 717 | $this->server = $server; |
@@ -725,8 +725,8 @@ discard block |
||
| 725 | 725 | /** |
| 726 | 726 | * PHP4 constructor. |
| 727 | 727 | */ |
| 728 | - public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) { |
|
| 729 | - self::__construct( $server, $path, $port, $timeout ); |
|
| 728 | + public function IXR_Client($server, $path = false, $port = 80, $timeout = 15) { |
|
| 729 | + self::__construct($server, $path, $port, $timeout); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | function query() |
@@ -737,15 +737,15 @@ discard block |
||
| 737 | 737 | $length = $request->getLength(); |
| 738 | 738 | $xml = $request->getXml(); |
| 739 | 739 | $r = "\r\n"; |
| 740 | - $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 740 | + $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 741 | 741 | |
| 742 | 742 | // Merged from WP #8145 - allow custom headers |
| 743 | 743 | $this->headers['Host'] = $this->server; |
| 744 | 744 | $this->headers['Content-Type'] = 'text/xml'; |
| 745 | 745 | $this->headers['User-Agent'] = $this->useragent; |
| 746 | - $this->headers['Content-Length']= $length; |
|
| 746 | + $this->headers['Content-Length'] = $length; |
|
| 747 | 747 | |
| 748 | - foreach( $this->headers as $header => $value ) { |
|
| 748 | + foreach ($this->headers as $header => $value) { |
|
| 749 | 749 | $request .= "{$header}: {$value}{$r}"; |
| 750 | 750 | } |
| 751 | 751 | $request .= $r; |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | } else { |
| 763 | 763 | $fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
| 764 | 764 | } |
| 765 | - if (!$fp) { |
|
| 765 | + if ( ! $fp) { |
|
| 766 | 766 | $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
| 767 | 767 | return false; |
| 768 | 768 | } |
@@ -771,9 +771,9 @@ discard block |
||
| 771 | 771 | $debugContents = ''; |
| 772 | 772 | $gotFirstLine = false; |
| 773 | 773 | $gettingHeaders = true; |
| 774 | - while (!feof($fp)) { |
|
| 774 | + while ( ! feof($fp)) { |
|
| 775 | 775 | $line = fgets($fp, 4096); |
| 776 | - if (!$gotFirstLine) { |
|
| 776 | + if ( ! $gotFirstLine) { |
|
| 777 | 777 | // Check line for '200' |
| 778 | 778 | if (strstr($line, '200') === false) { |
| 779 | 779 | $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | if (trim($line) == '') { |
| 785 | 785 | $gettingHeaders = false; |
| 786 | 786 | } |
| 787 | - if (!$gettingHeaders) { |
|
| 787 | + if ( ! $gettingHeaders) { |
|
| 788 | 788 | // merged from WP #12559 - remove trim |
| 789 | 789 | $contents .= $line; |
| 790 | 790 | } |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | |
| 799 | 799 | // Now parse what we've got back |
| 800 | 800 | $this->message = new IXR_Message($contents); |
| 801 | - if (!$this->message->parse()) { |
|
| 801 | + if ( ! $this->message->parse()) { |
|
| 802 | 802 | // XML error |
| 803 | 803 | $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
| 804 | 804 | return false; |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | /** |
| 852 | 852 | * PHP5 constructor. |
| 853 | 853 | */ |
| 854 | - function __construct( $code, $message ) |
|
| 854 | + function __construct($code, $message) |
|
| 855 | 855 | { |
| 856 | 856 | $this->code = $code; |
| 857 | 857 | $this->message = htmlspecialchars($message); |
@@ -860,8 +860,8 @@ discard block |
||
| 860 | 860 | /** |
| 861 | 861 | * PHP4 constructor. |
| 862 | 862 | */ |
| 863 | - public function IXR_Error( $code, $message ) { |
|
| 864 | - self::__construct( $code, $message ); |
|
| 863 | + public function IXR_Error($code, $message) { |
|
| 864 | + self::__construct($code, $message); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | function getXml() |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | /** |
| 908 | 908 | * PHP5 constructor. |
| 909 | 909 | */ |
| 910 | - function __construct( $time ) |
|
| 910 | + function __construct($time) |
|
| 911 | 911 | { |
| 912 | 912 | // $time can be a PHP timestamp or an ISO one |
| 913 | 913 | if (is_numeric($time)) { |
@@ -920,8 +920,8 @@ discard block |
||
| 920 | 920 | /** |
| 921 | 921 | * PHP4 constructor. |
| 922 | 922 | */ |
| 923 | - public function IXR_Date( $time ) { |
|
| 924 | - self::__construct( $time ); |
|
| 923 | + public function IXR_Date($time) { |
|
| 924 | + self::__construct($time); |
|
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | function parseTimestamp($timestamp) |
@@ -975,7 +975,7 @@ discard block |
||
| 975 | 975 | /** |
| 976 | 976 | * PHP5 constructor. |
| 977 | 977 | */ |
| 978 | - function __construct( $data ) |
|
| 978 | + function __construct($data) |
|
| 979 | 979 | { |
| 980 | 980 | $this->data = $data; |
| 981 | 981 | } |
@@ -983,8 +983,8 @@ discard block |
||
| 983 | 983 | /** |
| 984 | 984 | * PHP4 constructor. |
| 985 | 985 | */ |
| 986 | - public function IXR_Base64( $data ) { |
|
| 987 | - self::__construct( $data ); |
|
| 986 | + public function IXR_Base64($data) { |
|
| 987 | + self::__construct($data); |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | function getXml() |
@@ -1058,12 +1058,12 @@ discard block |
||
| 1058 | 1058 | function call($methodname, $args) |
| 1059 | 1059 | { |
| 1060 | 1060 | // Make sure it's in an array |
| 1061 | - if ($args && !is_array($args)) { |
|
| 1061 | + if ($args && ! is_array($args)) { |
|
| 1062 | 1062 | $args = array($args); |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | // Over-rides default call method, adds signature check |
| 1066 | - if (!$this->hasMethod($methodname)) { |
|
| 1066 | + if ( ! $this->hasMethod($methodname)) { |
|
| 1067 | 1067 | return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); |
| 1068 | 1068 | } |
| 1069 | 1069 | $method = $this->callbacks[$methodname]; |
@@ -1084,13 +1084,13 @@ discard block |
||
| 1084 | 1084 | switch ($type) { |
| 1085 | 1085 | case 'int': |
| 1086 | 1086 | case 'i4': |
| 1087 | - if (is_array($arg) || !is_int($arg)) { |
|
| 1087 | + if (is_array($arg) || ! is_int($arg)) { |
|
| 1088 | 1088 | $ok = false; |
| 1089 | 1089 | } |
| 1090 | 1090 | break; |
| 1091 | 1091 | case 'base64': |
| 1092 | 1092 | case 'string': |
| 1093 | - if (!is_string($arg)) { |
|
| 1093 | + if ( ! is_string($arg)) { |
|
| 1094 | 1094 | $ok = false; |
| 1095 | 1095 | } |
| 1096 | 1096 | break; |
@@ -1101,18 +1101,18 @@ discard block |
||
| 1101 | 1101 | break; |
| 1102 | 1102 | case 'float': |
| 1103 | 1103 | case 'double': |
| 1104 | - if (!is_float($arg)) { |
|
| 1104 | + if ( ! is_float($arg)) { |
|
| 1105 | 1105 | $ok = false; |
| 1106 | 1106 | } |
| 1107 | 1107 | break; |
| 1108 | 1108 | case 'date': |
| 1109 | 1109 | case 'dateTime.iso8601': |
| 1110 | - if (!is_a($arg, 'IXR_Date')) { |
|
| 1110 | + if ( ! is_a($arg, 'IXR_Date')) { |
|
| 1111 | 1111 | $ok = false; |
| 1112 | 1112 | } |
| 1113 | 1113 | break; |
| 1114 | 1114 | } |
| 1115 | - if (!$ok) { |
|
| 1115 | + if ( ! $ok) { |
|
| 1116 | 1116 | return new IXR_Error(-32602, 'server error. invalid method parameters'); |
| 1117 | 1117 | } |
| 1118 | 1118 | } |
@@ -1122,7 +1122,7 @@ discard block |
||
| 1122 | 1122 | |
| 1123 | 1123 | function methodSignature($method) |
| 1124 | 1124 | { |
| 1125 | - if (!$this->hasMethod($method)) { |
|
| 1125 | + if ( ! $this->hasMethod($method)) { |
|
| 1126 | 1126 | return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); |
| 1127 | 1127 | } |
| 1128 | 1128 | // We should be returning an array of types |
@@ -1179,7 +1179,7 @@ discard block |
||
| 1179 | 1179 | /** |
| 1180 | 1180 | * PHP5 constructor. |
| 1181 | 1181 | */ |
| 1182 | - function __construct( $server, $path = false, $port = 80 ) |
|
| 1182 | + function __construct($server, $path = false, $port = 80) |
|
| 1183 | 1183 | { |
| 1184 | 1184 | parent::IXR_Client($server, $path, $port); |
| 1185 | 1185 | $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
@@ -1188,8 +1188,8 @@ discard block |
||
| 1188 | 1188 | /** |
| 1189 | 1189 | * PHP4 constructor. |
| 1190 | 1190 | */ |
| 1191 | - public function IXR_ClientMulticall( $server, $path = false, $port = 80 ) { |
|
| 1192 | - self::__construct( $server, $path, $port ); |
|
| 1191 | + public function IXR_ClientMulticall($server, $path = false, $port = 80) { |
|
| 1192 | + self::__construct($server, $path, $port); |
|
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | 1195 | function addCall() |
@@ -534,17 +534,19 @@ |
||
| 534 | 534 | function output($xml) |
| 535 | 535 | { |
| 536 | 536 | $charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
| 537 | - if ($charset) |
|
| 538 | - $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
| 539 | - else |
|
| 540 | - $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
| 537 | + if ($charset) { |
|
| 538 | + $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
| 539 | + } else { |
|
| 540 | + $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
| 541 | + } |
|
| 541 | 542 | $length = strlen($xml); |
| 542 | 543 | header('Connection: close'); |
| 543 | 544 | header('Content-Length: '.$length); |
| 544 | - if ($charset) |
|
| 545 | - header('Content-Type: text/xml; charset='.$charset); |
|
| 546 | - else |
|
| 547 | - header('Content-Type: text/xml'); |
|
| 545 | + if ($charset) { |
|
| 546 | + header('Content-Type: text/xml; charset='.$charset); |
|
| 547 | + } else { |
|
| 548 | + header('Content-Type: text/xml'); |
|
| 549 | + } |
|
| 548 | 550 | header('Date: '.date('r')); |
| 549 | 551 | echo $xml; |
| 550 | 552 | exit; |
@@ -62,6 +62,9 @@ discard block |
||
| 62 | 62 | self::__construct( $iteration_count_log2, $portable_hashes ); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | + /** |
|
| 66 | + * @param integer $count |
|
| 67 | + */ |
|
| 65 | 68 | function get_random_bytes($count) |
| 66 | 69 | { |
| 67 | 70 | $output = ''; |
@@ -85,6 +88,9 @@ discard block |
||
| 85 | 88 | return $output; |
| 86 | 89 | } |
| 87 | 90 | |
| 91 | + /** |
|
| 92 | + * @param integer $count |
|
| 93 | + */ |
|
| 88 | 94 | function encode64($input, $count) |
| 89 | 95 | { |
| 90 | 96 | $output = ''; |
@@ -108,6 +114,9 @@ discard block |
||
| 108 | 114 | return $output; |
| 109 | 115 | } |
| 110 | 116 | |
| 117 | + /** |
|
| 118 | + * @param string $input |
|
| 119 | + */ |
|
| 111 | 120 | function gensalt_private($input) |
| 112 | 121 | { |
| 113 | 122 | $output = '$P$'; |
@@ -163,6 +172,9 @@ discard block |
||
| 163 | 172 | return $output; |
| 164 | 173 | } |
| 165 | 174 | |
| 175 | + /** |
|
| 176 | + * @param string $input |
|
| 177 | + */ |
|
| 166 | 178 | function gensalt_extended($input) |
| 167 | 179 | { |
| 168 | 180 | $count_log2 = min($this->iteration_count_log2 + 8, 24); |
@@ -181,6 +193,9 @@ discard block |
||
| 181 | 193 | return $output; |
| 182 | 194 | } |
| 183 | 195 | |
| 196 | + /** |
|
| 197 | + * @param string $input |
|
| 198 | + */ |
|
| 184 | 199 | function gensalt_blowfish($input) |
| 185 | 200 | { |
| 186 | 201 | # This one needs to use a different order of characters and a |
@@ -222,6 +237,9 @@ discard block |
||
| 222 | 237 | return $output; |
| 223 | 238 | } |
| 224 | 239 | |
| 240 | + /** |
|
| 241 | + * @param string $password |
|
| 242 | + */ |
|
| 225 | 243 | function HashPassword($password) |
| 226 | 244 | { |
| 227 | 245 | if ( strlen( $password ) > 4096 ) { |
@@ -1,11 +1,11 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Portable PHP password hashing framework. |
|
| 4 | - * @package phpass |
|
| 5 | - * @since 2.5.0 |
|
| 6 | - * @version 0.3 / WordPress |
|
| 7 | - * @link http://www.openwall.com/phpass/ |
|
| 8 | - */ |
|
| 3 | + * Portable PHP password hashing framework. |
|
| 4 | + * @package phpass |
|
| 5 | + * @since 2.5.0 |
|
| 6 | + * @version 0.3 / WordPress |
|
| 7 | + * @link http://www.openwall.com/phpass/ |
|
| 8 | + */ |
|
| 9 | 9 | |
| 10 | 10 | # |
| 11 | 11 | # Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | $output = ''; |
| 68 | 68 | if ( @is_readable('/dev/urandom') && |
| 69 | - ($fh = @fopen('/dev/urandom', 'rb'))) { |
|
| 69 | + ($fh = @fopen('/dev/urandom', 'rb'))) { |
|
| 70 | 70 | $output = fread($fh, $count); |
| 71 | 71 | fclose($fh); |
| 72 | 72 | } |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | $output = ''; |
| 76 | 76 | for ($i = 0; $i < $count; $i += 16) { |
| 77 | 77 | $this->random_state = |
| 78 | - md5(microtime() . $this->random_state); |
|
| 78 | + md5(microtime() . $this->random_state); |
|
| 79 | 79 | $output .= |
| 80 | - pack('H*', md5($this->random_state)); |
|
| 80 | + pack('H*', md5($this->random_state)); |
|
| 81 | 81 | } |
| 82 | 82 | $output = substr($output, 0, $count); |
| 83 | 83 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) { |
| 234 | 234 | $random = $this->get_random_bytes(16); |
| 235 | 235 | $hash = |
| 236 | - crypt($password, $this->gensalt_blowfish($random)); |
|
| 236 | + crypt($password, $this->gensalt_blowfish($random)); |
|
| 237 | 237 | if (strlen($hash) == 60) |
| 238 | 238 | return $hash; |
| 239 | 239 | } |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | if (strlen($random) < 3) |
| 243 | 243 | $random = $this->get_random_bytes(3); |
| 244 | 244 | $hash = |
| 245 | - crypt($password, $this->gensalt_extended($random)); |
|
| 245 | + crypt($password, $this->gensalt_extended($random)); |
|
| 246 | 246 | if (strlen($hash) == 20) |
| 247 | 247 | return $hash; |
| 248 | 248 | } |
@@ -250,8 +250,8 @@ discard block |
||
| 250 | 250 | if (strlen($random) < 6) |
| 251 | 251 | $random = $this->get_random_bytes(6); |
| 252 | 252 | $hash = |
| 253 | - $this->crypt_private($password, |
|
| 254 | - $this->gensalt_private($random)); |
|
| 253 | + $this->crypt_private($password, |
|
| 254 | + $this->gensalt_private($random)); |
|
| 255 | 255 | if (strlen($hash) == 34) |
| 256 | 256 | return $hash; |
| 257 | 257 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | /** |
| 43 | 43 | * PHP5 constructor. |
| 44 | 44 | */ |
| 45 | - function __construct( $iteration_count_log2, $portable_hashes ) |
|
| 45 | + function __construct($iteration_count_log2, $portable_hashes) |
|
| 46 | 46 | { |
| 47 | 47 | $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
| 48 | 48 | |
@@ -52,20 +52,20 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $this->portable_hashes = $portable_hashes; |
| 54 | 54 | |
| 55 | - $this->random_state = microtime() . uniqid(rand(), TRUE); // removed getmypid() for compatibility reasons |
|
| 55 | + $this->random_state = microtime().uniqid(rand(), TRUE); // removed getmypid() for compatibility reasons |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * PHP4 constructor. |
| 60 | 60 | */ |
| 61 | - public function PasswordHash( $iteration_count_log2, $portable_hashes ) { |
|
| 62 | - self::__construct( $iteration_count_log2, $portable_hashes ); |
|
| 61 | + public function PasswordHash($iteration_count_log2, $portable_hashes) { |
|
| 62 | + self::__construct($iteration_count_log2, $portable_hashes); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function get_random_bytes($count) |
| 66 | 66 | { |
| 67 | 67 | $output = ''; |
| 68 | - if ( @is_readable('/dev/urandom') && |
|
| 68 | + if (@is_readable('/dev/urandom') && |
|
| 69 | 69 | ($fh = @fopen('/dev/urandom', 'rb'))) { |
| 70 | 70 | $output = fread($fh, $count); |
| 71 | 71 | fclose($fh); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $output = ''; |
| 76 | 76 | for ($i = 0; $i < $count; $i += 16) { |
| 77 | 77 | $this->random_state = |
| 78 | - md5(microtime() . $this->random_state); |
|
| 78 | + md5(microtime().$this->random_state); |
|
| 79 | 79 | $output .= |
| 80 | 80 | pack('H*', md5($this->random_state)); |
| 81 | 81 | } |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | # consequently in lower iteration counts and hashes that are |
| 147 | 147 | # quicker to crack (by non-PHP code). |
| 148 | 148 | if (PHP_VERSION >= '5') { |
| 149 | - $hash = md5($salt . $password, TRUE); |
|
| 149 | + $hash = md5($salt.$password, TRUE); |
|
| 150 | 150 | do { |
| 151 | - $hash = md5($hash . $password, TRUE); |
|
| 151 | + $hash = md5($hash.$password, TRUE); |
|
| 152 | 152 | } while (--$count); |
| 153 | 153 | } else { |
| 154 | - $hash = pack('H*', md5($salt . $password)); |
|
| 154 | + $hash = pack('H*', md5($salt.$password)); |
|
| 155 | 155 | do { |
| 156 | - $hash = pack('H*', md5($hash . $password)); |
|
| 156 | + $hash = pack('H*', md5($hash.$password)); |
|
| 157 | 157 | } while (--$count); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -224,13 +224,13 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | function HashPassword($password) |
| 226 | 226 | { |
| 227 | - if ( strlen( $password ) > 4096 ) { |
|
| 227 | + if (strlen($password) > 4096) { |
|
| 228 | 228 | return '*'; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $random = ''; |
| 232 | 232 | |
| 233 | - if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) { |
|
| 233 | + if (CRYPT_BLOWFISH == 1 && ! $this->portable_hashes) { |
|
| 234 | 234 | $random = $this->get_random_bytes(16); |
| 235 | 235 | $hash = |
| 236 | 236 | crypt($password, $this->gensalt_blowfish($random)); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | return $hash; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) { |
|
| 241 | + if (CRYPT_EXT_DES == 1 && ! $this->portable_hashes) { |
|
| 242 | 242 | if (strlen($random) < 3) |
| 243 | 243 | $random = $this->get_random_bytes(3); |
| 244 | 244 | $hash = |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | function CheckPassword($password, $stored_hash) |
| 265 | 265 | { |
| 266 | - if ( strlen( $password ) > 4096 ) { |
|
| 266 | + if (strlen($password) > 4096) { |
|
| 267 | 267 | return false; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -46,8 +46,9 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
| 48 | 48 | |
| 49 | - if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) |
|
| 50 | - $iteration_count_log2 = 8; |
|
| 49 | + if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) { |
|
| 50 | + $iteration_count_log2 = 8; |
|
| 51 | + } |
|
| 51 | 52 | $this->iteration_count_log2 = $iteration_count_log2; |
| 52 | 53 | |
| 53 | 54 | $this->portable_hashes = $portable_hashes; |
@@ -92,16 +93,20 @@ discard block |
||
| 92 | 93 | do { |
| 93 | 94 | $value = ord($input[$i++]); |
| 94 | 95 | $output .= $this->itoa64[$value & 0x3f]; |
| 95 | - if ($i < $count) |
|
| 96 | - $value |= ord($input[$i]) << 8; |
|
| 96 | + if ($i < $count) { |
|
| 97 | + $value |= ord($input[$i]) << 8; |
|
| 98 | + } |
|
| 97 | 99 | $output .= $this->itoa64[($value >> 6) & 0x3f]; |
| 98 | - if ($i++ >= $count) |
|
| 99 | - break; |
|
| 100 | - if ($i < $count) |
|
| 101 | - $value |= ord($input[$i]) << 16; |
|
| 100 | + if ($i++ >= $count) { |
|
| 101 | + break; |
|
| 102 | + } |
|
| 103 | + if ($i < $count) { |
|
| 104 | + $value |= ord($input[$i]) << 16; |
|
| 105 | + } |
|
| 102 | 106 | $output .= $this->itoa64[($value >> 12) & 0x3f]; |
| 103 | - if ($i++ >= $count) |
|
| 104 | - break; |
|
| 107 | + if ($i++ >= $count) { |
|
| 108 | + break; |
|
| 109 | + } |
|
| 105 | 110 | $output .= $this->itoa64[($value >> 18) & 0x3f]; |
| 106 | 111 | } while ($i < $count); |
| 107 | 112 | |
@@ -121,23 +126,27 @@ discard block |
||
| 121 | 126 | function crypt_private($password, $setting) |
| 122 | 127 | { |
| 123 | 128 | $output = '*0'; |
| 124 | - if (substr($setting, 0, 2) == $output) |
|
| 125 | - $output = '*1'; |
|
| 129 | + if (substr($setting, 0, 2) == $output) { |
|
| 130 | + $output = '*1'; |
|
| 131 | + } |
|
| 126 | 132 | |
| 127 | 133 | $id = substr($setting, 0, 3); |
| 128 | 134 | # We use "$P$", phpBB3 uses "$H$" for the same thing |
| 129 | - if ($id != '$P$' && $id != '$H$') |
|
| 130 | - return $output; |
|
| 135 | + if ($id != '$P$' && $id != '$H$') { |
|
| 136 | + return $output; |
|
| 137 | + } |
|
| 131 | 138 | |
| 132 | 139 | $count_log2 = strpos($this->itoa64, $setting[3]); |
| 133 | - if ($count_log2 < 7 || $count_log2 > 30) |
|
| 134 | - return $output; |
|
| 140 | + if ($count_log2 < 7 || $count_log2 > 30) { |
|
| 141 | + return $output; |
|
| 142 | + } |
|
| 135 | 143 | |
| 136 | 144 | $count = 1 << $count_log2; |
| 137 | 145 | |
| 138 | 146 | $salt = substr($setting, 4, 8); |
| 139 | - if (strlen($salt) != 8) |
|
| 140 | - return $output; |
|
| 147 | + if (strlen($salt) != 8) { |
|
| 148 | + return $output; |
|
| 149 | + } |
|
| 141 | 150 | |
| 142 | 151 | # We're kind of forced to use MD5 here since it's the only |
| 143 | 152 | # cryptographic primitive available in all versions of PHP |
@@ -234,26 +243,31 @@ discard block |
||
| 234 | 243 | $random = $this->get_random_bytes(16); |
| 235 | 244 | $hash = |
| 236 | 245 | crypt($password, $this->gensalt_blowfish($random)); |
| 237 | - if (strlen($hash) == 60) |
|
| 238 | - return $hash; |
|
| 246 | + if (strlen($hash) == 60) { |
|
| 247 | + return $hash; |
|
| 248 | + } |
|
| 239 | 249 | } |
| 240 | 250 | |
| 241 | 251 | if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) { |
| 242 | - if (strlen($random) < 3) |
|
| 243 | - $random = $this->get_random_bytes(3); |
|
| 252 | + if (strlen($random) < 3) { |
|
| 253 | + $random = $this->get_random_bytes(3); |
|
| 254 | + } |
|
| 244 | 255 | $hash = |
| 245 | 256 | crypt($password, $this->gensalt_extended($random)); |
| 246 | - if (strlen($hash) == 20) |
|
| 247 | - return $hash; |
|
| 257 | + if (strlen($hash) == 20) { |
|
| 258 | + return $hash; |
|
| 259 | + } |
|
| 248 | 260 | } |
| 249 | 261 | |
| 250 | - if (strlen($random) < 6) |
|
| 251 | - $random = $this->get_random_bytes(6); |
|
| 262 | + if (strlen($random) < 6) { |
|
| 263 | + $random = $this->get_random_bytes(6); |
|
| 264 | + } |
|
| 252 | 265 | $hash = |
| 253 | 266 | $this->crypt_private($password, |
| 254 | 267 | $this->gensalt_private($random)); |
| 255 | - if (strlen($hash) == 34) |
|
| 256 | - return $hash; |
|
| 268 | + if (strlen($hash) == 34) { |
|
| 269 | + return $hash; |
|
| 270 | + } |
|
| 257 | 271 | |
| 258 | 272 | # Returning '*' on error is safe here, but would _not_ be safe |
| 259 | 273 | # in a crypt(3)-like function used _both_ for generating new |
@@ -268,8 +282,9 @@ discard block |
||
| 268 | 282 | } |
| 269 | 283 | |
| 270 | 284 | $hash = $this->crypt_private($password, $stored_hash); |
| 271 | - if ($hash[0] == '*') |
|
| 272 | - $hash = crypt($password, $stored_hash); |
|
| 285 | + if ($hash[0] == '*') { |
|
| 286 | + $hash = crypt($password, $stored_hash); |
|
| 287 | + } |
|
| 273 | 288 | |
| 274 | 289 | return $hash === $stored_hash; |
| 275 | 290 | } |
@@ -626,6 +626,9 @@ |
||
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | + /** |
|
| 630 | + * @param string $server_text |
|
| 631 | + */ |
|
| 629 | 632 | function parse_banner ( $server_text ) { |
| 630 | 633 | $outside = true; |
| 631 | 634 | $banner = ""; |
@@ -17,53 +17,53 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | class POP3 { |
| 20 | - var $ERROR = ''; // Error string. |
|
| 20 | + var $ERROR = ''; // Error string. |
|
| 21 | 21 | |
| 22 | - var $TIMEOUT = 60; // Default timeout before giving up on a |
|
| 23 | - // network operation. |
|
| 22 | + var $TIMEOUT = 60; // Default timeout before giving up on a |
|
| 23 | + // network operation. |
|
| 24 | 24 | |
| 25 | - var $COUNT = -1; // Mailbox msg count |
|
| 25 | + var $COUNT = -1; // Mailbox msg count |
|
| 26 | 26 | |
| 27 | - var $BUFFER = 512; // Socket buffer for socket fgets() calls. |
|
| 28 | - // Per RFC 1939 the returned line a POP3 |
|
| 29 | - // server can send is 512 bytes. |
|
| 27 | + var $BUFFER = 512; // Socket buffer for socket fgets() calls. |
|
| 28 | + // Per RFC 1939 the returned line a POP3 |
|
| 29 | + // server can send is 512 bytes. |
|
| 30 | 30 | |
| 31 | - var $FP = ''; // The connection to the server's |
|
| 32 | - // file descriptor |
|
| 31 | + var $FP = ''; // The connection to the server's |
|
| 32 | + // file descriptor |
|
| 33 | 33 | |
| 34 | - var $MAILSERVER = ''; // Set this to hard code the server name |
|
| 34 | + var $MAILSERVER = ''; // Set this to hard code the server name |
|
| 35 | 35 | |
| 36 | - var $DEBUG = FALSE; // set to true to echo pop3 |
|
| 37 | - // commands and responses to error_log |
|
| 38 | - // this WILL log passwords! |
|
| 36 | + var $DEBUG = FALSE; // set to true to echo pop3 |
|
| 37 | + // commands and responses to error_log |
|
| 38 | + // this WILL log passwords! |
|
| 39 | 39 | |
| 40 | - var $BANNER = ''; // Holds the banner returned by the |
|
| 41 | - // pop server - used for apop() |
|
| 40 | + var $BANNER = ''; // Holds the banner returned by the |
|
| 41 | + // pop server - used for apop() |
|
| 42 | 42 | |
| 43 | - var $ALLOWAPOP = FALSE; // Allow or disallow apop() |
|
| 44 | - // This must be set to true |
|
| 45 | - // manually |
|
| 43 | + var $ALLOWAPOP = FALSE; // Allow or disallow apop() |
|
| 44 | + // This must be set to true |
|
| 45 | + // manually |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * PHP5 constructor. |
| 49 | 49 | */ |
| 50 | - function __construct ( $server = '', $timeout = '' ) { |
|
| 51 | - settype($this->BUFFER,"integer"); |
|
| 52 | - if( !empty($server) ) { |
|
| 53 | - // Do not allow programs to alter MAILSERVER |
|
| 54 | - // if it is already specified. They can get around |
|
| 55 | - // this if they -really- want to, so don't count on it. |
|
| 56 | - if(empty($this->MAILSERVER)) |
|
| 57 | - $this->MAILSERVER = $server; |
|
| 58 | - } |
|
| 59 | - if(!empty($timeout)) { |
|
| 60 | - settype($timeout,"integer"); |
|
| 61 | - $this->TIMEOUT = $timeout; |
|
| 62 | - if (!ini_get('safe_mode')) |
|
| 63 | - set_time_limit($timeout); |
|
| 64 | - } |
|
| 65 | - return true; |
|
| 66 | - } |
|
| 50 | + function __construct ( $server = '', $timeout = '' ) { |
|
| 51 | + settype($this->BUFFER,"integer"); |
|
| 52 | + if( !empty($server) ) { |
|
| 53 | + // Do not allow programs to alter MAILSERVER |
|
| 54 | + // if it is already specified. They can get around |
|
| 55 | + // this if they -really- want to, so don't count on it. |
|
| 56 | + if(empty($this->MAILSERVER)) |
|
| 57 | + $this->MAILSERVER = $server; |
|
| 58 | + } |
|
| 59 | + if(!empty($timeout)) { |
|
| 60 | + settype($timeout,"integer"); |
|
| 61 | + $this->TIMEOUT = $timeout; |
|
| 62 | + if (!ini_get('safe_mode')) |
|
| 63 | + set_time_limit($timeout); |
|
| 64 | + } |
|
| 65 | + return true; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * PHP4 constructor. |
@@ -72,591 +72,591 @@ discard block |
||
| 72 | 72 | self::__construct( $server, $timeout ); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - function update_timer () { |
|
| 76 | - if (!ini_get('safe_mode')) |
|
| 77 | - set_time_limit($this->TIMEOUT); |
|
| 78 | - return true; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - function connect ($server, $port = 110) { |
|
| 82 | - // Opens a socket to the specified server. Unless overridden, |
|
| 83 | - // port defaults to 110. Returns true on success, false on fail |
|
| 84 | - |
|
| 85 | - // If MAILSERVER is set, override $server with it's value |
|
| 86 | - |
|
| 87 | - if (!isset($port) || !$port) {$port = 110;} |
|
| 88 | - if(!empty($this->MAILSERVER)) |
|
| 89 | - $server = $this->MAILSERVER; |
|
| 90 | - |
|
| 91 | - if(empty($server)){ |
|
| 92 | - $this->ERROR = "POP3 connect: " . _("No server specified"); |
|
| 93 | - unset($this->FP); |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $fp = @fsockopen("$server", $port, $errno, $errstr); |
|
| 98 | - |
|
| 99 | - if(!$fp) { |
|
| 100 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]"; |
|
| 101 | - unset($this->FP); |
|
| 102 | - return false; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - socket_set_blocking($fp,-1); |
|
| 106 | - $this->update_timer(); |
|
| 107 | - $reply = fgets($fp,$this->BUFFER); |
|
| 108 | - $reply = $this->strip_clf($reply); |
|
| 109 | - if($this->DEBUG) |
|
| 110 | - error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 111 | - if(!$this->is_ok($reply)) { |
|
| 112 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]"; |
|
| 113 | - unset($this->FP); |
|
| 114 | - return false; |
|
| 115 | - } |
|
| 116 | - $this->FP = $fp; |
|
| 117 | - $this->BANNER = $this->parse_banner($reply); |
|
| 118 | - return true; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - function user ($user = "") { |
|
| 122 | - // Sends the USER command, returns true or false |
|
| 123 | - |
|
| 124 | - if( empty($user) ) { |
|
| 125 | - $this->ERROR = "POP3 user: " . _("no login ID submitted"); |
|
| 126 | - return false; |
|
| 127 | - } elseif(!isset($this->FP)) { |
|
| 128 | - $this->ERROR = "POP3 user: " . _("connection not established"); |
|
| 129 | - return false; |
|
| 130 | - } else { |
|
| 131 | - $reply = $this->send_cmd("USER $user"); |
|
| 132 | - if(!$this->is_ok($reply)) { |
|
| 133 | - $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]"; |
|
| 134 | - return false; |
|
| 135 | - } else |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - function pass ($pass = "") { |
|
| 141 | - // Sends the PASS command, returns # of msgs in mailbox, |
|
| 142 | - // returns false (undef) on Auth failure |
|
| 143 | - |
|
| 144 | - if(empty($pass)) { |
|
| 145 | - $this->ERROR = "POP3 pass: " . _("No password submitted"); |
|
| 146 | - return false; |
|
| 147 | - } elseif(!isset($this->FP)) { |
|
| 148 | - $this->ERROR = "POP3 pass: " . _("connection not established"); |
|
| 149 | - return false; |
|
| 150 | - } else { |
|
| 151 | - $reply = $this->send_cmd("PASS $pass"); |
|
| 152 | - if(!$this->is_ok($reply)) { |
|
| 153 | - $this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]"; |
|
| 154 | - $this->quit(); |
|
| 155 | - return false; |
|
| 156 | - } else { |
|
| 157 | - // Auth successful. |
|
| 158 | - $count = $this->last("count"); |
|
| 159 | - $this->COUNT = $count; |
|
| 160 | - return $count; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - function apop ($login,$pass) { |
|
| 166 | - // Attempts an APOP login. If this fails, it'll |
|
| 167 | - // try a standard login. YOUR SERVER MUST SUPPORT |
|
| 168 | - // THE USE OF THE APOP COMMAND! |
|
| 169 | - // (apop is optional per rfc1939) |
|
| 170 | - |
|
| 171 | - if(!isset($this->FP)) { |
|
| 172 | - $this->ERROR = "POP3 apop: " . _("No connection to server"); |
|
| 173 | - return false; |
|
| 174 | - } elseif(!$this->ALLOWAPOP) { |
|
| 175 | - $retVal = $this->login($login,$pass); |
|
| 176 | - return $retVal; |
|
| 177 | - } elseif(empty($login)) { |
|
| 178 | - $this->ERROR = "POP3 apop: " . _("No login ID submitted"); |
|
| 179 | - return false; |
|
| 180 | - } elseif(empty($pass)) { |
|
| 181 | - $this->ERROR = "POP3 apop: " . _("No password submitted"); |
|
| 182 | - return false; |
|
| 183 | - } else { |
|
| 184 | - $banner = $this->BANNER; |
|
| 185 | - if( (!$banner) or (empty($banner)) ) { |
|
| 186 | - $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort"); |
|
| 187 | - $retVal = $this->login($login,$pass); |
|
| 188 | - return $retVal; |
|
| 189 | - } else { |
|
| 190 | - $AuthString = $banner; |
|
| 191 | - $AuthString .= $pass; |
|
| 192 | - $APOPString = md5($AuthString); |
|
| 193 | - $cmd = "APOP $login $APOPString"; |
|
| 194 | - $reply = $this->send_cmd($cmd); |
|
| 195 | - if(!$this->is_ok($reply)) { |
|
| 196 | - $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort"); |
|
| 197 | - $retVal = $this->login($login,$pass); |
|
| 198 | - return $retVal; |
|
| 199 | - } else { |
|
| 200 | - // Auth successful. |
|
| 201 | - $count = $this->last("count"); |
|
| 202 | - $this->COUNT = $count; |
|
| 203 | - return $count; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - function login ($login = "", $pass = "") { |
|
| 210 | - // Sends both user and pass. Returns # of msgs in mailbox or |
|
| 211 | - // false on failure (or -1, if the error occurs while getting |
|
| 212 | - // the number of messages.) |
|
| 213 | - |
|
| 214 | - if( !isset($this->FP) ) { |
|
| 215 | - $this->ERROR = "POP3 login: " . _("No connection to server"); |
|
| 216 | - return false; |
|
| 217 | - } else { |
|
| 218 | - $fp = $this->FP; |
|
| 219 | - if( !$this->user( $login ) ) { |
|
| 220 | - // Preserve the error generated by user() |
|
| 221 | - return false; |
|
| 222 | - } else { |
|
| 223 | - $count = $this->pass($pass); |
|
| 224 | - if( (!$count) || ($count == -1) ) { |
|
| 225 | - // Preserve the error generated by last() and pass() |
|
| 226 | - return false; |
|
| 227 | - } else |
|
| 228 | - return $count; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - function top ($msgNum, $numLines = "0") { |
|
| 234 | - // Gets the header and first $numLines of the msg body |
|
| 235 | - // returns data in an array with each returned line being |
|
| 236 | - // an array element. If $numLines is empty, returns |
|
| 237 | - // only the header information, and none of the body. |
|
| 238 | - |
|
| 239 | - if(!isset($this->FP)) { |
|
| 240 | - $this->ERROR = "POP3 top: " . _("No connection to server"); |
|
| 241 | - return false; |
|
| 242 | - } |
|
| 243 | - $this->update_timer(); |
|
| 244 | - |
|
| 245 | - $fp = $this->FP; |
|
| 246 | - $buffer = $this->BUFFER; |
|
| 247 | - $cmd = "TOP $msgNum $numLines"; |
|
| 248 | - fwrite($fp, "TOP $msgNum $numLines\r\n"); |
|
| 249 | - $reply = fgets($fp, $buffer); |
|
| 250 | - $reply = $this->strip_clf($reply); |
|
| 251 | - if($this->DEBUG) { |
|
| 252 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 253 | - } |
|
| 254 | - if(!$this->is_ok($reply)) |
|
| 255 | - { |
|
| 256 | - $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]"; |
|
| 257 | - return false; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $count = 0; |
|
| 261 | - $MsgArray = array(); |
|
| 262 | - |
|
| 263 | - $line = fgets($fp,$buffer); |
|
| 264 | - while ( !preg_match('/^\.\r\n/',$line)) |
|
| 265 | - { |
|
| 266 | - $MsgArray[$count] = $line; |
|
| 267 | - $count++; |
|
| 268 | - $line = fgets($fp,$buffer); |
|
| 269 | - if(empty($line)) { break; } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return $MsgArray; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - function pop_list ($msgNum = "") { |
|
| 276 | - // If called with an argument, returns that msgs' size in octets |
|
| 277 | - // No argument returns an associative array of undeleted |
|
| 278 | - // msg numbers and their sizes in octets |
|
| 279 | - |
|
| 280 | - if(!isset($this->FP)) |
|
| 281 | - { |
|
| 282 | - $this->ERROR = "POP3 pop_list: " . _("No connection to server"); |
|
| 283 | - return false; |
|
| 284 | - } |
|
| 285 | - $fp = $this->FP; |
|
| 286 | - $Total = $this->COUNT; |
|
| 287 | - if( (!$Total) or ($Total == -1) ) |
|
| 288 | - { |
|
| 289 | - return false; |
|
| 290 | - } |
|
| 291 | - if($Total == 0) |
|
| 292 | - { |
|
| 293 | - return array("0","0"); |
|
| 294 | - // return -1; // mailbox empty |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - $this->update_timer(); |
|
| 298 | - |
|
| 299 | - if(!empty($msgNum)) |
|
| 300 | - { |
|
| 301 | - $cmd = "LIST $msgNum"; |
|
| 302 | - fwrite($fp,"$cmd\r\n"); |
|
| 303 | - $reply = fgets($fp,$this->BUFFER); |
|
| 304 | - $reply = $this->strip_clf($reply); |
|
| 305 | - if($this->DEBUG) { |
|
| 306 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 307 | - } |
|
| 308 | - if(!$this->is_ok($reply)) |
|
| 309 | - { |
|
| 310 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 311 | - return false; |
|
| 312 | - } |
|
| 313 | - list($junk,$num,$size) = preg_split('/\s+/',$reply); |
|
| 314 | - return $size; |
|
| 315 | - } |
|
| 316 | - $cmd = "LIST"; |
|
| 317 | - $reply = $this->send_cmd($cmd); |
|
| 318 | - if(!$this->is_ok($reply)) |
|
| 319 | - { |
|
| 320 | - $reply = $this->strip_clf($reply); |
|
| 321 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - $MsgArray = array(); |
|
| 325 | - $MsgArray[0] = $Total; |
|
| 326 | - for($msgC=1;$msgC <= $Total; $msgC++) |
|
| 327 | - { |
|
| 328 | - if($msgC > $Total) { break; } |
|
| 329 | - $line = fgets($fp,$this->BUFFER); |
|
| 330 | - $line = $this->strip_clf($line); |
|
| 331 | - if(strpos($line, '.') === 0) |
|
| 332 | - { |
|
| 333 | - $this->ERROR = "POP3 pop_list: " . _("Premature end of list"); |
|
| 334 | - return false; |
|
| 335 | - } |
|
| 336 | - list($thisMsg,$msgSize) = preg_split('/\s+/',$line); |
|
| 337 | - settype($thisMsg,"integer"); |
|
| 338 | - if($thisMsg != $msgC) |
|
| 339 | - { |
|
| 340 | - $MsgArray[$msgC] = "deleted"; |
|
| 341 | - } |
|
| 342 | - else |
|
| 343 | - { |
|
| 344 | - $MsgArray[$msgC] = $msgSize; |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - return $MsgArray; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - function get ($msgNum) { |
|
| 351 | - // Retrieve the specified msg number. Returns an array |
|
| 352 | - // where each line of the msg is an array element. |
|
| 353 | - |
|
| 354 | - if(!isset($this->FP)) |
|
| 355 | - { |
|
| 356 | - $this->ERROR = "POP3 get: " . _("No connection to server"); |
|
| 357 | - return false; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $this->update_timer(); |
|
| 361 | - |
|
| 362 | - $fp = $this->FP; |
|
| 363 | - $buffer = $this->BUFFER; |
|
| 364 | - $cmd = "RETR $msgNum"; |
|
| 365 | - $reply = $this->send_cmd($cmd); |
|
| 366 | - |
|
| 367 | - if(!$this->is_ok($reply)) |
|
| 368 | - { |
|
| 369 | - $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]"; |
|
| 370 | - return false; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $count = 0; |
|
| 374 | - $MsgArray = array(); |
|
| 375 | - |
|
| 376 | - $line = fgets($fp,$buffer); |
|
| 377 | - while ( !preg_match('/^\.\r\n/',$line)) |
|
| 378 | - { |
|
| 379 | - if ( $line{0} == '.' ) { $line = substr($line,1); } |
|
| 380 | - $MsgArray[$count] = $line; |
|
| 381 | - $count++; |
|
| 382 | - $line = fgets($fp,$buffer); |
|
| 383 | - if(empty($line)) { break; } |
|
| 384 | - } |
|
| 385 | - return $MsgArray; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - function last ( $type = "count" ) { |
|
| 389 | - // Returns the highest msg number in the mailbox. |
|
| 390 | - // returns -1 on error, 0+ on success, if type != count |
|
| 391 | - // results in a popstat() call (2 element array returned) |
|
| 392 | - |
|
| 393 | - $last = -1; |
|
| 394 | - if(!isset($this->FP)) |
|
| 395 | - { |
|
| 396 | - $this->ERROR = "POP3 last: " . _("No connection to server"); |
|
| 397 | - return $last; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - $reply = $this->send_cmd("STAT"); |
|
| 401 | - if(!$this->is_ok($reply)) |
|
| 402 | - { |
|
| 403 | - $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]"; |
|
| 404 | - return $last; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - $Vars = preg_split('/\s+/',$reply); |
|
| 408 | - $count = $Vars[1]; |
|
| 409 | - $size = $Vars[2]; |
|
| 410 | - settype($count,"integer"); |
|
| 411 | - settype($size,"integer"); |
|
| 412 | - if($type != "count") |
|
| 413 | - { |
|
| 414 | - return array($count,$size); |
|
| 415 | - } |
|
| 416 | - return $count; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - function reset () { |
|
| 420 | - // Resets the status of the remote server. This includes |
|
| 421 | - // resetting the status of ALL msgs to not be deleted. |
|
| 422 | - // This method automatically closes the connection to the server. |
|
| 423 | - |
|
| 424 | - if(!isset($this->FP)) |
|
| 425 | - { |
|
| 426 | - $this->ERROR = "POP3 reset: " . _("No connection to server"); |
|
| 427 | - return false; |
|
| 428 | - } |
|
| 429 | - $reply = $this->send_cmd("RSET"); |
|
| 430 | - if(!$this->is_ok($reply)) |
|
| 431 | - { |
|
| 432 | - // The POP3 RSET command -never- gives a -ERR |
|
| 433 | - // response - if it ever does, something truely |
|
| 434 | - // wild is going on. |
|
| 435 | - |
|
| 436 | - $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]"; |
|
| 437 | - @error_log("POP3 reset: ERROR [$reply]",0); |
|
| 438 | - } |
|
| 439 | - $this->quit(); |
|
| 440 | - return true; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - function send_cmd ( $cmd = "" ) |
|
| 444 | - { |
|
| 445 | - // Sends a user defined command string to the |
|
| 446 | - // POP server and returns the results. Useful for |
|
| 447 | - // non-compliant or custom POP servers. |
|
| 448 | - // Do NOT includ the \r\n as part of your command |
|
| 449 | - // string - it will be appended automatically. |
|
| 450 | - |
|
| 451 | - // The return value is a standard fgets() call, which |
|
| 452 | - // will read up to $this->BUFFER bytes of data, until it |
|
| 453 | - // encounters a new line, or EOF, whichever happens first. |
|
| 454 | - |
|
| 455 | - // This method works best if $cmd responds with only |
|
| 456 | - // one line of data. |
|
| 457 | - |
|
| 458 | - if(!isset($this->FP)) |
|
| 459 | - { |
|
| 460 | - $this->ERROR = "POP3 send_cmd: " . _("No connection to server"); |
|
| 461 | - return false; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - if(empty($cmd)) |
|
| 465 | - { |
|
| 466 | - $this->ERROR = "POP3 send_cmd: " . _("Empty command string"); |
|
| 467 | - return ""; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $fp = $this->FP; |
|
| 471 | - $buffer = $this->BUFFER; |
|
| 472 | - $this->update_timer(); |
|
| 473 | - fwrite($fp,"$cmd\r\n"); |
|
| 474 | - $reply = fgets($fp,$buffer); |
|
| 475 | - $reply = $this->strip_clf($reply); |
|
| 476 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 477 | - return $reply; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - function quit() { |
|
| 481 | - // Closes the connection to the POP3 server, deleting |
|
| 482 | - // any msgs marked as deleted. |
|
| 483 | - |
|
| 484 | - if(!isset($this->FP)) |
|
| 485 | - { |
|
| 486 | - $this->ERROR = "POP3 quit: " . _("connection does not exist"); |
|
| 487 | - return false; |
|
| 488 | - } |
|
| 489 | - $fp = $this->FP; |
|
| 490 | - $cmd = "QUIT"; |
|
| 491 | - fwrite($fp,"$cmd\r\n"); |
|
| 492 | - $reply = fgets($fp,$this->BUFFER); |
|
| 493 | - $reply = $this->strip_clf($reply); |
|
| 494 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 495 | - fclose($fp); |
|
| 496 | - unset($this->FP); |
|
| 497 | - return true; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - function popstat () { |
|
| 501 | - // Returns an array of 2 elements. The number of undeleted |
|
| 502 | - // msgs in the mailbox, and the size of the mbox in octets. |
|
| 503 | - |
|
| 504 | - $PopArray = $this->last("array"); |
|
| 505 | - |
|
| 506 | - if($PopArray == -1) { return false; } |
|
| 507 | - |
|
| 508 | - if( (!$PopArray) or (empty($PopArray)) ) |
|
| 509 | - { |
|
| 510 | - return false; |
|
| 511 | - } |
|
| 512 | - return $PopArray; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - function uidl ($msgNum = "") |
|
| 516 | - { |
|
| 517 | - // Returns the UIDL of the msg specified. If called with |
|
| 518 | - // no arguments, returns an associative array where each |
|
| 519 | - // undeleted msg num is a key, and the msg's uidl is the element |
|
| 520 | - // Array element 0 will contain the total number of msgs |
|
| 521 | - |
|
| 522 | - if(!isset($this->FP)) { |
|
| 523 | - $this->ERROR = "POP3 uidl: " . _("No connection to server"); |
|
| 524 | - return false; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $fp = $this->FP; |
|
| 528 | - $buffer = $this->BUFFER; |
|
| 529 | - |
|
| 530 | - if(!empty($msgNum)) { |
|
| 531 | - $cmd = "UIDL $msgNum"; |
|
| 532 | - $reply = $this->send_cmd($cmd); |
|
| 533 | - if(!$this->is_ok($reply)) |
|
| 534 | - { |
|
| 535 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 536 | - return false; |
|
| 537 | - } |
|
| 538 | - list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply); |
|
| 539 | - return $myUidl; |
|
| 540 | - } else { |
|
| 541 | - $this->update_timer(); |
|
| 542 | - |
|
| 543 | - $UIDLArray = array(); |
|
| 544 | - $Total = $this->COUNT; |
|
| 545 | - $UIDLArray[0] = $Total; |
|
| 546 | - |
|
| 547 | - if ($Total < 1) |
|
| 548 | - { |
|
| 549 | - return $UIDLArray; |
|
| 550 | - } |
|
| 551 | - $cmd = "UIDL"; |
|
| 552 | - fwrite($fp, "UIDL\r\n"); |
|
| 553 | - $reply = fgets($fp, $buffer); |
|
| 554 | - $reply = $this->strip_clf($reply); |
|
| 555 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 556 | - if(!$this->is_ok($reply)) |
|
| 557 | - { |
|
| 558 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 559 | - return false; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - $line = ""; |
|
| 563 | - $count = 1; |
|
| 564 | - $line = fgets($fp,$buffer); |
|
| 565 | - while ( !preg_match('/^\.\r\n/',$line)) { |
|
| 566 | - list ($msg,$msgUidl) = preg_split('/\s+/',$line); |
|
| 567 | - $msgUidl = $this->strip_clf($msgUidl); |
|
| 568 | - if($count == $msg) { |
|
| 569 | - $UIDLArray[$msg] = $msgUidl; |
|
| 570 | - } |
|
| 571 | - else |
|
| 572 | - { |
|
| 573 | - $UIDLArray[$count] = 'deleted'; |
|
| 574 | - } |
|
| 575 | - $count++; |
|
| 576 | - $line = fgets($fp,$buffer); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - return $UIDLArray; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - function delete ($msgNum = "") { |
|
| 583 | - // Flags a specified msg as deleted. The msg will not |
|
| 584 | - // be deleted until a quit() method is called. |
|
| 585 | - |
|
| 586 | - if(!isset($this->FP)) |
|
| 587 | - { |
|
| 588 | - $this->ERROR = "POP3 delete: " . _("No connection to server"); |
|
| 589 | - return false; |
|
| 590 | - } |
|
| 591 | - if(empty($msgNum)) |
|
| 592 | - { |
|
| 593 | - $this->ERROR = "POP3 delete: " . _("No msg number submitted"); |
|
| 594 | - return false; |
|
| 595 | - } |
|
| 596 | - $reply = $this->send_cmd("DELE $msgNum"); |
|
| 597 | - if(!$this->is_ok($reply)) |
|
| 598 | - { |
|
| 599 | - $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]"; |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - return true; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - // ********************************************************* |
|
| 606 | - |
|
| 607 | - // The following methods are internal to the class. |
|
| 608 | - |
|
| 609 | - function is_ok ($cmd = "") { |
|
| 610 | - // Return true or false on +OK or -ERR |
|
| 611 | - |
|
| 612 | - if( empty($cmd) ) |
|
| 613 | - return false; |
|
| 614 | - else |
|
| 615 | - return( stripos($cmd, '+OK') !== false ); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - function strip_clf ($text = "") { |
|
| 619 | - // Strips \r\n from server responses |
|
| 620 | - |
|
| 621 | - if(empty($text)) |
|
| 622 | - return $text; |
|
| 623 | - else { |
|
| 624 | - $stripped = str_replace(array("\r","\n"),'',$text); |
|
| 625 | - return $stripped; |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - function parse_banner ( $server_text ) { |
|
| 630 | - $outside = true; |
|
| 631 | - $banner = ""; |
|
| 632 | - $length = strlen($server_text); |
|
| 633 | - for($count =0; $count < $length; $count++) |
|
| 634 | - { |
|
| 635 | - $digit = substr($server_text,$count,1); |
|
| 636 | - if(!empty($digit)) { |
|
| 637 | - if( (!$outside) && ($digit != '<') && ($digit != '>') ) |
|
| 638 | - { |
|
| 639 | - $banner .= $digit; |
|
| 640 | - } |
|
| 641 | - if ($digit == '<') |
|
| 642 | - { |
|
| 643 | - $outside = false; |
|
| 644 | - } |
|
| 645 | - if($digit == '>') |
|
| 646 | - { |
|
| 647 | - $outside = true; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - $banner = $this->strip_clf($banner); // Just in case |
|
| 652 | - return "<$banner>"; |
|
| 653 | - } |
|
| 75 | + function update_timer () { |
|
| 76 | + if (!ini_get('safe_mode')) |
|
| 77 | + set_time_limit($this->TIMEOUT); |
|
| 78 | + return true; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + function connect ($server, $port = 110) { |
|
| 82 | + // Opens a socket to the specified server. Unless overridden, |
|
| 83 | + // port defaults to 110. Returns true on success, false on fail |
|
| 84 | + |
|
| 85 | + // If MAILSERVER is set, override $server with it's value |
|
| 86 | + |
|
| 87 | + if (!isset($port) || !$port) {$port = 110;} |
|
| 88 | + if(!empty($this->MAILSERVER)) |
|
| 89 | + $server = $this->MAILSERVER; |
|
| 90 | + |
|
| 91 | + if(empty($server)){ |
|
| 92 | + $this->ERROR = "POP3 connect: " . _("No server specified"); |
|
| 93 | + unset($this->FP); |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $fp = @fsockopen("$server", $port, $errno, $errstr); |
|
| 98 | + |
|
| 99 | + if(!$fp) { |
|
| 100 | + $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]"; |
|
| 101 | + unset($this->FP); |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + socket_set_blocking($fp,-1); |
|
| 106 | + $this->update_timer(); |
|
| 107 | + $reply = fgets($fp,$this->BUFFER); |
|
| 108 | + $reply = $this->strip_clf($reply); |
|
| 109 | + if($this->DEBUG) |
|
| 110 | + error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 111 | + if(!$this->is_ok($reply)) { |
|
| 112 | + $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]"; |
|
| 113 | + unset($this->FP); |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 116 | + $this->FP = $fp; |
|
| 117 | + $this->BANNER = $this->parse_banner($reply); |
|
| 118 | + return true; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + function user ($user = "") { |
|
| 122 | + // Sends the USER command, returns true or false |
|
| 123 | + |
|
| 124 | + if( empty($user) ) { |
|
| 125 | + $this->ERROR = "POP3 user: " . _("no login ID submitted"); |
|
| 126 | + return false; |
|
| 127 | + } elseif(!isset($this->FP)) { |
|
| 128 | + $this->ERROR = "POP3 user: " . _("connection not established"); |
|
| 129 | + return false; |
|
| 130 | + } else { |
|
| 131 | + $reply = $this->send_cmd("USER $user"); |
|
| 132 | + if(!$this->is_ok($reply)) { |
|
| 133 | + $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]"; |
|
| 134 | + return false; |
|
| 135 | + } else |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + function pass ($pass = "") { |
|
| 141 | + // Sends the PASS command, returns # of msgs in mailbox, |
|
| 142 | + // returns false (undef) on Auth failure |
|
| 143 | + |
|
| 144 | + if(empty($pass)) { |
|
| 145 | + $this->ERROR = "POP3 pass: " . _("No password submitted"); |
|
| 146 | + return false; |
|
| 147 | + } elseif(!isset($this->FP)) { |
|
| 148 | + $this->ERROR = "POP3 pass: " . _("connection not established"); |
|
| 149 | + return false; |
|
| 150 | + } else { |
|
| 151 | + $reply = $this->send_cmd("PASS $pass"); |
|
| 152 | + if(!$this->is_ok($reply)) { |
|
| 153 | + $this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]"; |
|
| 154 | + $this->quit(); |
|
| 155 | + return false; |
|
| 156 | + } else { |
|
| 157 | + // Auth successful. |
|
| 158 | + $count = $this->last("count"); |
|
| 159 | + $this->COUNT = $count; |
|
| 160 | + return $count; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + function apop ($login,$pass) { |
|
| 166 | + // Attempts an APOP login. If this fails, it'll |
|
| 167 | + // try a standard login. YOUR SERVER MUST SUPPORT |
|
| 168 | + // THE USE OF THE APOP COMMAND! |
|
| 169 | + // (apop is optional per rfc1939) |
|
| 170 | + |
|
| 171 | + if(!isset($this->FP)) { |
|
| 172 | + $this->ERROR = "POP3 apop: " . _("No connection to server"); |
|
| 173 | + return false; |
|
| 174 | + } elseif(!$this->ALLOWAPOP) { |
|
| 175 | + $retVal = $this->login($login,$pass); |
|
| 176 | + return $retVal; |
|
| 177 | + } elseif(empty($login)) { |
|
| 178 | + $this->ERROR = "POP3 apop: " . _("No login ID submitted"); |
|
| 179 | + return false; |
|
| 180 | + } elseif(empty($pass)) { |
|
| 181 | + $this->ERROR = "POP3 apop: " . _("No password submitted"); |
|
| 182 | + return false; |
|
| 183 | + } else { |
|
| 184 | + $banner = $this->BANNER; |
|
| 185 | + if( (!$banner) or (empty($banner)) ) { |
|
| 186 | + $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort"); |
|
| 187 | + $retVal = $this->login($login,$pass); |
|
| 188 | + return $retVal; |
|
| 189 | + } else { |
|
| 190 | + $AuthString = $banner; |
|
| 191 | + $AuthString .= $pass; |
|
| 192 | + $APOPString = md5($AuthString); |
|
| 193 | + $cmd = "APOP $login $APOPString"; |
|
| 194 | + $reply = $this->send_cmd($cmd); |
|
| 195 | + if(!$this->is_ok($reply)) { |
|
| 196 | + $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort"); |
|
| 197 | + $retVal = $this->login($login,$pass); |
|
| 198 | + return $retVal; |
|
| 199 | + } else { |
|
| 200 | + // Auth successful. |
|
| 201 | + $count = $this->last("count"); |
|
| 202 | + $this->COUNT = $count; |
|
| 203 | + return $count; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + function login ($login = "", $pass = "") { |
|
| 210 | + // Sends both user and pass. Returns # of msgs in mailbox or |
|
| 211 | + // false on failure (or -1, if the error occurs while getting |
|
| 212 | + // the number of messages.) |
|
| 213 | + |
|
| 214 | + if( !isset($this->FP) ) { |
|
| 215 | + $this->ERROR = "POP3 login: " . _("No connection to server"); |
|
| 216 | + return false; |
|
| 217 | + } else { |
|
| 218 | + $fp = $this->FP; |
|
| 219 | + if( !$this->user( $login ) ) { |
|
| 220 | + // Preserve the error generated by user() |
|
| 221 | + return false; |
|
| 222 | + } else { |
|
| 223 | + $count = $this->pass($pass); |
|
| 224 | + if( (!$count) || ($count == -1) ) { |
|
| 225 | + // Preserve the error generated by last() and pass() |
|
| 226 | + return false; |
|
| 227 | + } else |
|
| 228 | + return $count; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + function top ($msgNum, $numLines = "0") { |
|
| 234 | + // Gets the header and first $numLines of the msg body |
|
| 235 | + // returns data in an array with each returned line being |
|
| 236 | + // an array element. If $numLines is empty, returns |
|
| 237 | + // only the header information, and none of the body. |
|
| 238 | + |
|
| 239 | + if(!isset($this->FP)) { |
|
| 240 | + $this->ERROR = "POP3 top: " . _("No connection to server"); |
|
| 241 | + return false; |
|
| 242 | + } |
|
| 243 | + $this->update_timer(); |
|
| 244 | + |
|
| 245 | + $fp = $this->FP; |
|
| 246 | + $buffer = $this->BUFFER; |
|
| 247 | + $cmd = "TOP $msgNum $numLines"; |
|
| 248 | + fwrite($fp, "TOP $msgNum $numLines\r\n"); |
|
| 249 | + $reply = fgets($fp, $buffer); |
|
| 250 | + $reply = $this->strip_clf($reply); |
|
| 251 | + if($this->DEBUG) { |
|
| 252 | + @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 253 | + } |
|
| 254 | + if(!$this->is_ok($reply)) |
|
| 255 | + { |
|
| 256 | + $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]"; |
|
| 257 | + return false; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $count = 0; |
|
| 261 | + $MsgArray = array(); |
|
| 262 | + |
|
| 263 | + $line = fgets($fp,$buffer); |
|
| 264 | + while ( !preg_match('/^\.\r\n/',$line)) |
|
| 265 | + { |
|
| 266 | + $MsgArray[$count] = $line; |
|
| 267 | + $count++; |
|
| 268 | + $line = fgets($fp,$buffer); |
|
| 269 | + if(empty($line)) { break; } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return $MsgArray; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + function pop_list ($msgNum = "") { |
|
| 276 | + // If called with an argument, returns that msgs' size in octets |
|
| 277 | + // No argument returns an associative array of undeleted |
|
| 278 | + // msg numbers and their sizes in octets |
|
| 279 | + |
|
| 280 | + if(!isset($this->FP)) |
|
| 281 | + { |
|
| 282 | + $this->ERROR = "POP3 pop_list: " . _("No connection to server"); |
|
| 283 | + return false; |
|
| 284 | + } |
|
| 285 | + $fp = $this->FP; |
|
| 286 | + $Total = $this->COUNT; |
|
| 287 | + if( (!$Total) or ($Total == -1) ) |
|
| 288 | + { |
|
| 289 | + return false; |
|
| 290 | + } |
|
| 291 | + if($Total == 0) |
|
| 292 | + { |
|
| 293 | + return array("0","0"); |
|
| 294 | + // return -1; // mailbox empty |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + $this->update_timer(); |
|
| 298 | + |
|
| 299 | + if(!empty($msgNum)) |
|
| 300 | + { |
|
| 301 | + $cmd = "LIST $msgNum"; |
|
| 302 | + fwrite($fp,"$cmd\r\n"); |
|
| 303 | + $reply = fgets($fp,$this->BUFFER); |
|
| 304 | + $reply = $this->strip_clf($reply); |
|
| 305 | + if($this->DEBUG) { |
|
| 306 | + @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 307 | + } |
|
| 308 | + if(!$this->is_ok($reply)) |
|
| 309 | + { |
|
| 310 | + $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 313 | + list($junk,$num,$size) = preg_split('/\s+/',$reply); |
|
| 314 | + return $size; |
|
| 315 | + } |
|
| 316 | + $cmd = "LIST"; |
|
| 317 | + $reply = $this->send_cmd($cmd); |
|
| 318 | + if(!$this->is_ok($reply)) |
|
| 319 | + { |
|
| 320 | + $reply = $this->strip_clf($reply); |
|
| 321 | + $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + $MsgArray = array(); |
|
| 325 | + $MsgArray[0] = $Total; |
|
| 326 | + for($msgC=1;$msgC <= $Total; $msgC++) |
|
| 327 | + { |
|
| 328 | + if($msgC > $Total) { break; } |
|
| 329 | + $line = fgets($fp,$this->BUFFER); |
|
| 330 | + $line = $this->strip_clf($line); |
|
| 331 | + if(strpos($line, '.') === 0) |
|
| 332 | + { |
|
| 333 | + $this->ERROR = "POP3 pop_list: " . _("Premature end of list"); |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 336 | + list($thisMsg,$msgSize) = preg_split('/\s+/',$line); |
|
| 337 | + settype($thisMsg,"integer"); |
|
| 338 | + if($thisMsg != $msgC) |
|
| 339 | + { |
|
| 340 | + $MsgArray[$msgC] = "deleted"; |
|
| 341 | + } |
|
| 342 | + else |
|
| 343 | + { |
|
| 344 | + $MsgArray[$msgC] = $msgSize; |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + return $MsgArray; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + function get ($msgNum) { |
|
| 351 | + // Retrieve the specified msg number. Returns an array |
|
| 352 | + // where each line of the msg is an array element. |
|
| 353 | + |
|
| 354 | + if(!isset($this->FP)) |
|
| 355 | + { |
|
| 356 | + $this->ERROR = "POP3 get: " . _("No connection to server"); |
|
| 357 | + return false; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $this->update_timer(); |
|
| 361 | + |
|
| 362 | + $fp = $this->FP; |
|
| 363 | + $buffer = $this->BUFFER; |
|
| 364 | + $cmd = "RETR $msgNum"; |
|
| 365 | + $reply = $this->send_cmd($cmd); |
|
| 366 | + |
|
| 367 | + if(!$this->is_ok($reply)) |
|
| 368 | + { |
|
| 369 | + $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]"; |
|
| 370 | + return false; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $count = 0; |
|
| 374 | + $MsgArray = array(); |
|
| 375 | + |
|
| 376 | + $line = fgets($fp,$buffer); |
|
| 377 | + while ( !preg_match('/^\.\r\n/',$line)) |
|
| 378 | + { |
|
| 379 | + if ( $line{0} == '.' ) { $line = substr($line,1); } |
|
| 380 | + $MsgArray[$count] = $line; |
|
| 381 | + $count++; |
|
| 382 | + $line = fgets($fp,$buffer); |
|
| 383 | + if(empty($line)) { break; } |
|
| 384 | + } |
|
| 385 | + return $MsgArray; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + function last ( $type = "count" ) { |
|
| 389 | + // Returns the highest msg number in the mailbox. |
|
| 390 | + // returns -1 on error, 0+ on success, if type != count |
|
| 391 | + // results in a popstat() call (2 element array returned) |
|
| 392 | + |
|
| 393 | + $last = -1; |
|
| 394 | + if(!isset($this->FP)) |
|
| 395 | + { |
|
| 396 | + $this->ERROR = "POP3 last: " . _("No connection to server"); |
|
| 397 | + return $last; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + $reply = $this->send_cmd("STAT"); |
|
| 401 | + if(!$this->is_ok($reply)) |
|
| 402 | + { |
|
| 403 | + $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]"; |
|
| 404 | + return $last; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + $Vars = preg_split('/\s+/',$reply); |
|
| 408 | + $count = $Vars[1]; |
|
| 409 | + $size = $Vars[2]; |
|
| 410 | + settype($count,"integer"); |
|
| 411 | + settype($size,"integer"); |
|
| 412 | + if($type != "count") |
|
| 413 | + { |
|
| 414 | + return array($count,$size); |
|
| 415 | + } |
|
| 416 | + return $count; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + function reset () { |
|
| 420 | + // Resets the status of the remote server. This includes |
|
| 421 | + // resetting the status of ALL msgs to not be deleted. |
|
| 422 | + // This method automatically closes the connection to the server. |
|
| 423 | + |
|
| 424 | + if(!isset($this->FP)) |
|
| 425 | + { |
|
| 426 | + $this->ERROR = "POP3 reset: " . _("No connection to server"); |
|
| 427 | + return false; |
|
| 428 | + } |
|
| 429 | + $reply = $this->send_cmd("RSET"); |
|
| 430 | + if(!$this->is_ok($reply)) |
|
| 431 | + { |
|
| 432 | + // The POP3 RSET command -never- gives a -ERR |
|
| 433 | + // response - if it ever does, something truely |
|
| 434 | + // wild is going on. |
|
| 435 | + |
|
| 436 | + $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]"; |
|
| 437 | + @error_log("POP3 reset: ERROR [$reply]",0); |
|
| 438 | + } |
|
| 439 | + $this->quit(); |
|
| 440 | + return true; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + function send_cmd ( $cmd = "" ) |
|
| 444 | + { |
|
| 445 | + // Sends a user defined command string to the |
|
| 446 | + // POP server and returns the results. Useful for |
|
| 447 | + // non-compliant or custom POP servers. |
|
| 448 | + // Do NOT includ the \r\n as part of your command |
|
| 449 | + // string - it will be appended automatically. |
|
| 450 | + |
|
| 451 | + // The return value is a standard fgets() call, which |
|
| 452 | + // will read up to $this->BUFFER bytes of data, until it |
|
| 453 | + // encounters a new line, or EOF, whichever happens first. |
|
| 454 | + |
|
| 455 | + // This method works best if $cmd responds with only |
|
| 456 | + // one line of data. |
|
| 457 | + |
|
| 458 | + if(!isset($this->FP)) |
|
| 459 | + { |
|
| 460 | + $this->ERROR = "POP3 send_cmd: " . _("No connection to server"); |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + if(empty($cmd)) |
|
| 465 | + { |
|
| 466 | + $this->ERROR = "POP3 send_cmd: " . _("Empty command string"); |
|
| 467 | + return ""; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $fp = $this->FP; |
|
| 471 | + $buffer = $this->BUFFER; |
|
| 472 | + $this->update_timer(); |
|
| 473 | + fwrite($fp,"$cmd\r\n"); |
|
| 474 | + $reply = fgets($fp,$buffer); |
|
| 475 | + $reply = $this->strip_clf($reply); |
|
| 476 | + if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 477 | + return $reply; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + function quit() { |
|
| 481 | + // Closes the connection to the POP3 server, deleting |
|
| 482 | + // any msgs marked as deleted. |
|
| 483 | + |
|
| 484 | + if(!isset($this->FP)) |
|
| 485 | + { |
|
| 486 | + $this->ERROR = "POP3 quit: " . _("connection does not exist"); |
|
| 487 | + return false; |
|
| 488 | + } |
|
| 489 | + $fp = $this->FP; |
|
| 490 | + $cmd = "QUIT"; |
|
| 491 | + fwrite($fp,"$cmd\r\n"); |
|
| 492 | + $reply = fgets($fp,$this->BUFFER); |
|
| 493 | + $reply = $this->strip_clf($reply); |
|
| 494 | + if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 495 | + fclose($fp); |
|
| 496 | + unset($this->FP); |
|
| 497 | + return true; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + function popstat () { |
|
| 501 | + // Returns an array of 2 elements. The number of undeleted |
|
| 502 | + // msgs in the mailbox, and the size of the mbox in octets. |
|
| 503 | + |
|
| 504 | + $PopArray = $this->last("array"); |
|
| 505 | + |
|
| 506 | + if($PopArray == -1) { return false; } |
|
| 507 | + |
|
| 508 | + if( (!$PopArray) or (empty($PopArray)) ) |
|
| 509 | + { |
|
| 510 | + return false; |
|
| 511 | + } |
|
| 512 | + return $PopArray; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + function uidl ($msgNum = "") |
|
| 516 | + { |
|
| 517 | + // Returns the UIDL of the msg specified. If called with |
|
| 518 | + // no arguments, returns an associative array where each |
|
| 519 | + // undeleted msg num is a key, and the msg's uidl is the element |
|
| 520 | + // Array element 0 will contain the total number of msgs |
|
| 521 | + |
|
| 522 | + if(!isset($this->FP)) { |
|
| 523 | + $this->ERROR = "POP3 uidl: " . _("No connection to server"); |
|
| 524 | + return false; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $fp = $this->FP; |
|
| 528 | + $buffer = $this->BUFFER; |
|
| 529 | + |
|
| 530 | + if(!empty($msgNum)) { |
|
| 531 | + $cmd = "UIDL $msgNum"; |
|
| 532 | + $reply = $this->send_cmd($cmd); |
|
| 533 | + if(!$this->is_ok($reply)) |
|
| 534 | + { |
|
| 535 | + $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 536 | + return false; |
|
| 537 | + } |
|
| 538 | + list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply); |
|
| 539 | + return $myUidl; |
|
| 540 | + } else { |
|
| 541 | + $this->update_timer(); |
|
| 542 | + |
|
| 543 | + $UIDLArray = array(); |
|
| 544 | + $Total = $this->COUNT; |
|
| 545 | + $UIDLArray[0] = $Total; |
|
| 546 | + |
|
| 547 | + if ($Total < 1) |
|
| 548 | + { |
|
| 549 | + return $UIDLArray; |
|
| 550 | + } |
|
| 551 | + $cmd = "UIDL"; |
|
| 552 | + fwrite($fp, "UIDL\r\n"); |
|
| 553 | + $reply = fgets($fp, $buffer); |
|
| 554 | + $reply = $this->strip_clf($reply); |
|
| 555 | + if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 556 | + if(!$this->is_ok($reply)) |
|
| 557 | + { |
|
| 558 | + $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 559 | + return false; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + $line = ""; |
|
| 563 | + $count = 1; |
|
| 564 | + $line = fgets($fp,$buffer); |
|
| 565 | + while ( !preg_match('/^\.\r\n/',$line)) { |
|
| 566 | + list ($msg,$msgUidl) = preg_split('/\s+/',$line); |
|
| 567 | + $msgUidl = $this->strip_clf($msgUidl); |
|
| 568 | + if($count == $msg) { |
|
| 569 | + $UIDLArray[$msg] = $msgUidl; |
|
| 570 | + } |
|
| 571 | + else |
|
| 572 | + { |
|
| 573 | + $UIDLArray[$count] = 'deleted'; |
|
| 574 | + } |
|
| 575 | + $count++; |
|
| 576 | + $line = fgets($fp,$buffer); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + return $UIDLArray; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + function delete ($msgNum = "") { |
|
| 583 | + // Flags a specified msg as deleted. The msg will not |
|
| 584 | + // be deleted until a quit() method is called. |
|
| 585 | + |
|
| 586 | + if(!isset($this->FP)) |
|
| 587 | + { |
|
| 588 | + $this->ERROR = "POP3 delete: " . _("No connection to server"); |
|
| 589 | + return false; |
|
| 590 | + } |
|
| 591 | + if(empty($msgNum)) |
|
| 592 | + { |
|
| 593 | + $this->ERROR = "POP3 delete: " . _("No msg number submitted"); |
|
| 594 | + return false; |
|
| 595 | + } |
|
| 596 | + $reply = $this->send_cmd("DELE $msgNum"); |
|
| 597 | + if(!$this->is_ok($reply)) |
|
| 598 | + { |
|
| 599 | + $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]"; |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + return true; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + // ********************************************************* |
|
| 606 | + |
|
| 607 | + // The following methods are internal to the class. |
|
| 608 | + |
|
| 609 | + function is_ok ($cmd = "") { |
|
| 610 | + // Return true or false on +OK or -ERR |
|
| 611 | + |
|
| 612 | + if( empty($cmd) ) |
|
| 613 | + return false; |
|
| 614 | + else |
|
| 615 | + return( stripos($cmd, '+OK') !== false ); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + function strip_clf ($text = "") { |
|
| 619 | + // Strips \r\n from server responses |
|
| 620 | + |
|
| 621 | + if(empty($text)) |
|
| 622 | + return $text; |
|
| 623 | + else { |
|
| 624 | + $stripped = str_replace(array("\r","\n"),'',$text); |
|
| 625 | + return $stripped; |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + function parse_banner ( $server_text ) { |
|
| 630 | + $outside = true; |
|
| 631 | + $banner = ""; |
|
| 632 | + $length = strlen($server_text); |
|
| 633 | + for($count =0; $count < $length; $count++) |
|
| 634 | + { |
|
| 635 | + $digit = substr($server_text,$count,1); |
|
| 636 | + if(!empty($digit)) { |
|
| 637 | + if( (!$outside) && ($digit != '<') && ($digit != '>') ) |
|
| 638 | + { |
|
| 639 | + $banner .= $digit; |
|
| 640 | + } |
|
| 641 | + if ($digit == '<') |
|
| 642 | + { |
|
| 643 | + $outside = false; |
|
| 644 | + } |
|
| 645 | + if($digit == '>') |
|
| 646 | + { |
|
| 647 | + $outside = true; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + $banner = $this->strip_clf($banner); // Just in case |
|
| 652 | + return "<$banner>"; |
|
| 653 | + } |
|
| 654 | 654 | |
| 655 | 655 | } // End class |
| 656 | 656 | |
| 657 | 657 | // For php4 compatibility |
| 658 | 658 | if (!function_exists("stripos")) { |
| 659 | - function stripos($haystack, $needle){ |
|
| 660 | - return strpos($haystack, stristr( $haystack, $needle )); |
|
| 661 | - } |
|
| 659 | + function stripos($haystack, $needle){ |
|
| 660 | + return strpos($haystack, stristr( $haystack, $needle )); |
|
| 661 | + } |
|
| 662 | 662 | } |
@@ -17,49 +17,49 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | class POP3 { |
| 20 | - var $ERROR = ''; // Error string. |
|
| 20 | + var $ERROR = ''; // Error string. |
|
| 21 | 21 | |
| 22 | - var $TIMEOUT = 60; // Default timeout before giving up on a |
|
| 22 | + var $TIMEOUT = 60; // Default timeout before giving up on a |
|
| 23 | 23 | // network operation. |
| 24 | 24 | |
| 25 | - var $COUNT = -1; // Mailbox msg count |
|
| 25 | + var $COUNT = -1; // Mailbox msg count |
|
| 26 | 26 | |
| 27 | - var $BUFFER = 512; // Socket buffer for socket fgets() calls. |
|
| 27 | + var $BUFFER = 512; // Socket buffer for socket fgets() calls. |
|
| 28 | 28 | // Per RFC 1939 the returned line a POP3 |
| 29 | 29 | // server can send is 512 bytes. |
| 30 | 30 | |
| 31 | - var $FP = ''; // The connection to the server's |
|
| 31 | + var $FP = ''; // The connection to the server's |
|
| 32 | 32 | // file descriptor |
| 33 | 33 | |
| 34 | - var $MAILSERVER = ''; // Set this to hard code the server name |
|
| 34 | + var $MAILSERVER = ''; // Set this to hard code the server name |
|
| 35 | 35 | |
| 36 | - var $DEBUG = FALSE; // set to true to echo pop3 |
|
| 36 | + var $DEBUG = FALSE; // set to true to echo pop3 |
|
| 37 | 37 | // commands and responses to error_log |
| 38 | 38 | // this WILL log passwords! |
| 39 | 39 | |
| 40 | - var $BANNER = ''; // Holds the banner returned by the |
|
| 40 | + var $BANNER = ''; // Holds the banner returned by the |
|
| 41 | 41 | // pop server - used for apop() |
| 42 | 42 | |
| 43 | - var $ALLOWAPOP = FALSE; // Allow or disallow apop() |
|
| 43 | + var $ALLOWAPOP = FALSE; // Allow or disallow apop() |
|
| 44 | 44 | // This must be set to true |
| 45 | 45 | // manually |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * PHP5 constructor. |
| 49 | 49 | */ |
| 50 | - function __construct ( $server = '', $timeout = '' ) { |
|
| 51 | - settype($this->BUFFER,"integer"); |
|
| 52 | - if( !empty($server) ) { |
|
| 50 | + function __construct($server = '', $timeout = '') { |
|
| 51 | + settype($this->BUFFER, "integer"); |
|
| 52 | + if ( ! empty($server)) { |
|
| 53 | 53 | // Do not allow programs to alter MAILSERVER |
| 54 | 54 | // if it is already specified. They can get around |
| 55 | 55 | // this if they -really- want to, so don't count on it. |
| 56 | - if(empty($this->MAILSERVER)) |
|
| 56 | + if (empty($this->MAILSERVER)) |
|
| 57 | 57 | $this->MAILSERVER = $server; |
| 58 | 58 | } |
| 59 | - if(!empty($timeout)) { |
|
| 60 | - settype($timeout,"integer"); |
|
| 59 | + if ( ! empty($timeout)) { |
|
| 60 | + settype($timeout, "integer"); |
|
| 61 | 61 | $this->TIMEOUT = $timeout; |
| 62 | - if (!ini_get('safe_mode')) |
|
| 62 | + if ( ! ini_get('safe_mode')) |
|
| 63 | 63 | set_time_limit($timeout); |
| 64 | 64 | } |
| 65 | 65 | return true; |
@@ -68,48 +68,48 @@ discard block |
||
| 68 | 68 | /** |
| 69 | 69 | * PHP4 constructor. |
| 70 | 70 | */ |
| 71 | - public function POP3( $server = '', $timeout = '' ) { |
|
| 72 | - self::__construct( $server, $timeout ); |
|
| 71 | + public function POP3($server = '', $timeout = '') { |
|
| 72 | + self::__construct($server, $timeout); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - function update_timer () { |
|
| 76 | - if (!ini_get('safe_mode')) |
|
| 75 | + function update_timer() { |
|
| 76 | + if ( ! ini_get('safe_mode')) |
|
| 77 | 77 | set_time_limit($this->TIMEOUT); |
| 78 | 78 | return true; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - function connect ($server, $port = 110) { |
|
| 81 | + function connect($server, $port = 110) { |
|
| 82 | 82 | // Opens a socket to the specified server. Unless overridden, |
| 83 | 83 | // port defaults to 110. Returns true on success, false on fail |
| 84 | 84 | |
| 85 | 85 | // If MAILSERVER is set, override $server with it's value |
| 86 | 86 | |
| 87 | - if (!isset($port) || !$port) {$port = 110;} |
|
| 88 | - if(!empty($this->MAILSERVER)) |
|
| 87 | + if ( ! isset($port) || ! $port) {$port = 110; } |
|
| 88 | + if ( ! empty($this->MAILSERVER)) |
|
| 89 | 89 | $server = $this->MAILSERVER; |
| 90 | 90 | |
| 91 | - if(empty($server)){ |
|
| 92 | - $this->ERROR = "POP3 connect: " . _("No server specified"); |
|
| 91 | + if (empty($server)) { |
|
| 92 | + $this->ERROR = "POP3 connect: "._("No server specified"); |
|
| 93 | 93 | unset($this->FP); |
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $fp = @fsockopen("$server", $port, $errno, $errstr); |
| 98 | 98 | |
| 99 | - if(!$fp) { |
|
| 100 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]"; |
|
| 99 | + if ( ! $fp) { |
|
| 100 | + $this->ERROR = "POP3 connect: "._("Error ")."[$errno] [$errstr]"; |
|
| 101 | 101 | unset($this->FP); |
| 102 | 102 | return false; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - socket_set_blocking($fp,-1); |
|
| 105 | + socket_set_blocking($fp, -1); |
|
| 106 | 106 | $this->update_timer(); |
| 107 | - $reply = fgets($fp,$this->BUFFER); |
|
| 107 | + $reply = fgets($fp, $this->BUFFER); |
|
| 108 | 108 | $reply = $this->strip_clf($reply); |
| 109 | - if($this->DEBUG) |
|
| 110 | - error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 111 | - if(!$this->is_ok($reply)) { |
|
| 112 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]"; |
|
| 109 | + if ($this->DEBUG) |
|
| 110 | + error_log("POP3 SEND [connect: $server] GOT [$reply]", 0); |
|
| 111 | + if ( ! $this->is_ok($reply)) { |
|
| 112 | + $this->ERROR = "POP3 connect: "._("Error ")."[$reply]"; |
|
| 113 | 113 | unset($this->FP); |
| 114 | 114 | return false; |
| 115 | 115 | } |
@@ -118,39 +118,39 @@ discard block |
||
| 118 | 118 | return true; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - function user ($user = "") { |
|
| 121 | + function user($user = "") { |
|
| 122 | 122 | // Sends the USER command, returns true or false |
| 123 | 123 | |
| 124 | - if( empty($user) ) { |
|
| 125 | - $this->ERROR = "POP3 user: " . _("no login ID submitted"); |
|
| 124 | + if (empty($user)) { |
|
| 125 | + $this->ERROR = "POP3 user: "._("no login ID submitted"); |
|
| 126 | 126 | return false; |
| 127 | - } elseif(!isset($this->FP)) { |
|
| 128 | - $this->ERROR = "POP3 user: " . _("connection not established"); |
|
| 127 | + } elseif ( ! isset($this->FP)) { |
|
| 128 | + $this->ERROR = "POP3 user: "._("connection not established"); |
|
| 129 | 129 | return false; |
| 130 | 130 | } else { |
| 131 | 131 | $reply = $this->send_cmd("USER $user"); |
| 132 | - if(!$this->is_ok($reply)) { |
|
| 133 | - $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]"; |
|
| 132 | + if ( ! $this->is_ok($reply)) { |
|
| 133 | + $this->ERROR = "POP3 user: "._("Error ")."[$reply]"; |
|
| 134 | 134 | return false; |
| 135 | 135 | } else |
| 136 | 136 | return true; |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - function pass ($pass = "") { |
|
| 140 | + function pass($pass = "") { |
|
| 141 | 141 | // Sends the PASS command, returns # of msgs in mailbox, |
| 142 | 142 | // returns false (undef) on Auth failure |
| 143 | 143 | |
| 144 | - if(empty($pass)) { |
|
| 145 | - $this->ERROR = "POP3 pass: " . _("No password submitted"); |
|
| 144 | + if (empty($pass)) { |
|
| 145 | + $this->ERROR = "POP3 pass: "._("No password submitted"); |
|
| 146 | 146 | return false; |
| 147 | - } elseif(!isset($this->FP)) { |
|
| 148 | - $this->ERROR = "POP3 pass: " . _("connection not established"); |
|
| 147 | + } elseif ( ! isset($this->FP)) { |
|
| 148 | + $this->ERROR = "POP3 pass: "._("connection not established"); |
|
| 149 | 149 | return false; |
| 150 | 150 | } else { |
| 151 | 151 | $reply = $this->send_cmd("PASS $pass"); |
| 152 | - if(!$this->is_ok($reply)) { |
|
| 153 | - $this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]"; |
|
| 152 | + if ( ! $this->is_ok($reply)) { |
|
| 153 | + $this->ERROR = "POP3 pass: "._("Authentication failed")." [$reply]"; |
|
| 154 | 154 | $this->quit(); |
| 155 | 155 | return false; |
| 156 | 156 | } else { |
@@ -162,29 +162,29 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - function apop ($login,$pass) { |
|
| 165 | + function apop($login, $pass) { |
|
| 166 | 166 | // Attempts an APOP login. If this fails, it'll |
| 167 | 167 | // try a standard login. YOUR SERVER MUST SUPPORT |
| 168 | 168 | // THE USE OF THE APOP COMMAND! |
| 169 | 169 | // (apop is optional per rfc1939) |
| 170 | 170 | |
| 171 | - if(!isset($this->FP)) { |
|
| 172 | - $this->ERROR = "POP3 apop: " . _("No connection to server"); |
|
| 171 | + if ( ! isset($this->FP)) { |
|
| 172 | + $this->ERROR = "POP3 apop: "._("No connection to server"); |
|
| 173 | 173 | return false; |
| 174 | - } elseif(!$this->ALLOWAPOP) { |
|
| 175 | - $retVal = $this->login($login,$pass); |
|
| 174 | + } elseif ( ! $this->ALLOWAPOP) { |
|
| 175 | + $retVal = $this->login($login, $pass); |
|
| 176 | 176 | return $retVal; |
| 177 | - } elseif(empty($login)) { |
|
| 178 | - $this->ERROR = "POP3 apop: " . _("No login ID submitted"); |
|
| 177 | + } elseif (empty($login)) { |
|
| 178 | + $this->ERROR = "POP3 apop: "._("No login ID submitted"); |
|
| 179 | 179 | return false; |
| 180 | - } elseif(empty($pass)) { |
|
| 181 | - $this->ERROR = "POP3 apop: " . _("No password submitted"); |
|
| 180 | + } elseif (empty($pass)) { |
|
| 181 | + $this->ERROR = "POP3 apop: "._("No password submitted"); |
|
| 182 | 182 | return false; |
| 183 | 183 | } else { |
| 184 | 184 | $banner = $this->BANNER; |
| 185 | - if( (!$banner) or (empty($banner)) ) { |
|
| 186 | - $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort"); |
|
| 187 | - $retVal = $this->login($login,$pass); |
|
| 185 | + if (( ! $banner) or (empty($banner))) { |
|
| 186 | + $this->ERROR = "POP3 apop: "._("No server banner").' - '._("abort"); |
|
| 187 | + $retVal = $this->login($login, $pass); |
|
| 188 | 188 | return $retVal; |
| 189 | 189 | } else { |
| 190 | 190 | $AuthString = $banner; |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | $APOPString = md5($AuthString); |
| 193 | 193 | $cmd = "APOP $login $APOPString"; |
| 194 | 194 | $reply = $this->send_cmd($cmd); |
| 195 | - if(!$this->is_ok($reply)) { |
|
| 196 | - $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort"); |
|
| 197 | - $retVal = $this->login($login,$pass); |
|
| 195 | + if ( ! $this->is_ok($reply)) { |
|
| 196 | + $this->ERROR = "POP3 apop: "._("apop authentication failed").' - '._("abort"); |
|
| 197 | + $retVal = $this->login($login, $pass); |
|
| 198 | 198 | return $retVal; |
| 199 | 199 | } else { |
| 200 | 200 | // Auth successful. |
@@ -206,22 +206,22 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - function login ($login = "", $pass = "") { |
|
| 209 | + function login($login = "", $pass = "") { |
|
| 210 | 210 | // Sends both user and pass. Returns # of msgs in mailbox or |
| 211 | 211 | // false on failure (or -1, if the error occurs while getting |
| 212 | 212 | // the number of messages.) |
| 213 | 213 | |
| 214 | - if( !isset($this->FP) ) { |
|
| 215 | - $this->ERROR = "POP3 login: " . _("No connection to server"); |
|
| 214 | + if ( ! isset($this->FP)) { |
|
| 215 | + $this->ERROR = "POP3 login: "._("No connection to server"); |
|
| 216 | 216 | return false; |
| 217 | 217 | } else { |
| 218 | 218 | $fp = $this->FP; |
| 219 | - if( !$this->user( $login ) ) { |
|
| 219 | + if ( ! $this->user($login)) { |
|
| 220 | 220 | // Preserve the error generated by user() |
| 221 | 221 | return false; |
| 222 | 222 | } else { |
| 223 | 223 | $count = $this->pass($pass); |
| 224 | - if( (!$count) || ($count == -1) ) { |
|
| 224 | + if (( ! $count) || ($count == -1)) { |
|
| 225 | 225 | // Preserve the error generated by last() and pass() |
| 226 | 226 | return false; |
| 227 | 227 | } else |
@@ -230,14 +230,14 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - function top ($msgNum, $numLines = "0") { |
|
| 233 | + function top($msgNum, $numLines = "0") { |
|
| 234 | 234 | // Gets the header and first $numLines of the msg body |
| 235 | 235 | // returns data in an array with each returned line being |
| 236 | 236 | // an array element. If $numLines is empty, returns |
| 237 | 237 | // only the header information, and none of the body. |
| 238 | 238 | |
| 239 | - if(!isset($this->FP)) { |
|
| 240 | - $this->ERROR = "POP3 top: " . _("No connection to server"); |
|
| 239 | + if ( ! isset($this->FP)) { |
|
| 240 | + $this->ERROR = "POP3 top: "._("No connection to server"); |
|
| 241 | 241 | return false; |
| 242 | 242 | } |
| 243 | 243 | $this->update_timer(); |
@@ -248,94 +248,94 @@ discard block |
||
| 248 | 248 | fwrite($fp, "TOP $msgNum $numLines\r\n"); |
| 249 | 249 | $reply = fgets($fp, $buffer); |
| 250 | 250 | $reply = $this->strip_clf($reply); |
| 251 | - if($this->DEBUG) { |
|
| 252 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 251 | + if ($this->DEBUG) { |
|
| 252 | + @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); |
|
| 253 | 253 | } |
| 254 | - if(!$this->is_ok($reply)) |
|
| 254 | + if ( ! $this->is_ok($reply)) |
|
| 255 | 255 | { |
| 256 | - $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]"; |
|
| 256 | + $this->ERROR = "POP3 top: "._("Error ")."[$reply]"; |
|
| 257 | 257 | return false; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | $count = 0; |
| 261 | 261 | $MsgArray = array(); |
| 262 | 262 | |
| 263 | - $line = fgets($fp,$buffer); |
|
| 264 | - while ( !preg_match('/^\.\r\n/',$line)) |
|
| 263 | + $line = fgets($fp, $buffer); |
|
| 264 | + while ( ! preg_match('/^\.\r\n/', $line)) |
|
| 265 | 265 | { |
| 266 | 266 | $MsgArray[$count] = $line; |
| 267 | 267 | $count++; |
| 268 | - $line = fgets($fp,$buffer); |
|
| 269 | - if(empty($line)) { break; } |
|
| 268 | + $line = fgets($fp, $buffer); |
|
| 269 | + if (empty($line)) { break; } |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | return $MsgArray; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - function pop_list ($msgNum = "") { |
|
| 275 | + function pop_list($msgNum = "") { |
|
| 276 | 276 | // If called with an argument, returns that msgs' size in octets |
| 277 | 277 | // No argument returns an associative array of undeleted |
| 278 | 278 | // msg numbers and their sizes in octets |
| 279 | 279 | |
| 280 | - if(!isset($this->FP)) |
|
| 280 | + if ( ! isset($this->FP)) |
|
| 281 | 281 | { |
| 282 | - $this->ERROR = "POP3 pop_list: " . _("No connection to server"); |
|
| 282 | + $this->ERROR = "POP3 pop_list: "._("No connection to server"); |
|
| 283 | 283 | return false; |
| 284 | 284 | } |
| 285 | 285 | $fp = $this->FP; |
| 286 | 286 | $Total = $this->COUNT; |
| 287 | - if( (!$Total) or ($Total == -1) ) |
|
| 287 | + if (( ! $Total) or ($Total == -1)) |
|
| 288 | 288 | { |
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | - if($Total == 0) |
|
| 291 | + if ($Total == 0) |
|
| 292 | 292 | { |
| 293 | - return array("0","0"); |
|
| 293 | + return array("0", "0"); |
|
| 294 | 294 | // return -1; // mailbox empty |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | $this->update_timer(); |
| 298 | 298 | |
| 299 | - if(!empty($msgNum)) |
|
| 299 | + if ( ! empty($msgNum)) |
|
| 300 | 300 | { |
| 301 | 301 | $cmd = "LIST $msgNum"; |
| 302 | - fwrite($fp,"$cmd\r\n"); |
|
| 303 | - $reply = fgets($fp,$this->BUFFER); |
|
| 302 | + fwrite($fp, "$cmd\r\n"); |
|
| 303 | + $reply = fgets($fp, $this->BUFFER); |
|
| 304 | 304 | $reply = $this->strip_clf($reply); |
| 305 | - if($this->DEBUG) { |
|
| 306 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 305 | + if ($this->DEBUG) { |
|
| 306 | + @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); |
|
| 307 | 307 | } |
| 308 | - if(!$this->is_ok($reply)) |
|
| 308 | + if ( ! $this->is_ok($reply)) |
|
| 309 | 309 | { |
| 310 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 310 | + $this->ERROR = "POP3 pop_list: "._("Error ")."[$reply]"; |
|
| 311 | 311 | return false; |
| 312 | 312 | } |
| 313 | - list($junk,$num,$size) = preg_split('/\s+/',$reply); |
|
| 313 | + list($junk, $num, $size) = preg_split('/\s+/', $reply); |
|
| 314 | 314 | return $size; |
| 315 | 315 | } |
| 316 | 316 | $cmd = "LIST"; |
| 317 | 317 | $reply = $this->send_cmd($cmd); |
| 318 | - if(!$this->is_ok($reply)) |
|
| 318 | + if ( ! $this->is_ok($reply)) |
|
| 319 | 319 | { |
| 320 | 320 | $reply = $this->strip_clf($reply); |
| 321 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 321 | + $this->ERROR = "POP3 pop_list: "._("Error ")."[$reply]"; |
|
| 322 | 322 | return false; |
| 323 | 323 | } |
| 324 | 324 | $MsgArray = array(); |
| 325 | 325 | $MsgArray[0] = $Total; |
| 326 | - for($msgC=1;$msgC <= $Total; $msgC++) |
|
| 326 | + for ($msgC = 1; $msgC <= $Total; $msgC++) |
|
| 327 | 327 | { |
| 328 | - if($msgC > $Total) { break; } |
|
| 329 | - $line = fgets($fp,$this->BUFFER); |
|
| 328 | + if ($msgC > $Total) { break; } |
|
| 329 | + $line = fgets($fp, $this->BUFFER); |
|
| 330 | 330 | $line = $this->strip_clf($line); |
| 331 | - if(strpos($line, '.') === 0) |
|
| 331 | + if (strpos($line, '.') === 0) |
|
| 332 | 332 | { |
| 333 | - $this->ERROR = "POP3 pop_list: " . _("Premature end of list"); |
|
| 333 | + $this->ERROR = "POP3 pop_list: "._("Premature end of list"); |
|
| 334 | 334 | return false; |
| 335 | 335 | } |
| 336 | - list($thisMsg,$msgSize) = preg_split('/\s+/',$line); |
|
| 337 | - settype($thisMsg,"integer"); |
|
| 338 | - if($thisMsg != $msgC) |
|
| 336 | + list($thisMsg, $msgSize) = preg_split('/\s+/', $line); |
|
| 337 | + settype($thisMsg, "integer"); |
|
| 338 | + if ($thisMsg != $msgC) |
|
| 339 | 339 | { |
| 340 | 340 | $MsgArray[$msgC] = "deleted"; |
| 341 | 341 | } |
@@ -347,13 +347,13 @@ discard block |
||
| 347 | 347 | return $MsgArray; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - function get ($msgNum) { |
|
| 350 | + function get($msgNum) { |
|
| 351 | 351 | // Retrieve the specified msg number. Returns an array |
| 352 | 352 | // where each line of the msg is an array element. |
| 353 | 353 | |
| 354 | - if(!isset($this->FP)) |
|
| 354 | + if ( ! isset($this->FP)) |
|
| 355 | 355 | { |
| 356 | - $this->ERROR = "POP3 get: " . _("No connection to server"); |
|
| 356 | + $this->ERROR = "POP3 get: "._("No connection to server"); |
|
| 357 | 357 | return false; |
| 358 | 358 | } |
| 359 | 359 | |
@@ -364,83 +364,83 @@ discard block |
||
| 364 | 364 | $cmd = "RETR $msgNum"; |
| 365 | 365 | $reply = $this->send_cmd($cmd); |
| 366 | 366 | |
| 367 | - if(!$this->is_ok($reply)) |
|
| 367 | + if ( ! $this->is_ok($reply)) |
|
| 368 | 368 | { |
| 369 | - $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]"; |
|
| 369 | + $this->ERROR = "POP3 get: "._("Error ")."[$reply]"; |
|
| 370 | 370 | return false; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $count = 0; |
| 374 | 374 | $MsgArray = array(); |
| 375 | 375 | |
| 376 | - $line = fgets($fp,$buffer); |
|
| 377 | - while ( !preg_match('/^\.\r\n/',$line)) |
|
| 376 | + $line = fgets($fp, $buffer); |
|
| 377 | + while ( ! preg_match('/^\.\r\n/', $line)) |
|
| 378 | 378 | { |
| 379 | - if ( $line{0} == '.' ) { $line = substr($line,1); } |
|
| 379 | + if ($line{0} == '.') { $line = substr($line, 1); } |
|
| 380 | 380 | $MsgArray[$count] = $line; |
| 381 | 381 | $count++; |
| 382 | - $line = fgets($fp,$buffer); |
|
| 383 | - if(empty($line)) { break; } |
|
| 382 | + $line = fgets($fp, $buffer); |
|
| 383 | + if (empty($line)) { break; } |
|
| 384 | 384 | } |
| 385 | 385 | return $MsgArray; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - function last ( $type = "count" ) { |
|
| 388 | + function last($type = "count") { |
|
| 389 | 389 | // Returns the highest msg number in the mailbox. |
| 390 | 390 | // returns -1 on error, 0+ on success, if type != count |
| 391 | 391 | // results in a popstat() call (2 element array returned) |
| 392 | 392 | |
| 393 | 393 | $last = -1; |
| 394 | - if(!isset($this->FP)) |
|
| 394 | + if ( ! isset($this->FP)) |
|
| 395 | 395 | { |
| 396 | - $this->ERROR = "POP3 last: " . _("No connection to server"); |
|
| 396 | + $this->ERROR = "POP3 last: "._("No connection to server"); |
|
| 397 | 397 | return $last; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | $reply = $this->send_cmd("STAT"); |
| 401 | - if(!$this->is_ok($reply)) |
|
| 401 | + if ( ! $this->is_ok($reply)) |
|
| 402 | 402 | { |
| 403 | - $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]"; |
|
| 403 | + $this->ERROR = "POP3 last: "._("Error ")."[$reply]"; |
|
| 404 | 404 | return $last; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - $Vars = preg_split('/\s+/',$reply); |
|
| 407 | + $Vars = preg_split('/\s+/', $reply); |
|
| 408 | 408 | $count = $Vars[1]; |
| 409 | 409 | $size = $Vars[2]; |
| 410 | - settype($count,"integer"); |
|
| 411 | - settype($size,"integer"); |
|
| 412 | - if($type != "count") |
|
| 410 | + settype($count, "integer"); |
|
| 411 | + settype($size, "integer"); |
|
| 412 | + if ($type != "count") |
|
| 413 | 413 | { |
| 414 | - return array($count,$size); |
|
| 414 | + return array($count, $size); |
|
| 415 | 415 | } |
| 416 | 416 | return $count; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - function reset () { |
|
| 419 | + function reset() { |
|
| 420 | 420 | // Resets the status of the remote server. This includes |
| 421 | 421 | // resetting the status of ALL msgs to not be deleted. |
| 422 | 422 | // This method automatically closes the connection to the server. |
| 423 | 423 | |
| 424 | - if(!isset($this->FP)) |
|
| 424 | + if ( ! isset($this->FP)) |
|
| 425 | 425 | { |
| 426 | - $this->ERROR = "POP3 reset: " . _("No connection to server"); |
|
| 426 | + $this->ERROR = "POP3 reset: "._("No connection to server"); |
|
| 427 | 427 | return false; |
| 428 | 428 | } |
| 429 | 429 | $reply = $this->send_cmd("RSET"); |
| 430 | - if(!$this->is_ok($reply)) |
|
| 430 | + if ( ! $this->is_ok($reply)) |
|
| 431 | 431 | { |
| 432 | 432 | // The POP3 RSET command -never- gives a -ERR |
| 433 | 433 | // response - if it ever does, something truely |
| 434 | 434 | // wild is going on. |
| 435 | 435 | |
| 436 | - $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]"; |
|
| 437 | - @error_log("POP3 reset: ERROR [$reply]",0); |
|
| 436 | + $this->ERROR = "POP3 reset: "._("Error ")."[$reply]"; |
|
| 437 | + @error_log("POP3 reset: ERROR [$reply]", 0); |
|
| 438 | 438 | } |
| 439 | 439 | $this->quit(); |
| 440 | 440 | return true; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - function send_cmd ( $cmd = "" ) |
|
| 443 | + function send_cmd($cmd = "") |
|
| 444 | 444 | { |
| 445 | 445 | // Sends a user defined command string to the |
| 446 | 446 | // POP server and returns the results. Useful for |
@@ -455,25 +455,25 @@ discard block |
||
| 455 | 455 | // This method works best if $cmd responds with only |
| 456 | 456 | // one line of data. |
| 457 | 457 | |
| 458 | - if(!isset($this->FP)) |
|
| 458 | + if ( ! isset($this->FP)) |
|
| 459 | 459 | { |
| 460 | - $this->ERROR = "POP3 send_cmd: " . _("No connection to server"); |
|
| 460 | + $this->ERROR = "POP3 send_cmd: "._("No connection to server"); |
|
| 461 | 461 | return false; |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - if(empty($cmd)) |
|
| 464 | + if (empty($cmd)) |
|
| 465 | 465 | { |
| 466 | - $this->ERROR = "POP3 send_cmd: " . _("Empty command string"); |
|
| 466 | + $this->ERROR = "POP3 send_cmd: "._("Empty command string"); |
|
| 467 | 467 | return ""; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | $fp = $this->FP; |
| 471 | 471 | $buffer = $this->BUFFER; |
| 472 | 472 | $this->update_timer(); |
| 473 | - fwrite($fp,"$cmd\r\n"); |
|
| 474 | - $reply = fgets($fp,$buffer); |
|
| 473 | + fwrite($fp, "$cmd\r\n"); |
|
| 474 | + $reply = fgets($fp, $buffer); |
|
| 475 | 475 | $reply = $this->strip_clf($reply); |
| 476 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 476 | + if ($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); } |
|
| 477 | 477 | return $reply; |
| 478 | 478 | } |
| 479 | 479 | |
@@ -481,61 +481,61 @@ discard block |
||
| 481 | 481 | // Closes the connection to the POP3 server, deleting |
| 482 | 482 | // any msgs marked as deleted. |
| 483 | 483 | |
| 484 | - if(!isset($this->FP)) |
|
| 484 | + if ( ! isset($this->FP)) |
|
| 485 | 485 | { |
| 486 | - $this->ERROR = "POP3 quit: " . _("connection does not exist"); |
|
| 486 | + $this->ERROR = "POP3 quit: "._("connection does not exist"); |
|
| 487 | 487 | return false; |
| 488 | 488 | } |
| 489 | 489 | $fp = $this->FP; |
| 490 | 490 | $cmd = "QUIT"; |
| 491 | - fwrite($fp,"$cmd\r\n"); |
|
| 492 | - $reply = fgets($fp,$this->BUFFER); |
|
| 491 | + fwrite($fp, "$cmd\r\n"); |
|
| 492 | + $reply = fgets($fp, $this->BUFFER); |
|
| 493 | 493 | $reply = $this->strip_clf($reply); |
| 494 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 494 | + if ($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); } |
|
| 495 | 495 | fclose($fp); |
| 496 | 496 | unset($this->FP); |
| 497 | 497 | return true; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - function popstat () { |
|
| 500 | + function popstat() { |
|
| 501 | 501 | // Returns an array of 2 elements. The number of undeleted |
| 502 | 502 | // msgs in the mailbox, and the size of the mbox in octets. |
| 503 | 503 | |
| 504 | 504 | $PopArray = $this->last("array"); |
| 505 | 505 | |
| 506 | - if($PopArray == -1) { return false; } |
|
| 506 | + if ($PopArray == -1) { return false; } |
|
| 507 | 507 | |
| 508 | - if( (!$PopArray) or (empty($PopArray)) ) |
|
| 508 | + if (( ! $PopArray) or (empty($PopArray))) |
|
| 509 | 509 | { |
| 510 | 510 | return false; |
| 511 | 511 | } |
| 512 | 512 | return $PopArray; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - function uidl ($msgNum = "") |
|
| 515 | + function uidl($msgNum = "") |
|
| 516 | 516 | { |
| 517 | 517 | // Returns the UIDL of the msg specified. If called with |
| 518 | 518 | // no arguments, returns an associative array where each |
| 519 | 519 | // undeleted msg num is a key, and the msg's uidl is the element |
| 520 | 520 | // Array element 0 will contain the total number of msgs |
| 521 | 521 | |
| 522 | - if(!isset($this->FP)) { |
|
| 523 | - $this->ERROR = "POP3 uidl: " . _("No connection to server"); |
|
| 522 | + if ( ! isset($this->FP)) { |
|
| 523 | + $this->ERROR = "POP3 uidl: "._("No connection to server"); |
|
| 524 | 524 | return false; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | $fp = $this->FP; |
| 528 | 528 | $buffer = $this->BUFFER; |
| 529 | 529 | |
| 530 | - if(!empty($msgNum)) { |
|
| 530 | + if ( ! empty($msgNum)) { |
|
| 531 | 531 | $cmd = "UIDL $msgNum"; |
| 532 | 532 | $reply = $this->send_cmd($cmd); |
| 533 | - if(!$this->is_ok($reply)) |
|
| 533 | + if ( ! $this->is_ok($reply)) |
|
| 534 | 534 | { |
| 535 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 535 | + $this->ERROR = "POP3 uidl: "._("Error ")."[$reply]"; |
|
| 536 | 536 | return false; |
| 537 | 537 | } |
| 538 | - list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply); |
|
| 538 | + list ($ok, $num, $myUidl) = preg_split('/\s+/', $reply); |
|
| 539 | 539 | return $myUidl; |
| 540 | 540 | } else { |
| 541 | 541 | $this->update_timer(); |
@@ -552,20 +552,20 @@ discard block |
||
| 552 | 552 | fwrite($fp, "UIDL\r\n"); |
| 553 | 553 | $reply = fgets($fp, $buffer); |
| 554 | 554 | $reply = $this->strip_clf($reply); |
| 555 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 556 | - if(!$this->is_ok($reply)) |
|
| 555 | + if ($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); } |
|
| 556 | + if ( ! $this->is_ok($reply)) |
|
| 557 | 557 | { |
| 558 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 558 | + $this->ERROR = "POP3 uidl: "._("Error ")."[$reply]"; |
|
| 559 | 559 | return false; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | $line = ""; |
| 563 | 563 | $count = 1; |
| 564 | - $line = fgets($fp,$buffer); |
|
| 565 | - while ( !preg_match('/^\.\r\n/',$line)) { |
|
| 566 | - list ($msg,$msgUidl) = preg_split('/\s+/',$line); |
|
| 564 | + $line = fgets($fp, $buffer); |
|
| 565 | + while ( ! preg_match('/^\.\r\n/', $line)) { |
|
| 566 | + list ($msg, $msgUidl) = preg_split('/\s+/', $line); |
|
| 567 | 567 | $msgUidl = $this->strip_clf($msgUidl); |
| 568 | - if($count == $msg) { |
|
| 568 | + if ($count == $msg) { |
|
| 569 | 569 | $UIDLArray[$msg] = $msgUidl; |
| 570 | 570 | } |
| 571 | 571 | else |
@@ -573,30 +573,30 @@ discard block |
||
| 573 | 573 | $UIDLArray[$count] = 'deleted'; |
| 574 | 574 | } |
| 575 | 575 | $count++; |
| 576 | - $line = fgets($fp,$buffer); |
|
| 576 | + $line = fgets($fp, $buffer); |
|
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | 579 | return $UIDLArray; |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - function delete ($msgNum = "") { |
|
| 582 | + function delete($msgNum = "") { |
|
| 583 | 583 | // Flags a specified msg as deleted. The msg will not |
| 584 | 584 | // be deleted until a quit() method is called. |
| 585 | 585 | |
| 586 | - if(!isset($this->FP)) |
|
| 586 | + if ( ! isset($this->FP)) |
|
| 587 | 587 | { |
| 588 | - $this->ERROR = "POP3 delete: " . _("No connection to server"); |
|
| 588 | + $this->ERROR = "POP3 delete: "._("No connection to server"); |
|
| 589 | 589 | return false; |
| 590 | 590 | } |
| 591 | - if(empty($msgNum)) |
|
| 591 | + if (empty($msgNum)) |
|
| 592 | 592 | { |
| 593 | - $this->ERROR = "POP3 delete: " . _("No msg number submitted"); |
|
| 593 | + $this->ERROR = "POP3 delete: "._("No msg number submitted"); |
|
| 594 | 594 | return false; |
| 595 | 595 | } |
| 596 | 596 | $reply = $this->send_cmd("DELE $msgNum"); |
| 597 | - if(!$this->is_ok($reply)) |
|
| 597 | + if ( ! $this->is_ok($reply)) |
|
| 598 | 598 | { |
| 599 | - $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]"; |
|
| 599 | + $this->ERROR = "POP3 delete: "._("Command failed ")."[$reply]"; |
|
| 600 | 600 | return false; |
| 601 | 601 | } |
| 602 | 602 | return true; |
@@ -606,35 +606,35 @@ discard block |
||
| 606 | 606 | |
| 607 | 607 | // The following methods are internal to the class. |
| 608 | 608 | |
| 609 | - function is_ok ($cmd = "") { |
|
| 609 | + function is_ok($cmd = "") { |
|
| 610 | 610 | // Return true or false on +OK or -ERR |
| 611 | 611 | |
| 612 | - if( empty($cmd) ) |
|
| 612 | + if (empty($cmd)) |
|
| 613 | 613 | return false; |
| 614 | 614 | else |
| 615 | - return( stripos($cmd, '+OK') !== false ); |
|
| 615 | + return(stripos($cmd, '+OK') !== false); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - function strip_clf ($text = "") { |
|
| 618 | + function strip_clf($text = "") { |
|
| 619 | 619 | // Strips \r\n from server responses |
| 620 | 620 | |
| 621 | - if(empty($text)) |
|
| 621 | + if (empty($text)) |
|
| 622 | 622 | return $text; |
| 623 | 623 | else { |
| 624 | - $stripped = str_replace(array("\r","\n"),'',$text); |
|
| 624 | + $stripped = str_replace(array("\r", "\n"), '', $text); |
|
| 625 | 625 | return $stripped; |
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - function parse_banner ( $server_text ) { |
|
| 629 | + function parse_banner($server_text) { |
|
| 630 | 630 | $outside = true; |
| 631 | 631 | $banner = ""; |
| 632 | 632 | $length = strlen($server_text); |
| 633 | - for($count =0; $count < $length; $count++) |
|
| 633 | + for ($count = 0; $count < $length; $count++) |
|
| 634 | 634 | { |
| 635 | - $digit = substr($server_text,$count,1); |
|
| 636 | - if(!empty($digit)) { |
|
| 637 | - if( (!$outside) && ($digit != '<') && ($digit != '>') ) |
|
| 635 | + $digit = substr($server_text, $count, 1); |
|
| 636 | + if ( ! empty($digit)) { |
|
| 637 | + if (( ! $outside) && ($digit != '<') && ($digit != '>')) |
|
| 638 | 638 | { |
| 639 | 639 | $banner .= $digit; |
| 640 | 640 | } |
@@ -642,21 +642,21 @@ discard block |
||
| 642 | 642 | { |
| 643 | 643 | $outside = false; |
| 644 | 644 | } |
| 645 | - if($digit == '>') |
|
| 645 | + if ($digit == '>') |
|
| 646 | 646 | { |
| 647 | 647 | $outside = true; |
| 648 | 648 | } |
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | - $banner = $this->strip_clf($banner); // Just in case |
|
| 651 | + $banner = $this->strip_clf($banner); // Just in case |
|
| 652 | 652 | return "<$banner>"; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | } // End class |
| 656 | 656 | |
| 657 | 657 | // For php4 compatibility |
| 658 | -if (!function_exists("stripos")) { |
|
| 659 | - function stripos($haystack, $needle){ |
|
| 660 | - return strpos($haystack, stristr( $haystack, $needle )); |
|
| 658 | +if ( ! function_exists("stripos")) { |
|
| 659 | + function stripos($haystack, $needle) { |
|
| 660 | + return strpos($haystack, stristr($haystack, $needle)); |
|
| 661 | 661 | } |
| 662 | 662 | } |
@@ -53,14 +53,16 @@ discard block |
||
| 53 | 53 | // Do not allow programs to alter MAILSERVER |
| 54 | 54 | // if it is already specified. They can get around |
| 55 | 55 | // this if they -really- want to, so don't count on it. |
| 56 | - if(empty($this->MAILSERVER)) |
|
| 57 | - $this->MAILSERVER = $server; |
|
| 56 | + if(empty($this->MAILSERVER)) { |
|
| 57 | + $this->MAILSERVER = $server; |
|
| 58 | + } |
|
| 58 | 59 | } |
| 59 | 60 | if(!empty($timeout)) { |
| 60 | 61 | settype($timeout,"integer"); |
| 61 | 62 | $this->TIMEOUT = $timeout; |
| 62 | - if (!ini_get('safe_mode')) |
|
| 63 | - set_time_limit($timeout); |
|
| 63 | + if (!ini_get('safe_mode')) { |
|
| 64 | + set_time_limit($timeout); |
|
| 65 | + } |
|
| 64 | 66 | } |
| 65 | 67 | return true; |
| 66 | 68 | } |
@@ -73,8 +75,9 @@ discard block |
||
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | function update_timer () { |
| 76 | - if (!ini_get('safe_mode')) |
|
| 77 | - set_time_limit($this->TIMEOUT); |
|
| 78 | + if (!ini_get('safe_mode')) { |
|
| 79 | + set_time_limit($this->TIMEOUT); |
|
| 80 | + } |
|
| 78 | 81 | return true; |
| 79 | 82 | } |
| 80 | 83 | |
@@ -85,8 +88,9 @@ discard block |
||
| 85 | 88 | // If MAILSERVER is set, override $server with it's value |
| 86 | 89 | |
| 87 | 90 | if (!isset($port) || !$port) {$port = 110;} |
| 88 | - if(!empty($this->MAILSERVER)) |
|
| 89 | - $server = $this->MAILSERVER; |
|
| 91 | + if(!empty($this->MAILSERVER)) { |
|
| 92 | + $server = $this->MAILSERVER; |
|
| 93 | + } |
|
| 90 | 94 | |
| 91 | 95 | if(empty($server)){ |
| 92 | 96 | $this->ERROR = "POP3 connect: " . _("No server specified"); |
@@ -106,8 +110,9 @@ discard block |
||
| 106 | 110 | $this->update_timer(); |
| 107 | 111 | $reply = fgets($fp,$this->BUFFER); |
| 108 | 112 | $reply = $this->strip_clf($reply); |
| 109 | - if($this->DEBUG) |
|
| 110 | - error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 113 | + if($this->DEBUG) { |
|
| 114 | + error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 115 | + } |
|
| 111 | 116 | if(!$this->is_ok($reply)) { |
| 112 | 117 | $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]"; |
| 113 | 118 | unset($this->FP); |
@@ -132,8 +137,9 @@ discard block |
||
| 132 | 137 | if(!$this->is_ok($reply)) { |
| 133 | 138 | $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]"; |
| 134 | 139 | return false; |
| 135 | - } else |
|
| 136 | - return true; |
|
| 140 | + } else { |
|
| 141 | + return true; |
|
| 142 | + } |
|
| 137 | 143 | } |
| 138 | 144 | } |
| 139 | 145 | |
@@ -224,8 +230,9 @@ discard block |
||
| 224 | 230 | if( (!$count) || ($count == -1) ) { |
| 225 | 231 | // Preserve the error generated by last() and pass() |
| 226 | 232 | return false; |
| 227 | - } else |
|
| 228 | - return $count; |
|
| 233 | + } else { |
|
| 234 | + return $count; |
|
| 235 | + } |
|
| 229 | 236 | } |
| 230 | 237 | } |
| 231 | 238 | } |
@@ -338,8 +345,7 @@ discard block |
||
| 338 | 345 | if($thisMsg != $msgC) |
| 339 | 346 | { |
| 340 | 347 | $MsgArray[$msgC] = "deleted"; |
| 341 | - } |
|
| 342 | - else |
|
| 348 | + } else |
|
| 343 | 349 | { |
| 344 | 350 | $MsgArray[$msgC] = $msgSize; |
| 345 | 351 | } |
@@ -567,8 +573,7 @@ discard block |
||
| 567 | 573 | $msgUidl = $this->strip_clf($msgUidl); |
| 568 | 574 | if($count == $msg) { |
| 569 | 575 | $UIDLArray[$msg] = $msgUidl; |
| 570 | - } |
|
| 571 | - else |
|
| 576 | + } else |
|
| 572 | 577 | { |
| 573 | 578 | $UIDLArray[$count] = 'deleted'; |
| 574 | 579 | } |
@@ -609,18 +614,19 @@ discard block |
||
| 609 | 614 | function is_ok ($cmd = "") { |
| 610 | 615 | // Return true or false on +OK or -ERR |
| 611 | 616 | |
| 612 | - if( empty($cmd) ) |
|
| 613 | - return false; |
|
| 614 | - else |
|
| 615 | - return( stripos($cmd, '+OK') !== false ); |
|
| 617 | + if( empty($cmd) ) { |
|
| 618 | + return false; |
|
| 619 | + } else { |
|
| 620 | + return( stripos($cmd, '+OK') !== false ); |
|
| 621 | + } |
|
| 616 | 622 | } |
| 617 | 623 | |
| 618 | 624 | function strip_clf ($text = "") { |
| 619 | 625 | // Strips \r\n from server responses |
| 620 | 626 | |
| 621 | - if(empty($text)) |
|
| 622 | - return $text; |
|
| 623 | - else { |
|
| 627 | + if(empty($text)) { |
|
| 628 | + return $text; |
|
| 629 | + } else { |
|
| 624 | 630 | $stripped = str_replace(array("\r","\n"),'',$text); |
| 625 | 631 | return $stripped; |
| 626 | 632 | } |
@@ -1614,7 +1614,7 @@ discard block |
||
| 1614 | 1614 | /** |
| 1615 | 1615 | * Get the error message for the occurred error. |
| 1616 | 1616 | * |
| 1617 | - * @return string|array Error message, or array of messages for multifeeds |
|
| 1617 | + * @return string Error message, or array of messages for multifeeds |
|
| 1618 | 1618 | */ |
| 1619 | 1619 | public function error() |
| 1620 | 1620 | { |
@@ -1627,7 +1627,7 @@ discard block |
||
| 1627 | 1627 | * This is the same as the old `$feed->enable_xml_dump(true)`, but returns |
| 1628 | 1628 | * the data instead of printing it. |
| 1629 | 1629 | * |
| 1630 | - * @return string|boolean Raw XML data, false if the cache is used |
|
| 1630 | + * @return string Raw XML data, false if the cache is used |
|
| 1631 | 1631 | */ |
| 1632 | 1632 | public function get_raw_data() |
| 1633 | 1633 | { |
@@ -2607,7 +2607,7 @@ discard block |
||
| 2607 | 2607 | * @since 1.0 |
| 2608 | 2608 | * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo |
| 2609 | 2609 | * @link http://www.georss.org/ GeoRSS |
| 2610 | - * @return string|null |
|
| 2610 | + * @return double|null |
|
| 2611 | 2611 | */ |
| 2612 | 2612 | public function get_latitude() |
| 2613 | 2613 | { |
@@ -2636,7 +2636,7 @@ discard block |
||
| 2636 | 2636 | * @since 1.0 |
| 2637 | 2637 | * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo |
| 2638 | 2638 | * @link http://www.georss.org/ GeoRSS |
| 2639 | - * @return string|null |
|
| 2639 | + * @return double|null |
|
| 2640 | 2640 | */ |
| 2641 | 2641 | public function get_longitude() |
| 2642 | 2642 | { |
@@ -2778,7 +2778,7 @@ discard block |
||
| 2778 | 2778 | * Uses `<image><width>` or defaults to 88.0 if no width is specified and |
| 2779 | 2779 | * the feed is an RSS 2.0 feed. |
| 2780 | 2780 | * |
| 2781 | - * @return int|float|null |
|
| 2781 | + * @return double|null |
|
| 2782 | 2782 | */ |
| 2783 | 2783 | public function get_image_width() |
| 2784 | 2784 | { |
@@ -2804,7 +2804,7 @@ discard block |
||
| 2804 | 2804 | * Uses `<image><height>` or defaults to 31.0 if no height is specified and |
| 2805 | 2805 | * the feed is an RSS 2.0 feed. |
| 2806 | 2806 | * |
| 2807 | - * @return int|float|null |
|
| 2807 | + * @return double|null |
|
| 2808 | 2808 | */ |
| 2809 | 2809 | public function get_image_height() |
| 2810 | 2810 | { |
@@ -1,35 +1,35 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! class_exists( 'SimplePie' ) ) : |
|
| 2 | +if ( ! class_exists('SimplePie')) : |
|
| 3 | 3 | |
| 4 | 4 | // Load classes we will need. |
| 5 | -require ABSPATH . WPINC . '/SimplePie/Misc.php'; |
|
| 6 | -require ABSPATH . WPINC . '/SimplePie/Cache.php'; |
|
| 7 | -require ABSPATH . WPINC . '/SimplePie/File.php'; |
|
| 8 | -require ABSPATH . WPINC . '/SimplePie/Sanitize.php'; |
|
| 9 | -require ABSPATH . WPINC . '/SimplePie/Registry.php'; |
|
| 10 | -require ABSPATH . WPINC . '/SimplePie/IRI.php'; |
|
| 11 | -require ABSPATH . WPINC . '/SimplePie/Locator.php'; |
|
| 12 | -require ABSPATH . WPINC . '/SimplePie/Content/Type/Sniffer.php'; |
|
| 13 | -require ABSPATH . WPINC . '/SimplePie/XML/Declaration/Parser.php'; |
|
| 14 | -require ABSPATH . WPINC . '/SimplePie/Parser.php'; |
|
| 15 | -require ABSPATH . WPINC . '/SimplePie/Item.php'; |
|
| 16 | -require ABSPATH . WPINC . '/SimplePie/Parse/Date.php'; |
|
| 17 | -require ABSPATH . WPINC . '/SimplePie/Author.php'; |
|
| 5 | +require ABSPATH.WPINC.'/SimplePie/Misc.php'; |
|
| 6 | +require ABSPATH.WPINC.'/SimplePie/Cache.php'; |
|
| 7 | +require ABSPATH.WPINC.'/SimplePie/File.php'; |
|
| 8 | +require ABSPATH.WPINC.'/SimplePie/Sanitize.php'; |
|
| 9 | +require ABSPATH.WPINC.'/SimplePie/Registry.php'; |
|
| 10 | +require ABSPATH.WPINC.'/SimplePie/IRI.php'; |
|
| 11 | +require ABSPATH.WPINC.'/SimplePie/Locator.php'; |
|
| 12 | +require ABSPATH.WPINC.'/SimplePie/Content/Type/Sniffer.php'; |
|
| 13 | +require ABSPATH.WPINC.'/SimplePie/XML/Declaration/Parser.php'; |
|
| 14 | +require ABSPATH.WPINC.'/SimplePie/Parser.php'; |
|
| 15 | +require ABSPATH.WPINC.'/SimplePie/Item.php'; |
|
| 16 | +require ABSPATH.WPINC.'/SimplePie/Parse/Date.php'; |
|
| 17 | +require ABSPATH.WPINC.'/SimplePie/Author.php'; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * WordPress autoloader for SimplePie. |
| 21 | 21 | * |
| 22 | 22 | * @since 3.5.0 |
| 23 | 23 | */ |
| 24 | -function wp_simplepie_autoload( $class ) { |
|
| 25 | - if ( 0 !== strpos( $class, 'SimplePie_' ) ) |
|
| 24 | +function wp_simplepie_autoload($class) { |
|
| 25 | + if (0 !== strpos($class, 'SimplePie_')) |
|
| 26 | 26 | return; |
| 27 | 27 | |
| 28 | - $file = ABSPATH . WPINC . '/' . str_replace( '_', '/', $class ) . '.php'; |
|
| 29 | - include( $file ); |
|
| 28 | + $file = ABSPATH.WPINC.'/'.str_replace('_', '/', $class).'.php'; |
|
| 29 | + include($file); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | -if ( function_exists( 'spl_autoload_register' ) ) { |
|
| 32 | +if (function_exists('spl_autoload_register')) { |
|
| 33 | 33 | /** |
| 34 | 34 | * We autoload classes we may not need. |
| 35 | 35 | * |
@@ -38,25 +38,25 @@ discard block |
||
| 38 | 38 | * Core.php is not loaded manually, because SimplePie_Core (a deprecated class) |
| 39 | 39 | * was never included in WordPress core. |
| 40 | 40 | */ |
| 41 | - spl_autoload_register( 'wp_simplepie_autoload' ); |
|
| 41 | + spl_autoload_register('wp_simplepie_autoload'); |
|
| 42 | 42 | } else { |
| 43 | - require ABSPATH . WPINC . '/SimplePie/Cache/Base.php'; |
|
| 44 | - require ABSPATH . WPINC . '/SimplePie/Cache/DB.php'; |
|
| 45 | - require ABSPATH . WPINC . '/SimplePie/Cache/File.php'; |
|
| 46 | - require ABSPATH . WPINC . '/SimplePie/Cache/Memcache.php'; |
|
| 47 | - require ABSPATH . WPINC . '/SimplePie/Cache/MySQL.php'; |
|
| 48 | - require ABSPATH . WPINC . '/SimplePie/Caption.php'; |
|
| 49 | - require ABSPATH . WPINC . '/SimplePie/Category.php'; |
|
| 50 | - require ABSPATH . WPINC . '/SimplePie/Copyright.php'; |
|
| 51 | - require ABSPATH . WPINC . '/SimplePie/Credit.php'; |
|
| 52 | - require ABSPATH . WPINC . '/SimplePie/Decode/HTML/Entities.php'; |
|
| 53 | - require ABSPATH . WPINC . '/SimplePie/Enclosure.php'; |
|
| 54 | - require ABSPATH . WPINC . '/SimplePie/gzdecode.php'; |
|
| 55 | - require ABSPATH . WPINC . '/SimplePie/HTTP/Parser.php'; |
|
| 56 | - require ABSPATH . WPINC . '/SimplePie/Net/IPv6.php'; |
|
| 57 | - require ABSPATH . WPINC . '/SimplePie/Rating.php'; |
|
| 58 | - require ABSPATH . WPINC . '/SimplePie/Restriction.php'; |
|
| 59 | - require ABSPATH . WPINC . '/SimplePie/Source.php'; |
|
| 43 | + require ABSPATH.WPINC.'/SimplePie/Cache/Base.php'; |
|
| 44 | + require ABSPATH.WPINC.'/SimplePie/Cache/DB.php'; |
|
| 45 | + require ABSPATH.WPINC.'/SimplePie/Cache/File.php'; |
|
| 46 | + require ABSPATH.WPINC.'/SimplePie/Cache/Memcache.php'; |
|
| 47 | + require ABSPATH.WPINC.'/SimplePie/Cache/MySQL.php'; |
|
| 48 | + require ABSPATH.WPINC.'/SimplePie/Caption.php'; |
|
| 49 | + require ABSPATH.WPINC.'/SimplePie/Category.php'; |
|
| 50 | + require ABSPATH.WPINC.'/SimplePie/Copyright.php'; |
|
| 51 | + require ABSPATH.WPINC.'/SimplePie/Credit.php'; |
|
| 52 | + require ABSPATH.WPINC.'/SimplePie/Decode/HTML/Entities.php'; |
|
| 53 | + require ABSPATH.WPINC.'/SimplePie/Enclosure.php'; |
|
| 54 | + require ABSPATH.WPINC.'/SimplePie/gzdecode.php'; |
|
| 55 | + require ABSPATH.WPINC.'/SimplePie/HTTP/Parser.php'; |
|
| 56 | + require ABSPATH.WPINC.'/SimplePie/Net/IPv6.php'; |
|
| 57 | + require ABSPATH.WPINC.'/SimplePie/Rating.php'; |
|
| 58 | + require ABSPATH.WPINC.'/SimplePie/Restriction.php'; |
|
| 59 | + require ABSPATH.WPINC.'/SimplePie/Source.php'; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -127,12 +127,12 @@ discard block |
||
| 127 | 127 | * SimplePie Useragent |
| 128 | 128 | * @see SimplePie::set_useragent() |
| 129 | 129 | */ |
| 130 | -define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD); |
|
| 130 | +define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME.'/'.SIMPLEPIE_VERSION.' (Feed Parser; '.SIMPLEPIE_URL.'; Allow like Gecko) Build/'.SIMPLEPIE_BUILD); |
|
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | 133 | * SimplePie Linkback |
| 134 | 134 | */ |
| 135 | -define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>'); |
|
| 135 | +define('SIMPLEPIE_LINKBACK', '<a href="'.SIMPLEPIE_URL.'" title="'.SIMPLEPIE_NAME.' '.SIMPLEPIE_VERSION.'">'.SIMPLEPIE_NAME.'</a>'); |
|
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * No Autodiscovery |
@@ -725,9 +725,9 @@ discard block |
||
| 725 | 725 | */ |
| 726 | 726 | public function __destruct() |
| 727 | 727 | { |
| 728 | - if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode')) |
|
| 728 | + if ((version_compare(PHP_VERSION, '5.3', '<') || ! gc_enabled()) && ! ini_get('zend.ze1_compatibility_mode')) |
|
| 729 | 729 | { |
| 730 | - if (!empty($this->data['items'])) |
|
| 730 | + if ( ! empty($this->data['items'])) |
|
| 731 | 731 | { |
| 732 | 732 | foreach ($this->data['items'] as $item) |
| 733 | 733 | { |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | } |
| 736 | 736 | unset($item, $this->data['items']); |
| 737 | 737 | } |
| 738 | - if (!empty($this->data['ordered_items'])) |
|
| 738 | + if ( ! empty($this->data['ordered_items'])) |
|
| 739 | 739 | { |
| 740 | 740 | foreach ($this->data['ordered_items'] as $item) |
| 741 | 741 | { |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | if ($file instanceof SimplePie_File) |
| 803 | 803 | { |
| 804 | 804 | $this->feed_url = $file->url; |
| 805 | - $this->file =& $file; |
|
| 805 | + $this->file = & $file; |
|
| 806 | 806 | return true; |
| 807 | 807 | } |
| 808 | 808 | return false; |
@@ -1237,7 +1237,7 @@ discard block |
||
| 1237 | 1237 | { |
| 1238 | 1238 | if ($page !== false) |
| 1239 | 1239 | { |
| 1240 | - $this->sanitize->set_image_handler($page . '?' . $qs . '='); |
|
| 1240 | + $this->sanitize->set_image_handler($page.'?'.$qs.'='); |
|
| 1241 | 1241 | } |
| 1242 | 1242 | else |
| 1243 | 1243 | { |
@@ -1267,12 +1267,12 @@ discard block |
||
| 1267 | 1267 | public function init() |
| 1268 | 1268 | { |
| 1269 | 1269 | // Check absolute bare minimum requirements. |
| 1270 | - if (!extension_loaded('xml') || !extension_loaded('pcre')) |
|
| 1270 | + if ( ! extension_loaded('xml') || ! extension_loaded('pcre')) |
|
| 1271 | 1271 | { |
| 1272 | 1272 | return false; |
| 1273 | 1273 | } |
| 1274 | 1274 | // Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader. |
| 1275 | - elseif (!extension_loaded('xmlreader')) |
|
| 1275 | + elseif ( ! extension_loaded('xmlreader')) |
|
| 1276 | 1276 | { |
| 1277 | 1277 | static $xml_is_sane = null; |
| 1278 | 1278 | if ($xml_is_sane === null) |
@@ -1282,7 +1282,7 @@ discard block |
||
| 1282 | 1282 | xml_parser_free($parser_check); |
| 1283 | 1283 | $xml_is_sane = isset($values[0]['value']); |
| 1284 | 1284 | } |
| 1285 | - if (!$xml_is_sane) |
|
| 1285 | + if ( ! $xml_is_sane) |
|
| 1286 | 1286 | { |
| 1287 | 1287 | return false; |
| 1288 | 1288 | } |
@@ -1298,7 +1298,7 @@ discard block |
||
| 1298 | 1298 | $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache')); |
| 1299 | 1299 | $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen); |
| 1300 | 1300 | |
| 1301 | - if (!empty($this->multifeed_url)) |
|
| 1301 | + if ( ! empty($this->multifeed_url)) |
|
| 1302 | 1302 | { |
| 1303 | 1303 | $i = 0; |
| 1304 | 1304 | $success = 0; |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | $this->multifeed_objects[$i]->set_feed_url($url); |
| 1311 | 1311 | $single_success = $this->multifeed_objects[$i]->init(); |
| 1312 | 1312 | $success |= $single_success; |
| 1313 | - if (!$single_success) |
|
| 1313 | + if ( ! $single_success) |
|
| 1314 | 1314 | { |
| 1315 | 1315 | $this->error[$i] = $this->multifeed_objects[$i]->error(); |
| 1316 | 1316 | } |
@@ -1410,7 +1410,7 @@ discard block |
||
| 1410 | 1410 | if ($parser->parse($utf8_data, 'UTF-8')) |
| 1411 | 1411 | { |
| 1412 | 1412 | $this->data = $parser->get_data(); |
| 1413 | - if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE)) |
|
| 1413 | + if ( ! ($this->get_type() & ~SIMPLEPIE_TYPE_NONE)) |
|
| 1414 | 1414 | { |
| 1415 | 1415 | $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed."; |
| 1416 | 1416 | $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); |
@@ -1424,7 +1424,7 @@ discard block |
||
| 1424 | 1424 | $this->data['build'] = SIMPLEPIE_BUILD; |
| 1425 | 1425 | |
| 1426 | 1426 | // Cache the file if caching is enabled |
| 1427 | - if ($cache && !$cache->save($this)) |
|
| 1427 | + if ($cache && ! $cache->save($this)) |
|
| 1428 | 1428 | { |
| 1429 | 1429 | trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); |
| 1430 | 1430 | } |
@@ -1462,10 +1462,10 @@ discard block |
||
| 1462 | 1462 | { |
| 1463 | 1463 | // Load the Cache |
| 1464 | 1464 | $this->data = $cache->load(); |
| 1465 | - if (!empty($this->data)) |
|
| 1465 | + if ( ! empty($this->data)) |
|
| 1466 | 1466 | { |
| 1467 | 1467 | // If the cache is for an outdated build of SimplePie |
| 1468 | - if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD) |
|
| 1468 | + if ( ! isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD) |
|
| 1469 | 1469 | { |
| 1470 | 1470 | $cache->unlink(); |
| 1471 | 1471 | $this->data = array(); |
@@ -1511,7 +1511,7 @@ discard block |
||
| 1511 | 1511 | $headers['if-none-match'] = $this->data['headers']['etag']; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | - $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen)); |
|
| 1514 | + $file = $this->registry->create('File', array($this->feed_url, $this->timeout / 10, 5, $headers, $this->useragent, $this->force_fsockopen)); |
|
| 1515 | 1515 | |
| 1516 | 1516 | if ($file->success) |
| 1517 | 1517 | { |
@@ -1542,11 +1542,11 @@ discard block |
||
| 1542 | 1542 | } |
| 1543 | 1543 | } |
| 1544 | 1544 | // If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it. |
| 1545 | - if (!isset($file)) |
|
| 1545 | + if ( ! isset($file)) |
|
| 1546 | 1546 | { |
| 1547 | 1547 | if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url) |
| 1548 | 1548 | { |
| 1549 | - $file =& $this->file; |
|
| 1549 | + $file = & $this->file; |
|
| 1550 | 1550 | } |
| 1551 | 1551 | else |
| 1552 | 1552 | { |
@@ -1557,26 +1557,26 @@ discard block |
||
| 1557 | 1557 | } |
| 1558 | 1558 | } |
| 1559 | 1559 | // If the file connection has an error, set SimplePie::error to that and quit |
| 1560 | - if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) |
|
| 1560 | + if ( ! $file->success && ! ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) |
|
| 1561 | 1561 | { |
| 1562 | 1562 | $this->error = $file->error; |
| 1563 | - return !empty($this->data); |
|
| 1563 | + return ! empty($this->data); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | - if (!$this->force_feed) |
|
| 1566 | + if ( ! $this->force_feed) |
|
| 1567 | 1567 | { |
| 1568 | 1568 | // Check if the supplied URL is a feed, if it isn't, look for it. |
| 1569 | 1569 | $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds)); |
| 1570 | 1570 | |
| 1571 | - if (!$locate->is_feed($file)) |
|
| 1571 | + if ( ! $locate->is_feed($file)) |
|
| 1572 | 1572 | { |
| 1573 | 1573 | // We need to unset this so that if SimplePie::set_file() has been called that object is untouched |
| 1574 | 1574 | unset($file); |
| 1575 | 1575 | try |
| 1576 | 1576 | { |
| 1577 | - if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))) |
|
| 1577 | + if ( ! ($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))) |
|
| 1578 | 1578 | { |
| 1579 | - $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed."; |
|
| 1579 | + $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or ".SIMPLEPIE_NAME." was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed."; |
|
| 1580 | 1580 | $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); |
| 1581 | 1581 | return false; |
| 1582 | 1582 | } |
@@ -1591,7 +1591,7 @@ discard block |
||
| 1591 | 1591 | if ($cache) |
| 1592 | 1592 | { |
| 1593 | 1593 | $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD); |
| 1594 | - if (!$cache->save($this)) |
|
| 1594 | + if ( ! $cache->save($this)) |
|
| 1595 | 1595 | { |
| 1596 | 1596 | trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); |
| 1597 | 1597 | } |
@@ -1666,12 +1666,12 @@ discard block |
||
| 1666 | 1666 | */ |
| 1667 | 1667 | public function handle_content_type($mime = 'text/html') |
| 1668 | 1668 | { |
| 1669 | - if (!headers_sent()) |
|
| 1669 | + if ( ! headers_sent()) |
|
| 1670 | 1670 | { |
| 1671 | 1671 | $header = "Content-type: $mime;"; |
| 1672 | 1672 | if ($this->get_encoding()) |
| 1673 | 1673 | { |
| 1674 | - $header .= ' charset=' . $this->get_encoding(); |
|
| 1674 | + $header .= ' charset='.$this->get_encoding(); |
|
| 1675 | 1675 | } |
| 1676 | 1676 | else |
| 1677 | 1677 | { |
@@ -1709,7 +1709,7 @@ discard block |
||
| 1709 | 1709 | */ |
| 1710 | 1710 | public function get_type() |
| 1711 | 1711 | { |
| 1712 | - if (!isset($this->data['type'])) |
|
| 1712 | + if ( ! isset($this->data['type'])) |
|
| 1713 | 1713 | { |
| 1714 | 1714 | $this->data['type'] = SIMPLEPIE_TYPE_ALL; |
| 1715 | 1715 | if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) |
@@ -1997,7 +1997,7 @@ discard block |
||
| 1997 | 1997 | */ |
| 1998 | 1998 | public function get_base($element = array()) |
| 1999 | 1999 | { |
| 2000 | - if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) |
|
| 2000 | + if ( ! ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && ! empty($element['xml_base_explicit']) && isset($element['xml_base'])) |
|
| 2001 | 2001 | { |
| 2002 | 2002 | return $element['xml_base']; |
| 2003 | 2003 | } |
@@ -2145,7 +2145,7 @@ discard block |
||
| 2145 | 2145 | $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); |
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | - if (!empty($categories)) |
|
| 2148 | + if ( ! empty($categories)) |
|
| 2149 | 2149 | { |
| 2150 | 2150 | return array_unique($categories); |
| 2151 | 2151 | } |
@@ -2243,7 +2243,7 @@ discard block |
||
| 2243 | 2243 | $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); |
| 2244 | 2244 | } |
| 2245 | 2245 | |
| 2246 | - if (!empty($authors)) |
|
| 2246 | + if ( ! empty($authors)) |
|
| 2247 | 2247 | { |
| 2248 | 2248 | return array_unique($authors); |
| 2249 | 2249 | } |
@@ -2329,7 +2329,7 @@ discard block |
||
| 2329 | 2329 | } |
| 2330 | 2330 | } |
| 2331 | 2331 | |
| 2332 | - if (!empty($contributors)) |
|
| 2332 | + if ( ! empty($contributors)) |
|
| 2333 | 2333 | { |
| 2334 | 2334 | return array_unique($contributors); |
| 2335 | 2335 | } |
@@ -2387,7 +2387,7 @@ discard block |
||
| 2387 | 2387 | */ |
| 2388 | 2388 | public function get_links($rel = 'alternate') |
| 2389 | 2389 | { |
| 2390 | - if (!isset($this->data['links'])) |
|
| 2390 | + if ( ! isset($this->data['links'])) |
|
| 2391 | 2391 | { |
| 2392 | 2392 | $this->data['links'] = array(); |
| 2393 | 2393 | if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) |
@@ -2431,19 +2431,19 @@ discard block |
||
| 2431 | 2431 | { |
| 2432 | 2432 | if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key))) |
| 2433 | 2433 | { |
| 2434 | - if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) |
|
| 2434 | + if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key])) |
|
| 2435 | 2435 | { |
| 2436 | - $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); |
|
| 2437 | - $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; |
|
| 2436 | + $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key]); |
|
| 2437 | + $this->data['links'][$key] = & $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key]; |
|
| 2438 | 2438 | } |
| 2439 | 2439 | else |
| 2440 | 2440 | { |
| 2441 | - $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; |
|
| 2441 | + $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key] = & $this->data['links'][$key]; |
|
| 2442 | 2442 | } |
| 2443 | 2443 | } |
| 2444 | 2444 | elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) |
| 2445 | 2445 | { |
| 2446 | - $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; |
|
| 2446 | + $this->data['links'][substr($key, 41)] = & $this->data['links'][$key]; |
|
| 2447 | 2447 | } |
| 2448 | 2448 | $this->data['links'][$key] = array_unique($this->data['links'][$key]); |
| 2449 | 2449 | } |
@@ -2885,9 +2885,9 @@ discard block |
||
| 2885 | 2885 | */ |
| 2886 | 2886 | public function get_items($start = 0, $end = 0) |
| 2887 | 2887 | { |
| 2888 | - if (!isset($this->data['items'])) |
|
| 2888 | + if ( ! isset($this->data['items'])) |
|
| 2889 | 2889 | { |
| 2890 | - if (!empty($this->multifeed_objects)) |
|
| 2890 | + if ( ! empty($this->multifeed_objects)) |
|
| 2891 | 2891 | { |
| 2892 | 2892 | $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit); |
| 2893 | 2893 | } |
@@ -2937,17 +2937,17 @@ discard block |
||
| 2937 | 2937 | } |
| 2938 | 2938 | } |
| 2939 | 2939 | |
| 2940 | - if (!empty($this->data['items'])) |
|
| 2940 | + if ( ! empty($this->data['items'])) |
|
| 2941 | 2941 | { |
| 2942 | 2942 | // If we want to order it by date, check if all items have a date, and then sort it |
| 2943 | 2943 | if ($this->order_by_date && empty($this->multifeed_objects)) |
| 2944 | 2944 | { |
| 2945 | - if (!isset($this->data['ordered_items'])) |
|
| 2945 | + if ( ! isset($this->data['ordered_items'])) |
|
| 2946 | 2946 | { |
| 2947 | 2947 | $do_sort = true; |
| 2948 | 2948 | foreach ($this->data['items'] as $item) |
| 2949 | 2949 | { |
| 2950 | - if (!$item->get_date('U')) |
|
| 2950 | + if ( ! $item->get_date('U')) |
|
| 2951 | 2951 | { |
| 2952 | 2952 | $do_sort = false; |
| 2953 | 2953 | break; |
@@ -3007,7 +3007,7 @@ discard block |
||
| 3007 | 3007 | |
| 3008 | 3008 | if (($url = $this->get_link()) !== null) |
| 3009 | 3009 | { |
| 3010 | - return 'http://g.etfv.co/' . urlencode($url); |
|
| 3010 | + return 'http://g.etfv.co/'.urlencode($url); |
|
| 3011 | 3011 | } |
| 3012 | 3012 | |
| 3013 | 3013 | return false; |
@@ -3088,7 +3088,7 @@ discard block |
||
| 3088 | 3088 | $do_sort = true; |
| 3089 | 3089 | foreach ($items as $item) |
| 3090 | 3090 | { |
| 3091 | - if (!$item->get_date('U')) |
|
| 3091 | + if ( ! $item->get_date('U')) |
|
| 3092 | 3092 | { |
| 3093 | 3093 | $do_sort = false; |
| 3094 | 3094 | break; |
@@ -22,8 +22,9 @@ discard block |
||
| 22 | 22 | * @since 3.5.0 |
| 23 | 23 | */ |
| 24 | 24 | function wp_simplepie_autoload( $class ) { |
| 25 | - if ( 0 !== strpos( $class, 'SimplePie_' ) ) |
|
| 26 | - return; |
|
| 25 | + if ( 0 !== strpos( $class, 'SimplePie_' ) ) { |
|
| 26 | + return; |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | $file = ABSPATH . WPINC . '/' . str_replace( '_', '/', $class ) . '.php'; |
| 29 | 30 | include( $file ); |
@@ -784,8 +785,7 @@ discard block |
||
| 784 | 785 | { |
| 785 | 786 | $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1)); |
| 786 | 787 | } |
| 787 | - } |
|
| 788 | - else |
|
| 788 | + } else |
|
| 789 | 789 | { |
| 790 | 790 | $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1)); |
| 791 | 791 | } |
@@ -920,8 +920,7 @@ discard block |
||
| 920 | 920 | if ($encoding) |
| 921 | 921 | { |
| 922 | 922 | $this->input_encoding = (string) $encoding; |
| 923 | - } |
|
| 924 | - else |
|
| 923 | + } else |
|
| 925 | 924 | { |
| 926 | 925 | $this->input_encoding = false; |
| 927 | 926 | } |
@@ -1238,8 +1237,7 @@ discard block |
||
| 1238 | 1237 | if ($page !== false) |
| 1239 | 1238 | { |
| 1240 | 1239 | $this->sanitize->set_image_handler($page . '?' . $qs . '='); |
| 1241 | - } |
|
| 1242 | - else |
|
| 1240 | + } else |
|
| 1243 | 1241 | { |
| 1244 | 1242 | $this->image_handler = ''; |
| 1245 | 1243 | } |
@@ -1317,8 +1315,7 @@ discard block |
||
| 1317 | 1315 | $i++; |
| 1318 | 1316 | } |
| 1319 | 1317 | return (bool) $success; |
| 1320 | - } |
|
| 1321 | - elseif ($this->feed_url === null && $this->raw_data === null) |
|
| 1318 | + } elseif ($this->feed_url === null && $this->raw_data === null) |
|
| 1322 | 1319 | { |
| 1323 | 1320 | return false; |
| 1324 | 1321 | } |
@@ -1342,8 +1339,7 @@ discard block |
||
| 1342 | 1339 | if (($fetched = $this->fetch_data($cache)) === true) |
| 1343 | 1340 | { |
| 1344 | 1341 | return true; |
| 1345 | - } |
|
| 1346 | - elseif ($fetched === false) { |
|
| 1342 | + } elseif ($fetched === false) { |
|
| 1347 | 1343 | return false; |
| 1348 | 1344 | } |
| 1349 | 1345 | |
@@ -1373,8 +1369,7 @@ discard block |
||
| 1373 | 1369 | } |
| 1374 | 1370 | $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry))); |
| 1375 | 1371 | $encodings[] = 'UTF-8'; |
| 1376 | - } |
|
| 1377 | - elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') |
|
| 1372 | + } elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') |
|
| 1378 | 1373 | { |
| 1379 | 1374 | if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) |
| 1380 | 1375 | { |
@@ -1437,8 +1432,7 @@ discard block |
||
| 1437 | 1432 | { |
| 1438 | 1433 | // We have an error, just set SimplePie_Misc::error to it and quit |
| 1439 | 1434 | $this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column()); |
| 1440 | - } |
|
| 1441 | - else |
|
| 1435 | + } else |
|
| 1442 | 1436 | { |
| 1443 | 1437 | $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.'; |
| 1444 | 1438 | } |
@@ -1520,8 +1514,7 @@ discard block |
||
| 1520 | 1514 | $cache->touch(); |
| 1521 | 1515 | return true; |
| 1522 | 1516 | } |
| 1523 | - } |
|
| 1524 | - else |
|
| 1517 | + } else |
|
| 1525 | 1518 | { |
| 1526 | 1519 | unset($file); |
| 1527 | 1520 | } |
@@ -1547,8 +1540,7 @@ discard block |
||
| 1547 | 1540 | if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url) |
| 1548 | 1541 | { |
| 1549 | 1542 | $file =& $this->file; |
| 1550 | - } |
|
| 1551 | - else |
|
| 1543 | + } else |
|
| 1552 | 1544 | { |
| 1553 | 1545 | $headers = array( |
| 1554 | 1546 | 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', |
@@ -1580,8 +1572,7 @@ discard block |
||
| 1580 | 1572 | $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); |
| 1581 | 1573 | return false; |
| 1582 | 1574 | } |
| 1583 | - } |
|
| 1584 | - catch (SimplePie_Exception $e) |
|
| 1575 | + } catch (SimplePie_Exception $e) |
|
| 1585 | 1576 | { |
| 1586 | 1577 | // This is usually because DOMDocument doesn't exist |
| 1587 | 1578 | $this->error = $e->getMessage(); |
@@ -1672,8 +1663,7 @@ discard block |
||
| 1672 | 1663 | if ($this->get_encoding()) |
| 1673 | 1664 | { |
| 1674 | 1665 | $header .= ' charset=' . $this->get_encoding(); |
| 1675 | - } |
|
| 1676 | - else |
|
| 1666 | + } else |
|
| 1677 | 1667 | { |
| 1678 | 1668 | $header .= ' charset=UTF-8'; |
| 1679 | 1669 | } |
@@ -1715,12 +1705,10 @@ discard block |
||
| 1715 | 1705 | if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) |
| 1716 | 1706 | { |
| 1717 | 1707 | $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10; |
| 1718 | - } |
|
| 1719 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) |
|
| 1708 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) |
|
| 1720 | 1709 | { |
| 1721 | 1710 | $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03; |
| 1722 | - } |
|
| 1723 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) |
|
| 1711 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) |
|
| 1724 | 1712 | { |
| 1725 | 1713 | if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel']) |
| 1726 | 1714 | || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image']) |
@@ -1736,8 +1724,7 @@ discard block |
||
| 1736 | 1724 | { |
| 1737 | 1725 | $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090; |
| 1738 | 1726 | } |
| 1739 | - } |
|
| 1740 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'])) |
|
| 1727 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'])) |
|
| 1741 | 1728 | { |
| 1742 | 1729 | $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL; |
| 1743 | 1730 | if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) |
@@ -1778,8 +1765,7 @@ discard block |
||
| 1778 | 1765 | break; |
| 1779 | 1766 | } |
| 1780 | 1767 | } |
| 1781 | - } |
|
| 1782 | - else |
|
| 1768 | + } else |
|
| 1783 | 1769 | { |
| 1784 | 1770 | $this->data['type'] = SIMPLEPIE_TYPE_NONE; |
| 1785 | 1771 | } |
@@ -1804,8 +1790,7 @@ discard block |
||
| 1804 | 1790 | if ($this->feed_url !== null) |
| 1805 | 1791 | { |
| 1806 | 1792 | return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI); |
| 1807 | - } |
|
| 1808 | - else |
|
| 1793 | + } else |
|
| 1809 | 1794 | { |
| 1810 | 1795 | return null; |
| 1811 | 1796 | } |
@@ -2000,12 +1985,10 @@ discard block |
||
| 2000 | 1985 | if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) |
| 2001 | 1986 | { |
| 2002 | 1987 | return $element['xml_base']; |
| 2003 | - } |
|
| 2004 | - elseif ($this->get_link() !== null) |
|
| 1988 | + } elseif ($this->get_link() !== null) |
|
| 2005 | 1989 | { |
| 2006 | 1990 | return $this->get_link(); |
| 2007 | - } |
|
| 2008 | - else |
|
| 1991 | + } else |
|
| 2009 | 1992 | { |
| 2010 | 1993 | return $this->subscribe_url(); |
| 2011 | 1994 | } |
@@ -2039,32 +2022,25 @@ discard block |
||
| 2039 | 2022 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) |
| 2040 | 2023 | { |
| 2041 | 2024 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2042 | - } |
|
| 2043 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) |
|
| 2025 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) |
|
| 2044 | 2026 | { |
| 2045 | 2027 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2046 | - } |
|
| 2047 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) |
|
| 2028 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) |
|
| 2048 | 2029 | { |
| 2049 | 2030 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2050 | - } |
|
| 2051 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) |
|
| 2031 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) |
|
| 2052 | 2032 | { |
| 2053 | 2033 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2054 | - } |
|
| 2055 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) |
|
| 2034 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) |
|
| 2056 | 2035 | { |
| 2057 | 2036 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2058 | - } |
|
| 2059 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) |
|
| 2037 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) |
|
| 2060 | 2038 | { |
| 2061 | 2039 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2062 | - } |
|
| 2063 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) |
|
| 2040 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) |
|
| 2064 | 2041 | { |
| 2065 | 2042 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2066 | - } |
|
| 2067 | - else |
|
| 2043 | + } else |
|
| 2068 | 2044 | { |
| 2069 | 2045 | return null; |
| 2070 | 2046 | } |
@@ -2083,8 +2059,7 @@ discard block |
||
| 2083 | 2059 | if (isset($categories[$key])) |
| 2084 | 2060 | { |
| 2085 | 2061 | return $categories[$key]; |
| 2086 | - } |
|
| 2087 | - else |
|
| 2062 | + } else |
|
| 2088 | 2063 | { |
| 2089 | 2064 | return null; |
| 2090 | 2065 | } |
@@ -2129,8 +2104,7 @@ discard block |
||
| 2129 | 2104 | if (isset($category['attribs']['']['domain'])) |
| 2130 | 2105 | { |
| 2131 | 2106 | $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2132 | - } |
|
| 2133 | - else |
|
| 2107 | + } else |
|
| 2134 | 2108 | { |
| 2135 | 2109 | $scheme = null; |
| 2136 | 2110 | } |
@@ -2148,8 +2122,7 @@ discard block |
||
| 2148 | 2122 | if (!empty($categories)) |
| 2149 | 2123 | { |
| 2150 | 2124 | return array_unique($categories); |
| 2151 | - } |
|
| 2152 | - else |
|
| 2125 | + } else |
|
| 2153 | 2126 | { |
| 2154 | 2127 | return null; |
| 2155 | 2128 | } |
@@ -2168,8 +2141,7 @@ discard block |
||
| 2168 | 2141 | if (isset($authors[$key])) |
| 2169 | 2142 | { |
| 2170 | 2143 | return $authors[$key]; |
| 2171 | - } |
|
| 2172 | - else |
|
| 2144 | + } else |
|
| 2173 | 2145 | { |
| 2174 | 2146 | return null; |
| 2175 | 2147 | } |
@@ -2246,8 +2218,7 @@ discard block |
||
| 2246 | 2218 | if (!empty($authors)) |
| 2247 | 2219 | { |
| 2248 | 2220 | return array_unique($authors); |
| 2249 | - } |
|
| 2250 | - else |
|
| 2221 | + } else |
|
| 2251 | 2222 | { |
| 2252 | 2223 | return null; |
| 2253 | 2224 | } |
@@ -2266,8 +2237,7 @@ discard block |
||
| 2266 | 2237 | if (isset($contributors[$key])) |
| 2267 | 2238 | { |
| 2268 | 2239 | return $contributors[$key]; |
| 2269 | - } |
|
| 2270 | - else |
|
| 2240 | + } else |
|
| 2271 | 2241 | { |
| 2272 | 2242 | return null; |
| 2273 | 2243 | } |
@@ -2332,8 +2302,7 @@ discard block |
||
| 2332 | 2302 | if (!empty($contributors)) |
| 2333 | 2303 | { |
| 2334 | 2304 | return array_unique($contributors); |
| 2335 | - } |
|
| 2336 | - else |
|
| 2305 | + } else |
|
| 2337 | 2306 | { |
| 2338 | 2307 | return null; |
| 2339 | 2308 | } |
@@ -2353,8 +2322,7 @@ discard block |
||
| 2353 | 2322 | if (isset($links[$key])) |
| 2354 | 2323 | { |
| 2355 | 2324 | return $links[$key]; |
| 2356 | - } |
|
| 2357 | - else |
|
| 2325 | + } else |
|
| 2358 | 2326 | { |
| 2359 | 2327 | return null; |
| 2360 | 2328 | } |
@@ -2435,13 +2403,11 @@ discard block |
||
| 2435 | 2403 | { |
| 2436 | 2404 | $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); |
| 2437 | 2405 | $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; |
| 2438 | - } |
|
| 2439 | - else |
|
| 2406 | + } else |
|
| 2440 | 2407 | { |
| 2441 | 2408 | $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; |
| 2442 | 2409 | } |
| 2443 | - } |
|
| 2444 | - elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) |
|
| 2410 | + } elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) |
|
| 2445 | 2411 | { |
| 2446 | 2412 | $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; |
| 2447 | 2413 | } |
@@ -2452,8 +2418,7 @@ discard block |
||
| 2452 | 2418 | if (isset($this->data['links'][$rel])) |
| 2453 | 2419 | { |
| 2454 | 2420 | return $this->data['links'][$rel]; |
| 2455 | - } |
|
| 2456 | - else |
|
| 2421 | + } else |
|
| 2457 | 2422 | { |
| 2458 | 2423 | return null; |
| 2459 | 2424 | } |
@@ -2478,40 +2443,31 @@ discard block |
||
| 2478 | 2443 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) |
| 2479 | 2444 | { |
| 2480 | 2445 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2481 | - } |
|
| 2482 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) |
|
| 2446 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) |
|
| 2483 | 2447 | { |
| 2484 | 2448 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2485 | - } |
|
| 2486 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) |
|
| 2449 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) |
|
| 2487 | 2450 | { |
| 2488 | 2451 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2489 | - } |
|
| 2490 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) |
|
| 2452 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) |
|
| 2491 | 2453 | { |
| 2492 | 2454 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2493 | - } |
|
| 2494 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) |
|
| 2455 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) |
|
| 2495 | 2456 | { |
| 2496 | 2457 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); |
| 2497 | - } |
|
| 2498 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) |
|
| 2458 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) |
|
| 2499 | 2459 | { |
| 2500 | 2460 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2501 | - } |
|
| 2502 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) |
|
| 2461 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) |
|
| 2503 | 2462 | { |
| 2504 | 2463 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2505 | - } |
|
| 2506 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) |
|
| 2464 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) |
|
| 2507 | 2465 | { |
| 2508 | 2466 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); |
| 2509 | - } |
|
| 2510 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) |
|
| 2467 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) |
|
| 2511 | 2468 | { |
| 2512 | 2469 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); |
| 2513 | - } |
|
| 2514 | - else |
|
| 2470 | + } else |
|
| 2515 | 2471 | { |
| 2516 | 2472 | return null; |
| 2517 | 2473 | } |
@@ -2530,24 +2486,19 @@ discard block |
||
| 2530 | 2486 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) |
| 2531 | 2487 | { |
| 2532 | 2488 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2533 | - } |
|
| 2534 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) |
|
| 2489 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) |
|
| 2535 | 2490 | { |
| 2536 | 2491 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2537 | - } |
|
| 2538 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) |
|
| 2492 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) |
|
| 2539 | 2493 | { |
| 2540 | 2494 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2541 | - } |
|
| 2542 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) |
|
| 2495 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) |
|
| 2543 | 2496 | { |
| 2544 | 2497 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2545 | - } |
|
| 2546 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) |
|
| 2498 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) |
|
| 2547 | 2499 | { |
| 2548 | 2500 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2549 | - } |
|
| 2550 | - else |
|
| 2501 | + } else |
|
| 2551 | 2502 | { |
| 2552 | 2503 | return null; |
| 2553 | 2504 | } |
@@ -2566,32 +2517,25 @@ discard block |
||
| 2566 | 2517 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language')) |
| 2567 | 2518 | { |
| 2568 | 2519 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2569 | - } |
|
| 2570 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) |
|
| 2520 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) |
|
| 2571 | 2521 | { |
| 2572 | 2522 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2573 | - } |
|
| 2574 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) |
|
| 2523 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) |
|
| 2575 | 2524 | { |
| 2576 | 2525 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2577 | - } |
|
| 2578 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'])) |
|
| 2526 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'])) |
|
| 2579 | 2527 | { |
| 2580 | 2528 | return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2581 | - } |
|
| 2582 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'])) |
|
| 2529 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'])) |
|
| 2583 | 2530 | { |
| 2584 | 2531 | return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2585 | - } |
|
| 2586 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'])) |
|
| 2532 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'])) |
|
| 2587 | 2533 | { |
| 2588 | 2534 | return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2589 | - } |
|
| 2590 | - elseif (isset($this->data['headers']['content-language'])) |
|
| 2535 | + } elseif (isset($this->data['headers']['content-language'])) |
|
| 2591 | 2536 | { |
| 2592 | 2537 | return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2593 | - } |
|
| 2594 | - else |
|
| 2538 | + } else |
|
| 2595 | 2539 | { |
| 2596 | 2540 | return null; |
| 2597 | 2541 | } |
@@ -2615,12 +2559,10 @@ discard block |
||
| 2615 | 2559 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) |
| 2616 | 2560 | { |
| 2617 | 2561 | return (float) $return[0]['data']; |
| 2618 | - } |
|
| 2619 | - elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) |
|
| 2562 | + } elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) |
|
| 2620 | 2563 | { |
| 2621 | 2564 | return (float) $match[1]; |
| 2622 | - } |
|
| 2623 | - else |
|
| 2565 | + } else |
|
| 2624 | 2566 | { |
| 2625 | 2567 | return null; |
| 2626 | 2568 | } |
@@ -2643,16 +2585,13 @@ discard block |
||
| 2643 | 2585 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) |
| 2644 | 2586 | { |
| 2645 | 2587 | return (float) $return[0]['data']; |
| 2646 | - } |
|
| 2647 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) |
|
| 2588 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) |
|
| 2648 | 2589 | { |
| 2649 | 2590 | return (float) $return[0]['data']; |
| 2650 | - } |
|
| 2651 | - elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) |
|
| 2591 | + } elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) |
|
| 2652 | 2592 | { |
| 2653 | 2593 | return (float) $match[2]; |
| 2654 | - } |
|
| 2655 | - else |
|
| 2594 | + } else |
|
| 2656 | 2595 | { |
| 2657 | 2596 | return null; |
| 2658 | 2597 | } |
@@ -2672,24 +2611,19 @@ discard block |
||
| 2672 | 2611 | if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) |
| 2673 | 2612 | { |
| 2674 | 2613 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2675 | - } |
|
| 2676 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) |
|
| 2614 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) |
|
| 2677 | 2615 | { |
| 2678 | 2616 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2679 | - } |
|
| 2680 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) |
|
| 2617 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) |
|
| 2681 | 2618 | { |
| 2682 | 2619 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2683 | - } |
|
| 2684 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) |
|
| 2620 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) |
|
| 2685 | 2621 | { |
| 2686 | 2622 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2687 | - } |
|
| 2688 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) |
|
| 2623 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) |
|
| 2689 | 2624 | { |
| 2690 | 2625 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2691 | - } |
|
| 2692 | - else |
|
| 2626 | + } else |
|
| 2693 | 2627 | { |
| 2694 | 2628 | return null; |
| 2695 | 2629 | } |
@@ -2711,28 +2645,22 @@ discard block |
||
| 2711 | 2645 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) |
| 2712 | 2646 | { |
| 2713 | 2647 | return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI); |
| 2714 | - } |
|
| 2715 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) |
|
| 2648 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) |
|
| 2716 | 2649 | { |
| 2717 | 2650 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2718 | - } |
|
| 2719 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) |
|
| 2651 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) |
|
| 2720 | 2652 | { |
| 2721 | 2653 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2722 | - } |
|
| 2723 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url')) |
|
| 2654 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url')) |
|
| 2724 | 2655 | { |
| 2725 | 2656 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2726 | - } |
|
| 2727 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url')) |
|
| 2657 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url')) |
|
| 2728 | 2658 | { |
| 2729 | 2659 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2730 | - } |
|
| 2731 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2660 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2732 | 2661 | { |
| 2733 | 2662 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2734 | - } |
|
| 2735 | - else |
|
| 2663 | + } else |
|
| 2736 | 2664 | { |
| 2737 | 2665 | return null; |
| 2738 | 2666 | } |
@@ -2755,16 +2683,13 @@ discard block |
||
| 2755 | 2683 | if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) |
| 2756 | 2684 | { |
| 2757 | 2685 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2758 | - } |
|
| 2759 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) |
|
| 2686 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) |
|
| 2760 | 2687 | { |
| 2761 | 2688 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2762 | - } |
|
| 2763 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) |
|
| 2689 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) |
|
| 2764 | 2690 | { |
| 2765 | 2691 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2766 | - } |
|
| 2767 | - else |
|
| 2692 | + } else |
|
| 2768 | 2693 | { |
| 2769 | 2694 | return null; |
| 2770 | 2695 | } |
@@ -2785,12 +2710,10 @@ discard block |
||
| 2785 | 2710 | if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width')) |
| 2786 | 2711 | { |
| 2787 | 2712 | return round($return[0]['data']); |
| 2788 | - } |
|
| 2789 | - elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2713 | + } elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2790 | 2714 | { |
| 2791 | 2715 | return 88.0; |
| 2792 | - } |
|
| 2793 | - else |
|
| 2716 | + } else |
|
| 2794 | 2717 | { |
| 2795 | 2718 | return null; |
| 2796 | 2719 | } |
@@ -2811,12 +2734,10 @@ discard block |
||
| 2811 | 2734 | if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height')) |
| 2812 | 2735 | { |
| 2813 | 2736 | return round($return[0]['data']); |
| 2814 | - } |
|
| 2815 | - elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2737 | + } elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2816 | 2738 | { |
| 2817 | 2739 | return 31.0; |
| 2818 | - } |
|
| 2819 | - else |
|
| 2740 | + } else |
|
| 2820 | 2741 | { |
| 2821 | 2742 | return null; |
| 2822 | 2743 | } |
@@ -2838,8 +2759,7 @@ discard block |
||
| 2838 | 2759 | if ($max === 0) |
| 2839 | 2760 | { |
| 2840 | 2761 | return $qty; |
| 2841 | - } |
|
| 2842 | - else |
|
| 2762 | + } else |
|
| 2843 | 2763 | { |
| 2844 | 2764 | return ($qty > $max) ? $max : $qty; |
| 2845 | 2765 | } |
@@ -2863,8 +2783,7 @@ discard block |
||
| 2863 | 2783 | if (isset($items[$key])) |
| 2864 | 2784 | { |
| 2865 | 2785 | return $items[$key]; |
| 2866 | - } |
|
| 2867 | - else |
|
| 2786 | + } else |
|
| 2868 | 2787 | { |
| 2869 | 2788 | return null; |
| 2870 | 2789 | } |
@@ -2890,8 +2809,7 @@ discard block |
||
| 2890 | 2809 | if (!empty($this->multifeed_objects)) |
| 2891 | 2810 | { |
| 2892 | 2811 | $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit); |
| 2893 | - } |
|
| 2894 | - else |
|
| 2812 | + } else |
|
| 2895 | 2813 | { |
| 2896 | 2814 | $this->data['items'] = array(); |
| 2897 | 2815 | if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) |
@@ -2961,8 +2879,7 @@ discard block |
||
| 2961 | 2879 | } |
| 2962 | 2880 | } |
| 2963 | 2881 | $items = $this->data['ordered_items']; |
| 2964 | - } |
|
| 2965 | - else |
|
| 2882 | + } else |
|
| 2966 | 2883 | { |
| 2967 | 2884 | $items = $this->data['items']; |
| 2968 | 2885 | } |
@@ -2971,13 +2888,11 @@ discard block |
||
| 2971 | 2888 | if ($end === 0) |
| 2972 | 2889 | { |
| 2973 | 2890 | return array_slice($items, $start); |
| 2974 | - } |
|
| 2975 | - else |
|
| 2891 | + } else |
|
| 2976 | 2892 | { |
| 2977 | 2893 | return array_slice($items, $start, $end); |
| 2978 | 2894 | } |
| 2979 | - } |
|
| 2980 | - else |
|
| 2895 | + } else |
|
| 2981 | 2896 | { |
| 2982 | 2897 | return array(); |
| 2983 | 2898 | } |
@@ -3078,8 +2993,7 @@ discard block |
||
| 3078 | 2993 | if ($arg instanceof SimplePie) |
| 3079 | 2994 | { |
| 3080 | 2995 | $items = array_merge($items, $arg->get_items(0, $limit)); |
| 3081 | - } |
|
| 3082 | - else |
|
| 2996 | + } else |
|
| 3083 | 2997 | { |
| 3084 | 2998 | trigger_error('Arguments must be SimplePie objects', E_USER_WARNING); |
| 3085 | 2999 | } |
@@ -3103,13 +3017,11 @@ discard block |
||
| 3103 | 3017 | if ($end === 0) |
| 3104 | 3018 | { |
| 3105 | 3019 | return array_slice($items, $start); |
| 3106 | - } |
|
| 3107 | - else |
|
| 3020 | + } else |
|
| 3108 | 3021 | { |
| 3109 | 3022 | return array_slice($items, $start, $end); |
| 3110 | 3023 | } |
| 3111 | - } |
|
| 3112 | - else |
|
| 3024 | + } else |
|
| 3113 | 3025 | { |
| 3114 | 3026 | trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING); |
| 3115 | 3027 | return array(); |
@@ -879,7 +879,7 @@ |
||
| 879 | 879 | * Send raw data to the server. |
| 880 | 880 | * @param string $data The data to send |
| 881 | 881 | * @access public |
| 882 | - * @return integer|boolean The number of bytes sent to the server or false on error |
|
| 882 | + * @return integer The number of bytes sent to the server or false on error |
|
| 883 | 883 | */ |
| 884 | 884 | public function client_send($data) |
| 885 | 885 | { |
@@ -26,535 +26,535 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | class SMTP |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * The PHPMailer SMTP version number. |
|
| 31 | - * @type string |
|
| 32 | - */ |
|
| 33 | - const VERSION = '5.2.10'; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * SMTP line break constant. |
|
| 37 | - * @type string |
|
| 38 | - */ |
|
| 39 | - const CRLF = "\r\n"; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * The SMTP port to use if one is not specified. |
|
| 43 | - * @type integer |
|
| 44 | - */ |
|
| 45 | - const DEFAULT_SMTP_PORT = 25; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * The maximum line length allowed by RFC 2822 section 2.1.1 |
|
| 49 | - * @type integer |
|
| 50 | - */ |
|
| 51 | - const MAX_LINE_LENGTH = 998; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Debug level for no output |
|
| 55 | - */ |
|
| 56 | - const DEBUG_OFF = 0; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Debug level to show client -> server messages |
|
| 60 | - */ |
|
| 61 | - const DEBUG_CLIENT = 1; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Debug level to show client -> server and server -> client messages |
|
| 65 | - */ |
|
| 66 | - const DEBUG_SERVER = 2; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Debug level to show connection status, client -> server and server -> client messages |
|
| 70 | - */ |
|
| 71 | - const DEBUG_CONNECTION = 3; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Debug level to show all messages |
|
| 75 | - */ |
|
| 76 | - const DEBUG_LOWLEVEL = 4; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * The PHPMailer SMTP Version number. |
|
| 80 | - * @type string |
|
| 81 | - * @deprecated Use the `VERSION` constant instead |
|
| 82 | - * @see SMTP::VERSION |
|
| 83 | - */ |
|
| 84 | - public $Version = '5.2.10'; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * SMTP server port number. |
|
| 88 | - * @type integer |
|
| 89 | - * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead |
|
| 90 | - * @see SMTP::DEFAULT_SMTP_PORT |
|
| 91 | - */ |
|
| 92 | - public $SMTP_PORT = 25; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * SMTP reply line ending. |
|
| 96 | - * @type string |
|
| 97 | - * @deprecated Use the `CRLF` constant instead |
|
| 98 | - * @see SMTP::CRLF |
|
| 99 | - */ |
|
| 100 | - public $CRLF = "\r\n"; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Debug output level. |
|
| 104 | - * Options: |
|
| 105 | - * * self::DEBUG_OFF (`0`) No debug output, default |
|
| 106 | - * * self::DEBUG_CLIENT (`1`) Client commands |
|
| 107 | - * * self::DEBUG_SERVER (`2`) Client commands and server responses |
|
| 108 | - * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status |
|
| 109 | - * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages |
|
| 110 | - * @type integer |
|
| 111 | - */ |
|
| 112 | - public $do_debug = self::DEBUG_OFF; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * How to handle debug output. |
|
| 116 | - * Options: |
|
| 117 | - * * `echo` Output plain-text as-is, appropriate for CLI |
|
| 118 | - * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output |
|
| 119 | - * * `error_log` Output to error log as configured in php.ini |
|
| 120 | - * |
|
| 121 | - * Alternatively, you can provide a callable expecting two params: a message string and the debug level: |
|
| 122 | - * <code> |
|
| 123 | - * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; |
|
| 124 | - * </code> |
|
| 125 | - * @type string|callable |
|
| 126 | - */ |
|
| 127 | - public $Debugoutput = 'echo'; |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Whether to use VERP. |
|
| 131 | - * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path |
|
| 132 | - * @link http://www.postfix.org/VERP_README.html Info on VERP |
|
| 133 | - * @type boolean |
|
| 134 | - */ |
|
| 135 | - public $do_verp = false; |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * The timeout value for connection, in seconds. |
|
| 139 | - * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 |
|
| 140 | - * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure. |
|
| 141 | - * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2 |
|
| 142 | - * @type integer |
|
| 143 | - */ |
|
| 144 | - public $Timeout = 300; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * How long to wait for commands to complete, in seconds. |
|
| 148 | - * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 |
|
| 149 | - * @type integer |
|
| 150 | - */ |
|
| 151 | - public $Timelimit = 300; |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * The socket for the server connection. |
|
| 155 | - * @type resource |
|
| 156 | - */ |
|
| 157 | - protected $smtp_conn; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Error information, if any, for the last SMTP command. |
|
| 161 | - * @type array |
|
| 162 | - */ |
|
| 163 | - protected $error = array( |
|
| 164 | - 'error' => '', |
|
| 165 | - 'detail' => '', |
|
| 166 | - 'smtp_code' => '', |
|
| 167 | - 'smtp_code_ex' => '' |
|
| 168 | - ); |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * The reply the server sent to us for HELO. |
|
| 172 | - * If null, no HELO string has yet been received. |
|
| 173 | - * @type string|null |
|
| 174 | - */ |
|
| 175 | - protected $helo_rply = null; |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * The set of SMTP extensions sent in reply to EHLO command. |
|
| 179 | - * Indexes of the array are extension names. |
|
| 180 | - * Value at index 'HELO' or 'EHLO' (according to command that was sent) |
|
| 181 | - * represents the server name. In case of HELO it is the only element of the array. |
|
| 182 | - * Other values can be boolean TRUE or an array containing extension options. |
|
| 183 | - * If null, no HELO/EHLO string has yet been received. |
|
| 184 | - * @type array|null |
|
| 185 | - */ |
|
| 186 | - protected $server_caps = null; |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * The most recent reply received from the server. |
|
| 190 | - * @type string |
|
| 191 | - */ |
|
| 192 | - protected $last_reply = ''; |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Output debugging info via a user-selected method. |
|
| 196 | - * @see SMTP::$Debugoutput |
|
| 197 | - * @see SMTP::$do_debug |
|
| 198 | - * @param string $str Debug string to output |
|
| 199 | - * @param integer $level The debug level of this message; see DEBUG_* constants |
|
| 200 | - * @return void |
|
| 201 | - */ |
|
| 202 | - protected function edebug($str, $level = 0) |
|
| 203 | - { |
|
| 204 | - if ($level > $this->do_debug) { |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - //Avoid clash with built-in function names |
|
| 208 | - if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { |
|
| 209 | - call_user_func($this->Debugoutput, $str, $this->do_debug); |
|
| 210 | - return; |
|
| 211 | - } |
|
| 212 | - switch ($this->Debugoutput) { |
|
| 213 | - case 'error_log': |
|
| 214 | - //Don't output, just log |
|
| 215 | - error_log($str); |
|
| 216 | - break; |
|
| 217 | - case 'html': |
|
| 218 | - //Cleans up output a bit for a better looking, HTML-safe output |
|
| 219 | - echo htmlentities( |
|
| 220 | - preg_replace('/[\r\n]+/', '', $str), |
|
| 221 | - ENT_QUOTES, |
|
| 222 | - 'UTF-8' |
|
| 223 | - ) |
|
| 224 | - . "<br>\n"; |
|
| 225 | - break; |
|
| 226 | - case 'echo': |
|
| 227 | - default: |
|
| 228 | - //Normalize line breaks |
|
| 229 | - $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str); |
|
| 230 | - echo gmdate('Y-m-d H:i:s') . "\t" . str_replace( |
|
| 231 | - "\n", |
|
| 232 | - "\n \t ", |
|
| 233 | - trim($str) |
|
| 234 | - )."\n"; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Connect to an SMTP server. |
|
| 240 | - * @param string $host SMTP server IP or host name |
|
| 241 | - * @param integer $port The port number to connect to |
|
| 242 | - * @param integer $timeout How long to wait for the connection to open |
|
| 243 | - * @param array $options An array of options for stream_context_create() |
|
| 244 | - * @access public |
|
| 245 | - * @return boolean |
|
| 246 | - */ |
|
| 247 | - public function connect($host, $port = null, $timeout = 30, $options = array()) |
|
| 248 | - { |
|
| 249 | - static $streamok; |
|
| 250 | - //This is enabled by default since 5.0.0 but some providers disable it |
|
| 251 | - //Check this once and cache the result |
|
| 252 | - if (is_null($streamok)) { |
|
| 253 | - $streamok = function_exists('stream_socket_client'); |
|
| 254 | - } |
|
| 255 | - // Clear errors to avoid confusion |
|
| 256 | - $this->setError(''); |
|
| 257 | - // Make sure we are __not__ connected |
|
| 258 | - if ($this->connected()) { |
|
| 259 | - // Already connected, generate error |
|
| 260 | - $this->setError('Already connected to a server'); |
|
| 261 | - return false; |
|
| 262 | - } |
|
| 263 | - if (empty($port)) { |
|
| 264 | - $port = self::DEFAULT_SMTP_PORT; |
|
| 265 | - } |
|
| 266 | - // Connect to the SMTP server |
|
| 267 | - $this->edebug( |
|
| 268 | - "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true), |
|
| 269 | - self::DEBUG_CONNECTION |
|
| 270 | - ); |
|
| 271 | - $errno = 0; |
|
| 272 | - $errstr = ''; |
|
| 273 | - if ($streamok) { |
|
| 274 | - $socket_context = stream_context_create($options); |
|
| 275 | - //Suppress errors; connection failures are handled at a higher level |
|
| 276 | - $this->smtp_conn = @stream_socket_client( |
|
| 277 | - $host . ":" . $port, |
|
| 278 | - $errno, |
|
| 279 | - $errstr, |
|
| 280 | - $timeout, |
|
| 281 | - STREAM_CLIENT_CONNECT, |
|
| 282 | - $socket_context |
|
| 283 | - ); |
|
| 284 | - } else { |
|
| 285 | - //Fall back to fsockopen which should work in more places, but is missing some features |
|
| 286 | - $this->edebug( |
|
| 287 | - "Connection: stream_socket_client not available, falling back to fsockopen", |
|
| 288 | - self::DEBUG_CONNECTION |
|
| 289 | - ); |
|
| 290 | - $this->smtp_conn = fsockopen( |
|
| 291 | - $host, |
|
| 292 | - $port, |
|
| 293 | - $errno, |
|
| 294 | - $errstr, |
|
| 295 | - $timeout |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - // Verify we connected properly |
|
| 299 | - if (!is_resource($this->smtp_conn)) { |
|
| 300 | - $this->setError( |
|
| 301 | - 'Failed to connect to server', |
|
| 302 | - $errno, |
|
| 303 | - $errstr |
|
| 304 | - ); |
|
| 305 | - $this->edebug( |
|
| 306 | - 'SMTP ERROR: ' . $this->error['error'] |
|
| 307 | - . ": $errstr ($errno)", |
|
| 308 | - self::DEBUG_CLIENT |
|
| 309 | - ); |
|
| 310 | - return false; |
|
| 311 | - } |
|
| 312 | - $this->edebug('Connection: opened', self::DEBUG_CONNECTION); |
|
| 313 | - // SMTP server can take longer to respond, give longer timeout for first read |
|
| 314 | - // Windows does not have support for this timeout function |
|
| 315 | - if (substr(PHP_OS, 0, 3) != 'WIN') { |
|
| 316 | - $max = ini_get('max_execution_time'); |
|
| 317 | - // Don't bother if unlimited |
|
| 318 | - if ($max != 0 && $timeout > $max) { |
|
| 319 | - @set_time_limit($timeout); |
|
| 320 | - } |
|
| 321 | - stream_set_timeout($this->smtp_conn, $timeout, 0); |
|
| 322 | - } |
|
| 323 | - // Get any announcement |
|
| 324 | - $announce = $this->get_lines(); |
|
| 325 | - $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER); |
|
| 326 | - return true; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Initiate a TLS (encrypted) session. |
|
| 331 | - * @access public |
|
| 332 | - * @return boolean |
|
| 333 | - */ |
|
| 334 | - public function startTLS() |
|
| 335 | - { |
|
| 336 | - if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) { |
|
| 337 | - return false; |
|
| 338 | - } |
|
| 339 | - // Begin encrypted connection |
|
| 340 | - if (!stream_socket_enable_crypto( |
|
| 341 | - $this->smtp_conn, |
|
| 342 | - true, |
|
| 343 | - STREAM_CRYPTO_METHOD_TLS_CLIENT |
|
| 344 | - )) { |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - return true; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Perform SMTP authentication. |
|
| 352 | - * Must be run after hello(). |
|
| 353 | - * @see hello() |
|
| 354 | - * @param string $username The user name |
|
| 355 | - * @param string $password The password |
|
| 356 | - * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5) |
|
| 357 | - * @param string $realm The auth realm for NTLM |
|
| 358 | - * @param string $workstation The auth workstation for NTLM |
|
| 359 | - * @access public |
|
| 360 | - * @return boolean True if successfully authenticated. |
|
| 361 | - */ |
|
| 362 | - public function authenticate( |
|
| 363 | - $username, |
|
| 364 | - $password, |
|
| 365 | - $authtype = null, |
|
| 366 | - $realm = '', |
|
| 367 | - $workstation = '' |
|
| 368 | - ) { |
|
| 369 | - if (!$this->server_caps) { |
|
| 370 | - $this->setError('Authentication is not allowed before HELO/EHLO'); |
|
| 371 | - return false; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if (array_key_exists('EHLO', $this->server_caps)) { |
|
| 375 | - // SMTP extensions are available. Let's try to find a proper authentication method |
|
| 376 | - |
|
| 377 | - if (!array_key_exists('AUTH', $this->server_caps)) { |
|
| 378 | - $this->setError('Authentication is not allowed at this stage'); |
|
| 379 | - // 'at this stage' means that auth may be allowed after the stage changes |
|
| 380 | - // e.g. after STARTTLS |
|
| 381 | - return false; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
| 385 | - self::edebug( |
|
| 386 | - 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), |
|
| 387 | - self::DEBUG_LOWLEVEL |
|
| 388 | - ); |
|
| 389 | - |
|
| 390 | - if (empty($authtype)) { |
|
| 391 | - foreach (array('LOGIN', 'CRAM-MD5', 'PLAIN') as $method) { |
|
| 392 | - if (in_array($method, $this->server_caps['AUTH'])) { |
|
| 393 | - $authtype = $method; |
|
| 394 | - break; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - if (empty($authtype)) { |
|
| 398 | - $this->setError('No supported authentication methods found'); |
|
| 399 | - return false; |
|
| 400 | - } |
|
| 401 | - self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if (!in_array($authtype, $this->server_caps['AUTH'])) { |
|
| 405 | - $this->setError("The requested authentication method \"$authtype\" is not supported by the server"); |
|
| 406 | - return false; |
|
| 407 | - } |
|
| 408 | - } elseif (empty($authtype)) { |
|
| 409 | - $authtype = 'LOGIN'; |
|
| 410 | - } |
|
| 411 | - switch ($authtype) { |
|
| 412 | - case 'PLAIN': |
|
| 413 | - // Start authentication |
|
| 414 | - if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { |
|
| 415 | - return false; |
|
| 416 | - } |
|
| 417 | - // Send encoded username and password |
|
| 418 | - if (!$this->sendCommand( |
|
| 419 | - 'User & Password', |
|
| 420 | - base64_encode("\0" . $username . "\0" . $password), |
|
| 421 | - 235 |
|
| 422 | - ) |
|
| 423 | - ) { |
|
| 424 | - return false; |
|
| 425 | - } |
|
| 426 | - break; |
|
| 427 | - case 'LOGIN': |
|
| 428 | - // Start authentication |
|
| 429 | - if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { |
|
| 430 | - return false; |
|
| 431 | - } |
|
| 432 | - if (!$this->sendCommand("Username", base64_encode($username), 334)) { |
|
| 433 | - return false; |
|
| 434 | - } |
|
| 435 | - if (!$this->sendCommand("Password", base64_encode($password), 235)) { |
|
| 436 | - return false; |
|
| 437 | - } |
|
| 438 | - break; |
|
| 439 | - case 'CRAM-MD5': |
|
| 440 | - // Start authentication |
|
| 441 | - if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { |
|
| 442 | - return false; |
|
| 443 | - } |
|
| 444 | - // Get the challenge |
|
| 445 | - $challenge = base64_decode(substr($this->last_reply, 4)); |
|
| 446 | - |
|
| 447 | - // Build the response |
|
| 448 | - $response = $username . ' ' . $this->hmac($challenge, $password); |
|
| 449 | - |
|
| 450 | - // send encoded credentials |
|
| 451 | - return $this->sendCommand('Username', base64_encode($response), 235); |
|
| 452 | - default: |
|
| 453 | - $this->setError("Authentication method \"$authtype\" is not supported"); |
|
| 454 | - return false; |
|
| 455 | - } |
|
| 456 | - return true; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Calculate an MD5 HMAC hash. |
|
| 461 | - * Works like hash_hmac('md5', $data, $key) |
|
| 462 | - * in case that function is not available |
|
| 463 | - * @param string $data The data to hash |
|
| 464 | - * @param string $key The key to hash with |
|
| 465 | - * @access protected |
|
| 466 | - * @return string |
|
| 467 | - */ |
|
| 468 | - protected function hmac($data, $key) |
|
| 469 | - { |
|
| 470 | - if (function_exists('hash_hmac')) { |
|
| 471 | - return hash_hmac('md5', $data, $key); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // The following borrowed from |
|
| 475 | - // http://php.net/manual/en/function.mhash.php#27225 |
|
| 476 | - |
|
| 477 | - // RFC 2104 HMAC implementation for php. |
|
| 478 | - // Creates an md5 HMAC. |
|
| 479 | - // Eliminates the need to install mhash to compute a HMAC |
|
| 480 | - // by Lance Rushing |
|
| 481 | - |
|
| 482 | - $bytelen = 64; // byte length for md5 |
|
| 483 | - if (strlen($key) > $bytelen) { |
|
| 484 | - $key = pack('H*', md5($key)); |
|
| 485 | - } |
|
| 486 | - $key = str_pad($key, $bytelen, chr(0x00)); |
|
| 487 | - $ipad = str_pad('', $bytelen, chr(0x36)); |
|
| 488 | - $opad = str_pad('', $bytelen, chr(0x5c)); |
|
| 489 | - $k_ipad = $key ^ $ipad; |
|
| 490 | - $k_opad = $key ^ $opad; |
|
| 491 | - |
|
| 492 | - return md5($k_opad . pack('H*', md5($k_ipad . $data))); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Check connection state. |
|
| 497 | - * @access public |
|
| 498 | - * @return boolean True if connected. |
|
| 499 | - */ |
|
| 500 | - public function connected() |
|
| 501 | - { |
|
| 502 | - if (is_resource($this->smtp_conn)) { |
|
| 503 | - $sock_status = stream_get_meta_data($this->smtp_conn); |
|
| 504 | - if ($sock_status['eof']) { |
|
| 505 | - // The socket is valid but we are not connected |
|
| 506 | - $this->edebug( |
|
| 507 | - 'SMTP NOTICE: EOF caught while checking if connected', |
|
| 508 | - self::DEBUG_CLIENT |
|
| 509 | - ); |
|
| 510 | - $this->close(); |
|
| 511 | - return false; |
|
| 512 | - } |
|
| 513 | - return true; // everything looks good |
|
| 514 | - } |
|
| 515 | - return false; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * Close the socket and clean up the state of the class. |
|
| 520 | - * Don't use this function without first trying to use QUIT. |
|
| 521 | - * @see quit() |
|
| 522 | - * @access public |
|
| 523 | - * @return void |
|
| 524 | - */ |
|
| 525 | - public function close() |
|
| 526 | - { |
|
| 527 | - $this->setError(''); |
|
| 528 | - $this->server_caps = null; |
|
| 529 | - $this->helo_rply = null; |
|
| 530 | - if (is_resource($this->smtp_conn)) { |
|
| 531 | - // close the connection and cleanup |
|
| 532 | - fclose($this->smtp_conn); |
|
| 533 | - $this->smtp_conn = null; //Makes for cleaner serialization |
|
| 534 | - $this->edebug('Connection: closed', self::DEBUG_CONNECTION); |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Send an SMTP DATA command. |
|
| 540 | - * Issues a data command and sends the msg_data to the server, |
|
| 541 | - * finializing the mail transaction. $msg_data is the message |
|
| 542 | - * that is to be send with the headers. Each header needs to be |
|
| 543 | - * on a single line followed by a <CRLF> with the message headers |
|
| 544 | - * and the message body being separated by and additional <CRLF>. |
|
| 545 | - * Implements rfc 821: DATA <CRLF> |
|
| 546 | - * @param string $msg_data Message data to send |
|
| 547 | - * @access public |
|
| 548 | - * @return boolean |
|
| 549 | - */ |
|
| 550 | - public function data($msg_data) |
|
| 551 | - { |
|
| 552 | - //This will use the standard timelimit |
|
| 553 | - if (!$this->sendCommand('DATA', 'DATA', 354)) { |
|
| 554 | - return false; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /* The server is ready to accept data! |
|
| 29 | + /** |
|
| 30 | + * The PHPMailer SMTP version number. |
|
| 31 | + * @type string |
|
| 32 | + */ |
|
| 33 | + const VERSION = '5.2.10'; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * SMTP line break constant. |
|
| 37 | + * @type string |
|
| 38 | + */ |
|
| 39 | + const CRLF = "\r\n"; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * The SMTP port to use if one is not specified. |
|
| 43 | + * @type integer |
|
| 44 | + */ |
|
| 45 | + const DEFAULT_SMTP_PORT = 25; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * The maximum line length allowed by RFC 2822 section 2.1.1 |
|
| 49 | + * @type integer |
|
| 50 | + */ |
|
| 51 | + const MAX_LINE_LENGTH = 998; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Debug level for no output |
|
| 55 | + */ |
|
| 56 | + const DEBUG_OFF = 0; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Debug level to show client -> server messages |
|
| 60 | + */ |
|
| 61 | + const DEBUG_CLIENT = 1; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Debug level to show client -> server and server -> client messages |
|
| 65 | + */ |
|
| 66 | + const DEBUG_SERVER = 2; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Debug level to show connection status, client -> server and server -> client messages |
|
| 70 | + */ |
|
| 71 | + const DEBUG_CONNECTION = 3; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Debug level to show all messages |
|
| 75 | + */ |
|
| 76 | + const DEBUG_LOWLEVEL = 4; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * The PHPMailer SMTP Version number. |
|
| 80 | + * @type string |
|
| 81 | + * @deprecated Use the `VERSION` constant instead |
|
| 82 | + * @see SMTP::VERSION |
|
| 83 | + */ |
|
| 84 | + public $Version = '5.2.10'; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * SMTP server port number. |
|
| 88 | + * @type integer |
|
| 89 | + * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead |
|
| 90 | + * @see SMTP::DEFAULT_SMTP_PORT |
|
| 91 | + */ |
|
| 92 | + public $SMTP_PORT = 25; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * SMTP reply line ending. |
|
| 96 | + * @type string |
|
| 97 | + * @deprecated Use the `CRLF` constant instead |
|
| 98 | + * @see SMTP::CRLF |
|
| 99 | + */ |
|
| 100 | + public $CRLF = "\r\n"; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Debug output level. |
|
| 104 | + * Options: |
|
| 105 | + * * self::DEBUG_OFF (`0`) No debug output, default |
|
| 106 | + * * self::DEBUG_CLIENT (`1`) Client commands |
|
| 107 | + * * self::DEBUG_SERVER (`2`) Client commands and server responses |
|
| 108 | + * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status |
|
| 109 | + * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages |
|
| 110 | + * @type integer |
|
| 111 | + */ |
|
| 112 | + public $do_debug = self::DEBUG_OFF; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * How to handle debug output. |
|
| 116 | + * Options: |
|
| 117 | + * * `echo` Output plain-text as-is, appropriate for CLI |
|
| 118 | + * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output |
|
| 119 | + * * `error_log` Output to error log as configured in php.ini |
|
| 120 | + * |
|
| 121 | + * Alternatively, you can provide a callable expecting two params: a message string and the debug level: |
|
| 122 | + * <code> |
|
| 123 | + * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; |
|
| 124 | + * </code> |
|
| 125 | + * @type string|callable |
|
| 126 | + */ |
|
| 127 | + public $Debugoutput = 'echo'; |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Whether to use VERP. |
|
| 131 | + * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path |
|
| 132 | + * @link http://www.postfix.org/VERP_README.html Info on VERP |
|
| 133 | + * @type boolean |
|
| 134 | + */ |
|
| 135 | + public $do_verp = false; |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * The timeout value for connection, in seconds. |
|
| 139 | + * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 |
|
| 140 | + * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure. |
|
| 141 | + * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2 |
|
| 142 | + * @type integer |
|
| 143 | + */ |
|
| 144 | + public $Timeout = 300; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * How long to wait for commands to complete, in seconds. |
|
| 148 | + * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 |
|
| 149 | + * @type integer |
|
| 150 | + */ |
|
| 151 | + public $Timelimit = 300; |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * The socket for the server connection. |
|
| 155 | + * @type resource |
|
| 156 | + */ |
|
| 157 | + protected $smtp_conn; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Error information, if any, for the last SMTP command. |
|
| 161 | + * @type array |
|
| 162 | + */ |
|
| 163 | + protected $error = array( |
|
| 164 | + 'error' => '', |
|
| 165 | + 'detail' => '', |
|
| 166 | + 'smtp_code' => '', |
|
| 167 | + 'smtp_code_ex' => '' |
|
| 168 | + ); |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * The reply the server sent to us for HELO. |
|
| 172 | + * If null, no HELO string has yet been received. |
|
| 173 | + * @type string|null |
|
| 174 | + */ |
|
| 175 | + protected $helo_rply = null; |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * The set of SMTP extensions sent in reply to EHLO command. |
|
| 179 | + * Indexes of the array are extension names. |
|
| 180 | + * Value at index 'HELO' or 'EHLO' (according to command that was sent) |
|
| 181 | + * represents the server name. In case of HELO it is the only element of the array. |
|
| 182 | + * Other values can be boolean TRUE or an array containing extension options. |
|
| 183 | + * If null, no HELO/EHLO string has yet been received. |
|
| 184 | + * @type array|null |
|
| 185 | + */ |
|
| 186 | + protected $server_caps = null; |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * The most recent reply received from the server. |
|
| 190 | + * @type string |
|
| 191 | + */ |
|
| 192 | + protected $last_reply = ''; |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Output debugging info via a user-selected method. |
|
| 196 | + * @see SMTP::$Debugoutput |
|
| 197 | + * @see SMTP::$do_debug |
|
| 198 | + * @param string $str Debug string to output |
|
| 199 | + * @param integer $level The debug level of this message; see DEBUG_* constants |
|
| 200 | + * @return void |
|
| 201 | + */ |
|
| 202 | + protected function edebug($str, $level = 0) |
|
| 203 | + { |
|
| 204 | + if ($level > $this->do_debug) { |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + //Avoid clash with built-in function names |
|
| 208 | + if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { |
|
| 209 | + call_user_func($this->Debugoutput, $str, $this->do_debug); |
|
| 210 | + return; |
|
| 211 | + } |
|
| 212 | + switch ($this->Debugoutput) { |
|
| 213 | + case 'error_log': |
|
| 214 | + //Don't output, just log |
|
| 215 | + error_log($str); |
|
| 216 | + break; |
|
| 217 | + case 'html': |
|
| 218 | + //Cleans up output a bit for a better looking, HTML-safe output |
|
| 219 | + echo htmlentities( |
|
| 220 | + preg_replace('/[\r\n]+/', '', $str), |
|
| 221 | + ENT_QUOTES, |
|
| 222 | + 'UTF-8' |
|
| 223 | + ) |
|
| 224 | + . "<br>\n"; |
|
| 225 | + break; |
|
| 226 | + case 'echo': |
|
| 227 | + default: |
|
| 228 | + //Normalize line breaks |
|
| 229 | + $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str); |
|
| 230 | + echo gmdate('Y-m-d H:i:s') . "\t" . str_replace( |
|
| 231 | + "\n", |
|
| 232 | + "\n \t ", |
|
| 233 | + trim($str) |
|
| 234 | + )."\n"; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Connect to an SMTP server. |
|
| 240 | + * @param string $host SMTP server IP or host name |
|
| 241 | + * @param integer $port The port number to connect to |
|
| 242 | + * @param integer $timeout How long to wait for the connection to open |
|
| 243 | + * @param array $options An array of options for stream_context_create() |
|
| 244 | + * @access public |
|
| 245 | + * @return boolean |
|
| 246 | + */ |
|
| 247 | + public function connect($host, $port = null, $timeout = 30, $options = array()) |
|
| 248 | + { |
|
| 249 | + static $streamok; |
|
| 250 | + //This is enabled by default since 5.0.0 but some providers disable it |
|
| 251 | + //Check this once and cache the result |
|
| 252 | + if (is_null($streamok)) { |
|
| 253 | + $streamok = function_exists('stream_socket_client'); |
|
| 254 | + } |
|
| 255 | + // Clear errors to avoid confusion |
|
| 256 | + $this->setError(''); |
|
| 257 | + // Make sure we are __not__ connected |
|
| 258 | + if ($this->connected()) { |
|
| 259 | + // Already connected, generate error |
|
| 260 | + $this->setError('Already connected to a server'); |
|
| 261 | + return false; |
|
| 262 | + } |
|
| 263 | + if (empty($port)) { |
|
| 264 | + $port = self::DEFAULT_SMTP_PORT; |
|
| 265 | + } |
|
| 266 | + // Connect to the SMTP server |
|
| 267 | + $this->edebug( |
|
| 268 | + "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true), |
|
| 269 | + self::DEBUG_CONNECTION |
|
| 270 | + ); |
|
| 271 | + $errno = 0; |
|
| 272 | + $errstr = ''; |
|
| 273 | + if ($streamok) { |
|
| 274 | + $socket_context = stream_context_create($options); |
|
| 275 | + //Suppress errors; connection failures are handled at a higher level |
|
| 276 | + $this->smtp_conn = @stream_socket_client( |
|
| 277 | + $host . ":" . $port, |
|
| 278 | + $errno, |
|
| 279 | + $errstr, |
|
| 280 | + $timeout, |
|
| 281 | + STREAM_CLIENT_CONNECT, |
|
| 282 | + $socket_context |
|
| 283 | + ); |
|
| 284 | + } else { |
|
| 285 | + //Fall back to fsockopen which should work in more places, but is missing some features |
|
| 286 | + $this->edebug( |
|
| 287 | + "Connection: stream_socket_client not available, falling back to fsockopen", |
|
| 288 | + self::DEBUG_CONNECTION |
|
| 289 | + ); |
|
| 290 | + $this->smtp_conn = fsockopen( |
|
| 291 | + $host, |
|
| 292 | + $port, |
|
| 293 | + $errno, |
|
| 294 | + $errstr, |
|
| 295 | + $timeout |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + // Verify we connected properly |
|
| 299 | + if (!is_resource($this->smtp_conn)) { |
|
| 300 | + $this->setError( |
|
| 301 | + 'Failed to connect to server', |
|
| 302 | + $errno, |
|
| 303 | + $errstr |
|
| 304 | + ); |
|
| 305 | + $this->edebug( |
|
| 306 | + 'SMTP ERROR: ' . $this->error['error'] |
|
| 307 | + . ": $errstr ($errno)", |
|
| 308 | + self::DEBUG_CLIENT |
|
| 309 | + ); |
|
| 310 | + return false; |
|
| 311 | + } |
|
| 312 | + $this->edebug('Connection: opened', self::DEBUG_CONNECTION); |
|
| 313 | + // SMTP server can take longer to respond, give longer timeout for first read |
|
| 314 | + // Windows does not have support for this timeout function |
|
| 315 | + if (substr(PHP_OS, 0, 3) != 'WIN') { |
|
| 316 | + $max = ini_get('max_execution_time'); |
|
| 317 | + // Don't bother if unlimited |
|
| 318 | + if ($max != 0 && $timeout > $max) { |
|
| 319 | + @set_time_limit($timeout); |
|
| 320 | + } |
|
| 321 | + stream_set_timeout($this->smtp_conn, $timeout, 0); |
|
| 322 | + } |
|
| 323 | + // Get any announcement |
|
| 324 | + $announce = $this->get_lines(); |
|
| 325 | + $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER); |
|
| 326 | + return true; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Initiate a TLS (encrypted) session. |
|
| 331 | + * @access public |
|
| 332 | + * @return boolean |
|
| 333 | + */ |
|
| 334 | + public function startTLS() |
|
| 335 | + { |
|
| 336 | + if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) { |
|
| 337 | + return false; |
|
| 338 | + } |
|
| 339 | + // Begin encrypted connection |
|
| 340 | + if (!stream_socket_enable_crypto( |
|
| 341 | + $this->smtp_conn, |
|
| 342 | + true, |
|
| 343 | + STREAM_CRYPTO_METHOD_TLS_CLIENT |
|
| 344 | + )) { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + return true; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Perform SMTP authentication. |
|
| 352 | + * Must be run after hello(). |
|
| 353 | + * @see hello() |
|
| 354 | + * @param string $username The user name |
|
| 355 | + * @param string $password The password |
|
| 356 | + * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5) |
|
| 357 | + * @param string $realm The auth realm for NTLM |
|
| 358 | + * @param string $workstation The auth workstation for NTLM |
|
| 359 | + * @access public |
|
| 360 | + * @return boolean True if successfully authenticated. |
|
| 361 | + */ |
|
| 362 | + public function authenticate( |
|
| 363 | + $username, |
|
| 364 | + $password, |
|
| 365 | + $authtype = null, |
|
| 366 | + $realm = '', |
|
| 367 | + $workstation = '' |
|
| 368 | + ) { |
|
| 369 | + if (!$this->server_caps) { |
|
| 370 | + $this->setError('Authentication is not allowed before HELO/EHLO'); |
|
| 371 | + return false; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if (array_key_exists('EHLO', $this->server_caps)) { |
|
| 375 | + // SMTP extensions are available. Let's try to find a proper authentication method |
|
| 376 | + |
|
| 377 | + if (!array_key_exists('AUTH', $this->server_caps)) { |
|
| 378 | + $this->setError('Authentication is not allowed at this stage'); |
|
| 379 | + // 'at this stage' means that auth may be allowed after the stage changes |
|
| 380 | + // e.g. after STARTTLS |
|
| 381 | + return false; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
| 385 | + self::edebug( |
|
| 386 | + 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), |
|
| 387 | + self::DEBUG_LOWLEVEL |
|
| 388 | + ); |
|
| 389 | + |
|
| 390 | + if (empty($authtype)) { |
|
| 391 | + foreach (array('LOGIN', 'CRAM-MD5', 'PLAIN') as $method) { |
|
| 392 | + if (in_array($method, $this->server_caps['AUTH'])) { |
|
| 393 | + $authtype = $method; |
|
| 394 | + break; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + if (empty($authtype)) { |
|
| 398 | + $this->setError('No supported authentication methods found'); |
|
| 399 | + return false; |
|
| 400 | + } |
|
| 401 | + self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if (!in_array($authtype, $this->server_caps['AUTH'])) { |
|
| 405 | + $this->setError("The requested authentication method \"$authtype\" is not supported by the server"); |
|
| 406 | + return false; |
|
| 407 | + } |
|
| 408 | + } elseif (empty($authtype)) { |
|
| 409 | + $authtype = 'LOGIN'; |
|
| 410 | + } |
|
| 411 | + switch ($authtype) { |
|
| 412 | + case 'PLAIN': |
|
| 413 | + // Start authentication |
|
| 414 | + if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { |
|
| 415 | + return false; |
|
| 416 | + } |
|
| 417 | + // Send encoded username and password |
|
| 418 | + if (!$this->sendCommand( |
|
| 419 | + 'User & Password', |
|
| 420 | + base64_encode("\0" . $username . "\0" . $password), |
|
| 421 | + 235 |
|
| 422 | + ) |
|
| 423 | + ) { |
|
| 424 | + return false; |
|
| 425 | + } |
|
| 426 | + break; |
|
| 427 | + case 'LOGIN': |
|
| 428 | + // Start authentication |
|
| 429 | + if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { |
|
| 430 | + return false; |
|
| 431 | + } |
|
| 432 | + if (!$this->sendCommand("Username", base64_encode($username), 334)) { |
|
| 433 | + return false; |
|
| 434 | + } |
|
| 435 | + if (!$this->sendCommand("Password", base64_encode($password), 235)) { |
|
| 436 | + return false; |
|
| 437 | + } |
|
| 438 | + break; |
|
| 439 | + case 'CRAM-MD5': |
|
| 440 | + // Start authentication |
|
| 441 | + if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { |
|
| 442 | + return false; |
|
| 443 | + } |
|
| 444 | + // Get the challenge |
|
| 445 | + $challenge = base64_decode(substr($this->last_reply, 4)); |
|
| 446 | + |
|
| 447 | + // Build the response |
|
| 448 | + $response = $username . ' ' . $this->hmac($challenge, $password); |
|
| 449 | + |
|
| 450 | + // send encoded credentials |
|
| 451 | + return $this->sendCommand('Username', base64_encode($response), 235); |
|
| 452 | + default: |
|
| 453 | + $this->setError("Authentication method \"$authtype\" is not supported"); |
|
| 454 | + return false; |
|
| 455 | + } |
|
| 456 | + return true; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Calculate an MD5 HMAC hash. |
|
| 461 | + * Works like hash_hmac('md5', $data, $key) |
|
| 462 | + * in case that function is not available |
|
| 463 | + * @param string $data The data to hash |
|
| 464 | + * @param string $key The key to hash with |
|
| 465 | + * @access protected |
|
| 466 | + * @return string |
|
| 467 | + */ |
|
| 468 | + protected function hmac($data, $key) |
|
| 469 | + { |
|
| 470 | + if (function_exists('hash_hmac')) { |
|
| 471 | + return hash_hmac('md5', $data, $key); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // The following borrowed from |
|
| 475 | + // http://php.net/manual/en/function.mhash.php#27225 |
|
| 476 | + |
|
| 477 | + // RFC 2104 HMAC implementation for php. |
|
| 478 | + // Creates an md5 HMAC. |
|
| 479 | + // Eliminates the need to install mhash to compute a HMAC |
|
| 480 | + // by Lance Rushing |
|
| 481 | + |
|
| 482 | + $bytelen = 64; // byte length for md5 |
|
| 483 | + if (strlen($key) > $bytelen) { |
|
| 484 | + $key = pack('H*', md5($key)); |
|
| 485 | + } |
|
| 486 | + $key = str_pad($key, $bytelen, chr(0x00)); |
|
| 487 | + $ipad = str_pad('', $bytelen, chr(0x36)); |
|
| 488 | + $opad = str_pad('', $bytelen, chr(0x5c)); |
|
| 489 | + $k_ipad = $key ^ $ipad; |
|
| 490 | + $k_opad = $key ^ $opad; |
|
| 491 | + |
|
| 492 | + return md5($k_opad . pack('H*', md5($k_ipad . $data))); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Check connection state. |
|
| 497 | + * @access public |
|
| 498 | + * @return boolean True if connected. |
|
| 499 | + */ |
|
| 500 | + public function connected() |
|
| 501 | + { |
|
| 502 | + if (is_resource($this->smtp_conn)) { |
|
| 503 | + $sock_status = stream_get_meta_data($this->smtp_conn); |
|
| 504 | + if ($sock_status['eof']) { |
|
| 505 | + // The socket is valid but we are not connected |
|
| 506 | + $this->edebug( |
|
| 507 | + 'SMTP NOTICE: EOF caught while checking if connected', |
|
| 508 | + self::DEBUG_CLIENT |
|
| 509 | + ); |
|
| 510 | + $this->close(); |
|
| 511 | + return false; |
|
| 512 | + } |
|
| 513 | + return true; // everything looks good |
|
| 514 | + } |
|
| 515 | + return false; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * Close the socket and clean up the state of the class. |
|
| 520 | + * Don't use this function without first trying to use QUIT. |
|
| 521 | + * @see quit() |
|
| 522 | + * @access public |
|
| 523 | + * @return void |
|
| 524 | + */ |
|
| 525 | + public function close() |
|
| 526 | + { |
|
| 527 | + $this->setError(''); |
|
| 528 | + $this->server_caps = null; |
|
| 529 | + $this->helo_rply = null; |
|
| 530 | + if (is_resource($this->smtp_conn)) { |
|
| 531 | + // close the connection and cleanup |
|
| 532 | + fclose($this->smtp_conn); |
|
| 533 | + $this->smtp_conn = null; //Makes for cleaner serialization |
|
| 534 | + $this->edebug('Connection: closed', self::DEBUG_CONNECTION); |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Send an SMTP DATA command. |
|
| 540 | + * Issues a data command and sends the msg_data to the server, |
|
| 541 | + * finializing the mail transaction. $msg_data is the message |
|
| 542 | + * that is to be send with the headers. Each header needs to be |
|
| 543 | + * on a single line followed by a <CRLF> with the message headers |
|
| 544 | + * and the message body being separated by and additional <CRLF>. |
|
| 545 | + * Implements rfc 821: DATA <CRLF> |
|
| 546 | + * @param string $msg_data Message data to send |
|
| 547 | + * @access public |
|
| 548 | + * @return boolean |
|
| 549 | + */ |
|
| 550 | + public function data($msg_data) |
|
| 551 | + { |
|
| 552 | + //This will use the standard timelimit |
|
| 553 | + if (!$this->sendCommand('DATA', 'DATA', 354)) { |
|
| 554 | + return false; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /* The server is ready to accept data! |
|
| 558 | 558 | * According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF) |
| 559 | 559 | * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into |
| 560 | 560 | * smaller lines to fit within the limit. |
@@ -562,541 +562,541 @@ discard block |
||
| 562 | 562 | * NOTE: this does not count towards line-length limit. |
| 563 | 563 | */ |
| 564 | 564 | |
| 565 | - // Normalize line breaks before exploding |
|
| 566 | - $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data)); |
|
| 565 | + // Normalize line breaks before exploding |
|
| 566 | + $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data)); |
|
| 567 | 567 | |
| 568 | - /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field |
|
| 568 | + /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field |
|
| 569 | 569 | * of the first line (':' separated) does not contain a space then it _should_ be a header and we will |
| 570 | 570 | * process all lines before a blank line as headers. |
| 571 | 571 | */ |
| 572 | 572 | |
| 573 | - $field = substr($lines[0], 0, strpos($lines[0], ':')); |
|
| 574 | - $in_headers = false; |
|
| 575 | - if (!empty($field) && strpos($field, ' ') === false) { |
|
| 576 | - $in_headers = true; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - foreach ($lines as $line) { |
|
| 580 | - $lines_out = array(); |
|
| 581 | - if ($in_headers and $line == '') { |
|
| 582 | - $in_headers = false; |
|
| 583 | - } |
|
| 584 | - //Break this line up into several smaller lines if it's too long |
|
| 585 | - //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len), |
|
| 586 | - while (isset($line[self::MAX_LINE_LENGTH])) { |
|
| 587 | - //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on |
|
| 588 | - //so as to avoid breaking in the middle of a word |
|
| 589 | - $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' '); |
|
| 590 | - //Deliberately matches both false and 0 |
|
| 591 | - if (!$pos) { |
|
| 592 | - //No nice break found, add a hard break |
|
| 593 | - $pos = self::MAX_LINE_LENGTH - 1; |
|
| 594 | - $lines_out[] = substr($line, 0, $pos); |
|
| 595 | - $line = substr($line, $pos); |
|
| 596 | - } else { |
|
| 597 | - //Break at the found point |
|
| 598 | - $lines_out[] = substr($line, 0, $pos); |
|
| 599 | - //Move along by the amount we dealt with |
|
| 600 | - $line = substr($line, $pos + 1); |
|
| 601 | - } |
|
| 602 | - //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1 |
|
| 603 | - if ($in_headers) { |
|
| 604 | - $line = "\t" . $line; |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - $lines_out[] = $line; |
|
| 608 | - |
|
| 609 | - //Send the lines to the server |
|
| 610 | - foreach ($lines_out as $line_out) { |
|
| 611 | - //RFC2821 section 4.5.2 |
|
| 612 | - if (!empty($line_out) and $line_out[0] == '.') { |
|
| 613 | - $line_out = '.' . $line_out; |
|
| 614 | - } |
|
| 615 | - $this->client_send($line_out . self::CRLF); |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - //Message data has been sent, complete the command |
|
| 620 | - //Increase timelimit for end of DATA command |
|
| 621 | - $savetimelimit = $this->Timelimit; |
|
| 622 | - $this->Timelimit = $this->Timelimit * 2; |
|
| 623 | - $result = $this->sendCommand('DATA END', '.', 250); |
|
| 624 | - //Restore timelimit |
|
| 625 | - $this->Timelimit = $savetimelimit; |
|
| 626 | - return $result; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Send an SMTP HELO or EHLO command. |
|
| 631 | - * Used to identify the sending server to the receiving server. |
|
| 632 | - * This makes sure that client and server are in a known state. |
|
| 633 | - * Implements RFC 821: HELO <SP> <domain> <CRLF> |
|
| 634 | - * and RFC 2821 EHLO. |
|
| 635 | - * @param string $host The host name or IP to connect to |
|
| 636 | - * @access public |
|
| 637 | - * @return boolean |
|
| 638 | - */ |
|
| 639 | - public function hello($host = '') |
|
| 640 | - { |
|
| 641 | - //Try extended hello first (RFC 2821) |
|
| 642 | - return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host)); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Send an SMTP HELO or EHLO command. |
|
| 647 | - * Low-level implementation used by hello() |
|
| 648 | - * @see hello() |
|
| 649 | - * @param string $hello The HELO string |
|
| 650 | - * @param string $host The hostname to say we are |
|
| 651 | - * @access protected |
|
| 652 | - * @return boolean |
|
| 653 | - */ |
|
| 654 | - protected function sendHello($hello, $host) |
|
| 655 | - { |
|
| 656 | - $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250); |
|
| 657 | - $this->helo_rply = $this->last_reply; |
|
| 658 | - if ($noerror) { |
|
| 659 | - $this->parseHelloFields($hello); |
|
| 660 | - } else { |
|
| 661 | - $this->server_caps = null; |
|
| 662 | - } |
|
| 663 | - return $noerror; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Parse a reply to HELO/EHLO command to discover server extensions. |
|
| 668 | - * In case of HELO, the only parameter that can be discovered is a server name. |
|
| 669 | - * @access protected |
|
| 670 | - * @param string $type - 'HELO' or 'EHLO' |
|
| 671 | - */ |
|
| 672 | - protected function parseHelloFields($type) |
|
| 673 | - { |
|
| 674 | - $this->server_caps = array(); |
|
| 675 | - $lines = explode("\n", $this->last_reply); |
|
| 676 | - foreach ($lines as $n => $s) { |
|
| 677 | - $s = trim(substr($s, 4)); |
|
| 678 | - if (!$s) { |
|
| 679 | - continue; |
|
| 680 | - } |
|
| 681 | - $fields = explode(' ', $s); |
|
| 682 | - if (!empty($fields)) { |
|
| 683 | - if (!$n) { |
|
| 684 | - $name = $type; |
|
| 685 | - $fields = $fields[0]; |
|
| 686 | - } else { |
|
| 687 | - $name = array_shift($fields); |
|
| 688 | - if ($name == 'SIZE') { |
|
| 689 | - $fields = ($fields) ? $fields[0] : 0; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - $this->server_caps[$name] = ($fields ? $fields : true); |
|
| 693 | - } |
|
| 694 | - } |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Send an SMTP MAIL command. |
|
| 699 | - * Starts a mail transaction from the email address specified in |
|
| 700 | - * $from. Returns true if successful or false otherwise. If True |
|
| 701 | - * the mail transaction is started and then one or more recipient |
|
| 702 | - * commands may be called followed by a data command. |
|
| 703 | - * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF> |
|
| 704 | - * @param string $from Source address of this message |
|
| 705 | - * @access public |
|
| 706 | - * @return boolean |
|
| 707 | - */ |
|
| 708 | - public function mail($from) |
|
| 709 | - { |
|
| 710 | - $useVerp = ($this->do_verp ? ' XVERP' : ''); |
|
| 711 | - return $this->sendCommand( |
|
| 712 | - 'MAIL FROM', |
|
| 713 | - 'MAIL FROM:<' . $from . '>' . $useVerp, |
|
| 714 | - 250 |
|
| 715 | - ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * Send an SMTP QUIT command. |
|
| 720 | - * Closes the socket if there is no error or the $close_on_error argument is true. |
|
| 721 | - * Implements from rfc 821: QUIT <CRLF> |
|
| 722 | - * @param boolean $close_on_error Should the connection close if an error occurs? |
|
| 723 | - * @access public |
|
| 724 | - * @return boolean |
|
| 725 | - */ |
|
| 726 | - public function quit($close_on_error = true) |
|
| 727 | - { |
|
| 728 | - $noerror = $this->sendCommand('QUIT', 'QUIT', 221); |
|
| 729 | - $err = $this->error; //Save any error |
|
| 730 | - if ($noerror or $close_on_error) { |
|
| 731 | - $this->close(); |
|
| 732 | - $this->error = $err; //Restore any error from the quit command |
|
| 733 | - } |
|
| 734 | - return $noerror; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * Send an SMTP RCPT command. |
|
| 739 | - * Sets the TO argument to $toaddr. |
|
| 740 | - * Returns true if the recipient was accepted false if it was rejected. |
|
| 741 | - * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> |
|
| 742 | - * @param string $toaddr The address the message is being sent to |
|
| 743 | - * @access public |
|
| 744 | - * @return boolean |
|
| 745 | - */ |
|
| 746 | - public function recipient($toaddr) |
|
| 747 | - { |
|
| 748 | - return $this->sendCommand( |
|
| 749 | - 'RCPT TO', |
|
| 750 | - 'RCPT TO:<' . $toaddr . '>', |
|
| 751 | - array(250, 251) |
|
| 752 | - ); |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * Send an SMTP RSET command. |
|
| 757 | - * Abort any transaction that is currently in progress. |
|
| 758 | - * Implements rfc 821: RSET <CRLF> |
|
| 759 | - * @access public |
|
| 760 | - * @return boolean True on success. |
|
| 761 | - */ |
|
| 762 | - public function reset() |
|
| 763 | - { |
|
| 764 | - return $this->sendCommand('RSET', 'RSET', 250); |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - /** |
|
| 768 | - * Send a command to an SMTP server and check its return code. |
|
| 769 | - * @param string $command The command name - not sent to the server |
|
| 770 | - * @param string $commandstring The actual command to send |
|
| 771 | - * @param integer|array $expect One or more expected integer success codes |
|
| 772 | - * @access protected |
|
| 773 | - * @return boolean True on success. |
|
| 774 | - */ |
|
| 775 | - protected function sendCommand($command, $commandstring, $expect) |
|
| 776 | - { |
|
| 777 | - if (!$this->connected()) { |
|
| 778 | - $this->setError("Called $command without being connected"); |
|
| 779 | - return false; |
|
| 780 | - } |
|
| 781 | - $this->client_send($commandstring . self::CRLF); |
|
| 782 | - |
|
| 783 | - $this->last_reply = $this->get_lines(); |
|
| 784 | - // Fetch SMTP code and possible error code explanation |
|
| 785 | - $matches = array(); |
|
| 786 | - if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) { |
|
| 787 | - $code = $matches[1]; |
|
| 788 | - $code_ex = (count($matches) > 2 ? $matches[2] : null); |
|
| 789 | - // Cut off error code from each response line |
|
| 790 | - $detail = preg_replace( |
|
| 791 | - "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m", |
|
| 792 | - '', |
|
| 793 | - $this->last_reply |
|
| 794 | - ); |
|
| 795 | - } else { |
|
| 796 | - // Fall back to simple parsing if regex fails |
|
| 797 | - $code = substr($this->last_reply, 0, 3); |
|
| 798 | - $code_ex = null; |
|
| 799 | - $detail = substr($this->last_reply, 4); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER); |
|
| 803 | - |
|
| 804 | - if (!in_array($code, (array)$expect)) { |
|
| 805 | - $this->setError( |
|
| 806 | - "$command command failed", |
|
| 807 | - $detail, |
|
| 808 | - $code, |
|
| 809 | - $code_ex |
|
| 810 | - ); |
|
| 811 | - $this->edebug( |
|
| 812 | - 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply, |
|
| 813 | - self::DEBUG_CLIENT |
|
| 814 | - ); |
|
| 815 | - return false; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - $this->setError(''); |
|
| 819 | - return true; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * Send an SMTP SAML command. |
|
| 824 | - * Starts a mail transaction from the email address specified in $from. |
|
| 825 | - * Returns true if successful or false otherwise. If True |
|
| 826 | - * the mail transaction is started and then one or more recipient |
|
| 827 | - * commands may be called followed by a data command. This command |
|
| 828 | - * will send the message to the users terminal if they are logged |
|
| 829 | - * in and send them an email. |
|
| 830 | - * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF> |
|
| 831 | - * @param string $from The address the message is from |
|
| 832 | - * @access public |
|
| 833 | - * @return boolean |
|
| 834 | - */ |
|
| 835 | - public function sendAndMail($from) |
|
| 836 | - { |
|
| 837 | - return $this->sendCommand('SAML', "SAML FROM:$from", 250); |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Send an SMTP VRFY command. |
|
| 842 | - * @param string $name The name to verify |
|
| 843 | - * @access public |
|
| 844 | - * @return boolean |
|
| 845 | - */ |
|
| 846 | - public function verify($name) |
|
| 847 | - { |
|
| 848 | - return $this->sendCommand('VRFY', "VRFY $name", array(250, 251)); |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * Send an SMTP NOOP command. |
|
| 853 | - * Used to keep keep-alives alive, doesn't actually do anything |
|
| 854 | - * @access public |
|
| 855 | - * @return boolean |
|
| 856 | - */ |
|
| 857 | - public function noop() |
|
| 858 | - { |
|
| 859 | - return $this->sendCommand('NOOP', 'NOOP', 250); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * Send an SMTP TURN command. |
|
| 864 | - * This is an optional command for SMTP that this class does not support. |
|
| 865 | - * This method is here to make the RFC821 Definition complete for this class |
|
| 866 | - * and _may_ be implemented in future |
|
| 867 | - * Implements from rfc 821: TURN <CRLF> |
|
| 868 | - * @access public |
|
| 869 | - * @return boolean |
|
| 870 | - */ |
|
| 871 | - public function turn() |
|
| 872 | - { |
|
| 873 | - $this->setError('The SMTP TURN command is not implemented'); |
|
| 874 | - $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT); |
|
| 875 | - return false; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - /** |
|
| 879 | - * Send raw data to the server. |
|
| 880 | - * @param string $data The data to send |
|
| 881 | - * @access public |
|
| 882 | - * @return integer|boolean The number of bytes sent to the server or false on error |
|
| 883 | - */ |
|
| 884 | - public function client_send($data) |
|
| 885 | - { |
|
| 886 | - $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT); |
|
| 887 | - return fwrite($this->smtp_conn, $data); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * Get the latest error. |
|
| 892 | - * @access public |
|
| 893 | - * @return array |
|
| 894 | - */ |
|
| 895 | - public function getError() |
|
| 896 | - { |
|
| 897 | - return $this->error; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - /** |
|
| 901 | - * Get SMTP extensions available on the server |
|
| 902 | - * @access public |
|
| 903 | - * @return array|null |
|
| 904 | - */ |
|
| 905 | - public function getServerExtList() |
|
| 906 | - { |
|
| 907 | - return $this->server_caps; |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * A multipurpose method |
|
| 912 | - * The method works in three ways, dependent on argument value and current state |
|
| 913 | - * 1. HELO/EHLO was not sent - returns null and set up $this->error |
|
| 914 | - * 2. HELO was sent |
|
| 915 | - * $name = 'HELO': returns server name |
|
| 916 | - * $name = 'EHLO': returns boolean false |
|
| 917 | - * $name = any string: returns null and set up $this->error |
|
| 918 | - * 3. EHLO was sent |
|
| 919 | - * $name = 'HELO'|'EHLO': returns server name |
|
| 920 | - * $name = any string: if extension $name exists, returns boolean True |
|
| 921 | - * or its options. Otherwise returns boolean False |
|
| 922 | - * In other words, one can use this method to detect 3 conditions: |
|
| 923 | - * - null returned: handshake was not or we don't know about ext (refer to $this->error) |
|
| 924 | - * - false returned: the requested feature exactly not exists |
|
| 925 | - * - positive value returned: the requested feature exists |
|
| 926 | - * @param string $name Name of SMTP extension or 'HELO'|'EHLO' |
|
| 927 | - * @return mixed |
|
| 928 | - */ |
|
| 929 | - public function getServerExt($name) |
|
| 930 | - { |
|
| 931 | - if (!$this->server_caps) { |
|
| 932 | - $this->setError('No HELO/EHLO was sent'); |
|
| 933 | - return null; |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - // the tight logic knot ;) |
|
| 937 | - if (!array_key_exists($name, $this->server_caps)) { |
|
| 938 | - if ($name == 'HELO') { |
|
| 939 | - return $this->server_caps['EHLO']; |
|
| 940 | - } |
|
| 941 | - if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) { |
|
| 942 | - return false; |
|
| 943 | - } |
|
| 944 | - $this->setError('HELO handshake was used. Client knows nothing about server extensions'); |
|
| 945 | - return null; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - return $this->server_caps[$name]; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - /** |
|
| 952 | - * Get the last reply from the server. |
|
| 953 | - * @access public |
|
| 954 | - * @return string |
|
| 955 | - */ |
|
| 956 | - public function getLastReply() |
|
| 957 | - { |
|
| 958 | - return $this->last_reply; |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - /** |
|
| 962 | - * Read the SMTP server's response. |
|
| 963 | - * Either before eof or socket timeout occurs on the operation. |
|
| 964 | - * With SMTP we can tell if we have more lines to read if the |
|
| 965 | - * 4th character is '-' symbol. If it is a space then we don't |
|
| 966 | - * need to read anything else. |
|
| 967 | - * @access protected |
|
| 968 | - * @return string |
|
| 969 | - */ |
|
| 970 | - protected function get_lines() |
|
| 971 | - { |
|
| 972 | - // If the connection is bad, give up straight away |
|
| 973 | - if (!is_resource($this->smtp_conn)) { |
|
| 974 | - return ''; |
|
| 975 | - } |
|
| 976 | - $data = ''; |
|
| 977 | - $endtime = 0; |
|
| 978 | - stream_set_timeout($this->smtp_conn, $this->Timeout); |
|
| 979 | - if ($this->Timelimit > 0) { |
|
| 980 | - $endtime = time() + $this->Timelimit; |
|
| 981 | - } |
|
| 982 | - while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { |
|
| 983 | - $str = @fgets($this->smtp_conn, 515); |
|
| 984 | - $this->edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL); |
|
| 985 | - $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL); |
|
| 986 | - $data .= $str; |
|
| 987 | - $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL); |
|
| 988 | - // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen |
|
| 989 | - if ((isset($str[3]) and $str[3] == ' ')) { |
|
| 990 | - break; |
|
| 991 | - } |
|
| 992 | - // Timed-out? Log and break |
|
| 993 | - $info = stream_get_meta_data($this->smtp_conn); |
|
| 994 | - if ($info['timed_out']) { |
|
| 995 | - $this->edebug( |
|
| 996 | - 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', |
|
| 997 | - self::DEBUG_LOWLEVEL |
|
| 998 | - ); |
|
| 999 | - break; |
|
| 1000 | - } |
|
| 1001 | - // Now check if reads took too long |
|
| 1002 | - if ($endtime and time() > $endtime) { |
|
| 1003 | - $this->edebug( |
|
| 1004 | - 'SMTP -> get_lines(): timelimit reached ('. |
|
| 1005 | - $this->Timelimit . ' sec)', |
|
| 1006 | - self::DEBUG_LOWLEVEL |
|
| 1007 | - ); |
|
| 1008 | - break; |
|
| 1009 | - } |
|
| 1010 | - } |
|
| 1011 | - return $data; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * Enable or disable VERP address generation. |
|
| 1016 | - * @param boolean $enabled |
|
| 1017 | - */ |
|
| 1018 | - public function setVerp($enabled = false) |
|
| 1019 | - { |
|
| 1020 | - $this->do_verp = $enabled; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - /** |
|
| 1024 | - * Get VERP address generation mode. |
|
| 1025 | - * @return boolean |
|
| 1026 | - */ |
|
| 1027 | - public function getVerp() |
|
| 1028 | - { |
|
| 1029 | - return $this->do_verp; |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * Set error messages and codes. |
|
| 1034 | - * @param string $message The error message |
|
| 1035 | - * @param string $detail Further detail on the error |
|
| 1036 | - * @param string $smtp_code An associated SMTP error code |
|
| 1037 | - * @param string $smtp_code_ex Extended SMTP code |
|
| 1038 | - */ |
|
| 1039 | - protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '') |
|
| 1040 | - { |
|
| 1041 | - $this->error = array( |
|
| 1042 | - 'error' => $message, |
|
| 1043 | - 'detail' => $detail, |
|
| 1044 | - 'smtp_code' => $smtp_code, |
|
| 1045 | - 'smtp_code_ex' => $smtp_code_ex |
|
| 1046 | - ); |
|
| 1047 | - } |
|
| 1048 | - |
|
| 1049 | - /** |
|
| 1050 | - * Set debug output method. |
|
| 1051 | - * @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it. |
|
| 1052 | - */ |
|
| 1053 | - public function setDebugOutput($method = 'echo') |
|
| 1054 | - { |
|
| 1055 | - $this->Debugoutput = $method; |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - /** |
|
| 1059 | - * Get debug output method. |
|
| 1060 | - * @return string |
|
| 1061 | - */ |
|
| 1062 | - public function getDebugOutput() |
|
| 1063 | - { |
|
| 1064 | - return $this->Debugoutput; |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - /** |
|
| 1068 | - * Set debug output level. |
|
| 1069 | - * @param integer $level |
|
| 1070 | - */ |
|
| 1071 | - public function setDebugLevel($level = 0) |
|
| 1072 | - { |
|
| 1073 | - $this->do_debug = $level; |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - /** |
|
| 1077 | - * Get debug output level. |
|
| 1078 | - * @return integer |
|
| 1079 | - */ |
|
| 1080 | - public function getDebugLevel() |
|
| 1081 | - { |
|
| 1082 | - return $this->do_debug; |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * Set SMTP timeout. |
|
| 1087 | - * @param integer $timeout |
|
| 1088 | - */ |
|
| 1089 | - public function setTimeout($timeout = 0) |
|
| 1090 | - { |
|
| 1091 | - $this->Timeout = $timeout; |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * Get SMTP timeout. |
|
| 1096 | - * @return integer |
|
| 1097 | - */ |
|
| 1098 | - public function getTimeout() |
|
| 1099 | - { |
|
| 1100 | - return $this->Timeout; |
|
| 1101 | - } |
|
| 573 | + $field = substr($lines[0], 0, strpos($lines[0], ':')); |
|
| 574 | + $in_headers = false; |
|
| 575 | + if (!empty($field) && strpos($field, ' ') === false) { |
|
| 576 | + $in_headers = true; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + foreach ($lines as $line) { |
|
| 580 | + $lines_out = array(); |
|
| 581 | + if ($in_headers and $line == '') { |
|
| 582 | + $in_headers = false; |
|
| 583 | + } |
|
| 584 | + //Break this line up into several smaller lines if it's too long |
|
| 585 | + //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len), |
|
| 586 | + while (isset($line[self::MAX_LINE_LENGTH])) { |
|
| 587 | + //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on |
|
| 588 | + //so as to avoid breaking in the middle of a word |
|
| 589 | + $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' '); |
|
| 590 | + //Deliberately matches both false and 0 |
|
| 591 | + if (!$pos) { |
|
| 592 | + //No nice break found, add a hard break |
|
| 593 | + $pos = self::MAX_LINE_LENGTH - 1; |
|
| 594 | + $lines_out[] = substr($line, 0, $pos); |
|
| 595 | + $line = substr($line, $pos); |
|
| 596 | + } else { |
|
| 597 | + //Break at the found point |
|
| 598 | + $lines_out[] = substr($line, 0, $pos); |
|
| 599 | + //Move along by the amount we dealt with |
|
| 600 | + $line = substr($line, $pos + 1); |
|
| 601 | + } |
|
| 602 | + //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1 |
|
| 603 | + if ($in_headers) { |
|
| 604 | + $line = "\t" . $line; |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + $lines_out[] = $line; |
|
| 608 | + |
|
| 609 | + //Send the lines to the server |
|
| 610 | + foreach ($lines_out as $line_out) { |
|
| 611 | + //RFC2821 section 4.5.2 |
|
| 612 | + if (!empty($line_out) and $line_out[0] == '.') { |
|
| 613 | + $line_out = '.' . $line_out; |
|
| 614 | + } |
|
| 615 | + $this->client_send($line_out . self::CRLF); |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + //Message data has been sent, complete the command |
|
| 620 | + //Increase timelimit for end of DATA command |
|
| 621 | + $savetimelimit = $this->Timelimit; |
|
| 622 | + $this->Timelimit = $this->Timelimit * 2; |
|
| 623 | + $result = $this->sendCommand('DATA END', '.', 250); |
|
| 624 | + //Restore timelimit |
|
| 625 | + $this->Timelimit = $savetimelimit; |
|
| 626 | + return $result; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Send an SMTP HELO or EHLO command. |
|
| 631 | + * Used to identify the sending server to the receiving server. |
|
| 632 | + * This makes sure that client and server are in a known state. |
|
| 633 | + * Implements RFC 821: HELO <SP> <domain> <CRLF> |
|
| 634 | + * and RFC 2821 EHLO. |
|
| 635 | + * @param string $host The host name or IP to connect to |
|
| 636 | + * @access public |
|
| 637 | + * @return boolean |
|
| 638 | + */ |
|
| 639 | + public function hello($host = '') |
|
| 640 | + { |
|
| 641 | + //Try extended hello first (RFC 2821) |
|
| 642 | + return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host)); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Send an SMTP HELO or EHLO command. |
|
| 647 | + * Low-level implementation used by hello() |
|
| 648 | + * @see hello() |
|
| 649 | + * @param string $hello The HELO string |
|
| 650 | + * @param string $host The hostname to say we are |
|
| 651 | + * @access protected |
|
| 652 | + * @return boolean |
|
| 653 | + */ |
|
| 654 | + protected function sendHello($hello, $host) |
|
| 655 | + { |
|
| 656 | + $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250); |
|
| 657 | + $this->helo_rply = $this->last_reply; |
|
| 658 | + if ($noerror) { |
|
| 659 | + $this->parseHelloFields($hello); |
|
| 660 | + } else { |
|
| 661 | + $this->server_caps = null; |
|
| 662 | + } |
|
| 663 | + return $noerror; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Parse a reply to HELO/EHLO command to discover server extensions. |
|
| 668 | + * In case of HELO, the only parameter that can be discovered is a server name. |
|
| 669 | + * @access protected |
|
| 670 | + * @param string $type - 'HELO' or 'EHLO' |
|
| 671 | + */ |
|
| 672 | + protected function parseHelloFields($type) |
|
| 673 | + { |
|
| 674 | + $this->server_caps = array(); |
|
| 675 | + $lines = explode("\n", $this->last_reply); |
|
| 676 | + foreach ($lines as $n => $s) { |
|
| 677 | + $s = trim(substr($s, 4)); |
|
| 678 | + if (!$s) { |
|
| 679 | + continue; |
|
| 680 | + } |
|
| 681 | + $fields = explode(' ', $s); |
|
| 682 | + if (!empty($fields)) { |
|
| 683 | + if (!$n) { |
|
| 684 | + $name = $type; |
|
| 685 | + $fields = $fields[0]; |
|
| 686 | + } else { |
|
| 687 | + $name = array_shift($fields); |
|
| 688 | + if ($name == 'SIZE') { |
|
| 689 | + $fields = ($fields) ? $fields[0] : 0; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + $this->server_caps[$name] = ($fields ? $fields : true); |
|
| 693 | + } |
|
| 694 | + } |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Send an SMTP MAIL command. |
|
| 699 | + * Starts a mail transaction from the email address specified in |
|
| 700 | + * $from. Returns true if successful or false otherwise. If True |
|
| 701 | + * the mail transaction is started and then one or more recipient |
|
| 702 | + * commands may be called followed by a data command. |
|
| 703 | + * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF> |
|
| 704 | + * @param string $from Source address of this message |
|
| 705 | + * @access public |
|
| 706 | + * @return boolean |
|
| 707 | + */ |
|
| 708 | + public function mail($from) |
|
| 709 | + { |
|
| 710 | + $useVerp = ($this->do_verp ? ' XVERP' : ''); |
|
| 711 | + return $this->sendCommand( |
|
| 712 | + 'MAIL FROM', |
|
| 713 | + 'MAIL FROM:<' . $from . '>' . $useVerp, |
|
| 714 | + 250 |
|
| 715 | + ); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * Send an SMTP QUIT command. |
|
| 720 | + * Closes the socket if there is no error or the $close_on_error argument is true. |
|
| 721 | + * Implements from rfc 821: QUIT <CRLF> |
|
| 722 | + * @param boolean $close_on_error Should the connection close if an error occurs? |
|
| 723 | + * @access public |
|
| 724 | + * @return boolean |
|
| 725 | + */ |
|
| 726 | + public function quit($close_on_error = true) |
|
| 727 | + { |
|
| 728 | + $noerror = $this->sendCommand('QUIT', 'QUIT', 221); |
|
| 729 | + $err = $this->error; //Save any error |
|
| 730 | + if ($noerror or $close_on_error) { |
|
| 731 | + $this->close(); |
|
| 732 | + $this->error = $err; //Restore any error from the quit command |
|
| 733 | + } |
|
| 734 | + return $noerror; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * Send an SMTP RCPT command. |
|
| 739 | + * Sets the TO argument to $toaddr. |
|
| 740 | + * Returns true if the recipient was accepted false if it was rejected. |
|
| 741 | + * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> |
|
| 742 | + * @param string $toaddr The address the message is being sent to |
|
| 743 | + * @access public |
|
| 744 | + * @return boolean |
|
| 745 | + */ |
|
| 746 | + public function recipient($toaddr) |
|
| 747 | + { |
|
| 748 | + return $this->sendCommand( |
|
| 749 | + 'RCPT TO', |
|
| 750 | + 'RCPT TO:<' . $toaddr . '>', |
|
| 751 | + array(250, 251) |
|
| 752 | + ); |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * Send an SMTP RSET command. |
|
| 757 | + * Abort any transaction that is currently in progress. |
|
| 758 | + * Implements rfc 821: RSET <CRLF> |
|
| 759 | + * @access public |
|
| 760 | + * @return boolean True on success. |
|
| 761 | + */ |
|
| 762 | + public function reset() |
|
| 763 | + { |
|
| 764 | + return $this->sendCommand('RSET', 'RSET', 250); |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + /** |
|
| 768 | + * Send a command to an SMTP server and check its return code. |
|
| 769 | + * @param string $command The command name - not sent to the server |
|
| 770 | + * @param string $commandstring The actual command to send |
|
| 771 | + * @param integer|array $expect One or more expected integer success codes |
|
| 772 | + * @access protected |
|
| 773 | + * @return boolean True on success. |
|
| 774 | + */ |
|
| 775 | + protected function sendCommand($command, $commandstring, $expect) |
|
| 776 | + { |
|
| 777 | + if (!$this->connected()) { |
|
| 778 | + $this->setError("Called $command without being connected"); |
|
| 779 | + return false; |
|
| 780 | + } |
|
| 781 | + $this->client_send($commandstring . self::CRLF); |
|
| 782 | + |
|
| 783 | + $this->last_reply = $this->get_lines(); |
|
| 784 | + // Fetch SMTP code and possible error code explanation |
|
| 785 | + $matches = array(); |
|
| 786 | + if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) { |
|
| 787 | + $code = $matches[1]; |
|
| 788 | + $code_ex = (count($matches) > 2 ? $matches[2] : null); |
|
| 789 | + // Cut off error code from each response line |
|
| 790 | + $detail = preg_replace( |
|
| 791 | + "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m", |
|
| 792 | + '', |
|
| 793 | + $this->last_reply |
|
| 794 | + ); |
|
| 795 | + } else { |
|
| 796 | + // Fall back to simple parsing if regex fails |
|
| 797 | + $code = substr($this->last_reply, 0, 3); |
|
| 798 | + $code_ex = null; |
|
| 799 | + $detail = substr($this->last_reply, 4); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER); |
|
| 803 | + |
|
| 804 | + if (!in_array($code, (array)$expect)) { |
|
| 805 | + $this->setError( |
|
| 806 | + "$command command failed", |
|
| 807 | + $detail, |
|
| 808 | + $code, |
|
| 809 | + $code_ex |
|
| 810 | + ); |
|
| 811 | + $this->edebug( |
|
| 812 | + 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply, |
|
| 813 | + self::DEBUG_CLIENT |
|
| 814 | + ); |
|
| 815 | + return false; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + $this->setError(''); |
|
| 819 | + return true; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * Send an SMTP SAML command. |
|
| 824 | + * Starts a mail transaction from the email address specified in $from. |
|
| 825 | + * Returns true if successful or false otherwise. If True |
|
| 826 | + * the mail transaction is started and then one or more recipient |
|
| 827 | + * commands may be called followed by a data command. This command |
|
| 828 | + * will send the message to the users terminal if they are logged |
|
| 829 | + * in and send them an email. |
|
| 830 | + * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF> |
|
| 831 | + * @param string $from The address the message is from |
|
| 832 | + * @access public |
|
| 833 | + * @return boolean |
|
| 834 | + */ |
|
| 835 | + public function sendAndMail($from) |
|
| 836 | + { |
|
| 837 | + return $this->sendCommand('SAML', "SAML FROM:$from", 250); |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Send an SMTP VRFY command. |
|
| 842 | + * @param string $name The name to verify |
|
| 843 | + * @access public |
|
| 844 | + * @return boolean |
|
| 845 | + */ |
|
| 846 | + public function verify($name) |
|
| 847 | + { |
|
| 848 | + return $this->sendCommand('VRFY', "VRFY $name", array(250, 251)); |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * Send an SMTP NOOP command. |
|
| 853 | + * Used to keep keep-alives alive, doesn't actually do anything |
|
| 854 | + * @access public |
|
| 855 | + * @return boolean |
|
| 856 | + */ |
|
| 857 | + public function noop() |
|
| 858 | + { |
|
| 859 | + return $this->sendCommand('NOOP', 'NOOP', 250); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * Send an SMTP TURN command. |
|
| 864 | + * This is an optional command for SMTP that this class does not support. |
|
| 865 | + * This method is here to make the RFC821 Definition complete for this class |
|
| 866 | + * and _may_ be implemented in future |
|
| 867 | + * Implements from rfc 821: TURN <CRLF> |
|
| 868 | + * @access public |
|
| 869 | + * @return boolean |
|
| 870 | + */ |
|
| 871 | + public function turn() |
|
| 872 | + { |
|
| 873 | + $this->setError('The SMTP TURN command is not implemented'); |
|
| 874 | + $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT); |
|
| 875 | + return false; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + /** |
|
| 879 | + * Send raw data to the server. |
|
| 880 | + * @param string $data The data to send |
|
| 881 | + * @access public |
|
| 882 | + * @return integer|boolean The number of bytes sent to the server or false on error |
|
| 883 | + */ |
|
| 884 | + public function client_send($data) |
|
| 885 | + { |
|
| 886 | + $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT); |
|
| 887 | + return fwrite($this->smtp_conn, $data); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * Get the latest error. |
|
| 892 | + * @access public |
|
| 893 | + * @return array |
|
| 894 | + */ |
|
| 895 | + public function getError() |
|
| 896 | + { |
|
| 897 | + return $this->error; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + /** |
|
| 901 | + * Get SMTP extensions available on the server |
|
| 902 | + * @access public |
|
| 903 | + * @return array|null |
|
| 904 | + */ |
|
| 905 | + public function getServerExtList() |
|
| 906 | + { |
|
| 907 | + return $this->server_caps; |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * A multipurpose method |
|
| 912 | + * The method works in three ways, dependent on argument value and current state |
|
| 913 | + * 1. HELO/EHLO was not sent - returns null and set up $this->error |
|
| 914 | + * 2. HELO was sent |
|
| 915 | + * $name = 'HELO': returns server name |
|
| 916 | + * $name = 'EHLO': returns boolean false |
|
| 917 | + * $name = any string: returns null and set up $this->error |
|
| 918 | + * 3. EHLO was sent |
|
| 919 | + * $name = 'HELO'|'EHLO': returns server name |
|
| 920 | + * $name = any string: if extension $name exists, returns boolean True |
|
| 921 | + * or its options. Otherwise returns boolean False |
|
| 922 | + * In other words, one can use this method to detect 3 conditions: |
|
| 923 | + * - null returned: handshake was not or we don't know about ext (refer to $this->error) |
|
| 924 | + * - false returned: the requested feature exactly not exists |
|
| 925 | + * - positive value returned: the requested feature exists |
|
| 926 | + * @param string $name Name of SMTP extension or 'HELO'|'EHLO' |
|
| 927 | + * @return mixed |
|
| 928 | + */ |
|
| 929 | + public function getServerExt($name) |
|
| 930 | + { |
|
| 931 | + if (!$this->server_caps) { |
|
| 932 | + $this->setError('No HELO/EHLO was sent'); |
|
| 933 | + return null; |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + // the tight logic knot ;) |
|
| 937 | + if (!array_key_exists($name, $this->server_caps)) { |
|
| 938 | + if ($name == 'HELO') { |
|
| 939 | + return $this->server_caps['EHLO']; |
|
| 940 | + } |
|
| 941 | + if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) { |
|
| 942 | + return false; |
|
| 943 | + } |
|
| 944 | + $this->setError('HELO handshake was used. Client knows nothing about server extensions'); |
|
| 945 | + return null; |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + return $this->server_caps[$name]; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + /** |
|
| 952 | + * Get the last reply from the server. |
|
| 953 | + * @access public |
|
| 954 | + * @return string |
|
| 955 | + */ |
|
| 956 | + public function getLastReply() |
|
| 957 | + { |
|
| 958 | + return $this->last_reply; |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + /** |
|
| 962 | + * Read the SMTP server's response. |
|
| 963 | + * Either before eof or socket timeout occurs on the operation. |
|
| 964 | + * With SMTP we can tell if we have more lines to read if the |
|
| 965 | + * 4th character is '-' symbol. If it is a space then we don't |
|
| 966 | + * need to read anything else. |
|
| 967 | + * @access protected |
|
| 968 | + * @return string |
|
| 969 | + */ |
|
| 970 | + protected function get_lines() |
|
| 971 | + { |
|
| 972 | + // If the connection is bad, give up straight away |
|
| 973 | + if (!is_resource($this->smtp_conn)) { |
|
| 974 | + return ''; |
|
| 975 | + } |
|
| 976 | + $data = ''; |
|
| 977 | + $endtime = 0; |
|
| 978 | + stream_set_timeout($this->smtp_conn, $this->Timeout); |
|
| 979 | + if ($this->Timelimit > 0) { |
|
| 980 | + $endtime = time() + $this->Timelimit; |
|
| 981 | + } |
|
| 982 | + while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { |
|
| 983 | + $str = @fgets($this->smtp_conn, 515); |
|
| 984 | + $this->edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL); |
|
| 985 | + $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL); |
|
| 986 | + $data .= $str; |
|
| 987 | + $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL); |
|
| 988 | + // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen |
|
| 989 | + if ((isset($str[3]) and $str[3] == ' ')) { |
|
| 990 | + break; |
|
| 991 | + } |
|
| 992 | + // Timed-out? Log and break |
|
| 993 | + $info = stream_get_meta_data($this->smtp_conn); |
|
| 994 | + if ($info['timed_out']) { |
|
| 995 | + $this->edebug( |
|
| 996 | + 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', |
|
| 997 | + self::DEBUG_LOWLEVEL |
|
| 998 | + ); |
|
| 999 | + break; |
|
| 1000 | + } |
|
| 1001 | + // Now check if reads took too long |
|
| 1002 | + if ($endtime and time() > $endtime) { |
|
| 1003 | + $this->edebug( |
|
| 1004 | + 'SMTP -> get_lines(): timelimit reached ('. |
|
| 1005 | + $this->Timelimit . ' sec)', |
|
| 1006 | + self::DEBUG_LOWLEVEL |
|
| 1007 | + ); |
|
| 1008 | + break; |
|
| 1009 | + } |
|
| 1010 | + } |
|
| 1011 | + return $data; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * Enable or disable VERP address generation. |
|
| 1016 | + * @param boolean $enabled |
|
| 1017 | + */ |
|
| 1018 | + public function setVerp($enabled = false) |
|
| 1019 | + { |
|
| 1020 | + $this->do_verp = $enabled; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + /** |
|
| 1024 | + * Get VERP address generation mode. |
|
| 1025 | + * @return boolean |
|
| 1026 | + */ |
|
| 1027 | + public function getVerp() |
|
| 1028 | + { |
|
| 1029 | + return $this->do_verp; |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * Set error messages and codes. |
|
| 1034 | + * @param string $message The error message |
|
| 1035 | + * @param string $detail Further detail on the error |
|
| 1036 | + * @param string $smtp_code An associated SMTP error code |
|
| 1037 | + * @param string $smtp_code_ex Extended SMTP code |
|
| 1038 | + */ |
|
| 1039 | + protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '') |
|
| 1040 | + { |
|
| 1041 | + $this->error = array( |
|
| 1042 | + 'error' => $message, |
|
| 1043 | + 'detail' => $detail, |
|
| 1044 | + 'smtp_code' => $smtp_code, |
|
| 1045 | + 'smtp_code_ex' => $smtp_code_ex |
|
| 1046 | + ); |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + /** |
|
| 1050 | + * Set debug output method. |
|
| 1051 | + * @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it. |
|
| 1052 | + */ |
|
| 1053 | + public function setDebugOutput($method = 'echo') |
|
| 1054 | + { |
|
| 1055 | + $this->Debugoutput = $method; |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + /** |
|
| 1059 | + * Get debug output method. |
|
| 1060 | + * @return string |
|
| 1061 | + */ |
|
| 1062 | + public function getDebugOutput() |
|
| 1063 | + { |
|
| 1064 | + return $this->Debugoutput; |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + /** |
|
| 1068 | + * Set debug output level. |
|
| 1069 | + * @param integer $level |
|
| 1070 | + */ |
|
| 1071 | + public function setDebugLevel($level = 0) |
|
| 1072 | + { |
|
| 1073 | + $this->do_debug = $level; |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + /** |
|
| 1077 | + * Get debug output level. |
|
| 1078 | + * @return integer |
|
| 1079 | + */ |
|
| 1080 | + public function getDebugLevel() |
|
| 1081 | + { |
|
| 1082 | + return $this->do_debug; |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * Set SMTP timeout. |
|
| 1087 | + * @param integer $timeout |
|
| 1088 | + */ |
|
| 1089 | + public function setTimeout($timeout = 0) |
|
| 1090 | + { |
|
| 1091 | + $this->Timeout = $timeout; |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * Get SMTP timeout. |
|
| 1096 | + * @return integer |
|
| 1097 | + */ |
|
| 1098 | + public function getTimeout() |
|
| 1099 | + { |
|
| 1100 | + return $this->Timeout; |
|
| 1101 | + } |
|
| 1102 | 1102 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | //Avoid clash with built-in function names |
| 208 | - if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { |
|
| 208 | + if ( ! in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { |
|
| 209 | 209 | call_user_func($this->Debugoutput, $str, $this->do_debug); |
| 210 | 210 | return; |
| 211 | 211 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | default: |
| 228 | 228 | //Normalize line breaks |
| 229 | 229 | $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str); |
| 230 | - echo gmdate('Y-m-d H:i:s') . "\t" . str_replace( |
|
| 230 | + echo gmdate('Y-m-d H:i:s')."\t".str_replace( |
|
| 231 | 231 | "\n", |
| 232 | 232 | "\n \t ", |
| 233 | 233 | trim($str) |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | $socket_context = stream_context_create($options); |
| 275 | 275 | //Suppress errors; connection failures are handled at a higher level |
| 276 | 276 | $this->smtp_conn = @stream_socket_client( |
| 277 | - $host . ":" . $port, |
|
| 277 | + $host.":".$port, |
|
| 278 | 278 | $errno, |
| 279 | 279 | $errstr, |
| 280 | 280 | $timeout, |
@@ -296,14 +296,14 @@ discard block |
||
| 296 | 296 | ); |
| 297 | 297 | } |
| 298 | 298 | // Verify we connected properly |
| 299 | - if (!is_resource($this->smtp_conn)) { |
|
| 299 | + if ( ! is_resource($this->smtp_conn)) { |
|
| 300 | 300 | $this->setError( |
| 301 | 301 | 'Failed to connect to server', |
| 302 | 302 | $errno, |
| 303 | 303 | $errstr |
| 304 | 304 | ); |
| 305 | 305 | $this->edebug( |
| 306 | - 'SMTP ERROR: ' . $this->error['error'] |
|
| 306 | + 'SMTP ERROR: '.$this->error['error'] |
|
| 307 | 307 | . ": $errstr ($errno)", |
| 308 | 308 | self::DEBUG_CLIENT |
| 309 | 309 | ); |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | } |
| 323 | 323 | // Get any announcement |
| 324 | 324 | $announce = $this->get_lines(); |
| 325 | - $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER); |
|
| 325 | + $this->edebug('SERVER -> CLIENT: '.$announce, self::DEBUG_SERVER); |
|
| 326 | 326 | return true; |
| 327 | 327 | } |
| 328 | 328 | |
@@ -333,11 +333,11 @@ discard block |
||
| 333 | 333 | */ |
| 334 | 334 | public function startTLS() |
| 335 | 335 | { |
| 336 | - if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) { |
|
| 336 | + if ( ! $this->sendCommand('STARTTLS', 'STARTTLS', 220)) { |
|
| 337 | 337 | return false; |
| 338 | 338 | } |
| 339 | 339 | // Begin encrypted connection |
| 340 | - if (!stream_socket_enable_crypto( |
|
| 340 | + if ( ! stream_socket_enable_crypto( |
|
| 341 | 341 | $this->smtp_conn, |
| 342 | 342 | true, |
| 343 | 343 | STREAM_CRYPTO_METHOD_TLS_CLIENT |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | $realm = '', |
| 367 | 367 | $workstation = '' |
| 368 | 368 | ) { |
| 369 | - if (!$this->server_caps) { |
|
| 369 | + if ( ! $this->server_caps) { |
|
| 370 | 370 | $this->setError('Authentication is not allowed before HELO/EHLO'); |
| 371 | 371 | return false; |
| 372 | 372 | } |
@@ -374,16 +374,16 @@ discard block |
||
| 374 | 374 | if (array_key_exists('EHLO', $this->server_caps)) { |
| 375 | 375 | // SMTP extensions are available. Let's try to find a proper authentication method |
| 376 | 376 | |
| 377 | - if (!array_key_exists('AUTH', $this->server_caps)) { |
|
| 377 | + if ( ! array_key_exists('AUTH', $this->server_caps)) { |
|
| 378 | 378 | $this->setError('Authentication is not allowed at this stage'); |
| 379 | 379 | // 'at this stage' means that auth may be allowed after the stage changes |
| 380 | 380 | // e.g. after STARTTLS |
| 381 | 381 | return false; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
| 384 | + self::edebug('Auth method requested: '.($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
| 385 | 385 | self::edebug( |
| 386 | - 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), |
|
| 386 | + 'Auth methods available on the server: '.implode(',', $this->server_caps['AUTH']), |
|
| 387 | 387 | self::DEBUG_LOWLEVEL |
| 388 | 388 | ); |
| 389 | 389 | |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - if (!in_array($authtype, $this->server_caps['AUTH'])) { |
|
| 404 | + if ( ! in_array($authtype, $this->server_caps['AUTH'])) { |
|
| 405 | 405 | $this->setError("The requested authentication method \"$authtype\" is not supported by the server"); |
| 406 | 406 | return false; |
| 407 | 407 | } |
@@ -411,13 +411,13 @@ discard block |
||
| 411 | 411 | switch ($authtype) { |
| 412 | 412 | case 'PLAIN': |
| 413 | 413 | // Start authentication |
| 414 | - if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { |
|
| 414 | + if ( ! $this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { |
|
| 415 | 415 | return false; |
| 416 | 416 | } |
| 417 | 417 | // Send encoded username and password |
| 418 | - if (!$this->sendCommand( |
|
| 418 | + if ( ! $this->sendCommand( |
|
| 419 | 419 | 'User & Password', |
| 420 | - base64_encode("\0" . $username . "\0" . $password), |
|
| 420 | + base64_encode("\0".$username."\0".$password), |
|
| 421 | 421 | 235 |
| 422 | 422 | ) |
| 423 | 423 | ) { |
@@ -426,26 +426,26 @@ discard block |
||
| 426 | 426 | break; |
| 427 | 427 | case 'LOGIN': |
| 428 | 428 | // Start authentication |
| 429 | - if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { |
|
| 429 | + if ( ! $this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { |
|
| 430 | 430 | return false; |
| 431 | 431 | } |
| 432 | - if (!$this->sendCommand("Username", base64_encode($username), 334)) { |
|
| 432 | + if ( ! $this->sendCommand("Username", base64_encode($username), 334)) { |
|
| 433 | 433 | return false; |
| 434 | 434 | } |
| 435 | - if (!$this->sendCommand("Password", base64_encode($password), 235)) { |
|
| 435 | + if ( ! $this->sendCommand("Password", base64_encode($password), 235)) { |
|
| 436 | 436 | return false; |
| 437 | 437 | } |
| 438 | 438 | break; |
| 439 | 439 | case 'CRAM-MD5': |
| 440 | 440 | // Start authentication |
| 441 | - if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { |
|
| 441 | + if ( ! $this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { |
|
| 442 | 442 | return false; |
| 443 | 443 | } |
| 444 | 444 | // Get the challenge |
| 445 | 445 | $challenge = base64_decode(substr($this->last_reply, 4)); |
| 446 | 446 | |
| 447 | 447 | // Build the response |
| 448 | - $response = $username . ' ' . $this->hmac($challenge, $password); |
|
| 448 | + $response = $username.' '.$this->hmac($challenge, $password); |
|
| 449 | 449 | |
| 450 | 450 | // send encoded credentials |
| 451 | 451 | return $this->sendCommand('Username', base64_encode($response), 235); |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | $k_ipad = $key ^ $ipad; |
| 490 | 490 | $k_opad = $key ^ $opad; |
| 491 | 491 | |
| 492 | - return md5($k_opad . pack('H*', md5($k_ipad . $data))); |
|
| 492 | + return md5($k_opad.pack('H*', md5($k_ipad.$data))); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | public function data($msg_data) |
| 551 | 551 | { |
| 552 | 552 | //This will use the standard timelimit |
| 553 | - if (!$this->sendCommand('DATA', 'DATA', 354)) { |
|
| 553 | + if ( ! $this->sendCommand('DATA', 'DATA', 354)) { |
|
| 554 | 554 | return false; |
| 555 | 555 | } |
| 556 | 556 | |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | |
| 573 | 573 | $field = substr($lines[0], 0, strpos($lines[0], ':')); |
| 574 | 574 | $in_headers = false; |
| 575 | - if (!empty($field) && strpos($field, ' ') === false) { |
|
| 575 | + if ( ! empty($field) && strpos($field, ' ') === false) { |
|
| 576 | 576 | $in_headers = true; |
| 577 | 577 | } |
| 578 | 578 | |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | //so as to avoid breaking in the middle of a word |
| 589 | 589 | $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' '); |
| 590 | 590 | //Deliberately matches both false and 0 |
| 591 | - if (!$pos) { |
|
| 591 | + if ( ! $pos) { |
|
| 592 | 592 | //No nice break found, add a hard break |
| 593 | 593 | $pos = self::MAX_LINE_LENGTH - 1; |
| 594 | 594 | $lines_out[] = substr($line, 0, $pos); |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | } |
| 602 | 602 | //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1 |
| 603 | 603 | if ($in_headers) { |
| 604 | - $line = "\t" . $line; |
|
| 604 | + $line = "\t".$line; |
|
| 605 | 605 | } |
| 606 | 606 | } |
| 607 | 607 | $lines_out[] = $line; |
@@ -609,10 +609,10 @@ discard block |
||
| 609 | 609 | //Send the lines to the server |
| 610 | 610 | foreach ($lines_out as $line_out) { |
| 611 | 611 | //RFC2821 section 4.5.2 |
| 612 | - if (!empty($line_out) and $line_out[0] == '.') { |
|
| 613 | - $line_out = '.' . $line_out; |
|
| 612 | + if ( ! empty($line_out) and $line_out[0] == '.') { |
|
| 613 | + $line_out = '.'.$line_out; |
|
| 614 | 614 | } |
| 615 | - $this->client_send($line_out . self::CRLF); |
|
| 615 | + $this->client_send($line_out.self::CRLF); |
|
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | public function hello($host = '') |
| 640 | 640 | { |
| 641 | 641 | //Try extended hello first (RFC 2821) |
| 642 | - return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host)); |
|
| 642 | + return (boolean) ($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host)); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | /** |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | */ |
| 654 | 654 | protected function sendHello($hello, $host) |
| 655 | 655 | { |
| 656 | - $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250); |
|
| 656 | + $noerror = $this->sendCommand($hello, $hello.' '.$host, 250); |
|
| 657 | 657 | $this->helo_rply = $this->last_reply; |
| 658 | 658 | if ($noerror) { |
| 659 | 659 | $this->parseHelloFields($hello); |
@@ -675,12 +675,12 @@ discard block |
||
| 675 | 675 | $lines = explode("\n", $this->last_reply); |
| 676 | 676 | foreach ($lines as $n => $s) { |
| 677 | 677 | $s = trim(substr($s, 4)); |
| 678 | - if (!$s) { |
|
| 678 | + if ( ! $s) { |
|
| 679 | 679 | continue; |
| 680 | 680 | } |
| 681 | 681 | $fields = explode(' ', $s); |
| 682 | - if (!empty($fields)) { |
|
| 683 | - if (!$n) { |
|
| 682 | + if ( ! empty($fields)) { |
|
| 683 | + if ( ! $n) { |
|
| 684 | 684 | $name = $type; |
| 685 | 685 | $fields = $fields[0]; |
| 686 | 686 | } else { |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | $useVerp = ($this->do_verp ? ' XVERP' : ''); |
| 711 | 711 | return $this->sendCommand( |
| 712 | 712 | 'MAIL FROM', |
| 713 | - 'MAIL FROM:<' . $from . '>' . $useVerp, |
|
| 713 | + 'MAIL FROM:<'.$from.'>'.$useVerp, |
|
| 714 | 714 | 250 |
| 715 | 715 | ); |
| 716 | 716 | } |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | { |
| 748 | 748 | return $this->sendCommand( |
| 749 | 749 | 'RCPT TO', |
| 750 | - 'RCPT TO:<' . $toaddr . '>', |
|
| 750 | + 'RCPT TO:<'.$toaddr.'>', |
|
| 751 | 751 | array(250, 251) |
| 752 | 752 | ); |
| 753 | 753 | } |
@@ -774,11 +774,11 @@ discard block |
||
| 774 | 774 | */ |
| 775 | 775 | protected function sendCommand($command, $commandstring, $expect) |
| 776 | 776 | { |
| 777 | - if (!$this->connected()) { |
|
| 777 | + if ( ! $this->connected()) { |
|
| 778 | 778 | $this->setError("Called $command without being connected"); |
| 779 | 779 | return false; |
| 780 | 780 | } |
| 781 | - $this->client_send($commandstring . self::CRLF); |
|
| 781 | + $this->client_send($commandstring.self::CRLF); |
|
| 782 | 782 | |
| 783 | 783 | $this->last_reply = $this->get_lines(); |
| 784 | 784 | // Fetch SMTP code and possible error code explanation |
@@ -799,9 +799,9 @@ discard block |
||
| 799 | 799 | $detail = substr($this->last_reply, 4); |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | - $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER); |
|
| 802 | + $this->edebug('SERVER -> CLIENT: '.$this->last_reply, self::DEBUG_SERVER); |
|
| 803 | 803 | |
| 804 | - if (!in_array($code, (array)$expect)) { |
|
| 804 | + if ( ! in_array($code, (array) $expect)) { |
|
| 805 | 805 | $this->setError( |
| 806 | 806 | "$command command failed", |
| 807 | 807 | $detail, |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | $code_ex |
| 810 | 810 | ); |
| 811 | 811 | $this->edebug( |
| 812 | - 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply, |
|
| 812 | + 'SMTP ERROR: '.$this->error['error'].': '.$this->last_reply, |
|
| 813 | 813 | self::DEBUG_CLIENT |
| 814 | 814 | ); |
| 815 | 815 | return false; |
@@ -871,7 +871,7 @@ discard block |
||
| 871 | 871 | public function turn() |
| 872 | 872 | { |
| 873 | 873 | $this->setError('The SMTP TURN command is not implemented'); |
| 874 | - $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT); |
|
| 874 | + $this->edebug('SMTP NOTICE: '.$this->error['error'], self::DEBUG_CLIENT); |
|
| 875 | 875 | return false; |
| 876 | 876 | } |
| 877 | 877 | |
@@ -928,13 +928,13 @@ discard block |
||
| 928 | 928 | */ |
| 929 | 929 | public function getServerExt($name) |
| 930 | 930 | { |
| 931 | - if (!$this->server_caps) { |
|
| 931 | + if ( ! $this->server_caps) { |
|
| 932 | 932 | $this->setError('No HELO/EHLO was sent'); |
| 933 | 933 | return null; |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | // the tight logic knot ;) |
| 937 | - if (!array_key_exists($name, $this->server_caps)) { |
|
| 937 | + if ( ! array_key_exists($name, $this->server_caps)) { |
|
| 938 | 938 | if ($name == 'HELO') { |
| 939 | 939 | return $this->server_caps['EHLO']; |
| 940 | 940 | } |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | protected function get_lines() |
| 971 | 971 | { |
| 972 | 972 | // If the connection is bad, give up straight away |
| 973 | - if (!is_resource($this->smtp_conn)) { |
|
| 973 | + if ( ! is_resource($this->smtp_conn)) { |
|
| 974 | 974 | return ''; |
| 975 | 975 | } |
| 976 | 976 | $data = ''; |
@@ -979,7 +979,7 @@ discard block |
||
| 979 | 979 | if ($this->Timelimit > 0) { |
| 980 | 980 | $endtime = time() + $this->Timelimit; |
| 981 | 981 | } |
| 982 | - while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { |
|
| 982 | + while (is_resource($this->smtp_conn) && ! feof($this->smtp_conn)) { |
|
| 983 | 983 | $str = @fgets($this->smtp_conn, 515); |
| 984 | 984 | $this->edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL); |
| 985 | 985 | $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL); |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | $info = stream_get_meta_data($this->smtp_conn); |
| 994 | 994 | if ($info['timed_out']) { |
| 995 | 995 | $this->edebug( |
| 996 | - 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', |
|
| 996 | + 'SMTP -> get_lines(): timed-out ('.$this->Timeout.' sec)', |
|
| 997 | 997 | self::DEBUG_LOWLEVEL |
| 998 | 998 | ); |
| 999 | 999 | break; |
@@ -1002,7 +1002,7 @@ discard block |
||
| 1002 | 1002 | if ($endtime and time() > $endtime) { |
| 1003 | 1003 | $this->edebug( |
| 1004 | 1004 | 'SMTP -> get_lines(): timelimit reached ('. |
| 1005 | - $this->Timelimit . ' sec)', |
|
| 1005 | + $this->Timelimit.' sec)', |
|
| 1006 | 1006 | self::DEBUG_LOWLEVEL |
| 1007 | 1007 | ); |
| 1008 | 1008 | break; |
@@ -781,6 +781,9 @@ discard block |
||
| 781 | 781 | Output: |
| 782 | 782 | \*======================================================================*/ |
| 783 | 783 | |
| 784 | + /** |
|
| 785 | + * @param string $http_method |
|
| 786 | + */ |
|
| 784 | 787 | function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
| 785 | 788 | { |
| 786 | 789 | $cookie_headers = ''; |
@@ -944,6 +947,9 @@ discard block |
||
| 944 | 947 | Output: |
| 945 | 948 | \*======================================================================*/ |
| 946 | 949 | |
| 950 | + /** |
|
| 951 | + * @param string $http_method |
|
| 952 | + */ |
|
| 947 | 953 | function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
| 948 | 954 | { |
| 949 | 955 | if($this->passcookies && $this->_redirectaddr) |
@@ -1189,6 +1195,10 @@ discard block |
||
| 1189 | 1195 | Output: post body |
| 1190 | 1196 | \*======================================================================*/ |
| 1191 | 1197 | |
| 1198 | + /** |
|
| 1199 | + * @param string $formvars |
|
| 1200 | + * @param string $formfiles |
|
| 1201 | + */ |
|
| 1192 | 1202 | function _prepare_post_body($formvars, $formfiles) |
| 1193 | 1203 | { |
| 1194 | 1204 | settype($formvars, "array"); |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | if(!$this->curl_path) |
| 206 | 206 | return false; |
| 207 | 207 | if(function_exists("is_executable")) |
| 208 | - if (!is_executable($this->curl_path)) |
|
| 209 | - return false; |
|
| 208 | + if (!is_executable($this->curl_path)) |
|
| 209 | + return false; |
|
| 210 | 210 | $this->host = $URI_PARTS["host"]; |
| 211 | 211 | if(!empty($URI_PARTS["port"])) |
| 212 | 212 | $this->port = $URI_PARTS["port"]; |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | if(!$this->curl_path) |
| 365 | 365 | return false; |
| 366 | 366 | if(function_exists("is_executable")) |
| 367 | - if (!is_executable($this->curl_path)) |
|
| 368 | - return false; |
|
| 367 | + if (!is_executable($this->curl_path)) |
|
| 368 | + return false; |
|
| 369 | 369 | $this->host = $URI_PARTS["host"]; |
| 370 | 370 | if(!empty($URI_PARTS["port"])) |
| 371 | 371 | $this->port = $URI_PARTS["port"]; |
@@ -885,10 +885,10 @@ discard block |
||
| 885 | 885 | |
| 886 | 886 | if(preg_match("|^HTTP/|",$currentHeader)) |
| 887 | 887 | { |
| 888 | - if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) |
|
| 888 | + if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) |
|
| 889 | 889 | { |
| 890 | 890 | $this->status= $status[1]; |
| 891 | - } |
|
| 891 | + } |
|
| 892 | 892 | $this->response_code = $currentHeader; |
| 893 | 893 | } |
| 894 | 894 | |
@@ -897,11 +897,11 @@ discard block |
||
| 897 | 897 | |
| 898 | 898 | $results = ''; |
| 899 | 899 | do { |
| 900 | - $_data = fread($fp, $this->maxlength); |
|
| 901 | - if (strlen($_data) == 0) { |
|
| 902 | - break; |
|
| 903 | - } |
|
| 904 | - $results .= $_data; |
|
| 900 | + $_data = fread($fp, $this->maxlength); |
|
| 901 | + if (strlen($_data) == 0) { |
|
| 902 | + break; |
|
| 903 | + } |
|
| 904 | + $results .= $_data; |
|
| 905 | 905 | } while(true); |
| 906 | 906 | |
| 907 | 907 | if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
@@ -3,9 +3,9 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * Deprecated. Use WP_HTTP (http.php, class-http.php) instead. |
| 5 | 5 | */ |
| 6 | -_deprecated_file( basename( __FILE__ ), '3.0', WPINC . '/http.php' ); |
|
| 6 | +_deprecated_file(basename(__FILE__), '3.0', WPINC.'/http.php'); |
|
| 7 | 7 | |
| 8 | -if ( !class_exists( 'Snoopy' ) ) : |
|
| 8 | +if ( ! class_exists('Snoopy')) : |
|
| 9 | 9 | /************************************************* |
| 10 | 10 | |
| 11 | 11 | Snoopy - the PHP net client |
@@ -41,54 +41,54 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | /* user definable vars */ |
| 43 | 43 | |
| 44 | - var $host = "www.php.net"; // host name we are connecting to |
|
| 45 | - var $port = 80; // port we are connecting to |
|
| 46 | - var $proxy_host = ""; // proxy host to use |
|
| 47 | - var $proxy_port = ""; // proxy port to use |
|
| 48 | - var $proxy_user = ""; // proxy user to use |
|
| 49 | - var $proxy_pass = ""; // proxy password to use |
|
| 44 | + var $host = "www.php.net"; // host name we are connecting to |
|
| 45 | + var $port = 80; // port we are connecting to |
|
| 46 | + var $proxy_host = ""; // proxy host to use |
|
| 47 | + var $proxy_port = ""; // proxy port to use |
|
| 48 | + var $proxy_user = ""; // proxy user to use |
|
| 49 | + var $proxy_pass = ""; // proxy password to use |
|
| 50 | 50 | |
| 51 | - var $agent = "Snoopy v1.2.4"; // agent we masquerade as |
|
| 52 | - var $referer = ""; // referer info to pass |
|
| 53 | - var $cookies = array(); // array of cookies to pass |
|
| 51 | + var $agent = "Snoopy v1.2.4"; // agent we masquerade as |
|
| 52 | + var $referer = ""; // referer info to pass |
|
| 53 | + var $cookies = array(); // array of cookies to pass |
|
| 54 | 54 | // $cookies["username"]="joe"; |
| 55 | - var $rawheaders = array(); // array of raw headers to send |
|
| 55 | + var $rawheaders = array(); // array of raw headers to send |
|
| 56 | 56 | // $rawheaders["Content-type"]="text/html"; |
| 57 | 57 | |
| 58 | - var $maxredirs = 5; // http redirection depth maximum. 0 = disallow |
|
| 59 | - var $lastredirectaddr = ""; // contains address of last redirected address |
|
| 60 | - var $offsiteok = true; // allows redirection off-site |
|
| 61 | - var $maxframes = 0; // frame content depth maximum. 0 = disallow |
|
| 62 | - var $expandlinks = true; // expand links to fully qualified URLs. |
|
| 58 | + var $maxredirs = 5; // http redirection depth maximum. 0 = disallow |
|
| 59 | + var $lastredirectaddr = ""; // contains address of last redirected address |
|
| 60 | + var $offsiteok = true; // allows redirection off-site |
|
| 61 | + var $maxframes = 0; // frame content depth maximum. 0 = disallow |
|
| 62 | + var $expandlinks = true; // expand links to fully qualified URLs. |
|
| 63 | 63 | // this only applies to fetchlinks() |
| 64 | 64 | // submitlinks(), and submittext() |
| 65 | - var $passcookies = true; // pass set cookies back through redirects |
|
| 65 | + var $passcookies = true; // pass set cookies back through redirects |
|
| 66 | 66 | // NOTE: this currently does not respect |
| 67 | 67 | // dates, domains or paths. |
| 68 | 68 | |
| 69 | - var $user = ""; // user for http authentication |
|
| 70 | - var $pass = ""; // password for http authentication |
|
| 69 | + var $user = ""; // user for http authentication |
|
| 70 | + var $pass = ""; // password for http authentication |
|
| 71 | 71 | |
| 72 | 72 | // http accept types |
| 73 | - var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|
| 73 | + var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|
| 74 | 74 | |
| 75 | - var $results = ""; // where the content is put |
|
| 75 | + var $results = ""; // where the content is put |
|
| 76 | 76 | |
| 77 | - var $error = ""; // error messages sent here |
|
| 78 | - var $response_code = ""; // response code returned from server |
|
| 79 | - var $headers = array(); // headers returned from server sent here |
|
| 80 | - var $maxlength = 500000; // max return data length (body) |
|
| 81 | - var $read_timeout = 0; // timeout on read operations, in seconds |
|
| 77 | + var $error = ""; // error messages sent here |
|
| 78 | + var $response_code = ""; // response code returned from server |
|
| 79 | + var $headers = array(); // headers returned from server sent here |
|
| 80 | + var $maxlength = 500000; // max return data length (body) |
|
| 81 | + var $read_timeout = 0; // timeout on read operations, in seconds |
|
| 82 | 82 | // supported only since PHP 4 Beta 4 |
| 83 | 83 | // set to 0 to disallow timeouts |
| 84 | - var $timed_out = false; // if a read operation timed out |
|
| 85 | - var $status = 0; // http request status |
|
| 84 | + var $timed_out = false; // if a read operation timed out |
|
| 85 | + var $status = 0; // http request status |
|
| 86 | 86 | |
| 87 | - var $temp_dir = "/tmp"; // temporary directory that the webserver |
|
| 87 | + var $temp_dir = "/tmp"; // temporary directory that the webserver |
|
| 88 | 88 | // has permission to write to. |
| 89 | 89 | // under Windows, this should be C:\temp |
| 90 | 90 | |
| 91 | - var $curl_path = "/usr/local/bin/curl"; |
|
| 91 | + var $curl_path = "/usr/local/bin/curl"; |
|
| 92 | 92 | // Snoopy will use cURL for fetching |
| 93 | 93 | // SSL content if a full system path to |
| 94 | 94 | // the cURL binary is supplied here. |
@@ -102,20 +102,20 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | /**** Private variables ****/ |
| 104 | 104 | |
| 105 | - var $_maxlinelen = 4096; // max line length (headers) |
|
| 105 | + var $_maxlinelen = 4096; // max line length (headers) |
|
| 106 | 106 | |
| 107 | - var $_httpmethod = "GET"; // default http request method |
|
| 108 | - var $_httpversion = "HTTP/1.0"; // default http request version |
|
| 109 | - var $_submit_method = "POST"; // default submit method |
|
| 110 | - var $_submit_type = "application/x-www-form-urlencoded"; // default submit type |
|
| 111 | - var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type |
|
| 112 | - var $_redirectaddr = false; // will be set if page fetched is a redirect |
|
| 113 | - var $_redirectdepth = 0; // increments on an http redirect |
|
| 114 | - var $_frameurls = array(); // frame src urls |
|
| 115 | - var $_framedepth = 0; // increments on frame depth |
|
| 107 | + var $_httpmethod = "GET"; // default http request method |
|
| 108 | + var $_httpversion = "HTTP/1.0"; // default http request version |
|
| 109 | + var $_submit_method = "POST"; // default submit method |
|
| 110 | + var $_submit_type = "application/x-www-form-urlencoded"; // default submit type |
|
| 111 | + var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type |
|
| 112 | + var $_redirectaddr = false; // will be set if page fetched is a redirect |
|
| 113 | + var $_redirectdepth = 0; // increments on an http redirect |
|
| 114 | + var $_frameurls = array(); // frame src urls |
|
| 115 | + var $_framedepth = 0; // increments on frame depth |
|
| 116 | 116 | |
| 117 | - var $_isproxy = false; // set if using a proxy server |
|
| 118 | - var $_fp_timeout = 30; // timeout for socket connection |
|
| 117 | + var $_isproxy = false; // set if using a proxy server |
|
| 118 | + var $_fp_timeout = 30; // timeout for socket connection |
|
| 119 | 119 | |
| 120 | 120 | /*======================================================================*\ |
| 121 | 121 | Function: fetch |
@@ -131,27 +131,27 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); |
| 133 | 133 | $URI_PARTS = parse_url($URI); |
| 134 | - if (!empty($URI_PARTS["user"])) |
|
| 134 | + if ( ! empty($URI_PARTS["user"])) |
|
| 135 | 135 | $this->user = $URI_PARTS["user"]; |
| 136 | - if (!empty($URI_PARTS["pass"])) |
|
| 136 | + if ( ! empty($URI_PARTS["pass"])) |
|
| 137 | 137 | $this->pass = $URI_PARTS["pass"]; |
| 138 | 138 | if (empty($URI_PARTS["query"])) |
| 139 | 139 | $URI_PARTS["query"] = ''; |
| 140 | 140 | if (empty($URI_PARTS["path"])) |
| 141 | 141 | $URI_PARTS["path"] = ''; |
| 142 | 142 | |
| 143 | - switch(strtolower($URI_PARTS["scheme"])) |
|
| 143 | + switch (strtolower($URI_PARTS["scheme"])) |
|
| 144 | 144 | { |
| 145 | 145 | case "http": |
| 146 | 146 | $this->host = $URI_PARTS["host"]; |
| 147 | - if(!empty($URI_PARTS["port"])) |
|
| 147 | + if ( ! empty($URI_PARTS["port"])) |
|
| 148 | 148 | $this->port = $URI_PARTS["port"]; |
| 149 | - if($this->_connect($fp)) |
|
| 149 | + if ($this->_connect($fp)) |
|
| 150 | 150 | { |
| 151 | - if($this->_isproxy) |
|
| 151 | + if ($this->_isproxy) |
|
| 152 | 152 | { |
| 153 | 153 | // using proxy, send entire URI |
| 154 | - $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
|
| 154 | + $this->_httprequest($URI, $fp, $URI, $this->_httpmethod); |
|
| 155 | 155 | } |
| 156 | 156 | else |
| 157 | 157 | { |
@@ -162,30 +162,30 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | $this->_disconnect($fp); |
| 164 | 164 | |
| 165 | - if($this->_redirectaddr) |
|
| 165 | + if ($this->_redirectaddr) |
|
| 166 | 166 | { |
| 167 | 167 | /* url was redirected, check if we've hit the max depth */ |
| 168 | - if($this->maxredirs > $this->_redirectdepth) |
|
| 168 | + if ($this->maxredirs > $this->_redirectdepth) |
|
| 169 | 169 | { |
| 170 | 170 | // only follow redirect if it's on this site, or offsiteok is true |
| 171 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
| 171 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
| 172 | 172 | { |
| 173 | 173 | /* follow the redirect */ |
| 174 | 174 | $this->_redirectdepth++; |
| 175 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
| 175 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
| 176 | 176 | $this->fetch($this->_redirectaddr); |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 181 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 182 | 182 | { |
| 183 | 183 | $frameurls = $this->_frameurls; |
| 184 | 184 | $this->_frameurls = array(); |
| 185 | 185 | |
| 186 | - while(list(,$frameurl) = each($frameurls)) |
|
| 186 | + while (list(,$frameurl) = each($frameurls)) |
|
| 187 | 187 | { |
| 188 | - if($this->_framedepth < $this->maxframes) |
|
| 188 | + if ($this->_framedepth < $this->maxframes) |
|
| 189 | 189 | { |
| 190 | 190 | $this->fetch($frameurl); |
| 191 | 191 | $this->_framedepth++; |
@@ -202,18 +202,18 @@ discard block |
||
| 202 | 202 | return true; |
| 203 | 203 | break; |
| 204 | 204 | case "https": |
| 205 | - if(!$this->curl_path) |
|
| 205 | + if ( ! $this->curl_path) |
|
| 206 | 206 | return false; |
| 207 | - if(function_exists("is_executable")) |
|
| 208 | - if (!is_executable($this->curl_path)) |
|
| 207 | + if (function_exists("is_executable")) |
|
| 208 | + if ( ! is_executable($this->curl_path)) |
|
| 209 | 209 | return false; |
| 210 | 210 | $this->host = $URI_PARTS["host"]; |
| 211 | - if(!empty($URI_PARTS["port"])) |
|
| 211 | + if ( ! empty($URI_PARTS["port"])) |
|
| 212 | 212 | $this->port = $URI_PARTS["port"]; |
| 213 | - if($this->_isproxy) |
|
| 213 | + if ($this->_isproxy) |
|
| 214 | 214 | { |
| 215 | 215 | // using proxy, send entire URI |
| 216 | - $this->_httpsrequest($URI,$URI,$this->_httpmethod); |
|
| 216 | + $this->_httpsrequest($URI, $URI, $this->_httpmethod); |
|
| 217 | 217 | } |
| 218 | 218 | else |
| 219 | 219 | { |
@@ -222,30 +222,30 @@ discard block |
||
| 222 | 222 | $this->_httpsrequest($path, $URI, $this->_httpmethod); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - if($this->_redirectaddr) |
|
| 225 | + if ($this->_redirectaddr) |
|
| 226 | 226 | { |
| 227 | 227 | /* url was redirected, check if we've hit the max depth */ |
| 228 | - if($this->maxredirs > $this->_redirectdepth) |
|
| 228 | + if ($this->maxredirs > $this->_redirectdepth) |
|
| 229 | 229 | { |
| 230 | 230 | // only follow redirect if it's on this site, or offsiteok is true |
| 231 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
| 231 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
| 232 | 232 | { |
| 233 | 233 | /* follow the redirect */ |
| 234 | 234 | $this->_redirectdepth++; |
| 235 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
| 235 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
| 236 | 236 | $this->fetch($this->_redirectaddr); |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 241 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 242 | 242 | { |
| 243 | 243 | $frameurls = $this->_frameurls; |
| 244 | 244 | $this->_frameurls = array(); |
| 245 | 245 | |
| 246 | - while(list(,$frameurl) = each($frameurls)) |
|
| 246 | + while (list(,$frameurl) = each($frameurls)) |
|
| 247 | 247 | { |
| 248 | - if($this->_framedepth < $this->maxframes) |
|
| 248 | + if ($this->_framedepth < $this->maxframes) |
|
| 249 | 249 | { |
| 250 | 250 | $this->fetch($frameurl); |
| 251 | 251 | $this->_framedepth++; |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | break; |
| 259 | 259 | default: |
| 260 | 260 | // not a valid protocol |
| 261 | - $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 261 | + $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 262 | 262 | return false; |
| 263 | 263 | break; |
| 264 | 264 | } |
@@ -276,34 +276,34 @@ discard block |
||
| 276 | 276 | Output: $this->results the text output from the post |
| 277 | 277 | \*======================================================================*/ |
| 278 | 278 | |
| 279 | - function submit($URI, $formvars="", $formfiles="") |
|
| 279 | + function submit($URI, $formvars = "", $formfiles = "") |
|
| 280 | 280 | { |
| 281 | 281 | unset($postdata); |
| 282 | 282 | |
| 283 | 283 | $postdata = $this->_prepare_post_body($formvars, $formfiles); |
| 284 | 284 | |
| 285 | 285 | $URI_PARTS = parse_url($URI); |
| 286 | - if (!empty($URI_PARTS["user"])) |
|
| 286 | + if ( ! empty($URI_PARTS["user"])) |
|
| 287 | 287 | $this->user = $URI_PARTS["user"]; |
| 288 | - if (!empty($URI_PARTS["pass"])) |
|
| 288 | + if ( ! empty($URI_PARTS["pass"])) |
|
| 289 | 289 | $this->pass = $URI_PARTS["pass"]; |
| 290 | 290 | if (empty($URI_PARTS["query"])) |
| 291 | 291 | $URI_PARTS["query"] = ''; |
| 292 | 292 | if (empty($URI_PARTS["path"])) |
| 293 | 293 | $URI_PARTS["path"] = ''; |
| 294 | 294 | |
| 295 | - switch(strtolower($URI_PARTS["scheme"])) |
|
| 295 | + switch (strtolower($URI_PARTS["scheme"])) |
|
| 296 | 296 | { |
| 297 | 297 | case "http": |
| 298 | 298 | $this->host = $URI_PARTS["host"]; |
| 299 | - if(!empty($URI_PARTS["port"])) |
|
| 299 | + if ( ! empty($URI_PARTS["port"])) |
|
| 300 | 300 | $this->port = $URI_PARTS["port"]; |
| 301 | - if($this->_connect($fp)) |
|
| 301 | + if ($this->_connect($fp)) |
|
| 302 | 302 | { |
| 303 | - if($this->_isproxy) |
|
| 303 | + if ($this->_isproxy) |
|
| 304 | 304 | { |
| 305 | 305 | // using proxy, send entire URI |
| 306 | - $this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata); |
|
| 306 | + $this->_httprequest($URI, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
|
| 307 | 307 | } |
| 308 | 308 | else |
| 309 | 309 | { |
@@ -314,36 +314,36 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | $this->_disconnect($fp); |
| 316 | 316 | |
| 317 | - if($this->_redirectaddr) |
|
| 317 | + if ($this->_redirectaddr) |
|
| 318 | 318 | { |
| 319 | 319 | /* url was redirected, check if we've hit the max depth */ |
| 320 | - if($this->maxredirs > $this->_redirectdepth) |
|
| 320 | + if ($this->maxredirs > $this->_redirectdepth) |
|
| 321 | 321 | { |
| 322 | - if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 323 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 322 | + if ( ! preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 323 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 324 | 324 | |
| 325 | 325 | // only follow redirect if it's on this site, or offsiteok is true |
| 326 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
| 326 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
| 327 | 327 | { |
| 328 | 328 | /* follow the redirect */ |
| 329 | 329 | $this->_redirectdepth++; |
| 330 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
| 331 | - if( strpos( $this->_redirectaddr, "?" ) > 0 ) |
|
| 330 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
| 331 | + if (strpos($this->_redirectaddr, "?") > 0) |
|
| 332 | 332 | $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
| 333 | 333 | else |
| 334 | - $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 334 | + $this->submit($this->_redirectaddr, $formvars, $formfiles); |
|
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 339 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 340 | 340 | { |
| 341 | 341 | $frameurls = $this->_frameurls; |
| 342 | 342 | $this->_frameurls = array(); |
| 343 | 343 | |
| 344 | - while(list(,$frameurl) = each($frameurls)) |
|
| 344 | + while (list(,$frameurl) = each($frameurls)) |
|
| 345 | 345 | { |
| 346 | - if($this->_framedepth < $this->maxframes) |
|
| 346 | + if ($this->_framedepth < $this->maxframes) |
|
| 347 | 347 | { |
| 348 | 348 | $this->fetch($frameurl); |
| 349 | 349 | $this->_framedepth++; |
@@ -361,15 +361,15 @@ discard block |
||
| 361 | 361 | return true; |
| 362 | 362 | break; |
| 363 | 363 | case "https": |
| 364 | - if(!$this->curl_path) |
|
| 364 | + if ( ! $this->curl_path) |
|
| 365 | 365 | return false; |
| 366 | - if(function_exists("is_executable")) |
|
| 367 | - if (!is_executable($this->curl_path)) |
|
| 366 | + if (function_exists("is_executable")) |
|
| 367 | + if ( ! is_executable($this->curl_path)) |
|
| 368 | 368 | return false; |
| 369 | 369 | $this->host = $URI_PARTS["host"]; |
| 370 | - if(!empty($URI_PARTS["port"])) |
|
| 370 | + if ( ! empty($URI_PARTS["port"])) |
|
| 371 | 371 | $this->port = $URI_PARTS["port"]; |
| 372 | - if($this->_isproxy) |
|
| 372 | + if ($this->_isproxy) |
|
| 373 | 373 | { |
| 374 | 374 | // using proxy, send entire URI |
| 375 | 375 | $this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
@@ -381,36 +381,36 @@ discard block |
||
| 381 | 381 | $this->_httpsrequest($path, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - if($this->_redirectaddr) |
|
| 384 | + if ($this->_redirectaddr) |
|
| 385 | 385 | { |
| 386 | 386 | /* url was redirected, check if we've hit the max depth */ |
| 387 | - if($this->maxredirs > $this->_redirectdepth) |
|
| 387 | + if ($this->maxredirs > $this->_redirectdepth) |
|
| 388 | 388 | { |
| 389 | - if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 390 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 389 | + if ( ! preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 390 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 391 | 391 | |
| 392 | 392 | // only follow redirect if it's on this site, or offsiteok is true |
| 393 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
| 393 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
| 394 | 394 | { |
| 395 | 395 | /* follow the redirect */ |
| 396 | 396 | $this->_redirectdepth++; |
| 397 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
| 398 | - if( strpos( $this->_redirectaddr, "?" ) > 0 ) |
|
| 397 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
| 398 | + if (strpos($this->_redirectaddr, "?") > 0) |
|
| 399 | 399 | $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
| 400 | 400 | else |
| 401 | - $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 401 | + $this->submit($this->_redirectaddr, $formvars, $formfiles); |
|
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 406 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 407 | 407 | { |
| 408 | 408 | $frameurls = $this->_frameurls; |
| 409 | 409 | $this->_frameurls = array(); |
| 410 | 410 | |
| 411 | - while(list(,$frameurl) = each($frameurls)) |
|
| 411 | + while (list(,$frameurl) = each($frameurls)) |
|
| 412 | 412 | { |
| 413 | - if($this->_framedepth < $this->maxframes) |
|
| 413 | + if ($this->_framedepth < $this->maxframes) |
|
| 414 | 414 | { |
| 415 | 415 | $this->fetch($frameurl); |
| 416 | 416 | $this->_framedepth++; |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | |
| 425 | 425 | default: |
| 426 | 426 | // not a valid protocol |
| 427 | - $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 427 | + $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 428 | 428 | return false; |
| 429 | 429 | break; |
| 430 | 430 | } |
@@ -442,17 +442,17 @@ discard block |
||
| 442 | 442 | { |
| 443 | 443 | if ($this->fetch($URI)) |
| 444 | 444 | { |
| 445 | - if($this->lastredirectaddr) |
|
| 445 | + if ($this->lastredirectaddr) |
|
| 446 | 446 | $URI = $this->lastredirectaddr; |
| 447 | - if(is_array($this->results)) |
|
| 447 | + if (is_array($this->results)) |
|
| 448 | 448 | { |
| 449 | - for($x=0;$x<count($this->results);$x++) |
|
| 449 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 450 | 450 | $this->results[$x] = $this->_striplinks($this->results[$x]); |
| 451 | 451 | } |
| 452 | 452 | else |
| 453 | 453 | $this->results = $this->_striplinks($this->results); |
| 454 | 454 | |
| 455 | - if($this->expandlinks) |
|
| 455 | + if ($this->expandlinks) |
|
| 456 | 456 | $this->results = $this->_expandlinks($this->results, $URI); |
| 457 | 457 | return true; |
| 458 | 458 | } |
@@ -473,9 +473,9 @@ discard block |
||
| 473 | 473 | if ($this->fetch($URI)) |
| 474 | 474 | { |
| 475 | 475 | |
| 476 | - if(is_array($this->results)) |
|
| 476 | + if (is_array($this->results)) |
|
| 477 | 477 | { |
| 478 | - for($x=0;$x<count($this->results);$x++) |
|
| 478 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 479 | 479 | $this->results[$x] = $this->_stripform($this->results[$x]); |
| 480 | 480 | } |
| 481 | 481 | else |
@@ -497,11 +497,11 @@ discard block |
||
| 497 | 497 | |
| 498 | 498 | function fetchtext($URI) |
| 499 | 499 | { |
| 500 | - if($this->fetch($URI)) |
|
| 500 | + if ($this->fetch($URI)) |
|
| 501 | 501 | { |
| 502 | - if(is_array($this->results)) |
|
| 502 | + if (is_array($this->results)) |
|
| 503 | 503 | { |
| 504 | - for($x=0;$x<count($this->results);$x++) |
|
| 504 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 505 | 505 | $this->results[$x] = $this->_striptext($this->results[$x]); |
| 506 | 506 | } |
| 507 | 507 | else |
@@ -519,26 +519,26 @@ discard block |
||
| 519 | 519 | Output: $this->results an array of the links from the post |
| 520 | 520 | \*======================================================================*/ |
| 521 | 521 | |
| 522 | - function submitlinks($URI, $formvars="", $formfiles="") |
|
| 522 | + function submitlinks($URI, $formvars = "", $formfiles = "") |
|
| 523 | 523 | { |
| 524 | - if($this->submit($URI,$formvars, $formfiles)) |
|
| 524 | + if ($this->submit($URI, $formvars, $formfiles)) |
|
| 525 | 525 | { |
| 526 | - if($this->lastredirectaddr) |
|
| 526 | + if ($this->lastredirectaddr) |
|
| 527 | 527 | $URI = $this->lastredirectaddr; |
| 528 | - if(is_array($this->results)) |
|
| 528 | + if (is_array($this->results)) |
|
| 529 | 529 | { |
| 530 | - for($x=0;$x<count($this->results);$x++) |
|
| 530 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 531 | 531 | { |
| 532 | 532 | $this->results[$x] = $this->_striplinks($this->results[$x]); |
| 533 | - if($this->expandlinks) |
|
| 534 | - $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 533 | + if ($this->expandlinks) |
|
| 534 | + $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 535 | 535 | } |
| 536 | 536 | } |
| 537 | 537 | else |
| 538 | 538 | { |
| 539 | 539 | $this->results = $this->_striplinks($this->results); |
| 540 | - if($this->expandlinks) |
|
| 541 | - $this->results = $this->_expandlinks($this->results,$URI); |
|
| 540 | + if ($this->expandlinks) |
|
| 541 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 542 | 542 | } |
| 543 | 543 | return true; |
| 544 | 544 | } |
@@ -555,24 +555,24 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | function submittext($URI, $formvars = "", $formfiles = "") |
| 557 | 557 | { |
| 558 | - if($this->submit($URI,$formvars, $formfiles)) |
|
| 558 | + if ($this->submit($URI, $formvars, $formfiles)) |
|
| 559 | 559 | { |
| 560 | - if($this->lastredirectaddr) |
|
| 560 | + if ($this->lastredirectaddr) |
|
| 561 | 561 | $URI = $this->lastredirectaddr; |
| 562 | - if(is_array($this->results)) |
|
| 562 | + if (is_array($this->results)) |
|
| 563 | 563 | { |
| 564 | - for($x=0;$x<count($this->results);$x++) |
|
| 564 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 565 | 565 | { |
| 566 | 566 | $this->results[$x] = $this->_striptext($this->results[$x]); |
| 567 | - if($this->expandlinks) |
|
| 568 | - $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 567 | + if ($this->expandlinks) |
|
| 568 | + $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | else |
| 572 | 572 | { |
| 573 | 573 | $this->results = $this->_striptext($this->results); |
| 574 | - if($this->expandlinks) |
|
| 575 | - $this->results = $this->_expandlinks($this->results,$URI); |
|
| 574 | + if ($this->expandlinks) |
|
| 575 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 576 | 576 | } |
| 577 | 577 | return true; |
| 578 | 578 | } |
@@ -624,20 +624,20 @@ discard block |
||
| 624 | 624 | ([\"\'])? # find single or double quote |
| 625 | 625 | (?(1) (.*?)\\1 | ([^\s\>]+)) # if quote found, match up to next matching |
| 626 | 626 | # quote, otherwise match up to next space |
| 627 | - 'isx",$document,$links); |
|
| 627 | + 'isx",$document, $links); |
|
| 628 | 628 | |
| 629 | 629 | |
| 630 | 630 | // catenate the non-empty matches from the conditional subpattern |
| 631 | 631 | |
| 632 | - while(list($key,$val) = each($links[2])) |
|
| 632 | + while (list($key, $val) = each($links[2])) |
|
| 633 | 633 | { |
| 634 | - if(!empty($val)) |
|
| 634 | + if ( ! empty($val)) |
|
| 635 | 635 | $match[] = $val; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - while(list($key,$val) = each($links[3])) |
|
| 638 | + while (list($key, $val) = each($links[3])) |
|
| 639 | 639 | { |
| 640 | - if(!empty($val)) |
|
| 640 | + if ( ! empty($val)) |
|
| 641 | 641 | $match[] = $val; |
| 642 | 642 | } |
| 643 | 643 | |
@@ -654,10 +654,10 @@ discard block |
||
| 654 | 654 | |
| 655 | 655 | function _stripform($document) |
| 656 | 656 | { |
| 657 | - preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements); |
|
| 657 | + preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi", $document, $elements); |
|
| 658 | 658 | |
| 659 | 659 | // catenate the matches |
| 660 | - $match = implode("\r\n",$elements[0]); |
|
| 660 | + $match = implode("\r\n", $elements[0]); |
|
| 661 | 661 | |
| 662 | 662 | // return the links |
| 663 | 663 | return $match; |
@@ -679,11 +679,11 @@ discard block |
||
| 679 | 679 | // so, list your entities one by one here. I included some of the |
| 680 | 680 | // more common ones. |
| 681 | 681 | |
| 682 | - $search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript |
|
| 683 | - "'<[\/\!]*?[^<>]*?>'si", // strip out html tags |
|
| 684 | - "'([\r\n])[\s]+'", // strip out white space |
|
| 685 | - "'&(quot|#34|#034|#x22);'i", // replace html entities |
|
| 686 | - "'&(amp|#38|#038|#x26);'i", // added hexadecimal values |
|
| 682 | + $search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript |
|
| 683 | + "'<[\/\!]*?[^<>]*?>'si", // strip out html tags |
|
| 684 | + "'([\r\n])[\s]+'", // strip out white space |
|
| 685 | + "'&(quot|#34|#034|#x22);'i", // replace html entities |
|
| 686 | + "'&(amp|#38|#038|#x26);'i", // added hexadecimal values |
|
| 687 | 687 | "'&(lt|#60|#060|#x3c);'i", |
| 688 | 688 | "'&(gt|#62|#062|#x3e);'i", |
| 689 | 689 | "'&(nbsp|#160|#xa0);'i", |
@@ -694,8 +694,8 @@ discard block |
||
| 694 | 694 | "'&(reg|#174);'i", |
| 695 | 695 | "'&(deg|#176);'i", |
| 696 | 696 | "'&(#39|#039|#x27);'", |
| 697 | - "'&(euro|#8364);'i", // europe |
|
| 698 | - "'&a(uml|UML);'", // german |
|
| 697 | + "'&(euro|#8364);'i", // europe |
|
| 698 | + "'&a(uml|UML);'", // german |
|
| 699 | 699 | "'&o(uml|UML);'", |
| 700 | 700 | "'&u(uml|UML);'", |
| 701 | 701 | "'&A(uml|UML);'", |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | "'&U(uml|UML);'", |
| 704 | 704 | "'ß'i", |
| 705 | 705 | ); |
| 706 | - $replace = array( "", |
|
| 706 | + $replace = array("", |
|
| 707 | 707 | "", |
| 708 | 708 | "\\1", |
| 709 | 709 | "\"", |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | chr(0xDF), // ANSI ß |
| 729 | 729 | ); |
| 730 | 730 | |
| 731 | - $text = preg_replace($search,$replace,$document); |
|
| 731 | + $text = preg_replace($search, $replace, $document); |
|
| 732 | 732 | |
| 733 | 733 | return $text; |
| 734 | 734 | } |
@@ -741,32 +741,32 @@ discard block |
||
| 741 | 741 | Output: $expandedLinks the expanded links |
| 742 | 742 | \*======================================================================*/ |
| 743 | 743 | |
| 744 | - function _expandlinks($links,$URI) |
|
| 744 | + function _expandlinks($links, $URI) |
|
| 745 | 745 | { |
| 746 | 746 | |
| 747 | - preg_match("/^[^\?]+/",$URI,$match); |
|
| 747 | + preg_match("/^[^\?]+/", $URI, $match); |
|
| 748 | 748 | |
| 749 | - $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]); |
|
| 750 | - $match = preg_replace("|/$|","",$match); |
|
| 749 | + $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|", "", $match[0]); |
|
| 750 | + $match = preg_replace("|/$|", "", $match); |
|
| 751 | 751 | $match_part = parse_url($match); |
| 752 | 752 | $match_root = |
| 753 | 753 | $match_part["scheme"]."://".$match_part["host"]; |
| 754 | 754 | |
| 755 | - $search = array( "|^http://".preg_quote($this->host)."|i", |
|
| 755 | + $search = array("|^http://".preg_quote($this->host)."|i", |
|
| 756 | 756 | "|^(\/)|i", |
| 757 | 757 | "|^(?!http://)(?!mailto:)|i", |
| 758 | 758 | "|/\./|", |
| 759 | 759 | "|/[^\/]+/\.\./|" |
| 760 | 760 | ); |
| 761 | 761 | |
| 762 | - $replace = array( "", |
|
| 762 | + $replace = array("", |
|
| 763 | 763 | $match_root."/", |
| 764 | 764 | $match."/", |
| 765 | 765 | "/", |
| 766 | 766 | "/" |
| 767 | 767 | ); |
| 768 | 768 | |
| 769 | - $expandedLinks = preg_replace($search,$replace,$links); |
|
| 769 | + $expandedLinks = preg_replace($search, $replace, $links); |
|
| 770 | 770 | |
| 771 | 771 | return $expandedLinks; |
| 772 | 772 | } |
@@ -781,63 +781,63 @@ discard block |
||
| 781 | 781 | Output: |
| 782 | 782 | \*======================================================================*/ |
| 783 | 783 | |
| 784 | - function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
|
| 784 | + function _httprequest($url, $fp, $URI, $http_method, $content_type = "", $body = "") |
|
| 785 | 785 | { |
| 786 | 786 | $cookie_headers = ''; |
| 787 | - if($this->passcookies && $this->_redirectaddr) |
|
| 787 | + if ($this->passcookies && $this->_redirectaddr) |
|
| 788 | 788 | $this->setcookies(); |
| 789 | 789 | |
| 790 | 790 | $URI_PARTS = parse_url($URI); |
| 791 | - if(empty($url)) |
|
| 791 | + if (empty($url)) |
|
| 792 | 792 | $url = "/"; |
| 793 | 793 | $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
| 794 | - if(!empty($this->agent)) |
|
| 794 | + if ( ! empty($this->agent)) |
|
| 795 | 795 | $headers .= "User-Agent: ".$this->agent."\r\n"; |
| 796 | - if(!empty($this->host) && !isset($this->rawheaders['Host'])) { |
|
| 796 | + if ( ! empty($this->host) && ! isset($this->rawheaders['Host'])) { |
|
| 797 | 797 | $headers .= "Host: ".$this->host; |
| 798 | - if(!empty($this->port) && $this->port != 80) |
|
| 798 | + if ( ! empty($this->port) && $this->port != 80) |
|
| 799 | 799 | $headers .= ":".$this->port; |
| 800 | 800 | $headers .= "\r\n"; |
| 801 | 801 | } |
| 802 | - if(!empty($this->accept)) |
|
| 802 | + if ( ! empty($this->accept)) |
|
| 803 | 803 | $headers .= "Accept: ".$this->accept."\r\n"; |
| 804 | - if(!empty($this->referer)) |
|
| 804 | + if ( ! empty($this->referer)) |
|
| 805 | 805 | $headers .= "Referer: ".$this->referer."\r\n"; |
| 806 | - if(!empty($this->cookies)) |
|
| 806 | + if ( ! empty($this->cookies)) |
|
| 807 | 807 | { |
| 808 | - if(!is_array($this->cookies)) |
|
| 809 | - $this->cookies = (array)$this->cookies; |
|
| 808 | + if ( ! is_array($this->cookies)) |
|
| 809 | + $this->cookies = (array) $this->cookies; |
|
| 810 | 810 | |
| 811 | 811 | reset($this->cookies); |
| 812 | - if ( count($this->cookies) > 0 ) { |
|
| 812 | + if (count($this->cookies) > 0) { |
|
| 813 | 813 | $cookie_headers .= 'Cookie: '; |
| 814 | - foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
| 814 | + foreach ($this->cookies as $cookieKey => $cookieVal) { |
|
| 815 | 815 | $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; |
| 816 | 816 | } |
| 817 | - $headers .= substr($cookie_headers,0,-2) . "\r\n"; |
|
| 817 | + $headers .= substr($cookie_headers, 0, -2)."\r\n"; |
|
| 818 | 818 | } |
| 819 | 819 | } |
| 820 | - if(!empty($this->rawheaders)) |
|
| 820 | + if ( ! empty($this->rawheaders)) |
|
| 821 | 821 | { |
| 822 | - if(!is_array($this->rawheaders)) |
|
| 823 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 824 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
| 822 | + if ( ! is_array($this->rawheaders)) |
|
| 823 | + $this->rawheaders = (array) $this->rawheaders; |
|
| 824 | + while (list($headerKey, $headerVal) = each($this->rawheaders)) |
|
| 825 | 825 | $headers .= $headerKey.": ".$headerVal."\r\n"; |
| 826 | 826 | } |
| 827 | - if(!empty($content_type)) { |
|
| 827 | + if ( ! empty($content_type)) { |
|
| 828 | 828 | $headers .= "Content-type: $content_type"; |
| 829 | 829 | if ($content_type == "multipart/form-data") |
| 830 | 830 | $headers .= "; boundary=".$this->_mime_boundary; |
| 831 | 831 | $headers .= "\r\n"; |
| 832 | 832 | } |
| 833 | - if(!empty($body)) |
|
| 833 | + if ( ! empty($body)) |
|
| 834 | 834 | $headers .= "Content-length: ".strlen($body)."\r\n"; |
| 835 | - if(!empty($this->user) || !empty($this->pass)) |
|
| 835 | + if ( ! empty($this->user) || ! empty($this->pass)) |
|
| 836 | 836 | $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; |
| 837 | 837 | |
| 838 | 838 | //add proxy auth headers |
| 839 | - if(!empty($this->proxy_user)) |
|
| 840 | - $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n"; |
|
| 839 | + if ( ! empty($this->proxy_user)) |
|
| 840 | + $headers .= 'Proxy-Authorization: '.'Basic '.base64_encode($this->proxy_user.':'.$this->proxy_pass)."\r\n"; |
|
| 841 | 841 | |
| 842 | 842 | |
| 843 | 843 | $headers .= "\r\n"; |
@@ -847,34 +847,34 @@ discard block |
||
| 847 | 847 | socket_set_timeout($fp, $this->read_timeout); |
| 848 | 848 | $this->timed_out = false; |
| 849 | 849 | |
| 850 | - fwrite($fp,$headers.$body,strlen($headers.$body)); |
|
| 850 | + fwrite($fp, $headers.$body, strlen($headers.$body)); |
|
| 851 | 851 | |
| 852 | 852 | $this->_redirectaddr = false; |
| 853 | 853 | unset($this->headers); |
| 854 | 854 | |
| 855 | - while($currentHeader = fgets($fp,$this->_maxlinelen)) |
|
| 855 | + while ($currentHeader = fgets($fp, $this->_maxlinelen)) |
|
| 856 | 856 | { |
| 857 | 857 | if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
| 858 | 858 | { |
| 859 | - $this->status=-100; |
|
| 859 | + $this->status = -100; |
|
| 860 | 860 | return false; |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | - if($currentHeader == "\r\n") |
|
| 863 | + if ($currentHeader == "\r\n") |
|
| 864 | 864 | break; |
| 865 | 865 | |
| 866 | 866 | // if a header begins with Location: or URI:, set the redirect |
| 867 | - if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
|
| 867 | + if (preg_match("/^(Location:|URI:)/i", $currentHeader)) |
|
| 868 | 868 | { |
| 869 | 869 | // get URL portion of the redirect |
| 870 | - preg_match("/^(Location:|URI:)[ ]+(.*)/i",chop($currentHeader),$matches); |
|
| 870 | + preg_match("/^(Location:|URI:)[ ]+(.*)/i", chop($currentHeader), $matches); |
|
| 871 | 871 | // look for :// in the Location header to see if hostname is included |
| 872 | - if(!preg_match("|\:\/\/|",$matches[2])) |
|
| 872 | + if ( ! preg_match("|\:\/\/|", $matches[2])) |
|
| 873 | 873 | { |
| 874 | 874 | // no host in the path, so prepend |
| 875 | 875 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
| 876 | 876 | // eliminate double slash |
| 877 | - if(!preg_match("|^/|",$matches[2])) |
|
| 877 | + if ( ! preg_match("|^/|", $matches[2])) |
|
| 878 | 878 | $this->_redirectaddr .= "/".$matches[2]; |
| 879 | 879 | else |
| 880 | 880 | $this->_redirectaddr .= $matches[2]; |
@@ -883,11 +883,11 @@ discard block |
||
| 883 | 883 | $this->_redirectaddr = $matches[2]; |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | - if(preg_match("|^HTTP/|",$currentHeader)) |
|
| 886 | + if (preg_match("|^HTTP/|", $currentHeader)) |
|
| 887 | 887 | { |
| 888 | - if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) |
|
| 888 | + if (preg_match("|^HTTP/[^\s]*\s(.*?)\s|", $currentHeader, $status)) |
|
| 889 | 889 | { |
| 890 | - $this->status= $status[1]; |
|
| 890 | + $this->status = $status[1]; |
|
| 891 | 891 | } |
| 892 | 892 | $this->response_code = $currentHeader; |
| 893 | 893 | } |
@@ -902,31 +902,31 @@ discard block |
||
| 902 | 902 | break; |
| 903 | 903 | } |
| 904 | 904 | $results .= $_data; |
| 905 | - } while(true); |
|
| 905 | + } while (true); |
|
| 906 | 906 | |
| 907 | 907 | if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
| 908 | 908 | { |
| 909 | - $this->status=-100; |
|
| 909 | + $this->status = -100; |
|
| 910 | 910 | return false; |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | // check if there is a redirect meta tag |
| 914 | 914 | |
| 915 | - if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|
| 915 | + if (preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i", $results, $match)) |
|
| 916 | 916 | |
| 917 | 917 | { |
| 918 | - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
| 918 | + $this->_redirectaddr = $this->_expandlinks($match[1], $URI); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | // have we hit our frame depth and is there frame src to fetch? |
| 922 | - if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|
| 922 | + if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match)) |
|
| 923 | 923 | { |
| 924 | 924 | $this->results[] = $results; |
| 925 | - for($x=0; $x<count($match[1]); $x++) |
|
| 926 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 925 | + for ($x = 0; $x < count($match[1]); $x++) |
|
| 926 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"]."://".$this->host); |
|
| 927 | 927 | } |
| 928 | 928 | // have we already fetched framed content? |
| 929 | - elseif(is_array($this->results)) |
|
| 929 | + elseif (is_array($this->results)) |
|
| 930 | 930 | $this->results[] = $results; |
| 931 | 931 | // no framed content |
| 932 | 932 | else |
@@ -944,105 +944,105 @@ discard block |
||
| 944 | 944 | Output: |
| 945 | 945 | \*======================================================================*/ |
| 946 | 946 | |
| 947 | - function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
|
| 947 | + function _httpsrequest($url, $URI, $http_method, $content_type = "", $body = "") |
|
| 948 | 948 | { |
| 949 | - if($this->passcookies && $this->_redirectaddr) |
|
| 949 | + if ($this->passcookies && $this->_redirectaddr) |
|
| 950 | 950 | $this->setcookies(); |
| 951 | 951 | |
| 952 | 952 | $headers = array(); |
| 953 | 953 | |
| 954 | 954 | $URI_PARTS = parse_url($URI); |
| 955 | - if(empty($url)) |
|
| 955 | + if (empty($url)) |
|
| 956 | 956 | $url = "/"; |
| 957 | 957 | // GET ... header not needed for curl |
| 958 | 958 | //$headers[] = $http_method." ".$url." ".$this->_httpversion; |
| 959 | - if(!empty($this->agent)) |
|
| 959 | + if ( ! empty($this->agent)) |
|
| 960 | 960 | $headers[] = "User-Agent: ".$this->agent; |
| 961 | - if(!empty($this->host)) |
|
| 962 | - if(!empty($this->port)) |
|
| 961 | + if ( ! empty($this->host)) |
|
| 962 | + if ( ! empty($this->port)) |
|
| 963 | 963 | $headers[] = "Host: ".$this->host.":".$this->port; |
| 964 | 964 | else |
| 965 | 965 | $headers[] = "Host: ".$this->host; |
| 966 | - if(!empty($this->accept)) |
|
| 966 | + if ( ! empty($this->accept)) |
|
| 967 | 967 | $headers[] = "Accept: ".$this->accept; |
| 968 | - if(!empty($this->referer)) |
|
| 968 | + if ( ! empty($this->referer)) |
|
| 969 | 969 | $headers[] = "Referer: ".$this->referer; |
| 970 | - if(!empty($this->cookies)) |
|
| 970 | + if ( ! empty($this->cookies)) |
|
| 971 | 971 | { |
| 972 | - if(!is_array($this->cookies)) |
|
| 973 | - $this->cookies = (array)$this->cookies; |
|
| 972 | + if ( ! is_array($this->cookies)) |
|
| 973 | + $this->cookies = (array) $this->cookies; |
|
| 974 | 974 | |
| 975 | 975 | reset($this->cookies); |
| 976 | - if ( count($this->cookies) > 0 ) { |
|
| 976 | + if (count($this->cookies) > 0) { |
|
| 977 | 977 | $cookie_str = 'Cookie: '; |
| 978 | - foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
| 978 | + foreach ($this->cookies as $cookieKey => $cookieVal) { |
|
| 979 | 979 | $cookie_str .= $cookieKey."=".urlencode($cookieVal)."; "; |
| 980 | 980 | } |
| 981 | - $headers[] = substr($cookie_str,0,-2); |
|
| 981 | + $headers[] = substr($cookie_str, 0, -2); |
|
| 982 | 982 | } |
| 983 | 983 | } |
| 984 | - if(!empty($this->rawheaders)) |
|
| 984 | + if ( ! empty($this->rawheaders)) |
|
| 985 | 985 | { |
| 986 | - if(!is_array($this->rawheaders)) |
|
| 987 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 988 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
| 986 | + if ( ! is_array($this->rawheaders)) |
|
| 987 | + $this->rawheaders = (array) $this->rawheaders; |
|
| 988 | + while (list($headerKey, $headerVal) = each($this->rawheaders)) |
|
| 989 | 989 | $headers[] = $headerKey.": ".$headerVal; |
| 990 | 990 | } |
| 991 | - if(!empty($content_type)) { |
|
| 991 | + if ( ! empty($content_type)) { |
|
| 992 | 992 | if ($content_type == "multipart/form-data") |
| 993 | 993 | $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
| 994 | 994 | else |
| 995 | 995 | $headers[] = "Content-type: $content_type"; |
| 996 | 996 | } |
| 997 | - if(!empty($body)) |
|
| 997 | + if ( ! empty($body)) |
|
| 998 | 998 | $headers[] = "Content-length: ".strlen($body); |
| 999 | - if(!empty($this->user) || !empty($this->pass)) |
|
| 999 | + if ( ! empty($this->user) || ! empty($this->pass)) |
|
| 1000 | 1000 | $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
| 1001 | 1001 | |
| 1002 | - for($curr_header = 0; $curr_header < count($headers); $curr_header++) { |
|
| 1003 | - $safer_header = strtr( $headers[$curr_header], "\"", " " ); |
|
| 1002 | + for ($curr_header = 0; $curr_header < count($headers); $curr_header++) { |
|
| 1003 | + $safer_header = strtr($headers[$curr_header], "\"", " "); |
|
| 1004 | 1004 | $cmdline_params .= " -H \"".$safer_header."\""; |
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | - if(!empty($body)) |
|
| 1007 | + if ( ! empty($body)) |
|
| 1008 | 1008 | $cmdline_params .= " -d \"$body\""; |
| 1009 | 1009 | |
| 1010 | - if($this->read_timeout > 0) |
|
| 1010 | + if ($this->read_timeout > 0) |
|
| 1011 | 1011 | $cmdline_params .= " -m ".$this->read_timeout; |
| 1012 | 1012 | |
| 1013 | 1013 | $headerfile = tempnam($this->temp_dir, "sno"); |
| 1014 | 1014 | |
| 1015 | - exec($this->curl_path." -k -D \"$headerfile\"".$cmdline_params." \"".escapeshellcmd($URI)."\"",$results,$return); |
|
| 1015 | + exec($this->curl_path." -k -D \"$headerfile\"".$cmdline_params." \"".escapeshellcmd($URI)."\"", $results, $return); |
|
| 1016 | 1016 | |
| 1017 | - if($return) |
|
| 1017 | + if ($return) |
|
| 1018 | 1018 | { |
| 1019 | 1019 | $this->error = "Error: cURL could not retrieve the document, error $return."; |
| 1020 | 1020 | return false; |
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | |
| 1024 | - $results = implode("\r\n",$results); |
|
| 1024 | + $results = implode("\r\n", $results); |
|
| 1025 | 1025 | |
| 1026 | 1026 | $result_headers = file("$headerfile"); |
| 1027 | 1027 | |
| 1028 | 1028 | $this->_redirectaddr = false; |
| 1029 | 1029 | unset($this->headers); |
| 1030 | 1030 | |
| 1031 | - for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) |
|
| 1031 | + for ($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) |
|
| 1032 | 1032 | { |
| 1033 | 1033 | |
| 1034 | 1034 | // if a header begins with Location: or URI:, set the redirect |
| 1035 | - if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader])) |
|
| 1035 | + if (preg_match("/^(Location: |URI: )/i", $result_headers[$currentHeader])) |
|
| 1036 | 1036 | { |
| 1037 | 1037 | // get URL portion of the redirect |
| 1038 | - preg_match("/^(Location: |URI:)\s+(.*)/",chop($result_headers[$currentHeader]),$matches); |
|
| 1038 | + preg_match("/^(Location: |URI:)\s+(.*)/", chop($result_headers[$currentHeader]), $matches); |
|
| 1039 | 1039 | // look for :// in the Location header to see if hostname is included |
| 1040 | - if(!preg_match("|\:\/\/|",$matches[2])) |
|
| 1040 | + if ( ! preg_match("|\:\/\/|", $matches[2])) |
|
| 1041 | 1041 | { |
| 1042 | 1042 | // no host in the path, so prepend |
| 1043 | 1043 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
| 1044 | 1044 | // eliminate double slash |
| 1045 | - if(!preg_match("|^/|",$matches[2])) |
|
| 1045 | + if ( ! preg_match("|^/|", $matches[2])) |
|
| 1046 | 1046 | $this->_redirectaddr .= "/".$matches[2]; |
| 1047 | 1047 | else |
| 1048 | 1048 | $this->_redirectaddr .= $matches[2]; |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | $this->_redirectaddr = $matches[2]; |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | - if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
|
| 1054 | + if (preg_match("|^HTTP/|", $result_headers[$currentHeader])) |
|
| 1055 | 1055 | $this->response_code = $result_headers[$currentHeader]; |
| 1056 | 1056 | |
| 1057 | 1057 | $this->headers[] = $result_headers[$currentHeader]; |
@@ -1059,20 +1059,20 @@ discard block |
||
| 1059 | 1059 | |
| 1060 | 1060 | // check if there is a redirect meta tag |
| 1061 | 1061 | |
| 1062 | - if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|
| 1062 | + if (preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i", $results, $match)) |
|
| 1063 | 1063 | { |
| 1064 | - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
| 1064 | + $this->_redirectaddr = $this->_expandlinks($match[1], $URI); |
|
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | // have we hit our frame depth and is there frame src to fetch? |
| 1068 | - if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|
| 1068 | + if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match)) |
|
| 1069 | 1069 | { |
| 1070 | 1070 | $this->results[] = $results; |
| 1071 | - for($x=0; $x<count($match[1]); $x++) |
|
| 1072 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 1071 | + for ($x = 0; $x < count($match[1]); $x++) |
|
| 1072 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"]."://".$this->host); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | // have we already fetched framed content? |
| 1075 | - elseif(is_array($this->results)) |
|
| 1075 | + elseif (is_array($this->results)) |
|
| 1076 | 1076 | $this->results[] = $results; |
| 1077 | 1077 | // no framed content |
| 1078 | 1078 | else |
@@ -1090,9 +1090,9 @@ discard block |
||
| 1090 | 1090 | |
| 1091 | 1091 | function setcookies() |
| 1092 | 1092 | { |
| 1093 | - for($x=0; $x<count($this->headers); $x++) |
|
| 1093 | + for ($x = 0; $x < count($this->headers); $x++) |
|
| 1094 | 1094 | { |
| 1095 | - if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match)) |
|
| 1095 | + if (preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x], $match)) |
|
| 1096 | 1096 | $this->cookies[$match[1]] = urldecode($match[2]); |
| 1097 | 1097 | } |
| 1098 | 1098 | } |
@@ -1124,7 +1124,7 @@ discard block |
||
| 1124 | 1124 | |
| 1125 | 1125 | function _connect(&$fp) |
| 1126 | 1126 | { |
| 1127 | - if(!empty($this->proxy_host) && !empty($this->proxy_port)) |
|
| 1127 | + if ( ! empty($this->proxy_host) && ! empty($this->proxy_port)) |
|
| 1128 | 1128 | { |
| 1129 | 1129 | $this->_isproxy = true; |
| 1130 | 1130 | |
@@ -1139,7 +1139,7 @@ discard block |
||
| 1139 | 1139 | |
| 1140 | 1140 | $this->status = 0; |
| 1141 | 1141 | |
| 1142 | - if($fp = fsockopen( |
|
| 1142 | + if ($fp = fsockopen( |
|
| 1143 | 1143 | $host, |
| 1144 | 1144 | $port, |
| 1145 | 1145 | $errno, |
@@ -1155,16 +1155,16 @@ discard block |
||
| 1155 | 1155 | { |
| 1156 | 1156 | // socket connection failed |
| 1157 | 1157 | $this->status = $errno; |
| 1158 | - switch($errno) |
|
| 1158 | + switch ($errno) |
|
| 1159 | 1159 | { |
| 1160 | 1160 | case -3: |
| 1161 | - $this->error="socket creation failed (-3)"; |
|
| 1161 | + $this->error = "socket creation failed (-3)"; |
|
| 1162 | 1162 | case -4: |
| 1163 | - $this->error="dns lookup failure (-4)"; |
|
| 1163 | + $this->error = "dns lookup failure (-4)"; |
|
| 1164 | 1164 | case -5: |
| 1165 | - $this->error="connection refused or timed out (-5)"; |
|
| 1165 | + $this->error = "connection refused or timed out (-5)"; |
|
| 1166 | 1166 | default: |
| 1167 | - $this->error="connection failed (".$errno.")"; |
|
| 1167 | + $this->error = "connection failed (".$errno.")"; |
|
| 1168 | 1168 | } |
| 1169 | 1169 | return false; |
| 1170 | 1170 | } |
@@ -1201,7 +1201,7 @@ discard block |
||
| 1201 | 1201 | switch ($this->_submit_type) { |
| 1202 | 1202 | case "application/x-www-form-urlencoded": |
| 1203 | 1203 | reset($formvars); |
| 1204 | - while(list($key,$val) = each($formvars)) { |
|
| 1204 | + while (list($key, $val) = each($formvars)) { |
|
| 1205 | 1205 | if (is_array($val) || is_object($val)) { |
| 1206 | 1206 | while (list($cur_key, $cur_val) = each($val)) { |
| 1207 | 1207 | $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
@@ -1215,7 +1215,7 @@ discard block |
||
| 1215 | 1215 | $this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); |
| 1216 | 1216 | |
| 1217 | 1217 | reset($formvars); |
| 1218 | - while(list($key,$val) = each($formvars)) { |
|
| 1218 | + while (list($key, $val) = each($formvars)) { |
|
| 1219 | 1219 | if (is_array($val) || is_object($val)) { |
| 1220 | 1220 | while (list($cur_key, $cur_val) = each($val)) { |
| 1221 | 1221 | $postdata .= "--".$this->_mime_boundary."\r\n"; |
@@ -1233,7 +1233,7 @@ discard block |
||
| 1233 | 1233 | while (list($field_name, $file_names) = each($formfiles)) { |
| 1234 | 1234 | settype($file_names, "array"); |
| 1235 | 1235 | while (list(, $file_name) = each($file_names)) { |
| 1236 | - if (!is_readable($file_name)) continue; |
|
| 1236 | + if ( ! is_readable($file_name)) continue; |
|
| 1237 | 1237 | |
| 1238 | 1238 | $fp = fopen($file_name, "r"); |
| 1239 | 1239 | $file_content = fread($fp, filesize($file_name)); |
@@ -131,29 +131,33 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); |
| 133 | 133 | $URI_PARTS = parse_url($URI); |
| 134 | - if (!empty($URI_PARTS["user"])) |
|
| 135 | - $this->user = $URI_PARTS["user"]; |
|
| 136 | - if (!empty($URI_PARTS["pass"])) |
|
| 137 | - $this->pass = $URI_PARTS["pass"]; |
|
| 138 | - if (empty($URI_PARTS["query"])) |
|
| 139 | - $URI_PARTS["query"] = ''; |
|
| 140 | - if (empty($URI_PARTS["path"])) |
|
| 141 | - $URI_PARTS["path"] = ''; |
|
| 134 | + if (!empty($URI_PARTS["user"])) { |
|
| 135 | + $this->user = $URI_PARTS["user"]; |
|
| 136 | + } |
|
| 137 | + if (!empty($URI_PARTS["pass"])) { |
|
| 138 | + $this->pass = $URI_PARTS["pass"]; |
|
| 139 | + } |
|
| 140 | + if (empty($URI_PARTS["query"])) { |
|
| 141 | + $URI_PARTS["query"] = ''; |
|
| 142 | + } |
|
| 143 | + if (empty($URI_PARTS["path"])) { |
|
| 144 | + $URI_PARTS["path"] = ''; |
|
| 145 | + } |
|
| 142 | 146 | |
| 143 | 147 | switch(strtolower($URI_PARTS["scheme"])) |
| 144 | 148 | { |
| 145 | 149 | case "http": |
| 146 | 150 | $this->host = $URI_PARTS["host"]; |
| 147 | - if(!empty($URI_PARTS["port"])) |
|
| 148 | - $this->port = $URI_PARTS["port"]; |
|
| 151 | + if(!empty($URI_PARTS["port"])) { |
|
| 152 | + $this->port = $URI_PARTS["port"]; |
|
| 153 | + } |
|
| 149 | 154 | if($this->_connect($fp)) |
| 150 | 155 | { |
| 151 | 156 | if($this->_isproxy) |
| 152 | 157 | { |
| 153 | 158 | // using proxy, send entire URI |
| 154 | 159 | $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
| 155 | - } |
|
| 156 | - else |
|
| 160 | + } else |
|
| 157 | 161 | { |
| 158 | 162 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
| 159 | 163 | // no proxy, send only the path |
@@ -189,33 +193,34 @@ discard block |
||
| 189 | 193 | { |
| 190 | 194 | $this->fetch($frameurl); |
| 191 | 195 | $this->_framedepth++; |
| 196 | + } else { |
|
| 197 | + break; |
|
| 192 | 198 | } |
| 193 | - else |
|
| 194 | - break; |
|
| 195 | 199 | } |
| 196 | 200 | } |
| 197 | - } |
|
| 198 | - else |
|
| 201 | + } else |
|
| 199 | 202 | { |
| 200 | 203 | return false; |
| 201 | 204 | } |
| 202 | 205 | return true; |
| 203 | 206 | break; |
| 204 | 207 | case "https": |
| 205 | - if(!$this->curl_path) |
|
| 206 | - return false; |
|
| 207 | - if(function_exists("is_executable")) |
|
| 208 | - if (!is_executable($this->curl_path)) |
|
| 208 | + if(!$this->curl_path) { |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + if(function_exists("is_executable")) { |
|
| 212 | + if (!is_executable($this->curl_path)) |
|
| 209 | 213 | return false; |
| 214 | + } |
|
| 210 | 215 | $this->host = $URI_PARTS["host"]; |
| 211 | - if(!empty($URI_PARTS["port"])) |
|
| 212 | - $this->port = $URI_PARTS["port"]; |
|
| 216 | + if(!empty($URI_PARTS["port"])) { |
|
| 217 | + $this->port = $URI_PARTS["port"]; |
|
| 218 | + } |
|
| 213 | 219 | if($this->_isproxy) |
| 214 | 220 | { |
| 215 | 221 | // using proxy, send entire URI |
| 216 | 222 | $this->_httpsrequest($URI,$URI,$this->_httpmethod); |
| 217 | - } |
|
| 218 | - else |
|
| 223 | + } else |
|
| 219 | 224 | { |
| 220 | 225 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
| 221 | 226 | // no proxy, send only the path |
@@ -249,9 +254,9 @@ discard block |
||
| 249 | 254 | { |
| 250 | 255 | $this->fetch($frameurl); |
| 251 | 256 | $this->_framedepth++; |
| 257 | + } else { |
|
| 258 | + break; |
|
| 252 | 259 | } |
| 253 | - else |
|
| 254 | - break; |
|
| 255 | 260 | } |
| 256 | 261 | } |
| 257 | 262 | return true; |
@@ -283,29 +288,33 @@ discard block |
||
| 283 | 288 | $postdata = $this->_prepare_post_body($formvars, $formfiles); |
| 284 | 289 | |
| 285 | 290 | $URI_PARTS = parse_url($URI); |
| 286 | - if (!empty($URI_PARTS["user"])) |
|
| 287 | - $this->user = $URI_PARTS["user"]; |
|
| 288 | - if (!empty($URI_PARTS["pass"])) |
|
| 289 | - $this->pass = $URI_PARTS["pass"]; |
|
| 290 | - if (empty($URI_PARTS["query"])) |
|
| 291 | - $URI_PARTS["query"] = ''; |
|
| 292 | - if (empty($URI_PARTS["path"])) |
|
| 293 | - $URI_PARTS["path"] = ''; |
|
| 291 | + if (!empty($URI_PARTS["user"])) { |
|
| 292 | + $this->user = $URI_PARTS["user"]; |
|
| 293 | + } |
|
| 294 | + if (!empty($URI_PARTS["pass"])) { |
|
| 295 | + $this->pass = $URI_PARTS["pass"]; |
|
| 296 | + } |
|
| 297 | + if (empty($URI_PARTS["query"])) { |
|
| 298 | + $URI_PARTS["query"] = ''; |
|
| 299 | + } |
|
| 300 | + if (empty($URI_PARTS["path"])) { |
|
| 301 | + $URI_PARTS["path"] = ''; |
|
| 302 | + } |
|
| 294 | 303 | |
| 295 | 304 | switch(strtolower($URI_PARTS["scheme"])) |
| 296 | 305 | { |
| 297 | 306 | case "http": |
| 298 | 307 | $this->host = $URI_PARTS["host"]; |
| 299 | - if(!empty($URI_PARTS["port"])) |
|
| 300 | - $this->port = $URI_PARTS["port"]; |
|
| 308 | + if(!empty($URI_PARTS["port"])) { |
|
| 309 | + $this->port = $URI_PARTS["port"]; |
|
| 310 | + } |
|
| 301 | 311 | if($this->_connect($fp)) |
| 302 | 312 | { |
| 303 | 313 | if($this->_isproxy) |
| 304 | 314 | { |
| 305 | 315 | // using proxy, send entire URI |
| 306 | 316 | $this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata); |
| 307 | - } |
|
| 308 | - else |
|
| 317 | + } else |
|
| 309 | 318 | { |
| 310 | 319 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
| 311 | 320 | // no proxy, send only the path |
@@ -319,8 +328,9 @@ discard block |
||
| 319 | 328 | /* url was redirected, check if we've hit the max depth */ |
| 320 | 329 | if($this->maxredirs > $this->_redirectdepth) |
| 321 | 330 | { |
| 322 | - if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 323 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 331 | + if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) { |
|
| 332 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 333 | + } |
|
| 324 | 334 | |
| 325 | 335 | // only follow redirect if it's on this site, or offsiteok is true |
| 326 | 336 | if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
@@ -328,10 +338,13 @@ discard block |
||
| 328 | 338 | /* follow the redirect */ |
| 329 | 339 | $this->_redirectdepth++; |
| 330 | 340 | $this->lastredirectaddr=$this->_redirectaddr; |
| 331 | - if( strpos( $this->_redirectaddr, "?" ) > 0 ) |
|
| 332 | - $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
|
| 333 | - else |
|
| 334 | - $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 341 | + if( strpos( $this->_redirectaddr, "?" ) > 0 ) { |
|
| 342 | + $this->fetch($this->_redirectaddr); |
|
| 343 | + } |
|
| 344 | + // the redirect has changed the request method from post to get |
|
| 345 | + else { |
|
| 346 | + $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 347 | + } |
|
| 335 | 348 | } |
| 336 | 349 | } |
| 337 | 350 | } |
@@ -347,34 +360,35 @@ discard block |
||
| 347 | 360 | { |
| 348 | 361 | $this->fetch($frameurl); |
| 349 | 362 | $this->_framedepth++; |
| 363 | + } else { |
|
| 364 | + break; |
|
| 350 | 365 | } |
| 351 | - else |
|
| 352 | - break; |
|
| 353 | 366 | } |
| 354 | 367 | } |
| 355 | 368 | |
| 356 | - } |
|
| 357 | - else |
|
| 369 | + } else |
|
| 358 | 370 | { |
| 359 | 371 | return false; |
| 360 | 372 | } |
| 361 | 373 | return true; |
| 362 | 374 | break; |
| 363 | 375 | case "https": |
| 364 | - if(!$this->curl_path) |
|
| 365 | - return false; |
|
| 366 | - if(function_exists("is_executable")) |
|
| 367 | - if (!is_executable($this->curl_path)) |
|
| 376 | + if(!$this->curl_path) { |
|
| 377 | + return false; |
|
| 378 | + } |
|
| 379 | + if(function_exists("is_executable")) { |
|
| 380 | + if (!is_executable($this->curl_path)) |
|
| 368 | 381 | return false; |
| 382 | + } |
|
| 369 | 383 | $this->host = $URI_PARTS["host"]; |
| 370 | - if(!empty($URI_PARTS["port"])) |
|
| 371 | - $this->port = $URI_PARTS["port"]; |
|
| 384 | + if(!empty($URI_PARTS["port"])) { |
|
| 385 | + $this->port = $URI_PARTS["port"]; |
|
| 386 | + } |
|
| 372 | 387 | if($this->_isproxy) |
| 373 | 388 | { |
| 374 | 389 | // using proxy, send entire URI |
| 375 | 390 | $this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
| 376 | - } |
|
| 377 | - else |
|
| 391 | + } else |
|
| 378 | 392 | { |
| 379 | 393 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
| 380 | 394 | // no proxy, send only the path |
@@ -386,8 +400,9 @@ discard block |
||
| 386 | 400 | /* url was redirected, check if we've hit the max depth */ |
| 387 | 401 | if($this->maxredirs > $this->_redirectdepth) |
| 388 | 402 | { |
| 389 | - if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 390 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 403 | + if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) { |
|
| 404 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 405 | + } |
|
| 391 | 406 | |
| 392 | 407 | // only follow redirect if it's on this site, or offsiteok is true |
| 393 | 408 | if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
@@ -395,10 +410,13 @@ discard block |
||
| 395 | 410 | /* follow the redirect */ |
| 396 | 411 | $this->_redirectdepth++; |
| 397 | 412 | $this->lastredirectaddr=$this->_redirectaddr; |
| 398 | - if( strpos( $this->_redirectaddr, "?" ) > 0 ) |
|
| 399 | - $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
|
| 400 | - else |
|
| 401 | - $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 413 | + if( strpos( $this->_redirectaddr, "?" ) > 0 ) { |
|
| 414 | + $this->fetch($this->_redirectaddr); |
|
| 415 | + } |
|
| 416 | + // the redirect has changed the request method from post to get |
|
| 417 | + else { |
|
| 418 | + $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 419 | + } |
|
| 402 | 420 | } |
| 403 | 421 | } |
| 404 | 422 | } |
@@ -414,9 +432,9 @@ discard block |
||
| 414 | 432 | { |
| 415 | 433 | $this->fetch($frameurl); |
| 416 | 434 | $this->_framedepth++; |
| 435 | + } else { |
|
| 436 | + break; |
|
| 417 | 437 | } |
| 418 | - else |
|
| 419 | - break; |
|
| 420 | 438 | } |
| 421 | 439 | } |
| 422 | 440 | return true; |
@@ -442,22 +460,25 @@ discard block |
||
| 442 | 460 | { |
| 443 | 461 | if ($this->fetch($URI)) |
| 444 | 462 | { |
| 445 | - if($this->lastredirectaddr) |
|
| 446 | - $URI = $this->lastredirectaddr; |
|
| 463 | + if($this->lastredirectaddr) { |
|
| 464 | + $URI = $this->lastredirectaddr; |
|
| 465 | + } |
|
| 447 | 466 | if(is_array($this->results)) |
| 448 | 467 | { |
| 449 | - for($x=0;$x<count($this->results);$x++) |
|
| 450 | - $this->results[$x] = $this->_striplinks($this->results[$x]); |
|
| 468 | + for($x=0;$x<count($this->results);$x++) { |
|
| 469 | + $this->results[$x] = $this->_striplinks($this->results[$x]); |
|
| 470 | + } |
|
| 471 | + } else { |
|
| 472 | + $this->results = $this->_striplinks($this->results); |
|
| 451 | 473 | } |
| 452 | - else |
|
| 453 | - $this->results = $this->_striplinks($this->results); |
|
| 454 | 474 | |
| 455 | - if($this->expandlinks) |
|
| 456 | - $this->results = $this->_expandlinks($this->results, $URI); |
|
| 475 | + if($this->expandlinks) { |
|
| 476 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 477 | + } |
|
| 457 | 478 | return true; |
| 479 | + } else { |
|
| 480 | + return false; |
|
| 458 | 481 | } |
| 459 | - else |
|
| 460 | - return false; |
|
| 461 | 482 | } |
| 462 | 483 | |
| 463 | 484 | /*======================================================================*\ |
@@ -475,16 +496,17 @@ discard block |
||
| 475 | 496 | |
| 476 | 497 | if(is_array($this->results)) |
| 477 | 498 | { |
| 478 | - for($x=0;$x<count($this->results);$x++) |
|
| 479 | - $this->results[$x] = $this->_stripform($this->results[$x]); |
|
| 499 | + for($x=0;$x<count($this->results);$x++) { |
|
| 500 | + $this->results[$x] = $this->_stripform($this->results[$x]); |
|
| 501 | + } |
|
| 502 | + } else { |
|
| 503 | + $this->results = $this->_stripform($this->results); |
|
| 480 | 504 | } |
| 481 | - else |
|
| 482 | - $this->results = $this->_stripform($this->results); |
|
| 483 | 505 | |
| 484 | 506 | return true; |
| 507 | + } else { |
|
| 508 | + return false; |
|
| 485 | 509 | } |
| 486 | - else |
|
| 487 | - return false; |
|
| 488 | 510 | } |
| 489 | 511 | |
| 490 | 512 | |
@@ -501,15 +523,16 @@ discard block |
||
| 501 | 523 | { |
| 502 | 524 | if(is_array($this->results)) |
| 503 | 525 | { |
| 504 | - for($x=0;$x<count($this->results);$x++) |
|
| 505 | - $this->results[$x] = $this->_striptext($this->results[$x]); |
|
| 526 | + for($x=0;$x<count($this->results);$x++) { |
|
| 527 | + $this->results[$x] = $this->_striptext($this->results[$x]); |
|
| 528 | + } |
|
| 529 | + } else { |
|
| 530 | + $this->results = $this->_striptext($this->results); |
|
| 506 | 531 | } |
| 507 | - else |
|
| 508 | - $this->results = $this->_striptext($this->results); |
|
| 509 | 532 | return true; |
| 533 | + } else { |
|
| 534 | + return false; |
|
| 510 | 535 | } |
| 511 | - else |
|
| 512 | - return false; |
|
| 513 | 536 | } |
| 514 | 537 | |
| 515 | 538 | /*======================================================================*\ |
@@ -523,27 +546,29 @@ discard block |
||
| 523 | 546 | { |
| 524 | 547 | if($this->submit($URI,$formvars, $formfiles)) |
| 525 | 548 | { |
| 526 | - if($this->lastredirectaddr) |
|
| 527 | - $URI = $this->lastredirectaddr; |
|
| 549 | + if($this->lastredirectaddr) { |
|
| 550 | + $URI = $this->lastredirectaddr; |
|
| 551 | + } |
|
| 528 | 552 | if(is_array($this->results)) |
| 529 | 553 | { |
| 530 | 554 | for($x=0;$x<count($this->results);$x++) |
| 531 | 555 | { |
| 532 | 556 | $this->results[$x] = $this->_striplinks($this->results[$x]); |
| 533 | - if($this->expandlinks) |
|
| 534 | - $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 557 | + if($this->expandlinks) { |
|
| 558 | + $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 559 | + } |
|
| 535 | 560 | } |
| 536 | - } |
|
| 537 | - else |
|
| 561 | + } else |
|
| 538 | 562 | { |
| 539 | 563 | $this->results = $this->_striplinks($this->results); |
| 540 | - if($this->expandlinks) |
|
| 541 | - $this->results = $this->_expandlinks($this->results,$URI); |
|
| 564 | + if($this->expandlinks) { |
|
| 565 | + $this->results = $this->_expandlinks($this->results,$URI); |
|
| 566 | + } |
|
| 542 | 567 | } |
| 543 | 568 | return true; |
| 569 | + } else { |
|
| 570 | + return false; |
|
| 544 | 571 | } |
| 545 | - else |
|
| 546 | - return false; |
|
| 547 | 572 | } |
| 548 | 573 | |
| 549 | 574 | /*======================================================================*\ |
@@ -557,27 +582,29 @@ discard block |
||
| 557 | 582 | { |
| 558 | 583 | if($this->submit($URI,$formvars, $formfiles)) |
| 559 | 584 | { |
| 560 | - if($this->lastredirectaddr) |
|
| 561 | - $URI = $this->lastredirectaddr; |
|
| 585 | + if($this->lastredirectaddr) { |
|
| 586 | + $URI = $this->lastredirectaddr; |
|
| 587 | + } |
|
| 562 | 588 | if(is_array($this->results)) |
| 563 | 589 | { |
| 564 | 590 | for($x=0;$x<count($this->results);$x++) |
| 565 | 591 | { |
| 566 | 592 | $this->results[$x] = $this->_striptext($this->results[$x]); |
| 567 | - if($this->expandlinks) |
|
| 568 | - $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 593 | + if($this->expandlinks) { |
|
| 594 | + $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 595 | + } |
|
| 569 | 596 | } |
| 570 | - } |
|
| 571 | - else |
|
| 597 | + } else |
|
| 572 | 598 | { |
| 573 | 599 | $this->results = $this->_striptext($this->results); |
| 574 | - if($this->expandlinks) |
|
| 575 | - $this->results = $this->_expandlinks($this->results,$URI); |
|
| 600 | + if($this->expandlinks) { |
|
| 601 | + $this->results = $this->_expandlinks($this->results,$URI); |
|
| 602 | + } |
|
| 576 | 603 | } |
| 577 | 604 | return true; |
| 605 | + } else { |
|
| 606 | + return false; |
|
| 578 | 607 | } |
| 579 | - else |
|
| 580 | - return false; |
|
| 581 | 608 | } |
| 582 | 609 | |
| 583 | 610 | |
@@ -631,14 +658,16 @@ discard block |
||
| 631 | 658 | |
| 632 | 659 | while(list($key,$val) = each($links[2])) |
| 633 | 660 | { |
| 634 | - if(!empty($val)) |
|
| 635 | - $match[] = $val; |
|
| 661 | + if(!empty($val)) { |
|
| 662 | + $match[] = $val; |
|
| 663 | + } |
|
| 636 | 664 | } |
| 637 | 665 | |
| 638 | 666 | while(list($key,$val) = each($links[3])) |
| 639 | 667 | { |
| 640 | - if(!empty($val)) |
|
| 641 | - $match[] = $val; |
|
| 668 | + if(!empty($val)) { |
|
| 669 | + $match[] = $val; |
|
| 670 | + } |
|
| 642 | 671 | } |
| 643 | 672 | |
| 644 | 673 | // return the links |
@@ -784,29 +813,36 @@ discard block |
||
| 784 | 813 | function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
| 785 | 814 | { |
| 786 | 815 | $cookie_headers = ''; |
| 787 | - if($this->passcookies && $this->_redirectaddr) |
|
| 788 | - $this->setcookies(); |
|
| 816 | + if($this->passcookies && $this->_redirectaddr) { |
|
| 817 | + $this->setcookies(); |
|
| 818 | + } |
|
| 789 | 819 | |
| 790 | 820 | $URI_PARTS = parse_url($URI); |
| 791 | - if(empty($url)) |
|
| 792 | - $url = "/"; |
|
| 821 | + if(empty($url)) { |
|
| 822 | + $url = "/"; |
|
| 823 | + } |
|
| 793 | 824 | $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
| 794 | - if(!empty($this->agent)) |
|
| 795 | - $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
| 825 | + if(!empty($this->agent)) { |
|
| 826 | + $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
| 827 | + } |
|
| 796 | 828 | if(!empty($this->host) && !isset($this->rawheaders['Host'])) { |
| 797 | 829 | $headers .= "Host: ".$this->host; |
| 798 | - if(!empty($this->port) && $this->port != 80) |
|
| 799 | - $headers .= ":".$this->port; |
|
| 830 | + if(!empty($this->port) && $this->port != 80) { |
|
| 831 | + $headers .= ":".$this->port; |
|
| 832 | + } |
|
| 800 | 833 | $headers .= "\r\n"; |
| 801 | 834 | } |
| 802 | - if(!empty($this->accept)) |
|
| 803 | - $headers .= "Accept: ".$this->accept."\r\n"; |
|
| 804 | - if(!empty($this->referer)) |
|
| 805 | - $headers .= "Referer: ".$this->referer."\r\n"; |
|
| 835 | + if(!empty($this->accept)) { |
|
| 836 | + $headers .= "Accept: ".$this->accept."\r\n"; |
|
| 837 | + } |
|
| 838 | + if(!empty($this->referer)) { |
|
| 839 | + $headers .= "Referer: ".$this->referer."\r\n"; |
|
| 840 | + } |
|
| 806 | 841 | if(!empty($this->cookies)) |
| 807 | 842 | { |
| 808 | - if(!is_array($this->cookies)) |
|
| 809 | - $this->cookies = (array)$this->cookies; |
|
| 843 | + if(!is_array($this->cookies)) { |
|
| 844 | + $this->cookies = (array)$this->cookies; |
|
| 845 | + } |
|
| 810 | 846 | |
| 811 | 847 | reset($this->cookies); |
| 812 | 848 | if ( count($this->cookies) > 0 ) { |
@@ -819,32 +855,39 @@ discard block |
||
| 819 | 855 | } |
| 820 | 856 | if(!empty($this->rawheaders)) |
| 821 | 857 | { |
| 822 | - if(!is_array($this->rawheaders)) |
|
| 823 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 824 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
| 825 | - $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
| 858 | + if(!is_array($this->rawheaders)) { |
|
| 859 | + $this->rawheaders = (array)$this->rawheaders; |
|
| 860 | + } |
|
| 861 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) { |
|
| 862 | + $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
| 863 | + } |
|
| 826 | 864 | } |
| 827 | 865 | if(!empty($content_type)) { |
| 828 | 866 | $headers .= "Content-type: $content_type"; |
| 829 | - if ($content_type == "multipart/form-data") |
|
| 830 | - $headers .= "; boundary=".$this->_mime_boundary; |
|
| 867 | + if ($content_type == "multipart/form-data") { |
|
| 868 | + $headers .= "; boundary=".$this->_mime_boundary; |
|
| 869 | + } |
|
| 831 | 870 | $headers .= "\r\n"; |
| 832 | 871 | } |
| 833 | - if(!empty($body)) |
|
| 834 | - $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
| 835 | - if(!empty($this->user) || !empty($this->pass)) |
|
| 836 | - $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
| 872 | + if(!empty($body)) { |
|
| 873 | + $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
| 874 | + } |
|
| 875 | + if(!empty($this->user) || !empty($this->pass)) { |
|
| 876 | + $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
| 877 | + } |
|
| 837 | 878 | |
| 838 | 879 | //add proxy auth headers |
| 839 | - if(!empty($this->proxy_user)) |
|
| 840 | - $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n"; |
|
| 880 | + if(!empty($this->proxy_user)) { |
|
| 881 | + $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n"; |
|
| 882 | + } |
|
| 841 | 883 | |
| 842 | 884 | |
| 843 | 885 | $headers .= "\r\n"; |
| 844 | 886 | |
| 845 | 887 | // set the read timeout if needed |
| 846 | - if ($this->read_timeout > 0) |
|
| 847 | - socket_set_timeout($fp, $this->read_timeout); |
|
| 888 | + if ($this->read_timeout > 0) { |
|
| 889 | + socket_set_timeout($fp, $this->read_timeout); |
|
| 890 | + } |
|
| 848 | 891 | $this->timed_out = false; |
| 849 | 892 | |
| 850 | 893 | fwrite($fp,$headers.$body,strlen($headers.$body)); |
@@ -860,8 +903,9 @@ discard block |
||
| 860 | 903 | return false; |
| 861 | 904 | } |
| 862 | 905 | |
| 863 | - if($currentHeader == "\r\n") |
|
| 864 | - break; |
|
| 906 | + if($currentHeader == "\r\n") { |
|
| 907 | + break; |
|
| 908 | + } |
|
| 865 | 909 | |
| 866 | 910 | // if a header begins with Location: or URI:, set the redirect |
| 867 | 911 | if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
@@ -874,13 +918,14 @@ discard block |
||
| 874 | 918 | // no host in the path, so prepend |
| 875 | 919 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
| 876 | 920 | // eliminate double slash |
| 877 | - if(!preg_match("|^/|",$matches[2])) |
|
| 878 | - $this->_redirectaddr .= "/".$matches[2]; |
|
| 879 | - else |
|
| 880 | - $this->_redirectaddr .= $matches[2]; |
|
| 921 | + if(!preg_match("|^/|",$matches[2])) { |
|
| 922 | + $this->_redirectaddr .= "/".$matches[2]; |
|
| 923 | + } else { |
|
| 924 | + $this->_redirectaddr .= $matches[2]; |
|
| 925 | + } |
|
| 926 | + } else { |
|
| 927 | + $this->_redirectaddr = $matches[2]; |
|
| 881 | 928 | } |
| 882 | - else |
|
| 883 | - $this->_redirectaddr = $matches[2]; |
|
| 884 | 929 | } |
| 885 | 930 | |
| 886 | 931 | if(preg_match("|^HTTP/|",$currentHeader)) |
@@ -922,15 +967,18 @@ discard block |
||
| 922 | 967 | if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
| 923 | 968 | { |
| 924 | 969 | $this->results[] = $results; |
| 925 | - for($x=0; $x<count($match[1]); $x++) |
|
| 926 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 970 | + for($x=0; $x<count($match[1]); $x++) { |
|
| 971 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 972 | + } |
|
| 927 | 973 | } |
| 928 | 974 | // have we already fetched framed content? |
| 929 | - elseif(is_array($this->results)) |
|
| 930 | - $this->results[] = $results; |
|
| 975 | + elseif(is_array($this->results)) { |
|
| 976 | + $this->results[] = $results; |
|
| 977 | + } |
|
| 931 | 978 | // no framed content |
| 932 | - else |
|
| 933 | - $this->results = $results; |
|
| 979 | + else { |
|
| 980 | + $this->results = $results; |
|
| 981 | + } |
|
| 934 | 982 | |
| 935 | 983 | return true; |
| 936 | 984 | } |
@@ -946,31 +994,38 @@ discard block |
||
| 946 | 994 | |
| 947 | 995 | function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
| 948 | 996 | { |
| 949 | - if($this->passcookies && $this->_redirectaddr) |
|
| 950 | - $this->setcookies(); |
|
| 997 | + if($this->passcookies && $this->_redirectaddr) { |
|
| 998 | + $this->setcookies(); |
|
| 999 | + } |
|
| 951 | 1000 | |
| 952 | 1001 | $headers = array(); |
| 953 | 1002 | |
| 954 | 1003 | $URI_PARTS = parse_url($URI); |
| 955 | - if(empty($url)) |
|
| 956 | - $url = "/"; |
|
| 1004 | + if(empty($url)) { |
|
| 1005 | + $url = "/"; |
|
| 1006 | + } |
|
| 957 | 1007 | // GET ... header not needed for curl |
| 958 | 1008 | //$headers[] = $http_method." ".$url." ".$this->_httpversion; |
| 959 | - if(!empty($this->agent)) |
|
| 960 | - $headers[] = "User-Agent: ".$this->agent; |
|
| 961 | - if(!empty($this->host)) |
|
| 962 | - if(!empty($this->port)) |
|
| 1009 | + if(!empty($this->agent)) { |
|
| 1010 | + $headers[] = "User-Agent: ".$this->agent; |
|
| 1011 | + } |
|
| 1012 | + if(!empty($this->host)) { |
|
| 1013 | + if(!empty($this->port)) |
|
| 963 | 1014 | $headers[] = "Host: ".$this->host.":".$this->port; |
| 964 | - else |
|
| 965 | - $headers[] = "Host: ".$this->host; |
|
| 966 | - if(!empty($this->accept)) |
|
| 967 | - $headers[] = "Accept: ".$this->accept; |
|
| 968 | - if(!empty($this->referer)) |
|
| 969 | - $headers[] = "Referer: ".$this->referer; |
|
| 1015 | + } else { |
|
| 1016 | + $headers[] = "Host: ".$this->host; |
|
| 1017 | + } |
|
| 1018 | + if(!empty($this->accept)) { |
|
| 1019 | + $headers[] = "Accept: ".$this->accept; |
|
| 1020 | + } |
|
| 1021 | + if(!empty($this->referer)) { |
|
| 1022 | + $headers[] = "Referer: ".$this->referer; |
|
| 1023 | + } |
|
| 970 | 1024 | if(!empty($this->cookies)) |
| 971 | 1025 | { |
| 972 | - if(!is_array($this->cookies)) |
|
| 973 | - $this->cookies = (array)$this->cookies; |
|
| 1026 | + if(!is_array($this->cookies)) { |
|
| 1027 | + $this->cookies = (array)$this->cookies; |
|
| 1028 | + } |
|
| 974 | 1029 | |
| 975 | 1030 | reset($this->cookies); |
| 976 | 1031 | if ( count($this->cookies) > 0 ) { |
@@ -983,32 +1038,39 @@ discard block |
||
| 983 | 1038 | } |
| 984 | 1039 | if(!empty($this->rawheaders)) |
| 985 | 1040 | { |
| 986 | - if(!is_array($this->rawheaders)) |
|
| 987 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 988 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
| 989 | - $headers[] = $headerKey.": ".$headerVal; |
|
| 1041 | + if(!is_array($this->rawheaders)) { |
|
| 1042 | + $this->rawheaders = (array)$this->rawheaders; |
|
| 1043 | + } |
|
| 1044 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) { |
|
| 1045 | + $headers[] = $headerKey.": ".$headerVal; |
|
| 1046 | + } |
|
| 990 | 1047 | } |
| 991 | 1048 | if(!empty($content_type)) { |
| 992 | - if ($content_type == "multipart/form-data") |
|
| 993 | - $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|
| 994 | - else |
|
| 995 | - $headers[] = "Content-type: $content_type"; |
|
| 1049 | + if ($content_type == "multipart/form-data") { |
|
| 1050 | + $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|
| 1051 | + } else { |
|
| 1052 | + $headers[] = "Content-type: $content_type"; |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + if(!empty($body)) { |
|
| 1056 | + $headers[] = "Content-length: ".strlen($body); |
|
| 1057 | + } |
|
| 1058 | + if(!empty($this->user) || !empty($this->pass)) { |
|
| 1059 | + $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|
| 996 | 1060 | } |
| 997 | - if(!empty($body)) |
|
| 998 | - $headers[] = "Content-length: ".strlen($body); |
|
| 999 | - if(!empty($this->user) || !empty($this->pass)) |
|
| 1000 | - $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|
| 1001 | 1061 | |
| 1002 | 1062 | for($curr_header = 0; $curr_header < count($headers); $curr_header++) { |
| 1003 | 1063 | $safer_header = strtr( $headers[$curr_header], "\"", " " ); |
| 1004 | 1064 | $cmdline_params .= " -H \"".$safer_header."\""; |
| 1005 | 1065 | } |
| 1006 | 1066 | |
| 1007 | - if(!empty($body)) |
|
| 1008 | - $cmdline_params .= " -d \"$body\""; |
|
| 1067 | + if(!empty($body)) { |
|
| 1068 | + $cmdline_params .= " -d \"$body\""; |
|
| 1069 | + } |
|
| 1009 | 1070 | |
| 1010 | - if($this->read_timeout > 0) |
|
| 1011 | - $cmdline_params .= " -m ".$this->read_timeout; |
|
| 1071 | + if($this->read_timeout > 0) { |
|
| 1072 | + $cmdline_params .= " -m ".$this->read_timeout; |
|
| 1073 | + } |
|
| 1012 | 1074 | |
| 1013 | 1075 | $headerfile = tempnam($this->temp_dir, "sno"); |
| 1014 | 1076 | |
@@ -1042,17 +1104,19 @@ discard block |
||
| 1042 | 1104 | // no host in the path, so prepend |
| 1043 | 1105 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
| 1044 | 1106 | // eliminate double slash |
| 1045 | - if(!preg_match("|^/|",$matches[2])) |
|
| 1046 | - $this->_redirectaddr .= "/".$matches[2]; |
|
| 1047 | - else |
|
| 1048 | - $this->_redirectaddr .= $matches[2]; |
|
| 1107 | + if(!preg_match("|^/|",$matches[2])) { |
|
| 1108 | + $this->_redirectaddr .= "/".$matches[2]; |
|
| 1109 | + } else { |
|
| 1110 | + $this->_redirectaddr .= $matches[2]; |
|
| 1111 | + } |
|
| 1112 | + } else { |
|
| 1113 | + $this->_redirectaddr = $matches[2]; |
|
| 1049 | 1114 | } |
| 1050 | - else |
|
| 1051 | - $this->_redirectaddr = $matches[2]; |
|
| 1052 | 1115 | } |
| 1053 | 1116 | |
| 1054 | - if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
|
| 1055 | - $this->response_code = $result_headers[$currentHeader]; |
|
| 1117 | + if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) { |
|
| 1118 | + $this->response_code = $result_headers[$currentHeader]; |
|
| 1119 | + } |
|
| 1056 | 1120 | |
| 1057 | 1121 | $this->headers[] = $result_headers[$currentHeader]; |
| 1058 | 1122 | } |
@@ -1068,15 +1132,18 @@ discard block |
||
| 1068 | 1132 | if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
| 1069 | 1133 | { |
| 1070 | 1134 | $this->results[] = $results; |
| 1071 | - for($x=0; $x<count($match[1]); $x++) |
|
| 1072 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 1135 | + for($x=0; $x<count($match[1]); $x++) { |
|
| 1136 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 1137 | + } |
|
| 1073 | 1138 | } |
| 1074 | 1139 | // have we already fetched framed content? |
| 1075 | - elseif(is_array($this->results)) |
|
| 1076 | - $this->results[] = $results; |
|
| 1140 | + elseif(is_array($this->results)) { |
|
| 1141 | + $this->results[] = $results; |
|
| 1142 | + } |
|
| 1077 | 1143 | // no framed content |
| 1078 | - else |
|
| 1079 | - $this->results = $results; |
|
| 1144 | + else { |
|
| 1145 | + $this->results = $results; |
|
| 1146 | + } |
|
| 1080 | 1147 | |
| 1081 | 1148 | unlink("$headerfile"); |
| 1082 | 1149 | |
@@ -1092,8 +1159,9 @@ discard block |
||
| 1092 | 1159 | { |
| 1093 | 1160 | for($x=0; $x<count($this->headers); $x++) |
| 1094 | 1161 | { |
| 1095 | - if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match)) |
|
| 1096 | - $this->cookies[$match[1]] = urldecode($match[2]); |
|
| 1162 | + if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match)) { |
|
| 1163 | + $this->cookies[$match[1]] = urldecode($match[2]); |
|
| 1164 | + } |
|
| 1097 | 1165 | } |
| 1098 | 1166 | } |
| 1099 | 1167 | |
@@ -1130,8 +1198,7 @@ discard block |
||
| 1130 | 1198 | |
| 1131 | 1199 | $host = $this->proxy_host; |
| 1132 | 1200 | $port = $this->proxy_port; |
| 1133 | - } |
|
| 1134 | - else |
|
| 1201 | + } else |
|
| 1135 | 1202 | { |
| 1136 | 1203 | $host = $this->host; |
| 1137 | 1204 | $port = $this->port; |
@@ -1150,8 +1217,7 @@ discard block |
||
| 1150 | 1217 | // socket connection succeeded |
| 1151 | 1218 | |
| 1152 | 1219 | return true; |
| 1153 | - } |
|
| 1154 | - else |
|
| 1220 | + } else |
|
| 1155 | 1221 | { |
| 1156 | 1222 | // socket connection failed |
| 1157 | 1223 | $this->status = $errno; |
@@ -1195,8 +1261,9 @@ discard block |
||
| 1195 | 1261 | settype($formfiles, "array"); |
| 1196 | 1262 | $postdata = ''; |
| 1197 | 1263 | |
| 1198 | - if (count($formvars) == 0 && count($formfiles) == 0) |
|
| 1199 | - return; |
|
| 1264 | + if (count($formvars) == 0 && count($formfiles) == 0) { |
|
| 1265 | + return; |
|
| 1266 | + } |
|
| 1200 | 1267 | |
| 1201 | 1268 | switch ($this->_submit_type) { |
| 1202 | 1269 | case "application/x-www-form-urlencoded": |
@@ -1206,8 +1273,9 @@ discard block |
||
| 1206 | 1273 | while (list($cur_key, $cur_val) = each($val)) { |
| 1207 | 1274 | $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
| 1208 | 1275 | } |
| 1209 | - } else |
|
| 1210 | - $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
| 1276 | + } else { |
|
| 1277 | + $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
| 1278 | + } |
|
| 1211 | 1279 | } |
| 1212 | 1280 | break; |
| 1213 | 1281 | |
@@ -1233,7 +1301,9 @@ discard block |
||
| 1233 | 1301 | while (list($field_name, $file_names) = each($formfiles)) { |
| 1234 | 1302 | settype($file_names, "array"); |
| 1235 | 1303 | while (list(, $file_name) = each($file_names)) { |
| 1236 | - if (!is_readable($file_name)) continue; |
|
| 1304 | + if (!is_readable($file_name)) { |
|
| 1305 | + continue; |
|
| 1306 | + } |
|
| 1237 | 1307 | |
| 1238 | 1308 | $fp = fopen($file_name, "r"); |
| 1239 | 1309 | $file_content = fread($fp, filesize($file_name)); |