Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  
   3  /**
   4   *  BENNU - PHP iCalendar library
   5   *  (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
   6   *
   7   *  Released under the LGPL.
   8   *
   9   *  See http://bennu.sourceforge.net/ for more information and downloads.
  10   *
  11   * @author Ioannis Papaioannou 
  12   * @version $Id$
  13   * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  14   */
  15  
  16  class iCalendar_parameter {
  17      static function multiple_values_allowed($parameter) {
  18          switch($parameter) {
  19              case 'DELEGATED-FROM':
  20              case 'DELEGATED-TO':
  21              case 'MEMBER':
  22                  return true;
  23              default:
  24                  return false;
  25          }
  26      }
  27  
  28      static function default_value($parameter) {
  29          switch($parameter) {
  30              case 'CUTYPE':   return 'INDIVIDUAL';
  31              case 'FBTYPE':   return 'BUSY';
  32              case 'PARTSTAT': return 'NEEDS-ACTION';
  33              case 'RELATED':  return 'START';
  34              case 'RELTYPE':  return 'PARENT';
  35              case 'ROLE':     return 'REQ-PARTICIPANT';
  36              case 'RSVP':     return 'FALSE';
  37              default:         return NULL;
  38          }
  39      }
  40  
  41      static function is_valid_value(&$parent_property, $parameter, $value) {
  42          switch($parameter) {
  43              // These must all be a URI
  44              case 'ALTREP':
  45              case 'DIR':
  46                  return rfc2445_is_valid_value($value, RFC2445_TYPE_URI);
  47              break;
  48  
  49              // These must be CAL-ADDRESS, which is equivalent to URI
  50              case 'DELEGATED-FROM':
  51              case 'DELEGATED-TO':
  52              case 'MEMBER':
  53              case 'SENT-BY':
  54                  return rfc2445_is_valid_value($value, RFC2445_TYPE_CAL_ADDRESS);
  55              break;
  56  
  57              // RFC-2445: can contain quotes.
  58              case 'CN':
  59                  return true;
  60              break;
  61  
  62              // These have enumerated legal values
  63              case 'CUTYPE':
  64                  $value = strtoupper($value);
  65                  return ($value == 'INDIVIDUAL' || $value == 'GROUP' || $value == 'RESOURCE' || $value == 'ROOM' || $value == 'UNKNOWN' || rfc2445_is_xname($value));
  66              break;
  67  
  68              case 'ENCODING':
  69                  $value = strtoupper($value);
  70                  return ($value == '8BIT' || $value == 'BASE64' || rfc2445_is_xname($value));
  71              break;
  72  
  73              case 'FBTYPE':
  74                  $value = strtoupper($value);
  75                  return ($value == 'FREE' || $value == 'BUSY' || $value == 'BUSY-UNAVAILABLE' || $value == 'BUSY-TENTATIVE' || rfc2445_is_xname($value));
  76              break;
  77  
  78              case 'FMTTYPE':
  79                  $fmttypes = array(
  80                          'TEXT'        => array('PLAIN', 'RICHTEXT', 'ENRICHED', 'TAB-SEPARATED-VALUES', 'HTML', 'SGML',
  81                                                 'VND.LATEX-Z', 'VND.FMI.FLEXSTOR'),
  82                          'MULTIPART'   => array('MIXED', 'ALTERNATIVE', 'DIGEST', 'PARALLEL', 'APPLEDOUBLE', 'HEADER-SET',
  83                                                 'FORM-DATA', 'RELATED', 'REPORT', 'VOICE-MESSAGE', 'SIGNED', 'ENCRYPTED',
  84                                                 'BYTERANGES'),
  85                          'MESSAGE'     => array('RFC822', 'PARTIAL', 'EXTERNAL-BODY', 'NEWS', 'HTTP'),
  86                          'APPLICATION' => array('OCTET-STREAM', 'POSTSCRIPT', 'ODA', 'ATOMICMAIL', 'ANDREW-INSET', 'SLATE',
  87                                                 'WITA', 'DEC-DX', 'DCA-RFT', 'ACTIVEMESSAGE', 'RTF', 'APPLEFILE',
  88                                                 'MAC-BINHEX40', 'NEWS-MESSAGE-ID', 'NEWS-TRANSMISSION', 'WORDPERFECT5.1',
  89                                                 'PDF', 'ZIP', 'MACWRITEII', 'MSWORD', 'REMOTE-PRINTING', 'MATHEMATICA',
  90                                                 'CYBERCASH', 'COMMONGROUND', 'IGES', 'RISCOS', 'ESHOP', 'X400-BP', 'SGML',
  91                                                 'CALS-1840', 'PGP-ENCRYPTED', 'PGP-SIGNATURE', 'PGP-KEYS', 'VND.FRAMEMAKER',
  92                                                 'VND.MIF', 'VND.MS-EXCEL', 'VND.MS-POWERPOINT', 'VND.MS-PROJECT',
  93                                                 'VND.MS-WORKS', 'VND.MS-TNEF', 'VND.SVD', 'VND.MUSIC-NIFF', 'VND.MS-ARTGALRY',
  94                                                 'VND.TRUEDOC', 'VND.KOAN', 'VND.STREET-STREAM', 'VND.FDF',
  95                                                 'SET-PAYMENT-INITIATION', 'SET-PAYMENT', 'SET-REGISTRATION-INITIATION',
  96                                                 'SET-REGISTRATION', 'VND.SEEMAIL', 'VND.BUSINESSOBJECTS',
  97                                                 'VND.MERIDIAN-SLINGSHOT', 'VND.XARA', 'SGML-OPEN-CATALOG', 'VND.RAPID',
  98                                                 'VND.ENLIVEN', 'VND.JAPANNET-REGISTRATION-WAKEUP', 
  99                                                 'VND.JAPANNET-VERIFICATION-WAKEUP', 'VND.JAPANNET-PAYMENT-WAKEUP',
 100                                                 'VND.JAPANNET-DIRECTORY-SERVICE', 'VND.INTERTRUST.DIGIBOX', 'VND.INTERTRUST.NNCP'),
 101                          'IMAGE'       => array('JPEG', 'GIF', 'IEF', 'G3FAX', 'TIFF', 'CGM', 'NAPLPS', 'VND.DWG', 'VND.SVF',
 102                                                 'VND.DXF', 'PNG', 'VND.FPX', 'VND.NET-FPX'),
 103                          'AUDIO'       => array('BASIC', '32KADPCM', 'VND.QCELP'),
 104                          'VIDEO'       => array('MPEG', 'QUICKTIME', 'VND.VIVO', 'VND.MOTOROLA.VIDEO', 'VND.MOTOROLA.VIDEOP')
 105                  );
 106                  $value = strtoupper($value);
 107                  // Mimetype is enumerated above and anything else results in false.
 108                  @list($type, $subtype) = explode('/', $value);
 109                  if(empty($type) || empty($subtype)) {
 110                      return false;
 111                  }
 112                  if(!isset($fmttypes[$type]) || !in_array($subtype, $fmttypes[$type])) {
 113                      return false;
 114                  }
 115                  return true;
 116              break;
 117  
 118              case 'LANGUAGE':
 119                  $value = strtoupper($value);
 120                  $parts = explode('-', $value);
 121                  foreach($parts as $part) {
 122                      if(empty($part)) {
 123                          return false;
 124                      }
 125                      if(strspn($part, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') != strlen($part)) {
 126                          return false;
 127                      }
 128                  }
 129                  return true;
 130              break;
 131  
 132              case 'PARTSTAT':
 133                  $value = strtoupper($value);
 134                  switch($parent_property->parent_component) {
 135                      case 'VEVENT':
 136                          return ($value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || $value == 'TENTATIVE'
 137                                  || $value == 'DELEGATED' || rfc2445_is_xname($value));
 138                      break;
 139                      case 'VTODO':
 140                          return ($value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || $value == 'TENTATIVE'
 141                                  || $value == 'DELEGATED' || $value == 'COMPLETED' || $value == 'IN-PROCESS' || rfc2445_is_xname($value));
 142                      break;
 143                      case 'VJOURNAL':
 144                          return ($value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || rfc2445_is_xname($value));
 145                      break;
 146                  }
 147                  return false;
 148              break;
 149  
 150              case 'RANGE':
 151                  $value = strtoupper($value);
 152                  return ($value == 'THISANDPRIOR' || $value == 'THISANDFUTURE');
 153              break;
 154  
 155              case 'RELATED':
 156                  $value = strtoupper($value);
 157                  return ($value == 'START' || $value == 'END');
 158              break;
 159  
 160              case 'RELTYPE':
 161                  $value = strtoupper($value);
 162                  return ($value == 'PARENT' || $value == 'CHILD' || $value == 'SIBLING' || rfc2445_is_xname($value));
 163              break;
 164  
 165              case 'ROLE':
 166                  $value = strtoupper($value);
 167                  return ($value == 'CHAIR' || $value == 'REQ-PARTICIPANT' || $value == 'OPT-PARTICIPANT' || $value == 'NON-PARTICIPANT' || rfc2445_is_xname($value));
 168              break;
 169  
 170              case 'RSVP':
 171                  $value = strtoupper($value);
 172                  return ($value == 'TRUE' || $value == 'FALSE');
 173              break;
 174  
 175              case 'TZID':
 176                  if(empty($value)) {
 177                      return false;
 178                  }
 179                  return (strcspn($value, ';:,') == strlen($value));
 180              break;
 181  
 182              case 'VALUE':
 183                  $value = strtoupper($value);
 184                  return ($value == 'BINARY'    || $value == 'BOOLEAN'    || $value == 'CAL-ADDRESS' || $value == 'DATE'    ||
 185                          $value == 'DATE-TIME' || $value == 'DURATION'   || $value == 'FLOAT'       || $value == 'INTEGER' ||
 186                          $value == 'PERIOD'    || $value == 'RECUR'      || $value == 'TEXT'        || $value == 'TIME'    ||
 187                          $value == 'URI'       || $value == 'UTC-OFFSET' || rfc2445_is_xname($value));
 188              break;
 189          }
 190      }
 191  
 192      static function do_value_formatting($parameter, $value) {
 193          switch($parameter) {
 194              // Parameters of type CAL-ADDRESS or URI MUST be double-quoted
 195              case 'ALTREP':
 196              case 'DIR':
 197              case 'DELEGATED-FROM':
 198              case 'DELEGATED-TO':
 199              case 'MEMBER':
 200              case 'SENT-BY':
 201                  return '"'.$value.'"';
 202              break;
 203  
 204              // Textual parameter types must be double quoted if they contain COLON, SEMICOLON
 205              // or COMMA. Quoting always sounds easier and standards-conformant though.
 206              case 'CN':
 207                  return '"'.$value.'"';
 208              break;
 209  
 210              // Parameters with enumerated legal values, just make them all caps
 211              case 'CUTYPE':
 212              case 'ENCODING':
 213              case 'FBTYPE':
 214              case 'FMTTYPE':
 215              case 'LANGUAGE':
 216              case 'PARTSTAT':
 217              case 'RANGE':
 218              case 'RELATED':
 219              case 'RELTYPE':
 220              case 'ROLE':
 221              case 'RSVP':
 222              case 'VALUE':
 223                  return strtoupper($value);
 224              break;
 225  
 226              // Parameters we shouldn't be messing with
 227              case 'TZID':
 228                  return str_replace('"', '', $value);
 229              break;
 230          }
 231      }
 232  
 233      static function undo_value_formatting($parameter, $value) {
 234      }
 235  
 236  }