4
4
* phpagi.php : PHP AGI Functions for Asterisk
5
5
* @see https://github.com/welltime/phpagi
6
6
* @filesource http://phpagi.sourceforge.net/
7
- *
7
+ *
8
8
* $Id: phpagi.php,v 2.20 2010/09/30 02:21:00 masham Exp $
9
9
*
10
10
* Copyright (c) 2003 - 2010 Matthew Asham <[email protected] >, David Eder <[email protected] > and others
15
15
*
16
16
* We would be happy to list your phpagi based application on the phpagi
17
17
* website. Drop me an Email if you'd like us to list your program.
18
- *
18
+ *
19
19
*
20
20
* Written for PHP 4.3.4, should work with older PHP 4.x versions.
21
21
*
@@ -131,11 +131,11 @@ class AGI
131
131
132
132
/**
133
133
* Application option delimiter
134
- *
134
+ *
135
135
* @access public
136
136
*/
137
137
public $ option_delim = ", " ;
138
-
138
+
139
139
/**
140
140
* Constructor
141
141
*
@@ -377,19 +377,19 @@ function exec($application, $options)
377
377
* Asterisk looks for the file to play in /var/lib/asterisk/sounds by default.
378
378
*
379
379
* If the user doesn't press any keys when the message plays, there is $timeout milliseconds
380
- * of silence then the command ends.
380
+ * of silence then the command ends.
381
381
*
382
382
* The user has the opportunity to press a key at any time during the message or the
383
383
* post-message silence. If the user presses a key while the message is playing, the
384
384
* message stops playing. When the first key is pressed a timer starts counting for
385
385
* $timeout milliseconds. Every time the user presses another key the timer is restarted.
386
386
* The command ends when the counter goes to zero or the maximum number of digits is entered,
387
- * whichever happens first.
387
+ * whichever happens first.
388
388
*
389
389
* If you don't specify a time out then a default timeout of 2000 is used following a pressed
390
- * digit. If no digits are pressed then 6 seconds of silence follow the message.
390
+ * digit. If no digits are pressed then 6 seconds of silence follow the message.
391
391
*
392
- * If you don't specify $max_digits then the user can enter as many digits as they want.
392
+ * If you don't specify $max_digits then the user can enter as many digits as they want.
393
393
*
394
394
* Pressing the # key has the same effect as the timer running out: the command ends and
395
395
* any previously keyed digits are returned. A side effect of this is that there is no
@@ -440,7 +440,7 @@ function get_variable($variable,$getvalue=FALSE)
440
440
* @link http://www.voip-info.org/wiki-Asterisk+variables
441
441
* @param string $variable name
442
442
* @param string $channel channel
443
- * @param boolean $getvalue return the value only
443
+ * @param boolean $getvalue return the value only
444
444
* @return array, see evaluate for return information. ['result'] is 0 if variable hasn't been set, 1 if it has. ['data'] holds the value. returns value if $getvalue is TRUE
445
445
*/
446
446
function get_fullvariable ($ variable ,$ channel =FALSE ,$ getvalue =FALSE )
@@ -450,14 +450,14 @@ function get_fullvariable($variable,$channel=FALSE,$getvalue=FALSE)
450
450
} else {
451
451
$ req = $ variable .' ' .$ channel ;
452
452
}
453
-
453
+
454
454
$ res =$ this ->evaluate ('GET FULL VARIABLE ' .$ req );
455
-
455
+
456
456
if ($ getvalue ==FALSE )
457
457
return ($ res );
458
-
458
+
459
459
return ($ res ['data ' ]);
460
-
460
+
461
461
}
462
462
463
463
/**
@@ -496,7 +496,7 @@ function noop($string="")
496
496
*
497
497
* @link http://www.voip-info.org/wiki-receive+char
498
498
* @param integer $timeout milliseconds
499
- * @return array, see evaluate for return information. ['result'] is 0 on timeout or not supported, -1 on failure. Otherwise
499
+ * @return array, see evaluate for return information. ['result'] is 0 on timeout or not supported, -1 on failure. Otherwise
500
500
* it is the decimal value of the DTMF tone. Use chr() to convert to ASCII.
501
501
*/
502
502
function receive_char ($ timeout =-1 )
@@ -515,9 +515,9 @@ function receive_char($timeout=-1)
515
515
* @param integer $timeout is the maximum record time in milliseconds, or -1 for no timeout.
516
516
* @param integer $offset to seek to without exceeding the end of the file.
517
517
* @param boolean $beep
518
- * @param integer $silence number of seconds of silence allowed before the function returns despite the
518
+ * @param integer $silence number of seconds of silence allowed before the function returns despite the
519
519
* lack of dtmf digits or reaching timeout.
520
- * @return array, see evaluate for return information. ['result'] is -1 on error, 0 on hangup, otherwise a decimal value of the
520
+ * @return array, see evaluate for return information. ['result'] is -1 on error, 0 on hangup, otherwise a decimal value of the
521
521
* DTMF tone. Use chr() to convert to ASCII.
522
522
*/
523
523
function record_file ($ file , $ format , $ escape_digits ='' , $ timeout =-1 , $ offset =NULL , $ beep =false , $ silence =NULL )
@@ -534,7 +534,7 @@ function record_file($file, $format, $escape_digits='', $timeout=-1, $offset=NUL
534
534
* @link http://www.voip-info.org/wiki-say+digits
535
535
* @param integer $digits
536
536
* @param string $escape_digits
537
- * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
537
+ * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
538
538
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
539
539
*/
540
540
function say_digits ($ digits , $ escape_digits ='' )
@@ -548,7 +548,7 @@ function say_digits($digits, $escape_digits='')
548
548
* @link http://www.voip-info.org/wiki-say+number
549
549
* @param integer $number
550
550
* @param string $escape_digits
551
- * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
551
+ * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
552
552
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
553
553
*/
554
554
function say_number ($ number , $ escape_digits ='' )
@@ -562,7 +562,7 @@ function say_number($number, $escape_digits='')
562
562
* @link http://www.voip-info.org/wiki-say+phonetic
563
563
* @param string $text
564
564
* @param string $escape_digits
565
- * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
565
+ * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
566
566
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
567
567
*/
568
568
function say_phonetic ($ text , $ escape_digits ='' )
@@ -576,7 +576,7 @@ function say_phonetic($text, $escape_digits='')
576
576
* @link http://www.voip-info.org/wiki-say+time
577
577
* @param integer $time number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
578
578
* @param string $escape_digits
579
- * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
579
+ * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
580
580
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
581
581
*/
582
582
function say_time ($ time =NULL , $ escape_digits ='' )
@@ -592,7 +592,7 @@ function say_time($time=NULL, $escape_digits='')
592
592
*
593
593
* @link http://www.voip-info.org/wiki-send+image
594
594
* @param string $image without extension, often in /var/lib/asterisk/images
595
- * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the image is sent or
595
+ * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the image is sent or
596
596
* channel does not support image transmission.
597
597
*/
598
598
function send_image ($ image )
@@ -607,7 +607,7 @@ function send_image($image)
607
607
*
608
608
* @link http://www.voip-info.org/wiki-send+text
609
609
* @param $text
610
- * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the text is sent or
610
+ * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the text is sent or
611
611
* channel does not support text transmission.
612
612
*/
613
613
function send_text ($ text )
@@ -635,7 +635,7 @@ function set_autohangup($time=0)
635
635
*
636
636
* @link http://www.voip-info.org/wiki-set+callerid
637
637
* @param string $cid example: "John Smith"<1234567>
638
- * This command will let you take liberties with the <caller ID specification> but the format shown in the example above works
638
+ * This command will let you take liberties with the <caller ID specification> but the format shown in the example above works
639
639
* well: the name enclosed in double quotes followed immediately by the number inside angle brackets. If there is no name then
640
640
* you can omit it. If the name contains no spaces you can omit the double quotes around it. The number must follow the name
641
641
* immediately; don't put a space between them. The angle brackets around the number are necessary; if you omit them the
@@ -650,14 +650,14 @@ function set_callerid($cid)
650
650
/**
651
651
* Sets the context for continuation upon exiting the application.
652
652
*
653
- * Setting the context does NOT automatically reset the extension and the priority; if you want to start at the top of the new
654
- * context you should set extension and priority yourself.
653
+ * Setting the context does NOT automatically reset the extension and the priority; if you want to start at the top of the new
654
+ * context you should set extension and priority yourself.
655
655
*
656
- * If you specify a non-existent context you receive no error indication (['result'] is still 0) but you do get a
656
+ * If you specify a non-existent context you receive no error indication (['result'] is still 0) but you do get a
657
657
* warning message on the Asterisk console.
658
658
*
659
659
* @link http://www.voip-info.org/wiki-set+context
660
- * @param string $context
660
+ * @param string $context
661
661
* @return array, see evaluate for return information.
662
662
*/
663
663
function set_context ($ context )
@@ -668,10 +668,10 @@ function set_context($context)
668
668
/**
669
669
* Set the extension to be used for continuation upon exiting the application.
670
670
*
671
- * Setting the extension does NOT automatically reset the priority. If you want to start with the first priority of the
672
- * extension you should set the priority yourself.
671
+ * Setting the extension does NOT automatically reset the priority. If you want to start with the first priority of the
672
+ * extension you should set the priority yourself.
673
673
*
674
- * If you specify a non-existent extension you receive no error indication (['result'] is still 0) but you do
674
+ * If you specify a non-existent extension you receive no error indication (['result'] is still 0) but you do
675
675
* get a warning message on the Asterisk console.
676
676
*
677
677
* @link http://www.voip-info.org/wiki-set+extension
@@ -716,8 +716,8 @@ function set_priority($priority)
716
716
* Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>}
717
717
* in the dialplan.
718
718
*
719
- * These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary.
720
- * Variables created in one channel can not be accessed by another channel. When you hang up the phone, the channel is deleted
719
+ * These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary.
720
+ * Variables created in one channel can not be accessed by another channel. When you hang up the phone, the channel is deleted
721
721
* and any variables in that channel are deleted as well.
722
722
*
723
723
* @link http://www.voip-info.org/wiki-set+variable
@@ -732,8 +732,8 @@ function set_variable($variable, $value)
732
732
}
733
733
734
734
/**
735
- * Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA
736
- * command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of
735
+ * Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA
736
+ * command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of
737
737
* digits before returning.
738
738
*
739
739
* @example examples/ping.php Ping an IP address
@@ -742,7 +742,7 @@ function set_variable($variable, $value)
742
742
* @param string $filename without extension, often in /var/lib/asterisk/sounds
743
743
* @param string $escape_digits
744
744
* @param integer $offset
745
- * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
745
+ * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
746
746
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
747
747
*/
748
748
function stream_file ($ filename , $ escape_digits ='' , $ offset =0 )
@@ -767,9 +767,9 @@ function tdd_mode($setting)
767
767
*
768
768
* If the Asterisk verbosity level is $level or greater, send $message to the console.
769
769
*
770
- * The Asterisk verbosity system works as follows. The Asterisk user gets to set the desired verbosity at startup time or later
771
- * using the console 'set verbose' command. Messages are displayed on the console if their verbose level is less than or equal
772
- * to desired verbosity set by the user. More important messages should have a low verbose level; less important messages
770
+ * The Asterisk verbosity system works as follows. The Asterisk user gets to set the desired verbosity at startup time or later
771
+ * using the console 'set verbose' command. Messages are displayed on the console if their verbose level is less than or equal
772
+ * to desired verbosity set by the user. More important messages should have a low verbose level; less important messages
773
773
* should have a high verbose level.
774
774
*
775
775
* @link http://www.voip-info.org/wiki-verbose
@@ -792,7 +792,7 @@ function verbose($message, $level=1)
792
792
*
793
793
* @link http://www.voip-info.org/wiki-wait+for+digit
794
794
* @param integer $timeout in millisecons. Use -1 for the timeout value if you want the call to wait indefinitely.
795
- * @return array, see evaluate for return information. ['result'] is 0 if wait completes with no
795
+ * @return array, see evaluate for return information. ['result'] is 0 if wait completes with no
796
796
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
797
797
*/
798
798
function wait_for_digit ($ timeout =-1 )
@@ -808,9 +808,9 @@ function wait_for_digit($timeout=-1)
808
808
/**
809
809
* Set absolute maximum time of call.
810
810
*
811
- * Note that the timeout is set from the current time forward, not counting the number of seconds the call has already been up.
812
- * Each time you call AbsoluteTimeout(), all previous absolute timeouts are cancelled.
813
- * Will return the call to the T extension so that you can playback an explanatory note to the calling party (the called party
811
+ * Note that the timeout is set from the current time forward, not counting the number of seconds the call has already been up.
812
+ * Each time you call AbsoluteTimeout(), all previous absolute timeouts are cancelled.
813
+ * Will return the call to the T extension so that you can playback an explanatory note to the calling party (the called party
814
814
* will not hear that)
815
815
*
816
816
* @link http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands
@@ -1549,9 +1549,9 @@ function say_punctuation($text, $escape_digits='', $frequency=8000)
1549
1549
*/
1550
1550
function &new_AsteriskManager ()
1551
1551
{
1552
- $ this ->asm = new AGI_AsteriskManager (NULL , $ this ->config );
1552
+ $ this ->asm = new AGI_AsteriskManager (NULL , $ this ->config [ ' asmanager ' ] );
1553
1553
$ this ->asm ->setPagi ($ this );
1554
- $ this ->config =& $ this ->asm ->config ;
1554
+ $ this ->config [ ' asmanager ' ] =& $ this ->asm ->config [ ' asmanager ' ] ;
1555
1555
return $ this ->asm ;
1556
1556
}
1557
1557
@@ -1689,16 +1689,20 @@ function conlog($str, $vbl=1)
1689
1689
*/
1690
1690
function which ($ cmd , $ checkpath =NULL )
1691
1691
{
1692
- global $ _ENV ;
1693
- $ chpath = is_null ($ checkpath ) ? $ _ENV ['PATH ' ] : $ checkpath ;
1692
+ if (is_null ($ checkpath )) {
1693
+ $ chpath = getenv ('PATH ' );
1694
+ if ($ chpath === false ) {
1695
+ $ chpath = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin: ' .
1696
+ '/usr/X11R6/bin:/usr/local/apache/bin:/usr/local/mysql/bin ' ;
1697
+ }
1698
+ } else {
1699
+ $ chpath = $ checkpath ;
1700
+ }
1694
1701
1695
1702
foreach (explode (': ' , $ chpath ) as $ path )
1696
1703
if (is_executable ("$ path/ $ cmd " ))
1697
1704
return "$ path/ $ cmd " ;
1698
1705
1699
- if (is_null ($ checkpath ))
1700
- return $ this ->which ($ cmd , '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin: ' .
1701
- '/usr/X11R6/bin:/usr/local/apache/bin:/usr/local/mysql/bin ' );
1702
1706
return false ;
1703
1707
}
1704
1708
@@ -1708,7 +1712,7 @@ function which($cmd, $checkpath=NULL)
1708
1712
* @access private
1709
1713
* @param string $folder
1710
1714
* @param integer $perms
1711
- * @return boolean
1715
+ * @return boolean
1712
1716
*/
1713
1717
function make_folder ($ folder , $ perms =0755 )
1714
1718
{
@@ -1725,7 +1729,7 @@ function make_folder($folder, $perms=0755)
1725
1729
$ base .= DIRECTORY_SEPARATOR ;
1726
1730
}
1727
1731
return (TRUE );
1728
- }
1732
+ }
1729
1733
1730
1734
}
1731
1735
0 commit comments