Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezrssimport.php
Go to the documentation of this file.
1 <?php
18 class eZRSSImport extends eZPersistentObject
19 {
20 public $ObjectOwnerID;
21 public $ModifierID;
22 public $DestinationNodeID;
23 const STATUS_VALID = 1;
24 const STATUS_DRAFT = 0;
25
26 static function definition()
27 {
28 return array( "fields" => array( "id" => array( 'name' => 'ID',
29 'datatype' => 'integer',
30 'default' => 0,
31 'required' => true ),
32 'modified' => array( 'name' => 'Modified',
33 'datatype' => 'integer',
34 'default' => 0,
35 'required' => true ),
36 'modifier_id' => array( 'name' => 'ModifierID',
37 'datatype' => 'integer',
38 'default' => 0,
39 'required' => true,
40 'foreign_class' => 'eZUser',
41 'foreign_attribute' => 'contentobject_id',
42 'multiplicity' => '1..*' ),
43 'created' => array( 'name' => 'Created',
44 'datatype' => 'integer',
45 'default' => 0,
46 'required' => true ),
47 'creator_id' => array( 'name' => 'CreatorID',
48 'datatype' => 'integer',
49 'default' => 0,
50 'required' => true,
51 'foreign_class' => 'eZUser',
52 'foreign_attribute' => 'contentobject_id',
53 'multiplicity' => '1..*' ),
54 'object_owner_id' => array( 'name' => 'ObjectOwnerID',
55 'datatype' => 'integer',
56 'default' => 0,
57 'required' => true,
58 'foreign_class' => 'eZUser',
59 'foreign_attribute' => 'contentobject_id',
60 'multiplicity' => '1..*' ),
61 'status' => array( 'name' => 'Status',
62 'datatype' => 'integer',
63 'default' => 0,
64 'required' => true ),
65 'name' => array( 'name' => 'Name',
66 'datatype' => 'string',
67 'default' => '',
68 'required' => true ),
69 'url' => array( 'name' => 'URL',
70 'datatype' => 'string',
71 'default' => '',
72 'required' => true ),
73 'destination_node_id' => array( 'name' => 'DestinationNodeID',
74 'datatype' => 'int',
75 'default' => '',
76 'required' => true,
77 'foreign_class' => 'eZContentObjectTreeNode',
78 'foreign_attribute' => 'node_id',
79 'multiplicity' => '1..*' ),
80 'class_id' => array( 'name' => 'ClassID',
81 'datatype' => 'integer',
82 'default' => 0,
83 'required' => true,
84 'foreign_class' => 'eZContentClass',
85 'foreign_attribute' => 'id',
86 'multiplicity' => '1..*' ),
87 'class_title' => array( 'name' => 'ClassTitle', // deprecated
88 'datatype' => 'string',
89 'default' => '',
90 'required' => false ),
91 'class_url' => array( 'name' => 'ClassURL', // deprecated
92 'datatype' => 'string',
93 'default' => '',
94 'required' => false ),
95 'class_description' => array( 'name' => 'ClassDescription', // deprecated
96 'datatype' => 'string',
97 'default' => '',
98 'required' => false ),
99 'active' => array( 'name' => 'Active',
100 'datatype' => 'integer',
101 'default' => 1,
102 'required' => true ),
103 'import_description' => array( 'name' => 'ImportDescriptionValue',
104 'datatype' => 'string',
105 'default' => '',
106 'required' => true ) ),
107 "keys" => array( "id", 'status' ),
108 'function_attributes' => array( 'class_attributes' => 'classAttributes',
109 'destination_path' => 'destinationPath',
110 'modifier' => 'modifier',
111 'object_owner' => 'objectOwner',
112 'import_description_array' => 'importDescription',
113 'field_map' => 'fieldMap',
114 'object_attribute_list' => 'objectAttributeList' ),
115 "increment_key" => "id",
116 "class_name" => "eZRSSImport",
117 "name" => "ezrss_import" );
118 }
119
127 static function create( $userID = false )
128 {
129 if ( $userID === false )
130 {
131 $user = eZUser::currentUser();
132 $userID = $user->attribute( "contentobject_id" );
133 }
134
135 $dateTime = time();
136 $row = array( 'id' => null,
137 'name' => ezpI18n::tr( 'kernel/rss', 'New RSS Import' ),
138 'modifier_id' => $userID,
139 'modified' => $dateTime,
140 'creator_id' => $userID,
141 'created' => $dateTime,
142 'object_owner_id' => $userID,
143 'url' => '',
144 'status' => self::STATUS_DRAFT,
145 'destination_node_id' => 0,
146 'class_id' => 0,
147 'class_title' => '',
148 'class_url' => '',
149 'class_description' => '',
150 'active' => 1 );
151
152 return new eZRSSImport( $row );
153 }
154
160 function store( $fieldFilters = null )
161 {
162 $dateTime = time();
163 $user = eZUser::currentUser();
164
165 $this->setAttribute( 'modifier_id', $user->attribute( 'contentobject_id' ) );
166 $this->setAttribute( 'modified', $dateTime );
167 parent::store( $fieldFilters );
168 }
169
176 static function fetch( $id, $asObject = true, $status = eZRSSImport::STATUS_VALID )
177 {
178 return eZPersistentObject::fetchObject( eZRSSImport::definition(),
179 null,
180 array( "id" => $id,
181 'status' => $status ),
182 $asObject );
183 }
184
189 static function fetchList( $asObject = true, $status = eZRSSImport::STATUS_VALID )
190 {
191 $cond = null;
192 if ( $status !== false )
193 {
194 $cond = array( 'status' => $status );
195 }
196 return eZPersistentObject::fetchObjectList( eZRSSImport::definition(),
197 null, $cond, null, null,
198 $asObject );
199 }
200
205 static function fetchActiveList( $asObject = true )
206 {
207 return eZPersistentObject::fetchObjectList( eZRSSImport::definition(),
208 null,
209 array( 'status' => self::STATUS_VALID,
210 'active' => 1 ),
211 null,
212 null,
213 $asObject );
214 }
215
216
217 function objectOwner()
218 {
219 if ( isset( $this->ObjectOwnerID ) and $this->ObjectOwnerID )
220 {
221 return eZUser::fetch( $this->ObjectOwnerID );
222 }
223 return null;
224 }
225
226 function modifier()
227 {
228 if ( isset( $this->ModifierID ) and $this->ModifierID )
229 {
230 return eZUser::fetch( $this->ModifierID );
231 }
232 return null;
233 }
234
235 function classAttributes()
236 {
237 if ( isset( $this->ClassID ) and $this->ClassID )
238 {
239 $contentClass = eZContentClass::fetch( $this->ClassID );
240 if ( $contentClass )
241 {
242 return $contentClass->fetchAttributes();
243 }
244 }
245 return null;
246 }
247
248 function destinationPath()
249 {
250 $retValue = null;
251 if ( isset( $this->DestinationNodeID ) and $this->DestinationNodeID )
252 {
253 $objectNode = eZContentObjectTreeNode::fetch( $this->DestinationNodeID );
254 if ( isset( $objectNode ) )
255 {
256 $path_array = $objectNode->attribute( 'path_array' );
257 $path_array_count = count( $path_array );
258 for ( $i = 0; $i < $path_array_count; ++$i )
259 {
260 $treenode = eZContentObjectTreeNode::fetch( $path_array[$i], false, false );
261 if ( is_array( $treenode ) && array_key_exists( 'name', $treenode ) )
262 {
263 if ( $i == 0 )
264 {
265 $retValue = $treenode['name'];
266 }
267 else
268 {
269 $retValue .= '/' . $treenode['name'];
270 }
271 }
272 }
273 }
274 }
275 return $retValue;
276 }
277
286 static function getRSSVersion( $url )
287 {
288 $xmlData = eZHTTPTool::getDataByURL( $url );
289
290 if ( $xmlData === false )
291 return false;
292
293 // Create DomDocument from http data
294
295 $domDocument = new DOMDocument( '1.0', 'utf-8' );
296 $success = $domDocument->loadXML( $xmlData );
297
298 if ( !$success )
299 {
300 return false;
301 }
302
303 $root = $domDocument->documentElement;
304
305 switch( $root->getAttribute( 'version' ) )
306 {
307 default:
308 case '1.0':
309 {
310 return '1.0';
311 } break;
312
313 case '0.91':
314 case '0.92':
315 case '2.0':
316 {
317 return $root->getAttribute( 'version' );
318 } break;
319 }
320 }
321
326 static function objectAttributeList()
327 {
328 return array( 'published' => 'Published',
329 'modified' => 'Modified' );
330 }
331
341 static function rssFieldDefinition( $version = '2.0' )
342 {
343 switch ( $version )
344 {
345 case '1.0':
346 {
347 return array( 'item' => array( 'attributes' => array( 'about' ),
348 'elements' => array( 'title',
349 'link',
350 'description' ) ),
351 'channel' => array( 'attributes' => array( 'about' ),
352 'elements' => array( 'title',
353 'link',
354 'description'.
355 'image' => array( 'attributes' => array( 'resource' ) ) ) ) );
356 } break;
357
358 case '2.0':
359 case '0.91':
360 case '0.92':
361 {
362 return array( 'item' => array( 'elements' => array( 'title',
363 'link',
364 'description',
365 'author',
366 'category',
367 'comments',
368 'guid',
369 'pubDate' ) ),
370 'channel' => array( 'elements' => array( 'title',
371 'link',
372 'description',
373 'copyright',
374 'managingEditor',
375 'webMaster',
376 'pubDate',
377 'lastBuildDate',
378 'category',
379 'generator',
380 'docs',
381 'cloud',
382 'ttl' ) ) );
383 }
384 }
385 }
386
394 static function fieldMap( $version = '2.0' )
395 {
396 $fieldDefinition = eZRSSImport::rssFieldDefinition();
397
398 $ini = eZINI::instance();
399 foreach( $ini->variable( 'RSSSettings', 'ActiveExtensions' ) as $activeExtension )
400 {
401 if ( file_exists( eZExtension::baseDirectory() . '/' . $activeExtension . '/rss/' . $activeExtension . 'rssimport.php' ) )
402 {
403 include_once( eZExtension::baseDirectory() . '/' . $activeExtension . '/rss/' . $activeExtension . 'rssimport.php' );
404 $fieldDefinition = eZRSSImport::arrayMergeRecursive( $fieldDefinition, call_user_func( array( $activeExtension . 'rssimport', 'rssFieldDefinition' ), array() ) );
405 }
406 }
407
408 $returnArray = array();
409 eZRSSImport::recursiveFieldMap( $fieldDefinition, '', '', $returnArray, 0 );
410
411 return $returnArray;
412 }
413
421 static function recursiveFieldMap( $definitionArray, $globalKey, $value, &$returnArray, $count )
422 {
423 foreach( $definitionArray as $key => $definition )
424 {
425 if ( is_string( $definition ) )
426 {
427 $returnArray[$globalKey . ' - ' . $definition ] = $value . ' - ' . ucfirst( $definition );
428 }
429 else
430 {
431 eZRSSImport::recursiveFieldMap( $definition,
432 $globalKey . ( strlen( $globalKey ) ? ' - ' : '' ) . $key ,
433 $value . ( strlen( $value ) && ( $count % 2 == 0 ) ? ' - ' : '' ) . ( $count % 2 == 0 ? ucfirst( $key ) : '' ),
434 $returnArray, $count + 1 );
435 }
436 }
437 }
438
448 function setImportDescription( $definition = array() )
449 {
450 $this->setAttribute( 'import_description', serialize( $definition ) );
451 }
452
458 function importDescription()
459 {
460 $description = @unserialize( $this->attribute( 'import_description' ) );
461 if ( !$description )
462 {
463 $description = array();
464 }
465 return $description;
466 }
467
468 static function arrayMergeRecursive( $arr1, $arr2 )
469 {
470 if ( !is_array( $arr1 ) ||
471 !is_array( $arr2 ) )
472 {
473 return $arr2;
474 }
475 foreach ($arr2 AS $key => $value )
476 {
477 $arr1[$key] = eZRSSImport::arrayMergeRecursive( @$arr1[$key], $value);
478 }
479
480 return $arr1;
481 }
482 }
483
484 ?>
eZContentClass\fetch
static fetch( $id, $asObject=true, $version=eZContentClass::VERSION_STATUS_DEFINED, $user_id=false, $parent_id=null)
Definition: ezcontentclass.php:1116
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZExtension\baseDirectory
static baseDirectory(eZINI|null $siteINI=null)
Definition: ezextension.php:39
eZHTTPTool\getDataByURL
static getDataByURL( $url, $justCheckURL=false, $userAgent=false, $forceGetRequest=false)
Definition: ezhttptool.php:739
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\setAttribute
setAttribute( $attr, $val)
Definition: ezpersistentobject.php:1374
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZRSSImport
Handles RSS Import in eZ Publish.
Definition: ezrssimport.php:19
eZRSSImport\fetchActiveList
static fetchActiveList( $asObject=true)
Definition: ezrssimport.php:205
eZRSSImport\definition
static definition()
Definition: ezrssimport.php:26
eZRSSImport\fetchList
static fetchList( $asObject=true, $status=eZRSSImport::STATUS_VALID)
Definition: ezrssimport.php:189
eZRSSImport\destinationPath
destinationPath()
Definition: ezrssimport.php:248
eZRSSImport\$ModifierID
$ModifierID
Definition: ezrssimport.php:21
eZRSSImport\getRSSVersion
static getRSSVersion( $url)
Definition: ezrssimport.php:286
eZRSSImport\fieldMap
static fieldMap( $version='2.0')
Definition: ezrssimport.php:394
eZRSSImport\$DestinationNodeID
$DestinationNodeID
Definition: ezrssimport.php:22
eZRSSImport\objectOwner
objectOwner()
Definition: ezrssimport.php:217
eZRSSImport\STATUS_VALID
const STATUS_VALID
Definition: ezrssimport.php:23
eZRSSImport\fetch
static fetch( $id, $asObject=true, $status=eZRSSImport::STATUS_VALID)
Definition: ezrssimport.php:176
eZRSSImport\$ObjectOwnerID
$ObjectOwnerID
Definition: ezrssimport.php:20
eZRSSImport\arrayMergeRecursive
static arrayMergeRecursive( $arr1, $arr2)
Definition: ezrssimport.php:468
eZRSSImport\setImportDescription
setImportDescription( $definition=array())
Definition: ezrssimport.php:448
eZRSSImport\modifier
modifier()
Definition: ezrssimport.php:226
eZRSSImport\importDescription
importDescription()
Definition: ezrssimport.php:458
eZRSSImport\recursiveFieldMap
static recursiveFieldMap( $definitionArray, $globalKey, $value, &$returnArray, $count)
Definition: ezrssimport.php:421
eZRSSImport\rssFieldDefinition
static rssFieldDefinition( $version='2.0')
Definition: ezrssimport.php:341
eZRSSImport\classAttributes
classAttributes()
Definition: ezrssimport.php:235
eZRSSImport\objectAttributeList
static objectAttributeList()
Definition: ezrssimport.php:326
eZRSSImport\STATUS_DRAFT
const STATUS_DRAFT
Definition: ezrssimport.php:24
eZRSSImport\create
static create( $userID=false)
Definition: ezrssimport.php:127
eZRSSImport\store
store( $fieldFilters=null)
Definition: ezrssimport.php:160
eZUser\fetch
static fetch( $id, $asObject=true)
Definition: ezuser.php:351
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.