@@ -38,16 +38,16 @@ function __construct()
38
38
function saveParams ($ data = 0 )
39
39
{
40
40
$ p = array ();
41
- if (IsSet ($ this ->id )) {
41
+ if (isset ($ this ->id )) {
42
42
$ p ["id " ] = $ this ->id ;
43
43
}
44
- if (IsSet ($ this ->view_mode )) {
44
+ if (isset ($ this ->view_mode )) {
45
45
$ p ["view_mode " ] = $ this ->view_mode ;
46
46
}
47
- if (IsSet ($ this ->edit_mode )) {
47
+ if (isset ($ this ->edit_mode )) {
48
48
$ p ["edit_mode " ] = $ this ->edit_mode ;
49
49
}
50
- if (IsSet ($ this ->tab )) {
50
+ if (isset ($ this ->tab )) {
51
51
$ p ["tab " ] = $ this ->tab ;
52
52
}
53
53
return parent ::saveParams ($ p );
@@ -100,18 +100,18 @@ function run()
100
100
} else {
101
101
$ this ->usual ($ out );
102
102
}
103
- if (IsSet ($ this ->owner ->action )) {
103
+ if (isset ($ this ->owner ->action )) {
104
104
$ out ['PARENT_ACTION ' ] = $ this ->owner ->action ;
105
105
}
106
- if (IsSet ($ this ->owner ->name )) {
106
+ if (isset ($ this ->owner ->name )) {
107
107
$ out ['PARENT_NAME ' ] = $ this ->owner ->name ;
108
108
}
109
109
$ out ['VIEW_MODE ' ] = $ this ->view_mode ;
110
110
$ out ['EDIT_MODE ' ] = $ this ->edit_mode ;
111
111
$ out ['MODE ' ] = $ this ->mode ;
112
112
$ out ['ACTION ' ] = $ this ->action ;
113
113
$ out ['TAB ' ] = $ this ->tab ;
114
- if (IsSet ($ this ->script_id )) {
114
+ if (isset ($ this ->script_id )) {
115
115
$ out ['IS_SET_SCRIPT_ID ' ] = 1 ;
116
116
}
117
117
if ($ this ->single_rec ) {
@@ -250,18 +250,18 @@ function edit_patterns(&$out, $id)
250
250
*
251
251
* @access public
252
252
*/
253
- function checkAllPatterns ($ from_user_id = 0 )
253
+ function checkAllPatterns ($ from_user_id = 0 , $ details = 0 )
254
254
{
255
255
$ current_context = context_getcurrent ($ from_user_id );
256
256
//DebMes("current context:".$current_context);
257
257
if ($ from_user_id && preg_match ('/^ext(\d+)/ ' , $ current_context , $ m )) {
258
- $ res = $ this ->checkExtPatterns ($ m [1 ],$ from_user_id );
258
+ $ res = $ this ->checkExtPatterns ($ m [1 ], $ from_user_id );
259
259
} else {
260
260
$ patterns = SQLSelect ("SELECT * FROM patterns WHERE 1 AND PARENT_ID=' " . (int )$ current_context . "' AND PATTERN_TYPE=0 ORDER BY PRIORITY DESC, TITLE " );
261
261
$ total = count ($ patterns );
262
262
$ res = 0 ;
263
263
for ($ i = 0 ; $ i < $ total ; $ i ++) {
264
- $ matched = $ this ->checkPattern ($ patterns [$ i ]['ID ' ], $ from_user_id );
264
+ $ matched = $ this ->checkPattern ($ patterns [$ i ]['ID ' ], $ from_user_id, $ details );
265
265
if ($ matched ) {
266
266
$ res = 1 ;
267
267
if ($ patterns [$ i ]['IS_LAST ' ]) {
@@ -313,7 +313,7 @@ function getAvailableActions()
313
313
}
314
314
315
315
316
- function checkExtPatterns ($ ext_context_id , $ user_id= 0 )
316
+ function checkExtPatterns ($ ext_context_id , $ user_id = 0 )
317
317
{
318
318
319
319
$ message = SQLSelectOne ("SELECT MESSAGE FROM shouts ORDER BY ID DESC LIMIT 1 " );
@@ -400,7 +400,7 @@ function checkExtPatterns($ext_context_id, $user_id=0)
400
400
playMedia ($ data ['MEDIA_URL ' ]);
401
401
}
402
402
403
- context_activate_ext ($ data ['NEW_CONTEXT ' ], (int )$ data ['TIMEOUT ' ], $ data ['TIMEOUT_CODE ' ], (int )$ data ['TIMEOUT_CONTEXT_ID ' ],$ user_id );
403
+ context_activate_ext ($ data ['NEW_CONTEXT ' ], (int )$ data ['TIMEOUT ' ], $ data ['TIMEOUT_CODE ' ], (int )$ data ['TIMEOUT_CONTEXT_ID ' ], $ user_id );
404
404
405
405
return $ data ['MATCHED_CONTEXT ' ];
406
406
@@ -476,14 +476,17 @@ function getConnectDetails()
476
476
}
477
477
478
478
479
- function runPatternAction ($ id , $ matches = array (), $ original = '' , $ from_user_id = 0 )
479
+ function runPatternAction ($ id , $ matches = array (), $ original = '' , $ from_user_id = 0 , $ details = 0 )
480
480
{
481
481
$ rec = SQLSelectOne ("SELECT * FROM patterns WHERE ID=' " . (int )$ id . "' " );
482
482
483
- //global $noPatternMode;
484
- //$noPatternMode=1;
485
483
if ($ rec ['SCRIPT_ID ' ]) {
486
- runScriptSafe ($ rec ['SCRIPT_ID ' ], $ matches );
484
+ if (is_array ($ details )) {
485
+ $ details ['MATCHES ' ] = $ matches ;
486
+ runScriptSafe ($ rec ['SCRIPT_ID ' ], $ details );
487
+ } else {
488
+ runScriptSafe ($ rec ['SCRIPT_ID ' ], $ matches );
489
+ }
487
490
} elseif ($ rec ['SCRIPT ' ]) {
488
491
489
492
try {
@@ -496,7 +499,6 @@ function runPatternAction($id, $matches = array(), $original = '', $from_user_id
496
499
$ bases [$ i ] = $ form_bases [0 ];
497
500
}
498
501
}
499
-
500
502
$ code = $ rec ['SCRIPT ' ];
501
503
$ success = eval ($ code );
502
504
if ($ success === false ) {
@@ -509,11 +511,9 @@ function runPatternAction($id, $matches = array(), $original = '', $from_user_id
509
511
}
510
512
511
513
}
512
- //$noPatternMode=0;
513
-
514
514
}
515
515
516
- function runPatternExitAction ($ id , $ script_exit )
516
+ function runPatternExitAction ($ id , $ script_exit, $ details = 0 )
517
517
{
518
518
519
519
if ($ script_exit ) {
@@ -587,13 +587,10 @@ function generate_combinations(array $data, array &$all = array(), array $group
587
587
*
588
588
* @access public
589
589
*/
590
- function checkPattern ($ id , $ from_user_id = 0 )
590
+ function checkPattern ($ id , $ from_user_id = 0 , $ details = 0 )
591
591
{
592
- global $ session ;
593
592
global $ pattern_matched ;
594
593
595
-
596
- $ this_pattern_matched = 0 ;
597
594
$ condition_matched = 0 ;
598
595
599
596
if (!checkAccess ('pattern ' , $ id )) return 0 ;
@@ -643,7 +640,7 @@ function checkPattern($id, $from_user_id = 0)
643
640
SQLUpdate ('patterns ' , $ rec );
644
641
645
642
if ($ rec ['SCRIPT_EXIT ' ]) {
646
- $ this ->runPatternExitAction ($ rec ['ID ' ], $ rec ['SCRIPT_EXIT ' ]);
643
+ $ this ->runPatternExitAction ($ rec ['ID ' ], $ rec ['SCRIPT_EXIT ' ], $ details );
647
644
}
648
645
//to-do: state exit script
649
646
@@ -758,23 +755,17 @@ function checkPattern($id, $from_user_id = 0)
758
755
$ is_common = (int )$ parent_rec ['IS_COMMON_CONTEXT ' ];
759
756
}
760
757
761
- /*
762
- if (context_getcurrent()) {
763
- $history = context_get_history() . ' ' . $history;
764
- }
765
- */
766
-
767
758
if ($ rec ['IS_CONTEXT ' ]) {
768
- context_activate ($ rec ['ID ' ], 1 , $ history ,$ from_user_id );
759
+ context_activate ($ rec ['ID ' ], 1 , $ history , $ from_user_id, $ details );
769
760
} elseif ($ rec ['MATCHED_CONTEXT_ID ' ]) {
770
- context_activate ($ rec ['MATCHED_CONTEXT_ID ' ], 0 , $ history ,$ from_user_id );
761
+ context_activate ($ rec ['MATCHED_CONTEXT_ID ' ], 0 , $ history , $ from_user_id, $ details );
771
762
} elseif (!$ is_common ) {
772
- context_activate (0 ,0 , '' ,$ from_user_id );
763
+ context_activate (0 , 0 , '' , $ from_user_id, $ details );
773
764
}
774
765
775
766
$ rec ['LOG ' ] = date ('Y-m-d H:i:s ' ) . ' Pattern matched ' . "\n" . $ rec ['LOG ' ];
776
- if (strlen ($ rec ['LOG ' ])> 65000 ) {
777
- $ rec ['LOG ' ] = substr ($ rec ['LOG ' ],0 , 65000 );
767
+ if (strlen ($ rec ['LOG ' ]) > 65000 ) {
768
+ $ rec ['LOG ' ] = substr ($ rec ['LOG ' ], 0 , 65000 );
778
769
}
779
770
$ rec ['EXECUTED ' ] = time ();
780
771
SQLUpdate ('patterns ' , $ rec );
@@ -787,7 +778,7 @@ function checkPattern($id, $from_user_id = 0)
787
778
$ sub_patterns = SQLSelect ("SELECT ID, IS_LAST FROM patterns WHERE PARENT_ID=' " . $ rec ['ID ' ] . "' ORDER BY PRIORITY DESC, TITLE " );
788
779
$ total = count ($ sub_patterns );
789
780
for ($ i = 0 ; $ i < $ total ; $ i ++) {
790
- if ($ this ->checkPattern ($ sub_patterns [$ i ]['ID ' ], $ from_user_id )) {
781
+ if ($ this ->checkPattern ($ sub_patterns [$ i ]['ID ' ], $ from_user_id, $ details )) {
791
782
$ sub_patterns_matched = 1 ;
792
783
if ($ sub_patterns [$ i ]['IS_LAST ' ]) {
793
784
break ;
@@ -797,7 +788,7 @@ function checkPattern($id, $from_user_id = 0)
797
788
}
798
789
799
790
if (!$ sub_patterns_matched ) {
800
- $ this ->runPatternAction ($ rec ['ID ' ], $ matches , $ history , $ from_user_id );
791
+ $ this ->runPatternAction ($ rec ['ID ' ], $ matches , $ history , $ from_user_id, $ details );
801
792
}
802
793
803
794
if ($ rec ['ONETIME ' ]) {
@@ -848,7 +839,7 @@ function processSubscription($event, &$details)
848
839
global $ context_user_id ;
849
840
$ context_user_id = $ member_id ;
850
841
851
- $ res = $ this ->checkAllPatterns ($ member_id );
842
+ $ res = $ this ->checkAllPatterns ($ member_id, $ details );
852
843
if ($ event == 'COMMAND ' && $ res ) {
853
844
$ details ['BREAK ' ] = true ;
854
845
$ details ['PROCESSED ' ] = true ;
0 commit comments