Completed
Push — master ( a50592...10bab4 )
by Michael
01:56
created

action.blog.php (17 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: https://xoops.org                         //
25
// Project: Article Project                                                 //
26
// ------------------------------------------------------------------------ //
27
use Xmf\Request;
28
29
include __DIR__ . '/header.php';
30
31
$op      = Request::getString('op', Request::getString('op', '', 'POST'), 'GET');//!empty($_POST['op']) ? $_POST['op'] : (!empty($_GET['op']) ? $_GET['op'] : '');
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
32
$blog_id = Request::getArray('blog', Request::getArray('blog', [], 'POST'), 'GET');//!empty($_POST['blog']) ? $_POST['blog'] : (!empty($_GET['blog']) ? $_GET['blog'] : 0);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
33
$blog_id = is_array($blog_id) ? array_map('intval', $blog_id) : (int)$blog_id;
34
35
if (empty($xoopsModuleConfig['newblog_submit']) && (!is_object($xoopsUser) || !$xoopsUser->isAdmin())) {
36
    redirect_header('index.php', 2, _NOPERM);
37
}
38
39
if ('save' === $op && !empty(Request::getString('fetch', '', 'POST'))) {//!empty($_POST['fetch'])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
91% 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...
40
    $op = 'edit';
41
}
42
43
if ('save' === $op && !$GLOBALS['xoopsSecurity']->check()) {
44
    redirect_header('javascript:history.go(-1);', 1, planet_constant('MD_INVALID') . ': security check failed');
45
}
46
include XOOPS_ROOT_PATH . '/header.php';
47
include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/vars.php';
48
49
$blogHandler     = xoops_getModuleHandler('blog', $GLOBALS['moddirname']);
50
$categoryHandler = xoops_getModuleHandler('category', $GLOBALS['moddirname']);
51
52
switch ($op) {
53
    /* save a single blog */
54
    case 'save':
55
56
        if ($blog_id) {
57
            $blog_obj = $blogHandler->get($blog_id);
58
            if ($xoopsUser->isAdmin()) {
59
                $blog_obj->setVar('blog_status', Request::getInt('blog_status', 0, 'POST'));// @$_POST['blog_status']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
88% 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...
60
            }
61
        } else {
62
            if ($blog_exists = $blogHandler->getCount(new Criteria('blog_feed', $myts->addSlashes(trim(Request::getText('blog_feed', '', 'POST')))))  //$_POST['blog_feed']))))
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
63
            ) {
64
                redirect_header('index.php', 2, planet_constant('MD_BLOGEXISTS'));
65
            }
66
67
            $blog_obj = $blogHandler->create();
68
            $blog_obj->setVar('blog_submitter', is_object($xoopsUser) ? $xoopsUser->getVar('uid') : PlanetUtility::planetGetIP(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', Request::getString('blog_title', '', 'POST'));//$_POST['blog_title']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
96
        $blog_obj->setVar('blog_desc', Request::getString('blog_desc', '', 'POST'));//$_POST['blog_desc']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
97
        $blog_obj->setVar('blog_image', Request::getString('blog_image', '', 'POST'));//$_POST['blog_image']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
98
        $blog_obj->setVar('blog_feed', Request::getText('blog_feed', '', 'POST'));//$_POST['blog_feed']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
99
        $blog_obj->setVar('blog_link', Request::getString('blog_link', '', 'POST'));//$_POST['blog_link']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
100
        $blog_obj->setVar('blog_language', Request::getString('blog_language', '', 'POST'));//$_POST['blog_language']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
101
        $blog_obj->setVar('blog_charset', Request::getString('blog_charset', '', 'POST'));//$_POST['blog_charset']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
102
        $blog_obj->setVar('blog_trackback', Request::getString('blog_trackback', '', 'POST'));//$_POST['blog_trackback']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
103
        if ($blog_obj->isNew()) {
104
            $blog_obj->setVar('blog_submitter', is_object($xoopsUser) ? $xoopsUser->getVar('uid') : PlanetUtility::planetGetIP(true));
105
        }
106
107
        if (!$blogHandler->insert($blog_obj)) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
108
        } elseif (0 !== count(Request::getArray('categories', [], 'POST'))) {
109
            $blog_id = $blog_obj->getVar('blog_id');
110
            if (in_array(0, $_POST['categories'])) {
111
                $_POST['categories'] = [];
112
            }
113
            $blogHandler->setCategories($blog_id, Request::getString('andor', '', 'POST'));//$_POST['categories']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% 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...
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
    // no break
120
    case 'edit':
121 View Code Duplication
    default:
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
        if (!empty(Request::getString('fetch', '', 'POST'))) {
123
            $blog_obj = $blogHandler->fetch(Request::getText('blog_feed', '', 'POST'));
124
            $blog_obj->setVar('blog_id', $blog_id);
125
        } else {
126
            $blog_obj = $blogHandler->get($blog_id);
127
        }
128
        $categories = Request::getArray('categories', [], 'POST');//isset($_POST['categories']) ? $_POST['categories'] : array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
81% 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...
129
        if (in_array('-1', $categories)) {
130
            $categories = [];
131
        }
132
        if (empty($categories) && $blog_id > 0) {
133
            $crit       = new Criteria('bc.blog_id', $blog_id);
134
            $categories = array_keys($categoryHandler->getByBlog($crit));
135
        }
136
        if (empty($categories)) {
137
            $categories = [0 => _NONE];
138
        }
139
140
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _EDIT . '</legend>';
141
        echo '<br>';
142
        if (empty($blog_id) && $blog_obj->getVar('blog_feed')) {
143
            $criteria  = new Criteria('blog_feed', $blog_obj->getVar('blog_feed'));
144
            $blogs_obj = $blogHandler->getList($criteria);
145
            if (count($blogs_obj) > 0) {
146
                echo "<div class=\"errorMsg\">" . planet_constant('MD_BLOGEXISTS');
147
                foreach (array_keys($blogs_obj) as $bid) {
148
                    echo "<br><a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . 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