root / nephthys_tmpl.php

View | Annotate | Download (10.6 KB)

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