| 76 | /** |
| 77 | * Retrieve timezone. |
| 78 | * |
| 79 | * @return DateTimeZone |
| 80 | */ |
| 81 | function wp_timezone() { |
| 82 | $timezone_string = get_option( 'timezone_string' ); |
| 83 | |
| 84 | if ( ! empty( $timezone_string ) ) { |
| 85 | return new DateTimeZone( $timezone_string ); |
| 86 | } |
| 87 | |
| 88 | $gmt_offset = get_option( 'gmt_offset' ); |
| 89 | $hours = (int) $gmt_offset; |
| 90 | $minutes = abs( ( $gmt_offset - (int) $gmt_offset ) * 60 ); |
| 91 | $offset = sprintf( '%+03d:%02d', $hours, $minutes ); |
| 92 | |
| 93 | /** |
| 94 | * Offset values as timezone parameter are supported since PHP 5.5.10. |
| 95 | * |
| 96 | * @link http://php.net/manual/en/datetimezone.construct.php |
| 97 | */ |
| 98 | if ( version_compare( PHP_VERSION, '5.5.10', '<' ) ) { |
| 99 | $date = new DateTime( $offset ); |
| 100 | |
| 101 | return $date->getTimezone(); |
| 102 | } |
| 103 | |
| 104 | return new DateTimeZone( $offset ); |
| 105 | } |
| 106 | |
110 | | $datemonth = $wp_locale->get_month( date( 'm', $i ) ); |
111 | | $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth ); |
112 | | $dateweekday = $wp_locale->get_weekday( date( 'w', $i ) ); |
113 | | $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday ); |
114 | | $datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) ); |
115 | | $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) ); |
116 | | $dateformatstring = ' ' . $dateformatstring; |
117 | | $dateformatstring = preg_replace( '/([^\\\])D/', "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring ); |
118 | | $dateformatstring = preg_replace( '/([^\\\])F/', "\\1" . backslashit( $datemonth ), $dateformatstring ); |
119 | | $dateformatstring = preg_replace( '/([^\\\])l/', "\\1" . backslashit( $dateweekday ), $dateformatstring ); |
120 | | $dateformatstring = preg_replace( '/([^\\\])M/', "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring ); |
121 | | $dateformatstring = preg_replace( '/([^\\\])a/', "\\1" . backslashit( $datemeridiem ), $dateformatstring ); |
122 | | $dateformatstring = preg_replace( '/([^\\\])A/', "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring ); |
123 | | |
124 | | $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) - 1 ); |
125 | | } |
126 | | $timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' ); |
127 | | $timezone_formats_re = implode( '|', $timezone_formats ); |
128 | | if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) { |
129 | | $timezone_string = get_option( 'timezone_string' ); |
130 | | if ( $timezone_string ) { |
131 | | $timezone_object = timezone_open( $timezone_string ); |
132 | | $date_object = date_create( null, $timezone_object ); |
133 | | foreach ( $timezone_formats as $timezone_format ) { |
134 | | if ( false !== strpos( $dateformatstring, $timezone_format ) ) { |
135 | | $formatted = date_format( $date_object, $timezone_format ); |
136 | | $dateformatstring = ' ' . $dateformatstring; |
137 | | $dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring ); |
138 | | $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) - 1 ); |
139 | | } |
| 147 | $month = $wp_locale->get_month( $datetime->format( 'm' ) ); |
| 148 | $weekday = $wp_locale->get_weekday( $datetime->format( 'w' ) ); |
| 149 | |
| 150 | $format_length = strlen( $req_format ); |
| 151 | |
| 152 | $new_format = ''; |
| 153 | |
| 154 | for ( $i = 0; $i < $format_length; $i++ ) { |
| 155 | switch ( $req_format[ $i ] ) { |
| 156 | case 'D': |
| 157 | $new_format .= backslashit( $wp_locale->get_weekday_abbrev( $weekday ) ); |
| 158 | break; |
| 159 | case 'F': |
| 160 | $new_format .= backslashit( $month ); |
| 161 | break; |
| 162 | case 'l': |
| 163 | $new_format .= backslashit( $weekday ); |
| 164 | break; |
| 165 | case 'M': |
| 166 | $new_format .= backslashit( $wp_locale->get_month_abbrev( $month ) ); |
| 167 | break; |
| 168 | case 'a': |
| 169 | $new_format .= backslashit( $wp_locale->get_meridiem( $datetime->format( 'a' ) ) ); |
| 170 | break; |
| 171 | case 'A': |
| 172 | $new_format .= backslashit( $wp_locale->get_meridiem( $datetime->format( 'A' ) ) ); |
| 173 | break; |
| 174 | case '\\': |
| 175 | $new_format .= $format[ $i ]; |
| 176 | |
| 177 | if ( $i < $format_length ) { |
| 178 | $i++; |
| 179 | } |
| 180 | // no break |
| 181 | default: |
| 182 | $new_format .= $format[ $i ]; |
| 183 | break; |