mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
\r\n --> \n
Cause all the .php files containing lines ending with \r\n to instead end with \n.
DYI with:
find fusionpbx -type f -name '*.php' -exec dos2unix '{}' \;
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,139 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* cache class provides an abstracted cache
|
||||
*
|
||||
* @method string set
|
||||
* @method string get
|
||||
* @method string delete
|
||||
* @method string flush
|
||||
*/
|
||||
class cache {
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//place holder
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a specific item in the cache
|
||||
* @var string $key the cache id
|
||||
* @var string $value string to be cached
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
// connect to event socket
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//send a custom event
|
||||
|
||||
//run the memcache
|
||||
$command = "memcache set ".$key." ".$value;
|
||||
$result = event_socket_request($fp, 'api '.$command);
|
||||
|
||||
//close event socket
|
||||
fclose($fp);
|
||||
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific item from the cache
|
||||
* @var string $key cache id
|
||||
*/
|
||||
public function get($key) {
|
||||
// connect to event socket
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//send a custom event
|
||||
|
||||
//run the memcache
|
||||
$command = "memcache get ".$key;
|
||||
$result = event_socket_request($fp, 'api '.$command);
|
||||
|
||||
//close event socket
|
||||
fclose($fp);
|
||||
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific item from the cache
|
||||
* @var string $key cache id
|
||||
*/
|
||||
public function delete($key) {
|
||||
// connect to event socket
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//send a custom event
|
||||
$event = "sendevent CUSTOM\n";
|
||||
$event .= "Event-Name: MEMCACHE\n";
|
||||
$event .= "Event-Subclass: delete\n";
|
||||
$event .= "API-Command: memcache\n";
|
||||
$event .= "API-Command-Argument: delete ".$key."\n";
|
||||
event_socket_request($fp, $event);
|
||||
|
||||
//run the memcache
|
||||
$command = "memcache delete ".$key;
|
||||
$result = event_socket_request($fp, 'api '.$command);
|
||||
|
||||
//close event socket
|
||||
fclose($fp);
|
||||
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the entire cache
|
||||
*/
|
||||
public function flush() {
|
||||
// connect to event socket
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//send a custom event
|
||||
$event = "sendevent CUSTOM\n";
|
||||
$event .= "Event-Name: MEMCACHE\n";
|
||||
$event .= "Event-Subclass: flush\n";
|
||||
$event .= "API-Command: memcache\n";
|
||||
$event .= "API-Command-Argument: flush\n";
|
||||
event_socket_request($fp, $event);
|
||||
|
||||
//run the memcache
|
||||
$command = "memcache flush";
|
||||
$result = event_socket_request($fp, 'api '.$command);
|
||||
|
||||
//close event socket
|
||||
fclose($fp);
|
||||
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* cache class provides an abstracted cache
|
||||
*
|
||||
* @method string set
|
||||
* @method string get
|
||||
* @method string delete
|
||||
* @method string flush
|
||||
*/
|
||||
class cache {
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//place holder
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a specific item in the cache
|
||||
* @var string $key the cache id
|
||||
* @var string $value string to be cached
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
// connect to event socket
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//send a custom event
|
||||
|
||||
//run the memcache
|
||||
$command = "memcache set ".$key." ".$value;
|
||||
$result = event_socket_request($fp, 'api '.$command);
|
||||
|
||||
//close event socket
|
||||
fclose($fp);
|
||||
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific item from the cache
|
||||
* @var string $key cache id
|
||||
*/
|
||||
public function get($key) {
|
||||
// connect to event socket
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//send a custom event
|
||||
|
||||
//run the memcache
|
||||
$command = "memcache get ".$key;
|
||||
$result = event_socket_request($fp, 'api '.$command);
|
||||
|
||||
//close event socket
|
||||
fclose($fp);
|
||||
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific item from the cache
|
||||
* @var string $key cache id
|
||||
*/
|
||||
public function delete($key) {
|
||||
// connect to event socket
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//send a custom event
|
||||
$event = "sendevent CUSTOM\n";
|
||||
$event .= "Event-Name: MEMCACHE\n";
|
||||
$event .= "Event-Subclass: delete\n";
|
||||
$event .= "API-Command: memcache\n";
|
||||
$event .= "API-Command-Argument: delete ".$key."\n";
|
||||
event_socket_request($fp, $event);
|
||||
|
||||
//run the memcache
|
||||
$command = "memcache delete ".$key;
|
||||
$result = event_socket_request($fp, 'api '.$command);
|
||||
|
||||
//close event socket
|
||||
fclose($fp);
|
||||
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the entire cache
|
||||
*/
|
||||
public function flush() {
|
||||
// connect to event socket
|
||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||
if ($fp === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//send a custom event
|
||||
$event = "sendevent CUSTOM\n";
|
||||
$event .= "Event-Name: MEMCACHE\n";
|
||||
$event .= "Event-Subclass: flush\n";
|
||||
$event .= "API-Command: memcache\n";
|
||||
$event .= "API-Command-Argument: flush\n";
|
||||
event_socket_request($fp, $event);
|
||||
|
||||
//run the memcache
|
||||
$command = "memcache flush";
|
||||
$result = event_socket_request($fp, 'api '.$command);
|
||||
|
||||
//close event socket
|
||||
fclose($fp);
|
||||
|
||||
// return result
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,127 +1,127 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* config
|
||||
*
|
||||
* @method get config.php
|
||||
* @method find find the path to the config.php file
|
||||
* @method exists determin if the the config.php file exists
|
||||
*/
|
||||
class config {
|
||||
|
||||
/**
|
||||
* database variables and config path
|
||||
*/
|
||||
public $db_type;
|
||||
public $db_name;
|
||||
public $db_username;
|
||||
public $db_password;
|
||||
public $db_host;
|
||||
public $db_path;
|
||||
public $db_port;
|
||||
public $config_path;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//place holder
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the config.php exists
|
||||
* @var string $db_type - type of database
|
||||
* @var string $db_name - name of the database
|
||||
* @var string $db_username - username to access the database
|
||||
* @var string $db_password - password to access the database
|
||||
* @var string $db_host - hostname of the database server
|
||||
* @var string $db_path - path of the database file
|
||||
* @var string $db_port - network port to connect to the database
|
||||
*/
|
||||
public function get() {
|
||||
$this->find();
|
||||
if ($this->exists()) {
|
||||
require $this->config_path;
|
||||
$this->db_type = $db_type;
|
||||
$this->db_name = $db_name;
|
||||
$this->db_username = $db_username;
|
||||
$this->db_password = $db_password;
|
||||
$this->db_host = $db_host;
|
||||
$this->db_path = $db_path;
|
||||
$this->db_port = $db_port;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the path to the config.php
|
||||
* @var string $config_path - full path to the config.php file
|
||||
*/
|
||||
public function find() {
|
||||
//get the PROJECT PATH
|
||||
include "root.php";
|
||||
// find the file
|
||||
if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
|
||||
$this->config_path = $_SERVER["PROJECT_ROOT"]."/resources/config.php";
|
||||
} elseif (file_exists("/etc/fusionpbx/config.php")) {
|
||||
$this->config_path = "/etc/fusionpbx/config.php";
|
||||
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
|
||||
$this->config_path = "/usr/local/etc/fusionpbx/config.php";
|
||||
}
|
||||
else {
|
||||
$this->config_path = '';
|
||||
}
|
||||
//return the path
|
||||
return $this->config_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the config.php exists
|
||||
*/
|
||||
public function exists() {
|
||||
$this->find();
|
||||
if (strlen($this->config_path) > 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
$config = new config;
|
||||
$config_exists = $config->exists();
|
||||
$config_path = $config->find();
|
||||
$config->get();
|
||||
$db_type = $config->db_type;
|
||||
$db_name = $config->db_name;
|
||||
$db_username = $config->db_username;
|
||||
$db_password = $config->db_password;
|
||||
$db_host = $config->db_host;
|
||||
$db_path = $config->db_path;
|
||||
$db_port = $config->db_port;
|
||||
echo "config_path: ".$config_path."\n";
|
||||
if ($config_exists) {
|
||||
echo "config_exists: true\n";
|
||||
} else {
|
||||
echo "config_exists: false\n";
|
||||
}
|
||||
echo "db_type: ".$db_type."\n";
|
||||
echo "db_name: ".$db_name."\n";
|
||||
echo "db_username: ".$db_username."\n";
|
||||
echo "db_password: ".$db_password."\n";
|
||||
echo "db_host: ".$db_host."\n";
|
||||
echo "db_path: ".$db_path."\n";
|
||||
echo "db_port: ".$db_port."\n";
|
||||
*/
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* config
|
||||
*
|
||||
* @method get config.php
|
||||
* @method find find the path to the config.php file
|
||||
* @method exists determin if the the config.php file exists
|
||||
*/
|
||||
class config {
|
||||
|
||||
/**
|
||||
* database variables and config path
|
||||
*/
|
||||
public $db_type;
|
||||
public $db_name;
|
||||
public $db_username;
|
||||
public $db_password;
|
||||
public $db_host;
|
||||
public $db_path;
|
||||
public $db_port;
|
||||
public $config_path;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//place holder
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the config.php exists
|
||||
* @var string $db_type - type of database
|
||||
* @var string $db_name - name of the database
|
||||
* @var string $db_username - username to access the database
|
||||
* @var string $db_password - password to access the database
|
||||
* @var string $db_host - hostname of the database server
|
||||
* @var string $db_path - path of the database file
|
||||
* @var string $db_port - network port to connect to the database
|
||||
*/
|
||||
public function get() {
|
||||
$this->find();
|
||||
if ($this->exists()) {
|
||||
require $this->config_path;
|
||||
$this->db_type = $db_type;
|
||||
$this->db_name = $db_name;
|
||||
$this->db_username = $db_username;
|
||||
$this->db_password = $db_password;
|
||||
$this->db_host = $db_host;
|
||||
$this->db_path = $db_path;
|
||||
$this->db_port = $db_port;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the path to the config.php
|
||||
* @var string $config_path - full path to the config.php file
|
||||
*/
|
||||
public function find() {
|
||||
//get the PROJECT PATH
|
||||
include "root.php";
|
||||
// find the file
|
||||
if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
|
||||
$this->config_path = $_SERVER["PROJECT_ROOT"]."/resources/config.php";
|
||||
} elseif (file_exists("/etc/fusionpbx/config.php")) {
|
||||
$this->config_path = "/etc/fusionpbx/config.php";
|
||||
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
|
||||
$this->config_path = "/usr/local/etc/fusionpbx/config.php";
|
||||
}
|
||||
else {
|
||||
$this->config_path = '';
|
||||
}
|
||||
//return the path
|
||||
return $this->config_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the config.php exists
|
||||
*/
|
||||
public function exists() {
|
||||
$this->find();
|
||||
if (strlen($this->config_path) > 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
$config = new config;
|
||||
$config_exists = $config->exists();
|
||||
$config_path = $config->find();
|
||||
$config->get();
|
||||
$db_type = $config->db_type;
|
||||
$db_name = $config->db_name;
|
||||
$db_username = $config->db_username;
|
||||
$db_password = $config->db_password;
|
||||
$db_host = $config->db_host;
|
||||
$db_path = $config->db_path;
|
||||
$db_port = $config->db_port;
|
||||
echo "config_path: ".$config_path."\n";
|
||||
if ($config_exists) {
|
||||
echo "config_exists: true\n";
|
||||
} else {
|
||||
echo "config_exists: false\n";
|
||||
}
|
||||
echo "db_type: ".$db_type."\n";
|
||||
echo "db_name: ".$db_name."\n";
|
||||
echo "db_username: ".$db_username."\n";
|
||||
echo "db_password: ".$db_password."\n";
|
||||
echo "db_host: ".$db_host."\n";
|
||||
echo "db_path: ".$db_path."\n";
|
||||
echo "db_port: ".$db_port."\n";
|
||||
*/
|
||||
|
||||
?>
|
||||
@@ -1,280 +1,280 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* destinations
|
||||
*
|
||||
* @method get_array get the destinations
|
||||
* @method select build the html select
|
||||
*/
|
||||
class destinations {
|
||||
|
||||
/**
|
||||
* destinations array
|
||||
*/
|
||||
public $destinations;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//set the global variables
|
||||
global $db, $db_type;
|
||||
|
||||
//get the array from the app_config.php files
|
||||
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
||||
$x = 0;
|
||||
foreach ($config_list as &$config_path) {
|
||||
include($config_path);
|
||||
$x++;
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($apps as $x => &$app) {
|
||||
if (isset($app['destinations'])) foreach ($app['destinations'] as &$row) {
|
||||
$this->destinations[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
//put the array in order
|
||||
foreach ($this->destinations as $row) {
|
||||
$option_groups[] = $row['label'];
|
||||
}
|
||||
array_multisort($option_groups, SORT_ASC, $this->destinations);
|
||||
|
||||
//add the sql and data to the array
|
||||
$x = 0;
|
||||
foreach ($this->destinations as $row) {
|
||||
if ($row['type'] = 'sql') {
|
||||
if (isset($row['sql'])) {
|
||||
if (is_array($row['sql'])) {
|
||||
$sql = trim($row['sql'][$db_type])." ";
|
||||
}
|
||||
else {
|
||||
$sql = trim($row['sql'])." ";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$field_count = count($row['field']);
|
||||
$fields = '';
|
||||
$c = 1;
|
||||
foreach ($row['field'] as $key => $value) {
|
||||
if ($field_count != $c) { $delimiter = ','; } else { $delimiter = ''; }
|
||||
$fields .= $value." as ".$key.$delimiter." ";
|
||||
$c++;
|
||||
}
|
||||
$sql = "select ".$fields;
|
||||
$sql .= " from v_".$row['name']." ";
|
||||
}
|
||||
if (isset($row['where'])) {
|
||||
$sql .= trim($row['where'])." ";
|
||||
}
|
||||
$sql .= "order by ".trim($row['order_by']);
|
||||
$sql = str_replace("\${domain_uuid}", $_SESSION['domain_uuid'], $sql);
|
||||
$sql = trim($sql);
|
||||
$statement = $db->prepare($sql);
|
||||
$statement->execute();
|
||||
$result = $statement->fetchAll(PDO::FETCH_NAMED);
|
||||
unset($statement);
|
||||
|
||||
$this->destinations[$x]['result']['sql'] = $sql;
|
||||
$this->destinations[$x]['result']['data'] = $result;
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
$this->destinations[$x]['type'] = 'array';
|
||||
$this->destinations[$x]['label'] = 'other';
|
||||
$this->destinations[$x]['name'] = 'dialplan';
|
||||
$this->destinations[$x]['field']['name'] = "name";
|
||||
$this->destinations[$x]['field']['destination'] = "destination";
|
||||
$this->destinations[$x]['select_value']['dialplan'] = "transfer:\${destination}";
|
||||
$this->destinations[$x]['select_value']['ivr'] = "menu-exec-app:transfer \${destination}";
|
||||
$this->destinations[$x]['select_label'] = "\${name}";
|
||||
$y = 0;
|
||||
$this->destinations[$x]['result']['data'][$y]['label'] = 'check_voicemail';
|
||||
$this->destinations[$x]['result']['data'][$y]['name'] = '*98';
|
||||
$this->destinations[$x]['result']['data'][$y]['destination'] = '*98 XML ${context}';
|
||||
$y++;
|
||||
$this->destinations[$x]['result']['data'][$y]['label'] = 'company_directory';
|
||||
$this->destinations[$x]['result']['data'][$y]['name'] = '*411';
|
||||
$this->destinations[$x]['result']['data'][$y]['destination'] = '*411 XML ${context}';
|
||||
$y++;
|
||||
$this->destinations[$x]['result']['data'][$y]['label'] = 'hangup';
|
||||
$this->destinations[$x]['result']['data'][$y]['name'] = 'hangup';
|
||||
$this->destinations[$x]['result']['data'][$y]['application'] = 'hangup';
|
||||
$this->destinations[$x]['result']['data'][$y]['destination'] = '';
|
||||
$y++;
|
||||
$this->destinations[$x]['result']['data'][$y]['label'] = 'record';
|
||||
$this->destinations[$x]['result']['data'][$y]['name'] = '*732';
|
||||
$this->destinations[$x]['result']['data'][$y]['destination'] = '*732 XML ${context}';
|
||||
$y++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination menu
|
||||
* @var string $destination_type can be ivr, dialplan, call_center_contact or bridge
|
||||
* @var string $destination_name - current name
|
||||
* @var string $destination_value - current value
|
||||
*/
|
||||
public function select($destination_type, $destination_name, $destination_value) {
|
||||
|
||||
//remove special characters from the name
|
||||
$destination_id = str_replace("]", "", $destination_name);
|
||||
$destination_id = str_replace("[", "_", $destination_id);
|
||||
|
||||
//add additional
|
||||
if (if_group("superadmin")) {
|
||||
$response = "<script>\n";
|
||||
$response .= "var Objs;\n";
|
||||
$response .= "\n";
|
||||
$response .= "function changeToInput".$destination_id."(obj){\n";
|
||||
$response .= " tb=document.createElement('INPUT');\n";
|
||||
$response .= " tb.type='text';\n";
|
||||
$response .= " tb.name=obj.name;\n";
|
||||
$response .= " tb.className='formfld';\n";
|
||||
$response .= " tb.setAttribute('id', '".$destination_id."');\n";
|
||||
$response .= " tb.setAttribute('style', '".$select_style."');\n";
|
||||
if ($onchange != '') {
|
||||
$response .= " tb.setAttribute('onchange', \"".$onchange."\");\n";
|
||||
$response .= " tb.setAttribute('onkeyup', \"".$onchange."\");\n";
|
||||
}
|
||||
$response .= " tb.value=obj.options[obj.selectedIndex].value;\n";
|
||||
$response .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'hidden';\n";
|
||||
$response .= " tbb=document.createElement('INPUT');\n";
|
||||
$response .= " tbb.setAttribute('class', 'btn');\n";
|
||||
$response .= " tbb.setAttribute('style', 'margin-left: 4px;');\n";
|
||||
$response .= " tbb.type='button';\n";
|
||||
$response .= " tbb.value=$('<div />').html('◁').text();\n";
|
||||
$response .= " tbb.objs=[obj,tb,tbb];\n";
|
||||
$response .= " tbb.onclick=function(){ Replace".$destination_id."(this.objs); }\n";
|
||||
$response .= " obj.parentNode.insertBefore(tb,obj);\n";
|
||||
$response .= " obj.parentNode.insertBefore(tbb,obj);\n";
|
||||
$response .= " obj.parentNode.removeChild(obj);\n";
|
||||
$response .= " Replace".$destination_id."(this.objs);\n";
|
||||
$response .= "}\n";
|
||||
$response .= "\n";
|
||||
$response .= "function Replace".$destination_id."(obj){\n";
|
||||
$response .= " obj[2].parentNode.insertBefore(obj[0],obj[2]);\n";
|
||||
$response .= " obj[0].parentNode.removeChild(obj[1]);\n";
|
||||
$response .= " obj[0].parentNode.removeChild(obj[2]);\n";
|
||||
$response .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n";
|
||||
if ($onchange != '') {
|
||||
$response .= " ".$onchange.";\n";
|
||||
}
|
||||
$response .= "}\n";
|
||||
$response .= "</script>\n";
|
||||
$response .= "\n";
|
||||
}
|
||||
|
||||
//set default to false
|
||||
$select_found = false;
|
||||
|
||||
$response .= " <select name='".$destination_name."' id='".$destination_id."' class='formfld' style='".$select_style."' onchange=\"".$onchange."\">\n";
|
||||
$response .= " <option value=''></option>\n";
|
||||
foreach ($this->destinations as $row) {
|
||||
|
||||
$name = $row['name'];
|
||||
$label = $row['label'];
|
||||
$destination = $row['field']['destination'];
|
||||
|
||||
//add multi-lingual support
|
||||
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) {
|
||||
$language2 = new text;
|
||||
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name);
|
||||
}
|
||||
|
||||
if (count($row['result']['data']) > 0 and strlen($row['select_value'][$destination_type]) > 0) {
|
||||
$response .= " <optgroup label='".$text2['title-'.$label]."'>\n";
|
||||
$label2 = $label;
|
||||
foreach ($row['result']['data'] as $data) {
|
||||
$select_value = $row['select_value'][$destination_type];
|
||||
$select_label = $row['select_label'];
|
||||
foreach ($row['field'] as $key => $value) {
|
||||
if ($key == 'destination' and is_array($value)){
|
||||
if ($value['type'] == 'csv') {
|
||||
$array = explode($value['delimiter'], $data[$key]);
|
||||
$select_value = str_replace("\${destination}", $array[0], $select_value);
|
||||
$select_label = str_replace("\${destination}", $array[0], $select_label);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (strpos($value,',') !== false) {
|
||||
$keys = explode(",", $value);
|
||||
foreach ($keys as $k) {
|
||||
if (strlen($data[$k]) > 0) {
|
||||
$select_value = str_replace("\${".$key."}", $data[$k], $select_value);
|
||||
if (strlen($data['label']) == 0) {
|
||||
$select_label = str_replace("\${".$key."}", $data[$k], $select_label);
|
||||
}
|
||||
else {
|
||||
$label = $data['label'];
|
||||
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$select_value = str_replace("\${".$key."}", $data[$key], $select_value);
|
||||
if (strlen($data['label']) == 0) {
|
||||
$select_label = str_replace("\${".$key."}", $data[$key], $select_label);
|
||||
}
|
||||
else {
|
||||
$label = $data['label'];
|
||||
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
||||
}
|
||||
}
|
||||
//application: hangup
|
||||
if (strlen($data['application']) > 0) {
|
||||
$select_value = str_replace("transfer", $data['application'], $select_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$select_value = str_replace("\${domain_name}", $_SESSION['domain_name'], $select_value);
|
||||
$select_value = str_replace("\${context}", $_SESSION['context'], $select_value); //to do: context can come from the array
|
||||
$select_label = str_replace("\${domain_name}", $_SESSION['domain_name'], $select_label);
|
||||
$select_label = str_replace("\${context}", $_SESSION['context'], $select_label);
|
||||
$select_label = trim($select_label);
|
||||
if ($select_value == $destination_value) { $selected = "selected='selected' "; $select_found = true; } else { $selected = ''; }
|
||||
if ($label2 == 'destinations') { $select_label = format_phone($select_label); }
|
||||
$response .= " <option value='".$select_value."' ".$selected.">".$select_label."</option>\n";
|
||||
}
|
||||
$response .= " </optgroup>\n";
|
||||
unset($text);
|
||||
}
|
||||
}
|
||||
if (!$select_found) {
|
||||
$destination_label = str_replace(":", " ", $destination_value);
|
||||
$destination_label = str_replace("menu-exec-app:", " ", $destination_label);
|
||||
$response .= " <option value='".$destination_value."' selected='selected'>".trim($destination_label)."</option>\n";
|
||||
}
|
||||
$response .= " </select>\n";
|
||||
if (if_group("superadmin")) {
|
||||
$response .= "<input type='button' id='btn_select_to_input_".$destination_id."' class='btn' name='' alt='back' onclick='changeToInput".$destination_id."(document.getElementById(\"".$destination_id."\"));this.style.visibility = \"hidden\";' value='◁'>";
|
||||
}
|
||||
|
||||
//return the formatted destinations
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
/*
|
||||
$obj = new destinations;
|
||||
//$destinations = $obj->destinations;
|
||||
echo $obj->select('ivr', 'example1', 'menu-exec-app:transfer 32 XML voip.fusionpbx.com');
|
||||
echo $obj->select('ivr', 'example2', '');
|
||||
echo $obj->select('ivr', 'example3', '');
|
||||
echo $obj->select('ivr', 'example4', '');
|
||||
echo $obj->select('ivr', 'example5', '');
|
||||
echo $obj->select('ivr', 'example6', '');
|
||||
*/
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* destinations
|
||||
*
|
||||
* @method get_array get the destinations
|
||||
* @method select build the html select
|
||||
*/
|
||||
class destinations {
|
||||
|
||||
/**
|
||||
* destinations array
|
||||
*/
|
||||
public $destinations;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//set the global variables
|
||||
global $db, $db_type;
|
||||
|
||||
//get the array from the app_config.php files
|
||||
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
||||
$x = 0;
|
||||
foreach ($config_list as &$config_path) {
|
||||
include($config_path);
|
||||
$x++;
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($apps as $x => &$app) {
|
||||
if (isset($app['destinations'])) foreach ($app['destinations'] as &$row) {
|
||||
$this->destinations[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
//put the array in order
|
||||
foreach ($this->destinations as $row) {
|
||||
$option_groups[] = $row['label'];
|
||||
}
|
||||
array_multisort($option_groups, SORT_ASC, $this->destinations);
|
||||
|
||||
//add the sql and data to the array
|
||||
$x = 0;
|
||||
foreach ($this->destinations as $row) {
|
||||
if ($row['type'] = 'sql') {
|
||||
if (isset($row['sql'])) {
|
||||
if (is_array($row['sql'])) {
|
||||
$sql = trim($row['sql'][$db_type])." ";
|
||||
}
|
||||
else {
|
||||
$sql = trim($row['sql'])." ";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$field_count = count($row['field']);
|
||||
$fields = '';
|
||||
$c = 1;
|
||||
foreach ($row['field'] as $key => $value) {
|
||||
if ($field_count != $c) { $delimiter = ','; } else { $delimiter = ''; }
|
||||
$fields .= $value." as ".$key.$delimiter." ";
|
||||
$c++;
|
||||
}
|
||||
$sql = "select ".$fields;
|
||||
$sql .= " from v_".$row['name']." ";
|
||||
}
|
||||
if (isset($row['where'])) {
|
||||
$sql .= trim($row['where'])." ";
|
||||
}
|
||||
$sql .= "order by ".trim($row['order_by']);
|
||||
$sql = str_replace("\${domain_uuid}", $_SESSION['domain_uuid'], $sql);
|
||||
$sql = trim($sql);
|
||||
$statement = $db->prepare($sql);
|
||||
$statement->execute();
|
||||
$result = $statement->fetchAll(PDO::FETCH_NAMED);
|
||||
unset($statement);
|
||||
|
||||
$this->destinations[$x]['result']['sql'] = $sql;
|
||||
$this->destinations[$x]['result']['data'] = $result;
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
$this->destinations[$x]['type'] = 'array';
|
||||
$this->destinations[$x]['label'] = 'other';
|
||||
$this->destinations[$x]['name'] = 'dialplan';
|
||||
$this->destinations[$x]['field']['name'] = "name";
|
||||
$this->destinations[$x]['field']['destination'] = "destination";
|
||||
$this->destinations[$x]['select_value']['dialplan'] = "transfer:\${destination}";
|
||||
$this->destinations[$x]['select_value']['ivr'] = "menu-exec-app:transfer \${destination}";
|
||||
$this->destinations[$x]['select_label'] = "\${name}";
|
||||
$y = 0;
|
||||
$this->destinations[$x]['result']['data'][$y]['label'] = 'check_voicemail';
|
||||
$this->destinations[$x]['result']['data'][$y]['name'] = '*98';
|
||||
$this->destinations[$x]['result']['data'][$y]['destination'] = '*98 XML ${context}';
|
||||
$y++;
|
||||
$this->destinations[$x]['result']['data'][$y]['label'] = 'company_directory';
|
||||
$this->destinations[$x]['result']['data'][$y]['name'] = '*411';
|
||||
$this->destinations[$x]['result']['data'][$y]['destination'] = '*411 XML ${context}';
|
||||
$y++;
|
||||
$this->destinations[$x]['result']['data'][$y]['label'] = 'hangup';
|
||||
$this->destinations[$x]['result']['data'][$y]['name'] = 'hangup';
|
||||
$this->destinations[$x]['result']['data'][$y]['application'] = 'hangup';
|
||||
$this->destinations[$x]['result']['data'][$y]['destination'] = '';
|
||||
$y++;
|
||||
$this->destinations[$x]['result']['data'][$y]['label'] = 'record';
|
||||
$this->destinations[$x]['result']['data'][$y]['name'] = '*732';
|
||||
$this->destinations[$x]['result']['data'][$y]['destination'] = '*732 XML ${context}';
|
||||
$y++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination menu
|
||||
* @var string $destination_type can be ivr, dialplan, call_center_contact or bridge
|
||||
* @var string $destination_name - current name
|
||||
* @var string $destination_value - current value
|
||||
*/
|
||||
public function select($destination_type, $destination_name, $destination_value) {
|
||||
|
||||
//remove special characters from the name
|
||||
$destination_id = str_replace("]", "", $destination_name);
|
||||
$destination_id = str_replace("[", "_", $destination_id);
|
||||
|
||||
//add additional
|
||||
if (if_group("superadmin")) {
|
||||
$response = "<script>\n";
|
||||
$response .= "var Objs;\n";
|
||||
$response .= "\n";
|
||||
$response .= "function changeToInput".$destination_id."(obj){\n";
|
||||
$response .= " tb=document.createElement('INPUT');\n";
|
||||
$response .= " tb.type='text';\n";
|
||||
$response .= " tb.name=obj.name;\n";
|
||||
$response .= " tb.className='formfld';\n";
|
||||
$response .= " tb.setAttribute('id', '".$destination_id."');\n";
|
||||
$response .= " tb.setAttribute('style', '".$select_style."');\n";
|
||||
if ($onchange != '') {
|
||||
$response .= " tb.setAttribute('onchange', \"".$onchange."\");\n";
|
||||
$response .= " tb.setAttribute('onkeyup', \"".$onchange."\");\n";
|
||||
}
|
||||
$response .= " tb.value=obj.options[obj.selectedIndex].value;\n";
|
||||
$response .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'hidden';\n";
|
||||
$response .= " tbb=document.createElement('INPUT');\n";
|
||||
$response .= " tbb.setAttribute('class', 'btn');\n";
|
||||
$response .= " tbb.setAttribute('style', 'margin-left: 4px;');\n";
|
||||
$response .= " tbb.type='button';\n";
|
||||
$response .= " tbb.value=$('<div />').html('◁').text();\n";
|
||||
$response .= " tbb.objs=[obj,tb,tbb];\n";
|
||||
$response .= " tbb.onclick=function(){ Replace".$destination_id."(this.objs); }\n";
|
||||
$response .= " obj.parentNode.insertBefore(tb,obj);\n";
|
||||
$response .= " obj.parentNode.insertBefore(tbb,obj);\n";
|
||||
$response .= " obj.parentNode.removeChild(obj);\n";
|
||||
$response .= " Replace".$destination_id."(this.objs);\n";
|
||||
$response .= "}\n";
|
||||
$response .= "\n";
|
||||
$response .= "function Replace".$destination_id."(obj){\n";
|
||||
$response .= " obj[2].parentNode.insertBefore(obj[0],obj[2]);\n";
|
||||
$response .= " obj[0].parentNode.removeChild(obj[1]);\n";
|
||||
$response .= " obj[0].parentNode.removeChild(obj[2]);\n";
|
||||
$response .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n";
|
||||
if ($onchange != '') {
|
||||
$response .= " ".$onchange.";\n";
|
||||
}
|
||||
$response .= "}\n";
|
||||
$response .= "</script>\n";
|
||||
$response .= "\n";
|
||||
}
|
||||
|
||||
//set default to false
|
||||
$select_found = false;
|
||||
|
||||
$response .= " <select name='".$destination_name."' id='".$destination_id."' class='formfld' style='".$select_style."' onchange=\"".$onchange."\">\n";
|
||||
$response .= " <option value=''></option>\n";
|
||||
foreach ($this->destinations as $row) {
|
||||
|
||||
$name = $row['name'];
|
||||
$label = $row['label'];
|
||||
$destination = $row['field']['destination'];
|
||||
|
||||
//add multi-lingual support
|
||||
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) {
|
||||
$language2 = new text;
|
||||
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name);
|
||||
}
|
||||
|
||||
if (count($row['result']['data']) > 0 and strlen($row['select_value'][$destination_type]) > 0) {
|
||||
$response .= " <optgroup label='".$text2['title-'.$label]."'>\n";
|
||||
$label2 = $label;
|
||||
foreach ($row['result']['data'] as $data) {
|
||||
$select_value = $row['select_value'][$destination_type];
|
||||
$select_label = $row['select_label'];
|
||||
foreach ($row['field'] as $key => $value) {
|
||||
if ($key == 'destination' and is_array($value)){
|
||||
if ($value['type'] == 'csv') {
|
||||
$array = explode($value['delimiter'], $data[$key]);
|
||||
$select_value = str_replace("\${destination}", $array[0], $select_value);
|
||||
$select_label = str_replace("\${destination}", $array[0], $select_label);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (strpos($value,',') !== false) {
|
||||
$keys = explode(",", $value);
|
||||
foreach ($keys as $k) {
|
||||
if (strlen($data[$k]) > 0) {
|
||||
$select_value = str_replace("\${".$key."}", $data[$k], $select_value);
|
||||
if (strlen($data['label']) == 0) {
|
||||
$select_label = str_replace("\${".$key."}", $data[$k], $select_label);
|
||||
}
|
||||
else {
|
||||
$label = $data['label'];
|
||||
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$select_value = str_replace("\${".$key."}", $data[$key], $select_value);
|
||||
if (strlen($data['label']) == 0) {
|
||||
$select_label = str_replace("\${".$key."}", $data[$key], $select_label);
|
||||
}
|
||||
else {
|
||||
$label = $data['label'];
|
||||
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
||||
}
|
||||
}
|
||||
//application: hangup
|
||||
if (strlen($data['application']) > 0) {
|
||||
$select_value = str_replace("transfer", $data['application'], $select_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$select_value = str_replace("\${domain_name}", $_SESSION['domain_name'], $select_value);
|
||||
$select_value = str_replace("\${context}", $_SESSION['context'], $select_value); //to do: context can come from the array
|
||||
$select_label = str_replace("\${domain_name}", $_SESSION['domain_name'], $select_label);
|
||||
$select_label = str_replace("\${context}", $_SESSION['context'], $select_label);
|
||||
$select_label = trim($select_label);
|
||||
if ($select_value == $destination_value) { $selected = "selected='selected' "; $select_found = true; } else { $selected = ''; }
|
||||
if ($label2 == 'destinations') { $select_label = format_phone($select_label); }
|
||||
$response .= " <option value='".$select_value."' ".$selected.">".$select_label."</option>\n";
|
||||
}
|
||||
$response .= " </optgroup>\n";
|
||||
unset($text);
|
||||
}
|
||||
}
|
||||
if (!$select_found) {
|
||||
$destination_label = str_replace(":", " ", $destination_value);
|
||||
$destination_label = str_replace("menu-exec-app:", " ", $destination_label);
|
||||
$response .= " <option value='".$destination_value."' selected='selected'>".trim($destination_label)."</option>\n";
|
||||
}
|
||||
$response .= " </select>\n";
|
||||
if (if_group("superadmin")) {
|
||||
$response .= "<input type='button' id='btn_select_to_input_".$destination_id."' class='btn' name='' alt='back' onclick='changeToInput".$destination_id."(document.getElementById(\"".$destination_id."\"));this.style.visibility = \"hidden\";' value='◁'>";
|
||||
}
|
||||
|
||||
//return the formatted destinations
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
/*
|
||||
$obj = new destinations;
|
||||
//$destinations = $obj->destinations;
|
||||
echo $obj->select('ivr', 'example1', 'menu-exec-app:transfer 32 XML voip.fusionpbx.com');
|
||||
echo $obj->select('ivr', 'example2', '');
|
||||
echo $obj->select('ivr', 'example3', '');
|
||||
echo $obj->select('ivr', 'example4', '');
|
||||
echo $obj->select('ivr', 'example5', '');
|
||||
echo $obj->select('ivr', 'example6', '');
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,195 +1,195 @@
|
||||
<?php
|
||||
|
||||
class buffer {
|
||||
private $content;
|
||||
private $eol;
|
||||
|
||||
public function __construct() {
|
||||
$this->content = '';
|
||||
$this->eol = "\n";
|
||||
}
|
||||
|
||||
public function append($str) {
|
||||
$this->content .= $str;
|
||||
}
|
||||
|
||||
public function read_line() {
|
||||
$ar = explode($this->eol, $this->content, 2);
|
||||
if (count($ar) != 2) {
|
||||
return false;
|
||||
}
|
||||
$this->content = $ar[1];
|
||||
return $ar[0];
|
||||
}
|
||||
|
||||
public function read_n($n) {
|
||||
if (strlen($this->content) < $n) {
|
||||
return false;
|
||||
}
|
||||
$s = substr($this->content, 0, $n);
|
||||
$this->content = substr($this->content, $n);
|
||||
return $s;
|
||||
}
|
||||
|
||||
public function read_all($n) {
|
||||
$tmp = $this->content;
|
||||
$this->content = '';
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
//$b = new buffer;
|
||||
//$b->append("hello\nworld\n");
|
||||
//print($b->read_line());
|
||||
//print($b->read_line());
|
||||
|
||||
class event_socket {
|
||||
private $buffer;
|
||||
private $fp;
|
||||
|
||||
public function __construct($fp = false) {
|
||||
$this->buffer = new buffer;
|
||||
$this->fp = $fp;
|
||||
}
|
||||
|
||||
public function __destructor() {
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function read_event() {
|
||||
if (!$this->fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$b = $this->buffer;
|
||||
$content_length = 0;
|
||||
$content = Array();
|
||||
|
||||
while (true) {
|
||||
while(($line = $b->read_line()) !== false ) {
|
||||
if ($line == '') {
|
||||
break 2;
|
||||
}
|
||||
$kv = explode(':', $line, 2);
|
||||
$content[trim($kv[0])] = trim($kv[1]);
|
||||
}
|
||||
usleep(100);
|
||||
|
||||
if (feof($this->fp)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$buffer = fgets($this->fp, 1024);
|
||||
$b->append($buffer);
|
||||
}
|
||||
|
||||
if (array_key_exists('Content-Length', $content)) {
|
||||
$str = $b->read_n($content['Content-Length']);
|
||||
if ($str === false) {
|
||||
while (!feof($this->fp)) {
|
||||
$buffer = fgets($this->fp, 1024);
|
||||
$b->append($buffer);
|
||||
$str = $b->read_n($content['Content-Length']);
|
||||
if ($str !== false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($str !== false) {
|
||||
$content['$'] = $str;
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function connect($host, $port, $password) {
|
||||
$fp = fsockopen($host, $port, $errno, $errdesc, 3);
|
||||
|
||||
if (!$fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
socket_set_blocking($fp, false);
|
||||
$this->fp = $fp;
|
||||
|
||||
// Wait auth request and send response
|
||||
while (!feof($fp)) {
|
||||
$event = $this->read_event();
|
||||
if(@$event['Content-Type'] == 'auth/request'){
|
||||
fputs($fp, "auth $password\n\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait auth response
|
||||
while (!feof($fp)) {
|
||||
$event = $this->read_event();
|
||||
if (@$event['Content-Type'] == 'command/reply') {
|
||||
if (@$event['Reply-Text'] == '+OK accepted') {
|
||||
return $fp;
|
||||
}
|
||||
$this->fp = false;
|
||||
fclose($fp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function request($cmd) {
|
||||
if (!$this->fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd_array = explode("\n", $cmd);
|
||||
foreach ($cmd_array as &$value) {
|
||||
fputs($this->fp, $value."\n");
|
||||
}
|
||||
fputs($this->fp, "\n"); //second line feed to end the headers
|
||||
|
||||
$event = $this->read_event();
|
||||
|
||||
if (array_key_exists('$', $event)) {
|
||||
return $event['$'];
|
||||
}
|
||||
return $event;
|
||||
}
|
||||
|
||||
public function reset_fp($fp = false){
|
||||
$tmp = $this->fp;
|
||||
$this->fp = $fp;
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
public function close() {
|
||||
if ($this->fp) {
|
||||
fclose($fp->fp);
|
||||
$this->fp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
function event_socket_create($host, $port, $password) {
|
||||
$esl = new event_socket;
|
||||
if ($esl->connect($host, $port, $password)) {
|
||||
return $esl->reset_fp();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function event_socket_request($fp, $cmd) {
|
||||
$esl = new event_socket($fp);
|
||||
$result = $esl->request($cmd);
|
||||
$esl->reset_fp();
|
||||
return $result;
|
||||
}
|
||||
*/
|
||||
|
||||
// $esl = new event_socket;
|
||||
// $esl->connect('127.0.0.1', 8021, 'ClueCon');
|
||||
// print($esl->request('api sofia status'));
|
||||
|
||||
// $fp = event_socket_create('127.0.0.1', 8021, 'ClueCon');
|
||||
// print(event_socket_request($fp, 'api sofia status'));
|
||||
<?php
|
||||
|
||||
class buffer {
|
||||
private $content;
|
||||
private $eol;
|
||||
|
||||
public function __construct() {
|
||||
$this->content = '';
|
||||
$this->eol = "\n";
|
||||
}
|
||||
|
||||
public function append($str) {
|
||||
$this->content .= $str;
|
||||
}
|
||||
|
||||
public function read_line() {
|
||||
$ar = explode($this->eol, $this->content, 2);
|
||||
if (count($ar) != 2) {
|
||||
return false;
|
||||
}
|
||||
$this->content = $ar[1];
|
||||
return $ar[0];
|
||||
}
|
||||
|
||||
public function read_n($n) {
|
||||
if (strlen($this->content) < $n) {
|
||||
return false;
|
||||
}
|
||||
$s = substr($this->content, 0, $n);
|
||||
$this->content = substr($this->content, $n);
|
||||
return $s;
|
||||
}
|
||||
|
||||
public function read_all($n) {
|
||||
$tmp = $this->content;
|
||||
$this->content = '';
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
//$b = new buffer;
|
||||
//$b->append("hello\nworld\n");
|
||||
//print($b->read_line());
|
||||
//print($b->read_line());
|
||||
|
||||
class event_socket {
|
||||
private $buffer;
|
||||
private $fp;
|
||||
|
||||
public function __construct($fp = false) {
|
||||
$this->buffer = new buffer;
|
||||
$this->fp = $fp;
|
||||
}
|
||||
|
||||
public function __destructor() {
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function read_event() {
|
||||
if (!$this->fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$b = $this->buffer;
|
||||
$content_length = 0;
|
||||
$content = Array();
|
||||
|
||||
while (true) {
|
||||
while(($line = $b->read_line()) !== false ) {
|
||||
if ($line == '') {
|
||||
break 2;
|
||||
}
|
||||
$kv = explode(':', $line, 2);
|
||||
$content[trim($kv[0])] = trim($kv[1]);
|
||||
}
|
||||
usleep(100);
|
||||
|
||||
if (feof($this->fp)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$buffer = fgets($this->fp, 1024);
|
||||
$b->append($buffer);
|
||||
}
|
||||
|
||||
if (array_key_exists('Content-Length', $content)) {
|
||||
$str = $b->read_n($content['Content-Length']);
|
||||
if ($str === false) {
|
||||
while (!feof($this->fp)) {
|
||||
$buffer = fgets($this->fp, 1024);
|
||||
$b->append($buffer);
|
||||
$str = $b->read_n($content['Content-Length']);
|
||||
if ($str !== false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($str !== false) {
|
||||
$content['$'] = $str;
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function connect($host, $port, $password) {
|
||||
$fp = fsockopen($host, $port, $errno, $errdesc, 3);
|
||||
|
||||
if (!$fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
socket_set_blocking($fp, false);
|
||||
$this->fp = $fp;
|
||||
|
||||
// Wait auth request and send response
|
||||
while (!feof($fp)) {
|
||||
$event = $this->read_event();
|
||||
if(@$event['Content-Type'] == 'auth/request'){
|
||||
fputs($fp, "auth $password\n\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait auth response
|
||||
while (!feof($fp)) {
|
||||
$event = $this->read_event();
|
||||
if (@$event['Content-Type'] == 'command/reply') {
|
||||
if (@$event['Reply-Text'] == '+OK accepted') {
|
||||
return $fp;
|
||||
}
|
||||
$this->fp = false;
|
||||
fclose($fp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function request($cmd) {
|
||||
if (!$this->fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd_array = explode("\n", $cmd);
|
||||
foreach ($cmd_array as &$value) {
|
||||
fputs($this->fp, $value."\n");
|
||||
}
|
||||
fputs($this->fp, "\n"); //second line feed to end the headers
|
||||
|
||||
$event = $this->read_event();
|
||||
|
||||
if (array_key_exists('$', $event)) {
|
||||
return $event['$'];
|
||||
}
|
||||
return $event;
|
||||
}
|
||||
|
||||
public function reset_fp($fp = false){
|
||||
$tmp = $this->fp;
|
||||
$this->fp = $fp;
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
public function close() {
|
||||
if ($this->fp) {
|
||||
fclose($fp->fp);
|
||||
$this->fp = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
function event_socket_create($host, $port, $password) {
|
||||
$esl = new event_socket;
|
||||
if ($esl->connect($host, $port, $password)) {
|
||||
return $esl->reset_fp();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function event_socket_request($fp, $cmd) {
|
||||
$esl = new event_socket($fp);
|
||||
$result = $esl->request($cmd);
|
||||
$esl->reset_fp();
|
||||
return $result;
|
||||
}
|
||||
*/
|
||||
|
||||
// $esl = new event_socket;
|
||||
// $esl->connect('127.0.0.1', 8021, 'ClueCon');
|
||||
// print($esl->request('api sofia status'));
|
||||
|
||||
// $fp = event_socket_create('127.0.0.1', 8021, 'ClueCon');
|
||||
// print(event_socket_request($fp, 'api sofia status'));
|
||||
|
||||
@@ -1,191 +1,191 @@
|
||||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2016
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* groups class provides methods for add, delete groups, and add default groups
|
||||
*
|
||||
* @method string add
|
||||
* @method boolean delete
|
||||
* @method boolean defaults
|
||||
*/
|
||||
if (!class_exists('groups')) {
|
||||
class groups {
|
||||
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//connect to the database if not connected
|
||||
if (!$this->db) {
|
||||
require_once "resources/classes/database.php";
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$this->db = $database->db;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add a group
|
||||
*/
|
||||
public function add() {
|
||||
$id = uuid();
|
||||
//return $id;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a group
|
||||
*/
|
||||
public function delete($id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* add defaults groups
|
||||
*/
|
||||
public function defaults() {
|
||||
|
||||
//if the are no groups add the default groups
|
||||
$sql = "SELECT * FROM v_groups ";
|
||||
$sql .= "WHERE domain_uuid is null ";
|
||||
$result = $this->db->query($sql)->fetch();
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (count($result) == 0) {
|
||||
$x = 0;
|
||||
$tmp[$x]['group_name'] = 'superadmin';
|
||||
$tmp[$x]['group_description'] = 'Super Administrator Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$x++;
|
||||
$tmp[$x]['group_name'] = 'admin';
|
||||
$tmp[$x]['group_description'] = 'Administrator Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$x++;
|
||||
$tmp[$x]['group_name'] = 'user';
|
||||
$tmp[$x]['group_description'] = 'User Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$x++;
|
||||
$tmp[$x]['group_name'] = 'public';
|
||||
$tmp[$x]['group_description'] = 'Public Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$x++;
|
||||
$tmp[$x]['group_name'] = 'agent';
|
||||
$tmp[$x]['group_description'] = 'Call Center Agent Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$this->db->beginTransaction();
|
||||
foreach($tmp as $row) {
|
||||
if (strlen($row['group_name']) > 0) {
|
||||
$sql = "insert into v_groups ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "group_uuid, ";
|
||||
$sql .= "group_name, ";
|
||||
$sql .= "group_description, ";
|
||||
$sql .= "group_protected ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "null, ";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'".$row['group_name']."', ";
|
||||
$sql .= "'".$row['group_description']."', ";
|
||||
$sql .= "'".$row['group_protected']."' ";
|
||||
$sql .= ")";
|
||||
$this->db->exec($sql);
|
||||
unset($sql);
|
||||
}
|
||||
}
|
||||
$this->db->commit();
|
||||
}
|
||||
unset($prep_statement, $result);
|
||||
}
|
||||
|
||||
//if there are no permissions listed in v_group_permissions then set the default permissions
|
||||
$sql = "select count(*) as count from v_group_permissions ";
|
||||
$sql .= "where domain_uuid is null ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
unset ($prep_statement);
|
||||
if ($result['count'] == 0) {
|
||||
//build the apps array
|
||||
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
||||
$x = 0;
|
||||
foreach ($config_list as &$config_path) {
|
||||
include($config_path);
|
||||
$x++;
|
||||
}
|
||||
//no permissions found add the defaults
|
||||
$this->db->beginTransaction();
|
||||
foreach($apps as $app) {
|
||||
foreach ($app['permissions'] as $row) {
|
||||
foreach ($row['groups'] as $group) {
|
||||
//add the record
|
||||
$sql = "insert into v_group_permissions ";
|
||||
$sql .= "(";
|
||||
$sql .= "group_permission_uuid, ";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "permission_name, ";
|
||||
$sql .= "group_name ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "null, ";
|
||||
$sql .= "'".$row['name']."', ";
|
||||
$sql .= "'".$group."' ";
|
||||
$sql .= ")";
|
||||
$this->db->exec($sql);
|
||||
unset($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->db->commit();
|
||||
}
|
||||
}
|
||||
} //end scripts class
|
||||
}
|
||||
/*
|
||||
//example use
|
||||
$group = new groups;
|
||||
$group->defaults();
|
||||
*/
|
||||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2016
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* groups class provides methods for add, delete groups, and add default groups
|
||||
*
|
||||
* @method string add
|
||||
* @method boolean delete
|
||||
* @method boolean defaults
|
||||
*/
|
||||
if (!class_exists('groups')) {
|
||||
class groups {
|
||||
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//connect to the database if not connected
|
||||
if (!$this->db) {
|
||||
require_once "resources/classes/database.php";
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$this->db = $database->db;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add a group
|
||||
*/
|
||||
public function add() {
|
||||
$id = uuid();
|
||||
//return $id;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a group
|
||||
*/
|
||||
public function delete($id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* add defaults groups
|
||||
*/
|
||||
public function defaults() {
|
||||
|
||||
//if the are no groups add the default groups
|
||||
$sql = "SELECT * FROM v_groups ";
|
||||
$sql .= "WHERE domain_uuid is null ";
|
||||
$result = $this->db->query($sql)->fetch();
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (count($result) == 0) {
|
||||
$x = 0;
|
||||
$tmp[$x]['group_name'] = 'superadmin';
|
||||
$tmp[$x]['group_description'] = 'Super Administrator Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$x++;
|
||||
$tmp[$x]['group_name'] = 'admin';
|
||||
$tmp[$x]['group_description'] = 'Administrator Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$x++;
|
||||
$tmp[$x]['group_name'] = 'user';
|
||||
$tmp[$x]['group_description'] = 'User Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$x++;
|
||||
$tmp[$x]['group_name'] = 'public';
|
||||
$tmp[$x]['group_description'] = 'Public Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$x++;
|
||||
$tmp[$x]['group_name'] = 'agent';
|
||||
$tmp[$x]['group_description'] = 'Call Center Agent Group';
|
||||
$tmp[$x]['group_protected'] = 'false';
|
||||
$this->db->beginTransaction();
|
||||
foreach($tmp as $row) {
|
||||
if (strlen($row['group_name']) > 0) {
|
||||
$sql = "insert into v_groups ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "group_uuid, ";
|
||||
$sql .= "group_name, ";
|
||||
$sql .= "group_description, ";
|
||||
$sql .= "group_protected ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "null, ";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'".$row['group_name']."', ";
|
||||
$sql .= "'".$row['group_description']."', ";
|
||||
$sql .= "'".$row['group_protected']."' ";
|
||||
$sql .= ")";
|
||||
$this->db->exec($sql);
|
||||
unset($sql);
|
||||
}
|
||||
}
|
||||
$this->db->commit();
|
||||
}
|
||||
unset($prep_statement, $result);
|
||||
}
|
||||
|
||||
//if there are no permissions listed in v_group_permissions then set the default permissions
|
||||
$sql = "select count(*) as count from v_group_permissions ";
|
||||
$sql .= "where domain_uuid is null ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
unset ($prep_statement);
|
||||
if ($result['count'] == 0) {
|
||||
//build the apps array
|
||||
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
||||
$x = 0;
|
||||
foreach ($config_list as &$config_path) {
|
||||
include($config_path);
|
||||
$x++;
|
||||
}
|
||||
//no permissions found add the defaults
|
||||
$this->db->beginTransaction();
|
||||
foreach($apps as $app) {
|
||||
foreach ($app['permissions'] as $row) {
|
||||
foreach ($row['groups'] as $group) {
|
||||
//add the record
|
||||
$sql = "insert into v_group_permissions ";
|
||||
$sql .= "(";
|
||||
$sql .= "group_permission_uuid, ";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "permission_name, ";
|
||||
$sql .= "group_name ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "null, ";
|
||||
$sql .= "'".$row['name']."', ";
|
||||
$sql .= "'".$group."' ";
|
||||
$sql .= ")";
|
||||
$this->db->exec($sql);
|
||||
unset($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->db->commit();
|
||||
}
|
||||
}
|
||||
} //end scripts class
|
||||
}
|
||||
/*
|
||||
//example use
|
||||
$group = new groups;
|
||||
$group->defaults();
|
||||
*/
|
||||
?>
|
||||
@@ -1,105 +1,105 @@
|
||||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Copyright (C) 2015 All Rights Reserved.
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* permission class
|
||||
*
|
||||
* @method string add
|
||||
* @method string delete
|
||||
* @method string exists
|
||||
*/
|
||||
if (!class_exists('permissions')) {
|
||||
class permissions {
|
||||
|
||||
/**
|
||||
* Add a permission
|
||||
* @var string $permission
|
||||
*/
|
||||
public function add($permission, $type = '') {
|
||||
if (!$this->exists($permission)) {
|
||||
//set the ordinal number
|
||||
$i = count($_SESSION["permissions"])+1;
|
||||
|
||||
//set the permission
|
||||
$_SESSION["permissions"][$i]["permission_name"] = $permission;
|
||||
$_SESSION["permissions"][$i]["permission_type"] = "temp";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the permission
|
||||
* @var string $permission
|
||||
*/
|
||||
public function delete($permission, $type = '') {
|
||||
if ($this->exists($permission)) {
|
||||
foreach($_SESSION["permissions"] as $key => $row) {
|
||||
if ($row['permission_name'] == $permission) {
|
||||
if ($row['permission_name'] == $permission) {
|
||||
if ($type == 'temp') {
|
||||
if ($row['permission_type'] == "temp") {
|
||||
unset($_SESSION["permissions"][$key]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
unset($_SESSION["permissions"][$key]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the permission exists
|
||||
* @var string $permission
|
||||
*/
|
||||
function exists($permission) {
|
||||
//set default false
|
||||
$result = false;
|
||||
//search for the permission
|
||||
if (count($_SESSION["permissions"]) > 0) {
|
||||
foreach($_SESSION["permissions"] as $row) {
|
||||
if ($row['permission_name'] == $permission) {
|
||||
$result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//return the result
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//examples
|
||||
/*
|
||||
//add the permission
|
||||
$p = new permissions;
|
||||
$p->add($permission);
|
||||
//delete the permission
|
||||
$p = new permissions;
|
||||
$p->delete($permission);
|
||||
*/
|
||||
|
||||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Copyright (C) 2015 All Rights Reserved.
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* permission class
|
||||
*
|
||||
* @method string add
|
||||
* @method string delete
|
||||
* @method string exists
|
||||
*/
|
||||
if (!class_exists('permissions')) {
|
||||
class permissions {
|
||||
|
||||
/**
|
||||
* Add a permission
|
||||
* @var string $permission
|
||||
*/
|
||||
public function add($permission, $type = '') {
|
||||
if (!$this->exists($permission)) {
|
||||
//set the ordinal number
|
||||
$i = count($_SESSION["permissions"])+1;
|
||||
|
||||
//set the permission
|
||||
$_SESSION["permissions"][$i]["permission_name"] = $permission;
|
||||
$_SESSION["permissions"][$i]["permission_type"] = "temp";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the permission
|
||||
* @var string $permission
|
||||
*/
|
||||
public function delete($permission, $type = '') {
|
||||
if ($this->exists($permission)) {
|
||||
foreach($_SESSION["permissions"] as $key => $row) {
|
||||
if ($row['permission_name'] == $permission) {
|
||||
if ($row['permission_name'] == $permission) {
|
||||
if ($type == 'temp') {
|
||||
if ($row['permission_type'] == "temp") {
|
||||
unset($_SESSION["permissions"][$key]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
unset($_SESSION["permissions"][$key]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the permission exists
|
||||
* @var string $permission
|
||||
*/
|
||||
function exists($permission) {
|
||||
//set default false
|
||||
$result = false;
|
||||
//search for the permission
|
||||
if (count($_SESSION["permissions"]) > 0) {
|
||||
foreach($_SESSION["permissions"] as $row) {
|
||||
if ($row['permission_name'] == $permission) {
|
||||
$result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//return the result
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//examples
|
||||
/*
|
||||
//add the permission
|
||||
$p = new permissions;
|
||||
$p->add($permission);
|
||||
//delete the permission
|
||||
$p = new permissions;
|
||||
$p->delete($permission);
|
||||
*/
|
||||
|
||||
?>
|
||||
@@ -1,286 +1,286 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* switch_settings class provides access methods related to FreeSWITCH
|
||||
*
|
||||
* @method settings will add missing switch directories to default settings
|
||||
*/
|
||||
if (!class_exists('switch_settings')) {
|
||||
class switch_settings {
|
||||
|
||||
public $db;
|
||||
public $event_socket_ip_address;
|
||||
public $event_socket_port;
|
||||
public $event_socket_password;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//connect to the database if not connected
|
||||
if (!$this->db) {
|
||||
require_once "resources/classes/database.php";
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$this->db = $database->db;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* settings Set switch directories in default settings
|
||||
*/
|
||||
public function settings() {
|
||||
|
||||
//define the variables
|
||||
if (!isset($this->event_socket_ip_address)) {
|
||||
if (strlen($_SESSION['event_socket_ip_address']) > 0) {
|
||||
$this->event_socket_ip_address = $_SESSION['event_socket_ip_address'];
|
||||
}
|
||||
else {
|
||||
$this->event_socket_ip_address = '127.0.0.1';
|
||||
}
|
||||
}
|
||||
if (!isset($this->event_socket_port)) {
|
||||
if (strlen($_SESSION['event_socket_ip_address']) > 0) {
|
||||
$this->event_socket_port = $_SESSION['event_socket_port'];
|
||||
}
|
||||
else {
|
||||
$this->event_socket_port = '8021';
|
||||
}
|
||||
}
|
||||
if (!isset($this->event_socket_password)) {
|
||||
if (strlen($_SESSION['event_socket_ip_address']) > 0) {
|
||||
$this->event_socket_password = $_SESSION['event_socket_password'];
|
||||
}
|
||||
else {
|
||||
$this->event_socket_password = 'ClueCon';
|
||||
}
|
||||
}
|
||||
|
||||
{ //connect to event socket
|
||||
$esl = new event_socket;
|
||||
$esl->connect($this->event_socket_ip_address, $this->event_socket_port, $this->event_socket_password);
|
||||
|
||||
//run the api command
|
||||
$result = $esl->request('api global_getvar');
|
||||
} //close event socket
|
||||
|
||||
|
||||
//set the result as a named array
|
||||
$vars = array();
|
||||
foreach (explode("\n", $result) as $row) {
|
||||
$a = explode("=", $row);
|
||||
if (substr($a[0], -4) == "_dir") {
|
||||
$vars[$a[0]] = $a[1];
|
||||
}
|
||||
}
|
||||
|
||||
//set the bin directory
|
||||
if ($vars['base_dir'] == "/usr/local/freeswitch") {
|
||||
$bin = "/usr/local/freeswitch/bin";
|
||||
} else {
|
||||
$bin = "";
|
||||
}
|
||||
|
||||
//create the default settings array
|
||||
$x=0;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'bin';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $bin;
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'base';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['base_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'call_center';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/autoload_configs';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'conf';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'db';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['db_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'dialplan';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/dialplan';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'extensions';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/directory';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'grammar';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['grammar_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'log';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['log_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'mod';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['mod_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'phrases';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/lang';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'recordings';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['recordings_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'scripts';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['script_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'sip_profiles';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/sip_profiles';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'sounds';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['sounds_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'storage';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['storage_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'voicemail';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['storage_dir'].'/voicemail';
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
|
||||
//get an array of the default settings
|
||||
$sql = "select * from v_default_settings ";
|
||||
$sql .= "where default_setting_category = 'switch' ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->execute();
|
||||
$default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
unset ($prep_statement, $sql);
|
||||
|
||||
//find the missing default settings
|
||||
$x = 0;
|
||||
foreach ($array as $setting) {
|
||||
$found = false;
|
||||
$missing[$x] = $setting;
|
||||
foreach ($default_settings as $row) {
|
||||
if (trim($row['default_setting_subcategory']) == trim($setting['default_setting_subcategory'])) {
|
||||
$found = true;
|
||||
//remove items from the array that were found
|
||||
unset($missing[$x]);
|
||||
}
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
|
||||
//add the missing default settings
|
||||
if (is_array($missing)) {
|
||||
$sql = "insert into v_default_settings (";
|
||||
$sql .= "default_setting_uuid, ";
|
||||
$sql .= "default_setting_category, ";
|
||||
$sql .= "default_setting_subcategory, ";
|
||||
$sql .= "default_setting_name, ";
|
||||
$sql .= "default_setting_value, ";
|
||||
$sql .= "default_setting_enabled, ";
|
||||
$sql .= "default_setting_description ";
|
||||
$sql .= ") values \n";
|
||||
$i = 1;
|
||||
foreach ($missing as $row) {
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'".check_str($row['default_setting_category'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_subcategory'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_name'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_value'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_enabled'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_description'])."' ";
|
||||
$sql .= ")";
|
||||
if (sizeof($missing) != $i) {
|
||||
$sql .= ",\n";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->db->exec(check_sql($sql));
|
||||
unset($missing);
|
||||
}
|
||||
|
||||
//set the default settings
|
||||
foreach ($array as $row) {
|
||||
if (!isset($_SESSION['switch'][$row['default_setting_subcategory']])) {
|
||||
if ($row['default_setting_enabled'] != "false") {
|
||||
$_SESSION['switch'][$row['default_setting_subcategory']] = $row['default_setting_value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//unset the array variable
|
||||
unset($array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* switch_settings class provides access methods related to FreeSWITCH
|
||||
*
|
||||
* @method settings will add missing switch directories to default settings
|
||||
*/
|
||||
if (!class_exists('switch_settings')) {
|
||||
class switch_settings {
|
||||
|
||||
public $db;
|
||||
public $event_socket_ip_address;
|
||||
public $event_socket_port;
|
||||
public $event_socket_password;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//connect to the database if not connected
|
||||
if (!$this->db) {
|
||||
require_once "resources/classes/database.php";
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$this->db = $database->db;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* settings Set switch directories in default settings
|
||||
*/
|
||||
public function settings() {
|
||||
|
||||
//define the variables
|
||||
if (!isset($this->event_socket_ip_address)) {
|
||||
if (strlen($_SESSION['event_socket_ip_address']) > 0) {
|
||||
$this->event_socket_ip_address = $_SESSION['event_socket_ip_address'];
|
||||
}
|
||||
else {
|
||||
$this->event_socket_ip_address = '127.0.0.1';
|
||||
}
|
||||
}
|
||||
if (!isset($this->event_socket_port)) {
|
||||
if (strlen($_SESSION['event_socket_ip_address']) > 0) {
|
||||
$this->event_socket_port = $_SESSION['event_socket_port'];
|
||||
}
|
||||
else {
|
||||
$this->event_socket_port = '8021';
|
||||
}
|
||||
}
|
||||
if (!isset($this->event_socket_password)) {
|
||||
if (strlen($_SESSION['event_socket_ip_address']) > 0) {
|
||||
$this->event_socket_password = $_SESSION['event_socket_password'];
|
||||
}
|
||||
else {
|
||||
$this->event_socket_password = 'ClueCon';
|
||||
}
|
||||
}
|
||||
|
||||
{ //connect to event socket
|
||||
$esl = new event_socket;
|
||||
$esl->connect($this->event_socket_ip_address, $this->event_socket_port, $this->event_socket_password);
|
||||
|
||||
//run the api command
|
||||
$result = $esl->request('api global_getvar');
|
||||
} //close event socket
|
||||
|
||||
|
||||
//set the result as a named array
|
||||
$vars = array();
|
||||
foreach (explode("\n", $result) as $row) {
|
||||
$a = explode("=", $row);
|
||||
if (substr($a[0], -4) == "_dir") {
|
||||
$vars[$a[0]] = $a[1];
|
||||
}
|
||||
}
|
||||
|
||||
//set the bin directory
|
||||
if ($vars['base_dir'] == "/usr/local/freeswitch") {
|
||||
$bin = "/usr/local/freeswitch/bin";
|
||||
} else {
|
||||
$bin = "";
|
||||
}
|
||||
|
||||
//create the default settings array
|
||||
$x=0;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'bin';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $bin;
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'base';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['base_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'call_center';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/autoload_configs';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'conf';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'db';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['db_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'dialplan';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/dialplan';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'extensions';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/directory';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'grammar';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['grammar_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'log';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['log_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'mod';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['mod_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'phrases';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/lang';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'recordings';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['recordings_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'scripts';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['script_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'sip_profiles';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['conf_dir'].'/sip_profiles';
|
||||
$array[$x]['default_setting_enabled'] = 'false';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'sounds';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['sounds_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'storage';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['storage_dir'];
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
$array[$x]['default_setting_category'] = 'switch';
|
||||
$array[$x]['default_setting_subcategory'] = 'voicemail';
|
||||
$array[$x]['default_setting_name'] = 'dir';
|
||||
$array[$x]['default_setting_value'] = $vars['storage_dir'].'/voicemail';
|
||||
$array[$x]['default_setting_enabled'] = 'true';
|
||||
$array[$x]['default_setting_description'] = '';
|
||||
$x++;
|
||||
|
||||
//get an array of the default settings
|
||||
$sql = "select * from v_default_settings ";
|
||||
$sql .= "where default_setting_category = 'switch' ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->execute();
|
||||
$default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
unset ($prep_statement, $sql);
|
||||
|
||||
//find the missing default settings
|
||||
$x = 0;
|
||||
foreach ($array as $setting) {
|
||||
$found = false;
|
||||
$missing[$x] = $setting;
|
||||
foreach ($default_settings as $row) {
|
||||
if (trim($row['default_setting_subcategory']) == trim($setting['default_setting_subcategory'])) {
|
||||
$found = true;
|
||||
//remove items from the array that were found
|
||||
unset($missing[$x]);
|
||||
}
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
|
||||
//add the missing default settings
|
||||
if (is_array($missing)) {
|
||||
$sql = "insert into v_default_settings (";
|
||||
$sql .= "default_setting_uuid, ";
|
||||
$sql .= "default_setting_category, ";
|
||||
$sql .= "default_setting_subcategory, ";
|
||||
$sql .= "default_setting_name, ";
|
||||
$sql .= "default_setting_value, ";
|
||||
$sql .= "default_setting_enabled, ";
|
||||
$sql .= "default_setting_description ";
|
||||
$sql .= ") values \n";
|
||||
$i = 1;
|
||||
foreach ($missing as $row) {
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'".check_str($row['default_setting_category'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_subcategory'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_name'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_value'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_enabled'])."', ";
|
||||
$sql .= "'".check_str($row['default_setting_description'])."' ";
|
||||
$sql .= ")";
|
||||
if (sizeof($missing) != $i) {
|
||||
$sql .= ",\n";
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->db->exec(check_sql($sql));
|
||||
unset($missing);
|
||||
}
|
||||
|
||||
//set the default settings
|
||||
foreach ($array as $row) {
|
||||
if (!isset($_SESSION['switch'][$row['default_setting_subcategory']])) {
|
||||
if ($row['default_setting_enabled'] != "false") {
|
||||
$_SESSION['switch'][$row['default_setting_subcategory']] = $row['default_setting_value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//unset the array variable
|
||||
unset($array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,101 +1,101 @@
|
||||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Copyright (C) 2013
|
||||
All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
include "root.php";
|
||||
|
||||
//define the template class
|
||||
if (!class_exists('template')) {
|
||||
class template {
|
||||
|
||||
public $engine;
|
||||
public $template_dir;
|
||||
public $cache_dir;
|
||||
private $object;
|
||||
private $var_array;
|
||||
|
||||
public function __construct(){
|
||||
}
|
||||
|
||||
public function init() {
|
||||
if ($this->engine === 'smarty') {
|
||||
require_once "resources/templates/engine/smarty/Smarty.class.php";
|
||||
$this->object = new Smarty();
|
||||
$this->object->setTemplateDir($this->template_dir);
|
||||
$this->object->setCompileDir($this->cache_dir);
|
||||
$this->object->setCacheDir($this->cache_dir);
|
||||
}
|
||||
if ($this->engine === 'raintpl') {
|
||||
require_once "resources/templates/engine/raintpl/rain.tpl.class.php";
|
||||
$this->object = new RainTPL();
|
||||
RainTPL::configure('tpl_dir', realpath($this->template_dir)."/");
|
||||
RainTPL::configure('cache_dir', realpath($this->cache_dir)."/");
|
||||
}
|
||||
if ($this->engine === 'twig') {
|
||||
require_once "resources/templates/engine/Twig/Autoloader.php";
|
||||
Twig_Autoloader::register();
|
||||
$loader = new Twig_Loader_Filesystem($this->template_dir);
|
||||
$this->object = new Twig_Environment($loader);
|
||||
$lexer = new Twig_Lexer($this->object, array(
|
||||
'tag_comment' => array('{*', '*}'),
|
||||
'tag_block' => array('{', '}'),
|
||||
'tag_variable' => array('{$', '}'),
|
||||
));
|
||||
$this->object->setLexer($lexer);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
public function assign($key, $value) {
|
||||
if ($this->engine === 'smarty') {
|
||||
$this->object->assign($key, $value);
|
||||
}
|
||||
if ($this->engine === 'raintpl') {
|
||||
$this->object->assign($key, $value);
|
||||
}
|
||||
if ($this->engine === 'twig') {
|
||||
$this->var_array[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($name) {
|
||||
if ($this->engine === 'smarty') {
|
||||
return $this->object->fetch($name);
|
||||
}
|
||||
if ($this->engine === 'raintpl') {
|
||||
return $this->object-> draw($name, 'return_string=true');
|
||||
}
|
||||
if ($this->engine === 'twig') {
|
||||
return $this->object->render($name,$this->var_array);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Copyright (C) 2013
|
||||
All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
include "root.php";
|
||||
|
||||
//define the template class
|
||||
if (!class_exists('template')) {
|
||||
class template {
|
||||
|
||||
public $engine;
|
||||
public $template_dir;
|
||||
public $cache_dir;
|
||||
private $object;
|
||||
private $var_array;
|
||||
|
||||
public function __construct(){
|
||||
}
|
||||
|
||||
public function init() {
|
||||
if ($this->engine === 'smarty') {
|
||||
require_once "resources/templates/engine/smarty/Smarty.class.php";
|
||||
$this->object = new Smarty();
|
||||
$this->object->setTemplateDir($this->template_dir);
|
||||
$this->object->setCompileDir($this->cache_dir);
|
||||
$this->object->setCacheDir($this->cache_dir);
|
||||
}
|
||||
if ($this->engine === 'raintpl') {
|
||||
require_once "resources/templates/engine/raintpl/rain.tpl.class.php";
|
||||
$this->object = new RainTPL();
|
||||
RainTPL::configure('tpl_dir', realpath($this->template_dir)."/");
|
||||
RainTPL::configure('cache_dir', realpath($this->cache_dir)."/");
|
||||
}
|
||||
if ($this->engine === 'twig') {
|
||||
require_once "resources/templates/engine/Twig/Autoloader.php";
|
||||
Twig_Autoloader::register();
|
||||
$loader = new Twig_Loader_Filesystem($this->template_dir);
|
||||
$this->object = new Twig_Environment($loader);
|
||||
$lexer = new Twig_Lexer($this->object, array(
|
||||
'tag_comment' => array('{*', '*}'),
|
||||
'tag_block' => array('{', '}'),
|
||||
'tag_variable' => array('{$', '}'),
|
||||
));
|
||||
$this->object->setLexer($lexer);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
public function assign($key, $value) {
|
||||
if ($this->engine === 'smarty') {
|
||||
$this->object->assign($key, $value);
|
||||
}
|
||||
if ($this->engine === 'raintpl') {
|
||||
$this->object->assign($key, $value);
|
||||
}
|
||||
if ($this->engine === 'twig') {
|
||||
$this->var_array[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function render($name) {
|
||||
if ($this->engine === 'smarty') {
|
||||
return $this->object->fetch($name);
|
||||
}
|
||||
if ($this->engine === 'raintpl') {
|
||||
return $this->object-> draw($name, 'return_string=true');
|
||||
}
|
||||
if ($this->engine === 'twig') {
|
||||
return $this->object->render($name,$this->var_array);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Get the text for the correct translation
|
||||
*
|
||||
* @method array get
|
||||
*/
|
||||
class text {
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//place holder
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific item from the cache
|
||||
* @var string $language_code examples: en-us, es-cl, fr-fr, pt-pt
|
||||
* @var string $app_path examples: app/exec or core/domains
|
||||
*/
|
||||
public function get($language_code = null, $app_path = null, $exclude_global = false) {
|
||||
//get the global app_languages.php
|
||||
if (!$exclude_global){
|
||||
include $_SERVER["PROJECT_ROOT"]."/resources/app_languages.php";
|
||||
}
|
||||
|
||||
//get the app_languages.php
|
||||
if ($app_path != null) {
|
||||
$lang_path = $_SERVER["PROJECT_ROOT"]."/".$app_path."/app_languages.php";
|
||||
}
|
||||
else {
|
||||
$lang_path = getcwd().'/app_languages.php';
|
||||
}
|
||||
if(file_exists($lang_path)){
|
||||
require $lang_path;
|
||||
}
|
||||
|
||||
//get the available languages
|
||||
krsort($text);
|
||||
foreach ($text as $lang_label => $lang_codes) {
|
||||
foreach ($lang_codes as $lang_code => $lang_text) {
|
||||
if ($lang_text != '') {
|
||||
$app_languages[] = $lang_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
$_SESSION['app']['languages'] = array_unique($app_languages);
|
||||
|
||||
//check the session language
|
||||
if (isset($_SESSION['domain']) and $language_code == null){
|
||||
$language_code = $_SESSION['domain']['language']['code'];
|
||||
} elseif ($language_code == null){
|
||||
$language_code = 'en-us';
|
||||
}
|
||||
|
||||
//reduce to specific language
|
||||
if ($language_code != 'all') {
|
||||
foreach ($text as $key => $value) {
|
||||
if (strlen($value[$language_code]) > 0) {
|
||||
$text[$key] = $value[$language_code];
|
||||
} else {
|
||||
//fallback to en-us
|
||||
$text[$key] = $value['en-us'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return the array of translations
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Get the text for the correct translation
|
||||
*
|
||||
* @method array get
|
||||
*/
|
||||
class text {
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//place holder
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific item from the cache
|
||||
* @var string $language_code examples: en-us, es-cl, fr-fr, pt-pt
|
||||
* @var string $app_path examples: app/exec or core/domains
|
||||
*/
|
||||
public function get($language_code = null, $app_path = null, $exclude_global = false) {
|
||||
//get the global app_languages.php
|
||||
if (!$exclude_global){
|
||||
include $_SERVER["PROJECT_ROOT"]."/resources/app_languages.php";
|
||||
}
|
||||
|
||||
//get the app_languages.php
|
||||
if ($app_path != null) {
|
||||
$lang_path = $_SERVER["PROJECT_ROOT"]."/".$app_path."/app_languages.php";
|
||||
}
|
||||
else {
|
||||
$lang_path = getcwd().'/app_languages.php';
|
||||
}
|
||||
if(file_exists($lang_path)){
|
||||
require $lang_path;
|
||||
}
|
||||
|
||||
//get the available languages
|
||||
krsort($text);
|
||||
foreach ($text as $lang_label => $lang_codes) {
|
||||
foreach ($lang_codes as $lang_code => $lang_text) {
|
||||
if ($lang_text != '') {
|
||||
$app_languages[] = $lang_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
$_SESSION['app']['languages'] = array_unique($app_languages);
|
||||
|
||||
//check the session language
|
||||
if (isset($_SESSION['domain']) and $language_code == null){
|
||||
$language_code = $_SESSION['domain']['language']['code'];
|
||||
} elseif ($language_code == null){
|
||||
$language_code = 'en-us';
|
||||
}
|
||||
|
||||
//reduce to specific language
|
||||
if ($language_code != 'all') {
|
||||
foreach ($text as $key => $value) {
|
||||
if (strlen($value[$language_code]) > 0) {
|
||||
$text[$key] = $value[$language_code];
|
||||
} else {
|
||||
//fallback to en-us
|
||||
$text[$key] = $value['en-us'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return the array of translations
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,77 +1,77 @@
|
||||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2016
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* users class provides methods for adding and removing users
|
||||
*
|
||||
* @method string add
|
||||
* @method boolean delete
|
||||
*/
|
||||
if (!class_exists('users')) {
|
||||
class users {
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//place holder
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add a user
|
||||
*/
|
||||
public function add($username, $password) {
|
||||
$id = uuid();
|
||||
//return $id;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a user
|
||||
*/
|
||||
public function delete($id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} //end scripts class
|
||||
}
|
||||
/*
|
||||
//example use
|
||||
$user = new users;
|
||||
$user->add($username, $password);
|
||||
*/
|
||||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2016
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* users class provides methods for adding and removing users
|
||||
*
|
||||
* @method string add
|
||||
* @method boolean delete
|
||||
*/
|
||||
if (!class_exists('users')) {
|
||||
class users {
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//place holder
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when there are no references to a particular object
|
||||
* unset the variables used in the class
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach ($this as $key => $value) {
|
||||
unset($this->$key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add a user
|
||||
*/
|
||||
public function add($username, $password) {
|
||||
$id = uuid();
|
||||
//return $id;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a user
|
||||
*/
|
||||
public function delete($id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} //end scripts class
|
||||
}
|
||||
/*
|
||||
//example use
|
||||
$user = new users;
|
||||
$user->add($username, $password);
|
||||
*/
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,52 +1,52 @@
|
||||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5.2
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class FilterASCIIHexDecode
|
||||
*/
|
||||
class FilterASCIIHexDecode
|
||||
{
|
||||
/**
|
||||
* Converts an ASCII hexadecimal encoded string into it's binary representation.
|
||||
*
|
||||
* @param string $data The input string
|
||||
* @return string
|
||||
*/
|
||||
public function decode($data)
|
||||
{
|
||||
$data = preg_replace('/[^0-9A-Fa-f]/', '', rtrim($data, '>'));
|
||||
if ((strlen($data) % 2) == 1) {
|
||||
$data .= '0';
|
||||
}
|
||||
|
||||
return pack('H*', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string into ASCII hexadecimal representation.
|
||||
*
|
||||
* @param string $data The input string
|
||||
* @param boolean $leaveEOD
|
||||
* @return string
|
||||
*/
|
||||
public function encode($data, $leaveEOD = false)
|
||||
{
|
||||
return current(unpack('H*', $data)) . ($leaveEOD ? '' : '>');
|
||||
}
|
||||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5.2
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class FilterASCIIHexDecode
|
||||
*/
|
||||
class FilterASCIIHexDecode
|
||||
{
|
||||
/**
|
||||
* Converts an ASCII hexadecimal encoded string into it's binary representation.
|
||||
*
|
||||
* @param string $data The input string
|
||||
* @return string
|
||||
*/
|
||||
public function decode($data)
|
||||
{
|
||||
$data = preg_replace('/[^0-9A-Fa-f]/', '', rtrim($data, '>'));
|
||||
if ((strlen($data) % 2) == 1) {
|
||||
$data .= '0';
|
||||
}
|
||||
|
||||
return pack('H*', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string into ASCII hexadecimal representation.
|
||||
*
|
||||
* @param string $data The input string
|
||||
* @param boolean $leaveEOD
|
||||
* @return string
|
||||
*/
|
||||
public function encode($data, $leaveEOD = false)
|
||||
{
|
||||
return current(unpack('H*', $data)) . ($leaveEOD ? '' : '>');
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,354 +1,354 @@
|
||||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5.2
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
require_once('pdf_parser.php');
|
||||
|
||||
/**
|
||||
* Class fpdi_pdf_parser
|
||||
*/
|
||||
class fpdi_pdf_parser extends pdf_parser
|
||||
{
|
||||
/**
|
||||
* Pages
|
||||
*
|
||||
* Index begins at 0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_pages;
|
||||
|
||||
/**
|
||||
* Page count
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_pageCount;
|
||||
|
||||
/**
|
||||
* Current page number
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $pageNo;
|
||||
|
||||
/**
|
||||
* PDF version of imported document
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_pdfVersion;
|
||||
|
||||
/**
|
||||
* Available BoxTypes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $availableBoxes = array('/MediaBox', '/CropBox', '/BleedBox', '/TrimBox', '/ArtBox');
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*
|
||||
* @param string $filename The source filename
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
parent::__construct($filename);
|
||||
|
||||
// resolve Pages-Dictonary
|
||||
$pages = $this->resolveObject($this->_root[1][1]['/Pages']);
|
||||
|
||||
// Read pages
|
||||
$this->_readPages($pages, $this->_pages);
|
||||
|
||||
// count pages;
|
||||
$this->_pageCount = count($this->_pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page count from source file.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPageCount()
|
||||
{
|
||||
return $this->_pageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the page number.
|
||||
*
|
||||
* @param int $pageNo Page number to use
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setPageNo($pageNo)
|
||||
{
|
||||
$pageNo = ((int) $pageNo) - 1;
|
||||
|
||||
if ($pageNo < 0 || $pageNo >= $this->getPageCount()) {
|
||||
throw new InvalidArgumentException('Invalid page number!');
|
||||
}
|
||||
|
||||
$this->pageNo = $pageNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page-resources from current page
|
||||
*
|
||||
* @return array|boolean
|
||||
*/
|
||||
public function getPageResources()
|
||||
{
|
||||
return $this->_getPageResources($this->_pages[$this->pageNo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page-resources from a /Page dictionary.
|
||||
*
|
||||
* @param array $obj Array of pdf-data
|
||||
* @return array|boolean
|
||||
*/
|
||||
protected function _getPageResources($obj)
|
||||
{
|
||||
$obj = $this->resolveObject($obj);
|
||||
|
||||
// If the current object has a resources
|
||||
// dictionary associated with it, we use
|
||||
// it. Otherwise, we move back to its
|
||||
// parent object.
|
||||
if (isset($obj[1][1]['/Resources'])) {
|
||||
$res = $this->resolveObject($obj[1][1]['/Resources']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
return $res;
|
||||
}
|
||||
|
||||
if (!isset($obj[1][1]['/Parent'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->_getPageResources($obj[1][1]['/Parent']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content of current page.
|
||||
*
|
||||
* If /Contents is an array, the streams are concatenated
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
$buffer = '';
|
||||
|
||||
if (isset($this->_pages[$this->pageNo][1][1]['/Contents'])) {
|
||||
$contents = $this->_getPageContent($this->_pages[$this->pageNo][1][1]['/Contents']);
|
||||
foreach ($contents AS $tmpContent) {
|
||||
$buffer .= $this->_unFilterStream($tmpContent) . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve all content objects.
|
||||
*
|
||||
* @param array $contentRef
|
||||
* @return array
|
||||
*/
|
||||
protected function _getPageContent($contentRef)
|
||||
{
|
||||
$contents = array();
|
||||
|
||||
if ($contentRef[0] == pdf_parser::TYPE_OBJREF) {
|
||||
$content = $this->resolveObject($contentRef);
|
||||
if ($content[1][0] == pdf_parser::TYPE_ARRAY) {
|
||||
$contents = $this->_getPageContent($content[1]);
|
||||
} else {
|
||||
$contents[] = $content;
|
||||
}
|
||||
} else if ($contentRef[0] == pdf_parser::TYPE_ARRAY) {
|
||||
foreach ($contentRef[1] AS $tmp_content_ref) {
|
||||
$contents = array_merge($contents, $this->_getPageContent($tmp_content_ref));
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a boundary box from a page
|
||||
*
|
||||
* Array format is same as used by FPDF_TPL.
|
||||
*
|
||||
* @param array $page a /Page dictionary
|
||||
* @param string $boxIndex Type of box {see {@link $availableBoxes})
|
||||
* @param float Scale factor from user space units to points
|
||||
*
|
||||
* @return array|boolean
|
||||
*/
|
||||
protected function _getPageBox($page, $boxIndex, $k)
|
||||
{
|
||||
$page = $this->resolveObject($page);
|
||||
$box = null;
|
||||
if (isset($page[1][1][$boxIndex])) {
|
||||
$box = $page[1][1][$boxIndex];
|
||||
}
|
||||
|
||||
if (!is_null($box) && $box[0] == pdf_parser::TYPE_OBJREF) {
|
||||
$tmp_box = $this->resolveObject($box);
|
||||
$box = $tmp_box[1];
|
||||
}
|
||||
|
||||
if (!is_null($box) && $box[0] == pdf_parser::TYPE_ARRAY) {
|
||||
$b = $box[1];
|
||||
return array(
|
||||
'x' => $b[0][1] / $k,
|
||||
'y' => $b[1][1] / $k,
|
||||
'w' => abs($b[0][1] - $b[2][1]) / $k,
|
||||
'h' => abs($b[1][1] - $b[3][1]) / $k,
|
||||
'llx' => min($b[0][1], $b[2][1]) / $k,
|
||||
'lly' => min($b[1][1], $b[3][1]) / $k,
|
||||
'urx' => max($b[0][1], $b[2][1]) / $k,
|
||||
'ury' => max($b[1][1], $b[3][1]) / $k,
|
||||
);
|
||||
} else if (!isset($page[1][1]['/Parent'])) {
|
||||
return false;
|
||||
} else {
|
||||
return $this->_getPageBox($this->resolveObject($page[1][1]['/Parent']), $boxIndex, $k);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all page boundary boxes by page number
|
||||
*
|
||||
* @param int $pageNo The page number
|
||||
* @param float $k Scale factor from user space units to points
|
||||
* @return array
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function getPageBoxes($pageNo, $k)
|
||||
{
|
||||
if (!isset($this->_pages[$pageNo - 1])) {
|
||||
throw new InvalidArgumentException('Page ' . $pageNo . ' does not exists.');
|
||||
}
|
||||
|
||||
return $this->_getPageBoxes($this->_pages[$pageNo - 1], $k);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all boxes from /Page dictionary
|
||||
*
|
||||
* @param array $page A /Page dictionary
|
||||
* @param float $k Scale factor from user space units to points
|
||||
* @return array
|
||||
*/
|
||||
protected function _getPageBoxes($page, $k)
|
||||
{
|
||||
$boxes = array();
|
||||
|
||||
foreach($this->availableBoxes AS $box) {
|
||||
if ($_box = $this->_getPageBox($page, $box, $k)) {
|
||||
$boxes[$box] = $_box;
|
||||
}
|
||||
}
|
||||
|
||||
return $boxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page rotation by page number
|
||||
*
|
||||
* @param integer $pageNo
|
||||
* @throws InvalidArgumentException
|
||||
* @return array
|
||||
*/
|
||||
public function getPageRotation($pageNo)
|
||||
{
|
||||
if (!isset($this->_pages[$pageNo - 1])) {
|
||||
throw new InvalidArgumentException('Page ' . $pageNo . ' does not exists.');
|
||||
}
|
||||
|
||||
return $this->_getPageRotation($this->_pages[$pageNo - 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rotation value of a page
|
||||
*
|
||||
* @param array $obj A /Page dictionary
|
||||
* @return array|bool
|
||||
*/
|
||||
protected function _getPageRotation($obj)
|
||||
{
|
||||
$obj = $this->resolveObject($obj);
|
||||
if (isset($obj[1][1]['/Rotate'])) {
|
||||
$res = $this->resolveObject($obj[1][1]['/Rotate']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
return $res;
|
||||
}
|
||||
|
||||
if (!isset($obj[1][1]['/Parent'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->_getPageRotation($obj[1][1]['/Parent']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all pages
|
||||
*
|
||||
* @param array $pages /Pages dictionary
|
||||
* @param array $result The result array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _readPages(&$pages, &$result)
|
||||
{
|
||||
// Get the kids dictionary
|
||||
$_kids = $this->resolveObject($pages[1][1]['/Kids']);
|
||||
|
||||
if (!is_array($_kids)) {
|
||||
throw new Exception('Cannot find /Kids in current /Page-Dictionary');
|
||||
}
|
||||
|
||||
if ($_kids[0] === self::TYPE_OBJECT) {
|
||||
$_kids = $_kids[1];
|
||||
}
|
||||
|
||||
$kids = $_kids[1];
|
||||
|
||||
foreach ($kids as $v) {
|
||||
$pg = $this->resolveObject($v);
|
||||
if ($pg[1][1]['/Type'][1] === '/Pages') {
|
||||
// If one of the kids is an embedded
|
||||
// /Pages array, resolve it as well.
|
||||
$this->_readPages($pg, $result);
|
||||
} else {
|
||||
$result[] = $pg;
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5.2
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
require_once('pdf_parser.php');
|
||||
|
||||
/**
|
||||
* Class fpdi_pdf_parser
|
||||
*/
|
||||
class fpdi_pdf_parser extends pdf_parser
|
||||
{
|
||||
/**
|
||||
* Pages
|
||||
*
|
||||
* Index begins at 0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_pages;
|
||||
|
||||
/**
|
||||
* Page count
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_pageCount;
|
||||
|
||||
/**
|
||||
* Current page number
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $pageNo;
|
||||
|
||||
/**
|
||||
* PDF version of imported document
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_pdfVersion;
|
||||
|
||||
/**
|
||||
* Available BoxTypes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $availableBoxes = array('/MediaBox', '/CropBox', '/BleedBox', '/TrimBox', '/ArtBox');
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*
|
||||
* @param string $filename The source filename
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
parent::__construct($filename);
|
||||
|
||||
// resolve Pages-Dictonary
|
||||
$pages = $this->resolveObject($this->_root[1][1]['/Pages']);
|
||||
|
||||
// Read pages
|
||||
$this->_readPages($pages, $this->_pages);
|
||||
|
||||
// count pages;
|
||||
$this->_pageCount = count($this->_pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page count from source file.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPageCount()
|
||||
{
|
||||
return $this->_pageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the page number.
|
||||
*
|
||||
* @param int $pageNo Page number to use
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setPageNo($pageNo)
|
||||
{
|
||||
$pageNo = ((int) $pageNo) - 1;
|
||||
|
||||
if ($pageNo < 0 || $pageNo >= $this->getPageCount()) {
|
||||
throw new InvalidArgumentException('Invalid page number!');
|
||||
}
|
||||
|
||||
$this->pageNo = $pageNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page-resources from current page
|
||||
*
|
||||
* @return array|boolean
|
||||
*/
|
||||
public function getPageResources()
|
||||
{
|
||||
return $this->_getPageResources($this->_pages[$this->pageNo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page-resources from a /Page dictionary.
|
||||
*
|
||||
* @param array $obj Array of pdf-data
|
||||
* @return array|boolean
|
||||
*/
|
||||
protected function _getPageResources($obj)
|
||||
{
|
||||
$obj = $this->resolveObject($obj);
|
||||
|
||||
// If the current object has a resources
|
||||
// dictionary associated with it, we use
|
||||
// it. Otherwise, we move back to its
|
||||
// parent object.
|
||||
if (isset($obj[1][1]['/Resources'])) {
|
||||
$res = $this->resolveObject($obj[1][1]['/Resources']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
return $res;
|
||||
}
|
||||
|
||||
if (!isset($obj[1][1]['/Parent'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->_getPageResources($obj[1][1]['/Parent']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content of current page.
|
||||
*
|
||||
* If /Contents is an array, the streams are concatenated
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
$buffer = '';
|
||||
|
||||
if (isset($this->_pages[$this->pageNo][1][1]['/Contents'])) {
|
||||
$contents = $this->_getPageContent($this->_pages[$this->pageNo][1][1]['/Contents']);
|
||||
foreach ($contents AS $tmpContent) {
|
||||
$buffer .= $this->_unFilterStream($tmpContent) . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve all content objects.
|
||||
*
|
||||
* @param array $contentRef
|
||||
* @return array
|
||||
*/
|
||||
protected function _getPageContent($contentRef)
|
||||
{
|
||||
$contents = array();
|
||||
|
||||
if ($contentRef[0] == pdf_parser::TYPE_OBJREF) {
|
||||
$content = $this->resolveObject($contentRef);
|
||||
if ($content[1][0] == pdf_parser::TYPE_ARRAY) {
|
||||
$contents = $this->_getPageContent($content[1]);
|
||||
} else {
|
||||
$contents[] = $content;
|
||||
}
|
||||
} else if ($contentRef[0] == pdf_parser::TYPE_ARRAY) {
|
||||
foreach ($contentRef[1] AS $tmp_content_ref) {
|
||||
$contents = array_merge($contents, $this->_getPageContent($tmp_content_ref));
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a boundary box from a page
|
||||
*
|
||||
* Array format is same as used by FPDF_TPL.
|
||||
*
|
||||
* @param array $page a /Page dictionary
|
||||
* @param string $boxIndex Type of box {see {@link $availableBoxes})
|
||||
* @param float Scale factor from user space units to points
|
||||
*
|
||||
* @return array|boolean
|
||||
*/
|
||||
protected function _getPageBox($page, $boxIndex, $k)
|
||||
{
|
||||
$page = $this->resolveObject($page);
|
||||
$box = null;
|
||||
if (isset($page[1][1][$boxIndex])) {
|
||||
$box = $page[1][1][$boxIndex];
|
||||
}
|
||||
|
||||
if (!is_null($box) && $box[0] == pdf_parser::TYPE_OBJREF) {
|
||||
$tmp_box = $this->resolveObject($box);
|
||||
$box = $tmp_box[1];
|
||||
}
|
||||
|
||||
if (!is_null($box) && $box[0] == pdf_parser::TYPE_ARRAY) {
|
||||
$b = $box[1];
|
||||
return array(
|
||||
'x' => $b[0][1] / $k,
|
||||
'y' => $b[1][1] / $k,
|
||||
'w' => abs($b[0][1] - $b[2][1]) / $k,
|
||||
'h' => abs($b[1][1] - $b[3][1]) / $k,
|
||||
'llx' => min($b[0][1], $b[2][1]) / $k,
|
||||
'lly' => min($b[1][1], $b[3][1]) / $k,
|
||||
'urx' => max($b[0][1], $b[2][1]) / $k,
|
||||
'ury' => max($b[1][1], $b[3][1]) / $k,
|
||||
);
|
||||
} else if (!isset($page[1][1]['/Parent'])) {
|
||||
return false;
|
||||
} else {
|
||||
return $this->_getPageBox($this->resolveObject($page[1][1]['/Parent']), $boxIndex, $k);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all page boundary boxes by page number
|
||||
*
|
||||
* @param int $pageNo The page number
|
||||
* @param float $k Scale factor from user space units to points
|
||||
* @return array
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function getPageBoxes($pageNo, $k)
|
||||
{
|
||||
if (!isset($this->_pages[$pageNo - 1])) {
|
||||
throw new InvalidArgumentException('Page ' . $pageNo . ' does not exists.');
|
||||
}
|
||||
|
||||
return $this->_getPageBoxes($this->_pages[$pageNo - 1], $k);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all boxes from /Page dictionary
|
||||
*
|
||||
* @param array $page A /Page dictionary
|
||||
* @param float $k Scale factor from user space units to points
|
||||
* @return array
|
||||
*/
|
||||
protected function _getPageBoxes($page, $k)
|
||||
{
|
||||
$boxes = array();
|
||||
|
||||
foreach($this->availableBoxes AS $box) {
|
||||
if ($_box = $this->_getPageBox($page, $box, $k)) {
|
||||
$boxes[$box] = $_box;
|
||||
}
|
||||
}
|
||||
|
||||
return $boxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page rotation by page number
|
||||
*
|
||||
* @param integer $pageNo
|
||||
* @throws InvalidArgumentException
|
||||
* @return array
|
||||
*/
|
||||
public function getPageRotation($pageNo)
|
||||
{
|
||||
if (!isset($this->_pages[$pageNo - 1])) {
|
||||
throw new InvalidArgumentException('Page ' . $pageNo . ' does not exists.');
|
||||
}
|
||||
|
||||
return $this->_getPageRotation($this->_pages[$pageNo - 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rotation value of a page
|
||||
*
|
||||
* @param array $obj A /Page dictionary
|
||||
* @return array|bool
|
||||
*/
|
||||
protected function _getPageRotation($obj)
|
||||
{
|
||||
$obj = $this->resolveObject($obj);
|
||||
if (isset($obj[1][1]['/Rotate'])) {
|
||||
$res = $this->resolveObject($obj[1][1]['/Rotate']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
return $res;
|
||||
}
|
||||
|
||||
if (!isset($obj[1][1]['/Parent'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->_getPageRotation($obj[1][1]['/Parent']);
|
||||
if ($res[0] == pdf_parser::TYPE_OBJECT)
|
||||
return $res[1];
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all pages
|
||||
*
|
||||
* @param array $pages /Pages dictionary
|
||||
* @param array $result The result array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _readPages(&$pages, &$result)
|
||||
{
|
||||
// Get the kids dictionary
|
||||
$_kids = $this->resolveObject($pages[1][1]['/Kids']);
|
||||
|
||||
if (!is_array($_kids)) {
|
||||
throw new Exception('Cannot find /Kids in current /Page-Dictionary');
|
||||
}
|
||||
|
||||
if ($_kids[0] === self::TYPE_OBJECT) {
|
||||
$_kids = $_kids[1];
|
||||
}
|
||||
|
||||
$kids = $_kids[1];
|
||||
|
||||
foreach ($kids as $v) {
|
||||
$pg = $this->resolveObject($v);
|
||||
if ($pg[1][1]['/Type'][1] === '/Pages') {
|
||||
// If one of the kids is an embedded
|
||||
// /Pages array, resolve it as well.
|
||||
$this->_readPages($pg, $result);
|
||||
} else {
|
||||
$result[] = $pg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,153 +1,153 @@
|
||||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5.2
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class pdf_context
|
||||
*/
|
||||
class pdf_context
|
||||
{
|
||||
/**
|
||||
* Mode
|
||||
*
|
||||
* @var integer 0 = file | 1 = string
|
||||
*/
|
||||
protected $_mode = 0;
|
||||
|
||||
/**
|
||||
* @var resource|string
|
||||
*/
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $buffer;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
public $offset;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
public $length;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $stack;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @param resource $f
|
||||
*/
|
||||
public function __construct(&$f)
|
||||
{
|
||||
$this->file =& $f;
|
||||
if (is_string($this->file))
|
||||
$this->_mode = 1;
|
||||
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position in the file stream
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPos()
|
||||
{
|
||||
if ($this->_mode == 0) {
|
||||
return ftell($this->file);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the position in the file stream.
|
||||
*
|
||||
* Optionally move the file pointer to a new location and reset the buffered data.
|
||||
*
|
||||
* @param null $pos
|
||||
* @param int $l
|
||||
*/
|
||||
public function reset($pos = null, $l = 100)
|
||||
{
|
||||
if ($this->_mode == 0) {
|
||||
if (!is_null($pos)) {
|
||||
fseek ($this->file, $pos);
|
||||
}
|
||||
|
||||
$this->buffer = $l > 0 ? fread($this->file, $l) : '';
|
||||
$this->length = strlen($this->buffer);
|
||||
if ($this->length < $l)
|
||||
$this->increaseLength($l - $this->length);
|
||||
} else {
|
||||
$this->buffer = $this->file;
|
||||
$this->length = strlen($this->buffer);
|
||||
}
|
||||
$this->offset = 0;
|
||||
$this->stack = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that there is at least one character beyond the current offset in the buffer.
|
||||
*
|
||||
* To prevent the tokenizer from attempting to access data that does not exist.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ensureContent()
|
||||
{
|
||||
if ($this->offset >= $this->length - 1) {
|
||||
return $this->increaseLength();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully read more data into the buffer
|
||||
*
|
||||
* @param int $l
|
||||
* @return bool
|
||||
*/
|
||||
public function increaseLength($l = 100)
|
||||
{
|
||||
if ($this->_mode == 0 && feof($this->file)) {
|
||||
return false;
|
||||
} else if ($this->_mode == 0) {
|
||||
$totalLength = $this->length + $l;
|
||||
do {
|
||||
$toRead = $totalLength - $this->length;
|
||||
if ($toRead < 1)
|
||||
break;
|
||||
|
||||
$this->buffer .= fread($this->file, $toRead);
|
||||
} while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
//
|
||||
// FPDI - Version 1.5.2
|
||||
//
|
||||
// Copyright 2004-2014 Setasign - Jan Slabon
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/**
|
||||
* Class pdf_context
|
||||
*/
|
||||
class pdf_context
|
||||
{
|
||||
/**
|
||||
* Mode
|
||||
*
|
||||
* @var integer 0 = file | 1 = string
|
||||
*/
|
||||
protected $_mode = 0;
|
||||
|
||||
/**
|
||||
* @var resource|string
|
||||
*/
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $buffer;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
public $offset;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
public $length;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $stack;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*
|
||||
* @param resource $f
|
||||
*/
|
||||
public function __construct(&$f)
|
||||
{
|
||||
$this->file =& $f;
|
||||
if (is_string($this->file))
|
||||
$this->_mode = 1;
|
||||
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position in the file stream
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPos()
|
||||
{
|
||||
if ($this->_mode == 0) {
|
||||
return ftell($this->file);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the position in the file stream.
|
||||
*
|
||||
* Optionally move the file pointer to a new location and reset the buffered data.
|
||||
*
|
||||
* @param null $pos
|
||||
* @param int $l
|
||||
*/
|
||||
public function reset($pos = null, $l = 100)
|
||||
{
|
||||
if ($this->_mode == 0) {
|
||||
if (!is_null($pos)) {
|
||||
fseek ($this->file, $pos);
|
||||
}
|
||||
|
||||
$this->buffer = $l > 0 ? fread($this->file, $l) : '';
|
||||
$this->length = strlen($this->buffer);
|
||||
if ($this->length < $l)
|
||||
$this->increaseLength($l - $this->length);
|
||||
} else {
|
||||
$this->buffer = $this->file;
|
||||
$this->length = strlen($this->buffer);
|
||||
}
|
||||
$this->offset = 0;
|
||||
$this->stack = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that there is at least one character beyond the current offset in the buffer.
|
||||
*
|
||||
* To prevent the tokenizer from attempting to access data that does not exist.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ensureContent()
|
||||
{
|
||||
if ($this->offset >= $this->length - 1) {
|
||||
return $this->increaseLength();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully read more data into the buffer
|
||||
*
|
||||
* @param int $l
|
||||
* @return bool
|
||||
*/
|
||||
public function increaseLength($l = 100)
|
||||
{
|
||||
if ($this->_mode == 0 && feof($this->file)) {
|
||||
return false;
|
||||
} else if ($this->_mode == 0) {
|
||||
$totalLength = $this->length + $l;
|
||||
do {
|
||||
$toRead = $totalLength - $this->length;
|
||||
if ($toRead < 1)
|
||||
break;
|
||||
|
||||
$this->buffer .= fread($this->file, $toRead);
|
||||
} while ((($this->length = strlen($this->buffer)) != $totalLength) && !feof($this->file));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,393 +1,393 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parsetrees
|
||||
*
|
||||
* These are classes to build parsetrees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
abstract class _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Parser object
|
||||
* @var object
|
||||
*/
|
||||
public $parser;
|
||||
/**
|
||||
* Buffer content
|
||||
* @var mixed
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Return buffer
|
||||
*
|
||||
* @return string buffer content
|
||||
*/
|
||||
abstract public function to_smarty_php();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A complete smarty tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_tag extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Saved block nesting level
|
||||
* @var int
|
||||
*/
|
||||
public $saved_block_nesting;
|
||||
|
||||
/**
|
||||
* Create parse tree buffer for Smarty tag
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
$this->saved_block_nesting = $parser->block_nesting_level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return complied code that loads the evaluated outout of buffer content into a temporary variable
|
||||
*
|
||||
* @return string template code
|
||||
*/
|
||||
public function assign_to_var()
|
||||
{
|
||||
$var = sprintf('$_tmp%d', ++Smarty_Internal_Templateparser::$prefix_number);
|
||||
$this->parser->compiler->prefix_code[] = sprintf('<?php ob_start();?>%s<?php %s=ob_get_clean();?>', $this->data, $var);
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Code fragment inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_code extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for code fragment
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content in parentheses
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return sprintf("(%s)", $this->data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Double quoted string inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_doublequoted extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for double quoted string subtrees
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param _smarty_parsetree $subtree parsetree buffer
|
||||
*/
|
||||
public function __construct($parser, _smarty_parsetree $subtree)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->subtrees[] = $subtree;
|
||||
if ($subtree instanceof _smarty_tag) {
|
||||
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param _smarty_parsetree $subtree parsetree buffer
|
||||
*/
|
||||
public function append_subtree(_smarty_parsetree $subtree)
|
||||
{
|
||||
$last_subtree = count($this->subtrees) - 1;
|
||||
if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof _smarty_tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) {
|
||||
if ($subtree instanceof _smarty_code) {
|
||||
$this->subtrees[$last_subtree]->data .= '<?php echo ' . $subtree->data . ';?>';
|
||||
} elseif ($subtree instanceof _smarty_dq_content) {
|
||||
$this->subtrees[$last_subtree]->data .= '<?php echo "' . $subtree->data . '";?>';
|
||||
} else {
|
||||
$this->subtrees[$last_subtree]->data .= $subtree->data;
|
||||
}
|
||||
} else {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
if ($subtree instanceof _smarty_tag) {
|
||||
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge subtree buffer content together
|
||||
*
|
||||
* @return string compiled template code
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
$code = '';
|
||||
foreach ($this->subtrees as $subtree) {
|
||||
if ($code !== "") {
|
||||
$code .= ".";
|
||||
}
|
||||
if ($subtree instanceof _smarty_tag) {
|
||||
$more_php = $subtree->assign_to_var();
|
||||
} else {
|
||||
$more_php = $subtree->to_smarty_php();
|
||||
}
|
||||
|
||||
$code .= $more_php;
|
||||
|
||||
if (!$subtree instanceof _smarty_dq_content) {
|
||||
$this->parser->compiler->has_variable_string = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw chars as part of a double quoted string.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_dq_content extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer with string content
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data string section
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content as double quoted string
|
||||
*
|
||||
* @return string doubled quoted string
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return '"' . $this->data . '"';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Template element
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_template_buffer extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Array of template elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subtrees = Array();
|
||||
|
||||
/**
|
||||
* Create root of parse tree for template elements
|
||||
*
|
||||
* @param object $parser parse object
|
||||
*/
|
||||
public function __construct($parser)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param _smarty_parsetree $subtree
|
||||
*/
|
||||
public function append_subtree(_smarty_parsetree $subtree)
|
||||
{
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize and merge subtree buffers together
|
||||
*
|
||||
* @return string template code content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
$code = '';
|
||||
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
|
||||
if ($key + 2 < $cnt) {
|
||||
if ($this->subtrees[$key] instanceof _smarty_linebreak && $this->subtrees[$key + 1] instanceof _smarty_tag && $this->subtrees[$key + 1]->data == '' && $this->subtrees[$key + 2] instanceof _smarty_linebreak) {
|
||||
$key = $key + 1;
|
||||
continue;
|
||||
}
|
||||
if (substr($this->subtrees[$key]->data, -1) == '<' && $this->subtrees[$key + 1]->data == '' && substr($this->subtrees[$key + 2]->data, -1) == '?') {
|
||||
$key = $key + 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (substr($code, -1) == '<') {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
if (substr($subtree, 0, 1) == '?') {
|
||||
$code = substr($code, 0, strlen($code) - 1) . '<<?php ?>?' . substr($subtree, 1);
|
||||
} elseif ($this->parser->asp_tags && substr($subtree, 0, 1) == '%') {
|
||||
$code = substr($code, 0, strlen($code) - 1) . '<<?php ?>%' . substr($subtree, 1);
|
||||
} else {
|
||||
$code .= $subtree;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ($this->parser->asp_tags && substr($code, -1) == '%') {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
if (substr($subtree, 0, 1) == '>') {
|
||||
$code = substr($code, 0, strlen($code) - 1) . '%<?php ?>>' . substr($subtree, 1);
|
||||
} else {
|
||||
$code .= $subtree;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (substr($code, -1) == '?') {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
if (substr($subtree, 0, 1) == '>') {
|
||||
$code = substr($code, 0, strlen($code) - 1) . '?<?php ?>>' . substr($subtree, 1);
|
||||
} else {
|
||||
$code .= $subtree;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$code .= $this->subtrees[$key]->to_smarty_php();
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* template text
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_text extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create template text buffer
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data text
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @return strint text
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* template linebreaks
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_linebreak extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create buffer with linebreak content
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data linebreak string
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return linebrak
|
||||
*
|
||||
* @return string linebreak
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parsetrees
|
||||
*
|
||||
* These are classes to build parsetrees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
abstract class _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Parser object
|
||||
* @var object
|
||||
*/
|
||||
public $parser;
|
||||
/**
|
||||
* Buffer content
|
||||
* @var mixed
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Return buffer
|
||||
*
|
||||
* @return string buffer content
|
||||
*/
|
||||
abstract public function to_smarty_php();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A complete smarty tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_tag extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Saved block nesting level
|
||||
* @var int
|
||||
*/
|
||||
public $saved_block_nesting;
|
||||
|
||||
/**
|
||||
* Create parse tree buffer for Smarty tag
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
$this->saved_block_nesting = $parser->block_nesting_level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return complied code that loads the evaluated outout of buffer content into a temporary variable
|
||||
*
|
||||
* @return string template code
|
||||
*/
|
||||
public function assign_to_var()
|
||||
{
|
||||
$var = sprintf('$_tmp%d', ++Smarty_Internal_Templateparser::$prefix_number);
|
||||
$this->parser->compiler->prefix_code[] = sprintf('<?php ob_start();?>%s<?php %s=ob_get_clean();?>', $this->data, $var);
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Code fragment inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_code extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for code fragment
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content in parentheses
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return sprintf("(%s)", $this->data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Double quoted string inside a tag.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_doublequoted extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer for double quoted string subtrees
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param _smarty_parsetree $subtree parsetree buffer
|
||||
*/
|
||||
public function __construct($parser, _smarty_parsetree $subtree)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->subtrees[] = $subtree;
|
||||
if ($subtree instanceof _smarty_tag) {
|
||||
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param _smarty_parsetree $subtree parsetree buffer
|
||||
*/
|
||||
public function append_subtree(_smarty_parsetree $subtree)
|
||||
{
|
||||
$last_subtree = count($this->subtrees) - 1;
|
||||
if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof _smarty_tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) {
|
||||
if ($subtree instanceof _smarty_code) {
|
||||
$this->subtrees[$last_subtree]->data .= '<?php echo ' . $subtree->data . ';?>';
|
||||
} elseif ($subtree instanceof _smarty_dq_content) {
|
||||
$this->subtrees[$last_subtree]->data .= '<?php echo "' . $subtree->data . '";?>';
|
||||
} else {
|
||||
$this->subtrees[$last_subtree]->data .= $subtree->data;
|
||||
}
|
||||
} else {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
if ($subtree instanceof _smarty_tag) {
|
||||
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge subtree buffer content together
|
||||
*
|
||||
* @return string compiled template code
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
$code = '';
|
||||
foreach ($this->subtrees as $subtree) {
|
||||
if ($code !== "") {
|
||||
$code .= ".";
|
||||
}
|
||||
if ($subtree instanceof _smarty_tag) {
|
||||
$more_php = $subtree->assign_to_var();
|
||||
} else {
|
||||
$more_php = $subtree->to_smarty_php();
|
||||
}
|
||||
|
||||
$code .= $more_php;
|
||||
|
||||
if (!$subtree instanceof _smarty_dq_content) {
|
||||
$this->parser->compiler->has_variable_string = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw chars as part of a double quoted string.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_dq_content extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create parse tree buffer with string content
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data string section
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content as double quoted string
|
||||
*
|
||||
* @return string doubled quoted string
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return '"' . $this->data . '"';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Template element
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_template_buffer extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Array of template elements
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subtrees = Array();
|
||||
|
||||
/**
|
||||
* Create root of parse tree for template elements
|
||||
*
|
||||
* @param object $parser parse object
|
||||
*/
|
||||
public function __construct($parser)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append buffer to subtree
|
||||
*
|
||||
* @param _smarty_parsetree $subtree
|
||||
*/
|
||||
public function append_subtree(_smarty_parsetree $subtree)
|
||||
{
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize and merge subtree buffers together
|
||||
*
|
||||
* @return string template code content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
$code = '';
|
||||
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
|
||||
if ($key + 2 < $cnt) {
|
||||
if ($this->subtrees[$key] instanceof _smarty_linebreak && $this->subtrees[$key + 1] instanceof _smarty_tag && $this->subtrees[$key + 1]->data == '' && $this->subtrees[$key + 2] instanceof _smarty_linebreak) {
|
||||
$key = $key + 1;
|
||||
continue;
|
||||
}
|
||||
if (substr($this->subtrees[$key]->data, -1) == '<' && $this->subtrees[$key + 1]->data == '' && substr($this->subtrees[$key + 2]->data, -1) == '?') {
|
||||
$key = $key + 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (substr($code, -1) == '<') {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
if (substr($subtree, 0, 1) == '?') {
|
||||
$code = substr($code, 0, strlen($code) - 1) . '<<?php ?>?' . substr($subtree, 1);
|
||||
} elseif ($this->parser->asp_tags && substr($subtree, 0, 1) == '%') {
|
||||
$code = substr($code, 0, strlen($code) - 1) . '<<?php ?>%' . substr($subtree, 1);
|
||||
} else {
|
||||
$code .= $subtree;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ($this->parser->asp_tags && substr($code, -1) == '%') {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
if (substr($subtree, 0, 1) == '>') {
|
||||
$code = substr($code, 0, strlen($code) - 1) . '%<?php ?>>' . substr($subtree, 1);
|
||||
} else {
|
||||
$code .= $subtree;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (substr($code, -1) == '?') {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
if (substr($subtree, 0, 1) == '>') {
|
||||
$code = substr($code, 0, strlen($code) - 1) . '?<?php ?>>' . substr($subtree, 1);
|
||||
} else {
|
||||
$code .= $subtree;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$code .= $this->subtrees[$key]->to_smarty_php();
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* template text
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_text extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create template text buffer
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data text
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @return strint text
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* template linebreaks
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @ignore
|
||||
*/
|
||||
class _smarty_linebreak extends _smarty_parsetree
|
||||
{
|
||||
/**
|
||||
* Create buffer with linebreak content
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data linebreak string
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return linebrak
|
||||
*
|
||||
* @return string linebreak
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user