TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,219
  • Total Topics: 21,352
  • Online today: 556
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online

Calendar Event Details Block

Started by jpark, August 14, 2007, 01:42:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jacortina

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%" />';
}

jpark

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...

jacortina

#12
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++;
}
}

jpark

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...

jacortina

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 '

jpark


jpark

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

jacortina

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.

jpark

ah i see.. that seems waayy above me so I'll just stick to what I have now.  thanks for all your help!

martinmarinekeeper

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 ?

This website is proudly hosted on Crocweb Cloud Website Hosting.