changeset 204 | 09a1c134465b |
parent 194 | 32102edaa81b |
203:f507feede89a | 204:09a1c134465b |
---|---|
57 * @return int|string String if $type is 'gmt', int if $type is 'timestamp'. |
57 * @return int|string String if $type is 'gmt', int if $type is 'timestamp'. |
58 */ |
58 */ |
59 function current_time( $type, $gmt = 0 ) { |
59 function current_time( $type, $gmt = 0 ) { |
60 switch ( $type ) { |
60 switch ( $type ) { |
61 case 'mysql': |
61 case 'mysql': |
62 return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) ); |
62 return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) ); |
63 break; |
63 break; |
64 case 'timestamp': |
64 case 'timestamp': |
65 return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 ); |
65 return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
66 break; |
66 break; |
67 } |
67 } |
68 } |
68 } |
69 |
69 |
70 /** |
70 /** |
212 $start_of_week = get_option( 'start_of_week' ); |
212 $start_of_week = get_option( 'start_of_week' ); |
213 |
213 |
214 if ( $weekday < $start_of_week ) |
214 if ( $weekday < $start_of_week ) |
215 $weekday += 7; |
215 $weekday += 7; |
216 |
216 |
217 $start = $day - 86400 * ( $weekday - $start_of_week ); // The most recent week start day on or before $day |
217 $start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week ); // The most recent week start day on or before $day |
218 $end = $start + 604799; // $start + 7 days - 1 second |
218 $end = $start + 7 * DAY_IN_SECONDS - 1; // $start + 7 days - 1 second |
219 return compact( 'start', 'end' ); |
219 return compact( 'start', 'end' ); |
220 } |
220 } |
221 |
221 |
222 /** |
222 /** |
223 * Unserialize value only if it was serialized. |
223 * Unserialize value only if it was serialized. |
456 // the extension |
456 // the extension |
457 $url_parts = @parse_url( $url ); |
457 $url_parts = @parse_url( $url ); |
458 if ( false !== $url_parts ) { |
458 if ( false !== $url_parts ) { |
459 $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); |
459 $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); |
460 if ( !empty( $extension ) ) { |
460 if ( !empty( $extension ) ) { |
461 foreach ( get_allowed_mime_types( ) as $exts => $mime ) { |
461 foreach ( wp_get_mime_types() as $exts => $mime ) { |
462 if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
462 if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
463 $type = $mime; |
463 $type = $mime; |
464 break; |
464 break; |
465 } |
465 } |
466 } |
466 } |
635 * @param mixed $param3 Optional. Old query or uri |
635 * @param mixed $param3 Optional. Old query or uri |
636 * @return string New URL query string. |
636 * @return string New URL query string. |
637 */ |
637 */ |
638 function add_query_arg() { |
638 function add_query_arg() { |
639 $ret = ''; |
639 $ret = ''; |
640 if ( is_array( func_get_arg(0) ) ) { |
640 $args = func_get_args(); |
641 if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) ) |
641 if ( is_array( $args[0] ) ) { |
642 if ( count( $args ) < 2 || false === $args[1] ) |
|
642 $uri = $_SERVER['REQUEST_URI']; |
643 $uri = $_SERVER['REQUEST_URI']; |
643 else |
644 else |
644 $uri = @func_get_arg( 1 ); |
645 $uri = $args[1]; |
645 } else { |
646 } else { |
646 if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) ) |
647 if ( count( $args ) < 3 || false === $args[2] ) |
647 $uri = $_SERVER['REQUEST_URI']; |
648 $uri = $_SERVER['REQUEST_URI']; |
648 else |
649 else |
649 $uri = @func_get_arg( 2 ); |
650 $uri = $args[2]; |
650 } |
651 } |
651 |
652 |
652 if ( $frag = strstr( $uri, '#' ) ) |
653 if ( $frag = strstr( $uri, '#' ) ) |
653 $uri = substr( $uri, 0, -strlen( $frag ) ); |
654 $uri = substr( $uri, 0, -strlen( $frag ) ); |
654 else |
655 else |
655 $frag = ''; |
656 $frag = ''; |
656 |
657 |
657 if ( preg_match( '|^https?://|i', $uri, $matches ) ) { |
658 if ( 0 === stripos( 'http://', $uri ) ) { |
658 $protocol = $matches[0]; |
659 $protocol = 'http://'; |
659 $uri = substr( $uri, strlen( $protocol ) ); |
660 $uri = substr( $uri, 7 ); |
661 } elseif ( 0 === stripos( 'https://', $uri ) ) { |
|
662 $protocol = 'https://'; |
|
663 $uri = substr( $uri, 8 ); |
|
660 } else { |
664 } else { |
661 $protocol = ''; |
665 $protocol = ''; |
662 } |
666 } |
663 |
667 |
664 if ( strpos( $uri, '?' ) !== false ) { |
668 if ( strpos( $uri, '?' ) !== false ) { |
668 $query = $parts[0]; |
672 $query = $parts[0]; |
669 } else { |
673 } else { |
670 $base = $parts[0] . '?'; |
674 $base = $parts[0] . '?'; |
671 $query = $parts[1]; |
675 $query = $parts[1]; |
672 } |
676 } |
673 } elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) { |
677 } elseif ( $protocol || strpos( $uri, '=' ) === false ) { |
674 $base = $uri . '?'; |
678 $base = $uri . '?'; |
675 $query = ''; |
679 $query = ''; |
676 } else { |
680 } else { |
677 $base = ''; |
681 $base = ''; |
678 $query = $uri; |
682 $query = $uri; |
679 } |
683 } |
680 |
684 |
681 wp_parse_str( $query, $qs ); |
685 wp_parse_str( $query, $qs ); |
682 $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string |
686 $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string |
683 if ( is_array( func_get_arg( 0 ) ) ) { |
687 if ( is_array( $args[0] ) ) { |
684 $kayvees = func_get_arg( 0 ); |
688 $kayvees = $args[0]; |
685 $qs = array_merge( $qs, $kayvees ); |
689 $qs = array_merge( $qs, $kayvees ); |
686 } else { |
690 } else { |
687 $qs[func_get_arg( 0 )] = func_get_arg( 1 ); |
691 $qs[ $args[0] ] = $args[1]; |
688 } |
692 } |
689 |
693 |
690 foreach ( (array) $qs as $k => $v ) { |
694 foreach ( $qs as $k => $v ) { |
691 if ( $v === false ) |
695 if ( $v === false ) |
692 unset( $qs[$k] ); |
696 unset( $qs[$k] ); |
693 } |
697 } |
694 |
698 |
695 $ret = build_query( $qs ); |
699 $ret = build_query( $qs ); |
896 * @return array The associative array of header names and field values. |
900 * @return array The associative array of header names and field values. |
897 */ |
901 */ |
898 function wp_get_nocache_headers() { |
902 function wp_get_nocache_headers() { |
899 $headers = array( |
903 $headers = array( |
900 'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT', |
904 'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT', |
901 'Last-Modified' => gmdate( 'D, d M Y H:i:s' ) . ' GMT', |
905 'Last-Modified' => '', |
902 'Cache-Control' => 'no-cache, must-revalidate, max-age=0', |
906 'Cache-Control' => 'no-cache, must-revalidate, max-age=0', |
903 'Pragma' => 'no-cache', |
907 'Pragma' => 'no-cache', |
904 ); |
908 ); |
905 |
909 |
906 if ( function_exists('apply_filters') ) { |
910 if ( function_exists('apply_filters') ) { |
920 */ |
924 */ |
921 function nocache_headers() { |
925 function nocache_headers() { |
922 $headers = wp_get_nocache_headers(); |
926 $headers = wp_get_nocache_headers(); |
923 foreach( $headers as $name => $field_value ) |
927 foreach( $headers as $name => $field_value ) |
924 @header("{$name}: {$field_value}"); |
928 @header("{$name}: {$field_value}"); |
929 if ( empty( $headers['Last-Modified'] ) && function_exists( 'header_remove' ) ) |
|
930 @header_remove( 'Last-Modified' ); |
|
925 } |
931 } |
926 |
932 |
927 /** |
933 /** |
928 * Set the headers for caching for 10 days with JavaScript content type. |
934 * Set the headers for caching for 10 days with JavaScript content type. |
929 * |
935 * |
930 * @since 2.1.0 |
936 * @since 2.1.0 |
931 */ |
937 */ |
932 function cache_javascript_headers() { |
938 function cache_javascript_headers() { |
933 $expiresOffset = 864000; // 10 days |
939 $expiresOffset = 10 * DAY_IN_SECONDS; |
934 header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) ); |
940 header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) ); |
935 header( "Vary: Accept-Encoding" ); // Handle proxies |
941 header( "Vary: Accept-Encoding" ); // Handle proxies |
936 header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" ); |
942 header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" ); |
937 } |
943 } |
938 |
944 |
1289 * |
1295 * |
1290 * @param string $target Full path to attempt to create. |
1296 * @param string $target Full path to attempt to create. |
1291 * @return bool Whether the path was created. True if path already exists. |
1297 * @return bool Whether the path was created. True if path already exists. |
1292 */ |
1298 */ |
1293 function wp_mkdir_p( $target ) { |
1299 function wp_mkdir_p( $target ) { |
1300 $wrapper = null; |
|
1301 |
|
1302 // strip the protocol |
|
1303 if( wp_is_stream( $target ) ) { |
|
1304 list( $wrapper, $target ) = explode( '://', $target, 2 ); |
|
1305 } |
|
1306 |
|
1294 // from php.net/mkdir user contributed notes |
1307 // from php.net/mkdir user contributed notes |
1295 $target = str_replace( '//', '/', $target ); |
1308 $target = str_replace( '//', '/', $target ); |
1309 |
|
1310 // put the wrapper back on the target |
|
1311 if( $wrapper !== null ) { |
|
1312 $target = $wrapper . '://' . $target; |
|
1313 } |
|
1296 |
1314 |
1297 // safe mode fails with a trailing slash under certain PHP versions. |
1315 // safe mode fails with a trailing slash under certain PHP versions. |
1298 $target = rtrim($target, '/'); // Use rtrim() instead of untrailingslashit to avoid formatting.php dependency. |
1316 $target = rtrim($target, '/'); // Use rtrim() instead of untrailingslashit to avoid formatting.php dependency. |
1299 if ( empty($target) ) |
1317 if ( empty($target) ) |
1300 $target = '/'; |
1318 $target = '/'; |
1361 return rtrim($base, '/') . '/' . ltrim($path, '/'); |
1379 return rtrim($base, '/') . '/' . ltrim($path, '/'); |
1362 } |
1380 } |
1363 |
1381 |
1364 /** |
1382 /** |
1365 * Determines a writable directory for temporary files. |
1383 * Determines a writable directory for temporary files. |
1366 * Function's preference is to WP_CONTENT_DIR followed by the return value of <code>sys_get_temp_dir()</code>, before finally defaulting to /tmp/ |
1384 * Function's preference is the return value of <code>sys_get_temp_dir()</code>, |
1367 * |
1385 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR, |
1368 * In the event that this function does not find a writable location, It may be overridden by the <code>WP_TEMP_DIR</code> constant in your <code>wp-config.php</code> file. |
1386 * before finally defaulting to /tmp/ |
1387 * |
|
1388 * In the event that this function does not find a writable location, |
|
1389 * It may be overridden by the <code>WP_TEMP_DIR</code> constant in |
|
1390 * your <code>wp-config.php</code> file. |
|
1369 * |
1391 * |
1370 * @since 2.5.0 |
1392 * @since 2.5.0 |
1371 * |
1393 * |
1372 * @return string Writable temporary directory |
1394 * @return string Writable temporary directory |
1373 */ |
1395 */ |
1375 static $temp; |
1397 static $temp; |
1376 if ( defined('WP_TEMP_DIR') ) |
1398 if ( defined('WP_TEMP_DIR') ) |
1377 return trailingslashit(WP_TEMP_DIR); |
1399 return trailingslashit(WP_TEMP_DIR); |
1378 |
1400 |
1379 if ( $temp ) |
1401 if ( $temp ) |
1380 return trailingslashit($temp); |
1402 return trailingslashit( rtrim( $temp, '\\' ) ); |
1403 |
|
1404 $is_win = ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ); |
|
1405 |
|
1406 if ( function_exists('sys_get_temp_dir') ) { |
|
1407 $temp = sys_get_temp_dir(); |
|
1408 if ( @is_dir( $temp ) && ( $is_win ? win_is_writable( $temp ) : @is_writable( $temp ) ) ) { |
|
1409 return trailingslashit( rtrim( $temp, '\\' ) ); |
|
1410 } |
|
1411 } |
|
1412 |
|
1413 $temp = ini_get('upload_tmp_dir'); |
|
1414 if ( is_dir( $temp ) && ( $is_win ? win_is_writable( $temp ) : @is_writable( $temp ) ) ) |
|
1415 return trailingslashit( rtrim( $temp, '\\' ) ); |
|
1381 |
1416 |
1382 $temp = WP_CONTENT_DIR . '/'; |
1417 $temp = WP_CONTENT_DIR . '/'; |
1383 if ( is_dir($temp) && @is_writable($temp) ) |
1418 if ( is_dir( $temp ) && ( $is_win ? win_is_writable( $temp ) : @is_writable( $temp ) ) ) |
1384 return $temp; |
1419 return $temp; |
1385 |
|
1386 if ( function_exists('sys_get_temp_dir') ) { |
|
1387 $temp = sys_get_temp_dir(); |
|
1388 if ( @is_writable($temp) ) |
|
1389 return trailingslashit($temp); |
|
1390 } |
|
1391 |
|
1392 $temp = ini_get('upload_tmp_dir'); |
|
1393 if ( is_dir($temp) && @is_writable($temp) ) |
|
1394 return trailingslashit($temp); |
|
1395 |
1420 |
1396 $temp = '/tmp/'; |
1421 $temp = '/tmp/'; |
1397 return $temp; |
1422 return $temp; |
1423 } |
|
1424 |
|
1425 /** |
|
1426 * Workaround for Windows bug in is_writable() function |
|
1427 * |
|
1428 * @since 2.8.0 |
|
1429 * |
|
1430 * @param string $path |
|
1431 * @return bool |
|
1432 */ |
|
1433 function win_is_writable( $path ) { |
|
1434 /* will work in despite of Windows ACLs bug |
|
1435 * NOTE: use a trailing slash for folders!!! |
|
1436 * see http://bugs.php.net/bug.php?id=27609 |
|
1437 * see http://bugs.php.net/bug.php?id=30931 |
|
1438 */ |
|
1439 |
|
1440 if ( $path[strlen( $path ) - 1] == '/' ) // recursively return a temporary file path |
|
1441 return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp'); |
|
1442 else if ( is_dir( $path ) ) |
|
1443 return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' ); |
|
1444 // check tmp file for read/write capabilities |
|
1445 $should_delete_tmp_file = !file_exists( $path ); |
|
1446 $f = @fopen( $path, 'a' ); |
|
1447 if ( $f === false ) |
|
1448 return false; |
|
1449 fclose( $f ); |
|
1450 if ( $should_delete_tmp_file ) |
|
1451 unlink( $path ); |
|
1452 return true; |
|
1398 } |
1453 } |
1399 |
1454 |
1400 /** |
1455 /** |
1401 * Get an array containing the current upload directory's path and url. |
1456 * Get an array containing the current upload directory's path and url. |
1402 * |
1457 * |
1429 * |
1484 * |
1430 * @param string $time Optional. Time formatted in 'yyyy/mm'. |
1485 * @param string $time Optional. Time formatted in 'yyyy/mm'. |
1431 * @return array See above for description. |
1486 * @return array See above for description. |
1432 */ |
1487 */ |
1433 function wp_upload_dir( $time = null ) { |
1488 function wp_upload_dir( $time = null ) { |
1434 global $switched; |
|
1435 $siteurl = get_option( 'siteurl' ); |
1489 $siteurl = get_option( 'siteurl' ); |
1436 $upload_path = get_option( 'upload_path' ); |
1490 $upload_path = trim( get_option( 'upload_path' ) ); |
1437 $upload_path = trim($upload_path); |
1491 |
1438 $main_override = is_multisite() && defined( 'MULTISITE' ) && is_main_site(); |
1492 if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) { |
1439 if ( empty($upload_path) ) { |
|
1440 $dir = WP_CONTENT_DIR . '/uploads'; |
1493 $dir = WP_CONTENT_DIR . '/uploads'; |
1494 } elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) { |
|
1495 // $dir is absolute, $upload_path is (maybe) relative to ABSPATH |
|
1496 $dir = path_join( ABSPATH, $upload_path ); |
|
1441 } else { |
1497 } else { |
1442 $dir = $upload_path; |
1498 $dir = $upload_path; |
1443 if ( 'wp-content/uploads' == $upload_path ) { |
|
1444 $dir = WP_CONTENT_DIR . '/uploads'; |
|
1445 } elseif ( 0 !== strpos($dir, ABSPATH) ) { |
|
1446 // $dir is absolute, $upload_path is (maybe) relative to ABSPATH |
|
1447 $dir = path_join( ABSPATH, $dir ); |
|
1448 } |
|
1449 } |
1499 } |
1450 |
1500 |
1451 if ( !$url = get_option( 'upload_url_path' ) ) { |
1501 if ( !$url = get_option( 'upload_url_path' ) ) { |
1452 if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) ) |
1502 if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) ) |
1453 $url = WP_CONTENT_URL . '/uploads'; |
1503 $url = WP_CONTENT_URL . '/uploads'; |
1454 else |
1504 else |
1455 $url = trailingslashit( $siteurl ) . $upload_path; |
1505 $url = trailingslashit( $siteurl ) . $upload_path; |
1456 } |
1506 } |
1457 |
1507 |
1458 if ( defined('UPLOADS') && !$main_override && ( !isset( $switched ) || $switched === false ) ) { |
1508 // Obey the value of UPLOADS. This happens as long as ms-files rewriting is disabled. |
1509 // We also sometimes obey UPLOADS when rewriting is enabled -- see the next block. |
|
1510 if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) { |
|
1459 $dir = ABSPATH . UPLOADS; |
1511 $dir = ABSPATH . UPLOADS; |
1460 $url = trailingslashit( $siteurl ) . UPLOADS; |
1512 $url = trailingslashit( $siteurl ) . UPLOADS; |
1461 } |
1513 } |
1462 |
1514 |
1463 if ( is_multisite() && !$main_override && ( !isset( $switched ) || $switched === false ) ) { |
1515 // If multisite (and if not the main site in a post-MU network) |
1464 if ( defined( 'BLOGUPLOADDIR' ) ) |
1516 if ( is_multisite() && ! ( is_main_site() && defined( 'MULTISITE' ) ) ) { |
1465 $dir = untrailingslashit(BLOGUPLOADDIR); |
1517 |
1466 $url = str_replace( UPLOADS, 'files', $url ); |
1518 if ( ! get_site_option( 'ms_files_rewriting' ) ) { |
1467 } |
1519 // If ms-files rewriting is disabled (networks created post-3.5), it is fairly straightforward: |
1468 |
1520 // Append sites/%d if we're not on the main site (for post-MU networks). (The extra directory |
1469 $bdir = $dir; |
1521 // prevents a four-digit ID from conflicting with a year-based directory for the main site. |
1470 $burl = $url; |
1522 // But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra |
1523 // directory, as they never had wp-content/uploads for the main site.) |
|
1524 |
|
1525 if ( defined( 'MULTISITE' ) ) |
|
1526 $ms_dir = '/sites/' . get_current_blog_id(); |
|
1527 else |
|
1528 $ms_dir = '/' . get_current_blog_id(); |
|
1529 |
|
1530 $dir .= $ms_dir; |
|
1531 $url .= $ms_dir; |
|
1532 |
|
1533 } elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) { |
|
1534 // Handle the old-form ms-files.php rewriting if the network still has that enabled. |
|
1535 // When ms-files rewriting is enabled, then we only listen to UPLOADS when: |
|
1536 // 1) we are not on the main site in a post-MU network, |
|
1537 // as wp-content/uploads is used there, and |
|
1538 // 2) we are not switched, as ms_upload_constants() hardcodes |
|
1539 // these constants to reflect the original blog ID. |
|
1540 // |
|
1541 // Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute. |
|
1542 // (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as |
|
1543 // as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files |
|
1544 // rewriting in multisite, the resulting URL is /files. (#WP22702 for background.) |
|
1545 |
|
1546 if ( defined( 'BLOGUPLOADDIR' ) ) |
|
1547 $dir = untrailingslashit( BLOGUPLOADDIR ); |
|
1548 else |
|
1549 $dir = ABSPATH . UPLOADS; |
|
1550 $url = trailingslashit( $siteurl ) . 'files'; |
|
1551 } |
|
1552 } |
|
1553 |
|
1554 $basedir = $dir; |
|
1555 $baseurl = $url; |
|
1471 |
1556 |
1472 $subdir = ''; |
1557 $subdir = ''; |
1473 if ( get_option( 'uploads_use_yearmonth_folders' ) ) { |
1558 if ( get_option( 'uploads_use_yearmonth_folders' ) ) { |
1474 // Generate the yearly and monthly dirs |
1559 // Generate the yearly and monthly dirs |
1475 if ( !$time ) |
1560 if ( !$time ) |
1480 } |
1565 } |
1481 |
1566 |
1482 $dir .= $subdir; |
1567 $dir .= $subdir; |
1483 $url .= $subdir; |
1568 $url .= $subdir; |
1484 |
1569 |
1485 $uploads = apply_filters( 'upload_dir', array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false ) ); |
1570 $uploads = apply_filters( 'upload_dir', |
1571 array( |
|
1572 'path' => $dir, |
|
1573 'url' => $url, |
|
1574 'subdir' => $subdir, |
|
1575 'basedir' => $basedir, |
|
1576 'baseurl' => $baseurl, |
|
1577 'error' => false, |
|
1578 ) ); |
|
1486 |
1579 |
1487 // Make sure we have an uploads dir |
1580 // Make sure we have an uploads dir |
1488 if ( ! wp_mkdir_p( $uploads['path'] ) ) { |
1581 if ( ! wp_mkdir_p( $uploads['path'] ) ) { |
1489 if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) |
1582 if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) |
1490 $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; |
1583 $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; |
1491 else |
1584 else |
1492 $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; |
1585 $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; |
1493 |
1586 |
1494 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); |
1587 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); |
1495 return array( 'error' => $message ); |
1588 $uploads['error'] = $message; |
1496 } |
1589 } |
1497 |
1590 |
1498 return $uploads; |
1591 return $uploads; |
1499 } |
1592 } |
1500 |
1593 |
1589 |
1682 |
1590 if ( empty( $name ) ) |
1683 if ( empty( $name ) ) |
1591 return array( 'error' => __( 'Empty filename' ) ); |
1684 return array( 'error' => __( 'Empty filename' ) ); |
1592 |
1685 |
1593 $wp_filetype = wp_check_filetype( $name ); |
1686 $wp_filetype = wp_check_filetype( $name ); |
1594 if ( !$wp_filetype['ext'] ) |
1687 if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) ) |
1595 return array( 'error' => __( 'Invalid file type' ) ); |
1688 return array( 'error' => __( 'Invalid file type' ) ); |
1596 |
1689 |
1597 $upload = wp_upload_dir( $time ); |
1690 $upload = wp_upload_dir( $time ); |
1598 |
1691 |
1599 if ( $upload['error'] !== false ) |
1692 if ( $upload['error'] !== false ) |
1649 * @param string $ext The extension to search. |
1742 * @param string $ext The extension to search. |
1650 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found. |
1743 * @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found. |
1651 */ |
1744 */ |
1652 function wp_ext2type( $ext ) { |
1745 function wp_ext2type( $ext ) { |
1653 $ext2type = apply_filters( 'ext2type', array( |
1746 $ext2type = apply_filters( 'ext2type', array( |
1654 'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), |
1747 'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), |
1655 'video' => array( 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), |
1748 'video' => array( 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), |
1656 'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'rtf', 'wp', 'wpd' ), |
1749 'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'rtf', 'wp', 'wpd' ), |
1657 'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsb', 'xlsm' ), |
1750 'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsm', 'xlsb' ), |
1658 'interactive' => array( 'key', 'ppt', 'pptx', 'pptm', 'odp', 'swf' ), |
1751 'interactive' => array( 'swf', 'key', 'ppt', 'pptx', 'pptm', 'pps', 'ppsx', 'ppsm', 'sldx', 'sldm', 'odp' ), |
1659 'text' => array( 'asc', 'csv', 'tsv', 'txt' ), |
1752 'text' => array( 'asc', 'csv', 'tsv', 'txt' ), |
1660 'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ), |
1753 'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ), |
1661 'code' => array( 'css', 'htm', 'html', 'php', 'js' ), |
1754 'code' => array( 'css', 'htm', 'html', 'php', 'js' ), |
1662 )); |
1755 )); |
1663 foreach ( $ext2type as $type => $exts ) |
1756 foreach ( $ext2type as $type => $exts ) |
1664 if ( in_array( $ext, $exts ) ) |
1757 if ( in_array( $ext, $exts ) ) |
1665 return $type; |
1758 return $type; |
1761 // Should return an array in the style of array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename ) |
1854 // Should return an array in the style of array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename ) |
1762 return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes ); |
1855 return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes ); |
1763 } |
1856 } |
1764 |
1857 |
1765 /** |
1858 /** |
1859 * Retrieve list of mime types and file extensions. |
|
1860 * |
|
1861 * @since 3.5.0 |
|
1862 * |
|
1863 * @uses apply_filters() Calls 'mime_types' on returned array. This filter should |
|
1864 * be used to add types, not remove them. To remove types use the upload_mimes filter. |
|
1865 * |
|
1866 * @return array Array of mime types keyed by the file extension regex corresponding to those types. |
|
1867 */ |
|
1868 function wp_get_mime_types() { |
|
1869 // Accepted MIME types are set here as PCRE unless provided. |
|
1870 return apply_filters( 'mime_types', array( |
|
1871 // Image formats |
|
1872 'jpg|jpeg|jpe' => 'image/jpeg', |
|
1873 'gif' => 'image/gif', |
|
1874 'png' => 'image/png', |
|
1875 'bmp' => 'image/bmp', |
|
1876 'tif|tiff' => 'image/tiff', |
|
1877 'ico' => 'image/x-icon', |
|
1878 // Video formats |
|
1879 'asf|asx|wax|wmv|wmx' => 'video/asf', |
|
1880 'avi' => 'video/avi', |
|
1881 'divx' => 'video/divx', |
|
1882 'flv' => 'video/x-flv', |
|
1883 'mov|qt' => 'video/quicktime', |
|
1884 'mpeg|mpg|mpe' => 'video/mpeg', |
|
1885 'mp4|m4v' => 'video/mp4', |
|
1886 'ogv' => 'video/ogg', |
|
1887 'mkv' => 'video/x-matroska', |
|
1888 // Text formats |
|
1889 'txt|asc|c|cc|h' => 'text/plain', |
|
1890 'csv' => 'text/csv', |
|
1891 'tsv' => 'text/tab-separated-values', |
|
1892 'ics' => 'text/calendar', |
|
1893 'rtx' => 'text/richtext', |
|
1894 'css' => 'text/css', |
|
1895 'htm|html' => 'text/html', |
|
1896 // Audio formats |
|
1897 'mp3|m4a|m4b' => 'audio/mpeg', |
|
1898 'ra|ram' => 'audio/x-realaudio', |
|
1899 'wav' => 'audio/wav', |
|
1900 'ogg|oga' => 'audio/ogg', |
|
1901 'mid|midi' => 'audio/midi', |
|
1902 'wma' => 'audio/wma', |
|
1903 'mka' => 'audio/x-matroska', |
|
1904 // Misc application formats |
|
1905 'rtf' => 'application/rtf', |
|
1906 'js' => 'application/javascript', |
|
1907 'pdf' => 'application/pdf', |
|
1908 'swf' => 'application/x-shockwave-flash', |
|
1909 'class' => 'application/java', |
|
1910 'tar' => 'application/x-tar', |
|
1911 'zip' => 'application/zip', |
|
1912 'gz|gzip' => 'application/x-gzip', |
|
1913 'rar' => 'application/rar', |
|
1914 '7z' => 'application/x-7z-compressed', |
|
1915 'exe' => 'application/x-msdownload', |
|
1916 // MS Office formats |
|
1917 'doc' => 'application/msword', |
|
1918 'pot|pps|ppt' => 'application/vnd.ms-powerpoint', |
|
1919 'wri' => 'application/vnd.ms-write', |
|
1920 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel', |
|
1921 'mdb' => 'application/vnd.ms-access', |
|
1922 'mpp' => 'application/vnd.ms-project', |
|
1923 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
|
1924 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', |
|
1925 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
|
1926 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', |
|
1927 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
|
1928 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', |
|
1929 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
|
1930 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
|
1931 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', |
|
1932 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
|
1933 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
|
1934 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', |
|
1935 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
|
1936 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', |
|
1937 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
|
1938 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', |
|
1939 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', |
|
1940 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
|
1941 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', |
|
1942 'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote', |
|
1943 // OpenOffice formats |
|
1944 'odt' => 'application/vnd.oasis.opendocument.text', |
|
1945 'odp' => 'application/vnd.oasis.opendocument.presentation', |
|
1946 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
|
1947 'odg' => 'application/vnd.oasis.opendocument.graphics', |
|
1948 'odc' => 'application/vnd.oasis.opendocument.chart', |
|
1949 'odb' => 'application/vnd.oasis.opendocument.database', |
|
1950 'odf' => 'application/vnd.oasis.opendocument.formula', |
|
1951 // WordPerfect formats |
|
1952 'wp|wpd' => 'application/wordperfect', |
|
1953 ) ); |
|
1954 } |
|
1955 /** |
|
1766 * Retrieve list of allowed mime types and file extensions. |
1956 * Retrieve list of allowed mime types and file extensions. |
1767 * |
1957 * |
1768 * @since 2.8.6 |
1958 * @since 2.8.6 |
1769 * |
1959 * |
1960 * @uses apply_filters() Calls 'upload_mimes' on returned array |
|
1961 * @uses wp_get_upload_mime_types() to fetch the list of mime types |
|
1962 * |
|
1770 * @return array Array of mime types keyed by the file extension regex corresponding to those types. |
1963 * @return array Array of mime types keyed by the file extension regex corresponding to those types. |
1771 */ |
1964 */ |
1772 function get_allowed_mime_types() { |
1965 function get_allowed_mime_types() { |
1773 static $mimes = false; |
1966 return apply_filters( 'upload_mimes', wp_get_mime_types() ); |
1774 |
|
1775 if ( !$mimes ) { |
|
1776 // Accepted MIME types are set here as PCRE unless provided. |
|
1777 $mimes = apply_filters( 'upload_mimes', array( |
|
1778 'jpg|jpeg|jpe' => 'image/jpeg', |
|
1779 'gif' => 'image/gif', |
|
1780 'png' => 'image/png', |
|
1781 'bmp' => 'image/bmp', |
|
1782 'tif|tiff' => 'image/tiff', |
|
1783 'ico' => 'image/x-icon', |
|
1784 'asf|asx|wax|wmv|wmx' => 'video/asf', |
|
1785 'avi' => 'video/avi', |
|
1786 'divx' => 'video/divx', |
|
1787 'flv' => 'video/x-flv', |
|
1788 'mov|qt' => 'video/quicktime', |
|
1789 'mpeg|mpg|mpe' => 'video/mpeg', |
|
1790 'txt|asc|c|cc|h' => 'text/plain', |
|
1791 'csv' => 'text/csv', |
|
1792 'tsv' => 'text/tab-separated-values', |
|
1793 'ics' => 'text/calendar', |
|
1794 'rtx' => 'text/richtext', |
|
1795 'css' => 'text/css', |
|
1796 'htm|html' => 'text/html', |
|
1797 'mp3|m4a|m4b' => 'audio/mpeg', |
|
1798 'mp4|m4v' => 'video/mp4', |
|
1799 'ra|ram' => 'audio/x-realaudio', |
|
1800 'wav' => 'audio/wav', |
|
1801 'ogg|oga' => 'audio/ogg', |
|
1802 'ogv' => 'video/ogg', |
|
1803 'mid|midi' => 'audio/midi', |
|
1804 'wma' => 'audio/wma', |
|
1805 'mka' => 'audio/x-matroska', |
|
1806 'mkv' => 'video/x-matroska', |
|
1807 'rtf' => 'application/rtf', |
|
1808 'js' => 'application/javascript', |
|
1809 'pdf' => 'application/pdf', |
|
1810 'doc|docx' => 'application/msword', |
|
1811 'pot|pps|ppt|pptx|ppam|pptm|sldm|ppsm|potm' => 'application/vnd.ms-powerpoint', |
|
1812 'wri' => 'application/vnd.ms-write', |
|
1813 'xla|xls|xlsx|xlt|xlw|xlam|xlsb|xlsm|xltm' => 'application/vnd.ms-excel', |
|
1814 'mdb' => 'application/vnd.ms-access', |
|
1815 'mpp' => 'application/vnd.ms-project', |
|
1816 'docm|dotm' => 'application/vnd.ms-word', |
|
1817 'pptx|sldx|ppsx|potx' => 'application/vnd.openxmlformats-officedocument.presentationml', |
|
1818 'xlsx|xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml', |
|
1819 'docx|dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml', |
|
1820 'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote', |
|
1821 'swf' => 'application/x-shockwave-flash', |
|
1822 'class' => 'application/java', |
|
1823 'tar' => 'application/x-tar', |
|
1824 'zip' => 'application/zip', |
|
1825 'gz|gzip' => 'application/x-gzip', |
|
1826 'rar' => 'application/rar', |
|
1827 '7z' => 'application/x-7z-compressed', |
|
1828 'exe' => 'application/x-msdownload', |
|
1829 // openoffice formats |
|
1830 'odt' => 'application/vnd.oasis.opendocument.text', |
|
1831 'odp' => 'application/vnd.oasis.opendocument.presentation', |
|
1832 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
|
1833 'odg' => 'application/vnd.oasis.opendocument.graphics', |
|
1834 'odc' => 'application/vnd.oasis.opendocument.chart', |
|
1835 'odb' => 'application/vnd.oasis.opendocument.database', |
|
1836 'odf' => 'application/vnd.oasis.opendocument.formula', |
|
1837 // wordperfect formats |
|
1838 'wp|wpd' => 'application/wordperfect', |
|
1839 ) ); |
|
1840 } |
|
1841 |
|
1842 return $mimes; |
|
1843 } |
|
1844 |
|
1845 /** |
|
1846 * Retrieve nonce action "Are you sure" message. |
|
1847 * |
|
1848 * Deprecated in 3.4.1 and 3.5.0. Backported to 3.3.3. |
|
1849 * |
|
1850 * @since 2.0.4 |
|
1851 * @deprecated 3.4.1 |
|
1852 * @deprecated Use wp_nonce_ays() |
|
1853 * @see wp_nonce_ays() |
|
1854 * |
|
1855 * @param string $action Nonce action. |
|
1856 * @return string Are you sure message. |
|
1857 */ |
|
1858 function wp_explain_nonce( $action ) { |
|
1859 _deprecated_function( __FUNCTION__, '3.4.1', 'wp_nonce_ays()' ); |
|
1860 return __( 'Are you sure you want to do this?' ); |
|
1861 } |
1967 } |
1862 |
1968 |
1863 /** |
1969 /** |
1864 * Display "Are You Sure" message to confirm the action being taken. |
1970 * Display "Are You Sure" message to confirm the action being taken. |
1865 * |
1971 * |
1904 function wp_die( $message = '', $title = '', $args = array() ) { |
2010 function wp_die( $message = '', $title = '', $args = array() ) { |
1905 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
2011 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
1906 $function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); |
2012 $function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); |
1907 elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
2013 elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
1908 $function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' ); |
2014 $function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' ); |
1909 elseif ( defined( 'APP_REQUEST' ) && APP_REQUEST ) |
|
1910 $function = apply_filters( 'wp_die_app_handler', '_scalar_wp_die_handler' ); |
|
1911 else |
2015 else |
1912 $function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' ); |
2016 $function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' ); |
1913 |
2017 |
1914 call_user_func( $function, $message, $title, $args ); |
2018 call_user_func( $function, $message, $title, $args ); |
1915 } |
2019 } |
2027 text-decoration: none; |
2131 text-decoration: none; |
2028 } |
2132 } |
2029 a:hover { |
2133 a:hover { |
2030 color: #D54E21; |
2134 color: #D54E21; |
2031 } |
2135 } |
2032 |
|
2033 .button { |
2136 .button { |
2034 font-family: sans-serif; |
2137 display: inline-block; |
2035 text-decoration: none; |
2138 text-decoration: none; |
2036 font-size: 14px !important; |
2139 font-size: 14px; |
2037 line-height: 16px; |
2140 line-height: 23px; |
2038 padding: 6px 12px; |
2141 height: 24px; |
2142 margin: 0; |
|
2143 padding: 0 10px 1px; |
|
2039 cursor: pointer; |
2144 cursor: pointer; |
2040 border: 1px solid #bbb; |
2145 border-width: 1px; |
2041 color: #464646; |
2146 border-style: solid; |
2042 -webkit-border-radius: 15px; |
2147 -webkit-border-radius: 3px; |
2043 border-radius: 15px; |
2148 border-radius: 3px; |
2044 -moz-box-sizing: content-box; |
2149 white-space: nowrap; |
2045 -webkit-box-sizing: content-box; |
2150 -webkit-box-sizing: border-box; |
2046 box-sizing: content-box; |
2151 -moz-box-sizing: border-box; |
2047 background-color: #f5f5f5; |
2152 box-sizing: border-box; |
2048 background-image: -ms-linear-gradient(top, #ffffff, #f2f2f2); |
2153 background: #f3f3f3; |
2049 background-image: -moz-linear-gradient(top, #ffffff, #f2f2f2); |
2154 background-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#f4f4f4)); |
2050 background-image: -o-linear-gradient(top, #ffffff, #f2f2f2); |
2155 background-image: -webkit-linear-gradient(top, #fefefe, #f4f4f4); |
2051 background-image: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#f2f2f2)); |
2156 background-image: -moz-linear-gradient(top, #fefefe, #f4f4f4); |
2052 background-image: -webkit-linear-gradient(top, #ffffff, #f2f2f2); |
2157 background-image: -o-linear-gradient(top, #fefefe, #f4f4f4); |
2053 background-image: linear-gradient(top, #ffffff, #f2f2f2); |
2158 background-image: linear-gradient(to bottom, #fefefe, #f4f4f4); |
2054 } |
2159 border-color: #bbb; |
2055 |
2160 color: #333; |
2056 .button:hover { |
2161 text-shadow: 0 1px 0 #fff; |
2057 color: #000; |
2162 } |
2058 border-color: #666; |
2163 |
2164 .button.button-large { |
|
2165 height: 29px; |
|
2166 line-height: 28px; |
|
2167 padding: 0 12px; |
|
2168 } |
|
2169 |
|
2170 .button:hover, |
|
2171 .button:focus { |
|
2172 background: #f3f3f3; |
|
2173 background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#f3f3f3)); |
|
2174 background-image: -webkit-linear-gradient(top, #fff, #f3f3f3); |
|
2175 background-image: -moz-linear-gradient(top, #fff, #f3f3f3); |
|
2176 background-image: -ms-linear-gradient(top, #fff, #f3f3f3); |
|
2177 background-image: -o-linear-gradient(top, #fff, #f3f3f3); |
|
2178 background-image: linear-gradient(to bottom, #fff, #f3f3f3); |
|
2179 border-color: #999; |
|
2180 color: #222; |
|
2181 } |
|
2182 |
|
2183 .button:focus { |
|
2184 -webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2); |
|
2185 box-shadow: 1px 1px 1px rgba(0,0,0,.2); |
|
2059 } |
2186 } |
2060 |
2187 |
2061 .button:active { |
2188 .button:active { |
2062 background-image: -ms-linear-gradient(top, #f2f2f2, #ffffff); |
2189 outline: none; |
2063 background-image: -moz-linear-gradient(top, #f2f2f2, #ffffff); |
2190 background: #eee; |
2064 background-image: -o-linear-gradient(top, #f2f2f2, #ffffff); |
2191 background-image: -webkit-gradient(linear, left top, left bottom, from(#f4f4f4), to(#fefefe)); |
2065 background-image: -webkit-gradient(linear, left top, left bottom, from(#f2f2f2), to(#ffffff)); |
2192 background-image: -webkit-linear-gradient(top, #f4f4f4, #fefefe); |
2066 background-image: -webkit-linear-gradient(top, #f2f2f2, #ffffff); |
2193 background-image: -moz-linear-gradient(top, #f4f4f4, #fefefe); |
2067 background-image: linear-gradient(top, #f2f2f2, #ffffff); |
2194 background-image: -ms-linear-gradient(top, #f4f4f4, #fefefe); |
2195 background-image: -o-linear-gradient(top, #f4f4f4, #fefefe); |
|
2196 background-image: linear-gradient(to bottom, #f4f4f4, #fefefe); |
|
2197 border-color: #999; |
|
2198 color: #333; |
|
2199 text-shadow: 0 -1px 0 #fff; |
|
2200 -webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); |
|
2201 box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ); |
|
2068 } |
2202 } |
2069 |
2203 |
2070 <?php if ( 'rtl' == $text_direction ) : ?> |
2204 <?php if ( 'rtl' == $text_direction ) : ?> |
2071 body { font-family: Tahoma, Arial; } |
2205 body { font-family: Tahoma, Arial; } |
2072 <?php endif; ?> |
2206 <?php endif; ?> |
2134 */ |
2268 */ |
2135 function _scalar_wp_die_handler( $message = '' ) { |
2269 function _scalar_wp_die_handler( $message = '' ) { |
2136 if ( is_scalar( $message ) ) |
2270 if ( is_scalar( $message ) ) |
2137 die( (string) $message ); |
2271 die( (string) $message ); |
2138 die(); |
2272 die(); |
2273 } |
|
2274 |
|
2275 /** |
|
2276 * Send a JSON response back to an Ajax request. |
|
2277 * |
|
2278 * @since 3.5.0 |
|
2279 * |
|
2280 * @param mixed $response Variable (usually an array or object) to encode as JSON, then print and die. |
|
2281 */ |
|
2282 function wp_send_json( $response ) { |
|
2283 @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); |
|
2284 echo json_encode( $response ); |
|
2285 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
2286 wp_die(); |
|
2287 else |
|
2288 die; |
|
2289 } |
|
2290 |
|
2291 /** |
|
2292 * Send a JSON response back to an Ajax request, indicating success. |
|
2293 * |
|
2294 * @since 3.5.0 |
|
2295 * |
|
2296 * @param mixed $data Data to encode as JSON, then print and die. |
|
2297 */ |
|
2298 function wp_send_json_success( $data = null ) { |
|
2299 $response = array( 'success' => true ); |
|
2300 |
|
2301 if ( isset( $data ) ) |
|
2302 $response['data'] = $data; |
|
2303 |
|
2304 wp_send_json( $response ); |
|
2305 } |
|
2306 |
|
2307 /** |
|
2308 * Send a JSON response back to an Ajax request, indicating failure. |
|
2309 * |
|
2310 * @since 3.5.0 |
|
2311 * |
|
2312 * @param mixed $data Data to encode as JSON, then print and die. |
|
2313 */ |
|
2314 function wp_send_json_error( $data = null ) { |
|
2315 $response = array( 'success' => false ); |
|
2316 |
|
2317 if ( isset( $data ) ) |
|
2318 $response['data'] = $data; |
|
2319 |
|
2320 wp_send_json( $response ); |
|
2139 } |
2321 } |
2140 |
2322 |
2141 /** |
2323 /** |
2142 * Retrieve the WordPress home page URL. |
2324 * Retrieve the WordPress home page URL. |
2143 * |
2325 * |
2427 foreach ( $list as $key => $obj ) { |
2609 foreach ( $list as $key => $obj ) { |
2428 $to_match = (array) $obj; |
2610 $to_match = (array) $obj; |
2429 |
2611 |
2430 $matched = 0; |
2612 $matched = 0; |
2431 foreach ( $args as $m_key => $m_value ) { |
2613 foreach ( $args as $m_key => $m_value ) { |
2432 if ( $m_value == $to_match[ $m_key ] ) |
2614 if ( array_key_exists( $m_key, $to_match ) && $m_value == $to_match[ $m_key ] ) |
2433 $matched++; |
2615 $matched++; |
2434 } |
2616 } |
2435 |
2617 |
2436 if ( ( 'AND' == $operator && $matched == $count ) |
2618 if ( ( 'AND' == $operator && $matched == $count ) |
2437 || ( 'OR' == $operator && $matched > 0 ) |
2619 || ( 'OR' == $operator && $matched > 0 ) |
2485 * @since 2.2.0 |
2667 * @since 2.2.0 |
2486 * @uses $submenu The administration submenu list. |
2668 * @uses $submenu The administration submenu list. |
2487 */ |
2669 */ |
2488 function wp_widgets_add_menu() { |
2670 function wp_widgets_add_menu() { |
2489 global $submenu; |
2671 global $submenu; |
2672 |
|
2673 if ( ! current_theme_supports( 'widgets' ) ) |
|
2674 return; |
|
2675 |
|
2490 $submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' ); |
2676 $submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' ); |
2491 ksort( $submenu['themes.php'], SORT_NUMERIC ); |
2677 ksort( $submenu['themes.php'], SORT_NUMERIC ); |
2492 } |
2678 } |
2493 |
2679 |
2494 /** |
2680 /** |
2579 * @param string $url |
2765 * @param string $url |
2580 * @return bool Whether SSL access is available |
2766 * @return bool Whether SSL access is available |
2581 */ |
2767 */ |
2582 function url_is_accessable_via_ssl($url) |
2768 function url_is_accessable_via_ssl($url) |
2583 { |
2769 { |
2584 if (in_array('curl', get_loaded_extensions())) { |
2770 if ( in_array( 'curl', get_loaded_extensions() ) ) { |
2585 $ssl = preg_replace( '/^http:\/\//', 'https://', $url ); |
2771 $ssl = set_url_scheme( $url, 'https' ); |
2586 |
2772 |
2587 $ch = curl_init(); |
2773 $ch = curl_init(); |
2588 curl_setopt($ch, CURLOPT_URL, $ssl); |
2774 curl_setopt($ch, CURLOPT_URL, $ssl); |
2589 curl_setopt($ch, CURLOPT_FAILONERROR, true); |
2775 curl_setopt($ch, CURLOPT_FAILONERROR, true); |
2590 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
2776 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
2930 */ |
3116 */ |
2931 function wp_guess_url() { |
3117 function wp_guess_url() { |
2932 if ( defined('WP_SITEURL') && '' != WP_SITEURL ) { |
3118 if ( defined('WP_SITEURL') && '' != WP_SITEURL ) { |
2933 $url = WP_SITEURL; |
3119 $url = WP_SITEURL; |
2934 } else { |
3120 } else { |
2935 $schema = is_ssl() ? 'https://' : 'http://'; |
3121 $schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet |
2936 $url = preg_replace('#/(wp-admin/.*|wp-login.php)#i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
3122 $url = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
2937 } |
3123 } |
3124 |
|
2938 return rtrim($url, '/'); |
3125 return rtrim($url, '/'); |
2939 } |
3126 } |
2940 |
3127 |
2941 /** |
3128 /** |
2942 * Temporarily suspend cache additions. |
3129 * Temporarily suspend cache additions. |
2991 * |
3178 * |
2992 * @param int $blog_id optional blog id to test (default current blog) |
3179 * @param int $blog_id optional blog id to test (default current blog) |
2993 * @return bool True if not multisite or $blog_id is main site |
3180 * @return bool True if not multisite or $blog_id is main site |
2994 */ |
3181 */ |
2995 function is_main_site( $blog_id = '' ) { |
3182 function is_main_site( $blog_id = '' ) { |
2996 global $current_site, $current_blog; |
3183 global $current_site; |
2997 |
3184 |
2998 if ( !is_multisite() ) |
3185 if ( ! is_multisite() ) |
2999 return true; |
3186 return true; |
3000 |
3187 |
3001 if ( !$blog_id ) |
3188 if ( ! $blog_id ) |
3002 $blog_id = $current_blog->blog_id; |
3189 $blog_id = get_current_blog_id(); |
3003 |
3190 |
3004 return $blog_id == $current_site->blog_id; |
3191 return $blog_id == $current_site->blog_id; |
3005 } |
3192 } |
3006 |
3193 |
3007 /** |
3194 /** |
3045 $timezone_object = timezone_open( $timezone_string ); |
3232 $timezone_object = timezone_open( $timezone_string ); |
3046 $datetime_object = date_create(); |
3233 $datetime_object = date_create(); |
3047 if ( false === $timezone_object || false === $datetime_object ) { |
3234 if ( false === $timezone_object || false === $datetime_object ) { |
3048 return false; |
3235 return false; |
3049 } |
3236 } |
3050 return round( timezone_offset_get( $timezone_object, $datetime_object ) / 3600, 2 ); |
3237 return round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 ); |
3051 } |
3238 } |
3052 |
3239 |
3053 /** |
3240 /** |
3054 * {@internal Missing Short Description}} |
3241 * {@internal Missing Short Description}} |
3055 * |
3242 * |
3245 * @since 2.9.0 |
3432 * @since 2.9.0 |
3246 */ |
3433 */ |
3247 function wp_scheduled_delete() { |
3434 function wp_scheduled_delete() { |
3248 global $wpdb; |
3435 global $wpdb; |
3249 |
3436 |
3250 $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); |
3437 $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
3251 |
3438 |
3252 $posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A); |
3439 $posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A); |
3253 |
3440 |
3254 foreach ( (array) $posts_to_delete as $post ) { |
3441 foreach ( (array) $posts_to_delete as $post ) { |
3255 $post_id = (int) $post['post_id']; |
3442 $post_id = (int) $post['post_id']; |
3534 */ |
3721 */ |
3535 function wp_allowed_protocols() { |
3722 function wp_allowed_protocols() { |
3536 static $protocols; |
3723 static $protocols; |
3537 |
3724 |
3538 if ( empty( $protocols ) ) { |
3725 if ( empty( $protocols ) ) { |
3539 $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' ); |
3726 $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp' ); |
3540 $protocols = apply_filters( 'kses_allowed_protocols', $protocols ); |
3727 $protocols = apply_filters( 'kses_allowed_protocols', $protocols ); |
3541 } |
3728 } |
3542 |
3729 |
3543 return $protocols; |
3730 return $protocols; |
3544 } |
3731 } |
3626 |
3813 |
3627 if ( strpos($ua, 'iPhone') !== false |
3814 if ( strpos($ua, 'iPhone') !== false |
3628 || strpos($ua, 'iPad') !== false |
3815 || strpos($ua, 'iPad') !== false |
3629 || strpos($ua, 'iPod') !== false ) { |
3816 || strpos($ua, 'iPod') !== false ) { |
3630 return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' ); |
3817 return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' ); |
3631 } else { |
3818 } |
3632 return true; |
3819 |
3633 } |
3820 return true; |
3634 } |
3821 } |
3635 |
3822 |
3823 /** |
|
3824 * Test if a given path is a stream URL |
|
3825 * |
|
3826 * @param string $path The resource path or URL |
|
3827 * @return bool True if the path is a stream URL |
|
3828 */ |
|
3829 function wp_is_stream( $path ) { |
|
3830 $wrappers = stream_get_wrappers(); |
|
3831 $wrappers_re = '(' . join('|', $wrappers) . ')'; |
|
3832 |
|
3833 return preg_match( "!^$wrappers_re://!", $path ) === 1; |
|
3834 } |
|
3835 |
|
3836 /** |
|
3837 * Test if the supplied date is valid for the Gregorian calendar |
|
3838 * |
|
3839 * @since 3.5.0 |
|
3840 * |
|
3841 * @return bool true|false |
|
3842 */ |
|
3843 function wp_checkdate( $month, $day, $year, $source_date ) { |
|
3844 return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date ); |
|
3845 } |