CMS  Version 3.9
section_manager.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
44 {
46  {
47  }
48 
49  function export()
50  {
51  $xml = "\n<SectionMap>";
52  $xml .= SerializationManager::serialize(Section, "ORDER BY section_id");
53  $xml .= SerializationManager::serialize(SectionContent, "ORDER BY section_content_id");
56  $xml .= "</SectionMap>";
57 
58  return $xml;
59  }
60 
61  function import($doc, $tx)
62  {
67  }
68 }
69 
79 {
80  private static $map = array();
81 
88  static function registerManager($type, $manager)
89  {
90  trace("Section Type '{$type}' will be managed by ".get_class($manager), 4);
91  SectionContentManagerMap::$map[$type] = $manager;
92  }
93 
100  static function getManager($section)
101  {
102  $mgr = SectionContentManagerMap::$map[$section->section_type];
103  if (!$mgr)
104  {
105  throw new FakoliException("Unknown section manager for section '{$section->section}'");
106  }
107 
108  return $mgr;
109  }
110 
116  static function isSectionTypeRegistered($section_type)
117  {
118  return array_key_exists($section_type, SectionContentManagerMap::$map);
119  }
120 
125  static function getRegisteredTypes()
126  {
127  $types = array_keys(SectionContentManagerMap::$map);
128  sort($types);
129  return $types;
130  }
131 
132  static function onInitialize()
133  {
134  trace("Registering Section Content Managers", 4);
135  ComponentManager::fireEvent('RegisterSectionContentManagers');
136  }
137 }
138 
139 
146 {
147  static function ensureContentManager()
148  {
150  {
152  }
153  }
154 
155  static function addToSection($section_folder, $identifier, $role = "", $template = "", $use_SSL = false, $permissions = "")
156  {
157  trace("Adding '$identifier' to section '$section_folder'", 3);
158 
160 
161  if (SectionManager::isInSection($section_folder, $identifier)) return;
162  $section = Section::createFromIdentifier($section_folder);
163 
164  $content = new SectionContent();
165  $content->section_id = $section->section_id;
166  $content->identifier = $identifier;
167  $content->role = $role;
168  $content->permissions = $permissions;
169  $content->template = $template;
170  $conent->use_SSL = $use_SSL;
171  $content->save();
172  }
173 
174  static function removeFromSection($section_folder, $identifier)
175  {
176  trace("Removing '$identifier' from section '$section_folder'", 3);
177 
179 
180  $section = Section::createFromIdentifier($section_folder);
181 
182  $content = new SectionContent();
183  $content->delete("WHERE section_id={$section->section_id} AND identifier='$identifier'");
184  }
185 
186  static function isInSection($section_folder, $identifier)
187  {
189  $section = Section::createFromIdentifier($section_folder);
190 
191  $content = new SectionContent();
192  return $content->exists("WHERE section_id={$section->section_id} AND identifier='$identifier'");
193  }
194 
195  static function permissionDeleted($permission)
196  {
197  $affected = Query::create(SectionContent, "WHERE permissions REGEXP '[[:<:]]{$permission}[[:>:]]'")
198  ->execute();
199 
200  foreach($affected as $a)
201  {
202  $p = array();
203  $perms = explode(",", $a->permissions);
204  foreach($perms as $q)
205  {
206  if ($q != $a) $p[] = $q;
207  }
208 
209  $a->permissions = implode(",", $p);
210  $a->filter = new InclusionFilter("permissions");
211  $a->save();
212 
213  }
214  }
215 
216  static function upgradeComponent($version)
217  {
218  $mgr = new SectionUpgradeManager();
219  $mgr->upgrade($version);
220  }
221 
223  {
225  }
226 
228  {
229  SerializationManager::registerHandler("section", "Sections and Section Content", new SectionSerializationHandler());
230  return true;
231  }
232 }
233 
234 //SectionManager::registerSectionContentManager();?>
$section
Definition: event_form.inc:44
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
Maintains the map of SectionContentManagers for different Section types.
static getManager($section)
Retrieves the SectionContentManager object for the specified section.
static isSectionTypeRegistered($section_type)
Check whether a SectionContentManager has been registered for the specified type.
static registerManager($type, $manager)
Registers a SectionContentManager for handling a specified section type.
static getRegisteredTypes()
Returns the list of registered section content types.
Section DataItem, defining the data model for sections within a site.
Definition: section.inc:45
static createFromIdentifier($identifier)
Definition: section.inc:95
SectionManager provides simple programmatic interface for managing registration of pages to sections.
static upgradeComponent($version)
static registerSerializationHandler()
static registerSectionContentManager()
static isInSection($section_folder, $identifier)
static addToSection($section_folder, $identifier, $role="", $template="", $use_SSL=false, $permissions="")
static removeFromSection($section_folder, $identifier)
static ensureContentManager()
static permissionDeleted($permission)
Handles serialization of the section map for import/export.
static serialize($class, $constraint="")
Serializes the specified DataItems to XML.
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
static unserialize($class, $doc, $tx, $save=true)
Instantiates DataItems from the supplied XML document and stores them in the database.
$role
Definition: role_form.inc:41
$identifier
Definition: rss.inc:37
$types
if(array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER)) $content
Definition: styles.css.inc:24