本文整理汇总了PHP中getGlobal函数的典型用法代码示例。如果您正苦于以下问题:PHP getGlobal函数的具体用法?PHP getGlobal怎么用?PHP getGlobal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getGlobal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: poll_device
/**
* Title
*
* Description
*
* @access public
*/
function poll_device($id)
{
$rec = SQLSelectOne("SELECT * FROM modbusdevices WHERE ID='" . (int) $id . "'");
if (!$rec['ID']) {
return;
}
$rec['CHECK_LATEST'] = date('Y-m-d H:i:s');
$rec['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + (int) $rec['POLLPERIOD']);
SQLUpdate('modbusdevices', $rec);
if ($rec['LINKED_OBJECT'] && $rec['LINKED_PROPERTY'] && ($rec['REQUEST_TYPE'] == 'FC5' || $rec['REQUEST_TYPE'] == 'FC6' || $rec['REQUEST_TYPE'] == 'FC15' || $rec['REQUEST_TYPE'] == 'FC16' || $rec['REQUEST_TYPE'] == 'FC23')) {
$rec['DATA'] = getGlobal($rec['LINKED_OBJECT'] . '.' . $rec['LINKED_PROPERTY']);
}
require_once dirname(__FILE__) . '/ModbusMaster.php';
$modbus = new ModbusMaster($rec['HOST'], $rec['PROTOCOL']);
if ($rec['PORT']) {
$modbus->port = $rec['PORT'];
}
if ($rec['REQUEST_TYPE'] == 'FC1') {
//FC1 Read coils
try {
$recData = $modbus->readCoils($rec['DEVICE_ID'], $rec['REQUEST_START'], $rec['REQUEST_TOTAL']);
if (is_array($recData)) {
foreach ($recData as $k => $v) {
$recData[$k] = (int) $v;
}
}
} catch (Exception $e) {
// Print error information if any
$rec['LOG'] = date('Y-m-d H:i:s') . " FC1 Error: {$modbus} {$e}\n" . $rec['LOG'];
}
} elseif ($rec['REQUEST_TYPE'] == 'FC2') {
//FC2 Read input discretes
try {
$recData = $modbus->readInputDiscretes($rec['DEVICE_ID'], $rec['REQUEST_START'], $rec['REQUEST_TOTAL']);
if (is_array($recData)) {
foreach ($recData as $k => $v) {
$recData[$k] = (int) $v;
}
}
} catch (Exception $e) {
// Print error information if any
$rec['LOG'] = date('Y-m-d H:i:s') . " FC2 Error: {$modbus} {$e}\n" . $rec['LOG'];
}
} elseif ($rec['REQUEST_TYPE'] == 'FC3') {
//FC3 Read holding registers
try {
$recData = $modbus->readMultipleRegisters($rec['DEVICE_ID'], $rec['REQUEST_START'], $rec['REQUEST_TOTAL']);
} catch (Exception $e) {
// Print error information if any
$rec['LOG'] = date('Y-m-d H:i:s') . " FC3 Error: {$modbus} {$e}\n" . $rec['LOG'];
}
} elseif ($rec['REQUEST_TYPE'] == 'FC4') {
//FC4 Read holding input registers
try {
$recData = $modbus->readMultipleInputRegisters($rec['DEVICE_ID'], $rec['REQUEST_START'], $rec['REQUEST_TOTAL']);
} catch (Exception $e) {
// Print error information if any
$rec['LOG'] = date('Y-m-d H:i:s') . " FC4 Error: {$modbus} {$e}\n" . $rec['LOG'];
}
} elseif ($rec['REQUEST_TYPE'] == 'FC5') {
//FC5 Write single coil
if ((int) $rec['DATA']) {
$data_set = array(TRUE);
} else {
$data_set = array(FALSE);
}
try {
$modbus->writeSingleCoil($rec['DEVICE_ID'], $rec['REQUEST_START'], $data_set);
} catch (Exception $e) {
$rec['LOG'] = date('Y-m-d H:i:s') . " FC5 Error: {$modbus} {$e}\n" . $rec['LOG'];
}
} elseif ($rec['REQUEST_TYPE'] == 'FC6') {
//FC6 Write single register
try {
$data_set = array((int) $rec['DATA']);
if ($rec['RESPONSE_CONVERT'] == 'r2f') {
$dataTypes = array("REAL");
$swapregs = false;
} elseif ($rec['RESPONSE_CONVERT'] == 'r2fs') {
$dataTypes = array("REAL");
$swapregs = true;
} elseif ($rec['RESPONSE_CONVERT'] == 'd2i' || $rec['RESPONSE_CONVERT'] == 'dw2i') {
$dataTypes = array("DINT");
$swapregs = false;
} elseif ($rec['RESPONSE_CONVERT'] == 'd2is' || $rec['RESPONSE_CONVERT'] == 'dw2is') {
$dataTypes = array("DINT");
$swapregs = true;
} else {
$dataTypes = array("INT");
$swapregs = false;
}
$recData = $modbus->writeSingleRegister($rec['DEVICE_ID'], $rec['REQUEST_START'], $data_set, $dataTypes, $swapregs);
} catch (Exception $e) {
//.........这里部分代码省略.........
示例2: say
/**
* Title
*
* Description
*
* @access public
*/
function say($ph, $level=0) {
global $commandLine;
global $voicemode;
/*
if ($commandLine) {
echo utf2win($ph);
} else {
echo $ph;
}
*/
$rec=array();
$rec['MESSAGE']=$ph;
$rec['ADDED']=date('Y-m-d H:i:s');
$rec['ROOM_ID']=0;
$rec['MEMBER_ID']=0;
if ($level>0) {
$rec['IMPORTANCE']=$level;
}
SQLInsert('shouts', $rec);
if ($level>=(int)getGlobal('minMsgLevel')) { //$voicemode!='off' &&
$lang='en';
if (defined('SETTINGS_SITE_LANGUAGE')) {
$lang=SETTINGS_SITE_LANGUAGE;
}
if (defined('SETTINGS_VOICE_LANGUAGE')) {
$lang=SETTINGS_VOICE_LANGUAGE;
}
$google_file=GoogleTTS($ph, $lang);
if ($google_file) {
@touch($google_file);
playSound($google_file, 1, $level);
} else {
//getObject("alice")->raiseEvent("say", array("say"=>$ph));
safe_exec('cscript '.DOC_ROOT.'/rc/sapi.js '.$ph, 1, $level);
}
}
postToTwitter($ph);
global $noPatternMode;
if (!$noPatternMode) {
include_once(DIR_MODULES.'patterns/patterns.class.php');
$pt=new patterns();
$pt->checkAllPatterns();
}
}
示例3: cycleBody
/**
* Summary of cycleBody
* @return void
*/
function cycleBody()
{
// check main system states
$objects = getObjectsByClass('systemStates');
$total = count($objects);
for ($i = 0; $i < $total; $i++) {
$oldState = getGlobal($objects[$i]['TITLE'] . '.stateColor');
callMethod($objects[$i]['TITLE'] . '.checkState');
$newState = getGlobal($objects[$i]['TITLE'] . '.stateColor');
if ($newState != $oldState) {
echo $objects[$i]['TITLE'] . " state changed to " . $newState . PHP_EOL;
$params = array('STATE' => $newState);
callMethod($objects[$i]['TITLE'] . '.stateChanged', $params);
}
}
}
示例4: tick
public function tick()
{
global $config;
if (time() - $this->last_check > 3) {
$queue_data = getGlobal('IRCBot1.pushMessage');
$this->last_check = time();
if ($queue_data != '') {
setGlobal('IRCBot1.pushMessage', '');
$messages = explode("\n", $queue_data);
$total = count($messages);
for ($i = 0; $i < $total; $i++) {
if ($messages[$i]) {
sendMessage($this->socket, $this->config['channel'], iconv('UTF-8', $config['encoding'], $messages[$i]));
}
}
}
setGlobal('cycle_app_ircbotRun', time(), 1);
if (file_exists('./reboot')) {
global $db;
$db->Disconnect();
exit;
}
}
}
示例5: getPageGlobal
/**
* returns a page global
* currently an alias for getGlobal
* @since 3.4.0
*/
function getPageGlobal($var)
{
return getGlobal($var);
}
示例6: array
}
if (preg_match_all('/%(\\w{2,}?)\\.(\\w{2,}?)\\|(\\d+)%/isu', $result, $m)) {
if (!defined('DISABLE_WEBSOCKETS') || DISABLE_WEBSOCKETS == 0) {
$tracked_properties = array();
$total = count($m[0]);
$seen = array();
$sub_js = '';
for ($i = 0; $i < $total; $i++) {
$var = mb_strtolower($m[1][$i] . '.' . $m[2][$i], 'UTF-8');
if (!$seen[$var]) {
$tracked_properties[] = $var;
}
$seen[$var] = 1;
$id = 'var_' . preg_replace('/\\W/', '_', $var);
$sub_js .= "if (obj[i]['PROPERTY']=='{$var}') {\$('.{$id}').html(obj[i]['VALUE']);\$.publish('{$var}.updated', obj[i]['VALUE']);}\n";
$result = str_replace($m[0][$i], '<span class="' . $id . '">' . getGlobal($var) . '</span>', $result);
}
$js = "<script language='javascript'>\$.subscribe('wsConnected', function (_) {\n var payload;\n payload = new Object();\n payload.action = 'Subscribe';\n payload.data = new Object();\n payload.data.TYPE='properties';\n payload.data.PROPERTIES='" . implode(',', $tracked_properties) . "';\n wsSocket.send(JSON.stringify(payload));\n });\n";
$js .= "function processPropertiesUpdate(data) {\n var obj=jQuery.parseJSON(data);\n var objCnt = obj.length;\n if (objCnt) {\n for(var i=0;i<objCnt;i++) {\n {$sub_js}\n }\n }\n }";
$js .= "\$.subscribe('wsData', function (_, response) {\n if (response.action=='properties') {\n processPropertiesUpdate(response.data);\n }\n });";
$js .= '</script>';
$result = str_replace('</body>', $js . '</body>', $result);
} else {
$total = count($m[0]);
$seen = array();
for ($i = 0; $i < $total; $i++) {
$var = $m[1][$i] . '.' . $m[2][$i];
$interval = (int) $m[2][$i] * 1000;
if (!$interval) {
$interval = 10000;
}
示例7: SQLUpdate
$object_rec['CLASS_ID'] = $class_rec['ID'];
SQLUpdate('objects', $object_rec);
}
foreach ($known_fields as $k => $v) {
$prop_rec = SQLSelectOne("SELECT * FROM properties WHERE TITLE LIKE '" . DBSafe($k) . "' AND CLASS_ID = '" . $object_rec['CLASS_ID'] . "'");
if (!$prop_rec['ID']) {
$prop_rec['CLASS_ID'] = $object_rec['CLASS_ID'];
$prop_rec['TITLE'] = $k;
$prop_rec['KEEP_HISTORY'] = 7;
$prop_rec['ID'] = SQLInsert('properties', $prop_rec);
}
}
$res = '';
$updated = array();
foreach ($known_fields as $k => $v) {
if ($v < 0) {
continue;
}
$res .= $k . ' = ' . $data[(int) $v] . "\n";
$old_value = getGlobal('ws.' . $k);
if ($old_value != $data[(int) $v]) {
$updated[$k] = 1;
setGlobal('ws.' . $k, $data[(int) $v]);
}
}
if ($updated['pressure']) {
setGlobal('ws.pressureRt', round((double) getGlobal('ws.pressure') / 1.33), 1);
}
echo "OK";
$db->Disconnect();
// closing database connection
示例8: date
$old_hour = date('h');
if ($_GET['onetime']) {
$old_minute = -1;
if (date('i') == '00') {
$old_hour = -1;
}
}
$old_date = date('Y-m-d');
$checked_time = 0;
$started_time = time();
echo date("H:i:s") . " running " . basename(__FILE__) . "\n";
while (1) {
if (time() - $checked_time > 5) {
$checked_time = time();
setGlobal(str_replace('.php', '', basename(__FILE__)) . 'Run', time(), 1);
setGlobal('ThisComputer.uptime', time() - getGlobal('ThisComputer.started_time'));
}
$m = date('i');
$h = date('h');
$dt = date('Y-m-d');
if ($m != $old_minute) {
//echo "new minute\n";
$sqlQuery = "SELECT ID, TITLE\n FROM objects\n WHERE {$o_qry}";
$objects = SQLSelect($sqlQuery);
$total = count($objects);
for ($i = 0; $i < $total; $i++) {
echo date('H:i:s') . ' ' . $objects[$i]['TITLE'] . "->onNewMinute\n";
getObject($objects[$i]['TITLE'])->setProperty("time", date('Y-m-d H:i:s'));
getObject($objects[$i]['TITLE'])->raiseEvent("onNewMinute");
}
$old_minute = $m;
示例9: say
/**
* Title
*
* Description
*
* @access public
*/
function say($ph, $level = 0, $member_id = 0)
{
global $commandLine;
global $voicemode;
global $noPatternMode;
global $ignorePushover;
global $ignorePushbullet;
global $ignoreGrowl;
global $ignoreTwitter;
/*
if ($commandLine) {
echo utf2win($ph);
} else {
echo $ph;
}
*/
$rec = array();
$rec['MESSAGE'] = $ph;
$rec['ADDED'] = date('Y-m-d H:i:s');
$rec['ROOM_ID'] = 0;
$rec['MEMBER_ID'] = $member_id;
if ($level > 0) {
$rec['IMPORTANCE'] = $level;
}
$rec['ID'] = SQLInsert('shouts', $rec);
if ($member_id) {
//if (!$noPatternMode) {
include_once DIR_MODULES . 'patterns/patterns.class.php';
$pt = new patterns();
$pt->checkAllPatterns($member_id);
//}
return;
}
if (defined('SETTINGS_HOOK_BEFORE_SAY') && SETTINGS_HOOK_BEFORE_SAY != '') {
eval(SETTINGS_HOOK_BEFORE_SAY);
}
global $ignoreVoice;
if ($level >= (int) getGlobal('minMsgLevel') && !$ignoreVoice && !$member_id) {
//$voicemode!='off' &&
$lang = 'en';
if (defined('SETTINGS_SITE_LANGUAGE')) {
$lang = SETTINGS_SITE_LANGUAGE;
}
if (defined('SETTINGS_VOICE_LANGUAGE')) {
$lang = SETTINGS_VOICE_LANGUAGE;
}
if (!defined('SETTINGS_TTS_GOOGLE') || SETTINGS_TTS_GOOGLE) {
$google_file = GoogleTTS($ph, $lang);
} else {
$google_file = false;
}
if (!defined('SETTINGS_SPEAK_SIGNAL') || SETTINGS_SPEAK_SIGNAL == '1') {
$passed = time() - (int) getGlobal('lastSayTime');
if ($passed > 20) {
// play intro-sound only if more than 20 seconds passed from the last one
setGlobal('lastSayTime', time());
playSound('dingdong', 1, $level);
}
}
if ($google_file) {
@touch($google_file);
playSound($google_file, 1, $level);
} else {
safe_exec('cscript ' . DOC_ROOT . '/rc/sapi.js ' . $ph, 1, $level);
}
}
if (!$noPatternMode) {
include_once DIR_MODULES . 'patterns/patterns.class.php';
$pt = new patterns();
$pt->checkAllPatterns($member_id);
}
if (defined('SETTINGS_PUSHOVER_USER_KEY') && SETTINGS_PUSHOVER_USER_KEY && !$ignorePushover) {
include_once ROOT . 'lib/pushover/pushover.inc.php';
if (defined('SETTINGS_PUSHOVER_LEVEL')) {
if ($level >= SETTINGS_PUSHOVER_LEVEL) {
postToPushover($ph);
}
} elseif ($level > 0) {
postToPushover($ph);
}
}
if (defined('SETTINGS_PUSHBULLET_KEY') && SETTINGS_PUSHBULLET_KEY && !$ignorePushbullet) {
include_once ROOT . 'lib/pushbullet/pushbullet.inc.php';
if (defined('SETTINGS_PUSHBULLET_PREFIX') && SETTINGS_PUSHBULLET_PREFIX) {
$prefix = SETTINGS_PUSHBULLET_PREFIX . ' ';
} else {
$prefix = '';
}
if (defined('SETTINGS_PUSHBULLET_LEVEL')) {
if ($level >= SETTINGS_PUSHBULLET_LEVEL) {
postToPushbullet($prefix . $ph);
}
} elseif ($level > 0) {
//.........这里部分代码省略.........
示例10: SQLSelect
// CHECK/REPAIR/OPTIMIZE TABLES
$tables = SQLSelect("SHOW TABLES FROM `" . DB_NAME . "`");
$total = count($tables);
for ($i = 0; $i < $total; $i++) {
$table = $tables[$i]['Tables_in_' . DB_NAME];
echo 'Checking table [' . $table . '] ...';
if ($result = SQLExec("CHECK TABLE " . $table . ";")) {
echo "OK\n";
} else {
echo " broken ... repair ...";
SQLExec("REPAIR TABLE " . $table . ";");
echo "OK\n";
}
}
setGlobal('ThisComputer.started_time', time());
if (time() >= getGlobal('ThisComputer.started_time')) {
SQLExec("DELETE FROM events WHERE ADDED > NOW()");
SQLExec("DELETE FROM phistory WHERE ADDED > NOW()");
SQLExec("DELETE FROM history WHERE ADDED > NOW()");
SQLExec("DELETE FROM shouts WHERE ADDED > NOW()");
SQLExec("DELETE FROM jobs WHERE PROCESSED = 1");
SQLExec("DELETE FROM history WHERE (TO_DAYS(NOW()) - TO_DAYS(ADDED)) >= 5");
}
// CHECKING DATA
/*
$tables = array('commands' => 'commands',
'owproperties' => 'onewire',
'snmpproperties' => 'snmpdevices',
'zwave_properties' => 'zwave',
'mqtt' => 'mqtt',
'modbusdevices' => 'modbus');
示例11: SQLSelect
$res = SQLSelect("SELECT * FROM commands WHERE {$qry} ORDER BY {$sortby}");
if ($res[0]['ID']) {
if ($this->action != 'admin') {
$dynamic_res = array();
$total = count($res);
for ($i = 0; $i < $total; $i++) {
if ($res[$i]['SMART_REPEAT'] && $res[$i]['LINKED_OBJECT']) {
$obj = getObject($res[$i]['LINKED_OBJECT']);
$objects = getObjectsByClass($obj->class_id);
$total_o = count($objects);
for ($io = 0; $io < $total_o; $io++) {
$rec = $res[$i];
$rec['ID'] = $res[$i]['ID'] . '_' . $objects[$io]['ID'];
$rec['LINKED_OBJECT'] = $objects[$io]['TITLE'];
$rec['DATA'] = str_replace('%' . $res[$i]['LINKED_OBJECT'] . '.', '%' . $rec['LINKED_OBJECT'] . '.', $rec['DATA']);
$rec['CUR_VALUE'] = getGlobal($rec['LINKED_OBJECT'] . '.' . $rec['LINKED_PROPERTY']);
$rec['TITLE'] = $objects[$io]['TITLE'];
$dynamic_res[] = $rec;
}
} else {
$dynamic_res[] = $res[$i];
}
}
$res = $dynamic_res;
}
$this->processMenuElements($res);
if ($this->action == 'admin') {
$res = $this->buildTree_commands($res);
}
$out['RESULT'] = $res;
//$out['RESULT_HTML']=$this->buildHTML($out['RESULT']);
示例12: pollDevice
//.........这里部分代码省略.........
$comments_str = '';
for ($i = 0; $i < 255; $i++) {
if ($data->commandClasses->{"64"}->data->{$i}) {
$comments_str .= "{$i} = " . $data->commandClasses->{"64"}->data->{$i}->modeName->value . "; ";
}
}
$comments['Thermostat mode'] = $comments_str;
if (isset($data->commandClasses->{"67"}->data)) {
//ThermostatSetPoint
for ($i = 0; $i < 255; $i++) {
if ($data->commandClasses->{"67"}->data->{$i}->val) {
$key = 'ThermostatSetPoint ' . $data->commandClasses->{"67"}->data->{$i}->modeName->value;
$properties[$key] = $data->commandClasses->{"67"}->data->{$i}->val->value;
$command_classes[$key] = 67;
if ($data->commandClasses->{"67"}->data->{$i}->scaleString->value) {
$comments[$key] = $data->commandClasses->{"67"}->data->{$i}->scaleString->value;
}
}
}
}
if (isset($data->commandClasses->{"68"}->data->mode->value)) {
//ThermostatFanMode
$properties['ThermostatFanOn'] = (int) $data->commandClasses->{"68"}->data->on->value;
$command_classes['ThermostatFanMode'] = 68;
$properties['ThermostatFanMode'] = $data->commandClasses->{"68"}->data->mode->value;
if ($data->commandClasses->{"68"}->data->{"updateTime"} > $updateTime) {
$updateTime = $data->commandClasses->{"68"}->data->{"updateTime"};
}
$rec['SENSOR_VALUE'] .= " Fan Mode: " . $data->commandClasses->{"68"}->data->{$data->commandClasses->{"68"}->data->mode->value}->modeName->value . ';';
$comments_str = '';
for ($i = 0; $i < 255; $i++) {
if ($data->commandClasses->{"68"}->data->{$i}) {
$comments_str .= "{$i} = " . $data->commandClasses->{"68"}->data->{$i}->modeName->value . "; ";
}
}
$comments['ThermostatFanMode'] = $comments_str;
}
}
if ($updateTime) {
$properties['updateTime'] = $updateTime;
$rec['LATEST_UPDATE'] = date('Y-m-d H:i:s', $properties['updateTime']);
$rec_updated = 1;
}
if ($rec_updated) {
SQLUpdate('zwave_devices', $rec);
}
foreach ($properties as $k => $v) {
$prop = SQLSelectOne("SELECT * FROM zwave_properties WHERE DEVICE_ID='" . $rec['ID'] . "' AND UNIQ_ID LIKE '" . DBSafe($k) . "'");
$prop['DEVICE_ID'] = $rec['ID'];
$prop['UNIQ_ID'] = $k;
$prop['TITLE'] = $k;
$prop['COMMAND_CLASS'] = $command_classes[$k];
if ($prop['VALUE'] != $v) {
$prop['UPDATED'] = date('Y-m-d H:i:s');
}
if ($updatedList[$k]) {
$prop['UPDATED'] = date('Y-m-d H:i:s', $updatedList[$k]);
}
$prop['VALUE'] = $v;
if ($comments[$k]) {
$prop['COMMENTS'] = $comments[$k];
}
if (is_numeric($prop['VALUE']) && $prop['VALUE'] !== '') {
$prop['VALUE'] = round($prop['VALUE'], 3);
}
if ($prop['ID']) {
SQLUpdate('zwave_properties', $prop);
if ($prop['VALUE'] !== '') {
$validated = 1;
} else {
$validated = 0;
continue;
}
if ($prop['LINKED_OBJECT']) {
if ($prop['CORRECT_VALUE']) {
$prop['VALUE'] += (double) $prop['CORRECT_VALUE'];
}
}
if ($prop['VALIDATE']) {
if ((double) $prop['VALUE'] < (double) $prop['VALID_FROM'] || (double) $prop['VALUE'] > (double) $prop['VALID_TO']) {
$validated = 0;
}
}
if ($prop['LINKED_OBJECT'] && $prop['LINKED_PROPERTY'] && $validated) {
$old_value = getGlobal($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_PROPERTY']);
if ($prop['VALUE'] != $old_value) {
setGlobal($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_PROPERTY'], $prop['VALUE'], array($this->name => '0'));
}
}
if ($prop['LINKED_OBJECT'] && $prop['LINKED_METHOD'] && $validated && ($prop['VALUE'] != $old_value || !$prop['LINKED_PROPERTY'])) {
$params = array();
$params['VALUE'] = $prop['VALUE'];
callMethod($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_METHOD'], $params);
}
} else {
$prop['ID'] = SQLInsert('zwave_properties', $prop);
}
}
//print_r($data);exit;
}
示例13: processSubscription
function processSubscription($event, $details = '')
{
//to-do
if ($event == 'SAY') {
$level = $details['level'];
$message = $details['message'];
$current_queue = getGlobal('IRCBot1.pushMessage');
$queue = explode("\n", $current_queue);
$queue[] = $message;
if (count($queue) >= 25) {
$queue = array_slice($queue, -25);
}
setGlobal('IRCBot1.pushMessage', implode("\n", $queue));
}
}
示例14: run
function run()
{
global $session;
Define('ALTERNATIVE_TEMPLATES', 'templates_alt');
if ($this->action == 'ajaxgetglobal') {
header("HTTP/1.0: 200 OK\n");
header('Content-Type: text/html; charset=utf-8');
$res['DATA'] = getGlobal($_GET['var']);
echo json_encode($res);
global $db;
$db->Disconnect();
exit;
}
if ($this->action == 'ajaxsetglobal') {
header("HTTP/1.0: 200 OK\n");
header('Content-Type: text/html; charset=utf-8');
setGlobal($_GET['var'], $_GET['value']);
$res['DATA'] = 'OK';
echo json_encode($res);
global $db;
$db->Disconnect();
exit;
}
if ($this->action == 'getlatestnote') {
header("HTTP/1.0: 200 OK\n");
header('Content-Type: text/html; charset=utf-8');
$msg = SQLSelectOne("SELECT * FROM shouts WHERE MEMBER_ID=0 ORDER BY ID DESC LIMIT 1");
$res = array();
$res['DATA'] = $msg['MESSAGE'];
echo json_encode($res);
global $db;
$db->Disconnect();
exit;
}
if ($this->action == 'getlatestmp3') {
header("HTTP/1.0: 200 OK\n");
header('Content-Type: text/html; charset=utf-8');
if ($dir = @opendir(ROOT . "cached/voice")) {
while (($file = readdir($dir)) !== false) {
if (preg_match('/\\.mp3$/', $file)) {
$mtime = filemtime(ROOT . "cached/voice" . $file);
if (time() - $mtime > 60 * 60 * 24 && $mtime > 0) {
//old file, delete?
unlink(ROOT . "cached/voice" . $file);
} else {
$files[] = array('FILENAME' => $file, 'MTIME' => filemtime(ROOT . "cached/voice" . $file));
}
}
if (preg_match('/\\.wav$/', $file)) {
$mtime = filemtime(ROOT . "cached/voice" . $file);
if (time() - $mtime > 60 * 60 * 24 && $mtime > 0) {
//old file, delete?
unlink(ROOT . "cached/voice" . $file);
}
}
}
closedir($dir);
}
if (is_array($files)) {
function sortFiles($a, $b)
{
if ($a['MTIME'] == $b['MTIME']) {
return 0;
}
return $a['MTIME'] > $b['MTIME'] ? -1 : 1;
}
usort($files, 'sortFiles');
echo '/cached/voice/' . $files[0]['FILENAME'];
}
global $db;
$db->Disconnect();
exit;
}
if (!defined('SETTINGS_SITE_LANGUAGE') || !defined('SETTINGS_SITE_TIMEZONE') || !defined('SETTINGS_TTS_GOOGLE') || !defined('SETTINGS_GROWL_ENABLE') || !defined('SETTINGS_HOOK_BEFORE_SAY')) {
$this->action = 'first_start';
}
if ($this->action == 'first_start') {
include DIR_MODULES . 'first_start.php';
}
$out["ACTION"] = $this->action;
$out["TODAY"] = date('l, F d, Y');
$out["DOC_NAME"] = $this->doc_name;
global $username;
if ($username) {
$user = SQLSelectOne("SELECT * FROM users WHERE USERNAME LIKE '" . DBSafe($username) . "'");
if (!$user['PASSWORD']) {
$session->data['SITE_USERNAME'] = $user['USERNAME'];
$session->data['SITE_USER_ID'] = $user['ID'];
} else {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="MajorDoMo"');
header('HTTP/1.0 401 Unauthorized');
echo 'Password required!';
exit;
} else {
if ($_SERVER['PHP_AUTH_USER'] == $user['USERNAME'] && $_SERVER['PHP_AUTH_PW'] == $user['PASSWORD']) {
$session->data['SITE_USERNAME'] = $user['USERNAME'];
$session->data['SITE_USER_ID'] = $user['ID'];
} else {
header('WWW-Authenticate: Basic realm="MajorDoMo"');
//.........这里部分代码省略.........
示例15: control_modules
include_once "./load_settings.php";
include_once DIR_MODULES . "control_modules/control_modules.class.php";
$ctl = new control_modules();
include_once DIR_MODULES . 'app_asterisk/app_asterisk.class.php';
$asterisk = new app_asterisk();
$asterisk->getConfig();
$parent_class_rec = SQLSelectOne("SELECT * FROM classes WHERE TITLE LIKE 'Telephony'");
if ($parent_class_rec['ID']) {
$class_rec = SQLSelectOne("SELECT * FROM classes WHERE TITLE LIKE 'AsteriskAMI' AND PARENT_ID = '" . $parent_class_rec['ID'] . "'");
if ($class_rec['ID']) {
$obj_rec = SQLSelectOne("SELECT * FROM objects WHERE CLASS_ID='" . $class_rec['ID'] . "'");
if ($obj_rec['ID']) {
$amihost = getGlobal($obj_rec['TITLE'] . '.amihost');
$amiport = getGlobal($obj_rec['TITLE'] . '.amiport');
$amiusername = getGlobal($obj_rec['TITLE'] . '.amiusername');
$amipassword = getGlobal($obj_rec['TITLE'] . '.amipassword');
}
}
}
if (!$amihost) {
echo date('Y-m-d H:i:s') . " : AMI is not configured. No need to run cycle\n";
exit;
}
echo date("Y-m-d H:i:s") . " running " . basename(__FILE__) . PHP_EOL;
include './lib/phpagi/phpagi-asmanager.php';
$manager = new AGI_AsteriskManager();
echo date('Y-m-d H:i:s') . " : Connecting to AMI... ";
if (!$manager->connect($amihost . ":" . $amiport, $amiusername, $amipassword)) {
echo " ...Connection failed.\n";
exit;
} else {