/** * Get destinations of every module * This function might be slow, but it works from within bmo * @return array Array of destinations */ public function getDestinations() { $this->loadAllFunctionsInc(); $modules = $this->getActiveModules(); $destinations = array(); foreach ($modules as $rawname => $data) { $funct = strtolower($rawname . '_destinations'); $funct2 = strtolower($rawname . '_getdestinfo'); if (function_exists($funct)) { \modgettext::push_textdomain($rawname); $index = ''; //used in certain situations but not here $destArray = $funct($index); //returns an array with 'destination' and 'description', and optionally 'category' \modgettext::pop_textdomain(); if (!empty($destArray)) { foreach ($destArray as $dest) { $destinations[$dest['destination']] = $dest; $destinations[$dest['destination']]['module'] = $rawname; $destinations[$dest['destination']]['name'] = $data['name']; if (function_exists($funct2)) { $info = $funct2($dest['destination']); $destinations[$dest['destination']]['edit_url'] = $info['edit_url']; } } } } } return $destinations; }
private function processNewHooks() { $hooks = $this->FreePBX->Hooks->getAllHooks(); if (is_array($hooks['ConfigFiles'])) { foreach ($hooks['ConfigFiles'] as $hook) { $mod = str_replace("FreePBX\\modules\\", "", $hook); \modgettext::push_textdomain(strtolower($mod)); $hparts = explode("\\", $hook); if (count($hparts) > 0) { $c = count($hparts); $hook = $hparts[$c - 1]; } $this->FreePBX->Performance->Stamp("fileHook-" . $hook . "_start"); // This is where we'd hook the output of files, if it was implemented. // As no-one wants it yet, I'm not going to bother. if (!method_exists($this->FreePBX->{$hook}, "genConfig")) { throw new \Exception("{$hook} asked to generate a config file, but, doesn't implement genConfig()"); } $tmpconf = $this->FreePBX->{$hook}->genConfig(); // Here we want to hand off $tmpconf to other modules, if they somehow say they want to do something // with it. if (!method_exists($this->FreePBX->{$hook}, "writeConfig")) { throw new \Exception("{$hook} asked to generate a config file, but, doesn't implement writeConfig()"); } $this->FreePBX->{$hook}->writeConfig($tmpconf); $this->FreePBX->Performance->Stamp("fileHook-" . $hook . "_stop"); \modgettext::pop_textdomain(); } } }
function install_hooks($viewing_itemid, $target_module, $target_menuid = '') { global $active_modules; /* Loop though all active modules and find which ones have hooks. * Then process those hooks. Note we split this into two loops * because of #4057, if drawselects() is called from within a hook * it's interaction with the same $active_modules array renders the * foreach loop done after that module and execution ends. */ $our_hooks = array(); foreach ($active_modules as $this_module) { // look for requested hooks for $module // ie: findme_hook_extensions() $funct = $this_module['rawname'] . '_hook_' . $target_module; if (function_exists($funct)) { // remember who installed hooks // we need to know this for processing form vars $this->arrHooks[] = $this_module['rawname']; $our_hooks[$this_module['rawname']] = $funct; } } foreach ($our_hooks as $thismod => $funct) { modgettext::push_textdomain($thismod); if ($hookReturn = $funct($target_menuid, $viewing_itemid)) { $this->hookHtml .= $hookReturn; } modgettext::pop_textdomain(); } }
public function __construct($freepbx = null) { if ($freepbx == null) { throw new \Exception("Not given a FreePBX Object"); } if (!class_exists('FreePBX\\modules\\Voicemail\\Vmx') && file_exists(__DIR__ . '/Vmx.class.php')) { include __DIR__ . '/Vmx.class.php'; $this->Vmx = new Voicemail\Vmx($freepbx); } $this->FreePBX = $freepbx; $this->astman = $this->FreePBX->astman; $this->db = $freepbx->Database; $this->vmPath = $this->FreePBX->Config->get_conf_setting('ASTSPOOLDIR') . "/voicemail"; $this->messageLimit = $this->FreePBX->Config->get_conf_setting('UCP_MESSAGE_LIMIT'); \modgettext::push_textdomain("voicemail"); foreach ($this->folders as $folder) { $this->vmFolders[$folder] = array("folder" => $folder, "name" => _($folder)); } \modgettext::pop_textdomain(); //Force translation for later pickup if (false) { _("INBOX"); _("Family"); _("Friends"); _("Old"); _("Work"); _("Urgent"); _('Unavailable Greeting'); _('Name Greeting'); _('Busy Greeting'); _('Temporary Greeting'); } }
public function processHooks($engine, $hooks = null) { global $ext; if ($hooks == null) { throw new Exception("I wasn't given any modules to hook. Bug."); } // The array should already be sorted before it's given to us. Don't // sort again. Just run through it! foreach ($hooks as $pri => $hook) { foreach ($hook as $module => $cmds) { \modgettext::push_textdomain(strtolower($module)); foreach ($cmds as $cmd) { // Is this an old-style function call? (_hookGet, _hook_core etc) if (isset($cmd['function'])) { $func = $cmd['function']; if (!function_exists($func)) { // Old style modules may be licenced, and as such their functions may not be there. Let's see if this // module is one of those. $funcarr = explode("_", $func); $x = $this->FreePBX->Modules->getInfo($funcarr[0]); if (isset($x[$funcarr[0]]) && $x[$funcarr[0]]['license'] == "Commercial") { continue; } else { print "HANDLED-ERROR: {$func} should exist, but it doesn't - Dazed and confused, but continuing. This is a bug.\n"; continue; } } $this->FreePBX->Performance->Stamp("olddialplanHook-" . $func . "_start"); $func($engine); $this->FreePBX->Performance->Stamp("olddialplanHook-" . $func . "_stop"); } elseif (isset($cmd['Class'])) { // This is a new BMO Object! $class = $cmd['Class']; try { if (!method_exists($this->FreePBX->{$class}, "doDialplanHook")) { print "HANDLED-ERROR: {$class}->doDialplanHook() isn't there, but the module is saying it wants to hook - Dazed and confused, but continuing. This is a bug\n"; continue; } $this->FreePBX->Performance->Stamp($class . "->doDialplanHook_start"); $this->FreePBX->{$class}->doDialplanHook($ext, $engine, $pri); $this->FreePBX->Performance->Stamp($class . "->doDialplanHook_stop"); } catch (\Exception $e) { $this->FreePBX->Performance->Stamp($class . "->doDialplanHook_stop"); print "HANDLED-ERROR: Tried to run {$class}->doDialplanHook(), it threw an exception. I received " . $e->getMessage() . "\nContinuing. This is a bug\n"; } } else { // I have no idea what this is. throw new \Exception("I was handed " . json_encode($cmd) . " to hook. Don't know how to handle it"); } } \modgettext::pop_textdomain(); } } }
public function processHooks($engine, $hooks = null) { global $ext; if ($hooks == null) { throw new \Exception("I wasn't given any modules to hook. Bug."); } // The array should already be sorted before it's given to us. Don't // sort again. Just run through it! $hooks = is_array($hooks) ? $hooks : array(); foreach ($hooks as $pri => $hook) { $hook = is_array($hook) ? $hook : array(); foreach ($hook as $module => $cmds) { \modgettext::push_textdomain(strtolower($module)); $cmds = is_array($cmds) ? $cmds : array(); foreach ($cmds as $cmd) { // Is this an old-style function call? (_hookGet, _hook_core etc) if (isset($cmd['function'])) { $func = $cmd['function']; if (!function_exists($func)) { // Old style modules may be licenced, and as such their functions may not be there. Let's see if this // module is one of those. $funcarr = explode("_", $func); $x = $this->FreePBX->Modules->getInfo($funcarr[0]); if (isset($x[$funcarr[0]]) && $x[$funcarr[0]]['license'] == "Commercial") { continue; } else { out(sprintf(_("HANDLED-ERROR: %s should exist, but it doesn't. This is a bug in %s"), $func, $funcarr[0])); continue; } } $this->FreePBX->Performance->Stamp("olddialplanHook-" . $func . "_start"); $func($engine); $this->FreePBX->Performance->Stamp("olddialplanHook-" . $func . "_stop"); } elseif (isset($cmd['Class'])) { // This is a new BMO Object! $class = $cmd['Class']; if (!method_exists($this->FreePBX->{$class}, "doDialplanHook")) { out(sprintf(_("HANDLED-ERROR: %s->doDialplanHook() isn't there, but the module is saying it wants to hook. This is a bug in %s"), $class, $class)); continue; } $this->FreePBX->Performance->Stamp($class . "->doDialplanHook_start"); $this->FreePBX->{$class}->doDialplanHook($ext, $engine, $pri); $this->FreePBX->Performance->Stamp($class . "->doDialplanHook_stop"); } else { // I have no idea what this is. throw new \Exception(sprintf(_("I was handed %s to hook. Don't know how to handle it"), json_encode($cmd))); } } \modgettext::pop_textdomain(); } } }
public function process_hooks($viewing_itemid, $target_module, $target_menuid, $request) { if (is_array($this->arrHooks)) { foreach ($this->arrHooks as $hookingMod) { // check if there is a processing function $funct = $hookingMod . '_hookProcess_' . $target_module; if (function_exists($funct)) { modgettext::push_textdomain(strtolower($hookingMod)); $funct($viewing_itemid, $request); modgettext::pop_textdomain(); } } } }
/** * Process the hook(s) for said page * @param string $viewing_itemid The item id, could be: {userdisplay, extdisplay, id, itemid, selection} * @param string $target_module The module rawname * @param string $module_page The Module Page Name * @param array $request The passed $_REQUEST global array */ public function process_hooks($viewing_itemid, $target_module, $module_page, $request) { if (is_array($this->arrHooks)) { foreach ($this->arrHooks as $hookingMod) { // check if there is a processing function $funct = $hookingMod . '_hookProcess_' . $target_module; if (function_exists($funct)) { modgettext::push_textdomain(strtolower($hookingMod)); $funct($viewing_itemid, $request); modgettext::pop_textdomain(); } } } foreach ($this->our_hooks as $thismod => $funct) { modgettext::push_textdomain($thismod); if ($hookReturn = $funct($viewing_itemid, $module_page)) { $this->hookHtml .= $hookReturn; } modgettext::pop_textdomain(); } }
public function moduleSearch() { $results = array(); if (!isset($_REQUEST['query'])) { return array(); } // Make the query string usable. $qs = htmlentities($_REQUEST['query'], ENT_QUOTES, 'UTF-8', false); $mods = \FreePBX::Modules()->getModulesByMethod("search"); foreach ($mods as $mod) { \modgettext::push_textdomain(strtolower($mod)); $this->FreePBX->{$mod}->search($qs, $results); \modgettext::pop_textdomain(); } // Remove any results from the search that are unneeded. foreach ($results as $i => $r) { if ($r['type'] == "text" || isset($r['force'])) { // Always return text fields that were given back to us, or if the result // was forced to display. continue; } // We should try to use UTF-8 sensible matching if possible. if (function_exists("mb_stripos")) { if (mb_stripos($r['text'], $qs) === false) { // Doesn't match? Remove. unset($results[$i]); } } else { // Use UTF-8 unsafe check. if (stripos($r['text'], $qs) === false) { // Doesn't match? Remove. unset($results[$i]); } } } return $results; }
/** * Get List of Menu items from said Modules */ private function getModuleList() { $active_modules = $this->FreePBX->Modules->getActiveModules(); $module_list = array(); if (is_array($active_modules)) { $dis = $this->FreePBX->Config->get('AMPEXTENSIONS') == 'deviceanduser' ? _("Add Device") : _("Add Extension"); $active_modules['au']['items'][] = array('name' => _("Apply Changes Bar"), 'display' => '99'); $active_modules['au']['items'][] = array('name' => $dis, 'display' => '999'); foreach ($active_modules as $key => $module) { //create an array of module sections to display if (isset($module['items']) && is_array($module['items'])) { foreach ($module['items'] as $itemKey => $item) { $listKey = !empty($item['display']) ? $item['display'] : $itemKey; if (isset($item['rawname'])) { $item['rawname'] = $module['rawname']; \modgettext::push_textdomain($module['rawname']); } $item['name'] = _($item['name']); $module_list[$listKey] = $item; if (isset($item['rawname'])) { \modgettext::pop_textdomain(); } } } } } // extensions vs device/users ... module_list setting if (isset($amp_conf["AMPEXTENSIONS"]) && $amp_conf["AMPEXTENSIONS"] == "deviceanduser") { unset($module_list["extensions"]); } else { unset($module_list["devices"]); unset($module_list["users"]); } unset($module_list['ampusers']); return $module_list; }
/** * Destination drawselects. * * This is where the magic happens. Query all modules for valid destinations * Then build a javascript based multi-select box. * Hide the second select box until the first is selected. * Auto-populate the second based on the first. * * The first is almost always a module name, though it can be custom as well. * The second is the actually destination * * @param string $goto The current goto destination setting. EG: ext-local,2000,1 * @param int $i the destination set number (used when drawing multiple destination sets in a single form ie: digital receptionist) * @param array $restrict_modules Array of modules or array of modules with ids to restrict getting destinations from * @param bool $table Wrap this in a table row using <tr> and <td> (deprecated should not be used in 13+) * @param string $nodest_msg No Destination selected message * @param bool $required Whether the destination is required to be set * @param bool $output_array Output an array instead of html (you will need to make sure the html is correct later on for the functionality of this to work correctly) * @param bool $reset Reset the drawselect_* globals (useful when using multiple destination dropdowns on a page, each with their own restricted modules) * @param bool $disable Set html element to disabled on creation * @param string $class String of classes to add to to the html element (class="<string>") * @return mixed Array if $output_array is true otherwise a string of html */ function drawselects($goto, $i, $restrict_modules = false, $table = true, $nodest_msg = '', $required = false, $output_array = false, $reset = false, $disable = false, $class = '') { global $tabindex, $active_modules, $drawselect_destinations, $drawselects_module_hash, $fw_popover; static $drawselects_id_hash; if ($reset) { unset($drawselect_destinations); unset($drawselects_module_hash); unset($drawselects_id_hash); } //php session last_dest $fw_popover = isset($fw_popover) ? $fw_popover : FALSE; $disabled = $disable ? "disabled" : ""; $html = $destmod = $errorclass = $errorstyle = ''; if ($nodest_msg == '') { $nodest_msg = '== ' . modgettext::_('choose one', 'amp') . ' =='; } if ($table) { $html .= '<tr><td colspan=2>'; } //wrap in table tags if requested if (!isset($drawselect_destinations)) { $popover_hash = array(); $add_a_new = _('Add new %s …'); //check for module-specific destination functions foreach ($active_modules as $rawmod => $module) { $restricted = false; if (is_array($restrict_modules) && !in_array($rawmod, $restrict_modules) && !isset($restrict_modules[$rawmod])) { $restricted = true; } $funct = strtolower($rawmod . '_destinations'); $popover_hash = array(); //if the modulename_destinations() function exits, run it and display selections for it if (function_exists($funct)) { modgettext::push_textdomain($rawmod); $destArray = $funct($i); //returns an array with 'destination' and 'description', and optionally 'category' modgettext::pop_textdomain(); if (is_Array($destArray)) { foreach ($destArray as $dest) { $cat = isset($dest['category']) ? $dest['category'] : $module['displayname']; $cat = str_replace(array("|"), "", $cat); $cat = str_replace("&", _("and"), $cat); $ds_id = isset($dest['id']) ? $dest['id'] : $rawmod; // don't restrict the currently selected destination if ($restricted && $dest['destination'] != $goto) { continue; } if (empty($restrict_modules[$rawmod]) || is_array($restrict_modules[$rawmod]) && in_array($ds_id, $restrict_modules[$rawmod])) { $popover_hash[$ds_id] = $cat; $drawselect_destinations[$cat][] = $dest; $drawselects_module_hash[$cat] = $rawmod; $drawselects_id_hash[$cat] = $ds_id; } } } if ($restricted) { continue; } if (isset($module['popovers']) && !$fw_popover) { modgettext::push_textdomain($rawmod); $funct = strtolower($rawmod . '_destination_popovers'); modgettext::pop_textdomain(); if (function_exists($funct)) { $protos = $funct(); foreach ($protos as $ds_id => $cat) { if (empty($restrict_modules[$rawmod]) || is_array($restrict_modules[$rawmod]) && in_array($ds_id, $restrict_modules[$rawmod])) { $popover_hash[$ds_id] = $cat; $drawselects_module_hash[$cat] = $rawmod; $drawselects_id_hash[$cat] = $ds_id; } } } else { if (empty($destArray)) { // We have popovers in XML, there were no destinations, and no mod_destination_popovers() // funciton so generate the Add a new selection. // $drawselects_module_hash[$module['displayname']] = $rawmod; $drawselects_id_hash[$module['displayname']] = $rawmod; $drawselect_destinations[$module['displayname']][99999] = array("destination" => "popover", "description" => sprintf($add_a_new, $module['displayname'])); } } } // if we have a popver_hash either from real values or mod_destination_popovers() // then we create the 'Add a new option foreach ($popover_hash as $ds_id => $cat) { if (isset($module['popovers'][$ds_id]) && !$fw_popover) { $drawselect_destinations[$cat][99999] = array("destination" => "popover", "description" => sprintf($add_a_new, $cat), "category" => $cat); } } } } //sort destination alphabetically if (is_array($drawselect_destinations)) { ksort($drawselect_destinations); } if (is_array($drawselects_module_hash)) { ksort($drawselects_module_hash); } } $ds_array = $drawselect_destinations; //set variables as arrays for the rare (impossible?) case where there are none if (!isset($drawselect_destinations)) { $drawselect_destinations = array(); } if (!isset($drawselects_module_hash)) { $drawselects_module_hash = array(); } $foundone = false; $tabindex_needed = true; //get the destination module name if we have a $goto, add custom if there is an issue if ($goto) { foreach ($drawselects_module_hash as $mod => $description) { foreach ($drawselect_destinations[$mod] as $destination) { if ($goto == $destination['destination']) { $destmod = $mod; } } } if ($destmod == '') { //if we haven't found a match, display error dest $destmod = 'Error'; $drawselect_destinations['Error'][] = array('destination' => $goto, 'description' => 'Bad Dest: ' . $goto, 'class' => 'drawselect_error'); $drawselects_module_hash['Error'] = 'error'; $drawselects_id_hash['Error'] = 'error'; } //Set 'data-last' values for popover return to last saved values $data_last_cat = str_replace(' ', '_', $destmod); $data_last_dest = $goto; } else { //Set 'data-last' values for popover return to nothing because this is a new 'route' $data_last_cat = ''; $data_last_dest = ''; } //draw "parent" select box $style = ' style="' . ($destmod == 'Error' ? 'background-color:red;' : '') . '"'; $html .= '<select data-last="' . $data_last_cat . '" name="goto' . $i . '" id="goto' . $i . '" class="form-control destdropdown ' . $class . '" ' . $style . ' tabindex="' . ++$tabindex . '"' . ($required ? ' required ' : '') . ' data-id="' . $i . '" ' . $disabled . '>'; $html .= '<option value="" style="">' . $nodest_msg . '</option>'; foreach ($drawselects_module_hash as $mod => $disc) { $label_text = modgettext::_($mod, $drawselects_module_hash[$mod]); /* end i18n */ $selected = $mod == $destmod ? ' SELECTED ' : ' '; $style = ' style="' . ($mod == 'Error' ? 'background-color:red;' : '') . '"'; $html .= '<option value="' . str_replace(' ', '_', $mod) . '"' . $selected . $style . '>' . $label_text . '</option>'; } $html .= '</select> '; //draw "children" select boxes $tabindexhtml = ' tabindex="' . ++$tabindex . '"'; //keep out of the foreach so that we don't increment it foreach ($drawselect_destinations as $cat => $destination) { $style = ''; if ($cat == 'Error') { $style .= ' ' . $errorstyle; } //add error style $style = ' style="' . ($cat == 'Error' ? 'background-color:red;' : $style) . '"'; // if $fw_popover is set, then we are in a popover so we don't allow another level // $rawmod = $drawselects_module_hash[$cat]; $ds_id = $drawselects_id_hash[$cat]; if (isset($active_modules[$rawmod]['popovers'][$ds_id]) && !$fw_popover) { $args = array(); foreach ($active_modules[$rawmod]['popovers'][$ds_id] as $k => $v) { $args[] = $k . '=' . $v; } $data_url = 'data-url="config.php?' . implode('&', $args) . '" '; $data_class = 'data-class="' . $ds_id . '" '; $data_mod = 'data-mod="' . $rawmod . '" '; } else { $data_url = ''; $data_mod = ''; if (isset($active_modules[$rawmod]['popovers']) && !$fw_popover) { $data_class = 'data-class="' . $ds_id . '" '; } else { $data_class = ''; } } $hidden = $cat == $destmod ? '' : 'hidden'; $class_tag = ' class="form-control destdropdown2 ' . $rawmod . " " . $hidden . " " . $class; $class_tag .= $rawmod == $ds_id ? '"' : ' ' . $ds_id . '"'; $name_tag = str_replace(' ', '_', $cat) . $i; $html .= '<select ' . $data_url . $data_class . $data_mod . 'data-last="' . $data_last_dest . '" name="' . $name_tag . '" id="' . $name_tag . '" ' . $tabindexhtml . $style . $class_tag . ' data-id="' . $i . '" ' . $disabled . '>'; foreach ($destination as $key => $dest) { $selected = $goto == $dest['destination'] ? 'SELECTED ' : ' '; $ds_array[$cat][$key]['selected'] = $goto == $dest['destination'] ? true : false; $child_label_text = $dest['description']; $style = ' style="' . ($cat == 'Error' ? 'background-color:red;' : '') . '"'; $html .= '<option value="' . $dest['destination'] . '" ' . $selected . $style . '>' . $child_label_text . '</option>'; } $html .= '</select>'; } if (isset($drawselect_destinations['Error'])) { unset($drawselect_destinations['Error']); } if (isset($drawselects_module_hash['Error'])) { unset($drawselects_module_hash['Error']); } if ($table) { $html .= '</td></tr>'; } //wrap in table tags if requested return $output_array ? $ds_array : $html; }
/** * Construct Module Configuration Pages * This is used to setup and display module configuration pages * in User Manager * @param {array} $user The user array */ function constructModuleConfigPages($user) { //module with no module folder $html = ''; $modulef =& module_functions::create(); $modules = $modulef->getinfo(false); $path = $this->FreePBX->Config->get_conf_setting('AMPWEBROOT'); $location = $path . "/admin/modules"; foreach ($modules as $module) { if (isset($module['rawname']) && $module['status'] == MODULE_STATUS_ENABLED) { $rawname = trim($module['rawname']); $mod = ucfirst(strtolower($module['rawname'])); if (file_exists($location . "/" . $rawname . "/" . $mod . ".class.php")) { if (method_exists(FreePBX::create()->{$mod}, 'getUCPAdminDisplay')) { \modgettext::push_textdomain(strtolower($mod)); $data = FreePBX::create()->{$mod}->getUCPAdminDisplay($user); \modgettext::pop_textdomain(); if (isset($data['content'])) { $html[] = array('description' => $data['description'], 'content' => $data['content']); } elseif (isset($data[0]['content'])) { foreach ($data as $item) { $html[] = array('description' => $item['description'], 'content' => $item['content']); } } } } } } return $html; }
/** * Process all cached hooks */ public function processHooks() { //get hooks from level "2" backtrace $sortedHooks = $this->returnHooks(2); $return = array(); if (!empty($sortedHooks)) { foreach ($sortedHooks as $hook) { $module = $hook['module']; $namespace = $hook['namespace']; if (!class_exists($namespace . $hook['class'])) { //its active so lets get BMO to load it //basically we are hoping the module itself will load the right class //follow FreePBX BMO naming Schema try { $this->FreePBX->{$module}; if (!class_exists($namespace . $hook['class'])) { //Ok we really couln't find it. Give up throw new \Exception('Cant find ' . $namespace . $hook['class']); } } catch (\Exception $e) { throw new \Exception('Cant find ' . $namespace . $hook['class'] . "::: " . $e->getMessage()); } } $meth = $hook['method']; //now send the method from that class the data! \modgettext::push_textdomain(strtolower($module)); $return[$module] = call_user_func_array(array($this->FreePBX->{$module}, $meth), func_get_args()); \modgettext::pop_textdomain(); } } //return the data from that class return $return; }
/** * Process all cached hooks */ public function processHooks() { $this->activemods = $this->FreePBX->Modules->getActiveModules(); $hooks = $this->getAllHooks(); $o = debug_backtrace(); $callingMethod = !empty($o[1]['function']) ? $o[1]['function'] : ''; $callingClass = !empty($o[1]['class']) ? $o[1]['class'] : ''; $return = array(); if (!empty($hooks['ModuleHooks'][$callingClass]) && !empty($hooks['ModuleHooks'][$callingClass][$callingMethod])) { foreach ($hooks['ModuleHooks'][$callingClass][$callingMethod] as $module => $hooks) { if (isset($this->activemods[$module])) { foreach ($hooks as $hook) { $namespace = !empty($hook['namespace']) ? $hook['namespace'] . '\\' : ''; $module = ucfirst(strtolower($module)); if (!class_exists($namespace . $hook['class'])) { //its active so lets get BMO to load it //basically we are hoping the module itself will load the right class //follow FreePBX BMO naming Schema try { $this->FreePBX->{$module}; if (!class_exists($namespace . $hook['class'])) { //Ok we really couln't find it. Give up throw new \Exception('Cant find ' . $namespace . $hook['class']); } } catch (\Exception $e) { throw new \Exception('Cant find ' . $namespace . $hook['class'] . "::: " . $e->getMessage()); } } $meth = $hook['method']; //now send the method from that class the data! modgettext::push_textdomain(strtolower($module)); $return[$module] = call_user_func_array(array($this->FreePBX->{$module}, $meth), func_get_args()); modgettext::pop_textdomain(); } } } } //return the data from that class return $return; }
/** * Add a Notification Message * * @param const $level Notification Level * @param string $module Raw name of the module requesting * @param string $id ID of the notification * @param string $display_text The text that will be displayed as the subject/header of the message * @param string $extended_text The extended text of the notification when it is expanded * @param string $link The link that is set to the notification * @param bool $reset Reset notification on module update * @param bool $candelete If the notification can be deleted by the user on the notifications display page * @return int Returns the number of notifications per module & id * @ignore */ function _add_type($level, $module, $id, $display_text, $extended_text = "", $link = "", $reset = false, $candelete = false) { global $amp_conf; if (!empty($amp_conf["NOTIFICATION_IGNORE_{$module}_{$id}"])) { return null; } \modgettext::push_textdomain(strtolower($module)); if ($this->not_loaded) { $this->notification_table = $this->_list("", true); $this->not_loaded = false; } $existing_row = false; foreach ($this->notification_table as $row) { if ($row['module'] == $module && $row['id'] == $id) { $existing_row = $row; break; } } // Found an existing row - check if anything changed or if we are suppose to reset it // $candelete = $candelete ? 1 : 0; if ($existing_row) { if ($reset && $existing_row['reset'] == 1 || $existing_row['level'] != $level || $existing_row['display_text'] != $display_text || $existing_row['extended_text'] != $extended_text || $existing_row['link'] != $link || $existing_row['candelete'] == $candelete) { // If $reset is set to the special case of PASSIVE then the updates will not change it's value in an update // $reset_value = $reset == 'PASSIVE' ? $existing_row['reset'] : 0; $module = q($module); $id = q($id); $level = q($level); $display_text = q($display_text); $extended_text = q($extended_text); $link = q($link); $now = time(); $sql = "UPDATE notifications SET\n\t\t\t\t\tlevel = {$level},\n\t\t\t\t\tdisplay_text = {$display_text},\n\t\t\t\t\textended_text = {$extended_text},\n\t\t\t\t\tlink = {$link},\n\t\t\t\t\treset = {$reset_value},\n\t\t\t\t\tcandelete = {$candelete},\n\t\t\t\t\ttimestamp = {$now}\n\t\t\t\t\tWHERE module = {$module} AND id = {$id}\n\t\t\t\t\t"; sql($sql); // TODO: I should really just add this to the internal cache, but really // how often does this get called that if is a big deal. $this->not_loaded = true; } } else { // No existing row so insert this new one // $now = time(); $module = q($module); $id = q($id); $level = q($level); $display_text = q($display_text); $extended_text = q($extended_text); $link = q($link); $sql = "INSERT INTO notifications\n\t\t\t\t(module, id, level, display_text, extended_text, link, reset, candelete, timestamp)\n\t\t\t\tVALUES\n\t\t\t\t({$module}, {$id}, {$level}, {$display_text}, {$extended_text}, {$link}, 0, {$candelete}, {$now})\n\t\t\t\t"; sql($sql); // TODO: I should really just add this to the internal cache, but really // how often does this get called that if is a big deal. $this->not_loaded = true; } \modgettext::pop_textdomain(); }
function recordings_list_usage($id) { global $active_modules; $full_usage_arr = array(); foreach (array_keys($active_modules) as $mod) { $function = $mod . "_recordings_usage"; if (function_exists($function)) { modgettext::push_textdomain($mod); $recordings_usage = $function($id); modgettext::pop_textdomain(); if (!empty($recordings_usage)) { $full_usage_arr = array_merge($full_usage_arr, $recordings_usage); } } } return $full_usage_arr; }
function buildconfigpage() { if (!$this->_sorted_guifuncs) { $this->sortguifuncs(); } if (is_array($this->_guifuncs)) { foreach (array_keys($this->_guifuncs) as $sortorder) { foreach ($this->_guifuncs[$sortorder] as $func) { $modparts = explode("_", $func, 2); $thismod = $modparts[0]; modgettext::push_textdomain($thismod); $func($this->_compname); modgettext::pop_textdomain(); } } } }
function buildconfigpage() { if (!$this->sorted_guifuncs) { $this->sortguifuncs(); } $perf = FreePBX::Performance(); if (is_array($this->guifuncs)) { foreach (array_keys($this->guifuncs) as $sortorder) { foreach ($this->guifuncs[$sortorder] as $func) { $modparts = explode("_", $func, 2); $thismod = $modparts[0]; modgettext::push_textdomain($thismod); $perf->Start("buildpager-{$func}"); $func($this->compname); $perf->Stop("buildpager-{$func}"); modgettext::pop_textdomain(); } } } }
#!/usr/bin/env php <?php //include freepbx configuration $restrict_mods = array('fax' => true); if (!@(include_once getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) { include_once '/etc/asterisk/freepbx.conf'; } \modgettext::push_textdomain("fax"); $var['hostname'] = gethostname(); $var['from'] = sql('SELECT value FROM fax_details WHERE `key` = "sender_address"', 'getOne'); $var['from'] = $var['from'] ? $var['from'] : '*****@*****.**'; $var['subject'] = ''; $var = array_merge($var, get_opt()); $var['callerid'] = empty($var['callerid']) || $var['callerid'] === true ? '' : $var['callerid']; //prevent callerid from being blank $var['keep_file'] = !empty($var['delete']) && $var['delete'] == 'true' ? false : true; $var['attachformat'] = !empty($var['attachformat']) ? $var['attachformat'] : 'pdf'; $var['remotestationid'] = !empty($var['remotestationid']) ? $var['remotestationid'] : ''; //double check some of the options foreach ($var as $k => $v) { if (!is_string($k)) { continue; } switch ($k) { case 'file': if (!file_exists($var['file'])) { die_fax('email-fax dying, file ' . $var['file'] . ' not found!'); } break; case 'to': if (empty($var['to']) && !$var['keep_file']) {
/** determines which module a list of destinations belongs to, and if the destination object exists * @param mixed an array of destinations to check against * @param array a hash of module names to search for callbacks, otherwise global $active_modules is used * @return array an array structure with informaiton about the destinations (see code) * @description Mainly used by framework_list_problem_destinations. This function will find the module * that a destination belongs to and determine if the object still exits. This allow it to * either obtain the identify, identify it as an object that has been deleted, or identify * it as an unknown destination, usually a custom destination. * * FIXME: This is slow, and needs to be sped up. * */ function framework_identify_destinations($dest, $module_hash = false) { global $active_modules; static $dest_cache = array(); $dest_results = array(); $dest_usage = array(); $dest_matches = array(); if (!is_array($module_hash)) { $module_hash = $active_modules; } if (!is_array($dest)) { $dest = array($dest); } foreach ($dest as $target) { if (isset($dest_cache[$target])) { $dest_results[$target] = $dest_cache[$target]; } else { $found_owner = false; foreach (array_keys($module_hash) as $mod) { $function = $mod . "_getdestinfo"; if (function_exists($function)) { modgettext::push_textdomain($mod); $check_module = $function($target); modgettext::pop_textdomain(); if ($check_module !== false) { $found_owner = true; $dest_cache[$target] = array($mod => $check_module); $dest_results[$target] = $dest_cache[$target]; break; } } } if (!$found_owner) { //echo "Not Found: $target\n"; $dest_cache[$target] = false; $dest_results[$target] = $dest_cache[$target]; } } } return $dest_results; }
\t</div> \t<div class="row"> \t\t<div class="col-md-12"> HERE; $inputhtmlend = <<<HERE \t\t</div> \t</div> </div> HERE; $forminputs = ''; foreach ($conf as $c) { if ($c['hidden']) { continue; } if (!empty($c['module'])) { \modgettext::push_textdomain(strtolower($c['module'])); } else { \modgettext::pop_textdomain(); } unset($true); unset($false); if ($c['category'] != $current_category && $current_category != '') { $forminputs .= '</div><br/>'; } if ($c['category'] != $current_category) { $current_category = $c['category']; $catid = preg_replace('/\\s+/', '', $current_category); $forminputs .= '<div class="section-title hidden" data-for="' . $catid . '">'; $forminputs .= '<h2><i class="fa fa-minus"></i> ' . _($current_category) . '</h2>'; $forminputs .= '</div>'; $forminputs .= '<div class="section hidden" data-id="' . $catid . '">';
private function doBMOConfigPage($class, $display) { $mod = str_replace("FreePBX\\modules\\", "", $class); if (method_exists($this->FreePBX->{$class}, "doConfigPageInit")) { $this->FreePBX->Performance->Stamp($class . "->doConfigPageInit-{$display}" . "_start"); \modgettext::push_textdomain(strtolower($mod)); $this->FreePBX->{$class}->doConfigPageInit($display); \modgettext::pop_textdomain(); $this->FreePBX->Performance->Stamp($class . "->doConfigPageInit-{$display}" . "_stop"); } else { print "Page {$class} doesn't implement doConfigPageInit, this is bad.\n"; } }
// check current item if ($display == $item['display']) { // found current menuitem, make a reference to it $cur_menuitem =& $fpbx_menu[$itemKey]; } } } } } if ($cur_menuitem === null && !in_array($display, array('noauth', 'badrefer', 'noaccess', ''))) { $display = 'noaccess'; } // new gui hooks if (!$quietmode && is_array($active_modules)) { foreach ($active_modules as $key => $module) { modgettext::push_textdomain($module['rawname']); if (isset($module['items']) && is_array($module['items'])) { foreach ($module['items'] as $itemKey => $itemName) { //list of potential _configpageinit functions $initfuncname = $key . '_' . $itemKey . '_configpageinit'; if (function_exists($initfuncname)) { $configpageinits[] = $initfuncname; } } } //check for module level (rather than item as above) _configpageinit function $initfuncname = $key . '_configpageinit'; if (function_exists($initfuncname)) { $configpageinits[] = $initfuncname; } modgettext::pop_textdomain();