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

Last change on this file since 31979 was 31979, checked in by SergeD, 5 years ago

version 1.3.1 - see changelog for details

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