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

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

version 1.1.19 - please refer to changelog for more details

  • Property svn:eol-style set to native
File size: 11.7 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5define('GDTHEME_VERSION', '1.1.19');
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      // General Settings
39      "p_logo_path"        => array("value" => null,     "quotes" => QUOTES_NONE),
40      "p_favicon_path"     => array("value" => null,     "quotes" => QUOTES_NONE),
41      "p_apple_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" => null,     "quotes" => QUOTES_NONE),
45   
46      // Advanced Options - General
47      "p_main_menu"        => array("value" => "closed", "quotes" => QUOTES_NONE), // static, closed, opened, top, header-bottom, header-top, disabled
48      "p_animated_menu"    => array("value" => "off",    "quotes" => QUOTES_NONE),
49
50      "p_lowertext"        => array("value" => "off",    "quotes" => QUOTES_NONE),
51      "p_credits"          => array("value" => "off",    "quotes" => QUOTES_NONE),
52      "p_nogenerator"      => array("value" => "off",    "quotes" => QUOTES_NONE),
53      "p_hideabout"        => array("value" => "off",    "quotes" => QUOTES_NONE),
54      "p_adminemail"       => array("value" => "off",    "quotes" => QUOTES_NONE),
55      "p_nocounter"        => array("value" => "off",    "quotes" => QUOTES_NONE),
56
57      // Advanced Options - Photo Page
58      "p_pict_tab_mode"    => array("value" => "txt-tab-open", "quotes" => QUOTES_NONE),
59      "p_pict_tab_default" => array("value" => "desc",   "quotes" => QUOTES_NONE),
60      "p_pict_tab_anim"    => array("value" => "off",    "quotes" => QUOTES_NONE),
61      "p_pict_tab_exif"    => array("value" => "on",     "quotes" => QUOTES_NONE),
62
63      // Advanced Options - Root Page
64      "p_rootpage"         => array("value" => "off",    "quotes" => QUOTES_NONE),
65      "p_rootpage_desc"    => array("value" => null,     "quotes" => QUOTES_SAFE | QUOTES_LAZY),
66      "p_rootpage_src"     => array("value" => "slider", "quotes" => QUOTES_NONE),
67      "p_rootpage_size"    => array("value" => "M",      "quotes" => QUOTES_NONE),
68      "p_rootpage_id"      => array("value" => 1,        "quotes" => QUOTES_NONE),
69      "p_rootpage_mode"    => array("value" => "fade",   "quotes" => QUOTES_NONE),
70      "p_rootpage_delay"   => array("value" => 10,       "quotes" => QUOTES_NONE),
71      "p_rootpage_elastic" => array("value" => "off",    "quotes" => QUOTES_NONE),
72      "p_rootpage_navarr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
73      "p_rootpage_navctr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
74
75      'p_customcss'        => array("value" => null,     "quotes" => (QUOTES_LAZY | QUOTES_SINGLE)),
76      'p_debug'            => array("value" => "off",    "quotes" => FALSE)
77    );
78  }
79
80  private function loadConfig($ver = '') {
81    global $conf, $pwg_loaded_plugins;
82    $this->themeConfigMin = unserialize($conf['greydragon']);
83    $this->themeConfigMin["version"] = $ver;
84    $this->themeConfigMin["hasUserTags"] = isset($pwg_loaded_plugins['user_tags']);
85
86    $this->themeConfig = $this->validateDefault($this->themeConfigMin);
87  }
88
89  private function validateDefault($config) {
90    $theme_default_settings = $this->getDefaults();
91
92    foreach ($theme_default_settings as $key => $value):
93      if ($value["value"]):
94        if (array_key_exists($key, $config)):
95        else:
96          $config[$key] = $value["value"];
97        endif;
98      endif;
99    endforeach;
100
101    // Populate some system settings
102
103    $url_root = get_root_url();
104    $config['U_SITE_ADMIN'] = $url_root . 'admin.php?page=';
105
106    return $config;
107  }
108
109  public function initEvents() {
110    // add_event_handler('get_admin_plugin_menu_links', array(&$this, 'pluginAdminMenu') );
111  }
112
113  public function loadCSS() {
114    // parent::loadCSS();
115    // GPCCore::addUI('gpcCSS');
116  }
117
118  public function getConfig($isFull = TRUE) {
119    if ($isFull):
120      return $this->themeConfig;
121    else:
122      return $this->themeConfigMin;
123    endif;
124  }
125
126  public function setSetting($name, $value) {
127    $this->themeConfig[$name] = $value;
128  }
129
130  public function saveSettingFromPOST($name) {
131    $theme_default_settings = $this->getDefaults();
132
133    $isFound  = FALSE;
134    $isStored = FALSE;
135
136    if (array_key_exists($name, $theme_default_settings)):
137      $setting    = $theme_default_settings[$name];
138      $default    = $setting["value"];
139      $quotes     = $setting["quotes"];
140
141      if (isset($_POST[$name]) and !empty($_POST[$name])):
142        $isFound = TRUE;
143        $value   = $_POST[$name];
144
145        if ($value != $default):
146          $isStored = TRUE;
147
148          if ($quotes):
149            if (($quotes & QUOTES_LAZY) == QUOTES_LAZY):
150              $value = str_replace('\"', '"', $value);
151              $value = str_replace("\'", "'", $value);
152            endif;
153            if (($quotes & QUOTES_SINGLE) == QUOTES_SINGLE):
154              $value = str_replace("'", '"', $value);
155            endif;
156            if (($quotes & QUOTES_SAFE) == QUOTES_SAFE):
157              $value = str_replace("'", '&apos;', $value);
158              $value = str_replace('"', '&quot;', $value);
159            endif;
160
161            $value = str_replace("\'", "';", $value);
162          endif;
163        endif;
164      endif;
165
166      if ($isFound):
167        $this->themeConfig[$name] = $value;
168        if ($isStored):
169          $this->themeConfigMin[$name] = $value;
170        endif;
171      endif;
172    endif;
173
174    // Config cleanup
175    if ((!$isStored) && (array_key_exists($name, $this->themeConfigMin))):
176      unset($this->themeConfigMin[$name]);
177    endif;
178    if ((!$isFound) && (array_key_exists($name, $this->themeConfig))):
179      unset($this->themeConfig[$name]);
180    endif;   
181   
182  }
183
184  public function saveSettingsFromPost(){
185    $theme_default_settings = $this->getDefaults();
186
187    if ((isset($_POST["p_reset"])) && ($_POST["p_reset"] == "on")):
188      // Reset theme settings
189      conf_update_param('greydragon', pwg_db_real_escape_string(serialize(array())));
190      load_conf_from_db();
191      $this->loadConfig();
192    else:
193      foreach ($theme_default_settings as $key => $value):
194        $this->saveSettingFromPOST($key);
195      endforeach;
196    endif;
197  }
198
199  public function hasSettingFromPost($name) {
200    return (isset($_POST[$name]));
201  } 
202
203  public function getSettingFromPost($name) {
204    if (isset($_POST[$name])):
205      return $_POST[$name];
206    else:
207      return FALSE;
208    endif;
209  }
210
211  public function hasOption($name, $isGlobal = FALSE) {
212    global $conf;
213
214    if ($isGlobal):
215      return (array_key_exists($name, $conf) && isset($conf[$name]) && ($conf[$name]));
216    else:
217      return (array_key_exists($name, $this->themeConfig));
218    endif;
219  }
220
221  public function getOption($name, $isGlobal = FALSE) {
222    global $conf;
223
224    if ($isGlobal):
225      if (array_key_exists($name, $conf)):
226        return $conf[$name];
227      else:
228        return FALSE;
229      endif;
230    else:
231      if (array_key_exists($name, $this->themeConfig)):
232        return $this->themeConfig[$name];
233      else:
234        return FALSE;
235      endif;
236    endif;
237  }
238
239  public function prepareHomePage($prefix, $pageId) {
240
241    $r_desc    = $this->getOption('p_rootpage_desc');
242    $r_scr     = $this->getOption('p_rootpage_src');
243    $r_size    = $this->getOption('p_rootpage_size');
244    $r_mode    = $this->getOption('p_rootpage_mode');
245    $r_id      = $this->getOption('p_rootpage_id');
246    $r_delay   = $this->getOption('p_rootpage_delay');
247    $r_elastic = ($this->getOption('p_rootpage_elastic') == "on")? 'true' : 'false';
248    $r_navarr  = ($this->getOption('p_rootpage_navarr') == "on")? 'true' : 'false';
249    $r_navctr  = ($this->getOption('p_rootpage_navctr') == "on")? 'true' : 'false';
250
251    $content = '<!-- GD Auto generated. Do not modify -->
252<style type="text/css">
253  .titrePage { display: none; }
254  .content { max-width: 95%; margin: 1em 0 1em 4% !important; }
255</style>
256<div id="gdHomeContent">';
257    if ($r_desc):
258      $content .= '
259  <div class="gdHomeQuote">' . $r_desc . '</div>';
260    endif;
261    $content .= '
262  <div class="gdHomePagePhoto">
263    <a href="index.php?/categories">
264      <div style="width: 800px; min-height: 500px; display: inline-block; overflow: hidden;">
265';
266
267      if ($r_scr == "photo"):
268        $content .= '[photo id=' . $r_id . ' size=' . $r_size . ' html=yes link=no]';
269      elseif ($r_scr == "random"):
270        $content .= '[random album=' . $r_id . ' size=' . $r_size . ' html=yes link=no]';
271      else:
272        $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 . ']';
273      endif;
274      $content .= '     
275      </div>
276    </a>
277  </div>
278</div>';
279
280    // <div class="gdHomeLinks">
281    //   <a href="index.php?/categories">Gallery</a>&nbsp;&#9679;&nbsp;<a href="index.php?/contact">Contact</a>
282    //  </div>
283
284    $query = 'UPDATE ' . $prefix . 'additionalpages '
285           . 'SET content = "' . pwg_db_real_escape_string($content) . '" '
286           . ' , standalone = FALSE '
287           . 'WHERE (id = ' . $pageId . ') AND (content <> "' . pwg_db_real_escape_string($content) . '");';
288    pwg_query($query);
289    return (pwg_db_changes() > 0);
290  }
291
292  public function getHeader() {
293    $content = "";
294    $root_base = get_root_url();
295    if ($root_base):
296    else:
297      $root_base = '/';
298    endif;
299
300    if ($this->hasOption('p_logo_path')):
301      $content .= '<a title="Home" id="g-logo" href="' . $root_base . '"><img alt="Home" src="' . $root_base . $this->getOption('p_logo_path') . '"></a>';
302    endif;
303    if ($this->hasOption('p_header')):
304      $content .= '<a title="Home" id="g-header-text" href="' . $root_base . '">' . $this->getOption('p_header') . '</a>';
305    elseif ($this->hasOption('page_banner', TRUE)):
306      $content .= '<a title="Home" id="g-header-text" href="' . $root_base . '">' . $this->getOption('page_banner', TRUE) . '</a>';
307    endif;                                                                                                             
308
309    return $content;
310  }
311
312  public function prepareCustomCSS() {
313
314    $this->cssfile = dirname(dirname(dirname(dirname(__FILE__)))) . '/' . PWG_LOCAL_DIR . 'greydragon/custom.css';
315
316    if ($this->getOption('p_lowertext') == "on"):
317      $css  = "/* Theme dynamic settings. Do not modify */\n"
318            . "html, body, input, select, textarea, file { text-transform: lowercase; }\n\n";
319    else:
320      $css = "";
321    endif;
322    $temp = $this->getOption('p_customcss');
323    if ($temp):
324      $css .= "/* Custom CSS. Do not modify */\n" . $temp;
325    endif;
326
327    // create a local directory
328    if (!file_exists($this->dir)):
329      mkdir($this->dir, 0755);
330    endif;
331
332    if ($css):
333      $handle = fopen($this->cssfile, "w");
334      if ($handle):
335        fwrite($handle, $css);
336        fclose($handle);
337      endif;
338    else:
339      @unlink($this->cssfile);
340    endif;
341  }
342
343  public function deleteCustomCSS() {
344
345    // delete local folder
346    foreach (scandir($this->dir) as $file):
347      if ($file == '.' or $file == '..') continue;
348      unlink($this->dir . $file);
349    endforeach;
350    rmdir($this->dir);
351  }
352
353}
354
355?>
Note: See TracBrowser for help on using the repository browser.