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(); } }
/** * 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; }
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 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; }
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(); } } }
if (!isset($_REQUEST['module'])) { $module = "framework"; } else { $module = $_REQUEST['module']; } if (isset($_REQUEST['command'])) { $command = $_REQUEST['command']; } else { $command = "unset"; } // I think we'll default to having astman connected, // it adds a REALLY minor startup penalty, and saves // work in the modules. Feel free to revisit later and // yell at me if you disagree. // // $bootstrap_settings['skip_astman'] = true; // No auth - we'll do that later. $bootstrap_settings['freepbx_auth'] = false; // Throw verbose exceptions, no matter what. $bootstrap_settings['freepbx_error_handler'] = false; // No non-BMO Modules. $restrict_mods = true; // Bootstrap! if (!@(include_once getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) { include_once '/etc/asterisk/freepbx.conf'; } // We may remove this, but for the moment, ajax should be // 100% error and warning free. error_reporting(-1); modgettext::textdomain($module); $bmo->Ajax->doRequest($module, $command);
?> </td> </tr> <?php } ?> <tr> <td><?php echo _("Description"); ?> :</td> <?php if (!empty($module['description'])) { ?> <td><?php echo nl2br(modgettext::_($module['description'], $module['loc_domain'])); ?> </td> <?php } else { ?> <td><?php echo _("No description is available."); ?> </td> </tr> <?php } ?> <tr> <td><?php
/** 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; }
/** * 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; }
foreach ($modules[$name]['vulnerabilities']['vul'] as $vul) { $security_issues_to_report[$vul] = true; } } else { $module_display[$category]['data'][$name]['vulnerabilities'] = array(); } $module_display[$category]['data'][$name]['raw']['online'] = !empty($modules_online[$name]) ? $modules_online[$name] : array(); $module_display[$category]['data'][$name]['raw']['local'] = !empty($modules_local[$name]) ? $modules_local[$name] : array(); $module_display[$category]['data'][$name]['name'] = $name; $module_display[$category]['data'][$name]['pretty_name'] = !empty($name_text) ? $name_text : $name; $module_display[$category]['data'][$name]['repo'] = $modules[$name]['repo']; $module_display[$category]['data'][$name]['dbversion'] = !empty($modules[$name]['dbversion']) ? $modules[$name]['dbversion'] : ''; $module_display[$category]['data'][$name]['publisher'] = !empty($modules[$name]['publisher']) ? $modules[$name]['publisher'] : ''; $module_display[$category]['data'][$name]['salert'] = $salert; if (!empty($modules_online[$name]['attention'])) { $module_display[$category]['data'][$name]['attention'] = nl2br(modgettext::_($modules[$name]['attention'], $loc_domain)); } if (!empty($modules_online[$name]['changelog'])) { $module_display[$category]['data'][$name]['changelog'] = format_changelog($modules_online[$name]['changelog']); } elseif (!empty($modules_local[$name]['changelog'])) { $module_display[$category]['data'][$name]['changelog'] = format_changelog($modules_local[$name]['changelog']); } $module_display[$category]['data'][$name]['description'] = isset($module_display[$category]['data'][$name]['description']) ? trim(preg_replace('/\\s+/', ' ', $module_display[$category]['data'][$name]['description'])) : ''; if (!empty($module_display[$category]['data'][$name]['previous'])) { foreach ($module_display[$category]['data'][$name]['previous'] as &$release) { if (preg_match("/" . $release['version'] . "[\\s|:|\\*](.*)/m", $release['changelog'], $matches)) { $release['pretty_change'] = !empty($matches[1]) ? format_changelog($matches[1]) : _('No Change Log'); } } } $track = !empty($modules_local[$name]['track']) ? $modules_local[$name]['track'] : 'stable';
/** * 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; }
echo '<input type="radio" id="uninstall_' . prep_id($name) . '" name="moduleaction[' . prep_id($name) . ']" value="uninstall" /> ' . '<label for="uninstall_' . prep_id($name) . '">' . _('Uninstall') . '</label> <br />'; } break; } echo "\t\t\t\t</div>\n"; echo "\t\t\t\t<div class=\"tabbertab\" title=\"" . _("Description") . "\">\n"; if (isset($modules[$name]['publisher'])) { echo "<h5>" . sprintf(_("Publisher: %s"), $modules[$name]['publisher']) . "</h5>"; } echo "<h5>" . sprintf(_("License: %s"), isset($modules[$name]['license']) ? $modules[$name]['license'] : "GPLv2") . "</h5>"; if ($salert) { echo "<h5>" . sprintf(_("Fixes Vulnerabilities: %s"), implode($modules[$name]['vulnerabilities']['vul'], ', ')) . "</h5>"; } if (isset($modules[$name]['description']) && !empty($modules[$name]['description'])) { echo "<h5>" . sprintf(_("Description for version %s"), $modules[$name]['version']) . "</h5>"; echo nl2br(modgettext::_($modules[$name]['description'], $loc_domain)); } else { echo _("No description is available."); } if (isset($modules[$name]['info']) && !empty($modules[$name]['info'])) { echo '<p>' . _('More info') . ': <a href="' . $modules[$name]['info'] . '" target="_new">' . $modules[$name]['info'] . '</a></p>'; } else { echo '<p>' . _('More info') . ': <a href="' . "{$freepbx_help_url}&freepbx_module=" . urlencode($name) . '" target="help">' . sprintf(_("Get help for %s"), $name_text) . '</a></p>'; } echo "\t\t\t\t</div>\n"; if (isset($modules[$name]['changelog']) && !empty($modules[$name]['changelog'])) { echo "\t\t\t\t<div class=\"tabbertab\" title=\"" . _("Changelog") . "\">\n"; echo "<h5>" . sprintf(_("Change Log for version %s"), $modules[$name]['version']) . "</h5>"; // convert "1.x.x:" and "*1.x.x*" into bold, and do nl2br // TODO: need to fix this to convert 1.x.xbetax.x, 1.x.xalphax.x, 1.x.xrcx.x, 1.x.xRCx.x formats as well //
} $prev_category = NULL; if (is_array($active_modules)) { $dis = $amp_conf['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) { if (!isset($module['rawname'])) { continue; } $listKey = !empty($item['display']) ? $item['display'] : $itemKey; $item['rawname'] = $module['rawname']; $item['name'] = modgettext::_($item['name'], $module['rawname']); $module_list[$listKey] = $item; } } } } $module_list[99] = array("name" => _("Apply Changes Bar")); $module_list[999] = array("name" => $amp_conf['AMPEXTENSIONS'] == 'deviceanduser' ? _("Add Device") : _("Add Extension")); $module_list['*'] = array("name" => _("ALL SECTIONS")); uasort($module_list, function ($a, $b) { return strnatcmp($a['name'], $b['name']); }); $selected = array(); $unselected = array(); foreach ($module_list as $key => $val) { if (!empty($user['sections']) && is_array($user['sections']) && (in_array($key, array_values($user['sections'])) || $user['sections'][0] == '*')) {
/** * 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; }
$forminputs .= '<input type="hidden" id="' . $c['keyword'] . 'default" value="' . $c['defaultval'] . '">'; $forminputs .= '<textarea class="form-control ' . $inputclass . '" rows = "4" id="' . $c['keyword'] . '" name="' . $c['keyword'] . '">' . $c['value'] . '</textarea>'; $forminputs .= '</div>'; $forminputs .= $inputhtmlmiddle; if ($display_friendly_name == 1) { $forminputs .= '<span id="' . $c['keyword'] . '-help" class="help-block fpbx-help-block">' . _("KEYWORD") . ":" . $c['keyword'] . "<br/>" . _($c['description']) . '</span>'; } else { $forminputs .= '<span id="' . $c['keyword'] . '-help" class="help-block fpbx-help-block">' . _("Friendly Name") . ":" . $c['name'] . "<br/>" . _($c['description']) . '</span>'; } $forminputs .= $inputhtmlend; break; default: dbug($c); break; } \modgettext::pop_textdomain(); } $forminputs .= "</div> <!-- close last element -->\n"; ?> <div class="container-fluid"> <h1><?php echo sprintf(_("%s Advanced Settings"), $conf['DASHBOARD_FREEPBX_BRAND']['value']); ?> </h1> <div class="alert alert-warning"> <?php echo "<b>" . _('IMPORTANT:') . "</b>" . _('Use extreme caution when making changes!'); ?> </div> <div class="well">
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']) {
} else { $bmo->Performance->Start("includefile-{$module_file}"); include $module_file; $bmo->Performance->Stop("includefile-{$module_file}"); } } } else { echo sprintf(_("404 Not found (%s)"), $module_file); } } } // BMO TODO: Post display hooks. $bmo->GuiHooks->getPostDisplay($module_name, $_REQUEST); // global component if (isset($currentcomponent)) { modgettext::textdomain($module_name); echo $currentcomponent->generateconfigpage(); } } break; } $header = array(); $footer = array(); if ($quietmode) { // send the output buffer, should be sending just the page contents @ob_end_flush(); } elseif ($fw_popover || $fw_popover_process) { $admin_template = $template = array(); //get the page contents from the buffer $content = ob_get_contents(); @ob_end_clean();
/** * 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; }
$classes = array(); //build defualt module url $href = isset($mod['href']) ? $mod['href'] : "config.php?display=" . $mod['display']; $target = isset($mod['target']) ? ' target="' . $mod['target'] . '" ' : ''; //highlight currently in-use module if ($display == $mod['display']) { $classes[] = 'ui-state-highlight'; $classes[] = 'ui-corner-all'; } //highlight disabled modules if (isset($mod['disabled']) && $mod['disabled']) { $classes[] = 'ui-state-disabled'; $classes[] = 'ui-corner-all'; } // try the module's translation domain first $items[$mod['name']] = '<li><a href="' . $href . '"' . $target . (!empty($classes) ? ' class="' . implode(' ', $classes) . '">' : '>') . modgettext::_($mod['name'], $mod['module']['rawname']) . '</a></li>'; $_item_sort[$mod['name']] = $mod['sort']; } uksort($items, '_item_sort'); $mods[$t] .= implode($items) . '</ul>'; unset($items); unset($_item_sort); } uksort($mods, '_menu_sort'); $out .= implode($mods); } if ($amp_conf['SHOWLANGUAGE']) { $out .= '<a id="language-menu-button" ' . 'class="button-right ui-widget-content ui-state-default">' . _('Language') . '</a>'; $out .= '<ul id="fpbx_lang" style="display:none;">'; $out .= '<li data-lang="en_US"><a href="#">' . _('English') . '</a></li>'; $out .= '<li data-lang="bg_BG"><a href="#">' . _('Bulgarian') . '</a></li>';
} $currentmodule = "(none)"; $modlines = ''; $modules = array(); foreach ($featurecodes as $item) { $moduledesc = isset($item['moduledescription']) ? modgettext::_($item['moduledescription'], $item['modulename']) : null; // just in case the translator put the translation in featurcodes module: if ($moduledesc !== null && !empty($moduledesc) && $moduledesc == $item['moduledescription']) { $moduledesc = _($moduledesc); } $featuredesc = !empty($item['featuredescription']) ? modgettext::_($item['featuredescription'], $item['modulename']) : ""; // just in case the translator put the translation in featurcodes module: if (!empty($item['featuredescription']) && $featuredesc == $item['featuredescription']) { $featuredesc = _($featuredesc); } $help = !empty($item['featurehelptext']) ? modgettext::_($item['featurehelptext'], $item['modulename']) : ""; if (!empty($item['featurehelptext']) && $help == $item['featurehelptext']) { $help = _($help); } //TODO: What did we do here before when the module was disabled? //bueller, bueller, bueller $moduleena = $item['moduleenabled'] == 1 ? true : false; $default = isset($item['defaultcode']) ? $item['defaultcode'] : ''; $custom = isset($item['customcode']) ? $item['customcode'] : ''; $code = $custom != '' ? $custom : $default; $thismodule = $item['modulename']; if ($thismodule != $currentmodule) { $lastmodule = $currentmodule; $currentmodule = $thismodule; $title = ucfirst($thismodule); $modules[$thismodule]['title'] = $title;
function featurecodeadmin_destinations() { $featurecodes = featurecodes_getAllFeaturesDetailed(); if (isset($featurecodes)) { $text_domain = array(); foreach ($featurecodes as $result) { // Ignore disabled codes, and modules, and ones not providing destinations // if ($result['featureenabled'] == 1 && $result['moduleenabled'] == 1 && $result['providedest'] == 1) { $modulename = $result['modulename']; $description = modgettext::_($result['featuredescription'], $modulename); // Just in case the translation was not found in either the module or amp, we will try to see // if they put it in the featurecode module i18n if ($description == $result['featuredescription']) { $description = _($description); } $thisexten = $result['customcode'] != '' ? $result['customcode'] : $result['defaultcode']; $extens[] = array('destination' => 'ext-featurecodes,' . $result['defaultcode'] . ',1', 'description' => $description . ' <' . $thisexten . '>'); } } } if (isset($extens)) { return $extens; } else { return null; } }
/** * 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; }
$prev_category = NULL; foreach ($module_list as $key => $row) { if ($row['category'] != $prev_category) { if ($prev_category) { echo "</optgroup>\n"; } $catname = _(ucwords($row['category'])); $catname = $catname != ucwords($row['category']) ? $catname : modgettext::_(ucwords($row['category']), $row['rawname']); echo "<optgroup label=\"" . $catname . "\">\n"; $prev_category = $row['category']; } echo "<option value=\"" . $key . "\""; if (in_array($key, $sections)) { echo " SELECTED"; } $label = modgettext::_($row['name'], $row['rawname']); echo ">" . $label . "</option>\n"; } echo "</optgroup>\n"; // Apply Changes Bar echo "<option value=\"99\""; if (in_array("99", $sections)) { echo " SELECTED"; } echo ">" . _("Apply Changes Bar") . "</option>\n"; // Apply Changes Bar echo "<option value=\"999\""; if (in_array("999", $sections)) { echo " SELECTED"; } echo ">" . ($amp_conf['AMPEXTENSIONS'] == 'deviceanduser' ? _("Add Device") : _("Add Extension")) . "</option>\n";
/** * 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 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(); } } } }
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"; } }
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(); } } }