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

Recent

Welcome to TinyPortal. Please login or sign up.

May 19, 2024, 04:01:22 AM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 100
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 72
  • Total: 72

SMF Calendar Block

Started by Lesmond, September 03, 2005, 11:30:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Porky

Quote from: fangweile on May 23, 2007, 12:16:35 PM
can I adjust the Width of the calendar?

Are you talking about the one in a block or the one in SMF?

For the block you can goto the settings in TP and change the widths of a block
And if it is the SMF Calendar just set it up not to display blocks when viewed.

fangweile

I am talking about the width of the calendar, I have set my block to 150 pixel and when I try to use the calendar its overlaps in the blocks.

jacortina

Which version of the Calendar block are you using (probably easiest to paste the code from the block into a post here)?

fangweile

I have used this code:

Quoteglobal $scripturl;

         $now = mktime();
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: red; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 3;
         $month_href = NULL;
         $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 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>'."\n".
      '<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<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 class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
      $calendar .= "</tr>\n<tr>";
   }

   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>\n<tr>";
      }
      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\">$day</td>";
   }
   if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

   echo $calendar."</tr>\n</table>\n";

jacortina

Right off, I'd try changing:
         $day_name_length = 3;

To:
         $day_name_length = 2;

As long as you can settle for chopping the day column labels to two letters.

fangweile

Its really works, thanks a lot J.A.Cortin :lol:

purplegold

Quote from: J.A.Cortina on May 24, 2007, 01:57:19 AM
Right off, I'd try changing:
         $day_name_length = 3;

To:
         $day_name_length = 2;

As long as you can settle for chopping the day column labels to two letters.


Sounds good, it does seem to fix the width with the rest of the block however how can you position the calender in the centre since it looks too far to the left and a whole bunch of empty space on the right.

thanks.

jacortina

Try changing:
   $calendar = '<table>'."\n".
      '<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'[/url]' : $title).$n."</caption>\n<tr>";


To:
   $calendar = '<table align="center">'."\n".
      '<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'[/url]' : $title).$n."</caption>\n<tr>";


purplegold

Thanks alot!!!  :coolsmiley:

Galious

I'm trying to change language in a server-independent way, so I've done the modifications in the last page. The problem is that now the month name has disappeared. I've revised the code, but I haven't been able to find why.

Any ideas?

I'm using this code:
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 = 1;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$day_names = array('Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');                                      #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));
$month_nam = array();
$month_nam[01] = 'Enero';
$month_nam[02] = 'Febrero';
$month_nam[03] = 'Marzo';
$month_nam[04] = 'Abril';
$month_nam[05] = 'Mayo';
$month_nam[06] = 'Junio';
$month_nam[07] = 'Julio';
$month_nam[08] = 'Agosto';
$month_nam[09] = 'Septiembre';
$month_nam[10] = 'Octubre';
$month_nam[11] = 'Noviembre';
$month_nam[12] = 'Diciembre';
$month_name = $month_nam[$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'] . ';">Cumpleaños</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("j M",$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'] . ';">Eventos</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'] . ';">Vacaciones</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>';