Completed
Pull Request — master (#6)
by Michael
04:18
created

submit.php (1 issue)

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
//
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                  Copyright (c) 2000-2016 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');
29
if (!defined('XOOPS_ROOT_PATH')) {
30
    include __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
$op = 'form';
66
67
//If approve privileges
68
$approveprivilege = 0;
69
if (is_object($xoopsUser) && $gperm_handler->checkRight('news_approve', $perm_itemid, $groups, $module_id)) {
70
    $approveprivilege = 1;
71
}
72
73
if (isset($_POST['preview'])) {
74
    $op = 'preview';
75
} elseif (isset($_POST['post'])) {
76
    $op = 'post';
77
} elseif (isset($_GET['op']) && isset($_GET['storyid'])) {
78
    // Verify that the user can edit or delete an article
79
    if ($_GET['op'] === 'edit' || $_GET['op'] === 'delete') {
80
        if ($xoopsModuleConfig['authoredit'] == 1) {
81
            $tmpstory = new NewsStory((int)$_GET['storyid']);
82
            if (is_object($xoopsUser) && $xoopsUser->getVar('uid') != $tmpstory->uid() && !news_is_admin_group()) {
83
                redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
84
            }
85
        } else { // Users can't edit their articles
86
            if (!news_is_admin_group()) {
87
                redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
88
            }
89
        }
90
    }
91
92
    if ($approveprivilege && $_GET['op'] === 'edit') {
93
        $op      = 'edit';
94
        $storyid = (int)$_GET['storyid'];
95
    } elseif ($approveprivilege && $_GET['op'] === 'delete') {
96
        $op      = 'delete';
97
        $storyid = (int)$_GET['storyid'];
98
    } else {
99
        if (news_getmoduleoption('authoredit') && is_object($xoopsUser) && isset($_GET['storyid'])
100
            && ($_GET['op'] === 'edit'
101
                || $_POST['op'] === 'preview'
102
                || $_POST['op'] === 'post')
103
        ) {
104
            $storyid = 0;
105
            $storyid = isset($_GET['storyid']) ? (int)$_GET['storyid'] : (int)$_POST['storyid'];
106
            if (!empty($storyid)) {
107
                $tmpstory = new NewsStory($storyid);
108
                if ($tmpstory->uid() == $xoopsUser->getVar('uid')) {
109
                    $op = isset($_GET['op']) ? $_GET['op'] : $_POST['post'];
110
                    unset($tmpstory);
111
                    $approveprivilege = 1;
112 View Code Duplication
                } else {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
                    unset($tmpstory);
114
                    if (!news_is_admin_group()) {
115
                        redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM);
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
            } else {
126
                $approveprivilege = 1;
127
            }
128
        }
129
    }
130
}
131
132
switch ($op) {
133
    case 'edit':
134
        if (!$approveprivilege) {
135
            redirect_header(XOOPS_URL . '/modules/news/index.php', 0, _NOPERM);
136
137
            break;
138
        }
139
        //if ($storyid==0 && isset($_POST['storyid'])) {
140
        //$storyid=(int)($_POST['storyid']);
141
        //}
142
        $story = new NewsStory($storyid);
143 View Code Duplication
        if (!$gperm_handler->checkRight('news_view', $story->topicid(), $groups, $module_id)) {
144
            redirect_header(XOOPS_URL . '/modules/news/index.php', 0, _NOPERM);
145
        }
146
        echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td class=\"odd\">";
147
        echo '<h4>' . _AM_EDITARTICLE . '</h4>';
148
        $title       = $story->title('Edit');
149
        $subtitle    = $story->subtitle('Edit');
150
        $hometext    = $story->hometext('Edit');
151
        $bodytext    = $story->bodytext('Edit');
152
        $nohtml      = $story->nohtml();
153
        $nosmiley    = $story->nosmiley();
154
        $description = $story->description();
155
        $keywords    = $story->keywords();
156
        $ihome       = $story->ihome();
157
        $newsauthor  = $story->uid();
158
        $topicid     = $story->topicid();
159
        $notifypub   = $story->notifypub();
160
        $picture     = $story->picture();
161
        $pictureinfo = $story->pictureinfo;
162
        $approve     = 0;
163
        $published   = $story->published();
164
        if (isset($published) && $published > 0) {
165
            $approve = 1;
166
        }
167
        if ($story->published() != 0) {
168
            $published = $story->published();
169
        }
170
        if ($story->expired() != 0) {
171
            $expired = $story->expired();
172
        } else {
173
            $expired = 0;
174
        }
175
        $type         = $story->type();
176
        $topicdisplay = $story->topicdisplay();
177
        $topicalign   = $story->topicalign(false);
178
        if (!news_is_admin_group()) {
179
            include_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
180
        } else {
181
            include_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.original.php';
182
        }
183
        echo '</td></tr></table>';
184
        break;
185
186
    case 'preview':
187
        $topic_id = (int)$_POST['topic_id'];
188
        $xt       = new NewsTopic($topic_id);
189 View Code Duplication
        if (isset($_GET['storyid'])) {
190
            $storyid = (int)$_GET['storyid'];
191
        } else {
192
            if (isset($_POST['storyid'])) {
193
                $storyid = (int)$_POST['storyid'];
194
            } else {
195
                $storyid = 0;
196
            }
197
        }
198
199
        if (!empty($storyid)) {
200
            $story     = new NewsStory($storyid);
201
            $published = $story->published();
202
            $expired   = $story->expired();
203
        } else {
204
            $story     = new NewsStory();
205
            $published = isset($_POST['publish_date']) ? $_POST['publish_date'] : 0;
206 View Code Duplication
            if (!empty($published) && isset($_POST['autodate']) && (int)($_POST['autodate'] == 1)) {
207
                $published = strtotime($published['date']) + $published['time'];
208
            } else {
209
                $published = 0;
210
            }
211
            $expired = isset($_POST['expiry_date']) ? $_POST['expiry_date'] : 0;
212 View Code Duplication
            if (!empty($expired) && isset($_POST['autoexpdate']) && (int)($_POST['autoexpdate'] == 1)) {
213
                $expired = strtotime($expired['date']) + $expired['time'];
214
            } else {
215
                $expired = 0;
216
            }
217
        }
218
        $topicid = $topic_id;
219
        if (isset($_POST['topicdisplay'])) {
220
            $topicdisplay = (int)$_POST['topicdisplay'];
221
        } else {
222
            $topicdisplay = 1;
223
        }
224
225
        $approve    = isset($_POST['approve']) ? (int)$_POST['approve'] : 0;
226
        $topicalign = 'R';
227
        if (isset($_POST['topicalign'])) {
228
            $topicalign = $_POST['topicalign'];
229
        }
230
        $story->setTitle($_POST['title']);
231
        $story->setSubtitle($_POST['subtitle']);
232
        $story->setHometext($_POST['hometext']);
233
        if ($approveprivilege) {
234
            $story->setTopicdisplay($topicdisplay);
235
            $story->setTopicalign($topicalign);
236
            $story->setBodytext($_POST['bodytext']);
237
            if (news_getmoduleoption('metadata')) {
238
                $story->setKeywords($_POST['keywords']);
239
                $story->setDescription($_POST['description']);
240
                $story->setIhome((int)$_POST['ihome']);
241
            }
242
        } else {
243
            $noname = isset($_POST['noname']) ? (int)$_POST['noname'] : 0;
244
        }
245
246
        if ($approveprivilege || (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid()))) {
247
            if (isset($_POST['author'])) {
248
                $story->setUid((int)$_POST['author']);
249
            }
250
        }
251
252
        $notifypub = isset($_POST['notifypub']) ? (int)$_POST['notifypub'] : 0;
253
        $nosmiley  = isset($_POST['nosmiley']) ? (int)$_POST['nosmiley'] : 0;
254
        if (isset($nosmiley) && ($nosmiley == 0 || $nosmiley == 1)) {
255
            $story->setNosmiley($nosmiley);
256
        } else {
257
            $nosmiley = 0;
258
        }
259
        if ($approveprivilege) {
260
            $nohtml = isset($_POST['nohtml']) ? (int)$_POST['nohtml'] : 0;
261
            $story->setNohtml($nohtml);
262
            if (!isset($_POST['approve'])) {
263
                $approve = 0;
264
            }
265
        } else {
266
            $story->setNohtml = 1;
267
        }
268
269
        $title    = $story->title('InForm');
270
        $subtitle = $story->subtitle('InForm');
271
        $hometext = $story->hometext('InForm');
272
        if ($approveprivilege) {
273
            $bodytext    = $story->bodytext('InForm');
274
            $ihome       = $story->ihome();
275
            $description = $story->description('E');
276
            $keywords    = $story->keywords('E');
277
        }
278
        $pictureinfo = $story->pictureinfo('InForm');
279
280
        //Display post preview
281
        $newsauthor = $story->uid();
282
        $p_title    = $story->title('Preview');
283
        $p_hometext = $story->hometext('Preview');
284
        if ($approveprivilege) {
285
            $p_bodytext = $story->bodytext('Preview');
286
            $p_hometext .= '<br><br>' . $p_bodytext;
287
        }
288
        $topicalign2 = isset($story->topicalign) ? 'align="' . $story->topicalign() . '"' : '';
289
        $p_hometext  = (($xt->topic_imgurl() !== '') && $topicdisplay) ? '<img src="assets/images/topics/'
290
                                                                         . $xt->topic_imgurl()
291
                                                                         . '" '
292
                                                                         . $topicalign2
293
                                                                         . ' alt="" />'
294
                                                                         . $p_hometext : $p_hometext;
295
        themecenterposts($p_title, $p_hometext);
296
297
        //Display post edit form
298
        $returnside = (int)$_POST['returnside'];
299
        include_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
300
        break;
301
302
    case 'post':
303
        $nohtml_db = isset($_POST['nohtml']) ? $_POST['nohtml'] : 1;
304
        if (is_object($xoopsUser)) {
305
            $uid = $xoopsUser->getVar('uid');
306
            if ($approveprivilege) {
307
                $nohtml_db = empty($_POST['nohtml']) ? 0 : 1;
308
            }
309
            if (isset($_POST['author']) && ($approveprivilege || $xoopsUser->isAdmin($xoopsModule->mid()))) {
310
                $uid = (int)$_POST['author'];
311
            }
312
        } else {
313
            $uid = 0;
314
        }
315
316 View Code Duplication
        if (isset($_GET['storyid'])) {
317
            $storyid = (int)$_GET['storyid'];
318
        } else {
319
            if (isset($_POST['storyid'])) {
320
                $storyid = (int)$_POST['storyid'];
321
            } else {
322
                $storyid = 0;
323
            }
324
        }
325
326
        if (empty($storyid)) {
327
            $story    = new NewsStory();
328
            $editmode = false;
329
        } else {
330
            $story    = new NewsStory($storyid);
331
            $editmode = true;
332
        }
333
        $story->setUid($uid);
334
        $story->setTitle($_POST['title']);
335
        $story->setSubtitle($_POST['subtitle']);
336
        $story->setHometext($_POST['hometext']);
337
        $story->setTopicId((int)$_POST['topic_id']);
338
        $story->setHostname(xoops_getenv('REMOTE_ADDR'));
339
        $story->setNohtml($nohtml_db);
340
        $nosmiley = isset($_POST['nosmiley']) ? (int)$_POST['nosmiley'] : 0;
341
        $story->setNosmiley($nosmiley);
342
        $notifypub = isset($_POST['notifypub']) ? (int)$_POST['notifypub'] : 0;
343
        $story->setNotifyPub($notifypub);
344
        $story->setType($_POST['type']);
345
346
        if (!empty($_POST['autodate']) && $approveprivilege) {
347
            $publish_date = $_POST['publish_date'];
348
            $pubdate      = strtotime($publish_date['date']) + $publish_date['time'];
349
            //$offset = $xoopsUser -> timezone() - $xoopsConfig['server_TZ'];
350
            //$pubdate = $pubdate - ( $offset * 3600 );
351
            $story->setPublished($pubdate);
352
        }
353
        if (!empty($_POST['autoexpdate']) && $approveprivilege) {
354
            $expiry_date = $_POST['expiry_date'];
355
            $expiry_date = strtotime($expiry_date['date']) + $expiry_date['time'];
356
            $offset      = $xoopsUser->timezone() - $xoopsConfig['server_TZ'];
357
            $expiry_date = $expiry_date - ($offset * 3600);
358
            $story->setExpired($expiry_date);
359
        } else {
360
            $story->setExpired(0);
361
        }
362
363
        if ($approveprivilege) {
364
            if (news_getmoduleoption('metadata')) {
365
                $story->setDescription($_POST['description']);
366
                $story->setKeywords($_POST['keywords']);
367
            }
368
            $story->setTopicdisplay($_POST['topicdisplay']); // Display Topic Image ? (Yes or No)
369
            $story->setTopicalign($_POST['topicalign']); // Topic Align, 'Right' or 'Left'
370
            $story->setIhome($_POST['ihome']); // Publish in home ? (Yes or No)
371
            if (isset($_POST['bodytext'])) {
372
                $story->setBodytext($_POST['bodytext']);
373
            } else {
374
                $story->setBodytext(' ');
375
            }
376
            $approve = isset($_POST['approve']) ? (int)$_POST['approve'] : 0;
377
378
            if (!$story->published() && $approve) {
379
                $story->setPublished(time());
380
            }
381
            if (!$story->expired()) {
382
                $story->setExpired(0);
383
            }
384
385
            if (!$approve) {
386
                $story->setPublished(0);
387
            }
388
        } elseif ($xoopsModuleConfig['autoapprove'] == 1 && !$approveprivilege) {
389
            if (empty($storyid)) {
390
                $approve = 1;
391
            } else {
392
                $approve = isset($_POST['approve']) ? (int)$_POST['approve'] : 0;
393
            }
394
            if ($approve) {
395
                $story->setPublished(time());
396
            } else {
397
                $story->setPublished(0);
398
            }
399
            $story->setExpired(0);
400
            $story->setTopicalign('R');
401
        } else {
402
            $approve = 0;
403
        }
404
        $story->setApproved($approve);
405
406
        if ($approve) {
407
            news_updateCache();
408
        }
409
410
        // Increment author's posts count (only if it's a new article)
411
        // First case, it's not an anonyous, the story is approved and it's a new story
412
        if ($uid && $approve && empty($storyid)) {
413
            $tmpuser        = new xoopsUser($uid);
414
            $member_handler = xoops_getHandler('member');
415
            $member_handler->updateUserByField($tmpuser, 'posts', $tmpuser->getVar('posts') + 1);
416
        }
417
418
        // 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)
419
        if (is_object($xoopsUser) && $approve && !empty($storyid)) {
420
            $storytemp = new NewsStory($storyid);
421
            if (!$storytemp->published() && $storytemp->uid() > 0) { // the article has been submited but not approved
422
                $tmpuser        = new xoopsUser($storytemp->uid());
423
                $member_handler = xoops_getHandler('member');
424
                $member_handler->updateUserByField($tmpuser, 'posts', $tmpuser->getVar('posts') + 1);
425
            }
426
            unset($storytemp);
427
        }
428
429
        $allowupload = false;
430 View Code Duplication
        switch ($xoopsModuleConfig['uploadgroups']) {
431
            case 1: //Submitters and Approvers
432
                $allowupload = true;
433
                break;
434
            case 2: //Approvers only
435
                $allowupload = $approveprivilege ? true : false;
436
                break;
437
            case 3: //Upload Disabled
438
                $allowupload = false;
439
                break;
440
        }
441
442
        if ($allowupload && isset($_POST['deleteimage']) && (int)$_POST['deleteimage'] == 1) {
443
            $currentPicture = $story->picture();
444
            if (xoops_trim($currentPicture) !== '') {
445
                $currentPicture = XOOPS_ROOT_PATH . '/uploads/news/image/' . xoops_trim($story->picture());
446
                if (is_file($currentPicture) && file_exists($currentPicture)) {
447
                    if (!unlink($currentPicture)) {
448
                        trigger_error('Error, impossible to delete the picture attached to this article');
449
                    }
450
                }
451
            }
452
            $story->setPicture('');
453
            $story->setPictureinfo('');
454
        }
455
456
        if ($allowupload) { // L'image
457
            if (isset($_POST['xoops_upload_file'])) {
458
                $fldname = $_FILES[$_POST['xoops_upload_file'][1]];
459
                $fldname = $fldname['name'];
460
                if (xoops_trim($fldname !== '')) {
461
                    $sfiles         = new sFiles();
462
                    $destname       = $sfiles->createUploadName(XOOPS_ROOT_PATH . '/uploads/news/image', $fldname);
463
                    $permittedtypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
464
                    $uploader       = new XoopsMediaUploader(XOOPS_ROOT_PATH . '/uploads/news/image', $permittedtypes,
465
                                                             $xoopsModuleConfig['maxuploadsize']);
466
                    $uploader->setTargetFileName($destname);
467
                    if ($uploader->fetchMedia($_POST['xoops_upload_file'][1])) {
468
                        if ($uploader->upload()) {
469
                            $fullPictureName = XOOPS_ROOT_PATH . '/uploads/news/image/' . basename($destname);
470
                            $newName         = XOOPS_ROOT_PATH . '/uploads/news/image/redim_' . basename($destname);
471
                            news_resizePicture($fullPictureName, $newName, $xoopsModuleConfig['maxwidth'], $xoopsModuleConfig['maxheight']);
472
                            if (file_exists($newName)) {
473
                                @unlink($fullPictureName);
474
                                rename($newName, $fullPictureName);
475
                            }
476
                            $story->setPicture(basename($destname));
477
                        } else {
478
                            echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
479
                        }
480
                    } else {
481
                        echo $uploader->getErrors();
482
                    }
483
                }
484
                $story->setPictureinfo($_POST['pictureinfo']);
485
            }
486
        }
487
        $destname = '';
488
489
        $result = $story->store();
490
        if ($result) {
491
            if (xoops_isActiveModule('tag') && news_getmoduleoption('tags')) {
492
                $tag_handler = xoops_getModuleHandler('tag', 'tag');
493
                $tag_handler->updateByItem($_POST['item_tag'], $story->storyid(), $xoopsModule->getVar('dirname'), 0);
494
            }
495
496
            if (!$editmode) {
497
                //  Notification
498
                // TODO: modifier afin qu'en cas de pr�publication, la notification ne se fasse pas
499
                $notification_handler = xoops_getHandler('notification');
500
                $tags                 = array();
501
                $tags['STORY_NAME']   = $story->title();
502
                $tags['STORY_URL']    = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/article.php?storyid=' . $story->storyid();
503
                // If notify checkbox is set, add subscription for approve
504
                if ($notifypub && $approve) {
505
                    include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
506
                    $notification_handler->subscribe('story', $story->storyid(), 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE,
507
                                                     $xoopsModule->getVar('mid'), $story->uid());
508
                }
509
510
                if ($approve == 1) {
511
                    $notification_handler->triggerEvent('global', 0, 'new_story', $tags);
512
                    $notification_handler->triggerEvent('story', $story->storyid(), 'approve', $tags);
513
                    // Added by Lankford on 2007/3/23
514
                    $notification_handler->triggerEvent('category', $story->topicid(), 'new_story', $tags);
515
                } else {
516
                    $tags['WAITINGSTORIES_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=newarticle';
517
                    $notification_handler->triggerEvent('global', 0, 'story_submit', $tags);
518
                }
519
            }
520
521
            if ($allowupload) {
522
                // Manage upload(s)
523
                if (isset($_POST['delupload']) && count($_POST['delupload']) > 0) {
524
                    foreach ($_POST['delupload'] as $onefile) {
525
                        $sfiles = new sFiles($onefile);
526
                        $sfiles->delete();
527
                    }
528
                }
529
530
                if (isset($_POST['xoops_upload_file'])) {
531
                    $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
532
                    $fldname = $fldname['name'];
533
                    if (xoops_trim($fldname !== '')) {
534
                        $sfiles   = new sFiles();
535
                        $destname = $sfiles->createUploadName(XOOPS_UPLOAD_PATH, $fldname);
536
                        /**
537
                         * You can attach files to your news
538
                         */
539
                        $permittedtypes = explode("\n", str_replace("\r", '', news_getmoduleoption('mimetypes')));
540
                        array_walk($permittedtypes, 'trim');
541
                        $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, $permittedtypes, $xoopsModuleConfig['maxuploadsize']);
542
                        $uploader->setTargetFileName($destname);
543
                        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
544
                            if ($uploader->upload()) {
545
                                $sfiles->setFileRealName($uploader->getMediaName());
546
                                $sfiles->setStoryid($story->storyid());
547
                                $sfiles->setMimetype($sfiles->giveMimetype(XOOPS_UPLOAD_PATH . '/' . $uploader->getMediaName()));
548
                                $sfiles->setDownloadname($destname);
549
                                if (!$sfiles->store()) {
550
                                    echo _AM_UPLOAD_DBERROR_SAVE;
551
                                }
552
                            } else {
553
                                echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
554
                            }
555
                        } else {
556
                            echo $uploader->getErrors();
557
                        }
558
                    }
559
                }
560
            }
561
        } else {
562
            echo _ERRORS;
563
        }
564
        $returnside = isset($_POST['returnside']) ? (int)$_POST['returnside'] : 0;
565
        if (!$returnside) {
566
            redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_THANKS);
567
        } else {
568
            redirect_header(XOOPS_URL . '/modules/news/admin/index.php?op=newarticle', 2, _NW_THANKS);
569
        }
570
        break;
571
572
    case 'form':
573
        $xt        = new NewsTopic();
574
        $title     = '';
575
        $subtitle  = '';
576
        $hometext  = '';
577
        $noname    = 0;
578
        $nohtml    = 0;
579
        $nosmiley  = 0;
580
        $notifypub = 1;
581
        $topicid   = 0;
582
        if ($approveprivilege) {
583
            $description  = '';
584
            $keywords     = '';
585
            $topicdisplay = 0;
586
            $topicalign   = 'R';
587
            $ihome        = 0;
588
            $bodytext     = '';
589
            $approve      = 0;
590
            $autodate     = '';
591
            $expired      = 0;
592
            $published    = 0;
593
        }
594
        if ($xoopsModuleConfig['autoapprove'] == 1) {
595
            $approve = 1;
596
        }
597
        include_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php';
598
        break;
599
}
600
include_once XOOPS_ROOT_PATH . '/footer.php';
601