244 } |
244 } |
245 return $logged_in && getConfig('main_page_alt_enable', '0') == '1' ? getConfig('main_page_alt', getConfig('main_page', 'Main_Page')) : getConfig('main_page', 'Main_Page'); |
245 return $logged_in && getConfig('main_page_alt_enable', '0') == '1' ? getConfig('main_page_alt', getConfig('main_page', 'Main_Page')) : getConfig('main_page', 'Main_Page'); |
246 } |
246 } |
247 |
247 |
248 /** |
248 /** |
|
249 * Get the requested page title, taking into account all the different possible URL parsing schemes. |
|
250 * @param bool If true (default), runs the result through sanitize_page_id(). |
|
251 * @param bool If true (default is false), and the return is a Special or Admin page, trims off anything beyond and including the first slash. |
|
252 * @return string |
|
253 */ |
|
254 |
|
255 function get_title($sanitize = true, $chop_special = false) |
|
256 { |
|
257 $title = ''; |
|
258 if ( isset($_GET['title']) ) |
|
259 { |
|
260 $title = $_GET['title']; |
|
261 } |
|
262 else if ( isset($_SERVER['PATH_INFO']) ) |
|
263 { |
|
264 // fix for apache + CGI (occurred on a GoDaddy server, thanks mm3) |
|
265 if ( @substr(@$_SERVER['GATEWAY_INTERFACE'], 0, 3) === 'CGI' && $_SERVER['PATH_INFO'] == scriptPath . '/index.php' ) |
|
266 { |
|
267 // do nothing; ignore PATH_INFO |
|
268 } |
|
269 else |
|
270 { |
|
271 $title = substr($_SERVER['PATH_INFO'], ( strpos($_SERVER['PATH_INFO'], '/') ) + 1 ); |
|
272 } |
|
273 } |
|
274 else |
|
275 { |
|
276 // This method really isn't supported because apache has a habit of passing dots as underscores, thus corrupting the request |
|
277 // If you really want to try it, the URI format is yoursite.com/?/Page_title |
|
278 if ( !empty($_SERVER['QUERY_STRING']) && substr($_SERVER['QUERY_STRING'], 0, 1) == '/' ) |
|
279 { |
|
280 $pos = ( ($_ = strpos($_SERVER['QUERY_STRING'], '&')) !== false ) ? $_ - 1: 0x7FFFFFFF; |
|
281 $title = substr($_SERVER['QUERY_STRING'], 1, $pos); |
|
282 } |
|
283 } |
|
284 |
|
285 if ( $chop_special ) |
|
286 { |
|
287 list(, $ns) = RenderMan::strToPageID($title); |
|
288 if ( $ns == 'Special' || $ns == 'Admin' ) |
|
289 { |
|
290 list($title) = explode('/', $title); |
|
291 } |
|
292 } |
|
293 |
|
294 return ( $sanitize ) ? sanitize_page_id($title) : $title; |
|
295 } |
|
296 |
|
297 |
|
298 /** |
249 * Enano replacement for date(). Accounts for individual users' timezone preferences. |
299 * Enano replacement for date(). Accounts for individual users' timezone preferences. |
250 * @param string Date-formatted string |
300 * @param string Date-formatted string |
251 * @param int Optional - UNIX timestamp value to use. If omitted, the current time is used. |
301 * @param int Optional - UNIX timestamp value to use. If omitted, the current time is used. |
252 * @return string Formatted string |
302 * @return string Formatted string |
253 */ |
303 */ |
262 global $session, $lang; |
312 global $session, $lang; |
263 $date_fmt = is_object($session) ? $session->date_format : DATE_4; |
313 $date_fmt = is_object($session) ? $session->date_format : DATE_4; |
264 $time_fmt = is_object($session) ? $session->time_format : TIME_24_NS; |
314 $time_fmt = is_object($session) ? $session->time_format : TIME_24_NS; |
265 |
315 |
266 // within a week? use a relative date |
316 // within a week? use a relative date |
267 if ( $timestamp + ( 86400 * 7 ) >= time() && $string & ED_DATE && is_object($lang) && is_object($session) ) |
317 if ( $timestamp + ( 86400 * 7 ) >= time() && $string & ED_DATE && is_object($lang) && is_object($session) && !($string & ED_DATE_FULL) ) |
268 { |
318 { |
269 $relative_date = get_relative_date($timestamp); |
319 $relative_date = get_relative_date($timestamp); |
270 if ( $string === ED_DATE ) |
320 if ( $string === ED_DATE ) |
271 // why do more work if we're done? |
321 // why do more work if we're done? |
272 return $relative_date; |
322 return $relative_date; |
3424 // expand address range. |
3474 // expand address range. |
3425 // this takes short ranges like: |
3475 // this takes short ranges like: |
3426 // 2001:470-471:054-b02b::5-bb |
3476 // 2001:470-471:054-b02b::5-bb |
3427 // up to: |
3477 // up to: |
3428 // 2001:0470-0471:0054-b02b:0000:0000:0000:0005-00bb |
3478 // 2001:0470-0471:0054-b02b:0000:0000:0000:0005-00bb |
|
3479 $range = preg_replace('/^:/', '0000:', $range); |
3429 $range = explode(':', $range); |
3480 $range = explode(':', $range); |
3430 $expanded = ''; |
3481 $expanded = ''; |
3431 $size = count($range); |
3482 $size = count($range); |
3432 foreach ( $range as $byteset ) |
3483 foreach ( $range as $byteset ) |
3433 { |
3484 { |
3645 else if ( $low_type == 'alph' && $high_type == 'num' ) |
3696 else if ( $low_type == 'alph' && $high_type == 'num' ) |
3646 { |
3697 { |
3647 // ???? this should never happen |
3698 // ???? this should never happen |
3648 return __hexdigitrange($high, $low); |
3699 return __hexdigitrange($high, $low); |
3649 } |
3700 } |
|
3701 } |
|
3702 |
|
3703 /** |
|
3704 * Expand an IPv6 address to full form |
|
3705 * @param string ::1, 2001:470:e054::2 |
|
3706 * @return string 0000:0000:0000:0000:0000:0000:0000:0001, 2001:0470:e054:0000:0000:0000:0000:0002 |
|
3707 */ |
|
3708 |
|
3709 function expand_ipv6_address($addr) |
|
3710 { |
|
3711 $expanded = array(); |
|
3712 $addr = explode(':', $addr); |
|
3713 foreach ( $addr as $i => $bytepair ) |
|
3714 { |
|
3715 if ( empty($bytepair) ) |
|
3716 { |
|
3717 // :: |
|
3718 while ( count($expanded) < (8 - count($addr) + $i + 1) ) |
|
3719 { |
|
3720 $expanded[] = '0000'; |
|
3721 } |
|
3722 } |
|
3723 else |
|
3724 { |
|
3725 while ( strlen($bytepair) < 4 ) |
|
3726 $bytepair = "0$bytepair"; |
|
3727 $expanded[] = $bytepair; |
|
3728 } |
|
3729 } |
|
3730 return implode(':', $expanded); |
3650 } |
3731 } |
3651 |
3732 |
3652 /** |
3733 /** |
3653 * Validates an e-mail address. Uses a compacted version of the regular expression generated by the scripts at <http://examples.oreilly.com/regex/>. |
3734 * Validates an e-mail address. Uses a compacted version of the regular expression generated by the scripts at <http://examples.oreilly.com/regex/>. |
3654 * @param string E-mail address |
3735 * @param string E-mail address |