Documentation is available at basicextension.class.php
1 <?php
2 /**
3 * @author Jan H. Andersen <jha@ipwsystems.dk>
4 * @author Martin R. Larsen <mrl@ipwsystems.dk>
5 * @copyright {@link http://www.ipwsystems.dk/ IPW Systems a.s}
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @package METAjour
8 * @subpackage extension
9 * $Id: basicextension.class.php,v 1.7 2005/01/31 06:14:34 jan Exp $
10 */
11
12 require_once($system_path.'ow.php');
13 require_once($system_path.'basic_error.php');
14 require_once($system_path.'basic_event.php');
15 require_once($system_path.'basic_user.php');
16
17 class basicextension {
18 var $errorhandler;
19 var $userhandler;
20 var $eventhandler;
21 var $extconfig;
22 var $extoutput;
23 var $extresult;
24
25 var $extname;
26 var $extconfigset;
27 var $extconfigsetid;
28 var $extcmd;
29
30 var $force_extcf; # bruges hvis et modul skal tvinge formen til at gå over i et andet configset
31 var $user;
32 var $document;
33 var $templatefile;
34 var $functions;
35 var $extparams;
36
37 var $documentmodified;
38
39 var $smarty;
40
41 function basicextension() {
42 $this->errorhandler =& GetErrorHandler();
43 $this->eventhandler =& GetEventHandler();
44 $this->userhandler =& GetUserHandler();
45
46 $this->site = $this->userhandler->getSite();
47 $this->system_url = $this->userhandler->getSystemUrl();
48 $this->system_path = $this->userhandler->getSystemPath();
49 $this->viewer_url = $this->userhandler->getViewerUrl();
50 $this->viewer_path = $this->userhandler->getViewerPath();
51 $this->webuser = $this->userhandler->getWebuser();
52 # herunder skal ændres til request i stedet for get, men et problem vis siden vises som den første gennem index.php
53 $this->MeUrl = $viewer_url .'showpage.php?pageid='.$_REQUEST['pageid'];
54 $this->documentmodified = false;
55 $this->functions = array();
56 $this->extparams = array();
57 $this->addfunction('_do');
58 $this->addextparam('force_extcf');
59 $this->addextparam('cmd');
60 $this->smarty = $this->userhandler->getSmarty();
61 $this->smarty->default_resource_type = 'template';
62 }
63
64 // Overridden by childclasses if they allow caching
65 function cacheallowed() {
66 return false;
67 }
68
69 // Overridden by childclasses if they have a valid cache
70 function iscached() {
71 return false;
72 }
73
74 // Overridden by childclasses if they allow caching
75 function cachelifetime() {
76 return 0;
77 }
78
79 // Overridden by childclasses if they allow caching
80 function cacheid() {
81 return null;
82 }
83
84 function objaddslashes($string) {
85 if (get_magic_quotes_gpc()) {
86 return $string;
87 } else {
88 return addslashes($string);
89 }
90 }
91
92 function getdefaultconf() {
93 }
94
95 function getconfparams($params) {
96
97 if (isset($params['force_extcf'])) $this->force_extcf = $params['force_extcf'];
98
99 reset ($this->extparams);
100 while (list ($key, $val) = each ($this->extparams)) {
101 if (isset($params[$val])) $this->extconfig[$val] = $params[$val];
102 }
103 if ($this->hasconfigset == true) {
104 reset ($this->extconfig);
105 while (list ($key, $val) = each ($this->extconfig)) {
106 if (isset($params[$key])) $this->extconfig[$key] = $params[$key];
107 }
108 }
109 }
110
111 function readconf() {
112 if ($this->hasconfigset == true) {
113 $obj = owNew($this->extname);
114 # if the supplied configset is an integer it's an objectid
115 # else try to locate the configset by that name
116 $this->extconfigsetid = is_int($this->extconfigset) ? $this->extconfigset : $obj->locatebyname($this->extconfigset);
117 if ($this->extconfigsetid) {
118 $obj->readobject($this->extconfigsetid);
119 $this->extconfig = $obj->elements[0];
120 }
121 }
122 }
123
124 function setdocument($document) {
125 $this->document = $document;
126 }
127
128 function settemplate($templateid) {
129 $templateobj = owRead($templateid);
130 if ($templateobj) {
131 $this->templatefile = $templateobj->elements[0]['name'];
132 $this->userhandler->addHeaderCache($templateobj->elements[0]['objectid'],$templateobj->elements[0]['header']);
133 $this->userhandler->addStyleCache($templateobj->elements[0]['objectid'],$templateobj->elements[0]['style']);
134 }
135 }
136
137 function settemplatebyname($name) {
138 $templateobj = owNew('template');
139 $templateid = $templateobj->locatebyname($name);
140 if ($templateid) {
141 $this->settemplate($templateid);
142 }
143 }
144
145 function installtemplate($name) {
146 $templateobj = owNew('template');
147 if (!$templateobj->locateByName($name)) {
148 $userid = $this->userhandler->getSystemAccountId();
149 $cid = array();
150 $templateobj = owImportObj($name,$this->system_path."extension/".$this->extname."/standard/",$cid);
151 # $arr['name'] = $name;
152 # $arr['content'] = file_get_contents($this->system_path."extension/".$this->extname."/standard/".$name.".tpl");
153 /**
154 * @todo language is not set
155 */
156 # $templateobj->createobject($arr);
157 $templateobj->setCreatedBy($userid);
158 }
159 }
160
161 function generate($cached = false) {
162 $smarty =& $this->smarty;
163
164 if (!$cached || $this->templatefile == '') {
165 $smarty->assign_by_ref("config",$this->extconfig);
166 $smarty->assign_by_ref("result",$this->extresult);
167
168 $smarty->assign("_ext",$this->extname);
169 if (isset($this->force_extcf)) {
170 $smarty->assign_by_ref("_extcf",$this->force_extcf);
171 } else {
172 $smarty->assign_by_ref("_extcf",$this->extconfigset);
173 }
174
175 $smarty->assign_by_ref("_cmd",$this->next_extcmd);
176 $smarty->assign_by_ref("document",$this->document);
177 $smarty->assign_by_ref("me",$this->MeUrl);
178
179 $this->extoutput = ($this->templatefile != "") ? $smarty->fetch($this->templatefile, $this->cacheid()) : "";
180 } else {
181 $this->extoutput = $smarty->fetch($this->templatefile, $this->cacheid());
182 }
183 }
184
185
186 function execute($configset, $params="", $function='_do') {
187 // Check if the requested function is legal.
188 if (!in_array($function, $this->functions))
189 $function = '_do';
190
191 $this->extconfigset = $configset;
192 $this->getdefaultconf();
193 $this->readconf();
194 if (is_array($params))
195 $this->getconfparams($params);
196
197 if ($this->cacheallowed()) {
198 $this->smarty->caching = 2;
199 $this->smarty->cache_lifetime = $this->cachelifetime();
200 }
201
202 if ($this->iscached()) {
203 $this->generate(true);
204 } else {
205 if ((
206 $_REQUEST['_extcf'] != "")
207 AND ($_REQUEST['_extcf'] == $this->extconfigset)
208 AND ($_REQUEST['_ext'] == $this->extname)) {
209 $this->extcmd = $_REQUEST['_cmd'];
210 }
211 $this->$function();
212 $this->generate();
213 }
214 }
215
216 function addfunction($name) {
217 if (is_array($name)) {
218 $this->functions = array_merge($this->functions, $name);
219 } else {
220 $this->functions[] = $name;
221 }
222 }
223
224 function addextparam($name) {
225 if (is_array($name)) {
226 $this->extparams = array_merge($this->extparams, $name);
227 } else {
228 $this->extparams[] = $name;
229 }
230 }
231
232 }
Documentation generated on Thu, 9 Jun 2005 06:51:00 +0200 by phpDocumentor 1.2.3