Skip to content

Commit 1167ca4

Browse files
committed
Scripts auto-link fix
Remove auto-linking for scripts
1 parent bbbec97 commit 1167ca4

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

Diff for: modules/scripts/scripts.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ function checkScheduledScripts()
449449

450450
function propertySetHandle($object, $property, $value)
451451
{
452-
$scripts = SQLSelect("SELECT ID FROM scripts WHERE LINKED_OBJECT LIKE '" . DBSafe($object) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "'");
452+
$scripts = SQLSelect("SELECT ID FROM scripts WHERE AUTO_LINK=1 AND LINKED_OBJECT LIKE '" . DBSafe($object) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "'");
453453
$total = count($scripts);
454454
if ($total) {
455455
for ($i = 0; $i < $total; $i++) {

Diff for: modules/scripts/scripts_edit.inc.php

+50-50
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
$table_name = 'scripts';
99
$rec = SQLSelectOne("SELECT * FROM $table_name WHERE ID='$id'");
1010

11-
if(defined('SETTINGS_CODEEDITOR_TURNONSETTINGS')) {
12-
$out['SETTINGS_CODEEDITOR_TURNONSETTINGS'] = SETTINGS_CODEEDITOR_TURNONSETTINGS;
13-
$out['SETTINGS_CODEEDITOR_UPTOLINE'] = SETTINGS_CODEEDITOR_UPTOLINE;
14-
$out['SETTINGS_CODEEDITOR_SHOWERROR'] = SETTINGS_CODEEDITOR_SHOWERROR;
11+
if (defined('SETTINGS_CODEEDITOR_TURNONSETTINGS')) {
12+
$out['SETTINGS_CODEEDITOR_TURNONSETTINGS'] = SETTINGS_CODEEDITOR_TURNONSETTINGS;
13+
$out['SETTINGS_CODEEDITOR_UPTOLINE'] = SETTINGS_CODEEDITOR_UPTOLINE;
14+
$out['SETTINGS_CODEEDITOR_SHOWERROR'] = SETTINGS_CODEEDITOR_SHOWERROR;
1515
}
1616
if ($this->mode == 'update') {
1717

@@ -43,37 +43,37 @@
4343

4444
//echo $code;exit;
4545

46-
$old_code=$rec['CODE'];
46+
$old_code = $rec['CODE'];
4747
$rec['CODE'] = $code;
48-
48+
4949
if ($rec['CODE'] != '') {
5050
//echo $content;
51-
51+
5252
$errors = php_syntax_error($rec['CODE']);
5353

5454
if ($errors) {
55-
$out['ERR_LINE'] = preg_replace('/[^0-9]/', '', substr(stristr($errors, 'php on line '), 0, 18))-2;
55+
$out['ERR_LINE'] = preg_replace('/[^0-9]/', '', substr(stristr($errors, 'php on line '), 0, 18)) - 2;
5656
$out['ERR_CODE'] = 1;
57-
$errorStr = explode('Parse error: ', htmlspecialchars(strip_tags(nl2br($errors))));
58-
$errorStr = explode('Errors parsing', $errorStr[1]);
59-
$errorStr = explode(' in ', $errorStr[0]);
57+
$errorStr = explode('Parse error: ', htmlspecialchars(strip_tags(nl2br($errors))));
58+
$errorStr = explode('Errors parsing', $errorStr[1]);
59+
$errorStr = explode(' in ', $errorStr[0]);
6060
if ($errorStr[0]) {
6161
$out['ERRORS'] = $errorStr[0];
62-
$out['ERR_FULL'] = $errorStr[0].' '.$errorStr[1];
62+
$out['ERR_FULL'] = $errorStr[0] . ' ' . $errorStr[1];
6363
} else {
6464
$out['ERRORS'] = $errors;
6565
$out['ERR_FULL'] = nl2br($errors);
6666
}
67-
$out['ERR_OLD_CODE'] = $old_code;
67+
$out['ERR_OLD_CODE'] = $old_code;
6868
$ok = 0;
6969
}
7070
}
7171

7272
global $run_periodically;
7373
global $run_days;
7474
global $run_minutes;
75-
global $run_hours;
76-
75+
global $run_hours;
76+
7777
if ($run_periodically && isset($run_days)) {
7878
$rec['RUN_PERIODICALLY'] = (int)$run_periodically;
7979
$rec['RUN_DAYS'] = @implode(',', $run_days);
@@ -85,54 +85,54 @@
8585
$rec['RUN_PERIODICALLY'] = 0;
8686
$rec['RUN_DAYS'] = false;
8787
$rec['RUN_TIME'] = false;
88-
}
89-
88+
}
89+
9090
//$rec['EXECUTED']='0000-00-00 00:00:00';
9191
unset($rec['EXECUTED']);
9292

9393
global $auto_link;
94-
$rec['AUTO_LINK']=(int)$auto_link;
94+
$rec['AUTO_LINK'] = (int)$auto_link;
9595

9696
//UPDATING RECORD
9797
if ($ok) {
9898
$linked_object = '';
9999
$linked_property = '';
100100

101-
if (!isset($_REQUEST['auto_link']) || $_REQUEST['auto_link']==1) {
102-
if (preg_match('/^if(.+?){/is', $rec['CODE'], $m)) {
103-
$conditions = trim($m[1], '()');
104-
if (preg_match('/getglobal\(["\'](\w+)\.(\w+)["\']\)/is', $conditions, $m2)) {
105-
$linked_object=$m2[1];
106-
$linked_property=$m2[2];
107-
} elseif (preg_match('/gg\(["\'](\w+)\.(\w+)["\']\)/is', $conditions, $m2)) {
108-
$linked_object=$m2[1];
109-
$linked_property=$m2[2];
110-
} elseif (preg_match('/timeis/is', $conditions) ||
111-
preg_match('/timebefore/is', $conditions) ||
112-
preg_match('/timeafter/is', $conditions) ||
113-
preg_match('/timebetween/is', $conditions)) {
114-
$linked_object='ClockChime';
115-
$linked_property='time';
116-
}
101+
if (preg_match('/^if(.+?){/is', $rec['CODE'], $m)) {
102+
$conditions = trim($m[1], '()');
103+
if (preg_match('/getglobal\(["\'](\w+)\.(\w+)["\']\)/is', $conditions, $m2)) {
104+
$linked_object = $m2[1];
105+
$linked_property = $m2[2];
106+
} elseif (preg_match('/gg\(["\'](\w+)\.(\w+)["\']\)/is', $conditions, $m2)) {
107+
$linked_object = $m2[1];
108+
$linked_property = $m2[2];
109+
} elseif (preg_match('/timeis/is', $conditions) ||
110+
preg_match('/timebefore/is', $conditions) ||
111+
preg_match('/timeafter/is', $conditions) ||
112+
preg_match('/timebetween/is', $conditions)) {
113+
$linked_object = 'ClockChime';
114+
$linked_property = 'time';
117115
}
116+
}
118117

119-
if ($linked_object!='' && $linked_property!='') {
120-
$rec['AUTO_LINK_AVAILABLE']=1;
121-
$rec['AUTO_LINK']=1;
122-
} else {
123-
$rec['AUTO_LINK_AVAILABLE']=0;
124-
}
118+
if ($linked_object != '' && $linked_property != '') {
119+
$rec['AUTO_LINK_AVAILABLE'] = 1;
125120
} else {
126-
$rec['AUTO_LINK']=0;
121+
$rec['AUTO_LINK_AVAILABLE'] = 0;
127122
}
128123

124+
$rec['AUTO_LINK'] = gr('auto_link', 'int');
129125
$rec['LINKED_OBJECT'] = $linked_object;
130126
$rec['LINKED_PROPERTY'] = $linked_property;
131-
if ($linked_object != '' && $linked_property != '') {
127+
128+
if ($rec['AUTO_LINK'] && $rec['LINKED_OBJECT'] != '' && $rec['LINKED_PROPERTY'] != '') {
132129
addLinkedProperty($linked_object, $linked_property, $this->name);
130+
} else {
131+
$rec['AUTO_LINK'] = 0;
132+
removeLinkedPropertyIfNotUsed('scripts', $rec['LINKED_OBJECT'], $rec['LINKED_PROPERTY'], $this->name);
133133
}
134134

135-
$rec['UPDATED']=date('Y-m-d H:i:s');
135+
$rec['UPDATED'] = date('Y-m-d H:i:s');
136136

137137
if ($rec['ID']) {
138138
SQLUpdate($table_name, $rec); // update
@@ -144,13 +144,13 @@
144144

145145
global $edit_run;
146146
if ($edit_run) {
147-
echo '<div style="margin: 30px 0px;border: 1px solid #dddddd;padding: 10px;border-left: 10px solid #4d96d3;resize: vertical;height: 400px;min-height: 100px;overflow: auto;">
148-
<h3 style="margin: 0px;border-bottom: 1px solid #dddddd;padding-bottom: 5px;margin-bottom: 10px;">'.LANG_NEWDASH_RESULT.':</h3>
147+
echo '<div style="margin: 30px 0px;border: 1px solid #dddddd;padding: 10px;border-left: 10px solid #4d96d3;resize: vertical;height: 400px;min-height: 100px;overflow: auto;">
148+
<h3 style="margin: 0px;border-bottom: 1px solid #dddddd;padding-bottom: 5px;margin-bottom: 10px;">' . LANG_NEWDASH_RESULT . ':</h3>
149149
<pre>';
150-
$this->runScript($rec['ID']);
151-
echo '</pre></div>';
152-
153-
$rec['EDIT_RUN'] = $edit_run;
150+
$this->runScript($rec['ID']);
151+
echo '</pre></div>';
152+
153+
$rec['EDIT_RUN'] = $edit_run;
154154
}
155155

156156

@@ -206,7 +206,7 @@
206206
}
207207

208208
$run_days = array();
209-
if ($rec['RUN_DAYS']!=='') {
209+
if ($rec['RUN_DAYS'] !== '') {
210210
$run_days = explode(',', $rec['RUN_DAYS']);
211211
}
212212

0 commit comments

Comments
 (0)