Issues (1210)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

class/APCal_xoops.php (24 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
if (!class_exists('APCal_xoops')) {
23
    /**
24
     * Class APCal_xoops
25
     */
26
    class APCal_xoops extends APCal
27
    {
28
        /**
29
         * @param $data
30
         * @return mixed
31
         */
32
        public function textarea_sanitizer_for_sql($data)
33
        {
34
            //  preventing double-addslashes()
35
            //  $myts = MyTextSanitizer::getInstance();
36
            //  return $myts->makeTareaData4Save($data);
37
            return $data;
38
        }
39
40
        /**
41
         * @param $data
42
         * @return mixed
43
         */
44
        public function textarea_sanitizer_for_show($data)
45
        {
46
            $myts = MyTextSanitizer::getInstance();
47
48
            return $myts->displayTarea($data);
49
        }
50
51
        /**
52
         * @param $data
53
         * @return mixed
54
         */
55
        public function textarea_sanitizer_for_edit($data)
56
        {
57
            $myts = MyTextSanitizer::getInstance();
58
59
            return $myts->htmlSpecialChars($data);
60
        }
61
62
        /**
63
         * @param $data
64
         * @return mixed
65
         */
66
        public function textarea_sanitizer_for_export_ics($data)
67
        {
68
            $myts = MyTextSanitizer::getInstance();
69
70
            return $myts->displayTarea($data);
71
        }
72
73
        /**
74
         * @param $data
75
         * @return mixed
76
         */
77
        public function text_sanitizer_for_show($data)
78
        {
79
            $myts = MyTextSanitizer::getInstance();
80
81
            return $myts->htmlSpecialChars($data);
82
        }
83
84
        /**
85
         * @param $data
86
         * @return mixed
87
         */
88
        public function text_sanitizer_for_edit($data)
89
        {
90
            $myts = MyTextSanitizer::getInstance();
91
92
            return $myts->htmlSpecialChars($data);
93
        }
94
95
        /**
96
         * @param         $name
97
         * @param         $ymd
98
         * @param  string $long_ymdn
99
         * @return string
100
         */
101
        public function get_formtextdateselect($name, $ymd, $long_ymdn = '')
102
        {
103
            require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
104
105
            // day of week starting
106
            $first_day = $this->week_start ? 1 : 0;
107
108
            if ($this->jscalendar === 'xoops') {
109
                $jstime = formatTimestamp($this->unixtime, 'F j Y, H:i:s');
110
111
                if ($this->week_start) {
112
                    $js_cal_week_start = 'true';
113
                }    // Monday
114
                else {
115
                    $js_cal_week_start = 'false';
116
                }                        // Sunday
117
118
                // <input type='reset' value='...' onclick='
119
                return "
120
            <input type='text' name='$name' id='$name' size='15' maxlength='15' value='$ymd' />
121
            <input type='image' src='$this->images_url/button_date_selecting.gif' onclick='
122
123
          var el = xoopsGetElementById(\"$name\");
124
          if (calendar != null) {
125
            calendar.hide();
126
            calendar.parseDate(el.value);
127
          } else {
128
            var cal = new Calendar($js_cal_week_start, new Date(\"$jstime\"), selected, closeHandler);
129
            calendar = cal;
130
            cal.setRange(2000, 2100);
131
            calendar.create();
132
            calendar.parseDate(el.value);
133
          }
134
          calendar.sel = el;
135
          calendar.showAtElement(el);
136
          Calendar.addEvent(document, \"mousedown\", checkCalendar);
137
138
          return false;
139
140
        ' />
141
        ";
142
            } else {
143
                return "
144
        <input type='text' name='$name' id='$name' size='12' maxlength='12' value='$ymd' />
145
        <img src='$this->images_url/button_date_selecting.gif' id='trigger_{$name}' style='cursor: pointer; vertical-align:bottom;' title='Date selector' />
146
        <span id='display_{$name}'>$long_ymdn</span>
147
148
        <script type='text/javascript'>
149
        Calendar.setup({
150
            inputField : '$name',
151
            button : 'trigger_{$name}',
152
            displayArea : 'display_{$name}',
153
            daFormat : '" . _APCAL_JSFMT_YMDN . "' ,
154
            ifFormat : '%Y-%m-%d',
155
            showsTime : false,
156
            align :'Br',
157
            step : 1 ,
158
            firstDay : $first_day ,
159
            singleClick : false
160
        });
161
        </script>
162
        ";
163
            }
164
        }
165
166
        /**
167
         * @param $uid
168
         * @return string
169
         */
170
        public function get_submitter_info($uid)
171
        {
172
            if ($uid <= 0) {
173
                return _GUESTS;
174
            }
175
176
            $poster = new XoopsUser($uid);
177
178
            // check if invalid uid
179
            if ($poster->uname() === '') {
180
                return '';
181
            }
182
183
            if ($this->nameoruname === 'uname') {
184
                $name = $poster->uname();
185
            } else {
186
                $name = trim($poster->name());
187
                if ($name === '') {
188
                    $name = $poster->uname();
189
                }
190
            }
191
192
            return "<a href='" . XOOPS_URL . "/userinfo.php?uid=$uid'>$name</a>";
193
        }
194
195
        // XOOPS���?�Х븡�����
196
197
        /**
198
         * @param $keywords
199
         * @param $andor
200
         * @param $limit
201
         * @param $offset
202
         * @param $uid
203
         * @return array
204
         */
205
        public function get_xoops_search_result($keywords, $andor, $limit, $offset, $uid)
206
        {
207
            // �����׻�
208
            $tzoffset = ($this->user_TZ - $this->server_TZ) * 3600;
209
210
            // ���ƥ��꡼��Ϣ��WHERE������
211
            $whr_categories = $this->get_where_about_categories();
212
213
            // CLASS��Ϣ��WHERE������
214
            $whr_class = $this->get_where_about_class();
215
216
            // ʸ�������
217
            if (!empty($keywords)) {
218
                switch (strtolower($andor)) {
219 View Code Duplication
                    case 'and':
0 ignored issues
show
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...
220
                        $whr_text = '';
221
                        foreach ($keywords as $keyword) {
222
                            $whr_text .= "CONCAT(summary,' ',description) LIKE '%$keyword%' AND ";
223
                        }
224
                        $whr_text = substr($whr_text, 0, -5);
225
                        break;
226 View Code Duplication
                    case 'or':
0 ignored issues
show
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...
227
                        $whr_text = '';
228
                        foreach ($keywords as $keyword) {
229
                            $whr_text .= "CONCAT(summary,' ',description) LIKE '%$keyword%' OR ";
230
                        }
231
                        $whr_text = substr($whr_text, 0, -4);
232
                        break;
233
                    default:
234
                        $whr_text = "CONCAT(summary,'  ',description) LIKE '%{$keywords[0]}%'";
235
                        break;
236
                }
237
            } else {
238
                $whr_text = '1';
239
            }
240
241
            // �桼��ID����
242
            if ($uid > 0) {
243
                $whr_uid = "uid=$uid";
244
            } else {
245
                $whr_uid = '1';
246
            }
247
248
            // XOOPS Search module
249
            $showcontext = empty($_GET['showcontext']) ? 0 : 1;
250
            $select4con  = $showcontext ? 'description' : "'' AS description";
251
252
            // SQLʸ����
253
            $sql = "SELECT id,uid,summary,UNIX_TIMESTAMP(dtstamp) AS udtstamp, start, end, allday, start_date, end_date, extkey0, $select4con FROM $this->table WHERE admission>0 AND (rrule_pid=0 OR rrule_pid=id) AND ($whr_categories) AND ($whr_class) AND ($whr_text) AND ($whr_uid) ORDER BY dtstamp DESC LIMIT $offset,$limit";
254
            // ������
255
            $rs = $GLOBALS['xoopsDB']->query($sql);
256
257
            $ret     = array();
258
            $context = '';
259
            $myts    = MyTextSanitizer::getInstance();
260
            while ($event = $GLOBALS['xoopsDB']->fetchObject($rs)) {
261 View Code Duplication
                if (isset($event->start_date)) {
0 ignored issues
show
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...
262
                    $start_str = $event->start_date;
263
                } elseif ($event->allday) {
264
                    $start_str = $this->get_long_ymdn($event->start);
265
                } else {
266
                    $start_str = $this->get_long_ymdn($event->start + $tzoffset);
267
                }
268
269 View Code Duplication
                if (isset($event->end_date)) {
0 ignored issues
show
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...
270
                    $end_str = $event->end_date;
271
                } elseif ($event->allday) {
272
                    $end_str = $this->get_long_ymdn($event->end - 300);
273
                } else {
274
                    $end_str = $this->get_long_ymdn($event->end + $tzoffset);
275
                }
276
277
                $date_desc = ($start_str == $end_str) ? $start_str : "$start_str - $end_str";
278
279
                // get context for module "search"
280
                if (function_exists('search_make_context') && $showcontext) {
281
                    $full_context = strip_tags($myts->displayTarea($event->description, 1, 1, 1, 1, 1));
282
                    if (function_exists('easiestml')) {
283
                        $full_context = easiestml($full_context);
284
                    }
285
                    $context = search_make_context($full_context, $keywords);
286
                }
287
288
                $ret[] = array(
289
                    'image'   => 'assets/images/apcal.gif',
290
                    'link'    => "index.php?action=View&amp;event_id=$event->id",
291
                    'title'   => "[$date_desc] $event->summary",
292
                    'time'    => $event->udtstamp,
293
                    'uid'     => $uid,
294
                    'context' => $context
295
                );
296
            }
297
298
            return $ret;
299
        }
300
301
        // Notifications
302
        // triggerEvent ���Ϥ�URI�ϡ�& �Ƕ��ڤ� (&amp; �ǤϤʤ�)
303
        /**
304
         * @param $event_id
305
         * @return bool
306
         */
307
        public function notify_new_event($event_id)
308
        {
309
            $rs    = $GLOBALS['xoopsDB']->query("SELECT summary,admission,categories,class,uid,groupid FROM $this->table WHERE id='$event_id'");
310
            $event = $GLOBALS['xoopsDB']->fetchObject($rs);
311
312
            // No notification if not admitted yet
313
            if (!$event->admission) {
314
                return false;
315
            }
316
317
            // Private events
318
            if ($event->class === 'PRIVATE') {
319
                if ($event->groupid > 0) {
320
                    $memberHandler = xoops_getHandler('member');
321
                    $user_list      = $memberHandler->getUsersByGroup($event->groupid);
322
                } else {
323
                    $user_list = array($event->uid);
324
                }
325
            } else {
326
                $user_list = array();
327
            }
328
329
            $notificationHandler = xoops_getHandler('notification');
330
331
            // �����٥�Ȥ���Ͽ�������ƥ��꡼�ˤΥȥꥬ��
332
            $notificationHandler->triggerEvent('global', 0, 'new_event', array(
333
                'EVENT_SUMMARY' => $event->summary,
334
                'EVENT_URI'     => "$this->base_url/index.php?action=View&event_id=$event_id"
335
            ), $user_list, null, 0);
336
337
            // �����٥�Ȥ���Ͽ�ʥ��ƥ��꡼��ˤΥȥꥬ��
338
            $cids = explode(',', $event->categories);
339
            foreach ($cids as $cid) {
340
                $cid = (int)$cid;
341
                if (isset($this->categories[$cid])) {
342
                    $notificationHandler->triggerEvent('category', $cid, 'new_event', array(
343
                        'EVENT_SUMMARY'  => $event->summary,
344
                        'CATEGORY_TITLE' => $this->text_sanitizer_for_show($this->categories[$cid]->cat_title),
345
                        'EVENT_URI'      => "$this->base_url/index.php?smode=List&cid=$cid"
346
                    ), $user_list, null, 0);
347
                }
348
            }
349
350
            return true;
351
        }
352
353
        // $this->caldate���ͽ��֥�å�������֤�
354
355
        /**
356
         * @param  string $get_target
357
         * @return array
358
         */
359
        public function get_blockarray_date_event($get_target = '')
360
        {
361
            // if( $get_target == '' ) $get_target = $_SERVER['SCRIPT_NAME'] ;
362
363
            // ������׻����Ĥġ�WHERE��δ�֤˴ؤ���������
364
            $tzoffset          = (int)(($this->user_TZ - $this->server_TZ) * 3600);
365
            $toptime_of_day    = $this->unixtime + $this->day_start - $tzoffset;
366
            $bottomtime_of_day = $toptime_of_day + 86400;
367
            $whr_term          = "(allday AND start<='$this->unixtime' AND end>'$this->unixtime') || ( ! allday AND start<'$bottomtime_of_day' AND (start='$toptime_of_day' OR end>'$toptime_of_day'))";
368
369
            // ���ƥ��꡼��Ϣ��WHERE������
370
            $whr_categories = $this->get_where_about_categories();
371
372
            // CLASS��Ϣ��WHERE������
373
            $whr_class = $this->get_where_about_class();
374
375
            // ����Υ������塼�����
376
            $yrs      = $GLOBALS['xoopsDB']->query("SELECT start,end,summary,id,uid,allday,location,contact,description,(start>='$toptime_of_day') AS is_start_date,(end<='$bottomtime_of_day') AS is_end_date FROM $this->table WHERE admission>0 AND ($whr_term) AND ($whr_categories) AND ($whr_class) ORDER BY start,end");
377
            $num_rows = $GLOBALS['xoopsDB']->getRowsNum($yrs);
378
379
            $block = array(
380
                'insertable'                      => $this->insertable,
381
                'num_rows'                        => $num_rows,
382
                'get_target'                      => $get_target,
383
                'images_url'                      => $this->images_url,
384
                'caldate'                         => $this->caldate,
385
                'lang_APCAL_MB_CONTINUING'   => _APCAL_MB_CONTINUING,
386
                'lang_APCAL_MB_NOEVENT'      => _APCAL_MB_NOEVENT,
387
                'lang_APCAL_MB_ADDEVENT'     => _APCAL_MB_ADDEVENT,
388
                'lang_APCAL_MB_ALLDAY_EVENT' => _APCAL_MB_ALLDAY_EVENT
389
            );
390
391
            while ($event = $GLOBALS['xoopsDB']->fetchObject($yrs)) {
392
                if (!$event->allday) {
393
                    // �̾磻�٥��
394
                    // $event->start,end �ϥ����л���  $start,$end �ϥ桼������
395
                    $start = $event->start + $tzoffset;
396
                    $end   = $event->end + $tzoffset;
397
398
                    // ����˳��Ϥ佪λ���뤫�ǥɥå�GIF���ؤ���
399
                    if ($event->is_start_date) {
400
                        $dot = 'dot_startday.gif';
401
                    } elseif ($event->is_end_date) {
402
                        $dot = 'dot_endday.gif';
403
                    } else {
404
                        $dot = 'dot_interimday.gif';
405
                    }
406
407
                    // $day_start ���꤬������Ρ�24:00�ʹߤν���
408 View Code Duplication
                    if ($event->is_start_date && $bottomtime_of_day - $event->start <= $this->day_start) {
0 ignored issues
show
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...
409
                        $start_desc = $this->get_middle_hi($start, true);
410
                    } else {
411
                        $start_desc = $this->get_middle_hi($start);
412
                    }
413
414
                    if ($event->is_end_date) {
415
                        // $day_start ���꤬������Ρ�24:00�ʹߤν���
416 View Code Duplication
                        if ($bottomtime_of_day - $event->end <= $this->day_start) {
0 ignored issues
show
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...
417
                            $end_desc = $this->get_middle_hi($end, true);
418
                        } else {
419
                            $end_desc = $this->get_middle_hi($end);
420
                        }
421
                    } else {
422
                        $end_desc = $this->get_middle_md($end);
423
                    }
424
425
                    // �̾磻�٥�Ȥ����󥻥å�
426
                    $block['events'][] = array(
427
                        'summary'       => $this->text_sanitizer_for_show($event->summary),
428
                        'location'      => $this->text_sanitizer_for_show($event->location),
429
                        'contact'       => $this->text_sanitizer_for_show($event->contact),
430
                        'description'   => $this->textarea_sanitizer_for_show($event->description),
431
                        'allday'        => $event->allday,
432
                        'start'         => $start,
433
                        'start_desc'    => $start_desc,
434
                        'end'           => $end,
435
                        'end_desc'      => $end_desc,
436
                        'id'            => $event->id,
437
                        'uid'           => $event->uid,
438
                        'dot_gif'       => $dot,
439
                        'is_start_date' => $event->is_start_date,
440
                        'is_end_date'   => $event->is_end_date
441
                    );
442
                } else {
443
                    // ����٥�Ȥ����󥻥å�
444
                    $block['events'][] = array(
445
                        'summary'       => $this->text_sanitizer_for_show($event->summary),
446
                        'location'      => $this->text_sanitizer_for_show($event->location),
447
                        'contact'       => $this->text_sanitizer_for_show($event->contact),
448
                        'description'   => $this->textarea_sanitizer_for_show($event->description),
449
                        'allday'        => $event->allday,
450
                        'start'         => $event->start,
451
                        'end'           => $event->end,
452
                        'id'            => $event->id,
453
                        'uid'           => $event->uid,
454
                        'dot_gif'       => 'dot_allday.gif',
455
                        'is_start_date' => $event->is_start_date,
456
                        'is_end_date'   => $event->is_end_date
457
                    );
458
                }
459
            }
460
461
            return $block;
462
        }
463
464
        // $this->caldate�ʹߤ�ͽ��֥�å�������֤�
465
466
        /**
467
         * @param  string $get_target
468
         * @param  int    $num
469
         * @param  bool   $for_coming
470
         * @param  int    $untildays
471
         * @return array
472
         */
473
        public function get_blockarray_coming_event($get_target = '', $num = 5, $for_coming = false, $untildays = 0)
474
        {
475
            // if( $get_target == '' ) $get_target = $_SERVER['SCRIPT_NAME'] ;
476
            $now = $for_coming ? time() : $this->unixtime + $this->day_start;
477
478
            // ������׻����Ƥ���
479
            $tzoffset = (int)(($this->user_TZ - $this->server_TZ) * 3600);
480
481
            if ($for_coming) {
482
                // �ֺ����ͽ��פΤߡ�����оݤ����ն����ǤϤʤ��������� (thx Chado)
483
                $whr_term = "end>'$now'";
484
            } elseif ($tzoffset == 0) {
485
                $whr_term = "end>'$now'";
486
            } else {
487
                // ������������ϡ�allday�ˤ�äƾ��ʬ��
488
                $whr_term = "(allday AND end>'$now') || ( ! allday AND ( start >= '$now' OR end>'" . ($now - $tzoffset) . "'))";
489
            }
490
491
            // ���ƥ��꡼��Ϣ��WHERE������
492
            $whr_categories = $this->get_where_about_categories();
493
494
            // CLASS��Ϣ��WHERE������
495
            $whr_class = $this->get_where_about_class();
496
497
            // ������
498
            //            $yrs      = $xoopsDB->query("SELECT COUNT(*) FROM $this->table WHERE admission>0 AND ($whr_term) AND ($whr_categories) AND ($whr_class)");
499
            //            $num_rows = mysql_result($yrs, 0, 0);
500
            //            $yrs = $xoopsDB->query("SELECT start,end,summary,id,uid,allday,location,contact,description,mainCategory FROM $this->table WHERE admission>0 AND ($whr_term) AND ($whr_categories) AND ($whr_class) ORDER BY start LIMIT $num");
501
502
            $yrs       = $GLOBALS['xoopsDB']->query("SELECT COUNT(*) FROM $this->table WHERE admission>0 AND ($whr_term) AND ($whr_categories) AND ($whr_class)");
503
            $num_rows   = 0;
504
            $resultRow = $GLOBALS['xoopsDB']->fetchRow($yrs);
505
            if (false !== $resultRow && isset($resultRow[0])) {
506
                $num_rows = $resultRow[0];
507
            }
508
            $yrs = $GLOBALS['xoopsDB']->query("SELECT start,end,summary,id,uid,allday,location,contact,description,mainCategory,extkey0 FROM $this->table WHERE admission>0 AND ($whr_term) AND ($whr_categories) AND ($whr_class) ORDER BY start LIMIT $num");
509
510
            $block = array(
511
                'insertable'                       => $this->insertable,
512
                'num_rows'                         => $num_rows,
513
                'get_target'                       => $get_target,
514
                'images_url'                       => $this->images_url,
515
                'caldate'                          => $this->caldate,
516
                'lang_APCAL_MB_CONTINUING'    => _APCAL_MB_CONTINUING,
517
                'lang_APCAL_MB_NOEVENT'       => _APCAL_MB_NOEVENT,
518
                'lang_APCAL_MB_ADDEVENT'      => _APCAL_MB_ADDEVENT,
519
                'lang_APCAL_MB_RESTEVENT_PRE' => _APCAL_MB_RESTEVENT_PRE,
520
                'lang_APCAL_MB_RESTEVENT_SUF' => _APCAL_MB_RESTEVENT_SUF,
521
                'lang_APCAL_MB_ALLDAY_EVENT'  => _APCAL_MB_ALLDAY_EVENT
522
            );
523
524
            $count = 0;
525
            //            while ($event = $xoopsDB->fetchObject($yrs)) {
526
            while ($event = $GLOBALS['xoopsDB']->fetchObject($yrs)) {
527
                if (++$count > $num) {
528
                    break;
529
                }
530
531
                // ������$untildays�����Ǥ���С��������Ǥ��ڤ�
532
                if ($untildays > 0 && $event->start > $this->unixtime + $untildays * 86400) {
533
                    $num_rows = $count;
534
                    break;
535
                }
536
537
                // $event->start,end �ϥ����л���  $start,$end �ϥ桼������
538
                if ($event->allday) {
539
                    $can_time_disp  = false;
540
                    $start_for_time = $start_for_date = $event->start + $tzoffset;
541
                    $end_for_time   = $end_for_date = $event->end - 300 + $tzoffset;
542
                } else {
543
                    $can_time_disp  = $for_coming;
544
                    $start_for_time = $event->start + $tzoffset;
545
                    $start_for_date = $event->start + $tzoffset - $this->day_start;
546
                    $end_for_time   = $event->end + $tzoffset;
547
                    $end_for_date   = $event->end + $tzoffset - $this->day_start;
548
                }
549
550
                if ($event->start < $now) { // TODO zer0fill  $now + $tzoffset ���?��?
551
                    // already started
552
                    $distance   = 0;
553
                    $dot        = 'dot_started.gif';
554
                    $start_desc = '';
555 View Code Duplication
                    if ($event->end - $now < 86400 && $can_time_disp) {
0 ignored issues
show
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...
556
                        if (date('G', $end_for_time) * 3600 <= $this->day_start) {
557
                            $end_desc = $this->get_middle_hi($end_for_time, true);
558
                        } else {
559
                            $end_desc = $this->get_middle_hi($end_for_time);
560
                        }
561
                    } else {
562
                        $end_desc = $this->get_middle_md($end_for_date);
563
                    }
564
                } elseif ($event->start - $now < 86400) {
565
                    // near event (24hour)
566
                    $dot = 'dot_today.gif';
567 View Code Duplication
                    if ($can_time_disp) {
0 ignored issues
show
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...
568
                        if (date('G', $start_for_time) * 3600 < $this->day_start) {
569
                            $start_desc = $this->get_middle_hi($start_for_time, true);
570
                        } else {
571
                            $start_desc = $this->get_middle_hi($start_for_time);
572
                        }
573
                    } else {
574
                        $start_desc = $this->get_middle_md($start_for_date);
575
                    }
576
                    if ($event->end - $now < 86400 && $can_time_disp) {
577
                        if (date('G', $end_for_time) * 3600 <= $this->day_start) {
578
                            $end_desc = $this->get_middle_hi($end_for_time, true);
579
                        } else {
580
                            $end_desc = $this->get_middle_hi($end_for_time);
581
                        }
582
                        $distance = 1;
583
                    } else {
584
                        $end_desc = $this->get_middle_md($end_for_date);
585
                        $distance = 2;
586
                    }
587
                } else {
588
                    // far event (>1day)
589
                    $distance   = 3;
590
                    $dot        = 'dot_future.gif';
591
                    $start_desc = $this->get_middle_md($start_for_date);
592
                    $end_desc   = $this->get_middle_md($end_for_date);
593
                }
594
595
                $multiday = (int)date('j', $end_for_time) > (int)date('j', $start_for_time);
596
597
                $pic = $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->query("SELECT picture FROM {$this->pic_table} WHERE event_id={$event->id} AND main_pic=1 LIMIT 0,1"));
598
                $cat = $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->query("SELECT cat_title FROM {$this->cat_table} WHERE cid={$event->mainCategory} LIMIT 0,1"));
599
600
                $block['events'][] = array(
601
                    'summary'     => $this->text_sanitizer_for_show($event->summary),
602
                    'location'    => $this->text_sanitizer_for_show($event->location),
603
                    'contact'     => $this->text_sanitizer_for_show($event->contact),
604
                    'description' => $this->textarea_sanitizer_for_show($event->description),
605
                    'allday'      => $event->allday,
606
                    'start'       => $start_for_time,
607
                    'start_desc'  => $start_desc,
608
                    'end'         => $end_for_time,
609
                    'end_desc'    => $end_desc,
610
                    'id'          => $event->id,
611
                    'uid'         => $event->uid,
612
                    'dot_gif'     => $dot,
613
                    'distance'    => $distance,
614
                    'multiday'    => $multiday,
615
                    'picture'     => $pic ? $pic->picture : '',
616
                    'extkey0'     => $event->extkey0,
617
                    'mainCat_id'  => $event->mainCategory,
618
                    'mainCat'     => $cat ? htmlentities($cat->cat_title, ENT_QUOTES, 'UTF-8') : ''
619
                );
620
            }
621
622
            $block['num_rows_rest'] = $num_rows - $count;
623
624
            return $block;
625
        }
626
627
        // ��������Ͽ���줿ͽ��֥�å�������֤�
628
629
        /**
630
         * @param  string $get_target
631
         * @param  int    $num
632
         * @return array
633
         */
634
        public function get_blockarray_new_event($get_target = '', $num = 5)
635
        {
636
            // if( $get_target == '' ) $get_target = $_SERVER['SCRIPT_NAME'] ;
637
638
            // tzoffset
639
            $tzoffset = ($this->user_TZ - $this->server_TZ) * 3600;
640
641
            // ���ƥ��꡼��Ϣ��WHERE������
642
            $whr_categories = $this->get_where_about_categories();
643
644
            // CLASS��Ϣ��WHERE������
645
            $whr_class = $this->get_where_about_class();
646
647
            // ��������˥������塼�����
648
            $yrs = $GLOBALS['xoopsDB']->query("SELECT id,uid,summary,UNIX_TIMESTAMP(dtstamp) AS udtstamp , start, end, allday, start_date, end_date FROM $this->table WHERE admission>0 AND ($whr_categories) AND ($whr_class) AND (rrule_pid=0 OR rrule_pid=id) ORDER BY dtstamp DESC");
649
650
            $num_rows = $GLOBALS['xoopsDB']->getRowsNum($yrs);
651
652
            $block = array(
653
                'insertable'                       => $this->insertable,
654
                'num_rows'                         => $num_rows,
655
                'get_target'                       => $get_target,
656
                'images_url'                       => $this->images_url,
657
                'caldate'                          => $this->caldate,
658
                'lang_APCAL_MB_CONTINUING'    => _APCAL_MB_CONTINUING,
659
                'lang_APCAL_MB_NOEVENT'       => _APCAL_MB_NOEVENT,
660
                'lang_APCAL_MB_ADDEVENT'      => _APCAL_MB_ADDEVENT,
661
                'lang_APCAL_MB_RESTEVENT_PRE' => _APCAL_MB_RESTEVENT_PRE,
662
                'lang_APCAL_MB_RESTEVENT_SUF' => _APCAL_MB_RESTEVENT_SUF,
663
                'lang_APCAL_MB_ALLDAY_EVENT'  => _APCAL_MB_ALLDAY_EVENT
664
            );
665
666
            $count = 0;
667
            while ($event = $GLOBALS['xoopsDB']->fetchObject($yrs)) {
668
                if (++$count > $num) {
669
                    break;
670
                }
671
672 View Code Duplication
                if (isset($event->start_date)) {
0 ignored issues
show
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...
673
                    $start_str = $event->start_date;
674
                } elseif ($event->allday) {
675
                    $start_str = $this->get_long_ymdn($event->start);
676
                } else {
677
                    $start_str = $this->get_long_ymdn($event->start + $tzoffset);
678
                }
679
680 View Code Duplication
                if (isset($event->end_date)) {
0 ignored issues
show
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...
681
                    $end_str = $event->end_date;
682
                } elseif ($event->allday) {
683
                    $end_str = $this->get_long_ymdn($event->end - 300);
684
                } else {
685
                    $end_str = $this->get_long_ymdn($event->end + $tzoffset);
686
                }
687
688
                $date_desc         = ($start_str == $end_str) ? $start_str : "$start_str - $end_str";
689
                $block['events'][] = array(
690
                    'summary'    => $this->text_sanitizer_for_show($event->summary),
691
                    'allday'     => $event->allday,
692
                    'start'      => $event->start,
693
                    'start_desc' => $start_str,
694
                    'end'        => $event->end,
695
                    'end_desc'   => $end_str,
696
                    'date_desc'  => $date_desc,
697
                    'post_date'  => formatTimestamp($event->udtstamp),
698
                    'uid'        => $event->uid,
699
                    'id'         => $event->id
700
                );
701
            }
702
703
            $block['num_rows_rest'] = $num_rows - $count;
704
705
            return $block;
706
        }
707
708
        // Get the events list view
709
710
        /**
711
         * @param         $tpl
712
         * @param  string $get_target
713
         * @return bool
714
         */
715
        public function assign_event_list(&$tpl, $get_target = '')
716
        {
717
            $pos = isset($_GET['pos']) ? (int)$_GET['pos'] : 0;
718
            $num = isset($_GET['num']) ? (int)$_GET['num'] : 20;
719
720
            $roimage = XOOPS_URL . '/modules/apcal/assets/images/regonline/regonline.png'; // added by goffy: image for online registration
721
722
            // �����Ƚ�
723
            $orders = array(
724
                'summary'      => _APCAL_TH_SUMMARY . ' ' . _APCAL_MB_ORDER_ASC,
725
                'summary DESC' => _APCAL_TH_SUMMARY . ' ' . _APCAL_MB_ORDER_DESC,
726
                'start'        => _APCAL_TH_STARTDATETIME . ' ' . _APCAL_MB_ORDER_ASC,
727
                'start DESC'   => _APCAL_TH_STARTDATETIME . ' ' . _APCAL_MB_ORDER_DESC,
728
                'dtstamp'      => _APCAL_TH_LASTMODIFIED . ' ' . _APCAL_MB_ORDER_ASC,
729
                'dtstamp DESC' => _APCAL_TH_LASTMODIFIED . ' ' . _APCAL_MB_ORDER_DESC,
730
                'uid'          => _APCAL_TH_SUBMITTER . ' ' . _APCAL_MB_ORDER_ASC,
731
                'uid DESC'     => _APCAL_TH_SUBMITTER . ' ' . _APCAL_MB_ORDER_DESC
732
            );
733
            if (isset($_GET['order']) && isset($orders[$_GET['order']])) {
734
                $order = $_GET['order'];
735
            } else {
736
                $order = 'start';
737
            }
738
739
            // tzoffset
740
            $tzoffset = ($this->user_TZ - $this->server_TZ) * 3600;
0 ignored issues
show
$tzoffset is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
741
742
            $cat_desc = !empty($this->now_cid)
743
                        && !empty($this->categories[$this->now_cid]) ? $this->textarea_sanitizer_for_show($this->categories[$this->now_cid]->cat_desc) : '';
744
745
            $whr_categories = $this->get_where_about_categories();
746
            $whr_class      = $this->get_where_about_class();
747
748
            $categories_selform = $this->get_categories_selform($get_target);
749
750
            $ops = array(
751
                'after'  => _APCAL_MB_OP_AFTER,
752
                'on'     => _APCAL_MB_OP_ON,
753
                'before' => _APCAL_MB_OP_BEFORE,
754
                'all'    => _APCAL_MB_OP_ALL
755
            );
756
757
            $op             = empty($_GET['op']) ? '' : preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['op']);
758
            $tzoffset       = (int)(($this->user_TZ - $this->server_TZ) * 3600);
759
            $toptime_of_day = $this->unixtime + $this->day_start;
760
            switch ($op) {
761
                case 'all':
762
                    $whr_term = '1';
763
                    break;
764
                case 'before':
765
                    $whr_term = "(allday AND start<='$this->unixtime') || ( ! allday AND start<='" . ($toptime_of_day + 86400 - $tzoffset) . "')";
766
                    //$whr_term = "start<$this->unixtime" ;
767
                    break;
768
                default:
769
                case 'after':
0 ignored issues
show
case 'after': $op = ...et) . '\')'; break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
770
                    $op       = 'after';
771
                    $whr_term = "(allday AND end>'$this->unixtime') || ( ! allday AND end>'" . ($toptime_of_day - $tzoffset) . "')";
772
                    //$whr_term = "end>$this->unixtime" ;
773
                    break;
774
                case 'on':
775
                    $whr_term = "(allday AND start<='$this->unixtime' AND end>'$this->unixtime') || ( ! allday AND start<='"
776
                                . ($toptime_of_day + 86400 - $tzoffset)
777
                                . "' AND end>'"
778
                                . ($toptime_of_day
779
                                   - $tzoffset)
780
                                . "')";
781
                    break;
782
            }
783
784
            // ���ձ黻�Ҥ���������
785
            $op_options = '';
786
            foreach ($ops as $op_id => $op_title) {
787
                if ($op_id == $op) {
788
                    $op_options .= "\t\t\t<option value='$op_id' selected>$op_title</option>\n";
789
                } else {
790
                    $op_options .= "\t\t\t<option value='$op_id'>$op_title</option>\n";
791
                }
792
            }
793
794
            // ǯ�������(2001��2020 �Ȥ���)
795
            $year_options = '';
796 View Code Duplication
            for ($y = 2001; $y <= 2020; ++$y) {
0 ignored issues
show
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...
797
                if ($y == $this->year) {
798
                    $year_options .= "\t\t\t<option value='$y' selected>" . sprintf(strip_tags(_APCAL_FMT_YEAR), $y) . "</option>\n";
799
                } else {
800
                    $year_options .= "\t\t\t<option value='$y'>" . sprintf(strip_tags(_APCAL_FMT_YEAR), $y) . "</option>\n";
801
                }
802
            }
803
804
            // ��������
805
            $month_options = '';
806 View Code Duplication
            for ($m = 1; $m <= 12; ++$m) {
0 ignored issues
show
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...
807
                if ($m == $this->month) {
808
                    $month_options .= "\t\t\t<option value='$m' selected>{$this->month_short_names[$m]}</option>\n";
809
                } else {
810
                    $month_options .= "\t\t\t<option value='$m'>{$this->month_short_names[$m]}</option>\n";
811
                }
812
            }
813
814
            // ��������
815
            $date_options = '';
816 View Code Duplication
            for ($d = 1; $d <= 31; ++$d) {
0 ignored issues
show
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...
817
                if ($d == $this->date) {
818
                    $date_options .= "\t\t\t<option value='$d' selected>{$this->date_short_names[$d]}</option>\n";
819
                } else {
820
                    $date_options .= "\t\t\t<option value='$d'>{$this->date_short_names[$d]}</option>\n";
821
                }
822
            }
823
824
            $ymdo_selects = sprintf(_APCAL_FMT_YMDO, "<select name='apcal_year'>$year_options</select>", "<select name='apcal_month'>$month_options</select>",
825
                                    "<select name='apcal_date'>$date_options</select>", "<select name='op'>$op_options</select>");
826
827
            // �쥳���ɿ��μ���
828
            $whr      = "($whr_term) AND ($whr_categories) AND ($whr_class)";
829
            $yrs      = $GLOBALS['xoopsDB']->query("SELECT *,UNIX_TIMESTAMP(dtstamp) AS udtstamp , start, end, allday, start_date, end_date, extkey0 FROM $this->table WHERE $whr");
830
            $num_rows = $GLOBALS['xoopsDB']->getRowsNum($yrs);
831
832
            // �ܥ�����
833
            $yrs = $GLOBALS['xoopsDB']->query("SELECT *,UNIX_TIMESTAMP(dtstamp) AS udtstamp , start, end, allday, start_date, end_date, mainCategory, extkey0 FROM $this->table WHERE $whr ORDER BY $order LIMIT $pos,$num");
834
835
            // �ڡ���ʬ�����
836
            require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
837
            $nav      = new XoopsPageNav($num_rows, $num, $pos, 'pos', "smode=List&amp;cid=$this->now_cid&amp;num=$num&amp;order=$order&amp;op=$op&amp;caldate=$this->caldate");
838
            $nav_html = $nav->renderNav(5);
839 View Code Duplication
            if ($num_rows <= 0) {
0 ignored issues
show
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...
840
                $nav_num_info = _NONE;
841
            } elseif ($pos + $num > $num_rows) {
842
                $nav_num_info = ($pos + 1) . "-$num_rows/$num_rows";
843
            } else {
844
                $nav_num_info = ($pos + 1) . '-' . ($pos + $num) . '/' . $num_rows;
845
            }
846
847
            // �����ѿ��Υ�������
848
            $tpl->assign(array(
849
                             'page_nav'              => $nav_html,
850
                             'page_nav_info'         => $nav_num_info,
851
                             'categories_selform'    => $categories_selform,
852
                             'cat_desc'              => $cat_desc,
853
                             'insertable'            => $this->insertable,
854
                             'get_target'            => $get_target,
855
                             'num'                   => $num,
856
                             'now_cid'               => $this->now_cid,
857
                             'num_rows'              => $num_rows,
858
                             'images_url'            => $this->images_url,
859
                             'mod_url'               => $this->base_url,
860
                             'caldate'               => $this->caldate,
861
                             'op'                    => $op,
862
                             'order'                 => $order,
863
                             'user_can_output_ics'   => $this->can_output_ics,
864
                             'print_link'            => "$this->base_url/print.php?cid=$this->now_cid&amp;smode=List&amp;num=$num&amp;pos=$pos&amp;order="
865
                                                        . urlencode($order)
866
                                                        . "&amp;caldate=$this->caldate",
867
                             'apcal_copyright'       => _MD_APCAL_COPYRIGHT,
868
                             'ymdo_selects'          => $ymdo_selects,
869
                             'calhead_bgcolor'       => $this->calhead_bgcolor,
870
                             'calhead_color'         => $this->calhead_color,
871
                             'alt_list'              => _APCAL_ICON_LIST,
872
                             'alt_daily'             => _APCAL_ICON_DAILY,
873
                             'alt_weekly'            => _APCAL_ICON_WEEKLY,
874
                             'alt_monthly'           => _APCAL_ICON_MONTHLY,
875
                             'alt_yearly'            => _APCAL_ICON_YEARLY,
876
                             'alt_print'             => _APCAL_BTN_PRINT,
877
                             'lang_checkeditems'     => _APCAL_MB_LABEL_CHECKEDITEMS,
878
                             'lang_icalendar_output' => _APCAL_MB_LABEL_OUTPUTICS,
879
                             'lang_button_export'    => _APCAL_BTN_EXPORT,
880
                             'lang_button_jump'      => _APCAL_BTN_JUMP,
881
                             'lang_order'            => $orders[$order],
882
                             'lang_summary'          => _APCAL_TH_SUMMARY,
883
                             'lang_startdatetime'    => _APCAL_TH_STARTDATETIME,
884
                             'lang_enddatetime'      => _APCAL_TH_ENDDATETIME,
885
                             'lang_location'         => _APCAL_TH_LOCATION,
886
                             'lang_contact'          => _APCAL_TH_CONTACT,
887
                             'lang_description'      => _APCAL_TH_DESCRIPTION,
888
                             'lang_categories'       => _APCAL_TH_CATEGORIES,
889
                             'lang_submitter'        => _APCAL_TH_SUBMITTER,
890
                             'lang_class'            => _APCAL_TH_CLASS,
891
                             'lang_rrule'            => _APCAL_TH_RRULE,
892
                             'lang_admissionstatus'  => _APCAL_TH_ADMISSIONSTATUS,
893
                             'lang_lastmodified'     => _APCAL_TH_LASTMODIFIED,
894
                             'lang_cursortedby'      => _APCAL_MB_CURSORTEDBY,
895
                             'lang_sortby'           => _APCAL_MB_SORTBY,
896
                             'ro_image'              => $roimage
897
                         ));
898
899
            // ���٥�ȥ�������롼��
900
            $count  = 0;
901
            $events = array();
902
            while ($event = $GLOBALS['xoopsDB']->fetchObject($yrs)) {
903 View Code Duplication
                if ($event->gmlat > 0 || $event->gmlong > 0) {
0 ignored issues
show
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...
904
                    $this->gmPoints[] = array(
905
                        'summary'   => $event->summary,
906
                        'gmlat'     => $event->gmlat,
907
                        'gmlong'    => $event->gmlong,
908
                        'location'  => $event->location,
909
                        'contact'   => $event->contact,
910
                        'startDate' => date('j', $event->start),
911
                        'event_id'  => $event->id
912
                    );
913
                }
914
                if (++$count > $num) {
915
                    break;
916
                }
917
918
                // �Խ���ǽ���ɤ���
919
                $editable = ($this->isadmin || $event->uid == $this->user_id && $this->editable);
920
                // �Խ���ǽ�Ǥʤ�̤��ǧ�쥳���ɤ�ɽ�����ʤ�
921
                if (!$editable && $event->admission == 0) {
922
                    continue;
923
                }
924
925
                // ���ϻ���
926 View Code Duplication
                if (isset($event->start_date)) {
0 ignored issues
show
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...
927
                    $start_date_desc = $event->start_date;
928
                    $start_time_desc = '';
929
                    $start           = 0;
930
                } elseif ($event->allday) {
931
                    $start_date_desc = $this->get_long_ymdn($event->start);
932
                    $start_time_desc = '';
933
                    $start           = $event->start;
934
                } else {
935
                    $start           = $event->start + $tzoffset;
936
                    $start_date_desc = $this->get_long_ymdn($start);
937
                    $start_time_desc = $this->get_middle_hi($start);
938
                }
939
940
                // �����
941 View Code Duplication
                if (isset($event->end_date)) {
0 ignored issues
show
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...
942
                    $end_date_desc = $event->end_date;
943
                    $end_time_desc = '';
944
                    $end           = 0x7fffffff;
945
                } elseif ($event->allday) {
946
                    $end_date_desc = $this->get_long_ymdn($event->end - 300);
947
                    $end_time_desc = '';
948
                    $end           = $event->end;
949
                } else {
950
                    $end           = $event->end + $tzoffset;
951
                    $end_date_desc = $this->get_long_ymdn($end);
952
                    $end_time_desc = $this->get_middle_hi($end);
953
                }
954
955
                // ����¾��ɽ����������
956
                $admission_status = $event->admission ? _APCAL_MB_EVENT_ADMITTED : _APCAL_MB_EVENT_NEEDADMIT;
957
                $last_modified    = $this->get_long_ymdn($event->udtstamp - (int)(($this->user_TZ - $this->server_TZ) * 3600));
958
                $description      = $this->textarea_sanitizer_for_show($event->description);
959
                $summary          = $this->text_sanitizer_for_show($event->summary);
960
                $location         = $this->text_sanitizer_for_show($event->location);
961
                $contact          = $this->text_sanitizer_for_show($event->contact);
962
                $eventURL         = $this->make_event_link($event->id, $get_target, date('Y-n-j', $event->start));
963
                // Get picture
964
                $pic     = $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->query("SELECT picture FROM {$this->pic_table} WHERE event_id={$event->id} AND main_pic=1 LIMIT 0,1"));
965
                $picture = $pic && $this->showPicList ? "<img src='" . XOOPS_UPLOAD_URL . "/apcal/{$pic->picture}' alt='{$summary}' height='50' style='vertical-align: middle;' />" : '';
966
                // Get maincat
967
                $cat = $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->query("SELECT cat_title FROM {$this->cat_table} WHERE cid={$event->mainCategory} LIMIT 0,1")); //added by goffy
968
                $maincat = $cat ? htmlentities($cat->cat_title, ENT_QUOTES, 'UTF-8') : ''; //added by goffy
969
                
970
                $events[] = array(
971
                    'count'           => $count,
972
                    'oddeven'         => $count & 1 == 1 ? 'odd' : 'even',
973
                    'eventURL'        => $eventURL,
974
                    'picture'         => $picture,
975
                    'summary'         => $summary,
976
                    'location'        => $location,
977
                    'contact'         => $contact,
978
                    'description'     => $description,
979
                    'admission'       => $admission_status,
980
                    'editable'        => $editable,
981
                    'allday'          => $event->allday,
982
                    'start'           => $start,
983
                    'start_date_desc' => $start_date_desc,
984
                    'start_time_desc' => $start_time_desc,
985
                    'end'             => $end,
986
                    'end_date_desc'   => $end_date_desc,
987
                    'end_time_desc'   => $end_time_desc,
988
                    'post_date'       => $last_modified,
989
                    'rrule'           => $this->rrule_to_human_language($event->rrule),
990
                    'uid'             => $event->uid,
991
                    'submitter_info'  => $this->get_submitter_info($event->uid),
992
                    'id'              => $event->id,
993
                    'target_id'       => ($event->rrule_pid > 0) ? $event->rrule_pid : $event->id,
994
                    'maincat'         => $maincat, //added by goffy
995
                    'regonline'       => $event->extkey0 //added by goffy
996
                );
997
            }
998
            $tpl->assign('events', $events);
999
1000
            $tpl->assign('YEARLYVIEW', $this->make_cal_link($get_target, 'Yearly', $this->now_cid, $this->caldate));
1001
            $tpl->assign('MONTHLYVIEW', $this->make_cal_link($get_target, 'Monthly', $this->now_cid, $this->caldate));
1002
            $tpl->assign('WEEKLYVIEW', $this->make_cal_link($get_target, 'Weekly', $this->now_cid, $this->caldate));
1003
            $tpl->assign('DAILYVIEW', $this->make_cal_link($get_target, 'Daily', $this->now_cid, $this->caldate));
1004
            $tpl->assign('isAdmin', $this->isadmin);
1005
            $tpl->assign('showSubmitter', $this->nameoruname !== 'none');
1006
1007
            return true;
1008
        }
1009
1010
        // get public ICS via snoopy
1011
1012
        /**
1013
         * @param         $uri
1014
         * @param  bool   $force_http
1015
         * @param  string $user_uri
1016
         * @return string
1017
         */
1018
        public function import_ics_via_fopen($uri, $force_http = true, $user_uri = '')
1019
        {
1020
            $user_uri = empty($user_uri) ? '' : $uri;
0 ignored issues
show
$user_uri is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1021
            // changing webcal://* to http://*
1022
            $uri = str_replace('webcal://', 'http://', $uri);
1023
1024
            if ($force_http) {
1025
                if (0 !== strpos($uri, 'http://')) {
1026
                    $uri = 'http://' . $uri;
1027
                }
1028
            }
1029
1030
            // temporary file for store ics via http
1031
            $ics_cache_file = XOOPS_CACHE_PATH . '/apcal_getics_' . uniqid('');
1032
1033
            // http get via Snoopy
1034
            $error_level_stored = error_reporting();
1035
            error_reporting($error_level_stored & ~E_NOTICE);
1036
            // includes Snoopy class for remote file access
1037
            require_once XOOPS_ROOT_PATH . '/class/snoopy.php';
1038
            $snoopy = new Snoopy;
1039
            // TIMEOUT from config
1040
            // $snoopy->read_timeout = $config['snoopy_timeout'] ;
1041
            $snoopy->read_timeout = 10;
1042
            // Set proxy if needed
1043
            //if ( trim( $config['proxy_host'] ) != '' ) {
1044
            //$snoopy->proxy_host = $config['proxy_host'] ;
1045
            //$snoopy->proxy_port = $config['proxy_port'] > 0 ? (int)( $config['proxy_port'] ) : 8080 ;
1046
            //$snoopy->user = $config['proxy_user'] ;
1047
            //$snoopy->pass = $config['proxy_pass'] ;
1048
            //}
1049
            //URL fetch
1050
            if (!$snoopy->fetch($uri) || !$snoopy->results) {
1051
                return "-1:Could not open uri: $uri";
1052
            }
1053
1054
            $data = $snoopy->results;
1055
            error_reporting($error_level_stored);
1056
1057
            $fp = fopen($ics_cache_file, 'w');
1058
            fwrite($fp, $data);
1059
            fclose($fp);
1060
1061
            $ret = parent::import_ics_via_fopen($ics_cache_file, false, $uri);
1062
            list($records, $calname, $tmpname) = explode(':', $ret, 3);
0 ignored issues
show
The assignment to $tmpname is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1063
            @unlink($ics_cache_file);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1064
1065
            if ($records < 1) {
1066
                return "$records:$calname:$uri";
1067
            } else {
1068
                return $ret;
1069
            }
1070
        }
1071
1072
        // returns assigned array for extensible mini calendar block
1073
1074
        /**
1075
         * @param  int   $gifaday
1076
         * @param  int   $just1gif
1077
         * @param  array $plugins
1078
         * @return array
1079
         */
1080
        public function get_minical_ex($gifaday = 2, $just1gif = 0, $plugins = array())
1081
        {
1082
            $db   = XoopsDatabaseFactory::getDatabaseConnection();
1083
            $myts = MyTextSanitizer::getInstance();
1084
1085
            $tzoffset_s2u = (int)(($this->user_TZ - $this->server_TZ) * 3600);
1086
            $now          = time();
1087
            $user_now_Ynj = date('Y-n-j', $now + $tzoffset_s2u);
1088
1089
            // prev_month points the tail, next_month points the head
1090
            $prev_month = date('Y-n-j', mktime(0, 0, 0, $this->month, 0, $this->year));
1091
            $next_month = date('Y-n-j', mktime(0, 0, 0, $this->month + 1, 1, $this->year));
1092
1093
            $block = array(
1094
                'xoops_url' => XOOPS_URL,
1095
                'mod_url'   => $this->base_url,
1096
                'root_url'  => '',
1097
1098
                'skinpath'         => $this->images_url,
1099
                'frame_css'        => $this->frame_css,
1100
                'month_name'       => $this->month_middle_names[$this->month],
1101
                'year_month_title' => sprintf(_APCAL_FMT_YEAR_MONTH, $this->year, $this->month_middle_names[$this->month]),
1102
                'prev_month'       => $prev_month,
1103
                'next_month'       => $next_month,
1104
                'lang_prev_month'  => _APCAL_MB_PREV_MONTH,
1105
                'lang_next_month'  => _APCAL_MB_NEXT_MONTH,
1106
1107
                'calhead_bgcolor' => $this->calhead_bgcolor,
1108
                'calhead_color'   => $this->calhead_color
1109
            );
1110
1111
            $first_date = getdate(mktime(0, 0, 0, $this->month, 1, $this->year));
1112
            $date       = (-$first_date['wday'] + $this->week_start - 7) % 7;
1113
            $wday_end   = 7 + $this->week_start;
1114
1115
            // Loop of weeknames
1116
            $daynames = array();
1117 View Code Duplication
            for ($wday = $this->week_start; $wday < $wday_end; ++$wday) {
0 ignored issues
show
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...
1118
                if ($wday % 7 == 0) {
1119
                    //  Sunday
1120
                    $bgcolor = $this->sunday_bgcolor;
1121
                    $color   = $this->sunday_color;
1122
                } elseif ($wday == 6) {
1123
                    //  Saturday
1124
                    $bgcolor = $this->saturday_bgcolor;
1125
                    $color   = $this->saturday_color;
1126
                } else {
1127
                    // Weekday
1128
                    $bgcolor = $this->weekday_bgcolor;
1129
                    $color   = $this->weekday_color;
1130
                }
1131
1132
                // assigning weeknames
1133
                $daynames[] = array(
1134
                    'bgcolor' => $bgcolor,
1135
                    'color'   => $color,
1136
                    'dayname' => $this->week_short_names[$wday % 7]
1137
                );
1138
            }
1139
            $block['daynames'] = $daynames;
1140
1141
            // get the result of plugins
1142
            $plugin_returns   = array();
1143
            $tzoffset_s2u     = (int)(($this->user_TZ - $this->server_TZ) * 3600);
1144
            $block['plugins'] = $plugins;
1145
            foreach ($plugins as $plugin) {
1146
                $plugin_fullpath = $this->base_path . '/' . $this->plugins_path_monthly . '/' . $plugin['file'];
1147
                if (file_exists($plugin_fullpath)) {
1148
                    include $plugin_fullpath;
1149
                }
1150
            }
1151
1152
            // Loop of week (row)
1153
            $weeks = array();
1154
            for ($week = 0; $week < 6; ++$week) {
1155
                $days = array();
1156
                // Loop of day (col)
1157
                for ($wday = $this->week_start; $wday < $wday_end; ++$wday) {
1158
                    ++$date;
1159
1160
                    $time = mktime(0, 0, 0, $this->month, $date, $this->year);
1161
1162
                    // Out of the month
1163
                    if (!checkdate($this->month, $date, $this->year)) {
1164
                        $days[] = array(
1165
                            'date' => date('j', $time),
1166
                            'type' => 0
1167
                        );
1168
                        continue;
1169
                    }
1170
1171
                    $link = "$this->year-$this->month-$date";
1172
1173
                    // COLORS of days
1174 View Code Duplication
                    if (isset($this->holidays[$link])) {
0 ignored issues
show
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...
1175
                        // Holiday
1176
                        $bgcolor = $this->holiday_bgcolor;
1177
                        $color   = $this->holiday_color;
1178
                    } elseif ($wday % 7 == 0) {
1179
                        // Sunday
1180
                        $bgcolor = $this->sunday_bgcolor;
1181
                        $color   = $this->sunday_color;
1182
                    } elseif ($wday == 6) {
1183
                        // Saturday
1184
                        $bgcolor = $this->saturday_bgcolor;
1185
                        $color   = $this->saturday_color;
1186
                    } else {
1187
                        // Weekday
1188
                        $bgcolor = $this->weekday_bgcolor;
1189
                        $color   = $this->weekday_color;
1190
                    }
1191
1192
                    // Hi-Lighting the SELECTED DATE
1193
                    if ($link == $user_now_Ynj) {
1194
                        $bgcolor = $this->targetday_bgcolor;
1195
                    }
1196
1197
                    // Preparing the returns from plugins
1198
                    $ex = empty($plugin_returns[$date]) ? array() : array_slice($plugin_returns[$date], 0, $gifaday);
1199
                    // if( ! empty( $ex ) ) var_dump( $ex ) ;
1200
1201
                    // Assigning attribs of the day
1202
                    $days[] = array(
1203
                        'bgcolor' => $bgcolor,
1204
                        'color'   => $color,
1205
                        'link'    => $link,
1206
                        'date'    => $date,
1207
                        'type'    => 1,
1208
                        'ex'      => $ex
1209
                    );
1210
                }
1211
                $weeks[] = $days;
1212
            }
1213
            $block['weeks'] = $weeks;
1214
1215
            return $block;
1216
        }
1217
1218
        // ���ꤵ�줿type�Υץ饰����������֤�
1219
1220
        /**
1221
         * @param $type
1222
         * @return array
1223
         */
1224
        public function get_plugins($type)
1225
        {
1226
            global $xoopsDB, $xoopsUser;
1227
1228
            // MyTextSanitizer
1229
            $myts = MyTextSanitizer::getInstance();
1230
1231
            // allowed modules
1232
            $modulepermHandler = xoops_getHandler('groupperm');
1233
            $groups             = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
1234
            $allowed_mids       = $modulepermHandler->getItemIds('module_read', $groups);
1235
1236
            // plugins
1237
            $plugins = array();
1238
            $prs     = $GLOBALS['xoopsDB']->query("SELECT pi_title,pi_dirname AS dirname,pi_file AS file,pi_dotgif AS dotgif,pi_options AS options FROM $this->plugin_table WHERE pi_type='"
1239
                                                  . addslashes($type)
1240
                                                  . "' AND pi_enabled ORDER BY pi_weight");
1241
            while ($plugin = $GLOBALS['xoopsDB']->fetchArray($prs)) {
1242
                $dirname4sql = addslashes($plugin['dirname']);
1243
                $mrs         = $GLOBALS['xoopsDB']->query('SELECT mid,name FROM ' . $GLOBALS['xoopsDB']->prefix('modules') . " WHERE dirname='$dirname4sql'");
1244
                if ($mrs && $GLOBALS['xoopsDB']->getRowsNum($mrs)) {
1245
                    list($mid, $name) = $GLOBALS['xoopsDB']->fetchRow($mrs);
1246
                    if (!in_array($mid, $allowed_mids)) {
1247
                        continue;
1248
                    }
1249
                    $plugin['pi_title'] = $myts->htmlSpecialChars($plugin['pi_title']);
1250
                    $plugin['name']     = $myts->htmlSpecialChars($name);
1251
                    $plugin['mid']      = $mid;
1252
                    $plugins[]          = $plugin;
1253
                }
1254
            }
1255
1256
            return $plugins;
1257
        }
1258
1259
        // The End of Class
1260
    }
1261
}
1262