Documentation is available at templateclass.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 core
9 * $Id: templateclass.php,v 1.8 2005/01/03 05:18:37 jan Exp $
10 */
11
12 require_once('basicclass.php');
13
14 class template extends basic {
15
16 var $ERR_FILE_ALREADY_EXISTS = 1;
17 var $ERR_NO_FILE_UPLOADED = 2;
18 var $ERR_POSSIBLE_FILE_UPLOAD_ATTACK = 3;
19 var $ERR_FILE_COULD_NOT_BE_OPENED = 4;
20 var $ERR_FILE_COULD_NOT_BE_CLOSED = 5;
21 var $ERR_NO_TEMPLATE_NAME = 6;
22 var $ERR_CANNOTWRITE = 7;
23 var $ERR_CANNOTMAKEDIR = 8;
24 var $ERR_CANNOTDELETE = 9;
25 var $ERR_INCLUDETAG = 10;
26 var $ERR_INCLUDENOTEXIST = 11;
27
28 function template() {
29 $this->basic();
30 $this->setobjecttable('templates');
31 $this->allowduplicate = false;
32 $this->addcolumn('name',0,UI_STRING);
33 $this->addcolumn('content',0,UI_TEXT);
34 $this->addcolumn('param',0,UI_HIDDEN);
35 $this->addcolumn('setting',0,UI_HIDDEN);
36 $this->addcolumn('tpltype',0,UI_COMBO);
37 $this->addcolumn('header',0,UI_TEXT);
38 $this->addcolumn('style',0,UI_TEXT);
39 $this->addcolumn('doctype',0,UI_HIDDEN);
40
41 $this->removeview('createvariant');
42 $this->removeview('createfuture');
43 $this->removeview('approvepublish');
44 $this->removeview('requestapproval');
45 $this->addview('default');
46 }
47
48 function initLayout() {
49 basic::initLayout();
50 $this->addcolumnstyle('content','height: 600px');
51 }
52
53 function stdListCol() {
54 $arr[] = 'name';
55 $arr[] = 'tpltype';
56 $arr[] = 'createdbyname';
57 $arr[] = 'changed';
58 $arr[] = 'language';
59 $arr[] = 'objectid';
60 return $arr;
61 }
62
63 function match_include($text) {
64 $reg = '/\{include file="([a-z0-9æøåÆØÅ:\/\.\s_-]+)"\}/i';
65 preg_match_all($reg, $text, $matches);
66 return $matches;
67 }
68
69 function match_modules($text) {
70 $reg = "/\{[^\}]*".'\$?document\.ext'."\.([a-z0-9-]+)\.([a-z0-9-]+)\.[^\}]*\}/i";
71 preg_match_all($reg, $text, $matches);
72 return $matches;
73 }
74
75 function process_include($text) {
76 $module_matches = $this->match_include($text);
77 while(list($index, $module) = each($module_matches[1])) {
78 $filnavn = $module_matches[1][$index];
79 if (!$module or !$filnavn) {
80 $this->errorcode = $this->ERR_INCLUDETAG;
81 return $this->errorcode;
82 }
83
84 $row = $this->_adodb->getrow("select templates.objectid as objid from templates,object where object.site = '$this->site' and templates.name = '$filnavn' and object.objectid = templates.objectid and object.deleted = 0");
85 if (!is_array($row)) {
86 $this->errorinfo = $filnavn;
87 $this->errorcode = $this->ERR_INCLUDENOTEXIST;
88 return $this->errorcode;
89 } else {
90 $includeid = $row['objid'];
91 $this->_adodb->execute("insert into template_include values (-1, $includeid)");
92 }
93 }
94 }
95
96 function process_modules($text) {
97 $module_matches = $this->match_modules($text);
98 // Modultypen er i $module_matches[1][x]
99 // og dataset er i $module_matches[2][x]
100
101 while(list($index, $module) = each($module_matches[1])) {
102 $dataset = $module_matches[2][$index];
103 $this->_adodb->execute("replace into template_modules (template, type, configset) values (-1,'$module','$dataset')");
104 }
105 }
106
107 function prv_createobject(&$arr) {
108 basic::prv_createobject($arr);
109 $this->process_modules($arr['content']);
110 $this->process_include($arr['content']);
111 $this->_adodb->execute("update template_modules set template = ".$this->getObjectId()." where template = -1");
112 $this->_adodb->execute("update template_include set templateid = ".$this->getObjectId()." where templateid = -1");
113 }
114
115
116 function prv_updateobject($objectid, $arr) {
117 basic::prv_updateobject($objectid, $arr);
118 $this->_adodb->execute("delete from template_modules where template = $objectid");
119 $this->_adodb->execute("delete from template_include where templateid = $objectid ");
120 $this->process_modules($arr['content']);
121 $this->process_include($arr['content']);
122 $row = $this->_adodb->getrow("select * from templates where objectid=$objectid");
123 $this->_adodb->execute("update template_modules set template = $objectid where template = -1");
124 $this->_adodb->execute("update template_include set templateid = $objectid where templateid = -1");
125 }
126
127 function prv_deleteobject() {
128 $this->_adodb->execute("delete from templates where objectid = ".$this->getObjectId());
129 $this->_adodb->execute("delete from template_modules where template = ".$this->getObjectId());
130 $this->_adodb->execute("delete from template_include where templateid = ".$this->getObjectId());
131 $this->_adodb->execute("delete from template_include where includeid = ".$this->getObjectId());
132 }
133
134 function errortext() {
135 switch($this->errorcode) {
136 case $this->ERR_NO_TEMPLATE_NAME :
137 return "Intet skabelonnavn angivet";
138 case $this->ERR_FILE_ALREADY_EXISTS :
139 return "Der findes allerede en skabelon med det angivne navn";
140 case $this->ERR_NO_FILE_UPLOADED :
141 return "Der er ikke uploadet nogen fil";
142 case $this->ERR_POSSIBLE_FILE_UPLOAD_ATTACK :
143 return "Ugyldig destination";
144 case $this->ERR_FILE_COULD_NOT_BE_OPENED :
145 return "Filen kunne ikke åbnes";
146 case $this->ERR_FILE_COULD_NOT_BE_CLOSED :
147 return "Filen kunne ikke lukkes";
148 case $this->ERR_INCLUDETAG :
149 return "Fejl i includetag";
150 case $this->ERR_INCLUDENOTEXIST :
151 return "Der findes ikke en template med navnet $this->errorinfo";
152 }
153 return basic::errortext();
154 }
155
156 }
Documentation generated on Thu, 9 Jun 2005 06:54:08 +0200 by phpDocumentor 1.2.3