CMS  Version 3.9
module_view.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 
39 /**************************************************************
40 
41 Title: module_view.php
42 
43 Description: To view the module.
44 
45 author Reshma Joshi for Sonjara, Inc.
46 
47 date: 11/09
48 
49 ***************************************************************/
50 
51 Fakoli::using("article", "document");
52 
53 abstract class ModuleView
54 {
55  var $module;
56 
57  function ModuleView($module)
58  {
59  $this->module = $module;
60  }
61 
62  static function create($module)
63  {
64  switch($module->content_type)
65  {
66  case "Menu":
67  return new MenuModuleView($module);
68  case "Code":
69  return new CodeModuleView($module);
70  case "HTML":
71  return new HTMLModuleView($module);
72  default:
73  return new QueryModuleView($module);
74  }
75  }
76 
77  abstract function drawView();
78 
79  function wrap($output)
80  {
81  if (!Settings::getValue("settings", "wrap_modules")) return $output;
82 
83  $cssClass = trim("module {$this->module->css_class} $cssClass");
84  return ($output !== '') ? "<div class='$cssClass'>".$output."</div>" : "";
85  }
86 }
87 
89 {
91  {
92  $this->ModuleView($module);
93  }
94 
95  function drawView($cssClass = "")
96  {
97  $cssClass = trim("module {$this->module->css_class} $cssClass");
98 
99  $title = $this->module->getTitle();
100 
101  $className= $this->module->getContent_Type();
102 
103  $constraint = $this->module->getConstraint();
104  if (!$constraint) {
105  $constraint = "1=1";
106  }
107  else if($constraint == "site_user_id") {
108  global $user;
109  $constraint = " site_user_id='$user->site_user_id' ";
110  }
111  $limit= $this->module->getNum_Items();
112 
113  if ($limit) $limit = "LIMIT $limit";
114 
115  $orderby= $this->module->getOrd_By();
116 
117  $results = query($className, "WHERE $constraint ORDER BY $orderby DESC $limit");
118 
119  ob_start();
120 
121  eval($this->module->template);
122 
123  $template = trim(ob_get_contents());
124 
125  ob_end_clean();
126 
127  return $this->wrap($template);
128  }
129 }
130 
132 {
134  {
135  $this->ModuleView($module);
136  }
137 
138  function drawView($cssClass = "")
139  {
140  global $config;
141  global $method;
142  global $user;
143  global $script;
144  global $styles;
145  global $breadcrumbs;
146  global $dialogs;
147  global $page;
148  global $site;
149  global $section;
150  global $menu_identifier;
151  global $identifier;
152  global $section;
153 
154 
155  if ($this->module->php_code_file)
156  {
157  ob_start();
158 
159  try
160  {
161  $codePath = explode(",", $this->module->php_code_file);
162  if (count($codePath) == 2)
163  {
164  $name = $codePath[0];
165  $php_code_file = $codePath[1];
167  if (array_key_exists($name, $components))
168  {
169  $path = $components[$name]->component_path;
171 
172  include $path."/{$php_code_file}";
173 
175  }
176  else
177  {
178  throw new FakoliException("Unknown component");
179  }
180  }
181  else
182  {
184 
185  include $config['homedir']."/{$this->module->php_code_file}";
186 
188  }
189  $output = trim(ob_get_contents());
190  }
191  catch(Exception $e)
192  {
193  $output = $e->__toString();
194  }
195 
196  ob_end_clean();
197  $output = $this->wrap($output);
198  }
199 
200  return $output;
201  }
202 }
203 
205 {
207  {
208  $this->ModuleView($module);
209  }
210 
211  function drawView($cssClass = "")
212  {
213  return $this->wrap($this->module->template);
214  }
215 }
216 
218 {
220  {
221  $this->ModuleView($module);
222  }
223 
224  function drawView($cssClass = "")
225  {
226  $cssClass = trim("module {$this->module->css_class} $cssClass");
227  $menu = $this->module->Menu();
228 
229  $params = explode(",", $this->module->menu_parameters);
230 
231  $qs = "";
232  $x = "?";
233 
234  foreach($params as $param)
235  {
236  if ($_GET[$param])
237  {
238  $qs .= $x . $param . "=" . $_GET[$param];
239  $x = "&";
240  }
241  }
242 
243  trace("QUERYSTRING: $qs", 3);
244 
245  $menuView = new MenuView($menu);
246  $menuView->queryString = $qs;
247  return $this->wrap($menuView->drawView());
248  }
249 }?>
$constraint
$section
Definition: event_form.inc:44
$page
Definition: help.inc:39
if(! $page) $path
Definition: page.inc:57
$components
Definition: tree.inc:41
$menu
Definition: menu_form.inc:47
$name
Definition: upload.inc:54
drawView($cssClass="")
CodeModuleView($module)
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
static coreTraceLevel()
Change to the configured trace level for Fakoli core code.
Definition: core.inc:1346
static getComponents()
Retrieve an array of all the currently enabled components, indexed by component name.
Definition: core.inc:206
static applicationTraceLevel()
Change to the configured trace level for application code.
Definition: core.inc:1338
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
HTMLModuleView($module)
drawView($cssClass="")
drawView($cssClass="")
MenuModuleView($module)
static create($module)
Definition: module_view.inc:62
wrap($output)
Definition: module_view.inc:79
ModuleView($module)
Definition: module_view.inc:57
QueryModuleView($module)
Definition: module_view.inc:90
drawView($cssClass="")
Definition: module_view.inc:95
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
global $user
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$output
Definition: generate.inc:9
global $config
Definition: import.inc:4
$styles
$identifier
Definition: rss.inc:37