@@ -35,91 +35,91 @@ |
||
35 | 35 | |
36 | 36 | class LDAPAuthentificator implements IAuthentificator { |
37 | 37 | |
38 | - public function __construct() { |
|
39 | - // |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * check password of user and import user, if neccessary |
|
44 | - * |
|
45 | - * @param $username string name of user |
|
46 | - * @param $password string password of user |
|
47 | - * |
|
48 | - * @return userID or -1, if credentials are wrong |
|
49 | - */ |
|
50 | - public function checkPasswordAndImport(string $username, string $password): int { |
|
51 | - //https://samjlevy.com/php-ldap-login/ |
|
52 | - |
|
53 | - //Free test ldap server: https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/ |
|
54 | - |
|
55 | - //https://www.experts-exchange.com/questions/23969673/Using-PHP-with-LDAP-to-connect-to-Active-Directory-on-another-machine.html |
|
56 | - |
|
57 | - //http://www.devshed.com/c/a/php/using-php-with-ldap-part-1/3/ |
|
58 | - |
|
59 | - //check, if username contains a komma (because komma is not allowed here) |
|
60 | - if (strpos($username, ",") !== FALSE) { |
|
61 | - throw new IllegalArgumentException("',' is not allowed in username."); |
|
62 | - return -1; |
|
63 | - } |
|
64 | - |
|
65 | - $ldap_client = new LDAPClient(); |
|
66 | - |
|
67 | - //try to login user on ldap server |
|
68 | - $res = $ldap_client->bind($username, $password); |
|
69 | - |
|
70 | - if (!$res) { |
|
71 | - //user doesnt exists or credentials are wrong |
|
72 | - return -1; |
|
73 | - } |
|
74 | - |
|
75 | - //TODO: set user groups |
|
76 | - |
|
77 | - //get attributes of user |
|
78 | - $attributes = $ldap_client->listAllAttributesOfUser($username); |
|
79 | - |
|
80 | - $mail = ""; |
|
81 | - |
|
82 | - //get mail of user |
|
83 | - if (isset($attributes['mail'])) { |
|
84 | - //get first mail |
|
85 | - $mail = $attributes['mail'][0]; |
|
86 | - } else { |
|
87 | - //generate random local mail |
|
88 | - $mail = md5(PHPUtils::randomString(10) . time()) . "@local"; |
|
89 | - } |
|
90 | - |
|
91 | - $common_name = ""; |
|
92 | - |
|
93 | - if (isset($attributes['cn'])) { |
|
94 | - $common_name = $attributes['cn'][0]; |
|
95 | - } else { |
|
96 | - $common_name = $username; |
|
97 | - } |
|
98 | - |
|
99 | - //get surname |
|
100 | - $surname = ""; |
|
101 | - |
|
102 | - if (isset($attributes['sn'])) { |
|
103 | - $surname = $attributes['sn'][0]; |
|
104 | - } |
|
105 | - |
|
106 | - //unbind |
|
107 | - $ldap_client->unbind(); |
|
108 | - |
|
109 | - //check, if we have to import user |
|
110 | - if (!User::existsUsername($username)) { |
|
111 | - //generate random password |
|
112 | - $password = md5(PHPUtils::randomString(16) . time()); |
|
113 | - |
|
114 | - //import user and create user in database |
|
115 | - $res = User::create($username, $password, $mail, PHPUtils::getClientIP(), 2, "none", 1, "Plugin\\LDAPLogin\\LDAPAuthentificator"); |
|
116 | - |
|
117 | - return $res['userID']; |
|
118 | - } else { |
|
119 | - //return userID |
|
120 | - return User::getIDByUsernameFromDB($username); |
|
121 | - } |
|
122 | - } |
|
38 | + public function __construct() { |
|
39 | + // |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * check password of user and import user, if neccessary |
|
44 | + * |
|
45 | + * @param $username string name of user |
|
46 | + * @param $password string password of user |
|
47 | + * |
|
48 | + * @return userID or -1, if credentials are wrong |
|
49 | + */ |
|
50 | + public function checkPasswordAndImport(string $username, string $password): int { |
|
51 | + //https://samjlevy.com/php-ldap-login/ |
|
52 | + |
|
53 | + //Free test ldap server: https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/ |
|
54 | + |
|
55 | + //https://www.experts-exchange.com/questions/23969673/Using-PHP-with-LDAP-to-connect-to-Active-Directory-on-another-machine.html |
|
56 | + |
|
57 | + //http://www.devshed.com/c/a/php/using-php-with-ldap-part-1/3/ |
|
58 | + |
|
59 | + //check, if username contains a komma (because komma is not allowed here) |
|
60 | + if (strpos($username, ",") !== FALSE) { |
|
61 | + throw new IllegalArgumentException("',' is not allowed in username."); |
|
62 | + return -1; |
|
63 | + } |
|
64 | + |
|
65 | + $ldap_client = new LDAPClient(); |
|
66 | + |
|
67 | + //try to login user on ldap server |
|
68 | + $res = $ldap_client->bind($username, $password); |
|
69 | + |
|
70 | + if (!$res) { |
|
71 | + //user doesnt exists or credentials are wrong |
|
72 | + return -1; |
|
73 | + } |
|
74 | + |
|
75 | + //TODO: set user groups |
|
76 | + |
|
77 | + //get attributes of user |
|
78 | + $attributes = $ldap_client->listAllAttributesOfUser($username); |
|
79 | + |
|
80 | + $mail = ""; |
|
81 | + |
|
82 | + //get mail of user |
|
83 | + if (isset($attributes['mail'])) { |
|
84 | + //get first mail |
|
85 | + $mail = $attributes['mail'][0]; |
|
86 | + } else { |
|
87 | + //generate random local mail |
|
88 | + $mail = md5(PHPUtils::randomString(10) . time()) . "@local"; |
|
89 | + } |
|
90 | + |
|
91 | + $common_name = ""; |
|
92 | + |
|
93 | + if (isset($attributes['cn'])) { |
|
94 | + $common_name = $attributes['cn'][0]; |
|
95 | + } else { |
|
96 | + $common_name = $username; |
|
97 | + } |
|
98 | + |
|
99 | + //get surname |
|
100 | + $surname = ""; |
|
101 | + |
|
102 | + if (isset($attributes['sn'])) { |
|
103 | + $surname = $attributes['sn'][0]; |
|
104 | + } |
|
105 | + |
|
106 | + //unbind |
|
107 | + $ldap_client->unbind(); |
|
108 | + |
|
109 | + //check, if we have to import user |
|
110 | + if (!User::existsUsername($username)) { |
|
111 | + //generate random password |
|
112 | + $password = md5(PHPUtils::randomString(16) . time()); |
|
113 | + |
|
114 | + //import user and create user in database |
|
115 | + $res = User::create($username, $password, $mail, PHPUtils::getClientIP(), 2, "none", 1, "Plugin\\LDAPLogin\\LDAPAuthentificator"); |
|
116 | + |
|
117 | + return $res['userID']; |
|
118 | + } else { |
|
119 | + //return userID |
|
120 | + return User::getIDByUsernameFromDB($username); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | ?> |
@@ -27,59 +27,59 @@ |
||
27 | 27 | |
28 | 28 | class ApiAuth { |
29 | 29 | |
30 | - protected static $instance = null; |
|
31 | - |
|
32 | - protected $oauth = null; |
|
33 | - protected $is_authentificated = false;//flag, if user is authentificated |
|
34 | - |
|
35 | - /** |
|
36 | - * ApiAuth constructor. |
|
37 | - */ |
|
38 | - public function __construct() { |
|
39 | - // |
|
40 | - } |
|
41 | - |
|
42 | - public function init () { |
|
43 | - //check for secret token |
|
44 | - if (isset($_REQUEST['access_token'])) { |
|
45 | - $access_token = Validator_String::get($_REQUEST['access_token']); |
|
46 | - |
|
47 | - //try to verify access token |
|
48 | - $oauth = new ApiOAuth(); |
|
49 | - if (!$oauth->load($access_token)) { |
|
50 | - //api token isn't valide |
|
51 | - return; |
|
52 | - } |
|
53 | - |
|
54 | - //user is authentificated |
|
55 | - $this->is_authentificated = true; |
|
56 | - $this->oauth = $oauth; |
|
57 | - |
|
58 | - //set userID and load user |
|
59 | - User::current()->load($oauth->getUserID()); |
|
60 | - } |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * check, if user is authentificated |
|
65 | - * |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function isAuthentificated () : bool { |
|
69 | - return $this->is_authentificated; |
|
70 | - } |
|
71 | - |
|
72 | - public function getOAuth () : OAuth { |
|
73 | - return $this->oauth; |
|
74 | - } |
|
75 | - |
|
76 | - public static function &getInstance () : ApiAuth { |
|
77 | - if (self::$instance == null) { |
|
78 | - self::$instance = new ApiAuth(); |
|
79 | - } |
|
80 | - |
|
81 | - return self::$instance; |
|
82 | - } |
|
30 | + protected static $instance = null; |
|
31 | + |
|
32 | + protected $oauth = null; |
|
33 | + protected $is_authentificated = false;//flag, if user is authentificated |
|
34 | + |
|
35 | + /** |
|
36 | + * ApiAuth constructor. |
|
37 | + */ |
|
38 | + public function __construct() { |
|
39 | + // |
|
40 | + } |
|
41 | + |
|
42 | + public function init () { |
|
43 | + //check for secret token |
|
44 | + if (isset($_REQUEST['access_token'])) { |
|
45 | + $access_token = Validator_String::get($_REQUEST['access_token']); |
|
46 | + |
|
47 | + //try to verify access token |
|
48 | + $oauth = new ApiOAuth(); |
|
49 | + if (!$oauth->load($access_token)) { |
|
50 | + //api token isn't valide |
|
51 | + return; |
|
52 | + } |
|
53 | + |
|
54 | + //user is authentificated |
|
55 | + $this->is_authentificated = true; |
|
56 | + $this->oauth = $oauth; |
|
57 | + |
|
58 | + //set userID and load user |
|
59 | + User::current()->load($oauth->getUserID()); |
|
60 | + } |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * check, if user is authentificated |
|
65 | + * |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function isAuthentificated () : bool { |
|
69 | + return $this->is_authentificated; |
|
70 | + } |
|
71 | + |
|
72 | + public function getOAuth () : OAuth { |
|
73 | + return $this->oauth; |
|
74 | + } |
|
75 | + |
|
76 | + public static function &getInstance () : ApiAuth { |
|
77 | + if (self::$instance == null) { |
|
78 | + self::$instance = new ApiAuth(); |
|
79 | + } |
|
80 | + |
|
81 | + return self::$instance; |
|
82 | + } |
|
83 | 83 | |
84 | 84 | } |
85 | 85 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | protected static $instance = null; |
31 | 31 | |
32 | 32 | protected $oauth = null; |
33 | - protected $is_authentificated = false;//flag, if user is authentificated |
|
33 | + protected $is_authentificated = false; //flag, if user is authentificated |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * ApiAuth constructor. |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | // |
40 | 40 | } |
41 | 41 | |
42 | - public function init () { |
|
42 | + public function init() { |
|
43 | 43 | //check for secret token |
44 | 44 | if (isset($_REQUEST['access_token'])) { |
45 | 45 | $access_token = Validator_String::get($_REQUEST['access_token']); |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return bool |
67 | 67 | */ |
68 | - public function isAuthentificated () : bool { |
|
68 | + public function isAuthentificated() : bool { |
|
69 | 69 | return $this->is_authentificated; |
70 | 70 | } |
71 | 71 | |
72 | - public function getOAuth () : OAuth { |
|
72 | + public function getOAuth() : OAuth { |
|
73 | 73 | return $this->oauth; |
74 | 74 | } |
75 | 75 | |
76 | - public static function &getInstance () : ApiAuth { |
|
76 | + public static function &getInstance() : ApiAuth { |
|
77 | 77 | if (self::$instance == null) { |
78 | 78 | self::$instance = new ApiAuth(); |
79 | 79 | } |
@@ -27,187 +27,187 @@ |
||
27 | 27 | |
28 | 28 | class JSBuilder { |
29 | 29 | |
30 | - protected $content = ""; |
|
30 | + protected $content = ""; |
|
31 | 31 | |
32 | - protected static $benchmark = array(); |
|
32 | + protected static $benchmark = array(); |
|
33 | 33 | |
34 | - public function __construct() { |
|
35 | - // |
|
36 | - } |
|
34 | + public function __construct() { |
|
35 | + // |
|
36 | + } |
|
37 | 37 | |
38 | - public function generateJS (string $style_name, string $media = "ALL", string $position = "header") { |
|
39 | - if (ACTIVATE_BENCHMARK) { |
|
40 | - $start_time = microtime(true); |
|
41 | - } |
|
38 | + public function generateJS (string $style_name, string $media = "ALL", string $position = "header") { |
|
39 | + if (ACTIVATE_BENCHMARK) { |
|
40 | + $start_time = microtime(true); |
|
41 | + } |
|
42 | 42 | |
43 | - //validate values |
|
44 | - $style_name = Validator_Filename::get($style_name); |
|
45 | - $media = strtoupper(Validator_Filename::get($media)); |
|
46 | - $position = strtoupper(Validator_Filename::get($position)); |
|
43 | + //validate values |
|
44 | + $style_name = Validator_Filename::get($style_name); |
|
45 | + $media = strtoupper(Validator_Filename::get($media)); |
|
46 | + $position = strtoupper(Validator_Filename::get($position)); |
|
47 | 47 | |
48 | - $suffix = ""; |
|
48 | + $suffix = ""; |
|
49 | 49 | |
50 | - if ($position !== "HEADER") { |
|
51 | - $suffix = "_" . strtolower($position); |
|
52 | - } |
|
50 | + if ($position !== "HEADER") { |
|
51 | + $suffix = "_" . strtolower($position); |
|
52 | + } |
|
53 | 53 | |
54 | - $js_files = array(); |
|
54 | + $js_files = array(); |
|
55 | 55 | |
56 | - //get css files from style.json |
|
57 | - if (file_exists(STYLE_PATH . $style_name . "/style.json")) { |
|
58 | - $json = json_decode(file_get_contents(STYLE_PATH . $style_name . "/style.json"), true); |
|
56 | + //get css files from style.json |
|
57 | + if (file_exists(STYLE_PATH . $style_name . "/style.json")) { |
|
58 | + $json = json_decode(file_get_contents(STYLE_PATH . $style_name . "/style.json"), true); |
|
59 | 59 | |
60 | - if (isset($json['js' . $suffix]) && is_array($json['js' . $suffix])) { |
|
61 | - foreach ($json['js' . $suffix] as $js_file) { |
|
62 | - $full_path = STYLE_PATH . $style_name . "/" . $js_file; |
|
63 | - $js_files[] = $full_path; |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
60 | + if (isset($json['js' . $suffix]) && is_array($json['js' . $suffix])) { |
|
61 | + foreach ($json['js' . $suffix] as $js_file) { |
|
62 | + $full_path = STYLE_PATH . $style_name . "/" . $js_file; |
|
63 | + $js_files[] = $full_path; |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - //load js files from database |
|
69 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}js_files` WHERE (`style` = :style OR `style` = 'ALL') AND (`media` = :media OR `media` = 'ALL') AND `position` = :position AND `activated` = '1'; ", array( |
|
70 | - 'style' => $style_name, |
|
71 | - 'media' => $media, |
|
72 | - 'position' => $position |
|
73 | - )); |
|
68 | + //load js files from database |
|
69 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}js_files` WHERE (`style` = :style OR `style` = 'ALL') AND (`media` = :media OR `media` = 'ALL') AND `position` = :position AND `activated` = '1'; ", array( |
|
70 | + 'style' => $style_name, |
|
71 | + 'media' => $media, |
|
72 | + 'position' => $position |
|
73 | + )); |
|
74 | 74 | |
75 | - foreach ($rows as $row) { |
|
76 | - $js_files[] = $row['js_file']; |
|
77 | - } |
|
75 | + foreach ($rows as $row) { |
|
76 | + $js_files[] = $row['js_file']; |
|
77 | + } |
|
78 | 78 | |
79 | - $buffer = ""; |
|
79 | + $buffer = ""; |
|
80 | 80 | |
81 | - foreach ($js_files as $js_file) { |
|
82 | - //first check, if file exists |
|
83 | - if (!file_exists($js_file)) { |
|
84 | - if (DEBUG_MODE) { |
|
85 | - echo "Coulnd't found javascript file (style: " . $style_name . "): " . $js_file; |
|
81 | + foreach ($js_files as $js_file) { |
|
82 | + //first check, if file exists |
|
83 | + if (!file_exists($js_file)) { |
|
84 | + if (DEBUG_MODE) { |
|
85 | + echo "Coulnd't found javascript file (style: " . $style_name . "): " . $js_file; |
|
86 | 86 | |
87 | - ob_end_flush(); |
|
88 | - exit; |
|
89 | - } else { |
|
90 | - continue; |
|
91 | - } |
|
92 | - } |
|
87 | + ob_end_flush(); |
|
88 | + exit; |
|
89 | + } else { |
|
90 | + continue; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - //add file content to buffer |
|
95 | - $buffer .= file_get_contents($js_file) . "\n"; |
|
96 | - } |
|
94 | + //add file content to buffer |
|
95 | + $buffer .= file_get_contents($js_file) . "\n"; |
|
96 | + } |
|
97 | 97 | |
98 | - //$code = preg_replace("/\s\s+/", " ", $code); |
|
98 | + //$code = preg_replace("/\s\s+/", " ", $code); |
|
99 | 99 | |
100 | - //https://github.com/matthiasmullie/minify |
|
100 | + //https://github.com/matthiasmullie/minify |
|
101 | 101 | |
102 | - //https://github.com/tchwork/jsqueeze |
|
102 | + //https://github.com/tchwork/jsqueeze |
|
103 | 103 | |
104 | - //https://ourcodeworld.com/articles/read/350/how-to-minify-javascript-and-css-using-php |
|
104 | + //https://ourcodeworld.com/articles/read/350/how-to-minify-javascript-and-css-using-php |
|
105 | 105 | |
106 | - //compress js: https://github.com/tedious/JShrink |
|
106 | + //compress js: https://github.com/tedious/JShrink |
|
107 | 107 | |
108 | - //remove comments |
|
109 | - //$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); |
|
108 | + //remove comments |
|
109 | + //$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); |
|
110 | 110 | |
111 | - // remove space after colons |
|
112 | - //$buffer = str_replace(': ', ':', $buffer); |
|
111 | + // remove space after colons |
|
112 | + //$buffer = str_replace(': ', ':', $buffer); |
|
113 | 113 | |
114 | - //remove whitespace |
|
115 | - //$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer); |
|
114 | + //remove whitespace |
|
115 | + //$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer); |
|
116 | 116 | |
117 | - //replace template variables |
|
118 | - $buffer = str_replace("{STYLE_PATH}", DomainUtils::getBaseURL() . "/styles/" . $style_name . "/", $buffer); |
|
117 | + //replace template variables |
|
118 | + $buffer = str_replace("{STYLE_PATH}", DomainUtils::getBaseURL() . "/styles/" . $style_name . "/", $buffer); |
|
119 | 119 | |
120 | - //compress code |
|
121 | - $jz = new JSqueeze(); |
|
122 | - $buffer = $jz->squeeze( |
|
123 | - $buffer, |
|
124 | - true, // $singleLine |
|
125 | - false, // $keepImportantComments |
|
126 | - false // $specialVarRx |
|
127 | - ); |
|
120 | + //compress code |
|
121 | + $jz = new JSqueeze(); |
|
122 | + $buffer = $jz->squeeze( |
|
123 | + $buffer, |
|
124 | + true, // $singleLine |
|
125 | + false, // $keepImportantComments |
|
126 | + false // $specialVarRx |
|
127 | + ); |
|
128 | 128 | |
129 | - //set flag, if buffer is empty |
|
130 | - $empty_flag = empty($buffer); |
|
129 | + //set flag, if buffer is empty |
|
130 | + $empty_flag = empty($buffer); |
|
131 | 131 | |
132 | - //add comment so md5 hash will change |
|
133 | - $buffer = "/* generated by jsbuilder on " . gmdate("D, d M Y H:i:s", time()) . ", empty flag: " . ($empty_flag ? "true" : "false") . " */" . $buffer; |
|
132 | + //add comment so md5 hash will change |
|
133 | + $buffer = "/* generated by jsbuilder on " . gmdate("D, d M Y H:i:s", time()) . ", empty flag: " . ($empty_flag ? "true" : "false") . " */" . $buffer; |
|
134 | 134 | |
135 | - //create cache directory, if neccessary |
|
136 | - if (!file_exists(CACHE_PATH . "jsbuilder/")) { |
|
137 | - mkdir(CACHE_PATH . "jsbuilder/"); |
|
138 | - } |
|
135 | + //create cache directory, if neccessary |
|
136 | + if (!file_exists(CACHE_PATH . "jsbuilder/")) { |
|
137 | + mkdir(CACHE_PATH . "jsbuilder/"); |
|
138 | + } |
|
139 | 139 | |
140 | - //cache buffer |
|
141 | - file_put_contents($this->getCachePath($style_name, $media, $position), $buffer); |
|
140 | + //cache buffer |
|
141 | + file_put_contents($this->getCachePath($style_name, $media, $position), $buffer); |
|
142 | 142 | |
143 | - Cache::put("jsbuilder", "hash_" . $style_name . "_" . $media . "_" . strtolower($position), md5($buffer)); |
|
144 | - Cache::put("jsbuilder", "meta_" . $style_name . "_" . $media . "_" . strtolower($position), array('empty_flag' => $empty_flag)); |
|
143 | + Cache::put("jsbuilder", "hash_" . $style_name . "_" . $media . "_" . strtolower($position), md5($buffer)); |
|
144 | + Cache::put("jsbuilder", "meta_" . $style_name . "_" . $media . "_" . strtolower($position), array('empty_flag' => $empty_flag)); |
|
145 | 145 | |
146 | - $this->content = $buffer; |
|
146 | + $this->content = $buffer; |
|
147 | 147 | |
148 | - if (ACTIVATE_BENCHMARK) { |
|
149 | - $end_time = microtime(true); |
|
150 | - $exec_time = $end_time - $start_time; |
|
148 | + if (ACTIVATE_BENCHMARK) { |
|
149 | + $end_time = microtime(true); |
|
150 | + $exec_time = $end_time - $start_time; |
|
151 | 151 | |
152 | - self::$benchmark[$style_name . "_" . $media] = $exec_time; |
|
153 | - } |
|
152 | + self::$benchmark[$style_name . "_" . $media] = $exec_time; |
|
153 | + } |
|
154 | 154 | |
155 | - return $buffer; |
|
156 | - } |
|
155 | + return $buffer; |
|
156 | + } |
|
157 | 157 | |
158 | - public function getCachePath (string $style, string $media = "ALL", string $position = "header") : string { |
|
159 | - $position = strtolower($position); |
|
158 | + public function getCachePath (string $style, string $media = "ALL", string $position = "header") : string { |
|
159 | + $position = strtolower($position); |
|
160 | 160 | |
161 | - $md5_filename = md5("js_" . $style . "_" . $media . "_" . $position); |
|
162 | - $js_cache_path = CACHE_PATH . "jsbuilder/" . $md5_filename . ".js"; |
|
161 | + $md5_filename = md5("js_" . $style . "_" . $media . "_" . $position); |
|
162 | + $js_cache_path = CACHE_PATH . "jsbuilder/" . $md5_filename . ".js"; |
|
163 | 163 | |
164 | - return $js_cache_path; |
|
165 | - } |
|
164 | + return $js_cache_path; |
|
165 | + } |
|
166 | 166 | |
167 | - public function existsCache (string $style, string $media = "ALL", string $position = "header") : bool { |
|
168 | - return file_exists($this->getCachePath($style, $media, $position)); |
|
169 | - } |
|
167 | + public function existsCache (string $style, string $media = "ALL", string $position = "header") : bool { |
|
168 | + return file_exists($this->getCachePath($style, $media, $position)); |
|
169 | + } |
|
170 | 170 | |
171 | - public function getHash (string $style, string $media = "ALL", string $position = "header") : string { |
|
172 | - if (!$this->existsCache($style, $media, $position)) { |
|
173 | - //generate cached js file |
|
174 | - $this->generateJS($style, $media, $position); |
|
175 | - } |
|
171 | + public function getHash (string $style, string $media = "ALL", string $position = "header") : string { |
|
172 | + if (!$this->existsCache($style, $media, $position)) { |
|
173 | + //generate cached js file |
|
174 | + $this->generateJS($style, $media, $position); |
|
175 | + } |
|
176 | 176 | |
177 | - if (!Cache::contains("jsbuilder", "hash_" . $style . "_" . $media . "_" . $position)) { |
|
178 | - throw new IllegalStateException("cached js file 'hash_" . $style . "_" . $media . "_" . $position . "' doesnt exists."); |
|
179 | - } |
|
177 | + if (!Cache::contains("jsbuilder", "hash_" . $style . "_" . $media . "_" . $position)) { |
|
178 | + throw new IllegalStateException("cached js file 'hash_" . $style . "_" . $media . "_" . $position . "' doesnt exists."); |
|
179 | + } |
|
180 | 180 | |
181 | - return Cache::get("jsbuilder", "hash_" . $style . "_" . $media . "_" . $position); |
|
182 | - } |
|
181 | + return Cache::get("jsbuilder", "hash_" . $style . "_" . $media . "_" . $position); |
|
182 | + } |
|
183 | 183 | |
184 | - public function isEmpty (string $style, string $media = "ALL", string $position = "header") : bool { |
|
185 | - if (!Cache::contains("jsbuilder", "meta_" . $style . "_" . $media . "_" . $position)) { |
|
186 | - throw new IllegalStateException("cached js file 'meta_" . $style . "_" . $media . "_" . $position . "' doesnt exists."); |
|
187 | - } |
|
184 | + public function isEmpty (string $style, string $media = "ALL", string $position = "header") : bool { |
|
185 | + if (!Cache::contains("jsbuilder", "meta_" . $style . "_" . $media . "_" . $position)) { |
|
186 | + throw new IllegalStateException("cached js file 'meta_" . $style . "_" . $media . "_" . $position . "' doesnt exists."); |
|
187 | + } |
|
188 | 188 | |
189 | - $array = Cache::get("jsbuilder", "meta_" . $style . "_" . $media . "_" . $position); |
|
189 | + $array = Cache::get("jsbuilder", "meta_" . $style . "_" . $media . "_" . $position); |
|
190 | 190 | |
191 | - return $array['empty_flag'] == true; |
|
192 | - } |
|
191 | + return $array['empty_flag'] == true; |
|
192 | + } |
|
193 | 193 | |
194 | - public function load (string $style, string $media = "ALL", string $position = "header") { |
|
195 | - $cache_path = $this->getCachePath($style, $media, $position); |
|
194 | + public function load (string $style, string $media = "ALL", string $position = "header") { |
|
195 | + $cache_path = $this->getCachePath($style, $media, $position); |
|
196 | 196 | |
197 | - if (!$this->existsCache($style, $media, $position)) { |
|
198 | - $this->generateJS($style, $media, $position); |
|
199 | - } else { |
|
200 | - $this->content = file_get_contents($cache_path); |
|
201 | - } |
|
202 | - } |
|
197 | + if (!$this->existsCache($style, $media, $position)) { |
|
198 | + $this->generateJS($style, $media, $position); |
|
199 | + } else { |
|
200 | + $this->content = file_get_contents($cache_path); |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | - public function getBuffer () : string { |
|
205 | - return $this->content; |
|
206 | - } |
|
204 | + public function getBuffer () : string { |
|
205 | + return $this->content; |
|
206 | + } |
|
207 | 207 | |
208 | - public static function listBenchmarks () { |
|
209 | - return self::$benchmark; |
|
210 | - } |
|
208 | + public static function listBenchmarks () { |
|
209 | + return self::$benchmark; |
|
210 | + } |
|
211 | 211 | |
212 | 212 | } |
213 | 213 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | // |
36 | 36 | } |
37 | 37 | |
38 | - public function generateJS (string $style_name, string $media = "ALL", string $position = "header") { |
|
38 | + public function generateJS(string $style_name, string $media = "ALL", string $position = "header") { |
|
39 | 39 | if (ACTIVATE_BENCHMARK) { |
40 | 40 | $start_time = microtime(true); |
41 | 41 | } |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | $jz = new JSqueeze(); |
122 | 122 | $buffer = $jz->squeeze( |
123 | 123 | $buffer, |
124 | - true, // $singleLine |
|
125 | - false, // $keepImportantComments |
|
124 | + true, // $singleLine |
|
125 | + false, // $keepImportantComments |
|
126 | 126 | false // $specialVarRx |
127 | 127 | ); |
128 | 128 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | return $buffer; |
156 | 156 | } |
157 | 157 | |
158 | - public function getCachePath (string $style, string $media = "ALL", string $position = "header") : string { |
|
158 | + public function getCachePath(string $style, string $media = "ALL", string $position = "header") : string { |
|
159 | 159 | $position = strtolower($position); |
160 | 160 | |
161 | 161 | $md5_filename = md5("js_" . $style . "_" . $media . "_" . $position); |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | return $js_cache_path; |
165 | 165 | } |
166 | 166 | |
167 | - public function existsCache (string $style, string $media = "ALL", string $position = "header") : bool { |
|
167 | + public function existsCache(string $style, string $media = "ALL", string $position = "header") : bool { |
|
168 | 168 | return file_exists($this->getCachePath($style, $media, $position)); |
169 | 169 | } |
170 | 170 | |
171 | - public function getHash (string $style, string $media = "ALL", string $position = "header") : string { |
|
171 | + public function getHash(string $style, string $media = "ALL", string $position = "header") : string { |
|
172 | 172 | if (!$this->existsCache($style, $media, $position)) { |
173 | 173 | //generate cached js file |
174 | 174 | $this->generateJS($style, $media, $position); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | return Cache::get("jsbuilder", "hash_" . $style . "_" . $media . "_" . $position); |
182 | 182 | } |
183 | 183 | |
184 | - public function isEmpty (string $style, string $media = "ALL", string $position = "header") : bool { |
|
184 | + public function isEmpty(string $style, string $media = "ALL", string $position = "header") : bool { |
|
185 | 185 | if (!Cache::contains("jsbuilder", "meta_" . $style . "_" . $media . "_" . $position)) { |
186 | 186 | throw new IllegalStateException("cached js file 'meta_" . $style . "_" . $media . "_" . $position . "' doesnt exists."); |
187 | 187 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | return $array['empty_flag'] == true; |
192 | 192 | } |
193 | 193 | |
194 | - public function load (string $style, string $media = "ALL", string $position = "header") { |
|
194 | + public function load(string $style, string $media = "ALL", string $position = "header") { |
|
195 | 195 | $cache_path = $this->getCachePath($style, $media, $position); |
196 | 196 | |
197 | 197 | if (!$this->existsCache($style, $media, $position)) { |
@@ -201,11 +201,11 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - public function getBuffer () : string { |
|
204 | + public function getBuffer() : string { |
|
205 | 205 | return $this->content; |
206 | 206 | } |
207 | 207 | |
208 | - public static function listBenchmarks () { |
|
208 | + public static function listBenchmarks() { |
|
209 | 209 | return self::$benchmark; |
210 | 210 | } |
211 | 211 |
@@ -27,17 +27,17 @@ |
||
27 | 27 | |
28 | 28 | class LogLevel { |
29 | 29 | |
30 | - /** |
|
31 | - * Those are PSR-3 compatible loggin levels |
|
32 | - */ |
|
33 | - const EMERGENCY = 'emergency'; |
|
34 | - const ALERT = 'alert'; |
|
35 | - const CRITICAL = 'critical'; |
|
36 | - const ERROR = 'error'; |
|
37 | - const WARNING = 'warning'; |
|
38 | - const NOTICE = 'notice'; |
|
39 | - const INFO = 'info'; |
|
40 | - const DEBUG = 'debug'; |
|
30 | + /** |
|
31 | + * Those are PSR-3 compatible loggin levels |
|
32 | + */ |
|
33 | + const EMERGENCY = 'emergency'; |
|
34 | + const ALERT = 'alert'; |
|
35 | + const CRITICAL = 'critical'; |
|
36 | + const ERROR = 'error'; |
|
37 | + const WARNING = 'warning'; |
|
38 | + const NOTICE = 'notice'; |
|
39 | + const INFO = 'info'; |
|
40 | + const DEBUG = 'debug'; |
|
41 | 41 | |
42 | 42 | } |
43 | 43 |
@@ -27,46 +27,46 @@ |
||
27 | 27 | |
28 | 28 | class Logger { |
29 | 29 | |
30 | - //instance of logging provider |
|
31 | - protected static $provider = null; |
|
30 | + //instance of logging provider |
|
31 | + protected static $provider = null; |
|
32 | 32 | |
33 | - /** |
|
34 | - * initialize logging provider |
|
35 | - */ |
|
36 | - public static function init () { |
|
37 | - self::getProvider()->init(); |
|
38 | - } |
|
33 | + /** |
|
34 | + * initialize logging provider |
|
35 | + */ |
|
36 | + public static function init () { |
|
37 | + self::getProvider()->init(); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * log message |
|
42 | - */ |
|
43 | - public static function log (string $level, string $message, $args = array()) { |
|
44 | - self::getProvider()->log($level, $message, $args); |
|
45 | - } |
|
40 | + /** |
|
41 | + * log message |
|
42 | + */ |
|
43 | + public static function log (string $level, string $message, $args = array()) { |
|
44 | + self::getProvider()->log($level, $message, $args); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * lazy logging - write logs into file or send it to server |
|
49 | - */ |
|
50 | - public static function send () { |
|
51 | - self::getProvider()->send(); |
|
52 | - } |
|
47 | + /** |
|
48 | + * lazy logging - write logs into file or send it to server |
|
49 | + */ |
|
50 | + public static function send () { |
|
51 | + self::getProvider()->send(); |
|
52 | + } |
|
53 | 53 | |
54 | - public static function &getProvider () : LogProvider { |
|
55 | - if (self::$provider == null) { |
|
56 | - if (defined("LOGGING_ENABLED") && LOGGING_ENABLED == true) { |
|
57 | - //search for loggging provider |
|
58 | - $logging_provider = Settings::get("logging_provider", "EmptyLogProvider"); |
|
54 | + public static function &getProvider () : LogProvider { |
|
55 | + if (self::$provider == null) { |
|
56 | + if (defined("LOGGING_ENABLED") && LOGGING_ENABLED == true) { |
|
57 | + //search for loggging provider |
|
58 | + $logging_provider = Settings::get("logging_provider", "EmptyLogProvider"); |
|
59 | 59 | |
60 | - //create new instance of class in string |
|
61 | - self::$provider = new $logging_provider(); |
|
62 | - } else { |
|
63 | - //use dummy logging provider, which doesnt do anything |
|
64 | - self::$provider = new EmptyLogProvider(); |
|
65 | - } |
|
66 | - } |
|
60 | + //create new instance of class in string |
|
61 | + self::$provider = new $logging_provider(); |
|
62 | + } else { |
|
63 | + //use dummy logging provider, which doesnt do anything |
|
64 | + self::$provider = new EmptyLogProvider(); |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - return self::$provider; |
|
69 | - } |
|
68 | + return self::$provider; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | } |
72 | 72 |
@@ -33,25 +33,25 @@ |
||
33 | 33 | /** |
34 | 34 | * initialize logging provider |
35 | 35 | */ |
36 | - public static function init () { |
|
36 | + public static function init() { |
|
37 | 37 | self::getProvider()->init(); |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * log message |
42 | 42 | */ |
43 | - public static function log (string $level, string $message, $args = array()) { |
|
43 | + public static function log(string $level, string $message, $args = array()) { |
|
44 | 44 | self::getProvider()->log($level, $message, $args); |
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * lazy logging - write logs into file or send it to server |
49 | 49 | */ |
50 | - public static function send () { |
|
50 | + public static function send() { |
|
51 | 51 | self::getProvider()->send(); |
52 | 52 | } |
53 | 53 | |
54 | - public static function &getProvider () : LogProvider { |
|
54 | + public static function &getProvider() : LogProvider { |
|
55 | 55 | if (self::$provider == null) { |
56 | 56 | if (defined("LOGGING_ENABLED") && LOGGING_ENABLED == true) { |
57 | 57 | //search for loggging provider |
@@ -27,20 +27,20 @@ |
||
27 | 27 | |
28 | 28 | interface LogProvider { |
29 | 29 | |
30 | - /** |
|
31 | - * initialize logging provider |
|
32 | - */ |
|
33 | - public function init (); |
|
34 | - |
|
35 | - /** |
|
36 | - * log message |
|
37 | - */ |
|
38 | - public function log (string $level, string $message, $args = array()); |
|
39 | - |
|
40 | - /** |
|
41 | - * lazy logging - after generating page write logs to file or send them to server |
|
42 | - */ |
|
43 | - public function send (); |
|
30 | + /** |
|
31 | + * initialize logging provider |
|
32 | + */ |
|
33 | + public function init (); |
|
34 | + |
|
35 | + /** |
|
36 | + * log message |
|
37 | + */ |
|
38 | + public function log (string $level, string $message, $args = array()); |
|
39 | + |
|
40 | + /** |
|
41 | + * lazy logging - after generating page write logs to file or send them to server |
|
42 | + */ |
|
43 | + public function send (); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 |
@@ -30,17 +30,17 @@ |
||
30 | 30 | /** |
31 | 31 | * initialize logging provider |
32 | 32 | */ |
33 | - public function init (); |
|
33 | + public function init(); |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * log message |
37 | 37 | */ |
38 | - public function log (string $level, string $message, $args = array()); |
|
38 | + public function log(string $level, string $message, $args = array()); |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * lazy logging - after generating page write logs to file or send them to server |
42 | 42 | */ |
43 | - public function send (); |
|
43 | + public function send(); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | require("system/core/init.php"); |
27 | 27 | |
28 | 28 | if (DEBUG_MODE) { |
29 | - @ini_set('display_errors', 1); |
|
29 | + @ini_set('display_errors', 1); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | //throw event |
@@ -44,25 +44,25 @@ discard block |
||
44 | 44 | $method = ""; |
45 | 45 | |
46 | 46 | if (isset($_REQUEST['method']) && !empty($_REQUEST['method'])) { |
47 | - $method = htmlentities($_REQUEST['method']); |
|
47 | + $method = htmlentities($_REQUEST['method']); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | //execute api method, if available |
51 | 51 | if (!empty($method)) { |
52 | - //load api method |
|
53 | - $res = $api_method->loadMethod($method); |
|
54 | - |
|
55 | - if (!$res) { |
|
56 | - //print error message |
|
57 | - header("Content-Type: application/json"); |
|
58 | - echo "{\"error\": \"Api method '" . $method . "' doesnt exists\", \"status\": 400}"; |
|
59 | - } else { |
|
60 | - $api_method->executeApiMethod(); |
|
61 | - } |
|
52 | + //load api method |
|
53 | + $res = $api_method->loadMethod($method); |
|
54 | + |
|
55 | + if (!$res) { |
|
56 | + //print error message |
|
57 | + header("Content-Type: application/json"); |
|
58 | + echo "{\"error\": \"Api method '" . $method . "' doesnt exists\", \"status\": 400}"; |
|
59 | + } else { |
|
60 | + $api_method->executeApiMethod(); |
|
61 | + } |
|
62 | 62 | } else { |
63 | - //print error message |
|
64 | - header("Content-Type: application/json"); |
|
65 | - echo "{\"error\": \"No api method in request, correct call: api.php?method=<API_METHOD>\", \"status\": 400}"; |
|
63 | + //print error message |
|
64 | + header("Content-Type: application/json"); |
|
65 | + echo "{\"error\": \"No api method in request, correct call: api.php?method=<API_METHOD>\", \"status\": 400}"; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $end_time = microtime(true); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | //send logs to server |
75 | 75 | if (LOGGING_ENABLED) { |
76 | - Logger::send(); |
|
76 | + Logger::send(); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 |
@@ -29,17 +29,17 @@ |
||
29 | 29 | |
30 | 30 | class MyFirstTest extends PHPUnit_Framework_TestCase { |
31 | 31 | |
32 | - public function setUp() { |
|
33 | - // |
|
34 | - } |
|
32 | + public function setUp() { |
|
33 | + // |
|
34 | + } |
|
35 | 35 | |
36 | - public function tearDown() { |
|
37 | - // |
|
38 | - } |
|
36 | + public function tearDown() { |
|
37 | + // |
|
38 | + } |
|
39 | 39 | |
40 | - public function testSomething() { |
|
41 | - // |
|
42 | - } |
|
40 | + public function testSomething() { |
|
41 | + // |
|
42 | + } |
|
43 | 43 | |
44 | 44 | } |
45 | 45 |
@@ -111,11 +111,11 @@ |
||
111 | 111 | mt_rand(0, 0xffff), |
112 | 112 | // 16 bits for "time_hi_and_version", |
113 | 113 | // four most significant bits holds version number 4 |
114 | - mt_rand(0, 0x0fff) | 0x4000, |
|
114 | + mt_rand(0, 0x0fff)|0x4000, |
|
115 | 115 | // 16 bits, 8 bits for "clk_seq_hi_res", |
116 | 116 | // 8 bits for "clk_seq_low", |
117 | 117 | // two most significant bits holds zero and one for variant DCE1.1 |
118 | - mt_rand(0, 0x3fff) | 0x8000, |
|
118 | + mt_rand(0, 0x3fff)|0x8000, |
|
119 | 119 | // 48 bits for "node" |
120 | 120 | mt_rand(0, 0xffff), |
121 | 121 | mt_rand(0, 0xffff), |