Skip to content

Commit a2d23b3

Browse files
authored
Merge branch 'master' into Cypht-delay-send-later-scheduled-sending
2 parents dfa6839 + 70559b1 commit a2d23b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+442
-429
lines changed

lib/cache.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ private function prep_out($data, $crypt_key) {
201201
*/
202202
private function configured() {
203203
if (!$this->server || !$this->port) {
204-
Hm_Debug::add(sprintf('%s enabled but no server or port found', $this->type));
204+
Hm_Debug::add(sprintf('%s enabled but no server or port found', $this->type), 'warning');
205205
return false;
206206
}
207207
if (!$this->supported) {
208-
Hm_Debug::add(sprintf('%s enabled but not supported by PHP', $this->type));
208+
Hm_Debug::add(sprintf('%s enabled but not supported by PHP', $this->type), 'warning');
209209
return false;
210210
}
211211
return true;
@@ -399,7 +399,7 @@ public function __construct($config, $session) {
399399
if (!$this->check_redis($config) && !$this->check_memcache($config)) {
400400
$this->check_session($config);
401401
}
402-
Hm_Debug::add(sprintf('CACHE backend using: %s', $this->type));
402+
Hm_Debug::add(sprintf('CACHE backend using: %s', $this->type), 'info');
403403
}
404404

405405
/**
@@ -454,16 +454,16 @@ protected function check_memcache($config) {
454454
protected function log($key, $msg_type) {
455455
switch ($msg_type) {
456456
case 'save':
457-
Hm_Debug::add(sprintf('CACHE: saving "%s" using %s', $key, $this->type));
457+
Hm_Debug::add(sprintf('CACHE: saving "%s" using %s', $key, $this->type), 'info');
458458
break;
459459
case 'hit':
460-
Hm_Debug::add(sprintf('CACHE: hit for "%s" using %s', $key, $this->type));
460+
Hm_Debug::add(sprintf('CACHE: hit for "%s" using %s', $key, $this->type), 'info');
461461
break;
462462
case 'miss':
463-
Hm_Debug::add(sprintf('CACHE: miss for "%s" using %s', $key, $this->type));
463+
Hm_Debug::add(sprintf('CACHE: miss for "%s" using %s', $key, $this->type), 'warning');
464464
break;
465465
case 'del':
466-
Hm_Debug::add(sprintf('CACHE: deleting "%s" using %s', $key, $this->type));
466+
Hm_Debug::add(sprintf('CACHE: deleting "%s" using %s', $key, $this->type), 'info');
467467
break;
468468
}
469469
}
@@ -633,7 +633,7 @@ public function __construct($config, $session) {
633633
*/
634634
public function setup_cache() {
635635
$cache_class = $this->get_cache_class();
636-
Hm_Debug::add(sprintf('Using %s for cache', $cache_class));
636+
Hm_Debug::add(sprintf('Using %s for cache', $cache_class), 'info');
637637
return new $cache_class($this->config, $this->session);
638638
}
639639

lib/config.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public function __construct($config) {
338338
*/
339339
private function new_settings($username) {
340340
$res = Hm_DB::execute($this->dbh, 'insert into hm_user_settings values(?,?)', [$username, '']);
341-
Hm_Debug::add(sprintf("created new row in hm_user_settings for %s", $username));
341+
Hm_Debug::add(sprintf("created new row in hm_user_settings for %s", $username), 'success');
342342
$this->config = [];
343343
return $res ? true : false;
344344
}
@@ -417,7 +417,7 @@ public function save($username, $key) {
417417
$this->connect();
418418
if (Hm_DB::execute($this->dbh, 'select settings from hm_user_settings where username=?', [$username])) {
419419
Hm_DB::execute($this->dbh, 'update hm_user_settings set settings=? where username=?', [$config, $username]);
420-
Hm_Debug::add(sprintf("Saved user data to DB for %s", $username));
420+
Hm_Debug::add(sprintf("Saved user data to DB for %s", $username), 'success');
421421
$res = true;
422422
} else {
423423
$res = Hm_DB::execute($this->dbh, 'insert into hm_user_settings values(?,?)', [$username, $config]);
@@ -518,19 +518,19 @@ function load_user_config_object($config) {
518518
switch ($type) {
519519
case 'DB':
520520
$user_config = new Hm_User_Config_DB($config);
521-
Hm_Debug::add("Using DB user configuration");
521+
Hm_Debug::add("Using DB user configuration", 'info');
522522
break;
523523
case 'custom':
524524
if (class_exists($class)) {
525525
$user_config = new $class($config);
526-
Hm_Debug::add("Using custom user configuration: {$class}");
526+
Hm_Debug::add("Using custom user configuration: {$class}", 'info');
527527
break;
528528
} else {
529529
Hm_Debug::add("User configuration class does not exist: {$class}");
530530
}
531531
default:
532532
$user_config = new Hm_User_Config_File($config);
533-
Hm_Debug::add("Using file based user configuration");
533+
Hm_Debug::add("Using file based user configuration", "info");
534534
break;
535535
}
536536
return $user_config;

lib/db.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static public function execute($dbh, $sql, $args, $type = false, $all = false) {
107107
}
108108
return $sql->fetch(PDO::FETCH_ASSOC);
109109
} catch (PDOException $oops) {
110-
Hm_Msgs::add('ERRDatabase error. Please try again.');
110+
Hm_Msgs::add('Database error. Please try again.', 'danger');
111111
Hm_Debug::add($oops->getMessage());
112112
return false;
113113
}
@@ -146,11 +146,11 @@ static public function connect($site_config) {
146146
self::$dbh[$key] = new PDO($dsn, self::$config['db_user'], self::$config['db_pass']);
147147
self::$dbh[$key]->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
148148
self::$dbh[$key]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
149-
Hm_Debug::add(sprintf('Connecting to dsn: %s', $dsn));
149+
Hm_Debug::add(sprintf('Connecting to dsn: %s', $dsn), "info");
150150
return self::$dbh[$key];
151151
} catch (Exception $oops) {
152152
Hm_Debug::add($oops->getMessage());
153-
Hm_Msgs::add('ERRUnable to connect to the database. Please check your configuration settings and try again.');
153+
Hm_Msgs::add('Unable to connect to the database. Please check your configuration settings and try again.', 'danger');
154154
self::$dbh[$key] = false;
155155
return false;
156156
}

lib/dispatch.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function redirect_to_url($mod_exec) {
5454
* @return void
5555
*/
5656
private function forward_messages($session, $request) {
57-
$msgs = Hm_Msgs::get();
57+
$msgs = Hm_Msgs::getRaw();
5858
if (!empty($msgs)) {
5959
$session->secure_cookie($request, 'hm_msgs', base64_encode(json_encode($msgs)));
6060
}
@@ -114,7 +114,7 @@ public function unpack_messages($request, $session) {
114114
if (!empty($request->cookie['hm_msgs'])) {
115115
$msgs = @json_decode(base64_decode($request->cookie['hm_msgs']), true);
116116
if (is_array($msgs)) {
117-
array_walk($msgs, function($v) { Hm_Msgs::add($v); });
117+
array_walk($msgs, function($v) { Hm_Msgs::add($v['text'], $v['type']); });
118118
}
119119
$session->delete_cookie($request, 'hm_msgs');
120120
return true;
@@ -130,12 +130,12 @@ public function unpack_messages($request, $session) {
130130
*/
131131
static public function page_redirect($url, $status = false) {
132132
if (DEBUG_MODE) {
133-
Hm_Debug::add(sprintf('Redirecting to %s', $url));
133+
Hm_Debug::add(sprintf('Redirecting to %s', $url), 'info');
134134
Hm_Debug::load_page_stats();
135135
Hm_Debug::show();
136136
}
137137
if ($status == 303) {
138-
Hm_Debug::add('Redirect loop found');
138+
Hm_Debug::add('Redirect loop found', 'warning');
139139
Hm_Functions::cease('Redirect loop discovered');
140140
}
141141
Hm_Functions::header('HTTP/1.1 303 Found');
@@ -197,7 +197,7 @@ private function load_site_lib() {
197197
return;
198198
}
199199
if (is_readable(APP_PATH.'modules/site/lib.php')) {
200-
Hm_Debug::add('Including site module set lib.php');
200+
Hm_Debug::add('Including site module set lib.php', 'info');
201201
require APP_PATH.'modules/site/lib.php';
202202
}
203203
}
@@ -337,7 +337,7 @@ public function get_page($filters, $request) {
337337
$this->page = 'home';
338338
}
339339
$this->module_exec->page = $this->page;
340-
Hm_Debug::add('Page ID: '.$this->page);
340+
Hm_Debug::add('Page ID: '.$this->page, 'info');
341341
}
342342

343343
/**

lib/environment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function load($file = '.env') {
2626
}
2727
$envFile = static::get('CYPHT_DOTENV');
2828
if (!file_exists($envFile)) {
29-
Hm_Msgs::add('ERR.env file not found at: "' . $envFile . '"');
29+
Hm_Msgs::add('.env file not found at: "' . $envFile . '"', 'danger');
3030
return;
3131
}
3232
$dotenvLoader->load($envFile);

lib/format.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Hm_Format_JSON extends HM_Format {
4545
* @return string encoded data to be sent to the browser
4646
*/
4747
public function content($output, $allowed_output) {
48-
$output['router_user_msgs'] = Hm_Msgs::get();
48+
$output['router_user_msgs'] = Hm_Msgs::getRaw();
4949
$output = $this->filter_all_output($output, $allowed_output);
5050
if ($this->config->get('encrypt_ajax_requests', false)) {
5151
$output = ['payload' => Hm_Crypt_Base::ciphertext(json_encode($output, JSON_FORCE_OBJECT), Hm_Request_Key::generate())];

lib/framework.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Hm_Functions {
7272
*/
7373
public static function setcookie($name, $value, $lifetime = 0, $path = '', $domain = '', $secure = false, $html_only = false, $same_site = 'Strict') {
7474
$prefix = ($lifetime != 0 && $lifetime < time()) ? 'Deleting' : 'Setting';
75-
Hm_Debug::add(sprintf('%s cookie: name: %s, lifetime: %s, path: %s, domain: %s, secure: %s, html_only %s',$prefix, $name, $lifetime, $path, $domain, $secure, $html_only));
75+
Hm_Debug::add(sprintf('%s cookie: name: %s, lifetime: %s, path: %s, domain: %s, secure: %s, html_only %s',$prefix, $name, $lifetime, $path, $domain, $secure, $html_only), 'info');
7676
return setcookie($name, $value, [
7777
'expires' => $lifetime,
7878
'path' => $path,
@@ -140,7 +140,7 @@ public static function c_init() {
140140
if (extension_loaded('curl')) {
141141
return curl_init();
142142
} else {
143-
Hm_Msgs::add('ERRPlease enable the cURL extension.');
143+
Hm_Msgs::add('Please enable the cURL extension.', 'warning');
144144
return false;
145145
}
146146
}
@@ -152,7 +152,7 @@ public static function c_exec($handle) {
152152
$response = curl_exec($handle);
153153
if ($response === false) {
154154
$error = curl_error($handle);
155-
Hm_Msgs::add('ERRcURL error: '.$error);
155+
Hm_Msgs::add('cURL error: '.$error, 'danger');
156156
}
157157
return $response;
158158
}
@@ -265,7 +265,7 @@ function hm_exists($name) {
265265
$caller = array_shift($bt);
266266
$module = hm_get_module_from_path($caller['file']);
267267
if (function_exists($name)) {
268-
Hm_Debug::add(sprintf('Function in %s replaced: %s', $module, $name));
268+
Hm_Debug::add(sprintf('Function in %s replaced: %s', $module, $name), 'warning');
269269
return true;
270270
}
271271
return false;

lib/module.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function get($name, $default = NULL, $typed = true) {
146146
$val = $this->output[$name];
147147
if (!is_null($default) && $typed) {
148148
if (gettype($default) != gettype($val)) {
149-
Hm_Debug::add(sprintf('TYPE CONVERSION: %s to %s for %s', gettype($val), gettype($default), $name));
149+
Hm_Debug::add(sprintf('TYPE CONVERSION: %s to %s for %s', gettype($val), gettype($default), $name), 'info');
150150
settype($val, gettype($default));
151151
}
152152
}
@@ -439,7 +439,7 @@ public function module_is_supported($name) {
439439
}
440440

441441
public function save_hm_msgs() {
442-
$msgs = Hm_Msgs::get();
442+
$msgs = Hm_Msgs::getRaw();
443443
if (!empty($msgs)) {
444444
Hm_Msgs::flush();
445445
$this->session->secure_cookie($this->request, 'hm_msgs', base64_encode(json_encode($msgs)));
@@ -499,7 +499,7 @@ public function trans($string) {
499499
}
500500
}
501501
else {
502-
Hm_Debug::add(sprintf('TRANSLATION NOT FOUND :%s:', $string));
502+
Hm_Debug::add(sprintf('TRANSLATION NOT FOUND :%s:', $string), 'warning');
503503
}
504504
return str_replace('\n', '<br />', strip_tags($string));
505505
}

lib/modules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public static function add($page, $module, $logged_in, $marker=false, $placement
179179
self::add_page($page);
180180

181181
if (array_key_exists($module, self::$module_list[$page])) {
182-
Hm_Debug::add(sprintf("Already registered module for %s re-attempted: %s", $page, $module));
182+
Hm_Debug::add(sprintf("Already registered module for %s re-attempted: %s", $page, $module), 'warning');
183183
return true;
184184
}
185185
$source === false ? $source = self::$source : false;

lib/output.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ trait Hm_List {
7373
* @param string $string message to add
7474
* @return void
7575
*/
76-
public static function add($string) {
77-
self::$msgs[] = self::str($string, false);
76+
public static function add($string, $type = 'success') {
77+
self::$msgs[] = ['type' => $type, 'text' => self::str($string, false)];
7878
}
7979

8080
/**
8181
* Return all messages
8282
* @return array all messages
8383
*/
84-
public static function get() {
84+
public static function getRaw() {
8585
return self::$msgs;
8686
}
8787

@@ -110,12 +110,21 @@ public static function str($mixed, $return_type = true) {
110110
return $str;
111111
}
112112

113+
public static function get() {
114+
return array_map(function ($msg) {
115+
return $msg['text'];
116+
}, self::$msgs);
117+
}
118+
113119
/**
114120
* Log all messages
115121
* @return bool
116122
*/
117123
public static function show() {
118-
return Hm_Functions::error_log(print_r(self::$msgs, true));
124+
$msgs = array_map(function ($msg) {
125+
return strtoupper($msg['type']) . ': ' . $msg['text'];
126+
}, self::$msgs);
127+
return Hm_Functions::error_log(print_r($msgs, true));
119128
}
120129
}
121130

@@ -129,18 +138,27 @@ class Hm_Msgs { use Hm_List; }
129138
*/
130139
class Hm_Debug {
131140

132-
use Hm_List;
141+
use Hm_List {
142+
add as protected self_add;
143+
}
144+
145+
/**
146+
* @override
147+
*/
148+
public static function add($string, $type = 'danger') {
149+
self::self_add($string, $type);
150+
}
133151

134152
/**
135153
* Add page execution stats to the Hm_Debug list
136154
* @return void
137155
*/
138156
public static function load_page_stats() {
139-
self::add(sprintf("PHP version %s", phpversion()));
140-
self::add(sprintf("Zend version %s", zend_version()));
141-
self::add(sprintf("Peak Memory: %d", (memory_get_peak_usage(true)/1024)));
142-
self::add(sprintf("PID: %d", getmypid()));
143-
self::add(sprintf("Included files: %d", count(get_included_files())));
157+
self::add(sprintf("PHP version %s", phpversion()), 'info');
158+
self::add(sprintf("Zend version %s", zend_version()), 'info');
159+
self::add(sprintf("Peak Memory: %d", (memory_get_peak_usage(true)/1024)), 'info');
160+
self::add(sprintf("PID: %d", getmypid()), 'info');
161+
self::add(sprintf("Included files: %d", count(get_included_files())), 'info');
144162
}
145163
}
146164

0 commit comments

Comments
 (0)