Completed
Push — master ( 10fc3d...cbc6e7 )
by Michael
18s queued 10s
created

publisher_latest_news_show()   F

Complexity

Conditions 32
Paths > 20000

Size

Total Lines 216
Code Lines 134

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 32
eloc 134
nc 9437208
nop 1
dl 0
loc 216
rs 2
c 0
b 0
f 0

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
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         GNU GPL V2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package         Publisher
16
 * @subpackage      Blocks
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 * @author          Bandit-x
20
 * @author          Mowaffak
21
 * @version         $Id$
22
 */
23
24
include_once dirname(__DIR__) . '/include/common.php';
25
26
function publisher_latest_news_show($options)
27
{
28
    $xoops = Xoops::getInstance();
29
    $publisher = Publisher::getInstance();
30
    $publisher->loadLanguage('main');
31
32
    $block = array();
33
34
    $start = $options[0]; // You can show articles from specified range
35
    $limit = $options[1];
36
    $column_count = $options[2];
37
    $letters = $options[3];
38
    $selected_stories = $options[4];
39
    $sort = $options[9];
40
    $order = PublisherUtils::getOrderBy($sort);
41
    $imgwidth = $options[11];
42
    $imgheight = $options[12];
43
    $border = $options[13];
44
    $bordercolor = $options[14];
45
46
    $block['spec']['columnwidth'] = (int)(1 / $column_count * 100);
47
48
    $allcats = false;
49
    if (!isset($options[29])) {
50
        $allcats = true;
51
    } elseif (in_array(0, explode(',', $options[29]))) {
52
        $allcats = true;
53
    }
54
55
    // creating the ITEM objects that belong to the selected category
56
    if ($allcats) {
57
        $criteria = null;
58
    } else {
59
        $criteria = new CriteriaCompo();
60
        $criteria->add(new Criteria('categoryid', '(' . $options[29] . ')', 'IN'));
61
    }
62
63
    // Use specific ITEMS
64
    if ($selected_stories != 0) {
65
        unset($criteria); //removes category option
66
        $criteria = new CriteriaCompo();
67
        $criteria->add(new Criteria('itemid', '(' . $selected_stories . ')', 'IN'));
68
    }
69
70
    $itemsObj = $publisher->getItemHandler()->getItems($limit, $start, array(_PUBLISHER_STATUS_PUBLISHED), -1, $sort, $order, '', true, $criteria, 'itemid');
0 ignored issues
show
Bug introduced by
array(_PUBLISHER_STATUS_PUBLISHED) of type array<integer,integer> is incompatible with the type string expected by parameter $status of PublisherItemHandler::getItems(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
    $itemsObj = $publisher->getItemHandler()->getItems($limit, $start, /** @scrutinizer ignore-type */ array(_PUBLISHER_STATUS_PUBLISHED), -1, $sort, $order, '', true, $criteria, 'itemid');
Loading history...
Bug introduced by
It seems like $criteria can also be of type CriteriaCompo; however, parameter $otherCriteria of PublisherItemHandler::getItems() does only seem to accept null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
    $itemsObj = $publisher->getItemHandler()->getItems($limit, $start, array(_PUBLISHER_STATUS_PUBLISHED), -1, $sort, $order, '', true, /** @scrutinizer ignore-type */ $criteria, 'itemid');
Loading history...
71
72
    $scount = count($itemsObj);
73
74
    if ($scount == 0) {
75
        return false;
76
    }
77
    $k = 0;
78
    $columns = array();
79
80
    $thumbService = \Xoops::getInstance()->service('thumbnail');
81
82
    /* @var $itemObj PublisherItem */
83
    foreach ($itemsObj as $itemObj) {
84
        $item = array();
85
        $item['itemurl'] = $itemObj->getItemUrl();
86
        $item['title'] = $itemObj->getItemLink();
87
        $item['alt'] = strip_tags($itemObj->getItemLink());
88
        $mainImage = $itemObj->getMainImage();
89
        $item['item_image'] = $thumbService
90
            ->getImgUrl($mainImage['image_vpath'], $imgwidth, 0)
91
            ->getValue();
92
93
        $item['text'] = $itemObj->getBlockSummary($letters);
94
95
        $item = $itemObj->getMainImage($item); //returns an array
96
97
        $ls_height = '';
98
        if ($options[12] != 0) {
99
            $ls_height = 'height="' . $imgheight . '" ';
100
        }
101
102
        if ($options[15] === 'LEFT') {
103
            $imgposition = "float: left";
104
            $ls_margin = '-right';
105
        } elseif ($options[15] === 'CENTER') {
106
            $imgposition = "text-align:center";
107
            $ls_margin = '';
108
        } else {
109
            $imgposition = "float: right";
110
            $ls_margin = '-left';
111
        }
112
113
114
        //Image
115
        if ($options[10] == 1 && $item['image_path'] != '') {
116
            $startdiv = '<div style="' . $imgposition . '"><a href="' . $item['itemurl'] . '">';
117
            $style = 'style="margin' . $ls_margin . ': 10px; padding: 2px; border: ' . $border . 'px solid #' . $bordercolor . '"';
118
            $enddiv = 'width="' . $imgwidth . '" ' . $ls_height . '/></a></div>';
119
            $image = $startdiv . '<img ' . $style . ' src="' . $item['item_image'] . '" alt="' . $item['image_name'] . '" ' . $enddiv;
120
121
            $item['image'] = $image;
122
        }
123
124
        if ($publisher->isUserAdmin()) {
125
            $item['admin'] = "<a href='" . PUBLISHER_URL . "/submit.php?itemid=" . $itemObj->getVar('itemid'). "'><img src='" . PUBLISHER_URL . "/images/links/edit.gif'" . " title='" . _CO_PUBLISHER_EDIT . "' alt='" . _CO_PUBLISHER_EDIT . "' /></a>&nbsp;";
126
            $item['admin'] .= "<a href='" . PUBLISHER_URL . "/admin/item.php?op=del&amp;itemid=" . $itemObj->getVar('itemid'). "'><img src='" . PUBLISHER_URL . "/images/links/delete.png'" . " title='" . _CO_PUBLISHER_DELETE . "' alt='" . _CO_PUBLISHER_DELETE . "' /></a>";
127
        } else {
128
            $item['admin'] = '';
129
        }
130
131
        $block['topiclink'] = '';
132
        /*
133
        if ($options[16] == 1) {
134
         $block['topiclink'] = '| <a href="'.\XoopsBaseConfig::get('url').'/modules/news/topics_directory.php">'._AM_NEWS_TOPICS_DIRECTORY.'</a> ';
135
         }
136
         */
137
        $block['archivelink'] = '';
138
        if ($options[17] == 1) {
139
            $block['archivelink'] = '| <a href="' . PUBLISHER_URL . '/archive.php">' . _MB_PUBLISHER_ARCHIVE . '</a> ';
140
        }
141
142
        //TODO: Should we not show link to Anonymous?
143
        $block['submitlink'] = '';
144
        if ($options[18] == 1 && $xoops->isUser()) {
145
            $block['submitlink'] = '| <a href="' . PUBLISHER_URL . '/submit.php">' . _MB_PUBLISHER_SUBMITNEWS . '</a> ';
146
        }
147
148
        $item['poster'] = '';
149
        if ($options[19] == 1) {
150
            $item['poster'] = _MB_PUBLISHER_POSTER . ' ' . $itemObj->posterName();
151
        }
152
153
        $item['posttime'] = '';
154
        if ($options[20] == 1) {
155
            //todo, check this concatenation
156
            $item['posttime'] = strtolower(XoopsLocale::ON) . ' ' . $itemObj->datesub();
157
        }
158
159
        $item['topic_title'] = '';
160
        if ($options[21] == 1) {
161
            $item['topic_title'] = $itemObj->getCategoryLink() . _MB_PUBLISHER_SP;
162
        }
163
164
        $item['read'] = '';
165
        if ($options[22] == 1) {
166
            //todo, check this concatenation
167
            $item['read'] = '&nbsp;(' . $itemObj->getVar('counter') . ' ' . strtolower(XoopsLocale::READS) . ')';
168
        }
169
170
        $item['more'] = '';
171
        if ($itemObj->body() != '' || $itemObj->getVar('comments') > 0) {
172
            $item['more'] = '<a class="publisher_spotlight_readmore" href="' . $itemObj->getItemUrl() . '">' . _MB_PUBLISHER_READMORE . '</a>';
173
        }
174
175
        $comments = $itemObj->getVar('comments');
176
        if ($options[23] == 1) {
177
            if ($comments > 0) {
178
                //shows 1 comment instead of 1 comm. if comments ==1
179
                //langugage file modified accordingly
180
                if ($comments == 1) {
181
                    $item['comment'] = '&nbsp;' . _MB_PUBLISHER_ONECOMMENT . '&nbsp;';
182
                } else {
183
                    $item['comment'] = '&nbsp;' . $comments . '&nbsp;' . _MB_PUBLISHER_COMMENTS . '&nbsp;';
184
                }
185
            } else {
186
                $item['comment'] = '&nbsp;' . _MB_PUBLISHER_NO_COMMENTS . '&nbsp;';
187
            }
188
        }
189
190
        $item['print'] = '';
191
        if ($options[24] == 1) {
192
            $item['print'] = '<a href="' . PublisherUtils::seoGenUrl("print", $itemObj->getVar('itemid'), $itemObj->getVar('short_url')) . '" rel="nofollow"><img src="' . PUBLISHER_URL . '/images/links/print.gif" title="' . _CO_PUBLISHER_PRINT . '" alt="' . _CO_PUBLISHER_PRINT . '" /></a>&nbsp;';
193
        }
194
195
        $item['pdf'] = '';
196
        if ($options[25] == 1) {
197
            $item['pdf'] = "<a href='" . PUBLISHER_URL . "/makepdf.php?itemid=" . $itemObj->getVar('itemid'). "' rel='nofollow'><img src='" . PUBLISHER_URL . "/images/links/pdf.gif' title='" . _CO_PUBLISHER_PDF . "' alt='" . _CO_PUBLISHER_PDF . "' /></a>&nbsp;";
198
        }
199
200
        $item['email'] = '';
201
        if ($options[26] == 1 && $xoops->isActiveModule('tellafriend')) {
202
            $subject = sprintf(_CO_PUBLISHER_INTITEMFOUND, $xoops->getConfig('sitename'));
203
            $subject = $itemObj->_convert_for_japanese($subject);
204
            $maillink = PublisherUtils::tellafriend($subject);
205
206
            $item['email'] = '<a href="' . $maillink . '"><img src="' . PUBLISHER_URL . '/images/links/friend.gif" title="' . _CO_PUBLISHER_MAIL . '" alt="' . _CO_PUBLISHER_MAIL . '" /></a>&nbsp;';
207
        }
208
209
        $block['morelink'] = '';
210
        if ($options[27] == 1) {
211
            $block['morelink'] = '<a href="' . PUBLISHER_URL . '/index.php">' . _MB_PUBLISHER_MORE_ITEMS . '</a> ';
212
        }
213
214
        $block['latestnews_scroll'] = false;
215
        if ($options[5] == 1) {
216
            $block['latestnews_scroll'] = true;
217
        }
218
219
        $block['scrollheight'] = $options[6];
220
        $block['scrollspeed'] = $options[7];
221
        $block['scrolldir'] = $options[8];
222
223
        $block['template'] = $options[28];
224
225
        $block['imgwidth'] = $options[11];
226
        $block['imgheight'] = $options[12];
227
228
        $block['letters'] = $letters;
229
230
        $columns[$k][] = $item;
231
        ++$k;
232
233
        if ($k == $column_count) {
234
            $k = 0;
235
        }
236
    }
237
238
    unset($item);
239
    $block['columns'] = $columns;
240
241
    return $block;
242
}
243
244
function publisher_latest_news_edit($options)
245
{
246
    $tabletag1 = '<tr><td style="padding:3px" width="37%">';
247
    $tabletag2 = '</td><td style="padding:3px">';
248
    $tabletag3 = '<tr><td style="padding-top:20px;border-bottom:1px solid #000" colspan="2">';
249
    $tabletag4 = '</td></tr>';
250
251
    $form = "<table border='0' cellpadding='0' cellspacing='0'>";
252
    $form .= $tabletag3 . _MB_PUBLISHER_GENERALCONFIG . $tabletag4; // General Options
253
    $form .= $tabletag1 . _MB_PUBLISHER_FIRST . $tabletag2;
254
    $form .= "<input type='text' name='options[]' value='" . $options[0] . "' size='4'>&nbsp;" . _MB_PUBLISHER_ITEMS . "</td></tr>";
255
    $form .= $tabletag1 . _MB_PUBLISHER_DISP . $tabletag2;
256
    $form .= "<input type='text' name='options[]' value='" . $options[1] . "' size='4'>&nbsp;" . _MB_PUBLISHER_ITEMS . "</td></tr>";
257
    $form .= $tabletag1 . _MB_PUBLISHER_COLUMNS . $tabletag2;
258
    $form .= "<input type='text' name='options[]' value='" . $options[2] . "' size='4'>&nbsp;" . _MB_PUBLISHER_COLUMN . "</td></tr>";
259
    $form .= $tabletag1 . _MB_PUBLISHER_TEXTLENGTH . $tabletag2;
260
    $form .= "<input type='text' name='options[]' value='" . $options[3] . "' size='4'>&nbsp;" . _MB_PUBLISHER_LETTER . "</td></tr>";
261
    $form .= $tabletag1 . _MB_PUBLISHER_SELECTEDSTORIES . $tabletag2;
262
    $form .= "<input type='text' name='options[]' value='" . $options[4] . "' size='16'></td></tr>";
263
    $form .= $tabletag1 . _MB_PUBLISHER_SCROLL . $tabletag2;
264
    $form .= publisher_mk_chkbox($options, 5);
265
    $form .= $tabletag1 . _MB_PUBLISHER_SCROLLHEIGHT . $tabletag2;
266
    $form .= "<input type='text' name='options[]' value='" . $options[6] . "' size='4'></td></tr>";
267
    $form .= $tabletag1 . _MB_PUBLISHER_SCROLLSPEED . $tabletag2;
268
    $form .= "<input type='text' name='options[]' value='" . $options[7] . "' size='4'></td></tr>";
269
    $form .= $tabletag1 . _MB_PUBLISHER_SCROLLDIR . $tabletag2;
270
271
    $form .= "<select size='1' name='options[8]'>";
272
273
    $directions = array('right' => _MB_PUBLISHER_SCROLL_RIGHT, 'left' => _MB_PUBLISHER_SCROLL_LEFT, 'up' => _MB_PUBLISHER_SCROLL_UP, 'down' => _MB_PUBLISHER_SCROLL_DOWN);
274
    foreach ($directions as $key => $value) {
275
        $form .= "<option value='{$key}'";
276
        if ($options[8] == $key) {
277
            $form .= " selected='selected'";
278
        }
279
        $form .= ">{$value}</option>";
280
    }
281
    $form .= "</select></td></tr>";
282
283
    $form .= $tabletag1 . _MB_PUBLISHER_ORDER . $tabletag2;
284
285
    $form .= "<select name='options[9]'>";
286
    $form .= "<option value='datesub'";
287
    if ($options[9] === "datesub") {
288
        $form .= " selected='selected'";
289
    }
290
    $form .= ">" . _MB_PUBLISHER_DATE . "</option>";
291
292
    $form .= "<option value='counter'";
293
    if ($options[9] === "counter") {
294
        $form .= " selected='selected'";
295
    }
296
    $form .= ">" . _MB_PUBLISHER_HITS . "</option>";
297
298
    $form .= "<option value='weight'";
299
    if ($options[9] === "weight") {
300
        $form .= " selected='selected'";
301
    }
302
    $form .= ">" . _MB_PUBLISHER_WEIGHT . "</option>";
303
304
    $form .= "</select></td></tr>";
305
306
    $form .= $tabletag3 . _MB_PUBLISHER_PHOTOSCONFIG . $tabletag4; // Photos Options
307
    $form .= $tabletag1 . _MB_PUBLISHER_IMGDISPLAY . $tabletag2;
308
    $form .= publisher_mk_chkbox($options, 10);
309
    $form .= $tabletag1 . _MB_PUBLISHER_IMGWIDTH . $tabletag2;
310
    $form .= "<input type='text' name='options[]' value='" . $options[11] . "' size='4'>&nbsp;" . _MB_PUBLISHER_PIXEL . "</td></tr>";
311
    $form .= $tabletag1 . _MB_PUBLISHER_IMGHEIGHT . $tabletag2;
312
    $form .= "<input type='text' name='options[]' value='" . $options[12] . "' size='4'>&nbsp;" . _MB_PUBLISHER_PIXEL . "</td></tr>";
313
    $form .= $tabletag1 . _MB_PUBLISHER_BORDER . $tabletag2;
314
    $form .= "<input type='text' name='options[]' value='" . $options[13] . "' size='4'>&nbsp;" . _MB_PUBLISHER_PIXEL . "</td></tr>";
315
    $form .= $tabletag1 . _MB_PUBLISHER_BORDERCOLOR . $tabletag2;
316
    $form .= "<input type='text' name='options[]' value='" . $options[14] . "' size='8'></td></tr>";
317
    $form .= $tabletag1 . _MB_PUBLISHER_IMGPOSITION . $tabletag2;
318
    $form .= "<select name='options[]'>";
319
    $form .= "<option value='LEFT'";
320
    if ($options[15] === 'LEFT') {
321
        $form .= " selected='selected'";
322
    }
323
    $form .= '>' . XoopsLocale::LEFT . "</option>\n";
324
325
    $form .= "<option value='CENTER'";
326
    if ($options[15] === 'CENTER') {
327
        $form .= " selected='selected'";
328
    }
329
    $form .= '>' . XoopsLocale::CENTER . "</option>\n";
330
331
    $form .= "<option value='RIGHT'";
332
    if ($options[15] === 'RIGHT') {
333
        $form .= " selected='selected'";
334
    }
335
    $form .= '>' . XoopsLocale::RIGHT . '</option>';
336
    $form .= "</select></td></tr>";
337
338
    $form .= $tabletag3 . _MB_PUBLISHER_LINKSCONFIG . $tabletag4; // Links Options
339
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_TOPICLINK . $tabletag2;
340
    $form .= publisher_mk_chkbox($options, 16);
341
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_ARCHIVELINK . $tabletag2;
342
    $form .= publisher_mk_chkbox($options, 17);
343
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_SUBMITLINK . $tabletag2;
344
    $form .= publisher_mk_chkbox($options, 18);
345
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_POSTEDBY . $tabletag2;
346
    $form .= publisher_mk_chkbox($options, 19);
347
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_POSTTIME . $tabletag2;
348
    $form .= publisher_mk_chkbox($options, 20);
349
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_TOPICTITLE . $tabletag2;
350
    $form .= publisher_mk_chkbox($options, 21);
351
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_READ . $tabletag2;
352
    $form .= publisher_mk_chkbox($options, 22);
353
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_COMMENT . $tabletag2;
354
    $form .= publisher_mk_chkbox($options, 23);
355
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_PRINT . $tabletag2;
356
    $form .= publisher_mk_chkbox($options, 24);
357
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_PDF . $tabletag2;
358
    $form .= publisher_mk_chkbox($options, 25);
359
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_EMAIL . $tabletag2;
360
    $form .= publisher_mk_chkbox($options, 26);
361
    $form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_MORELINK . $tabletag2;
362
    $form .= publisher_mk_chkbox($options, 27);
363
364
365
    $form .= $tabletag3 . _MB_PUBLISHER_TEMPLATESCONFIG . $tabletag4; // Templates Options
366
    $form .= $tabletag1 . _MB_PUBLISHER_TEMPLATE . $tabletag2;
367
    $form .= "<select size='1' name='options[28]'>";
368
369
    $templates = array('normal' => _MB_PUBLISHER_TEMPLATE_NORMAL, 'extended' => _MB_PUBLISHER_TEMPLATE_EXTENDED, 'ticker' => _MB_PUBLISHER_TEMPLATE_TICKER, 'slider1' => _MB_PUBLISHER_TEMPLATE_SLIDER1, 'slider2' => _MB_PUBLISHER_TEMPLATE_SLIDER2);
370
    foreach ($templates as $key => $value) {
371
        $form .= "<option value='{$key}'";
372
        if ($options[28] == $key) {
373
            $form .= " selected='selected'";
374
        }
375
        $form .= ">{$value}</option>";
376
    }
377
    $form .= "</select></td></tr>";
378
379
    //Select Which Categories To Show
380
    $form .= $tabletag3 . _MB_PUBLISHER_TOPICSCONFIG . $tabletag4; // Topics Options
381
    $form .= $tabletag1 . _MB_PUBLISHER_TOPICSDISPLAY . $tabletag2;
382
    $form .= PublisherUtils::createCategorySelect($options[29], 0, true, 'options[29]');
383
    $form .= '</td></tr>';
384
385
    $form .= "</table>";
386
    return $form;
387
}
388
389
function publisher_mk_chkbox($options, $number)
390
{
391
    $chk = "";
392
    if ($options[$number] == 1) {
393
        $chk = " checked='checked'";
394
    }
395
    $chkbox = "<input type='radio' name='options[{$number}]' value='1'" . $chk . " />&nbsp;" . XoopsLocale::YES . "&nbsp;&nbsp;";
396
    $chk = "";
397
    if ($options[$number] == 0) {
398
        $chk = " checked='checked'";
399
    }
400
    $chkbox .= "<input type='radio' name='options[{$number}]' value='0'" . $chk . " />&nbsp;" . XoopsLocale::NO . "</td></tr>";
401
    return $chkbox;
402
}
403
404
function publisher_mk_select($options, $number)
405
{
406
    $slc = "";
407
    if ($options[$number] == 2) {
408
        $slc = " checked='checked'";
409
    }
410
    $select = "<input type='radio' name='options[{$number}]' value='2'" . $slc . " />&nbsp;" . XoopsLocale::LEFT . "&nbsp;&nbsp;";
411
    $slc = "";
412
    if ($options[$number] == 1) {
413
        $slc = " checked='checked'";
414
    }
415
    $select .= "<input type='radio' name='options[{$number}]' value='1'" . $slc . " />&nbsp;" . XoopsLocale::CENTER . "&nbsp;&nbsp;";
416
    $slc = "";
417
    if ($options[$number] == 0) {
418
        $slc = " checked='checked'";
419
    }
420
    $select .= "<input type='radio' name='options[{$number}]' value='0'" . $slc . " />&nbsp;" . XoopsLocale::RIGHT . "</td></tr>";
421
    return $select;
422
}
423