00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 include_once( "lib/ezxml/classes/ezxml.php" );
00051
00052 class eZAuthor
00053 {
00054
00055
00056 function eZAuthor( )
00057 {
00058 $Authors = array();
00059 $this->AuthorCount = 0;
00060 }
00061
00062
00063
00064
00065 function setName( $name )
00066 {
00067 $this->Name = $name;
00068 }
00069
00070
00071
00072
00073 function name()
00074 {
00075 return $this->Name;
00076 }
00077
00078
00079
00080
00081 function addAuthor( $id, $name, $email )
00082 {
00083 if ( $id == -1 )
00084 $id = $this->Authors[$this->AuthorCount - 1]['id'] + 1;
00085
00086 $this->Authors[] = array( "id" => $id,
00087 "name" => $name,
00088 "email" => $email,
00089 "is_default" => false );
00090
00091 $this->AuthorCount ++;
00092 }
00093
00094 function removeAuthors( $array_remove )
00095 {
00096 $authors =& $this->Authors;
00097
00098 if ( count( $array_remove ) > 0 )
00099 foreach ( $array_remove as $id )
00100 {
00101 foreach ( $authors as $authorKey => $author )
00102 {
00103 if ( $author['id'] == $id )
00104 {
00105 array_splice( $authors, $authorKey, 1 );
00106 $this->AuthorCount --;
00107 }
00108 }
00109 }
00110 }
00111
00112 function attributes()
00113 {
00114 return array( 'author_list',
00115 'name',
00116 'is_empty' );
00117 }
00118
00119 function hasAttribute( $name )
00120 {
00121 return in_array( $name, $this->attributes() );
00122 }
00123
00124 function &attribute( $name )
00125 {
00126 switch ( $name )
00127 {
00128 case "name" :
00129 {
00130 return $this->Name;
00131 }break;
00132 case "is_empty" :
00133 {
00134 $count = count( $this->Authors ) == 0 ;
00135 return $count;
00136 }break;
00137 case "author_list" :
00138 {
00139 return $this->Authors;
00140 }break;
00141 default:
00142 {
00143 eZDebug::writeError( "Attribute '$name' does not exist", 'eZAuthor::attribute' );
00144 $retValue = null;
00145 return $retValue;
00146 }
00147 break;
00148 }
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 function metaData()
00165 {
00166 $data = '';
00167 foreach ( $this->Authors as $author )
00168 {
00169 $data .= $author['name'] . ' ' . $author['email'] . "\n";
00170 }
00171 return $data;
00172 }
00173
00174
00175
00176
00177 function decodeXML( $xmlString )
00178 {
00179 $xml = new eZXML();
00180 $dom =& $xml->domTree( $xmlString );
00181
00182 if ( $dom )
00183 {
00184 $authorArray =& $dom->elementsByName( 'author' );
00185 if ( is_array( $authorArray ) )
00186 {
00187 foreach ( $authorArray as $author )
00188 {
00189 $this->addAuthor( $author->attributeValue( "id" ), $author->attributeValue( "name" ), $author->attributeValue( "email" ) );
00190 }
00191 }
00192 }
00193 else
00194 {
00195 }
00196 }
00197
00198
00199
00200
00201 function &xmlString( )
00202 {
00203 $doc = new eZDOMDocument( "Author" );
00204
00205 $root = $doc->createElementNode( "ezauthor" );
00206 $doc->setRoot( $root );
00207
00208 $authors = $doc->createElementNode( "authors" );
00209
00210 $root->appendChild( $authors );
00211 $id=0;
00212 if ( is_array( $this->Authors ) )
00213 {
00214 foreach ( $this->Authors as $author )
00215 {
00216 unset( $authorNode );
00217 $authorNode = $doc->createElementNode( "author" );
00218 $authorNode->appendAttribute( $doc->createAttributeNode( "id", $id++ ) );
00219 $authorNode->appendAttribute( $doc->createAttributeNode( "name", $author["name"] ) );
00220 $authorNode->appendAttribute( $doc->createAttributeNode( "email", $author["email"] ) );
00221
00222 $authors->appendChild( $authorNode );
00223 }
00224 }
00225
00226 $xml = $doc->toString();
00227
00228 return $xml;
00229 }
00230
00231
00232 var $Authors;
00233
00234
00235 var $AuthorCount;
00236 }
00237
00238 ?>