Advertisement
Guest User

Jeedom WazeInTime - ERROR INTERNAL SERVER 500 - Modified

a guest
Jan 16th, 2016
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.57 KB | None | 0 0
  1. <?php
  2.  
  3. /* This file is part of Jeedom.
  4. *
  5. * Jeedom is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Jeedom is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Jeedom. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. /* * ***************************Includes********************************* */
  20. require_once dirname(__FILE__) . '/../../../../core/php/core.inc.php';
  21.  
  22. class wazeintime extends eqLogic {
  23.     /*     * *************************Attributs****************************** */
  24.  
  25.     public static function cron30($_eqlogic_id = null) {
  26.         if($_eqlogic_id !== null){
  27.             $eqLogics = array(eqLogic::byId($_eqlogic_id));
  28.         }else{
  29.             $eqLogics = eqLogic::byType('wazeintime');
  30.         }
  31.         foreach ($eqLogics as $wazeintime) {
  32.             if ($wazeintime->getIsEnable() == 1) {
  33.                 log::add('wazeintime', 'debug', 'Pull Cron pour Waze in time');
  34.                 if ('none' == ($wazeintime->getConfiguration('geolocstart', ''))) {
  35.                     $latdepart=$wazeintime->getConfiguration('latdepart');
  36.                     $londepart=$wazeintime->getConfiguration('londepart');
  37.                 } else {
  38.                     $geoloc = $wazeintime->getConfiguration('geolocstart', '');
  39.                     $typeId = explode('|',$geoloc);
  40.                     if ($typeId[0] == 'ios') {
  41.                         $geolocCmd = geoloc_iosCmd::byId($typeId[1]);
  42.                     } else  {
  43.                         $geolocCmd = geolocCmd::byId($typeId[1]);
  44.                     }
  45.                     $geoloctab = explode(',', $geolocCmd->execCmd(null, 0));
  46.                     if (isset($geoloctab[0]) && isset($geoloctab[1])) {
  47.                         $latdepart = $geoloctab[0];
  48.                         $londepart = $geoloctab[1];
  49.                     } else {
  50.                         log::add('wazeintime', 'debug', 'Position de départ invalide');
  51.                         continue;
  52.                     }
  53.                 }
  54.                 if ('none' == ($wazeintime->getConfiguration('geolocend', ''))) {
  55.                     $latarrive=$wazeintime->getConfiguration('latarrive');
  56.                     $lonarrive=$wazeintime->getConfiguration('lonarrive');
  57.                 } else {
  58.                     $geoloc = $wazeintime->getConfiguration('geolocend', '');
  59.                     $typeId = explode('|',$geoloc);
  60.                     if ($typeId[0] == 'ios') {
  61.                         $geolocCmd = geoloc_iosCmd::byId($typeId[1]);
  62.                     } else  {
  63.                         $geolocCmd = geolocCmd::byId($typeId[1]);
  64.                     }
  65.                     $geoloctab = explode(',', $geolocCmd->execCmd(null, 0));
  66.                     if (isset($geoloctab[0]) && isset($geoloctab[1])) {
  67.                         $latarrive = $geoloctab[0];
  68.                         $lonarrive = $geoloctab[1];
  69.                     } else {
  70.                         log::add('wazeintime', 'debug', 'Position d\'arrivée invalide');
  71.                         continue;
  72.                     }
  73.                 }
  74.                 $route1retTotalTimeMin = 'old';
  75.                 $route2retTotalTimeMin = 'old';
  76.                 $route3retTotalTimeMin = 'old';
  77.                 $route1retName = 'old';
  78.                 $route2retName = 'old';
  79.                 $route3retName = 'old';
  80.                 $route1TotalTimeMin = 'old';
  81.                 $route2TotalTimeMin = 'old';
  82.                 $route3TotalTimeMin = 'old';
  83.                 $route1Name = 'old';
  84.                 $route2Name = 'old';
  85.                 $route3Name = 'old';
  86.                 if ($wazeintime->getConfiguration('NOA')){
  87.                     $row='';
  88.                 } else {
  89.                     $row='row-';
  90.                 }
  91.                 $wazeRouteurl = "https://www.waze.com/".$row."RoutingManager/routingRequest?from=x%3A$londepart+y%3A$latdepart&to=x%3A$lonarrive+y%3A$latarrive&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=3&options=AVOID_TRAILS%3At";
  92.                 log::add('wazeintime', 'debug', $wazeRouteurl);
  93.                 $wazeRoutereturl = "https://www.waze.com/".$row."RoutingManager/routingRequest?from=x%3A$lonarrive+y%3A$latarrive&to=x%3A$londepart+y%3A$latdepart&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=3&options=AVOID_TRAILS%3At";
  94.                 $opts = array(
  95.                     'http'=>array(
  96.                     'method'=>"GET",
  97.                     'header'=>"Accept-language: en\r\n" .
  98.                     "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0".
  99.                     "Cookie: foo=bar\r\n"
  100.                     )
  101.                 );
  102.                 $context = stream_context_create($opts);
  103.                 $routeResponseText = @file_get_contents($wazeRouteurl, false, $context);
  104.                 if ($routeResponseText === FALSE) {
  105.                      log::add('wazeintime', 'debug', 'Difficulté à contacter le serveur');
  106.                 } else {
  107.                     $routeResponseJson = json_decode($routeResponseText,true);
  108.                     $route1Name = (isset($routeResponseJson['alternatives'][0]['response']['routeName'])) ? $routeResponseJson['alternatives'][0]['response']['routeName'] : "NA";
  109.                     $route2Name = (isset($routeResponseJson['alternatives'][1]['response']['routeName'])) ? $routeResponseJson['alternatives'][1]['response']['routeName'] : "NA";
  110.                     $route3Name = (isset($routeResponseJson['alternatives'][2]['response']['routeName'])) ? $routeResponseJson['alternatives'][2]['response']['routeName'] : "NA";
  111.                     $route1 = (isset($routeResponseJson['alternatives'][0]['response']['results'])) ? $routeResponseJson['alternatives'][0]['response']['results'] : 0;
  112.                     $route2 = (isset($routeResponseJson['alternatives'][1]['response']['results'])) ? $routeResponseJson['alternatives'][1]['response']['results'] : 0;
  113.                     $route3 = (isset($routeResponseJson['alternatives'][2]['response']['results'])) ? $routeResponseJson['alternatives'][2]['response']['results'] : 0;
  114.                     $route1TotalTimeSec = 0;
  115.                     if ($route1 != 0) {
  116.                     foreach ($route1 as $street){
  117.                         $route1TotalTimeSec += $street['crossTime'];
  118.                     }
  119.                     }
  120.                     $route2TotalTimeSec = 0;
  121.                     if ($route2 != 0) {
  122.                     foreach ($route2 as $street){
  123.                         $route2TotalTimeSec += $street['crossTime'];
  124.                     }
  125.                     }
  126.                     $route3TotalTimeSec = 0;
  127.                     if ($route3 != 0) {
  128.                     foreach ($route3 as $street){
  129.                         $route3TotalTimeSec += $street['crossTime'];
  130.                     }
  131.                     }
  132.                     $route1TotalTimeMin = round($route1TotalTimeSec/60);
  133.                     $route2TotalTimeMin = round($route2TotalTimeSec/60);
  134.                     $route3TotalTimeMin = round($route3TotalTimeSec/60);
  135.                 }
  136.                 $routeretResponseText = @file_get_contents($wazeRoutereturl, false, $context);
  137.                 if ($routeretResponseText === FALSE) {
  138.                      log::add('wazeintime', 'debug', 'Difficulté à contacter le serveur');
  139.                 } else {
  140.                     $routeretResponseJson = json_decode($routeretResponseText,true);
  141.                     $route1retName = (isset($routeretResponseJson['alternatives'][0]['response']['routeName'])) ? $routeretResponseJson['alternatives'][0]['response']['routeName'] : "NA";
  142.                     $route2retName = (isset($routeretResponseJson['alternatives'][1]['response']['routeName'])) ? $routeretResponseJson['alternatives'][1]['response']['routeName'] : "NA";
  143.                     $route3retName = (isset($routeretResponseJson['alternatives'][2]['response']['routeName'])) ? $routeretResponseJson['alternatives'][2]['response']['routeName'] : "NA";
  144.                     $routeret1 = (isset($routeretResponseJson['alternatives'][0]['response']['results'])) ? $routeretResponseJson['alternatives'][0]['response']['results'] : 0;
  145.                     $routeret2 = (isset($routeretResponseJson['alternatives'][1]['response']['results'])) ? $routeretResponseJson['alternatives'][1]['response']['results'] : 0;
  146.                     $routeret3 = (isset($routeretResponseJson['alternatives'][2]['response']['results'])) ? $routeretResponseJson['alternatives'][2]['response']['results'] : 0;
  147.                     $route1retTotalTimeSec = 0;
  148.                     if ($routeret1 != 0) {
  149.                     foreach ($routeret1 as $street){
  150.                         $route1retTotalTimeSec += $street['crossTime'];
  151.                     }
  152.                     }
  153.                     $route2retTotalTimeSec = 0;
  154.                     if ($routeret2 != 0) {
  155.                     foreach ($routeret2 as $street){
  156.                         $route2retTotalTimeSec += $street['crossTime'];
  157.                     }
  158.                     }
  159.                     $route3retTotalTimeSec = 0;
  160.                     if ($routeret3 != 0) {
  161.                     foreach ($routeret3 as $street){
  162.                         $route3retTotalTimeSec += $street['crossTime'];
  163.                     }
  164.                     }
  165.                     $route1retTotalTimeMin = round($route1retTotalTimeSec/60);
  166.                     $route2retTotalTimeMin = round($route2retTotalTimeSec/60);
  167.                     $route3retTotalTimeMin = round($route3retTotalTimeSec/60);
  168.                 }
  169.                 foreach ($wazeintime->getCmd('info') as $cmd) {
  170.                     switch ($cmd->getName()) {
  171.                         case 'Durée 1':
  172.                             $value=$route1TotalTimeMin;
  173.                         break;
  174.                         case 'Durée 2':
  175.                             $value=$route2TotalTimeMin; break;
  176.                         case 'Durée 3':
  177.                             $value=$route3TotalTimeMin; break;
  178.                         case 'Trajet 1':
  179.                             $value=$route1Name; break;
  180.                         case 'Trajet 2':
  181.                             $value=$route2Name; break;
  182.                         case 'Trajet 3':
  183.                             $value=$route3Name; break;
  184.                         case 'Dernier refresh':
  185.                             if ($route1TotalTimeMin == 'old') {
  186.                                 $value='old';break;
  187.                             } else {
  188.                                 $value=date('H:i'); break;
  189.                             }
  190.                         case 'Durée retour 1':
  191.                             $value=$route1retTotalTimeMin;
  192.                         break;
  193.                         case 'Durée retour 2':
  194.                             $value=$route2retTotalTimeMin; break;
  195.                         case 'Durée retour 3':
  196.                             $value=$route3retTotalTimeMin; break;
  197.                         case 'Trajet retour 1':
  198.                             $value=$route1retName; break;
  199.                         case 'Trajet retour 2':
  200.                             $value=$route2retName; break;
  201.                         case 'Trajet retour 3':
  202.                             $value=$route3retName; break;
  203.                         case 'Dernier refresh retour':
  204.                             if ($route1retTotalTimeMin == 'old') {
  205.                                 $value='old';break;
  206.                             } else {
  207.                                 $value=date('H:i'); break;
  208.                             }
  209.                     }
  210.                     if ($value != 'old'){
  211.                         $cmd->event($value);
  212.                         log::add('wazeintime','debug','set:'.$cmd->getName().' to '. $value);
  213.                     }
  214.                 }
  215.                 $mc = cache::byKey('wazeintimeWidgetmobile' . $wazeintime->getId());
  216.                 $mc->remove();
  217.                 $mc = cache::byKey('wazeintimeWidgetdashboard' . $wazeintime->getId());
  218.                 $mc->remove();
  219.                 $wazeintime->toHtml('mobile');
  220.                 $wazeintime->toHtml('dashboard');
  221.                 $wazeintime->refreshWidget();
  222.             }
  223.         }
  224.     }
  225.  
  226.     public function preUpdate() {
  227.        if ($this->getConfiguration('latdepart') == '' || !is_numeric($this->getConfiguration('latdepart'))) {
  228.             throw new Exception(__('La latitude de départ ne peut être vide et doit être un nombre valide',__FILE__));
  229.        }
  230.         if ($this->getConfiguration('latarrive') == '' || !is_numeric($this->getConfiguration('latarrive'))) {
  231.             throw new Exception(__('La latitude d\'arrivée ne peut être vide et doit être un nombre valide',__FILE__));
  232.        }
  233.         if ($this->getConfiguration('londepart') == '' || !is_numeric($this->getConfiguration('londepart'))) {
  234.             throw new Exception(__('La longitude de départ ne peut être vide et doit être un nombre valide',__FILE__));
  235.        }
  236.         if ($this->getConfiguration('lonarrive') == '' || !is_numeric($this->getConfiguration('lonarrive'))) {
  237.             throw new Exception(__('La longitude d\'arrivée ne peut être vide et doit être un nombre valide',__FILE__));
  238.        }
  239.     }
  240.  
  241.     public function postSave() {
  242.         if (!$this->getId())
  243.           return;
  244.  
  245.         $routename1 = $this->getCmd(null, 'routename1');
  246.         if (!is_object($routename1)) {
  247.             $routename1 = new wazeintimeCmd();
  248.             $routename1->setLogicalId('routename1');
  249.             $routename1->setIsVisible(1);
  250.             $routename1->setName(__('Trajet 1', __FILE__));
  251.         }
  252.         $routename1->setType('info');
  253.         $routename1->setSubType('string');
  254.         $routename1->setConfiguration('onlyChangeEvent',1);
  255.         $routename1->setEventOnly(1);
  256.         $routename1->setEqLogic_id($this->getId());
  257.         $routename1->save();
  258.  
  259.         $time1 = $this->getCmd(null, 'time1');
  260.         if (!is_object($time1)) {
  261.             $time1 = new wazeintimeCmd();
  262.             $time1->setLogicalId('time1');
  263.             $time1->setUnite('min');
  264.             $time1->setIsVisible(1);
  265.             $time1->setName(__('Durée 1', __FILE__));
  266.         }
  267.         $time1->setType('info');
  268.         $time1->setSubType('numeric');
  269.         $time1->setConfiguration('onlyChangeEvent',1);
  270.         $time1->setEventOnly(1);
  271.         $time1->setEqLogic_id($this->getId());
  272.         $time1->save();
  273.  
  274.         $routename2 = $this->getCmd(null, 'routename2');
  275.         if (!is_object($routename2)) {
  276.             $routename2 = new wazeintimeCmd();
  277.             $routename2->setLogicalId('routename2');
  278.             $routename2->setIsVisible(1);
  279.             $routename2->setName(__('Trajet 2', __FILE__));
  280.         }
  281.         $routename2->setType('info');
  282.         $routename2->setSubType('string');
  283.         $routename2->setConfiguration('onlyChangeEvent',1);
  284.         $routename2->setEventOnly(1);
  285.         $routename2->setEqLogic_id($this->getId());
  286.         $routename2->save();
  287.  
  288.         $time2 = $this->getCmd(null, 'time2');
  289.         if (!is_object($time2)) {
  290.             $time2 = new wazeintimeCmd();
  291.             $time2->setLogicalId('time2');
  292.             $time2->setIsVisible(1);
  293.             $time2->setName(__('Durée 2', __FILE__));
  294.         }
  295.         $time2->setType('info');
  296.         $time2->setSubType('numeric');
  297.         $time2->setUnite('min');
  298.         $time2->setConfiguration('onlyChangeEvent',1);
  299.         $time2->setEventOnly(1);
  300.         $time2->setEqLogic_id($this->getId());
  301.         $time2->save();
  302.  
  303.         $routename3 = $this->getCmd(null, 'routename3');
  304.         if (!is_object($routename3)) {
  305.             $routename3 = new wazeintimeCmd();
  306.             $routename3->setLogicalId('routename3');
  307.             $routename3->setIsVisible(1);
  308.             $routename3->setName(__('Trajet 3', __FILE__));
  309.         }
  310.         $routename3->setType('info');
  311.         $routename3->setSubType('string');
  312.         $routename3->setConfiguration('onlyChangeEvent',1);
  313.         $routename3->setEventOnly(1);
  314.         $routename3->setEqLogic_id($this->getId());
  315.         $routename3->save();
  316.  
  317.         $time3 = $this->getCmd(null, 'time3');
  318.         if (!is_object($time3)) {
  319.             $time3 = new wazeintimeCmd();
  320.             $time3->setLogicalId('time3');
  321.             $time3->setIsVisible(1);
  322.             $time3->setName(__('Durée 3', __FILE__));
  323.         }
  324.         $time3->setType('info');
  325.         $time3->setSubType('numeric');
  326.         $time3->setUnite('min');
  327.         $time3->setConfiguration('onlyChangeEvent',1);
  328.         $time3->setEventOnly(1);
  329.         $time3->setEqLogic_id($this->getId());
  330.         $time3->save();
  331.  
  332.         $routeretname1 = $this->getCmd(null, 'routeretname1');
  333.         if (!is_object($routeretname1)) {
  334.             $routeretname1 = new wazeintimeCmd();
  335.             $routeretname1->setLogicalId('routeretname1');
  336.             $routeretname1->setIsVisible(1);
  337.             $routeretname1->setName(__('Trajet retour 1', __FILE__));
  338.         }
  339.         $routeretname1->setType('info');
  340.         $routeretname1->setSubType('string');
  341.         $routeretname1->setConfiguration('onlyChangeEvent',1);
  342.         $routeretname1->setEventOnly(1);
  343.         $routeretname1->setEqLogic_id($this->getId());
  344.         $routeretname1->save();
  345.  
  346.         $timeret1 = $this->getCmd(null, 'timeret1');
  347.         if (!is_object($timeret1)) {
  348.             $timeret1 = new wazeintimeCmd();
  349.             $timeret1->setLogicalId('timeret1');
  350.             $timeret1->setUnite('min');
  351.             $timeret1->setIsVisible(1);
  352.             $timeret1->setName(__('Durée retour 1', __FILE__));
  353.         }
  354.         $timeret1->setType('info');
  355.         $timeret1->setSubType('numeric');
  356.         $timeret1->setConfiguration('onlyChangeEvent',1);
  357.         $timeret1->setEventOnly(1);
  358.         $timeret1->setEqLogic_id($this->getId());
  359.         $timeret1->save();
  360.  
  361.         $routeretname2 = $this->getCmd(null, 'routeretname2');
  362.         if (!is_object($routeretname2)) {
  363.             $routeretname2 = new wazeintimeCmd();
  364.             $routeretname2->setLogicalId('routeretname2');
  365.             $routeretname2->setIsVisible(1);
  366.             $routeretname2->setName(__('Trajet retour 2', __FILE__));
  367.         }
  368.         $routeretname2->setType('info');
  369.         $routeretname2->setSubType('string');
  370.         $routeretname2->setConfiguration('onlyChangeEvent',1);
  371.         $routeretname2->setEventOnly(1);
  372.         $routeretname2->setEqLogic_id($this->getId());
  373.         $routeretname2->save();
  374.  
  375.         $timeret2 = $this->getCmd(null, 'timeret2');
  376.         if (!is_object($timeret2)) {
  377.             $timeret2 = new wazeintimeCmd();
  378.             $timeret2->setLogicalId('timeret2');
  379.             $timeret2->setIsVisible(1);
  380.             $timeret2->setName(__('Durée retour 2', __FILE__));
  381.         }
  382.         $timeret2->setType('info');
  383.         $timeret2->setSubType('numeric');
  384.         $timeret2->setUnite('min');
  385.         $timeret2->setConfiguration('onlyChangeEvent',1);
  386.         $timeret2->setEventOnly(1);
  387.         $timeret2->setEqLogic_id($this->getId());
  388.         $timeret2->save();
  389.  
  390.         $routeretname3 = $this->getCmd(null, 'routeretname3');
  391.         if (!is_object($routeretname3)) {
  392.             $routeretname3 = new wazeintimeCmd();
  393.             $routeretname3->setLogicalId('routeretname3');
  394.             $routeretname3->setIsVisible(1);
  395.             $routeretname3->setName(__('Trajet retour 3', __FILE__));
  396.         }
  397.         $routeretname3->setType('info');
  398.         $routeretname3->setSubType('string');
  399.         $routeretname3->setConfiguration('onlyChangeEvent',1);
  400.         $routeretname3->setEventOnly(1);
  401.         $routeretname3->setEqLogic_id($this->getId());
  402.         $routeretname3->save();
  403.  
  404.         $timeret3 = $this->getCmd(null, 'timeret3');
  405.         if (!is_object($timeret3)) {
  406.             $timeret3 = new wazeintimeCmd();
  407.             $timeret3->setLogicalId(timeret3);
  408.             $timeret3->setIsVisible(1);
  409.             $timeret3->setName(__('Durée retour 3', __FILE__));
  410.         }
  411.         $timeret3->setType('info');
  412.         $timeret3->setSubType('numeric');
  413.         $timeret3->setUnite('min');
  414.         $timeret3->setConfiguration('onlyChangeEvent',1);
  415.         $timeret3->setEventOnly(1);
  416.         $timeret3->setEqLogic_id($this->getId());
  417.         $timeret3->save();
  418.  
  419.         $refresh = $this->getCmd(null, 'refresh');
  420.         if (!is_object($refresh)) {
  421.             $refresh = new wazeintimeCmd();
  422.             $refresh->setLogicalId('refresh');
  423.             $refresh->setIsVisible(1);
  424.             $refresh->setName(__('Rafraichir', __FILE__));
  425.         }
  426.         $refresh->setType('action');
  427.         $refresh->setSubType('other');
  428.         $refresh->setEqLogic_id($this->getId());
  429.         $refresh->save();
  430.  
  431.         $lastrefresh = $this->getCmd(null, 'lastrefresh');
  432.         if (!is_object($lastrefresh)) {
  433.             $lastrefresh = new wazeintimeCmd();
  434.             $lastrefresh->setLogicalId('lastrefresh');
  435.             $lastrefresh->setIsVisible(1);
  436.             $lastrefresh->setName(__('Dernier refresh', __FILE__));
  437.         }
  438.         $lastrefresh->setType('info');
  439.         $lastrefresh->setSubType('string');
  440.         $lastrefresh->setConfiguration('onlyChangeEvent',1);
  441.         $lastrefresh->setEventOnly(1);
  442.         $lastrefresh->setEqLogic_id($this->getId());
  443.         $lastrefresh->save();
  444.  
  445.         $lastrefreshret = $this->getCmd(null, 'lastrefreshret');
  446.         if (!is_object($lastrefreshret)) {
  447.             $lastrefreshret = new wazeintimeCmd();
  448.             $lastrefreshret->setLogicalId('lastrefreshret');
  449.             $lastrefreshret->setIsVisible(1);
  450.             $lastrefreshret->setName(__('Dernier refresh retour', __FILE__));
  451.         }
  452.         $lastrefreshret->setType('info');
  453.         $lastrefreshret->setSubType('string');
  454.         $lastrefreshret->setConfiguration('onlyChangeEvent',1);
  455.         $lastrefreshret->setEventOnly(1);
  456.         $lastrefreshret->setEqLogic_id($this->getId());
  457.         $lastrefreshret->save();
  458.  
  459.     }
  460.  
  461.     public function postUpdate() {
  462.         $this->cron30($this->getId());
  463.     }
  464.  
  465.     public function toHtml($_version = 'dashboard') {
  466.         if ($this->getIsEnable() != 1) {
  467.             return '';
  468.         }
  469.         if (!$this->hasRight('r')) {
  470.             return '';
  471.         }
  472.         $version = jeedom::versionAlias($_version);
  473.         if ($this->getDisplay('hideOn' . $version) == 1) {
  474.             return '';
  475.         }
  476.         $mc = cache::byKey('wazeintimeWidget' . jeedom::versionAlias($_version) . $this->getId());
  477.         if ($mc->getValue() != '') {
  478.             return preg_replace("/" . preg_quote(self::UIDDELIMITER) . "(.*?)" . preg_quote(self::UIDDELIMITER) . "/", self::UIDDELIMITER . mt_rand() . self::UIDDELIMITER, $mc->getValue());
  479.         }
  480.         $_version = jeedom::versionAlias($_version);
  481.         $background=$this->getBackgroundColor($_version);
  482.         $hide1=$this->getConfiguration('hide1');
  483.         $hide2=$this->getConfiguration('hide2');
  484.         $hide3=$this->getConfiguration('hide3');
  485.         $replace = array(
  486.             '#name#' => $this->getName(),
  487.             '#id#' => $this->getId(),
  488.             '#background_color#' => $background,
  489.             '#eqLink#' => $this->getLinkToConfiguration(),
  490.             '#uid#' => 'wazeintime' . $this->getId() . self::UIDDELIMITER . mt_rand() . self::UIDDELIMITER,
  491.             '#height#' => $this->getDisplay('height', 'auto'),
  492.             '#width#' => $this->getDisplay('width', '330px'),
  493.             '#hide1#' => $hide1,
  494.             '#hide2#' => $hide2,
  495.             '#hide3#' => $hide3,
  496.         );
  497.         foreach ($this->getCmd('info') as $cmd) {
  498.             $replace['#' . $cmd->getLogicalId() . '_history#'] = '';
  499.                 $replace['#' . $cmd->getLogicalId() . '_id#'] = $cmd->getId();
  500.                 $replace['#' . $cmd->getLogicalId() . '#'] = $cmd->execCmd();
  501.                 $replace['#' . $cmd->getLogicalId() . '_collect#'] = $cmd->getCollectDate();
  502.                 if ($cmd->getIsHistorized() == 1) {
  503.                     $replace['#' . $cmd->getLogicalId() . '_history#'] = 'history cursor';
  504.                 }
  505.  
  506.         }
  507.  
  508.         $refresh = $this->getCmd(null, 'refresh');
  509.         $replace['#refresh_id#'] = $refresh->getId();
  510.  
  511.         if (($_version == 'dview' || $_version == 'mview') && $this->getDisplay('doNotShowNameOnView') == 1) {
  512.             $replace['#name#'] = '';
  513.             $replace['#object_name#'] = (is_object($object)) ? $object->getName() : '';
  514.         }
  515.         if (($_version == 'mobile' || $_version == 'dashboard') && $this->getDisplay('doNotShowNameOnDashboard') == 1) {
  516.             $replace['#name#'] = '<br/>';
  517.             $replace['#object_name#'] = (is_object($object)) ? $object->getName() : '';
  518.         }
  519.  
  520.         $parameters = $this->getDisplay('parameters');
  521.         if (is_array($parameters)) {
  522.             foreach ($parameters as $key => $value) {
  523.                 $replace['#' . $key . '#'] = $value;
  524.             }
  525.         }
  526.  
  527.         $html = template_replace($replace, getTemplate('core', $_version, 'eqlogic', 'wazeintime'));
  528.         cache::set('wazeintimeWidget' . $version . $this->getId(), $html, 0);
  529.         return $html;
  530.     }
  531. }
  532.  
  533. class wazeintimeCmd extends cmd {
  534.     /*     * *************************Attributs****************************** */
  535.  
  536.  
  537.     /*     * ***********************Methode static*************************** */
  538.  
  539.  
  540.     /*     * *********************Methode d'instance************************* */
  541.  
  542.     public function execute($_options = null) {
  543.         if ($this->getType() == '') {
  544.             return '';
  545.         }
  546.         $eqLogic = $this->getEqlogic();
  547.         $eqLogic->cron30($eqLogic->getId());
  548.     }
  549.  
  550.     /*     * **********************Getteur Setteur*************************** */
  551. }
  552. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement