apcal_after_schedule.php ➔ apcal_after_schedule_edit()   B
last analyzed

Complexity

Conditions 7
Paths 48

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 48
nop 1
dl 0
loc 54
rs 8.0703
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
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright   {@link http://xoops.org/ XOOPS Project}
14
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team,
18
 * @author       Antiques Promotion (http://www.antiquespromotion.ca)
19
 * @author       GIJ=CHECKMATE (PEAK Corp. http://www.peak.ne.jp/)
20
 */
21
22
if (!defined('APCAL_BLOCK_AFTER_SCHEDULE_INCLUDED')) {
23
    define('APCAL_BLOCK_AFTER_SCHEDULE_INCLUDED', 1);
24
25
    // XOOPS 2.1/2.2
26
    if (substr(XOOPS_VERSION, 6, 3) > 2.0) {
27
        $GLOBALS['apcal_blockinstance_object'] = $this;
28
    }
29
30
    /**
31
     * @param $options
32
     * @return array
33
     */
34
    function apcal_after_schedule_show_tpl($options)
35
    {
36
        global $xoopsConfig, $xoopsDB;
37
38
        $moduleDirName = empty($options[0]) ? basename(dirname(__DIR__)) : $options[0];
39
        $maxitem       = empty($options[1]) ? 10 : (int)$options[1];
40
        $now_cid       = empty($options[2]) ? 0 : (int)$options[2];
41
        $untildays     = empty($options[4]) ? 0 : (int)$options[4];
42
43
        // setting physical & virtual paths
44
        $mod_path = XOOPS_ROOT_PATH . "/modules/$moduleDirName";
45
        $mod_url  = XOOPS_URL . "/modules/$moduleDirName";
46
47
        // defining class of APCal
48
        if (!class_exists('APCal_xoops')) {
49
            require_once "$mod_path/class/APCal.php";
50
            require_once "$mod_path/class/APCal_xoops.php";
51
        }
52
53
        // creating an instance of APCal
54
        $cal = new APCal_xoops('', $xoopsConfig['language'], true);
55
56
        // cid ¤Ë¤è¤ë¹Ê¤ê¹þ¤ß
57
        $cal->now_cid = $now_cid;
58
59
        // setting properties of APCal
60
        $cal->conn = $GLOBALS['xoopsDB']->conn;
61
        include "$mod_path/include/read_configs.php";
62
        $cal->base_url    = $mod_url;
63
        $cal->base_path   = $mod_path;
64
        $cal->images_url  = "$mod_url/assets/images/$skin_folder";
0 ignored issues
show
Bug introduced by
The variable $skin_folder does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
65
        $cal->images_path = "$mod_path/assets/images/$skin_folder";
66
67
        // ¥Ö¥í¥Ã¥¯ÇÛÎó¤Î¼«Ê¬¼«¿È¤ò½ñ¤­´¹¤¨¤ë title ¤Ë %s ¤ò´Þ¤á¤ë¤³¤È
68 View Code Duplication
        if (substr(XOOPS_VERSION, 6, 3) > 2.0) {
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...
69
            $title_fmt = $GLOBALS['apcal_blockinstance_object']->getVar('title');
70
            $GLOBALS['apcal_blockinstance_object']->setVar('title', sprintf($title_fmt, sprintf(_APCAL_FMT_MD, $cal->month_short_names[date('n', $cal->unixtime)],
71
                                                                                                $cal->date_short_names[date('j', $cal->unixtime)])));
72
        } else {
73
            global $block_arr, $i;
74
            if (is_object($block_arr[$i])) {
75
                $title_fmt = $block_arr[$i]->getVar('title');
76
                $title     = sprintf($title_fmt, sprintf(_APCAL_FMT_MD, $cal->month_short_names[date('n', $cal->unixtime)], $cal->date_short_names[date('j', $cal->unixtime)]));
77
                $block_arr[$i]->setVar('title', $title);
78
            }
79
        }
80
81
        $block = $cal->get_blockarray_coming_event("$mod_url/index.php", $maxitem, false, $untildays);
82
83
        return $block;
84
    }
85
86
    /**
87
     * @param $options
88
     * @return string
89
     */
90
    function apcal_after_schedule_edit($options)
91
    {
92
        global $xoopsDB, $xoopsConfig;
93
94
        $moduleDirName = empty($options[0]) ? basename(dirname(__DIR__)) : $options[0];
95
        $maxitem       = empty($options[1]) ? 10 : (int)$options[1];
96
        $now_cid       = empty($options[2]) ? 0 : (int)$options[2];
97
        $untildays     = empty($options[4]) ? 0 : (int)$options[4];
98
99
        // setting physical & virtual paths
100
        $mod_path = XOOPS_ROOT_PATH . "/modules/$moduleDirName";
101
        $mod_url  = XOOPS_URL . "/modules/$moduleDirName";
102
103
        // defining class of APCal
104
        require_once "$mod_path/class/APCal.php";
105
        require_once "$mod_path/class/APCal_xoops.php";
106
107
        // creating an instance of APCal
108
        $cal                = new APCal_xoops(date('Y-n-j'), $xoopsConfig['language'], true);
109
        $cal->use_server_TZ = true;
110
111
        // setting properties of APCal
112
        $cal->conn = $GLOBALS['xoopsDB']->conn;
113
        include "$mod_path/include/read_configs.php";
114
        $cal->base_url    = $mod_url;
115
        $cal->base_path   = $mod_path;
116
        $cal->images_url  = "$mod_url/assets/images/$skin_folder";
0 ignored issues
show
Bug introduced by
The variable $skin_folder does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
117
        $cal->images_path = "$mod_path/assets/images/$skin_folder";
118
119
        $ret = "<input type='hidden' name='options[0]' value='$moduleDirName' />\n";
120
121
        // ɽ¼¨¸Ä¿ô
122
        $ret .= _MB_APCAL_MAXITEMS . ':';
123
        $ret .= "<input type='text' size='4' name='options[1]' value='$maxitem' style='text-align:right;' /><br>\n";
124
125
        // ¥«¥Æ¥´¥ê¡¼ÁªÂò¥Ü¥Ã¥¯¥¹¤ÎÀ¸À®
126
        $ret .= _MB_APCAL_CATSEL . ':';
127
        $ret .= "<select name='options[2]'>\n<option value='0'>" . _ALL . "</option>\n";
128
        foreach ($cal->categories as $cid => $cat) {
129
            $selected       = $now_cid == $cid ? 'selected' : '';
130
            $depth_desc     = str_repeat('-', (int)$cat->cat_depth);
131
            $cat_title4show = $cal->text_sanitizer_for_show($cat->cat_title);
132
            $ret            .= "\t<option value='$cid' $selected>$depth_desc $cat_title4show</option>\n";
133
        }
134
        $ret .= "</select><br>\n";
135
136
        // ¥µ¥Ö¥«¥Æ¥´¥ê¡¼É½¼¨¤Î¼ÂÁõ¤Ï¤Þ¤À¤Þ¤ÀÀè¡Ê°ì±þͽÌó¤À¤±¤·¤Æ¤ª¤¯¡Ë
137
        $ret .= "<input type='hidden' name='options[3]' value='0' />\n";
138
139
        // ɽ¼¨¾å¸ÂÆü¿ô
140
        $ret .= sprintf(_MB_APCAL_UNTILDAYS, "<input type='text' size='4' name='options[4]' value='$untildays' style='text-align:right;' />") . "<br>\n";
141
142
        return $ret;
143
    }
144
}
145