Completed
Push — master ( 53ea58...16270d )
by Michael
04:51
created

items_new.php ➔ publisher_items_new_show()   D

Complexity

Conditions 22
Paths 8

Size

Total Lines 98
Code Lines 69

Duplication

Lines 19
Ratio 19.39 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 22
eloc 69
c 1
b 0
f 0
nc 8
nop 1
dl 19
loc 98
rs 4.6625

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
14
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @package         Publisher
16
 * @subpackage      Blocks
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 * @author          The SmartFactory <www.smartfactory.ca>
20
 */
21
22
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
23
24
include_once dirname(__DIR__) . '/include/common.php';
25
26
/**
27
 * @param $options
28
 *
29
 * @return array
30
 */
31
function publisher_items_new_show($options)
32
{
33
    $publisher = PublisherPublisher::getInstance();
34
35
    $selectedcatids = explode(',', $options[0]);
36
37
    $block   = array();
38
    $allcats = false;
39
    if (in_array(0, $selectedcatids)) {
40
        $allcats = true;
41
    }
42
43
    $sort  = $options[1];
44
    $order = publisherGetOrderBy($sort);
45
    $limit = $options[3];
46
    $start = 0;
47
    $image = $options[5];
48
49
    // creating the ITEM objects that belong to the selected category
50 View Code Duplication
    if ($allcats) {
0 ignored issues
show
Duplication introduced by
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...
51
        $criteria = null;
52
    } else {
53
        $criteria = new CriteriaCompo();
54
        $criteria->add(new Criteria('categoryid', '(' . $options[0] . ')', 'IN'));
55
    }
56
    $itemsObj = $publisher->getHandler('item')->getItems($limit, $start, array(PublisherConstants::PUBLISHER_STATUS_PUBLISHED), -1, $sort, $order, '', true, $criteria, true);
57
58
    $totalitems = count($itemsObj);
59
    if ($itemsObj && $totalitems > 1) {
60
        for ($i = 0; $i < $totalitems; ++$i) {
61
            $item           = array();
62
            $item['link']   = $itemsObj[$i]->getItemLink(false, isset($options[4]) ? $options[4] : 65);
63
            $item['id']     = $itemsObj[$i]->itemid();
64
            $item['poster'] = $itemsObj[$i]->posterName(); // for make poster name linked, use getLinkedPosterName() instead of posterName()
65
66
            if ('article' === $image) {
67
                $item['image']      = XOOPS_URL . '/uploads/blank.gif';
68
                $item['image_name'] = '';
69
                $images             = $itemsObj[$i]->getImages();
70
                if (is_object($images['main'])) {
71
                    // check to see if GD function exist
72 View Code Duplication
                    if (!function_exists('imagecreatetruecolor')) {
0 ignored issues
show
Duplication introduced by
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...
73
                        $item['image'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name');
74
                    } else {
75
                        $item['image'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name') . '&amp;w=50';
76
                    }
77
                    $item['image_name'] = $images['main']->getVar('image_nicename');
78
                }
79
            } elseif ('category' === $image) {
80
                $item['image']      = $itemsObj[$i]->getCategoryImagePath();
81
                $item['image_name'] = $itemsObj[$i]->getCategoryName();
82
            } elseif ('avatar' === $image) {
83
                if ($itemsObj[$i]->uid() == '0') {
84
                    $item['image'] = XOOPS_URL . '/uploads/blank.gif';
85
                    $images        = $itemsObj[$i]->getImages();
86 View Code Duplication
                    if (is_object($images['main'])) {
0 ignored issues
show
Duplication introduced by
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...
87
                        // check to see if GD function exist
88
                        if (!function_exists('imagecreatetruecolor')) {
89
                            $item['image'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name');
90
                        } else {
91
                            $item['image'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name') . '&amp;w=50';
92
                        }
93
                    }
94
                } else {
95
                    // check to see if GD function exist
96
                    if (!function_exists('imagecreatetruecolor')) {
97
                        $item['image'] = XOOPS_URL . '/uploads/' . $itemsObj[$i]->posterAvatar();
98
                    } else {
99
                        $item['image'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $itemsObj[$i]->posterAvatar() . '&amp;w=50';
100
                    }
101
                }
102
                $item['image_name'] = $itemsObj[$i]->posterName();
103
            }
104
105
            $item['title'] = $itemsObj[$i]->getTitle();
106
107
            if ('datesub' === $sort) {
108
                $item['new'] = $itemsObj[$i]->getDatesub();
109
            } elseif ('counter' === $sort) {
110
                $item['new'] = $itemsObj[$i]->counter();
111
            } elseif ('weight' === $sort) {
112
                $item['new'] = $itemsObj[$i]->weight();
113
            } elseif ('rating' === $sort) {
114
                $item['new'] = $itemsObj[$i]->rating();
115
            } elseif ('votes' === $sort) {
116
                $item['new'] = $itemsObj[$i]->votes();
117
            } elseif ('comments' === $sort) {
118
                $item['new'] = $itemsObj[$i]->comments();
119
            }
120
121
            $block['newitems'][] = $item;
122
        }
123
    }
124
125
    $block['show_order'] = $options[2];
126
127
    return $block;
128
}
129
130
/**
131
 * @param $options
132
 *
133
 * @return string
134
 */
135
function publisher_items_new_edit($options)
136
{
137
    include_once PUBLISHER_ROOT_PATH . '/class/blockform.php';
138
    xoops_load('XoopsFormLoader');
139
140
    $form = new PublisherBlockForm();
141
142
    $catEle   = new XoopsFormLabel(_MB_PUBLISHER_SELECTCAT, publisherCreateCategorySelect($options[0], 0, true, 'options[0]'));
143
    $orderEle = new XoopsFormSelect(_MB_PUBLISHER_ORDER, 'options[1]', $options[1]);
144
    $orderEle->addOptionArray(array(
145
                                  'datesub'  => _MB_PUBLISHER_DATE,
146
                                  'counter'  => _MB_PUBLISHER_HITS,
147
                                  'weight'   => _MB_PUBLISHER_WEIGHT,
148
                                  'rating'   => _MI_PUBLISHER_ORDERBY_RATING,
149
                                  'votes'    => _MI_PUBLISHER_ORDERBY_VOTES,
150
                                  'comments' => _MI_PUBLISHER_ORDERBY_COMMENTS));
151
152
    $showEle  = new XoopsFormRadioYN(_MB_PUBLISHER_ORDER_SHOW, 'options[2]', $options[2]);
153
    $dispEle  = new XoopsFormText(_MB_PUBLISHER_DISP, 'options[3]', 10, 255, $options[3]);
154
    $charsEle = new XoopsFormText(_MB_PUBLISHER_CHARS, 'options[4]', 10, 255, $options[4]);
155
156
    $imageEle = new XoopsFormSelect(_MB_PUBLISHER_IMAGE_TO_DISPLAY, 'options[5]', $options[5]);
157
    $imageEle->addOptionArray(array(
158
                                  'none'     => _NONE,
159
                                  'article'  => _MB_PUBLISHER_IMAGE_ARTICLE,
160
                                  'category' => _MB_PUBLISHER_IMAGE_CATEGORY,
161
                                  'avatar'   => _MB_PUBLISHER_IMAGE_AVATAR));
162
163
    $form->addElement($catEle);
164
    $form->addElement($orderEle);
165
    $form->addElement($showEle);
166
    $form->addElement($dispEle);
167
    $form->addElement($charsEle);
168
    $form->addElement($imageEle);
169
170
    return $form->render();
171
}
172