Completed
Branch master (d598f1)
by Michael
02:16
created

index.php (3 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       Antiques Promotion (http://www.antiquespromotion.ca)
19
 * @author       GIJ=CHECKMATE (PEAK Corp. http://www.peak.ne.jp/)
20
 */
21
22
require_once __DIR__ . '/../../mainfile.php';
23
require_once __DIR__ . '/header.php';
24
$original_level = error_reporting(E_ALL ^ E_NOTICE);
25
26
if ((!isset($_GET['action']) || $_GET['action'] === '') && isset($_GET['cid']) && !is_numeric($_GET['cid'])) {
27
    $cat_title = addslashes($_GET['cid']);
28
    $cat       = $GLOBALS['xoopsDB']->queryF("SELECT cid FROM {$GLOBALS['xoopsDB']->prefix('apcal_cat')} WHERE cat_shorttitle LIKE '$cat_title' LIMIT 0,1");
29
30 View Code Duplication
    if ($cat && $GLOBALS['xoopsDB']->getRowsNum($cat)) {
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...
31
        $cat         = $GLOBALS['xoopsDB']->fetchObject($cat);
32
        $_GET['cid'] = $cat->cid;
33
    }
34
} elseif (isset($_GET['action']) && $_GET['action'] === 'View' && !is_numeric($_GET['event_id'])
35
          && isset($_GET['date'])
36
) {
37
    $summary = addslashes($_GET['event_id']);
38
    $date    = isset($_GET['date']) ? strtotime($_GET['date']) : time();
39
    $event   = $GLOBALS['xoopsDB']->queryF("SELECT id FROM {$GLOBALS['xoopsDB']->prefix('apcal_event')} WHERE shortsummary='$summary' AND UNIX_TIMESTAMP(DATE(FROM_UNIXTIME(start)))=$date LIMIT 0,1");
40
41 View Code Duplication
    if ($event && $GLOBALS['xoopsDB']->getRowsNum($event)) {
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...
42
        $event            = $GLOBALS['xoopsDB']->fetchObject($event);
43
        $_GET['event_id'] = $event->id;
44
    }
45
}
46
47
// for "Duplicatable"
48
$moduleDirName = basename(__DIR__);
49
if (!preg_match('/^(\D+)(\d*)$/', $moduleDirName, $regs)) {
50
    echo('invalid dirname: ' . htmlspecialchars($moduleDirName));
51
}
52
$mydirnumber = $regs[2] === '' ? '' : (int)$regs[2];
53
54
require_once XOOPS_ROOT_PATH . "/modules/$moduleDirName/include/gtickets.php";
55
56
// ����ƥ�����
57
// $xoopsConfig[ 'language' ] = 'french' ;
58
59
// MySQL�ؤ���³
60
// $conn = mysqli_connect( XOOPS_DB_HOST , XOOPS_DB_USER , XOOPS_DB_PASS ) || die( "Could not connect." ) ;
61
// mysqli_select_db( XOOPS_DB_NAME , $conn ) ;
62
$conn = $GLOBALS['xoopsDB']->conn;
63
64
// setting physical & virtual paths
65
$mod_path = XOOPS_ROOT_PATH . "/modules/$moduleDirName";
66
$mod_url  = XOOPS_URL . "/modules/$moduleDirName";
67
68
// ���饹������ɤ߹���
69
if (!class_exists('APCal_xoops')) {
70
    require_once "$mod_path/class/APCal.php";
71
    require_once "$mod_path/class/APCal_xoops.php";
72
}
73
74
// GET,POST�ѿ��μ�����������
75
if (empty($_GET['action']) && !empty($_GET['event_id'])) {
76
    $_GET['action'] = 'View';
77
}
78
79
if (isset($_GET['action'])) {
80
    $action = $_GET['action'];
81
} else {
82
    $action = '';
83
}
84
85
// creating an instance of APCal
86
$cal = new APCal_xoops('', $xoopsConfig['language'], true);
87
88
// setting properties of APCal
89
$cal->conn = $conn;
90
include "$mod_path/include/read_configs.php";
91
$cal->base_url    = $mod_url;
92
$cal->base_path   = $mod_path;
93
$cal->images_url  = "$mod_url/assets/images/$skin_folder";
94
$cal->images_path = "$mod_path/assets/images/$skin_folder";
95
$cal->frame_css   = 'border-color: ' . $cal->frame_css . ';';
96
97
// �ǡ����١��������ط��ν���ʤ�����⡢Location�����Ф���
98
if (isset($_POST['update'])) {
99
    // ����
100
    if (!$editable) {
101
        die(_MB_APCAL_ERR_NOPERMTOUPDATE);
102
    }
103
    // Ticket Check
104
    if (!$xoopsGTicket->check()) {
105
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
106
    }
107
    $cal->update_schedule("$admission_update_sql", $whr_sql_append);
108
} elseif (isset($_POST['insert']) || isset($_POST['saveas'])) {
109
    // saveas �ޤ��� ������Ͽ
110
    if (!$insertable) {
111
        die(_MD_APCAL_ERR_NOPERMTOINSERT);
112
    }
113
    $_POST['event_oldid'] = $_POST['event_id'];
114
    $_POST['event_id']    = '';
115
    // Ticket Check
116
    if (!$xoopsGTicket->check()) {
117
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
118
    }
119
    $cal->update_schedule(",uid='$user_id' $admission_insert_sql", '', 'notify_new_event');
120
} elseif (!empty($_POST['delete'])) {
121
    // ���
122
    if (!$deletable) {
123
        die(_MD_APCAL_ERR_NOPERMTODELETE);
124
    }
125
    // Ticket Check
126
    if (!$xoopsGTicket->check()) {
127
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
128
    }
129
    $cal->delete_schedule($whr_sql_append, 'global $xoopsModule; xoops_comment_delete($xoopsModule->mid(),$id);');
130
} elseif (!empty($_POST['delete_one'])) {
131
    // �����
132
    if (!$deletable) {
133
        die(_MD_APCAL_ERR_NOPERMTODELETE);
134
    }
135
    // Ticket Check
136
    if (!$xoopsGTicket->check()) {
137
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
138
    }
139
    $cal->delete_schedule_one($whr_sql_append);
140
} elseif (!empty($_GET['output_ics']) /* || ! empty( $_POST[ 'output_ics' ] ) */) {
141
    // output ics
142
    $cal->output_ics();
143
}
144
145
// smode���
146
if (!empty($_GET['smode'])) {
147
    $smode = $_GET['smode'];
148
} else {
149
    $smode = $default_view;
150
}
151
152
// XOOP�إå��������ν���
153
if ($action === 'View') {
154
    $GLOBALS['xoopsOption']['template_main'] = "apcal{$mydirnumber}_event_detail.tpl";
155
} else {
156
    // View�ʳ��Ǥϥ����ȶػ�
157
    $xoopsModuleConfig['com_rule'] = 0;
158
    if ($smode === 'List' && $action !== 'Edit') {
159
        $GLOBALS['xoopsOption']['template_main'] = "apcal{$mydirnumber}_event_list.tpl";
160
    }
161
}
162
163
// XOOPS�إå�����
164
include XOOPS_ROOT_PATH . '/header.php';
165
$xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/modules/apcal/assets/css/apcal.css" />' . $xoopsTpl->get_template_vars('xoops_module_header'));
166
167
// embed style sheet ��� (thx Ryuji)
168
$xoopsTpl->assign('xoops_module_header', "<style><!-- \n" . $cal->get_embed_css() . "\n--></style>\n" . $xoopsTpl->get_template_vars('xoops_module_header'));
169
170
// ���?�顼�˥�󥯤�ؤĤ餻�ʤ� follow -> nofollow
171
$meta_robots = str_replace(',follow', ',nofollow', $xoopsTpl->get_template_vars('xoops_meta_robots'));
172
$xoopsTpl->assign('xoops_meta_robots', $meta_robots);
173
174
// �¹Ի��ַ�¬��������
175
// list( $usec , $sec ) = explode( " " , microtime() ) ;
176
// $apcalstarttime = $sec + $usec ;
177
178
// �ڡ���ɽ����Ϣ�ν���ʬ��
179
if ($action === 'Edit') {
180
    if (is_dir(XOOPS_ROOT_PATH . '/modules/apcal/assets/js/jscalendar')) {
181
        // jscalendar in module dir (recommended)
182
        $jscalurl = XOOPS_URL . '/modules/apcal/assets/js/jscalendar';
183
        $xoopsTpl->assign('xoops_module_header', '
184
                <link rel="stylesheet" type="text/css" media="all" href="' . $jscalurl . '/calendar-system.css" />
185
                <script type="text/javascript" src="' . $jscalurl . '/calendar.js"></script>
186
                <script type="text/javascript" src="' . $jscalurl . '/lang/' . $cal->jscalendar_lang_file . '"></script>
187
                <script type="text/javascript" src="' . $jscalurl . '/calendar-setup.js"></script>
188
            ' . $xoopsTpl->get_template_vars('xoops_module_header'));
189
        $cal->jscalendar = 'jscalendar';
190
    } elseif (is_file(XOOPS_ROOT_PATH . '/include/calendarjs.php')) {
191
        // older jscalendar in XOOPS 2.0.x core
192
        include XOOPS_ROOT_PATH . '/include/calendarjs.php';
193
        $cal->jscalendar = 'xoops';
194
    } elseif (is_dir(XOOPS_ROOT_PATH . '/class/calendar')) {
195
        // jscalendar in XOOPS 2.2 core
196
        $jscalurl = XOOPS_URL . '/class/calendar';
197
        $xoopsTpl->assign('xoops_module_header', '
198
                <link rel="stylesheet" type="text/css" media="all" href="' . $jscalurl . '/CSS/calendar-blue.css" title="system" />
199
                <script type="text/javascript" src="' . $jscalurl . '/calendar.js"></script>
200
                <script type="text/javascript" src="' . $jscalurl . '/lang/' . $cal->jscalendar_lang_file . '"></script>
201
                <script type="text/javascript" src="' . $jscalurl . '/calendar-setup.js"></script>
202
            ' . $xoopsTpl->get_template_vars('xoops_module_header'));
203
        $cal->jscalendar = 'jscalendar';
204
    } else {
205
        // older jscalendar in XOOPS 2.0.x core
206
        include XOOPS_ROOT_PATH . '/include/calendarjs.php';
207
        $cal->jscalendar = 'xoops';
208
    }
209
    $xoopsTpl->assign('xoops_module_header', '<script type="text/javascript" src="' . XOOPS_URL . '/modules/apcal/ajax/pictures.js"></script>' . $xoopsTpl->get_template_vars('xoops_module_header'));
210
    echo $cal->get_schedule_edit_html();
211
} elseif ($action === 'View') {
212
    // echo $cal->get_schedule_view_html( ) ;
213
    $xoopsTpl->assign('detail_body', $cal->get_schedule_view_html());
214
    $xoopsTpl->assign('xoops_pagetitle', $cal->last_summary);
215
    $xoopsTpl->assign('xoops_default_comment_title', 'Re: ' . $cal->last_summary);
216
    $xoopsTpl->assign('print_link', "$mod_url/print.php?event_id={$_GET['event_id']}&amp;action=View");
217
    $xoopsTpl->assign('skinpath', "$cal->images_url");
218
    $xoopsTpl->assign('lang_print', _MD_APCAL_ALT_PRINTTHISEVENT);
219
    $xoopsTpl->assign('showPrint', $cal->enableprint);
220
    $HTTP_GET_VARS['event_id'] = $_GET['event_id'] = $cal->original_id;
221
    include XOOPS_ROOT_PATH . '/include/comment_view.php';
222
    // patch for commentAny
223
    $commentany = $xoopsTpl->get_template_vars('commentany');
224
    if (!empty($commentany['com_itemid'])) {
225
        $commentany['com_itemid'] = $cal->original_id;
226
        $xoopsTpl->assign('commentany', $commentany);
227
    }
228
} elseif (isset($_POST['output_ics_confirm']) && !empty($_POST['ids']) && is_array($_POST['ids'])) {
229
    echo $cal->output_ics_confirm("$mod_url/");
230
} else {
231
    switch ($smode) {
232
        case 'Yearly':
233
            $calDisplay = $cal->get_yearly(XOOPS_URL . '/modules/apcal/');
234
            break;
235
        case 'Weekly':
236
            $calDisplay = $cal->get_weekly(XOOPS_URL . '/modules/apcal/');
237
            break;
238
        case 'Daily':
239
            $calDisplay = $cal->get_daily(XOOPS_URL . '/modules/apcal/');
240
            break;
241
        case 'List':
242
            $cal->assign_event_list($xoopsTpl, XOOPS_URL . '/modules/apcal/');
243
            break;
244
        case 'Monthly':
245
        default:
246
            $calDisplay = $cal->get_monthly(XOOPS_URL . '/modules/apcal/');
247
            break;
248
    }
249
}
250
251
$xoopsTpl->assign('showSocial', $cal->enablesocial);
252
$xoopsTpl->assign('showPrint', $cal->enableprint);
253
$xoopsTpl->assign('showTellaFriend', $cal->enabletellafriend);
254
255
if ($action === 'View') {
256
    $event_id   = isset($_GET['event_id']) && $_GET['event_id'] > 0 ? $_GET['event_id'] : 0;
257
    $event      = $GLOBALS['xoopsDB']->fetchArray($GLOBALS['xoopsDB']->queryF("SELECT summary, description, location, categories, contact, start FROM {$GLOBALS['xoopsDB']->prefix('apcal_event')} WHERE id={$event_id} LIMIT 0,1"));
258
    $cats       = explode(',', $event['categories']);
259
    $categories = array();
260
    foreach ($cats as $cat) {
261
        if ('' !== $cat) {
262
            $title = $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->queryF("SELECT cat_title FROM {$GLOBALS['xoopsDB']->prefix('apcal_cat')} WHERE cid={$cat} LIMIT 0,1"));
263
            if ($title) {
264
                $categories[] = $title->cat_title;
265
            }
266
        }
267
    }
268
269
    if (!empty($event['description'])) {
270
        $metaDesc = explode(' ', $event['description']);
271
        $metaDesc = array_slice($metaDesc, 0, 20);
272
        $xoTheme->addMeta('meta', 'description', implode(' ', $metaDesc));
273
    } else {
274
        $desc     = $event['summary'];
275
        $desc     .= !empty($categories) ? ' - ' . implode(' ', $categories) : '';
276
        $desc     .= !empty($event['location']) ? ' - ' . $event['location'] : '';
277
        $desc     .= !empty($event['start']) ? ' - ' . $cal->get_long_ymdn($event['start']) : '';
278
        $desc     .= !empty($event['contact']) ? ' - ' . $event['contact'] : '';
279
        $metaDesc = explode(' ', $desc);
280
        $metaDesc = array_slice($metaDesc, 0, 20);
281
        $xoTheme->addMeta('meta', 'description', implode(' ', $metaDesc));
282
    }
283
284
    $title = $event['summary'];
285
    $title .= !empty($categories) ? ' - ' . implode(' ', $categories) : '';
286
    $title .= !empty($event['location']) ? ' - ' . $event['location'] : '';
287
    $title = strlen($title) > 60 ? substr($title, 0, 59) : $title;
288
    $xoopsTpl->assign('xoops_pagetitle', $title);
289
290
    $xoopsTpl->assign('showMap', $cal->enableeventmap);
291
    $xoopsTpl->assign('api_key', $moduleHelper->getConfig('apcal_mapsapi'));
292
} elseif ($action === '') {
293
    $cid          = isset($_GET['cid']) && $_GET['cid'] > 0 ? $_GET['cid'] : 0;
294
    $cat          = $GLOBALS['xoopsDB']->fetchArray($GLOBALS['xoopsDB']->queryF("SELECT cat_title, cat_desc FROM {$GLOBALS['xoopsDB']->prefix('apcal_cat')} WHERE cid={$cid} LIMIT 0,1"));
295
    $date         = isset($_GET['caldate']) ? $_GET['caldate'] : date('Y-n-j');
296
    $date         = explode('-', $date);
297
    $dateTitle    = (isset($_GET['smode']) && $_GET['smode'] === 'Yearly' ? '' : $cal->month_long_names[$date[1]] . ' ') . $date[0];
298
    $catNameTitle = isset($_GET['cid']) && $_GET['cid'] > 0 ? $cat['cat_title'] : $xoopsModule->getVar('name');
299
300
    $pageTitle = $catNameTitle . ' ' . $dateTitle;
301
    $pageTitle = strlen($pageTitle) > 60 ? substr($pageTitle, 0, 59) : $pageTitle;
302
303
    $metaDesc = explode(' ', $catNameTitle . ' ' . $dateTitle . ' - ' . strip_tags($cat['cat_desc']));
304
    $metaDesc = array_slice($metaDesc, 0, 20);
305
306
    $xoopsTpl->assign('xoops_pagetitle', $pageTitle);
307
    $xoTheme->addMeta('meta', 'description', implode(' ', $metaDesc));
308
309
    if (isset($cat) && $smode !== 'List' && !empty($catNameTitle) && $cal->displayCatTitle) {
310
        echo '<h1>' . $catNameTitle . '</h1>';
311
    }
312
    if (isset($cat) && $smode !== 'List' && !empty($cat['cat_desc'])) {
313
        echo $cat['cat_desc'] . '<br><br>';
314
    }
315
316
    if ($cal->enablecalmap == 1 && is_array($cal->gmPoints) && !empty($cal->gmPoints)) {
317
        $tpl = new XoopsTpl();
318
        $tpl->assign('GMlatitude', $cal->gmlat);
319
        $tpl->assign('GMlongitude', $cal->gmlng);
320
        $tpl->assign('GMzoom', $cal->gmzoom);
321
        $tpl->assign('GMheight', $cal->gmheight . 'px');
322
        $tpl->assign('GMPoints', $cal->gmPoints);
323
        $moduleHelper = Xmf\Module\Helper::getHelper($moduleDirName);
324
        $tpl->assign('api_key', $moduleHelper->getConfig('apcal_mapsapi'));
325
        if ($smode === 'List') {
326
            $xoopsTpl->assign('map', $tpl->fetch(XOOPS_ROOT_PATH . '/modules/apcal/templates/apcal_googlemap.tpl'));
327
        } else {
328
            $tpl->display(XOOPS_ROOT_PATH . '/modules/apcal/templates/apcal_googlemap.tpl');
329
        }
330
    }
331
    if ($cal->enablesocial && $smode !== 'List') {
332
        $smode = empty($_GET['smode']) ? $cal->defaultView : preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['smode']);
0 ignored issues
show
The property defaultView does not seem to exist in APCal_xoops.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
333
        echo '<div class="socialNetworks">
334
                <span class="print">
335
                    <a href="' . $cal->base_url . '/print.php?cid=' . $cal->now_cid . '&smode=' . $smode . '&caldate=' . $cal->caldate . '" target="_blank">
336
                        <img src="' . $cal->images_url . '/print.gif" alt="' . _APCAL_BTN_PRINT . '" border="0" ' . PRINT_ATTRIB . ' />
337
                    </a>
338
                </span>';
339
        if ($cal->enabletellafriend) {
340
            echo '<span class="tellafriend">
341
                        <a href="" title="' . _APCAL_TELLAFRIEND . '" onclick="window.open(\'' . XOOPS_URL . '/modules/apcal/tellafriend.php?url=\'+encodeURIComponent(location.href)+\'&title=\'+encodeURIComponent(document.title), \'_blank\',\'toolbar=no,width=800,height=450\'); return false;">
342
                            <img src="' . XOOPS_URL . '/modules/apcal/assets/images/tellafriend.png" height="20" width="20" alt="' . _APCAL_TELLAFRIEND . '" title="' . _APCAL_TELLAFRIEND . '" />
343
                        </a>
344
                    </span>';
345
        }
346
        echo '<span class="delicious">
347
                    <a href="http://www.delicious.com/save" title="Delicious" onclick="window.open(\'http://www.delicious.com/save?v=5&noui&jump=close&url=\'+encodeURIComponent(location.href)+\'&title=\'+encodeURIComponent(document.title), \'delicious\',\'toolbar=no,width=550,height=550\'); return false;">
348
                        <img src="' . XOOPS_URL . '/modules/apcal/assets/images/delicious.png" height="20" width="20" alt="Delicious" title="Delicious" />
349
                    </a>
350
                </span>
351
                <span class="googleplus">
352
                    <script type="text/javascript" src="https://apis.google.com/js/plusone.js">{lang: \'' . _APCAL_GPLUS_LNG . '\'}</script>
353
                    <g:plusone size="medium" count="false" href="' . XOOPS_URL . '/modules/apcal"></g:plusone>
354
                </span>
355
                <span class="linkedIn">
356
                    <script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
357
                    <script type="IN/Share" data-url="' . XOOPS_URL . '/modules/apcal"></script>
358
                </span>
359
                <span class="twitter">
360
                    <a href="https://twitter.com/share" class="twitter-share-button" data-url="' . XOOPS_URL . '/modules/apcal" data-count="none">Tweet</a>
361
                    <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
362
                </span>
363
                <span class="facebook">
364
                    <script type="text/javascript" src="http://connect.facebook.net/' . _APCAL_FB_LNG . '/all.js#xfbml=1"></script>
365
                    <div class="fb-like" data-href="' . XOOPS_URL . '/modules/apcal" data-send="false" data-layout="button_count" data-action="recommend" data-show-faces="false"></div>
366
                </span>
367
            </div>';
368
        //<a name="fb_share" type="button" share_url="http://www.example.com/page.html"></a>
369
        //<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
370
    }
371
    if ($cal->enablesharing && $smode !== 'List') {
372
        echo '<div class="share"><a href="' . XOOPS_URL . '/modules/apcal/shareCalendar.php" title="' . _APCAL_SHARECALENDAR . '"><img src="' . XOOPS_URL . '/modules/apcal/assets/images/share.png" /><span style="line-height: 32px; margin-bottom: 15px;">' . _APCAL_SHARECALENDAR . '</span></a></div>';
373
    }
374
}
375
376
if (isset($calDisplay)) {
377
    echo $calDisplay;
378
}
379
380
error_reporting($original_level);
381
382
// XOOPS footer
383
include XOOPS_ROOT_PATH . '/footer.php';
384