Пример #1
0
function displayCalendar($paramstring, $params = array())
{
    global $wgParser;
    global $wgScript, $wgScriptPath;
    global $wgTitle, $wgUser;
    global $wgRestrictCalendarTo, $wgCalendarDisableRedirects;
    global $wgCalendarForceNamespace, $wgCalendarDateFormat;
    $wgParser->disableCache();
    $wikiRoot = $wgScript . "?title=";
    $userMode = 'month';
    // grab the page title
    $title = $wgTitle->getPrefixedText();
    $config_page = " ";
    $calendar = null;
    $calendar = new Calendar($wikiRoot, isset($params["debug"]));
    //return $calendar->getURLRelativePath();
    $calendar->namespace = $wgTitle->getNsText();
    if (!isset($params["name"])) {
        $params["name"] = "Public";
    }
    // append simplemonth to name to seperate from normal calendar names
    //if(isset($params["simplemonth"])) $params["name"] .= "_simplemonth";
    $calendar->paramstring = $paramstring;
    // set path
    $params['path'] = str_replace("\\", "/", dirname(__FILE__));
    $name = Common::checkForMagicWord($params["name"]);
    // normal calendar...
    $calendar->calendarPageName = "{$title}/{$name}";
    // if the calendar isn't in a namespace(s) specificed in $wgCalendarForceNamespace, return a warning
    // this can be a string or an array
    if (isset($wgCalendarForceNamespace)) {
        if (is_array($wgCalendarForceNamespace)) {
            if (!in_array($calendar->namespace, $wgCalendarForceNamespace)) {
                $namespaces = "";
                foreach ($wgCalendarForceNamespace as $namespace) {
                    $namespaces .= $namespace . ", ";
                }
                return Common::translate('invalid_namespace') . '<b>' . $namespaces . '</b>';
            }
        } else {
            if ($wgCalendarForceNamespace != $calendar->namespace) {
                return Common::translate('invalid_namespace') . '<b>' . $wgCalendarForceNamespace . '</b>';
            }
        }
    }
    //set defaults that are required later in the code...
    if (!isset($params["timetrackhead"])) {
        $params["timetrackhead"] = "Event, Value";
    }
    if (!isset($params["maxdailyevents"])) {
        $params["maxdailyevents"] = 5;
    }
    if (!isset($params["yearoffset"])) {
        $params["yearoffset"] = 2;
    }
    if (!isset($params["charlimit"])) {
        $params["charlimit"] = 25;
    }
    if (!isset($params["css"])) {
        $params["css"] = "default.css";
    }
    //if(!isset($params["formatdate"])) $params["formatdate"] = 'M-D-YYYY';
    //if($params["formatdate"] == 'formatdate'){
    //	return 'Invalid date format';
    //}
    //set secure mode via $wgRestrictCalendarTo global
    // this global is set via LocalSetting.php (ex: $wgRestrictCalendarTo = 'sysop';
    if (isset($wgRestrictCalendarTo)) {
        $arrGroups = $wgUser->getGroups();
        if (is_array($wgRestrictCalendarTo)) {
            if (count(array_intersect($wgRestrictCalendarTo, $arrGroups)) == 0) {
                $params["lockdown"] = true;
            }
        } else {
            if (!in_array($wgRestrictCalendarTo, $arrGroups)) {
                $params["lockdown"] = true;
            }
        }
    }
    if (isset($wgCalendarDisableRedirects)) {
        $params['disableredirects'] = true;
    }
    // no need to pass a parameter here... isset check for the params name, thats it
    if (isset($params["lockdown"])) {
        $params['disableaddevent'] = true;
        $params['disablelinks'] = true;
        $params['locktemplates'] = true;
    }
    // this needs to be last after all required $params are updated, changed, defaulted or whatever
    $calendar->arrSettings = $params;
    // finished special conditions; set the $title and $name in the class
    $calendar->setTitle($title);
    $calendar->setName($name);
    $cookie_name = preg_replace('/(\\.|\\s)/', '_', $title . " " . $name);
    //replace periods and spaces
    if (isset($_COOKIE[$cookie_name])) {
        $calendar->debug->set('cookie loaded');
        $arrSession = split("`", $_COOKIE[$cookie_name]);
        $calendar->setMonth($arrSession[0]);
        $calendar->setDay($arrSession[1]);
        $calendar->setYear($arrSession[2]);
        $calendar->setTitle($arrSession[3]);
        $calendar->setName($arrSession[4]);
        if (strlen($arrSession[5]) > 0) {
            $userMode = $arrSession[5];
        }
    } else {
        // defaults from the <calendar /> parameters; must restart browser to enable
        if (isset($params['week'])) {
            $userMode = 'week';
        }
        if (isset($params['year'])) {
            $userMode = 'year';
        }
    }
    if (isset($params['useeventlist'])) {
        $userMode = 'events';
    }
    if (isset($params['date'])) {
        $userMode = 'day';
    }
    if (isset($params['simplemonth'])) {
        $userMode = 'simplemonth';
    }
    $render = $calendar->renderCalendar($userMode);
    // purge main calendar before displaying the calendar
    if ($calendar->invalidateCache) {
        $article = new Article(Title::newFromText($title));
        $article->purge();
        header("Location: " . $wikiRoot . $title);
    }
    return $render;
}
Пример #2
0
function displayCalendar($paramstring, $params = array())
{
    global $wgParser;
    global $wgScript, $wgScriptPath;
    global $wgTitle, $wgUser;
    global $wgRestrictCalendarTo, $wgCalendarDisableRedirects;
    global $wgCalendarForceNamespace, $wgCalendarDateFormat;
    $wgParser->disableCache();
    $wikiRoot = $wgScript . "?title=";
    $userMode = 'month';
    // grab the page title
    $title = $wgTitle->getPrefixedText();
    $config_page = " ";
    $calendar = null;
    $calendar = new Calendar($wikiRoot, isset($params["debug"]));
    //return $calendar->getURLRelativePath();
    $calendar->namespace = $wgTitle->getNsText();
    if (!isset($params["name"])) {
        $params["name"] = "Public";
    }
    // append simplemonth to name to seperate from normal calendar names
    //if(isset($params["simplemonth"])) $params["name"] .= "_simplemonth";
    $calendar->paramstring = $paramstring;
    // set path
    $params['path'] = str_replace("\\", "/", dirname(__FILE__));
    $name = Common::checkForMagicWord($params["name"]);
    // normal calendar...
    $calendar->calendarPageName = "{$title}/{$name}";
    $calendar->configPageName = "{$title}/{$name}/config";
    if (isset($params["useconfigpage"])) {
        $configs = $calendar->getConfig("{$title}/{$name}");
        //merge the config page and the calendar tag params; tag params overwrite config file
        $params = array_merge($configs, $params);
    }
    // just in case i rename some preferences... we can make them backwards compatible here...
    legacyAliasChecks($params);
    // if the calendar isn't in a namespace(s) specificed in $wgCalendarForceNamespace, return a warning
    // this can be a string or an array
    if (isset($wgCalendarForceNamespace)) {
        if (is_array($wgCalendarForceNamespace)) {
            if (!in_array($calendar->namespace, $wgCalendarForceNamespace) && !isset($params["fullsubscribe"])) {
                $namespaces = "";
                foreach ($wgCalendarForceNamespace as $namespace) {
                    $namespaces .= $namespace . ", ";
                }
                return Common::translate('invalid_namespace') . '<b>' . $namespaces . '</b>';
            }
        } else {
            if ($wgCalendarForceNamespace != $calendar->namespace && !isset($params["fullsubscribe"])) {
                return Common::translate('invalid_namespace') . '<b>' . $wgCalendarForceNamespace . '</b>';
            }
        }
    }
    //set defaults that are required later in the code...
    if (!isset($params["timetrackhead"])) {
        $params["timetrackhead"] = "Event, Value";
    }
    if (!isset($params["maxdailyevents"])) {
        $params["maxdailyevents"] = 5;
    }
    if (!isset($params["yearoffset"])) {
        $params["yearoffset"] = 2;
    }
    if (!isset($params["charlimit"])) {
        $params["charlimit"] = 25;
    }
    if (!isset($params["css"])) {
        $params["css"] = "default.css";
    }
    //if(!isset($params["formatdate"])) $params["formatdate"] = 'M-D-YYYY';
    //if($params["formatdate"] == 'formatdate'){
    //	return 'Invalid date format';
    //}
    //set secure mode via $wgRestrictCalendarTo global
    // this global is set via LocalSetting.php (ex: $wgRestrictCalendarTo = 'sysop';
    if (isset($wgRestrictCalendarTo)) {
        $arrGroups = $wgUser->getGroups();
        if (is_array($wgRestrictCalendarTo)) {
            if (count(array_intersect($wgRestrictCalendarTo, $arrGroups)) == 0) {
                $params["lockdown"] = true;
            }
        } else {
            if (!in_array($wgRestrictCalendarTo, $arrGroups)) {
                $params["lockdown"] = true;
            }
        }
    }
    if (isset($wgCalendarDisableRedirects)) {
        $params['disableredirects'] = true;
    }
    // no need to pass a parameter here... isset check for the params name, thats it
    if (isset($params["lockdown"])) {
        $params['disableaddevent'] = true;
        $params['disablelinks'] = true;
        $params['locktemplates'] = true;
    }
    if (isset($params["5dayweek"])) {
        $params['monday'] = true;
    }
    // this needs to be last after all required $params are updated, changed, defaulted or whatever
    $calendar->arrSettings = $params;
    // joint calendar...pulling data from our calendar and the subscribers...ie: "title/name" format
    if (isset($params["subscribe"])) {
        if ($params["subscribe"] != "subscribe") {
            $calendar->subscribedPages = split(",", $params["subscribe"]);
        }
    }
    // subscriber only calendar...basically, taking the subscribers identity fully...ie: "title/name" format
    if (isset($params["fullsubscribe"])) {
        if ($params["fullsubscribe"] != "fullsubscribe") {
            $arrString = explode('/', $params["fullsubscribe"]);
            array_pop($arrString);
            $string = implode('/', $arrString);
            $article = new Article(Title::newFromText($string));
            // if the fullsubscribe calendar doesn't exisit, return a warning...
            if (!$article->exists()) {
                return "Invalid 'fullsubscribe' calendar page: <b><i>{$string}</i></b>";
            }
            $calendar->calendarPageName = htmlspecialchars($params["fullsubscribe"]);
            $calendar->isFullSubscribe = true;
        }
    }
    // finished special conditions; set the $title and $name in the class
    $calendar->setTitle($title);
    $calendar->setName($name);
    $cookie_name = preg_replace('/(\\.|\\s)/', '_', $title . " " . $name);
    //replace periods and spaces
    if (isset($_COOKIE[$cookie_name])) {
        $calendar->debug->set('cookie loaded');
        $arrSession = split("`", $_COOKIE[$cookie_name]);
        $calendar->setMonth($arrSession[0]);
        $calendar->setDay($arrSession[1]);
        $calendar->setYear($arrSession[2]);
        $calendar->setTitle($arrSession[3]);
        $calendar->setName($arrSession[4]);
        if (strlen($arrSession[5]) > 0) {
            $userMode = $arrSession[5];
        }
    } else {
        // defaults from the <calendar /> parameters; must restart browser to enable
        if (isset($params['week'])) {
            $userMode = 'week';
        }
        if (isset($params['year'])) {
            $userMode = 'year';
        }
    }
    if (isset($params['useeventlist'])) {
        $userMode = 'events';
    }
    if (isset($params['date'])) {
        $userMode = 'day';
    }
    if (isset($params['simplemonth'])) {
        $userMode = 'simplemonth';
    }
    if (isset($_COOKIE['calendar_ical'])) {
        $calendar->debug->set('ical cookie loaded');
        $calendar->load_iCal($_COOKIE['calendar_ical']);
        //delete ical file in "mediawiki/images" folder
        @unlink($_COOKIE['calendar_ical']);
        // delete the ical path cookie
        setcookie('calendar_ical', "", time() - 3600);
        // refresh the calendar's newly added events
        $calendar->invalidateCache = true;
    }
    $render = $calendar->renderCalendar($userMode);
    // purge main calendar before displaying the calendar
    if ($calendar->invalidateCache) {
        $article = new Article(Title::newFromText($title));
        $article->purge();
        header("Location: " . $wikiRoot . $title);
    }
    return $render;
}
Пример #3
0
<?php

include "calendar.php";
$calendar = new Calendar("Tomorrow");
echo "Tomorrow: " . $calendar->getDate() . "<br>";
$calendar->setDay("yesterday");
echo "Yesterday: " . $calendar->getDate() . "<br>";
$calendar->setDay("today");
echo "Today is : " . $calendar->getDate() . "<br>";