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 include_once( 'kernel/classes/ezpersistentobject.php' );
00042
00043 define( "EZ_RSSIMPORT_STATUS_VALID", 1 );
00044 define( "EZ_RSSIMPORT_STATUS_DRAFT", 0 );
00045
00046 class eZRSSImport extends eZPersistentObject
00047 {
00048
00049
00050
00051 function eZRSSImport( $row )
00052 {
00053 $this->eZPersistentObject( $row );
00054 }
00055
00056
00057
00058
00059 function definition()
00060 {
00061 return array( "fields" => array( "id" => array( 'name' => 'ID',
00062 'datatype' => 'integer',
00063 'default' => 0,
00064 'required' => true ),
00065 'modified' => array( 'name' => 'Modified',
00066 'datatype' => 'integer',
00067 'default' => 0,
00068 'required' => true ),
00069 'modifier_id' => array( 'name' => 'ModifierID',
00070 'datatype' => 'integer',
00071 'default' => 0,
00072 'required' => true,
00073 'foreign_class' => 'eZUser',
00074 'foreign_attribute' => 'contentobject_id',
00075 'multiplicity' => '1..*' ),
00076 'created' => array( 'name' => 'Created',
00077 'datatype' => 'integer',
00078 'default' => 0,
00079 'required' => true ),
00080 'creator_id' => array( 'name' => 'CreatorID',
00081 'datatype' => 'integer',
00082 'default' => 0,
00083 'required' => true,
00084 'foreign_class' => 'eZUser',
00085 'foreign_attribute' => 'contentobject_id',
00086 'multiplicity' => '1..*' ),
00087 'object_owner_id' => array( 'name' => 'ObjectOwnerID',
00088 'datatype' => 'integer',
00089 'default' => 0,
00090 'required' => true,
00091 'foreign_class' => 'eZUser',
00092 'foreign_attribute' => 'contentobject_id',
00093 'multiplicity' => '1..*' ),
00094 'status' => array( 'name' => 'Status',
00095 'datatype' => 'integer',
00096 'default' => 0,
00097 'required' => true ),
00098 'name' => array( 'name' => 'Name',
00099 'datatype' => 'string',
00100 'default' => '',
00101 'required' => true ),
00102 'url' => array( 'name' => 'URL',
00103 'datatype' => 'string',
00104 'default' => '',
00105 'required' => true ),
00106 'destination_node_id' => array( 'name' => 'DestinationNodeID',
00107 'datatype' => 'int',
00108 'default' => '',
00109 'required' => true,
00110 'foreign_class' => 'eZContentObjectTreeNode',
00111 'foreign_attribute' => 'node_id',
00112 'multiplicity' => '1..*' ),
00113 'class_id' => array( 'name' => 'ClassID',
00114 'datatype' => 'integer',
00115 'default' => 0,
00116 'required' => true,
00117 'foreign_class' => 'eZContentClass',
00118 'foreign_attribute' => 'id',
00119 'multiplicity' => '1..*' ),
00120 'class_title' => array( 'name' => 'ClassTitle',
00121 'datatype' => 'string',
00122 'default' => '',
00123 'required' => false ),
00124 'class_url' => array( 'name' => 'ClassURL',
00125 'datatype' => 'string',
00126 'default' => '',
00127 'required' => false ),
00128 'class_description' => array( 'name' => 'ClassDescription',
00129 'datatype' => 'string',
00130 'default' => '',
00131 'required' => false ),
00132 'active' => array( 'name' => 'Active',
00133 'datatype' => 'integer',
00134 'default' => 1,
00135 'required' => true ),
00136 'import_description' => array( 'name' => 'ImportDescriptionValue',
00137 'datatype' => 'string',
00138 'default' => '',
00139 'required' => true ) ),
00140 "keys" => array( "id", 'status' ),
00141 'function_attributes' => array( 'class_attributes' => 'classAttributes',
00142 'destination_path' => 'destinationPath',
00143 'modifier' => 'modifier',
00144 'object_owner' => 'objectOwner',
00145 'import_description_array' => 'importDescription',
00146 'field_map' => 'fieldMap',
00147 'object_attribute_list' => 'objectAttributeList' ),
00148 "increment_key" => "id",
00149 "class_name" => "eZRSSImport",
00150 "name" => "ezrss_import" );
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160 function create( $userID = false )
00161 {
00162 if ( $userID === false )
00163 {
00164 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00165 $user = eZUser::currentUser();
00166 $userID = $user->attribute( "contentobject_id" );
00167 }
00168
00169 $dateTime = time();
00170 $row = array( 'id' => null,
00171 'name' => ezi18n( 'kernel/rss', 'New RSS Import' ),
00172 'modifier_id' => $userID,
00173 'modified' => $dateTime,
00174 'creator_id' => $userID,
00175 'created' => $dateTime,
00176 'object_owner_id' => $userID,
00177 'url' => '',
00178 'status' => 0,
00179 'destination_node_id' => 0,
00180 'class_id' => 0,
00181 'class_title' => '',
00182 'class_url' => '',
00183 'class_description' => '',
00184 'active' => 1 );
00185
00186 return new eZRSSImport( $row );
00187 }
00188
00189
00190
00191
00192
00193
00194 function store()
00195 {
00196 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00197 $dateTime = time();
00198 $user =& eZUser::currentUser();
00199
00200 $this->setAttribute( 'modifier_id', $user->attribute( 'contentobject_id' ) );
00201 $this->setAttribute( 'modified', $dateTime );
00202 eZPersistentObject::store();
00203 }
00204
00205
00206
00207
00208
00209
00210
00211 function fetch( $id, $asObject = true, $status = EZ_RSSIMPORT_STATUS_VALID )
00212 {
00213 return eZPersistentObject::fetchObject( eZRSSImport::definition(),
00214 null,
00215 array( "id" => $id,
00216 'status' => $status ),
00217 $asObject );
00218 }
00219
00220
00221
00222
00223
00224 function fetchList( $asObject = true, $status = EZ_RSSIMPORT_STATUS_VALID )
00225 {
00226 $cond = null;
00227 if ( $status !== false )
00228 {
00229 $cond = array( 'status' => $status );
00230 }
00231 return eZPersistentObject::fetchObjectList( eZRSSImport::definition(),
00232 null, $cond, null, null,
00233 $asObject );
00234 }
00235
00236
00237
00238
00239
00240 function fetchActiveList( $asObject = true )
00241 {
00242 return eZPersistentObject::fetchObjectList( eZRSSImport::definition(),
00243 null,
00244 array( 'status' => 1,
00245 'active' => 1 ),
00246 null,
00247 null,
00248 $asObject );
00249 }
00250
00251
00252 function &objectOwner()
00253 {
00254 if ( isset( $this->ObjectOwnerID ) and $this->ObjectOwnerID )
00255 {
00256 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00257 $user = eZUser::fetch( $this->ObjectOwnerID );
00258 }
00259 else
00260 $user = null;
00261 return $user;
00262 }
00263
00264 function &modifier()
00265 {
00266 if ( isset( $this->ModifierID ) and $this->ModifierID )
00267 {
00268 include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
00269 $user = eZUser::fetch( $this->ModifierID );
00270 }
00271 else
00272 $user = null;
00273 return $user;
00274 }
00275
00276 function &classAttributes()
00277 {
00278 if ( isset( $this->ClassID ) and $this->ClassID )
00279 {
00280 include_once( 'kernel/classes/ezcontentclass.php' );
00281 $contentClass = eZContentClass::fetch( $this->ClassID );
00282 if ( $contentClass )
00283 $attributes =& $contentClass->fetchAttributes();
00284 else
00285 $attributes = null;
00286 }
00287 else
00288 $attributes = null;
00289 return $attributes;
00290 }
00291
00292 function &destinationPath()
00293 {
00294 $retValue = null;
00295 if ( isset( $this->DestinationNodeID ) and $this->DestinationNodeID )
00296 {
00297 include_once( "kernel/classes/ezcontentobjecttreenode.php" );
00298 $objectNode = eZContentObjectTreeNode::fetch( $this->DestinationNodeID );
00299 if ( isset( $objectNode ) )
00300 {
00301 $path_array =& $objectNode->attribute( 'path_array' );
00302 $path_array_count = count( $path_array );
00303 for ( $i = 0; $i < $path_array_count; ++$i )
00304 {
00305 $treenode = eZContentObjectTreeNode::fetch( $path_array[$i], false, false );
00306 if ( is_array( $treenode ) && array_key_exists( 'name', $treenode ) )
00307 {
00308 if ( $i == 0 )
00309 {
00310 $retValue = $treenode['name'];
00311 }
00312 else
00313 {
00314 $retValue .= '/' . $treenode['name'];
00315 }
00316 }
00317 }
00318 }
00319 }
00320 return $retValue;
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 function getRSSVersion( $url )
00332 {
00333 include_once( "lib/ezutils/classes/ezhttptool.php" );
00334 $xmlData = eZHTTPTool::getDataByURL( $url );
00335
00336 if ( $xmlData === false )
00337 return false;
00338
00339 include_once( 'lib/ezxml/classes/ezxml.php' );
00340
00341 $xmlObject = new eZXML();
00342 $domDocument = $xmlObject->domTree( $xmlData );
00343
00344 if ( $domDocument == null or $domDocument === false )
00345 {
00346 return false;
00347 }
00348
00349 $root = $domDocument->root();
00350
00351 if ( $root == null )
00352 {
00353 return false;
00354 }
00355
00356 switch( $root->attributeValue( 'version' ) )
00357 {
00358 default:
00359 case '1.0':
00360 {
00361 return '1.0';
00362 } break;
00363
00364 case '0.91':
00365 case '0.92':
00366 case '2.0':
00367 {
00368 return $root->attributeValue( 'version' );
00369 } break;
00370 }
00371 }
00372
00373
00374
00375
00376
00377 function &objectAttributeList()
00378 {
00379 $objectAttributeList = array( 'published' => 'Published',
00380 'modified' => 'Modified' );
00381 return $objectAttributeList;
00382 }
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393 function rssFieldDefinition( $version = '2.0' )
00394 {
00395 switch ( $version )
00396 {
00397 case '1.0':
00398 {
00399 return array( 'item' => array( 'attributes' => array( 'about' ),
00400 'elements' => array( 'title',
00401 'link',
00402 'description' ) ),
00403 'channel' => array( 'attributes' => array( 'about' ),
00404 'elements' => array( 'title',
00405 'link',
00406 'description'.
00407 'image' => array( 'attributes' => array( 'resource' ) ) ) ) );
00408 } break;
00409
00410 case '2.0':
00411 case '0.91':
00412 case '0.92':
00413 {
00414 return array( 'item' => array( 'elements' => array( 'title',
00415 'link',
00416 'description',
00417 'author',
00418 'category',
00419 'comments',
00420 'guid',
00421 'pubDate' ) ),
00422 'channel' => array( 'elements' => array( 'title',
00423 'link',
00424 'description',
00425 'copyright',
00426 'managingEditor',
00427 'webMaster',
00428 'pubDate',
00429 'lastBuildDate',
00430 'category',
00431 'generator',
00432 'docs',
00433 'cloud',
00434 'ttl' ) ) );
00435 }
00436 }
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446 function &fieldMap( $version = '2.0' )
00447 {
00448 $fieldDefinition = eZRSSImport::rssFieldDefinition();
00449
00450 $ini = eZINI::instance();
00451 foreach( $ini->variable( 'RSSSettings', 'ActiveExtensions' ) as $activeExtension )
00452 {
00453 if ( file_exists( eZExtension::baseDirectory() . '/' . $activeExtension . '/rss/' . $activeExtension . 'rssimport.php' ) )
00454 {
00455 include_once( eZExtension::baseDirectory() . '/' . $activeExtension . '/rss/' . $activeExtension . 'rssimport.php' );
00456 $fieldDefinition = eZRSSImport::arrayMergeRecursive( $fieldDefinition, call_user_func( array( $activeExtension . 'rssimport', 'rssFieldDefinition' ), array() ) );
00457 }
00458 }
00459
00460 $returnArray = array();
00461 eZRSSImport::recursiveFieldMap( $fieldDefinition, '', '', $returnArray, 0 );
00462
00463 return $returnArray;
00464 }
00465
00466
00467
00468
00469
00470
00471
00472
00473 function recursiveFieldMap( $definitionArray, $globalKey, $value, &$returnArray, $count )
00474 {
00475 foreach( $definitionArray as $key => $definition )
00476 {
00477 if ( is_string( $definition ) )
00478 {
00479 $returnArray[$globalKey . ' - ' . $definition ] = $value . ' - ' . ucfirst( $definition );
00480 }
00481 else
00482 {
00483 eZRSSImport::recursiveFieldMap( $definition,
00484 $globalKey . ( strlen( $globalKey ) ? ' - ' : '' ) . $key ,
00485 $value . ( strlen( $value ) && ( $count % 2 == 0 ) ? ' - ' : '' ) . ( $count % 2 == 0 ? ucfirst( $key ) : '' ),
00486 $returnArray, $count + 1 );
00487 }
00488 }
00489 }
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500 function setImportDescription( $definition = array() )
00501 {
00502 $this->setAttribute( 'import_description', serialize( $definition ) );
00503 }
00504
00505
00506
00507
00508
00509
00510 function &importDescription()
00511 {
00512 $description = @unserialize( $this->attribute( 'import_description' ) );
00513 if ( !$description )
00514 {
00515 $description = array();
00516 }
00517 return $description;
00518 }
00519
00520 function arrayMergeRecursive( $arr1, $arr2 )
00521 {
00522 if ( !is_array( $arr1 ) ||
00523 !is_array( $arr2 ) )
00524 {
00525 return $arr2;
00526 }
00527 foreach ($arr2 AS $key => $value )
00528 {
00529 $arr1[$key] = eZRSSImport::arrayMergeRecursive( @$arr1[$key], $value);
00530 }
00531
00532 return $arr1;
00533 }
00534 }
00535
00536 ?>