FreePBX Open Source - Global Functions in 2.10 and Higher

FreePBX Open Source - Global Functions in 2.10 and Higher

Table of Contents

Global Functions

These functions can be used throughout FreePBX to obtain relevant data. Click below to see more about each function:

 

Get the Asterisk Version

Used to get the Version of Asterisk

engine_getinfo();

Example:

$ast_info = engine_getinfo(); $version = $ast_info["version"];

Get the FreePBX Version

Used to get the Version of FreePBX (Which is the Framework Version)

/**  * Get the FreePBX/Framework Version  * @param bool $cached Whether to pull from the DB or not  * @return string The FreePBX version number  */ getversion($cached=true);

Get the FreePBX Framework Version (Depreciated in favor of FreePBX Version)

Used to get the Framework Version of FreePBX

/**  * Get the FreePBX/Framework Version  * @param bool $cached Whether to pull from the DB or not  * @return string The FreePBX Framework version number  */ get_framework_version($cached=true);

Compare Two 'Version' Strings (2.11.0 vs 2.11.1)

Compare two versions of software, with special FreePBX nomenclature assumed.

/**  * version_compare that works with FreePBX version numbers  *  * @param string $version1 First version number  * @param string $version2 Second version number  * @param string $op If you specify the third optional operator argument,  *                   you can test for a particular relationship.  *                   The possible operators are:  *                   <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively.  * @return mixed returns -1 if the first version is lower than the second,  *               0 if they are equal, and 1 if the second is lower.  *               When using the optional operator argument, the function will  *               return TRUE if the relationship is the one specified by the  *               operator, FALSE otherwise.  */  version_compare_freepbx($version1, $version2, $op = null);

Example:

$string1 = '2.11.0beta1'; $string2 = '2.11.1'; if(version_compare_freepbx($string1,$string2,'<')) {     echo "Yes"; } else {     echo "No"; } //returns Yes

Send Message to Log

FreePBX Logging facility to FILE or syslog

this is not the same as the dbug() function!

/**   * FreePBX Logging facility to FILE or syslog  * @param  string   The level/severity of the error. Valid levels use constants:  *                  FPBX_LOG_FATAL, FPBX_LOG_CRITICAL, FPBX_LOG_SECURITY, FPBX_LOG_UPDATE,  *                  FPBX_LOG_ERROR, FPBX_LOG_WARNING, FPBX_LOG_NOTICE, FPBX_LOG_INFO.  * @param  string   The error message  */ freepbx_log($level, $message);

Generate Debug Message

FreePBX Debugging function, you can view the messages output by this function by running (On the CLI): amportal a dbug

/**  * FreePBX Debugging function  * This function can be called as follows:  * dbug() - will just print a time stamp to the debug log file ($amp_conf['FPBXDBUGFILE'])  * dbug('string') - same as above + will print the string  * dbug('string',$array) - same as above + will print_r the array after the message  * dbug($array) - will print_r the array with no message (just a time stamp)  * dbug('string',$array,1) - same as above + will var_dump the array  * dbug($array,1) - will var_dump the array with no message  (just a time stamp)  *  */ dbug();

Generate FreePBX Die Message

Throws a PHP DIE message from FreePBX

/**  * Throw FreePBX DIE Message  * @param string $text The message  * @param string $extended_text The Extended Message (Optional)  * @param string $type The message type (Optional)  */ die_freepbx($text, $extended_text="", $type="FATAL");

Show "Apply Changes" (Need Reload) Button

Tell the user we need to apply changes and reload Asterisk

/**  * Tell the user we need to apply changes and reload Asterisk  */ needreload();

Check if "Apply Changes" (Need Reload) flag is set

Check to see if Apply Changes/Need Reload flag has been set

/**  * Check to see if Apply Changes/Need Reload flag has been set  * @return bool true if flag is set, false if otherwise  */ check_reload_needed();

Locate System Application

returns the absolute path to a system application

/**  * returns the absolute path to a system application  *  * @pram string  * @retrun string  */ fpbx_which($app)

Recursively Remove a Directory

Recursively remove a directory

/**  * Recursively remove a directory  * @param string - dirname  *  * @return bool  */ rrmdir($dir)