liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file data.calendar.php

Documentation is available at data.calendar.php

  1. <?php
  2. /**
  3.  * @version  $Revision$
  4.  * @package  liberty
  5.  * @subpackage plugins_data
  6.  */
  7. // +----------------------------------------------------------------------+
  8. // | Copyright (c) 2004, bitweaver.org
  9. // +----------------------------------------------------------------------+
  10. // | All Rights Reserved. See below for details and a complete list of authors.
  11. // | Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
  12. // |
  13. // | For comments, please use phpdocu.sourceforge.net documentation standards!!!
  14. // | -> see http://phpdocu.sourceforge.net/
  15. // +----------------------------------------------------------------------+
  16. // | Author (TikiWiki): Luis Argerich <lrargerich@users.sourceforge.net>
  17. // | Reworked for Bitweaver (& Undoubtedly Screwed-Up)
  18. // | by: StarRider <starrrider@users.sourceforge.net>
  19. // +----------------------------------------------------------------------+
  20. // $Id$
  21.  
  22. /**
  23.  * definitions
  24.  */
  25. define( 'PLUGIN_GUID_DATACALENDAR', 'datacalendar' );
  26. global $gLibertySystem;
  27. $pluginParams = array (
  28.     'tag' => 'CALENDAR',
  29.     'auto_activate' => TRUE,
  30.     'requires_pair' => FALSE,
  31.     'load_function' => 'data_calendar',
  32.     'title' => 'Calendar',
  33.     'help_page' => 'DataPluginCalendar',
  34.     'description' => tra("Displays a mini calendar that links to the calendar package."),    
  35.     'syntax' => " {CALENDAR} ",
  36.     'plugin_type' => DATA_PLUGIN
  37. );
  38. $gLibertySystem->registerPlugin( PLUGIN_GUID_DATACALENDAR, $pluginParams );
  39. $gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATACALENDAR );
  40.  
  41. function data_calendar( $data, $params ) {
  42.      global $gBitSmarty, $gBitSystem;
  43.  
  44.      if ($gBitSystem->isPackageActive('calendar')) {
  45.          $offset = $gBitSystem->get_display_offset();
  46.          $bitDate = new BitDate($offset);    
  47.          
  48.          $time = $bitDate->getUTCTime();
  49.          $date = $bitDate->getDate($time, true);
  50.          
  51.          $month = $date['mon'];
  52.          $year = $date['year'];
  53.          $month_day = $date['mday'];
  54.          $month_name = $date['month'];
  55.          
  56.          // reset time so we can make today look different in template with compare
  57.          $time = $bitDate->mktime(0, 0, 0, $month, $month_day, $year);
  58.          
  59.          $last_time = $bitDate->mktime(0, 0, 0, $month, 0, $year);
  60.          $next_time = $bitDate->mktime(0, 0, 0, $month + 1, 1, $year);
  61.          $last = $bitDate->getDate($last_time);
  62.          $next = $bitDate->getDate($next_time);
  63.          
  64.          $days = array();
  65.          for ($i = 2; $i < 9; $i++) {
  66.              // Start from known sunday.
  67.              $timestamp = $bitDate->mktime(0, 0, 0, 1, $i, 2000);
  68.              $days[] = $bitDate->strftime('%a', $timestamp);
  69.          }
  70.          
  71.          // Build a two-dimensional array of UNIX timestamps.
  72.          $calendar = array();
  73.          
  74.          // Start with last days of previous month.
  75.          $week = array();
  76.          $month_begin = $bitDate->mktime(0, 0, 0, $month, 1, $year);
  77.          $month_begin_dow = strftime('%w', $month_begin);
  78.          
  79.          $days_last_month = $bitDate->daysInMonth($last['month'], $last['year']);
  80.          for ($dow = 0;
  81.               $dow < $month_begin_dow;
  82.               $dow++) {
  83.              $day = $days_last_month - $month_begin_dow + $dow;
  84.              $d['time'] = $bitDate->mktime(0, 0, 0, $month - 1, $day, $year);
  85.              $d['dim'] = true;
  86.              $week[] = $d;
  87.          }
  88.          
  89.          // Do this month
  90.          $days_in_month = $bitDate->daysInMonth($month, $year);
  91.          for ($i = 1; $i <= $days_in_month; $i++) {
  92.              if ($dow == 7) {
  93.                  $calendar[] = $week;
  94.                  
  95.                  // Done with row
  96.                  $dow = 0;
  97.                  unset($week);
  98.                  $week = array();
  99.              }
  100.              $d['time'] = $bitDate->mktime(0, 0, 0, $month, $i, $year);
  101.              $d['dim'] = false;
  102.              // Flag today
  103.              if ($i == $month_day) {
  104.                  $d['today'] = true;
  105.              }
  106.              $week[] = $d;
  107.              unset($d['today']);
  108.              $dow++;
  109.         }
  110.          
  111.          // Do the last month.
  112.          for ($i = 1; $dow < 7; $i++, $dow++) {
  113.              $d['time'] = $bitDate->mktime(0, 0, 0, $month + 1, $i, $year);
  114.              $d['dim'] = true;
  115.              $week[] = $d;
  116.          }
  117.          $calendar[] = $week;
  118.  
  119.          $gBitSmarty->assign('minical', true);
  120.          $gBitSmarty->assign('month_name', $month_name);
  121.          $gBitSmarty->assign('month', $month);
  122.          $gBitSmarty->assign('year', $year);
  123.          $gBitSmarty->assign('last_month', $last_time);
  124.          $gBitSmarty->assign('next_month', $next_time);
  125.          $gBitSmarty->assign('dow_abbrevs', $days);
  126.          $gBitSmarty->assign('calendar', $calendar);
  127.          $gBitSmarty->assign('today', $time);
  128.  
  129.          // Assign a base url
  130.          if (empty($params['events'])) {
  131.              $pBaseUrl = CALENDAR_PKG_URL.'index.php';
  132.          }
  133.          else {
  134.              $pBaseUrl = EVENTS_PKG_URL.'calendar.php';
  135.          }
  136.          $gBitSmarty->assign('baseCalendarUrl', $pBaseUrl);
  137.  
  138.          return $gBitSmarty->fetch('bitpackage:calendar/minical.tpl');
  139.      }
  140.      
  141.      return '<div class="error">Calendar Package Not Active</div>';
  142. }
  143. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:18 +0000 by phpDocumentor 1.5.0-lsces