hbonath / ciscospaxml

XML Scripts for Cisco SPA Phones and FreePBX/Asterisk
18 stars 6 forks source link

Modification to directory script to support Asterisk Phonebook #1

Open lgaetz opened 10 years ago

lgaetz commented 10 years ago

The block of code below is a direct drop in replacement for defining the $results array that pulls names and numbers from the Asterisk Phonebook instead of system extensions. Thinking you might use it to create a whole new Phonebook script or perhaps adapt it to some other usage.

// For this to work, the FreePBX phonebook module must be installed, not sure if there is a 
// function/method to test if specific module is installed, but this works. The bootstrap gives us 
// access to all FreePBX functions

if (function_exists('phonebook_list')) {
    $numbers = phonebook_list();
    //print_r($numbers);  //for debug
    $count = 0;
    foreach ($numbers as $num => $values)   {
        $results[$count][0] = htmlentities($values['name']);
        $results[$count][1] = $num;
        $count = $count + 1;
    }
} else {
    echo 'Requires FreePBX Phonebook module';
}
lgaetz commented 10 years ago

The following are illegal characters when returned in XML: & < > " ' There needs to be some sort of xml encode done to the data but I am not quite sure how to do that in PHP.

*edit @hbonath tm1000 suggested using htmlentities. Code above amended to include

hbonath commented 10 years ago

Thanks Lorne, are you suggesting that if the Phonebook entry has one of those characters, then there will be a problem?

lgaetz commented 10 years ago

Confirmed. If the Phonebook name includes an & or other special character, it will throw an error. Wrapping the var in htmlentities as now shown above should fix.