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

Last change on this file since 31322 was 31232, checked in by SergeD, 9 years ago

version 1.2.26 - see changelog for details

  • Property svn:eol-style set to native
File size: 16.0 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5define('GDTHEME_VERSION', '1.2.26');
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_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_link"    => array("value" => "off",    "quotes" => QUOTES_NONE),
74      "p_rootpage_src"     => array("value" => "slider", "quotes" => QUOTES_NONE),
75      "p_rootpage_size"    => array("value" => "M",      "quotes" => QUOTES_NONE),
76      "p_rootpage_id"      => array("value" => 1,        "quotes" => QUOTES_NONE),
77      "p_rootpage_mode"    => array("value" => "fade",   "quotes" => QUOTES_NONE),
78      "p_rootpage_delay"   => array("value" => 10,       "quotes" => QUOTES_NONE),
79      "p_rootpage_elastic" => array("value" => "off",    "quotes" => QUOTES_NONE),
80      "p_rootpage_navarr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
81      "p_rootpage_navctr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
82
83      'p_customcss'        => array("value" => null,     "quotes" => (QUOTES_LAZY | QUOTES_SINGLE)),
84      'p_debug'            => array("value" => "off",    "quotes" => FALSE)
85    );
86  }
87
88  private function loadConfig($ver = '') {
89    global $conf, $pwg_loaded_plugins;
90
91    $this->themeConfigMin = unserialize($conf['greydragon']);
92    $this->themeConfigMin["version"] = $ver;
93    $this->themeConfigMin["hasUserTags"] = isset($pwg_loaded_plugins['user_tags']);
94
95    $this->themeConfig = $this->validateDefault($this->themeConfigMin);
96  }
97
98  private function validateDefault($config) {
99
100    // Check version, perform update if necessary
101    if (!isset($config["p_version"]) || ($this->themeConfigMin["version"] !== $config["p_version"])):
102
103      if (isset($config["p_favicon_path"])):
104        $config["p_favicon_ico"] = $config["p_favicon_path"];
105        unset($config["p_favicon_path"]);
106      endif;
107    endif;
108
109    $theme_default_settings = $this->getDefaults();
110
111    foreach ($theme_default_settings as $key => $value):
112      if (isset($value["value"])):
113        if (array_key_exists($key, $config)):
114        else:
115          $config[$key] = $value["value"];
116        endif;
117      endif;
118    endforeach;
119
120    // Populate some system settings
121    $url_root = get_root_url();
122    $config['U_SITE_ADMIN'] = $url_root . 'admin.php?page=';
123
124    return $config;
125  }
126
127  public function initEvents() {
128    // add_event_handler('get_admin_plugin_menu_links', array(&$this, 'pluginAdminMenu') );
129  }
130
131  public function loadCSS() {
132    // parent::loadCSS();
133    // GPCCore::addUI('gpcCSS');
134  }
135
136  public function getConfig($isFull = TRUE) {
137    if ($isFull):
138      return $this->themeConfig;
139    else:
140      $config = $this->themeConfigMin;
141      $config['p_version'] = GDTHEME_VERSION;
142      return $config;
143    endif;
144  }
145
146  public function setSetting($name, $value) {
147    $this->themeConfig[$name] = $value;
148  }
149
150  public function saveSettingFromPOST($name) {
151    $theme_default_settings = $this->getDefaults();
152
153    $isFound  = FALSE;
154    $isStored = FALSE;
155
156    if (array_key_exists($name, $theme_default_settings)):
157      $setting    = $theme_default_settings[$name];
158      $default    = $setting["value"];
159      $quotes     = $setting["quotes"];
160
161      if (isset($_POST[$name]) and !empty($_POST[$name])):
162        $isFound = TRUE;
163        $value   = $_POST[$name];
164
165        if ($value != $default):
166          $isStored = TRUE;
167
168          if ($quotes):
169            if (($quotes & QUOTES_LAZY) == QUOTES_LAZY):
170              $value = str_replace('\"', '"', $value);
171              $value = str_replace("\'", "'", $value);
172            endif;
173            if (($quotes & QUOTES_SINGLE) == QUOTES_SINGLE):
174              $value = str_replace("'", '"', $value);
175            endif;
176            if (($quotes & QUOTES_SAFE) == QUOTES_SAFE):
177              $value = str_replace("'", '&apos;', $value);
178              $value = str_replace('"', '&quot;', $value);
179            endif;
180
181            $value = str_replace("\'", "';", $value);
182          endif;
183        endif;
184      endif;
185
186      if ($isFound):
187        $this->themeConfig[$name] = $value;
188        if ($isStored):
189          $this->themeConfigMin[$name] = $value;
190        endif;
191      endif;
192    endif;
193
194    // Config cleanup
195    if ((!$isStored) && (array_key_exists($name, $this->themeConfigMin))):
196      unset($this->themeConfigMin[$name]);
197    endif;
198    if ((!$isFound) && (array_key_exists($name, $this->themeConfig))):
199      unset($this->themeConfig[$name]);
200    endif;   
201   
202  }
203
204  public function saveSettingsFromPost(){
205    $theme_default_settings = $this->getDefaults();
206
207    if ((isset($_POST["p_reset"])) && ($_POST["p_reset"] == "on")):
208      // Reset theme settings
209      $config = array();
210      conf_update_param('greydragon', pwg_db_real_escape_string(serialize($config)));
211      load_conf_from_db();
212      $this->loadConfig();
213    else:
214      foreach ($theme_default_settings as $key => $value):
215        $this->saveSettingFromPOST($key);
216      endforeach;
217    endif;
218  }
219
220  public function hasSettingFromPost($name) {
221    return (isset($_POST[$name]));
222  } 
223
224  public function getSettingFromPost($name) {
225    if (isset($_POST[$name])):
226      return $_POST[$name];
227    else:
228      return FALSE;
229    endif;
230  }
231
232  public function hasOption($name, $isGlobal = FALSE) {
233    global $conf;
234
235    if ($isGlobal):
236      return (array_key_exists($name, $conf) && isset($conf[$name]) && ($conf[$name]));
237    else:
238      return (array_key_exists($name, $this->themeConfig));
239    endif;
240  }
241
242  public function deleteOption($name, $isGlobal = FALSE) {
243    global $conf;
244
245    if ($isGlobal):
246      if (array_key_exists($name, $conf) && isset($conf[$name])):
247        unset($conf[$name]);
248      endif;
249    else:
250      if (array_key_exists($name, $this->themeConfig)):
251        unset($this->themeConfig[$name]);
252      endif;
253    endif;
254  }
255
256  public function getOption($name, $isGlobal = FALSE) {
257    global $conf;
258
259    if ($isGlobal):
260      if (array_key_exists($name, $conf)):
261        return $conf[$name];
262      else:
263        return FALSE;
264      endif;
265    else:
266      if (array_key_exists($name, $this->themeConfig)):
267        return $this->themeConfig[$name];
268      else:
269        return FALSE;
270      endif;
271    endif;
272  }
273
274  public function hasCustomFavicon() {
275    return ($this->hasOption("p_logo_path"));
276  }
277
278  public function update($old_version, $new_version) {
279    $this->prepareCustomCSS();
280  }
281
282  public function uninstall() {
283    // delete configuration
284    $this->deleteCustomCSS();
285
286    conf_delete_param('greydragon');
287  }
288
289  public function prepareHomePage($prefix, $pageId) {
290
291    $r_desc    = $this->getOption('p_rootpage_desc');
292    $r_link    = $this->getOption('p_rootpage_link');
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: 95%; margin: 1em 0 1em 4% !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    <a href="index.php?/categories">
319      <div style="width: 800px; min-height: 500px; display: inline-block; overflow: hidden;">
320';
321
322      if ($r_scr == "photo"):
323        $content .= '[photo id=' . $r_id . ' size=' . $r_size . ' html=yes link=no]';
324      elseif ($r_scr == "random"):
325        $content .= '[random album=' . $r_id . ' size=' . $r_size . ' html=yes link=no]';
326      else:
327        $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 . ']';
328      endif;
329      $content .= '     
330      </div>
331    </a>
332  </div>
333</div>';
334
335    $query = 'UPDATE ' . $prefix . 'additionalpages '
336           . 'SET content = "' . pwg_db_real_escape_string($content) . '" '
337           . ' , standalone = FALSE '
338           . 'WHERE (id = ' . $pageId . ') AND (content <> "' . pwg_db_real_escape_string($content) . '");';
339    pwg_query($query);
340    return (pwg_db_changes() > 0);
341  }
342
343  public function getURLRoot() {
344    $root_base = get_root_url();
345    if ($root_base):
346    else:
347      $root_base = '/';
348    endif;
349    return $root_base;
350  }
351
352  public function getHeader() {
353    global $conf;
354
355    $content = "";
356    $root_base = $this->getURLRoot();
357
358    if ($this->hasOption('p_logo_path')):
359      $content .= '<a title="Home" id="g-logo" href="' . get_gallery_home_url() . '"><img alt="Home" src="' . $root_base . $this->getOption('p_logo_path') . '"></a>';
360    endif;
361    if ($this->hasOption('p_header')):
362      $p_header = $this->getOption('p_header');
363    elseif ($this->hasOption('page_banner', TRUE)):
364      $p_header = $this->getOption('page_banner', TRUE);
365    else:
366      $p_header = "";
367    endif;
368    $p_header = trim(str_replace('%gallery_title%', $conf['gallery_title'], $p_header));
369    if (strlen($p_header) > 0):
370      $content .= '<a title="Home" id="g-header-text" href="' . get_gallery_home_url() . '">' . $p_header . '</a>';
371    endif;
372
373    return $content;
374  }
375
376  public function prepareCustomCSS() {
377
378    $this->cssfile = dirname(dirname(dirname(dirname(__FILE__)))) . '/' . PWG_LOCAL_DIR . 'greydragon/custom.css';
379
380    if ($this->getOption('p_lowertext') == "on"):
381      $css  = "/* Theme dynamic settings. Do not modify */\n"
382            . "html, body, input, select, textarea, file { text-transform: lowercase; }\n\n";
383    else:
384      $css = "";
385    endif;
386    $temp = $this->getOption('p_customcss');
387    if ($temp):
388      $css .= "/* Custom CSS. Do not modify */\n" . $temp;
389    endif;
390
391    // create a local directory
392    if (!file_exists($this->dir)):
393      mkdir($this->dir, 0755);
394    endif;
395
396    if ($css):
397      $handle = fopen($this->cssfile, "w");
398      if ($handle):
399        fwrite($handle, $css);
400        fclose($handle);
401      endif;
402    else:
403      @unlink($this->cssfile);
404    endif;
405  }
406
407  public function deleteCustomCSS() {
408
409    // delete local folder
410    foreach (scandir($this->dir) as $file):
411      if ($file == '.' or $file == '..') continue;
412      unlink($this->dir . $file);
413    endforeach;
414    rmdir($this->dir);
415  }
416
417  public function getColorPackList() {
418    $themeroot = './themes/' . basename(dirname(dirname(__FILE__))) . '/';
419
420    $packlist = array();
421    $packroot = $themeroot . 'css/colorpack/';
422    foreach (scandir($packroot) as $pack_name):
423      if (file_exists($packroot . "$pack_name/styles.css")):
424        if ($pack_name[0] == "."):
425          continue;
426        endif;
427        $packlist[] = $pack_name;
428      endif;
429    endforeach;
430    return $packlist;
431  }
432
433  public function getPageTabs() {
434    // metadata array
435    // each tab represented by respected sub array
436    // sub array need to include
437    //   "id"         = unique id of the tab
438    //   "icon_class" = class to be used to render icon tabs
439    //   "title"      = tab or menu block title
440    //   "content"    = block content
441    //   "target"     = optional, rendering target - "left", "top", "right", "bottom", not supported, reserved for future use
442    //   "combine"    = combine_css or combine_js reference block
443    //
444    // prior to rendering, each element would be processed and converted into tab content in picture.tpl
445
446    $metadata = array();
447    $metadata = trigger_change('gd_get_metadata', $metadata);
448
449    $meta_icon = "";
450    $meta_text = "";
451    $meta_content = "";
452
453    foreach ($metadata as $item):
454
455      $id            = $item["id"];
456      $icon_class    = $item["icon_class"];
457      $title         = $item["title"];
458      $block_content = $item["content"];
459      $combine       = $item["combine"];
460      $no_overlay    = $item["no_overlay"];
461
462      if ($no_overlay):
463        $meta_icon .= '<li class="ico-btn btn-' . $id . '">' . $block_content . '</li>';
464      else:
465        $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>';
466      endif;
467
468      $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>';
469      if (isset($combine)):
470        $meta_content .= '{strip}' . $combine . '{strip}';
471      else:
472        $meta_content .= '<div id="tab-' . $id . '" class="image-metadata-tab">' . $block_content . '</div>';
473      endif;
474    endforeach;
475
476    return array("icon" => $meta_icon, "text" => $meta_text, "content" => $meta_content);
477  }
478}
479
480?>
Note: See TracBrowser for help on using the repository browser.