root / nephthys_tmpl.php
View | Annotate | Download (10.6 KB)
| 1 | <?php
|
|---|---|
| 2 | |
| 3 | /***************************************************************************
|
| 4 | * |
| 5 | * Nephthys - file sharing management |
| 6 | * Copyright (c) by Andreas Unterkircher, unki@netshadow.at |
| 7 | * |
| 8 | * This file is part of Nephthys. |
| 9 | * |
| 10 | * Nephthys is free software: you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation, either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * Nephthys is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with Nephthys. If not, see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | ***************************************************************************/ |
| 24 | |
| 25 | class NEPHTHYS_TMPL extends Smarty { |
| 26 | |
| 27 | private $parent;
|
| 28 | |
| 29 | public function __construct() |
| 30 | {
|
| 31 | global $nephthys;
|
| 32 | |
| 33 | $this->_translationTable = Array();
|
| 34 | $this->_loadedTranslationTables = Array();
|
| 35 | |
| 36 | $this->parent =& $nephthys;
|
| 37 | |
| 38 | if(!file_exists($nephthys->cfg->base_path .'/themes/'. $nephthys->cfg->theme_name .'/templates')) { |
| 39 | $this->parent->_error("No templates found in ". $nephthys->cfg->base_path .'/themes/'. $nephthys->cfg->theme_name .'/templates'); |
| 40 | exit(1); |
| 41 | } |
| 42 | |
| 43 | // for debugging - disable Smarty caching
|
| 44 | //$this->caching = 0;
|
| 45 | //$this->force_compile = true;
|
| 46 | |
| 47 | $this->Smarty();
|
| 48 | |
| 49 | $this->template_dir = $nephthys->cfg->base_path .'/themes/'. $nephthys->cfg->theme_name .'/templates'; |
| 50 | $this->compile_dir = $nephthys->cfg->tmpl_path .'/templates_c'; |
| 51 | $this->config_dir = $nephthys->cfg->tmpl_path .'/smarty_config'; |
| 52 | $this->cache_dir = $nephthys->cfg->tmpl_path .'/smarty_cache'; |
| 53 | $this->theme_root = $nephthys->cfg->web_path .'themes/'. $nephthys->cfg->theme_name; |
| 54 | |
| 55 | if(isset($_SESSION['login_idx']) && is_numeric($_SESSION['login_idx'])) { |
| 56 | $this->assign('login_name', $nephthys->get_user_name($_SESSION['login_idx'])); |
| 57 | $this->assign('login_priv', $nephthys->get_user_priv($_SESSION['login_idx'])); |
| 58 | $this->assign('login_idx', $_SESSION['login_idx']); |
| 59 | } |
| 60 | |
| 61 | $this->assign('theme_root', $this->theme_root); |
| 62 | $this->assign('bucket_sender', $nephthys->get_my_email()); |
| 63 | $this->assign('page_title', $nephthys->cfg->page_title); |
| 64 | $this->assign('product', $nephthys->cfg->product); |
| 65 | $this->assign('version', $nephthys->cfg->version); |
| 66 | $this->assign('db_version', $nephthys->cfg->db_version); |
| 67 | $this->assign('bucket_via_dav', $nephthys->cfg->bucket_via_dav); |
| 68 | $this->assign('bucket_via_ftp', $nephthys->cfg->bucket_via_ftp); |
| 69 | $this->assign('bucket_via_http_upload', $nephthys->cfg->bucket_via_http_upload); |
| 70 | $this->assign('template_path', 'themes/'. $nephthys->cfg->theme_name); |
| 71 | $this->register_function("page_start", array(&$this, "smarty_page_start"), false); |
| 72 | $this->register_function("page_end", array(&$this, "smarty_page_end"), false); |
| 73 | $this->register_function("save_button", array(&$this, "smarty_save_button"), false); |
| 74 | $this->register_function("import_bucket_list", array(&$this, "smarty_import_bucket_list"), false); |
| 75 | $this->register_function("expiration_list", array(&$this, "smarty_expiration_list"), false); |
| 76 | $this->register_function("language_list", array(&$this, "smarty_language_list"), false); |
| 77 | $this->register_function("owner_list", array(&$this, "smarty_owner_list"), false); |
| 78 | $this->register_function("sort_link", array(&$this, "smarty_sort_link"), false); |
| 79 | |
| 80 | $this->register_postfilter(array(&$this, "smarty_prefilter_i18n")); |
| 81 | |
| 82 | } // __construct()
|
| 83 | |
| 84 | public function smarty_page_start($params, &$smarty) |
| 85 | {
|
| 86 | if(isset($params['header'])) |
| 87 | $this->assign('header', $params['header']); |
| 88 | if(isset($params['subheader'])) |
| 89 | $this->assign('subheader', $params['subheader']); |
| 90 | |
| 91 | return $this->fetch('page_start.tpl'); |
| 92 | |
| 93 | } // smarty_function_page_start()
|
| 94 | |
| 95 | public function smarty_page_end($params, &$smarty) |
| 96 | {
|
| 97 | if(isset($params['focus_to'])) { |
| 98 | $this->assign('focus_to', $params['focus_to']); |
| 99 | } |
| 100 | |
| 101 | return $this->fetch('page_end.tpl'); |
| 102 | |
| 103 | } // smarty_function_startTable()
|
| 104 | |
| 105 | public function smarty_save_button($params, &$smarty) |
| 106 | {
|
| 107 | if(isset($params['text'])) { |
| 108 | $this->assign('text', $params['text']); |
| 109 | } |
| 110 | |
| 111 | return $this->fetch('save_button.tpl'); |
| 112 | |
| 113 | } // smarty_function_startTable()
|
| 114 | |
| 115 | /**
|
| 116 | * output sort link |
| 117 | * |
| 118 | * this function outputs the sort-links used to trigger |
| 119 | * the javascript function update_sort_order() to alternate |
| 120 | * the column-sort-ordering. |
| 121 | */ |
| 122 | public function smarty_sort_link($params, &$smarty) |
| 123 | {
|
| 124 | if(!isset($params['module']) || |
| 125 | !isset($params['column']) || |
| 126 | !isset($params['order'])) { |
| 127 | |
| 128 | $smarty->trigger_error('assign: module, column and order are required parameters');
|
| 129 | |
| 130 | } |
| 131 | |
| 132 | $module = $params['module'];
|
| 133 | $column = $params['column'];
|
| 134 | $order = $params['order'];
|
| 135 | |
| 136 | $string = "<a href=\"#\" onclick=\"update_sort_order("
|
| 137 | ."'". $module ."', " |
| 138 | ."'". $column ."', " |
| 139 | ."'". $order ."'"; |
| 140 | |
| 141 | if(isset($params['return'])) { |
| 142 | $string.= ", "
|
| 143 | ."'". $params['return'] ."'"; |
| 144 | } |
| 145 | |
| 146 | $string.= ");\" title=\"";
|
| 147 | |
| 148 | if($order == 'asc') { |
| 149 | $string.= $this->parent->_("##ASCENDING##"); |
| 150 | } |
| 151 | elseif($order == 'desc') { |
| 152 | $string.= $this->parent->_("##DESCENDING##"); |
| 153 | } |
| 154 | |
| 155 | $string.= "\"><img src=\"";
|
| 156 | |
| 157 | if($order == 'asc') { |
| 158 | if(isset($_SESSION['sort_order'][$module]) && |
| 159 | $_SESSION['sort_order'][$module]['column'] == $column && |
| 160 | $_SESSION['sort_order'][$module]['order'] == "asc") { |
| 161 | |
| 162 | $string.= $this->theme_root ."/images/sort_asc_sel.png"; |
| 163 | } |
| 164 | else {
|
| 165 | |
| 166 | $string.= $this->theme_root ."/images/sort_asc.png"; |
| 167 | } |
| 168 | } |
| 169 | elseif($order == 'desc') { |
| 170 | if(isset($_SESSION['sort_order'][$module]) && |
| 171 | $_SESSION['sort_order'][$module]['column'] == $column && |
| 172 | $_SESSION['sort_order'][$module]['order'] == "desc") { |
| 173 | |
| 174 | $string.= $this->theme_root ."/images/sort_desc_sel.png"; |
| 175 | } |
| 176 | else {
|
| 177 | |
| 178 | $string.= $this->theme_root ."/images/sort_desc.png"; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | $string.= "\" /></a>";
|
| 183 | |
| 184 | return $string;
|
| 185 | |
| 186 | } // smarty_sort_link()
|
| 187 | |
| 188 | public function smarty_import_bucket_list() |
| 189 | {
|
| 190 | $bucket = new NEPHTHYS_BUCKETS();
|
| 191 | return $bucket->showList();
|
| 192 | |
| 193 | } // smarty_import_bucket_list()
|
| 194 | |
| 195 | public function smarty_expiration_list($params, &$smarty) |
| 196 | {
|
| 197 | $select = "<select name=\"". $params['name'] ."\">\n"; |
| 198 | |
| 199 | foreach($this->parent->cfg->expirations as $expire) { |
| 200 | |
| 201 | list($days, $name, $require_priv) = preg_split("/;/", $expire); |
| 202 | |
| 203 | /* "user" privileged users are not allowed to create long-time
|
| 204 | existing buckets. Only if the got the right assigned by an |
| 205 | admin. |
| 206 | |
| 207 | if the expiry-entry requires higher privileges... |
| 208 | ... and the current user has no higher privileges |
| 209 | ... and his is not equipped with the long-time bucket priv |
| 210 | then go to the next entry... |
| 211 | */ |
| 212 | if($require_priv != "user" && ( |
| 213 | $this->parent->check_privileges('user') && |
| 214 | !$this->parent->has_bucket_privileges()
|
| 215 | )) {
|
| 216 | |
| 217 | continue;
|
| 218 | } |
| 219 | |
| 220 | /* if translation is requested, try to get it */
|
| 221 | if(preg_match('/(##.+?##)/', $name, $period)) { |
| 222 | |
| 223 | $period = $this->parent->_($period[0]); |
| 224 | $name = preg_replace('/##.+?##/', $period, $name);
|
| 225 | } |
| 226 | |
| 227 | $select.= "<option value=\"". $days ."\""; |
| 228 | if(isset($params['current']) && $params['current'] == $days) |
| 229 | $select.= " selected=\"selected\"";
|
| 230 | $select.= ">". $name."</option>\n"; |
| 231 | |
| 232 | } |
| 233 | |
| 234 | $select.= "</select>\n";
|
| 235 | return $select;
|
| 236 | |
| 237 | } //smarty_expiration_list()
|
| 238 | |
| 239 | public function smarty_owner_list($params, &$smarty) |
| 240 | {
|
| 241 | $users = $this->parent->db->db_query(" |
| 242 | SELECT * |
| 243 | FROM nephthys_users |
| 244 | WHERE user_active='Y' |
| 245 | ORDER BY user_name ASC |
| 246 | ");
|
| 247 | |
| 248 | $select = "<select name=\"". $params['name'] ."\">\n"; |
| 249 | |
| 250 | while($user = $users->fetchRow()) {
|
| 251 | |
| 252 | $select.= "<option value=\"". $user->user_idx ."\""; |
| 253 | if(isset($params['current']) && $params['current'] == $user->user_idx) |
| 254 | $select.= " selected=\"selected\"";
|
| 255 | $select.= ">". $user->user_name."</option>\n"; |
| 256 | } |
| 257 | |
| 258 | $select.= "</select>\n";
|
| 259 | return $select;
|
| 260 | |
| 261 | } //smarty_owner_list()
|
| 262 | |
| 263 | public function smarty_language_list($params, &$smarty) |
| 264 | {
|
| 265 | $select = "<select name=\"". $params['name'] ."\">\n"; |
| 266 | |
| 267 | foreach($this->parent->cfg->avail_langs as $locale => $lang) { |
| 268 | |
| 269 | $select.= "<option value=\"". $locale ."\""; |
| 270 | if(isset($params['current']) && $params['current'] == $locale) |
| 271 | $select.= " selected=\"selected\"";
|
| 272 | $select.= ">". $lang."</option>\n"; |
| 273 | |
| 274 | } |
| 275 | |
| 276 | $select.= "</select>\n";
|
| 277 | return $select;
|
| 278 | |
| 279 | } //smarty_language_list()
|
| 280 | |
| 281 | public function fetch($_smarty_tpl_file, $_smarty_cache_id = null, $_smarty_compile_id = null, $_smarty_display = false) |
| 282 | {
|
| 283 | // We need to set the cache id and the compile id so a new script will be
|
| 284 | // compiled for each language. This makes things really fast ;-)
|
| 285 | $_smarty_compile_id = $this->parent->get_language().'-'.$_smarty_compile_id; |
| 286 | $_smarty_cache_id = $_smarty_compile_id; |
| 287 | |
| 288 | // Now call parent method
|
| 289 | return parent::fetch( $_smarty_tpl_file, $_smarty_cache_id, $_smarty_compile_id, $_smarty_display );
|
| 290 | |
| 291 | } // fetch()
|
| 292 | |
| 293 | /**
|
| 294 | * smarty_prefilter_i18n() |
| 295 | * This function takes the language file, and rips it into the template |
| 296 | * |
| 297 | * @param $tpl_source |
| 298 | * @return |
| 299 | **/ |
| 300 | public function smarty_prefilter_i18n($tpl_source, &$smarty) |
| 301 | {
|
| 302 | // Now replace the matched language strings with the entry in the file
|
| 303 | return preg_replace_callback('/##(.+?)##/', array(&$this, '_compile_lang'), $tpl_source); |
| 304 | |
| 305 | } // smarty_prefilter_i18n()
|
| 306 | |
| 307 | /**
|
| 308 | * _compile_lang |
| 309 | * Called by smarty_prefilter_i18n function it processes every language |
| 310 | * identifier, and inserts the language string in its place. |
| 311 | * |
| 312 | */ |
| 313 | public function _compile_lang($key) |
| 314 | {
|
| 315 | return $this->parent->get_translation($key[1]); |
| 316 | |
| 317 | } // _compile_lang()
|
| 318 | |
| 319 | } // class SmartyML
|
| 320 | |
| 321 | // vim: set filetype=php expandtab softtabstop=3 tabstop=3 shiftwidth=3 autoindent smartindent:
|
| 322 | ?> |
| 323 |