1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
/*
Snow Theme for Question2Answer Package
Copyright (C) 2014 Q2A Market <http://www.q2amarket.com>
File: inc/qam-snow-theme.php
Version: Snow 1.4
Description: Snow theme core class
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/**
* Snow theme loader class
*
* This class loads all required data for the Snow theme. This is written more
* for future use and to keep untouched <code>qa_html_theme_base</code>
*
* @package Snow
* @subpackage Loader
* @category Theme
* @since Snow 1.4
* @version 1.0
* @author Q2A Market <http://www.q2amarket.com>
* @copyright (c) 2014, Q2A Market
* @license http://www.gnu.org/copyleft/gpl.html
*/
class qam_snow_theme
{
/**
* @var array Holds the data
*/
private $data;
/**
* Snow instance
*
* @access public
* @since Snow 1.4
* @version 1.0
*
* @static $instance
*
* @uses qam_snow_theme::setup_globals() Setup require globals
* @uses qam_snow_theme::includes() Include require files
* @uses qam_snow_theme::heads() Setup <code><head></code> elements
* @uses qam_snow_theme::set_options() Setup dynamic options for Snow
* @uses qam_snow_theme::headers() Setup header elements
* @uses qam_snow_theme::footers() Setup footer elements
*
* @see qam_snow_theme()
* @return mixed all qam_snow_theme
*
* @author Q2A Market <http://www.q2amarket.com>
* @copyright (c) 2014, Q2A Market
* @license http://www.gnu.org/copyleft/gpl.html
*/
public static function instance()
{
// Store the instance locally to avoid private static replication
static $instance = null;
// Only run these methods if they haven't been run previously
if (null === $instance) {
$instance = new qam_snow_theme;
$instance->setup_globals();
$instance->includes();
// $instance->heads();
$instance->get_options();
$instance->headers();
// $instance->footers();
}
// Always return the instance
return $instance;
}
/**
* Class construct
*/
private function __construct()
{ /* Do nothing here */
}
/**
*
* @param type $key
* @return type
*/
public function __isset($key)
{
return isset($this->data[$key]);
}
/**
*
* @param type $key
* @return type
*/
public function __get($key)
{
return isset($this->data[$key]) ? $this->data[$key] : null;
}
/**
*
* @param type $key
* @param type $value
*/
public function __set($key, $value)
{
$this->data[$key] = $value;
}
/**
*
* @param type $key
*/
public function __unset($key)
{
if (isset($this->data[$key])) {
unset($this->data[$key]);
}
}
/**
*
* @param type $name
* @param type $args
* @return null
*/
public function __call($name = '', $args = array())
{
unset($name, $args);
return null;
}
/**
* Snow theme globals
*
* @access private
* @since Snow 1.4
* @version 1.0
*
* @author Q2A Market <www.q2amarket.com>
* @copyright (c) 2014, Q2A Market
* @license http://www.gnu.org/copyleft/gpl.html
*/
private function setup_globals()
{
$this->theme = qa_opt('site_theme');
$this->author = $this->qam_opt('snow_author', 'Q2A Market');
$this->author_url = $this->qam_opt('snow_author_url', 'http://www.q2amarket.com');
$this->version = $this->qam_opt('snow_version', '1.4-beta');
$this->snow_version = strtolower($this->theme . '-' . $this->version);
$this->opt_prefix = 'qam_snow_';
$this->js_dir = 'js/';
$this->css_dir = 'css/';
$this->img_url = 'images/';
$this->icon_url = $this->img_url . 'icons/';
}
/**
* Incldue require files
*
* @access private
* @since Snow 1.4
* @version 1.0
*
* @author Q2A Market <www.q2amarket.com>
* @copyright (c) 2014, Q2A Market
* @license http://www.gnu.org/copyleft/gpl.html
*/
private function includes()
{ //do nothing now
}
/**
* Get theme options for customization.
*
* @access private
* @since Snow 1.4
* @version 1.0
* @return array|mixed theme options value
*
* @author Q2A Market <http://www.q2amarket.com>
* @copyright (c) 2014, Q2A Market
* @license http://www.gnu.org/copyleft/gpl.html
*/
private function get_options()
{
$this->data['ask_search_box_color'] = $this->qam_opt('ask_search_box_color');
$this->data['welcome_widget_color'] = $this->qam_opt('welcome_widget_color');
$this->data['fixed_topbar'] = (($this->qam_opt('fixed_topbar')) ? 'fixed' : null);
$this->data['header_custom_content'] = $this->qam_opt('header_custom_content');
$this->data['footer_custom_content'] = $this->qam_opt('above_footer_custom_content');
return $this->data;
}
/**
* Get header items
*
* @access private
* @since Snow 1.4
* @version 1.0
* @return array|mixed various header items (e.g. user account, scripts)
*
* @author Q2A Market <http://www.q2amarket.com>
* @copyright (c) 2014, Q2A Market
* @license http://www.gnu.org/copyleft/gpl.html
*/
private function headers()
{
$this->data['headers'] = array(
'user_points' => $this->user_points(),
'ask_button' => $this->ask_button(),
);
return $this->data;
}
/**
* Get logged in user's points
*
* @access private
* @since Snow 1.4
* @version 1.0
* @return string|null LoggedIn user's total points, null for guest
*
* @author Q2A Market <http://www.q2amarket.com>
* @copyright (c) 2014, Q2A Market
* @license http://www.gnu.org/copyleft/gpl.html
*/
private function user_points()
{
require_once QA_INCLUDE_DIR . 'app/format.php';
if (qa_is_logged_in()) {
$userpoints = qa_get_logged_in_points();
$pointshtml = ($userpoints == 1) ? qa_lang_html_sub('main/1_point', '1', '1') : qa_html(qa_format_number($userpoints));
$points = '<DIV CLASS="qam-logged-in-points">' . $pointshtml . '</DIV>';
return $points;
}
return null;
}
/**
* Custom ask button for medium and small screen
*
* @access private
* @since Snow 1.4
* @version 1.0
* @return string Ask button html markup
*
* @author Q2A Market <http://www.q2amarket.com>
* @copyright (c) 2014, Q2A Market
* @license http://www.gnu.org/copyleft/gpl.html
*/
private function ask_button()
{
$html = '<div class="qam-ask-search-box">';
$html .= '<div class="qam-ask-mobile"><a href="' . qa_path('ask', null, qa_path_to_root()) . '" class="' . $this->qam_opt('ask_search_box_color') . '">' . qa_lang_html('main/nav_ask') . '</a></div>';
$html .= '<div class="qam-search-mobile ' . $this->qam_opt('ask_search_box_color') . '" id="qam-search-mobile"></div>';
$html .= '</div>';
return $html;
}
}
/* ---------------------------------------------------------------------------- */
// create a function to instanciate the class
if (!function_exists('qam_snow_theme')) {
/**
* Return <code>qam_snow_theme</code> class instance
*
* @access public
* @since Snow 1.4
* @version 1.0
* @return array
*
* @author Q2A Market <http://www.q2amarket.com>
* @copyright (c) 2014, Q2A Market
* @license http://www.gnu.org/copyleft/gpl.html
*/
function qam_snow_theme()
{
return qam_snow_theme::instance();
}
}
// Declare global variable
if (class_exists('qam_snow_theme')) {
$GLOBALS['qam_snow'] = qam_snow_theme();
}