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