Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

article.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: article.php 9771 2003-02-11 13:04:22Z jb $
5 //
6 // Created on: <23-Oct-2000 17:53:46 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "ezarticle/classes/ezarticlecategory.php" );
28 // include_once( "ezarticle/classes/ezarticleattribute.php" );
29 // include_once( "ezarticle/classes/ezarticle.php" );
30 // include_once( "ezarticle/classes/ezarticletool.php" );
31 // include_once( "classes/ezlocale.php" );
32 // include_once( "ezsitemanager/classes/ezsection.php" );
33 // include_once( "ezform/classes/ezform.php" );
34 // include_once( "ezuser/classes/ezobjectpermission.php" );
35 // include_once( "ezxmlrpc/classes/ezxmlrpcarray.php" );
36 // include_once( "ezxmlrpc/classes/ezxmlrpcbool.php" );
37 // include_once( "ezxmlrpc/classes/ezxmlrpcint.php" );
38
39 if( $Command == "info" )
40 {
41 $article = new eZArticle();
42 if ( !$article->get( $ID ) )
43 {
44 $Error = createErrorMessage( EZERROR_NONEXISTING_OBJECT );
45 }
46 else
47 {
48 $ret = array( "Name" => new eZXMLRPCString( $article->name( false ) ) );
49 $ReturnData = new eZXMLRPCStruct( $ret );
50 }
51 }
52 else if ( $Command == "permission" )
53 {
54 $CategoryID = eZArticle::categoryDefinitionStatic( $ID );
55 $read = eZObjectPermission::hasPermissionWithDefinition( $ID, "article_article", "r", $User, $CategoryID );
56 $edit = eZObjectPermission::hasPermissionWithDefinition( $ID, "article_article", 'w', $User, $CategoryID );
57
58 $ret = array( "Read" => new eZXMLRPCBool( $read ),
59 "Edit" => new eZXMLRPCBool( $edit ) );
60 $ReturnData = new eZXMLRPCStruct( $ret );
61 }
62 else if( $Command == "data" ) // return all the data in the category
63 {
64 $article = new eZArticle();
65 if ( !$article->get( $ID ) )
66 {
67 $Error = createErrorMessage( EZERROR_NONEXISTING_OBJECT );
68 }
69 else
70 {
71 $writeGroups = eZObjectPermission::getGroups( $ID, "article_article", 'w', false );
72 $readGroups = eZObjectPermission::getGroups( $ID, "article_article", 'r', false );
73 $contentsWriter =& $article->contentsWriter( true );
74
75 $type_arr = array();
76 $types =& $article->types();
77 foreach( $types as $type )
78 {
79 $attributes =& $type->attributes();
80 if ( count( $attributes ) > 0 )
81 {
82 $attr_arr = array();
83 foreach( $attributes as $attrib )
84 {
85 $attr_arr[] = new eZXMLRPCStruct( array( "ID" => new eZXMLRPCInt( $attrib->id() ),
86 "Name" => new eZXMLRPCString( $attrib->name() ),
87 "Content" => new eZXMLRPCString( $attrib->value( $article ) ) ) );
88 }
89 $type_arr[] = new eZXMLRPCStruct( array( "ID" => new eZXMLRPCInt( $type->id() ),
90 "Name" => new eZXMLRPCString( $type->name() ),
91 "Attributes" => new eZXMLRPCArray( $attr_arr ) ) );
92 }
93 }
94 $images = $article->images( false );
95 $img = array();
96 foreach( $images as $image )
97 {
98 $img[] = new eZXMLRPCStruct( array( "Image" => new eZXMLRPCInt( $image["Image"] ),
99 "Placement" => new eZXMLRPCInt( $image["Placement"] ) ) );
100 }
101
102 $cat_def_id = $article->categoryDefinition( false );
103 $section_id = eZArticleCategory::sectionIDStatic( $cat_def_id );
104 $section_lang = false;
105 if ( $section_id != 0 )
106 {
107 $section = new eZSection( $section_id );
108 $section_lang = $section->language();
109 }
110 $cats = $article->categories( false );
111 $cats = array_diff( $cats, array( $cat_def_id ) );
112
113 $ret = array( "Location" => createURLStruct( "ezarticle", "article", $article->id() ),
114 "AuthorID" => new eZXMLRPCInt( $article->author( false ) ),
115 "Name" => new eZXMLRPCString( $article->name( false ) ), // title
116 "Contents" => new eZXMLRPCString( $article->contents( false ) ),
117 "ContentsWriterID" => new eZXMLRPCInt( $contentsWriter->id() ),
118 "LinkText" => new eZXMLRPCString( $article->linkText( false ) ),
119 "ManualKeyWords" => new eZXMLRPCString( $article->manualKeywords() ),
120 "Category" => new eZXMLRPCInt( $cat_def_id ),
121 "Categories" => new eZXMLRPCArray( $cats, "integer" ),
122 "Discuss" => new eZXMLRPCBool( $article->discuss() ),
123 "IsPublished" => new eZXMLRPCBool( $article->isPublished() ),
124 "PageCount" => new eZXMLRPCInt( $article->pageCount() ),
125 "Thumbnail" => new eZXMLRPCInt( $article->thumbnailImage( false ) ),
126 "Images" => new eZXMLRPCArray( $img ),
127 "Files" => new eZXMLRPCArray( $article->files( false ), "integer" ),
128 "Forms" => new eZXMLRPCArray( $article->forms( false ), "integer" ),
129 "ReadGroups" => new eZXMLRPCArray( $readGroups, "integer" ),
130 "WriteGroups" => new eZXMLRPCArray( $writeGroups, "integer" ),
131 "Types" => new eZXMLRPCArray( $type_arr ),
132 "Topic" => new eZXMLRPCInt( $article->topic( false ) )
133 // "PublishedDate" => new eZXMLRPCStruct(),
134 );
135 if ( $section_lang != false )
136 {
137 $charsetLocale = new eZLocale( $section_lang );
138 $section_charset = $charsetLocale->languageISO();
139 $ret["Section"] = new eZXMLRPCStruct( array( "Language" => $section_lang,
140 "Charset" => $section_charset ) );
141 }
142 $start_date = $article->startDate( false );
143 if ( !is_bool( $start_date ) )
144 $ret["StartDate"] = createDateTimeStruct( $article->startDate() );
145 $stop_date =& $article->stopDate( false );
146 if ( !is_bool( $stop_date ) )
147 $ret["StopDate"] = createDateTimeStruct( $article->stopDate() );
148 $published =& $article->published();
149 if ( $published->isValid() )
150 $ret["PublishedDate"] = createDateTimeStruct( $published );
151 $created =& $article->created();
152 if ( $created->isValid() )
153 $ret["CreatedDate"] = createDateTimeStruct( $created );
154 $modified =& $article->modified();
155 if ( $modified->isValid() )
156 $ret["ModifiedDate"] = createDateTimeStruct( $modified );
157 $ReturnData = new eZXMLRPCStruct( $ret );
158 }
159 }
160 else if( $Command == "storedata" )
161 {
162 $article = new eZArticle();
163 if( $ID != 0 )
164 $article->get( $ID );
165
166 $article->setAuthor( $Data["AuthorID"]->value() );
167 $article->setName( $Data["Name"]->value() ); // title
168 $article->setContents( $Data["Contents"]->value() );
169 $article->setContentsWriter( $Data["ContentsWriterID"]->value() );
170 $article->setLinkText( $Data["LinkText"]->value() );
171 $article->setDiscuss( $Data["Discuss"]->value() );
172 $article->setTopic( $Data["Topic"]->value() );
173
174 if ( isset( $Data["StartDate"] ) )
175 {
176 $startDate = createDateTime( $Data["StartDate"]->value() );
177 $article->setStartDate( $startDate );
178 }
179 if ( isset( $Data["StopDate"] ) )
180 {
181 $stopDate = createDateTime( $Data["StopDate"]->value() );
182 $article->setStopDate( $stopDate );
183 }
184
185 $article->store();
186 $ID = $article->id();
187
188 // Must have an article ID in order to set keywords
189 $article->setManualKeywords( $Data["ManualKeyWords"]->value() );
190
191 if ( isset( $Data["LogMessage"] ) )
192 {
193 $article->addLog( $Data["LogMessage"]->value(), $User );
194 }
195
196 $old_cat_def_id = $article->categoryDefinition( false );
197 $old_cats = $article->categories( false );
198
199 if ( isset( $Data["Category"] ) )
200 {
201 $cat = new eZArticleCategory( $Data["Category"]->value() );
202 $article->setCategoryDefinition( $cat );
203 }
204
205 $add_locs = array();
206 $cur_locs = array();
207 $old_locs = array();
208 if ( isset( $Data["Category" ] ) && isset( $Data["Categories"] ) )
209 {
210 $cat = $Data["Category"]->value();
211 $cat_arr =& $Data["Categories"]->value();
212 $cats = array( $cat );
213 foreach( $cat_arr as $cat )
214 {
215 $cats[] = $cat->value();
216 }
217 $cats = array_unique( $cats );
218 $remove_categories = array_diff( $old_cats, $cats );
219 $add_categories = array_diff( $cats, $old_cats );
220 $cur_categories = array_intersect( $old_cats, $cats );
221 }
222
223 if ( isset( $Data["Categories"] ) )
224 {
225 foreach( $remove_categories as $cat )
226 {
227 eZArticleCategory::removeArticle( $article, $cat );
228 }
229 foreach( $add_categories as $cat )
230 {
231 eZArticleCategory::addArticle( $article, $cat );
232 }
233 }
234
235 if ( isset( $Data["Category" ] ) && isset( $Data["Categories"] ) )
236 {
237 $add_locs =& createURLArray( $add_categories, "ezarticle", "category" );
238 $cur_locs =& createURLArray( $cur_categories, "ezarticle", "category" );
239 $old_locs =& createURLArray( $remove_categories, "ezarticle", "category" );
240 }
241
242 // images
243 $images = $Data["Images"]->value();
244 $new_images = array();
245 foreach( $images as $img )
246 {
247 $image = $img->value();
248 $id = $image["Image"]->value();
249 $ix = $image["Placement"]->value();
250 $new_images[$ix] = $id;
251 }
252 $images = $article->images( false );
253 $old_images = array();
254 foreach( $images as $image )
255 {
256 $id = $image["Image"];
257 $ix = $image["Placement"];
258 $old_images[$ix] = $id;
259 }
260 $del_images = array_diff( $old_images, $new_images );
261 $added_images = array_diff( $new_images, $old_images );
262 $changed_images = array_intersect( $new_images, $old_images );
263
264 foreach( $del_images as $image )
265 {
266 $article->deleteImage( $image );
267 }
268 while( list($add_ix, $add_id) = each($added_images) )
269 {
270 $article->addImage( $add_id, $add_ix );
271 }
272
273 if ( $Data["Thumbnail"]->value() > 0 )
274 {
275 $thumbImage = new eZImage( $Data["Thumbnail"]->value() );
276 }
277 else
278 $thumbImage = false;
279 $article->setThumbnailImage( $thumbImage );
280
281 // files
282 $files = $Data["Files"]->value();
283 $new_files = array();
284 foreach( $files as $fl )
285 {
286 $new_files[] = $fl->value();
287 }
288 $files =& $article->files( false );
289 $old_files = array_diff( $files, $new_files );
290 $added_files = array_diff( $new_files, $files );
291 $changed_files = array_intersect( $new_files, $files );
292 foreach( $old_files as $file )
293 $article->deleteFile( $file );
294 foreach( $added_files as $file )
295 $article->addFile( $file );
296
297 // permissions....
298 eZObjectPermission::removePermissions( $ID, "article_article", 'r' );
299 $readGroups = $Data["ReadGroups"]->value();
300 foreach( $readGroups as $readGroup )
301 eZObjectPermission::setPermission( $readGroup->value(), $ID, "article_article", 'r' );
302
303 eZObjectPermission::removePermissions( $ID, "article_article", 'w' );
304 $writeGroups = $Data["WriteGroups"]->value();
305 foreach( $writeGroups as $writeGroup )
306 eZObjectPermission::setPermission( $writeGroup->value(), $ID, "article_article", 'w' );
307
308 // types
309 $types = $Data["Types"]->value();
310 $old_types = $article->types( false );
311 $new_types = array();
312 foreach ( $types as $type )
313 {
314 $type = $type->value();
315 $typeID = $type["ID"]->value();
316 $new_types[] = $typeID;
317 $attrs = $type["Attributes"]->value();
318 $attr_map = array();
319 foreach( $attrs as $attr )
320 {
321 $attr = $attr->value();
322 $id = $attr["ID"]->value();
323 $name = $attr["Name"]->value();
324 $content = $attr["Content"]->value();
325 $attr_map[$id] = array( "ID" => $id,
326 "Name" => $name,
327 "Content" => $content );
328 }
329 $articleType = new eZArticleType( $typeID );
330 $attributes = $articleType->attributes();
331
332 foreach( $attributes as $attribute )
333 {
334 $id = $attribute->id();
335 if ( isset( $attr_map[$id] ) )
336 {
337 $attribute->setName( $attr_map[$id]["Name"] );
338 $attribute->store();
339 $attribute->setValue( $article, $attr_map[$id]["Content"] );
340 }
341 }
342 }
343 $removed_types = array_diff( $old_types, $new_types );
344 foreach( $removed_types as $typeID )
345 {
346 $type = new eZArticleType();
347 if ( $type->get( $typeID ) )
348 {
349 $article->deleteAttributesByType( $type );
350 }
351 }
352
353 // forms
354 $article->deleteForms();
355 $forms = $Data["Forms"]->value();
356 foreach( $forms as $form )
357 {
358 $form = new eZForm( $form->value() );
359 $article->addForm( $form );
360 }
361
362 $waspublished = true;
363 if ( !$article->isPublished() )
364 {
365 $waspublished = false;
366 }
367
368 // Set is published and store again
369 $article->setIsPublished( $Data["IsPublished"]->value(), $User );
370 $article->store();
371
372 if ( $article->isPublished() && !$waspublished )
373 {
374 eZArticleTool::notificationMessage( $article );
375 }
376
377 // categories
378 $category = new eZArticleCategory( eZArticle::categoryDefinitionStatic( $ID ) );
379 $par =& createPath( $category, "ezarticle", "category" );
380
381 $category = $article->categoryDefinition( );
382 $CategoryID = $category->id();
383 $CategoryArray =& $article->categories( false );
384 eZArticleTool::deleteCache( $ID, $CategoryID, $CategoryArray );
385
386 $cat_def_id = $article->categoryDefinition( false );
387 $section_id = eZArticleCategory::sectionIDStatic( $cat_def_id );
388 $section_lang = false;
389 if ( $section_id != 0 )
390 {
391 $section = new eZSection( $section_id );
392 $section_lang = $section->language();
393 }
394
395 $ret_arr = array( "Location" => createURLStruct( "ezarticle", "article", $ID ),
396 "Name" => new eZXMLRPCString( $article->name( false ) ),
397 "Path" => new eZXMLRPCArray( $par ),
398 "NewLocations" => $add_locs,
399 "ChangedLocations" => $cur_locs,
400 "RemovedLocations" => $old_locs,
401 "UpdateType" => new eZXMLRPCString( $Command )
402 );
403 if ( $section_lang != false )
404 {
405 $charsetLocale = new eZLocale( $section_lang );
406 $section_charset = $charsetLocale->languageISO();
407 $ret_arr["Section"] = new eZXMLRPCStruct( array( "Language" => $section_lang,
408 "Charset" => $section_charset ) );
409 }
410 $ReturnData = new eZXMLRPCStruct( $ret_arr );
411 $Command = "update";
412
413 }
414 else if( $Command == "delete" )
415 {
416 $category = eZArticle::categoryDefinitionStatic( $ID );
417 $category = new eZArticleCategory( $category );
418 $path =& $category->path();
419 if ( $category->id() != 0 )
420 {
421 $par[] = createURLStruct( "ezarticle", "category", 0 );
422 }
423 else
424 {
425 $par[] = createURLStruct( "ezarticle", "" );
426 }
427 foreach( $path as $item )
428 {
429 if ( $item[0] != $category->id() )
430 $par[] = createURLStruct( "ezarticle", "category", $item[0] );
431 }
432
433 $ReturnData = new eZXMLRPCStruct( array( "Location" => createURLStruct( "ezarticle", "article", $ID ),
434 "Path" => new eZXMLRPCArray( $par ),
435 "UpdateType" => new eZXMLRPCString( $Command )
436 )
437 );
438 $Command = "update";
439
440 $article = new eZArticle( $ID );
441 $category = $article->categoryDefinition( );
442 $CategoryID = $category->id();
443 $CategoryArray =& $article->categories( false );
444 eZArticleTool::deleteCache( $ID, $CategoryID, $CategoryArray );
445
446 $article->delete();
447 }
448 else if ( $Command == "search" )
449 {
450 $texts = $Data["Keywords"]->value();
451 $text = "";
452 foreach( $texts as $txt )
453 {
454 if ( $text == "" )
455 $text = $text . $txt->value();
456 else
457 $text = $text . " " . $txt->value();
458 }
459 $elements = array();
460 $article = new eZArticle();
461 $params = array();
462 if ( isset( $Data["Parameters"] ) )
463 {
464 $par = $Data["Parameters"]->value();
465 if ( isset( $par["FromDate"] ) )
466 $params["FromDate"] = createDateTime( $par["FromDate"]->value() );
467 if ( isset( $par["ToDate"] ) )
468 $params["ToDate"] = createDateTime( $par["ToDate"]->value() );
469 if ( isset( $par["Categories"] ) )
470 $params["Categories"] = $par["Categories"]->toArray();
471 if ( isset( $par["Type"] ) )
472 $params["Type"] = $par["Type"]->value();
473 if ( isset( $par["AuthorID"] ) )
474 $params["AuthorID"] = $par["AuthorID"]->value();
475 if ( isset( $par["PhotographerID"] ) )
476 $params["PhotographerID"] = $par["PhotographerID"]->value();
477 }
478 $search_count = 0;
479 $result =& $article->search( $text, "alpha", true, 0, -1, $params, $search_count );
480 foreach( $result as $item )
481 {
482 $cat =& $item->categoryDefinition();
483 $itemid = $item->id();
484 $catid = $cat->id();
485 $elements[] = new eZXMLRPCStruct( array( "Name" => new eZXMLRPCString( $item->name( false ) ),
486 "CategoryName" => new eZXMLRPCString( $cat->name( false ) ),
487 "Location" => createURLStruct( "ezarticle", "article", $item->id() ),
488 "CategoryLocation" => createURLStruct( "ezarticle", "category", $cat->id() ),
489 "WebURL" => new eZXMLRPCString( rewriteWebURL( "/article/articleview/$itemid/1/$catid/" ) ),
490 "CategoryWebURL" => new eZXMLRPCString( rewriteWebURL( "/article/archive/$catid/" ) )
491 ) );
492 }
493 $ret = array( "Elements" => new eZXMLRPCArray( $elements ) );
494 handleSearchData( $ret );
495 $ReturnData = new eZXMLRPCStruct( $ret );
496 }
497 else if ( $Command == "weburl" )
498 {
499 $path = "/article/articleview/" .
500 $Data["ArticleID"]->value() . "/" .
501 $Data["ArticlePage"]->value() . "/" .
502 $Data["ArticleCategory"]->value() . "/";
503 $ReturnData = new eZXMLRPCStruct(
504 array( "WebURL" => new eZXMLRPCString( rewriteWebURL( $path ) ) )
505 );
506 }
507
508 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$CategoryID
$CategoryID
Definition: admin/articleedit.php:53
$article
$article
Definition: articlelog.php:45
$types
$types
Definition: articlepreview.php:108
$files
$files
Definition: articlepreview.php:91
$images
$images
Definition: articlepreview.php:146
eZArticleCategory
Definition: ezarticlecategory.php:45
eZArticleCategory\addArticle
static addArticle( $value, $categoryid=false)
Definition: ezarticlecategory.php:1079
eZArticleCategory\removeArticle
static removeArticle( $value, $categoryid=false)
Definition: ezarticlecategory.php:1052
eZArticleCategory\sectionIDStatic
static sectionIDStatic($categoryID)
Definition: ezarticlecategory.php:662
eZArticleTool\notificationMessage
static notificationMessage(&$article)
Definition: ezarticletool.php:136
eZArticleTool\deleteCache
static deleteCache( $ArticleID, $CategoryID, $CategoryArray)
Definition: ezarticletool.php:52
eZArticleType
Definition: ezarticletype.php:46
eZArticle
Definition: ezarticle.php:82
eZArticle\categoryDefinitionStatic
static categoryDefinitionStatic( $id)
Definition: ezarticle.php:2541
eZForm
Definition: ezform.php:42
eZImage
Definition: ezimage.php:95
eZLocale
Definition: ezlocale.php:119
eZObjectPermission\getGroups
static getGroups( $objectID, $moduleTable, $permission, $GroupReturn=true)
Definition: ezobjectpermission.php:365
eZObjectPermission\setPermission
static setPermission( $group, $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:236
eZObjectPermission\removePermissions
static removePermissions( $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:320
eZObjectPermission\hasPermissionWithDefinition
static hasPermissionWithDefinition( $objectID, $moduleTable, $permission, $user=false, $categoryID=false)
Definition: ezobjectpermission.php:141
eZSection
Definition: ezsection.php:45
eZXMLRPCArray
Definition: ezxmlrpcarray.php:37
eZXMLRPCBool
Definition: ezxmlrpcbool.php:37
eZXMLRPCInt
Definition: ezxmlrpcint.php:37
eZXMLRPCString
Definition: ezxmlrpcstring.php:37
eZXMLRPCStruct
Definition: ezxmlrpcstruct.php:37
$item
$item
Definition: classes/admin/linklist.php:228
$type
$type
Definition: classes/admin/linkselect.php:220
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$forms
$forms
Definition: ezarticle/admin/formlist.php:74
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$cat
if(isset( $DeleteCategories)) $cat
Definition: ezforum/admin/categoryedit.php:49
$Error
if(isset( $EditButton)) if(!empty( $CancelButton)) if(!empty( $PreviewButton)) if( $Action=="preview") switch( $Action) $Error
Definition: ezforum/user/messageedit.php:134
$content
$content
Definition: ezimagecatalogue/admin/filedownload.php:53
$section
$section
Definition: ezimagecatalogue/user/categoryedit.php:393
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$form
$form
Definition: formedit.php:46
$elements
$elements
Definition: formedit.php:355
$ReturnData
$ReturnData
Definition: tag.php:48
$image
$image
Definition: user/articlelist.php:242
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.