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

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

version 1.0.14 - please refer to changelog for details

  • Property svn:eol-style set to native
File size: 10.1 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_mode"    => array("value" => "txt-tab-open", "quotes" => QUOTES_NONE),
53      "p_pict_tab_default" => array("value" => "desc",   "quotes" => QUOTES_NONE),
54      "p_pict_tab_anim"    => array("value" => "off",    "quotes" => QUOTES_NONE),
55
56      // Advanced Options - Root Page
57      "p_rootpage"         => array("value" => "off",    "quotes" => QUOTES_NONE),
58      "p_rootpage_desc"    => array("value" => null,     "quotes" => QUOTES_SAFE | QUOTES_LAZY),
59      "p_rootpage_src"     => array("value" => "slider", "quotes" => QUOTES_NONE),
60      "p_rootpage_id"      => array("value" => 1,        "quotes" => QUOTES_NONE),
61      "p_rootpage_mode"    => array("value" => "fade",   "quotes" => QUOTES_NONE),
62      "p_rootpage_delay"   => array("value" => 10,       "quotes" => QUOTES_NONE),
63      "p_rootpage_elastic" => array("value" => "off",    "quotes" => QUOTES_NONE),
64      "p_rootpage_navarr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
65      "p_rootpage_navctr"  => array("value" => "off",    "quotes" => QUOTES_NONE),
66
67      'p_customcss'        => array("value" => null,     "quotes" => (QUOTES_LAZY | QUOTES_SINGLE)),
68      'p_debug'            => array("value" => "off",    "quotes" => FALSE)
69    );
70  }
71
72  private function loadConfig($ver = '') {
73    global $conf;
74    $this->themeConfigMin = unserialize($conf['greydragon']);
75    $this->themeConfigMin["version"] = $ver;
76
77    $this->themeConfig = $this->validateDefault($this->themeConfigMin);
78  }
79
80  private function validateDefault($config) {
81    $theme_default_settings = $this->getDefaults();
82
83    foreach ($theme_default_settings as $key => $value):
84      if ($value["value"]):
85        if (array_key_exists($key, $config)):
86        else:
87          $config[$key] = $value["value"];
88        endif;
89      endif;
90    endforeach;
91
92    // Populate some system settings
93
94    $url_root = get_root_url();
95    $config['U_SITE_ADMIN'] = $url_root . 'admin.php?page=';
96
97    return $config;
98  }
99
100  public function initEvents() {
101    // add_event_handler('get_admin_plugin_menu_links', array(&$this, 'pluginAdminMenu') );
102  }
103
104  public function loadCSS() {
105    // parent::loadCSS();
106    // GPCCore::addUI('gpcCSS');
107  }
108
109  public function getConfig($isFull = TRUE) {
110    if ($isFull):
111      return $this->themeConfig;
112    else:
113      return $this->themeConfigMin;
114    endif;
115  }
116
117  public function setSetting($name, $value) {
118    $this->themeConfig[$name] = $value;
119  }
120
121  public function saveSettingFromPOST($name) {
122    $theme_default_settings = $this->getDefaults();
123
124    $isFound  = FALSE;
125    $isStored = FALSE;
126
127    if (array_key_exists($name, $theme_default_settings)):
128      $setting    = $theme_default_settings[$name];
129      $default    = $setting["value"];
130      $quotes     = $setting["quotes"];
131
132      if (isset($_POST[$name]) and !empty($_POST[$name])):
133        $isFound = TRUE;
134        $value   = $_POST[$name];
135
136        if ($value != $default):
137          $isStored = TRUE;
138
139          if ($quotes):
140            if (($quotes & QUOTES_LAZY) == QUOTES_LAZY):
141              $value = str_replace('\"', '"', $value);
142              $value = str_replace("\'", "'", $value);
143            endif;
144            if (($quotes & QUOTES_SINGLE) == QUOTES_SINGLE):
145              $value = str_replace("'", '"', $value);
146            endif;
147            if (($quotes & QUOTES_SAFE) == QUOTES_SAFE):
148              $value = str_replace("'", '&apos;', $value);
149              $value = str_replace('"', '&quot;', $value);
150            endif;
151
152            $value = str_replace("\'", "';", $value);
153          endif;
154        endif;
155      endif;
156
157      if ($isFound):
158        $this->themeConfig[$name] = $value;
159        if ($isStored):
160          $this->themeConfigMin[$name] = $value;
161        endif;
162      endif;
163    endif;
164
165    // Config cleanup
166    if ((!$isStored) && (array_key_exists($name, $this->themeConfigMin))):
167      unset($this->themeConfigMin[$name]);
168    endif;
169    if ((!$isFound) && (array_key_exists($name, $this->themeConfig))):
170      unset($this->themeConfig[$name]);
171    endif;   
172   
173  }
174
175  public function saveSettingsFromPost(){
176    $theme_default_settings = $this->getDefaults();
177
178    if ((isset($_POST["p_reset"])) && ($_POST["p_reset"] == "on")):
179      // Reset theme settings
180      conf_update_param('greydragon', pwg_db_real_escape_string(serialize(array())));
181      load_conf_from_db();
182      $this->loadConfig();
183    else:
184      foreach ($theme_default_settings as $key => $value):
185        $this->saveSettingFromPOST($key);
186      endforeach;
187    endif;
188  }
189
190  public function hasSettingFromPost($name) {
191    return (isset($_POST[$name]));
192  } 
193
194  public function getSettingFromPost($name) {
195    if (isset($_POST[$name])):
196      return $_POST[$name];
197    else:
198      return FALSE;
199    endif;
200  }
201
202  public function hasOption($name, $isGlobal = FALSE) {
203    global $conf;
204
205    if ($isGlobal):
206      return (array_key_exists($name, $conf) && isset($conf[$name]) && ($conf[$name]));
207    else:
208      return (array_key_exists($name, $this->themeConfig));
209    endif;
210  }
211
212  public function getOption($name, $isGlobal = FALSE) {
213    global $conf;
214
215    if ($isGlobal):
216      if (array_key_exists($name, $conf)):
217        return $conf[$name];
218      else:
219        return FALSE;
220      endif;
221    else:
222      if (array_key_exists($name, $this->themeConfig)):
223        return $this->themeConfig[$name];
224      else:
225        return FALSE;
226      endif;
227    endif;
228  }
229
230  public function prepareHomePage($prefix, $pageId) {
231
232    $r_desc    = $this->getOption('p_rootpage_desc');
233    $r_scr     = $this->getOption('p_rootpage_src');
234    $r_mode    = $this->getOption('p_rootpage_mode');
235    $r_id      = $this->getOption('p_rootpage_id');
236    $r_delay   = $this->getOption('p_rootpage_delay');
237    $r_elastic = ($this->getOption('p_rootpage_elastic') == "on")? 'true' : 'false';
238    $r_navarr  = ($this->getOption('p_rootpage_navarr') == "on")? 'true' : 'false';
239    $r_navctr  = ($this->getOption('p_rootpage_navctr') == "on")? 'true' : 'false';
240
241    $content = '<!-- GD Auto generated. Do not modify -->
242<style type="text/css">
243  .titrePage { display: none; }
244  .content { max-width: 95%; margin: 1em 0 1em 4% !important; }
245</style>
246<div id="gdHomeContent">';
247    if ($r_desc):
248      $content .= '
249  <div class="gdHomeQuote">' . $r_desc . '</div>';
250    endif;
251    $content .= '
252  <div class="gdHomePagePhoto">
253    <a href="index.php?/categories">
254      <div style="width: 800px; min-height: 500px; display: inline-block; overflow: hidden;">
255';
256
257      if ($r_scr == "photo"):
258        $content .= '[photo id=' . $r_id . ' size=M html=yes link=no]';
259      elseif ($r_scr == "random"):
260        $content .= '[random album=' . $r_id . ' size=M html=yes link=no]';
261      else:
262        $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 . ']';
263      endif;
264      $content .= '     
265      </div>
266    </a>
267  </div>
268</div>';
269
270    // <div class="gdHomeLinks">
271    //   <a href="index.php?/categories">Gallery</a>&nbsp;&#9679;&nbsp;<a href="index.php?/contact">Contact</a>
272    //  </div>
273
274    $query = 'UPDATE ' . $prefix . 'additionalpages '
275           . 'SET content = "' . pwg_db_real_escape_string($content) . '" '
276           . ' , standalone = FALSE '
277           . 'WHERE (id = ' . $pageId . ') AND (content <> "' . pwg_db_real_escape_string($content) . '");';
278    pwg_query($query);
279    return (pwg_db_changes() > 0);
280  }
281
282  public function getHeader() {
283    $content = "";
284    if ($this->hasOption('p_logo_path')):
285      $content .= '<a title="Home" id="g-logo" href="' . PHPWG_ROOT_PATH . '"><img alt="Home" src="' . PHPWG_ROOT_PATH . $this->getOption('p_logo_path') . '"></a>';
286    endif;
287    if ($this->hasOption('p_header')):
288      $content .= '<a title="Home" id="g-header-text" href="' . PHPWG_ROOT_PATH . '">' . $this->getOption('p_header') . '</a>';
289    elseif ($this->hasOption('page_banner', TRUE)):
290      $content .= '<a title="Home" id="g-header-text" href="' . PHPWG_ROOT_PATH . '">' . $this->getOption('page_banner', TRUE) . '</a>';
291    endif;                                                                                                             
292
293    return $content;
294  }
295
296}
297
298?>
Note: See TracBrowser for help on using the repository browser.