[ Index ]

krapohl.info

title

Body

[close]

/ -> pnuserapi.php (source)

   1  <?php
   2  @define('__POSTCALENDAR__','PostCalendar');
   3  /**
   4   *  $Id: pnuserapi.php,v 1.2 2004/02/11 19:18:19 larsneo Exp $
   5   *
   6   *  PostCalendar::PostNuke Events Calendar Module
   7   *  Copyright (C) 2002  The PostCalendar Team
   8   *  http://postcalendar.tv
   9   *  
  10   *  This program is free software; you can redistribute it and/or modify
  11   *  it under the terms of the GNU General Public License as published by
  12   *  the Free Software Foundation; either version 2 of the License, or
  13   *  (at your option) any later version.
  14   *  
  15   *  This program is distributed in the hope that it will be useful,
  16   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18   *  GNU General Public License for more details.
  19   *  
  20   *  You should have received a copy of the GNU General Public License
  21   *  along with this program; if not, write to the Free Software
  22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23   *
  24   *  To read the license please read the docs/license.txt or visit
  25   *  http://www.gnu.org/copyleft/gpl.html
  26   *
  27   */
  28  
  29  //=========================================================================
  30  //  Require utility classes
  31  //=========================================================================
  32  $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
  33  $pcDir = pnVarPrepForOS($pcModInfo['directory']);
  34  require_once("modules/$pcDir/common.api.php");
  35  unset($pcModInfo,$pcDir);
  36  
  37  function postcalendar_userapi_getLongDayName($args) 
  38  {
  39      extract($args); unset($args);
  40      if(!isset($Date)) { return false; }
  41      $pc_long_day = array(_CALLONGFIRSTDAY,
  42                           _CALLONGSECONDDAY,
  43                           _CALLONGTHIRDDAY,
  44                           _CALLONGFOURTHDAY,
  45                           _CALLONGFIFTHDAY,
  46                           _CALLONGSIXTHDAY,
  47                           _CALLONGSEVENTHDAY);
  48      return $pc_long_day[Date("w",$Date)];
  49  }
  50  
  51  /**
  52   *  postcalendar_userapi_buildView
  53   *
  54   *  Builds the month display
  55   *  @param string $Date mm/dd/yyyy format (we should use timestamps)
  56   *  @return string generated html output 
  57   *  @access public
  58   */
  59  function postcalendar_userapi_buildView($args)
  60  {   
  61      $print = pnVarCleanFromInput('print');
  62      extract($args); unset($args);
  63      //=================================================================
  64      //  get the module's information
  65      //=================================================================
  66      $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__));
  67      $pcDir = $modinfo['directory'];
  68      unset($modinfo);
  69      //=================================================================
  70      //  grab the for post variable
  71      //=================================================================
  72      $pc_username = pnVarCleanFromInput('pc_username');
  73      $category = pnVarCleanFromInput('pc_category');
  74      $topic    = pnVarCleanFromInput('pc_topic');
  75      //=================================================================
  76      //  set the correct date
  77      //=================================================================
  78      $Date =& postcalendar_getDate();
  79      //=================================================================
  80      //  get the current view
  81      //=================================================================
  82      if(!isset($viewtype)) { $viewtype = 'month'; }
  83      //=================================================================
  84      //  Find out what Template we're using
  85      //=================================================================
  86      $template_name = _SETTING_TEMPLATE;
  87      if(!isset($template_name)) { $template_name = 'default'; }
  88      //=================================================================
  89      //  Find out what Template View to use
  90      //=================================================================
  91      $template_view = pnVarCleanFromInput('tplview');
  92      if(!isset($template_view)) { $template_view = 'default'; }
  93      //=================================================================
  94      //  See if the template view exists
  95      //=================================================================
  96      if(!file_exists("modules/$pcDir/pntemplates/$template_name/views/$viewtype/$template_view.html")) {
  97          $template_view_load = 'default';
  98      } else {
  99          $template_view_load = pnVarPrepForOS($template_view);
 100      }
 101      //=================================================================
 102      //  Grab the current theme information
 103      //=================================================================
 104      pnThemeLoad(pnUserGetTheme());
 105      global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6, $textcolor1, $textcolor2;
 106      //=================================================================
 107      //  Insert necessary JavaScript into the page
 108      //=================================================================
 109      $output = pnModAPIFunc(__POSTCALENDAR__,'user','pageSetup');
 110      //=================================================================
 111      //  Setup Smarty Template Engine
 112      //=================================================================
 113      $tpl =& new pcSmarty();
 114      if(!$tpl->is_cached("$template_name/views/$viewtype/$template_view_load.html",$cacheid)) {
 115          //=================================================================
 116          //  Let's just finish setting things up
 117          //=================================================================
 118          $the_year   = substr($Date,0,4);
 119          $the_month  = substr($Date,4,2);
 120          $the_day    = substr($Date,6,2);
 121          $last_day = Date_Calc::daysInMonth($the_month,$the_year);
 122          //=================================================================
 123          //  populate the template object with information for
 124          //  Month Names, Long Day Names and Short Day Names
 125          //  as translated in the language files
 126          //  (may be adding more here soon - based on need)
 127          //=================================================================
 128          $pc_month_names = array(_CALJAN,_CALFEB,_CALMAR,_CALAPR,_CALMAY,_CALJUN,
 129                                  _CALJUL,_CALAUG,_CALSEP,_CALOCT,_CALNOV,_CALDEC);
 130  
 131          $pc_short_day_names = array(_CALSUNDAYSHORT, _CALMONDAYSHORT, 
 132                                      _CALTUESDAYSHORT, _CALWEDNESDAYSHORT,
 133                                      _CALTHURSDAYSHORT, _CALFRIDAYSHORT, 
 134                                      _CALSATURDAYSHORT);
 135  
 136          $pc_long_day_names = array(_CALSUNDAY, _CALMONDAY, 
 137                                     _CALTUESDAY, _CALWEDNESDAY,
 138                                     _CALTHURSDAY, _CALFRIDAY, 
 139                                     _CALSATURDAY);
 140          //=================================================================
 141          //  here we need to set up some information for later
 142          //  variable creation.  This helps us establish the correct
 143          //  date ranges for each view.  There may be a better way
 144          //  to handle all this, but my brain hurts, so your comments
 145          //  are very appreciated and welcomed.
 146          //=================================================================
 147          switch (_SETTING_FIRST_DAY_WEEK) 
 148          {
 149              case _IS_MONDAY:
 150                  $pc_array_pos = 1;
 151                  $first_day  = date('w',mktime(0,0,0,$the_month,0,$the_year));
 152                  $week_day   = date('w',mktime(0,0,0,$the_month,$the_day-1,$the_year));
 153                  $end_dow    = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
 154                  if($end_dow != 0) {
 155                      $the_last_day = $last_day+(7-$end_dow);
 156                  } else {
 157                      $the_last_day = $last_day;
 158                  }
 159                  break;
 160              case _IS_SATURDAY:
 161                  $pc_array_pos = 6;
 162                  $first_day  = date('w',mktime(0,0,0,$the_month,2,$the_year));
 163                  $week_day   = date('w',mktime(0,0,0,$the_month,$the_day+1,$the_year));
 164                  $end_dow    = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
 165                  if($end_dow == 6) {
 166                      $the_last_day = $last_day+6;
 167                  } elseif($end_dow != 5) {
 168                      $the_last_day = $last_day+(5-$end_dow);
 169                  } else {
 170                      $the_last_day = $last_day;
 171                  }
 172                  break;
 173              case _IS_SUNDAY:
 174              default:
 175                  $pc_array_pos = 0;
 176                  $first_day  = date('w',mktime(0,0,0,$the_month,1,$the_year));
 177                  $week_day   = date('w',mktime(0,0,0,$the_month,$the_day,$the_year));
 178                  $end_dow    = date('w',mktime(0,0,0,$the_month,$last_day,$the_year));
 179                  if($end_dow != 6) {
 180                      $the_last_day = $last_day+(6-$end_dow);
 181                  } else {
 182                      $the_last_day = $last_day;
 183                  }
 184                  break;
 185          }
 186          //=================================================================
 187          //  Week View is a bit of a pain in the ass, so we need to
 188          //  do some extra setup for that view.  This section will
 189          //  find the correct starting and ending dates for a given
 190          //  seven day period, based on the day of the week the
 191          //  calendar is setup to run under (Sunday, Saturday, Monday)
 192          //=================================================================
 193          $first_day_of_week = sprintf('%02d',$the_day-$week_day);
 194          $week_first_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week,$the_year));
 195          list($week_first_day_month, $week_first_day_date, $week_first_day_year) = explode('/',$week_first_day);
 196          $week_first_day_month_name  = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname',
 197                                                    array('Date'=>mktime(0,0,0,$week_first_day_month,$week_first_day_date,$week_first_day_year)));
 198          $week_last_day = date('m/d/Y',mktime(0,0,0,$the_month,$first_day_of_week+6,$the_year));
 199          list($week_last_day_month, $week_last_day_date, $week_last_day_year) = explode('/',$week_last_day);
 200          $week_last_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname',
 201                                                   array('Date'=>mktime(0,0,0,$week_last_day_month,$week_last_day_date,$week_last_day_year)));
 202  
 203          //=================================================================
 204          //  Setup some information so we know the actual month's dates
 205          //  also get today's date for later use and highlighting  
 206          //=================================================================
 207          $month_view_start = date('Y-m-d',mktime(0,0,0,$the_month,1,$the_year));
 208          $month_view_end   = date('Y-m-t',mktime(0,0,0,$the_month,1,$the_year));
 209          $today_date = postcalendar_today('%Y-%m-%d');
 210          //=================================================================
 211          //  Setup the starting and ending date ranges for pcGetEvents()
 212          //=================================================================
 213          switch($viewtype) {
 214              case 'day' :
 215                  $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
 216                  $ending_date   = date('m/d/Y',mktime(0,0,0,$the_month,$the_day,$the_year));
 217                  break;
 218              case 'week' :
 219                  $starting_date = "$week_first_day_month/$week_first_day_date/$week_first_day_year";
 220                  $ending_date   = "$week_last_day_month/$week_last_day_date/$week_last_day_year";
 221                  $calendarView  = Date_Calc::getCalendarWeek($week_first_day_date,
 222                                                              $week_first_day_month,
 223                                                              $week_first_day_year,
 224                                                              '%Y-%m-%d');
 225                  break;
 226              case 'month' :
 227                  $starting_date = date('m/d/Y',mktime(0,0,0,$the_month,1-$first_day,$the_year));
 228                  $ending_date   = date('m/d/Y',mktime(0,0,0,$the_month,$the_last_day,$the_year));
 229                  $calendarView  = Date_Calc::getCalendarMonth($the_month, $the_year, '%Y-%m-%d');
 230                  break;
 231              case 'year' :
 232                  $starting_date = date('m/d/Y',mktime(0,0,0,1,1,$the_year));
 233                  $ending_date   = date('m/d/Y',mktime(0,0,0,1,1,$the_year+1));
 234                  $calendarView  = Date_Calc::getCalendarYear($the_year, '%Y-%m-%d');
 235                  break;
 236          }
 237          //=================================================================
 238          //  Load the events
 239          //=================================================================
 240          if($viewtype != 'year') {
 241              $eventsByDate =& postcalendar_userapi_pcGetEvents(array('start'=>$starting_date,'end'=>$ending_date));
 242          } else {
 243              $eventsByDate = array();
 244          }
 245          //=================================================================
 246          //  Create and array with the day names in the correct order
 247          //=================================================================
 248          $daynames = array();
 249          $numDays = count($pc_long_day_names);
 250          for($i=0; $i < $numDays; $i++)
 251          {   if($pc_array_pos >= $numDays) {
 252                  $pc_array_pos = 0;
 253              }
 254              array_push($daynames,$pc_long_day_names[$pc_array_pos]);
 255              $pc_array_pos++;
 256          }
 257          unset($numDays);
 258          $sdaynames = array();
 259          $numDays = count($pc_short_day_names);
 260          for($i=0; $i < $numDays; $i++)
 261          {   if($pc_array_pos >= $numDays) {
 262                  $pc_array_pos = 0;
 263              }
 264              array_push($sdaynames,$pc_short_day_names[$pc_array_pos]);
 265              $pc_array_pos++;
 266          }
 267          unset($numDays);
 268          //=================================================================
 269          //  Prepare some values for the template
 270          //=================================================================
 271          $prev_month = Date_Calc::beginOfPrevMonth(1,$the_month,$the_year,'%Y%m%d');
 272          $next_month = Date_Calc::beginOfNextMonth(1,$the_month,$the_year,'%Y%m%d');
 273  
 274          $pc_prev = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view',
 275                              array('tplview'=>$template_view,
 276                                    'viewtype'=>'month',
 277                                    'Date'=>$prev_month,
 278                                    'pc_username'=>$pc_username,
 279                                    'pc_category'=>$category,
 280                                    'pc_topic'=>$topic)));
 281  
 282          $pc_next = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view',
 283                              array('tplview'=>$template_view,
 284                                    'viewtype'=>'month',
 285                                    'Date'=>$next_month,
 286                                    'pc_username'=>$pc_username,
 287                                    'pc_category'=>$category,
 288                                    'pc_topic'=>$topic)));
 289  
 290          $prev_day = Date_Calc::prevDay($the_day,$the_month,$the_year,'%Y%m%d');
 291          $next_day = Date_Calc::nextDay($the_day,$the_month,$the_year,'%Y%m%d');
 292          $pc_prev_day = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view',
 293                                   array('tplview'=>$template_view,
 294                                         'viewtype'=>'day',
 295                                         'Date'=>$prev_day,
 296                                         'pc_username'=>$pc_username,
 297                                           'pc_category'=>$category,
 298                                           'pc_topic'=>$topic)));
 299  
 300          $pc_next_day = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view',
 301                                  array('tplview'=>$template_view,
 302                                        'viewtype'=>'day',
 303                                        'Date'=>$next_day,
 304                                        'pc_username'=>$pc_username,
 305                                          'pc_category'=>$category,
 306                                          'pc_topic'=>$topic)));
 307  
 308          $prev_week = date('Ymd',mktime(0,0,0,$week_first_day_month,$week_first_day_date-7,$week_first_day_year));
 309          $next_week = date('Ymd',mktime(0,0,0,$week_last_day_month,$week_last_day_date+1,$week_last_day_year));
 310          $pc_prev_week = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view',
 311                                   array('viewtype'=>'week',
 312                                         'Date'=>$prev_week,
 313                                         'pc_username'=>$pc_username,
 314                                           'pc_category'=>$category,
 315                                           'pc_topic'=>$topic)));
 316          $pc_next_week = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view', 
 317                                   array('viewtype'=>'week',
 318                                         'Date'=>$next_week,
 319                                         'pc_username'=>$pc_username,
 320                                           'pc_category'=>$category,
 321                                           'pc_topic'=>$topic)));
 322          
 323          $prev_year = date('Ymd',mktime(0,0,0,1,1,$the_year-1));
 324          $next_year = date('Ymd',mktime(0,0,0,1,1,$the_year+1));
 325          $pc_prev_year = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view',
 326                                   array('viewtype'=>'year',
 327                                         'Date'=>$prev_year,
 328                                         'pc_username'=>$pc_username,
 329                                           'pc_category'=>$category,
 330                                           'pc_topic'=>$topic)));
 331          $pc_next_year = pnVarPrepForDisplay(pnModURL(__POSTCALENDAR__,'user','view',
 332                                   array('viewtype'=>'year',
 333                                         'Date'=>$next_year,
 334                                         'pc_username'=>$pc_username,
 335                                           'pc_category'=>$category,
 336                                           'pc_topic'=>$topic)));
 337          
 338          //=================================================================
 339          //  Populate the template
 340          //=================================================================
 341          $all_categories = pnModAPIFunc(__POSTCALENDAR__,'user','getCategories');
 342          if(isset($calendarView)) {
 343              $tpl->assign_by_ref('CAL_FORMAT',$calendarView);
 344          }
 345          $tpl->assign_by_ref('VIEW_TYPE',$viewtype);
 346          $tpl->assign_by_ref('A_MONTH_NAMES',$pc_month_names);
 347          $tpl->assign_by_ref('A_LONG_DAY_NAMES',$pc_long_day_names);
 348          $tpl->assign_by_ref('A_SHORT_DAY_NAMES',$pc_short_day_names);
 349          $tpl->assign_by_ref('S_LONG_DAY_NAMES',$daynames);
 350          $tpl->assign_by_ref('S_SHORT_DAY_NAMES',$sdaynames);
 351          $tpl->assign_by_ref('A_EVENTS',$eventsByDate);
 352          $tpl->assign_by_ref('A_CATEGORY',$all_categories);
 353          $tpl->assign_by_ref('PREV_MONTH_URL',$pc_prev);
 354          $tpl->assign_by_ref('NEXT_MONTH_URL',$pc_next);
 355          $tpl->assign_by_ref('PREV_DAY_URL',$pc_prev_day);
 356          $tpl->assign_by_ref('NEXT_DAY_URL',$pc_next_day);
 357          $tpl->assign_by_ref('PREV_WEEK_URL',$pc_prev_week);
 358          $tpl->assign_by_ref('NEXT_WEEK_URL',$pc_next_week);
 359          $tpl->assign_by_ref('PREV_YEAR_URL',$pc_prev_year);
 360          $tpl->assign_by_ref('NEXT_YEAR_URL',$pc_next_year);
 361          $tpl->assign_by_ref('MONTH_START_DATE',$month_view_start);
 362          $tpl->assign_by_ref('MONTH_END_DATE',$month_view_end);
 363          $tpl->assign_by_ref('TODAY_DATE',$today_date);
 364          $tpl->assign_by_ref('DATE',$Date);
 365      }
 366      //=================================================================
 367      //  Parse the template
 368      //=================================================================
 369      $template = "$template_name/views/$viewtype/$template_view_load.html";
 370      if(!$print) {
 371          $output .= "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
 372          $output .= $tpl->fetch($template,$cacheid);    // cache id
 373          $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n";
 374      } else {
 375          $theme = pnUserGetTheme();
 376          echo "<html><head>";
 377          echo "<LINK REL=\"StyleSheet\" HREF=\"themes/$theme/style/styleNN.css\" TYPE=\"text/css\">\n\n\n";
 378          echo "<style type=\"text/css\">\n";
 379          echo "@import url(\"themes/$theme/style/style.css\"); ";
 380          echo "</style>\n";
 381          echo "</head><body>\n";
 382          echo $output;
 383          $tpl->display($template,$cacheid);
 384          echo postcalendar_footer();
 385          echo "\n</body></html>";
 386          session_write_close();
 387          exit;
 388      }
 389      //=================================================================
 390      //  Return the output
 391      //=================================================================
 392      retur