checkbox.php
3 weeks ago
date.php
3 weeks ago
datetime.php
3 weeks ago
field.php
3 weeks ago
gallery.php
3 weeks ago
media.php
3 weeks ago
number.php
3 weeks ago
post.php
3 weeks ago
radio.php
3 weeks ago
repeater.php
3 weeks ago
select.php
3 weeks ago
switcher.php
3 weeks ago
text.php
3 weeks ago
time.php
3 weeks ago
toggle.php
3 weeks ago
user.php
3 weeks ago
gallery.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\AddonAPI; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 6 | |
| 7 | class PMXE_Addon_Gallery_Field extends PMXE_Addon_Media_Field { |
| 8 | |
| 9 | public function toString() { |
| 10 | $format = $this->settings['value_format'] ?? 'url'; |
| 11 | $urls = is_string( $this->value ) ? explode( ',', $this->value ) : $this->value; |
| 12 | |
| 13 | if ( empty( $urls ) ) { |
| 14 | return ''; |
| 15 | } |
| 16 | |
| 17 | $urls = array_map( function ( $item ) use ( $format ) { |
| 18 | switch ( $format ) { |
| 19 | case 'id': |
| 20 | return $this->getMediaId( $item ); |
| 21 | case 'filename': |
| 22 | return $this->getFileName( $item ); |
| 23 | default: |
| 24 | return $this->getMediaUrl( $item ); |
| 25 | } |
| 26 | }, $urls ); |
| 27 | |
| 28 | return implode( $this->getImplode(), $urls ); |
| 29 | } |
| 30 | |
| 31 | public function exportCustomXml( $article, $value, $write = true ) { |
| 32 | |
| 33 | $this->local_value = $value; |
| 34 | |
| 35 | $formatted_values = $this->toString(); |
| 36 | |
| 37 | $exported_value = $this->runPhpFunction( $formatted_values ); |
| 38 | |
| 39 | // By default we write the values to $article and return it. |
| 40 | // But if !$write we return the list of subfields we built instead. |
| 41 | if ( $write ) { |
| 42 | wp_all_export_write_article( $article, $this->elName, $exported_value ); |
| 43 | |
| 44 | return $article; |
| 45 | } else { |
| 46 | return $exported_value; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | public static function getImportTemplate( $field, $name, $field_tpl_key, $implode_delimiter, $is_xml_template ) { |
| 51 | return [ |
| 52 | 'search_in_media' => 1, |
| 53 | 'delim' => $implode_delimiter, |
| 54 | 'gallery' => '{' . $field_tpl_key . '}' |
| 55 | ]; |
| 56 | } |
| 57 | } |
| 58 |