Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

extgallery_blocks.php ➔ extgalleryBlockEdit()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 150
Code Lines 123

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 123
nc 2
nop 1
dl 0
loc 150
rs 8.2857
c 0
b 0
f 0

How to fix   Long Method   

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
 * ExtGallery Block settings
4
 * Manage all Blocks
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright   {@link https://xoops.org/ XOOPS Project}
14
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
15
 * @author      Zoullou (http://www.zoullou.net)
16
 * @package     ExtGallery
17
 * @param $options
18
 * @return array
19
 */
20
21
// Manage photo blocks
22
function extgalleryPhotoShow($options)
23
{
24
    global $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
25
    $photos = [];
26
27
    /** @var ExtgalleryPhotoHandler $photoHandler */
28
    $photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery');
29
30
    $param                = ['limit' => $options[0]];
31
    $direction            = $options[1];
32
    $title                = $options[2];
33
    $photoHandlertype     = $options[3];
34
    $jquery               = $options[4];
35
    $ajaxeffect           = $options[5];
36
    $overlyabg            = $options[6];
37
    $overlyaw             = $options[7];
38
    $overlyah             = $options[8];
39
    $tooltipw             = $options[9];
40
    $tooltipbw            = $options[10];
41
    $tooltipbbg           = $options[11];
42
    $fancyboxbg           = $options[12];
43
    $fancyboxop           = $options[13];
44
    $fancyboxtin          = $options[14];
45
    $fancyboxtout         = $options[15];
46
    $fancyboxtp           = $options[16];
47
    $fancyboxshow         = $options[17];
48
    $prettyphotospeed     = $options[18];
49
    $prettyphototheme     = $options[19];
50
    $prettyphotoslidspeed = $options[20];
51
    $prettyphotoautoplay  = $options[21];
52
    $jcarouselhwidth      = $options[22];
53
    $jcarouselvwidth      = $options[23];
54
    $jcarouselvheight     = $options[24];
55
    $column               = $options[25];
56
57
    array_shift($options);
58
    array_shift($options);
59
    array_shift($options);
60
    array_shift($options);
61
    array_shift($options);
62
    array_shift($options);
63
    array_shift($options);
64
    array_shift($options);
65
    array_shift($options);
66
    array_shift($options);
67
    array_shift($options);
68
    array_shift($options);
69
    array_shift($options);
70
    array_shift($options);
71
    array_shift($options);
72
    array_shift($options);
73
    array_shift($options);
74
    array_shift($options);
75
    array_shift($options);
76
    array_shift($options);
77
    array_shift($options);
78
    array_shift($options);
79
    array_shift($options);
80
    array_shift($options);
81
    array_shift($options);
82
    array_shift($options);
83
84
    $categories = [];
85
    foreach ($options as $cat) {
86
        if (0 == $cat) {
87
            $categories = [];
88
            break;
89
        }
90
        $categories[] = $cat;
91
    }
92
    $param['cat'] = $categories;
93
94 View Code Duplication
    switch ($photoHandlertype) {
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...
95
        case 'RandomPhoto':
96
            $photos = $photoHandler->objectToArray($photoHandler->getRandomPhoto($param));
97
            break;
98
99
        case 'LastPhoto':
100
            $photos = $photoHandler->objectToArray($photoHandler->getLastPhoto($param));
101
            break;
102
103
        case 'TopViewPhoto':
104
            $photos = $photoHandler->objectToArray($photoHandler->getTopViewPhoto($param));
105
            break;
106
107
        case 'TopRatedPhoto':
108
            $photos = $photoHandler->objectToArray($photoHandler->getTopRatedPhoto($param));
109
            break;
110
111
        case 'TopEcardPhoto':
112
            $photos = $photoHandler->objectToArray($photoHandler->getTopEcardPhoto($param));
113
            break;
114
    }
115
116
    if ('true' === $jquery && 'none' !== $ajaxeffect) {
117
        global $xoTheme;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
118
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
119
120
        switch ($ajaxeffect) {
121
            case 'lightbox':
122
                $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
123
                $xoTheme->addStylesheet('browse.php?modules/system/css/lightbox.css');
124
                break;
125
            case 'tooltip':
126
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/tooltip/image.tooltip.js');
127
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/tooltip/image.tooltip.css');
128
                break;
129
            case 'overlay':
130
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/overlay/overlay.jquery.tools.min.js');
131
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/overlay/overlay.css');
132
                break;
133
            case 'fancybox':
134
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/fancybox/mousewheel.js');
135
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/fancybox/fancybox.pack.js');
136
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/fancybox/fancybox.css');
137
                break;
138
            case 'prettyphoto':
139
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/prettyphoto/jquery.prettyPhoto.js');
140
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/prettyphoto/prettyPhoto.css');
141
                break;
142
            case 'jcarousel':
143
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/jcarousel/jquery.jcarousel.min.js');
144
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/jcarousel/skin.css');
145
                break;
146
            case 'TosRUs':
147
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/TosRUs/src/js/jquery.tosrus.js');
148
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/TosRUs/src/css/jquery.tosrus.css');
149
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/TosRUs/lib/jquery.hammer.min.js');
150
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/TosRUs/lib/FlameViewportScale.js');
151
                break;
152
        }
153
    }
154
155
    if (0 == count($photos)) {
156
        return [];
157
    }
158
159
    $ret = [
160
        'photos'               => $photos,
161
        'column'               => $column,
162
        'direction'            => $direction,
163
        'title'                => $title,
164
        'jquery'               => $jquery,
165
        'ajaxeffect'           => $ajaxeffect,
166
        'overlyabg'            => $overlyabg,
167
        'overlyaw'             => $overlyaw,
168
        'overlyah'             => $overlyah,
169
        'tooltipw'             => $tooltipw,
170
        'tooltipbw'            => $tooltipbw,
171
        'tooltipbbg'           => $tooltipbbg,
172
        'fancyboxbg'           => $fancyboxbg,
173
        'fancyboxop'           => $fancyboxop,
174
        'fancyboxtin'          => $fancyboxtin,
175
        'fancyboxtout'         => $fancyboxtout,
176
        'fancyboxtp'           => $fancyboxtp,
177
        'fancyboxshow'         => $fancyboxshow,
178
        'prettyphotospeed'     => $prettyphotospeed,
179
        'prettyphototheme'     => $prettyphototheme,
180
        'prettyphotoslidspeed' => $prettyphotoslidspeed,
181
        'prettyphotoautoplay'  => $prettyphotoautoplay,
182
        'jcarouselhwidth'      => $jcarouselhwidth,
183
        'jcarouselvwidth'      => $jcarouselvwidth,
184
        'jcarouselvheight'     => $jcarouselvheight
185
    ];
186
187
    return $ret;
188
}
189
190
// converts a 2D array in a comma separated list (or separator of our choice)
191
/**
192
 * @param $sep
193
 * @param $array
194
 *
195
 * @return string
196
 */
197
function implodeArray2Dextgallery($sep, $array)
198
{
199
    $num = count($array);
200
    $str = '';
201
    for ($i = 0; $i < $num; ++$i) {
202
        if ($i) {
203
            $str .= $sep;
204
        }
205
        $str .= $array[$i];
206
    }
207
208
    return $str;
209
}
210
211
// Manage Top Submitter blocks
212
/**
213
 * @param $options
214
 *
215
 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
216
 */
217
function extgalleryTopSubmitterShow($options)
218
{
219
    global $xoopsDB, $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
220
    $catauth = '';
221
    $block   = [];
222
    if (0 != $options[1]) {
223
        $cat     = array_slice($options, 1); //Get information about categories to display
224
        $catauth = implodeArray2Dextgallery(',', $cat); //Creation of categories list to use - separated by a coma
225
    }
226
    $sql = 'SELECT uid, count(photo_id) AS countphoto FROM ' . $xoopsDB->prefix('extgallery_publicphoto');
227
    $sql .= ' WHERE (uid>0)';
228
    if (0 != $options[1]) {
229
        $sql .= ' AND cat_id IN (' . $catauth . ')';
230
    }
231
    $sql .= ' GROUP BY uid ORDER BY countphoto DESC';
232
    if ((int)$options[0] > 0) {
233
        $sql .= ' LIMIT ' . (int)$options[0];
234
    }
235
    $result = $xoopsDB->query($sql);
236
    if (!$result) {
237
        return '';
238
    }
239
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
240
        $uid                  = $myrow['uid'];
241
        $countphoto           = $myrow['countphoto'];
242
        $uname                = XoopsUser::getUnameFromId($myrow['uid']);
243
        $block['designers'][] = ['uid' => $uid, 'uname' => $uname, 'countphoto' => $countphoto];
244
    }
245
246
    return $block;
247
}
248
249
// Manage Ajax photos
250
/**
251
 * @param $options
252
 *
253
 * @return array
254
 */
255
function extgalleryAjax($options)
256
{
257
    /** @var ExtgalleryPhotoHandler $photoHandler */
258
    $photoHandler       = xoops_getModuleHandler('publicphoto', 'extgallery');
259
    $param              = ['limit' => $options[0]];
260
    $photoHandlertype   = $options[1];
261
    $jquery             = $options[2];
262
    $ajaxeffect         = $options[3];
263
    $panel_width        = $options[4];
264
    $panel_height       = $options[5];
265
    $frame_width        = $options[6];
266
    $frame_height       = $options[7];
267
    $background_color   = $options[8];
268
    $transition_speed   = $options[9];
269
    $ransition_interval = $options[10];
270
    $overlay_height     = $options[11];
271
    $overlay_color      = $options[12];
272
    $overlay_text_color = $options[13];
273
    $caption_text_color = $options[14];
274
    $border             = $options[15];
275
    $overlay_opacity    = $options[16];
276
    $overlay_font_size  = $options[17];
277
    $nav_theme          = $options[18];
278
    $position           = $options[19];
279
    $easing             = $options[20];
280
    $gria_panelwidth    = $options[21];
281
    $gria_height        = $options[22];
282
    $gria_bgcolor       = $options[23];
283
    $gria_bcolor        = $options[24];
284
    $gria_bgimg         = $options[25];
285
    $gria_autoplay      = $options[26];
286
    $gria_transition    = $options[27];
287
    $gria_tspeed        = $options[28];
288
    $micro_size         = $options[29];
289
290
    array_shift($options);
291
    array_shift($options);
292
    array_shift($options);
293
    array_shift($options);
294
    array_shift($options);
295
    array_shift($options);
296
    array_shift($options);
297
    array_shift($options);
298
    array_shift($options);
299
    array_shift($options);
300
    array_shift($options);
301
    array_shift($options);
302
    array_shift($options);
303
    array_shift($options);
304
    array_shift($options);
305
    array_shift($options);
306
    array_shift($options);
307
    array_shift($options);
308
    array_shift($options);
309
    array_shift($options);
310
    array_shift($options);
311
    array_shift($options);
312
    array_shift($options);
313
    array_shift($options);
314
    array_shift($options);
315
    array_shift($options);
316
    array_shift($options);
317
    array_shift($options);
318
    array_shift($options);
319
    array_shift($options);
320
321
    $categories = [];
322
    foreach ($options as $cat) {
323
        if (0 == $cat) {
324
            $categories = [];
325
            break;
326
        }
327
        $categories[] = $cat;
328
    }
329
330
    $param['cat'] = $categories;
331
332 View Code Duplication
    switch ($photoHandlertype) {
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...
333
        case 'RandomPhoto':
334
            $photos = $photoHandler->objectToArray($photoHandler->getRandomPhoto($param));
335
            break;
336
        case 'LastPhoto':
337
            $photos = $photoHandler->objectToArray($photoHandler->getLastPhoto($param));
338
            break;
339
        case 'TopViewPhoto':
340
            $photos = $photoHandler->objectToArray($photoHandler->getTopViewPhoto($param));
341
            break;
342
        case 'TopRatedPhoto':
343
            $photos = $photoHandler->objectToArray($photoHandler->getTopRatedPhoto($param));
344
            break;
345
        case 'TopEcardPhoto':
346
            $photos = $photoHandler->objectToArray($photoHandler->getTopEcardPhoto($param));
347
            break;
348
    }
349
350
    if ('true' === $jquery) {
351
        global $xoTheme;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
352
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
353
354
        switch ($ajaxeffect) {
355
            case 'galleryview':
356
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/galleryview/galleryview.js');
357
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/galleryview/timers.js');
358
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/galleryview/easing.js');
359
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/galleryview/galleryview.css');
360
                break;
361
            case 'galleria':
362
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/galleria/galleria.js');
363
                break;
364
            case 'microgallery':
365
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/microgallery/jquery.microgallery.js');
366
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/microgallery/style.css');
367
                break;
368
        }
369
    }
370
371
    if (0 == count($photos)) {
0 ignored issues
show
Bug introduced by
The variable $photos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
372
        return [];
373
    }
374
375
    $ret = [
376
        'photos'              => $photos,
377
        'jquery'              => $jquery,
378
        'ajaxeffect'          => $ajaxeffect,
379
        'panel_width'         => $panel_width,
380
        'panel_height'        => $panel_height,
381
        'frame_width'         => $frame_width,
382
        'frame_height'        => $frame_height,
383
        'background_color'    => $background_color,
384
        'transition_speed'    => $transition_speed,
385
        'transition_interval' => $ransition_interval,
386
        'overlay_height'      => $overlay_height,
387
        'overlay_color'       => $overlay_color,
388
        'overlay_text_color'  => $overlay_text_color,
389
        'caption_text_color'  => $caption_text_color,
390
        'border'              => $border,
391
        'overlay_opacity'     => $overlay_opacity,
392
        'overlay_font_size'   => $overlay_font_size,
393
        'nav_theme'           => $nav_theme,
394
        'position'            => $position,
395
        'easing'              => $easing,
396
        'galleria_panelwidth' => $gria_panelwidth,
397
        'galleria_height'     => $gria_height,
398
        'galleria_bgcolor'    => $gria_bgcolor,
399
        'galleria_bcolor'     => $gria_bcolor,
400
        'galleria_bgimg'      => $gria_bgimg,
401
        'galleria_autoplay'   => $gria_autoplay,
402
        'galleria_transition' => $gria_transition,
403
        'galleria_tspeed'     => $gria_tspeed,
404
        'micro_size'          => $micro_size
405
    ];
406
407
    return $ret;
408
}
409
410
// Options photo blocks
411
/**
412
 * @param $options
413
 *
414
 * @return string
415
 */
416
function extgalleryBlockEdit($options)
417
{
418
419
    /** @var ExtgalleryCat $catHandler */
420
    $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
421
422
    $form = _MB_EXTGALLERY_PHOTO_NUMBER . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[0] . '" type="text"><br>';
423
424
    $Selected = new XoopsFormSelect(_MB_EXTGALLERY_DIRECTION, 'options[]', $options[1]);
425
    $Selected->addOption('0', _MB_EXTGALLERY_HORIZONTALLY);
426
    $Selected->addOption('1', _MB_EXTGALLERY_VERTICALLY);
427
    $Selected->addOption('2', _MB_EXTGALLERY_TABLE);
428
    $form .= _MB_EXTGALLERY_DIRECTION . ' : ' . $Selected->render() . '<br>';
429
430
    $yChecked = '';
431
    $nChecked = '';
432
    if (1 == $options[2]) {
433
        $yChecked = ' checked';
434
    } else {
435
        $nChecked = ' checked';
436
    }
437
438
    $form .= _MB_EXTGALLERY_DISPLAY_TITLE . ' : <input type="radio" name="options[]" value="1"' . $yChecked . '>&nbsp;' . _YES . '&nbsp;&nbsp;<input type="radio" name="options[]" value="0"' . $nChecked . '>' . _NO . '<br>';
439
440
    $effectTypeSelect = new XoopsFormSelect(_MB_EXTGALLERY_SHOW_TYPE, 'options[]', $options[3]);
441
    $effectTypeSelect->addOption('RandomPhoto', _MB_EXTGALLERY_TYPE_OP1);
442
    $effectTypeSelect->addOption('LastPhoto', _MB_EXTGALLERY_TYPE_OP2);
443
    $effectTypeSelect->addOption('TopViewPhoto', _MB_EXTGALLERY_TYPE_OP3);
444
    $effectTypeSelect->addOption('TopRatedPhoto', _MB_EXTGALLERY_TYPE_OP4);
445
    $effectTypeSelect->addOption('TopEcardPhoto', _MB_EXTGALLERY_TYPE_OP5);
446
    $form .= _MB_EXTGALLERY_SHOW_TYPE . ' : ' . $effectTypeSelect->render() . '<br>';
447
448
    $jqSelect = new XoopsFormSelect(_MB_EXTGALLERY_JQUERY, 'options[]', $options[4]);
449
    $jqSelect->addOption('true', _MB_EXTGALLERY_TRUE);
450
    $jqSelect->addOption('false', _MB_EXTGALLERY_FALSE);
451
    $form .= _MB_EXTGALLERY_JQUERY . ' : ' . $jqSelect->render() . '<br>';
452
453
    //select option
454
    $form             .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_USE_AJAX_EFFECTS . '</legend>';
455
    $ajaxeffectSelect = new XoopsFormSelect(_MB_EXTGALLERY_USE_AJAX_EFFECTS, 'options[]', $options[5]);
456
    $ajaxeffectSelect->addOption('none', _MB_EXTGALLERY_AJAX_NONE);
457
    $ajaxeffectSelect->addOption('lightbox', _MB_EXTGALLERY_AJAX_LIGHTBOX);
458
    $ajaxeffectSelect->addOption('overlay', _MB_EXTGALLERY_AJAX_OVERLAY);
459
    $ajaxeffectSelect->addOption('tooltip', _MB_EXTGALLERY_AJAX_TOOLTIP);
460
    $ajaxeffectSelect->addOption('fancybox', _MB_EXTGALLERY_AJAX_FANCYBOX);
461
    $ajaxeffectSelect->addOption('prettyphoto', _MB_EXTGALLERY_AJAX_PRETTPHOTO);
462
    $ajaxeffectSelect->addOption('jcarousel', _MB_EXTGALLERY_AJAX_JCAROUSEL);
463
    $ajaxeffectSelect->addOption('TosRUs', _MB_EXTGALLERY_AJAX_TOSRUS);
464
    $form .= _MB_EXTGALLERY_USE_AJAX_EFFECTS . ' : ' . $ajaxeffectSelect->render() . '<br>';
465
    $form .= '</fieldset><br>';
466
467
    //for overlay
468
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_OVERLAY . '</legend>';
469
    $form .= _MB_EXTGALLERY_OVERLAY_BG . ' : <input name="options[]" size="7" maxlength="7" value="' . $options[6] . '" type="text"><br>';
470
    $form .= _MB_EXTGALLERY_OVERLAY_WIDTH . ' : <input name="options[]" size="5" maxlength="5" value="' . $options[7] . '" type="text"><br>';
471
    $form .= _MB_EXTGALLERY_OVERLAY_HEIGHT . ' : <input name="options[]" size="5" maxlength="5" value="' . $options[8] . '" type="text"><br>';
472
    $form .= '</fieldset><br>';
473
474
    //for tooltip
475
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_TOOLTIP . '</legend>';
476
    $form .= _MB_EXTGALLERY_TOOLTIP_WIDTH . ' : <input name="options[]" size="5" maxlength="5" value="' . $options[9] . '" type="text"><br>';
477
    $form .= _MB_EXTGALLERY_TOOLTIP_BORDER_WIDTH . ' : <input name="options[]" size="5" maxlength="5" value="' . $options[10] . '" type="text"><br>';
478
    $form .= _MB_EXTGALLERY_TOOLTIP_BORDERCOLOR . ' : <input name="options[]" size="7" maxlength="7" value="' . $options[11] . '" type="text"><br>';
479
    $form .= '</fieldset><br>';
480
481
    //for fancybox
482
    $form              .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_FANCYBOX . '</legend>';
483
    $form              .= _MB_EXTGALLERY_FANCYBOX_BGCOLOR . ' : <input name="options[]" size="7" maxlength="7" value="' . $options[12] . '" type="text"><br>';
484
    $form              .= _MB_EXTGALLERY_FANCYBOX_OPACITY . ' : <input name="options[]" size="5" maxlength="5" value="' . $options[13] . '" type="text"><br>';
485
    $fancyboxtinSelect = new XoopsFormSelect(_MB_EXTGALLERY_FANCYBOX_TIN, 'options[]', $options[14]);
486
    $fancyboxtinSelect->addOption('none', _MB_EXTGALLERY_FANCYBOX_NONE);
487
    $fancyboxtinSelect->addOption('elastic', _MB_EXTGALLERY_FANCYBOX_ELASTIC);
488
    $form               .= _MB_EXTGALLERY_FANCYBOX_TIN . ' : ' . $fancyboxtinSelect->render() . '<br>';
489
    $fancyboxtoutSelect = new XoopsFormSelect(_MB_EXTGALLERY_FANCYBOX_TOUT, 'options[]', $options[15]);
490
    $fancyboxtoutSelect->addOption('none', _MB_EXTGALLERY_FANCYBOX_NONE);
491
    $fancyboxtoutSelect->addOption('elastic', _MB_EXTGALLERY_FANCYBOX_ELASTIC);
492
    $form             .= _MB_EXTGALLERY_FANCYBOX_TOUT . ' : ' . $fancyboxtoutSelect->render() . '<br>';
493
    $fancyboxtpSelect = new XoopsFormSelect(_MB_EXTGALLERY_FANCYBOX_TITLEPOSITION, 'options[]', $options[16]);
494
    $fancyboxtpSelect->addOption('over', _MB_EXTGALLERY_FANCYBOX_OVER);
495
    $fancyboxtpSelect->addOption('inside', _MB_EXTGALLERY_FANCYBOX_INSIDE);
496
    $fancyboxtpSelect->addOption('outside', _MB_EXTGALLERY_FANCYBOX_OUTSIDE);
497
    $form               .= _MB_EXTGALLERY_FANCYBOX_TITLEPOSITION . ' : ' . $fancyboxtpSelect->render() . '<br>';
498
    $fancyboxshowSelect = new XoopsFormSelect(_MB_EXTGALLERY_FANCYBOX_SHOWTYPE, 'options[]', $options[17]);
499
    $fancyboxshowSelect->addOption('single', _MB_EXTGALLERY_FANCYBOX_SINGLE);
500
    $fancyboxshowSelect->addOption('group', _MB_EXTGALLERY_FANCYBOX_GROUP);
501
    $form .= _MB_EXTGALLERY_FANCYBOX_SHOWTYPE . ' : ' . $fancyboxshowSelect->render() . '<br>';
502
    $form .= '</fieldset><br>';
503
504
    //for prettyphoto
505
    $form              .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_PRETTPHOTO . '</legend>';
506
    $prettyspeedSelect = new XoopsFormSelect(_MB_EXTGALLERY_PRETTPHOTO_SPEED, 'options[]', $options[18]);
507
    $prettyspeedSelect->addOption('fast', _MB_EXTGALLERY_PRETTPHOTO_FAST);
508
    $prettyspeedSelect->addOption('slow', _MB_EXTGALLERY_PRETTPHOTO_SLOW);
509
    $form              .= _MB_EXTGALLERY_PRETTPHOTO_SPEED . ' : ' . $prettyspeedSelect->render() . '<br>';
510
    $prettythemeSelect = new XoopsFormSelect(_MB_EXTGALLERY_PRETTPHOTO_THEME, 'options[]', $options[19]);
511
    $prettythemeSelect->addOption('dark_rounded', _MB_EXTGALLERY_PRETTPHOTO_THEME1);
512
    $prettythemeSelect->addOption('dark_square', _MB_EXTGALLERY_PRETTPHOTO_THEME2);
513
    $prettythemeSelect->addOption('facebook', _MB_EXTGALLERY_PRETTPHOTO_THEME3);
514
    $prettythemeSelect->addOption('light_rounded', _MB_EXTGALLERY_PRETTPHOTO_THEME4);
515
    $prettythemeSelect->addOption('light_square', _MB_EXTGALLERY_PRETTPHOTO_THEME5);
516
    $form                 .= _MB_EXTGALLERY_PRETTPHOTO_THEME . ' : ' . $prettythemeSelect->render() . '<br>';
517
    $form                 .= _MB_EXTGALLERY_PRETTPHOTO_SLIDESPEED . ' : <input name="options[]" size="5" maxlength="5" value="' . $options[20] . '" type="text"><br>';
518
    $prettyautoplaySelect = new XoopsFormSelect(_MB_EXTGALLERY_PRETTPHOTO_AUTOPLAY, 'options[]', $options[21]);
519
    $prettyautoplaySelect->addOption('true', _MB_EXTGALLERY_TRUE);
520
    $prettyautoplaySelect->addOption('false', _MB_EXTGALLERY_FALSE);
521
    $form .= _MB_EXTGALLERY_PRETTPHOTO_AUTOPLAY . ' : ' . $prettyautoplaySelect->render() . '<br>';
522
    $form .= '</fieldset><br>';
523
524
    //for jcarousel
525
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_JCAROUSEL . '</legend>';
526
    $form .= _MB_EXTGALLERY_JCAROUSEL_HWIDTH . ' : <input name="options[]" size="7" maxlength="7" value="' . $options[22] . '" type="text"><br>';
527
    $form .= _MB_EXTGALLERY_JCAROUSEL_VWIDTH . ' : <input name="options[]" size="7" maxlength="7" value="' . $options[23] . '" type="text"><br>';
528
    $form .= _MB_EXTGALLERY_JCAROUSEL_VHIGHT . ' : <input name="options[]" size="7" maxlength="7" value="' . $options[24] . '" type="text"><br>';
529
    $form .= '</fieldset><br>';
530
531
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_TABLE . '</legend>';
532
    $form .= _MB_EXTGALLERY_PHOTO_NUMBER_TABLE . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[25] . '" type="text"><br>';
533
    $form .= '</fieldset><br>';
534
535
    array_shift($options);
536
    array_shift($options);
537
    array_shift($options);
538
    array_shift($options);
539
    array_shift($options);
540
    array_shift($options);
541
    array_shift($options);
542
    array_shift($options);
543
    array_shift($options);
544
    array_shift($options);
545
    array_shift($options);
546
    array_shift($options);
547
    array_shift($options);
548
    array_shift($options);
549
    array_shift($options);
550
    array_shift($options);
551
    array_shift($options);
552
    array_shift($options);
553
    array_shift($options);
554
    array_shift($options);
555
    array_shift($options);
556
    array_shift($options);
557
    array_shift($options);
558
    array_shift($options);
559
    array_shift($options);
560
    array_shift($options);
561
562
    $form .= $catHandler->getBlockSelect($options);
563
564
    return $form;
565
}
566
567
// Options Ajax photos
568
/**
569
 * @param $options
570
 *
571
 * @return string
572
 */
573
function extgalleryAjaxEdit($options)
574
{
575
    $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
576
577
    $form = _MB_EXTGALLERY_PHOTO_NUMBER . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[0] . '" type="text"><br>';
578
579
    $showTypeSelect = new XoopsFormSelect(_MB_EXTGALLERY_SHOW_TYPE, 'options[]', $options[1]);
580
    $showTypeSelect->addOption('RandomPhoto', _MB_EXTGALLERY_TYPE_OP1);
581
    $showTypeSelect->addOption('LastPhoto', _MB_EXTGALLERY_TYPE_OP2);
582
    $showTypeSelect->addOption('TopViewPhoto', _MB_EXTGALLERY_TYPE_OP3);
583
    $showTypeSelect->addOption('TopRatedPhoto', _MB_EXTGALLERY_TYPE_OP4);
584
    $showTypeSelect->addOption('TopEcardPhoto', _MB_EXTGALLERY_TYPE_OP5);
585
    $form .= _MB_EXTGALLERY_SHOW_TYPE . ' : ' . $showTypeSelect->render() . '<br>';
586
587
    $jqSelect = new XoopsFormSelect(_MB_EXTGALLERY_JQUERY, 'options[]', $options[2]);
588
    $jqSelect->addOption('true', _MB_EXTGALLERY_TRUE);
589
    $jqSelect->addOption('false', _MB_EXTGALLERY_FALSE);
590
    $form .= _MB_EXTGALLERY_JQUERY . ' : ' . $jqSelect->render() . '<br>';
591
592
    //select option
593
    $form             .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_USE_AJAX_EFFECTS . '</legend>';
594
    $ajaxeffectSelect = new XoopsFormSelect(_MB_EXTGALLERY_USE_AJAX_EFFECTS, 'options[]', $options[3]);
595
    $ajaxeffectSelect->addOption('galleryview', _MB_EXTGALLERY_GVIEW);
596
    $ajaxeffectSelect->addOption('galleria', _MB_EXTGALLERY_GRIA);
597
    $ajaxeffectSelect->addOption('microgallery', _MB_EXTGALLERY_MICRO);
598
    $form .= _MB_EXTGALLERY_USE_AJAX_EFFECTS . ' : ' . $ajaxeffectSelect->render() . '<br>';
599
    $form .= '</fieldset><br>';
600
601
    $form        .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_GVIEW . '</legend>';
602
    $form        .= _MB_EXTGALLERY_PANEL_WIDTH . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[4] . '" type="text"><br>';
603
    $form        .= _MB_EXTGALLERY_PANEL_HEIGHT . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[5] . '" type="text"><br>';
604
    $form        .= _MB_EXTGALLERY_FRAME_WIDTH . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[6] . '" type="text"><br>';
605
    $form        .= _MB_EXTGALLERY_FRAME_HEIGHT . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[7] . '" type="text"><br>';
606
    $form        .= _MB_EXTGALLERY_BACKGROUND . ' : <input name="options[]" size="6" maxlength="255" value="' . $options[8] . '" type="text"><br>';
607
    $form        .= _MB_EXTGALLERY_TRANSITION_SPEED . ' : <input name="options[]" size="6" maxlength="255" value="' . $options[9] . '" type="text"><br>';
608
    $form        .= _MB_EXTGALLERY_TRANSITION_INTERVAL . ' : <input name="options[]" size="6" maxlength="255" value="' . $options[10] . '" type="text"><br>';
609
    $form        .= _MB_EXTGALLERY_OVERLAY_HEIGHT . ' : <input name="options[]" size="6" maxlength="255" value="' . $options[11] . '" type="text"><br>';
610
    $form        .= _MB_EXTGALLERY_OVERLAY_COLOR . ' : <input name="options[]" size="6" maxlength="255" value="' . $options[12] . '" type="text"><br>';
611
    $form        .= _MB_EXTGALLERY_OVERLAY_TEXT_COLOR . ' : <input name="options[]" size="6" maxlength="255" value="' . $options[13] . '" type="text"><br>';
612
    $form        .= _MB_EXTGALLERY_CAPTION_TEXT_COLOR . ' : <input name="options[]" size="6" maxlength="255" value="' . $options[14] . '" type="text"><br>';
613
    $form        .= _MB_EXTGALLERY_BORDER . ' : <input name="options[]" size="20" maxlength="255" value="' . $options[15] . '" type="text"><br>';
614
    $form        .= _MB_EXTGALLERY_OVERLAY_OPACITY . ' : <input name="options[]" size="6" maxlength="255" value="' . $options[16] . '" type="text"><br>';
615
    $form        .= _MB_EXTGALLERY_OVERLAY_FONT_SIZE . ' : <input name="options[]" size="6" maxlength="255" value="' . $options[17] . '" type="text"><br>';
616
    $themeSelect = new XoopsFormSelect(_MB_EXTGALLERY_SELECT_THEME, 'options[]', $options[18]);
617
    $themeSelect->addOption('light', _MB_EXTGALLERY_LIGHT);
618
    $themeSelect->addOption('dark', _MB_EXTGALLERY_DARK);
619
    $themeSelect->addOption('custom', _MB_EXTGALLERY_CUSTOM);
620
    $form           .= _MB_EXTGALLERY_SELECT_THEME . ' : ' . $themeSelect->render() . '<br>';
621
    $positionSelect = new XoopsFormSelect(_MB_EXTGALLERY_POSITION, 'options[]', $options[19]);
622
    $positionSelect->addOption('bottom', _MB_EXTGALLERY_BOTTOM);
623
    $positionSelect->addOption('top', _MB_EXTGALLERY_TOP);
624
    $form         .= _MB_EXTGALLERY_POSITION . ' : ' . $positionSelect->render() . '<br>';
625
    $easingSelect = new XoopsFormSelect(_MB_EXTGALLERY_EASING, 'options[]', $options[20]);
626
    $easingSelect->addOption('swing', _MB_EXTGALLERY_EASING_OP1);
627
    $easingSelect->addOption('linear', _MB_EXTGALLERY_EASING_OP2);
628
    $easingSelect->addOption('easeInOutBack', _MB_EXTGALLERY_EASING_OP3);
629
    $easingSelect->addOption('easeInOutQuad', _MB_EXTGALLERY_EASING_OP4);
630
    $easingSelect->addOption('easeOutBounce', _MB_EXTGALLERY_EASING_OP5);
631
    $form .= _MB_EXTGALLERY_EASING . ' : ' . $easingSelect->render() . '<br>';
632
    $form .= '</fieldset><br>';
633
634
    $form        .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_GRIA . '</legend>';
635
    $form        .= _MB_EXTGALLERY_GRIA_WIDTH . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[21] . '" type="text"><br>';
636
    $form        .= _MB_EXTGALLERY_GRIA_HEIGHT . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[22] . '" type="text"><br>';
637
    $form        .= _MB_EXTGALLERY_GRIA_BGCOLOR . ' : <input name="options[]" size="7" maxlength="255" value="' . $options[23] . '" type="text"><br>';
638
    $form        .= _MB_EXTGALLERY_GRIA_BCOLOR . ' : <input name="options[]" size="7" maxlength="255" value="' . $options[24] . '" type="text"><br>';
639
    $bgimgSelect = new XoopsFormSelect(_MB_EXTGALLERY_GRIA_BGIMG, 'options[]', $options[25]);
640
    $bgimgSelect->addOption('classic-map', _MB_EXTGALLERY_GRIA_BGIMG_OP1);
641
    $bgimgSelect->addOption('classic-map-b', _MB_EXTGALLERY_GRIA_BGIMG_OP2);
642
    $form .= _MB_EXTGALLERY_GRIA_BGIMG . ' : ' . $bgimgSelect->render() . '<br>';
643
644
    $autoplaySelect = new XoopsFormSelect(_MB_EXTGALLERY_GRIA_AUTOPLAY, 'options[]', $options[26]);
645
    $autoplaySelect->addOption('true', _MB_EXTGALLERY_TRUE);
646
    $autoplaySelect->addOption('false', _MB_EXTGALLERY_FALSE);
647
    $form         .= _MB_EXTGALLERY_GRIA_AUTOPLAY . ' : ' . $autoplaySelect->render() . '<br>';
648
    $select_trans = new XoopsFormSelect(_MB_EXTGALLERY_GRIA_TRANS, 'options[]', $options[27]);
649
    $select_trans->addOption('fade', _MB_EXTGALLERY_GRIA_TRANS_TYP1);
650
    $select_trans->addOption('flash', _MB_EXTGALLERY_GRIA_TRANS_TYP2);
651
    $select_trans->addOption('pulse', _MB_EXTGALLERY_GRIA_TRANS_TYP3);
652
    $select_trans->addOption('slide', _MB_EXTGALLERY_GRIA_TRANS_TYP4);
653
    $select_trans->addOption('fadeslide', _MB_EXTGALLERY_GRIA_TRANS_TYP5);
654
    $form .= _MB_EXTGALLERY_GRIA_TRANS . ' : ' . $select_trans->render() . '<br>';
655
    $form .= _MB_EXTGALLERY_GRIA_TSPEED . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[28] . '" type="text"><br>';
656
657
    $form .= '</fieldset><br>';
658
659
    $form       .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_MICRO . '</legend>';
660
    $sizeSelect = new XoopsFormSelect(_MB_EXTGALLERY_MICRO_SIZE, 'options[]', $options[29]);
661
    $sizeSelect->addOption('small', _MB_EXTGALLERY_MICRO_SIZE_OP1);
662
    $sizeSelect->addOption('medium', _MB_EXTGALLERY_MICRO_SIZE_OP2);
663
    $sizeSelect->addOption('large', _MB_EXTGALLERY_MICRO_SIZE_OP3);
664
    $form .= _MB_EXTGALLERY_MICRO_SIZE . ' : ' . $sizeSelect->render() . '<br>';
665
    $form .= '</fieldset><br>';
666
667
    array_shift($options);
668
    array_shift($options);
669
    array_shift($options);
670
    array_shift($options);
671
    array_shift($options);
672
    array_shift($options);
673
    array_shift($options);
674
    array_shift($options);
675
    array_shift($options);
676
    array_shift($options);
677
    array_shift($options);
678
    array_shift($options);
679
    array_shift($options);
680
    array_shift($options);
681
    array_shift($options);
682
    array_shift($options);
683
    array_shift($options);
684
    array_shift($options);
685
    array_shift($options);
686
    array_shift($options);
687
    array_shift($options);
688
    array_shift($options);
689
    array_shift($options);
690
    array_shift($options);
691
    array_shift($options);
692
    array_shift($options);
693
    array_shift($options);
694
    array_shift($options);
695
    array_shift($options);
696
    array_shift($options);
697
698
    $form .= $catHandler->getBlockSelect($options);
699
700
    return $form;
701
}
702
703
// Options TopSubmiter
704
/**
705
 * @param $options
706
 *
707
 * @return string
708
 */
709
function extgalleryTopSubmitterEdit($options)
710
{
711
    $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
712
713
    $form = _MB_EXTGALLERY_USER_NUMBER . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[0] . '" type="text"><br>';
714
715
    array_shift($options);
716
717
    $form .= $catHandler->getBlockSelect($options);
718
719
    return $form;
720
}
721
722
/**
723
 * @param $options
724
 *
725
 * @return array
726
 */
727
function extgalleryList($options)
728
{
729
    global $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
730
731
    /** @var ExtgalleryPhotoHandler $photoHandler */
732
    $photoHandler     = xoops_getModuleHandler('publicphoto', 'extgallery');
733
    $param            = ['limit' => $options[0]];
734
    $date             = $options[1];
735
    $hits             = $options[2];
736
    $rate             = $options[3];
737
    $photoHandlertype = $options[4];
738
739
    array_shift($options);
740
    array_shift($options);
741
    array_shift($options);
742
    array_shift($options);
743
    array_shift($options);
744
745
    $categories = [];
746
    foreach ($options as $cat) {
747
        if (0 == $cat) {
748
            $categories = [];
749
            break;
750
        }
751
        $categories[] = $cat;
752
    }
753
    $param['cat'] = $categories;
754
755 View Code Duplication
    switch ($photoHandlertype) {
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...
756
        case 'RandomPhoto':
757
            $photos = $photoHandler->objectToArray($photoHandler->getRandomPhoto($param));
758
            break;
759
        case 'LastPhoto':
760
            $photos = $photoHandler->objectToArray($photoHandler->getLastPhoto($param));
761
            break;
762
        case 'TopViewPhoto':
763
            $photos = $photoHandler->objectToArray($photoHandler->getTopViewPhoto($param));
764
            break;
765
        case 'TopRatedPhoto':
766
            $photos = $photoHandler->objectToArray($photoHandler->getTopRatedPhoto($param));
767
            break;
768
        case 'TopEcardPhoto':
769
            $photos = $photoHandler->objectToArray($photoHandler->getTopEcardPhoto($param));
770
            break;
771
    }
772
773
    if (0 == count($photos)) {
0 ignored issues
show
Bug introduced by
The variable $photos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
774
        return [];
775
    }
776
777 View Code Duplication
    foreach (array_keys($photos) as $i) {
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...
778
        if (isset($photos[$i]['photo_date'])) {
779
            $photos[$i]['photo_date'] = date(_SHORTDATESTRING, $photos[$i]['photo_date']);
780
        }
781
    }
782
783
    $ret = [
784
        'photos' => $photos,
785
        'date'   => $date,
786
        'hits'   => $hits,
787
        'rate'   => $rate
788
    ];
789
790
    return $ret;
791
}
792
793
/**
794
 * @param $options
795
 *
796
 * @return string
797
 */
798
function extgalleryListEdit($options)
799
{
800
    $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
801
    $form       = _MB_EXTGALLERY_PHOTO_NUMBER . ' : <input name="options[]" size="5" maxlength="255" value="' . $options[0] . '" type="text"><br>';
802
    //==================================
803
    $y2Checked = '';
804
    $n2Checked = '';
805
    if (1 == $options[1]) {
806
        $y2Checked = ' checked';
807
    } else {
808
        $n2Checked = ' checked';
809
    }
810
    $form .= _MB_EXTGALLERY_DISPLAY_DATE . ' : <input type="radio" name="options[1]" value="1"' . $y2Checked . '>&nbsp;' . _YES . '&nbsp;&nbsp;<input type="radio" name="options[1]" value="0"' . $n2Checked . '>' . _NO . '<br>';
811
    //==================================
812
    $y3Checked = '';
813
    $n3Checked = '';
814
    if (1 == $options[2]) {
815
        $y3Checked = ' checked';
816
    } else {
817
        $n3Checked = ' checked';
818
    }
819
    $form .= _MB_EXTGALLERY_DISPLAY_HITS . ' : <input type="radio" name="options[2]" value="1"' . $y3Checked . '>&nbsp;' . _YES . '&nbsp;&nbsp;<input type="radio" name="options[2]" value="0"' . $n3Checked . '>' . _NO . '<br>';
820
    //==================================
821
    $y4Checked = '';
822
    $n4Checked = '';
823
    if (1 == $options[3]) {
824
        $y4Checked = ' checked';
825
    } else {
826
        $n4Checked = ' checked';
827
    }
828
    $form .= _MB_EXTGALLERY_DISPLAY_RATE . ' : <input type="radio" name="options[3]" value="1"' . $y4Checked . '>&nbsp;' . _YES . '&nbsp;&nbsp;<input type="radio" name="options[3]" value="0"' . $n4Checked . '>' . _NO . '<br>';
829
    //==================================
830
    $effectTypeSelect = new XoopsFormSelect(_MB_EXTGALLERY_SHOW_TYPE, 'options[]', $options[4]);
831
    $effectTypeSelect->addOption('RandomPhoto', _MB_EXTGALLERY_TYPE_OP1);
832
    $effectTypeSelect->addOption('LastPhoto', _MB_EXTGALLERY_TYPE_OP2);
833
    $effectTypeSelect->addOption('TopViewPhoto', _MB_EXTGALLERY_TYPE_OP3);
834
    $effectTypeSelect->addOption('TopRatedPhoto', _MB_EXTGALLERY_TYPE_OP4);
835
    $effectTypeSelect->addOption('TopEcardPhoto', _MB_EXTGALLERY_TYPE_OP5);
836
    $form .= _MB_EXTGALLERY_SHOW_TYPE . ' : ' . $effectTypeSelect->render() . '<br>';
837
838
    array_shift($options);
839
    array_shift($options);
840
    array_shift($options);
841
    array_shift($options);
842
    array_shift($options);
843
844
    $form .= $catHandler->getBlockSelect($options);
845
846
    return $form;
847
}
848