# Sql: elect type,ext from mime_type where ext in ('json','csv','txt','yaml','xml','html','doc','xls');
protected static $content_types_aliases = array(
'text' => 'txt',
+ 'human' => 'txt',
);
protected static $content_types = array(
return $rows;
}
+ public static function strlen($v,$encoding='UTF-8') {
+ return mb_strlen($v,$encoding);
+ }
+
public static function mb_str_pad($input, $pad_length, $pad_string=' ', $pad_type=STR_PAD_RIGHT,$encoding='UTF-8'){
$mb_diff=mb_strlen($input, $encoding)-strlen($input);
return str_pad($input,$pad_length-$mb_diff,$pad_string,$pad_type);
*/
public function __construct($opt = []) {
- // 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']);
if (!$this->content_type()) $this->content_type($this->client_content_type());
+ // Nav
+ if (isset($opt['nav'])) list($title,$nav) = self::nav_parse($opt['nav']);
+ unset($opt['nav']);
+
// Statics
foreach ([
'charset',
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;
- // Call
+ // Call / Print
+
+ // Nav
foreach ((array)($this->call) as $call) {
if (is_scalar($call)) {
);
}
- if (!$is_html) return join("\n",(array)$content);
+ # NB 28.11.16: Proper Markdown yould be great !
+ #if (!$is_html) return (preg_match('/^(span|a|inline|label|input|select)$/',strtolower($tag))?"":"\n").join("\n",(array)$content);
+ // Markdonw to html
+ if (!$is_html) return join("\n",array_map(function($e) use($tag){
+
+ if (preg_match('/^(li|dd)$/',$tag)) {
+ $e = "- $e";
+ } elseif ($tag == 'h1') {
+ $e .= str_pad("\n",mb_strlen($e,self::$charset)+1,'=');
+ } elseif ($tag == 'h2') {
+ $e .= str_pad("\n",mb_strlen($e,self::$charset)+1,'-');
+ } elseif ($tag == 'code') {
+ $e = "```\n$e\n```\n";
+ } elseif ($tag == 'a') {
+ $e = "[$e]\n";
+ }
+
+ return ''
+ .(preg_match('/^(p|div)$/',$tag)?"\n":'')
+ .$e
+ .(preg_match('/^(p|div)$/',$tag)?"\n":'')
+ ;
+
+ },(array)$content));
if ($content===null) {
self::tag_end($tag);
if (preg_match('/tml$/',self::$content_type)) {
+ // META
if (self::$charset) $head .= '<meta http-equiv="Content-Type" content="text/html; charset='.self::$charset.'" />'.NB_EOL;
-
$head .= '<meta name="viewport" content="width=device-width, initial-scale=1" />'.NB_EOL;
- foreach ((array)($this->css) as $v) {
- $head .= '<link type="text/css" rel="stylesheet" href="' . $v . '" />'.NB_EOL;
+ // CSS
+ foreach ((array)($this->css) as $vv) {
+ foreach ($this->path2url($vv) as $v) {
+ $head .= '<link type="text/css" rel="stylesheet" href="' . $v . '" />'.NB_EOL;
+ }
}
if ($this->css_code) $head .= ''
. ' --></style>' . NB_EOL
;
- foreach ((array)($this->js) as $v) {
- $head .= '<script src="' . $v . '" type="text/javascript"></script>' . NB_EOL;
+ // JS
+ foreach ((array)($this->js) as $vv) {
+ foreach ($this->path2url($vv) as $v) {
+ $head .= '<script src="' . $v . '" type="text/javascript"></script>' . NB_EOL;
+ }
}
+
if ($this->js_code) $head .= ''
. '<script type="text/javascript"><!-- ' . NB_EOL
. trim($this->js_code)."\n"
return $head;
}
+ public static function path2url($paths) {
+ #$_SERVER['DOCUMENT_ROOT'] = '/opt/rent/www';
+ $urls = [];
+ foreach ((array)$paths as $p) {
+
+ if (preg_match('/[\*\?]/',$p)) {
+ foreach (glob($_SERVER['DOCUMENT_ROOT'].$p) as $pp) {
+ $urls[] = substr($pp, strlen($_SERVER['DOCUMENT_ROOT']));
+ }
+
+ } else {
+ $urls[] = $p;
+
+ }
+
+ }
+ #debug($urls);
+ return $urls;
+ }
+
public static function is($is) {
if ($is == 'xhtml') return preg_match('/xhtml$/',self::$content_type);
if ($is == 'html') return preg_match('/html$/',self::$content_type);
}
public static function content_type($set=null){
+ #if ($set) bye($set);
if ($set) return (self::$content_type = $set);
return self::$content_type;
}
if (!$content_type and $format) $content_type = self::ext2mime($format);
if (!$content_type and !$format and self::php_cli()) $content_type = 'text/plain';
if (!$content_type) $content_type = self::content_type();
+ #debug([$content_type,self::content_type()]);
return $content_type;
}