Adding the singleton portion of the functions class
[isso.git] / functions.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Globalized Functions
24 * functions.php
25 *
26 * @package ISSO
27 */
28
29 /**
30 * Globalized Functions
31 *
32 * This framework is a set of functions that are commonly used in most
33 * applications.
34 *
35 * @author Blue Static
36 * @copyright Copyright ©2002 - [#]year[#], Blue Static
37 * @version $Revision$
38 * @package ISSO
39 *
40 */
41 class Functions
42 {
43 /**
44 * Framework registry object
45 * @var object
46 */
47 private $registry = null;
48
49 /**
50 * The path that is used to set cookies
51 * @var string
52 */
53 private $cookiepath = '/';
54
55 /**
56 * The domain used for cookie setting
57 * @var string
58 */
59 private $cookiedom = '';
60
61 /**
62 * The time it takes for a cookie to expire
63 * @var integer
64 */
65 private $cookieexp = 900;
66
67 /**
68 * State of the current background colour during alternation
69 * @var string
70 */
71 public $bgcolour = '';
72
73 /**
74 * Fields array that is used in this module
75 * @var array
76 */
77 private $fields = array(
78 'cookiepath' => array(REQ_YES, null, true),
79 'cookiedom' => array(REQ_YES, null, true),
80 'cookieexp' => array(REQ_YES, null, true)
81 );
82
83 // ###################################################################
84 /**
85 * Constructor
86 */
87 public function __construct(&$registry)
88 {
89 $this->registry =& $registry;
90 }
91
92 // ###################################################################
93 /**
94 * Sets an ISSO field
95 *
96 * @param string Field name
97 * @param mixed Value of the field
98 */
99 public function set($name, $value)
100 {
101 $this->registry->do_set($name, $value, 'functions');
102 }
103
104 // ###################################################################
105 /**
106 * Gets an ISSO field
107 *
108 * @param string Field name
109 *
110 * @return mixed Value of the field
111 */
112 public function get($fieldname)
113 {
114 return $this->registry->do_get($fieldname, 'functions');
115 }
116
117 // ###################################################################
118 /**
119 * Sets a cookie with a friendly interface
120 *
121 * @param string The name of the cookie
122 * @param string Value of the cookie
123 * @param bool Is the cookie permanent?
124 */
125 public function cookie($name, $value = '', $sticky = true)
126 {
127 $this->registry->check_isso_fields(get_class($this));
128
129 // expire the cookie
130 if (!$value)
131 {
132 setcookie($name, $value, time() - (2 * $this->cookieexp), $this->cookiepath, $this->cookiedom);
133 }
134 // set the cookie
135 else
136 {
137 if ($sticky)
138 {
139 $expire = time() + 60 * 60 * 24 * 365;
140 }
141 else
142 {
143 $expire = time() + $this->cookieexp;
144 }
145
146 setcookie($name, $value, $expire, $this->cookiepath, $this->cookiedom);
147 }
148 }
149
150 // ###################################################################
151 /**
152 * Alternate between two background colours
153 *
154 * @param string First CSS class name
155 * @param string Second CSS class name
156 */
157 public function exec_swap_bg($class1 = 'alt1', $class2 = 'alt2')
158 {
159 static $count;
160
161 $this->bgcolour = ($count % 2) ? $class1 : $class2;
162 $count++;
163 }
164 }
165
166 /*=====================================================================*\
167 || ###################################################################
168 || # $HeadURL$
169 || # $Id$
170 || ###################################################################
171 \*=====================================================================*/
172 ?>