Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/Calendar/Calendar.php - 575 lines - 27297 bytes - Summary - Text - Print

Description: Calendar allows the user to display their calendars (in ICS format) in PHPiCalendar. It can also display an RSS feed from the calendar using the RSS viewer.

   1  <?php
   2  /**
   3  * Calendar allows the user to display their calendars (in ICS format) in
   4   * PHPiCalendar. It can also display an RSS feed from the
   5   * calendar using the RSS viewer.
   6   *
   7   * @author    benj, duncan, jasonay, davidig
   8   */
   9  
  10  require_once (T_CODE_BASE . 'Config.php');
  11  if( !defined('T_WEB_CAL'        ) ) define('T_WEB_CAL',         T_WEB_INC   . '/cal/');
  12  if( !defined('T_WEB_CAL_DATA'   ) ) define('T_WEB_CAL_DATA',    T_DATA_BASE . 'cal/');
  13  require_once(T_APP_BASE     . 'RSS/RSSReader.php');
  14  require_once(T_CODE_BASE    . 'FileManager/FileManagerClass.php');
  15  
  16  class Calendar extends App
  17  {      
  18      function onInit()
  19      {
  20          // default values
  21          if( !isset($this->httpVars['RSSView'] ) && !isset($this->params['RSSView']) )
  22              $this->params['RSSView'] = 'week';
  23          
  24          // make sure checkboxes get unset if necessary
  25          if ( isset($this->params['update']) )
  26          {
  27              if ( !isset($this->httpVars['Day']) )
  28                  $this->params['Day'] = '';
  29              if ( !isset($this->httpVars['Week']) )
  30                  $this->params['Week'] = '';
  31              if ( !isset($this->httpVars['Month']) )
  32                  $this->params['Month'] = '';
  33              if ( !isset($this->httpVars['Year']) )
  34                  $this->params['Year'] = '';
  35              if ( !isset($this->httpVars['RSS']) )
  36                  $this->params['RSS'] = '';
  37              if ( !isset($this->httpVars['OnlyRSS']) )
  38                  $this->params['OnlyRSS'] = '';
  39              if ( !isset($this->httpVars['numLinksUnlimited']) )
  40                  $this->params['numLinksUnlimited'] = '';
  41              if ( !isset($this->httpVars['descLengthUnlimited']) )
  42                  $this->params['descLengthUnlimited'] = '';
  43              if ( !isset($this->httpVars['Rolling']) )
  44                  $this->params['Rolling'] = '';
  45              if ( !isset($this->httpVars['adjustDST']) )
  46                  $this->params['adjustDST'] = '';
  47          }
  48          
  49          // for backwards compatibility
  50          if ((!isset($this->params['cpath']) && isset($this->params['filedn'])) ) {
  51              $this->httpVars['numCals'] = 1;
  52              $this->httpVars['title_id_0'] = $this->params['title'];
  53              $this->httpVars['location_id_0'] = $this->params['filedn'];
  54              $this->onSave();
  55          }
  56      }
  57  
  58      /**
  59      * lets the web master edit the display options for a calendar
  60       */        
  61      function getConfig()
  62      {
  63          /*// make sure that ~/My Documents/ICS/ exists.
  64          $dirdn = "mnOD=ICS,mnOD=My Documents,".T_ORG_DN;
  65          if(!$this->ldap->dnExists($dirdn))
  66              oDirectory::create($this->ldap, $dirdn);
  67          
  68          // redirect to FileManager if mode is fileICSExplorer
  69          if( $this->params['mode'] == 'fileICSExplorer' )
  70          {
  71              $this->fmVars['defaultDirectory'] = C_LDAP_ICS_FOLDER .','. T_ORG_DN;
  72              $this->fmVars['foldercheckbox'] = 'none';
  73              $this->fmVars['filecheckbox'] = 'radio';
  74              $this->fmVars['appVars']['mode'] = $this->params['mode'];
  75              $submit = isset($this->httpVars['submit']) ? $this->httpVars['submit'] : '';
  76              $nextDN = FileManager::parseSubmit($submit, 'Calendar');
  77              
  78              if ($submit == "Select")
  79              {
  80                  $filedn = isset($this->httpVars['fileDN']) ? $this->httpVars['fileDN'] : '';
  81                  print $filedn;
  82                  if ($filedn == '')
  83                      return FileManager::getHtml($nextDN, 'Calendar', 'Warning: file has no dn.');
  84                  print "saving $filedn in savesettings.\n";
  85                  $this->settingsVars['filedn'] = $filedn;
  86                  $this->saveSettings($this->settingsVars);    
  87                  $s = "Selected. This Window Will Close.<br><script type=\"text/javascript\">window.onload = function() { if(confirmLeave()) { destroyAndRefresh(); } } </script>";
  88                  return $s;
  89              }
  90              return FileManager::getHtml($nextDN,'Calendar');
  91          }*/
  92          
  93          // set up configuration template.
  94          $tpl = new Template_PHPLIB($this->appBase);
  95          $tpl->setfile('main', 'CalendarAdmin.tpl.html');
  96          // initialize the calendar paths.
  97          $localCals  = isset($this->settingsVars['localCals'])   ? $this->settingsVars['localCals']  : array();
  98          $remoteCals = isset($this->settingsVars['remoteCals'])  ? $this->settingsVars['remoteCals'] : array();
  99          
 100          $global_prefix = $this->paramName('');
 101          $tpl->setVar('global_prefix',   $global_prefix);
 102          $tpl->setVar('orgDN', T_ORG_DN);
 103          
 104          // option-page menu
 105          $pages = array('Calendars', 'Views', 'Advanced');
 106          foreach(array_keys($pages) as $i) {
 107              $nav_click[$i] = "selectorHideShowPages($i, 'p', " . count($pages) . ", 'menu');";
 108              $nav_attrs[$i] = array('id' => 'menu' . $i);
 109          }
 110          $tpl->setVar('menu', Widget::getWizardMenu($pages, 0, 0, $nav_click, $nav_attrs));
 111          
 112          // start the form
 113          $f = FormWidget::init(); 
 114          $f->id = $global_prefix . 'calendarFormID';
 115          $f->name('menu0');              
 116          
 117          // page 1. Calendar Selection
 118          $f->section('p0', 'Calendar Selection');
 119          $f->field('Calendars');
 120          
 121          $f->hidden('numCals', count($localCals) + count($remoteCals), array('id' => $global_prefix . 'numCals_id'));
 122  
 123          // set the calendar data.
 124          $index = 0;
 125          $calIds = array();
 126          $calTypes = array();
 127          $calLocations = array();
 128          
 129          $remoteType = 'remote';
 130          $localType = 'local';
 131          
 132          $i = 0;
 133          foreach( $localCals as $title => $location )
 134          {
 135              $f->hidden('title_id_' . $i, $title, array('id' => $this->paramName('title_id_') . $i));
 136              $f->hidden('type_id_' . $i, $localType, array('id' => $this->paramName('type_id_') . $i));
 137              $f->hidden('location_id_' . $i, $location, array('id' => $this->paramName('location_id_') . $i));
 138              $i++;
 139          }                       
 140  
 141          //$i = 0;
 142          foreach( $remoteCals as $title => $location )
 143          {
 144              $f->hidden('title_id_' . $i, $title, array('id' => $this->paramName('title_id_') . $i));
 145              $f->hidden('type_id_' . $i, $remoteType, array('id' => $this->paramName('type_id_') . $i));
 146              $f->hidden('location_id_' . $i, $location, array('id' => $this->paramName('location_id_') . $i));           
 147              $i++;
 148          }
 149          
 150          //added X to prevent from hiding
 151          $f->html('
 152         <div id="'. $global_prefix .'selectCalsDivX" style="float:left;" >
 153           <select name="' .$this->paramName('selectCals') . '" id="'. $global_prefix .'selectCals" onChange="onSelectCal(this.value)" size="10">
 154             <optgroup label="Local Calendars" id="'. $global_prefix .'localGroup">
 155             </optgroup>
 156             <optgroup label="Remote Calendars" id="'. $global_prefix .'remoteGroup">
 157             </optgroup>
 158           </select>
 159         </div>
 160          ');
 161          $f->html('<div style="float:left;">');
 162          $f->button('',  'Add Local Calendar', "newLocalCal()");
 163          $f->html('</div><br><br><br><div style="float:left;">');
 164          $f->button('',  'Add Remote Calendar', "newRemoteCal()");
 165          $f->html('</div><br><br><br><div style="float:left;">');
 166          $f->button('',  'Remove Calendar', "deleteCal()", array('id' => ''. $global_prefix .'deleteCalButton"'));
 167          $f->html('</div>');
 168          $f->field('');
 169          $f->html('<div id="'. $global_prefix .'instructionsDiv"  >
 170                   Use the buttons to add calendars.
 171                   </div> ');
 172          
 173          $f->field('Title');
 174          $f->text('title_', '', '', array('onChange' => 'onTitle()', 'id' => $this->paramName('title_') ) );
 175          
 176          $f->field('Source Location');
 177          $f->html('<div style="display:none;" id="' . $this->paramName('edit_file_location'). '">');
 178          $f->html("<br />Enter the URL for a remote calendar file in iCal (.ics) format:<br />");
 179          $f->text('location_', '', '',  array('onChange'=> "onLocation(); ", 'id' => $this->paramName('location_') ) );
 180          $f->html("</div><div style='display:none;' id=" . $this->paramName('edit_ics_location')." >");
 181          $f->html("<br />Select a calendar file in iCal (.ics) format:<br />");
 182          $f->filePicker('fileDN', '', 'mnOD=ICS,mnOD=My Documents,' . T_ORG_DN, 'ics', '', 1,  '', 0, 
 183              " self.opener.pickFile(); " );
 184          $f->html("</div>");
 185          
 186          // page 2. View Settings
 187          $f->section('p1', 'View Settings', 0);
 188  
 189          $f->field('View as');
 190          $f->checkbox( 'Day', $this->settingsVars['Day'], 'day', array($this->params[ 'Day' ] ? 'checked' : '') );
 191          $f->html('<br>');
 192          $f->checkbox( 'Week', $this->settingsVars['Week'], 'week', array($this->params[ 'Week' ] ? 'checked' : '') );
 193          $f->html('<br>');
 194          $f->checkbox( 'Month', $this->settingsVars['Month'], 'month', array($this->params[ 'Month'] ? 'checked' : '') );
 195          $f->html('<br>');
 196          $f->checkbox( 'Year', $this->settingsVars['Year'], 'year', array($this->params[ 'Year' ] ? 'checked' : '' ) );
 197  
 198  
 199          $f->field('Display a RSS Stream');
 200          $f->checkbox( 'RSS', $this->settingsVars['RSS'] ,'', array( $this->params[ 'RSS'        ] ? 'checked' : ''));
 201          $f->field('Display Only RSS Stream');
 202          $f->checkbox( 'OnlyRSS', $this->settingsVars['OnlyRSS'], '', array( $this->params[ 'OnlyRSS'    ] ? 'checked' : '')  );
 203          $f->field('Rolling');
 204          $f->checkbox( 'Rolling', $this->settingsVars['Rolling'], '', array( $this->params[ 'Rolling'    ] ? 'checked' : ''));
 205          
 206          $f->field('');
 207          $opt = array('day' => 'day', 'week' => 'week', 'month' => 'month');
 208          $f->radio( 'RSSView', $opt, $this->settingsVars['RSSView'] );
 209          
 210          $f->field('Maximum Number of Links:');
 211          $f->text( 'numLinks', $this->settingsVars['numLinks'], 2 );
 212          $f->html('links');
 213          $f->checkbox( 'numLinksUnlimited', $this->settingsVars['numLinksUnlimited'], 'No Limit', array( $this->params[ 'numLinksUnlimited'] ? 'checked' : '') );
 214          
 215          $f->field('Maximum Description Length:');
 216          $f->text( 'descLength',  $this->settingsVars['descLength'], 2 );
 217          $f->html('words');
 218          $f->checkbox('descLengthUnlimited', $this->settingsVars['descLengthUnlimited'], 'No Limit', array($this->params[ 'descLengthUnlimited'] ? 'checked' : ''  ) );
 219  
 220          // page 3. Advanced settings
 221          $f->section('p2', 'Advanced Settings', 0);
 222          
 223          $times = array();
 224          if( $handle = fopen (T_APP_BASE . 'Calendar/TIMEZONES', 'r') )
 225              while (!feof ($handle))
 226                  array_push( $times, rtrim(fgets($handle, 4096)) );
 227          else
 228              return "<font color='red'>Invalid file handle TIMEZONES. This should NEVER happen.</font>";
 229          fclose($handle);
 230          
 231          $calTimes = array();
 232          foreach($times as $i => $time)
 233              $calTimes[$time] = $time;      
 234          
 235          $f->field('My Time Zone');
 236          $f->select( 'timeZone', $calTimes, $this->settingsVars['timeZone'], '', 5);
 237  
 238          $f->field('');
 239          $f->checkbox( 'adjustDST', $this->settingsVars['adjustDST'], 'Automatically adjust for DST', array( $this->params['adjustDST'] ? 'checked' : '' ) );
 240          
 241          $f->endSection();
 242  
 243          // misc form stuff        
 244          $f->html('<div style="float:right;margin-top:20px;">');
 245          $f->defaultButtons();
 246          $f->html('</div>');
 247                  
 248          $tpl->setVar( 'pages', $f->get() );
 249          
 250          // names of the form elements
 251          $tpl->setVar( 'linkToSelf', $this->linkToSelf() );
 252          $elements = array( 'Day', 'Week', 'Month', 'Year', 'RSS', 'RSSView',
 253                             'OnlyRSS', 'timeZone', 'numLinks', 'numLinksUnlimited',
 254                             'descLength', 'descLengthUnlimited', 'Rolling', 'adjustDST' );
 255          
 256          foreach( $elements as $element )
 257              $tpl->setVar( $element, $this->paramName( $element ) );
 258          
 259          // set numCals to the current number of calendars.
 260          $tpl->setVar('numCals_id',  $this->paramName('numCals_id'));
 261          $times = array();
 262          if( $handle = fopen (T_APP_BASE . 'Calendar/TIMEZONES', 'r') )
 263              while (!feof ($handle)) 
 264                  array_push( $times, rtrim(fgets($handle, 4096)) );
 265          else
 266              return "<font color='red'>Invalid file handle TIMEZONES. This should NEVER happen.</font>";
 267          fclose ($handle);        
 268          $tpl->setBlock('main', 'timeBlock', 'times');
 269          $tpl->setVar('times', '');
 270          
 271          foreach( $times as $time )
 272          {
 273              if( isset($this->params['timeZone']) && $this->params['timeZone'] != '' )
 274                  $tpl->setVar('selected', ( $time == $this->params['timeZone'] ) ? 'selected' : 'false' );
 275              $tpl->setVar( 'offSet', $time );
 276              $tpl->setVar( 'value', $time );
 277              
 278              $tpl->parse('times', 'timeBlock', true);
 279          }                       
 280          $tpl->setVar('sel_adjustDST', $this->params['adjustDST'] ? 'checked' : '');
 281          
 282          if( $errors == '' )
 283              $tpl->setVar( 'preview', Calendar::getContent() );
 284          else
 285              $tpl->setVar( 'errors', $errors );
 286   
 287          return $tpl->subst('main');    
 288      }    
 289  
 290      /**
 291      * placeholder for onSave event (called when user has pressed a button named cv_submit)
 292       *
 293       * should be overloaded by inheriting app class to handle as an event
 294       *
 295       * @param    string  $submit title of the cv_submit button that was pressed
 296       */
 297      function onSave($submit)
 298      {
 299          $id_prefix = 'id_';
 300          $type_prefix = 'type_';
 301          $title_prefix = 'title_';
 302          $location_prefix = 'location_';
 303          $remoteType = 'remote';
 304          $localType = 'local';
 305          
 306          // set the calendar titles and locations from httpVars.
 307          $localCals  = array();
 308          $remoteCals = array();
 309          $calFlags   = array();
 310          
 311          $cal_data = array();
 312          
 313          $ldapDN = $this->ldapDN;
 314          //$localPath = T_CAL_LOCAL_BASE . $ldapDN;
 315          
 316          $orgDN = DN::dnToOrg($ldapDN);
 317          
 318          $basePath   = T_DOC_BASE . $orgDN;
 319          $baseDN     = C_LDAP_BASE_FOLDER . "," . $orgDN;
 320          
 321          $numCals = $this->httpVars['numCals'];
 322          for ($cal = 0; $cal < $numCals; $cal++) {
 323              $id = $id_prefix . $cal;
 324              $title = $this->httpVars[$title_prefix . $id];
 325              if (isset($title) && $title != '') {
 326                  $location = $this->httpVars[$location_prefix . $id];
 327                  if ($this->httpVars[$type_prefix . $id] == $remoteType) {
 328                      //print $title + $location . "<br>";
 329                      $remoteCals[$title] = $location;
 330                      
 331                      // check the url.
 332                      if (substr($location, 0, 7) == 'http://'
 333                          || substr($location, 0, 8) == 'https://'
 334                          || substr($location, 0, 9) == 'webcal://') {
 335                          $calFlags[$title] = true;
 336                          
 337                          $httpCal = str_replace('webcal://', 'http://', $location);
 338                          
 339                          $data = array();
 340                          $data['filenames']      = urlencode($title);
 341                          $data['cal_list']       = 'web_cals';
 342                          $data['path_list']      = $location;
 343                          $data['displaynames']   = $title;
 344                          $data['filelist']       = $location;
 345                          $data['cals']           = urlencode($location);
 346                          
 347                          $cal_data[$title] = $data;
 348                      } else {
 349                          $calFlags[$title] = false;
 350                      }
 351                  } else {
 352                      // change $location format.
 353                      $location = preg_replace('/^\//', '', $location);
 354                      $location = preg_replace('/^' . C_LDAP_BASE_FOLDER_NAME . '\//', '', $location);
 355                      
 356                      //break it down into the file and its parents.
 357                      $fileAndParents = array_reverse(explode("/", $location));
 358                      reset($fileAndParents);
 359                      list(, $value) = each($fileAndParents);
 360                      $calDN =  $value;
 361                      while (list(, $value) = each($fileAndParents))
 362                          $calDN .= ",mnOD=" . $value;
 363                      
 364                      //find the calendar DN, as well its absolute file path.
 365                      //$calDN     .= "," . $baseDN;
 366                      $calPath    = $basePath . "/" . $calDN;
 367                      $localCals[$title]  = $calDN;
 368  
 369                      if (file_exists($calPath)) {
 370                          $calFlags[$title]   = true;
 371                          $data = array();
 372                          $data['filenames']      = urlencode($location);
 373                          $data['cal_list']       = 'local_cals';
 374                          $data['path_list']      = $calPath;
 375                          $data['displaynames']   = $title;
 376                          $data['filelist']       = $calPath;
 377                          $data['cals']           = urlencode($calPath);
 378                          
 379                          $cal_data[$title] = $data;
 380                      } else {
 381                          $calFlags[$title] = false;
 382                      }
 383                  }
 384              }
 385          }
 386          
 387          if (!file_exists(T_WEB_CAL_DATA))
 388              mkdir(T_WEB_CAL_DATA);
 389          
 390          if (!file_exists(T_WEB_CAL_DATA . $ldapDN))
 391              mkdir(T_WEB_CAL_DATA . $ldapDN);
 392  
 393          // invalidate RSS cache
 394          $url = $this->getRSS_URI();
 395          $hash = md5($url . 'ISO-8859-1');
 396          $cache_file = T_CACHE . 'rss/magpie/' . $hash;
 397          @unlink($cache_file);
 398          
 399          if ($handle = fopen(T_WEB_CAL_DATA . $ldapDN . '/calendars.inc', 'w')) {
 400              fwrite($handle, "<?php\n\n");
 401              fwrite($handle, sprintf("    \$caravel_%s = array();\n",   'filenames'));
 402              fwrite($handle, sprintf("    \$caravel_%s = array();\n",   'displaynames'));
 403              fwrite($handle, sprintf("    \$caravel_%s = array();\n",   'filelist'));
 404              fwrite($handle, sprintf("    \$caravel_%s = array();\n",   'cals'));
 405              fwrite($handle, sprintf("    \$caravel_%s = array();\n",   'web_cals'));
 406              fwrite($handle, sprintf("    \$caravel_%s = array();\n",   'local_cals'));
 407              foreach ($cal_data as $title => $data) {
 408                  if ($calFlags[$title]) {
 409                      $title = addslashes($title);
 410                      fwrite($handle, sprintf("    \$caravel_%s[] = '%s';\n",     'filenames',       $title));
 411                      fwrite($handle, sprintf("    \$caravel_%s['%s'] = '%s';\n", 'displaynames',    urlencode($data['path_list']),  $title));
 412                      fwrite($handle, sprintf("    \$caravel_%s['%s'] = '%s';\n", 'filelist',        $title,                         $data['filelist']));
 413                      fwrite($handle, sprintf("    \$caravel_%s['%s'] = '%s';\n", 'cals',            $title,                         $data['cals']));
 414                      fwrite($handle, sprintf("    \$caravel_%s['%s'] = '%s';\n", $data['cal_list'], $title,                         $data['path_list']));
 415                  }
 416              }
 417              fwrite($handle, "\n?>\n");
 418              fclose($handle);
 419          }
 420          
 421          $this->settingsVars['cpath'                 ] = $ldapDN;
 422          $this->settingsVars['calFlags'              ] = $calFlags;
 423          $this->settingsVars['localCals'             ] = $localCals;
 424          $this->settingsVars['remoteCals'            ] = $remoteCals;
 425          
 426          $this->settingsVars[ 'Day'                  ] = $this->httpVars[ 'Day'                 ];
 427          $this->settingsVars[ 'Week'                 ] = $this->httpVars[ 'Week'                ];
 428          $this->settingsVars[ 'Month'                ] = $this->httpVars[ 'Month'               ];
 429          $this->settingsVars[ 'Year'                 ] = $this->httpVars[ 'Year'                ];
 430          $this->settingsVars[ 'RSS'                  ] = $this->httpVars[ 'RSS'                 ];
 431          $this->settingsVars[ 'RSSView'              ] = $this->httpVars[ 'RSSView'             ];
 432          $this->settingsVars[ 'OnlyRSS'              ] = $this->httpVars[ 'OnlyRSS'             ];
 433          $this->settingsVars[ 'timeZone'             ] = $this->httpVars[ 'timeZone'            ];
 434          $this->settingsVars[ 'numLinks'             ] = $this->httpVars[ 'numLinks'            ];
 435          $this->settingsVars[ 'numLinksUnlimited'    ] = $this->httpVars[ 'numLinksUnlimited'   ];
 436          $this->settingsVars[ 'descLength'           ] = $this->httpVars[ 'descLength'          ];
 437          $this->settingsVars[ 'descLengthUnlimited'  ] = $this->httpVars[ 'descLengthUnlimited' ];
 438          $this->settingsVars[ 'Rolling'              ] = $this->httpVars[ 'Rolling'             ];
 439          $this->settingsVars[ 'adjustDST'            ] = $this->httpVars[ 'adjustDST'           ];
 440          
 441          $this->saveSettings($this->settingsVars);
 442      }
 443  
 444      function getRSS_URI() {
 445          if( @$this->settingsVars['RSS'] ) {
 446              $call = 'http://' . T_DOMAIN . T_WEB_CAL .'rss/rss.php?cpath='. urlencode($this->settingsVars['cpath']); 
 447              $rssview = strtolower($this->settingsVars['RSSView']);
 448              if( isset($this->settingsVars['Rolling']) && $this->settingsVars['Rolling'] != '' ) {
 449                  if ($rssview == 'day')
 450                      $rssview = 'daysfrom&days=1';
 451                  else if ($rssview == 'week')
 452                      $rssview = 'daysfrom&days=7';
 453                  else if ($rssview == 'month')
 454                      $rssview = 'daysfrom&days=31';
 455              }
 456              $call .= '&rssview=' . $rssview;
 457              return $call;
 458          } else {
 459              return '';
 460          }        
 461      }
 462  
 463      /**
 464      * outputs the display for the user, using the options set by the web master    
 465       */
 466      function getContent()
 467      {
 468          $tpl = new Template_PHPLIB($this->appBase);
 469          $tpl->setfile( array('main' => 'CalendarView.tpl.html') );
 470          
 471          $tpl->setBlock('main','viewBlock','views');
 472          $tpl->setVar('views', '');
 473          $tpl->setBlock('main','titleBlock','titleB');
 474          $tpl->setVar('titleB', '');
 475          
 476          if( $this->params['timeZone'] == 'Same as Server' )
 477              $this->params['timeZone'] = $this->siteVars['timeZone'];
 478  
 479          if( isset($this->params['RSS']) && $this->params['RSS'] != '' )
 480          {
 481              $call = $this->getRSS_URI();
 482              $link = T_WEB_CAL . strtolower($this->settingsVars['RSSView']) . '.php?cpath=' . urlencode($this->settingsVars['cpath']);
 483  
 484              $numLinks = ( isset($this->params['numLinksUnlimited']) && $this->params['numLinksUnlimited'] != '' ) ? 'n' : $this->params['numLinks'];
 485              if ($numLinks === '') $numLinks = 'n';
 486              $descLength = ( isset($this->params['descLengthUnlimited']) && $this->params['descLengthUnlimited'] != '' ) ? 'unlimited' : $this->params['descLength'];            
 487  
 488              require_once(T_APP_BASE . 'RSS/magpie/rss_fetch.inc');
 489              if (!defined('MAGPIE_CACHE_DIR')) define('MAGPIE_CACHE_DIR', T_CACHE . 'rss/magpie');
 490              if (!defined('MAGPIE_FETCH_TIME_OUT')) define('MAGPIE_FETCH_TIME_OUT', '10');
 491              if (!defined('MAGPIE_CACHE_AGE')) define('MAGPIE_CACHE_AGE', '600');
 492              $rss = fetch_rss($call);
 493              if (!$rss)
 494                  $out = 'Unable to retrieve calendar.  Please inform the webmaster.';
 495              else {  
 496                  $out = '<a class="cvCalendarTitle" href="' . $link .'">' . implode(', ', array_keys($this->params['calFlags'])) . '</a>';
 497                  $out .= '<table style="width:100%;">';
 498                  $i = 1;
 499                  $count = 0;
 500                  $day = '';
 501                  foreach($rss->items as $item) {
 502                      $title = preg_replace('/^.+?:\s+/', '', $item['title']);
 503                      $description = isset($item['description']) ? $item['description'] : (isset($item['atom_content']) ? $item['atom_content'] : '');
 504                      preg_match('/^(.+)(AM|PM|All day event):\s*(.*)$/', $description, $t);
 505                      $all_day = ($t[2] == 'All day event');
 506                      $timestamp = strtotime($all_day ? $t[1] : $t[1] . $t[2]);
 507                      $description = $t[3];
 508                      $old_day = $day;
 509                      $day = date('M. j', $timestamp);
 510                      if ($old_day != $day && $old_day != '') {
 511                          $out = str_replace('CV_COUNT', $count, $out);
 512                          $count = 1;
 513                          $i = ($i == 1) ? 2 : 1;
 514                      } else {
 515                          $count++;
 516                      }
 517                      $date = ($day == $old_day) ? '' : date('l', $timestamp) . '<br /><b>' . date('M. j', $timestamp) . '</b>';
 518                      $time = $all_day ? '' : date('g:i a: ', $timestamp);
 519                      $out .= '<tr class="table' . $i . '">';
 520                      if ($old_day != $day)
 521                          $out .= '<td class="cvCalendarDate" rowspan="CV_COUNT">' . $date . '</td>';
 522                      $out .= '<td class="cvCalendarEvent">' . $time . '<div class="cvCalendarEventTitle">' . $title . '</div>';
 523                      $out .= $description . '</td></tr>';
 524                  }
 525                  $out = str_replace('CV_COUNT', $count, $out);
 526              }
 527              
 528              $tpl->setVar('RSS', $out);
 529  //            $tpl->setVar( 'RSS', RSSReader::view($call, $numLinks, $descLength, 'table', $this->params[ 'title' ], $link, 0 ) );
 530          }
 531          else
 532          {
 533              $tpl->setVar( 'title',  $this->params[ 'title'  ] );
 534              $tpl->parse( 'titleB', 'titleBlock' );
 535          }
 536    //      if( isset($this->params['OnlyRSS']) && $this->params['OnlyRSS'] != '' )
 537      //        return $tpl->subst('main');
 538  
 539          $views = array();
 540          $this->params['Day'] ? array_push($views, 'Day') : false;
 541          $this->params['Week'] ? array_push($views, 'Week') : false;
 542          $this->params['Month'] ? array_push($views, 'Month') : false;
 543          $this->params['Year'] ? array_push($views, 'Year') : false;
 544  
 545  //        $filedn = isset($this->params['filedn']) ? $this->params['filedn'] : '';
 546    //      if ($filedn == '')
 547      //    return 'No calendar has been selected to be displayed.';
 548  
 549          foreach( $views as $view )
 550          {
 551              $popupLink = T_BASE_LINK . T_WEB_CAL . strtolower($view) . '.php?cpath=' . urlencode($this->params['cpath']);
 552              $onClick = "popup('$popupLink', 'Explore', 820, 700); return false;";
 553  
 554              $tpl->setVar('viewViewL', strtolower($view));
 555              $tpl->setVar('viewViewU', $view);
 556              $tpl->setVar('viewIMG', T_WEB_IMG);
 557              $tpl->setVar('onClick', $onClick);
 558              $tpl->parse('views', 'viewBlock', true);
 559          }
 560  
 561          return $tpl->subst('main');
 562      }
 563  
 564      function getFMIcons() { return ''; }
 565      function getFMHeader() { return ''; }
 566      function getFMFooter()
 567      {
 568          $tpl = new Template_PHPLIB($this->appBase);
 569          $tpl->setFile(array('main' => 'fileICSExplorer.tpl.html'));
 570          $tpl->setVar('submit', $this->paramName('submit'));
 571          return $tpl->subst('main');        
 572      }
 573  
 574  } // end Calendar class
 575  ?>

title

Description

title

Description

title

Description

title

title

Body