# HG changeset patch
# User Dan
# Date 1250901438 14400
# Node ID 73abd46f5148181403d83a9eff9b87962efce90b
# Parent be6cfe79128c99466940a61a5b10d79c1a6daa47
A bit of shuffling around code related to determining the page title from the URL. It's done in common now, and $paths becomes more of an information repository rather than an information gatherer. Note: This BREAKS $paths->fullpage/$paths->getParam() in *_preloader!
diff -r be6cfe79128c -r 73abd46f5148 includes/common.php
--- a/includes/common.php Fri Aug 21 20:30:52 2009 -0400
+++ b/includes/common.php Fri Aug 21 20:37:18 2009 -0400
@@ -381,22 +381,25 @@
profiler_log('Finished base_classes_initted hook');
- // For special and administration pages, sometimes there is a "preloader" function that must be run
- // before the session manager and/or path manager get the init signal. Call it here.
- $p = RenderMan::strToPageId($paths->get_pageid_from_url());
- if( ( $p[1] == 'Admin' || $p[1] == 'Special' ) && function_exists('page_'.$p[1].'_'.$p[0].'_preloader'))
- {
- call_user_func('page_'.$p[1].'_'.$p[0].'_preloader');
- }
-
- profiler_log('Checked for preloader');
-
// One quick security check...
if ( !is_valid_ip($_SERVER['REMOTE_ADDR']) )
{
die('SECURITY: spoofed IP address: ' . htmlspecialchars($_SERVER['REMOTE_ADDR']));
}
-
+
+ // For special and administration pages, sometimes there is a "preloader" function that must be run
+ // before the session manager and/or path manager get the init signal. Call it here.
+ $title = get_title(true);
+ list($page_id, $namespace) = RenderMan::strToPageID($title);
+ list($page_id_top) = explode('/', $page_id);
+ $fname = "page_{$namespace}_{$page_id_top}_preloader";
+ if( ( $namespace == 'Admin' || $namespace == 'Special' ) && function_exists($fname))
+ {
+ call_user_func($fname);
+ }
+
+ profiler_log('Checked for (and ran, if applicable) preloader');
+
// All checks passed! Start the main components up.
$session->start();
@@ -423,7 +426,7 @@
profiler_log('Ran session_started hook');
- $paths->init();
+ $paths->init($title);
// setup output format
if ( defined('ENANO_OUTPUT_FORMAT') )
diff -r be6cfe79128c -r 73abd46f5148 includes/common_cli.php
--- a/includes/common_cli.php Fri Aug 21 20:30:52 2009 -0400
+++ b/includes/common_cli.php Fri Aug 21 20:37:18 2009 -0400
@@ -180,16 +180,6 @@
profiler_log('Finished base_classes_initted hook');
- // For special and administration pages, sometimes there is a "preloader" function that must be run
- // before the session manager and/or path manager get the init signal. Call it here.
- $p = RenderMan::strToPageId($paths->get_pageid_from_url());
- if( ( $p[1] == 'Admin' || $p[1] == 'Special' ) && function_exists('page_'.$p[1].'_'.$p[0].'_preloader'))
- {
- call_user_func('page_'.$p[1].'_'.$p[0].'_preloader');
- }
-
- profiler_log('Checked for preloader');
-
// One quick security check...
if ( isset($_SERVER['REMOTE_ADDR']) )
{
diff -r be6cfe79128c -r 73abd46f5148 includes/functions.php
--- a/includes/functions.php Fri Aug 21 20:30:52 2009 -0400
+++ b/includes/functions.php Fri Aug 21 20:37:18 2009 -0400
@@ -246,6 +246,56 @@
}
/**
+ * Get the requested page title, taking into account all the different possible URL parsing schemes.
+ * @param bool If true (default), runs the result through sanitize_page_id().
+ * @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.
+ * @return string
+ */
+
+function get_title($sanitize = true, $chop_special = false)
+{
+ $title = '';
+ if ( isset($_GET['title']) )
+ {
+ $title = $_GET['title'];
+ }
+ else if ( isset($_SERVER['PATH_INFO']) )
+ {
+ // fix for apache + CGI (occurred on a GoDaddy server, thanks mm3)
+ if ( @substr(@$_SERVER['GATEWAY_INTERFACE'], 0, 3) === 'CGI' && $_SERVER['PATH_INFO'] == scriptPath . '/index.php' )
+ {
+ // do nothing; ignore PATH_INFO
+ }
+ else
+ {
+ $title = substr($_SERVER['PATH_INFO'], ( strpos($_SERVER['PATH_INFO'], '/') ) + 1 );
+ }
+ }
+ else
+ {
+ // This method really isn't supported because apache has a habit of passing dots as underscores, thus corrupting the request
+ // If you really want to try it, the URI format is yoursite.com/?/Page_title
+ if ( !empty($_SERVER['QUERY_STRING']) && substr($_SERVER['QUERY_STRING'], 0, 1) == '/' )
+ {
+ $pos = ( ($_ = strpos($_SERVER['QUERY_STRING'], '&')) !== false ) ? $_ - 1: 0x7FFFFFFF;
+ $title = substr($_SERVER['QUERY_STRING'], 1, $pos);
+ }
+ }
+
+ if ( $chop_special )
+ {
+ list(, $ns) = RenderMan::strToPageID($title);
+ if ( $ns == 'Special' || $ns == 'Admin' )
+ {
+ list($title) = explode('/', $title);
+ }
+ }
+
+ return ( $sanitize ) ? sanitize_page_id($title) : $title;
+}
+
+
+/**
* Enano replacement for date(). Accounts for individual users' timezone preferences.
* @param string Date-formatted string
* @param int Optional - UNIX timestamp value to use. If omitted, the current time is used.
@@ -264,7 +314,7 @@
$time_fmt = is_object($session) ? $session->time_format : TIME_24_NS;
// within a week? use a relative date
- if ( $timestamp + ( 86400 * 7 ) >= time() && $string & ED_DATE && is_object($lang) && is_object($session) )
+ if ( $timestamp + ( 86400 * 7 ) >= time() && $string & ED_DATE && is_object($lang) && is_object($session) && !($string & ED_DATE_FULL) )
{
$relative_date = get_relative_date($timestamp);
if ( $string === ED_DATE )
@@ -3426,6 +3476,7 @@
// 2001:470-471:054-b02b::5-bb
// up to:
// 2001:0470-0471:0054-b02b:0000:0000:0000:0005-00bb
+ $range = preg_replace('/^:/', '0000:', $range);
$range = explode(':', $range);
$expanded = '';
$size = count($range);
@@ -3650,6 +3701,36 @@
}
/**
+ * Expand an IPv6 address to full form
+ * @param string ::1, 2001:470:e054::2
+ * @return string 0000:0000:0000:0000:0000:0000:0000:0001, 2001:0470:e054:0000:0000:0000:0000:0002
+ */
+
+function expand_ipv6_address($addr)
+{
+ $expanded = array();
+ $addr = explode(':', $addr);
+ foreach ( $addr as $i => $bytepair )
+ {
+ if ( empty($bytepair) )
+ {
+ // ::
+ while ( count($expanded) < (8 - count($addr) + $i + 1) )
+ {
+ $expanded[] = '0000';
+ }
+ }
+ else
+ {
+ while ( strlen($bytepair) < 4 )
+ $bytepair = "0$bytepair";
+ $expanded[] = $bytepair;
+ }
+ }
+ return implode(':', $expanded);
+}
+
+/**
* Validates an e-mail address. Uses a compacted version of the regular expression generated by the scripts at