Location: PHPKode > projects > PhpiCalLib > textproperties.php
<?php
/**
 * textproperties.php: iCalendar text property classes
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * @copyright Copyright (C) 2008 Nigel Swinson, hide@address.com 
 * @author  Nigel Swinson
 * @package PhpiCalLib
 * @version 1.0
 */

require_once 'contentline.php';
require_once 'datatypes.php';

/**
 * Many properties specify a value of type "text".  This base class can be used for those.
 * <pre>
 *        text       = *(TSAFE-CHAR / ":" / DQUOTE / ESCAPED-CHAR)
 *           ; Folded according to description above
 *
 *        ESCAPED-CHAR = ("\\" / "\;" / "\," / "\N" / "\n")
 *           ; \\ encodes \, \N or \n encodes newline
 *           ; \; encodes ;, \, encodes ,
 *
 *        TSAFE-CHAR = %x20-21 / %x23-2B / %x2D-39 / %x3C-5B /
 *                     %x5D-7E / NON-US-ASCII
 *           ; Any character except CTLs not needed by the current
 *           ; character set, DQUOTE %x22, ";" %x3B, ":" %x3A, "\" %x5C, "," %x2C
 * </pre>
 */
class PhpiCalLib_Properties_TextProperty extends PhpiCalLib_ContentLine {
	/**
	 * The text token value of this property
	 *
	 * @var PhpiCalLib_DataTypes_Text
	 */
	protected $TextValue = null;
	
	public function __construct() {
		parent::__construct();
		$this->TextValue = new PhpiCalLib_DataTypes_Text();
	}
	
	/**
	 * Overridden to do extra parsing to extract the $TextValue
	 */
	public function SetEncodedValue($Text) {
		// Establish our text token
		$this->TextValue->Parse($Text);
		// Set the value in the parent.
		parent::SetEncodedValue($this->TextValue->ToString());
	}
	
	/**
	 * Access the TextValue
	 */
	public function GetTextValue() {
		return $this->TextValue->GetValue();
	}
	
	/**
	 * Set the TextValue
	 */
	public function SetTextValue($String) {
		// Set our specialized version
		$this->TextValue->SetValue($String);
		// Set the value token
		parent::SetEncodedValue($this->TextValue->ToString());
	}
}

/**
 * The PRODID property.
 * <pre>
 *        prodid     = "PRODID" pidparam ":" pidvalue CRLF
 *
 *        pidparam   = *(";" other-param)
 *
 *        pidvalue   = text
 *        ;Any text that describes the product and version
 *        ;and that is generally assured of being unique.
 * </pre>
 * 
 * @link http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.7.3
 */
class PhpiCalLib_Properties_ProdIdProperty extends PhpiCalLib_Properties_TextProperty {
	public function __construct() {
		parent::__construct();
		$this->SetType(PHPICALLIB_PROPERTY_PRODID);
	}
}

/**
 * The DESCRIPTION property.
 * <pre>
 *        description        = "DESCRIPTION" descparam ":" text CRLF
 *
 *        descparam  = *(
 *                   ; the following are OPTIONAL,
 *                   ; but MUST NOT occur more than once
 *                   (";" altrepparam) / (";" languageparam) /
 *
 *                   ; the following is OPTIONAL,
 *                   ; and MAY occur more than once
 *                   (";" other-param)
 *                   )
 * </pre>
 * @link http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.1.5
 */
class PhpiCalLib_Properties_DescriptionProperty extends PhpiCalLib_Properties_TextProperty {
	public function __construct() {
		parent::__construct();
		$this->SetType(PHPICALLIB_PROPERTY_DESCRIPTION);
	}
}

/**
 * The CATEGORIES property
 * <pre>
 *         categories = "CATEGORIES" catparam ":" text *("," text)
 *                     CRLF
 *
 *        catparam   = *(
 *
 *                   ; the following is OPTIONAL,
 *                   ; but MUST NOT occur more than once
 *                   (";" languageparam ) /
 *
 *                   ; the following is OPTIONAL,
 *                   ; and MAY occur more than once
 *                   (";" other-param)
 *                   )
 * @link http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.1.2
 */
class PhpiCalLib_Properties_CategoriesProperty extends PhpiCalLib_Properties_TextProperty {
	public function __construct() {
		parent::__construct();
		$this->SetType(PHPICALLIB_PROPERTY_CATEGORIES);
	}
}

/**
 * The SUMMARY property.
 * <pre>
 *        summary    = "SUMMARY" summparam ":" text CRLF
 *
 *        summparam  = *(
 *                   ; the following are OPTIONAL,
 *                   ; but MUST NOT occur more than once
 *                   (";" altrepparam) / (";" languageparam) /
 *
 *                   ; the following is OPTIONAL,
 *                   ; and MAY occur more than once
 *                   (";" other-param)
 *
 *                   )
 * </pre>
 * @link http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.1.12
 */
class PhpiCalLib_Properties_SummaryProperty extends PhpiCalLib_Properties_TextProperty {
	public function __construct() {
		parent::__construct();
		$this->SetType(PHPICALLIB_PROPERTY_SUMMARY);
	}
}

/**
 * The UID property.
 * <pre>
 *        uid        = "UID" uidparam ":" text CRLF
 *
 *        uidparam   = *(";" other-param)
 * </pre>
 * @link http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.4.7
 */
class PhpiCalLib_Properties_UidProperty extends PhpiCalLib_Properties_TextProperty {
	public function __construct() {
		parent::__construct();
		$this->SetType(PHPICALLIB_PROPERTY_UID);
		//   Description:  The "UID" itself MUST be a globally unique identifier.
		//      The generator of the identifier MUST guarantee that the identifier
		//      is unique.  There are several algorithms that can be used to
		//      accomplish this.  A good method to assure uniqueness is to put the
		//      domain name or a domain literal IP address of the host on which
		//      the identifier was created on the right hand side of an "@", and
		//      on the left hand side, put a combination of the current calendar
		//      date and time of day (i.e., formatted in as a DATE-TIME value)
		//      along with some other currently unique (perhaps sequential)
		//      identifier available on the system (for example, a process id
		//      number).  Using a date/time value on the left hand side and a
		//      domain name or domain literal on the right hand side makes it
		//      possible to guarantee uniqueness since no two hosts should be
		//      using the same domain name or IP address at the same time.  Though
		//      other algorithms will work, it is RECOMMENDED that the right hand
		//      side contain some domain identifier (either of the host itself or
		//      otherwise) such that the generator of the message identifier can
		//      guarantee the uniqueness of the left hand side within the scope of
		//      that domain.
		$Now = new PhpiCalLib_DataTypes_DateTime();
		$Now->FromTimeStamp(time(), true);
		static $iIndex = 1;
		$Uid = sprintf('%s@%s-%08x-%s',
					// Unique to this server
					$_SERVER['SERVER_NAME'],
					// The current date/time 
					$Now->ToString(), 
					// An incrementing static
					$iIndex++, 
					// Part of the session id to improve uniqueness
					substr(session_id(), 0, 8));
		//      Implementations MUST be able to receive and persist values of at
		//      least 255 octets for this property but MUST NOT truncate values in
		//      the middle of a UTF-8 multi-octet sequence.
		$this->SetTextValue(substr($Uid,0,255));
	}
}
?>
Return current item: PhpiCalLib