/** * jTemplates-parse * Used to parse jTemplates * @access private * @param mixed $template jTemplate filename * @param mixed $data Data * @return string */ public function jtemplate_parse($template, &$data) { /* if (preg_match('/menu\.html/', $_SERVER['REQUEST_URI'])) { $compl=new jTemplateCompiler($template, "out", $this->owner); $out=&$data; include($compl->compiled_file); } */ startMeasure('Parse template ' . $template); $jTempl = new jTemplate($template, $data, $this->owner); $result = $jTempl->result; endMeasure('Parse template ' . $template); return $result; }
function processMenuElements(&$res) { startMeasure('processMenuElements'); startMeasure('processMenuElements ' . $_SERVER['REQUEST_URI']); if ($this->action != 'admin') { $total = count($res); $res2 = array(); for ($i = 0; $i < $total; $i++) { if (checkAccess('menu', $res[$i]['ID'])) { $res2[] = $res[$i]; } } $res = $res2; unset($res2); } $total = count($res); for ($i = 0; $i < $total; $i++) { // some action for every record if required if ($res[$i + 1]['INLINE']) { $res[$i]['INLINE'] = 1; } $item = $res[$i]; if ($item['VISIBLE_DELAY']) { $out['VISIBLE_DELAYS']++; } if ($item['EXT_ID'] && $this->action != 'admin') { $visible_delay = $item['VISIBLE_DELAY']; $tmp = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item['EXT_ID'] . "'"); if ($tmp['ID']) { $item = $tmp; $item['VISIBLE_DELAY'] = $visible_delay; $res[$i] = $item; } } elseif ($item['EXT_ID'] && $this->action == 'admin') { $tmp = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item['EXT_ID'] . "'"); if ($tmp['ID']) { $item['TITLE'] = $item['TITLE'] . ' (' . $tmp['TITLE'] . ')'; $res[$i] = $item; } } if ($item['LINKED_PROPERTY'] != '') { $lprop = getGlobal($item['LINKED_OBJECT'] . '.' . $item['LINKED_PROPERTY']); if ($item['TYPE'] == 'custom') { $field = 'DATA'; } else { $field = 'CUR_VALUE'; } if ($lprop != $item[$field]) { $item[$field] = $lprop; SQLUpdate('commands', $item); $res[$i] = $item; } } if ($item['TYPE'] == 'timebox') { $tmp = explode(':', $item['CUR_VALUE']); $value1 = (int) $tmp[0]; $value2 = (int) $tmp[1]; for ($h = 0; $h <= 23; $h++) { $v = $h; if ($v < 10) { $v = '0' . $v; } $selected = 0; if ($h == $value1) { $selected = 1; } $item['OPTIONS1'][] = array('VALUE' => $v, 'SELECTED' => $selected); } for ($h = 0; $h <= 59; $h++) { $v = $h; if ($v < 10) { $v = '0' . $v; } $selected = 0; if ($h == $value2) { $selected = 1; } $item['OPTIONS2'][] = array('VALUE' => $v, 'SELECTED' => $selected); } $res[$i] = $item; } if ($item['TYPE'] == 'switch') { if (trim($item['DATA'])) { $data = explode("\n", str_replace("\r", "", $item['DATA'])); $item['OFF_VALUE'] = trim($data[0]); $item['ON_VALUE'] = trim($data[1]); } else { $item['OFF_VALUE'] = 0; $item['ON_VALUE'] = 1; } $res[$i] = $item; } if ($item['TYPE'] == 'selectbox' || $item['TYPE'] == 'radiobox') { $data = explode("\n", str_replace("\r", "", $item['DATA'])); $item['OPTIONS'] = array(); $num = 1; foreach ($data as $line) { $line = trim($line); if ($line != '') { $option = array(); if (preg_match('/=/', $line)) { $tmp = explode('=', $line); } else { $tmp = explode('|', $line); } $option['VALUE'] = $tmp[0]; if ($tmp[1] != '') { $option['TITLE'] = $tmp[1]; } else { $option['TITLE'] = $option['VALUE']; } if ($option['VALUE'] == $item['CUR_VALUE']) { $option['SELECTED'] = 1; } $option['NUM'] = $num; $num++; $item['OPTIONS'][] = $option; } } $res[$i] = $item; } if ($this->owner->name != 'panel') { $res[$i]['TITLE'] = processTitle($res[$i]['TITLE'], $this); if ($res[$i]['TYPE'] == 'custom') { $res[$i]['DATA'] = processTitle($res[$i]['DATA'], $this); } if (preg_match('/#[\\w\\d]{6}/is', $res[$i]['TITLE'], $m)) { $color = $m[0]; $res[$i]['TITLE'] = trim(str_replace($m[0], '<style>#item' . $res[$i]['ID'] . ' .ui-btn-active {background-color:' . $color . ';border-color:' . $color . '}</style>', $res[$i]['TITLE'])); } if ($res[$i]['RENDER_TITLE'] != $res[$i]['TITLE'] || $res[$i]['RENDER_DATA'] != $res[$i]['DATA']) { $tmp = SQLSelectOne("SELECT * FROM commands WHERE ID='" . $res[$i]['ID'] . "'"); $tmp['RENDER_TITLE'] = $res[$i]['TITLE']; $tmp['RENDER_DATA'] = $res[$i]['DATA']; $tmp['RENDER_UPDATED'] = date('Y-m-d H:i:s'); SQLUpdate('commands', $tmp); } } if (preg_match('/<script/is', $res[$i]['DATA']) && $res[$i]['AUTO_UPDATE']) { $res[$i]['AUTO_UPDATE'] = 0; } $res[$i]['TITLE_SAFE'] = htmlspecialchars($res[$i]['TITLE']); /* foreach($res[$i] as $k=>$v) { if (!is_array($res[$i][$k]) && $k!='DATA') { $res[$i][$k]=addslashes($v); } } */ $tmp = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM commands WHERE PARENT_ID='" . $res[$i]['ID'] . "'"); if ($tmp['TOTAL']) { $res[$i]['RESULT_TOTAL'] = $tmp['TOTAL']; } if ($res[$i]['SUB_PRELOAD'] && $this->action != 'admin') { $children = SQLSelect("SELECT * FROM commands WHERE PARENT_ID='" . $res[$i]['ID'] . "' ORDER BY PRIORITY DESC, TITLE"); if ($children[0]['ID']) { $this->processMenuElements($children); if ($children[0]['ID']) { $res[$i]['RESULT'] = $children; } } } } endMeasure('processMenuElements ' . $_SERVER['REQUEST_URI'], 1); endMeasure('processMenuElements', 1); }
<?php /** * Main project script * * @package MajorDoMo * @author Serge Dzheigalo <*****@*****.**> http://smartliving.ru/ * @version 1.1 */ include_once "./config.php"; include_once "./lib/loader.php"; // start calculation of execution time startMeasure('TOTAL'); include_once DIR_MODULES . "application.class.php"; $session = new session("prj"); const GPS_LOCATION_RANGE_DEFAULT = 500; // connecting to database $db = new mysql(DB_HOST, '', DB_USER, DB_PASSWORD, DB_NAME); include_once "./load_settings.php"; if ($_REQUEST['location']) { $tmp = explode(',', $_REQUEST['location']); $_REQUEST['latitude'] = $tmp[0]; $_REQUEST['longitude'] = $tmp[1]; } if ($_REQUEST['op'] != '') { $op = $_REQUEST['op']; $ok = 0; if ($op == 'zones') { $zones = SQLSelect("SELECT * FROM gpslocations"); echo json_encode(array('RESULT' => array('ZONES' => $zones, 'STATUS' => 'OK'))); $ok = 1;
} } } // END: language constants if (!headers_sent()) { header("HTTP/1.0: 200 OK\n"); header('Content-Type: text/html; charset=utf-8'); } function echobig($string, $bufferSize = 8192) { $chars = strlen($string) - 1; for ($start = 0; $start <= $chars; $start += $bufferSize) { echo substr($string, $start, $bufferSize); } } startMeasure('final_echo'); ob_start("ob_gzhandler"); // should be un-commented for production server echobig($result); endMeasure('final_echo', 1); if ($cache_filename != '' && $cached_result == '') { SaveFile(ROOT . 'cached/' . $cache_filename, $result); } $session->save(); // closing database connection $db->Disconnect(); // end calculation of execution time endMeasure('TOTAL'); // print performance report performanceReport(); // ob_end_flush();
/** * Title * * Description * * @access public */ function setProperty($property, $value, $no_linked = 0) { startMeasure('setProperty'); startMeasure('setProperty (' . $property . ')'); $id = $this->getPropertyByName($property, $this->class_id, $this->id); $old_value = ''; if ($id) { $prop = SQLSelectOne("SELECT * FROM properties WHERE ID='" . $id . "'"); $v = SQLSelectOne("SELECT * FROM pvalues WHERE PROPERTY_ID='" . (int) $id . "' AND OBJECT_ID='" . (int) $this->id . "'"); $old_value = $v['VALUE']; $v['VALUE'] = $value; if ($v['ID']) { $v['UPDATED'] = date('Y-m-d H:i:s'); if ($old_value != $value) { SQLUpdate('pvalues', $v); //DebMes("Setting [".$this->object_title.".".$property."] to new value [".$value."]"); } else { SQLExec("UPDATE pvalues SET UPDATED='" . $v['UPDATED'] . "' WHERE ID='" . $v['ID'] . "'"); //DebMes("Setting [".$this->object_title.".".$property."] to the same value [".$value."]"); } } else { $v['PROPERTY_ID'] = $id; $v['OBJECT_ID'] = $this->id; $v['VALUE'] = $value; $v['UPDATED'] = date('Y-m-d H:i:s'); $v['ID'] = SQLInsert('pvalues', $v); } //DebMes(" $id to $value "); } else { $prop = array(); $prop['OBJECT_ID'] = $this->id; $prop['TITLE'] = $property; $prop['ID'] = SQLInsert('properties', $prop); $v['PROPERTY_ID'] = $prop['ID']; $v['OBJECT_ID'] = $this->id; $v['VALUE'] = $value; $v['UPDATED'] = date('Y-m-d H:i:s'); $v['ID'] = SQLInsert('pvalues', $v); } if ($prop['KEEP_HISTORY'] > 0) { startMeasure('DeleteOldHistory'); SQLExec("DELETE FROM phistory WHERE VALUE_ID='" . $v['ID'] . "' AND TO_DAYS(NOW())-TO_DAYS(ADDED)>" . (int) $prop['KEEP_HISTORY']); endMeasure('DeleteOldHistory', 1); $h = array(); $h['VALUE_ID'] = $v['ID']; $h['ADDED'] = date('Y-m-d H:i:s'); $h['VALUE'] = $value; $h['ID'] = SQLInsert('phistory', $h); } /* $h=array(); $h['ADDED']=date('Y-m-d H:i:s'); $h['OBJECT_ID']=$this->id; $h['VALUE_ID']=$v['ID']; $h['OLD_VALUE']=$old_value; $h['NEW_VALUE']=$value; SQLInsert('history', $h); */ //commands, owproperties, snmpproperties, zwave_properties, mqtt $tables = array('commands', 'owproperties', 'snmpproperties', 'zwave_properties', 'mqtt', 'modbusdevices'); if (!is_array($no_linked) && $no_linked) { $no_linked = array(); foreach ($tables as $t) { $no_linked[$k] = '0'; } } elseif (is_array($no_linked)) { foreach ($tables as $t) { if (!isset($no_linked[$k])) { $no_linked[$k] = '1'; } } } else { $no_linked = array(); foreach ($tables as $t) { $no_linked[$k] = '1'; } } foreach ($tables as $t) { if ($no_linked[$t] == '') { $no_linked[$t] = '1'; } } if ($no_linked['commands'] != '') { $commands = SQLSelect("SELECT * FROM commands WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['commands']); $total = count($commands); for ($i = 0; $i < $total; $i++) { $commands[$i]['CUR_VALUE'] = $value; SQLUpdate('commands', $commands[$i]); } } if ($no_linked['owproperties'] != '' && file_exists(DIR_MODULES . '/onewire/onewire.class.php')) { $owp = SQLSelect("SELECT ID FROM owproperties WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['owproperties']); $total = count($owp); if ($total) { include_once DIR_MODULES . '/onewire/onewire.class.php'; $on_wire = new onewire(); for ($i = 0; $i < $total; $i++) { $on_wire->setProperty($owp[$i]['ID'], $value); } } } if ($no_linked['snmpproperties'] != '' && file_exists(DIR_MODULES . '/snmpdevices/snmpdevices.class.php')) { $snmpdevices = SQLSelect("SELECT ID FROM snmpproperties WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['snmpproperties']); $total = count($snmpdevices); if ($total) { include_once DIR_MODULES . '/snmpdevices/snmpdevices.class.php'; $snmp = new snmpdevices(); for ($i = 0; $i < $total; $i++) { $snmp->setProperty($snmpdevices[$i]['ID'], $value); } } } if ($no_linked['zwave_properties'] != '' && file_exists(DIR_MODULES . '/zwave/zwave.class.php')) { $zwave_properties = SQLSelect("SELECT ID FROM zwave_properties WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['zwave_properties']); $total = count($zwave_properties); if ($total) { include_once DIR_MODULES . '/zwave/zwave.class.php'; $zwave = new zwave(); for ($i = 0; $i < $total; $i++) { $zwave->setProperty($zwave_properties[$i]['ID'], $value); } } } if ($no_linked['mqtt'] != '' && file_exists(DIR_MODULES . '/mqtt/mqtt.class.php')) { $mqtt_properties = SQLSelect("SELECT ID FROM mqtt WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['mqtt']); $total = count($mqtt_properties); if ($total) { include_once DIR_MODULES . '/mqtt/mqtt.class.php'; $mqtt = new mqtt(); for ($i = 0; $i < $total; $i++) { $mqtt->setProperty($mqtt_properties[$i]['ID'], $value); } } } if ($no_linked['modbusdevices'] != '' && file_exists(DIR_MODULES . '/modbus/modbus.class.php')) { $modbusdevices = SQLSelect("SELECT ID FROM modbusdevices WHERE LINKED_OBJECT LIKE '" . DBSafe($this->object_title) . "' AND LINKED_PROPERTY LIKE '" . DBSafe($property) . "' AND " . $no_linked['modbusdevices']); $total = count($modbusdevices); if ($total) { include_once DIR_MODULES . '/modbus/modbus.class.php'; $modbus = new modbus(); for ($i = 0; $i < $total; $i++) { $modbus->poll_device($modbusdevices[$i]['ID']); } } } if ($prop['ONCHANGE']) { global $property_linked_history; if (!$property_linked_history[$property][$prop['ONCHANGE']]) { $property_linked_history[$property][$prop['ONCHANGE']] = 1; global $on_change_called; $params = array(); $params['PROPERTY'] = $property; $params['NEW_VALUE'] = (string) $value; $params['OLD_VALUE'] = (string) $old_value; $this->callMethod($prop['ONCHANGE'], $params); unset($property_linked_history[$property][$prop['ONCHANGE']]); } } endMeasure('setProperty (' . $property . ')', 1); endMeasure('setProperty', 1); }
<? /** * RSS script * * @package MajorDoMo * @author Serge Dzheigalo <*****@*****.**> http://smartliving.ru/ * @version 1.1 */ include_once("./config.php"); include_once("./lib/loader.php"); startMeasure('TOTAL'); // start calculation of execution time include_once(DIR_MODULES."application.class.php"); $session=new session("prj"); $db=new mysql(DB_HOST, '', DB_USER, DB_PASSWORD, DB_NAME); // connecting to database // get settings $settings = SQLSelect('SELECT NAME, VALUE FROM settings'); $total = count($settings); for ($i = 0; $i < $total; $i ++) Define('SETTINGS_' . $settings[$i]['NAME'], $settings[$i]['VALUE']); // language selection by settings if (SETTINGS_SITE_LANGUAGE && file_exists(ROOT . 'languages/' . SETTINGS_SITE_LANGUAGE . '.php')) include_once (ROOT . 'languages/' . SETTINGS_SITE_LANGUAGE . '.php'); include_once (ROOT . 'languages/default.php'); if (defined('SETTINGS_SITE_TIMEZONE')) {
/** * processTitle * * Description * * @access public */ function processTitle($title, $object = 0) { global $title_memory_cache; $key = $title; if (!$title) { return $title; } startMeasure('processTitle'); $in_title = substr($title, 0, 100); //startMeasure('processTitle ['.$in_title.']'); if ($in_title != '') { if ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { if ($title_memory_cache[$key]) { return $title_memory_cache[$key]; } } if (preg_match('/\\[#.+?#\\]/is', $title)) { startMeasure('processTitleJTemplate'); if ($object) { $jTempl = new jTemplate($title, $object->data, $object); } else { $jTempl = new jTemplate($title, $data, $this); } $title = $jTempl->result; endMeasure('processTitleJTemplate'); } $title = preg_replace('/%rand%/is', rand(), $title); if (preg_match_all('/%([\\w\\d\\.]+?)\\.([\\w\\d\\.]+?)%/is', $title, $m)) { startMeasure('processTitleProperties'); $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], getGlobal($m[1][$i] . '.' . $m[2][$i]), $title); } endMeasure('processTitleProperties'); } elseif (preg_match_all('/%([\\w\\d\\.]+?)%/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { if (preg_match('/^%\\d/is', $m[0][$i])) { continue; // dirty hack, sorry for that } $title = str_replace($m[0][$i], getGlobal($m[1][$i]), $title); } } if (preg_match_all('/<#LANG_(\\w+?)#>/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], constant('LANG_' . $m[1][$i]), $title); } } if (preg_match_all('/\\<#LANG_(.+?)#\\>/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], constant('LANG_' . $m[1][$i]), $title); } } } //endMeasure('processTitle ['.$in_title.']', 1); if ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST') { $title_memory_cache[$key] = $title; } endMeasure('processTitle', 1); return $title; }
/** * Title * * Description * * @access public */ function getElements($qry = '1', $options = 0) { $elements = SQLSelect("SELECT * FROM elements WHERE {$qry} ORDER BY PRIORITY DESC, TITLE"); /* $totale=count($elements); $res2=array(); for($ie=0;$ie<$totale;$ie++) { if (checkAccess('scene_elements', $elements[$ie]['ID'])) { $res2[]=$elements[$ie]; } } $elements=$res2; */ $totale = count($elements); for ($ie = 0; $ie < $totale; $ie++) { if ($elements[$ie]['CSS_STYLE']) { $this->all_styles[$elements[$ie]['CSS_STYLE']] = 1; if (!is_array($options) || $options['ignore_css_image'] != 1) { $elements[$ie]['CSS_IMAGE'] = $this->getCSSImage($elements[$ie]['TYPE'], $elements[$ie]['CSS_STYLE']); } } if ($elements[$ie]['PRIORITY']) { $elements[$ie]['ZINDEX'] = round($elements[$ie]['PRIORITY'] / 10); } if ($elements[$ie]['TYPE'] == 'img') { $elements[$ie]['BACKGROUND'] = 0; } $positions[$elements[$ie]['ID']]['TOP'] = $elements[$ie]['TOP']; $positions[$elements[$ie]['ID']]['LEFT'] = $elements[$ie]['LEFT']; $states = SQLSelect("SELECT * FROM elm_states WHERE ELEMENT_ID='" . $elements[$ie]['ID'] . "' ORDER BY PRIORITY DESC, TITLE"); $total_s = count($states); for ($is = 0; $is < $total_s; $is++) { if ($elements[$ie]['TYPE'] == 'img') { unset($states[$is]['HTML']); } if ($states[$is]['HTML'] != '') { $states[$is]['HTML'] = processTitle($states[$is]['HTML']); } if (!is_array($options) || $options['ignore_state'] != 1) { startMeasure('checkstates'); $states[$is]['STATE'] = $this->checkState($states[$is]['ID']); endMeasure('checkstates'); } } $elements[$ie]['STATES'] = $states; if ($elements[$ie]['TYPE'] == 'container') { if (!is_array($options) || $options['ignore_sub'] != 1) { startMeasure('getSubElements'); $elements[$ie]['ELEMENTS'] = $this->getElements("CONTAINER_ID=" . (int) $elements[$ie]['ID'], $options); endMeasure('getSubElements'); } } } for ($ie = 0; $ie < $totale; $ie++) { if ($elements[$ie]['LINKED_ELEMENT_ID']) { $elements[$ie]['TOP'] = $positions[$elements[$ie]['LINKED_ELEMENT_ID']]['TOP'] + $elements[$ie]['TOP']; $elements[$ie]['LEFT'] = $positions[$elements[$ie]['LINKED_ELEMENT_ID']]['LEFT'] + $elements[$ie]['LEFT']; $positions[$elements[$ie]['ID']]['TOP'] = $elements[$ie]['TOP']; $positions[$elements[$ie]['ID']]['LEFT'] = $elements[$ie]['LEFT']; } } return $elements; }
/** * processTitle * * Description * * @access public */ function processTitle($title, $object = 0) { if (!$title) { return $title; } startMeasure('processTitle'); $in_title = substr($title, 0, 100); startMeasure('processTitle [' . $in_title . ']'); if ($in_title != '') { if (preg_match('/\\[#.+?#\\]/is', $title)) { if ($object) { $jTempl = new jTemplate($title, $object->data, $object); } else { $jTempl = new jTemplate($title, $data, $this); } $title = $jTempl->result; } $title = preg_replace('/%rand%/is', rand(), $title); if (preg_match_all('/%([\\w\\d\\.]+?)\\.([\\w\\d\\.]+?)%/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], getGlobal($m[1][$i] . '.' . $m[2][$i]), $title); } } elseif (preg_match_all('/%([\\w\\d\\.]+?)%/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], getGlobal($m[1][$i]), $title); } } if (preg_match_all('/<#LANG_(\\w+?)#>/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], constant('LANG_' . $m[1][$i]), $title); } } if (preg_match_all('/\\<#LANG_(.+?)#\\>/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], constant('LANG_' . $m[1][$i]), $title); } } } endMeasure('processTitle [' . $in_title . ']', 1); endMeasure('processTitle', 1); return $title; }
/** * Title * * Description * * @access public */ function setProperty($property, $value, $no_linked = 0) { startMeasure('setProperty'); startMeasure('setProperty (' . $property . ')'); $id = $this->getPropertyByName($property, $this->class_id, $this->id); $old_value = ''; if ($id) { $prop = SQLSelectOne("SELECT * FROM properties WHERE ID='" . $id . "'"); $v = SQLSelectOne("SELECT * FROM pvalues WHERE PROPERTY_ID='" . (int) $id . "' AND OBJECT_ID='" . (int) $this->id . "'"); $old_value = $v['VALUE']; $v['VALUE'] = $value; if ($v['ID']) { $v['UPDATED'] = date('Y-m-d H:i:s'); if ($old_value != $value) { SQLUpdate('pvalues', $v); } else { SQLExec("UPDATE pvalues SET UPDATED='" . $v['UPDATED'] . "' WHERE ID='" . $v['ID'] . "'"); } $cached_name = 'MJD:' . $this->object_title . '.' . $property; saveToCache($cached_name, $value); } else { $v['PROPERTY_ID'] = $id; $v['OBJECT_ID'] = $this->id; $v['VALUE'] = $value; $v['UPDATED'] = date('Y-m-d H:i:s'); $v['ID'] = SQLInsert('pvalues', $v); } //DebMes(" $id to $value "); } else { $prop = array(); $prop['OBJECT_ID'] = $this->id; $prop['TITLE'] = $property; $prop['ID'] = SQLInsert('properties', $prop); $v['PROPERTY_ID'] = $prop['ID']; $v['OBJECT_ID'] = $this->id; $v['VALUE'] = $value; $v['UPDATED'] = date('Y-m-d H:i:s'); $v['ID'] = SQLInsert('pvalues', $v); } if ($this->keep_history > 0) { $prop['KEEP_HISTORY'] = $this->keep_history; } //if (($prop['KEEP_HISTORY']>0) && (($value!=$old_value) || (defined('KEEP_HISTORY_DUPLICATES') && KEEP_HISTORY_DUPLICATES==1))) { if (isset($prop['KEEP_HISTORY']) && $prop['KEEP_HISTORY'] > 0 && $value != $old_value) { startMeasure('DeleteOldHistory'); SQLExec("DELETE FROM phistory WHERE VALUE_ID='" . $v['ID'] . "' AND TO_DAYS(NOW())-TO_DAYS(ADDED)>" . (int) $prop['KEEP_HISTORY']); endMeasure('DeleteOldHistory', 1); $h = array(); $h['VALUE_ID'] = $v['ID']; $h['ADDED'] = date('Y-m-d H:i:s'); $h['VALUE'] = $value; $h['ID'] = SQLInsert('phistory', $h); } elseif (isset($prop['KEEP_HISTORY']) && $prop['KEEP_HISTORY'] > 0 && $value == $old_value) { $tmp_history = SQLSelect("SELECT * FROM phistory WHERE VALUE_ID='" . $v['ID'] . "' ORDER BY ID DESC LIMIT 2"); $prev_value = $tmp_history[0]['VALUE']; $prev_prev_value = $tmp_history[1]['VALUE']; if ($prev_value == $prev_prev_value) { $tmp_history[0]['ADDED'] = date('Y-m-d H:i:s'); SQLUpdate('phistory', $tmp_history[0]); } else { $h = array(); $h['VALUE_ID'] = $v['ID']; $h['ADDED'] = date('Y-m-d H:i:s'); $h['VALUE'] = $value; $h['ID'] = SQLInsert('phistory', $h); } } if (isset($prop['ONCHANGE']) && $prop['ONCHANGE']) { global $property_linked_history; if (!$property_linked_history[$property][$prop['ONCHANGE']]) { $property_linked_history[$property][$prop['ONCHANGE']] = 1; global $on_change_called; $params = array(); $params['PROPERTY'] = $property; $params['NEW_VALUE'] = (string) $value; $params['OLD_VALUE'] = (string) $old_value; $this->callMethod($prop['ONCHANGE'], $params); unset($property_linked_history[$property][$prop['ONCHANGE']]); } } if (isset($v['LINKED_MODULES']) && $v['LINKED_MODULES']) { // TO-DO ! if (!is_array($no_linked) && $no_linked) { return; } elseif (!is_array($no_linked)) { $no_linked = array(); } $tmp = explode(',', $v['LINKED_MODULES']); $total = count($tmp); for ($i = 0; $i < $total; $i++) { $linked_module = trim($tmp[$i]); if (isset($no_linked[$linked_module])) { continue; } if (file_exists(DIR_MODULES . $linked_module . '/' . $linked_module . '.class.php')) { include_once DIR_MODULES . $linked_module . '/' . $linked_module . '.class.php'; $module_object = new $linked_module(); if (method_exists($module_object, 'propertySetHandle')) { $module_object->propertySetHandle($this->object_title, $property, $value); } } } } /* $h=array(); $h['ADDED']=date('Y-m-d H:i:s'); $h['OBJECT_ID']=$this->id; $h['VALUE_ID']=$v['ID']; $h['OLD_VALUE']=$old_value; $h['NEW_VALUE']=$value; SQLInsert('history', $h); */ endMeasure('setProperty (' . $property . ')', 1); endMeasure('setProperty', 1); }
function measure($message, callable $callback) { startMeasure($message); $result = $callback(); stopMeasure($message); return $result; }
if (checkAccess('scene', $res[$i]['ID'])) { $res2[] = $res[$i]; } } $res = $res2; unset($res2); } if ($res[0]['ID']) { $total = count($res); $positions = array(); for ($i = 0; $i < $total; $i++) { // some action for every record if required startMeasure('scene' . $res[$i]['ID'] . '_get root elements'); $res[$i]['ELEMENTS'] = $this->getElements("SCENE_ID='" . $res[$i]['ID'] . "' AND CONTAINER_ID=0", array('ignore_css_image' => 1)); endMeasure('scene' . $res[$i]['ID'] . '_get root elements'); startMeasure('scene' . $res[$i]['ID'] . '_get all elements'); $res[$i]['ALL_ELEMENTS'] = $this->getElements("SCENE_ID='" . $res[$i]['ID'] . "'", array('ignore_state' => 1, 'ignore_sub' => 1, 'ignore_css_image' => 1)); endMeasure('scene' . $res[$i]['ID'] . '_get all elements'); $res[$i]['NUM'] = $i; $res[$i]['NUMP'] = $i + 1; } if ($total == 1) { foreach ($res[0] as $k => $v) { $out['SCENE_' . $k] = $v; } } $out['TOTAL'] = $total; $out['RESULT'] = $res; $out['PARAMS'] = ''; if (is_array($_GET)) { foreach ($_GET as $k => $v) {
/** * Summary of processTitle * @param mixed $title Title * @param mixed $object Object (default 0) * @return mixed */ function processTitle($title, $object = 0) { global $title_memory_cache; $key = $title; if (!$title) { return $title; } startMeasure('processTitle'); $in_title = substr($title, 0, 100); //startMeasure('processTitle ['.$in_title.']'); if ($in_title != '') { if (isset($_SERVER['REQUEST_METHOD'])) { if ($title_memory_cache[$key]) { return $title_memory_cache[$key]; } } if (preg_match('/\\[#.+?#\\]/is', $title)) { startMeasure('processTitleJTemplate'); if ($object) { $jTempl = new jTemplate($title, $object->data, $object); } else { $jTempl = new jTemplate($title, $data, $this); } $title = $jTempl->result; endMeasure('processTitleJTemplate'); } $title = preg_replace('/%rand%/is', rand(), $title); $title = preg_replace('/%([\\w\\d\\.]+?)\\.([\\w\\d\\.]+?)\\|(\\d+)%/uis', '%\\1.\\2%', $title); if (preg_match_all('/%([\\w\\d\\.]+?)\\.([\\w\\d\\.]+?)%/uis', $title, $m)) { startMeasure('processTitleProperties'); $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], getGlobal($m[1][$i] . '.' . $m[2][$i]), $title); } endMeasure('processTitleProperties'); } if (preg_match_all('/%([\\w\\d\\.]+?)\\.([\\w\\d\\.]+?)\\|"(.+?)"%/uis', $title, $m)) { startMeasure('processTitlePropertiesReplace'); $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $data = getGlobal($m[1][$i] . '.' . $m[2][$i]); $descr = $m[3][$i]; $tmp = explode(';', $descr); $totald = count($tmp); $hsh = array(); for ($id = 0; $id < $totald; $id++) { $item = trim($tmp[$id]); if (preg_match('/(.+?)=(.+)/uis', $item, $md)) { $search_value = $md[1]; $search_replace = $md[2]; } else { $search_value = $id; $search_replace = $item; } $hsh[$search_value] = $search_replace; } $title = str_replace($m[0][$i], $hsh[$data], $title); } endMeasure('processTitlePropertiesReplace'); } if (preg_match_all('/%([\\w\\d\\.]+?)%/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { if (preg_match('/^%\\d/is', $m[0][$i])) { continue; // dirty hack, sorry for that } $title = str_replace($m[0][$i], getGlobal($m[1][$i]), $title); } } if (preg_match_all('/<#LANG_(\\w+?)#>/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], constant('LANG_' . $m[1][$i]), $title); } } if (preg_match_all('/\\<#LANG_(.+?)#\\>/is', $title, $m)) { $total = count($m[0]); for ($i = 0; $i < $total; $i++) { $title = str_replace($m[0][$i], constant('LANG_' . $m[1][$i]), $title); } } } //endMeasure('processTitle ['.$in_title.']', 1); if (isset($_SERVER['REQUEST_METHOD'])) { $title_memory_cache[$key] = $title; } endMeasure('processTitle', 1); return $title; }
/** * @param $order * * @return array */ private function getVariablesFromOrder($order) { $variables = []; foreach ($order as $order => $blocks) { foreach ($blocks as $block => $actions) { foreach ($actions as $action) { startMeasure('Getting output: ' . $action->getClass() . ' ' . $action->getMethod() . ' ' . $block . ' ' . $order); $variables[$block][] = $action->getHtml(); stopMeasure('Getting output: ' . $action->getClass() . ' ' . $action->getMethod() . ' ' . $block . ' ' . $order); } } } return $variables; }