wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.View.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.View.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/3rdparty/smarty/libs/Smarty.class.php");
20 require_once(BASE."wcmf/lib/util/class.InifileParser.php");
21 require_once(BASE."wcmf/lib/core/class.WCMFException.php");
22 
23 /**
24  * @class View
25  * @ingroup Presentation
26  * @brief View is used by Controller to handle the view presentation in MVC pattern.
27  * View is a subclass of Smarty that is customized for use with the wCMF.
28  *
29  * @author ingo herwig <ingo@wemove.com>
30  */
31 class View extends Smarty
32 {
33  /**
34  * Reimplementation of Smarty's error handling method.
35  * Delegates error handling to WCMFException::throwEx.
36  * @see Smarty::trigger_error()
37  */
38  function trigger_error($error_msg, $error_type = E_USER_WARNING)
39  {
40  WCMFException::throwEx("View error: $error_msg", __FILE__, __LINE__);
41  }
42 
43  /**
44  * Setup the View for display (set directories, attributes, ...).
45  */
46  function setup()
47  {
48  $parser = &InifileParser::getInstance();
49  if (($debugView = $parser->getValue('debugView', 'cms')) === false)
50  $debugView = 0;
51 
52  if (($compileCheck = $parser->getValue('compileCheck', 'smarty')) === false)
53  $compileCheck = 0;
54 
55  if (($caching = $parser->getValue('caching', 'smarty')) === false)
56  $caching = 0;
57  if (($cacheLifetime = $parser->getValue('cacheLifetime', 'smarty')) === false)
58  $cacheLifetime = 3600;
59 
60  $this->debugging = $debugView;
61  $this->compile_check = $compileCheck;
62  $this->caching = $caching;
63  $this->cache_lifetime = $cacheLifetime;
64  $this->plugins_dir = array('plugins', BASE.'wcmf/lib/presentation/smarty_plugins');
65 
66  // load filter
67  $this->load_filter('pre','removeprids');
68  $this->load_filter('output','trimwhitespace');
69 
70  // get template path
71  if (($smartyPath = $parser->getValue('templateDir', 'smarty')) === false)
72  WCMFException::throwEx("No 'smarty.templateDir' given in configfile.", __FILE__, __LINE__);
73 
74  if (substr($smartyPath,-1) != '/')
75  $smartyPath .= '/';
76 
77  $this->template_dir = $smartyPath;
78  $this->compile_dir = $smartyPath.'smarty/templates_c/';
79  $this->config_dir = $smartyPath.'smarty/configs/';
80  $this->cache_dir = $smartyPath.'smarty/cache/';
81 
82  if (!file_exists($this->compile_dir))
83  FileUtil::mkdirRec($this->compile_dir);
84  if (!file_exists($this->cache_dir))
85  FileUtil::mkdirRec($this->cache_dir);
86  }
87 
88  /**
89  * Static cache control methods
90  */
91 
92  /**
93  * Clear the complete cache
94  * @see Smarty::clear_all_cache()
95  */
96  function clearAllCache()
97  {
98  $view = new View();
99  $view->setup();
100  return $view->clear_all_cache();
101  }
102  /**
103  * Clear parts of cache
104  * @see Smarty::clear_cache()
105  */
106  function clearCache($tplFile=null, $cacheId=null)
107  {
108  $view = new View();
109  $view->setup();
110  return $view->clear_cache($tplFile, $cacheId);
111  }
112  /**
113  * Check if a view is cached. Returns also false, if caching is disabled
114  * to make sure that views get regenerated every time when expected.
115  * @see Smarty::is_cached()
116  */
117  function isCached($tplFile, $cacheId=null)
118  {
119  $view = new View();
120  $view->setup();
121  return ($view->caching && $view->is_cached($tplFile, $cacheId));
122  }
123 }
124 ?>
clearCache($tplFile=null, $cacheId=null)
Definition: class.View.php:106
clearAllCache()
Definition: class.View.php:96
mkdirRec($dirname)
setup()
Definition: class.View.php:46
throwEx($message, $file='', $line='')
isCached($tplFile, $cacheId=null)
Definition: class.View.php:117
View is used by Controller to handle the view presentation in MVC pattern. View is a subclass of Smar...
Definition: class.View.php:31
trigger_error($error_msg, $error_type=E_USER_WARNING)
Definition: class.View.php:38