1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* XOOPS news story |
4
|
|
|
* |
5
|
|
|
* You may not change or alter any portion of this comment or credits |
6
|
|
|
* of supporting developers from this source code or any supporting source code |
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
* |
12
|
|
|
* @copyright XOOPS Project (http://xoops.org) |
13
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
14
|
|
|
* @package kernel |
15
|
|
|
* @since 2.0.0 |
16
|
|
|
* @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
17
|
|
|
* @deprecated |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
21
|
|
|
//$GLOBALS['xoopsLogger']->addDeprecated("'/class/xoopsstory.php' is deprecated since XOOPS 2.5.4, please create your own class instead."); |
22
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstopic.php'; |
23
|
|
|
include_once XOOPS_ROOT_PATH . '/kernel/user.php'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class MyXoopsStory |
27
|
|
|
*/ |
28
|
|
|
class MyXoopsStory |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
public $table; |
31
|
|
|
public $storyid; |
32
|
|
|
public $topicid; |
33
|
|
|
public $uid; |
34
|
|
|
public $title; |
35
|
|
|
public $hometext; |
36
|
|
|
public $bodytext = ''; |
37
|
|
|
public $counter; |
38
|
|
|
public $created; |
39
|
|
|
public $published; |
40
|
|
|
public $expired; |
41
|
|
|
public $hostname; |
42
|
|
|
public $nohtml = 0; |
43
|
|
|
public $nosmiley = 0; |
44
|
|
|
public $ihome = 0; |
45
|
|
|
public $notifypub = 0; |
46
|
|
|
public $type; |
47
|
|
|
public $approved; |
48
|
|
|
public $topicdisplay; |
49
|
|
|
public $topicalign; |
50
|
|
|
public $db; |
51
|
|
|
public $topicstable; |
52
|
|
|
public $comments; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param $storyid |
56
|
|
|
*/ |
57
|
|
|
public function Story($storyid = -1) |
58
|
|
|
{ |
59
|
|
|
$this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
60
|
|
|
$this->table = ''; |
61
|
|
|
$this->topicstable = ''; |
62
|
|
View Code Duplication |
if (is_array($storyid)) { |
|
|
|
|
63
|
|
|
$this->makeStory($storyid); |
64
|
|
|
} elseif ($storyid != -1) { |
65
|
|
|
$this->getStory((int)$storyid); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param $value |
71
|
|
|
*/ |
72
|
|
|
public function setStoryId($value) |
73
|
|
|
{ |
74
|
|
|
$this->storyid = (int)$value; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param $value |
79
|
|
|
*/ |
80
|
|
|
public function setTopicId($value) |
81
|
|
|
{ |
82
|
|
|
$this->topicid = (int)$value; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $value |
87
|
|
|
*/ |
88
|
|
|
public function setUid($value) |
89
|
|
|
{ |
90
|
|
|
$this->uid = (int)$value; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param $value |
95
|
|
|
*/ |
96
|
|
|
public function setTitle($value) |
97
|
|
|
{ |
98
|
|
|
$this->title = $value; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param $value |
103
|
|
|
*/ |
104
|
|
|
public function setHometext($value) |
105
|
|
|
{ |
106
|
|
|
$this->hometext = $value; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param $value |
111
|
|
|
*/ |
112
|
|
|
public function setBodytext($value) |
113
|
|
|
{ |
114
|
|
|
$this->bodytext = $value; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param $value |
119
|
|
|
*/ |
120
|
|
|
public function setPublished($value) |
121
|
|
|
{ |
122
|
|
|
$this->published = (int)$value; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param $value |
127
|
|
|
*/ |
128
|
|
|
public function setExpired($value) |
129
|
|
|
{ |
130
|
|
|
$this->expired = (int)$value; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param $value |
135
|
|
|
*/ |
136
|
|
|
public function setHostname($value) |
137
|
|
|
{ |
138
|
|
|
$this->hostname = $value; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param int $value |
143
|
|
|
*/ |
144
|
|
|
public function setNohtml($value = 0) |
145
|
|
|
{ |
146
|
|
|
$this->nohtml = $value; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param int $value |
151
|
|
|
*/ |
152
|
|
|
public function setNosmiley($value = 0) |
153
|
|
|
{ |
154
|
|
|
$this->nosmiley = $value; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param $value |
159
|
|
|
*/ |
160
|
|
|
public function setIhome($value) |
161
|
|
|
{ |
162
|
|
|
$this->ihome = $value; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param $value |
167
|
|
|
*/ |
168
|
|
|
public function setNotifyPub($value) |
169
|
|
|
{ |
170
|
|
|
$this->notifypub = $value; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param $value |
175
|
|
|
*/ |
176
|
|
|
public function setType($value) |
177
|
|
|
{ |
178
|
|
|
$this->type = $value; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param $value |
183
|
|
|
*/ |
184
|
|
|
public function setApproved($value) |
185
|
|
|
{ |
186
|
|
|
$this->approved = (int)$value; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param $value |
191
|
|
|
*/ |
192
|
|
|
public function setTopicdisplay($value) |
193
|
|
|
{ |
194
|
|
|
$this->topicdisplay = $value; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param $value |
199
|
|
|
*/ |
200
|
|
|
public function setTopicalign($value) |
201
|
|
|
{ |
202
|
|
|
$this->topicalign = $value; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param $value |
207
|
|
|
*/ |
208
|
|
|
public function setComments($value) |
209
|
|
|
{ |
210
|
|
|
$this->comments = (int)$value; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param bool $approved |
215
|
|
|
* |
216
|
|
|
* @return bool |
217
|
|
|
*/ |
218
|
|
|
public function store($approved = false) |
|
|
|
|
219
|
|
|
{ |
220
|
|
|
//$newpost = 0; |
|
|
|
|
221
|
|
|
$myts = MyTextSanitizer::getInstance(); |
222
|
|
|
$title = $myts->censorString($this->title); |
223
|
|
|
$hometext = $myts->censorString($this->hometext); |
224
|
|
|
$bodytext = $myts->censorString($this->bodytext); |
225
|
|
|
$title = $myts->addSlashes($title); |
226
|
|
|
$hometext = $myts->addSlashes($hometext); |
227
|
|
|
$bodytext = $myts->addSlashes($bodytext); |
228
|
|
|
if (!isset($this->nohtml) || $this->nohtml != 1) { |
229
|
|
|
$this->nohtml = 0; |
230
|
|
|
} |
231
|
|
|
if (!isset($this->nosmiley) || $this->nosmiley != 1) { |
232
|
|
|
$this->nosmiley = 0; |
233
|
|
|
} |
234
|
|
|
if (!isset($this->notifypub) || $this->notifypub != 1) { |
235
|
|
|
$this->notifypub = 0; |
236
|
|
|
} |
237
|
|
|
if (!isset($this->topicdisplay) || $this->topicdisplay != 0) { |
238
|
|
|
$this->topicdisplay = 1; |
239
|
|
|
} |
240
|
|
|
$expired = !empty($this->expired) ? $this->expired : 0; |
241
|
|
|
if (!isset($this->storyid)) { |
242
|
|
|
//$newpost = 1; |
|
|
|
|
243
|
|
|
$newstoryid = $this->db->genId($this->table . '_storyid_seq'); |
244
|
|
|
$created = time(); |
245
|
|
|
$published = $this->approved ? $this->published : 0; |
246
|
|
|
|
247
|
|
|
$sql = |
248
|
|
|
sprintf("INSERT INTO %s (storyid, uid, title, created, published, expired, hostname, nohtml, nosmiley, hometext, bodytext, counter, topicid, ihome, notifypub, story_type, topicdisplay, topicalign, comments) VALUES (%u, %u, '%s', %u, %u, %u, '%s', %u, %u, '%s', '%s', %u, %u, %u, %u, '%s', %u, '%s', %u)", |
249
|
|
|
$this->table, $newstoryid, $this->uid, $title, $created, $published, $expired, $this->hostname, $this->nohtml, $this->nosmiley, $hometext, $bodytext, 0, $this->topicid, |
250
|
|
|
$this->ihome, $this->notifypub, $this->type, $this->topicdisplay, $this->topicalign, $this->comments); |
251
|
|
|
} else { |
252
|
|
|
if ($this->approved) { |
253
|
|
|
$sql = |
254
|
|
|
sprintf("UPDATE %s SET title = '%s', published = %u, expired = %u, nohtml = %u, nosmiley = %u, hometext = '%s', bodytext = '%s', topicid = %u, ihome = %u, topicdisplay = %u, topicalign = '%s', comments = %u WHERE storyid = %u", |
255
|
|
|
$this->table, $title, $this->published, $expired, $this->nohtml, $this->nosmiley, $hometext, $bodytext, $this->topicid, $this->ihome, $this->topicdisplay, |
256
|
|
|
$this->topicalign, $this->comments, $this->storyid); |
257
|
|
|
} else { |
258
|
|
|
$sql = |
259
|
|
|
sprintf("UPDATE %s SET title = '%s', expired = %u, nohtml = %u, nosmiley = %u, hometext = '%s', bodytext = '%s', topicid = %u, ihome = %u, topicdisplay = %u, topicalign = '%s', comments = %u WHERE storyid = %u", |
260
|
|
|
$this->table, $title, $expired, $this->nohtml, $this->nosmiley, $hometext, $bodytext, $this->topicid, $this->ihome, $this->topicdisplay, $this->topicalign, $this->comments, |
261
|
|
|
$this->storyid); |
262
|
|
|
} |
263
|
|
|
$newstoryid = $this->storyid; |
264
|
|
|
} |
265
|
|
|
if (!$result = $this->db->query($sql)) { |
266
|
|
|
return false; |
267
|
|
|
} |
268
|
|
|
if (empty($newstoryid)) { |
269
|
|
|
$newstoryid = $this->db->getInsertId(); |
270
|
|
|
$this->storyid = $newstoryid; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
return $newstoryid; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @param $storyid |
278
|
|
|
*/ |
279
|
|
View Code Duplication |
public function getStory($storyid) |
|
|
|
|
280
|
|
|
{ |
281
|
|
|
$storyid = (int)$storyid; |
282
|
|
|
$sql = 'SELECT * FROM ' . $this->table . ' WHERE storyid=' . $storyid . ''; |
283
|
|
|
$array = $this->db->fetchArray($this->db->query($sql)); |
284
|
|
|
$this->makeStory($array); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param $array |
289
|
|
|
*/ |
290
|
|
|
public function makeStory($array) |
291
|
|
|
{ |
292
|
|
|
foreach ($array as $key => $value) { |
293
|
|
|
$this->$key = $value; |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @return bool |
299
|
|
|
*/ |
300
|
|
View Code Duplication |
public function delete() |
|
|
|
|
301
|
|
|
{ |
302
|
|
|
$sql = sprintf('DELETE FROM %s WHERE storyid = %u', $this->table, $this->storyid); |
303
|
|
|
if (!$result = $this->db->query($sql)) { |
304
|
|
|
return false; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
return true; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @return bool |
312
|
|
|
*/ |
313
|
|
View Code Duplication |
public function updateCounter() |
|
|
|
|
314
|
|
|
{ |
315
|
|
|
$sql = sprintf('UPDATE %s SET counter = counter+1 WHERE storyid = %u', $this->table, $this->storyid); |
316
|
|
|
if (!$result = $this->db->queryF($sql)) { |
317
|
|
|
return false; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
return true; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @param $total |
325
|
|
|
* |
326
|
|
|
* @return bool |
327
|
|
|
*/ |
328
|
|
View Code Duplication |
public function updateComments($total) |
|
|
|
|
329
|
|
|
{ |
330
|
|
|
$sql = sprintf('UPDATE %s SET comments = %u WHERE storyid = %u', $this->table, $total, $this->storyid); |
331
|
|
|
if (!$result = $this->db->queryF($sql)) { |
332
|
|
|
return false; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
return true; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
public function topicid() |
339
|
|
|
{ |
340
|
|
|
return $this->topicid; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* @return MyXoopsTopic |
345
|
|
|
*/ |
346
|
|
|
public function topic() |
347
|
|
|
{ |
348
|
|
|
return new MyXoopsTopic($this->topicstable, $this->topicid); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
public function uid() |
352
|
|
|
{ |
353
|
|
|
return $this->uid; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @return string |
358
|
|
|
*/ |
359
|
|
|
public function uname() |
360
|
|
|
{ |
361
|
|
|
return XoopsUser::getUnameFromId($this->uid); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @param string $format |
366
|
|
|
* |
367
|
|
|
* @return mixed |
368
|
|
|
*/ |
369
|
|
View Code Duplication |
public function title($format = 'Show') |
|
|
|
|
370
|
|
|
{ |
371
|
|
|
$myts = MyTextSanitizer::getInstance(); |
372
|
|
|
$smiley = 1; |
|
|
|
|
373
|
|
|
if ($this->nosmiley()) { |
374
|
|
|
$smiley = 0; |
|
|
|
|
375
|
|
|
} |
376
|
|
|
switch ($format) { |
377
|
|
|
case 'Show': |
378
|
|
|
case 'Edit': |
379
|
|
|
$title = $myts->htmlSpecialChars($this->title); |
380
|
|
|
break; |
381
|
|
|
case 'Preview': |
382
|
|
|
case 'InForm': |
383
|
|
|
$title = $myts->htmlSpecialChars($myts->stripSlashesGPC($this->title)); |
384
|
|
|
break; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
return $title; |
|
|
|
|
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* @param string $format |
392
|
|
|
* |
393
|
|
|
* @return string |
394
|
|
|
*/ |
395
|
|
View Code Duplication |
public function hometext($format = 'Show') |
|
|
|
|
396
|
|
|
{ |
397
|
|
|
$myts = MyTextSanitizer::getInstance(); |
398
|
|
|
$html = 1; |
399
|
|
|
$smiley = 1; |
400
|
|
|
$xcodes = 1; |
401
|
|
|
if ($this->nohtml()) { |
402
|
|
|
$html = 0; |
403
|
|
|
} |
404
|
|
|
if ($this->nosmiley()) { |
405
|
|
|
$smiley = 0; |
406
|
|
|
} |
407
|
|
|
switch ($format) { |
408
|
|
|
case 'Show': |
409
|
|
|
$hometext = $myts->displayTarea($this->hometext, $html, $smiley, $xcodes); |
410
|
|
|
break; |
411
|
|
|
case 'Edit': |
412
|
|
|
$hometext = htmlspecialchars($this->hometext, ENT_QUOTES); |
413
|
|
|
break; |
414
|
|
|
case 'Preview': |
415
|
|
|
$hometext = $myts->previewTarea($this->hometext, $html, $smiley, $xcodes); |
416
|
|
|
break; |
417
|
|
|
case 'InForm': |
418
|
|
|
$hometext = htmlspecialchars($myts->stripSlashesGPC($this->hometext), ENT_QUOTES); |
419
|
|
|
break; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
return $hometext; |
|
|
|
|
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* @param string $format |
427
|
|
|
* |
428
|
|
|
* @return string |
429
|
|
|
*/ |
430
|
|
View Code Duplication |
public function bodytext($format = 'Show') |
|
|
|
|
431
|
|
|
{ |
432
|
|
|
$myts = MyTextSanitizer::getInstance(); |
433
|
|
|
$html = 1; |
434
|
|
|
$smiley = 1; |
435
|
|
|
$xcodes = 1; |
436
|
|
|
if ($this->nohtml()) { |
437
|
|
|
$html = 0; |
438
|
|
|
} |
439
|
|
|
if ($this->nosmiley()) { |
440
|
|
|
$smiley = 0; |
441
|
|
|
} |
442
|
|
|
switch ($format) { |
443
|
|
|
case 'Show': |
444
|
|
|
$bodytext = $myts->displayTarea($this->bodytext, $html, $smiley, $xcodes); |
445
|
|
|
break; |
446
|
|
|
case 'Edit': |
447
|
|
|
$bodytext = htmlspecialchars($this->bodytext, ENT_QUOTES); |
448
|
|
|
break; |
449
|
|
|
case 'Preview': |
450
|
|
|
$bodytext = $myts->previewTarea($this->bodytext, $html, $smiley, $xcodes); |
451
|
|
|
break; |
452
|
|
|
case 'InForm': |
453
|
|
|
$bodytext = htmlspecialchars($myts->stripSlashesGPC($this->bodytext), ENT_QUOTES); |
454
|
|
|
break; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
return $bodytext; |
|
|
|
|
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
public function counter() |
|
|
|
|
461
|
|
|
{ |
462
|
|
|
return $this->counter; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
public function created() |
|
|
|
|
466
|
|
|
{ |
467
|
|
|
return $this->created; |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
public function published() |
471
|
|
|
{ |
472
|
|
|
return $this->published; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
public function expired() |
476
|
|
|
{ |
477
|
|
|
return $this->expired; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
public function hostname() |
|
|
|
|
481
|
|
|
{ |
482
|
|
|
return $this->hostname; |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
public function storyid() |
486
|
|
|
{ |
487
|
|
|
return $this->storyid; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* @return int |
492
|
|
|
*/ |
493
|
|
|
public function nohtml() |
494
|
|
|
{ |
495
|
|
|
return $this->nohtml; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* @return int |
500
|
|
|
*/ |
501
|
|
|
public function nosmiley() |
502
|
|
|
{ |
503
|
|
|
return $this->nosmiley; |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* @return int |
508
|
|
|
*/ |
509
|
|
|
public function notifypub() |
510
|
|
|
{ |
511
|
|
|
return $this->notifypub; |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
public function type() |
|
|
|
|
515
|
|
|
{ |
516
|
|
|
return $this->type; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* @return int |
521
|
|
|
*/ |
522
|
|
|
public function ihome() |
523
|
|
|
{ |
524
|
|
|
return $this->ihome; |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
public function topicdisplay() |
528
|
|
|
{ |
529
|
|
|
return $this->topicdisplay; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* @param bool $astext |
534
|
|
|
* |
535
|
|
|
* @return string |
536
|
|
|
*/ |
537
|
|
|
public function topicalign($astext = true) |
538
|
|
|
{ |
539
|
|
|
if ($astext) { |
540
|
|
|
if ($this->topicalign === 'R') { |
541
|
|
|
$ret = 'right'; |
542
|
|
|
} else { |
543
|
|
|
$ret = 'left'; |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
return $ret; |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
return $this->topicalign; |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
public function comments() |
553
|
|
|
{ |
554
|
|
|
return $this->comments; |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.