@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | abstract class ParserAbstract { |
3 | - public function drawText( $_text, $_parameters = [] ) { |
|
4 | - return $this->draw(trim($_text), $_parameters); |
|
5 | - } |
|
6 | - abstract public function draw( $_text, $_parameters = [] ); |
|
3 | + public function drawText( $_text, $_parameters = [] ) { |
|
4 | + return $this->draw(trim($_text), $_parameters); |
|
5 | + } |
|
6 | + abstract public function draw( $_text, $_parameters = [] ); |
|
7 | 7 | } |
8 | 8 | ?> |
@@ -3,11 +3,11 @@ |
||
3 | 3 | jRequire("../../ExternalModules/Parsedown/Parsedown.php"); |
4 | 4 | use Parsedown as Parsedown; |
5 | 5 | class ParsedownAdapter extends ParserAbstract { |
6 | - public function draw( $_text, $_parameters = [] ) { |
|
7 | - $Parsedown = new Parsedown\Parsedown(); |
|
8 | - $page = $Parsedown->text($_text); |
|
9 | - $page = preg_replace('/[ ](?=[^>]*(?:<|$))/', " ", $page); |
|
10 | - return $page; |
|
11 | - } |
|
6 | + public function draw( $_text, $_parameters = [] ) { |
|
7 | + $Parsedown = new Parsedown\Parsedown(); |
|
8 | + $page = $Parsedown->text($_text); |
|
9 | + $page = preg_replace('/[ ](?=[^>]*(?:<|$))/', " ", $page); |
|
10 | + return $page; |
|
11 | + } |
|
12 | 12 | } |
13 | 13 | ?> |
@@ -1,31 +1,31 @@ |
||
1 | 1 | <?php |
2 | 2 | class JException extends Exception { |
3 | - static protected $escapeString = "|jate|"; |
|
4 | - public function __construct($_message, $_level = 2, $_code = 0, Exception $_previous = null) { |
|
5 | - parent::__construct($_message, $_code, $_previous); |
|
6 | - if(isset(debug_backtrace()[$_level]) && isset(debug_backtrace()[$_level]["file"])) |
|
7 | - $this->file = debug_backtrace()[$_level]["file"]; |
|
8 | - if(isset(debug_backtrace()[$_level]) && isset(debug_backtrace()[$_level]["line"])) |
|
9 | - $this->line = debug_backtrace()[$_level]["line"]; |
|
10 | - if(isset(debug_backtrace()[$_level]) && isset(debug_backtrace()[$_level]["function"])) |
|
11 | - $this->function = debug_backtrace()[$_level]["function"]; |
|
12 | - if(isset(debug_backtrace()[$_level]) && isset(debug_backtrace()[$_level]["class"])) |
|
13 | - $this->class = debug_backtrace()[$_level]["class"]; |
|
14 | - } |
|
15 | - public function __toString() { |
|
16 | - return JException::encode(JException::decode($this->message)); |
|
17 | - } |
|
18 | - static public function decode( $_message ) { |
|
19 | - $messageSplitted = explode(JException::$escapeString, $_message); |
|
20 | - if(count($messageSplitted) == 3) |
|
21 | - return $messageSplitted[1]; |
|
22 | - else |
|
23 | - return $_message; |
|
24 | - } |
|
25 | - static public function encode( $_message ) { |
|
26 | - $escape = JException::$escapeString; |
|
27 | - return "$escape$_message$escape"; |
|
3 | + static protected $escapeString = "|jate|"; |
|
4 | + public function __construct($_message, $_level = 2, $_code = 0, Exception $_previous = null) { |
|
5 | + parent::__construct($_message, $_code, $_previous); |
|
6 | + if(isset(debug_backtrace()[$_level]) && isset(debug_backtrace()[$_level]["file"])) |
|
7 | + $this->file = debug_backtrace()[$_level]["file"]; |
|
8 | + if(isset(debug_backtrace()[$_level]) && isset(debug_backtrace()[$_level]["line"])) |
|
9 | + $this->line = debug_backtrace()[$_level]["line"]; |
|
10 | + if(isset(debug_backtrace()[$_level]) && isset(debug_backtrace()[$_level]["function"])) |
|
11 | + $this->function = debug_backtrace()[$_level]["function"]; |
|
12 | + if(isset(debug_backtrace()[$_level]) && isset(debug_backtrace()[$_level]["class"])) |
|
13 | + $this->class = debug_backtrace()[$_level]["class"]; |
|
14 | + } |
|
15 | + public function __toString() { |
|
16 | + return JException::encode(JException::decode($this->message)); |
|
17 | + } |
|
18 | + static public function decode( $_message ) { |
|
19 | + $messageSplitted = explode(JException::$escapeString, $_message); |
|
20 | + if(count($messageSplitted) == 3) |
|
21 | + return $messageSplitted[1]; |
|
22 | + else |
|
23 | + return $_message; |
|
24 | + } |
|
25 | + static public function encode( $_message ) { |
|
26 | + $escape = JException::$escapeString; |
|
27 | + return "$escape$_message$escape"; |
|
28 | 28 | |
29 | - } |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | ?> |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | class ServerVars { |
3 | - public $server; |
|
4 | - public function __construct() { |
|
5 | - $this->server = []; |
|
6 | - $this->server["HTTP_HOST"] = $_SERVER["HTTP_HOST"]; |
|
7 | - $this->server["REQUEST_URI"] = $_SERVER["REQUEST_URI"]; |
|
8 | - $this->server["PHP_SELF"] = $_SERVER["PHP_SELF"]; |
|
9 | - $this->server["RELATIVE"] = str_replace("/index.php", "", $_SERVER["PHP_SELF"]); |
|
10 | - } |
|
3 | + public $server; |
|
4 | + public function __construct() { |
|
5 | + $this->server = []; |
|
6 | + $this->server["HTTP_HOST"] = $_SERVER["HTTP_HOST"]; |
|
7 | + $this->server["REQUEST_URI"] = $_SERVER["REQUEST_URI"]; |
|
8 | + $this->server["PHP_SELF"] = $_SERVER["PHP_SELF"]; |
|
9 | + $this->server["RELATIVE"] = str_replace("/index.php", "", $_SERVER["PHP_SELF"]); |
|
10 | + } |
|
11 | 11 | } |
12 | 12 | ?> |
@@ -1,54 +1,54 @@ |
||
1 | 1 | <?php |
2 | 2 | trait File { |
3 | - private $files; |
|
4 | - public function __construct() { |
|
5 | - $this->files = [ |
|
6 | - "required" => [], |
|
7 | - "attached" => [] |
|
8 | - ]; |
|
9 | - } |
|
10 | - public function addFile( $_file ) { |
|
11 | - try { |
|
12 | - $this->isCorrectPath($_file); |
|
13 | - } catch( Exception $e) { |
|
14 | - throw new JException($e->getMessage()); |
|
15 | - } |
|
16 | - $this->files["attached"][] = $_file; |
|
17 | - } |
|
18 | - public function addFileRequired( $_file ) { |
|
19 | - try { |
|
20 | - $this->isCorrectPath($_file); |
|
21 | - } catch( Exception $e) { |
|
22 | - throw new JException($e->getMessage()); |
|
23 | - } |
|
24 | - $this->files["required"][] = $_file; |
|
25 | - } |
|
26 | - public function addFiles( $_files ) { |
|
27 | - if(!is_array($_files)) |
|
28 | - throw new JException("Parameter must be an array."); |
|
29 | - foreach ($_files as $value) |
|
30 | - $this->addFile($value); |
|
31 | - } |
|
32 | - public function addFilesRequired( $_files ) { |
|
33 | - if(!is_array($_files)) |
|
34 | - throw new JException("Parameter must be an array."); |
|
35 | - foreach ($_files as $value) |
|
36 | - $this->addFileRequired($value); |
|
37 | - } |
|
38 | - public function getFiles() { |
|
39 | - return $this->files["attached"]; |
|
40 | - } |
|
41 | - public function getFilesRequired() { |
|
42 | - return $this->files["required"]; |
|
43 | - } |
|
44 | - protected function isCorrectPath( $_file ) { |
|
45 | - if(!is_string($_file)) |
|
46 | - throw new JException("Path must be a string."); |
|
47 | - if(!(file_exists($_file) || $this->isCorrectUrl($_file))) |
|
48 | - throw new JException("File [$_file] not found."); |
|
49 | - } |
|
50 | - protected function isCorrectUrl( $_url ) { |
|
51 | - return strpos(@get_headers($_url)[0],'200') === false ? false : true; |
|
52 | - } |
|
3 | + private $files; |
|
4 | + public function __construct() { |
|
5 | + $this->files = [ |
|
6 | + "required" => [], |
|
7 | + "attached" => [] |
|
8 | + ]; |
|
9 | + } |
|
10 | + public function addFile( $_file ) { |
|
11 | + try { |
|
12 | + $this->isCorrectPath($_file); |
|
13 | + } catch( Exception $e) { |
|
14 | + throw new JException($e->getMessage()); |
|
15 | + } |
|
16 | + $this->files["attached"][] = $_file; |
|
17 | + } |
|
18 | + public function addFileRequired( $_file ) { |
|
19 | + try { |
|
20 | + $this->isCorrectPath($_file); |
|
21 | + } catch( Exception $e) { |
|
22 | + throw new JException($e->getMessage()); |
|
23 | + } |
|
24 | + $this->files["required"][] = $_file; |
|
25 | + } |
|
26 | + public function addFiles( $_files ) { |
|
27 | + if(!is_array($_files)) |
|
28 | + throw new JException("Parameter must be an array."); |
|
29 | + foreach ($_files as $value) |
|
30 | + $this->addFile($value); |
|
31 | + } |
|
32 | + public function addFilesRequired( $_files ) { |
|
33 | + if(!is_array($_files)) |
|
34 | + throw new JException("Parameter must be an array."); |
|
35 | + foreach ($_files as $value) |
|
36 | + $this->addFileRequired($value); |
|
37 | + } |
|
38 | + public function getFiles() { |
|
39 | + return $this->files["attached"]; |
|
40 | + } |
|
41 | + public function getFilesRequired() { |
|
42 | + return $this->files["required"]; |
|
43 | + } |
|
44 | + protected function isCorrectPath( $_file ) { |
|
45 | + if(!is_string($_file)) |
|
46 | + throw new JException("Path must be a string."); |
|
47 | + if(!(file_exists($_file) || $this->isCorrectUrl($_file))) |
|
48 | + throw new JException("File [$_file] not found."); |
|
49 | + } |
|
50 | + protected function isCorrectUrl( $_url ) { |
|
51 | + return strpos(@get_headers($_url)[0],'200') === false ? false : true; |
|
52 | + } |
|
53 | 53 | } |
54 | 54 | ?> |
@@ -2,19 +2,19 @@ |
||
2 | 2 | jRequire("../Router/Router.php"); |
3 | 3 | jRequire("../JConfig/JConfig.php"); |
4 | 4 | class WebApp { |
5 | - private $router; |
|
6 | - private $misc; |
|
7 | - public function __construct() { |
|
8 | - $configPath = "config"; |
|
9 | - $this->misc = new JConfig("$configPath/app.json"); |
|
10 | - $this->router = new Router("$configPath/router.json", $this->misc->urlCaseSensitive); |
|
11 | - } |
|
12 | - public function draw() { |
|
13 | - $pageSelected = $this->router->getPage(); |
|
14 | - $currentPage = new $pageSelected[0](); |
|
15 | - $currentPage->setParameters(["app" => $this->misc, "page" => $pageSelected[1]]); |
|
16 | - $currentPage->init(); |
|
17 | - echo minifyOutput($currentPage->draw()); |
|
18 | - } |
|
5 | + private $router; |
|
6 | + private $misc; |
|
7 | + public function __construct() { |
|
8 | + $configPath = "config"; |
|
9 | + $this->misc = new JConfig("$configPath/app.json"); |
|
10 | + $this->router = new Router("$configPath/router.json", $this->misc->urlCaseSensitive); |
|
11 | + } |
|
12 | + public function draw() { |
|
13 | + $pageSelected = $this->router->getPage(); |
|
14 | + $currentPage = new $pageSelected[0](); |
|
15 | + $currentPage->setParameters(["app" => $this->misc, "page" => $pageSelected[1]]); |
|
16 | + $currentPage->init(); |
|
17 | + echo minifyOutput($currentPage->draw()); |
|
18 | + } |
|
19 | 19 | } |
20 | 20 | ?> |
@@ -1,63 +1,63 @@ |
||
1 | 1 | <?php |
2 | 2 | requireComponent("../ServerVars/ServerVars.php"); |
3 | 3 | class Router { |
4 | - protected $url; |
|
5 | - protected $pages; |
|
6 | - protected $defaultPage; |
|
7 | - protected $urlCaseSensitive; |
|
8 | - public function __construct( $_path, $_urlCaseSensitive = false ) { |
|
9 | - if(!is_string($_path)) |
|
10 | - throw new JException("Parameter must be a string."); |
|
11 | - $jConfig = new JConfig($_path); |
|
12 | - $server = new ServerVars(); |
|
13 | - $request = $server->server["REQUEST_URI"]; |
|
14 | - $base = $server->server["RELATIVE"]; |
|
15 | - $url = str_replace($base, "", $request); |
|
16 | - $this->url = explode("/", $url); |
|
17 | - $this->pages = $jConfig->pages; |
|
18 | - $this->defaultPage = $jConfig->defaultPage; |
|
19 | - $this->urlCaseSensitive = $_urlCaseSensitive; |
|
20 | - } |
|
21 | - public function getPage() { |
|
22 | - $parameters = []; |
|
23 | - $pageSelected = null; |
|
24 | - foreach ($this->pages as $page) { |
|
25 | - $urlParameters = $this->pathSeeker(explode("/", $page[0]), $this->url); |
|
26 | - if(is_array($urlParameters)) { |
|
27 | - if(isset($page[2]) && is_array($page[2])) |
|
28 | - $urlParameters = array_merge($urlParameters, $page[2]); |
|
29 | - $pageSelected = [ |
|
30 | - $page[1], |
|
31 | - $urlParameters |
|
32 | - ]; |
|
33 | - break; |
|
34 | - } |
|
35 | - } |
|
36 | - if( $pageSelected !== null ) |
|
37 | - return $pageSelected; |
|
38 | - else |
|
39 | - return $this->defaultPage; |
|
40 | - } |
|
41 | - protected function pathSeeker( $_path, $_url ) { |
|
42 | - $urlLength = count($_url); |
|
43 | - $cont = 0; |
|
44 | - $variables = []; |
|
45 | - $pathLength = count($_path); |
|
46 | - if($urlLength == $pathLength) { |
|
47 | - while($cont < $urlLength) { |
|
48 | - if( |
|
49 | - ($this->urlCaseSensitive && $_path[$cont] == $_url[$cont]) || |
|
50 | - (!$this->urlCaseSensitive && strtolower($_path[$cont]) == strtolower($_url[$cont])) ) |
|
51 | - $cont++; |
|
52 | - else if( strpos($_path[$cont], "\$") !== false ) { |
|
53 | - $variables[str_replace('$', "", $_path[$cont])] = $_url[$cont]; |
|
54 | - $cont++; |
|
55 | - } else break; |
|
56 | - } |
|
57 | - if($cont == $urlLength) |
|
58 | - return $variables; |
|
59 | - } |
|
60 | - return null; |
|
61 | - } |
|
4 | + protected $url; |
|
5 | + protected $pages; |
|
6 | + protected $defaultPage; |
|
7 | + protected $urlCaseSensitive; |
|
8 | + public function __construct( $_path, $_urlCaseSensitive = false ) { |
|
9 | + if(!is_string($_path)) |
|
10 | + throw new JException("Parameter must be a string."); |
|
11 | + $jConfig = new JConfig($_path); |
|
12 | + $server = new ServerVars(); |
|
13 | + $request = $server->server["REQUEST_URI"]; |
|
14 | + $base = $server->server["RELATIVE"]; |
|
15 | + $url = str_replace($base, "", $request); |
|
16 | + $this->url = explode("/", $url); |
|
17 | + $this->pages = $jConfig->pages; |
|
18 | + $this->defaultPage = $jConfig->defaultPage; |
|
19 | + $this->urlCaseSensitive = $_urlCaseSensitive; |
|
20 | + } |
|
21 | + public function getPage() { |
|
22 | + $parameters = []; |
|
23 | + $pageSelected = null; |
|
24 | + foreach ($this->pages as $page) { |
|
25 | + $urlParameters = $this->pathSeeker(explode("/", $page[0]), $this->url); |
|
26 | + if(is_array($urlParameters)) { |
|
27 | + if(isset($page[2]) && is_array($page[2])) |
|
28 | + $urlParameters = array_merge($urlParameters, $page[2]); |
|
29 | + $pageSelected = [ |
|
30 | + $page[1], |
|
31 | + $urlParameters |
|
32 | + ]; |
|
33 | + break; |
|
34 | + } |
|
35 | + } |
|
36 | + if( $pageSelected !== null ) |
|
37 | + return $pageSelected; |
|
38 | + else |
|
39 | + return $this->defaultPage; |
|
40 | + } |
|
41 | + protected function pathSeeker( $_path, $_url ) { |
|
42 | + $urlLength = count($_url); |
|
43 | + $cont = 0; |
|
44 | + $variables = []; |
|
45 | + $pathLength = count($_path); |
|
46 | + if($urlLength == $pathLength) { |
|
47 | + while($cont < $urlLength) { |
|
48 | + if( |
|
49 | + ($this->urlCaseSensitive && $_path[$cont] == $_url[$cont]) || |
|
50 | + (!$this->urlCaseSensitive && strtolower($_path[$cont]) == strtolower($_url[$cont])) ) |
|
51 | + $cont++; |
|
52 | + else if( strpos($_path[$cont], "\$") !== false ) { |
|
53 | + $variables[str_replace('$', "", $_path[$cont])] = $_url[$cont]; |
|
54 | + $cont++; |
|
55 | + } else break; |
|
56 | + } |
|
57 | + if($cont == $urlLength) |
|
58 | + return $variables; |
|
59 | + } |
|
60 | + return null; |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | ?> |
@@ -3,99 +3,99 @@ |
||
3 | 3 | requireComponent("../Module/Module.php"); |
4 | 4 | requireComponent("../JException/JException.php"); |
5 | 5 | abstract class Html extends Module { |
6 | - public $template; |
|
7 | - public $app; |
|
8 | - public $page; |
|
9 | - public $tags; |
|
10 | - public $jsVars; |
|
11 | - public function __construct() { |
|
12 | - parent::__construct(); |
|
13 | - $this->template = ""; |
|
14 | - $this->app = []; |
|
15 | - $this->page = []; |
|
16 | - $this->jsVars = []; |
|
17 | - $this->tags = [ |
|
18 | - "css" => [], |
|
19 | - "js" => [], |
|
20 | - "jsVar" => [], |
|
21 | - "base" => "" |
|
22 | - ]; |
|
23 | - } |
|
24 | - public function setParameters( $_parameters = [ "app" => null, "page" => null] ) { |
|
25 | - $this->app = $_parameters["app"]; |
|
26 | - $this->page = $_parameters["page"]; |
|
27 | - } |
|
28 | - abstract public function init(); |
|
29 | - public function draw() { |
|
30 | - if($this->template == "") |
|
31 | - throw new JException("The variable \$this->template must be set in class $this->name function init()."); |
|
32 | - $server = new ServerVars(); |
|
33 | - $this->addDipendences(); |
|
34 | - $this->tags["css"] = array_unique($this->tags["css"]); |
|
35 | - $this->tags["js"] = array_unique($this->tags["js"]); |
|
36 | - $this->tags["base"] = $server->server["RELATIVE"]."/"; |
|
37 | - $this->stringifyDipendences(); |
|
38 | - return jBlockFile($this->template, $this->tags); |
|
39 | - } |
|
40 | - public function getCss() { |
|
41 | - return $this->getRequire("getCss",".css"); |
|
42 | - } |
|
43 | - public function getJs() { |
|
44 | - return $this->getRequire("getJs",".js"); |
|
45 | - } |
|
46 | - public function getJsVars() { |
|
47 | - return $this->jsVars; |
|
48 | - } |
|
49 | - public function addJsVar( $_name, $_value ) { |
|
50 | - if(!is_string($_name)) |
|
51 | - throw new InvalidArgumentException("Parameter name must be a string."); |
|
52 | - if(!is_string($_value)) |
|
53 | - throw new InvalidArgumentException("Parameter value must be a string."); |
|
54 | - $this->jsVars[] = [$_name, $_value]; |
|
55 | - } |
|
56 | - public function addJsVars( $_array ) { |
|
57 | - if(!is_array($_array)) |
|
58 | - throw new InvalidArgumentException("Parameter must be an array."); |
|
59 | - foreach ($_array as $value) |
|
60 | - $this->addJsVar($value[0], $value[1]); |
|
61 | - } |
|
62 | - protected function stringifyDipendences() { |
|
63 | - $tempStr = ""; |
|
64 | - $timeParameter = "?t=".time(); |
|
65 | - $time = ($this->app->cache->css == true) ? "" : $timeParameter; |
|
66 | - foreach ($this->tags["css"] as $i) |
|
67 | - $tempStr .= "<link rel='stylesheet' href='$i$time'>"; |
|
68 | - $this->tags["css"] = $tempStr; |
|
69 | - $tempStr = ""; |
|
70 | - $time = ($this->app->cache->js == true) ? "" : $timeParameter; |
|
71 | - foreach ($this->tags["js"] as $i) |
|
72 | - $tempStr .= "<script src='$i$time'></script>"; |
|
73 | - $this->tags["js"] = $tempStr; |
|
74 | - $tempStr = ""; |
|
75 | - $tempStr .= "<script type='text/javascript'>"; |
|
76 | - foreach ($this->tags["jsVar"] as $i) |
|
77 | - $tempStr .= " $i[0] = $i[1];\n"; |
|
78 | - $tempStr .= "</script>"; |
|
79 | - $this->tags["jsVar"] = $tempStr; |
|
80 | - } |
|
81 | - protected function addDipendences() { |
|
82 | - $this->tags["css"] = $this->getCss(); |
|
83 | - $this->tags["js"] = $this->getJs(); |
|
84 | - $this->tags["jsVar"] = $this->getJsVars(); |
|
85 | - } |
|
86 | - protected function getRequire( $_function, $_extenction) { |
|
87 | - $temp = []; |
|
88 | - $filesRequired = $this->getFilesRequired(); |
|
89 | - $files = $this->getFiles(); |
|
90 | - foreach ($filesRequired as $i) |
|
91 | - if (!is_array($i) && strpos($i, $_extenction) !== FALSE) |
|
92 | - $temp[] = $i; |
|
93 | - foreach ($this->modules as $i) |
|
94 | - $temp = array_merge( $temp, $i->$_function() ); |
|
95 | - foreach ($files as $i) |
|
96 | - if (!is_array($i) && strpos($i, $_extenction) !== FALSE) |
|
97 | - $temp[] = $i; |
|
98 | - return $temp; |
|
99 | - } |
|
6 | + public $template; |
|
7 | + public $app; |
|
8 | + public $page; |
|
9 | + public $tags; |
|
10 | + public $jsVars; |
|
11 | + public function __construct() { |
|
12 | + parent::__construct(); |
|
13 | + $this->template = ""; |
|
14 | + $this->app = []; |
|
15 | + $this->page = []; |
|
16 | + $this->jsVars = []; |
|
17 | + $this->tags = [ |
|
18 | + "css" => [], |
|
19 | + "js" => [], |
|
20 | + "jsVar" => [], |
|
21 | + "base" => "" |
|
22 | + ]; |
|
23 | + } |
|
24 | + public function setParameters( $_parameters = [ "app" => null, "page" => null] ) { |
|
25 | + $this->app = $_parameters["app"]; |
|
26 | + $this->page = $_parameters["page"]; |
|
27 | + } |
|
28 | + abstract public function init(); |
|
29 | + public function draw() { |
|
30 | + if($this->template == "") |
|
31 | + throw new JException("The variable \$this->template must be set in class $this->name function init()."); |
|
32 | + $server = new ServerVars(); |
|
33 | + $this->addDipendences(); |
|
34 | + $this->tags["css"] = array_unique($this->tags["css"]); |
|
35 | + $this->tags["js"] = array_unique($this->tags["js"]); |
|
36 | + $this->tags["base"] = $server->server["RELATIVE"]."/"; |
|
37 | + $this->stringifyDipendences(); |
|
38 | + return jBlockFile($this->template, $this->tags); |
|
39 | + } |
|
40 | + public function getCss() { |
|
41 | + return $this->getRequire("getCss",".css"); |
|
42 | + } |
|
43 | + public function getJs() { |
|
44 | + return $this->getRequire("getJs",".js"); |
|
45 | + } |
|
46 | + public function getJsVars() { |
|
47 | + return $this->jsVars; |
|
48 | + } |
|
49 | + public function addJsVar( $_name, $_value ) { |
|
50 | + if(!is_string($_name)) |
|
51 | + throw new InvalidArgumentException("Parameter name must be a string."); |
|
52 | + if(!is_string($_value)) |
|
53 | + throw new InvalidArgumentException("Parameter value must be a string."); |
|
54 | + $this->jsVars[] = [$_name, $_value]; |
|
55 | + } |
|
56 | + public function addJsVars( $_array ) { |
|
57 | + if(!is_array($_array)) |
|
58 | + throw new InvalidArgumentException("Parameter must be an array."); |
|
59 | + foreach ($_array as $value) |
|
60 | + $this->addJsVar($value[0], $value[1]); |
|
61 | + } |
|
62 | + protected function stringifyDipendences() { |
|
63 | + $tempStr = ""; |
|
64 | + $timeParameter = "?t=".time(); |
|
65 | + $time = ($this->app->cache->css == true) ? "" : $timeParameter; |
|
66 | + foreach ($this->tags["css"] as $i) |
|
67 | + $tempStr .= "<link rel='stylesheet' href='$i$time'>"; |
|
68 | + $this->tags["css"] = $tempStr; |
|
69 | + $tempStr = ""; |
|
70 | + $time = ($this->app->cache->js == true) ? "" : $timeParameter; |
|
71 | + foreach ($this->tags["js"] as $i) |
|
72 | + $tempStr .= "<script src='$i$time'></script>"; |
|
73 | + $this->tags["js"] = $tempStr; |
|
74 | + $tempStr = ""; |
|
75 | + $tempStr .= "<script type='text/javascript'>"; |
|
76 | + foreach ($this->tags["jsVar"] as $i) |
|
77 | + $tempStr .= " $i[0] = $i[1];\n"; |
|
78 | + $tempStr .= "</script>"; |
|
79 | + $this->tags["jsVar"] = $tempStr; |
|
80 | + } |
|
81 | + protected function addDipendences() { |
|
82 | + $this->tags["css"] = $this->getCss(); |
|
83 | + $this->tags["js"] = $this->getJs(); |
|
84 | + $this->tags["jsVar"] = $this->getJsVars(); |
|
85 | + } |
|
86 | + protected function getRequire( $_function, $_extenction) { |
|
87 | + $temp = []; |
|
88 | + $filesRequired = $this->getFilesRequired(); |
|
89 | + $files = $this->getFiles(); |
|
90 | + foreach ($filesRequired as $i) |
|
91 | + if (!is_array($i) && strpos($i, $_extenction) !== FALSE) |
|
92 | + $temp[] = $i; |
|
93 | + foreach ($this->modules as $i) |
|
94 | + $temp = array_merge( $temp, $i->$_function() ); |
|
95 | + foreach ($files as $i) |
|
96 | + if (!is_array($i) && strpos($i, $_extenction) !== FALSE) |
|
97 | + $temp[] = $i; |
|
98 | + return $temp; |
|
99 | + } |
|
100 | 100 | } |
101 | 101 | ?> |
@@ -2,34 +2,34 @@ |
||
2 | 2 | jRequire("../Query/Query.php"); |
3 | 3 | jRequire("../File/File.php"); |
4 | 4 | class Module { |
5 | - use Query { |
|
6 | - Query::__construct as private __queryConstruct; |
|
7 | - } |
|
8 | - use File { |
|
9 | - File::__construct as private __fileConstruct; |
|
10 | - } |
|
11 | - public $name; |
|
12 | - public $modules; |
|
13 | - public function __construct() { |
|
14 | - $this->name = get_class($this); |
|
15 | - $this->modules = []; |
|
16 | - $this->__queryConstruct(); |
|
17 | - $this->__fileConstruct(); |
|
18 | - } |
|
19 | - public function addModules( $_modules ) { |
|
20 | - if(!is_array($_modules)) |
|
21 | - throw new JException("Parameter must be an array."); |
|
22 | - foreach ($_modules as $value) |
|
23 | - $this->addModule($value); |
|
24 | - } |
|
25 | - public function addModule( $_module ) { |
|
26 | - if(!is_object($_module)) |
|
27 | - throw new JException("Parameter must be a object."); |
|
28 | - if(! is_subclass_of ($_module, "Module")) |
|
29 | - throw new JException("Parameter must be a object inherited from Module object."); |
|
30 | - $this->modules[$_module->name] = $_module; |
|
31 | - if($this->currentConnection) |
|
32 | - $this->modules[$_module->name]->addConnectionMan($this->currentConnection); |
|
33 | - } |
|
5 | + use Query { |
|
6 | + Query::__construct as private __queryConstruct; |
|
7 | + } |
|
8 | + use File { |
|
9 | + File::__construct as private __fileConstruct; |
|
10 | + } |
|
11 | + public $name; |
|
12 | + public $modules; |
|
13 | + public function __construct() { |
|
14 | + $this->name = get_class($this); |
|
15 | + $this->modules = []; |
|
16 | + $this->__queryConstruct(); |
|
17 | + $this->__fileConstruct(); |
|
18 | + } |
|
19 | + public function addModules( $_modules ) { |
|
20 | + if(!is_array($_modules)) |
|
21 | + throw new JException("Parameter must be an array."); |
|
22 | + foreach ($_modules as $value) |
|
23 | + $this->addModule($value); |
|
24 | + } |
|
25 | + public function addModule( $_module ) { |
|
26 | + if(!is_object($_module)) |
|
27 | + throw new JException("Parameter must be a object."); |
|
28 | + if(! is_subclass_of ($_module, "Module")) |
|
29 | + throw new JException("Parameter must be a object inherited from Module object."); |
|
30 | + $this->modules[$_module->name] = $_module; |
|
31 | + if($this->currentConnection) |
|
32 | + $this->modules[$_module->name]->addConnectionMan($this->currentConnection); |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | ?> |