Completed
Pull Request — master (#24)
by Michael
04:00
created

shareCalendar.php (4 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 81 and the first side effect is on line 22.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
24
include XOOPS_ROOT_PATH . '/header.php';
25
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
26
27
$tpl        = new XoopsTpl();
28
$form       = new XoopsThemeForm(_APCAL_SHARECALENDARFORM, 'calendar', '', 'post');
29
$formCustom = new XoopsThemeForm(_APCAL_IFCUSTOM, 'custom', '', 'post');
30
31
$catSelect = new XoopsFormSelect(_APCAL_CATEGORIES, 'c', 0);
32
$catSelect->addOptionArray(getCategories());
33
34
$styleSelect = new XoopsFormRadio(_APCAL_STYLE, 't', 'default');
35
$styleSelect->addOption('default', _APCAL_DEFAULT);
36
$styleSelect->addOption('theme', _APCAL_THEME);
37
$styleSelect->addOption('custom', _APCAL_CUSTOM);
38
$styleSelect->setExtra('onclick="showCustomSettings();"');
39
40
$unitSelect = new XoopsFormSelect('', 'u', '%');
41
$unitSelect->addOption('%', '%');
42
$unitSelect->addOption('px', 'px');
43
$unitSelect->addOption('em', 'em');
44
45
$wTray = new XoopsFormElementTray(_APCAL_WIDTH);
46
$wTray->addElement(new XoopsFormText('', 'w', 10, 7, '100'), true);
47
$wTray->addElement($unitSelect);
48
49
$generateButton = new XoopsFormButton(_APCAL_GENERATEHINT, 'generate', _APCAL_GENERATE, 'submit');
50
$generateButton->setExtra('onclick="showHTMLCode();return false;"');
51
52
$form->addElement(new XoopsFormText(_APCAL_TITLE, 'h', 30, 60, $xoopsModule->getVar('name')), true);
53
$form->addElement($catSelect, true);
54
$form->addElement(new XoopsFormText(_APCAL_NBEVENTS, 'n', 5, 3, '10'), true);
55
$form->addElement($wTray, true);
56
$form->addElement($styleSelect, true);
57
//$form->insertBreak('');
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
//$form->insertBreak(_APCAL_IFCUSTOM);
59
//$form->insertBreak('');
60
$formCustom->addElement(new XoopsFormText(_APCAL_BORDER, 'APborder', 60, 255, 'border: 3px double #000000;'), false);
61
$formCustom->addElement(new XoopsFormText(_APCAL_TITLE, 'APtitle', 60, 255, 'color: #000000; font-size: 1.3em;'), false);
62
$formCustom->addElement(new XoopsFormText(_APCAL_TEXT, 'APtext', 60, 255, 'color: #000000; font-size: 1.0em;'), false);
63
$formCustom->addElement(new XoopsFormText(_APCAL_LINK, 'APlink', 60, 255, 'color: #0000FF; text-decoration: none;'), false);
64
$formCustom->addElement(new XoopsFormText(_APCAL_EVEN, 'APeven', 60, 255, 'background-color: #F2F2F2;'), false);
65
$formCustom->addElement(new XoopsFormText(_APCAL_ODD, 'APodd', 60, 255, 'background-color: #EBEBEB;'), false);
66
$form->addElement($generateButton, false);
67
68
$form->display();
69
echo '<div id="customSettings" style="display: none;">';
70
$formCustom->display();
71
echo '</div>';
72
echo '<br>' . _APCAL_SHAREINFO . '<br>';
73
echo '<div id="htmlCode"></div>';
74
echo $tpl->fetch(XOOPS_ROOT_PATH . '/modules/apcal/templates/shareCalendar.tpl');
75
76
include XOOPS_ROOT_PATH . '/footer.php';
77
78
/**
79
 * @return array
80
 */
81
function getCategories()
0 ignored issues
show
getCategories uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
82
{
83
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
84
85
    $cats   = array(0 => _APCAL_SHOWALLCAT);
86
    $result = $GLOBALS['xoopsDB']->queryF("SELECT cid, cat_title, cat_depth FROM {$GLOBALS['xoopsDB']->prefix('apcal_cat')} ORDER BY weight");
87
88
    while ($cat = $GLOBALS['xoopsDB']->fetchObject($result)) {
89
        $depth_desc      = str_repeat('-', (int)$cat->cat_depth);
90
        $title           = htmlspecialchars($cat->cat_title, ENT_QUOTES);
91
        $cats[$cat->cid] = "$depth_desc $title";
92
    }
93
94
    return $cats;
95
}
96