-
Notifications
You must be signed in to change notification settings - Fork 1
/
argument.php
289 lines (239 loc) · 7.39 KB
/
argument.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
/********************************************************************************
* The contents of this file are subject to the Common Public Attribution License
* Version 1.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.wikiarguments.net/license/. The License is based on the Mozilla
* Public License Version 1.1 but Sections 14 and 15 have been added to cover
* use of software over a computer network and provide for limited attribution
* for the Original Developer. In addition, Exhibit A has been modified to be
* consistent with Exhibit B.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is Wikiarguments. The Original Developer is the Initial
* Developer and is Wikiarguments GbR. All portions of the code written by
* Wikiarguments GbR are Copyright (c) 2012. All Rights Reserved.
* Contributor(s):
* Andreas Wierz (andreas.wierz@gmail.com).
*
* Attribution Information
* Attribution Phrase (not exceeding 10 words): Powered by Wikiarguments
* Attribution URL: http://www.wikiarguments.net
*
* This display should be, at a minimum, the Attribution Phrase displayed in the
* footer of the page and linked to the Attribution URL. The link to the Attribution
* URL must not contain any form of 'nofollow' attribute.
*
* Display of Attribution Information is required in Larger Works which are
* defined in the CPAL as a work which combines Covered Code or portions
* thereof with code not governed by the terms of the CPAL.
*******************************************************************************/
class Argument
{
public function Argument($argumentId, $row = false, $parent = false)
{
global $sDB, $sQuery;
if(!$row)
{
$res = $sDB->exec("SELECT * FROM `arguments` WHERE `argumentId` = '".i($argumentId)."' LIMIT 1;");
$row = mysql_fetch_object($res);
}
if(!$row)
{
$this->argumentId = -1;
return;
}
$this->argumentId = $argumentId;
$this->questionId = $row->questionId;
$this->parentId = $row->parentId;
$this->parent = $parent;
$this->userId = $row->userId;
$this->username = $sQuery->getUsernameById($row->userId);
$this->headline = $row->headline;
$this->abstract = $row->abstract;
$this->details = $row->details;
$this->dateAdded = $row->dateAdded;
$this->type = $row->type;
$this->score = $row->score;
$this->url = $row->url;
$this->timeSince = timeSinceString($row->dateAdded);
$this->arguments = Array();
}
public function argumentId()
{
return $this->argumentId;
}
public function questionId()
{
return $this->questionId;
}
public function parentId()
{
return $this->parentId;
}
public function parent()
{
global $sQuery;
if(!$this->parent && $this->parentId())
{
$this->parent = $sQuery->getArgumentById($this->parentId());
}
return $this->parent;
}
public function userId()
{
return $this->userId;
}
public function headline()
{
return htmlspecialchars($this->headline);
}
public function abstractText()
{
return htmlspecialchars($this->abstract);
}
public function details()
{
return nl2br(htmlspecialchars($this->details));
}
public function headlinePlain()
{
return $this->headline;
}
public function abstractTextPlain()
{
return $this->abstract;
}
public function detailsPlain()
{
return $this->details;
}
public function dateAdded()
{
return $this->dateAdded;
}
public function arguments($sort = SORT_SCORE)
{
$ret = Array();
foreach($this->arguments as $k => $v)
{
array_push($ret, $v);
}
if($sort == SORT_SCORE)
{
array_sortObjDesc($ret, "score");
}
return $ret;
}
public function numArguments()
{
return count($this->arguments);
}
public function addArgument(Argument $a)
{
array_push($this->arguments, $a);
}
public function type()
{
return $this->type;
}
public function score()
{
return $this->score;
}
public function url($basePath)
{
$url = $basePath.($this->type() == ARGUMENT_PRO ? "p" : "c")."/".$this->url."/";
if($this->parentId())
{
$url = $basePath.($this->type() == ARGUMENT_PRO ? "p" : "c")."/".$this->parent()->urlPlain()."/ca/".$this->url."/";
}
return $url;
}
public function urlCounterArguments($basePath)
{
return $url = $this->url($basePath)."ca/";
}
public function urlNewCounterArgument($basePath)
{
$url = $basePath.($this->type() == ARGUMENT_PRO ? "p" : "c")."/".$this->url."/ca/new-argument/";
return $url;
}
public function urlPlain()
{
return $this->url;
}
public function shortUrl()
{
global $sTemplate;
$id = new BaseConvert($this->argumentId());
return $sTemplate->getShortUrlBase()."a".$id->val();
}
public function shortUrlCA()
{
global $sTemplate;
$id = new BaseConvert($this->argumentId());
return $sTemplate->getShortUrlBase()."c".$id->val();
}
public function timeSince()
{
return $this->timeSince;
}
public function authorLink()
{
global $sTemplate;
if($this->userId == 0)
{
return htmlspecialchars($this->username);
}
return "<a href = '".$sTemplate->getProfileLink($this->userId)."'>".htmlspecialchars($this->username)."</a>";
}
public function author()
{
return $this->username;
}
/*
* Returns true iff $user can edit this question.
*/
public function canEdit(User $user)
{
if(!$this->userId() || $this->userId() != $user->getUserId())
{
return false;
}
if($this->dateAdded() <= time() - ARGUMENT_EDIT_INTERVAL)
{
return false;
}
if(count($this->arguments()))
{
return false;
}
return true;
}
/*
* Return time left for edit in minutes
*/
public function timeLeftEdit()
{
return ceil((ARGUMENT_EDIT_INTERVAL - time() + $this->dateAdded()) / 60);
}
private $argumentId;
private $questionId;
private $parentId;
private $parent;
private $userId;
private $userName;
private $headline;
private $abstract;
private $details;
private $dateAdded;
private $type;
private $score;
private $url;
private $arguments;
};
?>