Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
getURLBackground fixes
  • Loading branch information
sergejey committed Nov 13, 2018
1 parent 08b539a commit 9cd1513
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 68 deletions.
101 changes: 39 additions & 62 deletions lib/common.class.php
Expand Up @@ -169,55 +169,7 @@ function say($ph, $level = 0, $member_id = 0, $source = '')
}

function ask($prompt, $target = '') {
processSubscriptions('ASK', array('prompt' => $prompt, 'message'=>$prompt, 'target' => $target, 'destination'=>$target));
/*
$service_port='7999';
$in='ask:'.$prompt;
if (preg_match('/^[\d\.]+$/',$target)) {
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket) {
$result = socket_connect($socket, $target, $service_port);
if ($result) {
socket_write($socket, $in, strlen($in));
}
}
socket_close($socket);
} elseif (preg_match('/^[a-zA-Z]+$/',$target)) {
$qry=1;
$qry.=" AND MAJORDROID_API=1";
$qry.=" AND (NAME LIKE '".DBSafe($target)."' OR TITLE LIKE '".DBSafe($target)."')";
$terminals = SQLSelect("SELECT * FROM terminals WHERE IS_ONLINE=$qry");
$total = count($terminals);
for ($i = 0; $i < $total; $i++) {
$address = $terminals[$i]['HOST'];
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket) {
$result = socket_connect($socket, $address, $service_port);
if ($result) {
socket_write($socket, $in, strlen($in));
}
}
socket_close($socket);
}
} else {
$qry=1;
$qry.=" AND MAJORDROID_API=1";
$terminals = SQLSelect("SELECT * FROM terminals WHERE IS_ONLINE=$qry");
$total = count($terminals);
for ($i = 0; $i < $total; $i++) {
$address = $terminals[$i]['HOST'];
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket) {
$result = socket_connect($socket, $address, $service_port);
if ($result) {
socket_write($socket, $in, strlen($in));
}
}
socket_close($socket);
}
}
*/
processSubscriptionsSafe('ASK', array('prompt' => $prompt, 'message'=>$prompt, 'target' => $target, 'destination'=>$target));
}

/**
Expand Down Expand Up @@ -711,17 +663,25 @@ function playMedia($path, $host = 'localhost', $safe_play = FALSE) {
return 0;
}

include_once(DIR_MODULES.'app_player/app_player.class.php');

$player = new app_player();
$player->terminal_id = $terminal['ID'];
$player->command = ($safe_play?'safe_play':'play');
$player->param = $path;
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);

return $player->json['success'];
$url = BASE_URL . ROOTHTML . 'ajax/app_player.html?';
$url .= "&command=".($safe_play?'safe_play':'play');
$url .= "&terminal_id=".$terminal['ID'];
$url .= "&param=" . urlencode($path);
//DebMes($url,'playmedia');
getURLBackground($url);
return 1;

/*
include_once(DIR_MODULES.'app_player/app_player.class.php');
$player = new app_player();
$player->terminal_id = $terminal['ID'];
$player->command = ($safe_play?'safe_play':'play');
$player->param = $path;
$player->ajax = TRUE;
$player->intCall = TRUE;
$player->usual($out);
return $player->json['success'];
*/
}

/**
Expand Down Expand Up @@ -775,7 +735,24 @@ function callScript($id, $params = '')
}

function getURLBackground($url, $cache = 0, $username = '', $password = '') {
getURL($url, $cache, $username, $password, true);
getURL($url, $cache, $username, $password, true);
/*
if (strlen($url)>=255) {
getURL($url, $cache, $username, $password, true);
} else {
$data = array();
if ($cache) {
$data['cache']=$cache;
}
if ($username) {
$data['username']=$username;
}
if ($password) {
$data['password']=$password;
}
addToOperationsQueue('getURLBackground',$url,json_encode($data),false,5*60);
}
*/
}

/**
Expand Down Expand Up @@ -815,7 +792,7 @@ function getURL($url, $cache = 0, $username = '', $password = '', $background =

if ($background) {
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1000);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1);
}

if ($username != '' || $password != '')
Expand Down
3 changes: 2 additions & 1 deletion lib/hooks.inc.php
Expand Up @@ -76,7 +76,8 @@ function processSubscriptionsSafe($event_name,$details='') {
$url.='&'.$k.'='.urlencode($v);
}
}
$result = getURL($url,0);
$result = getURLBackground($url,0);
//$result = getURL($url,0);
return $result;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/objects.class.php
Expand Up @@ -1333,8 +1333,8 @@ function objectClassChanged($object_id) {
}

function checkOperationsQueue($topic) {
$data=SQLSelect("SELECT * FROM operations_queue WHERE TOPIC='".DBSafe($topic)."' ORDER BY ID");
if ($data[0]['ID']) {
$data=SQLSelect("SELECT * FROM operations_queue WHERE TOPIC='".DBSafe($topic)."' ORDER BY EXPIRE");
if ($data[0]['TOPIC']) {
SQLExec("DELETE FROM operations_queue WHERE TOPIC='".DBSafe($topic)."'");
}
return $data;
Expand Down
1 change: 1 addition & 0 deletions modules/application.class.php
Expand Up @@ -362,6 +362,7 @@ function sortFiles($a, $b) {
global $ajax;
$ajax=1;
if (file_exists(DIR_MODULES.$this->action)) {
ignore_user_abort(1);
include_once(DIR_MODULES.$this->action.'/'.$this->action.'.class.php');
$obj="\$object$i";
$code="";
Expand Down
5 changes: 3 additions & 2 deletions modules/objects/objects.class.php
Expand Up @@ -1014,15 +1014,16 @@ function dbInstall($data) {
SQLExec($sqlQuery);

$sqlQuery = "CREATE TABLE IF NOT EXISTS `operations_queue`
(`ID` int(10) unsigned NOT NULL auto_increment,
`TOPIC` char(255) NOT NULL,
(`TOPIC` char(255) NOT NULL,
`DATANAME` char(255) NOT NULL,
`DATAVALUE` char(255) NOT NULL,
`EXPIRE` datetime NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE = MEMORY DEFAULT CHARSET=utf8;";
SQLExec($sqlQuery);

$sqlQuery = "ALTER TABLE operations_queue DROP COLUMN IF EXISTS `ID`;";
SQLExec($sqlQuery);


/*
Expand Down
2 changes: 1 addition & 1 deletion modules/terminals/terminals.class.php
Expand Up @@ -266,7 +266,7 @@ function terminalSay($terminal_rec, $message, $level)
function processSubscription($event, $details = '')
{
$this->getConfig();

DebMes("Processing $event: ".json_encode($details),'terminals');
if ($event == 'SAY') {
$terminals = SQLSelect("SELECT * FROM terminals WHERE CANTTS=1");
foreach ($terminals as $terminal_rec) {
Expand Down
1 change: 1 addition & 0 deletions objects/index.php
Expand Up @@ -91,6 +91,7 @@

//echo "object: $object op: $op m: $m status: $status ";exit;
if (!$commandLine) {
ignore_user_abort(1);
header('Content-Type: text/html; charset=utf-8');
}

Expand Down

0 comments on commit 9cd1513

Please sign in to comment.