Quick Search:

View

Revision:

Diff

Diff from 320 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/boxes.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
8   Copyright (c) 2005 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   class osC_Boxes {
14     var $_boxes,
hpdl
313
15         $_code,
hpdl
308
16         $_title,
17         $_title_link,
hpdl
313
18         $_content,
19         $_author_name,
20         $_author_www,
21         $_keys;
hpdl
308
22
23     function osC_Boxes() {
hpdl
317
24       global $osC_Database, $osC_Template, $osC_Cache;
hpdl
313
25
hpdl
317
26       if ($osC_Cache->read('templates_boxes_layout-' . $osC_Template->getTemplate() . '-' . $osC_Template->getGroup() . '-' . $osC_Template->getPageContentsFilename())) {
27         $data = $osC_Cache->getCache();
28       } else {
29         $data = array();
hpdl
313
30
hpdl
317
31         $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 b2p.templates_id = t.id order by b2p.boxes_group, b2p.sort_order');
32         $Qspecific->bindTable(':table_templates_boxes_to_pages', TABLE_TEMPLATES_BOXES_TO_PAGES);
33         $Qspecific->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
34         $Qspecific->bindTable(':table_templates', TABLE_TEMPLATES);
35         $Qspecific->bindInt(':templates_id', 1);
hpdl
320
36         $Qspecific->bindRaw(':content_page', '"*", "' . $osC_Template->getGroup() . '/*", "' . $osC_Template->getGroup() . '/' . substr($osC_Template->getPageContentsFilename(), 0, strrpos($osC_Template->getPageContentsFilename(), '.')) . '"');
hpdl
317
37         $Qspecific->execute();
38
39         if ($Qspecific->numberOfRows()) {
40           while ($Qspecific->next()) {
41             $data[$Qspecific->value('boxes_group')][] = $Qspecific->value('code');
42           }
43         } else {
hpdl
319
44           $Qboxes = $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 b2p.templates_id = t.id order by b2p.boxes_group, b2p.sort_order');
hpdl
317
45           $Qboxes->bindTable(':table_templates_boxes_to_pages', TABLE_TEMPLATES_BOXES_TO_PAGES);
46           $Qboxes->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
47           $Qboxes->bindTable(':table_templates', TABLE_TEMPLATES);
48           $Qboxes->bindInt(':templates_id', 1);
hpdl
320
49           $Qboxes->bindRaw(':content_page', '"*", "' . $osC_Template->getGroup() . '/*", "' . $osC_Template->getGroup() . '/' . substr($osC_Template->getPageContentsFilename(), 0, strrpos($osC_Template->getPageContentsFilename(), '.')) . '"');
hpdl
317
50           $Qboxes->execute();
51
52           while ($Qboxes->next()) {
hpdl
319
53             $_data[$Qboxes->value('boxes_group')][] = array('code' => $Qboxes->value('code'),
54                                                             'page' => $Qboxes->value('content_page'));
hpdl
317
55           }
hpdl
319
56
57           foreach ($_data as $groups => $boxes) {
58             $clean = array();
59
60             foreach ($boxes as $box) {
61               if (isset($clean[$box['code']])) {
62                 if (substr_count($box['page'], '/') > substr_count($clean[$box['code']]['page'], '/')) {
63                   unset($clean[$box['code']]);
64                 }
65               }
66
67               $clean[$box['code']] = $box;
68             }
69
70             $_data[$groups] = $clean;
71           }
72
73           foreach ($_data as $groups => $boxes) {
74             foreach ($boxes as $box) {
75               $data[$groups][] = $box['code'];
76             }
77           }
hpdl
317
78         }
79
80         $osC_Cache->writeBuffer($data);
hpdl
313
81       }
82
hpdl
317
83       $this->_boxes = $data;
hpdl
308
84     }
85
hpdl
313
86     function getCode() {
87       return $this->_code;
88     }
89
hpdl
308
90     function getTitle() {
91       return $this->_title;
92     }
93
94     function getTitleLink() {
95       return $this->_title_link;
96     }
97
98     function hasTitleLink() {
99       return !empty($this->_title_link);
100     }
101
102     function getContent() {
103       return $this->_content;
104     }
105
106     function hasContent() {
107       return !empty($this->_content);
108     }
109
110     function getGroup($group) {
111       $boxes = array();
112
hpdl
310
113       if (isset($this->_boxes[$group])) {
114         foreach ($this->_boxes[$group] as $box) {
hpdl
313
115           if (file_exists('includes/boxes/' . $box . '.php')) {
116             $box_class = 'osC_Boxes_' . $box;
hpdl
308
117
hpdl
310
118             if (class_exists($box_class) === false) {
hpdl
313
119               include('includes/boxes/' . $box . '.php');
hpdl
310
120             }
121
hpdl
313
122             $boxes[] = array('class' => $box . '.php', 'object' => $box_class);
hpdl
308
123           }
124         }
125       }
126
127       return $boxes;
128     }
hpdl
313
129
130     function isInstalled() {
131       global $osC_Database;
132
133       static $is_installed;
134
135       if (isset($is_installed) === false) {
136         $Qcheck = $osC_Database->query('select id from :table_templates_boxes where code = :code');
137         $Qcheck->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
138         $Qcheck->bindValue(':code', $this->_code);
139         $Qcheck->execute();
140
141         $is_installed = ($Qcheck->numberOfRows()) ? true : false;
142       }
143
144       return $is_installed;
145     }
146
147     function hasKeys() {
148       static $has_keys;
149
150       if (isset($has_keys) === false) {
151         $has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
152       }
153
154       return $has_keys;
155     }
156
157     function getKeys() {
158       if (!isset($this->_keys)) {
159         $this->_keys = array();
160       }
161
162       return $this->_keys;
163     }
164
165     function isActive() {
166       return true;
167     }
168
169     function remove() {
170       global $osC_Database;
171
172       $Qbox = $osC_Database->query('select id from :table_templates_boxes where code = :code');
173       $Qbox->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
174       $Qbox->bindValue(':code', $this->_code);
175       $Qbox->execute();
176
177       $Qdel = $osC_Database->query('delete from :table_templates_boxes_to_pages where templates_boxes_id = :templates_boxes_id');
178       $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
179       $Qdel->bindValue(':templates_boxes_id', $Qbox->valueInt('id'));
180       $Qdel->execute();
181
182       $Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code');
183       $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
184       $Qdel->bindValue(':code', $this->_code);
185       $Qdel->execute();
186
187       if ($this->hasKeys()) {
188         $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
189         $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
190         $Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
191         $Qdel->execute();
192       }
193     }
194
195     function getAuthorName() {
196       return $this->_author_name;
197     }
198
199     function getAuthorAddress() {
200       return $this->_author_www;
201     }
hpdl
308
202   }
203 ?>