I was working on the calendar block.
I tried adding some links to the calendar for "next month".
I keep getting a parse error:
QuoteParse error: syntax error, unexpected ',' in /home/.abigaildryer/xarcell/vestatt.org/smf/Sources/Load.php(1735) : eval()'d code(52) : eval()'d code on line 33
Here is the code I'm using:
$calendar = '<table align="center" valign="top" width="100%"><tr><td><a href="', $context['next_calendar']['href'], '">»</a></td><td>'."\n".
'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>
' : $title).$n."</caption>\n </td><td><a href="', $context['next_calendar']['href'], '">»</a></td></tr><tr>";Any suggestions on how to fix it?
You are not escaping back to PHP at this point.
.$n"</caption>
Should be:
.$n,'"</caption>
I think. :)
Nah that didn't help....
Here is the whole snippet if that helps. I cannot figure it out:
global $context, $settings, $options, $txt, $scripturl, $modSettings;
$now = mktime() + $modSettings['time_offset'] * 3600;
$today = date('j',$now);
$days = array($today=>array(NULL,NULL,'<a align="center" class="windowbg2" style="color: #999999; font-weight: bold; border: solid 1px black; padding: 2px 4px 2px 4px; font-size: xx-small; font-family: verdana, sans-serif;" onmouseover="this.className=\'windowbg3\'" onMouseOut="this.className=\'windowbg2\'" href="'.$scripturl.'?action=calendar;sa=post;" target="_self">'.$today.'</a>'));
$year = date("Y",$now);
$month = date("n",$now);
$day_name_length = 3;
$month_href = $scripturl . '?action=calendar';
$first_day = 0;
$pn = array();
$first_of_month = gmmktime(0,0,0,$month,1,$year);
# remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()
$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
#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = '<span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%"><tr><td><a href="', $context['next_calendar']['href'], '">»</a></td><td>'."\n".
'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>
' : $title).$n."</caption>\n </td><td><a href="', $context['next_calendar']['href'], '">»</a></td></tr><tr>";
if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= '<th style="font-size: xx-small; font-family: verdana, sans-serif;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}
if($weekday > 0) $calendar .= '<td style="font-family: verdana, sans-serif;" 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>\n<tr style=\"text-align:center;\">";
}
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=\"windowbg\" style=\"font-size: x-small; font-family: verdana, sans-serif;\"><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 style="font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';
#create notice for Holidays, Events & Birthdays.
if (ssi_todaysEvents('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['events']))
{
echo '<tr><td colspan="2"><hr></td><td width="30px" colspan="3" class="smalltext" align="center">' , $txt['calendar4'] , '</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext" valign="middle">';
$events = $result['events'];
foreach ($events as $event)
{
if ($event['can_edit']){
echo '
<a href="' . $event['modify_href'] . '" style="color: #c00000;">'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':</a>';
}
else
echo '
'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':';
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $event['link'] . '</span><br />';
}
}
echo '</td></tr>';
}
// Show a little "post event" button?
echo '
<tr><td colspan="7" align="center" style="padding-top: 1em; font-size: x-small; font-weight: 600; text-transform: uppercase;"><a href="', $scripturl, '?action=calendar;sa=post;sesc=', $context['session_id'], '">' , $txt['calendar23'] , '</a></td></tr>';
echo '</table>';
You have some inconsistencies with your quotes. Also, as a side note, you should try to stay consistent with your concatenation operators. I notice you used the period ( . ) throughout most of the script, but on the code line you had issues, you used the comma ( , ). While both are "legal" concatenation operators, you should use one consistently. I personally use the period since it is already seen as an "operator" and most php editors (including Dreamweaver which is what I use) will give it the same code coloring as you set for other operators, making it stick out well when viewing in the <editor of your choice here>.
Here's a copy of the full code again, look at the area of your first post for info. I did not test this however, but simply "eye-balled" it (and put periods in place of the commas on that line to be consistent with the rest of the code):
global $context, $settings, $options, $txt, $scripturl, $modSettings;
$now = mktime() + $modSettings['time_offset'] * 3600;
$today = date('j',$now);
$days = array($today=>array(NULL,NULL,'<a align="center" class="windowbg2" style="color: #999999; font-weight: bold; border: solid 1px black; padding: 2px 4px 2px 4px; font-size: xx-small; font-family: verdana, sans-serif;" onmouseover="this.className=\'windowbg3\'" onMouseOut="this.className=\'windowbg2\'" href="'.$scripturl.'?action=calendar;sa=post;" target="_self">'.$today.'</a>'));
$year = date("Y",$now);
$month = date("n",$now);
$day_name_length = 3;
$month_href = $scripturl . '?action=calendar';
$first_day = 0;
$pn = array();
$first_of_month = gmmktime(0,0,0,$month,1,$year);
# remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()
$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
#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = '<span style="font-size: xx-small; font-family: verdana, sans-serif;">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table align="center" valign="top" width="100%"><tr><td><a href="' . $context['next_calendar']['href'] . '">»</a></td><td>' . "\n" .
'<caption >' . $p . ($month_href ? '<a href="' . htmlspecialchars($month_href) . '">' . $title . '</a>' : $title) . $n . '</caption>\n </td><td><a href="' . $context['next_calendar']['href'] . '">»</a></td></tr><tr>';
if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= '<th style="font-size: xx-small; font-family: verdana, sans-serif;" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:center;\">";
}
if($weekday > 0) $calendar .= '<td style="font-family: verdana, sans-serif;" 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>\n<tr style=\"text-align:center;\">";
}
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=\"windowbg\" style=\"font-size: x-small; font-family: verdana, sans-serif;\"><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 style="font-size: xx-small; font-family: verdana, sans-serif;" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';
#create notice for Holidays, Events & Birthdays.
if (ssi_todaysEvents('')) {
$result = ssi_todaysCalendar('');
if(!empty($result['events']))
{
echo '<tr><td colspan="2"><hr></td><td width="30px" colspan="3" class="smalltext" align="center">' , $txt['calendar4'] , '</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext" valign="middle">';
$events = $result['events'];
foreach ($events as $event)
{
if ($event['can_edit']){
echo '
<a href="' . $event['modify_href'] . '" style="color: #c00000;">'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':</a>';
}
else
echo '
'.substr($event['start_date'],5 , 2).'/'.substr($event['start_date'],8).':';
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $event['link'] . '</span><br />';
}
}
echo '</td></tr>';
}
// Show a little "post event" button?
echo '
<tr><td colspan="7" align="center" style="padding-top: 1em; font-size: x-small; font-weight: 600; text-transform: uppercase;"><a href="', $scripturl, '?action=calendar;sa=post;sesc=', $context['session_id'], '">' , $txt['calendar23'] , '</a></td></tr>';
echo '</table>';
Thank you for the pointers and it's working somewhat as it should. Just one little issue.
In that script, I added "next month" and "previous month" links.
Area of code(everything else is the same as you posted):
$calendar = '<table align="center" valign="top" width="100%">'."\n".
'<caption >'.$p.($month_href ? '<a href="' . $context['previous_calendar']['href'] . '"> « </a> <a href="'.htmlspecialchars($month_href).'">'.$title.'</a> </a> <a href="' . $context['next_calendar']['href'] . '"> » </a>' : $title).$n."</caption>\n<tr>";
However, those links only work when viewing the calendar page, outside the calendar page they just link to index.
Was there something simple I overlooked?
Without going through the entire code, I would say that the $context array is at issue here. Since that is where your link url is coming from, in particular the 'previous_calendar' and 'next_calendar' indexes in that array. The 'href' element for each apparently holds the url information. If you are seeing a link only to the index when outside the calendar page, then SMF must be loading the index page's url into those array elements when not in the calendar.
I haven't really looked into the calendar code in SMF, but you will probably need to call their function that retrieves the next and previous months (based on the current month) within your script. Or, make your own function that calculates what the next and previous months are based on the current month. I say this because you are already using the date function to get the current month, so you can calculate the next/previous.
That would be the quick fix I think. Otherwise, it probably means digging into SMF code to see why/where they reset those two URLs to point to the index page. Which probably would lead to modifying the SMF code, and that's "usually" not desirable for a block code snippet unless there is no alternative.
I didn't mention storing the values for those elements in your own variables when they do not point to the index page, since this would imply you are able to get that info already, which I'm assuming wouldn't happen until the first time they went to the calendar page. Hence...
You could probably quickly create a simple function to get next/previous months based on the current month value, then just create the URLs based on that in your block where they go.