Last active
May 23, 2024 12:52
-
-
Save lgaetz/07bed0d452c134d2c5018582a7ebeb20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** | |
* Developer Notes: | |
* | |
* Version History: | |
* 2022-06-13 Initial commit #FREEPBX-23555 | |
* 2022-07-14 Update to version 16, add multi language support, refactor code, tested = only message error (Javier Pastor Aka VSC55) | |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***/ | |
namespace FreePBX\modules\Superfecta\sources; | |
include_once ("baseSources.php"); | |
class EZCNAM extends baseSources { | |
public function __construct() | |
{ | |
$this->version_requirement = "16.0"; | |
$this->description = "https://www.ezcn am.com/ - "._("Commercial source for Caller ID Name data."); | |
$this->source_type = array( | |
'caller_id' | |
); | |
$this->source_param = array( | |
'Key' => array( | |
'description' => _('Your unique API key will be assigned to you when you create an EZCNAM account.'), | |
'type' => 'text' | |
), | |
'Ignore_Keywords' => array( | |
'description' => _('If this source provides CNAM including any of the keywords listed here, the CNAM will be ignored and other sources will be used to find the value.<br>Separate keywords with commas.'), | |
'type' => 'textarea', | |
'default' => 'unavailable, unknown' | |
), | |
); | |
} | |
function get_caller_id($thenumber, $run_param=array()) | |
{ | |
$caller_id = parent::get_caller_id($thenumber, $run_param); | |
$this->DebugPrint(""); | |
// Get Config | |
$Key = $this->getSourceParam($run_param, 'Key', null); | |
$Ignore_Keywords = $this->getSourceParam($run_param, 'Ignore_Keywords'); | |
$thenumber = urlencode($thenumber); | |
if ( empty($Key)) | |
{ | |
$this->DebugPrint(_("Lookups require account key... Skipping!")); | |
} | |
else | |
{ | |
$url = sprintf("https://api.ezcnam.com/v1?key=%s&phone=%s&out=json", $Key, $thenumber); | |
$ret = $this->get_url_contents($url); | |
$result = json_decode($ret, true); | |
if ( strtoupper($result['status']) == "OK") | |
{ | |
$sname = trim($result['name']); | |
if (strlen($sname) > 1) | |
{ | |
// convert list of ignore keywords into array | |
$key_words = array(); | |
$temp_array = explode(',', $Ignore_Keywords); | |
foreach($temp_array as $val) { | |
$key_words[] = trim($val); | |
} | |
// Remove all ignore keywords from the retuned CNAM string and compare the before and after. | |
$test_string = trim(str_ireplace($key_words,'',$sname)); | |
if($test_string == $sname) | |
{ | |
$caller_id = $sname; | |
} | |
else | |
{ | |
$this->DebugPrint( sprintf(_("'%s' contains flagged key word(s), discarding... Skipping!"), $sname)); | |
} | |
} | |
} | |
else | |
{ | |
$this->DebugPrint( sprintf(_("%s: %s"), $result['status'], $result['reason'])); | |
} | |
$this->DebugPrint( is_null($caller_id) ? _("Not Found") : _("Found")); | |
} | |
return($caller_id); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** | |
* Developer Notes: | |
* | |
* Version History: | |
* 2022-06-13 Initial commit | |
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***/ | |
class EZCNAM extends superfecta_base { | |
public $description = "https://www.ezcnam.com/ Commercial source for Caller ID Name data."; | |
public $version_requirement = "2.11"; | |
public $source_param = array( | |
'Key' => array( | |
'description' => 'Your unique API key will be assigned to you when you create an EZCNAM account.', | |
'type' => 'text' | |
), | |
'Ignore_Keywords' => array( | |
'description' => 'If this source provides CNAM including any of the keywords listed here, the CNAM will be ignored and other sources will be used to find the value.<br>Separate keywords with commas.', | |
'type' => 'textarea', | |
'default' => 'unavailable, unknown' | |
), | |
); | |
function get_caller_id($thenumber, $run_param=array()) { | |
$run_param['Key'] = isset($run_param['Key'])?trim($run_param['Key']):null; | |
$caller_id = null; | |
$thenumber = urlencode($thenumber); | |
$this->DebugPrint("Searching ezcnam.com ... "); | |
if ($run_param['Key'] == null) { | |
$this->DebugPrint("Lookups require account key, exiting ... "); | |
exit; | |
} | |
$url = "https://api.ezcnam.com/v1?key=".$run_param['Key']."&phone=".$thenumber."&out=text"; | |
$sname = $this->get_url_contents($url); | |
if (strlen($sname) > 1) { | |
// convert list of ignore keywords into array | |
$key_words = array(); | |
$temp_array = explode(',',(isset($run_param['Ignore_Keywords'])?$run_param['Ignore_Keywords']:$this->source_param['Ignore_Keywords']['default'])); | |
foreach($temp_array as $val) { | |
$key_words[] = trim($val); | |
} | |
// Remove all ignore keywords from the retuned CNAM string and compare the before and after. | |
$test_string = str_ireplace($key_words,'',$sname); | |
if($test_string == $sname) { | |
$caller_id = $sname; | |
$this->DebugPrint("CNAM determined good."); | |
} else { | |
$this->DebugPrint(" '$sname' contains flagged key word(s), discarding ..."); | |
} | |
} else { | |
$this->DebugPrint("CNAM not found."); | |
} | |
return($caller_id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment