Documentation is available at basic_model_filter.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 model
9 * $Id: basic_model_filter.php,v 1.9 2005/02/09 13:21:43 SYSTEM Exp $
10 */
11
12 require_once(dirname(__FILE__) . '/basic_model.php');
13
14 class basic_model_filter extends basic_model {
15
16 function preparsertf($filename) {
17 $content = file_get_contents($filename);
18 $content=str_replace('<<<','¶',$content);
19 $content=str_replace('\lquote ','\'',$content);
20 $content=str_replace('\rquote ','\'',$content);
21 $content=str_replace('>>>','§',$content);
22
23 if (!unlink($filename)) {
24 $this->errorhandler->seterror('filter_unlink');
25 return;
26 }
27
28 if (($handle = @fopen($filename,"ab")) === false) {
29 $this->errorhandler->seterror('filter_createfile');
30 return;
31 }
32
33 if ((@fwrite($handle, $content)) === false) {
34 $this->errorhandler->seterror('filter_writefile');
35 return;
36 }
37
38 @fclose($handle);
39 }
40
41 /**
42 * Return all data in textual form
43 * @param objectid array of objectids
44 * @return array of objects as read by owReadExpand
45 * @see owReadExpand
46 */
47 function getData($objectid) {
48 $result = array();
49 foreach ($objectid as $curid) {
50 $result[] = owReadExpand($curid);
51 }
52 return $result;
53 }
54
55 function parsefilter($objectid, $filterid=0, $filterfilename='', $filterfiletype='') {
56 $smarty =& $this->userhandler->getSmarty();
57 if (!$filterfilename) $smarty->default_resource_type = 'filter';
58 if ($filterfiletype == 'rtf') {
59 /**
60 * @todo: fix me
61 **/
62 if ($filterfilename) {
63 $this->preparsertf($filterfilename);
64 if ($this->errorhandler->haserror()) {
65 // Bail out
66 return;
67 }
68 }
69 $smarty->left_delimiter = '¶';
70 $smarty->right_delimiter = '§';
71 }
72
73 $result = $this->getData($objectid);
74
75 $smarty->assign("user",$this->userhandler->GetSmartyVars());
76 $smarty->assign("data",$result);
77 if ($filterfilename) {
78 return $smarty->fetch($filterfilename);
79 } else {
80 return $smarty->fetch($filterid);
81 }
82 }
83
84 function model() {
85 $this->context->clearall(); #TODO
86 if ($this->data['filterid']) {
87
88 $uploadfile = $this->userhandler->getDirFilterUpload() . $_FILES['userfile']['name'];
89 $obj = owRead($this->data['filterid']);
90
91 include_once($this->userhandler->getSystemPath().'core/util/class.mimetypes.php');
92 $mime =& new Mime_Types($this->userhandler->getSystemPath().'core/util/mime.types');
93
94 $mimetype = $obj->elements[0]['mimetype'];
95 if (!$mimetype) $mimetype = 'application/octetstream';
96 $name = $obj->elements[0]['name'].".".$mime->get_extension($obj->elements[0]['mimetype']);
97
98 if ($this->data['uploadfile']) {
99 if ($obj->elements[0]['filterfiletype'] == 'rtf') $this->preparsertf($this->data['uploadfile']);
100 $result = $this->parsefilter($this->objectid,$this->data['filterid'],$this->data['uploadfile'],$obj->elements[0]['filterfiletype']);
101 } elseif($obj->elements[0]['filtertype'] == 5) {
102 # TODO - no conversion on each use
103 if ($obj->elements[0]['filterfiletype'] == 'rtf') $this->preparsertf($this->userhandler->getDirFilter().$obj->elements[0]['binfileid']);
104
105 $result = $this->parsefilter($this->objectid,$this->data['filterid'],$this->userhandler->getDirFilter().$obj->elements[0]['binfileid'],$obj->elements[0]['filterfiletype']);
106 } else {
107 $result = $this->parsefilter($this->objectid,$this->data['filterid']);
108 }
109
110 if (!$this->errorhandler->haserror()) {
111 header("Pragma: no-cache");
112 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
113 header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
114 header('Cache-Control: no-store, no-cache, must-revalidate');
115 header('Cache-Control: pre-check=0, post-check=0, max-age=0');
116 header('Content-Transfer-Encoding: none');
117 header('Content-Type: '.$mimetype.'; name="' . $name . '"'); // This should work for IE & Opera
118 header('Content-Disposition: inline; filename="' . $name . '"');
119 echo $result;
120 }
121 }
122 }
123 }
124
125 ?>
Documentation generated on Thu, 9 Jun 2005 06:51:09 +0200 by phpDocumentor 1.2.3