Skip to content

Commit 71c63da

Browse files
committed
Code style fixes
1 parent bc26253 commit 71c63da

12 files changed

+160
-146
lines changed

lib/module.class.php

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public function createParamsString($data, $name)
173173
return $res;
174174
}
175175
// --------------------------------------------------------------------
176+
176177
/**
177178
* Restoring module data from query string
178179
*
@@ -251,13 +252,13 @@ public function restoreParams()
251252

252253
/**
253254
* Restoring module data from query string (old version)
254-
* @deprecated
255255
* @return void
256+
* @deprecated
256257
*/
257258
public function restoreParamsOld()
258259
{
259-
$md=gr('md'); // query param - current module
260-
$pd=gr('pd'); // query param - all params
260+
$md = gr('md'); // query param - current module
261+
$pd = gr('pd'); // query param - all params
261262

262263
$global_params = array();
263264

@@ -323,7 +324,7 @@ public function saveParentParams()
323324
public function checkInstalled()
324325
{
325326

326-
$flag_filename = ROOT.'cms/modules_installed/'.$this->name . '.installed';
327+
$flag_filename = ROOT . 'cms/modules_installed/' . $this->name . '.installed';
327328
if (!file_exists($flag_filename)) {
328329
$this->install();
329330
} else {
@@ -412,13 +413,13 @@ public function install($parent_name = "")
412413
} else {
413414
SQLUpdate("project_modules", $rec);
414415
}
415-
SQLExec("DELETE FROM project_modules WHERE NAME = '".$this->name."' AND ID!=".$rec["ID"]);
416+
SQLExec("DELETE FROM project_modules WHERE NAME = '" . $this->name . "' AND ID!=" . $rec["ID"]);
416417

417-
if (!is_dir(ROOT.'cms/modules_installed')) {
418+
if (!is_dir(ROOT . 'cms/modules_installed')) {
418419
umask(0);
419-
mkdir(ROOT.'cms/modules_installed',0777);
420+
mkdir(ROOT . 'cms/modules_installed', 0777);
420421
}
421-
$flag_filename = ROOT.'cms/modules_installed/'.$this->name . '.installed';
422+
$flag_filename = ROOT . 'cms/modules_installed/' . $this->name . '.installed';
422423
if (!file_exists($flag_filename)) SaveFile($flag_filename, date("H:m d.M.Y"));
423424
}
424425

@@ -445,12 +446,13 @@ public function uninstall()
445446
SQLExec($sqlQuery);
446447
}
447448

448-
$flag_filename = ROOT.'cms/modules_installed/'.$this->name . '.installed';
449+
$flag_filename = ROOT . 'cms/modules_installed/' . $this->name . '.installed';
449450
if (file_exists($flag_filename)) unlink($flag_filename);
450451
}
451452

452453

453454
// --------------------------------------------------------------------
455+
454456
/**
455457
* Module data installation
456458
*
@@ -528,14 +530,14 @@ public function dbInstall($data)
528530
$definition = str_replace('`', '', $definition);
529531
$sql = "ALTER TABLE $table ADD $definition;";
530532
SQLExec($sql);
531-
SQLExec("FLUSH TABLES ".$table.";");
533+
SQLExec("FLUSH TABLES " . $table . ";");
532534
$to_optimize[] = $table;
533535
}
534536
} elseif (!isset($tbl_fields[$table][$field])) {
535537
// new field
536538
$sql = "ALTER TABLE $table ADD $definition;";
537539
SQLExec($sql);
538-
SQLExec("FLUSH TABLES ".$table.";");
540+
SQLExec("FLUSH TABLES " . $table . ";");
539541
}
540542
}
541543

@@ -599,13 +601,14 @@ public function redirect($url)
599601
global $session;
600602

601603
$new_url = $this->makeRealURL($url);
602-
if (isset($this->owner) && $this->owner->name=='panel' && preg_match('/nf\.php/',$new_url)) {
603-
$new_url = str_replace('nf.php','admin.php',$new_url);
604+
if (isset($this->owner) && $this->owner->name == 'panel' && preg_match('/nf\.php/', $new_url)) {
605+
$new_url = str_replace('nf.php', 'admin.php', $new_url);
604606
}
605607

606608
$session->save();
607609

608-
if ($_GET['part_load']) {
610+
$part_load = gr('part_load');
611+
if ($part_load) {
609612
$res = array();
610613
$res['CONTENT'] = '';
611614
$res['NEED_RELOAD'] = 1;
@@ -723,7 +726,7 @@ public function dynamic($content)
723726
*/
724727
public function parseLinks($result)
725728
{
726-
$md=gr('md');
729+
$md = gr('md');
727730
if (!isset($_SERVER['PHP_SELF'])) {
728731
global $PHP_SELF;
729732
$_SERVER['PHP_SELF'] = $PHP_SELF;
@@ -843,55 +846,55 @@ public function codeParams($in)
843846

844847
return $res_str;
845848
}
846-
847-
public function sendNotification($str, $type = 'default')
849+
850+
public function sendNotification($str, $type = 'default')
848851
{
849852

850853
if (!SQLTableExists('module_notifications')) {
851-
return json_encode(array('status'=>false));
852-
}
853-
854-
if($type != 'info' && $type != 'danger' && $type != 'warning' && $type != 'success' && $type != 'default') {
855-
$type = 'default';
856-
}
857-
858-
$rec["ADDED"] = date('Y-m-d H:i:s');
859-
$rec["TYPE"] = $type;
860-
$rec["MODULE_NAME"] = $this->name;
861-
$rec["MESSAGE"] = htmlspecialchars(strip_tags($str));
862-
863-
if(SQLSelectOne("SELECT COUNT(*) AS TOTAL_UNREAD FROM `module_notifications` WHERE `MODULE_NAME` = '".$rec["MODULE_NAME"]."' AND `IS_READ` = '0'")['TOTAL_UNREAD'] > 10) {
864-
return json_encode(array('status' => false, 'error' => 'More than 10 notifications in the unread status.'));
865-
}
866-
867-
$ifExist = SQLSelectOne("SELECT ID FROM `module_notifications` WHERE `MESSAGE` = '".DBSafe($rec['MESSAGE'])."' AND TYPE='".DBSafe($rec['TYPE'])."' AND `IS_READ` = '0'");
868-
if(!empty($ifExist) && is_array($ifExist)) {
869-
return json_encode(array('status' => false, 'error' => 'Notification already exists. ID: '.$ifExist['ID'], 'id' => $ifExist['ID']));
870-
}
871-
872-
$rec["ID"] = SQLInsert("module_notifications", $rec);
873-
874-
return json_encode(array('status' => true, 'id' => $rec["ID"]));
854+
return json_encode(array('status' => false));
855+
}
856+
857+
if ($type != 'info' && $type != 'danger' && $type != 'warning' && $type != 'success' && $type != 'default') {
858+
$type = 'default';
859+
}
860+
861+
$rec["ADDED"] = date('Y-m-d H:i:s');
862+
$rec["TYPE"] = $type;
863+
$rec["MODULE_NAME"] = $this->name;
864+
$rec["MESSAGE"] = htmlspecialchars(strip_tags($str));
865+
866+
if (SQLSelectOne("SELECT COUNT(*) AS TOTAL_UNREAD FROM `module_notifications` WHERE `MODULE_NAME` = '" . $rec["MODULE_NAME"] . "' AND `IS_READ` = '0'")['TOTAL_UNREAD'] > 10) {
867+
return json_encode(array('status' => false, 'error' => 'More than 10 notifications in the unread status.'));
868+
}
869+
870+
$ifExist = SQLSelectOne("SELECT ID FROM `module_notifications` WHERE `MESSAGE` = '" . DBSafe($rec['MESSAGE']) . "' AND TYPE='" . DBSafe($rec['TYPE']) . "' AND `IS_READ` = '0'");
871+
if (!empty($ifExist) && is_array($ifExist)) {
872+
return json_encode(array('status' => false, 'error' => 'Notification already exists. ID: ' . $ifExist['ID'], 'id' => $ifExist['ID']));
873+
}
874+
875+
$rec["ID"] = SQLInsert("module_notifications", $rec);
876+
877+
return json_encode(array('status' => true, 'id' => $rec["ID"]));
875878

876879
}
877-
878-
public function readNotification($notification_id)
880+
881+
public function readNotification($notification_id)
879882
{
880883

881884
if (!SQLTableExists('module_notifications')) {
882-
return json_encode(array('status'=>false));
883-
}
884-
885-
$rec["ID"] = $notification_id;
886-
$rec["IS_READ"] = 1;
887-
888-
if(empty(SQLSelectOne("SELECT ID FROM `module_notifications` WHERE `ID` = '".$rec["ID"]."' AND `IS_READ` = '0'")['ID'])) {
889-
return json_encode(array('status' => false, 'error' => 'No such noty found'));
890-
}
891-
892-
SQLUpdate("module_notifications", $rec);
893-
894-
return json_encode(array('status' => true));
885+
return json_encode(array('status' => false));
886+
}
887+
888+
$rec["ID"] = $notification_id;
889+
$rec["IS_READ"] = 1;
890+
891+
if (empty(SQLSelectOne("SELECT ID FROM `module_notifications` WHERE `ID` = '" . $rec["ID"] . "' AND `IS_READ` = '0'")['ID'])) {
892+
return json_encode(array('status' => false, 'error' => 'No such noty found'));
893+
}
894+
895+
SQLUpdate("module_notifications", $rec);
896+
897+
return json_encode(array('status' => true));
895898

896899
}
897900
}

lib/mysqli.class.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function Ping()
267267
*/
268268
public function Update($table, $data, $ndx = "ID")
269269
{
270-
if (is_array($ndx)) $ndx='ID';
270+
if (is_array($ndx)) $ndx = 'ID';
271271
$qry = "UPDATE `$table` SET ";
272272
$qry_fields = array();
273273
foreach ($data as $field => $value) {
@@ -284,7 +284,7 @@ public function Update($table, $data, $ndx = "ID")
284284
}
285285
$qry .= " WHERE $ndx = '" . $data[$ndx] . "'";
286286
if (gr('debug_qry')) {
287-
dprint($qry,false);
287+
dprint($qry, false);
288288
}
289289
if (!$this->Exec($qry)) {
290290
$this->Error($qry);
@@ -351,8 +351,10 @@ public function DbSafe($str)
351351
echo "Database is not connected!";
352352
exit;
353353
}
354-
$str = mysqli_real_escape_string($this->dbh, $str);
355-
$str = str_replace("%", "\%", $str);
354+
if ($str != '') {
355+
$str = mysqli_real_escape_string($this->dbh, $str);
356+
$str = str_replace("%", "\%", $str);
357+
}
356358
return $str;
357359
}
358360

modules/classes/classes.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ function updateTree_classes($parent_id=0, $parent_list='') {
594594
$res=SQLSelect("SELECT * FROM $table WHERE PARENT_ID='$parent_id'");
595595
$total=count($res);
596596
for($i=0;$i<$total;$i++) {
597-
if ($parent_list[0]) {
597+
if (isset($parent_list[0])) {
598598
$res[$i]['PARENT_LIST']=implode(',', $parent_list);
599599
} else {
600600
$res[$i]['PARENT_LIST']='0';
@@ -603,7 +603,7 @@ function updateTree_classes($parent_id=0, $parent_list='') {
603603
$tmp_parent=$parent_list;
604604
$tmp_parent[]=$res[$i]['ID'];
605605
$sub_this=$this->updateTree_classes($res[$i]['ID'], $tmp_parent);
606-
if ($sub_this[0]) {
606+
if (isset($sub_this[0])) {
607607
$res[$i]['SUB_LIST']=implode(',', $sub_this);
608608
} else {
609609
$res[$i]['SUB_LIST']=$res[$i]['ID'];

modules/classes/classes_edit.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
}
8080
if (is_array($rec)) {
8181
foreach($rec as $k=>$v) {
82-
if (!is_array($v)) {
82+
if (!is_array($v) && $v) {
8383
$rec[$k]=htmlspecialchars($v);
8484
}
8585
}

modules/commands/commands.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ function delete_commands($id)
612612
$rec = SQLSelectOne("SELECT * FROM commands WHERE ID='$id'");
613613
// some action for related tables
614614
$tmp = SQLSelectOne("SELECT ID FROM commands WHERE PARENT_ID=" . $rec['ID']);
615-
if ($tmp['ID']) {
615+
if (isset($tmp['ID'])) {
616616
return;
617617
}
618618
SQLExec("DELETE FROM security_rules WHERE OBJECT_TYPE='menu' AND OBJECT_ID=" . (int)$rec['ID']);
@@ -656,7 +656,7 @@ function updateTree_commands($parent_id = 0, $parent_list = '')
656656
$res = SQLSelect("SELECT * FROM $table WHERE PARENT_ID='$parent_id'");
657657
$total = count($res);
658658
for ($i = 0; $i < $total; $i++) {
659-
if ($parent_list[0]) {
659+
if (isset($parent_list[0])) {
660660
$res[$i]['PARENT_LIST'] = implode(',', $parent_list);
661661
} else {
662662
$res[$i]['PARENT_LIST'] = '0';
@@ -665,7 +665,7 @@ function updateTree_commands($parent_id = 0, $parent_list = '')
665665
$tmp_parent = $parent_list;
666666
$tmp_parent[] = $res[$i]['ID'];
667667
$sub_this = $this->updateTree_commands($res[$i]['ID'], $tmp_parent);
668-
if ($sub_this[0]) {
668+
if (isset($sub_this[0])) {
669669
$res[$i]['SUB_LIST'] = implode(',', $sub_this);
670670
} else {
671671
$res[$i]['SUB_LIST'] = $res[$i]['ID'];
@@ -853,7 +853,7 @@ function processMenuElements(&$res)
853853

854854
}
855855

856-
if (preg_match('/<script/is', $res[$i]['DATA']) || preg_match('/\[#module/is', $res[$i]['DATA'])) {
856+
if (isset($res[$i]['DATA']) && (preg_match('/<script/is', $res[$i]['DATA']) || preg_match('/\[#module/is', $res[$i]['DATA']))) {
857857
$res[$i]['AUTO_UPDATE'] = 0;
858858
} elseif (!$res[$i]['AUTO_UPDATE'] && $res[$i]['TYPE'] != 'object' && (!defined('DISABLE_WEBSOCKETS') || DISABLE_WEBSOCKETS == 0)) {
859859
$res[$i]['AUTO_UPDATE'] = 10;

modules/commands/commands_edit.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
}
180180
$total = count($parents);
181181
for ($i = 0; $i < $total; $i++) {
182-
if ($titles[$parents[$i]['PARENT_ID']]) {
182+
if (isset($titles[$parents[$i]['PARENT_ID']])) {
183183
$parents[$i]['TITLE'] = $titles[$parents[$i]['PARENT_ID']] . ' &gt; ' . $parents[$i]['TITLE'];
184184
}
185185
}

modules/commands/commands_search.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
$menu_loaded = 1;
1111

12-
if ($this->pda) {
13-
$out['PDA'] = 1;
12+
if (isset($this->pda)) {
13+
$out['PDA'] = $this->pda;
1414
}
1515

1616
global $session;

modules/objects/objects_edit.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$rec = SQLSelectOne("SELECT * FROM $table_name WHERE ID='$id'");
1212

1313
$device_rec = SQLSelectOne("SELECT * FROM devices WHERE LINKED_OBJECT='" . $rec['TITLE'] . "'");
14-
if ($device_rec['ID']) {
14+
if (isset($device_rec['ID'])) {
1515
$out['DEVICE_ID'] = $device_rec['ID'];
1616
$out['DEVICE_TITLE'] = $device_rec['TITLE'];
1717
}

modules/patterns/patterns_edit.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
}
116116

117117

118-
$rec['PARENT_ID'] = gr('parent_id','int');
118+
$rec['PARENT_ID'] = gr('parent_id', 'int');
119119

120120
if ($rec['PATTERN_TYPE'] == 1) {
121121
$rec['PARENT_ID'] = 0;
@@ -145,7 +145,7 @@
145145

146146
if (is_array($rec)) {
147147
foreach ($rec as $k => $v) {
148-
if (!is_array($v)) {
148+
if (!is_array($v) && $v) {
149149
$rec[$k] = htmlspecialchars($v);
150150
}
151151
}

0 commit comments

Comments
 (0)