コード例 #1
0
ファイル: IEHost.php プロジェクト: stpq/icinga_configurator
 /**
  * Zjistí ikonu, stahne jí z netu, zkonvertuje a použije jako ikonu hosta
  */
 public function favToIcon()
 {
     $icoUrl = false;
     $baseUrl = 'http://' . $this->getDataValue('host_name') . '/';
     $indexpage = @file_get_contents($baseUrl);
     $icoUrls = array();
     if (strlen($indexpage)) {
         $dom = new DOMDocument();
         @$dom->loadHTML($indexpage);
         $links = $dom->getElementsByTagName('link');
         foreach ($links as $link) {
             $urlLink = false;
             if (isset($link->attributes)) {
                 foreach ($link->attributes as $atribut) {
                     if (isset($atribut->name)) {
                         if ($atribut->name == 'rel' && stristr($atribut->value, 'icon')) {
                             $urlLink = true;
                             $rel = $atribut->value;
                         }
                         if ($atribut->name == 'href') {
                             $url = $atribut->value;
                         }
                     }
                 }
                 if ($urlLink) {
                     if (strstr($url, '://')) {
                         $icoUrls[$rel] = $url;
                     } else {
                         $icoUrls[$rel] = $baseUrl . $url;
                     }
                 }
             }
         }
     }
     if (!count($icoUrls)) {
         $icoUrls[] = $baseUrl . '/favicon.ico';
     } else {
         if (count($icoUrls) == 1) {
             $icoUrl = current($icoUrls);
         } else {
             foreach ($icoUrls as $ico) {
                 if (strstr($ico, '.png')) {
                     $icoUrl = $ico;
                 }
             }
             if (!$icoUrl) {
                 foreach ($icoUrls as $ico) {
                     if (strstr($ico, '.gif')) {
                         $icoUrl = $ico;
                     }
                 }
             }
             if (!$icoUrl) {
                 foreach ($icoUrls as $ico) {
                     if (strstr($ico, '.jpg')) {
                         $icoUrl = $ico;
                     }
                 }
             }
             if (!$icoUrl) {
                 $icoUrl = current($icoUrls);
             }
         }
     }
     $tmpfilename = sys_get_temp_dir() . '/' . EaseSand::randomString();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $icoUrl);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     $downloaded = curl_exec($ch);
     curl_close($ch);
     file_put_contents($tmpfilename, $downloaded);
     if (IEIconSelector::imageTypeOK($tmpfilename)) {
         EaseShared::webPage()->addStatusMessage(sprintf(_('Nalezena ikona %s'), $icoUrl), 'success');
         $newicon = IEIconSelector::saveIcon($tmpfilename, $this);
         if ($newicon) {
             $this->setDataValue('icon_image', $newicon);
             $this->setDataValue('statusmap_image', $newicon);
             return true;
         }
     } else {
         unlink($tmpfilename);
     }
     return false;
 }
コード例 #2
0
ファイル: host.php プロジェクト: stpq/icinga_configurator
         fclose($fp);
         if (!file_exists($tmpfilename)) {
             $oPage->addStatusMessage(sprintf(_('Soubor %s se nepodařilo stahnout'), $icourlurl));
         }
     } else {
         if (isset($_FILES) && count($_FILES)) {
             $tmpfilename = $_FILES['icofile']['tmp_name'];
         } else {
             if ($oPage->isPosted()) {
                 $oPage->addStatusMessage(_('Nebyl vybrán soubor s ikonou hosta'), 'warning');
             }
         }
     }
     if (isset($tmpfilename)) {
         if (IEIconSelector::imageTypeOK($tmpfilename)) {
             $newicon = IEIconSelector::saveIcon($tmpfilename, $host);
         } else {
             unlink($tmpfilename);
             $oPage->addStatusMessage(_('toto není obrázek požadovaného typu'), 'warning');
         }
     }
 case 'newicon':
     if (!isset($newicon)) {
         $newicon = $oPage->getRequestValue('newicon');
     }
     if (strlen($newicon)) {
         $host->setDataValue('icon_image', $newicon);
         $host->setDataValue('statusmap_image', $newicon);
         $host->setDataValue('icon_image_alt', $oPage->getRequestValue('icon_image_alt'));
         if ($host->saveToMySQL()) {
             $oUser->addStatusMessage(_('Ikona byla přiřazena'), 'success');