<?php
/**
* Mod Name: Ereignisse auf Startseite 1.1
* Copyright © 2006 frankrieger
*/
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook('index_end', 'eventsindex');
function eventsindex_info()
{
return array(
"name" => "Ereignisse auf Startseite",
"description" => "Ereignisse werden auf der Startseite angezeigt.",
"website" => "http://testforum.rotenhaene.de",
"author" => "frankrieger",
"authorsite" => "http://www.rotenhaene.de",
"version" => "1.1"
);
}
function eventsindex_activate()
{
global $db;
$eventsindex_group = array(
"name" => "events_on_indexpage",
"title" => "Ereignisse auf Startseite",
"description" => "Einstellungen für Plugin Ereignisse auf Startseite",
"disporder" => "5",
"isdefault" => "no"
);
$db->insert_query(TABLE_PREFIX."settinggroups", $eventsindex_group);
$gid = $db->insert_id();
$eventsindex_1 = array(
"sid" => "NULL",
"name" => "events_on_indexpage_futuredays",
"title" => "Anzahl der nächsten x Tage?",
"description" => "Wieviele Tage sollen angezeigt werden (0=alle anzeigen, -1=nur heutige Ereignisse anzeigen)?",
"optionscode" => "text",
"value" => "7",
"disporder" => "1",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $eventsindex_1);
$eventsindex_2 = array(
"sid" => "NULL",
"name" => "events_on_indexpage_maxevents",
"title" => "Zeige maximal x Ereignisse",
"description" => "Anzahl der Ereignisse die maximal gezeigt werden sollen (0=alle anzeigen).",
"optionscode" => "text",
"value" => "5",
"disporder" => "2",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $eventsindex_2);
$eventsindex_3 = array(
"sid" => "NULL",
"name" => "events_on_indexpage_top",
"title" => "Anzeige am Anfang der Startseite?",
"description" => "Wollen sie die Ereignisse am Anfang der Startseite anzeigen?",
"optionscode" => "yesno",
"value" => "no",
"disporder" => "3",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $eventsindex_3);
$eventsindex_4 = array(
"sid" => "NULL",
"name" => "events_on_indexpage_bottom",
"title" => "Anzeige bei der Statistik?",
"description" => "Wollen sie die Ereignisse bei Who\'s online und der Statistik anzeigen?",
"optionscode" => "yesno",
"value" => "yes",
"disporder" => "4",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $eventsindex_4);
$eventsindex_5 = array(
"sid" => "NULL",
"name" => "events_on_indexpage_private",
"title" => "Private Ereignisse anzeigen?",
"description" => "Wollen sie die eigenen privaten Ereignisse auch anzeigen?",
"optionscode" => "yesno",
"value" => "yes",
"disporder" => "5",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $eventsindex_5);
$eventsindex_6 = array(
"sid" => "NULL",
"name" => "events_on_indexpage_dateformat",
"title" => "Wochentag angezeigen?",
"description" => "Soll das Datum mit Wochentag angezeigt werden?",
"optionscode" => "yesno",
"value" => "yes",
"disporder" => "6",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $eventsindex_6);
$eventsindex_7 = array(
"sid" => "NULL",
"name" => "events_on_indexpage_dateformat2",
"title" => "Datumsformat",
"description" => "Wie soll das Datum angezeigt werden (Standard d.m.Y)?",
"optionscode" => "text",
"value" => "d.m.Y",
"disporder" => "7",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $eventsindex_7);
rebuild_settings();
$template = array(
"tid" => NULL,
"title" => "events_on_indexpage_stat",
"template" => "<tr>
<td class=\"tcat\"><strong>{\$lang->events_on_indexpage}</strong> [<a href=\"calendar.php\">{\$lang->toplinks_calendar}</a>]</td>
</tr>
<tr>
<td class=\"trow1\"><span class=\"smalltext\">{\$events}</span></td>
</tr>",
"sid" => "-1"
);
$db->insert_query(TABLE_PREFIX."templates", $template);
$template2 = array(
"title" => "events_on_indexpage_row_private",
"template" => "{\$comma}{\$eventdate}<a href=\"calendar.php?action=event&eid={\$event[\$x][\'eid\']}\" title=\"{\$event[\$x][\'subject\']}\"><span class=\"smalltext\"><font color=\"{\$mybb->settings[\'privateeventcolor\']}\">{\$event[\$x][\'subject\']}</font></span></a>",
"sid" => -1
);
$db->insert_query(TABLE_PREFIX."templates", $template2);
$template3 = array(
"title" => "events_on_indexpage_row_public",
"template" => "{\$comma}{\$eventdate}<a href=\"calendar.php?action=event&eid={\$event[\$x][\'eid\']}\" title=\"{\$event[\$x][\'subject\']}\"><span class=\"smalltext\"><font color=\"{\$mybb->settings[\'publiceventcolor\']}\">{\$event[\$x][\'subject\']}</font></span></a>",
"sid" => -1
);
$db->insert_query(TABLE_PREFIX."templates", $template3);
$template4 = array(
"tid" => "NULL",
"title" => "events_on_indexpage_top",
"template" => "<table border=\"0\" cellspacing=\"{\$theme[borderwidth]}\" cellpadding=\"{\$theme[tablespace]}\" class=\"tborder\">
<thead>
<tr>
<td class=\"thead\" colspan=\"2\">
<div class=\"expcolimage\"><img src=\"{\$theme[\'imgdir\']}/collapse{\$collapsedimg[\'events\']}.gif\" id=\"events_img\" class=\"expander\" alt=\"[-]\" /></div>
<div><strong>{\$lang->events_on_indexpage}</strong></div>
</td>
</tr>
</thead>
<tbody style=\"{\$collapsed[\'events\']}\" id=\"events_e\">
<tr>
<td class=\"trow1\" align=\"center\" valign=\"top\" width=\"35\"><img src=\"{\$theme[\'imgdir\']}/events.gif\" border=\"0\" alt=\"Ereignisse\" />
</td>
<td class=\"trow2\"><span class=\"smalltext\">{\$events}</span></td>
</tr>
</tbody>
</table>
<br />",
"sid" => "-1",
);
$db->insert_query(TABLE_PREFIX."templates", $template4);
require MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets('index', '#{\$header}#', "{\$header}\n{\$eventstop}");
find_replace_templatesets('index', '#{\$whosonline}#', "{\$whosonline}\n{\$eventsstat}");
}
function eventsindex_deactivate()
{
global $db;
//Einstellungsgruppe löschen
$query = $db->query("SELECT gid FROM ".TABLE_PREFIX."settinggroups WHERE name='events_on_indexpage'");
$g = $db->fetch_array($query);
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE gid='".$g['gid']."'");
//Einstellungen löschen
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE gid='".$g['gid']."'");
rebuild_settings();
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='events_on_indexpage_stat'");
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='events_on_indexpage_row_private'");
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='events_on_indexpage_row_public'");
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='events_on_indexpage_top'");
require MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets('index', '#(\r?)(\n?){\$eventstop}#', '', 0);
find_replace_templatesets('index', '#(\r?)(\n?){\$eventsstat}#', '', 0);
}
function eventsindex()
{
global $db, $mybb, $templates, $eventsstat, $eventstop, $lang, $theme;
$days = intval($mybb->settings['events_on_indexpage_futuredays']);
$maxdays = intval($mybb->settings['events_on_indexpage_maxevents']);
if ($maxdays == 1)
{
$lang->events_on_indexpage = $lang->events_on_indexpage_one_event;
}
elseif($days == -1 && $maxdays > 0)
{
$max = sprintf($lang->events_on_indexpage_max, $maxdays);
$lang->events_on_indexpage = sprintf($lang->events_on_indexpage_one, $max);
}
elseif($days == -1)
{
$lang->events_on_indexpage = sprintf($lang->events_on_indexpage_one, "");
}
elseif($days == 1 && $maxdays > 0)
{
$lang->events_on_indexpage = sprintf($lang->events_on_indexpage_tom, $maxdays." ");
}
elseif($days == 1)
{
$lang->events_on_indexpage = sprintf($lang->events_on_indexpage_tom, "");
}
elseif ($days > 0 && $maxdays > 0)
{
$max = sprintf($lang->events_on_indexpage_max, $maxdays);
$lang->events_on_indexpage = sprintf($lang->events_on_indexpage, $days, $max);
}
elseif ($days > 0)
{
$lang->events_on_indexpage = sprintf($lang->events_on_indexpage, $days, "");
}
elseif ($maxdays > 0)
{
$lang->events_on_indexpage = sprintf($lang->events_on_indexpage_no_days, $maxdays." ");
}
else
{
$lang->events_on_indexpage = sprintf($lang->events_on_indexpage_no_days, "");
}
if ($mybb->settings['events_on_indexpage_private'] != "no")
{
$private = "((author = '".$mybb->user['uid']."' AND private = 'yes') OR private != 'yes')";
}
else
{
$private = "private != 'yes'";
}
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."events WHERE ".$private);
$y = -1;
while($eventtemp = $db->fetch_array($query))
{
++$y;
$event[$y]['eid'] = $eventtemp['eid'];
$event[$y]['subject'] = $eventtemp['subject'];
$event[$y]['description'] = $eventtemp['description'];
$event[$y]['private'] = $eventtemp['private'];
$event[$y]['date'] = $eventtemp['date'];
$datum = explode("-", $eventtemp['date']);
$event[$y]['datetimestamp'] = mktime(0,0,0,$datum[1],$datum[0],$datum[2]);
}
for($x=0; $x <= $y; $x++)
{
for($z=$x; $z <= $y; $z++)
{
if($event[$x]['datetimestamp'] > $event[$z]['datetimestamp'])
{
$var = $event[$x];
$event[$x] = $event[$z];
$event[$z] = $var;
}
}
}
$comma = $events = '';
$anzahl = 0;
$today = mktime( 0, 0, 0, date("m"), date("d"), date("Y"));
if ($days > 0)
{
$lastday = mktime( 0, 0, 0, date("m"), date("d") + $days + 1, date("Y"));
}
elseif ($days == -1)
{
$lastday = mktime( 0, 0, 0, date("m"), date("d") + 1, date("Y"));
}
for($x=0; $x <= $y; $x++)
{
if ($event[$x]['datetimestamp'] >= $today && ($event[$x]['datetimestamp'] < $lastday || $days == 0) && ($anzahl < $maxdays || $maxdays == 0))
{
if ($days != -1)
{
$eventdate = date($mybb->settings['events_on_indexpage_dateformat2'], $event[$x]['datetimestamp']);
$eventdate .= " ";
if ($mybb->settings['events_on_indexpage_dateformat'] != "no" && $event[$x]['date'] == date("j-n-Y"))
{
$eventdate = $lang->today.": ".$wochentag." ";
}
elseif ($event[$x]['date'] == date("j-n-Y"))
{
$eventdate = $lang->today." ";
}
elseif ($mybb->settings['events_on_indexpage_dateformat'] != "no")
{
switch(date("w", $event[$x]['datetimestamp']))
{
case 0:
$wochentag = $lang->sunday;
break;
case 1:
$wochentag = $lang->monday;
break;
case 2:
$wochentag = $lang->tuesday;
break;
case 3:
$wochentag = $lang->wednesday;
break;
case 4:
$wochentag = $lang->thursday;
break;
case 5:
$wochentag = $lang->friday;
break;
case 6:
$wochentag = $lang->saturday;
break;
}
$eventdate = $wochentag.", ".$eventdate;
}
}
if ($event[$x]['private'] != "no")
{
eval("\$events .= \"".$templates->get("events_on_indexpage_row_private")."\";");
}
else
{
eval("\$events .= \"".$templates->get("events_on_indexpage_row_public")."\";");
}
$comma = "<br />";
++$anzahl;
}
}
if($events != "") {
if ($mybb->settings['events_on_indexpage_top'] != "no")
{
eval("\$eventstop = \"".$templates->get("events_on_indexpage_top")."\";");
}
if ($mybb->settings['events_on_indexpage_bottom'] != "no")
{
eval("\$eventsstat = \"".$templates->get("events_on_indexpage_stat")."\";");
}
}
}
if(!function_exists("rebuild_settings"))
{
function rebuild_settings()
{
global $db;
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."settings ORDER BY title ASC");
while($setting = $db->fetch_array($query)) {
$setting['value'] = addslashes($setting['value']);
$settings .= "\$settings['".$setting['name']."'] = \"".$setting['value']."\";\n";
}
$settings = "<"."?php\n/*********************************\ \n DO NOT EDIT THIS FILE, PLEASE USE\n THE SETTINGS EDITOR\n\*********************************/\n\n$settings\n?".">";
$file = fopen(MYBB_ROOT."/inc/settings.php", "w");
fwrite($file, $settings);
fclose($file);
}
}
?>