Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezauthor.php
Go to the documentation of this file.
1 <?php
28 class eZAuthor
29 {
30 public function __construct( )
31 {
32 $this->Authors = array();
33 $this->AuthorCount = 0;
34 }
35
39 function setName( $name )
40 {
41 $this->Name = $name;
42 }
43
47 function name()
48 {
49 return $this->Name;
50 }
51
59 function addAuthor( $id, $name, $email )
60 {
61 if ( $id == -1 )
62 {
63 if ( isset( $this->Authors[$this->AuthorCount - 1] ) )
64 $id = $this->Authors[$this->AuthorCount - 1]['id'] + 1;
65 else
66 $id = 1;
67 }
68
69 $this->Authors[] = array( "id" => $id,
70 "name" => $name,
71 "email" => $email,
72 "is_default" => false );
73
74 $this->AuthorCount ++;
75 }
76
82 function removeAuthors( $removeList )
83 {
84 if ( count( $removeList ) > 0 )
85 foreach ( $removeList as $id )
86 {
87 foreach ( $this->Authors as $authorKey => $author )
88 {
89 if ( $author['id'] == $id )
90 {
91 array_splice( $this->Authors, $authorKey, 1 );
92 $this->AuthorCount --;
93 }
94 }
95 }
96 }
97
98 function attributes()
99 {
100 static $def = array( 'author_list',
101 'name',
102 'is_empty' );
103 return $def;
104 }
105
106 function hasAttribute( $name )
107 {
108 return in_array( $name, $this->attributes() );
109 }
110
111 function attribute( $name )
112 {
113 switch ( $name )
114 {
115 case "name" :
116 {
117 return $this->Name;
118 }break;
119 case "is_empty" :
120 {
121 return $this->AuthorCount === 0;
122 }break;
123 case "author_list" :
124 {
125 return $this->Authors;
126 }break;
127 default:
128 {
129 eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ );
130 return null;
131 }
132 break;
133 }
134 }
135
149 function metaData()
150 {
151 $data = '';
152 foreach ( $this->Authors as $author )
153 {
154 $data .= $author['name'] . ' ' . $author['email'] . "\n";
155 }
156 return $data;
157 }
158
162 function decodeXML( $xmlString )
163 {
164 $dom = new DOMDocument( '1.0', 'utf-8' );
165 $success = $dom->loadXML( $xmlString );
166
167 if ( $success )
168 {
169 $authors = $dom->getElementsByTagName( 'author' );
170 foreach ( $authors as $author )
171 {
172 $this->addAuthor( $author->getAttribute( "id" ), $author->getAttribute( "name" ), $author->getAttribute( "email" ) );
173 }
174 }
175 }
176
180 function xmlString( )
181 {
182 $doc = new DOMDocument( '1.0', 'utf-8' );
183
184 $root = $doc->createElement( "ezauthor" );
185 $doc->appendChild( $root );
186
187 $authors = $doc->createElement( "authors" );
188 $root->appendChild( $authors );
189
190 $id = 0;
191 foreach ( $this->Authors as $author )
192 {
193 unset( $authorNode );
194 $authorNode = $doc->createElement( "author" );
195 $authorNode->setAttribute( "id", $id++ );
196 $authorNode->setAttribute( "name", $author["name"] );
197 $authorNode->setAttribute( "email", $author["email"] );
198
199 $authors->appendChild( $authorNode );
200 }
201
202 $xml = $doc->saveXML();
203
204 return $xml;
205 }
206
208 protected $Authors;
209
211 protected $AuthorCount;
212
213 // Contains the name of the author set.
214 protected $Name;
215 }
216
217 ?>
eZAuthor
eZAuthor handles author lists
Definition: ezauthor.php:29
eZAuthor\$AuthorCount
$AuthorCount
Contains the author counter value.
Definition: ezauthor.php:211
eZAuthor\$Authors
$Authors
Contains the Authors.
Definition: ezauthor.php:208
eZAuthor\xmlString
xmlString()
Definition: ezauthor.php:180
eZAuthor\removeAuthors
removeAuthors( $removeList)
Definition: ezauthor.php:82
eZAuthor\addAuthor
addAuthor( $id, $name, $email)
Definition: ezauthor.php:59
eZAuthor\setName
setName( $name)
Definition: ezauthor.php:39
eZAuthor\name
name()
Definition: ezauthor.php:47
eZAuthor\attributes
attributes()
Definition: ezauthor.php:98
eZAuthor\__construct
__construct()
Definition: ezauthor.php:30
eZAuthor\decodeXML
decodeXML( $xmlString)
Definition: ezauthor.php:162
eZAuthor\$Name
$Name
Definition: ezauthor.php:214
eZAuthor\hasAttribute
hasAttribute( $name)
Definition: ezauthor.php:106
eZAuthor\attribute
attribute( $name)
Definition: ezauthor.php:111
eZAuthor\metaData
metaData()
Definition: ezauthor.php:149
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.