Completed
Branch master (95d503)
by Michael
03:25
created

extgallery_blocks.php ➔ extgalleryPhotoShow()   F

Complexity

Conditions 18
Paths 324

Size

Total Lines 165
Code Lines 142

Duplication

Lines 21
Ratio 12.73 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
cc 18
eloc 142
c 4
b 0
f 1
nc 324
nop 1
dl 21
loc 165
rs 3.6714

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
 * 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 http://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
    /** @var ExtgalleryPhotoHandler $photoHandler */
26
    $photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery');
27
28
    $param                = array('limit' => $options[0]);
29
    $direction            = $options[1];
30
    $title                = $options[2];
31
    $photoHandlertype     = $options[3];
32
    $jquery               = $options[4];
33
    $ajaxeffect           = $options[5];
34
    $overlyabg            = $options[6];
35
    $overlyaw             = $options[7];
36
    $overlyah             = $options[8];
37
    $tooltipw             = $options[9];
38
    $tooltipbw            = $options[10];
39
    $tooltipbbg           = $options[11];
40
    $fancyboxbg           = $options[12];
41
    $fancyboxop           = $options[13];
42
    $fancyboxtin          = $options[14];
43
    $fancyboxtout         = $options[15];
44
    $fancyboxtp           = $options[16];
45
    $fancyboxshow         = $options[17];
46
    $prettyphotospeed     = $options[18];
47
    $prettyphototheme     = $options[19];
48
    $prettyphotoslidspeed = $options[20];
49
    $prettyphotoautoplay  = $options[21];
50
    $jcarouselhwidth      = $options[22];
51
    $jcarouselvwidth      = $options[23];
52
    $jcarouselvheight     = $options[24];
53
    $column               = $options[25];
54
55
    array_shift($options);
56
    array_shift($options);
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
82
    $categories = array();
83
    foreach ($options as $cat) {
84
        if ($cat == 0) {
85
            $categories = array();
86
            break;
87
        }
88
        $categories[] = $cat;
89
    }
90
    $param['cat'] = $categories;
91
92 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...
93
        case 'RandomPhoto':
94
            $photos = $photoHandler->objectToArray($photoHandler->getRandomPhoto($param));
95
            break;
96
97
        case 'LastPhoto':
98
            $photos = $photoHandler->objectToArray($photoHandler->getLastPhoto($param));
99
            break;
100
101
        case 'TopViewPhoto':
102
            $photos = $photoHandler->objectToArray($photoHandler->getTopViewPhoto($param));
103
            break;
104
105
        case 'TopRatedPhoto':
106
            $photos = $photoHandler->objectToArray($photoHandler->getTopRatedPhoto($param));
107
            break;
108
109
        case 'TopEcardPhoto':
110
            $photos = $photoHandler->objectToArray($photoHandler->getTopEcardPhoto($param));
111
            break;
112
    }
113
114
    if ($jquery === 'true' && $ajaxeffect !== 'none') {
115
        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...
116
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
117
118
        switch ($ajaxeffect) {
119
            case 'lightbox':
120
                $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
121
                $xoTheme->addStylesheet('browse.php?modules/system/css/lightbox.css');
122
                break;
123
            case 'tooltip':
124
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/tooltip/image.tooltip.js');
125
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/tooltip/image.tooltip.css');
126
                break;
127
            case 'overlay':
128
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/overlay/overlay.jquery.tools.min.js');
129
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/overlay/overlay.css');
130
                break;
131
            case 'fancybox':
132
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/fancybox/mousewheel.js');
133
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/fancybox/fancybox.pack.js');
134
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/fancybox/fancybox.css');
135
                break;
136
            case 'prettyphoto':
137
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/prettyphoto/jquery.prettyPhoto.js');
138
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/prettyphoto/prettyPhoto.css');
139
                break;
140
            case 'jcarousel':
141
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/jcarousel/jquery.jcarousel.min.js');
142
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/jcarousel/skin.css');
143
                break;
144
            case 'TosRUs':
145
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/TosRUs/src/js/jquery.tosrus.js');
146
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/TosRUs/src/css/jquery.tosrus.css');
147
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/TosRUs/lib/jquery.hammer.min.js');
148
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/TosRUs/lib/FlameViewportScale.js');
149
                break;
150
        }
151
    }
152
153
    if (count($photos) == 0) {
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...
154
        return array();
155
    }
156
157
    $ret = array(
158
        'photos'               => $photos,
159
        'column'               => $column,
160
        'direction'            => $direction,
161
        'title'                => $title,
162
        'jquery'               => $jquery,
163
        'ajaxeffect'           => $ajaxeffect,
164
        'overlyabg'            => $overlyabg,
165
        'overlyaw'             => $overlyaw,
166
        'overlyah'             => $overlyah,
167
        'tooltipw'             => $tooltipw,
168
        'tooltipbw'            => $tooltipbw,
169
        'tooltipbbg'           => $tooltipbbg,
170
        'fancyboxbg'           => $fancyboxbg,
171
        'fancyboxop'           => $fancyboxop,
172
        'fancyboxtin'          => $fancyboxtin,
173
        'fancyboxtout'         => $fancyboxtout,
174
        'fancyboxtp'           => $fancyboxtp,
175
        'fancyboxshow'         => $fancyboxshow,
176
        'prettyphotospeed'     => $prettyphotospeed,
177
        'prettyphototheme'     => $prettyphototheme,
178
        'prettyphotoslidspeed' => $prettyphotoslidspeed,
179
        'prettyphotoautoplay'  => $prettyphotoautoplay,
180
        'jcarouselhwidth'      => $jcarouselhwidth,
181
        'jcarouselvwidth'      => $jcarouselvwidth,
182
        'jcarouselvheight'     => $jcarouselvheight
183
    );
184
185
    return $ret;
186
}
187
188
// converts a 2D array in a comma separated list (or separator of our choice)
189
/**
190
 * @param $sep
191
 * @param $array
192
 *
193
 * @return string
194
 */
195
function implodeArray2Dextgallery($sep, $array)
196
{
197
    $num = count($array);
198
    $str = '';
199
    for ($i = 0; $i < $num; ++$i) {
200
        if ($i) {
201
            $str .= $sep;
202
        }
203
        $str .= $array[$i];
204
    }
205
206
    return $str;
207
}
208
209
// Manage Top Submitter blocks
210
/**
211
 * @param $options
212
 *
213
 * @return string
214
 */
215
function extgalleryTopSubmitterShow($options)
216
{
217
    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...
218
    $block = '';
219
    if ($options[1] != 0) {
220
        $cat     = array_slice($options, 1); //Get information about categories to display
221
        $catauth = implodeArray2Dextgallery(',', $cat); //Creation of categories list to use - separated by a coma
222
    }
223
    $sql = 'SELECT uid, count(photo_id) as countphoto FROM ' . $xoopsDB->prefix('extgallery_publicphoto');
224
    $sql .= ' WHERE (uid>0)';
225
    if ($options[1] != 0) {
226
        $sql .= ' AND cat_id IN (' . $catauth . ')';
0 ignored issues
show
Bug introduced by
The variable $catauth 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...
227
    }
228
    $sql .= ' GROUP BY uid ORDER BY countphoto DESC';
229
    if ((int)$options[0] > 0) {
230
        $sql .= ' LIMIT ' . (int)$options[0];
231
    }
232
    $result = $xoopsDB->query($sql);
233
    if (!$result) {
234
        return '';
235
    }
236
    while ($myrow = $xoopsDB->fetchArray($result)) {
237
        $uid                  = $myrow['uid'];
238
        $countphoto           = $myrow['countphoto'];
239
        $uname                = XoopsUser::getUnameFromId($myrow['uid']);
240
        $block['designers'][] = array('uid' => $uid, 'uname' => $uname, 'countphoto' => $countphoto);
241
    }
242
243
    return $block;
244
}
245
246
// Manage Ajax photos
247
/**
248
 * @param $options
249
 *
250
 * @return array
251
 */
252
function extgalleryAjax($options)
253
{
254
    /** @var ExtgalleryPhotoHandler $photoHandler */
255
    $photoHandler       = xoops_getModuleHandler('publicphoto', 'extgallery');
256
    $param              = array('limit' => $options[0]);
257
    $photoHandlertype   = $options[1];
258
    $jquery             = $options[2];
259
    $ajaxeffect         = $options[3];
260
    $panel_width        = $options[4];
261
    $panel_height       = $options[5];
262
    $frame_width        = $options[6];
263
    $frame_height       = $options[7];
264
    $background_color   = $options[8];
265
    $transition_speed   = $options[9];
266
    $ransition_interval = $options[10];
267
    $overlay_height     = $options[11];
268
    $overlay_color      = $options[12];
269
    $overlay_text_color = $options[13];
270
    $caption_text_color = $options[14];
271
    $border             = $options[15];
272
    $overlay_opacity    = $options[16];
273
    $overlay_font_size  = $options[17];
274
    $nav_theme          = $options[18];
275
    $position           = $options[19];
276
    $easing             = $options[20];
277
    $gria_panelwidth    = $options[21];
278
    $gria_height        = $options[22];
279
    $gria_bgcolor       = $options[23];
280
    $gria_bcolor        = $options[24];
281
    $gria_bgimg         = $options[25];
282
    $gria_autoplay      = $options[26];
283
    $gria_transition    = $options[27];
284
    $gria_tspeed        = $options[28];
285
    $micro_size         = $options[29];
286
287
    array_shift($options);
288
    array_shift($options);
289
    array_shift($options);
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
318
    $categories = array();
319
    foreach ($options as $cat) {
320
        if ($cat == 0) {
321
            $categories = array();
322
            break;
323
        }
324
        $categories[] = $cat;
325
    }
326
327
    $param['cat'] = $categories;
328
329 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...
330
        case 'RandomPhoto':
331
            $photos = $photoHandler->objectToArray($photoHandler->getRandomPhoto($param));
332
            break;
333
        case 'LastPhoto':
334
            $photos = $photoHandler->objectToArray($photoHandler->getLastPhoto($param));
335
            break;
336
        case 'TopViewPhoto':
337
            $photos = $photoHandler->objectToArray($photoHandler->getTopViewPhoto($param));
338
            break;
339
        case 'TopRatedPhoto':
340
            $photos = $photoHandler->objectToArray($photoHandler->getTopRatedPhoto($param));
341
            break;
342
        case 'TopEcardPhoto':
343
            $photos = $photoHandler->objectToArray($photoHandler->getTopEcardPhoto($param));
344
            break;
345
    }
346
347
    if ($jquery === 'true') {
348
        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...
349
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
350
351
        switch ($ajaxeffect) {
352
            case 'galleryview':
353
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/galleryview/galleryview.js');
354
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/galleryview/timers.js');
355
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/galleryview/easing.js');
356
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/galleryview/galleryview.css');
357
                break;
358
            case 'galleria':
359
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/galleria/galleria.js');
360
                break;
361
            case 'microgallery':
362
                $xoTheme->addScript('browse.php?modules/extgallery/assets/js/microgallery/jquery.microgallery.js');
363
                $xoTheme->addStylesheet('browse.php?modules/extgallery/assets/js/microgallery/style.css');
364
                break;
365
        }
366
    }
367
368
    if (count($photos) == 0) {
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...
369
        return array();
370
    }
371
372
    $ret = array(
373
        'photos'              => $photos,
374
        'jquery'              => $jquery,
375
        'ajaxeffect'          => $ajaxeffect,
376
        'panel_width'         => $panel_width,
377
        'panel_height'        => $panel_height,
378
        'frame_width'         => $frame_width,
379
        'frame_height'        => $frame_height,
380
        'background_color'    => $background_color,
381
        'transition_speed'    => $transition_speed,
382
        'transition_interval' => $ransition_interval,
383
        'overlay_height'      => $overlay_height,
384
        'overlay_color'       => $overlay_color,
385
        'overlay_text_color'  => $overlay_text_color,
386
        'caption_text_color'  => $caption_text_color,
387
        'border'              => $border,
388
        'overlay_opacity'     => $overlay_opacity,
389
        'overlay_font_size'   => $overlay_font_size,
390
        'nav_theme'           => $nav_theme,
391
        'position'            => $position,
392
        'easing'              => $easing,
393
        'galleria_panelwidth' => $gria_panelwidth,
394
        'galleria_height'     => $gria_height,
395
        'galleria_bgcolor'    => $gria_bgcolor,
396
        'galleria_bcolor'     => $gria_bcolor,
397
        'galleria_bgimg'      => $gria_bgimg,
398
        'galleria_autoplay'   => $gria_autoplay,
399
        'galleria_transition' => $gria_transition,
400
        'galleria_tspeed'     => $gria_tspeed,
401
        'micro_size'          => $micro_size
402
    );
403
404
    return $ret;
405
}
406
407
// Options photo blocks
408
/**
409
 * @param $options
410
 *
411
 * @return string
412
 */
413
function extgalleryBlockEdit($options)
414
{
415
    global $xoopsUser;
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...
416
417
    $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
418
419
    $form = _MB_EXTGALLERY_PHOTO_NUMBER . " : <input name=\"options[]\" size=\"5\" maxlength=\"255\" value=\"" . $options[0] . "\" type=\"text\" /><br>";
420
421
    $Selected = new XoopsFormSelect(_MB_EXTGALLERY_DIRECTION, 'options[]', $options[1]);
422
    $Selected->addOption('0', _MB_EXTGALLERY_HORIZONTALLY);
423
    $Selected->addOption('1', _MB_EXTGALLERY_VERTICALLY);
424
    $Selected->addOption('2', _MB_EXTGALLERY_TABLE);
425
    $form .= _MB_EXTGALLERY_DIRECTION . ' : ' . $Selected->render() . '<br>';
426
427
    $yChecked = '';
428
    $nChecked = '';
429
    if ($options[2] == 1) {
430
        $yChecked = ' checked';
431
    } else {
432
        $nChecked = ' checked';
433
    }
434
435
    $form .= _MB_EXTGALLERY_DISPLAY_TITLE . ' : <input type="radio" name="options[]" value="1"' . $yChecked . ' />&nbsp;' . _YES . '&nbsp;&nbsp;<input type="radio" name="options[]" value="0"'
436
             . $nChecked . ' />' . _NO . '<br>';
437
438
    $effectTypeSelect = new XoopsFormSelect(_MB_EXTGALLERY_SHOW_TYPE, 'options[]', $options[3]);
439
    $effectTypeSelect->addOption('RandomPhoto', _MB_EXTGALLERY_TYPE_OP1);
440
    $effectTypeSelect->addOption('LastPhoto', _MB_EXTGALLERY_TYPE_OP2);
441
    $effectTypeSelect->addOption('TopViewPhoto', _MB_EXTGALLERY_TYPE_OP3);
442
    $effectTypeSelect->addOption('TopRatedPhoto', _MB_EXTGALLERY_TYPE_OP4);
443
    $effectTypeSelect->addOption('TopEcardPhoto', _MB_EXTGALLERY_TYPE_OP5);
444
    $form .= _MB_EXTGALLERY_SHOW_TYPE . ' : ' . $effectTypeSelect->render() . '<br>';
445
446
    $jqSelect = new XoopsFormSelect(_MB_EXTGALLERY_JQUERY, 'options[]', $options[4]);
447
    $jqSelect->addOption('true', _MB_EXTGALLERY_TRUE);
448
    $jqSelect->addOption('false', _MB_EXTGALLERY_FALSE);
449
    $form .= _MB_EXTGALLERY_JQUERY . ' : ' . $jqSelect->render() . '<br>';
450
451
    //select option
452
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_USE_AJAX_EFFECTS . '</legend>';
453
    $ajaxeffectSelect = new XoopsFormSelect(_MB_EXTGALLERY_USE_AJAX_EFFECTS, 'options[]', $options[5]);
454
    $ajaxeffectSelect->addOption('none', _MB_EXTGALLERY_AJAX_NONE);
455
    $ajaxeffectSelect->addOption('lightbox', _MB_EXTGALLERY_AJAX_LIGHTBOX);
456
    $ajaxeffectSelect->addOption('overlay', _MB_EXTGALLERY_AJAX_OVERLAY);
457
    $ajaxeffectSelect->addOption('tooltip', _MB_EXTGALLERY_AJAX_TOOLTIP);
458
    $ajaxeffectSelect->addOption('fancybox', _MB_EXTGALLERY_AJAX_FANCYBOX);
459
    $ajaxeffectSelect->addOption('prettyphoto', _MB_EXTGALLERY_AJAX_PRETTPHOTO);
460
    $ajaxeffectSelect->addOption('jcarousel', _MB_EXTGALLERY_AJAX_JCAROUSEL);
461
    $ajaxeffectSelect->addOption('TosRUs', _MB_EXTGALLERY_AJAX_TOSRUS);
462
    $form .= _MB_EXTGALLERY_USE_AJAX_EFFECTS . ' : ' . $ajaxeffectSelect->render() . '<br>';
463
    $form .= '</fieldset><br>';
464
465
    //for overlay
466
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_OVERLAY . '</legend>';
467
    $form .= _MB_EXTGALLERY_OVERLAY_BG . " : <input name=\"options[]\" size=\"7\" maxlength=\"7\" value=\"" . $options[6] . "\" type=\"text\" /><br>";
468
    $form .= _MB_EXTGALLERY_OVERLAY_WIDTH . " : <input name=\"options[]\" size=\"5\" maxlength=\"5\" value=\"" . $options[7] . "\" type=\"text\" /><br>";
469
    $form .= _MB_EXTGALLERY_OVERLAY_HEIGHT . " : <input name=\"options[]\" size=\"5\" maxlength=\"5\" value=\"" . $options[8] . "\" type=\"text\" /><br>";
470
    $form .= '</fieldset><br>';
471
472
    //for tooltip
473
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_TOOLTIP . '</legend>';
474
    $form .= _MB_EXTGALLERY_TOOLTIP_WIDTH . " : <input name=\"options[]\" size=\"5\" maxlength=\"5\" value=\"" . $options[9] . "\" type=\"text\" /><br>";
475
    $form .= _MB_EXTGALLERY_TOOLTIP_BORDER_WIDTH . " : <input name=\"options[]\" size=\"5\" maxlength=\"5\" value=\"" . $options[10] . "\" type=\"text\" /><br>";
476
    $form .= _MB_EXTGALLERY_TOOLTIP_BORDERCOLOR . " : <input name=\"options[]\" size=\"7\" maxlength=\"7\" value=\"" . $options[11] . "\" type=\"text\" /><br>";
477
    $form .= '</fieldset><br>';
478
479
    //for fancybox
480
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_FANCYBOX . '</legend>';
481
    $form .= _MB_EXTGALLERY_FANCYBOX_BGCOLOR . " : <input name=\"options[]\" size=\"7\" maxlength=\"7\" value=\"" . $options[12] . "\" type=\"text\" /><br>";
482
    $form .= _MB_EXTGALLERY_FANCYBOX_OPACITY . " : <input name=\"options[]\" size=\"5\" maxlength=\"5\" value=\"" . $options[13] . "\" type=\"text\" /><br>";
483
    $fancyboxtinSelect = new XoopsFormSelect(_MB_EXTGALLERY_FANCYBOX_TIN, 'options[]', $options[14]);
484
    $fancyboxtinSelect->addOption('none', _MB_EXTGALLERY_FANCYBOX_NONE);
485
    $fancyboxtinSelect->addOption('elastic', _MB_EXTGALLERY_FANCYBOX_ELASTIC);
486
    $form .= _MB_EXTGALLERY_FANCYBOX_TIN . ' : ' . $fancyboxtinSelect->render() . '<br>';
487
    $fancyboxtoutSelect = new XoopsFormSelect(_MB_EXTGALLERY_FANCYBOX_TOUT, 'options[]', $options[15]);
488
    $fancyboxtoutSelect->addOption('none', _MB_EXTGALLERY_FANCYBOX_NONE);
489
    $fancyboxtoutSelect->addOption('elastic', _MB_EXTGALLERY_FANCYBOX_ELASTIC);
490
    $form .= _MB_EXTGALLERY_FANCYBOX_TOUT . ' : ' . $fancyboxtoutSelect->render() . '<br>';
491
    $fancyboxtpSelect = new XoopsFormSelect(_MB_EXTGALLERY_FANCYBOX_TITLEPOSITION, 'options[]', $options[16]);
492
    $fancyboxtpSelect->addOption('over', _MB_EXTGALLERY_FANCYBOX_OVER);
493
    $fancyboxtpSelect->addOption('inside', _MB_EXTGALLERY_FANCYBOX_INSIDE);
494
    $fancyboxtpSelect->addOption('outside', _MB_EXTGALLERY_FANCYBOX_OUTSIDE);
495
    $form .= _MB_EXTGALLERY_FANCYBOX_TITLEPOSITION . ' : ' . $fancyboxtpSelect->render() . '<br>';
496
    $fancyboxshowSelect = new XoopsFormSelect(_MB_EXTGALLERY_FANCYBOX_SHOWTYPE, 'options[]', $options[17]);
497
    $fancyboxshowSelect->addOption('single', _MB_EXTGALLERY_FANCYBOX_SINGLE);
498
    $fancyboxshowSelect->addOption('group', _MB_EXTGALLERY_FANCYBOX_GROUP);
499
    $form .= _MB_EXTGALLERY_FANCYBOX_SHOWTYPE . ' : ' . $fancyboxshowSelect->render() . '<br>';
500
    $form .= '</fieldset><br>';
501
502
    //for prettyphoto
503
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_PRETTPHOTO . '</legend>';
504
    $prettyspeedSelect = new XoopsFormSelect(_MB_EXTGALLERY_PRETTPHOTO_SPEED, 'options[]', $options[18]);
505
    $prettyspeedSelect->addOption('fast', _MB_EXTGALLERY_PRETTPHOTO_FAST);
506
    $prettyspeedSelect->addOption('slow', _MB_EXTGALLERY_PRETTPHOTO_SLOW);
507
    $form .= _MB_EXTGALLERY_PRETTPHOTO_SPEED . ' : ' . $prettyspeedSelect->render() . '<br>';
508
    $prettythemeSelect = new XoopsFormSelect(_MB_EXTGALLERY_PRETTPHOTO_THEME, 'options[]', $options[19]);
509
    $prettythemeSelect->addOption('dark_rounded', _MB_EXTGALLERY_PRETTPHOTO_THEME1);
510
    $prettythemeSelect->addOption('dark_square', _MB_EXTGALLERY_PRETTPHOTO_THEME2);
511
    $prettythemeSelect->addOption('facebook', _MB_EXTGALLERY_PRETTPHOTO_THEME3);
512
    $prettythemeSelect->addOption('light_rounded', _MB_EXTGALLERY_PRETTPHOTO_THEME4);
513
    $prettythemeSelect->addOption('light_square', _MB_EXTGALLERY_PRETTPHOTO_THEME5);
514
    $form .= _MB_EXTGALLERY_PRETTPHOTO_THEME . ' : ' . $prettythemeSelect->render() . '<br>';
515
    $form .= _MB_EXTGALLERY_PRETTPHOTO_SLIDESPEED . " : <input name=\"options[]\" size=\"5\" maxlength=\"5\" value=\"" . $options[20] . "\" type=\"text\" /><br>";
516
    $prettyautoplaySelect = new XoopsFormSelect(_MB_EXTGALLERY_PRETTPHOTO_AUTOPLAY, 'options[]', $options[21]);
517
    $prettyautoplaySelect->addOption('true', _MB_EXTGALLERY_TRUE);
518
    $prettyautoplaySelect->addOption('false', _MB_EXTGALLERY_FALSE);
519
    $form .= _MB_EXTGALLERY_PRETTPHOTO_AUTOPLAY . ' : ' . $prettyautoplaySelect->render() . '<br>';
520
    $form .= '</fieldset><br>';
521
522
    //for jcarousel
523
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_AJAX_JCAROUSEL . '</legend>';
524
    $form .= _MB_EXTGALLERY_JCAROUSEL_HWIDTH . " : <input name=\"options[]\" size=\"7\" maxlength=\"7\" value=\"" . $options[22] . "\" type=\"text\" /><br>";
525
    $form .= _MB_EXTGALLERY_JCAROUSEL_VWIDTH . " : <input name=\"options[]\" size=\"7\" maxlength=\"7\" value=\"" . $options[23] . "\" type=\"text\" /><br>";
526
    $form .= _MB_EXTGALLERY_JCAROUSEL_VHIGHT . " : <input name=\"options[]\" size=\"7\" maxlength=\"7\" value=\"" . $options[24] . "\" type=\"text\" /><br>";
527
    $form .= '</fieldset><br>';
528
529
    $form .= "<fieldset><legend style='font-weight:bold; color:#990000;'>" . _MB_EXTGALLERY_TABLE . '</legend>';
530
    $form .= _MB_EXTGALLERY_PHOTO_NUMBER_TABLE . " : <input name=\"options[]\" size=\"5\" maxlength=\"255\" value=\"" . $options[25] . "\" type=\"text\" /><br>";
531
    $form .= '</fieldset><br>';
532
533
    array_shift($options);
534
    array_shift($options);
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
560
    $form .= $catHandler->getBlockSelect($options);
561
562
    return $form;
563
}
564
565
// Options Ajax photos
566
/**
567
 * @param $options
568
 *
569
 * @return string
570
 */
571
function extgalleryAjaxEdit($options)
572
{
573
    global $xoopsUser;
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...
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
    global $xoopsUser;
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...
712
713
    $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
714
715
    $form = _MB_EXTGALLERY_USER_NUMBER . " : <input name=\"options[]\" size=\"5\" maxlength=\"255\" value=\"" . $options[0] . "\" type=\"text\" /><br>";
716
717
    array_shift($options);
718
719
    $form .= $catHandler->getBlockSelect($options);
720
721
    return $form;
722
}
723
724
/**
725
 * @param $options
726
 *
727
 * @return array
728
 */
729
function extgalleryList($options)
730
{
731
    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...
732
733
    /** @var ExtgalleryPhotoHandler $photoHandler */
734
    $photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery');
735
    $param            = array('limit' => $options[0]);
736
    $date             = $options[1];
737
    $hits             = $options[2];
738
    $rate             = $options[3];
739
    $photoHandlertype = $options[4];
740
741
    array_shift($options);
742
    array_shift($options);
743
    array_shift($options);
744
    array_shift($options);
745
    array_shift($options);
746
747
    $categories = array();
748
    foreach ($options as $cat) {
749
        if ($cat == 0) {
750
            $categories = array();
751
            break;
752
        }
753
        $categories[] = $cat;
754
    }
755
    $param['cat'] = $categories;
756
757 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...
758
        case 'RandomPhoto':
759
            $photos = $photoHandler->objectToArray($photoHandler->getRandomPhoto($param));
760
            break;
761
        case 'LastPhoto':
762
            $photos = $photoHandler->objectToArray($photoHandler->getLastPhoto($param));
763
            break;
764
        case 'TopViewPhoto':
765
            $photos = $photoHandler->objectToArray($photoHandler->getTopViewPhoto($param));
766
            break;
767
        case 'TopRatedPhoto':
768
            $photos = $photoHandler->objectToArray($photoHandler->getTopRatedPhoto($param));
769
            break;
770
        case 'TopEcardPhoto':
771
            $photos = $photoHandler->objectToArray($photoHandler->getTopEcardPhoto($param));
772
            break;
773
    }
774
775
    if (count($photos) == 0) {
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...
776
        return array();
777
    }
778
779 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...
780
        if (isset($photos[$i]['photo_date'])) {
781
            $photos[$i]['photo_date'] = date(_SHORTDATESTRING, $photos[$i]['photo_date']);
782
        }
783
    }
784
785
    $ret = array(
786
        'photos' => $photos,
787
        'date'   => $date,
788
        'hits'   => $hits,
789
        'rate'   => $rate
790
    );
791
792
    return $ret;
793
}
794
795
/**
796
 * @param $options
797
 *
798
 * @return string
799
 */
800
function extgalleryListEdit($options)
801
{
802
    global $xoopsUser;
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...
803
    $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
804
    $form       = _MB_EXTGALLERY_PHOTO_NUMBER . " : <input name=\"options[]\" size=\"5\" maxlength=\"255\" value=\"" . $options[0] . "\" type=\"text\" /><br>";
805
    //==================================
806
    $y2Checked = '';
807
    $n2Checked = '';
808
    if ($options[1] == 1) {
809
        $y2Checked = ' checked';
810
    } else {
811
        $n2Checked = ' checked';
812
    }
813
    $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"'
814
             . $n2Checked . ' />' . _NO . '<br>';
815
    //==================================
816
    $y3Checked = '';
817
    $n3Checked = '';
818
    if ($options[2] == 1) {
819
        $y3Checked = ' checked';
820
    } else {
821
        $n3Checked = ' checked';
822
    }
823
    $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"'
824
             . $n3Checked . ' />' . _NO . '<br>';
825
    //==================================
826
    $y4Checked = '';
827
    $n4Checked = '';
828
    if ($options[3] == 1) {
829
        $y4Checked = ' checked';
830
    } else {
831
        $n4Checked = ' checked';
832
    }
833
    $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"'
834
             . $n4Checked . ' />' . _NO . '<br>';
835
    //==================================
836
    $effectTypeSelect = new XoopsFormSelect(_MB_EXTGALLERY_SHOW_TYPE, 'options[]', $options[4]);
837
    $effectTypeSelect->addOption('RandomPhoto', _MB_EXTGALLERY_TYPE_OP1);
838
    $effectTypeSelect->addOption('LastPhoto', _MB_EXTGALLERY_TYPE_OP2);
839
    $effectTypeSelect->addOption('TopViewPhoto', _MB_EXTGALLERY_TYPE_OP3);
840
    $effectTypeSelect->addOption('TopRatedPhoto', _MB_EXTGALLERY_TYPE_OP4);
841
    $effectTypeSelect->addOption('TopEcardPhoto', _MB_EXTGALLERY_TYPE_OP5);
842
    $form .= _MB_EXTGALLERY_SHOW_TYPE . ' : ' . $effectTypeSelect->render() . '<br>';
843
844
    array_shift($options);
845
    array_shift($options);
846
    array_shift($options);
847
    array_shift($options);
848
    array_shift($options);
849
850
    $form .= $catHandler->getBlockSelect($options);
851
852
    return $form;
853
}
854