source: extensions/greydragon/include/greydragon.class.php

Last change on this file was 32863, checked in by SergeD, 18 months ago

Version 1.3.8 - see changelog for details

  • Property svn:eol-style set to native
File size: 16.5 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5define('GDTHEME_VERSION', '1.3.8');
6
7define("QUOTES_NONE",   FALSE);
8define("QUOTES_LAZY",   1);
9define("QUOTES_SINGLE", 2);
10define("QUOTES_SAFE",   4);
11
12final 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_fullscreen"       => array("value" => "off",        "quotes" => QUOTES_NONE),
54      "p_main_menu"        => array("value" => "closed",     "quotes" => QUOTES_NONE), // static, closed, opened, top, header-bottom, header-top, disabled
55      "p_animated_menu"    => array("value" => "off",        "quotes" => QUOTES_NONE),
56      "p_main_menu_close"  => array("value" => "off",        "quotes" => QUOTES_NONE),
57
58      "p_lowertext"        => array("value" => "off",        "quotes" => QUOTES_NONE),
59      "p_credits"          => array("value" => "off",        "quotes" => QUOTES_NONE),
60      "p_nogenerator"      => array("value" => "off",        "quotes" => QUOTES_NONE),
61      "p_hideabout"        => array("value" => "off",        "quotes" => QUOTES_NONE),
62      "p_adminemail"       => array("value" => "off",        "quotes" => QUOTES_NONE),
63      "p_nocounter"        => array("value" => "off",        "quotes" => QUOTES_NONE),
64
65      // Advanced Options - Photo Page
66      "p_pict_tab_mode"    => array("value" => "txt-tab-open", "quotes" => QUOTES_NONE),
67      "p_pict_tab_default" => array("value" => "desc",       "quotes" => QUOTES_NONE),
68      "p_pict_tab_anim"    => array("value" => "off",        "quotes" => QUOTES_NONE),
69      "p_pict_tab_exif"    => array("value" => "on",         "quotes" => QUOTES_NONE),
70
71      // Advanced Options - Root Page
72      "p_rootpage"         => array("value" => "off",    "quotes" => QUOTES_NONE),
73      "p_rootpage_desc"    => array("value" => null,     "quotes" => QUOTES_SAFE | QUOTES_LAZY),
74      "p_rootpage_link"    => array("value" => "off",    "quotes" => QUOTES_NONE),
75      "p_rootpage_src"     => array("value" => "slider", "quotes" => QUOTES_NONE),
76      "p_rootpage_size"    => array("value" => "M",      "quotes" => QUOTES_NONE),
77      "p_rootpage_id"      => array("value" => 1,        "quotes" => QUOTES_NONE),
78      "p_rootpage_mode"    => array("value" => "fade",   "quotes" => QUOTES_NONE),
79      "p_rootpage_delay"   => array("value" => 10,       "quotes" => QUOTES_NONE),
80      "p_rootpage_elastic" => array("value" => "off",    "quotes" => QUOTES_NONE),
81      "p_rootpage_navarr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
82      "p_rootpage_navctr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
83      "p_rootpage_noclick" => array("value" => "off",    "quotes" => QUOTES_NONE),
84
85      'p_customcss'        => array("value" => null,     "quotes" => (QUOTES_LAZY | QUOTES_SINGLE)),
86      'p_debug'            => array("value" => "off",    "quotes" => FALSE)
87    );
88  }
89
90  private function loadConfig($ver = '') {
91    global $conf, $pwg_loaded_plugins;
92
93    $this->themeConfigMin = unserialize($conf['greydragon']);
94    $this->themeConfigMin["version"] = $ver;
95    $this->themeConfigMin["hasUserTags"] = isset($pwg_loaded_plugins['user_tags']);
96   
97    $this->themeConfig = $this->validateDefault($this->themeConfigMin);
98  }
99
100  private function validateDefault($config) {
101
102    // Check version, perform update if necessary
103    if (!isset($config["p_version"]) || ($this->themeConfigMin["version"] !== $config["p_version"])):
104
105      if (isset($config["p_favicon_path"])):
106        $config["p_favicon_ico"] = $config["p_favicon_path"];
107        unset($config["p_favicon_path"]);
108      endif;
109    endif;
110
111    $theme_default_settings = $this->getDefaults();
112
113    foreach ($theme_default_settings as $key => $value):
114      if (isset($value["value"])):
115        if (array_key_exists($key, $config)):
116        else:
117          $config[$key] = $value["value"];
118        endif;
119      endif;
120    endforeach;
121
122    // Populate some system settings
123    $url_root = get_root_url();
124    $config['U_SITE_ADMIN'] = $url_root . 'admin.php?page=';
125
126    return $config;
127  }
128
129  public function initEvents() {
130  }
131
132  public function loadCSS() {
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("'", '&apos;', $value);
177              $value = str_replace('"', '&quot;', $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, $remove) {
289
290    $r_desc    = $this->getOption('p_rootpage_desc');
291    $r_link    = $this->getOption('p_rootpage_link');
292    $r_noclick = $this->getOption('p_rootpage_noclick'); 
293    $r_scr     = $this->getOption('p_rootpage_src');
294    $r_size    = $this->getOption('p_rootpage_size');
295    $r_mode    = $this->getOption('p_rootpage_mode');
296    $r_id      = $this->getOption('p_rootpage_id');
297    $r_delay   = $this->getOption('p_rootpage_delay');
298    $r_elastic = ($this->getOption('p_rootpage_elastic') == "on")? 'true' : 'false';
299    $r_navarr  = ($this->getOption('p_rootpage_navarr') == "on")? 'true' : 'false';
300    $r_navctr  = ($this->getOption('p_rootpage_navctr') == "on")? 'true' : 'false';
301
302    $content = '<!-- GD Auto generated. Do not modify -->
303<style type="text/css">
304  .titrePage { display: none; }
305  .content { max-width: 100%; margin: 0 !important; }
306</style>
307<div id="gdHomeContent">';
308    if ($r_desc):
309      $content .= '
310  <div class="gdHomeQuote">' . l10n($r_desc) . '</div>';
311    endif;
312    if ($r_link):
313      $content .= '
314  <div class="gdHomeEnter"><a href="index.php?/categories">' . l10n('Click to Enter') . '</a></div>';
315    endif;
316    $content .= '
317  <div class="gdHomePagePhoto">';
318    if ($r_noclick != "on"):
319      $content .= '
320    <a href="index.php?/categories">';
321    endif;
322    $content .= '
323      <div style="width: 800px; min-height: 500px; display: inline-block; overflow: hidden;">
324';
325
326      if ($r_scr == "photo"):
327        $content .= '[photo id=' . $r_id . ' size=' . $r_size . ' html=yes link=no]';
328      elseif ($r_scr == "random"):
329        $content .= '[random album=' . $r_id . ' size=' . $r_size . ' html=yes link=no]';
330      else:
331        $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 . ']';
332      endif;
333      $content .= '     
334      </div>';
335    if ($r_noclick != "on"):
336      $content .= '     
337      </a>';
338    endif;
339    $content .= '     
340  </div>
341</div>';
342
343    if ($remove):
344      $query = 'UPDATE ' . $prefix . 'additionalpages '
345             . 'SET content = "" '
346             . 'WHERE (id = ' . $pageId . ') AND (content = "' . pwg_db_real_escape_string($content) . '");';
347      pwg_query($query);
348      return (pwg_db_changes() > 0);
349    else:
350      $query = 'UPDATE ' . $prefix . 'additionalpages '
351             . 'SET content = "' . pwg_db_real_escape_string($content) . '" '
352             . ' , standalone = FALSE '
353             . 'WHERE (id = ' . $pageId . ') AND (content <> "' . pwg_db_real_escape_string($content) . '");';
354      pwg_query($query);
355      return (pwg_db_changes() > 0);
356    endif;
357    return false;
358  }
359
360  public function getURLRoot() {
361    $root_base = get_root_url();
362    if ($root_base):
363    else:
364      $root_base = '/';
365    endif;
366    return $root_base;
367  }
368
369  public function getHeader() {
370    global $conf;
371
372    $content = "";
373    $root_base = $this->getURLRoot();
374
375    if ($this->hasOption('p_logo_path')):
376      $content .= '<a title="Home" id="g-logo" href="' . get_gallery_home_url() . '"><img alt="Home" src="' . $root_base . $this->getOption('p_logo_path') . '"></a>';
377    endif;
378    if ($this->hasOption('p_header')):
379      $p_header = $this->getOption('p_header');
380    elseif ($this->hasOption('page_banner', TRUE)):
381      $p_header = $this->getOption('page_banner', TRUE);
382    else:
383      $p_header = "";
384    endif;
385    $p_header = trim(str_replace('%gallery_title%', $conf['gallery_title'], $p_header));
386    if (strlen($p_header) > 0):
387      $content .= '<a title="Home" id="g-header-text" href="' . get_gallery_home_url() . '">' . $p_header . '</a>';
388    endif;
389
390    return $content;
391  }
392
393  public function prepareCustomCSS() {
394
395    $this->cssfile = dirname(dirname(dirname(dirname(__FILE__)))) . '/' . PWG_LOCAL_DIR . 'greydragon/custom.css';
396
397    if ($this->getOption('p_lowertext') == "on"):
398      $css  = "/* Theme dynamic settings. Do not modify */\n"
399            . "html, body, input, select, textarea, file { text-transform: lowercase; }\n\n";
400    else:
401      $css = "";
402    endif;
403    $temp = $this->getOption('p_customcss');
404    if ($temp):
405      $css .= "/* Custom CSS. Do not modify */\n" . $temp;
406    endif;
407
408    // create a local directory
409    if (!file_exists($this->dir)):
410      mkdir($this->dir, 0755);
411    endif;
412
413    if ($css):
414      $handle = fopen($this->cssfile, "w");
415      if ($handle):
416        fwrite($handle, $css);
417        fclose($handle);
418      endif;
419    else:
420      @unlink($this->cssfile);
421    endif;
422  }
423
424  public function deleteCustomCSS() {
425
426    // delete local folder
427    foreach (scandir($this->dir) as $file):
428      if ($file == '.' or $file == '..') continue;
429      unlink($this->dir . $file);
430    endforeach;
431    rmdir($this->dir);
432  }
433
434  public function getColorPackList() {
435    $themeroot = './themes/' . basename(dirname(dirname(__FILE__))) . '/';
436
437    $packlist = array();
438    $packroot = $themeroot . 'css/colorpack/';
439    foreach (scandir($packroot) as $pack_name):
440      if (file_exists($packroot . "$pack_name/styles.css")):
441        if ($pack_name[0] == "."):
442          continue;
443        endif;
444        $packlist[] = $pack_name;
445      endif;
446    endforeach;
447    return $packlist;
448  }
449
450  public function getPageTabs() {
451    // metadata array
452    // each tab represented by respected sub array
453    // sub array need to include
454    //   "id"         = unique id of the tab
455    //   "icon_class" = class to be used to render icon tabs
456    //   "title"      = tab or menu block title
457    //   "content"    = block content
458    //   "target"     = optional, rendering target - "left", "top", "right", "bottom", not supported, reserved for future use
459    //   "combine"    = combine_css or combine_js reference block
460    //
461    // prior to rendering, each element would be processed and converted into tab content in picture.tpl
462
463    $metadata = array();
464    $metadata = trigger_change('gd_get_metadata', $metadata);
465
466    $meta_icon = "";
467    $meta_text = "";
468    $meta_content = "";
469
470    foreach ($metadata as $item):
471
472      $id            = $item["id"];
473      $icon_class    = $item["icon_class"];
474      $title         = $item["title"];
475      $block_content = $item["content"];
476      $combine       = $item["combine"];
477      $no_overlay    = $item["no_overlay"];
478
479      if ($no_overlay):
480        $meta_icon .= '<li class="ico-btn btn-' . $id . '">' . $block_content . '</li>';
481      else:
482        $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>';
483      endif;
484
485      $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>';
486      if (isset($combine)):
487        $meta_content .= '{strip}' . $combine . '{strip}';
488      else:
489        $meta_content .= '<div id="tab-' . $id . '" class="image-metadata-tab">' . $block_content . '</div>';
490      endif;
491    endforeach;
492
493    return array("icon" => $meta_icon, "text" => $meta_text, "content" => $meta_content);
494  }
495}
496
497?>
Note: See TracBrowser for help on using the repository browser.