Quick Search:

View

Revision:

Diff

Diff from 1672 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/trunk/oscommerce/includes/classes/modules.php

Annotated File View

hpdl
308
1 <?php
2 /*
3   $Id: $
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
1672
8   Copyright (c) 2007 osCommerce
hpdl
308
9
hpdl
1497
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
hpdl
308
13 */
14
hpdl
333
15   class osC_Modules {
16     var $_modules,
hpdl
313
17         $_code,
hpdl
308
18         $_title,
19         $_title_link,
hpdl
313
20         $_content,
21         $_author_name,
22         $_author_www,
hpdl
331
23         $_keys,
hpdl
333
24         $_group;
hpdl
308
25
hpdl
1672
26     function __construct($group) {
hpdl
317
27       global $osC_Database, $osC_Template, $osC_Cache;
hpdl
313
28
hpdl
333
29       $this->_group = $group;
30
hpdl
352
31       if ($osC_Cache->read('templates_' . $this->_group . '_layout-' . $osC_Template->getCode() . '-' . $osC_Template->getGroup() . '-' . $osC_Template->getPageContentsFilename())) {
hpdl
317
32         $data = $osC_Cache->getCache();
33       } else {
34         $data = array();
hpdl
313
35
hpdl
331
36         $Qspecific = $osC_Database->query('select b2p.boxes_group, b.code from :table_templates_boxes_to_pages b2p, :table_templates_boxes b, :table_templates t where b2p.templates_id = :templates_id and b2p.page_specific = 1 and b2p.content_page in (:content_page) and b2p.templates_boxes_id = b.id and b.modules_group = :modules_group and b2p.templates_id = t.id order by b2p.boxes_group, b2p.sort_order');
hpdl
317
37         $Qspecific->bindTable(':table_templates_boxes_to_pages', TABLE_TEMPLATES_BOXES_TO_PAGES);
38         $Qspecific->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
39         $Qspecific->bindTable(':table_templates', TABLE_TEMPLATES);
hpdl
351
40         $Qspecific->bindInt(':templates_id', $osC_Template->getID());
hpdl
320
41         $Qspecific->bindRaw(':content_page', '"*", "' . $osC_Template->getGroup() . '/*", "' . $osC_Template->getGroup() . '/' . substr($osC_Template->getPageContentsFilename(), 0, strrpos($osC_Template->getPageContentsFilename(), '.')) . '"');
hpdl
333
42         $Qspecific->bindValue(':modules_group', $this->_group);
hpdl
317
43         $Qspecific->execute();
44
45         if ($Qspecific->numberOfRows()) {
46           while ($Qspecific->next()) {
47             $data[$Qspecific->value('boxes_group')][] = $Qspecific->value('code');
48           }
49         } else {
hpdl
333
50           $_data = array();
hpdl
317
51
hpdl
333
52           $Qmodules = $osC_Database->query('select b2p.boxes_group, b2p.content_page, b.code from :table_templates_boxes_to_pages b2p, :table_templates_boxes b, :table_templates t where b2p.templates_id = :templates_id and b2p.content_page in (:content_page) and b2p.templates_boxes_id = b.id and b.modules_group = :modules_group and b2p.templates_id = t.id order by b2p.boxes_group, b2p.sort_order');
53           $Qmodules->bindTable(':table_templates_boxes_to_pages', TABLE_TEMPLATES_BOXES_TO_PAGES);
54           $Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
55           $Qmodules->bindTable(':table_templates', TABLE_TEMPLATES);
hpdl
351
56           $Qmodules->bindInt(':templates_id', $osC_Template->getID());
hpdl
333
57           $Qmodules->bindRaw(':content_page', '"*", "' . $osC_Template->getGroup() . '/*", "' . $osC_Template->getGroup() . '/' . substr($osC_Template->getPageContentsFilename(), 0, strrpos($osC_Template->getPageContentsFilename(), '.')) . '"');
58           $Qmodules->bindValue(':modules_group', $this->_group);
59           $Qmodules->execute();
60
61           while ($Qmodules->next()) {
62             $_data[$Qmodules->value('boxes_group')][] = array('code' => $Qmodules->value('code'),
63                                                               'page' => $Qmodules->value('content_page'));
hpdl
317
64           }
hpdl
319
65
hpdl
333
66           foreach ($_data as $groups => $modules) {
hpdl
319
67             $clean = array();
68
hpdl
333
69             foreach ($modules as $module) {
70               if (isset($clean[$module['code']])) {
71                 if (substr_count($module['page'], '/') > substr_count($clean[$module['code']]['page'], '/')) {
72                   unset($clean[$module['code']]);
hpdl
319
73                 }
74               }
75
hpdl
333
76               $clean[$module['code']] = $module;
hpdl
319
77             }
78
79             $_data[$groups] = $clean;
80           }
81
hpdl
333
82           foreach ($_data as $groups => $modules) {
83             foreach ($modules as $module) {
84               $data[$groups][] = $module['code'];
hpdl
319
85             }
86           }
hpdl
317
87         }
88
hpdl
1672
89         $osC_Cache->write($data);
hpdl
313
90       }
91
hpdl
333
92       $this->_modules = $data;
hpdl
308
93     }
94
hpdl
313
95     function getCode() {
96       return $this->_code;
97     }
98
hpdl
308
99     function getTitle() {
100       return $this->_title;
101     }
102
103     function getTitleLink() {
104       return $this->_title_link;
105     }
106
107     function hasTitleLink() {
108       return !empty($this->_title_link);
109     }
110
111     function getContent() {
112       return $this->_content;
113     }
114
115     function hasContent() {
116       return !empty($this->_content);
117     }
118
hpdl
333
119     function getAuthorName() {
120       return $this->_author_name;
121     }
122
123     function getAuthorAddress() {
124       return $this->_author_www;
125     }
126
hpdl
308
127     function getGroup($group) {
hpdl
333
128       $modules = array();
hpdl
308
129
hpdl
333
130       if (isset($this->_modules[$group])) {
131         foreach ($this->_modules[$group] as $module) {
132           if (file_exists('includes/modules/' . $this->_group . '/' . $module . '.php')) {
133             $class = 'osC_' . ucfirst($this->_group) . '_' . $module;
hpdl
308
134
hpdl
333
135             if (class_exists($class) === false) {
136               include('includes/modules/' . $this->_group . '/' . $module . '.php');
hpdl
310
137             }
138
hpdl
333
139             $modules[] = $class;
hpdl
308
140           }
141         }
142       }
143
hpdl
333
144       return $modules;
hpdl
308
145     }
hpdl
313
146
hpdl
395
147     function isInstalled($code = '', $group = '') {
hpdl
313
148       global $osC_Database;
149
hpdl
395
150       if (empty($code) && empty($group)) {
151         static $is_installed;
hpdl
313
152
hpdl
395
153         $code = $this->_code;
154         $group = $this->_group;
155       }
156
hpdl
313
157       if (isset($is_installed) === false) {
hpdl
331
158         $Qcheck = $osC_Database->query('select id from :table_templates_boxes where code = :code and modules_group = :modules_group');
hpdl
313
159         $Qcheck->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
hpdl
395
160         $Qcheck->bindValue(':code', $code);
161         $Qcheck->bindValue(':modules_group', $group);
hpdl
313
162         $Qcheck->execute();
163
164         $is_installed = ($Qcheck->numberOfRows()) ? true : false;
165       }
166
167       return $is_installed;
168     }
169
170     function hasKeys() {
171       static $has_keys;
172
173       if (isset($has_keys) === false) {
174         $has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
175       }
176
177       return $has_keys;
178     }
179
180     function getKeys() {
hpdl
333
181       if (isset($this->_keys) === false) {
hpdl
313
182         $this->_keys = array();
183       }
184
185       return $this->_keys;
186     }
187
188     function isActive() {
189       return true;
190     }
191
hpdl
345
192     function install() {
hpdl
395
193       global $osC_Database, $osC_Language;
hpdl
345
194
195       $Qinstall = $osC_Database->query('insert into :table_templates_boxes (title, code, author_name, author_www, modules_group) values (:title, :code, :author_name, :author_www, :modules_group)');
196       $Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
197       $Qinstall->bindValue(':title', $this->_title);
198       $Qinstall->bindValue(':code', $this->_code);
199       $Qinstall->bindValue(':author_name', $this->_author_name);
200       $Qinstall->bindValue(':author_www', $this->_author_www);
201       $Qinstall->bindValue(':modules_group', $this->_group);
202       $Qinstall->execute();
hpdl
395
203
204       foreach ($osC_Language->getAll() as $key => $value) {
205         if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
206           foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
207             $Qcheck = $osC_Database->query('select id from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id limit 1');
208             $Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
209             $Qcheck->bindValue(':definition_key', $def['key']);
210             $Qcheck->bindValue(':content_group', $def['group']);
211             $Qcheck->bindInt(':languages_id', $value['id']);
212             $Qcheck->execute();
213
214             if ($Qcheck->numberOfRows() === 1) {
215               $Qdef = $osC_Database->query('update :table_languages_definitions set definition_value = :definition_value where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id');
216             } else {
217               $Qdef = $osC_Database->query('insert into :table_languages_definitions (languages_id, content_group, definition_key, definition_value) values (:languages_id, :content_group, :definition_key, :definition_value)');
218             }
219             $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
220             $Qdef->bindInt(':languages_id', $value['id']);
221             $Qdef->bindValue(':content_group', $def['group']);
222             $Qdef->bindValue(':definition_key', $def['key']);
223             $Qdef->bindValue(':definition_value', $def['value']);
224             $Qdef->execute();
225           }
226         }
227       }
228
229       osC_Cache::clear('languages');
hpdl
345
230     }
231
hpdl
313
232     function remove() {
hpdl
395
233       global $osC_Database, $osC_Language;
hpdl
313
234
hpdl
333
235       $Qmodule = $osC_Database->query('select id from :table_templates_boxes where code = :code and modules_group = :modules_group');
236       $Qmodule->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
237       $Qmodule->bindValue(':code', $this->_code);
238       $Qmodule->bindValue(':modules_group', $this->_group);
239       $Qmodule->execute();
hpdl
313
240
241       $Qdel = $osC_Database->query('delete from :table_templates_boxes_to_pages where templates_boxes_id = :templates_boxes_id');
hpdl
425
242       $Qdel->bindTable(':table_templates_boxes_to_pages', TABLE_TEMPLATES_BOXES_TO_PAGES);
hpdl
333
243       $Qdel->bindValue(':templates_boxes_id', $Qmodule->valueInt('id'));
hpdl
313
244       $Qdel->execute();
245
hpdl
331
246       $Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
hpdl
313
247       $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
248       $Qdel->bindValue(':code', $this->_code);
hpdl
333
249       $Qdel->bindValue(':modules_group', $this->_group);
hpdl
313
250       $Qdel->execute();
251
252       if ($this->hasKeys()) {
253         $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
254         $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
255         $Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
256         $Qdel->execute();
257       }
hpdl
395
258
259       if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
260         foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
261           $Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
262           $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
263           $Qdel->bindValue(':definition_key', $def['key']);
264           $Qdel->bindValue(':content_group', $def['group']);
265           $Qdel->execute();
266         }
267
268         osC_Cache::clear('languages');
269       }
hpdl
313
270     }
hpdl
308
271   }
272 ?>