TinyPortal

Development => Support => Topic started by: stigmartyr on May 17, 2009, 06:04:43 PM

Title: Help with Calendar Snippet
Post by: stigmartyr on May 17, 2009, 06:04:43 PM
So I've been using this Calendar/Event/Birthday block for a while now and I've noticed that it's not showing Events at all and I've got lots of them in the calendar.  Is this due to permissions (guest permissions), even logged in I cannot see events printed there.

Or is there some other bug in how many events can be parsed?
Title: Help with Calendar Snippet
Post by: Zetan on May 17, 2009, 06:10:29 PM
Quote from: Ã,§tigmartyr on May 17, 2009, 06:04:43 PM
So I've been using this Calendar/Event/Birthday block for a while now and I've noticed that it's not showing Events at all and I've got lots of them in the calendar.  Is this due to permissions (guest permissions), even logged in I cannot see events printed there.

Or is there some other bug in how many events can be parsed?

You have too many events and the SMF calendar is looking ahead too far. reduce the look ahead to around two weeks. If you can't do that, you need to ask at SMF as the calendar is part of the forum software. TP's calendar blocks only pull the data used by SMF,
Title: Help with Calendar Snippet
Post by: stigmartyr on May 17, 2009, 06:23:14 PM
Quote from: Zetan on May 17, 2009, 06:10:29 PM
Quote from: Ã,§tigmartyr on May 17, 2009, 06:04:43 PM
So I've been using this Calendar/Event/Birthday block for a while now and I've noticed that it's not showing Events at all and I've got lots of them in the calendar.  Is this due to permissions (guest permissions), even logged in I cannot see events printed there.

Or is there some other bug in how many events can be parsed?

You have too many events and the SMF calendar is looking ahead too far. reduce the look ahead to around two weeks. If you can't do that, you need to ask at SMF as the calendar is part of the forum software. TP's calendar blocks only pull the data used by SMF,

I reduced "Max days in advance on board index:" from 30 days to 1 day and it still wont show :(
Title: Help with Calendar Snippet
Post by: Zetan on May 17, 2009, 06:53:50 PM
Do you have the forum to display events in the Info Center? How many events are there.

A link to your site would help.

I have also split this topic into it's own topic. Please include your code in the first post and follow the posting guide.
Title: Re: Help with Calendar Snippet
Post by: stigmartyr on May 18, 2009, 04:17:07 AM
Link to my site: http://www.stangnation.com
SMF version: SMF 1.1.5
TP version: 0.9.8
Theme name and version: Musiconica (original)
Browser Name and Version: IE8/FF/Chrome
Mods installed: Repeating Calendar Events v1.2.6, others not related to calendar
Related Error messages: No msg.  Just doesn't parse or show Events in the Calendar Block located on the lower right hand column.  Currently set to show events 10 days in advance.

I also have calendar set to show events in Board Index AND Calendar, yet it wont show in Board Index either now that you mention it.  I wonder if perhaps something was knocked out by the Repeating Calendar Events mod? 

Here is the code I am using:


global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

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:steelblue; 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>';
$calendar = '<table align="center">'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    if(isset($days[$day]) and is_array($days[$day])){
        @list($link, $classes, $content) = $days[$day];
        if(is_null($content))  $content  = $day;
        $calendar .= '<td '.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
list ($uyear, $umonth, $uday) = explode('-', $row['birthdate']);
        $birthdate = strtotime(sprintf('%04d-%02d-%02d', date("Y"), $umonth, $uday));
        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    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);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
// WHERE title='".str_replace("'","''",$holiday)."'
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."-%' OR eventDate LIKE '0004-%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime(date("Y").substr($row['eventDate'], 4));

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';

Title: Re: Help with Calendar Snippet
Post by: JPDeni on May 18, 2009, 04:31:18 AM
QuoteI wonder if perhaps something was knocked out by the Repeating Calendar Events mod? 

Not knowing what that mod does, there's no way to know other than for you to uninstall the mod and see what happens.
Title: Re: Help with Calendar Snippet
Post by: Ianedres on May 18, 2009, 04:34:18 AM
I'm not familiar with the function called in the second line of your code, so I assume it is part of the calendar mod you mentioned. If your theme isn't aware of the calendar mod's function, the script is most likely failing at that point. (Check your error log for 'undefined function'...)

That said, I recently authored a calendar extraction snippet that will display a sliding range of events that you may wish to try; it uses the SMF function API to retrieve the events stored in the calendar... so it should be available, regardless of the theme.

http://www.tinyportal.net/index.php/topic,29465.0.html
Title: Re: Help with Calendar Snippet
Post by: stigmartyr on May 18, 2009, 04:58:57 AM
Ok - I'll try to sort out any issues with that mod, then.  I did try that other mod but it didn't quite fit my dimensions and look.

I should note I did another version of the mod (the one you're talking about) but it didn't work, though I dont think I tried to set the advance to less than 30 days when I did have that code up
Title: Re: Help with Calendar Snippet
Post by: stigmartyr on May 18, 2009, 05:24:19 AM
Ok I am now using the code found on this post: http://www.tinyportal.net/index.php/topic,28689.msg229041.html#msg229041

I'll sort out the repeating events mod and report back.  When I go to uninstall it I get errors with these files at the moment:

./Themes/default/languages/index.english.php
./Themes/default/Calendar.template.php
./Themes/default/Post.template.php

Based on experience I know that if the custom theme lacks these files then SMF defaults to the default folder.  In my case, all three files above should be edited from the default themes folder, so that's where I'm troubleshooting from.
Title: Re: Help with Calendar Snippet
Post by: Ianedres on May 18, 2009, 05:27:09 AM
View the block in the default theme and see if it is loading anything so that you can verify the mod is working at all.

Secondly, this mod is doing moderate amounts of calculating the sliding window that my feeble mind can't follow. There are several raw SQL queries that are retrieving the information that the SMF API function already provides, so you're adding some load to the server by having the additional queries for each birthday member.

I'm not trying to tear the mod apart; just trying to help out by reading the code without having the mod installed is difficult.

I think the code that loads smf_loadCalendarInfo may be available only in the default theme... which mean you'll have to add it to Musiconica's theme files.
Title: Re: Help with Calendar Snippet
Post by: stigmartyr on May 18, 2009, 05:48:38 AM
Dont see any change using the default theme..

Thanks for pointing out the load on the Bday queries.  Would you suggest removing it entirely or writing it a different way?

I can say that at one point a while back I was able to see events printed in on the board index and the block was showing events in the custom theme.  It's been a while since I last checked on it and I've tweaked the site a bit since then.

I guess I'll just have to track down what changed, compare with error logs and report back :)
Title: Re: Help with Calendar Snippet
Post by: Ianedres on May 18, 2009, 06:11:39 AM
Where are the brackets { } for the 'for' statement on line #22, as well as for the 'foreach' statement on line #36?

That very well may some of the problem for processing the script...

QuoteThanks for pointing out the load on the Bday queries.  Would you suggest removing it entirely or writing it a different way?

Probably isn't adding too many queries unless you're looking at a long range of dates... I just think the API calendarBirthdayArray function (http://support.simplemachines.org/function_db/index.php?action=view_function;id=27) would be easier to use.
Title: Re: Help with Calendar Snippet
Post by: ardecki on October 19, 2009, 09:54:57 PM
I am using this same code I will copy paste it below.   It has been working well, but now It is showing Holloween as Dec 31. not Oct.
My Site.  www.theamericansclan.com
It is also showing like this on OP's Stang Page.

Been searching for a fix but I havent come across one yet. Any help would be appreciated.

Thanks

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

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:steelblue; 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;
// Change for more letters

$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>';
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

/////////////////////////////////////////////////////////////////
//   CALENDAR SECTION
//
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    if(isset($days[$day]) and is_array($days[$day])){
        @list($link, $classes, $content) = $days[$day];
        if(is_null($content))  $content  = $day;
        $calendar .= '<td '.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $birthdate = strtotime($row['birthdate']);

        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    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);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime($row['eventDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';
Title: Re: Help with Calendar Snippet
Post by: ZarPrime on October 21, 2009, 01:12:30 PM
ardecki,

I don't know who originally did this code but there is obviously some problem with it.  I have tried it on both a TP 1.0 beta 1 Forum and a TP 1.0 beta 4 Forum and it has quirks.

I would suggest that you try one of the other calendar snippets located in our block Code Snippets Board as this one is not working right.

ZarPrime
Title: Re: Help with Calendar Snippet
Post by: ardecki on October 21, 2009, 01:42:24 PM
Quote from: ZarPrime on October 21, 2009, 01:12:30 PM
ardecki,

I don't know who originally did this code but there is obviously some problem with it.  I have tried it on both a TP 1.0 beta 1 Forum and a TP 1.0 beta 4 Forum and it has quirks.

I would suggest that you try one of the other calendar snippets located in our block Code Snippets Board as this one is not working right.

ZarPrime
Thank You ZarPrime,
I will take a look and see if I can find another one I like.
Ardecki