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

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

version 1.0.15 - please refer to changelog for more details

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