|
@@ -24,15 +24,11 @@ class Context {
|
|
|
protected $logLevelClasses = NULL;
|
|
|
|
|
|
|
|
|
- * Directory in which the current script is located.
|
|
|
- *
|
|
|
- * Follow symlinks if applicable, to obtain the actual implementation
|
|
|
- * directory, instead of just the main file symlink, in order to find the
|
|
|
- * other files.
|
|
|
+ * Base URL for the script.
|
|
|
*
|
|
|
* @var string
|
|
|
*/
|
|
|
- protected $dirname;
|
|
|
+ protected $base;
|
|
|
|
|
|
|
|
|
* Graphics context
|
|
@@ -78,6 +74,10 @@ class Context {
|
|
|
*/
|
|
|
protected $user = FALSE;
|
|
|
|
|
|
+ function __construct() {
|
|
|
+ $this->getTidy();
|
|
|
+ }
|
|
|
+
|
|
|
function __destruct() {
|
|
|
if (!empty($this->messages)) {
|
|
|
$ret = (string) new Element('pre', array('class' => array('messages')),
|
|
@@ -91,12 +91,20 @@ class Context {
|
|
|
return $ret;
|
|
|
}
|
|
|
|
|
|
- public function getDirname() {
|
|
|
- if (!isset($this->dirname)) {
|
|
|
- $this->dirname = dirname(__FILE__);
|
|
|
+
|
|
|
+ * Get the base path where the script is located.
|
|
|
+ *
|
|
|
+ * This is helpful to locate other files using paths relative to the install.
|
|
|
+ */
|
|
|
+ public function getBase() {
|
|
|
+ if (!isset($this->base)) {
|
|
|
+ $this->base = dirname($_SERVER['SCRIPT_NAME']);
|
|
|
+ if ($this->base == '/') {
|
|
|
+ $this->base = '';
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- return $this->dirname;
|
|
|
+ return $this->base;
|
|
|
}
|
|
|
|
|
|
public function getLogLevel() {
|
|
@@ -170,7 +178,15 @@ class Context {
|
|
|
return $this->path;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Return the "tidy" status.
|
|
|
+ *
|
|
|
+ * Will only be TRUE if requested (possibly by default) and extension is
|
|
|
+ * loaded. A warning will be generated if tidy is requested but extension is
|
|
|
+ * not loaded.
|
|
|
+ */
|
|
|
public function getTidy() {
|
|
|
+ static $notified = FALSE;
|
|
|
if (!isset($this->tidy)) {
|
|
|
$this->tidy = TRUE;
|
|
|
foreach ($_GET as $key => $value) {
|
|
@@ -179,6 +195,13 @@ class Context {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ if (!$notified && $this->tidy && !extension_loaded('tidy')) {
|
|
|
+ $this->setMessage(strtr('Extension @tidy requested but missing: skipping', array(
|
|
|
+ '@tidy' => 'tidy',
|
|
|
+ )), LOG_WARNING);
|
|
|
+ $notified = TRUE;
|
|
|
+ $this->tidy = FALSE;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $this->tidy;
|
|
@@ -195,7 +218,7 @@ class Context {
|
|
|
public function setMessage($text, $logLevel = LOG_NOTICE) {
|
|
|
if ($logLevel <= $this->getlogLevel()) {
|
|
|
if (is_array($text) || (is_object($text) && !method_exists($text, '__toString'))) {
|
|
|
- $this->messages[] = array(print_r($text, TRUE), $logLevel);
|
|
|
+ $this->messages[] = array('<pre>' . print_r($text, TRUE) . '</pre>', $logLevel);
|
|
|
}
|
|
|
else {
|
|
|
$this->messages[] = array((string) $text, $logLevel);
|
|
@@ -309,6 +332,8 @@ class Page extends Element {
|
|
|
public function __construct(Context $context, array $item) {
|
|
|
parent::__construct('html');
|
|
|
$this->context = $context;
|
|
|
+ $this->initializeHead();
|
|
|
+ $this->initializeBody();
|
|
|
}
|
|
|
|
|
|
public function finalizeBody() {
|
|
@@ -322,7 +347,10 @@ class Page extends Element {
|
|
|
'class' => array($this->context->getLogLevelClass($row[1])),
|
|
|
), $row[0]);
|
|
|
}
|
|
|
- $this->setBody(new Element('div', array('class' => array('messages')), $items));
|
|
|
+ $this->setBody(new Element('div', array('class' => array('messages')), $items), 'messages');
|
|
|
+ }
|
|
|
+ foreach ($this->getRegions() as $region) {
|
|
|
+ $this->body[$region] = implode('', $this->body[$region]);
|
|
|
}
|
|
|
$this->finalized['body'] = TRUE;
|
|
|
}
|
|
@@ -334,10 +362,9 @@ class Page extends Element {
|
|
|
$cssLink = new Element('link', array(
|
|
|
'rel' => 'stylesheet',
|
|
|
'type' => 'text/css',
|
|
|
- 'href' => $this->context->getPath() .'/memcache_ui.css',
|
|
|
+ 'href' => $this->context->getBase() .'/memcache_ui.css',
|
|
|
));
|
|
|
$this->setHead($cssLink);
|
|
|
-
|
|
|
$this->finalized['head'] = TRUE;
|
|
|
}
|
|
|
|
|
@@ -358,13 +385,44 @@ class Page extends Element {
|
|
|
public function getHeader($name) {
|
|
|
}
|
|
|
|
|
|
+ public function getRegions() {
|
|
|
+ $ret = array(
|
|
|
+ 'header',
|
|
|
+ 'first sidebar',
|
|
|
+ 'content top',
|
|
|
+ 'messages',
|
|
|
+ 'help',
|
|
|
+ 'content',
|
|
|
+ 'content bottom',
|
|
|
+ 'second sidebar',
|
|
|
+ 'footer',
|
|
|
+ );
|
|
|
+
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function initializeBody() {
|
|
|
+ foreach ($this->getRegions() as $region) {
|
|
|
+ $this->body[$region] = array();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function initializeHead() {
|
|
|
+ $this->setHead(new Element('title', NULL, 'Memcache info'));
|
|
|
+ }
|
|
|
+
|
|
|
public function render() {
|
|
|
$html = new Element('html', NULL, $this->getHead() . $this->getBody());
|
|
|
return (string) $html;
|
|
|
}
|
|
|
|
|
|
- public function setBody($fragment) {
|
|
|
- $this->body[] = $fragment;
|
|
|
+ public function setBody($fragment, $region = 'content') {
|
|
|
+ if (!in_array($region, $this->getRegions())) {
|
|
|
+ $this->context->setMessage(strtr('Attempted to insert data in nonexistent region @region', array(
|
|
|
+ '@region' => self::check_plain($region),
|
|
|
+ )), LOG_WARNING);
|
|
|
+ }
|
|
|
+ $this->body[$region][] = $fragment;
|
|
|
}
|
|
|
|
|
|
public function setHead($item) {
|
|
@@ -386,6 +444,27 @@ class Page_Main extends Page {
|
|
|
|
|
|
}
|
|
|
|
|
|
+class Page_Server_Flush extends Page {
|
|
|
+ public function __construct(Context $context, $item) {
|
|
|
+ parent::__construct($context, $item);
|
|
|
+ $context->setMessage($item, LOG_DEBUG);
|
|
|
+ }
|
|
|
+
|
|
|
+ function finalizeBody() {
|
|
|
+ $hello = new Element('p', NULL, 'Flush server');
|
|
|
+ $this->setBody($hello);
|
|
|
+ parent::finalizeBody();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class Page_Slab_Overview extends Page {
|
|
|
+ function finalizeBody() {
|
|
|
+ $hello = new Element('p', NULL, 'Slabs');
|
|
|
+ $this->setBody($hello);
|
|
|
+ parent::finalizeBody();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
class Router {
|
|
|
function __construct(Context $context) {
|
|
|
$this->context = $context;
|
|
@@ -400,7 +479,7 @@ class Router {
|
|
|
'title arguments' => 'page arguments',
|
|
|
),
|
|
|
'^server/(\w+)/flush$' => array(
|
|
|
- 'page class' => 'page_server_flush',
|
|
|
+ 'page class' => 'Page_server_Flush',
|
|
|
'page arguments' => array('$1'),
|
|
|
'title callback' => 'title_server',
|
|
|
'title arguments' => 'page arguments',
|
|
@@ -446,11 +525,11 @@ class Router {
|
|
|
),
|
|
|
|
|
|
'^slabs$' => array(
|
|
|
- 'page class' => 'page_slab_overview',
|
|
|
+ 'page class' => 'Page_Slab_Overview',
|
|
|
'title' => 'Slabs per server',
|
|
|
),
|
|
|
|
|
|
- '^$' => array(
|
|
|
+ '' => array(
|
|
|
'page class' => 'Page_Main',
|
|
|
'title' => 'Overview',
|
|
|
),
|
|
@@ -475,14 +554,18 @@ class Router {
|
|
|
}
|
|
|
}
|
|
|
if ($found) {
|
|
|
- $this->context->setMessage("Found at $regex", LOG_DEBUG);
|
|
|
- $this->context->setMessage("Info: ". print_r($info, TRUE), LOG_DEBUG);
|
|
|
+ $this->context->setMessage("Menu hit on $regex", LOG_DEBUG);
|
|
|
$info = array_merge($infoDefaults, $info);
|
|
|
+ $this->context->setMessage("Info: ". print_r($info, TRUE), LOG_DEBUG);
|
|
|
if (!empty($info['page arguments'])) {
|
|
|
$regexes = array_fill(0, count($info['page arguments']), $regex);
|
|
|
$paths = array_fill(0, count($info['page arguments']), $path);
|
|
|
$info['page arguments'] = preg_replace($regexes, $info['page arguments'], $paths);
|
|
|
}
|
|
|
+ if ($info['title arguments'] == 'page arguments') {
|
|
|
+ $info['title arguments'] = &$info['page arguments'];
|
|
|
+ }
|
|
|
+ $this->context->setMessage("Info resolved: ". print_r($info, TRUE), LOG_DEBUG);
|
|
|
}
|
|
|
else {
|
|
|
$info = NULL;
|
|
@@ -496,7 +579,7 @@ function main() {
|
|
|
try {
|
|
|
ob_start();
|
|
|
$context = new Context();
|
|
|
- $context->setMessage("Dirname: [". $context->getDirname() . "]", LOG_DEBUG);
|
|
|
+ $context->setMessage("Dirname: [". $context->getBase() . "]", LOG_DEBUG);
|
|
|
$context->setMessage("Path: [". $context->getPath() . "]", LOG_DEBUG);
|
|
|
|
|
|
$router = new Router($context);
|