#'title' => 'Test',
'call' => array(
'begin',
- array('out', 'Hello World !!!'),
+ ['out', 'Hello World !!!'],
#array('out', print_r($_SERVER,true)),
'end',
),
class Page extends nb {
- public $call = array();
+ public $call = [];
# NB 04.08.15 wtf ??? public $output;
protected static $content_type = 'text/html';
public static $expires; # Seconds to cache, no cache if 0, no head if null
public $title = '';
- public $css = array();
- public $head = array();
+ public $css = [];
+ public $head = [];
public $css_code = '';
- public $js = array();
+ public $js = [];
public $js_code = '';
public $body_class = '';
public $body_id = '';
public $h1 = '';
+ public $sep = ' / ';
/*
- Create
+ New
*/
- public function __construct($opt = array()) {
+ public function __construct($opt = []) {
- //// opt
- foreach ($opt as $k => $v) {
- if ( ! array_key_exists($k,$this) ) die ("Page->new(): unknow param $k = $v");
- $this->$k = is_array($v) ? $v : trim($v);
- }
+ // Nav
+ if (isset($opt['nav'])) list($title,$nav) = Page::nav_parse($opt['nav']);
+ unset($opt['nav']);
+
+ // Content-type
+ if (isset($opt['content_type'])) $this->content_type($opt['content_type']);
+ elseif($this->php_cli()) $this->content_type('text/html');
+ unset($opt['content_type']);
+
+ // Opt
+ parent::__construct($opt);
// Defaults
- if ( empty($this->title) ) $this->title = $this->filename2title();
+ if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title();
+ if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title;
- //// Default
- #print_r($this);
+ // Call
+ foreach ($this->to_array($this->call) as $call) {
- //// Call
- foreach ($this->to_array($this->call) as $v) {
+ if (is_scalar($call)) {
+ $this->$call();
- if ( is_array($v) ) {
- $k = $v[0]; $v = $v[1];
- $this->$k($v);
+ } elseif ( is_array($call) ) {
+ $k = $call[0];
+ $this->$k($call[1]);
+
+ } elseif (is_callable($call)) {
+ $call($this);
} else {
- $this->$v();
}
}
public static function to_array($v) {
- return (is_array($v) ? $v : array($v));
+ return (is_array($v) ? $v : [$v]);
}
public static function title2filename($title,$content_type='') {
return '<' . $tag . ($attrs ? " $attrs" : "") . '>';
}
- if (!is_array($content)) $content = array($content);
- $tags = array();
+ if (!is_array($content)) $content = [$content];
+ $tags = [];
foreach ($content as $c) {
}
public static function tag_end($tag=null) {
- static $tags = array();
+ static $tags = [];
if ($tag !== null) return array_unshift($tags,$tag);
foreach ($tags as $t) echo "</$t>".NB_EOL;
- $tags = array();
+ $tags = [];
return $tags;
return join('',self::ar_map('',$tags));
if ($tag === null) return $tags;
return preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']);
}
- /**
- * @copyright (C) 2016 Nicolas Boisselier
- * @author Nicolas Boisselier nicolas.boisselier@gmail.com
- * Does what the name says
- *
- * @param datatype1|datatype2 \$paramname description
- * @return datatype1|datatype2 description
- */
- public static function init($param) {
- global $Page;
- if (isset($Page)) self::bye("Page.init(): GLOBALS['Page'] already exists !");
- if (!self::is_hash($param)) $param = array('nav' => $param);
-
- $Page = new self(array(
-
- # 'head' => array(
- # '<meta name="viewport" content="initial-scale=1, maximum-scale=1" />',
- # ),
- 'body_class' => 'db',
-
- 'css' => false ? array() : array(
- #'/jquery/jquery.mobile.css',
- #'/jquery/jquery-ui.css',
- '/css/reset.css',
- '/css/block.css',
- '/css/button.css',
- '/css/db.css',
- ),
-
- 'js' => array(
- '/jquery/jquery.js',
- '/jquery/jquery-ui.js',
- #'/jquery/jquery.mobile.js',
- '/js/nb.js',
- ),
-
- ));
- if (isset($param['js'])) foreach ($param['js'] as $v) { $Page->js[] = $v; }
- if (isset($param['css'])) foreach ($param['css'] as $v) { $Page->css[] = $v; }
-
- $title = $nav = array();
-
- if (isset($param['nav'])) foreach ($param['nav'] as $k => $v) {
+ public static function files_concat($files) {
+
+ }
+
+ public static function nav_parse($array) {
+ #$v = &$sep;
+ foreach ($array as $k => $v) {
if ($v === '' or $v === null or empty($v[0])) {
continue;
}
if (count($v)==3) {
$title[] = $v[0];
- $nav[] = self::tag('a',$v[1],'href="'.$v[2].'"');
+ $nav[] = empty($v[2]) ? $v[1] : self::tag('a',$v[1],'href="'.$v[2].'"');
} else {
$title[] = $v[0];
- $nav[] = self::tag('a',$v[0],'href="'.$v[1].'"');
+ $nav[] = empty($v[1]) ? $v[0] : self::tag('a',$v[0],'href="'.$v[1].'"');
}
} else {
}
}
-
- #debug(array($nav,$title)); return;
- $Page->h1 = join(' / ',$nav);
-
- $Page->title = join(' / ',$title);
-
- return $Page;
+ return [$title,$nav];
+ return [
+ 'title' => $title,
+ 'title' => $title,
+ ];
}
- public function phpinfo() {
+ public static function phpinfo() {
ob_start();
phpinfo(INFO_ALL - INFO_LICENSE);
$phpinfo = ob_get_contents();
public function infos() {
$out = array(
- 'path' => $this->path()
+ 'path' => self::path()
);
foreach (get_class_vars(get_class($this)) as $k=>$v) {
if (!empty($this->$k)) $out[$k] = is_scalar($this->$k) ? $this->$k : out::scalar($this->$k);
#foreach ($_SERVER as $k=>$v) $out['_SERVER.'.$k] = $v;
#foreach ($_ENV as $k=>$v) $out['_ENV.'.$k] = $v;
- $out = array_map(function($k, $v) { return array("name"=>$k,"value"=>$v); },array_keys($out),$out);
+ $out = array_map(function($k, $v) { return ["name"=>$k,"value"=>$v]; },array_keys($out),$out);
return $out;
}
$is_html = out::is_html($format);
if ($action == 'page.infos') {
- $out = $this->infos();
+ $out = self::infos();
out::rows($format,$out);
return true;
} elseif ($action == 'page.phpinfo' or $action == 'phpinfo') {
- echo $this->phpinfo(); return true;
+ echo self::phpinfo(); return true;
} elseif ($r=self::class_action_out($this,$action)) {
return $r;