root/trunk/wifidog-auth/wifidog/classes/SmartyWifidog.php @ 1462

Revision 1421, 8.3 KB (checked in by benoitg, 4 years ago)

Update my email address

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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  2004-2006 Benoit Grégoire, Technologies Coeus inc.
40 * @version    Subversion $Id$
41 * @link       http://www.wifidog.org/
42 */
43
44/**
45 * Load required classes
46 */
47require_once("classes/Locale.php");
48require_once("classes/Utils.php");
49// Check if all mandatory components (such as Smarty) installed, if not redirect user to web-base installation
50if (Dependency::checkMandatoryComponents($errmsg)) {
51    // Load Smarty library
52    require_once(SMARTY_PATH.'Smarty.class.php');
53} else {
54    // Build the system_path for the auth-server
55    print "Redirecting to Wifidog web-based install script since a mandatory Dependency is missing (Error was: $errmsg)<META HTTP-EQUIV=Refresh CONTENT=\"5; URL=".BASE_URL_PATH."/install.php\">";
56    exit();
57}
58require_once("include/smarty.resource.string.php");
59/*
60 * Smarty plugin
61 * -------------------------------------------------------------
62 * Type:    modifier
63 * Name:    fsize_format
64 * Version:    0.2
65 * Date:    2003-05-15
66 * Author:    Joscha Feth, joscha@feth.com
67 * Purpose: formats a filesize (in bytes) to human-readable format
68 * Usage:    In the template, use
69 {$filesize|fsize_format}    =>    123.45 B|KB|MB|GB|TB
70 or
71 {$filesize|fsize_format:"MB"}    =>    123.45 MB
72 or
73 {$filesize|fsize_format:"TB":4}    =>    0.0012 TB
74 * Params:
75 int        size            the filesize in bytes
76 string    format            the format, the output shall be: B, KB, MB, GB or TB
77 int        precision        the rounding precision
78 string    dec_point        the decimal separator
79 string    thousands_sep    the thousands separator
80 * Install: Drop into the plugin directory
81 * Version:
82 *            2003-05-15    Version 0.2    - added dec_point and thousands_sep thanks to Thomas Brandl, tbrandl@barff.de
83 *                                    - made format always uppercase
84 *                                    - count sizes "on-the-fly"
85 *            2003-02-21    Version 0.1    - initial release
86 * -------------------------------------------------------------
87 */
88function smarty_modifier_fsize_format($size,$format = '',$precision = 2, $dec_point = ".", $thousands_sep = ",")
89{
90    $format = strtoupper($format);
91
92    static $sizes = array();
93
94    if(!count($sizes)) {
95        $b = 1024;
96        $sizes["B"]        =    1;
97        $sizes["KB"]    =    $sizes["B"]  * $b;
98        $sizes["MB"]    =    $sizes["KB"] * $b;
99        $sizes["GB"]    =    $sizes["MB"] * $b;
100        $sizes["TB"]    =    $sizes["GB"] * $b;
101
102        $sizes = array_reverse($sizes,true);
103    }
104
105    //~ get "human" filesize
106    foreach($sizes    AS    $unit => $bytes) {
107        if($size > $bytes || $unit == $format) {
108            //~ return formatted size
109            return    number_format($size / $bytes,$precision,$dec_point,$thousands_sep)." ".$unit;
110        } //~ end if
111    } //~ end foreach
112} //~ end function
113
114// The setup.php file is a good place to load
115// required application library files, and you
116// can do that right here. An example:
117// require('guestbook/guestbook.lib.php');
118
119/**
120 * @package    WiFiDogAuthServer
121 * @author     Benoit Grégoire <benoitg@coeus.ca>
122 * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
123 */
124class SmartyWifidog extends Smarty {
125    public static function &getObject() {
126        $retval = new self();
127        return $retval;
128    }
129    private function __construct()
130    {
131
132        // Class Constructor. These automatically get set with each new instance.
133
134        $this->Smarty();
135        //Now that we have user-definable templates, we must turn on security
136        $this->security = true;
137        //pretty_print_r($this->security_settings);
138        $this->security_settings['MODIFIER_FUNCS'][] = 'sprintf';
139        $this->template_dir = WIFIDOG_ABS_FILE_PATH;
140        $this->compile_dir = $this->template_dir . 'tmp/smarty/templates_c/';
141        $this->config_dir = $this->template_dir . 'tmp/smarty/configs/';
142        $this->cache_dir = $this->template_dir . 'tmp/smarty/cache/';
143
144        /* Register the _ smarty modifier to call the _()
145         * PHP function which is the gettext() function
146         */
147        $this->register_modifier("_","_");
148        $this->register_modifier("urlencode","urlencode");
149        $this->register_modifier("remove_accents",array('Utils', "remove_accents"));
150        $this->register_modifier("fsize_format", "smarty_modifier_fsize_format");
151
152                // register the resource name "string"
153                $this->register_resource("string", array("smarty_resource_string_source",
154                                       "smarty_resource_string_timestamp",
155                                       "smarty_resource_string_secure",
156                                       "smarty_resource_string_trusted"));
157        $this->caching = false;
158        //$this->compile_check = true;
159
160        /* Common content */
161    $network = Network::GetCurrentNetwork();
162
163        /* Useful stuff from config.php */
164
165        $this->assign('base_url_path', BASE_URL_PATH);
166        $this->assign('base_ssl_path', BASE_SSL_PATH);
167    $this->assign('base_non_ssl_path', BASE_NON_SSL_PATH);
168    $this->assign('common_images_url', COMMON_IMAGES_URL);
169    $this->assign('base_public_stats_url', BASE_PUBLIC_STATS_URL);
170    $this->assign('base_theme_url', BASE_THEME_URL);
171   }
172
173   function SetTemplateDir( $template_dir)
174   {
175     $this->template_dir= $template_dir;
176   }
177     /**
178     * executes & returns or displays the template results
179     * This is extended by wifidog to make sure that the variables influenced by state (such as the current node) are as up to date as humanly possible.
180     * @param string $resource_name
181     * @param string $cache_id
182     * @param string $compile_id
183     * @param boolean $display
184     */
185    public function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
186    {
187     /* Other useful variables */
188     Network::assignSmartyValues($this);
189     Node::assignSmartyValues($this);
190     User::assignSmartyValues($this);
191     return parent::fetch($resource_name, $cache_id, $compile_id, $display);
192    }
193}
194
195/*
196 * Local variables:
197 * tab-width: 4
198 * c-basic-offset: 4
199 * c-hanging-comment-ender-p: nil
200 * End:
201 */
202
203
Note: See TracBrowser for help on using the browser.