Skip to content

Issue with unicode characters #313

@diplatis

Description

@diplatis

I've created the following module and the caller id returned contains wrong characters when result is not converted to greeklish ( $run_param['Convert_to_greeklish'] ) (greeklish=greek written in latin characters).
Test phone numbers: 2421026513 , 2421351000 , 2421421510

  • FreePBX: 14.0.2.14

EDIT: The issue also exists with GoogleContacts module, so I suspect there is a wider problem with unicode characters.
https://issues.freepbx.org/browse/FREEPBX-8137

`<?php

class Greece_11888 extends superfecta_base {

public $description, $source_param;
public $version_requirement = "2.11";
public $module_version = "1.10";

public $greek_chars   = array(
	'α','ά','Ά','Α','β','Β','γ', 'Γ', 'δ','Δ','ε','έ','Ε','Έ','ζ','Ζ','η','ή','Η','θ','Θ','ι','ί','ϊ','ΐ','Ι','Ί',
	'κ','Κ','λ','Λ','μ','Μ','ν','Ν','ξ','Ξ','ο','ό','Ο','Ό','π','Π','ρ','Ρ','σ','ς', 
	'Σ','τ','Τ','υ','ύ','Υ','Ύ','φ','Φ','χ','Χ','ψ','Ψ','ω','ώ','Ω','Ώ',' ',"'","'",','
);

public $english_chars = array(
	'a', 'a','A','A','b','B','g','G','d','D','e','e','E','E','z','Z','i','i','I','th','Th', 
	'i','i','i','i','I','I','k','K','l','L','m','M','n','N','x','X','o','o','O','O','p','P',
	'r','R','s','s','S','t','T','u','u','Y','Y','f','F','x','X','ps','PS','o','o','O','O',' ','_','_','_'
);

public function __construct() {
	$this->description = _("This module provides CallerID lookup from Greek 11888 website (www.11888.gr)<br/>Module Version: ".$this->module_version);
	$this->source_param = array(
        'Return_number_if_not_found' => array(
			'description' => 'Enable this setting to have the original number returned if no match is found on the website.<br/><br/><b>NOTICE</b><br/>If this is enabled superfecta cache will store the number as caller id name.',
			'type' => 'checkbox',
			'default' => 'off'
		),
		'Convert_to_greeklish' => array(
			'description' => 'Enable this setting to have the returned name converted to greeklish.',
			'type' => 'checkbox',
			'default' => 'on'
		)
	);
}

function get_caller_id($thenumber, $run_param=array()) {
	
	// Setup defaults
    $caller_id = null;
	$run_param['Return_number_if_not_found'] = isset($run_param['Return_number_if_not_found']) ? $run_param['Return_number_if_not_found'] : NULL;
	$run_param['Convert_to_greeklish'] = isset($run_param['Convert_to_greeklish']) ? $run_param['Convert_to_greeklish'] : NULL;
	
    $this->DebugPrint("Return number if not found = " . $run_param['Return_number_if_not_found']);
	$this->DebugPrint("Convert to greeklish = " . $run_param['Convert_to_greeklish']);
	
    // Strip leading GR country code 0030, +30, 30
    if (substr($thenumber, 0, 3) == '+30') {
        $thenumber=substr($thenumber, -10);
    }
    if (substr($thenumber, 0, 2) == '30') {
        $thenumber=substr($thenumber, -10);
    }
    if (substr($thenumber, 0, 4) == '0030') {
        $thenumber=substr($thenumber, -10);
    }
	
    $this->DebugPrint("Using number: ") . $thenumber;
	
	$url = 'https://www.11888.gr/search/reverse/?phone=' . $thenumber;
	$result = $this->get_url_contents($url);
	$result = json_decode($result, true);
	
	if ( array_key_exists( '0',$result['data']['wp'] ) ) {
		$caller_id = implode(" ", $result['data']['wp']['0']['name']);
	}
	else if( array_key_exists( '0',$result['data']['ps'] ) ) {
		$caller_id = $result['data']['ps']['0']['name'];
	}
	else if( !array_key_exists( '0',$result['data']['wp']) && !array_key_exists( '0',$result['data']['ps']) && !array_key_exists( '0',$result['data']['yp']) ) {
		$url = 'https://api.11888.gr/search-phone/' . $thenumber;
		$result = $this->get_url_contents($url);
		
		preg_match_all('/<div class="details">.*?class="title">(.*?)<\/a>/s', $result, $result);
		if (array_key_exists( '0',$result['1'])){
			$result=strip_tags($result[1][0]);
			$result=trim($result);
			$caller_id = $result;
		}
		else {
			if (!$run_param['Return_number_if_not_found']){
				return null;
			}
			else if ($run_param['Return_number_if_not_found']){
				$caller_id = $thenumber;
			}
		}
	}
	else {
		return null;
	}
	if ($run_param['Convert_to_greeklish']){
		$caller_id  = str_replace($this->greek_chars, $this->english_chars, $caller_id);
	}
    return($caller_id);
}

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions