From: Jim Hu <ji...@ta...> - 2004-09-23 08:46:42
|
Playing with this some more, I realized that I needed a few more tweaks: I changed $_GET['blogid'] to $_REQUEST['blogid'] to handle posts that invoke the page. More importantly, I realized that calendar blocks were not behaving correctly, so I split the mk_drawCalendar function into two functions. In blocks.php I changed mk_drawCalendar($m,$y,0); to $string .= mk_Calendar($m,$y,0); Splitting into the two functions makes any other calls to mk_drawCalendar work the same as before. Sorry to send off the other version prematurely...hope this works better. Jim --------------------revised functions for lib.php------------------ # # mk_drawCalendar - builds calander for archive script # function mk_drawCalendar($m,$y,$search=1) { echo mk_Calendar($m,$y,$search=1); } function mk_Calendar($m,$y,$search=1) { global $blogid, $db; if ((!$m) || (!$y)) { $m = date("n",mktime()); $y = date("Y",mktime()); } /*== get what weekday the first is on ==*/ $tmpd = getdate(mktime(0,0,0,$m,1,$y)); $month = $tmpd["month"]; $firstwday= $tmpd["wday"]; $today = date("Ymd",mktime()); $lastday = mk_getLastDayofMonth($m,$y); $string = ' <table><tr> <td style="padding-left:12px;padding-right:12px;padding-top:4px;padding- bottom:4px;border:1px solid #999999;background-color:#eeeeee;"> <table cellspacing="0" cellpadding="2" border="0"> <tr> <td colspan="7" align="center"><b>'."$month $y".'</b> </td> </tr> <tr> <td width="19" align="center" class="calday">Sun</td> <td width="19" align="center" class="calday">Mon</td> <td width="19" align="center" class="calday">Tue</td> <td width="19" align="center" class="calday">Wed</td> <td width="19" align="center" class="calday">Thu</td> <td width="19" align="center" class="calday">Fri</td> <td width="19" align="center" class="calday">Sat</td> </tr>'; $d = 1; $wday = $firstwday; $firstweek = true; /*== loop through all the days of the month ==*/ while ( $d <= $lastday) { /*== set up blank days for first week ==*/ if ($firstweek) { $string .= "<tr>"; for ($i=1; $i<=$firstwday; $i++) { $string .= "<td> </td>"; } $firstweek = false; } /*== Sunday start week with <tr> ==*/ if ($wday==0) { $string .= "<tr>"; } $mo = $m; if($mo <10) { if(!preg_match("/0\d/",$mo)) { $mo = "0".$mo; } } $da = $d; if($da <10) { if(!preg_match("/0\d/",$da)) { $da = "0".$da; } } /*== Look for blog entries for this day ==*/ $sql = "select count(*) as count from blog_entries where blog_id = $blogid AND date like '$y-$mo-$da%'"; $res = $db->Execute($sql); /*== check for event ==*/ $showdate = $y.$mo.$da; $string .= "<td align=center class=calday"; if($showdate == $today) { $string .= " bgcolor=gainsboro"; } $string .= ">"; /*== if entries are found, output link to that days entries ==*/ if($res->fields['count'] > 0) { $string .= "<a href=\"archive.php?m=$mo&d=$da&y=$y&blogid=$blogid\">$d</a>"; } else { $string .= $d; } $string .= "</td>\n"; /*== Saturday end week with </tr> ==*/ if ($wday==6) { $string .= "</tr>\n"; } $wday++; $wday = $wday % 7; $d++; } if($wday != 0) { for($i=$wday; $i <7; $i++) { $string .= "<td></td>\n"; } $string .= "</tr>\n"; } #determine next and previous month if(($m-1)<1) { $pm = 12; } else { $pm = $m-1; } if(($m+1)>12) { $nm = 1; } else { $nm = $m+1; } if(strlen($pm) == 1) { $pm = "0".$pm; }; if(strlen($nm) == 1) { $nm = "0".$nm; }; $string .= '<tr><td colspan=3 align=right>'; $string .= "<b><a href=\"archive.php?m=$pm&y=(($m-1)<1) ? $y-1 : $y&blogid=$blogid\">".getPrevMo($mo)."</a></b> </td><td><br></td>"; $string .= "<td colspan=3 align=left><b><a href=\"archive.php?m=$nm&y=(($m+1)>12) ? $y+1 : $y&blogid=$blogid?>\">".getNextMo($mo)."</b></a></td></tr> </table>"; if($search){ $string .= "<div align=center> <hr> <form action=\"archive.php\" method=POST> <input type=hidden name=blogid value=\"$blogid\"> <input type=hidden name=act value=\"search\"> <input type=text class=search2 name=keyw><br><input class=search type=submit value=\"Search\"> </form> </div>"; } $string .="</td></tr></table><br>"; return $string; /*== end drawCalendar function ==*/ } On Sep 23, 2004, at 1:00 AM, Jim Hu wrote: > Here's my revised version of blocks.php to put the blocks in an array. > To display them, > > include "blocks.php"; > foreach ($blockarray as $key=>$block){ > echo $block; > } > > To display just the first 3 (for example) > include "blocks.php"; > foreach ($blockarray as $key=>$block){ > if ($key<3) echo $block; > } > This is much better than what I posted before - as with the problem > with isUserAuthorized, using file("blocks.php?blogid=3") doesn't pass > the $_SESSION vars, so the login block doesn't act like you're ever > logged in. With this approach it works as expected. > > Jim > > <blocks.php> |