50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
|
<?php
|
||
|
# Tidspunkt for neste nerdepizza
|
||
|
|
||
|
define('PVV_NESTE_PIZZA_ID', 'pvv_neste_pizza');
|
||
|
|
||
|
$wgHooks['LanguageGetMagic'][] = 'pvvMagicWords';
|
||
|
function pvvMagicWords(&$magicWords, $lang) {
|
||
|
$magicWords[PVV_NESTE_PIZZA_ID] = array(0, 'NestePizza');
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
$wgHooks['ParserGetVariableValueSwitch'][] = 'pvvVariableValues';
|
||
|
function pvvVariableValues(&$parser, &$cache, &$magicWordId, &$ret) {
|
||
|
if ($magicWordId == PVV_NESTE_PIZZA_ID) {
|
||
|
$ret = pvvNestePizza();
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
function pvvNestePizza() {
|
||
|
$time = time();
|
||
|
$week = date('W');
|
||
|
$weekday = date('N');
|
||
|
if ($week % 2 == 0 && $weekday <= 5) {
|
||
|
$daysUntilPizza = 5 - $weekday;
|
||
|
} elseif ($week % 2 == 0 && $weekday > 5) {
|
||
|
$daysUntilPizza = 5 - $weekday + 14;
|
||
|
} else {
|
||
|
$daysUntilPizza = 5 - $weekday + 7;
|
||
|
}
|
||
|
$pizzaTime = $time + $daysUntilPizza*24*3600;
|
||
|
return 'Neste nerdepizza er fredag '
|
||
|
. date('d.m.Y', $pizzaTime)
|
||
|
. ' (' . $daysUntilPizza . ' dager igjen).';
|
||
|
}
|
||
|
|
||
|
$wgExtensionCredits['variable'][] = array(
|
||
|
'name' => 'NestePizza',
|
||
|
'author' => 'Øystein Skartsæterhagen',
|
||
|
'url' => 'http://wiki.pvv.ntnu.no/pvv/Nerdepizza',
|
||
|
'description' => 'Gir datoen for neste nerdepizza'
|
||
|
);
|
||
|
|
||
|
$wgHooks['MagicWordwgVariableIDs'][] = 'pvvDeclareVarIds';
|
||
|
function pvvDeclareVarIds(&$aCustomVariableIds) {
|
||
|
$aCustomVariableIds[] = PVV_NESTE_PIZZA_ID;
|
||
|
return true;
|
||
|
}
|
||
|
|