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