Completed
Pull Request — master (#4)
by Michael
03:05
created

submit.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
// $Id: submit.php 9767 2012-07-02 06:02:52Z beckmi $
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <http://xoops.org/>                             //
7
//  ------------------------------------------------------------------------ //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
28
//defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
29
if (!defined('XOOPS_ROOT_PATH')) {
30
    include dirname(dirname(__DIR__)) . '/mainfile.php';
31
}
32
include_once __DIR__ . '/header.php';
33
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
34
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
35
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
36
include_once XOOPS_ROOT_PATH . '/class/uploader.php';
37
include_once XOOPS_ROOT_PATH . '/header.php';
38
include_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php';
39 View Code Duplication
if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/admin.php')) {
40
    include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/admin.php';
41
} else {
42
    include_once XOOPS_ROOT_PATH . '/modules/news/language/english/admin.php';
43
}
44
$myts      =& MyTextSanitizer::getInstance();
45
$module_id = $xoopsModule->getVar('mid');
46
$storyid   = 0;
47
48
if (is_object($xoopsUser)) {
49
    $groups = $xoopsUser->getGroups();
50
} else {
51
    $groups = XOOPS_GROUP_ANONYMOUS;
52
}
53
54
$gperm_handler =& xoops_gethandler('groupperm');
55
56
if (isset($_POST['topic_id'])) {
57
    $perm_itemid = (int)($_POST['topic_id']);
58
} else {
59
    $perm_itemid = 0;
60
}
61
//If no access
62 View Code Duplication
if (!$gperm_handler->checkRight('news_submit', $perm_itemid, $groups, $module_id)) {
63
    redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
64
65
}
66
$op = 'form';
67
68
//If approve privileges
69
$approveprivilege = 0;
70
if (is_object($xoopsUser) && $gperm_handler->checkRight('news_approve', $perm_itemid, $groups, $module_id)) {
71
    $approveprivilege = 1;
72
}
73
74
if (isset($_POST['preview'])) {
75
    $op = 'preview';
76
} elseif (isset($_POST['post'])) {
77
    $op = 'post';
78
} elseif (isset($_GET['op']) && isset($_GET['storyid'])) {
79
    // Verify that the user can edit or delete an article
80
    if ($_GET['op'] == 'edit' || $_GET['op'] == 'delete') {
81
        if ($xoopsModuleConfig['authoredit'] == 1) {
82
            $tmpstory = new NewsStory((int)($_GET['storyid']));
83
            if (is_object($xoopsUser) && $xoopsUser->getVar('uid') != $tmpstory->uid() && !news_is_admin_group()) {
84
                redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
85
86
            }
87
        } else { // Users can't edit their articles
88
            if (!news_is_admin_group()) {
89
                redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
90
91
            }
92
        }
93
    }
94
95
    if ($approveprivilege && $_GET['op'] == 'edit') {
96
        $op      = 'edit';
97
        $storyid = (int)($_GET['storyid']);
98
    } elseif ($approveprivilege && $_GET['op'] == 'delete') {
99
        $op      = 'delete';
100
        $storyid = (int)($_GET['storyid']);
101
    } else {
102
        if (news_getmoduleoption('authoredit') && is_object($xoopsUser) && isset($_GET['storyid']) && ($_GET['op'] == 'edit' || $_POST['op'] == 'preview' || $_POST['op'] == 'post')) {
103
            $storyid = 0;
104
            $storyid = isset($_GET['storyid']) ? (int)($_GET['storyid']) : (int)($_POST['storyid']);
105
            if (!empty($storyid)) {
106
                $tmpstory = new NewsStory($storyid);
107
                if ($tmpstory->uid() == $xoopsUser->getVar('uid')) {
108
                    $op = isset($_GET['op']) ? $_GET['op'] : $_POST['post'];
109
                    unset($tmpstory);
110
                    $approveprivilege = 1;
111 View Code Duplication
                } else {
112
                    unset($tmpstory);
113
                    if (!news_is_admin_group()) {
114
                        redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
115
116
                    } else {
117
                        $approveprivilege = 1;
118
                    }
119
                }
120
            }
121 View Code Duplication
        } else {
122
            if (!news_is_admin_group()) {
123
                unset($tmpstory);
124
                redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
125
126
            } else {
127
                $approveprivilege = 1;
128
            }
129
        }
130
    }
131
}
132
133
switch ($op) {
134
    case 'edit':
135
        if (!$approveprivilege) {
136
            redirect_header(XOOPS_URL . '/modules/news/index.php', 0, _NOPERM);
137
138
            break;
139
        }
140
        //if ($storyid==0 && isset($_POST['storyid'])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
141
        //$storyid=(int)($_POST['storyid']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
90% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
142
        //}
143
        $story = new NewsStory($storyid);
144 View Code Duplication
        if (!$gperm_handler->checkRight('news_view', $story->topicid(), $groups, $module_id)) {
145
            redirect_header(XOOPS_URL . '/modules/news/index.php', 0, _NOPERM);
146
147
        }
148
        echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td class=\"odd\">";
149
        echo '<h4>' . _AM_EDITARTICLE . '</h4>';
150
        $title       = $story->title('Edit');
151
        $subtitle    = $story->subtitle('Edit');
152
        $hometext    = $story->hometext('Edit');
153
        $bodytext    = $story->bodytext('Edit');
154
        $nohtml      = $story->nohtml();
155
        $nosmiley    = $story->nosmiley();
156
        $description = $story->description();
157
        $keywords    = $story->keywords();
158
        $ihome       = $story->ihome();
159
        $newsauthor  = $story->uid();
160
        $topicid     = $story->topicid();
161
        $notifypub   = $story->notifypub();
162
        $picture     = $story->picture();
163
        $pictureinfo = $story->pictureinfo;
164
        $approve     = 0;
165
        $published   = $story->published();
166
        if (isset($published) && $published > 0) {
167
            $approve = 1;
168
        }
169
        if ($story ->published() != 0) {
170
            $published = $story->published();
171
        }
172
        if ($story ->expired() != 0) {
173
            $expired = $story->expired();
174
        } else {
175
            $expired = 0;
176
        }
177
        $type         = $story ->type();
178
        $topicdisplay = $story ->topicdisplay();
179
        $topicalign   = $story ->topicalign(false);
180
        if (!news_is_admin_group()) {
181
            include_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
182
        } else {
183
            include_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.original.php';
184
        }
185
        echo '</td></tr></table>';
186
        break;
187
188
    case 'preview':
189
        $topic_id = (int)($_POST['topic_id']);
190
        $xt       = new NewsTopic($topic_id);
191 View Code Duplication
        if (isset($_GET['storyid'])) {
192
            $storyid = (int)($_GET['storyid']);
193
        } else {
194
            if (isset($_POST['storyid'])) {
195
                $storyid = (int)($_POST['storyid']);
196
            } else {
197
                $storyid = 0;
198
            }
199
        }
200
201
        if (!empty($storyid)) {
202
            $story     = new NewsStory($storyid);
203
            $published = $story->published();
204
            $expired   = $story->expired();
205
        } else {
206
            $story     = new NewsStory();
207
            $published = isset($_POST['publish_date']) ? $_POST['publish_date'] : 0;
208 View Code Duplication
            if (!empty($published) && isset($_POST['autodate']) && (int)($_POST['autodate'] == 1)) {
209
                $published = strtotime($published['date']) + $published['time'];
210
            } else {
211
                $published = 0;
212
            }
213
            $expired = isset($_POST['expiry_date']) ? $_POST['expiry_date'] : 0;
214 View Code Duplication
            if (!empty($expired) && isset($_POST['autoexpdate']) && (int)($_POST['autoexpdate'] == 1)) {
215
                $expired = strtotime($expired['date']) + $expired['time'];
216
            } else {
217
                $expired = 0;
218
            }
219
        }
220
        $topicid = $topic_id;
221
        if (isset($_POST['topicdisplay'])) {
222
            $topicdisplay = (int)($_POST['topicdisplay']);
223
        } else {
224
            $topicdisplay = 1;
225
        }
226
227
        $approve    = isset($_POST['approve']) ? (int)($_POST['approve']) : 0;
228
        $topicalign = 'R';
229
        if (isset($_POST['topicalign'])) {
230
            $topicalign = $_POST['topicalign'];
231
        }
232
        $story->setTitle($_POST['title']);
233
        $story->setSubtitle($_POST['subtitle']);
234
        $story->setHometext($_POST['hometext']);
235
        if ($approveprivilege) {
236
            $story->setTopicdisplay($topicdisplay);
237
            $story->setTopicalign($topicalign);
238
            $story->setBodytext($_POST['bodytext']);
239
            if (news_getmoduleoption('metadata')) {
240
                $story->Setkeywords($_POST['keywords']);
241
                $story->setDescription($_POST['description']);
242
                $story->setIhome((int)($_POST['ihome']));
243
            }
244
        } else {
245
            $noname = isset($_POST['noname']) ? (int)($_POST['noname']) : 0;
246
        }
247
248
        if ($approveprivilege || (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid()))) {
249
            if (isset($_POST['author'])) {
250
                $story->setUid((int)($_POST['author']));
251
            }
252
        }
253
254
        $notifypub = isset($_POST['notifypub']) ? (int)($_POST['notifypub']) : 0;
255
        $nosmiley  = isset($_POST['nosmiley']) ? (int)($_POST['nosmiley']) : 0;
256
        if (isset($nosmiley) && ($nosmiley == 0 || $nosmiley == 1)) {
257
            $story ->setNosmiley($nosmiley);
258
        } else {
259
            $nosmiley = 0;
260
        }
261
        if ($approveprivilege) {
262
            $nohtml = isset($_POST['nohtml']) ? (int)($_POST['nohtml']) : 0;
263
            $story->setNohtml($nohtml);
264
            if (!isset($_POST['approve'])) {
265
                $approve = 0;
266
            }
267
        } else {
268
            $story->setNohtml = 1;
269
        }
270
271
        $title    = $story->title('InForm');
272
        $subtitle = $story->subtitle('InForm');
273
        $hometext = $story->hometext('InForm');
274
        if ($approveprivilege) {
275
            $bodytext    = $story->bodytext('InForm');
276
            $ihome       = $story ->ihome();
277
            $description = $story->description('E');
278
            $keywords    = $story->keywords('E');
279
        }
280
        $pictureinfo = $story->pictureinfo('InForm');
281
282
        //Display post preview
283
        $newsauthor = $story->uid();
284
        $p_title    = $story->title('Preview');
285
        $p_hometext = $story->hometext('Preview');
286
        if ($approveprivilege) {
287
            $p_bodytext = $story->bodytext('Preview');
288
            $p_hometext .= '<br /><br />' . $p_bodytext;
289
        }
290
        $topicalign2 = isset($story->topicalign) ? 'align="' . $story->topicalign() . '"' : '';
0 ignored issues
show
The property topicalign cannot be accessed from this context as it is declared private in class MyXoopsStory.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
291
        $p_hometext  = (($xt->topic_imgurl() != '') && $topicdisplay) ? '<img src="assets/images/topics/' . $xt->topic_imgurl() . '" ' . $topicalign2 . ' alt="" />' . $p_hometext : $p_hometext;
292
        themecenterposts($p_title, $p_hometext);
293
294
        //Display post edit form
295
        $returnside = (int)($_POST['returnside']);
296
        include_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
297
        break;
298
299
    case 'post':
300
        $nohtml_db = isset($_POST['nohtml']) ? $_POST['nohtml'] : 1;
301
        if (is_object($xoopsUser)) {
302
            $uid = $xoopsUser->getVar('uid');
303
            if ($approveprivilege) {
304
                $nohtml_db = empty($_POST['nohtml']) ? 0 : 1;
305
            }
306
            if (isset($_POST['author']) && ($approveprivilege || $xoopsUser->isAdmin($xoopsModule->mid()))) {
307
                $uid = (int)($_POST['author']);
308
            }
309
        } else {
310
            $uid = 0;
311
        }
312
313 View Code Duplication
        if (isset($_GET['storyid'])) {
314
            $storyid = (int)($_GET['storyid']);
315
        } else {
316
            if (isset($_POST['storyid'])) {
317
                $storyid = (int)($_POST['storyid']);
318
            } else {
319
                $storyid = 0;
320
            }
321
        }
322
323
        if (empty($storyid)) {
324
            $story    = new NewsStory();
325
            $editmode = false;
326
        } else {
327
            $story    = new NewsStory($storyid);
328
            $editmode = true;
329
        }
330
        $story->setUid($uid);
331
        $story->setTitle($_POST['title']);
332
        $story->setSubtitle($_POST['subtitle']);
333
        $story->setHometext($_POST['hometext']);
334
        $story->setTopicId((int)($_POST['topic_id']));
335
        $story->setHostname(xoops_getenv('REMOTE_ADDR'));
336
        $story->setNohtml($nohtml_db);
337
        $nosmiley = isset($_POST['nosmiley']) ? (int)($_POST['nosmiley']) : 0;
338
        $story->setNosmiley($nosmiley);
339
        $notifypub = isset($_POST['notifypub']) ? (int)($_POST['notifypub']) : 0;
340
        $story->setNotifyPub($notifypub);
341
        $story->setType($_POST['type']);
342
343
        if (!empty($_POST['autodate']) && $approveprivilege) {
344
            $publish_date = $_POST['publish_date'];
345
            $pubdate      = strtotime($publish_date['date']) + $publish_date['time'];
346
            //$offset = $xoopsUser -> timezone() - $xoopsConfig['server_TZ'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
347
            //$pubdate = $pubdate - ( $offset * 3600 );
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
348
            $story ->setPublished($pubdate);
349
        }
350
        if (!empty($_POST['autoexpdate']) && $approveprivilege) {
351
            $expiry_date = $_POST['expiry_date'];
352
            $expiry_date = strtotime($expiry_date['date']) + $expiry_date['time'];
353
            $offset      = $xoopsUser ->timezone() - $xoopsConfig['server_TZ'];
354
            $expiry_date = $expiry_date - ($offset * 3600);
355
            $story ->setExpired($expiry_date);
356
        } else {
357
            $story ->setExpired(0);
358
        }
359
360
        if ($approveprivilege) {
361
            if (news_getmoduleoption('metadata')) {
362
                $story->setDescription($_POST['description']);
363
                $story->Setkeywords($_POST['keywords']);
364
            }
365
            $story->setTopicdisplay($_POST['topicdisplay']); // Display Topic Image ? (Yes or No)
366
            $story->setTopicalign($_POST['topicalign']); // Topic Align, 'Right' or 'Left'
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
367
            $story->setIhome($_POST['ihome']); // Publish in home ? (Yes or No)
368
            if (isset($_POST['bodytext'])) {
369
                $story->setBodytext($_POST['bodytext']);
370
            } else {
371
                $story->setBodytext(' ');
372
            }
373
            $approve = isset($_POST['approve']) ? (int)($_POST['approve']) : 0;
374
375
            if (!$story->published() && $approve) {
376
                $story->setPublished(time());
377
            }
378
            if (!$story->expired()) {
379
                $story->setExpired(0);
380
            }
381
382
            if (!$approve) {
383
                $story->setPublished(0);
384
            }
385
        } elseif ($xoopsModuleConfig['autoapprove'] == 1 && !$approveprivilege) {
386
            if (empty($storyid)) {
387
                $approve = 1;
388
            } else {
389
                $approve = isset($_POST['approve']) ? (int)($_POST['approve']) : 0;
390
            }
391
            if ($approve) {
392
                $story->setPublished(time());
393
            } else {
394
                $story->setPublished(0);
395
            }
396
            $story->setExpired(0);
397
            $story->setTopicalign('R');
398
        } else {
399
            $approve = 0;
400
        }
401
        $story->setApproved($approve);
402
403
        if ($approve) {
404
            news_updateCache();
405
        }
406
407
        // Increment author's posts count (only if it's a new article)
408
        // First case, it's not an anonyous, the story is approved and it's a new story
409
        if ($uid && $approve && empty($storyid)) {
410
            $tmpuser        = new xoopsUser($uid);
411
            $member_handler =& xoops_gethandler('member');
412
            $member_handler->updateUserByField($tmpuser, 'posts', $tmpuser->getVar('posts') + 1);
413
        }
414
415
        // Second case, it's not an anonymous, the story is NOT approved and it's NOT a new story (typical when someone is approving a submited story)
416
        if (is_object($xoopsUser) && $approve && !empty($storyid)) {
417
            $storytemp = new NewsStory($storyid);
418
            if (!$storytemp->published() && $storytemp->uid() > 0) { // the article has been submited but not approved
419
                $tmpuser        = new xoopsUser($storytemp->uid());
420
                $member_handler =& xoops_gethandler('member');
421
                $member_handler->updateUserByField($tmpuser, 'posts', $tmpuser->getVar('posts') + 1);
422
            }
423
            unset($storytemp);
424
        }
425
426
        $allowupload = false;
427 View Code Duplication
        switch ($xoopsModuleConfig['uploadgroups']) {
428
            case 1: //Submitters and Approvers
429
                $allowupload = true;
430
                break;
431
            case 2: //Approvers only
432
                $allowupload = $approveprivilege ? true : false;
433
                break;
434
            case 3: //Upload Disabled
435
                $allowupload = false;
436
                break;
437
        }
438
439
        if ($allowupload && isset($_POST['deleteimage']) && (int)($_POST['deleteimage']) == 1) {
440
            $currentPicture = $story->picture();
441
            if (xoops_trim($currentPicture) != '') {
442
                $currentPicture = XOOPS_ROOT_PATH . '/uploads/news/image/' . xoops_trim($story->picture());
443
                if (is_file($currentPicture) && file_exists($currentPicture)) {
444
                    if (!unlink($currentPicture)) {
445
                        trigger_error("Error, impossible to delete the picture attached to this article");
446
                    }
447
                }
448
            }
449
            $story->setPicture('');
450
            $story->setPictureinfo('');
451
        }
452
453
        if ($allowupload) { // L'image
454
            if (isset($_POST['xoops_upload_file'])) {
455
                $fldname = $_FILES[$_POST['xoops_upload_file'][1]];
456
                $fldname = (get_magic_quotes_gpc()) ? stripslashes($fldname['name']) : $fldname['name'];
457
                if (xoops_trim($fldname != '')) {
458
                    $sfiles         = new sFiles();
459
                    $destname       = $sfiles->createUploadName(XOOPS_ROOT_PATH . '/uploads/news/image', $fldname);
460
                    $permittedtypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
461
                    $uploader       = new XoopsMediaUploader(XOOPS_ROOT_PATH . '/uploads/news/image', $permittedtypes, $xoopsModuleConfig['maxuploadsize']);
462
                    $uploader->setTargetFileName($destname);
463
                    if ($uploader->fetchMedia($_POST['xoops_upload_file'][1])) {
464
                        if ($uploader->upload()) {
465
                            $fullPictureName = XOOPS_ROOT_PATH . '/uploads/news/image/' . basename($destname);
466
                            $newName         = XOOPS_ROOT_PATH . '/uploads/news/image/redim_' . basename($destname);
467
                            news_resizePicture($fullPictureName, $newName, $xoopsModuleConfig['maxwidth'], $xoopsModuleConfig['maxheight']);
468
                            if (file_exists($newName)) {
469
                                @unlink($fullPictureName);
470
                                rename($newName, $fullPictureName);
471
                            }
472
                            $story->setPicture(basename($destname));
473
474
                        } else {
475
                            echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
476
                        }
477
                    } else {
478
                        echo $uploader->getErrors();
479
                    }
480
                }
481
                $story->setPictureinfo($_POST['pictureinfo']);
482
            }
483
        }
484
        $destname = '';
485
486
        $result = $story->store();
487
        if ($result) {
488
            if (news_getmoduleoption('tags')) {
489
                $tag_handler = xoops_getmodulehandler('tag', 'tag');
490
                $tag_handler->updateByItem($_POST['item_tag'], $story->storyid(), $xoopsModule->getVar('dirname'), 0);
491
            }
492
493
            if (!$editmode) {
494
                // 	Notification
495
                // TODO: modifier afin qu'en cas de pr�publication, la notification ne se fasse pas
496
                $notification_handler =& xoops_gethandler('notification');
497
                $tags                 = array();
498
                $tags['STORY_NAME']   = $story->title();
499
                $tags['STORY_URL']    = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?storyid=' . $story->storyid();
500
                // If notify checkbox is set, add subscription for approve
501
                if ($notifypub && $approve) {
502
                    include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
503
                    $notification_handler->subscribe('story', $story->storyid(), 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE, $xoopsModule->getVar('mid'), $story->uid());
504
                }
505
506
                if ($approve == 1) {
507
                    $notification_handler->triggerEvent('global', 0, 'new_story', $tags);
508
                    $notification_handler->triggerEvent('story', $story->storyid(), 'approve', $tags);
509
                    // Added by Lankford on 2007/3/23
510
                    $notification_handler->triggerEvent('category', $story->topicid(), 'new_story', $tags);
511
                } else {
512
                    $tags['WAITINGSTORIES_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=newarticle';
513
                    $notification_handler->triggerEvent('global', 0, 'story_submit', $tags);
514
                }
515
            }
516
517
            if ($allowupload) {
518
                // Manage upload(s)
519
                if (isset($_POST['delupload']) && count($_POST['delupload']) > 0) {
520
                    foreach ($_POST['delupload'] as $onefile) {
521
                        $sfiles = new sFiles($onefile);
522
                        $sfiles->delete();
523
                    }
524
                }
525
526
                if (isset($_POST['xoops_upload_file'])) {
527
                    $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
528
                    $fldname = (get_magic_quotes_gpc()) ? stripslashes($fldname['name']) : $fldname['name'];
529
                    if (xoops_trim($fldname != '')) {
530
                        $sfiles   = new sFiles();
531
                        $destname = $sfiles->createUploadName(XOOPS_UPLOAD_PATH, $fldname);
532
                        /**
533
                         * You can attach files to your news
534
                         */
535
                        $permittedtypes = explode("\n", str_replace("\r", '', news_getmoduleoption('mimetypes')));
536
                        array_walk($permittedtypes, 'trim');
537
                        $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, $permittedtypes, $xoopsModuleConfig['maxuploadsize']);
538
                        $uploader->setTargetFileName($destname);
539
                        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
540
                            if ($uploader->upload()) {
541
                                $sfiles->setFileRealName($uploader->getMediaName());
542
                                $sfiles->setStoryid($story->storyid());
543
                                $sfiles->setMimetype($sfiles->giveMimetype(XOOPS_UPLOAD_PATH . '/' . $uploader->getMediaName()));
544
                                $sfiles->setDownloadname($destname);
545
                                if (!$sfiles->store()) {
546
                                    echo _AM_UPLOAD_DBERROR_SAVE;
547
                                }
548
                            } else {
549
                                echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
550
                            }
551
                        } else {
552
                            echo $uploader->getErrors();
553
                        }
554
                    }
555
                }
556
            }
557
        } else {
558
            echo _ERRORS;
559
        }
560
        $returnside = isset($_POST['returnside']) ? (int)($_POST['returnside']) : 0;
561
        if (!$returnside) {
562
            redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_THANKS);
563
564
        } else {
565
            redirect_header(XOOPS_URL . '/modules/news/admin/index.php?op=newarticle', 2, _NW_THANKS);
566
567
        }
568
        break;
569
570
    case 'form':
571
        $xt        = new NewsTopic();
572
        $title     = '';
573
        $subtitle  = '';
574
        $hometext  = '';
575
        $noname    = 0;
576
        $nohtml    = 0;
577
        $nosmiley  = 0;
578
        $notifypub = 1;
579
        $topicid   = 0;
580
        if ($approveprivilege) {
581
            $description  = '';
582
            $keywords     = '';
583
            $topicdisplay = 0;
584
            $topicalign   = 'R';
585
            $ihome        = 0;
586
            $bodytext     = '';
587
            $approve      = 0;
588
            $autodate     = '';
589
            $expired      = 0;
590
            $published    = 0;
591
        }
592
        if ($xoopsModuleConfig['autoapprove'] == 1) {
593
            $approve = 1;
594
        }
595
        include_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
596
        break;
597
}
598
include_once XOOPS_ROOT_PATH . '/footer.php';
599