Skip to content

Instantly share code, notes, and snippets.

@moos3
Last active December 26, 2015 19:39
Show Gist options
  • Select an option

  • Save moos3/7202577 to your computer and use it in GitHub Desktop.

Select an option

Save moos3/7202577 to your computer and use it in GitHub Desktop.
<?php
require_once('./EventSocketLayer.php');
/**
* Create ESL Socket and send command to API
*/
function eslCommand($command) {
$esl = new ESLconnection(FS_ESL_HOST, FS_ESL_PORT, FS_ESL_PASSWORD);
$e = $esl->api($command);
if (is_object($e)) {
return $e->getBody();
}
$esl->disconnect();
}
/**
* Parse ESL Command Output
**/
function eslParser($input) {
$i = 0;
$lines = explode("\n",$input);
foreach ($lines as $line) {
$data[$i++] = explode('|',$line);
}
if (count($data) > 1){
$i = 0;
$keys = $data[0];
foreach($data as $points){
if (count($keys) == count($points)){
if ($keys !== $points){
$output[$i++] = array_combine($keys,$points);
}
}
}
}
return $output;
}
/**
* Create User Extension
**/
function createExtension($data){
global $access_key;
if ($data['access_key'] == $access_key){
if (!file_exists(FS_CONF_DIR.'/directory/'.FS_DOMAIN.'/'.$data['user_id'].'.xml')){
$xmlw = new XMLWriter();
$xmlw->openURI(FS_CONF_DIR.'/directory/'.FS_DOMAIN.'/'.$data['user_id'].'.xml');
$xmlw->setIndent(true);
$xmlw->startElement('include');
$xmlw->startElement('user');
$xmlw->writeAttribute('id', $data['user_id']);
$xmlw->startElement ( 'params' );
foreach($data['params'] as $pname => $pvalue){
$xmlw->startElement('param');
$xmlw->writeAttribute('name', $pname);
$xmlw->writeAttribute('value', $pvalue);
$xmlw->endElement();
}
$xmlw->endElement();
$xmlw->startElement ( 'variables' );
foreach( $data['variables'] as $vname => $vvalue) {
$xmlw->startElement('variable');
$xmlw->writeAttribute('name', $vname);
$xmlw->writeAttribute('value', $vvalue);
$xmlw->endElement();
}
$xmlw->endElement();
$xmlw->endElement();
$xmlw->endElement();
$xmlw->flush();
if (isset($data['action'])) {
eslCommand($data['action']);
}
return true;
} else {
return false;
}
} else {
return "Bad Access Key";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment