Back to index

awl  0.53
Public Member Functions | Protected Attributes | Static Private Member Functions
vProperty Class Reference

List of all members.

Public Member Functions

 __construct ($propstring=null)
 

@-


 ParseFrom ($propstring)
 The constructor parses the incoming string, which is formatted as per RFC2445 as a propname[;param1=pval1[; ...
 Name ($newname=null)
 Get/Set name property.
 Value ($newvalue=null)
 Get/Set the content of the property.
 Parameters ($newparams=null)
 Get/Set parameters in their entirety.
 TextMatch ($search)
 Test if our value contains a string.
 GetParameterValue ($name)
 Get the value of a parameter.
 SetParameterValue ($name, $value)
 Set the value of a parameter.
 RenderParameters ()
 Render the set of parameters as key1=value1[;key2=value2[; ...]] with any colons or semicolons escaped.
 Render ($force=false)
 Render a suitably escaped RFC2445 content string.
 __toString ()
 TestFilter ($filters)
 Test a PROP-FILTER or PARAM-FILTER and return a true/false PROP-FILTER (is-defined | is-not-defined | ((time-range | text-match)?, param-filter*)) PARAM-FILTER (is-defined | is-not-defined | ((time-range | text-match)?, param-filter*))
 TestParamFilter ($filters, $parameter_value)

Protected Attributes

 $name
 $parameters
 $content
 $rendered

Static Private Member Functions

static escapeParameter ($p)

Detailed Description

Definition at line 23 of file vComponent.php.


Constructor & Destructor Documentation

vProperty::__construct ( propstring = null)

@-

The constructor parses the incoming string, which is formatted as per RFC2445 as a propname[;param1=pval1[; ... ]]:propvalue however we allow ourselves to assume that the RFC2445 content unescaping has already happened when vComponent::ParseFrom() called vComponent::UnwrapComponent().

Parameters:
string$propstringThe string from the vComponent which contains this property.

Definition at line 66 of file vComponent.php.

                                             {
    $this->name = "";
    $this->content = "";
    $this->parameters = array();
    unset($this->rendered);
    if ( $propstring != null && gettype($propstring) == 'string' ) {
      $this->ParseFrom($propstring);
    }
  }

Here is the call graph for this function:


Member Function Documentation

Definition at line 303 of file vComponent.php.

                               {
    return $this->Render();
  }

Here is the call graph for this function:

static vProperty::escapeParameter ( p) [static, private]

Definition at line 227 of file vComponent.php.

                                              {
    if ( strpos($p, ';') === false && strpos($p, ':') === false ) return $p;
    return '"'.str_replace('"','\\"',$p).'"';    
  }

Here is the caller graph for this function:

Get the value of a parameter.

Parameters:
string$nameThe name of the parameter to retrieve the value for
Returns:
string The value of the parameter

Definition at line 207 of file vComponent.php.

                                      {
    $name = strtoupper($name);
    if ( isset($this->parameters[$name]) ) return $this->parameters[$name];
    return null;
  }

Here is the caller graph for this function:

vProperty::Name ( newname = null)

Get/Set name property.

Parameters:
string$newname[optional] A new name for the property
Returns:
string The name for the property.

Definition at line 142 of file vComponent.php.

                                   {
    if ( $newname != null ) {
      $this->name = strtoupper($newname);
      if ( isset($this->rendered) ) unset($this->rendered);
//      dbg_error_log('vComponent', " vProperty::Name(%s)", $this->name );
    }
    return $this->name;
  }
vProperty::Parameters ( newparams = null)

Get/Set parameters in their entirety.

Parameters:
array$newparamsAn array of new parameter key/value pairs. The 'value' may be an array of values.
Returns:
array The current array of parameters for the property.

Definition at line 175 of file vComponent.php.

                                           {
    if ( $newparams != null ) {
      $this->parameters = array();
      foreach( $newparams AS $k => $v ) {
        $this->parameters[strtoupper($k)] = $v;
      }
      if ( isset($this->rendered) ) unset($this->rendered);
    }
    return $this->parameters;
  }
vProperty::ParseFrom ( propstring)

The constructor parses the incoming string, which is formatted as per RFC2445 as a propname[;param1=pval1[; ...

]]:propvalue however we allow ourselves to assume that the RFC2445 content unescaping has already happened when vComponent::ParseFrom() called vComponent::UnwrapComponent().

Parameters:
string$propstringThe string from the vComponent which contains this property.

Definition at line 85 of file vComponent.php.

                                    {
    $this->rendered = (strlen($propstring) < 73 ? $propstring : null);  // Only pre-rendered if we didn't unescape it

    $unescaped = preg_replace( '{\\\\[nN]}', "\n", $propstring);

    // Split into two parts on : which is not preceded by a \, or within quotes like "str:ing".
    $offset = 0;
    do {
      $splitpos = strpos($unescaped,':',$offset);
      $start = substr($unescaped,0,$splitpos);
      if ( substr($start,-1) == '\\' ) {
        $offset = $splitpos + 1;
        continue;
      }
      $quotecount = strlen(preg_replace('{[^"]}', '', $start ));
      if ( ($quotecount % 2) != 0 ) {
        $offset = $splitpos + 1;
        continue;
      }
      break;
    }
    while( true );
    $values = substr($unescaped,$splitpos+1);
    $this->content = preg_replace( "/\\\\([,;:\"\\\\])/", '$1', $values);

    // Split on ; which is not preceded by a \
    $parameters = preg_split( '{(?<!\\\\);}', $start);

    $this->name = strtoupper(array_shift( $parameters ));
    $this->parameters = array();
    foreach( $parameters AS $k => $v ) {
      $pos = strpos($v,'=');
      $name = strtoupper(substr( $v, 0, $pos));
      $value = substr( $v, $pos + 1);
      if ( preg_match( '{^"(.*)"$}', $value, $matches) ) {
        $value = $matches[1];
      }
      if ( isset($this->parameters[$name]) && is_array($this->parameters[$name]) ) {
        $this->parameters[$name][] = $value;
      }
      elseif ( isset($this->parameters[$name]) ) {
        $this->parameters[$name] = array( $this->parameters[$name], $value);
      }
      else
        $this->parameters[$name] = $value;
    }
//    dbg_error_log('vComponent', " vProperty::ParseFrom found '%s' = '%s' with %d parameters", $this->name, substr($this->content,0,200), count($this->parameters) );
  }

Here is the caller graph for this function:

vProperty::Render ( force = false)

Render a suitably escaped RFC2445 content string.

Content escaping does not apply to these properties culled from RFC2445

Content escaping does not apply to these properties culled from RFC6350 / RFC2426

Content escaping applies by default to other properties

Definition at line 255 of file vComponent.php.

                                    {
    // If we still have the string it was parsed in from, it hasn't been screwed with
    // and we can just return that without modification.
    if ( $force === false && isset($this->rendered) ) return $this->rendered;

    $property = preg_replace( '/[;].*$/', '', $this->name );
    $escaped = $this->content;
    switch( $property ) {
      case 'ATTACH':                case 'GEO':                       case 'PERCENT-COMPLETE':      case 'PRIORITY':
      case 'DURATION':              case 'FREEBUSY':                  case 'TZOFFSETFROM':          case 'TZOFFSETTO':
      case 'TZURL':                 case 'ATTENDEE':                  case 'ORGANIZER':             case 'RECURRENCE-ID':
      case 'URL':                   case 'EXRULE':                    case 'SEQUENCE':              case 'CREATED':
      case 'RRULE':                 case 'REPEAT':                    case 'TRIGGER':               case 'RDATE':
      case 'COMPLETED':             case 'DTEND':                     case 'DUE':                   case 'DTSTART':
      case 'DTSTAMP':               case 'LAST-MODIFIED':             case 'CREATED':               case 'EXDATE':
        break;

      case 'ADR':                case 'N':
        // escaping for ';' for these fields also needs to happen to the components they are built from. 
        $escaped = str_replace( '\\', '\\\\', $escaped);
        $escaped = preg_replace( '/\r?\n/', '\\n', $escaped);
        $escaped = str_replace( ',', '\\,', $escaped);
        break;
        
      default:
        $escaped = str_replace( '\\', '\\\\', $escaped);
        $escaped = preg_replace( '/\r?\n/', '\\n', $escaped);
        $escaped = preg_replace( "/([,;])/", '\\\\$1', $escaped);
    }

    $property = sprintf( "%s%s:", $this->name, $this->RenderParameters() );
    if ( (strlen($property) + strlen($escaped)) <= 72 ) {
      $this->rendered = $property . $escaped;
    }
    else if ( (strlen($property) <= 72) && (strlen($escaped) <= 72) ) {
      $this->rendered = $property . "\r\n " . $escaped;
    }
    else {
      $this->rendered = preg_replace( '/(.{72})/u', '$1'."\r\n ", $property.$escaped );
    }
//    trace_bug( 'Re-rendered "%s" property.', $this->name );
    return $this->rendered;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Render the set of parameters as key1=value1[;key2=value2[; ...]] with any colons or semicolons escaped.

Definition at line 236 of file vComponent.php.

                              {
    $rendered = "";
    foreach( $this->parameters AS $k => $v ) {
      if ( is_array($v) ) {
        foreach( $v AS $vv ) {
          $rendered .= sprintf( ';%s=%s', $k, vProperty::escapeParameter($vv) );
        }
      }
      else {
          $rendered .= sprintf( ';%s=%s', $k, vProperty::escapeParameter($v) );
      }
    }
    return $rendered;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

vProperty::SetParameterValue ( name,
value 
)

Set the value of a parameter.

Parameters:
string$nameThe name of the parameter to set the value for
string$valueThe value of the parameter

Definition at line 220 of file vComponent.php.

                                              {
    if ( isset($this->rendered) ) unset($this->rendered);
    $this->parameters[strtoupper($name)] = $value;
//    dbg_error_log('PUT', $this->name.$this->RenderParameters().':'.$this->content );
  }
vProperty::TestFilter ( filters)

Test a PROP-FILTER or PARAM-FILTER and return a true/false PROP-FILTER (is-defined | is-not-defined | ((time-range | text-match)?, param-filter*)) PARAM-FILTER (is-defined | is-not-defined | ((time-range | text-match)?, param-filter*))

Parameters:
array$filterAn array of XMLElement defining the filter
Returns:
boolean Whether or not this vProperty passes the test
Todo:
: While this is unimplemented here at present, most time-range tests should occur at the SQL level.

Definition at line 317 of file vComponent.php.

                                  {
    foreach( $filters AS $k => $v ) {
      $tag = $v->GetNSTag();
//      dbg_error_log( 'vCalendar', "vProperty:TestFilter: '%s'='%s' => '%s'", $this->name, $tag, $this->content );
      switch( $tag ) {
        case 'urn:ietf:params:xml:ns:caldav:is-defined':
        case 'urn:ietf:params:xml:ns:carddav:is-defined':
          if ( empty($this->content) ) return false;
          break;
        
        case 'urn:ietf:params:xml:ns:caldav:is-not-defined':
        case 'urn:ietf:params:xml:ns:carddav:is-not-defined':
          if ( ! empty($this->content) ) return false;
          break;

        case 'urn:ietf:params:xml:ns:caldav:time-range':
          break;

        case 'urn:ietf:params:xml:ns:carddav:text-match':
        case 'urn:ietf:params:xml:ns:caldav:text-match':
          $search = $v->GetContent();
          $match = $this->TextMatch($search);
          $negate = $v->GetAttribute("negate-condition");
          if ( isset($negate) && strtolower($negate) == "yes" ) {
            $match = !$match;
          }
          if ( ! $match ) return false;
          break;

        case 'urn:ietf:params:xml:ns:carddav:param-filter':
        case 'urn:ietf:params:xml:ns:caldav:param-filter':
          $subfilter = $v->GetContent();
          $parameter = $this->GetParameterValue($v->GetAttribute("name"));
          if ( ! $this->TestParamFilter($subfilter,$parameter) ) return false;
          break;

        default:
          dbg_error_log( 'vComponent', ' vProperty::TestFilter: unhandled tag "%s"', $tag );
          break;
      }
    }
    return true;
  }

Here is the call graph for this function:

vProperty::TestParamFilter ( filters,
parameter_value 
)
Todo:
: While this is unimplemented here at present, most time-range tests should occur at the SQL level.

Definition at line 363 of file vComponent.php.

                                                         {
    foreach( $filters AS $k => $v ) {
      $subtag = $v->GetNSTag();
//      dbg_error_log( 'vCalendar', "vProperty:TestParamFilter: '%s'='%s' => '%s'", $this->name, $subtag, $parameter_value );
      switch( $subtag ) {
        case 'urn:ietf:params:xml:ns:caldav:is-defined':
        case 'urn:ietf:params:xml:ns:carddav:is-defined':
          if ( empty($parameter_value) ) return false;
          break;

        case 'urn:ietf:params:xml:ns:caldav:is-not-defined':
        case 'urn:ietf:params:xml:ns:carddav:is-not-defined':
          if ( ! empty($parameter_value) ) return false;
          break;

        case 'urn:ietf:params:xml:ns:caldav:time-range':
          break;

        case 'urn:ietf:params:xml:ns:carddav:text-match':
        case 'urn:ietf:params:xml:ns:caldav:text-match':
          $search = $v->GetContent();
          $match = false;
          if ( !empty($parameter_value) ) $match = strstr( $this->content, $search );
          $negate = $v->GetAttribute("negate-condition");
          if ( isset($negate) && strtolower($negate) == "yes" ) {
            $match = !$match;
          }
          if ( ! $match ) return false;
          break;

        default:
          dbg_error_log( 'vComponent', ' vProperty::TestParamFilter: unhandled tag "%s"', $tag );
          break;
      }
    }
    return true;
  }

Here is the caller graph for this function:

vProperty::TextMatch ( search)

Test if our value contains a string.

Parameters:
string$searchThe needle which we shall search the haystack for.
Returns:
string The name for the property.

Definition at line 194 of file vComponent.php.

                                {
    if ( isset($this->content) ) return strstr( $this->content, $search );
    return false;
  }

Here is the caller graph for this function:

vProperty::Value ( newvalue = null)

Get/Set the content of the property.

Parameters:
string$newvalue[optional] A new value for the property
Returns:
string The value of the property.

Definition at line 159 of file vComponent.php.

                                     {
    if ( $newvalue != null ) {
      $this->content = $newvalue;
      if ( isset($this->rendered) ) unset($this->rendered);
    }
    return $this->content;
  }

Member Data Documentation

vProperty::$content [protected]

Definition at line 47 of file vComponent.php.

vProperty::$name [protected]

Definition at line 33 of file vComponent.php.

Definition at line 40 of file vComponent.php.

vProperty::$rendered [protected]

Definition at line 54 of file vComponent.php.


The documentation for this class was generated from the following file: