Documentation is available at forum.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 * @subpackage forum
10 * $Id: forum.class.php,v 1.2 2005/01/03 05:28:48 jan Exp $
11 */
12
13 require_once($system_path.'extension/basicextension.class.php');
14 require_once('forum.datatype.php');
15 require_once('forumdata.datatype.php');
16
17 class ext_forum extends basicextension {
18
19 function ext_forum() {
20 $this->basicextension();
21 $this->extname = 'forum';
22 $this->hasconfigset = true;
23 }
24
25 function findTopMessage($objectid) {
26 $obj = owRead($objectid);
27 $pobj = owRead($obj->getParentId());
28 if ($pobj->getType() == 'forumdata') {
29 return $this->findtopmessage($pobj->getObjectId());
30 } else {
31 return $obj->getObjectId();
32 }
33 }
34
35 function getforum($parent, $level=0) {
36 $obj = owNew('forumdata');
37 $obj->setsort_col('lastreply');
38 $obj->setsort_way('desc');
39 $obj->listobjects($parent);
40
41 if (!isset($cnt)) $cnt = 0;
42 $z = 0;
43
44 while ($z < $obj->elementscount) {
45 $cnt = sizeof($this->extresult);
46 $this->extresult[$cnt] = $obj->elements[$z];
47 $this->extresult[$cnt]['level'] = $level;
48 #if ($obj->elements[$z]['haschild']) $this->getforum($obj->elements[$z]['objectid'], $level+1);
49 $z++;
50 }
51 }
52
53 function getmessage($parent, $level=0) {
54 $obj = owRead($parent);
55 $cnt = sizeof($this->extresult);
56 $this->extresult[$cnt] = $obj->elements[0];
57
58 $obj->listobjects($parent);
59
60 $z = 0;
61
62 while ($z < $obj->elementscount) {
63 $cnt = sizeof($this->extresult);
64 $this->extresult[$cnt] = $obj->elements[$z];
65 $this->extresult[$cnt]['level'] = $level;
66 if ($obj->elements[$z]['haschild']) $this->getforum($obj->elements[$z]['objectid'], $level+1);
67 $z++;
68 }
69 }
70
71 function makeforumlist() {
72 $this->next_extcmd = "list";
73 if (isset($this->extconfig['templatename_list'])) {
74 $this->settemplatebyname($this->extconfig['templatename_list']);
75 } elseif (isset($this->extconfig['templateid_list']) AND ($this->extconfig['templateid_list'] != 0)) {
76 $this->settemplate($this->extconfig['templateid_list']);
77 } else {
78 $this->installtemplate('standard_forum_list');
79 $this->settemplatebyname('standard_forum_list');
80 }
81 $this->getforum($this->extconfigsetid,1);
82 }
83
84 function convert_links($str, $www = false) {
85 #this converts http://* the link ends at the next space or(if there is no space) at the end of the string.
86 $str = preg_replace('#(http://)([^\s]*)#', '<a href="\\1\\2" target="_blank">\\1\\2</a>', $str);
87 #optional, replaces www.*
88 if($www) {
89 $str = preg_replace('=(www.)([^\s]*)=', '<a href="http://\\1\\2" target="_blank">\\1\\2</a>', $str);
90 }
91 return $str;
92 }
93
94
95 function _do() {
96 if (!$this->extconfigsetid) {
97 $obj = owNew('forum');
98 $obj->createObject(array('name' => $this->extconfigset));
99 $this->extconfigsetid = $obj->getObjectId();
100 $this->readconf();
101 }
102
103 switch ($this->extcmd) {
104
105 case "add":
106 $this->next_extcmd = "doadd";
107 if (isset($this->extconfig['templatename_add'])) {
108 $this->settemplatebyname($this->extconfig['templatename_add']);
109 } elseif (isset($this->extconfig['templateid_add']) AND ($this->extconfig['templateid_add'] != 0)) {
110 $this->settemplate($this->extconfig['templateid_add']);
111 } else {
112 $this->installtemplate('standard_forum_add');
113 $this->settemplatebyname('standard_forum_add');
114 }
115 break;
116
117 case "doadd":
118 $obj = owNew('forumdata');
119 $arr['name'] = htmlspecialchars($_REQUEST['name']);
120 $arr['content'] = $this->convert_links(htmlspecialchars($_REQUEST['content']),true);
121 $arr['uname'] = htmlspecialchars($_REQUEST['uname']);
122 $obj->createobject($arr, $_REQUEST['parentid']);
123 $pobj = owRead($_REQUEST['parentid']);
124 if ($pobj) {
125 if ($pobj->getType() == 'forumdata') {
126 $topmostid = $this->findTopMessage($_REQUEST['parentid']);
127 $topobj = owRead($topmostid);
128 if ($topobj) {
129 $topobj->updateObject($topobj->getObjectId(),array('lastreply'=>$obj->getCreated(),'numreply'=>$topobj->elements[0]['numreply']+1));
130 }
131 } else { # new message - set lastreply to created datetime
132 $obj->readObject($obj->getObjectId());
133 $obj->updateObject($obj->getObjectId(),array('lastreply'=>$obj->getCreated() ));
134 }
135 }
136 $this->makeforumlist();
137 break;
138
139 case "reply" :
140 $this->next_extcmd = "doadd";
141 $this->getmessage($_REQUEST['objectid'],1);
142 if (isset($this->extconfig['templatename_reply'])) {
143 $this->settemplatebyname($this->extconfig['templatename_reply']);
144 } elseif (isset($this->extconfig['templateid_reply']) AND ($this->extconfig['templateid_reply'] != 0)) {
145 $this->settemplate($this->extconfig['templateid_reply']);
146 } else {
147 $this->installtemplate('standard_forum_reply');
148 $this->settemplatebyname('standard_forum_reply');
149 }
150 break;
151
152 case "read" :
153 $obj = owRead($_REQUEST['objectid']);
154 if ($obj) {
155 $obj->updateObject($obj->getObjectId(),array('numread'=>$obj->elements[0]['numread']+1));
156 }
157 $this->getmessage($_REQUEST['objectid'],1);
158 if (isset($this->extconfig['templatename_read'])) {
159 $this->settemplatebyname($this->extconfig['templatename_read']);
160 } elseif (isset($this->extconfig['templateid_read']) AND ($this->extconfig['templateid_read'] != 0)) {
161 $this->settemplate($this->extconfig['templateid_read']);
162 } else {
163 $this->installtemplate('standard_forum_read');
164 $this->settemplatebyname('standard_forum_read');
165 }
166 break;
167
168 default:
169 $this->makeforumlist();
170 }
171 }
172 }
173 ?>
Documentation generated on Thu, 9 Jun 2005 06:52:26 +0200 by phpDocumentor 1.2.3