read_configs.php ➔ mb_strcut()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
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       GIJ=CHECKMATE (PEAK Corp. http://www.peak.ne.jp/)
19
 * @author       Antiques Promotion (http://www.antiquespromotion.ca)
20
 */
21
22
defined('XOOPS_ROOT_PATH') || exit('XOOPS Root Path not defined');
23
24
// for "Duplicatable"
25
$moduleDirName = basename(dirname(__DIR__));
26
if (!preg_match('/^(\D+)(\d*)$/', $moduleDirName, $regs)) {
27
    echo('invalid dirname: ' . htmlspecialchars($moduleDirName));
28
}
29
$mydirnumber       = $regs[2] === '' ? '' : (int)$regs[2];
30
$cal->table        = $GLOBALS['xoopsDB']->prefix("apcal{$mydirnumber}_event");
31
$cal->cat_table    = $GLOBALS['xoopsDB']->prefix("apcal{$mydirnumber}_cat");
32
$cal->pic_table    = $GLOBALS['xoopsDB']->prefix("apcal{$mydirnumber}_pictures");
33
$cal->plugin_table = $GLOBALS['xoopsDB']->prefix("apcal{$mydirnumber}_plugins");
34
35
global $xoopsDB, $xoopsUser, $xoopsConfig;
36
37
// anti-XoopsErrorHandler
38
//restore_error_handler() ;
39
40
// get my mid
41
$rs = $GLOBALS['xoopsDB']->query('SELECT mid FROM ' . $GLOBALS['xoopsDB']->prefix('modules') . " WHERE dirname='$moduleDirName'");
42
list($mid) = $GLOBALS['xoopsDB']->fetchRow($rs);
43
44
// read from xoops_config
45
$rs = $GLOBALS['xoopsDB']->query('SELECT conf_name,conf_value FROM ' . $GLOBALS['xoopsDB']->prefix('config') . " WHERE conf_modid=$mid");
46
while (list($key, $val) = $GLOBALS['xoopsDB']->fetchRow($rs)) {
47
    if (strncmp($key, 'apcal_', 6) == 0) {
48
        // 'apcal_' ����Ϥޤ��Τ� APCal���֥������ȤΥץ�ѥƥ�
49
        $property = substr($key, 6);
50
        if (isset($cal->$property)) {
51
            $cal->$property = $val;
52
        }
53
    } else {
54
        // 'apcal_' ����Ϥޤ�ʤ���Τ� xoops¦��������ѿ��Ȥ��Ƽ�����
55
        $$key = $val;
56
    }
57
}
58
59
// get server timezone
60
switch ($timezone_using) {
61
    case 'xoops':
62
        $cal->server_TZ = $xoopsConfig['server_TZ'];
63
        break;
64
    case 'summer':
65
        $cal->server_TZ = date('Z', 1120176000) / 3600;
66
        break;
67
    case 'winter':
68
    default:
69
        $cal->server_TZ = date('Z', 1104537600) / 3600;
70
        break;
71
}
72
73
// xoops ����桼������μ��� (�����Ȥʤ�user_id=0)
74
if (is_object($xoopsUser)) {
75
    // ��Ͽ�桼���ʤ�Timezone,uid������
76
    $cal->user_TZ = $xoopsUser->timezone();
77 View Code Duplication
    if ($cal->user_TZ != $cal->server_TZ && $cal->use_server_TZ) {
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...
78
        $tzoffset = ($cal->user_TZ - $cal->server_TZ) * 3600;
79
        $cal->set_date(date('Y-n-j', time() + $tzoffset));
80
    }
81
    $user_id = $xoopsUser->uid();
82
    $isadmin = $xoopsUser->isAdmin($mid);
83
84
    $memberHandler = xoops_getHandler('member');
85
    $system_groups  = $memberHandler->getGroupList();
86
87
    if ($isadmin) {
88
89
        // ����Ԥθ��¡ʴ���Ԥ��ѹ������鼫ưŪ�˾�ǧ�Ȥ����
90
        $insertable           = true;
91
        $editable             = true;
92
        $superedit            = true;
93
        $deletable            = true;
94
        $admission_insert_sql = ',admission=1';
95
        $admission_update_sql = ',admission=1';
96
        $whr_sql_append       = '';
97
98
        // ����ԤΥ��ƥ��ꥢ���������¡������ƥ����
99
        $sql             = "SELECT cid,pid,cat_shorttitle,cat_title,cat_desc,color,ismenuitem,cat_depth,canbemain FROM $cal->cat_table ORDER BY weight";
100
        $rs              = $GLOBALS['xoopsDB']->query($sql);
101
        $cal->categories = array();
102 View Code Duplication
        while ($cat = $GLOBALS['xoopsDB']->fetchObject($rs)) {
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...
103
            $cal->categories[(int)$cat->cid] = $cat;
104
            if ($cat->canbemain == 1) {
105
                $cal->canbemain_cats[(int)$cat->cid] = $cat;
106
            }
107
        }
108
109
        // ����Ԥ������롼�פ�����ǽ
110
        $cal->groups =& $system_groups;
111
    } else {
112
113
        // ���̥桼���ϼ�ʬ�ν�°���륰�롼�פΤ�
114
        $my_group_ids = $memberHandler->getGroupsByUser($user_id);
115
        $cal->groups  = array();
116
        $ids4sql      = '(';
117
        foreach ($my_group_ids as $id) {
118
            $cal->groups[$id] = $system_groups[$id];
119
            $ids4sql          .= "$id,";
120
        }
121
        $ids4sql .= '0)';
122
123
        // ���̥桼���Υ��ƥ��ꥢ����������
124
        $sql             = "SELECT distinct cid,pid,cat_shorttitle,cat_title,cat_desc,color,ismenuitem,cat_depth,canbemain FROM $cal->cat_table LEFT JOIN "
125
                           . $GLOBALS['xoopsDB']->prefix('group_permission')
126
                           . " ON cid=gperm_itemid WHERE gperm_name='apcal_cat' AND gperm_modid='$mid' AND enabled AND gperm_groupid IN $ids4sql ORDER BY weight";
127
        $rs              = $GLOBALS['xoopsDB']->query($sql);
128
        $cal->categories = array();
129 View Code Duplication
        while ($cat = $GLOBALS['xoopsDB']->fetchObject($rs)) {
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...
130
            $cal->categories[(int)$cat->cid] = $cat;
131
            if ($cat->canbemain == 1) {
132
                $cal->canbemain_cats[(int)$cat->cid] = $cat;
133
            }
134
        }
135
136
        // ���̥桼���Υ��?�Х븢��
137
        if ($users_authority & 256) {
138
139
            // groupperm �ǡ��ġ��Υ��롼�פ��Ȥ�����
140
            $gpermHandler = xoops_getHandler('groupperm');
141
142
            // ��Ͽ����
143
            $insertable = $gpermHandler->checkRight('apcal_global', 1, $my_group_ids, $mid);
144
            if ($insertable && $gpermHandler->checkRight('apcal_global', 2, $my_group_ids, $mid)) {
145
                $admission_insert_sql = ',admission=1';
146
            } else {
147
                $admission_insert_sql = ',admission=0';
148
            }
149
            // �Խ�����
150
            $editable  = $gpermHandler->checkRight('apcal_global', 4, $my_group_ids, $mid);
151
            // ���¡ʺ��ǧ�λ��Ȥ��ޤ��ʤΤǡ�̵�����Τߡ�
152
            $deletable = $gpermHandler->checkRight('apcal_global', 32, $my_group_ids, $mid);
153
154
            // �Ȥꤢ������¾�ͤΥ쥳���ɤϤ����餻�ʤ�
155
            $superedit = $gpermHandler->checkRight('apcal_global', 8, $my_group_ids, $mid);
156
            if ($superedit) {
157
                $admission_update_sql = ',admission=1';
158
                $admission_insert_sql = ',admission=1';
159
                $whr_sql_append = '';
160
            } else {
161
                $admission_update_sql = ',admission=0';
162
                $admission_insert_sql = ',admission=0';
163
                $whr_sql_append = "AND uid=$user_id ";
164
            }
165
        } elseif ($users_authority & 1) {
166
            // ��Ͽ�Ĥʤ��Խ���ġʤ�����user_id�����פ���ɬ�פ������
167
            $insertable     = true;
168
            $editable       = true;
169
            $whr_sql_append = "AND uid=$user_id ";
170
            if ($users_authority & 2) {
171
                // ��ǧ������ʤ������Խ������⾵ǧ����
172
                $deletable            = true;
173
                $admission_insert_sql = ',admission=1';
174
                $admission_update_sql = '';
175
            } else {
176
                // ��ǧ��ɬ�פʾ��ϡ��������Խ������龵ǧɬ��
177
                // ���ˤĤ��Ƥϡ����ǧ�λ��Ȥߤ���ޤ�̵����Ե���
178
                $deletable            = false;
179
                $admission_insert_sql = ',admission=0';
180
                $admission_update_sql = ',admission=0';
181
            }
182
        } else {
183
            // ��Ͽ�ԲĤʤ餹�٤��Ե���
184
            $insertable           = $editable = $deletable = false;
185
            $admission_insert_sql = $admission_update_sql = '';
186
            $whr_sql_append       = 'AND 0';
187
        }
188
    }
189
} else {
190
    // �����Ȥʤ�default_TZ��桼����Timezone�ȸ��ʤ�
191
    $cal->user_TZ = $xoopsConfig['default_TZ'];
192 View Code Duplication
    if ($cal->user_TZ != $cal->server_TZ && $cal->use_server_TZ) {
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...
193
        $tzoffset = ($cal->user_TZ - $cal->server_TZ) * 3600;
194
        $cal->set_date(date('Y-n-j', time() + $tzoffset));
195
    }
196
197
    // �����ȤΥ��ƥ��ꥢ����������
198
    $sql             = "SELECT distinct cid,pid,cat_title,cat_desc,color,ismenuitem,cat_depth,canbemain FROM $cal->cat_table LEFT JOIN "
199
                       . $GLOBALS['xoopsDB']->prefix('group_permission')
200
                       . " ON cid=gperm_itemid WHERE gperm_name='apcal_cat' AND gperm_modid='$mid' AND enabled AND gperm_groupid='"
201
                       . XOOPS_GROUP_ANONYMOUS
202
                       . "' ORDER BY weight";
203
    $rs              = $GLOBALS['xoopsDB']->query($sql);
204
    $cal->categories = array();
205 View Code Duplication
    while ($cat = $GLOBALS['xoopsDB']->fetchObject($rs)) {
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...
206
        $cal->categories[(int)$cat->cid] = $cat;
207
        if ($cat->canbemain == 1) {
208
            $cal->canbemain_cats[(int)$cat->cid] = $cat;
209
        }
210
    }
211
212
    // �����ȤΥ��?�Х븢��
213
    $user_id              = 0;
214
    $isadmin              = false;
215
    $insertable           = (bool)($guests_authority & 1);
216
    $editable             = false;        // �����ȤϾ���Խ����¤ʤ�
217
    $deletable            = false;    // �����ȤϾ�˺��¤ʤ�
218
    $admission_insert_sql = ',admission=' . (($guests_authority & 2) ? '1' : '0');
219
    $admission_update_sql = '';
220
    // �����Ȥ����������롼�������Բ�
221
    $cal->groups = array();
222
}
223
224
// �Ƽ︢�¤�APCal���֥������Ȥؤ���Ͽ
225
$cal->insertable = $insertable;
226
$cal->editable   = $editable;
227
$cal->superedit  = $superedit;
228
$cal->deletable  = $deletable;
229
$cal->user_id    = $user_id;
230
$cal->isadmin    = $isadmin;
231
232
// �?������ɹ�ľ��
233
if (!empty($cal->locale)) {
234
    $cal->read_locale();
235
}
236
237
// mbstring�Τʤ�PHP���Ф��륨�ߥ�졼��
238
// mb_strcut�Υ��ߥ�졼��
239
if (!function_exists('mb_strcut')) {
240
    /**
241
     * @param $str
242
     * @param $start
243
     * @param $len
244
     * @return string
245
     */
246
    function mb_strcut($str, $start, $len)
247
    {
248
        // 2�Х��ȴĶ��ʤ饫�åȤ��ʤ�
249
        // 1�Х��ȴĶ��ʤ���ľ��substr
250
        if (XOOPS_USE_MULTIBYTES) {
251
            return $str;
252
        } else {
253
            return substr($str, $start, $len);
254
        }
255
    }
256
}
257
// mb_convert_encoding�Υ��ߥ�졼�ȡʲ��⤷�ʤ���
258
if (!function_exists('mb_convert_encoding')) {
259
    /**
260
     * @param         $str
261
     * @param         $from
262
     * @param  string $to
263
     * @return mixed
264
     */
265
    function mb_convert_encoding($str, $from, $to = 'auto')
0 ignored issues
show
Unused Code introduced by
The parameter $from is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $to is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
266
    {
267
        return $str;
268
    }
269
}
270