Completed
Push — master ( 96da4e...7c5656 )
by Michael
04:52
created

action.blog.php (4 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
//
3
// ------------------------------------------------------------------------ //
4
// This program is free software; you can redistribute it and/or modify     //
5
// it under the terms of the GNU General Public License as published by     //
6
// the Free Software Foundation; either version 2 of the License, or        //
7
// (at your option) any later version.                                      //
8
//                                                                          //
9
// You may not change or alter any portion of this comment or credits       //
10
// of supporting developers from this source code or any supporting         //
11
// source code which is considered copyrighted (c) material of the          //
12
// original comment or credit authors.                                      //
13
//                                                                          //
14
// This program is distributed in the hope that it will be useful,          //
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
17
// GNU General Public License for more details.                             //
18
//                                                                          //
19
// You should have received a copy of the GNU General Public License        //
20
// along with this program; if not, write to the Free Software              //
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
22
// ------------------------------------------------------------------------ //
23
// Author: phppp (D.J., [email protected])                                  //
24
// URL: http://xoops.org                         //
25
// Project: Article Project                                                 //
26
// ------------------------------------------------------------------------ //
27
28
include __DIR__ . '/header.php';
29
30
$op      = !empty($_POST['op']) ? $_POST['op'] : (!empty($_GET['op']) ? $_GET['op'] : '');
31
$blog_id = !empty($_POST['blog']) ? $_POST['blog'] : (!empty($_GET['blog']) ? $_GET['blog'] : 0);
32
$blog_id = is_array($blog_id) ? array_map('intval', $blog_id) : (int)$blog_id;
33
34
if (empty($xoopsModuleConfig['newblog_submit']) && (!is_object($xoopsUser) || !$xoopsUser->isAdmin())) {
35
    redirect_header('index.php', 2, _NOPERM);
36
}
37
38
if ($op === 'save' && !empty($_POST['fetch'])) {
39
    $op = 'edit';
40
}
41
42
if ($op === 'save' && !$GLOBALS['xoopsSecurity']->check()) {
43
    redirect_header('javascript:history.go(-1);', 1, planet_constant('MD_INVALID') . ': security check failed');
44
}
45
include XOOPS_ROOT_PATH . '/header.php';
46
include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/vars.php';
47
48
$blog_handler     = xoops_getModuleHandler('blog', $GLOBALS['moddirname']);
49
$category_handler = xoops_getModuleHandler('category', $GLOBALS['moddirname']);
50
51
switch ($op) {
52
    /* save a single blog */
53
    case 'save':
54
55
        if ($blog_id) {
56
            $blog_obj =& $blog_handler->get($blog_id);
57
            if ($xoopsUser->isAdmin()) {
58
                $blog_obj->setVar('blog_status', @$_POST['blog_status']);
59
            }
60
        } else {
61
            if ($blog_exists = $blog_handler->getCount(new Criteria('blog_feed',
62
                                                                    $myts->addSlashes(trim($_POST['blog_feed']))))
63
            ) {
64
                redirect_header('index.php', 2, planet_constant('MD_BLOGEXISTS'));
65
            }
66
67
            $blog_obj =& $blog_handler->create();
68
            $blog_obj->setVar('blog_submitter', is_object($xoopsUser) ? $xoopsUser->getVar('uid') : planet_getIP(true));
69
70
            switch ($xoopsModuleConfig['newblog_submit']) {
71
                case 2:
72
                    if (!is_object($xoopsUser)) {
73
                        $status = 0;
74
                    } else {
75
                        $status = 1;
76
                    }
77
                    break;
78
                case 0:
79
                case 3:
80
                    $status = 1;
81
                    break;
82
                case 1:
83
                default:
84
                    if (!is_object($xoopsUser) || !$xoopsUser->isAdmin()) {
85
                        $status = 0;
86
                    } else {
87
                        $status = 1;
88
                    }
89
                    break;
90
            }
91
92
            $blog_obj->setVar('blog_status', $status);
93
        }
94
95
        $blog_obj->setVar('blog_title', $_POST['blog_title']);
96
        $blog_obj->setVar('blog_desc', $_POST['blog_desc']);
97
        $blog_obj->setVar('blog_image', $_POST['blog_image']);
98
        $blog_obj->setVar('blog_feed', $_POST['blog_feed']);
99
        $blog_obj->setVar('blog_link', $_POST['blog_link']);
100
        $blog_obj->setVar('blog_language', $_POST['blog_language']);
101
        $blog_obj->setVar('blog_charset', $_POST['blog_charset']);
102
        $blog_obj->setVar('blog_trackback', $_POST['blog_trackback']);
103
        if ($blog_obj->isNew()) {
104
            $blog_obj->setVar('blog_submitter', is_object($xoopsUser) ? $xoopsUser->getVar('uid') : planet_getIP(true));
105
        }
106
107 View Code Duplication
        if (!$blog_handler->insert($blog_obj)) {
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...
108
        } elseif (!empty($_POST['categories'])) {
109
            $blog_id = $blog_obj->getVar('blog_id');
110
            if (in_array(0, $_POST['categories'])) {
111
                $_POST['categories'] = array();
112
            }
113
            $blog_handler->setCategories($blog_id, $_POST['categories']);
114
        }
115
        $message = planet_constant('MD_DBUPDATED');
116
        redirect_header('index.php' . URL_DELIMITER . 'b' . $blog_id, 2, $message);
117
118
    /* edit a single blog */
119
    case 'edit':
120
    default:
121 View Code Duplication
        if (!empty($_POST['fetch'])) {
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...
122
            $blog_obj =& $blog_handler->fetch($_POST['blog_feed']);
123
            $blog_obj->setVar('blog_id', $blog_id);
124
        } else {
125
            $blog_obj =& $blog_handler->get($blog_id);
126
        }
127
        $categories = isset($_POST['categories']) ? $_POST['categories'] : array();
128
        if (in_array('-1', $categories)) {
129
            $categories = array();
130
        }
131 View Code Duplication
        if (empty($categories) && $blog_id > 0) {
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...
132
            $crit       = new Criteria('bc.blog_id', $blog_id);
133
            $categories = array_keys($category_handler->getByBlog($crit));
134
        }
135
        if (empty($categories)) {
136
            $categories = array(0 => _NONE);
137
        }
138
139
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _EDIT . '</legend>';
140
        echo '<br>';
141 View Code Duplication
        if (empty($blog_id) && $blog_obj->getVar('blog_feed')) {
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...
142
            $criteria  = new Criteria('blog_feed', $blog_obj->getVar('blog_feed'));
143
            $blogs_obj =& $blog_handler->getList($criteria);
144
            if (count($blogs_obj) > 0) {
145
                echo "<div class=\"errorMsg\">" . planet_constant('MD_BLOGEXISTS');
146
                foreach (array_keys($blogs_obj) as $bid) {
147
                    echo "<br><a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php'
148
                         . URL_DELIMITER . 'b' . $bid . "\" target=\"_blank\">" . $blogs_obj[$bid] . '</a>';
149
                }
150
                echo '</div>';
151
                unset($blogs_obj, $criteria);
152
            }
153
        }
154
        include XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/include/form.blog.php';
155
        echo '</fieldset>';
156
        break;
157
}
158
159
include XOOPS_ROOT_PATH . '/footer.php';
160