new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\IS;
|
||||
use ZN\Base;
|
||||
use ZN\Config;
|
||||
use ZN\Request;
|
||||
use ZN\Inclusion\Project\Theme;
|
||||
|
||||
class BootstrapExtends
|
||||
{
|
||||
/**
|
||||
* Protected Parameters
|
||||
*/
|
||||
protected static function _parameters($arguments, $cdn)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if( ! empty(Properties::$parameters['usable']) )
|
||||
{
|
||||
$lastParam = Properties::$parameters['usable'];
|
||||
|
||||
Properties::$parameters = [];
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
else
|
||||
{
|
||||
$argumentCount = count($arguments) - 1;
|
||||
$lastParam = $arguments[$argumentCount] ?? false;
|
||||
}
|
||||
|
||||
$arguments = array_unique($arguments);
|
||||
|
||||
if( $lastParam === true )
|
||||
{
|
||||
array_pop($arguments);
|
||||
}
|
||||
|
||||
return (object)
|
||||
[
|
||||
'arguments' => $arguments,
|
||||
'lastParam' => $lastParam,
|
||||
'cdnLinks' => array_change_key_case(Config::get('CDNLinks', $cdn) ?: [])
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Gettype
|
||||
*/
|
||||
public static function gettype($function, $scripts)
|
||||
{
|
||||
$str = '';
|
||||
$eol = EOL;
|
||||
$args = self::_parameters($scripts, $function . 's');
|
||||
$lastParam = $args->lastParam;
|
||||
$arguments = $args->arguments;
|
||||
$links = $args->cdnLinks;
|
||||
$scriptFix = $function . '_';
|
||||
|
||||
foreach( $arguments as $script )
|
||||
{
|
||||
if( is_array($script) )
|
||||
{
|
||||
$script = ''; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( IS::url($script) )
|
||||
{
|
||||
$str .= static::tag($script); // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
$projectFontDirectory = THEMES_DIR . Theme::$active;
|
||||
$externalFontDirectory = EXTERNAL_THEMES_DIR . Theme::$active;
|
||||
|
||||
$scriptFile = $projectFontDirectory . ($suffix = Base::suffix($script, $function === 'script' ? '.js' : '.css'));
|
||||
|
||||
if( ! is_file($scriptFile) )
|
||||
{
|
||||
$scriptFile = $externalFontDirectory . $suffix;
|
||||
}
|
||||
|
||||
if( ! in_array($scriptFix . $script, Properties::$isImport) )
|
||||
{
|
||||
if( is_file($scriptFile) )
|
||||
{
|
||||
$str .= static::tag(Request::getBaseURL($scriptFile)); // @codeCoverageIgnore
|
||||
}
|
||||
elseif( $lowerLinkName = ($links[strtolower($script)] ?? NULL) )
|
||||
{
|
||||
$str .= static::tag($lowerLinkName);
|
||||
}
|
||||
|
||||
Properties::$isImport[] = $scriptFix . $script;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( ! empty($str) )
|
||||
{
|
||||
if( $lastParam === true )
|
||||
{
|
||||
return $str; // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $str;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Inclusion\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class FileNotFoundException extends Exception
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace ZN\Inclusion\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Exclusion;
|
||||
|
||||
class InvalidArgumentException extends \InvalidArgumentException
|
||||
{
|
||||
use Exclusion;
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
|
||||
use ZN\Base;
|
||||
use ZN\Config;
|
||||
use ZN\Request;
|
||||
use ZN\Filesystem;
|
||||
use ZN\Inclusion\Project\Theme;
|
||||
|
||||
class Font extends BootstrapExtends
|
||||
{
|
||||
/**
|
||||
* Get Fonts
|
||||
*
|
||||
* @param string ...$fonts
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function use(...$fonts)
|
||||
{
|
||||
$eol = EOL;
|
||||
$str = "<style type='text/css'>".$eol;
|
||||
$args = self::_parameters($fonts, 'fonts');
|
||||
$lastParam = $args->lastParam;
|
||||
$arguments = $args->arguments;
|
||||
$links = $args->cdnLinks;
|
||||
$strEx = NULL;
|
||||
|
||||
foreach( $arguments as $font )
|
||||
{
|
||||
if( is_array($font) )
|
||||
{
|
||||
$font = ''; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$f = self::_fontName($font);
|
||||
|
||||
$allFontExtensions = array_merge(Config::expressions('differentFontExtensions'), ['svg', 'woff', 'otf', 'ttf', 'eot']);
|
||||
|
||||
if( ! empty($allFontExtensions) )
|
||||
{
|
||||
foreach( $allFontExtensions as $of )
|
||||
{
|
||||
$fontFile = THEMES_DIR . Theme::$active . $font;
|
||||
$baseUrl = Request::getBaseURL($fontFile);
|
||||
$isFontFile = $fontFile . ( $fontExtension = Base::prefix($of, '.') );
|
||||
|
||||
if( ! is_file($isFontFile) )
|
||||
{
|
||||
$fontFile = EXTERNAL_THEMES_DIR . Theme::$active . $font;
|
||||
$baseUrl = Request::getBaseURL($fontFile);
|
||||
$isFontFile = $fontFile . $fontExtension;
|
||||
}
|
||||
|
||||
if( is_file($isFontFile) )
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if( $of === 'eot' )
|
||||
{
|
||||
$str .= '<!--[if IE]>' . $eol;
|
||||
$str .= self::_face($f, $baseUrl, 'eot');
|
||||
$str .= '<![endif]-->';
|
||||
$str .= $eol;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
else
|
||||
{
|
||||
$str .= self::_face($f, $baseUrl . $fontExtension);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cndFont = isset($links[strtolower($font)]) ? $links[strtolower($font)] : NULL;
|
||||
|
||||
if( ! empty($cndFont) ) $str .= self::_face(self::_fontName($cndFont), $cndFont);
|
||||
}
|
||||
|
||||
$str .= '</style>'.$eol;
|
||||
|
||||
if( ! empty($str) )
|
||||
{
|
||||
if( $lastParam === true )
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $str;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Font Name
|
||||
*/
|
||||
protected static function _fontName($font)
|
||||
{
|
||||
$divide = explode('/', $font);
|
||||
|
||||
$sub = NULL;
|
||||
$name = $divide[0];
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if( $sub = ($divide[1] ?? NULL) )
|
||||
{
|
||||
if( $name === $sub )
|
||||
{
|
||||
$sub = NULL;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $name . $sub;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Font Face
|
||||
*/
|
||||
protected static function _face($f, $baseUrl, $extension = NULL)
|
||||
{
|
||||
$base = $baseUrl;
|
||||
|
||||
if( $extension !== NULL )
|
||||
{
|
||||
$base = Base::suffix($baseUrl, '.' . $extension); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return '@font-face{font-family:"' . Filesystem::removeExtension($f) . '"; src:url("' . $base . '") format("truetype")}' . EOL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Base;
|
||||
|
||||
class Handload
|
||||
{
|
||||
/**
|
||||
* Import Handload
|
||||
*
|
||||
* @param string ...$args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function use(...$args)
|
||||
{
|
||||
if( ! empty($args) ) foreach( $args as $file )
|
||||
{
|
||||
$suffix = Base::suffix($file, '.php');
|
||||
$commonFile = EXTERNAL_HANDLOAD_DIR.$suffix ;
|
||||
$file = HANDLOAD_DIR.$suffix;
|
||||
|
||||
if( is_file($file) )
|
||||
{
|
||||
require_once $file; # Local File
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
elseif( is_file($commonFile) )
|
||||
{
|
||||
require_once $commonFile; # Common File
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Config;
|
||||
use ZN\Request;
|
||||
use ZN\Hypertext;
|
||||
|
||||
class Masterpage
|
||||
{
|
||||
/**
|
||||
* Keeps Settings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $settings = [];
|
||||
|
||||
/**
|
||||
* Sets Head Data
|
||||
*
|
||||
* @param array $headData
|
||||
*
|
||||
* @return Masterpage
|
||||
*/
|
||||
public function headData(array $headData) : Masterpage
|
||||
{
|
||||
Properties::$parameters['headData'] = $headData;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Body Page
|
||||
*
|
||||
* @param string $head
|
||||
*
|
||||
* @return Masterpage
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function body(string $body) : Masterpage
|
||||
{
|
||||
self::$settings['bodyPage'] = $body;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Head Page
|
||||
*
|
||||
* @param mixed $head
|
||||
*
|
||||
* @return Masterpage
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function head($head) : Masterpage
|
||||
{
|
||||
self::$settings['headPage'] = $head;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Page Title
|
||||
*
|
||||
* @param string $title
|
||||
*
|
||||
* @return Masterpage
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function title(string $title) : Masterpage
|
||||
{
|
||||
self::$settings['title'] = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Meta Elements
|
||||
*
|
||||
* @param array $meta
|
||||
*
|
||||
* @return Masterpage
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function meta(array $meta) : Masterpage
|
||||
{
|
||||
self::$settings['meta'] = $meta;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Attributes
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Masterpage
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function attributes(array $attributes) : Masterpage
|
||||
{
|
||||
self::$settings['attributes'] = $attributes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* page Content
|
||||
*
|
||||
* @param array $content
|
||||
*
|
||||
* @return Masterpage
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function content(array $content) : Masterpage
|
||||
{
|
||||
self::$settings['content'] = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Body Content
|
||||
*
|
||||
* @param string $content
|
||||
*
|
||||
* @return Masterpage
|
||||
*/
|
||||
public function bodyContent(string $content) : Masterpage
|
||||
{
|
||||
Properties::$parameters['bodyContent'] = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Masterpage
|
||||
*
|
||||
* @param array $randomDataVariable = NULL
|
||||
* @param array $head = NULL
|
||||
*/
|
||||
public function use(?array $randomDataVariable = NULL, ?array $head = NULL)
|
||||
{
|
||||
if( ! empty(Properties::$parameters['headData']) ) $head = Properties::$parameters['headData'];
|
||||
if( ! empty(Properties::$parameters['data']) ) $randomDataVariable = Properties::$parameters['data'];
|
||||
|
||||
$bodyContent = Properties::$parameters['bodyContent'] ?? NULL;
|
||||
$viewDirectory = ($head['container'] ?? NULL) === true ? CONTAINER_PROJECT_DIR . 'Views/' : VIEWS_DIR;
|
||||
|
||||
Properties::$parameters = [];
|
||||
|
||||
if( ! empty(self::$settings) )
|
||||
{
|
||||
Config::set('Masterpage', self::$settings); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$masterPageSet = Config::get('Masterpage');
|
||||
$doctypes = array_merge(Config::get('Expressions', 'doctypes'), Properties::$doctype);
|
||||
$docType = $head['docType'] ?? $masterPageSet["docType"];
|
||||
$header = ($doctypes[$docType] ?? '<!DOCTYPE html>') . EOL;
|
||||
$htmlAttributes = Hypertext::attributes($head['attributes']['html'] ?? $masterPageSet['attributes']['html']);
|
||||
|
||||
$header .= '<html'.$htmlAttributes.'>'.EOL;
|
||||
$header .= '<head'.Hypertext::attributes($head['attributes']['head'] ?? $masterPageSet['attributes']['head']).'>'.EOL;
|
||||
$header .= $this->_contentCharset($head['content']['charset'] ?? $masterPageSet['content']['charset']);
|
||||
$header .= $this->_contentLanguage($head['content']['language'] ?? $masterPageSet['content']['language']);
|
||||
$header .= $this->_title($head['title'] ?? $masterPageSet["title"]);
|
||||
$header .= $this->_meta($masterPageSet['meta'], $head['meta'] ?? NULL);
|
||||
$header .= $this->_links($masterPageSet, $head, 'Font');
|
||||
$header .= $this->_links($masterPageSet, $head, 'Style');
|
||||
$header .= $this->_links($masterPageSet, $head, 'Script');
|
||||
$header .= $this->_browserIcon($head['browserIcon'] ?? $masterPageSet["browserIcon"]);
|
||||
$header .= $this->_theme($masterPageSet, $head);
|
||||
$header .= $this->_theme($masterPageSet, $head, 'plugin');
|
||||
$header .= $this->_setpage($head['headPage'] ?? $masterPageSet['headPage'], $viewDirectory);
|
||||
$header .= '</head>'.EOL;
|
||||
$header .= '<body'.Hypertext::attributes($head['attributes']['body'] ?? $masterPageSet['attributes']['body']).
|
||||
$this->_bgImage($head['backgroundImage'] ?? $masterPageSet["backgroundImage"]).'>'.EOL;
|
||||
|
||||
echo $header;
|
||||
|
||||
$randomPageVariable = $head['bodyPage'] ?? $masterPageSet['bodyPage'];
|
||||
|
||||
if( ! empty($randomPageVariable) )
|
||||
{
|
||||
$randomDataVariable['view'] = $bodyContent;
|
||||
|
||||
View::use($randomPageVariable, $randomDataVariable, false, $viewDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $bodyContent; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$randomFooterVariable = EOL.'</body>'.EOL;
|
||||
$randomFooterVariable .= '</html>';
|
||||
|
||||
echo $randomFooterVariable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Content Charset
|
||||
*/
|
||||
protected function _contentCharset($contentCharset)
|
||||
{
|
||||
$header = '';
|
||||
|
||||
if( is_array($contentCharset) )
|
||||
{
|
||||
foreach( $contentCharset as $v )
|
||||
{
|
||||
$header .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$v\">" . EOL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$header .= '<meta http-equiv="Content-Type" content="text/html; charset=' . $contentCharset . '">' . EOL; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Content Language
|
||||
*/
|
||||
protected function _contentLanguage($contentLanguage)
|
||||
{
|
||||
return '<meta http-equiv="Content-Language" content="'.$contentLanguage .'">'.EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Background Image
|
||||
*/
|
||||
protected function _bgImage($backgroundImage)
|
||||
{
|
||||
$bgImage = ( ! empty($backgroundImage) && is_file($backgroundImage) )
|
||||
? ' background="'.Request::getBaseURL($backgroundImage).'" bgproperties="fixed"' // @codeCoverageIgnore
|
||||
: '';
|
||||
|
||||
return $bgImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Browser Icon
|
||||
*/
|
||||
protected function _browserIcon($browserIcon)
|
||||
{
|
||||
if( ! empty($browserIcon) && is_file($browserIcon) )
|
||||
{
|
||||
return '<link rel="shortcut icon" href="'.Request::getBaseURL($browserIcon).'" />'.EOL; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Title
|
||||
*/
|
||||
protected function _title($title)
|
||||
{
|
||||
if( ! empty($title) )
|
||||
{
|
||||
return '<title>'.$title.'</title>'.EOL;
|
||||
}
|
||||
|
||||
return NULL; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Meta Data
|
||||
*/
|
||||
protected function _meta($metas, $headMeta)
|
||||
{
|
||||
if( $headMeta !== NULL )
|
||||
{
|
||||
$metas = array_merge($metas, $headMeta);
|
||||
}
|
||||
|
||||
$header = '';
|
||||
|
||||
if( ! empty($metas) ) foreach( $metas as $name => $content )
|
||||
{
|
||||
if( isset($headMeta[$name]) )
|
||||
{
|
||||
$content = $headMeta[$name];
|
||||
}
|
||||
|
||||
if( ! empty($content) )
|
||||
{
|
||||
$nameEx = explode(':', $name);
|
||||
$httpOrName = ( $nameEx[0] === 'http' ) ? 'http-equiv' : ( isset($nameEx[1]) ? $nameEx[0] : 'name' );
|
||||
|
||||
array_shift($nameEx);
|
||||
|
||||
$name = implode(':', $nameEx);
|
||||
|
||||
if( ! is_array($content) )
|
||||
{
|
||||
$header .= "<meta $httpOrName=\"$name\" content=\"$content\">".EOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
foreach( $content as $key => $val )
|
||||
{
|
||||
$header .= "<meta $httpOrName=\"$name\" content=\"$val\">".EOL;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Theme
|
||||
*/
|
||||
protected function _theme($masterPageSet, $head, $type = 'theme')
|
||||
{
|
||||
$theme = array_diff(array_merge((array) ($masterPageSet[$type]['name'] ?? []), (array) ($head[$type]['name'] ?? [])), ['']);
|
||||
|
||||
if( ! empty($theme) )
|
||||
{
|
||||
return Package::$type($theme, ($head[$type]['recursive'] ?? $masterPageSet[$type]['recursive']), true);
|
||||
}
|
||||
|
||||
return NULL; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Links
|
||||
*/
|
||||
protected function _links($masterPageSet, $head, $type)
|
||||
{
|
||||
$header = '';
|
||||
|
||||
$class = 'ZN\Inclusion\\' . $type;
|
||||
|
||||
if( empty($masterPageSet[$type]) && empty($head[$type]) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
$params = $masterPageSet[$type];
|
||||
|
||||
if( ! is_array($params) )
|
||||
{
|
||||
$params = [$params, true];
|
||||
}
|
||||
else
|
||||
{
|
||||
$params[] = true;
|
||||
}
|
||||
|
||||
$header .= $class::use(...$params);
|
||||
|
||||
if( isset($head[$type]) )
|
||||
{
|
||||
if( is_string($head[$type]) )
|
||||
{
|
||||
$headLinks = [$head[$type], true];
|
||||
}
|
||||
else
|
||||
{
|
||||
$head[$type][] = true;
|
||||
|
||||
$headLinks = $head[$type];
|
||||
}
|
||||
|
||||
$header .= $class::use(...$headLinks);
|
||||
}
|
||||
|
||||
return $header;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Set Page
|
||||
*/
|
||||
protected function _setpage($page, $viewDirectory)
|
||||
{
|
||||
if( ! empty($page) )
|
||||
{
|
||||
$return = '';
|
||||
|
||||
# Single Masterpage
|
||||
if( ! is_array($page) )
|
||||
{
|
||||
$return .= View::use($page, NULL, true, $viewDirectory).EOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
# Multiple Masterpage
|
||||
foreach( $page as $p )
|
||||
{
|
||||
$return .= View::use($p, NULL, true, $viewDirectory).EOL;
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Base;
|
||||
use ZN\Filesystem;
|
||||
use ZN\Inclusion\Project\Theme;
|
||||
|
||||
class Package
|
||||
{
|
||||
/**
|
||||
* Get package
|
||||
*
|
||||
* @param mixed $packages
|
||||
* @param bool $recursive = false
|
||||
* @param bool $getContents = false
|
||||
* @param string $dir = NULL
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function use($packages, bool $recursive = false, bool $getContents = false, ?string $dir = NULL)
|
||||
{
|
||||
if( ! empty(Properties::$parameters['usable']) )
|
||||
{
|
||||
$getContents = Properties::$parameters['usable']; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( ! empty(Properties::$parameters['recursive']) )
|
||||
{
|
||||
$recursive = Properties::$parameters['recursive']; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
Properties::$parameters = [];
|
||||
|
||||
if( ! is_array($packages) )
|
||||
{
|
||||
return self::_package($dir . $packages, $recursive, $getContents);
|
||||
}
|
||||
else
|
||||
{
|
||||
$return = '';
|
||||
|
||||
if( ! empty($packages) ) foreach( $packages as $package )
|
||||
{
|
||||
$return .= self::_package($dir . $package, $recursive, true);
|
||||
}
|
||||
|
||||
if( $getContents === false )
|
||||
{
|
||||
echo $return; // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
return ''; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme
|
||||
*
|
||||
* @param mixed $theme = 'Default'
|
||||
* @param bool $recursive = false
|
||||
* @param bool $getContents = false
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function theme($theme = 'Default', bool $recursive = false, bool $getContents = false)
|
||||
{
|
||||
if( Theme::$active !== NULL && is_array($theme) )
|
||||
{
|
||||
$dir = THEMES_DIR . Theme::$active;
|
||||
}
|
||||
else
|
||||
{
|
||||
$dir = THEMES_DIR;
|
||||
}
|
||||
|
||||
return self::use($theme, $recursive, $getContents, $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme
|
||||
*
|
||||
* @param mixed $plugin = 'Default'
|
||||
* @param bool $recursive = false
|
||||
* @param bool $getContents = false
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function plugin($plugin = 'Default', bool $recursive = false, bool $getContents = false)
|
||||
{
|
||||
return self::use($plugin, $recursive, $getContents, PLUGINS_DIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Package
|
||||
*/
|
||||
protected static function _package($packages, $recursive, $getContents)
|
||||
{
|
||||
$eol = EOL;
|
||||
$return = '';
|
||||
|
||||
# Common Directory
|
||||
if( ! is_dir($packages) && ! is_file($packages) )
|
||||
{
|
||||
$packages = str_replace(RESOURCES_DIR, EXTERNAL_RESOURCES_DIR, $packages);
|
||||
}
|
||||
|
||||
if( is_dir($packages) )
|
||||
{
|
||||
$packageFiles = Filesystem::getRecursiveFiles(Base::suffix($packages), $recursive);
|
||||
|
||||
if( ! empty($packageFiles) )
|
||||
{
|
||||
foreach( $packageFiles as $val )
|
||||
{
|
||||
if( $getContents === true )
|
||||
{
|
||||
$return .= Something::use($val, [], true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Something::use($val);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
elseif( is_file($packages) )
|
||||
{
|
||||
# Local Directory
|
||||
return Something::use($packages, [], $getContents);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php namespace ZN\Inclusion\Project;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Masterpage
|
||||
{
|
||||
use ViewTrait;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php namespace ZN\Inclusion\Project;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\IS;
|
||||
use ZN\Base;
|
||||
use ZN\Request;
|
||||
|
||||
class Theme
|
||||
{
|
||||
/**
|
||||
* Active status
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $active = NULL;
|
||||
|
||||
/**
|
||||
* Match elements.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $elements = [NULL, NULL];
|
||||
|
||||
/**
|
||||
* Active theme.
|
||||
*
|
||||
* @param string $active = 'Default'
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function active(string $active = 'Default')
|
||||
{
|
||||
self::$active = Base::suffix($active);
|
||||
|
||||
define('CURRENT_THEME', $active);
|
||||
|
||||
if( ! is_dir($themeDirectory = THEMES_DIR . self::$active) )
|
||||
{
|
||||
if( is_dir($externalThemeDirectory = EXTERNAL_THEMES_DIR . self::$active) )
|
||||
{
|
||||
$themeDirectory = $externalThemeDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
define('CURRENT_THEME_DIR', $themeDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match element.
|
||||
*
|
||||
* @param array $elements
|
||||
*/
|
||||
public static function matchElement(?string $inputs = NULL, ?string $attributes = NULL)
|
||||
{
|
||||
self::$elements = [Base::prefix($inputs, '|'), Base::prefix($attributes, '|')];
|
||||
|
||||
return new self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme integration.
|
||||
*
|
||||
* 5.7.5.5[changed]
|
||||
*
|
||||
* @param string $themeName
|
||||
* @param string &$data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function integration(string $themeName, string &$data)
|
||||
{
|
||||
$data = preg_replace_callback
|
||||
(
|
||||
[
|
||||
'/<(link|img|script|div|a' . self::$elements[0] . ')\s.*?(href|src' . self::$elements[1] . ')\=(\"|\')(?<element>.*?)(\"|\').*?\>/i',
|
||||
'/background(-image)*\s*\:\s*url\((?<element>.*?)\)/i'
|
||||
],
|
||||
function($selector) use ($themeName)
|
||||
{
|
||||
$orig = $selector[0];
|
||||
$path = trim($selector['element'], '\'');
|
||||
$path = preg_replace('/(\.\.\/)+/', '//', $path);
|
||||
|
||||
if( ! IS::url($path) && ! is_file($path) )
|
||||
{
|
||||
$suffix = Base::suffix($themeName) . $path;
|
||||
|
||||
if( is_file(THEMES_DIR . $suffix) )
|
||||
{
|
||||
return self::getReplacePath($path, THEMES_DIR, $suffix, $orig); // @codeCoverageIgnore
|
||||
}
|
||||
elseif( is_file(EXTERNAL_THEMES_DIR . $suffix) )
|
||||
{
|
||||
return self::getReplacePath($path, EXTERNAL_THEMES_DIR, $suffix, $orig);
|
||||
}
|
||||
}
|
||||
|
||||
return $selector[0];
|
||||
|
||||
}, $data
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* protected get replace path
|
||||
*/
|
||||
protected static function getReplacePath($path, $dir, $suffix, $orig)
|
||||
{
|
||||
return str_replace($path, Request::getBaseURL($dir) . $suffix, $orig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php namespace ZN\Inclusion\Project;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Inclusion;
|
||||
|
||||
class View
|
||||
{
|
||||
use ViewTrait;
|
||||
|
||||
/**
|
||||
* Load view.
|
||||
*
|
||||
* @param string $file = NULL
|
||||
* @param bool $usable = false
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get(?string $file = NULL, $usable = false)
|
||||
{
|
||||
return Inclusion\View::use($file, [], $usable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php namespace ZN\Inclusion\Project;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Singleton;
|
||||
|
||||
trait ViewTrait
|
||||
{
|
||||
/**
|
||||
* Keep data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $data = [];
|
||||
|
||||
/**
|
||||
* Usable view methods
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $usableViewMethods =
|
||||
[
|
||||
'page', 'view', 'cview', 'template', 'something'
|
||||
];
|
||||
|
||||
/**
|
||||
* Usable resources methods
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $usableResourcesMethods =
|
||||
[
|
||||
'script', 'style', 'font', 'theme', 'plugin'
|
||||
];
|
||||
|
||||
/**
|
||||
* Magic call static
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
if( ($return = self::call($method, $parameters)) !== NULL )
|
||||
{
|
||||
return $return; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return new self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic call
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if( ($return = self::call($method, $parameters)) !== NULL )
|
||||
{
|
||||
return $return; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get method & parameters
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function call($method, $parameters)
|
||||
{
|
||||
# If the invoked method does not contain a parameter, it returns the current value.
|
||||
if( empty($parameters) )
|
||||
{
|
||||
return self::$data[$method] ?? false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
# If the parameter of the invoked method contains a measurable value,
|
||||
# a special operation is executed.
|
||||
if( self::isImportMethod($parameters[0], $resolve) )
|
||||
{
|
||||
# The other parameters are used like the parametric array of the import method.
|
||||
$getImportMethodParameters = self::getImportMethodParameters($parameters);
|
||||
|
||||
# If the inclusion method is one of the following 4 methods;
|
||||
# [cview|page|view|something|template]
|
||||
# If no data is sent to the import method,
|
||||
# the second parameter of the method is set to NULL.
|
||||
if( in_array($getImportMethod = $resolve['method'], self::$usableViewMethods) && ! is_array($getImportMethodParameters[0]) )
|
||||
{
|
||||
array_unshift($getImportMethodParameters, NULL);
|
||||
}
|
||||
|
||||
# Getting the contents of the included file.
|
||||
self::$data[$method] = $isImportMethodContent = self::getImportMethod($getImportMethod, $resolve['parameter'], $getImportMethodParameters);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
# If the included file is not valid or has no content,
|
||||
# the parameter is assumed to be a normal value.
|
||||
if( empty($isImportMethodContent) )
|
||||
{
|
||||
self::$data[$method] = $parameters[0];
|
||||
}
|
||||
|
||||
# Returning NULL resumes object transfer. The return value is assumed to be $this.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected is import method
|
||||
*/
|
||||
protected static function isImportMethod($parameter, &$match)
|
||||
{
|
||||
return is_scalar($parameter) && preg_match
|
||||
(
|
||||
'/^(?<method>' . implode('|', self::$usableViewMethods + self::$usableResourcesMethods) . ')\:(?<parameter>.*)/',
|
||||
$parameter ?? '',
|
||||
$match
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get import method
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected static function getImportMethod($getImportMethod, $firstParameter, $getOtherParameters)
|
||||
{
|
||||
return Singleton::class('ZN\Import')->$getImportMethod($firstParameter, ...$getOtherParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected get import method parameters
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected static function getImportMethodParameters($parameters)
|
||||
{
|
||||
return Singleton::class('ZN\DataTypes\Collection')
|
||||
->data($parameters)
|
||||
->removeFirst()
|
||||
->addLast(true)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Properties
|
||||
{
|
||||
/**
|
||||
* Defined Doctypes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $doctype =
|
||||
[
|
||||
'xhtml1Strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//TR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||
'xhtml1Transitional' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//TR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||
'xhtml1Frameset' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//TR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//TR" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
|
||||
'html4Strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//TR" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||
'html4Transitional' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//TR" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||
'html4Frameset' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//TR" "http://www.w3.org/TR/html4/frameset.dtd">',
|
||||
'html5' => '<!DOCTYPE html>'
|
||||
];
|
||||
|
||||
/**
|
||||
* Is Import
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $isImport = [];
|
||||
|
||||
/**
|
||||
* Keeps parameters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $parameters =
|
||||
[
|
||||
'data' => [],
|
||||
'usable' => false
|
||||
];
|
||||
|
||||
/**
|
||||
* Usable
|
||||
*
|
||||
* @param bool $usable = true
|
||||
*/
|
||||
public static function usable(bool $usable = true)
|
||||
{
|
||||
self::$parameters['usable'] = $usable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive
|
||||
*
|
||||
* @param bool $recursive = true
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function recursive(bool $recursive = true)
|
||||
{
|
||||
self::$parameters['recursive'] = $recursive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public static function data(array $data)
|
||||
{
|
||||
self::$parameters['data'] = $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Script extends BootstrapExtends
|
||||
{
|
||||
/**
|
||||
* HTML Element
|
||||
*
|
||||
* @param string $src = NULL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function tag(?string $src = NULL) : string
|
||||
{
|
||||
return '<script type="text/javascript" src="'.$src.'"></script>' . EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scripts
|
||||
*
|
||||
* @param string ...$scripts
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function use(...$scripts)
|
||||
{
|
||||
return self::gettype('script', $scripts);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Base;
|
||||
use ZN\Config;
|
||||
use ZN\Request;
|
||||
use ZN\Datatype;
|
||||
use ZN\Buffering;
|
||||
use ZN\Filesystem;
|
||||
use ZN\Inclusion\Exception\InvalidArgumentException;
|
||||
|
||||
class Something
|
||||
{
|
||||
/**
|
||||
* Import Somehing
|
||||
*
|
||||
* @param string $randomPageVariable
|
||||
* @param array $randomDataVariable = NULL
|
||||
* @param bool $randomObGetContentsVariable = false
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function use(string $randomPageVariable, ?array $randomDataVariable = NULL, bool $randomObGetContentsVariable = false)
|
||||
{
|
||||
if( ! empty(Properties::$parameters['usable']) )
|
||||
{
|
||||
$randomObGetContentsVariable = Properties::$parameters['usable']; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( ! empty(Properties::$parameters['data']) )
|
||||
{
|
||||
$randomDataVariable = Properties::$parameters['data']; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
Properties::$parameters = [];
|
||||
|
||||
$eol = EOL;
|
||||
|
||||
$randomPageVariableExtension = Filesystem::getExtension($randomPageVariable) ?: NULL;
|
||||
$randomPageVariableBaseUrl = Request::getBaseURL($randomPageVariable);
|
||||
|
||||
$return = '';
|
||||
|
||||
if( $randomPageVariableExtension === 'js' )
|
||||
{
|
||||
$return = Script::tag($randomPageVariableBaseUrl);
|
||||
}
|
||||
elseif( $randomPageVariableExtension === 'css' )
|
||||
{
|
||||
$return = Style::tag($randomPageVariableBaseUrl);
|
||||
}
|
||||
elseif( stristr('svg|woff|otf|ttf|'.implode('|', Config::expressions('differentFontExtensions')), $randomPageVariableExtension) )
|
||||
{
|
||||
$return = self::_style($randomPageVariable, $randomPageVariableBaseUrl);
|
||||
}
|
||||
elseif( $randomPageVariableExtension === 'eot' )
|
||||
{
|
||||
$$return = self::_style($randomPageVariable, $randomPageVariableBaseUrl, true); // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
$randomPageVariable = Base::suffix($randomPageVariable, '.php');
|
||||
|
||||
if( is_file($randomPageVariable) )
|
||||
{
|
||||
$return = Buffering::file($randomPageVariable, $randomDataVariable);
|
||||
|
||||
if( $randomObGetContentsVariable === false )
|
||||
{
|
||||
echo $return; return; // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( $randomObGetContentsVariable === false )
|
||||
{
|
||||
echo $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Style
|
||||
*/
|
||||
protected static function _style($randomPageVariable, $randomPageVariableBaseUrl, $ie = false)
|
||||
{
|
||||
return '<style type="text/css">
|
||||
'.( $ie === true ? '<!--[if IE]>' : NULL ).'
|
||||
@font-face{font-family:"'.Datatype::divide(Filesystem::removeExtension($randomPageVariable), "/", -1).'";
|
||||
src:url("'.$randomPageVariableBaseUrl.'")
|
||||
format("truetype")}
|
||||
'.( $ie === true ? '<![endif]-->' : NULL ).'
|
||||
</style>' . EOL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Style extends BootstrapExtends
|
||||
{
|
||||
/**
|
||||
* HTML Element
|
||||
*
|
||||
* @param string $src = NULL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function tag(?string $src = NULL) : string
|
||||
{
|
||||
return '<link href="' . $src . '" rel="stylesheet" type="text/css" />' . EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get styles
|
||||
*
|
||||
* @param string ...$styles
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function use(...$styles)
|
||||
{
|
||||
return self::gettype('style', $styles);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Inclusion\Exception\FileNotFoundException;
|
||||
|
||||
class Template
|
||||
{
|
||||
/**
|
||||
* Import Template
|
||||
*
|
||||
* @param string $page
|
||||
* @param array $data = NULL
|
||||
* @param bool $obGetContents = false
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function use(string $page, ?array $data = NULL, bool $obGetContents = false)
|
||||
{
|
||||
if( $return = View::use($page, $data, $obGetContents, TEMPLATES_DIR) )
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
elseif( $return = View::use($page, $data, $obGetContents, EXTERNAL_TEMPLATES_DIR) )
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php namespace ZN\Inclusion;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\In;
|
||||
use ZN\Base;
|
||||
use ZN\Wizard;
|
||||
use ZN\Buffering;
|
||||
use ZN\Inclusion\Project\Theme;
|
||||
use ZN\Inclusion\Project\View as Views;
|
||||
|
||||
class View
|
||||
{
|
||||
/**
|
||||
* Template Wizard Extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $templateWizardExtension = '.wizard';
|
||||
|
||||
/**
|
||||
* Get container view
|
||||
*
|
||||
* @param string $page
|
||||
* @param array $data = NULL
|
||||
* @param bool $obGetContents = false
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function container(string $page, ?array $data = NULL, bool $obGetContents = false)
|
||||
{
|
||||
return self::use($page, $data, $obGetContents, CONTAINER_PROJECT_DIR . 'Views/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get view
|
||||
* @param string $page
|
||||
* @param array $data = NULL
|
||||
* @param bool $obGetContents = false
|
||||
* @param string $randomPageDir = VIEWS_DIR
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function use(string $page, ?array $data = NULL, bool $obGetContents = false, string $randomPageDir = VIEWS_DIR)
|
||||
{
|
||||
# If the view starts with / symbol, it refers to pulling a file from
|
||||
# the view directory linked to the corresponding controller.
|
||||
# 5.7.4[added]
|
||||
if( isset($page[0]) && $page[0] === '/' )
|
||||
{
|
||||
$page = CURRENT_CONTROLLER . $page; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( ! empty(Properties::$parameters['usable']) )
|
||||
{
|
||||
$obGetContents = Properties::$parameters['usable'];
|
||||
}
|
||||
|
||||
if( ! empty(Properties::$parameters['data']) )
|
||||
{
|
||||
$data = Properties::$parameters['data'];
|
||||
}
|
||||
|
||||
Properties::$parameters = [];
|
||||
|
||||
if( ! empty($viewData = In::$view ) )
|
||||
{
|
||||
$inData = array_merge(...$viewData);
|
||||
}
|
||||
else
|
||||
{
|
||||
$inData = [];
|
||||
}
|
||||
|
||||
$data = array_merge($inData, Views::$data, (array) $data);
|
||||
|
||||
if( is_file($randomPageDir . Base::suffix($page, '.php')) && ! strstr($page, self::$templateWizardExtension) )
|
||||
{
|
||||
return self::_page($page, $data, $obGetContents, $randomPageDir);
|
||||
}
|
||||
|
||||
return self::_templateWizard(Base::suffix(Base::removeSuffix($page, '.php'), self::$templateWizardExtension), $data, $obGetContents, $randomPageDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get view
|
||||
*
|
||||
* @param string $page
|
||||
* @param array $data = NULL
|
||||
* @param bool $obGetContents = false
|
||||
* @param string $randomPageDir = VIEWS_DIR
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function _page($randomPageVariable, $randomDataVariable, $randomObGetContentsVariable = false, $randomPageDir = VIEWS_DIR, $randomIsWizard = NULL)
|
||||
{
|
||||
if( ! pathinfo($randomPageVariable, PATHINFO_EXTENSION) || stristr($randomPageVariable, self::$templateWizardExtension) )
|
||||
{
|
||||
$randomPageVariable = Base::suffix($randomPageVariable, '.php');
|
||||
}
|
||||
|
||||
$randomPagePath = $randomPageDir . $randomPageVariable;
|
||||
|
||||
if( ($active = Theme::$active) !== NULL )
|
||||
{
|
||||
$activeRandomPagePath = $randomPageDir . $active . $randomPageVariable;
|
||||
|
||||
if( is_file($activeRandomPagePath) )
|
||||
{
|
||||
$randomPagePath = $activeRandomPagePath; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
if( $randomIsWizard === true )
|
||||
{
|
||||
Wizard::isolation($randomPagePath);
|
||||
}
|
||||
|
||||
if( is_file($randomPagePath) )
|
||||
{
|
||||
$return = Buffering::file($randomPagePath, $randomDataVariable);
|
||||
|
||||
if( $active !== NULL )
|
||||
{
|
||||
Theme::integration($active, $return);
|
||||
}
|
||||
|
||||
if( $randomObGetContentsVariable === false )
|
||||
{
|
||||
echo $return; return; // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get view
|
||||
*
|
||||
* @param string $page
|
||||
* @param array $data = NULL
|
||||
* @param bool $obGetContents = false
|
||||
* @param string $randomPageDir = PAGES_DIR
|
||||
*
|
||||
* @return void|mixed
|
||||
*/
|
||||
protected static function _templateWizard($page, $data, $obGetContents, $randomPageDir = PAGES_DIR)
|
||||
{
|
||||
$return = Wizard::data(self::_page($page, $data, true, $randomPageDir, true), (array) $data);
|
||||
|
||||
if( $obGetContents === true )
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
|
||||
echo $return;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user