|
@@ -12,7 +12,7 @@ function applyTidy (&$html) {
|
|
'indent' => TRUE,
|
|
'indent' => TRUE,
|
|
'output-xhtml' => TRUE,
|
|
'output-xhtml' => TRUE,
|
|
'sort-attributes' => 'alpha',
|
|
'sort-attributes' => 'alpha',
|
|
- 'wrap' => 80,
|
|
+ 'wrap' => 200,
|
|
);
|
|
);
|
|
$tidy = new tidy();
|
|
$tidy = new tidy();
|
|
$tidy->parseString($html, $config, 'utf8');
|
|
$tidy->parseString($html, $config, 'utf8');
|
|
@@ -275,7 +275,7 @@ class Element {
|
|
$ret .= (string) $this->value;
|
|
$ret .= (string) $this->value;
|
|
}
|
|
}
|
|
elseif (is_array($this->value)) {
|
|
elseif (is_array($this->value)) {
|
|
- $ret .= implode('', $this->value);
|
|
+ $ret .= implode("\n", $this->value);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
$ret .= $this->value;
|
|
$ret .= $this->value;
|
|
@@ -290,7 +290,7 @@ class GraphicsContext {
|
|
protected $palette = array();
|
|
protected $palette = array();
|
|
}
|
|
}
|
|
|
|
|
|
-class Page extends Element {
|
|
+abstract class Page extends Element {
|
|
|
|
|
|
|
|
|
|
* The HTML body element of the page.
|
|
* The HTML body element of the page.
|
|
@@ -299,17 +299,32 @@ class Page extends Element {
|
|
*/
|
|
*/
|
|
protected $body;
|
|
protected $body;
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * The MIME content type with charset
|
|
|
|
+ *
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ protected $contentType = 'text/html; charset=utf8';
|
|
|
|
+
|
|
|
|
|
|
* @var Context
|
|
* @var Context
|
|
*/
|
|
*/
|
|
protected $context;
|
|
protected $context;
|
|
|
|
|
|
|
|
|
|
- * Ths HTML head element of the page.
|
|
+ * The HTML head element of the page.
|
|
*
|
|
*
|
|
* @var array
|
|
* @var array
|
|
*/
|
|
*/
|
|
protected $head;
|
|
protected $head;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * The array of HTTP headers
|
|
|
|
+ *
|
|
|
|
+ * @var array
|
|
|
|
+ */
|
|
|
|
+ protected $headers = array();
|
|
|
|
+
|
|
|
|
|
|
* @var array
|
|
* @var array
|
|
*/
|
|
*/
|
|
@@ -335,16 +350,25 @@ class Page extends Element {
|
|
$this->context = $context;
|
|
$this->context = $context;
|
|
$this->initializeHead();
|
|
$this->initializeHead();
|
|
$this->initializeBody();
|
|
$this->initializeBody();
|
|
- if (method_exists($this, 'build')) {
|
|
+
|
|
- $this->build();
|
|
+ $this->build();
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public function __toString() {
|
|
public function __toString() {
|
|
|
|
+ $this->finalizeHeader();
|
|
$html = new Element('html', NULL, $this->getHead() . $this->getBody());
|
|
$html = new Element('html', NULL, $this->getHead() . $this->getBody());
|
|
return (string) $html;
|
|
return (string) $html;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public abstract function build();
|
|
|
|
+
|
|
|
|
+ public function emitHeaders() {
|
|
|
|
+ $this->finalizeHeader();
|
|
|
|
+ foreach ($this->headers as $name => $value) {
|
|
|
|
+ header("$name: $value");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public function finalizeBody() {
|
|
public function finalizeBody() {
|
|
if (isset($this->finalized['body'])) {
|
|
if (isset($this->finalized['body'])) {
|
|
throw new Exception('Attempt to finalize already finalized body');
|
|
throw new Exception('Attempt to finalize already finalized body');
|
|
@@ -377,6 +401,13 @@ class Page extends Element {
|
|
$this->finalized['head'] = TRUE;
|
|
$this->finalized['head'] = TRUE;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function finalizeHeader() {
|
|
|
|
+ $contentType = $this->getHeader('content-type');
|
|
|
|
+ if (empty($contentType)) {
|
|
|
|
+ $this->setHeader('content-type', $this->contentType);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public function getBody() {
|
|
public function getBody() {
|
|
$this->finalizeBody();
|
|
$this->finalizeBody();
|
|
$body = new Element('body', NULL, $this->body);
|
|
$body = new Element('body', NULL, $this->body);
|
|
@@ -434,25 +465,48 @@ class Page extends Element {
|
|
}
|
|
}
|
|
|
|
|
|
public function setHeader($name, $value) {
|
|
public function setHeader($name, $value) {
|
|
-
|
|
+ $this->headers[$name] = $value;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-class Page_Main extends Page {
|
|
+
|
|
|
|
+ * Provide common layout elements to child classes.
|
|
|
|
+ *
|
|
|
|
+ * - header
|
|
|
|
+ */
|
|
|
|
+abstract class Page_Memcache_Base extends Page {
|
|
|
|
+ function build() {
|
|
|
|
+ $this->setBody(
|
|
|
|
+ new Element('div', array('class' => array('head')),
|
|
|
|
+ new Element('h1', array('class' => array('memcache')), array(
|
|
|
|
+ new Element('span', array('class' => array('logo')),
|
|
|
|
+ new Element('a', array('href' => 'http://pecl.php.net/package/memcache'), 'memcache')
|
|
|
|
+ ),
|
|
|
|
+ new Element('span', array('class' => array('nameinfo')), 'memcache_ui.php from an idea by <a href="http://livebookmark.net">Harun Yayli</a>'),
|
|
|
|
+ ))),
|
|
|
|
+ 'header'
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+class Page_Memcache_Main extends Page_Memcache_Base {
|
|
function build() {
|
|
function build() {
|
|
|
|
+ parent::build();
|
|
$this->setBody(new Element('p', NULL, 'Hello world'));
|
|
$this->setBody(new Element('p', NULL, 'Hello world'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class Page_Server_Flush extends Page {
|
|
+class Page_Memcache_Server_Flush extends Page_Memcache_Base {
|
|
function build() {
|
|
function build() {
|
|
|
|
+ parent::build();
|
|
$this->setBody(new Element('p', NULL, 'Flush server'));
|
|
$this->setBody(new Element('p', NULL, 'Flush server'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class Page_Slab_Overview extends Page {
|
|
+class Page_Memcache_Slab_Overview extends Page_Memcache_Base {
|
|
function build() {
|
|
function build() {
|
|
|
|
+ parent::build();
|
|
$this->setBody(new Element('p', NULL, 'Slabs'));
|
|
$this->setBody(new Element('p', NULL, 'Slabs'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -471,7 +525,7 @@ class Router {
|
|
'title arguments' => 'page arguments',
|
|
'title arguments' => 'page arguments',
|
|
),
|
|
),
|
|
'^server/(\w+)/flush$' => array(
|
|
'^server/(\w+)/flush$' => array(
|
|
- 'page class' => 'Page_server_Flush',
|
|
+ 'page class' => 'Page_Memcache_Server_Flush',
|
|
'page arguments' => array('$1'),
|
|
'page arguments' => array('$1'),
|
|
'title callback' => 'title_server',
|
|
'title callback' => 'title_server',
|
|
'title arguments' => 'page arguments',
|
|
'title arguments' => 'page arguments',
|
|
@@ -517,12 +571,12 @@ class Router {
|
|
),
|
|
),
|
|
|
|
|
|
'^slabs$' => array(
|
|
'^slabs$' => array(
|
|
- 'page class' => 'Page_Slab_Overview',
|
|
+ 'page class' => 'Page_Memcache_Slab_Overview',
|
|
'title' => 'Slabs per server',
|
|
'title' => 'Slabs per server',
|
|
),
|
|
),
|
|
|
|
|
|
'' => array(
|
|
'' => array(
|
|
- 'page class' => 'Page_Main',
|
|
+ 'page class' => 'Page_Memcache_Main',
|
|
'title' => 'Overview',
|
|
'title' => 'Overview',
|
|
),
|
|
),
|
|
);
|
|
);
|
|
@@ -577,6 +631,7 @@ function main() {
|
|
$router = new Router($context);
|
|
$router = new Router($context);
|
|
$item = $router->getRoute();
|
|
$item = $router->getRoute();
|
|
$page = new $item['page class']($context, $item);
|
|
$page = new $item['page class']($context, $item);
|
|
|
|
+ $page->emitHeaders();
|
|
echo $page;
|
|
echo $page;
|
|
|
|
|
|
$html = ob_get_clean();
|
|
$html = ob_get_clean();
|