| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ |
|---|
| 4 | |
|---|
| 5 | // +-------------------------------------------------------------------+ |
|---|
| 6 | // | WiFiDog Authentication Server | |
|---|
| 7 | // | ============================= | |
|---|
| 8 | // | | |
|---|
| 9 | // | The WiFiDog Authentication Server is part of the WiFiDog captive | |
|---|
| 10 | // | portal suite. | |
|---|
| 11 | // +-------------------------------------------------------------------+ |
|---|
| 12 | // | PHP version 5 required. | |
|---|
| 13 | // +-------------------------------------------------------------------+ |
|---|
| 14 | // | Homepage: http://www.wifidog.org/ | |
|---|
| 15 | // | Source Forge: http://sourceforge.net/projects/wifidog/ | |
|---|
| 16 | // +-------------------------------------------------------------------+ |
|---|
| 17 | // | This program is free software; you can redistribute it and/or | |
|---|
| 18 | // | modify it under the terms of the GNU General Public License as | |
|---|
| 19 | // | published by the Free Software Foundation; either version 2 of | |
|---|
| 20 | // | the License, or (at your option) any later version. | |
|---|
| 21 | // | | |
|---|
| 22 | // | This program is distributed in the hope that it will be useful, | |
|---|
| 23 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 24 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 25 | // | GNU General Public License for more details. | |
|---|
| 26 | // | | |
|---|
| 27 | // | You should have received a copy of the GNU General Public License | |
|---|
| 28 | // | along with this program; if not, contact: | |
|---|
| 29 | // | | |
|---|
| 30 | // | Free Software Foundation Voice: +1-617-542-5942 | |
|---|
| 31 | // | 59 Temple Place - Suite 330 Fax: +1-617-542-2652 | |
|---|
| 32 | // | Boston, MA 02111-1307, USA gnu@gnu.org | |
|---|
| 33 | // | | |
|---|
| 34 | // +-------------------------------------------------------------------+ |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * @package WiFiDogAuthServer |
|---|
| 38 | * @author Benoit Grégoire <benoitg@coeus.ca> |
|---|
| 39 | * @copyright 2006 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 40 | * @version Subversion $Id: $ |
|---|
| 41 | * @link http://www.wifidog.org/ |
|---|
| 42 | */ |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Theme packs contain stylesheets and graphical elements to customize the |
|---|
| 46 | * general look of the system. |
|---|
| 47 | * |
|---|
| 48 | * @package WiFiDogAuthServer |
|---|
| 49 | * @author Benoit Grégoire <benoitg@coeus.ca> |
|---|
| 50 | * @copyright 2006 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 51 | */ |
|---|
| 52 | class ThemePack { |
|---|
| 53 | /** |
|---|
| 54 | * ID of ThemePack |
|---|
| 55 | * |
|---|
| 56 | |
|---|
| 57 | */ |
|---|
| 58 | private $_id; |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | * Name of ThemePack |
|---|
| 62 | * |
|---|
| 63 | |
|---|
| 64 | */ |
|---|
| 65 | private $_name; |
|---|
| 66 | |
|---|
| 67 | /** |
|---|
| 68 | * Description of ThemePack |
|---|
| 69 | * |
|---|
| 70 | |
|---|
| 71 | */ |
|---|
| 72 | private $_description; |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * Constructor |
|---|
| 76 | * |
|---|
| 77 | * @param string $themePackId The id of the theme pack (actually, the |
|---|
| 78 | * folder name without the path) |
|---|
| 79 | * |
|---|
| 80 | * @return void |
|---|
| 81 | |
|---|
| 82 | */ |
|---|
| 83 | private function __construct($themePackId) { |
|---|
| 84 | $handle = @ opendir(WIFIDOG_ABS_FILE_PATH . NETWORK_THEME_PACKS_DIR . $themePackId.'/'); |
|---|
| 85 | |
|---|
| 86 | if (!$handle) { |
|---|
| 87 | throw new exception(sprintf(_("Theme pack %s cannot be found in %s"), $themePackId, WIFIDOG_ABS_FILE_PATH . NETWORK_THEME_PACKS_DIR . $themePackId . '/')); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | $this->_id = $themePackId; |
|---|
| 91 | $this->_name = file_get_contents(WIFIDOG_ABS_FILE_PATH . NETWORK_THEME_PACKS_DIR . $this->_id . '/name.txt'); |
|---|
| 92 | |
|---|
| 93 | if ($this->_name == null) { |
|---|
| 94 | $this->_name = sprintf(_("%s (Theme did not include a name.txt file)"), $this->_id); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | $this->_description = file_get_contents(WIFIDOG_ABS_FILE_PATH . NETWORK_THEME_PACKS_DIR . $this->_id . '/description.txt'); |
|---|
| 98 | |
|---|
| 99 | if ($this->_description == null) { |
|---|
| 100 | $this->_description = sprintf(_("%s (Theme did not include a description.txt file)"), $this->_name); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | /** |
|---|
| 105 | * Get an interface to pick a theme pack |
|---|
| 106 | * |
|---|
| 107 | * If there is only one network available, no interface is actually shown |
|---|
| 108 | * |
|---|
| 109 | * @param string $userPrefix An identifier provided by the |
|---|
| 110 | * programmer to recognise it's |
|---|
| 111 | * generated html form |
|---|
| 112 | * @param object $preSelectedThemePack Theme object: The theme to be pre- |
|---|
| 113 | * selected in the form object |
|---|
| 114 | * |
|---|
| 115 | * @return string HTML markup |
|---|
| 116 | |
|---|
| 117 | */ |
|---|
| 118 | public static function getSelectUI($userPrefix, $preSelectedThemePack = null) { |
|---|
| 119 | $html = ''; |
|---|
| 120 | $name = $userPrefix; |
|---|
| 121 | $html .= _("Theme pack:")." \n"; |
|---|
| 122 | |
|---|
| 123 | if ($preSelectedThemePack) { |
|---|
| 124 | $selected_id = $preSelectedThemePack->getId(); |
|---|
| 125 | } else { |
|---|
| 126 | $selected_id = null; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | if ($handle = @ opendir(WIFIDOG_ABS_FILE_PATH.NETWORK_THEME_PACKS_DIR)) { |
|---|
| 130 | $tab = array (); |
|---|
| 131 | $i = 0; |
|---|
| 132 | |
|---|
| 133 | while (false !== ($directory = readdir($handle))) { |
|---|
| 134 | if ($directory != '.' && $directory != '..' && $directory != '.svn' && is_dir(WIFIDOG_ABS_FILE_PATH.NETWORK_THEME_PACKS_DIR.$directory.'/')) { |
|---|
| 135 | $theme_pack = self::getObject($directory); |
|---|
| 136 | $tab[$i][0] = $theme_pack->getId(); |
|---|
| 137 | $tab[$i][1] = $theme_pack->getName(); |
|---|
| 138 | $tab[$i][2] = $theme_pack->getDescription(); |
|---|
| 139 | $i ++; |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | closedir($handle); |
|---|
| 143 | } else { |
|---|
| 144 | throw new exception(_("Unable to open the network theme packs directory")); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | //pretty_print_r($tab); |
|---|
| 148 | if (count($tab) > 0) { |
|---|
| 149 | $html .= FormSelectGenerator :: generateFromArray($tab, $selected_id, $name, null, true); |
|---|
| 150 | } else { |
|---|
| 151 | $html .= sprintf(_("No network theme packs available in %s"), WIFIDOG_ABS_FILE_PATH.NETWORK_THEME_PACKS_DIR); |
|---|
| 152 | $html .= "<input type='hidden' name='$name' value=''>"; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | return $html; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | /** |
|---|
| 159 | * Get an instance of the object |
|---|
| 160 | * |
|---|
| 161 | * @param object $id The object id |
|---|
| 162 | * |
|---|
| 163 | * @return object The Content object, or null if there was an error (an |
|---|
| 164 | * exception is also thrown) |
|---|
| 165 | * |
|---|
| 166 | |
|---|
| 167 | */ |
|---|
| 168 | static public function getObject($id) { |
|---|
| 169 | return new self($id); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | /** |
|---|
| 173 | * Retreives the id of the object |
|---|
| 174 | * |
|---|
| 175 | * @return string The id |
|---|
| 176 | */ |
|---|
| 177 | public function getId() { |
|---|
| 178 | return $this->_id; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | /** |
|---|
| 182 | * Retreives the name of the ThemePack |
|---|
| 183 | * |
|---|
| 184 | * @return string Name of ThemePack |
|---|
| 185 | */ |
|---|
| 186 | public function getName() { |
|---|
| 187 | return $this->_name; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | /** |
|---|
| 191 | * Retreives the description of the ThemePack |
|---|
| 192 | * |
|---|
| 193 | * @return string Description of ThemePack |
|---|
| 194 | */ |
|---|
| 195 | public function getDescription() { |
|---|
| 196 | return $this->_description; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | /** |
|---|
| 200 | * Retreives the url of this theme's stylesheet |
|---|
| 201 | * |
|---|
| 202 | * @return string URL of this theme's stylesheet |
|---|
| 203 | */ |
|---|
| 204 | public function getStylesheetUrl() { |
|---|
| 205 | return BASE_URL_PATH . NETWORK_THEME_PACKS_DIR . $this->_id . '/stylesheet.css'; |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | /** |
|---|
| 209 | * Retreives the url of this theme's config file (if exists |
|---|
| 210 | * |
|---|
| 211 | * @return string URL of this theme's config |
|---|
| 212 | */ |
|---|
| 213 | public function getThemeConfigPath() { |
|---|
| 214 | return WIFIDOG_ABS_FILE_PATH . NETWORK_THEME_PACKS_DIR . $this->_id . '/themeconfig.php'; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | /* |
|---|
| 221 | * Local variables: |
|---|
| 222 | * tab-width: 4 |
|---|
| 223 | * c-basic-offset: 4 |
|---|
| 224 | * c-hanging-comment-ender-p: nil |
|---|
| 225 | * End: |
|---|
| 226 | */ |
|---|