diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index c38eba22b..1472f38f0 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -65,7 +65,7 @@ class Collection extends Entity { static $db_identifier_sufix = '_item'; public function __toString() { - return 'Hello, my name is ' . $this->get_name(); + return apply_filters("tainacan-collection-to-string", $this->get_name(), $this); } public function _toArray() { @@ -78,7 +78,7 @@ class Collection extends Entity { $array_collection['creation_date'] = $this->get_date_i18n( explode( ' ', $array_collection['creation_date'] )[0] ); $array_collection['modification_date'] = $this->get_date_i18n( explode( ' ', $array_collection['modification_date'] )[0] ); - return $array_collection; + return apply_filters('tainacan-collection-to-array', $array_collection, $this); } /** @@ -200,21 +200,22 @@ class Collection extends Entity { } } - return $attachments_prepared; + return apply_filters("tainacan-collection-get-attachments", $attachments_prepared, $exclude, $this); } /** * @return string */ function get_author_name() { - return get_the_author_meta( 'display_name', $this->get_author_id() ); + $name = get_the_author_meta( 'display_name', $this->get_author_id() ); + return apply_filters("tainacan-collection-get-author-name", $name, $this); } /** * @return array */ function get_thumbnail() { - return array( + $thumbs = array( 'thumb' => get_the_post_thumbnail_url( $this->get_id(), 'thumbnail' ), 'full' => get_the_post_thumbnail_url( $this->get_id(), 'full' ), 'medium' => get_the_post_thumbnail_url( $this->get_id(), 'medium' ), @@ -224,13 +225,15 @@ class Collection extends Entity { 'tainacan_medium' => get_the_post_thumbnail_url( $this->get_id(), 'tainacan-medium' ), 'tainacan_medium_full' => get_the_post_thumbnail_url( $this->get_id(), 'tainacan-medium-full' ), ); + return apply_filters("tainacan-collection-get-thumbnail", $thumbs, $this); } /** * @return false|string */ function get_header_image(){ - return wp_get_attachment_url( $this->get_header_image_id() ); + $header_image = wp_get_attachment_url( $this->get_header_image_id() ); + return apply_filters("tainacan-collection-get-header-image", $header_image, $this); } /** diff --git a/src/classes/entities/class-tainacan-entity.php b/src/classes/entities/class-tainacan-entity.php index a9503a4f9..13afaaf8f 100644 --- a/src/classes/entities/class-tainacan-entity.php +++ b/src/classes/entities/class-tainacan-entity.php @@ -160,8 +160,9 @@ class Entity { //prop is not set at object, try to get from database $repository = $this->get_repository(); + $value = $repository->get_mapped_property($this, $prop); - return $repository->get_mapped_property($this, $prop); + return apply_filters('tainacan-entity-get-property', $value, $prop, $this); } /** @@ -175,6 +176,7 @@ class Entity { */ protected function set_mapped_property($prop, $value) { $this->set_validated(false); + $value = apply_filters('tainacan-entity-set-property', $value, $prop, $this); $this->$prop = $value; } @@ -358,8 +360,10 @@ class Entity { foreach($map as $prop => $content) { $attributes[$prop] = $this->get_mapped_property($prop); } - - return $attributes; + + $hook_prefix = self::get_post_type(); + + return apply_filters("{$hook_prefix}-to-array", $attributes, $this); } public function _toJson(){ diff --git a/src/classes/entities/class-tainacan-filter.php b/src/classes/entities/class-tainacan-filter.php index e098fb583..b160e8afc 100644 --- a/src/classes/entities/class-tainacan-filter.php +++ b/src/classes/entities/class-tainacan-filter.php @@ -31,7 +31,7 @@ class Filter extends Entity { protected $repository = 'Filters'; public function __toString(){ - return 'Hello, my name is '. $this->get_name(); + return apply_filters("tainacan-filter-to-string", $this->get_name(), $this); } /** @@ -51,8 +51,7 @@ class Filter extends Entity { $filter_array['metadatum']['metadata_type_object'] = $meta_object->_toArray(); } - - return $filter_array; + return apply_filters('tainacan-filter-to-array', $filter_array, $this); } /** diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php index 15fb8a91a..52679adc0 100644 --- a/src/classes/entities/class-tainacan-item-metadata-entity.php +++ b/src/classes/entities/class-tainacan-item-metadata-entity.php @@ -46,6 +46,36 @@ class Item_Metadata_Entity extends Entity { } + /** + * Gets the string used before each value when concatenating multiple values + * to display item metadata value as html or string + * + * @return string + */ + public function get_multivalue_prefix() { + return apply_filters('tainacan-item-metadata-get-multivalue-prefix', '', $this); + } + + /** + * Gets the string used after each value when concatenating multiple values + * to display item metadata value as html or string + * + * @return string + */ + public function get_multivalue_suffix() { + return apply_filters('tainacan-item-metadata-get-multivalue-suffix', '', $this); + } + + /** + * Gets the string used in between each value when concatenating multiple values + * to display item metadata value as html or string + * + * @return string + */ + public function get_multivalue_separator() { + return apply_filters('tainacan-item-metadata-get-multivalue-separator', ', ', $this); + } + /** * Get the value as a HTML string, with markup and links * @return string @@ -72,13 +102,21 @@ class Item_Metadata_Entity extends Entity { $total = sizeof($value); $count = 0; + $prefix = $item_metadata->get_multivalue_prefix(); + $suffix = $item_metadata->get_multivalue_suffix(); + $separator = $item_metadata->get_multivalue_separator(); foreach ($value as $v) { + + $return .= $prefix; + $return .= (string) $v; + $return .= $suffix; + $count ++; if ($count < $total) - $return .= ', '; + $return .= $separator; } } else { @@ -150,7 +188,7 @@ class Item_Metadata_Entity extends Entity { $as_array['item'] = $this->get_item()->_toArray(); $as_array['metadatum'] = $this->get_metadatum()->_toArray(); - return $as_array; + return apply_filters('tainacan-item-metadata-to-array', $as_array, $this); } /** diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index 9f79c51a2..085d0a38f 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -46,7 +46,7 @@ class Item extends Entity { } public function __toString() { - return 'Hello, my name is ' . $this->get_title(); + return apply_filters("tainacan-item-to-string", $this->get_title(), $this); } public function _toArray() { @@ -59,7 +59,7 @@ class Item extends Entity { $array_item['creation_date'] = $this->get_date_i18n( explode( ' ', $array_item['creation_date'] )[0] ); $array_item['modification_date'] = $this->get_date_i18n( explode( ' ', $array_item['modification_date'] )[0] ); - return $array_item; + return apply_filters('tainacan-item-to-array', $array_item, $this); } /** @@ -114,7 +114,7 @@ class Item extends Entity { } } - return $attachments_prepared; + return apply_filters("tainacan-item-get-attachments", $attachments_prepared, $exclude, $this); } @@ -122,14 +122,15 @@ class Item extends Entity { * @return string */ function get_author_name() { - return get_the_author_meta( 'display_name', $this->get_author_id() ); + $name = get_the_author_meta( 'display_name', $this->get_author_id() ); + return apply_filters("tainacan-item-get-author-name", $name, $this); } /** * @return array */ function get_thumbnail() { - return array( + $thumbs = array( 'thumb' => get_the_post_thumbnail_url( $this->get_id(), 'thumbnail' ), 'full' => get_the_post_thumbnail_url( $this->get_id(), 'full' ), 'medium' => get_the_post_thumbnail_url( $this->get_id(), 'medium' ), @@ -139,6 +140,7 @@ class Item extends Entity { 'tainacan_medium' => get_the_post_thumbnail_url( $this->get_id(), 'tainacan-medium' ), 'tainacan_medium_full' => get_the_post_thumbnail_url( $this->get_id(), 'tainacan-medium-full' ), ); + return apply_filters("tainacan-item-get-thumbnail", $thumbs, $this); } /** @@ -661,9 +663,6 @@ class Item extends Entity { $embed = $wp_embed->autoembed($url); if ( $embed == $url ) { - - // No embed handler found - // TODO: Add filter to allow customization $output .= sprintf("%s", $url, $url); } else { $output .= $embed; @@ -674,7 +673,7 @@ class Item extends Entity { } - return $output; + return apply_filters("tainacan-item-get-document-html", $output, $img_size, $this); } diff --git a/src/classes/entities/class-tainacan-log.php b/src/classes/entities/class-tainacan-log.php index 32fb1cb7d..c6375775f 100644 --- a/src/classes/entities/class-tainacan-log.php +++ b/src/classes/entities/class-tainacan-log.php @@ -38,7 +38,7 @@ class Log extends Entity { } public function __toString() { - return 'Hello, my title is ' . $this->get_title(); + return apply_filters("tainacan-log-to-string", $this->get_title(), $this); } /** @@ -49,7 +49,7 @@ class Log extends Entity { $array_log['user_name'] = $this->get_user_name(); - return $array_log; + return apply_filters('tainacan-log-to-array', $array_log, $this); } diff --git a/src/classes/entities/class-tainacan-metadatum.php b/src/classes/entities/class-tainacan-metadatum.php index 179e8812a..86e4de177 100644 --- a/src/classes/entities/class-tainacan-metadatum.php +++ b/src/classes/entities/class-tainacan-metadatum.php @@ -48,7 +48,7 @@ class Metadatum extends Entity { protected $repository = 'Metadata'; public function __toString(){ - return 'Hello, my name is '. $this->get_name(); + return apply_filters("tainacan-metadatum-to-string", $this->get_name(), $this); } diff --git a/src/classes/entities/class-tainacan-taxonomy.php b/src/classes/entities/class-tainacan-taxonomy.php index 0340334d9..ff31448e5 100644 --- a/src/classes/entities/class-tainacan-taxonomy.php +++ b/src/classes/entities/class-tainacan-taxonomy.php @@ -45,7 +45,7 @@ class Taxonomy extends Entity { static $db_identifier_prefix = 'tnc_tax_'; public function __toString(){ - return 'Hello, my name is '. $this->get_name(); + return apply_filters("tainacan-taxonomy-to-string", $this->get_name(), $this); } /** diff --git a/src/classes/entities/class-tainacan-term.php b/src/classes/entities/class-tainacan-term.php index 2f7b4c3b5..6bc7b4cc6 100644 --- a/src/classes/entities/class-tainacan-term.php +++ b/src/classes/entities/class-tainacan-term.php @@ -52,7 +52,7 @@ class Term extends Entity { } public function __toString(){ - return 'Hello, my name is '. $this->get_name(); + return apply_filters("tainacan-term-to-string", $this->get_name(), $this); } public function _toArray(){ @@ -67,7 +67,7 @@ class Term extends Entity { $term_array['header_image'] = $this->get_header_image(); $term_array['url'] = get_term_link( $this->get_id() ); - return $term_array; + return apply_filters('tainacan-term-to-array', $term_array, $this); } // Getters diff --git a/src/classes/metadata-types/core-description/class-tainacan-core-description.php b/src/classes/metadata-types/core-description/class-tainacan-core-description.php index 3590e0ef3..47b442a75 100644 --- a/src/classes/metadata-types/core-description/class-tainacan-core-description.php +++ b/src/classes/metadata-types/core-description/class-tainacan-core-description.php @@ -93,11 +93,16 @@ class Core_Description extends Metadata_Type { if ( $item_metadata->is_multiple() ) { $total = sizeof($value); $count = 0; + $prefix = $item_metadata->get_multivalue_prefix(); + $suffix = $item_metadata->get_multivalue_suffix(); + $separator = $item_metadata->get_multivalue_separator(); foreach ( $value as $el ) { + $return .= $prefix; $return .= nl2br($this->make_clickable_links($el)); + $return .= $suffix; $count ++; if ($count < $total) - $return .= ', '; + $return .= $separator; } } else { $return = nl2br($this->make_clickable_links($value)); diff --git a/src/classes/metadata-types/relationship/class-tainacan-relationship.php b/src/classes/metadata-types/relationship/class-tainacan-relationship.php index a118c71a2..4a0544955 100644 --- a/src/classes/metadata-types/relationship/class-tainacan-relationship.php +++ b/src/classes/metadata-types/relationship/class-tainacan-relationship.php @@ -84,6 +84,9 @@ class Relationship extends Metadata_Type { $count = 1; $total = sizeof($value); + $prefix = $item_metadata->get_multivalue_prefix(); + $suffix = $item_metadata->get_multivalue_suffix(); + $separator = $item_metadata->get_multivalue_separator(); foreach ( $value as $item_id ) { @@ -91,16 +94,23 @@ class Relationship extends Metadata_Type { $item = new \Tainacan\Entities\Item($item_id); - if ( $item instanceof \Tainacan\Entities\Item ) { - $return .= $item->_toHtml(); - } - $count ++; - if ( $count <= $total ) { - $return .= ', '; + if ( $item instanceof \Tainacan\Entities\Item ) { + + $return .= $prefix; + + $return .= $item->_toHtml(); + + $return .= $suffix; + + if ( $count <= $total ) { + $return .= $separator; + } + } + } catch (Exception $e) { // item not found } diff --git a/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php b/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php index e1b463490..ab28bae81 100644 --- a/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php +++ b/src/classes/metadata-types/taxonomy/class-tainacan-taxonomy.php @@ -154,18 +154,27 @@ class Taxonomy extends Metadata_Type { $count = 1; $total = sizeof($value); + $prefix = $item_metadata->get_multivalue_prefix(); + $suffix = $item_metadata->get_multivalue_suffix(); + $separator = $item_metadata->get_multivalue_separator(); foreach ( $value as $term ) { - if ( $term instanceof \Tainacan\Entities\Term ) { - $return .= $term->_toHtml(); - } $count ++; - if ( $count <= $total ) { - $return .= ', '; + if ( $term instanceof \Tainacan\Entities\Term ) { + $return .= $prefix; + + $return .= $term->_toHtml(); + + $return .= $suffix; + + if ( $count <= $total ) { + $return .= $separator; + } + } - + } } else { diff --git a/src/classes/metadata-types/text/class-tainacan-text.php b/src/classes/metadata-types/text/class-tainacan-text.php index 2d75b5e30..35aa83cac 100644 --- a/src/classes/metadata-types/text/class-tainacan-text.php +++ b/src/classes/metadata-types/text/class-tainacan-text.php @@ -41,11 +41,16 @@ class Text extends Metadata_Type { if ( $item_metadata->is_multiple() ) { $total = sizeof($value); $count = 0; + $prefix = $item_metadata->get_multivalue_prefix(); + $suffix = $item_metadata->get_multivalue_suffix(); + $separator = $item_metadata->get_multivalue_separator(); foreach ( $value as $el ) { + $return .= $prefix; $return .= $this->make_clickable_links($el); + $return .= $suffix; $count ++; if ($count < $total) - $return .= ', '; + $return .= $separator; } } else { $return = $this->make_clickable_links($value); diff --git a/src/classes/metadata-types/textarea/class-tainacan-textarea.php b/src/classes/metadata-types/textarea/class-tainacan-textarea.php index 207467591..85496c726 100644 --- a/src/classes/metadata-types/textarea/class-tainacan-textarea.php +++ b/src/classes/metadata-types/textarea/class-tainacan-textarea.php @@ -42,11 +42,16 @@ class Textarea extends Metadata_Type { if ( $item_metadata->is_multiple() ) { $total = sizeof($value); $count = 0; + $prefix = $item_metadata->get_multivalue_prefix(); + $suffix = $item_metadata->get_multivalue_suffix(); + $separator = $item_metadata->get_multivalue_separator(); foreach ( $value as $el ) { + $return .= $prefix; $return .= nl2br($this->make_clickable_links($el)); + $return .= $suffix; $count ++; if ($count < $total) - $return .= ', '; + $return .= $separator; } } else { $return = nl2br($this->make_clickable_links($value));