1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | define('GDTHEME_VERSION', '1.2.25'); |
---|
6 | |
---|
7 | define("QUOTES_NONE", FALSE); |
---|
8 | define("QUOTES_LAZY", 1); |
---|
9 | define("QUOTES_SINGLE", 2); |
---|
10 | define("QUOTES_SAFE", 4); |
---|
11 | |
---|
12 | final class greyDragonCore { |
---|
13 | |
---|
14 | // singleton instance |
---|
15 | private static $instance; |
---|
16 | private static $version; |
---|
17 | private $themeConfig; |
---|
18 | private $themeConfigMin; |
---|
19 | private $dir; |
---|
20 | private $cssfile; |
---|
21 | |
---|
22 | public static function Instance($ver = '') { |
---|
23 | if (!self::$instance): |
---|
24 | self::$instance = new self($ver); |
---|
25 | endif; |
---|
26 | return self::$instance; |
---|
27 | } |
---|
28 | |
---|
29 | private function __construct($ver = ''){ |
---|
30 | $this->dir = PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'greydragon/'; |
---|
31 | |
---|
32 | self::loadConfig($ver); |
---|
33 | } |
---|
34 | |
---|
35 | private function getDefaults() { |
---|
36 | |
---|
37 | return array( |
---|
38 | "p_version" => array("value" => "", "quotes" => QUOTES_NONE), |
---|
39 | |
---|
40 | // General Settings |
---|
41 | "p_logo_path" => array("value" => null, "quotes" => QUOTES_NONE), |
---|
42 | "p_header" => array("value" => null, "quotes" => QUOTES_LAZY), |
---|
43 | "p_footer" => array("value" => null, "quotes" => QUOTES_LAZY), |
---|
44 | "p_colorpack" => array("value" => "greydragon", "quotes" => QUOTES_NONE), |
---|
45 | |
---|
46 | "p_favicon_ico" => array("value" => null, "quotes" => QUOTES_NONE), |
---|
47 | "p_favicon_png" => array("value" => "", "quotes" => QUOTES_NONE), |
---|
48 | "p_favicon_gif" => array("value" => "", "quotes" => QUOTES_NONE), |
---|
49 | "p_favicon_apple" => array("value" => "", "quotes" => QUOTES_NONE), |
---|
50 | "p_favicon_noshine" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
51 | |
---|
52 | // Advanced Options - General |
---|
53 | "p_main_menu" => array("value" => "closed", "quotes" => QUOTES_NONE), // static, closed, opened, top, header-bottom, header-top, disabled |
---|
54 | "p_animated_menu" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
55 | "p_main_menu_close" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
56 | |
---|
57 | "p_lowertext" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
58 | "p_credits" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
59 | "p_nogenerator" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
60 | "p_hideabout" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
61 | "p_adminemail" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
62 | "p_nocounter" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
63 | |
---|
64 | // Advanced Options - Photo Page |
---|
65 | "p_pict_tab_mode" => array("value" => "txt-tab-open", "quotes" => QUOTES_NONE), |
---|
66 | "p_pict_tab_default" => array("value" => "desc", "quotes" => QUOTES_NONE), |
---|
67 | "p_pict_tab_anim" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
68 | "p_pict_tab_exif" => array("value" => "on", "quotes" => QUOTES_NONE), |
---|
69 | |
---|
70 | // Advanced Options - Root Page |
---|
71 | "p_rootpage" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
72 | "p_rootpage_desc" => array("value" => null, "quotes" => QUOTES_SAFE | QUOTES_LAZY), |
---|
73 | "p_rootpage_src" => array("value" => "slider", "quotes" => QUOTES_NONE), |
---|
74 | "p_rootpage_size" => array("value" => "M", "quotes" => QUOTES_NONE), |
---|
75 | "p_rootpage_id" => array("value" => 1, "quotes" => QUOTES_NONE), |
---|
76 | "p_rootpage_mode" => array("value" => "fade", "quotes" => QUOTES_NONE), |
---|
77 | "p_rootpage_delay" => array("value" => 10, "quotes" => QUOTES_NONE), |
---|
78 | "p_rootpage_elastic" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
79 | "p_rootpage_navarr" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
80 | "p_rootpage_navctr" => array("value" => "off", "quotes" => QUOTES_NONE), |
---|
81 | |
---|
82 | 'p_customcss' => array("value" => null, "quotes" => (QUOTES_LAZY | QUOTES_SINGLE)), |
---|
83 | 'p_debug' => array("value" => "off", "quotes" => FALSE) |
---|
84 | ); |
---|
85 | } |
---|
86 | |
---|
87 | private function loadConfig($ver = '') { |
---|
88 | global $conf, $pwg_loaded_plugins; |
---|
89 | |
---|
90 | $this->themeConfigMin = unserialize($conf['greydragon']); |
---|
91 | $this->themeConfigMin["version"] = $ver; |
---|
92 | $this->themeConfigMin["hasUserTags"] = isset($pwg_loaded_plugins['user_tags']); |
---|
93 | |
---|
94 | $this->themeConfig = $this->validateDefault($this->themeConfigMin); |
---|
95 | } |
---|
96 | |
---|
97 | private function validateDefault($config) { |
---|
98 | |
---|
99 | // Check version, perform update if necessary |
---|
100 | if (!isset($config["p_version"]) || ($this->themeConfigMin["version"] !== $config["p_version"])): |
---|
101 | |
---|
102 | if (isset($config["p_favicon_path"])): |
---|
103 | $config["p_favicon_ico"] = $config["p_favicon_path"]; |
---|
104 | unset($config["p_favicon_path"]); |
---|
105 | endif; |
---|
106 | endif; |
---|
107 | |
---|
108 | $theme_default_settings = $this->getDefaults(); |
---|
109 | |
---|
110 | foreach ($theme_default_settings as $key => $value): |
---|
111 | if (isset($value["value"])): |
---|
112 | if (array_key_exists($key, $config)): |
---|
113 | else: |
---|
114 | $config[$key] = $value["value"]; |
---|
115 | endif; |
---|
116 | endif; |
---|
117 | endforeach; |
---|
118 | |
---|
119 | // Populate some system settings |
---|
120 | $url_root = get_root_url(); |
---|
121 | $config['U_SITE_ADMIN'] = $url_root . 'admin.php?page='; |
---|
122 | |
---|
123 | return $config; |
---|
124 | } |
---|
125 | |
---|
126 | public function initEvents() { |
---|
127 | // add_event_handler('get_admin_plugin_menu_links', array(&$this, 'pluginAdminMenu') ); |
---|
128 | } |
---|
129 | |
---|
130 | public function loadCSS() { |
---|
131 | // parent::loadCSS(); |
---|
132 | // GPCCore::addUI('gpcCSS'); |
---|
133 | } |
---|
134 | |
---|
135 | public function getConfig($isFull = TRUE) { |
---|
136 | if ($isFull): |
---|
137 | return $this->themeConfig; |
---|
138 | else: |
---|
139 | $config = $this->themeConfigMin; |
---|
140 | $config['p_version'] = GDTHEME_VERSION; |
---|
141 | return $config; |
---|
142 | endif; |
---|
143 | } |
---|
144 | |
---|
145 | public function setSetting($name, $value) { |
---|
146 | $this->themeConfig[$name] = $value; |
---|
147 | } |
---|
148 | |
---|
149 | public function saveSettingFromPOST($name) { |
---|
150 | $theme_default_settings = $this->getDefaults(); |
---|
151 | |
---|
152 | $isFound = FALSE; |
---|
153 | $isStored = FALSE; |
---|
154 | |
---|
155 | if (array_key_exists($name, $theme_default_settings)): |
---|
156 | $setting = $theme_default_settings[$name]; |
---|
157 | $default = $setting["value"]; |
---|
158 | $quotes = $setting["quotes"]; |
---|
159 | |
---|
160 | if (isset($_POST[$name]) and !empty($_POST[$name])): |
---|
161 | $isFound = TRUE; |
---|
162 | $value = $_POST[$name]; |
---|
163 | |
---|
164 | if ($value != $default): |
---|
165 | $isStored = TRUE; |
---|
166 | |
---|
167 | if ($quotes): |
---|
168 | if (($quotes & QUOTES_LAZY) == QUOTES_LAZY): |
---|
169 | $value = str_replace('\"', '"', $value); |
---|
170 | $value = str_replace("\'", "'", $value); |
---|
171 | endif; |
---|
172 | if (($quotes & QUOTES_SINGLE) == QUOTES_SINGLE): |
---|
173 | $value = str_replace("'", '"', $value); |
---|
174 | endif; |
---|
175 | if (($quotes & QUOTES_SAFE) == QUOTES_SAFE): |
---|
176 | $value = str_replace("'", ''', $value); |
---|
177 | $value = str_replace('"', '"', $value); |
---|
178 | endif; |
---|
179 | |
---|
180 | $value = str_replace("\'", "';", $value); |
---|
181 | endif; |
---|
182 | endif; |
---|
183 | endif; |
---|
184 | |
---|
185 | if ($isFound): |
---|
186 | $this->themeConfig[$name] = $value; |
---|
187 | if ($isStored): |
---|
188 | $this->themeConfigMin[$name] = $value; |
---|
189 | endif; |
---|
190 | endif; |
---|
191 | endif; |
---|
192 | |
---|
193 | // Config cleanup |
---|
194 | if ((!$isStored) && (array_key_exists($name, $this->themeConfigMin))): |
---|
195 | unset($this->themeConfigMin[$name]); |
---|
196 | endif; |
---|
197 | if ((!$isFound) && (array_key_exists($name, $this->themeConfig))): |
---|
198 | unset($this->themeConfig[$name]); |
---|
199 | endif; |
---|
200 | |
---|
201 | } |
---|
202 | |
---|
203 | public function saveSettingsFromPost(){ |
---|
204 | $theme_default_settings = $this->getDefaults(); |
---|
205 | |
---|
206 | if ((isset($_POST["p_reset"])) && ($_POST["p_reset"] == "on")): |
---|
207 | // Reset theme settings |
---|
208 | $config = array(); |
---|
209 | conf_update_param('greydragon', pwg_db_real_escape_string(serialize($config))); |
---|
210 | load_conf_from_db(); |
---|
211 | $this->loadConfig(); |
---|
212 | else: |
---|
213 | foreach ($theme_default_settings as $key => $value): |
---|
214 | $this->saveSettingFromPOST($key); |
---|
215 | endforeach; |
---|
216 | endif; |
---|
217 | } |
---|
218 | |
---|
219 | public function hasSettingFromPost($name) { |
---|
220 | return (isset($_POST[$name])); |
---|
221 | } |
---|
222 | |
---|
223 | public function getSettingFromPost($name) { |
---|
224 | if (isset($_POST[$name])): |
---|
225 | return $_POST[$name]; |
---|
226 | else: |
---|
227 | return FALSE; |
---|
228 | endif; |
---|
229 | } |
---|
230 | |
---|
231 | public function hasOption($name, $isGlobal = FALSE) { |
---|
232 | global $conf; |
---|
233 | |
---|
234 | if ($isGlobal): |
---|
235 | return (array_key_exists($name, $conf) && isset($conf[$name]) && ($conf[$name])); |
---|
236 | else: |
---|
237 | return (array_key_exists($name, $this->themeConfig)); |
---|
238 | endif; |
---|
239 | } |
---|
240 | |
---|
241 | public function deleteOption($name, $isGlobal = FALSE) { |
---|
242 | global $conf; |
---|
243 | |
---|
244 | if ($isGlobal): |
---|
245 | if (array_key_exists($name, $conf) && isset($conf[$name])): |
---|
246 | unset($conf[$name]); |
---|
247 | endif; |
---|
248 | else: |
---|
249 | if (array_key_exists($name, $this->themeConfig)): |
---|
250 | unset($this->themeConfig[$name]); |
---|
251 | endif; |
---|
252 | endif; |
---|
253 | } |
---|
254 | |
---|
255 | public function getOption($name, $isGlobal = FALSE) { |
---|
256 | global $conf; |
---|
257 | |
---|
258 | if ($isGlobal): |
---|
259 | if (array_key_exists($name, $conf)): |
---|
260 | return $conf[$name]; |
---|
261 | else: |
---|
262 | return FALSE; |
---|
263 | endif; |
---|
264 | else: |
---|
265 | if (array_key_exists($name, $this->themeConfig)): |
---|
266 | return $this->themeConfig[$name]; |
---|
267 | else: |
---|
268 | return FALSE; |
---|
269 | endif; |
---|
270 | endif; |
---|
271 | } |
---|
272 | |
---|
273 | public function hasCustomFavicon() { |
---|
274 | return ($this->hasOption("p_logo_path")); |
---|
275 | } |
---|
276 | |
---|
277 | public function update($old_version, $new_version) { |
---|
278 | $this->prepareCustomCSS(); |
---|
279 | } |
---|
280 | |
---|
281 | public function uninstall() { |
---|
282 | // delete configuration |
---|
283 | $this->deleteCustomCSS(); |
---|
284 | |
---|
285 | conf_delete_param('greydragon'); |
---|
286 | } |
---|
287 | |
---|
288 | public function prepareHomePage($prefix, $pageId) { |
---|
289 | |
---|
290 | $r_desc = $this->getOption('p_rootpage_desc'); |
---|
291 | $r_scr = $this->getOption('p_rootpage_src'); |
---|
292 | $r_size = $this->getOption('p_rootpage_size'); |
---|
293 | $r_mode = $this->getOption('p_rootpage_mode'); |
---|
294 | $r_id = $this->getOption('p_rootpage_id'); |
---|
295 | $r_delay = $this->getOption('p_rootpage_delay'); |
---|
296 | $r_elastic = ($this->getOption('p_rootpage_elastic') == "on")? 'true' : 'false'; |
---|
297 | $r_navarr = ($this->getOption('p_rootpage_navarr') == "on")? 'true' : 'false'; |
---|
298 | $r_navctr = ($this->getOption('p_rootpage_navctr') == "on")? 'true' : 'false'; |
---|
299 | |
---|
300 | $content = '<!-- GD Auto generated. Do not modify --> |
---|
301 | <style type="text/css"> |
---|
302 | .titrePage { display: none; } |
---|
303 | .content { max-width: 95%; margin: 1em 0 1em 4% !important; } |
---|
304 | </style> |
---|
305 | <div id="gdHomeContent">'; |
---|
306 | if ($r_desc): |
---|
307 | $content .= ' |
---|
308 | <div class="gdHomeQuote">' . $r_desc . '</div>'; |
---|
309 | endif; |
---|
310 | $content .= ' |
---|
311 | <div class="gdHomePagePhoto"> |
---|
312 | <a href="index.php?/categories"> |
---|
313 | <div style="width: 800px; min-height: 500px; display: inline-block; overflow: hidden;"> |
---|
314 | '; |
---|
315 | |
---|
316 | if ($r_scr == "photo"): |
---|
317 | $content .= '[photo id=' . $r_id . ' size=' . $r_size . ' html=yes link=no]'; |
---|
318 | elseif ($r_scr == "random"): |
---|
319 | $content .= '[random album=' . $r_id . ' size=' . $r_size . ' html=yes link=no]'; |
---|
320 | else: |
---|
321 | $content .= '[slider album=' . $r_id . ' nb_images=10 random=yes size=' . $r_size . ' speed=' . $r_delay . ' title=no effect=' . $r_mode . ' arrows=' . $r_navarr . ' control=' . $r_navctr . ' elastic=' . $r_elastic . ']'; |
---|
322 | endif; |
---|
323 | $content .= ' |
---|
324 | </div> |
---|
325 | </a> |
---|
326 | </div> |
---|
327 | </div>'; |
---|
328 | |
---|
329 | $query = 'UPDATE ' . $prefix . 'additionalpages ' |
---|
330 | . 'SET content = "' . pwg_db_real_escape_string($content) . '" ' |
---|
331 | . ' , standalone = FALSE ' |
---|
332 | . 'WHERE (id = ' . $pageId . ') AND (content <> "' . pwg_db_real_escape_string($content) . '");'; |
---|
333 | pwg_query($query); |
---|
334 | return (pwg_db_changes() > 0); |
---|
335 | } |
---|
336 | |
---|
337 | public function getURLRoot() { |
---|
338 | $root_base = get_root_url(); |
---|
339 | if ($root_base): |
---|
340 | else: |
---|
341 | $root_base = '/'; |
---|
342 | endif; |
---|
343 | return $root_base; |
---|
344 | } |
---|
345 | |
---|
346 | public function getHeader() { |
---|
347 | global $conf; |
---|
348 | |
---|
349 | $content = ""; |
---|
350 | $root_base = $this->getURLRoot(); |
---|
351 | |
---|
352 | if ($this->hasOption('p_logo_path')): |
---|
353 | $content .= '<a title="Home" id="g-logo" href="' . get_gallery_home_url() . '"><img alt="Home" src="' . $root_base . $this->getOption('p_logo_path') . '"></a>'; |
---|
354 | endif; |
---|
355 | if ($this->hasOption('p_header')): |
---|
356 | $p_header = $this->getOption('p_header'); |
---|
357 | elseif ($this->hasOption('page_banner', TRUE)): |
---|
358 | $p_header = $this->getOption('page_banner', TRUE); |
---|
359 | else: |
---|
360 | $p_header = ""; |
---|
361 | endif; |
---|
362 | $p_header = trim(str_replace('%gallery_title%', $conf['gallery_title'], $p_header)); |
---|
363 | if (strlen($p_header) > 0): |
---|
364 | $content .= '<a title="Home" id="g-header-text" href="' . get_gallery_home_url() . '">' . $p_header . '</a>'; |
---|
365 | endif; |
---|
366 | |
---|
367 | return $content; |
---|
368 | } |
---|
369 | |
---|
370 | public function prepareCustomCSS() { |
---|
371 | |
---|
372 | $this->cssfile = dirname(dirname(dirname(dirname(__FILE__)))) . '/' . PWG_LOCAL_DIR . 'greydragon/custom.css'; |
---|
373 | |
---|
374 | if ($this->getOption('p_lowertext') == "on"): |
---|
375 | $css = "/* Theme dynamic settings. Do not modify */\n" |
---|
376 | . "html, body, input, select, textarea, file { text-transform: lowercase; }\n\n"; |
---|
377 | else: |
---|
378 | $css = ""; |
---|
379 | endif; |
---|
380 | $temp = $this->getOption('p_customcss'); |
---|
381 | if ($temp): |
---|
382 | $css .= "/* Custom CSS. Do not modify */\n" . $temp; |
---|
383 | endif; |
---|
384 | |
---|
385 | // create a local directory |
---|
386 | if (!file_exists($this->dir)): |
---|
387 | mkdir($this->dir, 0755); |
---|
388 | endif; |
---|
389 | |
---|
390 | if ($css): |
---|
391 | $handle = fopen($this->cssfile, "w"); |
---|
392 | if ($handle): |
---|
393 | fwrite($handle, $css); |
---|
394 | fclose($handle); |
---|
395 | endif; |
---|
396 | else: |
---|
397 | @unlink($this->cssfile); |
---|
398 | endif; |
---|
399 | } |
---|
400 | |
---|
401 | public function deleteCustomCSS() { |
---|
402 | |
---|
403 | // delete local folder |
---|
404 | foreach (scandir($this->dir) as $file): |
---|
405 | if ($file == '.' or $file == '..') continue; |
---|
406 | unlink($this->dir . $file); |
---|
407 | endforeach; |
---|
408 | rmdir($this->dir); |
---|
409 | } |
---|
410 | |
---|
411 | public function getColorPackList() { |
---|
412 | $themeroot = './themes/' . basename(dirname(dirname(__FILE__))) . '/'; |
---|
413 | |
---|
414 | $packlist = array(); |
---|
415 | $packroot = $themeroot . 'css/colorpack/'; |
---|
416 | foreach (scandir($packroot) as $pack_name): |
---|
417 | if (file_exists($packroot . "$pack_name/styles.css")): |
---|
418 | if ($pack_name[0] == "."): |
---|
419 | continue; |
---|
420 | endif; |
---|
421 | $packlist[] = $pack_name; |
---|
422 | endif; |
---|
423 | endforeach; |
---|
424 | return $packlist; |
---|
425 | } |
---|
426 | |
---|
427 | public function getPageTabs() { |
---|
428 | // metadata array |
---|
429 | // each tab represented by respected sub array |
---|
430 | // sub array need to include |
---|
431 | // "id" = unique id of the tab |
---|
432 | // "icon_class" = class to be used to render icon tabs |
---|
433 | // "title" = tab or menu block title |
---|
434 | // "content" = block content |
---|
435 | // "target" = optional, rendering target - "left", "top", "right", "bottom", not supported, reserved for future use |
---|
436 | // "combine" = combine_css or combine_js reference block |
---|
437 | // |
---|
438 | // prior to rendering, each element would be processed and converted into tab content in picture.tpl |
---|
439 | |
---|
440 | $metadata = array(); |
---|
441 | $metadata = trigger_change('gd_get_metadata', $metadata); |
---|
442 | |
---|
443 | $meta_icon = ""; |
---|
444 | $meta_text = ""; |
---|
445 | $meta_content = ""; |
---|
446 | |
---|
447 | foreach ($metadata as $item): |
---|
448 | |
---|
449 | $id = $item["id"]; |
---|
450 | $icon_class = $item["icon_class"]; |
---|
451 | $title = $item["title"]; |
---|
452 | $block_content = $item["content"]; |
---|
453 | $combine = $item["combine"]; |
---|
454 | $no_overlay = $item["no_overlay"]; |
---|
455 | |
---|
456 | if ($no_overlay): |
---|
457 | $meta_icon .= '<li class="ico-btn btn-' . $id . '">' . $block_content . '</li>'; |
---|
458 | else: |
---|
459 | $meta_icon .= '<li class="meta-' . $id . '{if $ico_mode=="on"} ' . $icon_class . '{/if}{if $def_tab == "' . $id . '"} active{/if}"{if $ico_mode=="on"} title="{"' . $title . '"|@translate}"{/if}>{if $ico_mode=="off"}' . $title . '{/if}</li>'; |
---|
460 | endif; |
---|
461 | |
---|
462 | $meta_text .= '<li class="{if $ico_mode=="on"}' . $icon_class . '{/if}{if $def_tab == "' . $id . '"} active{/if}" rel="tab-' . $id . '"{if $ico_mode=="on"} title="{"' . $title . '"|@translate}"{/if}>{if $ico_mode=="off"}' . $title . '{/if}</li>'; |
---|
463 | if (isset($combine)): |
---|
464 | $meta_content .= '{strip}' . $combine . '{strip}'; |
---|
465 | else: |
---|
466 | $meta_content .= '<div id="tab-' . $id . '" class="image-metadata-tab">' . $block_content . '</div>'; |
---|
467 | endif; |
---|
468 | endforeach; |
---|
469 | |
---|
470 | return array("icon" => $meta_icon, "text" => $meta_text, "content" => $meta_content); |
---|
471 | } |
---|
472 | } |
---|
473 | |
---|
474 | ?> |
---|