Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha #630

Merged
merged 9 commits into from
Sep 24, 2019
Merged

Alpha #630

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions 3rdparty/googleblockly/blocks/majordomo_states.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,33 @@
include_once("./config.php");
include_once("./lib/loader.php");

$session=new session("prj");
$session = new session("prj");

include_once("./load_settings.php");
include_once(DIR_MODULES . "control_modules/control_modules.class.php");

$objects = getObjectsByClass('OperationalModes');
$objects = getObjectsByClass('OperationalModes');

foreach($objects as $object) {
$object = SQLSelectOne("SELECT * FROM objects WHERE ID=".$object['ID']);
?>

foreach($objects as $object) {
$object = SQLSelectOne("SELECT * FROM objects WHERE ID=" . $object['ID']);
if (!$object['DESCRIPTION']) {
$object['DESCRIPTION']=$object['TITLE'];
}
?>

Blockly.Blocks['majordomo_<?php echo $object['TITLE']?>'] = {
init: function() {
init: function () {
var thisBlock = this;
this.setColour(220);
this.appendDummyInput()
.appendField('<?php echo addcslashes($object['DESCRIPTION'],"'")?>');
.appendField('<?php echo addcslashes($object['DESCRIPTION'], "'")?>');
this.setOutput(true);
this.setTooltip('');
}
};

<?php
}
}

$session->save();
2 changes: 2 additions & 0 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

$result = str_replace("nf.php", "admin.php", $result);

require(ROOT.'lib/utils/postprocess_general.inc.php');
require(ROOT.'lib/utils/postprocess_subscriptions.inc.php');
//require(ROOT.'lib/utils/postprocess_result.inc.php');


Expand Down
6 changes: 5 additions & 1 deletion css/menu_custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
}
.ui-listview>li>a.ui-btn {
padding: 0.3em 1em;
}
}
select {
background-color: Gray;
}

2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
$result = $cached_result;
}

require(ROOT.'lib/utils/postprocess_general.inc.php');
require(ROOT.'lib/utils/postprocess_subscriptions.inc.php');
require(ROOT.'lib/utils/postprocess_result.inc.php');

/**
Expand Down
2 changes: 2 additions & 0 deletions languages/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,8 @@
'PREVIOUS' => 'Prev',
'NEXT' => 'Next',
'LOCATED_IN_ROOM' => 'located in',
'BLOCK_SENSOR' => 'Block sensor',
'UNBLOCK_SENSOR' => 'Un-block sensor',

'TEST' => 'test'

Expand Down
3 changes: 3 additions & 0 deletions languages/ru.php
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,9 @@

'LOCATED_IN_ROOM' => 'расположеный в комнате',

'BLOCK_SENSOR' => 'Блокировать датчик',
'UNBLOCK_SENSOR' => 'Разблокировать датчик',

/* end module names */


Expand Down
1 change: 1 addition & 0 deletions lib/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ function getURLBackground($url, $cache = 0, $username = '', $password = '')
{
//DebMes("URL: ".$url,'debug1');
getURL($url, $cache, $username, $password, true);
return true;
}

/**
Expand Down
76 changes: 45 additions & 31 deletions lib/context.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
*/
function context_getuser()
{
global $context_user_id;
if ($context_user_id) {
return $context_user_id;
}

global $session;
if ($session->data['SITE_USER_ID'])
{
return $session->data['SITE_USER_ID'];
if ($session->data['SITE_USER_ID']) {
return (int)$session->data['SITE_USER_ID'];
}

$user = SQLSelectOne("SELECT ID FROM users WHERE IS_DEFAULT=1");

$session->data['SITE_USER_ID'] = $user['ID'];

return (int)$user['ID'];
Expand All @@ -23,19 +26,17 @@ function context_getuser()
* Summary of context_getcurrent
* @return int|string
*/
function context_getcurrent()
function context_getcurrent($from_user_id = 0)
{
$user_id = context_getuser();

if (!$from_user_id) {
$from_user_id = context_getuser();
}
$sqlQuery = "SELECT ID, ACTIVE_CONTEXT_ID, ACTIVE_CONTEXT_EXTERNAL
FROM users
WHERE ID = '" . (int)$user_id . "'";

WHERE ID = '" . (int)$from_user_id . "'";
$user = SQLSelectOne($sqlQuery);

if (!$user['ID'])
return 0;

if ($user['ACTIVE_CONTEXT_EXTERNAL'])
{
return 'ext' . (int)$user['ACTIVE_CONTEXT_ID'];
Expand All @@ -50,10 +51,11 @@ function context_getcurrent()
* Summary of context_get_history
* @return mixed
*/
function context_get_history()
function context_get_history($user_id = 0)
{
$user_id = context_getuser();

if (!$user_id) {
$user_id = context_getuser();
}
$sqlQuery = "SELECT ID, ACTIVE_CONTEXT_ID, ACTIVE_CONTEXT_EXTERNAL, ACTIVE_CONTEXT_HISTORY
FROM users
WHERE ID = '" . (int)$user_id . "'";
Expand All @@ -70,10 +72,13 @@ function context_get_history()
* Summary of context_clear
* @return void
*/
function context_clear()
function context_clear($user_id=0)
{
$user_id = context_getuser();


if (!$user_id) {
$user_id = context_getuser();
}

$user = SQLSelectOne("SELECT * FROM users WHERE ID = '" . (int)$user_id . "'");

$user['ACTIVE_CONTEXT_ID'] = 0;
Expand All @@ -91,9 +96,11 @@ function context_clear()
* @param mixed $history History (default '')
* @return void
*/
function context_activate($id, $no_action = 0, $history = '')
function context_activate($id, $no_action = 0, $history = '', $user_id = 0)
{
$user_id = context_getuser();
if (!$user_id) {
$user_id = context_getuser();
}
$user = SQLSelectOne("SELECT * FROM users WHERE ID = '" . (int)$user_id . "'");

$user['ACTIVE_CONTEXT_ID'] = $id;
Expand Down Expand Up @@ -127,7 +134,7 @@ function context_activate($id, $no_action = 0, $history = '')
}
else
{
context_clear();
context_clear($user_id);
clearTimeOut('user_' . $user_id . '_contexttimeout');
}
}
Expand All @@ -140,9 +147,12 @@ function context_activate($id, $no_action = 0, $history = '')
* @param mixed $timeout_context_id Timeout context id (default 0)
* @return void
*/
function context_activate_ext($id, $timeout = 0, $timeout_code = '', $timeout_context_id = 0)
function context_activate_ext($id, $timeout = 0, $timeout_code = '', $timeout_context_id = 0, $user_id = 0)
{
$user_id = context_getuser();

if (!$user_id) {
$user_id = context_getuser();
}
$user = SQLSelectOne("SELECT * FROM users WHERE ID = '" . (int)$user_id . "'");

$user['ACTIVE_CONTEXT_ID'] = $id;
Expand Down Expand Up @@ -176,7 +186,7 @@ function context_activate_ext($id, $timeout = 0, $timeout_code = '', $timeout_co
}
else
{
context_clear();
context_clear($user_id);
clearTimeOut('user_' . $user_id . '_contexttimeout');
}
}
Expand All @@ -187,18 +197,22 @@ function context_activate_ext($id, $timeout = 0, $timeout_code = '', $timeout_co
* @param mixed $user_id User ID
* @return void
*/
function context_timeout($id, $user_id)
function context_timeout($id, $user_id = 0)
{
global $session;

$user = SQLSelectOne("SELECT * FROM users WHERE ID = '" . (int)$user_id . "'");

$session->data['SITE_USER_ID'] = $user['ID'];
if (!$user_id) {
$user_id = context_getuser();
} else {
global $context_user_id;
$context_user_id = $user_id;
}
//global $session;
//$user = SQLSelectOne("SELECT * FROM users WHERE ID = '" . (int)$user_id . "'");
//$session->data['SITE_USER_ID'] = $user['ID'];

$context = SQLSelectOne("SELECT * FROM patterns WHERE ID = '" . (int)$id . "'");

if (!$context['TIMEOUT_CONTEXT_ID'])
context_activate(0);
if (!$context['TIMEOUT_CONTEXT_ID']) context_activate(0,0,'',$user_id);

if ($context['TIMEOUT_SCRIPT'])
{
Expand All @@ -221,7 +235,7 @@ function context_timeout($id, $user_id)
}

if ($context['TIMEOUT_CONTEXT_ID'])
context_activate((int)$context['TIMEOUT_CONTEXT_ID']);
context_activate((int)$context['TIMEOUT_CONTEXT_ID'],0,'',$user_id);
}

/**
Expand Down
35 changes: 19 additions & 16 deletions lib/hooks.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,40 +95,39 @@ function processSubscriptionsSafe($event_name, $details = '')
* @param mixed $details Details (default '')
* @return int|void
*/
function processSubscriptions($event_name, $details = '')
function processSubscriptions($event_name, $details = '', $return_output = false)
{
//DebMes("New event: ".$event_name,'process_subscription');
postToWebSocketQueue($event_name, $details, 'PostEvent');
if (!$return_output) {
postToWebSocketQueue($event_name, $details, 'PostEvent');
}
//DebMes("Post websocket event done: ".$event_name,'process_subscription');

if (!defined('SETTINGS_HOOK_EVENT_' . strtoupper($event_name))) {
DebMes("Processing not defined for " . 'SETTINGS_HOOK_EVENT_' . strtoupper($event_name), 'process_subscription');
//DebMes("Processing not defined for " . 'SETTINGS_HOOK_EVENT_' . strtoupper($event_name), 'process_subscription');
return 0;
}

$data = json_decode(constant('SETTINGS_HOOK_EVENT_' . strtoupper($event_name)), true);
//DebMes("Subscription data for ".'SETTINGS_HOOK_EVENT_' . strtoupper($event_name).": ".serialize($data),'process_subscription');

if (!is_array($data)) {
DebMes("Incorrect data for " . 'SETTINGS_HOOK_EVENT_' . strtoupper($event_name) . ':' . constant('SETTINGS_HOOK_EVENT_' . strtoupper($event_name)), 'process_subscription');
//DebMes("Incorrect data for " . 'SETTINGS_HOOK_EVENT_' . strtoupper($event_name) . ':' . constant('SETTINGS_HOOK_EVENT_' . strtoupper($event_name)), 'process_subscription');
} else {
$data2 = array();
foreach ($data as $k => $v) {
$data2[] = array('module' => $k, 'filter' => $v['filter'], 'priority' => (int)$v['priority']);
}

usort($data2, function ($a, $b) {
if ($a['priority'] == $b['priority']) return 0;
return ($a['priority'] > $b['priority']) ? -1 : 1;
});

$output = '';
$total = count($data2);
for ($i = 0; $i < $total; $i++) {
$module_name = $data2[$i]['module'];
$filter_details = $data2[$i]['filter'];

//DebMes("Post event ".$event_name." to module ".$module_name. " (details: ".json_encode($details).")",'process_subscription');

$modulePath = DIR_MODULES . $module_name . '/' . $module_name . '.class.php';

if (file_exists($modulePath)) {
Expand All @@ -138,30 +137,34 @@ function processSubscriptions($event_name, $details = '')
//DebMes("$module_name.processSubscription ($event_name)",'process_subscription');
verbose_log("Processing subscription to [" . $event_name . "] by [" . $module_name . "] (" . (is_array($details) ? json_encode($details) : '') . ")");
try {
$module_object->processSubscription($event_name, $details);
$output .= $module_object->processSubscription($event_name, $details);
} catch (Exception $e) {
DebMes('Error in processing "%s": ' . $e->getMessage(), 'process_subscription');
//DebMes('Error in processing "%s": ' . $e->getMessage(), 'process_subscription');
}
//DebMes("$module_name.processSubscription ($event_name) DONE",'process_subscription');
} else {
DebMes("$module_name.processSubscription error (method not found)", 'process_subscription');
//DebMes("$module_name.processSubscription error (method not found)", 'process_subscription');
}
if (!isset($details['BREAK'])) {
$details['BREAK'] = false;
}
if ($details['BREAK']) break;
} else {
DebMes("$module_name.processSubscription error (module class not found)", 'process_subscription');
//DebMes("$module_name.processSubscription error (module class not found)", 'process_subscription');
}
}

if (!isset($details['PROCESSED'])) {
$details['PROCESSED'] = false;
}
/*
if (!$details['PROCESSED'] && $event_name == 'COMMAND') { sayReplySafe(LANG_DEVICES_UNKNOWN_COMMAND,2);}
*/
return (int)$details['PROCESSED'];

//if (!$details['PROCESSED'] && $event_name == 'COMMAND') { sayReplySafe(LANG_DEVICES_UNKNOWN_COMMAND,2);}

if ($return_output) {
return $output;
} else {
return (int)$details['PROCESSED'];
}
}
return 0;

Expand Down
4 changes: 4 additions & 0 deletions lib/utils/postprocess_general.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

$result = preg_replace('/<!--\s+(\w)/','<!--$1',$result);
$result = preg_replace('/([\w\]])\s+-->/','$1-->',$result);
7 changes: 3 additions & 4 deletions lib/utils/postprocess_result.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


// BEGIN: begincut endcut placecut
if (preg_match_all('/<!-- placecut (\w+?) -->/is', $result, $matches))
if (preg_match_all('/<!--placecut (\w+?)-->/is', $result, $matches))
{
$matchesCount = count($matches[1]);
for ($i = 0; $i < $matchesCount; $i++)
{
$block = $matches[1][$i];
if (preg_match('/<!-- begincut ' . $block . ' -->(.*?)<!-- endcut ' . $block . ' -->/is', $result, $matches2))
if (preg_match('/<!--begincut ' . $block . ' -->(.*?)<!--endcut ' . $block . '-->/is', $result, $matches2))
{
$result = str_replace($matches[0][$i], $matches2[1], $result);
$result = str_replace($matches2[0], '', $result);
Expand All @@ -20,7 +20,7 @@
// BEGIN: filter output
if (isset($filterblock) && $filterblock != '')
{
$matchPattern = '/<!-- begin_data \[' . $filterblock . '\] -->(.*?)<!-- end_data \[' . $filterblock . '\] -->/is';
$matchPattern = '/<!--begin_data \[' . $filterblock . '\]-->(.*?)<!--end_data \[' . $filterblock . '\]-->/is';
preg_match($matchPattern, $result, $match);
$result = $match[1];
}
Expand Down Expand Up @@ -115,7 +115,6 @@
}

}

// END GLOBALS

// BEGIN: language constants
Expand Down