Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
    setGlobal($user['LINKED_OBJECT'] . '.seenAt', '');
}
$sqlQuery = "SELECT *, DATE_FORMAT(ADDED, '%H:%i') as DAT\n               FROM shouts\n              ORDER BY ADDED DESC\n              LIMIT 1";
$tmp = SQLSelectOne($sqlQuery);
if (!headers_sent()) {
    header("HTTP/1.0: 200 OK\n");
    header('Content-Type: text/html; charset=utf-8');
}
if (defined('BTRACED')) {
    echo "OK";
} elseif ($tmp['MESSAGE'] != '') {
    echo ' ' . $tmp['DAT'] . ' ' . transliterate($tmp['MESSAGE']);
}
// closing database connection
$db->Disconnect();
endMeasure('TOTAL');
// end calculation of execution time
/**
 * Calculate distance between two GPS coordinates
 * @param mixed $latA First coord latitude
 * @param mixed $lonA First coord longitude
 * @param mixed $latB Second coord latitude
 * @param mixed $lonB Second coord longitude
 * @return double
 */
function calculateTheDistance($latA, $lonA, $latB, $lonB)
{
    define('EARTH_RADIUS', 6372795);
    $lat1 = $latA * M_PI / 180;
    $lat2 = $latB * M_PI / 180;
    $long1 = $lonA * M_PI / 180;
Beispiel #4
0
 /**
 * 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);
 }
Beispiel #5
0
/**
* 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('/\\&#060#LANG_(.+?)#\\&#062/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;
}
Beispiel #6
0
 /**
 * 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;
 }
Beispiel #7
0
/**
* 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('/\\&#060#LANG_(.+?)#\\&#062/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;
}
Beispiel #8
0
 /**
 * 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);
 }
Beispiel #9
0
 if (!headers_sent()) {
  header ("HTTP/1.0: 200 OK\n");
  header ('Content-Type: text/html; charset=utf-8');
 }

 echo "OK";
 if ($tmp['MESSAGE']!='') {
  echo ' '.$tmp['DAT'].' '.transliterate($tmp['MESSAGE']);
 }




 $db->Disconnect(); // closing database connection

 endMeasure('TOTAL'); // end calculation of execution time
// Радиус земли


function calculateTheDistance ($latA, $lonA, $latB, $lonB) {
    
    define('EARTH_RADIUS', 6372795);

//    $lat1= $latA;
 //   $lat2= $la

    $lat1 = $latA * M_PI / 180;
    $lat2 = $latB * M_PI / 180;
    $long1 = $lonA * M_PI / 180;
    $long2 = $lonB * M_PI / 180;
 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' => $mtime);
                 }
                 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);
         }
         //print_r($files);exit;
         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"');
                     header('HTTP/1.0 401 Unauthorized');
                     echo 'Incorrect username/password!';
                     exit;
                 }
             }
         }
     }
     global $terminal;
     if ($terminal) {
         $session->data['TERMINAL'] = $terminal;
     }
     if (preg_match('/^app_\\w+$/is', $this->action) || $this->action == 'xray') {
         $out['APP_ACTION'] = 1;
     }
     if ($this->app_action) {
         $out['APP_ACTION'] = 1;
     }
     $terminals = SQLSelect("SELECT * FROM terminals ORDER BY TITLE");
     $total = count($terminals);
     for ($i = 0; $i < $total; $i++) {
         //!$session->data['TERMINAL'] &&
         if ($terminals[$i]['HOST'] != '' && $_SERVER['REMOTE_ADDR'] == $terminals[$i]['HOST']) {
             $session->data['TERMINAL'] = $terminals[$i]['NAME'];
         }
         if ($terminals[$i]['NAME'] == $session->data['TERMINAL']) {
             $terminals[$i]['SELECTED'] = 1;
             $out['TERMINAL_TITLE'] = $terminals[$i]['TITLE'];
         }
     }
     $out['TERMINALS'] = $terminals;
     if ($total == 1) {
         $out['HIDE_TERMINALS'] = 1;
         $session->data['TERMINAL'] = $terminals[0]['NAME'];
     }
     $users = SQLSelect("SELECT * FROM users ORDER BY NAME");
     $total = count($users);
     for ($i = 0; $i < $total; $i++) {
         if ($users[$i]['USERNAME'] == $session->data['SITE_USERNAME']) {
             $users[$i]['SELECTED'] = 1;
             $out['USER_TITLE'] = $users[$i]['NAME'];
             $out['USER_AVATAR'] = $users[$i]['AVATAR'];
         } elseif (!$session->data['SITE_USERNAME'] && $users[$i]['HOST'] && $users[$i]['HOST'] == $_SERVER['REMOTE_ADDR']) {
             $session->data['SITE_USERNAME'] = $users[$i]['USERNAME'];
             $session->data['SITE_USER_ID'] = $users[$i]['ID'];
             $out['USER_TITLE'] = $users[$i]['NAME'];
             $out['USER_AVATAR'] = $users[$i]['AVATAR'];
         }
         if ($users[$i]['IS_DEFAULT'] == 1) {
             $out['DEFAULT_USERNAME'] = $users[$i]['USERNAME'];
             $out['DEFAULT_USER_ID'] = $users[$i]['ID'];
         }
     }
     $out['USERS'] = $users;
     if ($total == 1) {
         $out['HIDE_USERS'] = 1;
         $session->data['SITE_USERNAME'] = $users[0]['USERNAME'];
         $session->data['SITE_USER_ID'] = $users[0]['ID'];
     }
     if (!$session->data['SITE_USERNAME'] && $out['DEFAULT_USERNAME']) {
         $session->data['SITE_USERNAME'] = $out['DEFAULT_USERNAME'];
         $session->data['SITE_USER_ID'] = $out['DEFAULT_USER_ID'];
         for ($i = 0; $i < $total; $i++) {
             if ($users[$i]['USERNAME'] == $session->data['USERNAME']) {
                 $users[$i]['SELECTED'] = 1;
                 $out['USER_TITLE'] = $users[$i]['NAME'];
                 $out['USER_AVATAR'] = $users[$i]['AVATAR'];
             }
         }
     }
     if ($out['USER_TITLE']) {
         Define('USER_TITLE', $out['USER_TITLE']);
         Define('USER_AVATAR', $out['USER_AVATAR']);
     } else {
         Define('USER_TITLE', '');
         Define('USER_AVATAR', '');
     }
     if ($out["DOC_NAME"]) {
         //$doc=SQLSelectOne("SELECT ID FROM cms_docs WHERE NAME LIKE '".DBSafe($out['DOC_NAME'])."'");
         if ($doc['ID']) {
             $this->doc = $doc['ID'];
         }
     }
     if ($session->data["AUTHORIZED"]) {
         $out['AUTHORIZED_ADMIN'] = 1;
     }
     if ($this->action == '' || $this->action == 'pages') {
         $res = SQLSelect("SELECT * FROM layouts ORDER BY PRIORITY DESC, TITLE");
         if ($this->action != 'admin') {
             $total = count($res);
             $res2 = array();
             for ($i = 0; $i < $total; $i++) {
                 if (checkAccess('layout', $res[$i]['ID'])) {
                     $res2[] = $res[$i];
                 }
             }
             $res = $res2;
             unset($res2);
         }
         $out['LAYOUTS'] = $res;
         $total = count($out['LAYOUTS']);
         for ($i = 0; $i < $total; $i++) {
             $out['LAYOUTS'][$i]['NUM'] = $i;
         }
         $out['TOTAL_LAYOUTS'] = count($out['LAYOUTS']);
     }
     if ($this->doc) {
         $this->doc_id = $this->doc;
     }
     $out["DOC_ID"] = $this->doc_id;
     if ($session->data['MY_MEMBER']) {
         $out['MY_MEMBER'] = $session->data['MY_MEMBER'];
         $tmp = SQLSelectOne("SELECT ID FROM users WHERE ID='" . (int) $out['MY_MEMBER'] . "' AND ACTIVE_CONTEXT_ID!=0 AND TIMESTAMPDIFF(SECOND, ACTIVE_CONTEXT_UPDATED, NOW())>600");
         if ($tmp['ID']) {
             SQLExec("UPDAE users SET ACTIVE_CONTEXT_ID=0, ACTIVE_CONTEXT_EXTERNAL=0 WHERE ID='" . $tmp['ID'] . "'");
         }
     }
     $out['AJAX'] = $this->ajax;
     $out['POPUP'] = $this->popup;
     $days = array('Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота');
     $out['TODAY'] = $days[date('w')] . ', ' . date('d.m.Y');
     Define(TODAY, $out['TODAY']);
     global $ajt;
     if ($ajt == '') {
         $template_file = DIR_TEMPLATES . $this->name . ".html";
     } else {
         $template_file = ROOT . 'templates_ajax/' . $this->name . "_" . $ajt . ".html";
     }
     if ($this->action == 'menu') {
         $template_file = DIR_TEMPLATES . "menu.html";
     }
     if ($this->action == 'pages') {
         $template_file = DIR_TEMPLATES . "pages.html";
     }
     if ($this->action == 'scenes') {
         $template_file = DIR_TEMPLATES . "scenes.html";
     }
     if ($this->ajax && $this->action) {
         global $ajax;
         $ajax = 1;
         if (file_exists(DIR_MODULES . $this->action)) {
             include_once DIR_MODULES . $this->action . '/' . $this->action . '.class.php';
             $obj = "\$object{$i}";
             $code = "";
             $code .= "{$obj}=new " . $this->action . ";\n";
             $code .= $obj . "->owner=&\$this;\n";
             $code .= $obj . "->getParams();\n";
             $code .= $obj . "->ajax=1;\n";
             $code .= $obj . "->run();\n";
             StartMeasure("module_" . $this->action);
             eval($code);
             endMeasure("module_" . $this->action);
         }
         return;
     } else {
         $this->data = $out;
         $p = new parser($template_file, $this->data, $this);
         return $p->result;
     }
 }
Beispiel #11
0
        }
    }
    $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) {
            $out[$k] = $v;
            $out['PARAMS'] .= "&{$k}=" . urlencode($v);
Beispiel #12
0
/**
 * 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('/\\&#060#LANG_(.+?)#\\&#062/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;
}