|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZAuthor class 00004 // 00005 // Created on: <19-Aug-2002 10:52:01 bf> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! 00032 \class eZAuthor ezauthor.php 00033 \ingroup eZDatatype 00034 \brief eZAuthor handles author lists 00035 00036 \code 00037 00038 //include_once( "kernel/classes/datatypes/ezauthor/ezauthor.php" ); 00039 00040 $author = new eZAuthor( "Colour" ); 00041 $author->addValue( "Red" ); 00042 $author->addValue( "Green" ); 00043 00044 // Serialize the class to an XML document 00045 $xmlString = $author->xmlString(); 00046 00047 \endcode 00048 */ 00049 00050 class eZAuthor 00051 { 00052 /*! 00053 */ 00054 function eZAuthor( ) 00055 { 00056 $this->Authors = array(); 00057 $this->AuthorCount = 0; 00058 } 00059 00060 /*! 00061 Sets the name of the author 00062 */ 00063 function setName( $name ) 00064 { 00065 $this->Name = $name; 00066 } 00067 00068 /*! 00069 Returns the name of the author set. 00070 */ 00071 function name() 00072 { 00073 return $this->Name; 00074 } 00075 00076 /*! 00077 Adds an author 00078 */ 00079 function addAuthor( $id, $name, $email ) 00080 { 00081 if ( $id == -1 ) 00082 $id = $this->Authors[$this->AuthorCount - 1]['id'] + 1; 00083 00084 $this->Authors[] = array( "id" => $id, 00085 "name" => $name, 00086 "email" => $email, 00087 "is_default" => false ); 00088 00089 $this->AuthorCount ++; 00090 } 00091 00092 function removeAuthors( $array_remove ) 00093 { 00094 if ( count( $array_remove ) > 0 ) 00095 foreach ( $array_remove as $id ) 00096 { 00097 foreach ( $this->Authors as $authorKey => $author ) 00098 { 00099 if ( $author['id'] == $id ) 00100 { 00101 array_splice( $this->Authors, $authorKey, 1 ); 00102 $this->AuthorCount --; 00103 } 00104 } 00105 } 00106 } 00107 00108 function attributes() 00109 { 00110 return array( 'author_list', 00111 'name', 00112 'is_empty' ); 00113 } 00114 00115 function hasAttribute( $name ) 00116 { 00117 return in_array( $name, $this->attributes() ); 00118 } 00119 00120 function attribute( $name ) 00121 { 00122 switch ( $name ) 00123 { 00124 case "name" : 00125 { 00126 return $this->Name; 00127 }break; 00128 case "is_empty" : 00129 { 00130 return count( $this->Authors ) == 0 ; 00131 }break; 00132 case "author_list" : 00133 { 00134 return $this->Authors; 00135 }break; 00136 default: 00137 { 00138 eZDebug::writeError( "Attribute '$name' does not exist", 'eZAuthor::attribute' ); 00139 return null; 00140 } 00141 break; 00142 } 00143 } 00144 00145 /*! 00146 \return a string which contains all the interesting meta data. 00147 00148 The result of this method can passed to the search engine or other 00149 parts which work on meta data. 00150 00151 The string will contain all the authors with their name and email. 00152 00153 Example: 00154 \code 00155 'John Doe john@doe.com' 00156 \endcode 00157 */ 00158 function metaData() 00159 { 00160 $data = ''; 00161 foreach ( $this->Authors as $author ) 00162 { 00163 $data .= $author['name'] . ' ' . $author['email'] . "\n"; 00164 } 00165 return $data; 00166 } 00167 00168 /*! 00169 Will decode an xml string and initialize the eZ author object 00170 */ 00171 function decodeXML( $xmlString ) 00172 { 00173 $dom = new DOMDocument( '1.0', 'utf-8' ); 00174 $success = $dom->loadXML( $xmlString ); 00175 00176 if ( $success ) 00177 { 00178 $authors = $dom->getElementsByTagName( 'author' ); 00179 foreach ( $authors as $author ) 00180 { 00181 $this->addAuthor( $author->getAttribute( "id" ), $author->getAttribute( "name" ), $author->getAttribute( "email" ) ); 00182 } 00183 } 00184 } 00185 00186 /*! 00187 Will return the XML string for this author set. 00188 */ 00189 function xmlString( ) 00190 { 00191 $doc = new DOMDocument( '1.0', 'utf-8' ); 00192 00193 $root = $doc->createElement( "ezauthor" ); 00194 $doc->appendChild( $root ); 00195 00196 $authors = $doc->createElement( "authors" ); 00197 $root->appendChild( $authors ); 00198 00199 $id=0; 00200 if ( is_array( $this->Authors ) ) 00201 { 00202 foreach ( $this->Authors as $author ) 00203 { 00204 unset( $authorNode ); 00205 $authorNode = $doc->createElement( "author" ); 00206 $authorNode->setAttribute( "id", $id++ ); 00207 $authorNode->setAttribute( "name", $author["name"] ); 00208 $authorNode->setAttribute( "email", $author["email"] ); 00209 00210 $authors->appendChild( $authorNode ); 00211 } 00212 } 00213 00214 $xml = $doc->saveXML(); 00215 00216 return $xml; 00217 } 00218 00219 /// Contains the Authors 00220 public $Authors; 00221 00222 /// Contains the author counter value 00223 public $AuthorCount; 00224 00225 public $Name; 00226 } 00227 00228 ?>