collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 372
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

If you're interested in helping other members with support requests, consider joining the Community Support Helpers group.

Author Topic: Need help with merged calender block  (Read 2520 times)

0 Members and 1 Guest are viewing this topic.

Offline Zirc

  • Jr. Member
  • **
  • Posts: 53
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Need help with merged calender block
« on: January 08, 2010, 12:38:39 AM »
Okay here's the thing, I'm trying to get my site cleaned up by removing redundant blocks or merging some blocks together into one.  My current task is merging the Calender block and the Calender information block into one.  Now I can get the calender information code to display events scheduled for today but it won't show me any future events like the actual calender information block does so I must be missing a little bit of code somewhere any help would be great.  I'm not great at php and have made some crude cosmetic adjustments to the code as well so don't laugh too hard at that stuff it works for me. :P

If you want to see what I got displayed you can go to www.tholeweb.com/forums i have created a couple events that guests can see and the calenderinformation block is still up until i find the solution.

From portalblocks.php
Code: [Select]
function sp_calendar($parameters, $id, $return_parameters = false)
{

global $context, $sourcedir, $modSettings, $options, $scripturl, $txt;

$block_parameters = array(
'events' => 'check',
'birthdays' => 'check',
'holidays' => 'check',
'future' => 'int',
);

if ($return_parameters)
return $block_parameters;

$show_event = !empty($parameters['events']);
$event_future = !empty($parameters['future']) ? (int) $parameters['future'] : 0;
$event_future = abs($event_future);
$show_birthday = !empty($parameters['birthdays']);
$show_holiday = !empty($parameters['holidays']);
$show_titles = false;

require_once($sourcedir . '/Calendar.php');
$today = array(
'day' => (int) strftime('%d', forum_time()),
'month' => (int) strftime('%m', forum_time()),
'year' => (int) strftime('%Y', forum_time()),
'date' => strftime('%Y-%m-%d', forum_time()),
);

$curPage = array(
'day' => $today['day'],
'month' => $today['month'],
'year' => $today['year']
);

$calendarOptions = array(
'start_day' => !empty($options['calendar_start_day']) ? $options['calendar_start_day'] : 0,
'show_events' => !empty($parameters['events']),
'show_birthdays' => !empty($parameters['birthdays']),
'show_holidays' => !empty($parameters['holidays']),
);

$calendar_data = array(
'week_days' => array(),
'weeks' => array(),
'current_month' => $curPage['month'],
'current_year' => $curPage['year'],
);

$month_info = array(
'first_day' => array(
'day_of_week' => (int) strftime('%w', mktime(0, 0, 0, $curPage['month'], 1, $curPage['year'])),
'week_num' => (int) strftime('%U', mktime(0, 0, 0, $curPage['month'], 1, $curPage['year'])),
'date' => strftime('%Y-%m-%d', mktime(0, 0, 0, $curPage['month'], 1, $curPage['year'])),
),
'last_day' => array(
'day_of_month' => (int) strftime('%d', mktime(0, 0, 0, $curPage['month'] == 12 ? 1 : $curPage['month'] + 1, 0, $curPage['month'] == 12 ? $curPage['year'] + 1 : $curPage['year'])),
'date' => strftime('%Y-%m-%d', mktime(0, 0, 0, $curPage['month'] == 12 ? 1 : $curPage['month'] + 1, 0, $curPage['month'] == 12 ? $curPage['year'] + 1 : $curPage['year'])),
),
'first_day_of_year' => (int) strftime('%w', mktime(0, 0, 0, 1, 1, $curPage['year'])),
);

$nShift = $month_info['first_day']['day_of_week'];
$calendarOptions['start_day'] = empty($calendarOptions['start_day']) ? 0 : (int) $calendarOptions['start_day'];

if (!empty($calendarOptions['start_day']))
{
$nShift -= $calendarOptions['start_day'];
if ($nShift < 0)
$nShift = 7 + $nShift;
}

$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
$nRows++;

$bday = $calendarOptions['show_birthdays'] ? calendarBirthdayArray($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
$events = $calendarOptions['show_events'] ? calendarEventArray($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
$holidays = $calendarOptions['show_holidays'] ? calendarHolidayArray($month_info['first_day']['date'], $month_info['last_day']['date']) : array();

$count = $calendarOptions['start_day'];
for ($i = 0; $i < 7; $i++)
{
$calendar_data['week_days'][] = $count;
$count++;
if ($count == 7)
$count = 0;
}

$nWeekAdjust = 0;
$calendar_data['weeks'] = array();
for ($nRow = 0; $nRow < $nRows; $nRow++)
{
$calendar_data['weeks'][$nRow] = array(
'days' => array(),
'number' => $month_info['first_day']['week_num'] + $nRow + $nWeekAdjust
);
if ($calendar_data['weeks'][$nRow]['number'] == 53 && $nShift != 4)
$calendar_data['weeks'][$nRow]['number'] = 1;

for ($nCol = 0; $nCol < 7; $nCol++)
{
$nDay = ($nRow * 7) + $nCol - $nShift + 1;

if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
$nDay = 0;

$date = sprintf('%04d-%02d-%02d', $curPage['year'], $curPage['month'], $nDay);

$calendar_data['weeks'][$nRow]['days'][$nCol] = array(
'day' => $nDay,
'date' => $date,
'is_today' => $date == $today['date'],
'is_first_day' => !empty($calendarOptions['show_week_num']) && (($month_info['first_day']['day_of_week'] + $nDay - 1) % 7 == $calendarOptions['start_day']),
'holidays' => !empty($holidays[$date]) ? $holidays[$date] : array(),
'events' => !empty($events[$date]) ? $events[$date] : array(),
'birthdays' => !empty($bday[$date]) ? $bday[$date] : array()
);
}
}

echo '
<table class="sp_acalendar smalltext">
<tr>
<td class="sp_center smalltext" colspan="7">
', !empty($modSettings['cal_enabled']) ? '<a href="' . $scripturl . '?action=calendar;year=' . $calendar_data['current_year'] . ';month=' . $calendar_data['current_month'] . '">' . $txt['months_titles'][$calendar_data['current_month']] . ' ' . $calendar_data['current_year'] . '</a>' : $txt['months_titles'][$calendar_data['current_month']] . ' ' . $calendar_data['current_year'], '
</td>
</tr><tr>';

foreach ($calendar_data['week_days'] as $day)
echo '
<td class="sp_center smalltext">', $txt['days_short'][$day], '</td>';

echo '
</tr>';

foreach ($calendar_data['weeks'] as $week_key => $week)
{
echo '<tr>';

foreach ($week['days'] as $day_key => $day)
{
echo '
<td class="sp_acalendar_day smalltext">';

if (empty($day['day']))
unset($calendar_data['weeks'][$week_key]['days'][$day_key]);
else
{
if (!empty($day['events']))
echo '<a class="portalcal" href="#day" onclick="return sp_collapseCalendar(\'', $day['day'], '\');"><font color="black">', $day['is_today'] ? '[' : '', $day['day'], $day['is_today'] ? ']' : '', '</font></a>';
else
echo '<a href="#day" onclick="return sp_collapseCalendar(\'0\');">', $day['is_today'] ? '<font color="cyan">[' : '', $day['day'], $day['is_today'] ? ']</font>' : '', '</a>';
}

echo '</td>';
}

echo '
</tr>';
}

echo '
</table>
';



echo '
<div class="sp_center smalltext" id="sp_calendar_0" style="display: none;">', $txt['error_sp_no_items_day'], '</div>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var current_day = "sp_calendar_', $curPage['day'], '";
function sp_collapseCalendar(id)
{
new_day = "sp_calendar_" + id;
if (new_day == current_day)
return false;
document.getElementById(current_day).style.display = "none";
document.getElementById(new_day).style.display = "";
current_day = new_day;
}
// ]]></script>';



echo ' <br /><center><font color="white" size="2">Upcoming Events</font></center><br />';

/*This is where the calender information block code starts*/

if (!$show_event && !$show_birthday && !$show_holiday)
{
echo '
', $txt['sp_calendar_noEventsFound'];
return;
}

$now = forum_time();
$today_date = date("Y-m-d", $now);
$calendar_array = array(
'todayEvents' => array(),
'futureEvents' => array(),
'todayBirthdays' => array(),
'todayHolidays' => array()
);

if ($show_event)
{
if (!empty($event_future))
$event_future_date = date("Y-m-d", ($now + $event_future * 86400));
else
$event_future_date = $today_date;

$events = sp_loadCalendarData('getEvents', $today_date, $event_future_date);

$displayed = array();
foreach ($events as $day => $day_events)
foreach ($day_events as $event_key => $event)
if (in_array($event['id'], $displayed))
unset($events[$day][$event_key]);
else
$displayed[] = $event['id'];

if (!empty($events[$today_date]))
{
$calendar_array['todayEvents'] = $events[$today_date];
unset($events[$today_date]);
}

if (!empty($events))
{
ksort($events);
$calendar_array['futureEvents'] = $events;
}
}

if ($show_birthday)
{
$calendar_array['todayBirthdays'] = current(sp_loadCalendarData('getBirthdays', $today_date));
$show_titles = !empty($show_event) || !empty($show_holiday);
}

if ($show_holiday)
{
$calendar_array['todayHolidays'] = current(sp_loadCalendarData('getHolidays', $today_date));
$show_titles = !empty($show_event) || !empty($show_birthday);
}

if (empty($calendar_array['todayEvents']) && empty($calendar_array['futureEvents']) && empty($calendar_array['todayBirthdays']) && empty($calendar_array['todayHolidays']))
{
echo '
', $txt['sp_calendar_noEventsFound'];
return;
}
else
{
echo '
<ul class="sp_listcal">';

if (!empty($calendar_array['todayHolidays']))
{
if ($show_titles)
echo '
<li><strong>', $txt['sp_calendar_holidays'] ,'</strong></li>';

foreach ($calendar_array['todayHolidays'] as $key => $holiday)
echo '
<li>', sp_embed_image('dot'), ' ', $holiday ,'</li>';
}

if (!empty($calendar_array['todayBirthdays']))
{
if ($show_titles)
echo '
<li><strong>', $txt['sp_calendar_birthdays'] ,'</strong></li>';

foreach ($calendar_array['todayBirthdays'] as $member)
echo '
<li>', sp_embed_image('dot'), ' <a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a></li>';
}

if (!empty($calendar_array['todayEvents']))
{
if ($show_titles)
echo '
<li class="sp_list"></li>';

foreach ($calendar_array['todayEvents'] as $event)
echo '
<li class="sp_listcal">', sp_embed_image('dot'), ' ', $event['link'],'
<br />&nbsp;&nbsp; ', $txt['zcalendar_today'],'</li>';
}

if (!empty($calendar_array['futureEvents']))
{
if ($show_titles)
echo '
<li class="sp_list">';

foreach($calendar_array['futureEvents'] as $startdate => $events)
{
list($year, $month, $day) = explode('-', $startdate);
$currentDay = $txt['months_short'][(int) $month] . ' ' . $day;

foreach($events as $event)
echo '
<li class="sp_listcal">', sp_embed_image('dot'), ' ', $event['link'], '<br />&nbsp;&nbsp; ', $currentDay;
}
}

echo '
</ul>';
}
}