protected function getLanguage() { $conf = new Config($this->webos); if ($this->webos->managers()->get('File')->exists('~/.config/locale.xml')) { $conf->load('~/.config/locale.xml'); } if ($conf->exist('language')) { $lang = $conf->get('language'); } else { $lang = $this->webos->managers()->get('Translation')->detectLanguage(); if ($this->webos->getUser()->isConnected()) { $conf->set('language', $lang); $conf->save('~/.config/locale.xml'); } } if ($conf->exist('locale')) { $locale = $conf->get('locale'); } else { $locale = $lang; if ($this->webos->getUser()->isConnected()) { $conf->set('locale', $locale); $conf->save('~/.config/locale.xml'); } } return array('language' => $lang, 'locale' => $locale); }
public function getAvailableSpace($path) { $cacheFile = '/var/cache/diskusage.json'; if (empty($this->quotas)) { $config = new Config($this->webos); $config->load('/etc/quotas.xml'); $this->quotas['home'] = (int) $config->get('home'); } $usersSizes = null; if (count($this->sizes) == 0 && $this->exists($cacheFile)) { $usersSizes = json_decode($this->get($cacheFile)->contents(), true); if (array_key_exists($this->webos->getUser()->getId(), $usersSizes)) { $this->sizes = $usersSizes[$this->webos->getUser()->getId()]; } } $paths = array('home' => $this->userDirectory()); $availableSpace = -1; $sizesModified = false; foreach ($paths as $name => $dirname) { if (strpos($path, $dirname) === 0) { if ($this->quotas[$name] == -1) { continue; } if (!array_key_exists($name, $this->sizes)) { if (!$this->exists($dirname)) { continue; } $dir = $this->get($dirname); if (!$dir->isDir()) { continue; } $this->sizes[$name] = $dir->contentsSize(); $sizesModified = true; } $dirAvailableSpace = $this->quotas[$name] - $this->sizes[$name]; if ($availableSpace == -1 or $dirAvailableSpace < $availableSpace) { $availableSpace = $dirAvailableSpace; } } } if ($sizesModified) { if (!$this->exists($cacheFile)) { $cacheFile = $this->createFile($cacheFile); if (empty($usersSizes)) { $usersSizes = array(); } } else { $cacheFile = $this->get($cacheFile); if (empty($usersSizes)) { $usersSizes = json_decode($cacheFile->contents(), true); } } $usersSizes[$this->webos->getUser()->getId()] = $this->sizes; $cacheFile->setContents(json_encode($usersSizes)); } return $availableSpace; }
protected function _getFavoritesConfig() { $userFavoritesFile = $this->webos->managers()->get('File')->get('/etc/ske1/.config/favorites.xml'); if ($this->webos->getUser()->isConnected()) { if (!$this->webos->managers()->get('File')->exists('~/.config/favorites.xml')) { if (!$this->webos->managers()->get('File')->exists('~/.config/')) { $this->webos->managers()->get('File')->createDir('~/.config/'); } $userFavoritesFile->copy('~/.config/favorites.xml'); } $userFavoritesFile = $this->webos->managers()->get('File')->get('~/.config/favorites.xml'); } $favoritesConfig = new \lib\models\Config($this->webos); $favoritesConfig->load($userFavoritesFile); return $favoritesConfig; }
/** * Afficher l'interface utilisateur (via JavaScript). */ public function run() { //On detecte la langue du visiteur si elle ne l'est pas $conf = new Config($this); if ($this->managers()->get('File')->exists('~/.config/locale.xml')) { $conf->load('~/.config/locale.xml'); } if ($conf->exist('language')) { $this->managers()->get('Translation')->setLanguage($conf->get('language')); } else { $lang = $this->managers()->get('Translation')->detectLanguage(); if ($this->user->isConnected()) { $conf->set('language', $lang); $conf->save('~/.config/locale.xml'); } } //On recupere les fichiers JavaScript de base a inclure $jsIncludes = $this->_getJsBootFiles(); ob_start(); //On inclut le layout (structure HTMl de base) require 'boot/includes/layout.php'; $out = ob_get_contents(); ob_end_clean(); //On ajoute le HTML genere a la reponse HTTP $this->getHTTPResponse()->addContent($out); //On envoie la reponse HTTP $this->getHTTPResponse()->send(); }
/** * Modifier plusieurs parametres d'une configuration. * @param string $path Le chemin vers le fichier de configuration. * @param array $set Les parametres a definir. * @param array $remove Les parametres a enlever. */ protected function changeConfig($path, array $set, array $remove) { $config = new Config($this->webos); $config->load($path); foreach ($set as $index => $value) { $config->set($index, $value); } foreach ($remove as $index => $value) { $config->remove($index); } $config->save(); }
/** * Recuperer tous les raccourcis. */ protected function get() { if ($this->webos->getUser()->isConnected()) { $path = '~/.config/prefered-openers.xml'; $config = new Config($this->webos); if (!$this->webos->managers()->get('File')->exists($path)) { $file = $this->webos->managers()->get('File')->createFile($path); $file->setContents($config->saveXML()); } $config->load($path); $preferedOpeners = $config->getConfig(); } else { $preferedOpeners = array(); } //On recupere la liste des raccourcis $applications = $this->webos->managers()->get('File')->get('/usr/share/applications/')->contents(); //On initialise la liste $list = array('applications' => array(), 'categories' => array()); //On recupere les infos pour chaque raccourci foreach ($applications as $shortcut) { if ($shortcut->isDir()) { continue; } if ($shortcut->extension() != 'xml') { continue; } $xml = new \DOMDocument(); $xml->loadXML($shortcut->contents()); $attributes = $xml->getElementsByTagName('attribute'); $attributesList = array(); foreach ($attributes as $attribute) { $attributesList[$attribute->getAttribute('name')] = $attribute->getAttribute('value'); } $attributesList['prefered_open'] = ''; if (array_key_exists($shortcut->filename(), $preferedOpeners)) { $opens = $preferedOpeners[$shortcut->filename()]; $attributesList['prefered_open'] = $opens; if (array_key_exists('open', $attributesList)) { $attributesList['open'] .= ',' . $opens; } else { $attributesList['open'] = $opens; } } if (array_key_exists('visible', $attributesList) && (int) $attributesList['visible'] == 0) { continue; } $list['applications'][$shortcut->filename()] = $attributesList; } $favoritesConfig = $this->_getFavoritesConfig(); foreach ($favoritesConfig->getConfig() as $app => $value) { if ((int) $value > 0 && array_key_exists($app, $list['applications'])) { $list['applications'][$app]['favorite'] = (int) $value; } } //On trie le tableau uasort($list['applications'], function ($a, $b) { $specialChars = array('Š' => 'S', 'š' => 's', 'Ð' => 'Dj', 'Ž' => 'Z', 'ž' => 'z', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'ý' => 'y', 'þ' => 'b', 'ÿ' => 'y', 'ƒ' => 'f'); $aTitle = strtr($a['title'], $specialChars); $bTitle = strtr($b['title'], $specialChars); return strcmp($aTitle, $bTitle); }); //On recupere la liste des categories $categories = $this->webos->managers()->get('File')->get('/usr/share/categories/')->contents(); //On recupere les infos pour cahque categorie foreach ($categories as $shortcut) { if ($shortcut->isDir()) { continue; } if ($shortcut->extension() != 'xml') { continue; } $xml = new \DOMDocument(); $xml->loadXML($shortcut->contents()); $attributes = $xml->getElementsByTagName('attribute'); $attributesList = array(); foreach ($attributes as $attribute) { $attributesList[$attribute->getAttribute('name')] = $attribute->getAttribute('value'); } if (array_key_exists('visible', $attributesList) && (int) $attributesList['visible'] == 0) { continue; } $list['categories'][] = $attributesList; } $this->webos->getHTTPResponse()->setData($list); }