PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/kernel/classes/ezdatatype.php

https://github.com/granitegreg/ezpublish
PHP | 1493 lines | 717 code | 121 blank | 655 comment | 60 complexity | 65df9c79c3fb12f553278322625a3ec5 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. //
  3. // Definition of eZDataType class
  4. //
  5. // Created on: <16-Apr-2002 11:08:14 amos>
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2011 eZ Systems AS
  11. // SOFTWARE LICENSE: GNU General Public License v2.0
  12. // NOTICE: >
  13. // This program is free software; you can redistribute it and/or
  14. // modify it under the terms of version 2.0 of the GNU General
  15. // Public License as published by the Free Software Foundation.
  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 version 2.0 of the GNU General
  23. // Public License along with this program; if not, write to the Free
  24. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. // MA 02110-1301, USA.
  26. //
  27. //
  28. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. /*! \defgroup eZDataType Content datatypes */
  31. /*!
  32. \class eZDataType ezdatatype.php
  33. \ingroup eZKernel
  34. \brief Base class for content datatypes
  35. Defines both the interface for datatypes as well as functions
  36. for registering, quering and fetching datatypes.
  37. Each new datatype will inherit this class and define some functions
  38. as well as three templates. A datatype has three roles, it handles
  39. definition of content class attributes, editing of a content object
  40. attribute and viewing of a content object attribute. The content class
  41. attribute definition part is optional while object attribute edit and
  42. view must be implemented for the datatype to be usable.
  43. If the datatype handles class attribute definition it must define one
  44. or more of these functions: storeClassAttribute, validateClassAttributeHTTPInput,
  45. fixupClassAttributeHTTPInput, fetchClassAttributeHTTPInput. See each function
  46. for more details. The class attribute definition usually defines the
  47. default data and/or the validation rules for an object attribute.
  48. Object attribute editing must define these functions: storeObjectAttribute,
  49. validateObjectAttributeHTTPInput, fixupObjectAttributeHTTPInput,
  50. fetchObjectAttributeHTTPInput, initializeObjectAttribute. If the attribute
  51. wants to have a custom action it must implement the customObjectAttributeHTTPAction
  52. function. See each function for more details.
  53. Each datatype initializes itself with a datatype string id (ezstring, ezinteger)
  54. and a descriptive name. The datatype string id must be unique for the whole
  55. system and should have a prefix, for instance we in eZ Systems use ez as our prefix.
  56. */
  57. class eZDataType
  58. {
  59. /*!
  60. Initializes the datatype with the string id \a $dataTypeString and
  61. the name \a $name.
  62. */
  63. function eZDataType( $dataTypeString, $name, $properties = array() )
  64. {
  65. $this->DataTypeString = $dataTypeString;
  66. $this->Name = $name;
  67. $translationAllowed = true;
  68. $serializeSupported = false;
  69. $objectSerializeMap = false;
  70. if ( isset( $properties['translation_allowed'] ) )
  71. $translationAllowed = $properties['translation_allowed'];
  72. if ( isset( $properties['serialize_supported'] ) )
  73. $serializeSupported = $properties['serialize_supported'];
  74. if ( isset( $properties['object_serialize_map'] ) )
  75. $objectSerializeMap = $properties['object_serialize_map'];
  76. $this->Attributes = array();
  77. $this->Attributes["is_indexable"] = $this->isIndexable();
  78. $this->Attributes["is_information_collector"] = $this->isInformationCollector();
  79. $this->Attributes["information"] = array( "string" => $this->DataTypeString,
  80. "name" => $this->Name );
  81. $this->Attributes["properties"] = array( "translation_allowed" => $translationAllowed,
  82. 'serialize_supported' => $serializeSupported,
  83. 'object_serialize_map' => $objectSerializeMap );
  84. }
  85. /*!
  86. \return the template name to use for viewing the attribute.
  87. \note Default is to return the datatype string which is OK
  88. for most datatypes, if you want dynamic templates
  89. reimplement this function and return a template name.
  90. \note The returned template name does not include the .tpl extension.
  91. \sa editTemplate, informationTemplate
  92. */
  93. function viewTemplate( $contentobjectAttribute )
  94. {
  95. return $this->DataTypeString;
  96. }
  97. /*!
  98. \return the template name to use for editing the attribute.
  99. \note Default is to return the datatype string which is OK
  100. for most datatypes, if you want dynamic templates
  101. reimplement this function and return a template name.
  102. \note The returned template name does not include the .tpl extension.
  103. \sa viewTemplate, informationTemplate
  104. */
  105. function editTemplate( $contentobjectAttribute )
  106. {
  107. return $this->DataTypeString;
  108. }
  109. /*!
  110. \return the template name to use for information collection for the attribute.
  111. \note Default is to return the datatype string which is OK
  112. for most datatypes, if you want dynamic templates
  113. reimplement this function and return a template name.
  114. \note The returned template name does not include the .tpl extension.
  115. \sa viewTemplate, editTemplate
  116. */
  117. function informationTemplate( $contentobjectAttribute )
  118. {
  119. return $this->DataTypeString;
  120. }
  121. /*!
  122. \return the template name to use for result view of an information collection attribute.
  123. \note Default is to return the datatype string which is OK
  124. for most datatypes, if you want dynamic templates
  125. reimplement this function and return a template name.
  126. \note The returned template name does not include the .tpl extension.
  127. \note \a $collectionAttribute can in some cases be a eZContentObjectAttribute, so any
  128. datatype that overrides this must be able to handle both types.
  129. */
  130. function resultTemplate( &$collectionAttribute )
  131. {
  132. return $this->DataTypeString;
  133. }
  134. /*!
  135. \static
  136. Crates a datatype instance of the datatype string id \a $dataTypeString.
  137. \note It only creates one instance for each datatype.
  138. */
  139. static function create( $dataTypeString )
  140. {
  141. $def = null;
  142. if ( !isset( $GLOBALS["eZDataTypes"][$dataTypeString] ) )
  143. {
  144. eZDataType::loadAndRegisterType( $dataTypeString );
  145. }
  146. if ( isset( $GLOBALS['eZDataTypes'][$dataTypeString] ) )
  147. {
  148. $className = $GLOBALS['eZDataTypes'][$dataTypeString];
  149. if ( !isset( $GLOBALS["eZDataTypeObjects"][$dataTypeString] ) ||
  150. get_class( $GLOBALS["eZDataTypeObjects"][$dataTypeString] ) != $className )
  151. {
  152. $GLOBALS["eZDataTypeObjects"][$dataTypeString] = new $className();
  153. }
  154. return $GLOBALS["eZDataTypeObjects"][$dataTypeString];
  155. }
  156. return null;
  157. }
  158. /*!
  159. \static
  160. \return a list of datatypes which has been registered.
  161. \note This will instantiate all datatypes.
  162. */
  163. static function registeredDataTypes()
  164. {
  165. $types = isset( $GLOBALS["eZDataTypes"] ) ? $GLOBALS["eZDataTypes"] : null;
  166. if ( isset( $types ) )
  167. {
  168. foreach ( $types as $dataTypeString => $className )
  169. {
  170. if ( !isset( $GLOBALS["eZDataTypeObjects"][$dataTypeString] ) )
  171. {
  172. $GLOBALS["eZDataTypeObjects"][$dataTypeString] = new $className();
  173. }
  174. }
  175. uasort( $GLOBALS["eZDataTypeObjects"],
  176. create_function( '$a, $b',
  177. 'return strcmp( $a->Name, $b->Name);' ) );
  178. return $GLOBALS["eZDataTypeObjects"];
  179. }
  180. return null;
  181. }
  182. /*!
  183. \static
  184. Registers the datatype with string id \a $dataTypeString and
  185. class name \a $className. The class name is used for instantiating
  186. the class and should be in lowercase letters.
  187. */
  188. static function register( $dataTypeString, $className )
  189. {
  190. $types =& $GLOBALS["eZDataTypes"];
  191. if ( !is_array( $types ) )
  192. $types = array();
  193. $types[$dataTypeString] = $className;
  194. }
  195. /*!
  196. \return the data type identification string.
  197. */
  198. function isA()
  199. {
  200. return $this->Attributes["information"]["string"];
  201. }
  202. /**
  203. * Indicates if datatype supports being translated
  204. *
  205. * @return bool
  206. */
  207. function isTranslatable()
  208. {
  209. return $this->Attributes['properties']['translation_allowed'];
  210. }
  211. /*!
  212. \return the attributes for this datatype.
  213. */
  214. function attributes()
  215. {
  216. return array_keys( $this->Attributes );
  217. }
  218. /*!
  219. \return true if the attribute \a $attr exists in this object.
  220. */
  221. function hasAttribute( $attr )
  222. {
  223. return isset( $this->Attributes[$attr] );
  224. }
  225. /*!
  226. \return the data for the attribute \a $attr or null if it does not exist.
  227. */
  228. function attribute( $attr )
  229. {
  230. if ( isset( $this->Attributes[$attr] ) )
  231. {
  232. return $this->Attributes[$attr];
  233. }
  234. eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ );
  235. $attributeData = null;
  236. return $attributeData;
  237. }
  238. /*!
  239. \return \c true if the datatype support insertion of HTTP files or \c false (default) otherwise.
  240. \sa insertHTTPFile()
  241. */
  242. function isHTTPFileInsertionSupported()
  243. {
  244. return false;
  245. }
  246. /*!
  247. \return \c true if the datatype support insertion of files or \c false (default) otherwise.
  248. \sa insertRegularFile()
  249. */
  250. function isRegularFileInsertionSupported()
  251. {
  252. return false;
  253. }
  254. /*!
  255. \return \c true if the datatype support insertion of simple strings or \c false (default) otherwise.
  256. \sa insertSimpleString()
  257. */
  258. function isSimpleStringInsertionSupported()
  259. {
  260. return false;
  261. }
  262. /*!
  263. \virtual
  264. Inserts the HTTP file \a $httpFile to the content object attribute \a $objectAttribute.
  265. \param $object The contentobject in which the attribute is contained
  266. \param $objectVersion The current version of the object it is being worked on
  267. \param $objectLanguage The current language being worked on
  268. \param $objectAttribute The attribute which will get the file
  269. \param $httpFile Object of type eZHTTPFile which contains information on the uploaded file
  270. \param $mimeData MIME-Type information on the file, can be used to figure out a storage name
  271. \param[out] $result Array which will be filled with information on the process, it will contain:
  272. - errors - Array with error elements, each element is an array with \c 'description' containing the text
  273. - require_storage - \c true if the attribute must be stored after this call, or \c false if not required at all
  274. \return \c true if the file was stored correctly in the attribute or \c false if something failed.
  275. \note The datatype will return \c null (the default) if does not support HTTP files.
  276. \note \a $result will not be defined if the return value is \c null
  277. \note The \a $httpFile must not be stored prior to calling this, the datatype will handle this internally
  278. \sa isHTTPFileInsertionSupported()
  279. */
  280. function insertHTTPFile( $object, $objectVersion, $objectLanguage,
  281. $objectAttribute, $httpFile, $mimeData,
  282. &$result )
  283. {
  284. eZDebug::writeWarning( "The datatype " . get_class( $this ) . " for attribute ID " . $objectAttribute->attribute( 'id' ) . " does not support insertion of HTTP files", __METHOD__ );
  285. return null;
  286. }
  287. /*!
  288. \virtual
  289. Inserts the file named \a $filePath to the content object attribute \a $objectAttribute.
  290. \param $object The contentobject in which the attribute is contained
  291. \param $objectVersion The current version of the object it is being worked on
  292. \param $objectLanguage The current language being worked on
  293. \param $objectAttribute The attribute which will get the file
  294. \param $filePath Full path including the filename
  295. \param[out] $result Array which will be filled with information on the process, it will contain:
  296. - errors - Array with error elements, each element is an array with \c 'description' containing the text
  297. - require_storage - \c true if the attribute must be stored after this call, or \c false if not required at all
  298. \return \c true if the file was stored correctly in the attribute or \c false if something failed.
  299. \note The datatype will return \c null (the default) if does not support HTTP files.
  300. \note \a $result will not be defined if the return value is \c null
  301. \sa isRegularFileInsertionSupported()
  302. */
  303. function insertRegularFile( $object, $objectVersion, $objectLanguage,
  304. $objectAttribute, $filePath,
  305. &$result )
  306. {
  307. eZDebug::writeWarning( "The datatype " . get_class( $this ) . " for attribute ID " . $objectAttribute->attribute( 'id' ) . " does not support insertion of regular files", __METHOD__ );
  308. return null;
  309. }
  310. /*!
  311. \virtual
  312. Inserts the string \a $string to the content object attribute \a $objectAttribute.
  313. \param $object The contentobject in which the attribute is contained
  314. \param $objectVersion The current version of the object it is being worked on
  315. \param $objectLanguage The current language being worked on
  316. \param $objectAttribute The attribute which will get the file
  317. \param $filePath Full path including the filename
  318. \param[out] $result Array which will be filled with information on the process, it will contain:
  319. - errors - Array with error elements, each element is an array with \c 'description' containing the text
  320. - require_storage - \c true if the attribute must be stored after this call, or \c false if not required at all
  321. \return \c true if the file was stored correctly in the attribute or \c false if something failed.
  322. \note The datatype will return \c null (the default) if does not support HTTP files.
  323. \note \a $result will not be defined if the return value is \c null
  324. \sa isSimpleStringInsertionSupported()
  325. */
  326. function insertSimpleString( $object, $objectVersion, $objectLanguage,
  327. $objectAttribute, $string,
  328. &$result )
  329. {
  330. eZDebug::writeWarning( "The datatype " . get_class( $this ) . " for attribute ID " . $objectAttribute->attribute( 'id' ) . " does not support insertion of simple strings", __METHOD__ );
  331. return null;
  332. }
  333. /*!
  334. \virtual
  335. Checks if the datatype supports returning file information.
  336. \param $object The contentobject in which the attribute is contained
  337. \param $objectVersion The current version of the object it is being worked on
  338. \param $objectLanguage The current language being worked on
  339. \param $objectAttribute The attribute which stored the file
  340. \return \c true if file information is supported or \c false if it doesn't.
  341. */
  342. function hasStoredFileInformation( $object, $objectVersion, $objectLanguage,
  343. $objectAttribute )
  344. {
  345. return false;
  346. }
  347. /*!
  348. \virtual
  349. This function is called when someone tries to download the file.
  350. \param $object The contentobject in which the attribute is contained
  351. \param $objectVersion The current version of the object it is being worked on
  352. \param $objectLanguage The current language being worked on
  353. \param $objectAttribute The attribute which stored the file
  354. \return \c true if any action has been don or \c false if hasn't.
  355. */
  356. function handleDownload( $object, $objectVersion, $objectLanguage,
  357. $objectAttribute )
  358. {
  359. return false;
  360. }
  361. /*!
  362. \virtual
  363. Returns file information for the filed stored by the attribute.
  364. \param $object The contentobject in which the attribute is contained
  365. \param $objectVersion The current version of the object it is being worked on
  366. \param $objectLanguage The current language being worked on
  367. \param $objectAttribute The attribute which stored the file
  368. \return An array structure with information or \c false (default) if no
  369. information could be found.
  370. The structure must contain:
  371. - filepath - The full path to the file
  372. The structure can contain:
  373. - filename - The name of the file, if not supplied it will
  374. be figured out from the filepath
  375. - filesize - The size of the file, if not supplied it will
  376. be figured out from the filepath
  377. - mime_type - The MIME type for the file, if not supplied it will
  378. be figured out from the filepath
  379. */
  380. function storedFileInformation( $object, $objectVersion, $objectLanguage,
  381. $objectAttribute )
  382. {
  383. return false;
  384. }
  385. /*!
  386. Fetches the product option information for option with ID \a $optionID and returns this information.
  387. This will be called from the basket when a new product with an option is added, it is then up to the
  388. specific datatype to return proper data. It will also be used to recalcuate prices.
  389. \param $objectAttribute The attribute that the datatype controls.
  390. \param $optionID The ID of the option which information should be returned from.
  391. \param $productItem The product item object which contains the option, is available for reading only.
  392. \return An array structure which contains:
  393. - id - The unique ID of the selected option, this must be unique in the attribute and will later on
  394. be used to recalculate prices.
  395. - name - The name of the option list
  396. - value - The display string of the selected option
  397. - additional_price - A value which is added to the total product price, set to 0 or \c false if no price is used.
  398. If the option could not be found it should return \c false, if not supported it should return \c null.
  399. \sa handleProductOption
  400. */
  401. function productOptionInformation( $objectAttribute, $optionID, $productItem )
  402. {
  403. eZDebug::writeWarning( "The datatype " . get_class( $this ) . " for attribute ID " . $objectAttribute->attribute( 'id' ) . " does not support product options", __METHOD__ );
  404. return null;
  405. }
  406. /*!
  407. \virtual
  408. Will return information on how the datatype should be represented in
  409. the various display modes when used by an object.
  410. If this method is reimplemented the implementor must call this method
  411. with the new info array as second parameter.
  412. \param $objectAttribute The content object attribute to return info for.
  413. \param $mergeInfo A structure that must match the returned array, or \c false to ignore.
  414. Any entries here will override the default.
  415. \return An array structure which contains:
  416. - \c edit
  417. - \c grouped_input - If \c true then the datatype has lots of input elements
  418. that should be grouped. (e.g. in a fieldset)
  419. EditSettings/GroupedInput in datatype.ini is used to
  420. automatically determine this field
  421. .
  422. - \c view
  423. - \c collection
  424. - \c grouped_input - If \c true then the datatype has lots of input elements
  425. that should be grouped. (e.g. in a fieldset)
  426. CollectionSettings/GroupedInput in datatype.ini is used to
  427. automatically determine this field and will override
  428. the default and datatype setting if used.
  429. .
  430. - \c result
  431. */
  432. function objectDisplayInformation( $objectAttribute, $mergeInfo = false )
  433. {
  434. $datatype = $objectAttribute->attribute( 'data_type_string' );
  435. $ini = eZINI::instance( 'datatype.ini' );
  436. $editGrouped = in_array( $datatype, $ini->variable( 'EditSettings', 'GroupedInput' ) );
  437. $viewGrouped = in_array( $datatype, $ini->variable( 'ViewSettings', 'GroupedInput' ) );
  438. $resultGrouped = in_array( $datatype, $ini->variable( 'ResultSettings', 'GroupedInput' ) );
  439. $collectionGrouped = in_array( $datatype, $ini->variable( 'CollectionSettings', 'GroupedInput' ) );
  440. $info = array( 'edit' => array( 'grouped_input' => false ),
  441. 'view' => array( 'grouped_input' => false),
  442. 'collection' => array( 'grouped_input' => false ),
  443. 'result' => array( 'grouped_input' => false ) );
  444. $override = array();
  445. if ( $editGrouped )
  446. $override['edit']['grouped_input'] = true;
  447. if ( $collectionGrouped )
  448. $override['collection']['grouped_input'] = true;
  449. if ( $viewGrouped )
  450. $override['view']['grouped_input'] = true;
  451. if ( $resultGrouped )
  452. $override['result']['grouped_input'] = true;
  453. if ( $mergeInfo )
  454. {
  455. // All entries in $mergeInfo will override the defaults
  456. foreach ( array( 'edit', 'view', 'collection', 'result' ) as $view )
  457. {
  458. if ( isset( $mergeInfo[$view] ) )
  459. $info[$view] = array_merge( $info[$view], $mergeInfo[$view] );
  460. if ( isset( $override[$view] ) )
  461. $info[$view] = array_merge( $info[$view], $override[$view] );
  462. }
  463. }
  464. else
  465. {
  466. // All entries in $override will override the defaults
  467. foreach ( array( 'edit', 'view', 'collection', 'result' ) as $view )
  468. {
  469. if ( isset( $override[$view] ) )
  470. $info[$view] = array_merge( $info[$view], $override[$view] );
  471. }
  472. }
  473. return $info;
  474. }
  475. /*!
  476. \virtual
  477. Will return information on how the datatype should be represented in
  478. the various display modes when used by a class.
  479. If this method is reimplemented the implementor must call this method
  480. with the new info array as second parameter.
  481. \param $classAttribute The content class attribute to return info for.
  482. \param $mergeInfo A structure that must match the returned array, or \c false to ignore.
  483. Any entries here will override the default.
  484. \return An array structure which contains:
  485. - \c edit
  486. - \c grouped_input - If \c true then the datatype has lots of input elements
  487. that should be grouped. (e.g. in a fieldset)
  488. ClassEditSettings/GroupedInput in datatype.ini is used to
  489. automatically determine this field and will override
  490. the default and datatype setting if used.
  491. .
  492. - \c view
  493. */
  494. function classDisplayInformation( $classAttribute, $mergeInfo = false )
  495. {
  496. $datatype = $classAttribute->attribute( 'data_type_string' );
  497. $ini = eZINI::instance( 'datatype.ini' );
  498. $editGrouped = in_array( $datatype, $ini->variable( 'ClassEditSettings', 'GroupedInput' ) );
  499. $info = array( 'edit' => array( 'grouped_input' => false ),
  500. 'view' => array() );
  501. $override = array();
  502. if ( $editGrouped )
  503. $override['edit']['grouped_input'] = true;
  504. if ( $mergeInfo )
  505. {
  506. // All entries in $mergeInfo will override the defaults
  507. foreach ( array( 'edit', 'view' ) as $view )
  508. {
  509. if ( isset( $mergeInfo[$view] ) )
  510. $info[$view] = array_merge( $info[$view], $mergeInfo[$view] );
  511. if ( isset( $override[$view] ) )
  512. $info[$view] = array_merge( $info[$view], $override[$view] );
  513. }
  514. }
  515. else
  516. {
  517. // All entries in $override will override the defaults
  518. foreach ( array( 'edit', 'view' ) as $view )
  519. {
  520. if ( isset( $override[$view] ) )
  521. $info[$view] = array_merge( $info[$view], $override[$view] );
  522. }
  523. }
  524. return $info;
  525. }
  526. /*!
  527. Returns the content data for the given content object attribute.
  528. */
  529. function objectAttributeContent( $objectAttribute )
  530. {
  531. $retValue = '';
  532. return $retValue;
  533. }
  534. /*!
  535. \return \c true if the datatype finds any content in the attribute \a $contentObjectAttribute.
  536. */
  537. function hasObjectAttributeContent( $contentObjectAttribute )
  538. {
  539. return false;
  540. }
  541. /*!
  542. Returns the content data for the given content class attribute.
  543. */
  544. function classAttributeContent( $classAttribute )
  545. {
  546. return '';
  547. }
  548. /*!
  549. Stores the datatype data to the database which is related to the
  550. object attribute.
  551. \return True if the value was stored correctly.
  552. \note The method is entirely up to the datatype, for instance
  553. it could reuse the available types in the the attribute or
  554. store in a separate object.
  555. \sa fetchObjectAttributeHTTPInput
  556. */
  557. function storeObjectAttribute( $objectAttribute )
  558. {
  559. }
  560. /*!
  561. Performs necessary actions with attribute data after object is published,
  562. it means that you have access to published nodes.
  563. \return True if the value was stored correctly.
  564. \note The method is entirely up to the datatype, for instance
  565. it could reuse the available types in the the attribute or
  566. store in a separate object.
  567. \note Might be transaction unsafe.
  568. */
  569. function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes )
  570. {
  571. }
  572. /*!
  573. Similar to the storeClassAttribute but is called before the
  574. attribute itself is stored and can be used to set values in the
  575. class attribute.
  576. \return True if the value was stored correctly.
  577. \sa fetchClassAttributeHTTPInput
  578. */
  579. function preStoreClassAttribute( $classAttribute, $version )
  580. {
  581. }
  582. /*!
  583. Stores the datatype data to the database which is related to the
  584. class attribute. The \a $version parameter determines which version
  585. is currently being stored, 0 is the real version while 1 is the
  586. temporary version.
  587. \return True if the value was stored correctly.
  588. \note The method is entirely up to the datatype, for instance
  589. it could reuse the available types in the the attribute or
  590. store in a separate object.
  591. \note This function is called after the attribute data has been stored.
  592. If you need to alter attribute data use preStoreClassAttribute instead.
  593. \sa fetchClassAttributeHTTPInput
  594. */
  595. function storeClassAttribute( $classAttribute, $version )
  596. {
  597. }
  598. /**
  599. * @note Transaction unsafe. If you call several transaction unsafe methods you must enclose
  600. * the calls within a db transaction; thus within db->begin and db->commit.
  601. *
  602. * @param eZContentClassAttribute $classAttribute Content class attribute of the datatype
  603. */
  604. function storeDefinedClassAttribute( $classAttribute )
  605. {
  606. }
  607. /**
  608. * @note Transaction unsafe. If you call several transaction unsafe methods you must enclose
  609. * the calls within a db transaction; thus within db->begin and db->commit.
  610. * @param eZContentClassAttribute $classAttribute Content class attribute of the datatype
  611. */
  612. function storeModifiedClassAttribute( $classAttribute )
  613. {
  614. }
  615. /**
  616. * @note Transaction unsafe. If you call several transaction unsafe methods you must enclose
  617. * the calls within a db transaction; thus within db->begin and db->commit.
  618. * @param eZContentClassAttribute $classAttribute Content class attribute of the datatype
  619. * @param int $version Version of the attribute to be stored
  620. */
  621. function storeVersionedClassAttribute( $classAttribute, $version )
  622. {
  623. switch ( $version )
  624. {
  625. case eZContentClass::VERSION_STATUS_DEFINED:
  626. $this->storeDefinedClassAttribute( $classAttribute );
  627. break;
  628. case eZContentClass::VERSION_STATUS_MODIFIED:
  629. $this->storeModifiedClassAttribute( $classAttribute );
  630. break;
  631. }
  632. }
  633. /**
  634. * @param eZContentClassAttribute $classAttribute Content class attribute of the datatype
  635. */
  636. function preStoreDefinedClassAttribute( $classAttribute )
  637. {
  638. $this->preStoreClassAttribute( $classAttribute, $classAttribute->attribute( 'version' ) );
  639. }
  640. /**
  641. * @param eZContentClassAttribute $classAttribute Content class attribute of the datatype
  642. */
  643. function preStoreModifiedClassAttribute( $classAttribute )
  644. {
  645. $this->preStoreClassAttribute( $classAttribute, $classAttribute->attribute( 'version' ) );
  646. }
  647. /**
  648. * Hook function which is called before an content class attribute is stored
  649. *
  650. * @see eZContentClassAttribute::storeVersioned()
  651. * @param eZContentClassAttribute $classAttribute Content class attribute of the datatype
  652. * @param int $version Version of the attribute to be stored
  653. */
  654. function preStoreVersionedClassAttribute( $classAttribute, $version )
  655. {
  656. switch ( $version )
  657. {
  658. case eZContentClass::VERSION_STATUS_DEFINED:
  659. $this->preStoreDefinedClassAttribute( $classAttribute );
  660. break;
  661. case eZContentClass::VERSION_STATUS_MODIFIED:
  662. $this->preStoreModifiedClassAttribute( $classAttribute );
  663. break;
  664. }
  665. }
  666. /*!
  667. Validates the input for a class attribute and returns a validation
  668. state as defined in eZInputValidator.
  669. \note Default implementation does nothing and returns accepted.
  670. */
  671. function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
  672. {
  673. return eZInputValidator::STATE_ACCEPTED;
  674. }
  675. /*!
  676. Tries to do a fixup on the input text so that it's acceptable as
  677. class attribute input.
  678. \note Default implementation does nothing and returns accepted.
  679. */
  680. function fixupClassAttributeHTTPInput( $http, $base, $classAttribute )
  681. {
  682. return eZInputValidator::STATE_ACCEPTED;
  683. }
  684. /*!
  685. Fetches the HTTP input for the content class attribute.
  686. \note Default implementation does nothing.
  687. */
  688. function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
  689. {
  690. }
  691. /*!
  692. Executes a custom action for a class attribute which was defined on the web page.
  693. \note Default implementation does nothing.
  694. */
  695. function customClassAttributeHTTPAction( $http, $action, $classAttribute )
  696. {
  697. }
  698. /*!
  699. Matches the action against the action name \a $actionName
  700. and extracts the value from the action puts it into \a $value.
  701. \return \c true if the action matched and a value was found,
  702. \c false otherwise.
  703. \node If no match is made or no value found the \a $value parameter is not modified.
  704. */
  705. function fetchActionValue( $action, $actionName, &$value )
  706. {
  707. if ( preg_match( "#^" . $actionName . "_(.+)$#", $action, $matches ) )
  708. {
  709. $value = $matches[1];
  710. return true;
  711. }
  712. return false;
  713. }
  714. /*!
  715. Validates the input for an object attribute and returns a validation
  716. state as defined in eZInputValidator.
  717. \note Default implementation does nothing and returns accepted.
  718. */
  719. function validateObjectAttributeHTTPInput( $http, $base, $objectAttribute )
  720. {
  721. return eZInputValidator::STATE_ACCEPTED;
  722. }
  723. /*!
  724. Tries to do a fixup on the input text so that it's acceptable as
  725. object attribute input.
  726. \note Default implementation does nothing.
  727. */
  728. function fixupObjectAttributeHTTPInput( $http, $base, $objectAttribute )
  729. {
  730. }
  731. /*!
  732. Fetches the HTTP input for the content object attribute.
  733. \note Default implementation does nothing.
  734. */
  735. function fetchObjectAttributeHTTPInput( $http, $base, $objectAttribute )
  736. {
  737. }
  738. /*!
  739. Validates the input for an object attribute and returns a validation
  740. state as defined in eZInputValidator.
  741. \note Default implementation does nothing and returns accepted.
  742. */
  743. function validateCollectionAttributeHTTPInput( $http, $base, $objectAttribute )
  744. {
  745. return eZInputValidator::STATE_ACCEPTED;
  746. }
  747. /*!
  748. Tries to do a fixup on the input text so that it's acceptable as
  749. object attribute input.
  750. \note Default implementation does nothing.
  751. */
  752. function fixupCollectionAttributeHTTPInput( $http, $base, $objectAttribute )
  753. {
  754. }
  755. /*!
  756. Fetches the HTTP collected information for the content object attribute.
  757. \note Default implementation does nothing.
  758. \return true if variable was successfully fetched.
  759. */
  760. function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $objectAttribute )
  761. {
  762. }
  763. /*!
  764. Executes a custom action for an object attribute which was defined on the web page.
  765. \note Default implementation does nothing.
  766. */
  767. function customObjectAttributeHTTPAction( $http, $action, $objectAttribute, $parameters )
  768. {
  769. }
  770. /*!
  771. Takes care of custom action handling, this means checking if a custom action request
  772. must be sent to a contentobject attribute. This function is only useful for
  773. datatypes that must do custom action handling for sub objects and attributes.
  774. \note Default implementation does nothing.
  775. */
  776. function handleCustomObjectHTTPActions( $http, $attributeDataBaseName,
  777. $customActionAttributeArray, $customActionParameters )
  778. {
  779. }
  780. /*!
  781. Initializes the class attribute with some data.
  782. \note Default implementation does nothing.
  783. */
  784. function initializeClassAttribute( $classAttribute )
  785. {
  786. }
  787. /*!
  788. Clones the date from the old class attribute to the new one.
  789. \note Default implementation does nothing which is good enough for datatypes which does not use external tables.
  790. */
  791. function cloneClassAttribute( $oldClassAttribute, $newClassAttribute )
  792. {
  793. }
  794. /*!
  795. Initializes the object attribute with some data.
  796. \note Default implementation does nothing.
  797. */
  798. function initializeObjectAttribute( $objectAttribute, $currentVersion, $originalContentObjectAttribute )
  799. {
  800. }
  801. /*!
  802. Tries to do a repair on the content object attribute \a $contentObjectAttribute and returns \c true if it succeeds.
  803. \return \c false if it fails or \c null if it is not supported to do a repair.
  804. */
  805. function repairContentObjectAttribute( $contentObjectAttribute )
  806. {
  807. return null;
  808. }
  809. /*!
  810. Initializes the object attribute with some data after object attribute is already stored. It means that for initial version you allready have an attribute_id and you can store data somewhere using this id.
  811. \note Default implementation does nothing.
  812. */
  813. function postInitializeObjectAttribute( $objectAttribute, $currentVersion, $originalContentObjectAttribute )
  814. {
  815. }
  816. /*
  817. Makes some post-store operations. Called by framework after store of eZContentObjectAttribute object.
  818. */
  819. function postStore( $objectAttribute )
  820. {
  821. }
  822. /*!
  823. Do any necessary changes to stored object attribute when moving an object to trash.
  824. \note Default implementation does nothing.
  825. */
  826. function trashStoredObjectAttribute( $objectAttribute, $version = null )
  827. {
  828. }
  829. /*!
  830. Clean up stored object attribute
  831. \note Default implementation does nothing.
  832. */
  833. function deleteStoredObjectAttribute( $objectAttribute, $version = null )
  834. {
  835. }
  836. /*!
  837. Clean up stored class attribute
  838. \note Default implementation does nothing.
  839. */
  840. function deleteStoredClassAttribute( $classAttribute, $version = null )
  841. {
  842. }
  843. /**
  844. * Return content action(s) which can be performed on object containing
  845. * the current datatype. Return format is array of arrays with key 'name'
  846. * and 'action'. 'action' can be mapped to url in datatype.ini
  847. *
  848. * @param eZContentClassAttribute $classAttribute
  849. * @return array
  850. */
  851. function contentActionList( $classAttribute )
  852. {
  853. $actionList = array();
  854. if ( $classAttribute instanceof eZContentClassAttribute )
  855. {
  856. if ( $classAttribute->attribute( 'is_information_collector' ) == true )
  857. {
  858. $actionList[] = array( 'name' => ezpI18n::tr( 'kernel/classes/datatypes', 'Send', 'Datatype information collector action' ),
  859. 'action' => 'ActionCollectInformation' );
  860. }
  861. }
  862. else
  863. {
  864. eZDebug::writeError( '$classAttribute isn\'t an object.', __METHOD__ );
  865. }
  866. return $actionList;
  867. }
  868. /*!
  869. \return true if the data type can do information collection
  870. */
  871. function hasInformationCollection()
  872. {
  873. return false;
  874. }
  875. /*!
  876. Returns the title of the current type, this is to form
  877. the title of the object.
  878. */
  879. function title( $objectAttribute, $name = null )
  880. {
  881. return "";
  882. }
  883. /*!
  884. \return true if the datatype can be indexed
  885. */
  886. function isIndexable()
  887. {
  888. return false;
  889. }
  890. /*!
  891. \return true if the datatype requires validation during add to basket procedure
  892. */
  893. function isAddToBasketValidationRequired()
  894. {
  895. return false;
  896. }
  897. /*!
  898. Validates the input for an object attribute during add to basket process
  899. and returns a validation state as defined in eZInputValidator.
  900. \note Default implementation does nothing and returns accepted.
  901. */
  902. function validateAddToBasket( $objectAttribute, $data, &$errors )
  903. {
  904. return eZInputValidator::STATE_ACCEPTED;
  905. }
  906. /*!
  907. Queries the datatype if the attribute containing this datatype can be
  908. removed from the class. This can be used by datatypes to ensure
  909. that very important datatypes that could cause system malfunction is
  910. not removed.
  911. The datatype will only need to reimplemented this if it wants to
  912. do some checking, the default returns \c true.
  913. \return \c true if the class attribute can be removed or \c false.
  914. \sa classAttributeRemovableInformation()
  915. \note The default code will call classAttributeRemovableInformation with
  916. $includeAll set to \c false, if it returns false or an empty \c 'list'
  917. it will return \c true.
  918. */
  919. function isClassAttributeRemovable( $classAttribute )
  920. {
  921. $info = $this->classAttributeRemovableInformation( $classAttribute, false );
  922. return ( $info === false or count( $info['list'] ) == 0 );
  923. }
  924. /*!
  925. If the call to isClassAttributeRemovable() returns \c false then this
  926. can be called to figure out why it cannot be removed, e.g to give
  927. information to the user.
  928. \return An array structure with information, or \c false if no info is available
  929. - text - Plain text explaining why it can't be removed
  930. - list - A list of reasons with details on why it can be removed
  931. - identifier - The identifier of the reason (optional)
  932. - text - Plain text explaning the reason
  933. \param $includeAll Controls whether the returned information will contain all
  934. sources for not being to remove or just the first that it finds.
  935. */
  936. function classAttributeRemovableInformation( $classAttribute, $includeAll = true )
  937. {
  938. return false;
  939. }
  940. /*!
  941. \return true if the datatype can be used as an information collector
  942. */
  943. function isInformationCollector()
  944. {
  945. return false;
  946. }
  947. /*!
  948. \return the sort key for the datatype. This is used for sorting on attribute level.
  949. */
  950. function sortKey( $objectAttribute )
  951. {
  952. return "";
  953. }
  954. /*!
  955. \returns the type of the sort key int|string
  956. False is returned if sorting is not supported
  957. */
  958. function sortKeyType()
  959. {
  960. return false;
  961. }
  962. function customSorting()
  963. {
  964. return false;
  965. }
  966. function customSortingSQL( $params )
  967. {
  968. return false;
  969. }
  970. /*!
  971. \return the text which should be indexed in the search engine. An associative array can
  972. be returned to enable searching in specific parts of the data. E.g. array( 'first_column' => "foo",
  973. 'second_column' => "bar" );
  974. */
  975. function metaData( $contentObjectAttribute )
  976. {
  977. return '';
  978. }
  979. /*!
  980. \return string representation of an contentobjectattribute data for simplified export
  981. */
  982. function toString( $objectAttribute )
  983. {
  984. return '';
  985. }
  986. function fromString( $objectAttribute, $string )
  987. {
  988. }
  989. /*!
  990. Can be called to figure out if a datatype has certain special templates that it relies on.
  991. This can for instance be used to figure out which override templates to include in a package.
  992. \return An array with template files that this datatype relies on.
  993. Each element can be one of the following types:
  994. - string - The filepath of the template
  995. - array - Advanced matching criteria, element 0 determines the type:
  996. - 'regexp' - A regular expression, element 1 is the regexp string (PREG)
  997. If \c false is returned it means there are no relations to any templates.
  998. \note All matching is done relative from templates directory in the given design.
  999. \note The templates that are found in content/datatype/* should not be included.
  1000. */
  1001. function templateList()
  1002. {
  1003. return false;
  1004. }
  1005. /*!
  1006. Adds the necessary dom structure to the attribute parameters.
  1007. \note The default is to add unsupported='true' to the attribute node,
  1008. meaning that the datatype does not support serializing.
  1009. */
  1010. function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
  1011. {
  1012. if ( !$this->Attributes['properties']['serialize_supported'] )
  1013. $attributeNode->setAttribute( 'unsupported', 'true' );
  1014. }
  1015. /*!
  1016. Extracts values from the attribute parameters and sets it in the class attribute.
  1017. \note This function is called after the attribute has been stored and a second store is
  1018. called after this function is done.
  1019. */
  1020. function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
  1021. {
  1022. }
  1023. /*!
  1024. \param package
  1025. \param objectAttribute content attribute
  1026. \return a DOM representation of the content object attribute
  1027. */
  1028. function serializeContentObjectAttribute( $package, $objectAttribute )
  1029. {
  1030. $dom = new DOMDocument( '1.0', 'utf-8' );
  1031. $node = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:attribute' );
  1032. $node->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:id', $objectAttribute->attribute( 'id' ) );
  1033. $node->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:identifier', $objectAttribute->contentClassAttributeIdentifier() );
  1034. $node->setAttribute( 'name', $objectAttribute->contentClassAttributeName() );
  1035. $node->setAttribute( 'type', $this->isA() );
  1036. if ( $this->Attributes["properties"]['object_serialize_map'] )
  1037. {
  1038. $map = $this->Attributes["properties"]['object_serialize_map'];
  1039. foreach ( $map as $attributeName => $xmlName )
  1040. {
  1041. if ( $objectAttribute->hasAttribute( $attributeName ) )
  1042. {
  1043. $value = $objectAttribute->attribute( $attributeName );
  1044. unset( $attributeNode );
  1045. $attributeNode = $dom->createElement( $xmlName );
  1046. $attributeNode->appendChild( $dom->createTextNode( (string)$value ) );
  1047. $node->appendChild( $attributeNode );
  1048. }
  1049. else
  1050. {
  1051. eZDebug::writeError( "The attribute '$attributeName' does not exist for contentobject attribute " . $objectAttribute->attribute( 'id' ), __METHOD__ );
  1052. }
  1053. }
  1054. }
  1055. else
  1056. {
  1057. $dataIntNode = $dom->createElement( 'data-int' );
  1058. $dataIntNode->appendChild( $dom->createTextNode( (string)$objectAttribute->attribute( 'data_int' ) ) );
  1059. $node->appendChild( $dataIntNode );
  1060. $dataFloatNode = $dom->createElement( 'data-float' );
  1061. $dataFloatNode->appendChild( $dom->createTextNode( (string)$objectAttribute->attribute( 'data_float' ) ) );
  1062. $node->appendChild( $dataFloatNode );
  1063. $dataTextNode = $dom->createElement( 'data-text' );
  1064. $dataTextNode->appendChild( $dom->createTextNode( $objectAttribute->attribute( 'data_text' ) ) );
  1065. $node->appendChild( $dataTextNode );
  1066. }
  1067. return $node;
  1068. }
  1069. /*!
  1070. Unserialize contentobject attribute
  1071. \param package
  1072. \param objectAttribute contentobject attribute object
  1073. \param attributeNode ezdomnode object
  1074. */
  1075. function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
  1076. {
  1077. if ( $this->Attributes["properties"]['object_serialize_map'] )
  1078. {
  1079. $map = $this->Attributes["properties"]['object_serialize_map'];
  1080. foreach ( $map as $attributeName => $xmlName )
  1081. {
  1082. if ( $objectAttribute->hasAttribute( $attributeName ) )
  1083. {
  1084. $elements = $attributeNode->getElementsByTagName( $xmlName );
  1085. if ( $elements->length !== 0 )
  1086. {
  1087. $value = $elements->item( 0 )->textContent;
  1088. $objectAttribute->setAttribute( $attributeName, $value );
  1089. }
  1090. else
  1091. {
  1092. eZDebug::writeError( "The xml element '$xmlName' does not exist for contentobject attribute " . $objectAttribute->attribute( 'id' ), __METHOD__ );
  1093. }
  1094. }
  1095. else
  1096. {
  1097. eZDebug::writeError( "The attribute '$attributeName' does not exist for contentobject attribute " . $objectAttribute->attribute( 'id' ), __METHOD__ );
  1098. }
  1099. }
  1100. }
  1101. else
  1102. {
  1103. $objectAttribute->setAttribute( 'data_int', (int)$attributeNode->getElementsByTagName( 'data-int' )->item( 0 )->textContent );
  1104. $objectAttribute->setAttribute( 'data_float', (float)$attributeNode->getElementsByTagName( 'data-float' )->item( 0 )->textContent );
  1105. $objectAttribute->setAttribute( 'data_text', $attributeNode->getElementsByTagName( 'data-text' )->item( 0 )->textContent );
  1106. }
  1107. }
  1108. /*
  1109. Post unserialize. Called after all related objects are created.
  1110. \return true means that attribute has been modified and should be stored
  1111. */
  1112. function postUnserializeContentObjectAttribute( $package, $objectAttribute )
  1113. {
  1114. return false;
  1115. }
  1116. static function allowedTypes()
  1117. {
  1118. $allowedTypes =& $GLOBALS["eZDataTypeAllowedTypes"];
  1119. if ( !is_array( $allowedTypes ) )
  1120. {
  1121. $contentINI = eZINI::instance( 'content.ini' );
  1122. $dataTypes = $contentINI->variable( 'DataTypeSettings', 'AvailableDataTypes' );
  1123. $allowedTypes = array_unique( $dataTypes );
  1124. }
  1125. return $allowedTypes;
  1126. }
  1127. static function loadAndRegisterAllTypes()
  1128. {
  1129. $allowedTypes = eZDataType::allowedTypes();
  1130. foreach( $allowedTypes as $type )
  1131. {
  1132. eZDataType::loadAndRegisterType( $type );
  1133. }
  1134. }
  1135. static function loadAndRegisterType( $type )
  1136. {
  1137. $types =& $GLOBALS["eZDataTypes"];
  1138. if ( isset( $types[$type] ) )
  1139. {
  1140. return false;
  1141. }
  1142. $baseDirectory = eZExtension::baseDirectory();
  1143. $contentINI = eZINI::instance( 'content.ini' );
  1144. $extensionDirectories = $contentINI->variable( 'DataTypeSettings', 'ExtensionDirectories' );
  1145. $extensionDirectories = array_unique( $extensionDirectories );
  1146. $repositoryDirectories = $contentINI->variable( 'DataTypeSettings', 'RepositoryDirectories' );
  1147. $triedDirectories = $repositoryDirectories;
  1148. foreach ( $extensionDirectories as $extensionDirectory )
  1149. {
  1150. $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/datatypes';
  1151. $triedDirectories[] = $extensionPath;
  1152. if ( file_exists( $extensionPath ) )
  1153. {
  1154. $repositoryDirect

Large files files are truncated, but you can click here to view the full file