Completed
Push — master ( 804154...96da4e )
by Michael
02:32
created

view.article.php (6 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
include __DIR__ . '/header.php';
28
29
/**
30
 * The comment detection scripts should be removed once absolute url is used in comment_view.php
31
 * The notification detection scripts should be removed once absolute url is used in notification_select.php
32
 *
33
 */
34
if (preg_match("/(\/comment_[^\.]*\.php\?.*=.*)/i", $_SERVER['REQUEST_URI'], $matches)) {
35
    header('location: ' . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . $matches[1]);
36
    exit();
37
}
38
if (preg_match("/\/notification_update\.php/i", $_SERVER['REQUEST_URI'], $matches)) {
39
    include XOOPS_ROOT_PATH . '/include/notification_update.php';
40
    exit();
41
}
42
43 View Code Duplication
if ($REQUEST_URI_parsed = planet_parse_args($args_num, $args, $args_str)) {
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...
44
    $args['article'] = @$args_num[0];
45
    $args['blog']    = @$args['blog'];
46
}
47
48
$article_id = (int)(empty($_GET['article']) ? @$args['article'] : $_GET['article']);
49
$blog_id    = (int)(empty($_GET['blog']) ? @$args['blog'] : $_GET['blog']);
50
51
$article_handler = xoops_getModuleHandler('article', $GLOBALS['moddirname']);
52
$blog_handler    = xoops_getModuleHandler('blog', $GLOBALS['moddirname']);
53
$article_obj     =& $article_handler->get($article_id);
54
$blog_obj        =& $blog_handler->get($article_obj->getVar('blog_id'));
55
56
// restore $_SERVER['REQUEST_URI']
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
57
if (!empty($REQUEST_URI_parsed)) {
58
    $_SERVER['REQUEST_URI'] = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php'
59
                              . (empty($article_id) ? '' : '?article=' . $article_id);
60
}
61
62
$xoopsOption['xoops_pagetitle'] = $xoopsModule->getVar('name') . ' - ' . $article_obj->getVar('art_title');
63
$xoopsOption['template_main']   = planet_getTemplate('article');
64
include_once XOOPS_ROOT_PATH . '/header.php';
65
include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/vars.php';
66
67
$article_data = array(
68
    'id'       => $article_id,
69
    'title'    => $article_obj->getVar('art_title'),
70
    'content'  => $article_obj->getVar('art_content'),
71
    'author'   => $article_obj->getVar('art_author'),
72
    'time'     => $article_obj->getTime(),
73
    'link'     => $article_obj->getVar('art_link'),
74
    'views'    => $article_obj->getVar('art_views'),
75
    'comments' => $article_obj->getVar('art_comments'),
76
    'star'     => $article_obj->getStar(),
77
    'rates'    => $article_obj->getVar('art_rates'),
78
    'blog'     => array('id' => $article_obj->getVar('blog_id'), 'title' => $blog_obj->getVar('blog_title'))
79
);
80
81
if (!empty($xoopsModuleConfig['do_sibling'])) {
82
    $articles_sibling =& $article_handler->getSibling($article_obj, $blog_id);
83 View Code Duplication
    if (!empty($articles_sibling['previous'])) {
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...
84
        $articles_sibling['previous']['url']   = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php'
85
                                                 . URL_DELIMITER . '' . $articles_sibling['previous']['id'] . '/b'
86
                                                 . $blog_id;
87
        $articles_sibling['previous']['title'] = $articles_sibling['previous']['title'];
88
    }
89 View Code Duplication
    if (!empty($articles_sibling['next'])) {
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...
90
        $articles_sibling['next']['url']   = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php'
91
                                             . URL_DELIMITER . '' . $articles_sibling['next']['id'] . '/b' . $blog_id;
92
        $articles_sibling['next']['title'] = $articles_sibling['next']['title'];
93
    }
94
}
95
96
$xoopsTpl->assign('modulename', $xoopsModule->getVar('name'));
97
98
$xoopsTpl->assign('article', $article_data);
99
$xoopsTpl->assign('sibling', $articles_sibling);
100
101
$xoopsTpl->assign('user_level', !is_object($xoopsUser) ? 0 : ($xoopsUser->isAdmin() ? 2 : 1));
102
if (empty($xoopsModuleConfig['anonymous_rate']) && !is_object($xoopsUser)) {
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...
103
} else {
104
    $xoopsTpl->assign('canrate', 1);
105
}
106
107
if ($transferbar = @include XOOPS_ROOT_PATH . '/Frameworks/transfer/bar.transfer.php') {
108
    $xoopsTpl->assign('transfer', $transferbar);
109
}
110
111
// Loading module meta data, NOT THE RIGHT WAY DOING IT
112
$xoopsTpl->assign('xoops_pagetitle', $xoopsOption['xoops_pagetitle']);
113
114
// for comment and notification
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% 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...
115
//$_SERVER['REQUEST_URI'] = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/view.article.php";
116
$_GET['article'] = $article_id;
117
include XOOPS_ROOT_PATH . '/include/comment_view.php';
118
119
include_once __DIR__ . '/footer.php';
120