I wanted a block that showed details of calendar events and not just a listing of the dates and event titles. So this is what I was able to get but I have an issue maybe someone could help me fix?
I used Thurnok's Custom Post Prefills (http://www.tinyportal.net/index.php?topic=9419.0) for the forum linked to my calendar so the event details are all in the form of
Date:
Time:
Place:
Notes:
I got this forum to show up using an edited boardnews ssi on a right block. (I copied the boardnews ssi and made a new ssi called calendarEvents and deleted the topic start date, topic starter, comments and edit lines) So currently, it looks really nice as a detailed events block. But the events are, as expected, ordered by topic post date. How could I call the event date so they are ordered by that instead?
This is the edited boardnews ssi:
// Show the calendar events in boardnews style with details.
function ssi_calendarEvents($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $func;
loadLanguage('Stats');
// Must be integers....
if ($limit === null)
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 3;
else
$limit = (int) $limit;
if ($start === null)
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
else
$start = (int) $start;
if ($board !== null)
$board = (int) $board;
elseif (isset($_GET['board']))
$board = (int) $_GET['board'];
if ($length === null)
$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
else
$length = (int) $length;
$limit = max(0, $limit);
$start = max(0, $start);
// Make sure guests can see this board.
$request = db_query("
SELECT ID_BOARD
FROM {$db_prefix}boards
WHERE " . ($board === null ? '' : "ID_BOARD = $board
AND ") . "FIND_IN_SET(-1, memberGroups)
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) == 0)
{
if ($output_method == 'echo')
die($txt['smf_news_error2']);
else
return array();
}
list ($board) = mysql_fetch_row($request);
mysql_free_result($request);
// Load the message icons - the usual suspects.
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';
// Find the post ids.
$request = db_query("
SELECT ID_FIRST_MSG
FROM {$db_prefix}topics
WHERE ID_BOARD = $board
ORDER BY ID_FIRST_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
$posts[] = $row['ID_FIRST_MSG'];
mysql_free_result($request);
if (empty($posts))
return array();
// Find the posts.
$request = db_query("
SELECT
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_FIRST_MSG DESC
LIMIT " . count($posts), __FILE__, __LINE__);
$return = array();
while ($row = mysql_fetch_assoc($request))
{
// If we want to limit the length of the post.
if (!empty($length) && $func['strlen']($row['body']) > $length)
{
$row['body'] = $func['substr']($row['body'], 0, $length);
// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));
if ($cutoff !== false)
$row['body'] = $func['substr']($row['body'], 0, $cutoff);
$row['body'] .= '...';
}
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
$return[] = array(
'id' => $row['ID_TOPIC'],
'message_id' => $row['ID_MSG'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
'replies' => $row['numReplies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'],
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => !empty($row['ID_MEMBER']) ? $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] : '',
'link' => !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
),
'locked' => !empty($row['locked']),
'is_last' => false
);
}
mysql_free_result($request);
if (empty($return))
return $return;
$return[count($return) - 1]['is_last'] = true;
if ($output_method != 'echo')
return $return;
foreach ($return as $news)
{
echo '
<div class="smalltext">
<a href="', $news['href'], '">', $news['icon'], ' <b>', $news['subject'], '</b></a>
<div class="post" style="padding: 0ex 0;">', $news['body'], '</div>
</div>';
if (!$news['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}
}
Notice how in the picture below, my events are not listed in order...
hmm.. perhaps there isn't an easy solution to this...
I'm afraid there isn't. I've been thinking about this since you first posted and I don't see a way to parse the date from within the post in order to use it for sorting.
:( <sigh>... i guess i'll have to do some sort of manual date manipulation... it would really be so nice if this worked...
thats actually sweet looking i dont know if i can do anything to it or not but I definitly like it :)
I've still been thinking about this and it occurred to me that you might be able to accomplish the same thing by taking a different approach.
As I understand it, each of your events is described in a separate topic, right? You can (and maybe already do) link a topic to the calendar. Once the topic is linked to the calendar, you can adapt one of the ssi calendar functions to display the upcoming events. The calendar would do the sorting for you, but the display would be the first post in the linked topic.
Does this make any sense?
hmm... sort of? so take a look at the calendar code and direct it to the calendar forum instead of the event dates? I'm not sure I'll figure it out but i'll definitely take a look at that.. thanks for the idea. I'll report back if I make any progress :)
I can't make this work... it just gives me a blank block...
I copied and pasted the code into my SSI.php and made a phpbox with
ssi_calendarEvents();
try putting the number of the board where you have your calendar events where it says "#":
ssi_calendarEvents(#);
okay.. i'm trying to get the hang of this php thing so it's really taking me a long time to figure this out but I started taking a different approach, as per JPDeni. I looked at the Calendar in a php-block (http://www.tinyportal.net/index.php?topic=700.0) block code snippet and just took the events part of it to get the title of the event and the date range.
Now if only I can figure out how to call the linked topic if one exists so the body of the linked topic in the form of time:, place:, and notes: can be added...
This was the code I was using (php block). If someone knows how to call the linked topic to get the topic body, it would help a lot.
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $txt, $settings, $func;
smf_loadCalendarInfo();
$now = mktime() + $modSettings['time_offset'] * 3600;
$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);
$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:#515151; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));
$day_name_length = 2;
$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();
$first_of_month = gmmktime(0,0,0,$month,1,$year);
$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
/////////////////////////////////////////////////////////////////
// EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
foreach ($context['calendar_events'] as $event)
{
$query = db_query(
"SELECT startDate
FROM {$db_prefix}calendar
WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);
$row = mysql_fetch_assoc($query);
$startdate = strtotime($row['startDate']);
mysql_free_result($query);
$query = db_query(
"SELECT endDate
FROM {$db_prefix}calendar
WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);
$row = mysql_fetch_assoc($query);
$enddate = strtotime($row['endDate']);
mysql_free_result($query);
echo '<div align="left">';
echo $event['link'] ;
echo '<br />';
echo 'Date: '; echo '' . date("n/j (D)",$startdate) . '';
if ($enddate !== $startdate)
{
echo ' - '; echo '' . date("n/j (D)",$enddate) . '';
}
echo '<br /><br />';
echo '</div>';
}
}
Well, sorry to say, I think you can replace what you have with:
global $sourcedir, $dbprefix, $settings, $modSettings, $txt, $scripturl;
require_once($sourcedir . '/Calendar.php');
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);
$low_date = strftime('%Y-%m-%d', $now);
$high_date = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);
$events = calendarEventArray($low_date, $high_date, false);
ksort($events);
That will load the $events array, sorted by date, with all the events from today through the number of 'lookahead' days specified in the forum Admin section.
And the events array is:
$events[YYYY-mm-dd][0] = array(
'id'
'title'
'topic'
'msg'
'poster'
'start_date'
'end_date'
'is_last'
'allowed_groups'
(a second event on the same day would be $events[YYYY-mm-dd][1]).
So, that gives you the topic and message ID (for those events associated with posted topics).
Dump the msg ids into an array:
$posts = array()
foreach ($events as $startdate => $evt_date)
{
foreach ($evt_date as $event)
{
$posts[] = $event['msg'];
}
}
Then you should be able to use the same code you started with once you have the list of posts to pull the message, topic, member info:
// Find the posts.
$request = db_query("
SELECT
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_FIRST_MSG DESC
LIMIT " . count($posts), __FILE__, __LINE__);
$return = array();
while ($row = mysql_fetch_assoc($request))
{
// If we want to limit the length of the post.
if (!empty($length) && $func['strlen']($row['body']) > $length)
{
$row['body'] = $func['substr']($row['body'], 0, $length);
// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));
if ($cutoff !== false)
$row['body'] = $func['substr']($row['body'], 0, $cutoff);
$row['body'] .= '...';
}
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
$return[] = array(
'id' => $row['ID_TOPIC'],
'message_id' => $row['ID_MSG'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
'replies' => $row['numReplies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'],
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => !empty($row['ID_MEMBER']) ? $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] : '',
'link' => !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
),
'locked' => !empty($row['locked']),
'is_last' => false
);
}
mysql_free_result($request);
if (empty($return))
return $return;
$return[count($return) - 1]['is_last'] = true;
if ($output_method != 'echo')
return $return;
foreach ($return as $news)
{
echo '
<div class="smalltext">
<a href="', $news['href'], '">', $news['icon'], ' <b>', $news['subject'], '</b></a>
<div class="post" style="padding: 0ex 0;">', $news['body'], '</div>
</div>';
if (!$news['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}
okay, if I'm understanding you correctly:
Put this into a php block?
require_once($sourcedir . '/Calendar.php');
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);
$low_date = strftime('%Y-%m-%d', $now);
$high_date = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);
$events = calendarEventArray($low_date, $high_date, false);
ksort($events);
$events[YYYY-mm-dd][0] = array(
'id'
'title'
'topic'
'msg'
'poster'
'start_date'
'end_date'
'is_last'
'allowed_groups'
$posts = array()
foreach ($events as $startdate => $evt_date)
{
foreach ($evt_date as $event)
{
$posts[] = $event['msg'];
}
}
I'm not sure what to do with the last bit of code - I originally kept that in the ssi.php file...
I showed the structure of the $events array only to illustrate the members that get returned.
When I thought about this a bit, I decided to look at the calendarArrayEvents function and I saw that the query it used could be adapted to pull the info from the post and handle sorting at the same time (one query for the whole thing; much better).
Of course, you understand that this is all tied to the SMF Calendar dates which get entered for an event (rather than the typed in date in the post).
Try this in a php block:
global $user_info, $settings, $scripturl, $db_prefix, $modSettings;
$max_length = 256;
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);
$low_date = strftime('%Y-%m-%d', $now);
$high_date = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);
$result = db_query("
SELECT
cal.ID_EVENT, cal.startDate, cal.endDate, cal.title, cal.ID_MEMBER, cal.ID_TOPIC,
cal.ID_BOARD, b.memberGroups, t.ID_FIRST_MSG,
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, m.smileysEnabled, m.ID_MSG, t.locked
FROM {$db_prefix}calendar AS cal
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = cal.ID_MEMBER)
LEFT JOIN {$db_prefix}topics AS t ON (t.ID_TOPIC = cal.ID_TOPIC)
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = cal.ID_BOARD)
LEFT JOIN {$db_prefix}messages AS m ON (m.ID_MSG = t.ID_FIRST_MSG)
WHERE cal.startDate <= '$high_date'
AND cal.endDate >= '$low_date'
AND cal.ID_TOPIC = t.ID_TOPIC
AND (".$user_info['query_see_board']." OR cal.ID_BOARD = 0)
ORDER BY cal.startDate, cal.ID_TOPIC", __FILE__, __LINE__);
$events = array();
if (mysql_num_rows($result) == 0) {
echo '<h3>No Events Found</h3>';
return;
}
while ($row = mysql_fetch_assoc($result)) {
if ($row['ID_BOARD'] != 0) {
// If we want to limit the length of the post.
if (!empty($max_length) && strlen($row['body']) > $max_length)
{
$row['body'] = substr($row['body'], 0, $max_length);
// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));
if ($cutoff !== false)
$row['body'] = substr($row['body'], 0, $cutoff);
$row['body'] .= '...';
}
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
}
censorText($row['title']);
$events[] = array(
'title' => $row['title'],
'topic' => $row['ID_TOPIC'],
'msg' => $row['ID_FIRST_MSG'],
'poster' => $row['ID_MEMBER'],
'start_date' => $row['startDate'],
'end_date' => $row['endDate'],
'icon' => $row['ID_BOARD'] == 0 ? '' : '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['ID_BOARD'] == 0 ? $row['title'] : $row['subject'],
'body' => $row['ID_BOARD'] == 0 ? '' : $row['body'],
'href' => $row['ID_BOARD'] == 0 ? ($scripturl . '?action=calendar;year=' . substr($row['startDate'],0,4) . ';month=' . substr($row['startDate'],5,2)) : ($scripturl . '?topic=' . $row['ID_TOPIC'] . '.0')
);
}
mysql_free_result($result);
$ctr = 1;
$tot = count($events);
foreach ($events as $event)
{
echo '
<div class="smalltext">
<a href="', $event['href'], '">', $event['icon'], ' <b>', $event['subject'], '</b></a>
<div class="post" style="padding: 0ex 0;">', $event['body'], '</div>
</div>';
if ($ctr < $tot) {
echo '<hr style="margin: 2ex 0;" width="100%" />';
$ctr++;
}
}
WOW~! thank you so much! that's exactly what I was looking for ;D
Now that you mention it, it would be better to have the date from the calendar show up rather than the typed in date from the post so would it be okay just to add this right before the <div class="post"... part?
<div><b>Date: </b>' . date("n/j (D)",$event['start_date']) . '';
if ($event['end_date'] !== $event['start_date']) {
echo '
- ' . date("n/j (D)",$event['end_date']) . '
';
}
echo '</div>';echo '
Actually I got it to work using ', $event['start_date'], ' and ', $event['end_date'], ' but I wanted the format to be like 11/2 (Fri) so I tried ' . date("n/j (D)",$event['start_date']) . ' and ' . date("n/j (D)",$event['end_date']) . ' but I'm getting 12/31 (Wed) for all the dates.. I'm sure I have to specify date( ) somewhere but I'm not sure where...
You almost got it.
Those date() functions expect a value in UNIX timestamp format (which is seconds since midnight Jan 1, 1970). The values in the array are in string format, so when it tried to use them, it got a zero value (and you were working with Dec 31, 1969).
To to do this, you need to send them through the php function strtotime():
<div><b>Date: </b>' . date("n/j (D)",strtotime($event['start_date'])) . '';
if ($event['end_date'] !== $event['start_date']) {
echo '
- ' . date("n/j (D)",strtotime($event['end_date'])) . '
';
}
echo '</div>';echo '
yay! it works! thanks so much~ ;D
haha... i guess the next logical step would be to add a "Time" and "Place" section to function template_event_post() so all of that can be collected when an event is posted.. then just have this snippet spit back all the information with the post body being the extra details... is this feasible? or maybe all this is in the works for a future release of tinyportal. :D
That's getting into the area of a mod for SMF. It's SMF's calendar table in the database and their template for posting events. PHP in blocks or articles managed by TP can pull all sorts of data and present it in various ways, but adding columns to the DB table and making changes to the code in place to manage those additional fields is a bit different.
Not saying it can't be done or would be tremendously difficult. Just that it IS something I'd see as non-trivial.
ah i see.. that seems waayy above me so I'll just stick to what I have now. thanks for all your help!
ok being playing wi this all morning and still cannot get it to display it either comes upwith nothing when i put it in as a ssp or written code when in php ?
what am i doing wrong ?
also do i need to creat a board for the calender events to direct to ?
has anybody got this fully working yet ?
if so how you get it in and which modded code did you find worked ?
you can ignore the first post about ssi changes and put JACortina's code into a php block. With the date modification, the full code is:
global $user_info, $settings, $scripturl, $db_prefix, $modSettings;
$max_length = 256;
$now = mktime() + (($user_info['time_offset'] + $modSettings['time_offset']) * 3600);
$low_date = strftime('%Y-%m-%d', $now);
$high_date = strftime('%Y-%m-%d', $now + max(($modSettings['cal_days_for_index'] - 1),0) * 24 * 3600);
$result = db_query("
SELECT
cal.ID_EVENT, cal.startDate, cal.endDate, cal.title, cal.ID_MEMBER, cal.ID_TOPIC,
cal.ID_BOARD, b.memberGroups, t.ID_FIRST_MSG,
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, m.smileysEnabled, m.ID_MSG, t.locked
FROM {$db_prefix}calendar AS cal
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = cal.ID_MEMBER)
LEFT JOIN {$db_prefix}topics AS t ON (t.ID_TOPIC = cal.ID_TOPIC)
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = cal.ID_BOARD)
LEFT JOIN {$db_prefix}messages AS m ON (m.ID_MSG = t.ID_FIRST_MSG)
WHERE cal.startDate <= '$high_date'
AND cal.endDate >= '$low_date'
AND cal.ID_TOPIC = t.ID_TOPIC
AND (".$user_info['query_see_board']." OR cal.ID_BOARD = 0)
ORDER BY cal.startDate, cal.ID_TOPIC", __FILE__, __LINE__);
$events = array();
if (mysql_num_rows($result) == 0) {
echo '<h3>No Events Found</h3>';
return;
}
while ($row = mysql_fetch_assoc($result)) {
if ($row['ID_BOARD'] != 0) {
// If we want to limit the length of the post.
if (!empty($max_length) && strlen($row['body']) > $max_length)
{
$row['body'] = substr($row['body'], 0, $max_length);
// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));
if ($cutoff !== false)
$row['body'] = substr($row['body'], 0, $cutoff);
$row['body'] .= '...';
}
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
censorText($row['subject']);
censorText($row['body']);
}
censorText($row['title']);
$events[] = array(
'title' => $row['title'],
'topic' => $row['ID_TOPIC'],
'msg' => $row['ID_FIRST_MSG'],
'poster' => $row['ID_MEMBER'],
'start_date' => $row['startDate'],
'end_date' => $row['endDate'],
'icon' => $row['ID_BOARD'] == 0 ? '' : '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['ID_BOARD'] == 0 ? $row['title'] : $row['subject'],
'body' => $row['ID_BOARD'] == 0 ? '' : $row['body'],
'href' => $row['ID_BOARD'] == 0 ? ($scripturl . '?action=calendar;year=' . substr($row['startDate'],0,4) . ';month=' . substr($row['startDate'],5,2)) : ($scripturl . '?topic=' . $row['ID_TOPIC'] . '.0')
);
}
mysql_free_result($result);
$ctr = 1;
$tot = count($events);
foreach ($events as $event)
{
echo '
<div class="smalltext">
<a href="', $event['href'], '">', $event['icon'], ' <b>', $event['subject'], '</b></a>
<div><b>Date: </b>' . date("n/j (D)",strtotime($event['start_date'])) . '';
if ($event['end_date'] !== $event['start_date']) {
echo '
- ' . date("n/j (D)",strtotime($event['end_date'])) . '
';
}
echo '</div>';echo '
<div class="post" style="padding: 0ex 0;">', $event['body'], '</div>
</div>';
if ($ctr < $tot) {
echo '<hr style="margin: 2ex 0;" width="100%" />';
$ctr++;
}
}
I believe the coding would require a board linked to calendar events since it's calling the information from there (icon, title, post body). You might still consider adding the Custom Post Prefill hack once you dedicate a board to your events so that you can have prefilled Time, Place, Notes in there already.
that works thanks for your help
Actually, the code 'should' also show events which AREN'T linked to a post (giving the event title in place of the topic subject). This won't have the topic icon or any further text, of course.
But it's driven by calendar event entries and will read in the referenced topic, whatever board it's in.
i got it working but it did need the link to a board or it just said no event
its block two on left
www.marine-keepers.com/forums
Hi all...
Firstly many thanks for all the help on this forum. I am using the code posted below by jpark (and it works a treat!), but was wondering if there is any way to change the date format from US to UK (ie. 1/22 to 22/1)? Not sure if this is to do with the code or the calendar... Bit of a newbie really!
Thanks, Chris
Quote from: jpark on November 02, 2007, 03:16:25 AM
This was the code I was using (php block). If someone knows how to call the linked topic to get the topic body, it would help a lot.
global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $txt, $settings, $func;
smf_loadCalendarInfo();
$now = mktime() + $modSettings['time_offset'] * 3600;
$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);
$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:#515151; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));
$day_name_length = 2;
$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();
$first_of_month = gmmktime(0,0,0,$month,1,$year);
$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
/////////////////////////////////////////////////////////////////
// EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
foreach ($context['calendar_events'] as $event)
{
$query = db_query(
"SELECT startDate
FROM {$db_prefix}calendar
WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);
$row = mysql_fetch_assoc($query);
$startdate = strtotime($row['startDate']);
mysql_free_result($query);
$query = db_query(
"SELECT endDate
FROM {$db_prefix}calendar
WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);
$row = mysql_fetch_assoc($query);
$enddate = strtotime($row['endDate']);
mysql_free_result($query);
echo '<div align="left">';
echo $event['link'] ;
echo '<br />';
echo 'Date: '; echo '' . date("n/j (D)",$startdate) . '';
if ($enddate !== $startdate)
{
echo ' - '; echo '' . date("n/j (D)",$enddate) . '';
}
echo '<br /><br />';
echo '</div>';
}
}
You might want to use JACortina's code instead (look at my reply #20)... it is the most updated. Using that code, you can change the date format by searching this code
date("n/j (D)",strtotime($event['start_date']))
and replacing it with this
date("j/n (D)",strtotime($event['start_date']))
lowercase j is day of month without leading zeros
lowercase n is month without leading zeros
You can find more date formats here: http://us.php.net/date
Many thanks :)