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

Last change on this file since 30210 was 30210, checked in by SergeD, 10 years ago

version 1.0.13
+ New colorpack - GreyDragon
+ ADMIN: Added support for horizontal menu - "Static Menu - Header Bottom". When used with Additional Pages Plugin, pages except Root Page would be embeded

into menu bar instead of drop down menu.

+ ADMIN: Added option "Display navigation arrows" for Root page
+ ADMIN: Added option "Display navigation controls" for Root page
+ Added support for thumb shadow space - custom CSS is required (please refer to help section in admin area). Latest gdThumb is recomended.
+ CSS: cleanup

  • Removed hardcoded height for root page slideshow to accomodate navigation controls
  • Fixed issues with Categories List overlapping when Static menu is enabled
  • In Phote page, hide overflow photo when huge size is used
  • Property svn:eol-style set to native
File size: 10.6 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5define("QUOTES_NONE",   FALSE);
6define("QUOTES_LAZY",   1);
7define("QUOTES_SINGLE", 2);
8define("QUOTES_SAFE",   4);
9
10final class greyDragonCore {
11
12  // singleton instance
13  private static $instance;
14  private static $version;
15  private $themeConfig;
16  private $themeConfigMin;
17
18  public static function Instance($ver = '') {
19    if (!self::$instance):
20      self::$instance = new self($ver);
21    endif;
22    return self::$instance; 
23  }
24
25  private function __construct($ver = ''){
26    self::loadConfig($ver);
27  }
28
29  private function getDefaults() {
30
31    return array(
32      // General Settings
33      "p_logo_path"        => array("value" => null,     "quotes" => QUOTES_NONE),
34      "p_favicon_path"     => array("value" => null,     "quotes" => QUOTES_NONE),
35      "p_apple_path"       => array("value" => null,     "quotes" => QUOTES_NONE),
36      "p_header"           => array("value" => null,     "quotes" => QUOTES_LAZY),
37      "p_footer"           => array("value" => null,     "quotes" => QUOTES_LAZY),
38      "p_colorpack"        => array("value" => null,     "quotes" => QUOTES_NONE),
39   
40      // Advanced Options - General
41      "p_main_menu"        => array("value" => "closed", "quotes" => QUOTES_NONE), // static, closed, opened, top, header-bottom, header-top, disabled
42      "p_animated_menu"    => array("value" => "off",    "quotes" => QUOTES_NONE),
43
44      "p_lowertext"        => array("value" => "off",    "quotes" => QUOTES_NONE),
45      "p_credits"          => array("value" => "off",    "quotes" => QUOTES_NONE),
46      "p_nogenerator"      => array("value" => "off",    "quotes" => QUOTES_NONE),
47      "p_hideabout"        => array("value" => "off",    "quotes" => QUOTES_NONE),
48      "p_adminemail"       => array("value" => "off",    "quotes" => QUOTES_NONE),
49      "p_nocounter"        => array("value" => "off",    "quotes" => QUOTES_NONE),
50
51      // Advanced Options - Photo Page
52      "p_pict_tab_default" => array("value" => "desc",   "quotes" => QUOTES_NONE),
53      "p_pict_tab_anim"    => array("value" => "off",    "quotes" => QUOTES_NONE),
54
55      // Advanced Options - Root Page
56      "p_rootpage"         => array("value" => "off",    "quotes" => QUOTES_NONE),
57      "p_rootpage_desc"    => array("value" => null,     "quotes" => QUOTES_SAFE | QUOTES_LAZY),
58      "p_rootpage_src"     => array("value" => "slider", "quotes" => QUOTES_NONE),
59      "p_rootpage_id"      => array("value" => 1,        "quotes" => QUOTES_NONE),
60      "p_rootpage_mode"    => array("value" => "fade",   "quotes" => QUOTES_NONE),
61      "p_rootpage_delay"   => array("value" => 10,       "quotes" => QUOTES_NONE),
62      "p_rootpage_elastic" => array("value" => "off",    "quotes" => QUOTES_NONE),
63      "p_rootpage_navarr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
64      "p_rootpage_navctr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
65
66      'p_customcss'        => array("value" => null,     "quotes" => (QUOTES_LAZY | QUOTES_SINGLE)),
67      'p_debug'            => array("value" => "off",    "quotes" => FALSE)
68    );
69  }
70
71  private function loadConfig($ver = '') {
72    global $conf;
73    $this->themeConfigMin = unserialize($conf['greydragon']);
74    $this->themeConfigMin["version"] = $ver;
75
76    $this->themeConfig = $this->validateDefault($this->themeConfigMin);
77  }
78
79  private function validateDefault($config) {
80    $theme_default_settings = $this->getDefaults();
81
82    foreach ($theme_default_settings as $key => $value):
83      if ($value["value"]):
84        if (array_key_exists($key, $config)):
85        else:
86          $config[$key] = $value["value"];
87        endif;
88      endif;
89    endforeach;
90
91    // Populate some system settings
92
93    $url_root = get_root_url();
94    $config['U_SITE_ADMIN'] = $url_root . 'admin.php?page=';
95
96    return $config;
97  }
98
99  public function initEvents() {
100    // add_event_handler('get_admin_plugin_menu_links', array(&$this, 'pluginAdminMenu') );
101  }
102
103  public function loadCSS() {
104    // parent::loadCSS();
105    // GPCCore::addUI('gpcCSS');
106  }
107
108  public function getConfig($isFull = TRUE) {
109    if ($isFull):
110      return $this->themeConfig;
111    else:
112      return $this->themeConfigMin;
113    endif;
114  }
115
116  public function setSetting($name, $value) {
117    $this->themeConfig[$name] = $value;
118  }
119
120  public function saveSettingFromPOST($name) {
121    $theme_default_settings = $this->getDefaults();
122
123    $isFound  = FALSE;
124    $isStored = FALSE;
125
126    if (array_key_exists($name, $theme_default_settings)):
127      $setting    = $theme_default_settings[$name];
128      $default    = $setting["value"];
129      $quotes     = $setting["quotes"];
130
131      if (isset($_POST[$name]) and !empty($_POST[$name])):
132        $isFound = TRUE;
133        $value   = $_POST[$name];
134
135        if ($value != $default):
136          $isStored = TRUE;
137
138          if ($quotes):
139            if (($quotes & QUOTES_LAZY) == QUOTES_LAZY):
140              $value = str_replace('\"', '"', $value);
141              $value = str_replace("\'", "'", $value);
142            endif;
143            if (($quotes & QUOTES_SINGLE) == QUOTES_SINGLE):
144              $value = str_replace("'", '"', $value);
145            endif;
146            if (($quotes & QUOTES_SAFE) == QUOTES_SAFE):
147              $value = str_replace("'", '&apos;', $value);
148              $value = str_replace('"', '&quot;', $value);
149            endif;
150
151            $value = str_replace("\'", "';", $value);
152          endif;
153        endif;
154      endif;
155
156      if ($isFound):
157        $this->themeConfig[$name] = $value;
158        if ($isStored):
159          $this->themeConfigMin[$name] = $value;
160        endif;
161      endif;
162    endif;
163
164    // Config cleanup
165    if ((!$isStored) && (array_key_exists($name, $this->themeConfigMin))):
166      unset($this->themeConfigMin[$name]);
167    endif;
168    if ((!$isFound) && (array_key_exists($name, $this->themeConfig))):
169      unset($this->themeConfig[$name]);
170    endif;   
171   
172  }
173
174  public function saveSettingsFromPost(){
175    $theme_default_settings = $this->getDefaults();
176
177    if ((isset($_POST["p_reset"])) && ($_POST["p_reset"] == "on")):
178      // Reset theme settings
179      conf_update_param('greydragon', pwg_db_real_escape_string(serialize(array())));
180      load_conf_from_db();
181      $this->loadConfig();
182    else:
183      foreach ($theme_default_settings as $key => $value):
184        $this->saveSettingFromPOST($key);
185      endforeach;
186    endif;
187  }
188
189  public function hasSettingFromPost($name) {
190    return (isset($_POST[$name]));
191  } 
192
193  public function getSettingFromPost($name) {
194    if (isset($_POST[$name])):
195      return $_POST[$name];
196    else:
197      return FALSE;
198    endif;
199  }
200
201  public function hasOption($name, $isGlobal = FALSE) {
202    global $conf;
203
204    if ($isGlobal):
205      return (array_key_exists($name, $conf) && isset($conf[$name]) && ($conf[$name]));
206    else:
207      return (array_key_exists($name, $this->themeConfig));
208    endif;
209  }
210
211  public function getOption($name, $isGlobal = FALSE) {
212    global $conf;
213
214    if ($isGlobal):
215      if (array_key_exists($name, $conf)):
216        return $conf[$name];
217      else:
218        return FALSE;
219      endif;
220    else:
221      if (array_key_exists($name, $this->themeConfig)):
222        return $this->themeConfig[$name];
223      else:
224        return FALSE;
225      endif;
226    endif;
227  }
228
229  public function prepareHomePage($prefix, $pageId) {
230
231    $r_desc    = $this->getOption('p_rootpage_desc');
232    $r_scr     = $this->getOption('p_rootpage_src');
233    $r_mode    = $this->getOption('p_rootpage_mode');
234    $r_id      = $this->getOption('p_rootpage_id');
235    $r_delay   = $this->getOption('p_rootpage_delay');
236    $r_elastic = ($this->getOption('p_rootpage_elastic') == "on")? 'true' : 'false';
237    $r_navarr  = ($this->getOption('p_rootpage_navarr') == "on")? 'true' : 'false';
238    $r_navctr  = ($this->getOption('p_rootpage_navctr') == "on")? 'true' : 'false';
239
240    $content = '<!-- GD Auto generated. Do not modify -->
241<style type="text/css">
242  .titrePage { display: none; }
243  .content { max-width: 95%; margin: 1em 0 1em 4% !important; }
244</style>
245<div id="gdHomeContent">';
246    if ($r_desc):
247      $content .= '
248  <div class="gdHomeQuote">' . $r_desc . '</div>';
249    endif;
250    $content .= '
251  <div class="gdHomePagePhoto">
252    <a href="index.php?/categories">
253      <div style="width: 800px; min-height: 500px; display: inline-block; overflow: hidden;">
254';
255
256      if ($r_scr == "photo"):
257        $content .= '[photo id=' . $r_id . ' size=M html=yes link=no]';
258      elseif ($r_scr == "random"):
259        $content .= '[random album=' . $r_id . ' size=M html=yes link=no]';
260      else:
261        $content .= '[slider album=' . $r_id . ' nb_images=10 random=yes size=M speed=' . $r_delay . ' title=no effect=' . $r_mode . ' arrows=' . $r_navarr . ' control=' . $r_navctr . ' elastic=' . $r_elastic . ']';
262      endif;
263      $content .= '     
264      </div>
265    </a>
266  </div>
267</div>';
268
269    // <div class="gdHomeLinks">
270    //   <a href="index.php?/categories">Gallery</a>&nbsp;&#9679;&nbsp;<a href="index.php?/contact">Contact</a>
271    //  </div>
272
273    $query = 'UPDATE ' . $prefix . 'additionalpages '
274           . 'SET content = "' . pwg_db_real_escape_string($content) . '" '
275           . ' , standalone = FALSE '
276           . 'WHERE (id = ' . $pageId . ') AND (content <> "' . pwg_db_real_escape_string($content) . '");';
277    pwg_query($query);
278    return (pwg_db_changes() > 0);
279  }
280
281  public function getHeader() {
282    $content = "";
283    if ($this->hasOption('p_logo_path')):
284      $content .= '<a title="Home" id="g-logo" href="' . PHPWG_ROOT_PATH . '"><img alt="Home" src="' . PHPWG_ROOT_PATH . $this->getOption('p_logo_path') . '"></a>';
285    endif;
286    if ($this->hasOption('p_header')):
287      $content .= '<a title="Home" id="g-header-text" href="' . PHPWG_ROOT_PATH . '">' . $this->getOption('p_header') . '</a>';
288    elseif ($this->hasOption('page_banner', TRUE)):
289      $content .= '<a title="Home" id="g-header-text" href="' . PHPWG_ROOT_PATH . '">' . $this->getOption('page_banner', TRUE) . '</a>';
290    endif;                                                                                                             
291
292    return $content;
293  }
294
295  public function getHead($content) {
296
297    if ($favicon_name = $this->getOption('p_favicon_path')):
298      $search = '#<link rel="shortcut icon".*?favicon.ico">#';
299      $replacement = '<link rel="shortcut icon" type="image/x-icon" href="' . PHPWG_ROOT_PATH . $favicon_name . '">';
300      $content = preg_replace($search, $replacement, $content);
301    endif;
302
303    if ($this->getOption('p_nogenerator') == "on"):
304      $search = '#<meta name="generator" .*see piwigo.org">#';
305      $replacement = '';
306      $content = preg_replace($search, $replacement, $content);
307    endif;
308
309    return $content;
310  }
311
312}
313
314?>
Note: See TracBrowser for help on using the repository browser.