1 | <?php |
---|
2 | |
---|
3 | namespace AC\Settings\Column; |
---|
4 | |
---|
5 | use AC\Settings; |
---|
6 | use AC\View; |
---|
7 | |
---|
8 | class ExifData extends Settings\Column |
---|
9 | implements Settings\FormatValue { |
---|
10 | |
---|
11 | /** |
---|
12 | * @var string |
---|
13 | */ |
---|
14 | private $exif_datatype; |
---|
15 | |
---|
16 | protected function set_name() { |
---|
17 | $this->name = 'exif_data'; |
---|
18 | } |
---|
19 | |
---|
20 | protected function define_options() { |
---|
21 | return [ 'exif_datatype' => 'aperture' ]; |
---|
22 | } |
---|
23 | |
---|
24 | public function create_view() { |
---|
25 | $setting = $this->create_element( 'select' ) |
---|
26 | ->set_attribute( 'data-label', 'update' ) |
---|
27 | ->set_attribute( 'data-refresh', 'column' ) |
---|
28 | ->set_options( $this->get_exif_types() ); |
---|
29 | |
---|
30 | return new View( [ |
---|
31 | 'label' => $this->column->get_label(), |
---|
32 | 'setting' => $setting, |
---|
33 | ] ); |
---|
34 | } |
---|
35 | |
---|
36 | public function get_dependent_settings() { |
---|
37 | |
---|
38 | switch ( $this->get_exif_datatype() ) { |
---|
39 | case 'aperture' : |
---|
40 | $settings = [ new Settings\Column\BeforeAfter\Aperture( $this->column ) ]; |
---|
41 | |
---|
42 | break; |
---|
43 | case 'focal_length' : |
---|
44 | $settings = [ new Settings\Column\BeforeAfter\FocalLength( $this->column ) ]; |
---|
45 | |
---|
46 | break; |
---|
47 | case 'iso' : |
---|
48 | $settings = [ new Settings\Column\BeforeAfter\ISO( $this->column ) ]; |
---|
49 | |
---|
50 | break; |
---|
51 | case 'shutter_speed' : |
---|
52 | $settings = [ new Settings\Column\BeforeAfter\ShutterSpeed( $this->column ) ]; |
---|
53 | |
---|
54 | break; |
---|
55 | default : |
---|
56 | $settings = [ new Settings\Column\BeforeAfter( $this->column ) ]; |
---|
57 | } |
---|
58 | |
---|
59 | return $settings; |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * Get EXIF data |
---|
64 | * Get extended image metadata |
---|
65 | * @return array EXIF data types |
---|
66 | * @since 2.0 |
---|
67 | */ |
---|
68 | private function get_exif_types() { |
---|
69 | $exif_types = [ |
---|
70 | 'aperture' => __( 'Aperture', 'codepress-admin-columns' ), |
---|
71 | 'credit' => __( 'Credit', 'codepress-admin-columns' ), |
---|
72 | 'camera' => __( 'Camera', 'codepress-admin-columns' ), |
---|
73 | 'caption' => __( 'Caption', 'codepress-admin-columns' ), |
---|
74 | 'created_timestamp' => __( 'Timestamp', 'codepress-admin-columns' ), |
---|
75 | 'copyright' => __( 'Copyright', 'codepress-admin-columns' ), |
---|
76 | 'focal_length' => __( 'Focal Length', 'codepress-admin-columns' ), |
---|
77 | 'iso' => __( 'ISO', 'codepress-admin-columns' ), |
---|
78 | 'shutter_speed' => __( 'Shutter Speed', 'codepress-admin-columns' ), |
---|
79 | 'title' => __( 'Title', 'codepress-admin-columns' ), |
---|
80 | 'orientation' => __( 'Orientation', 'codepress-admin-columns' ), |
---|
81 | 'keywords' => __( 'Keywords', 'codepress-admin-columns' ), |
---|
82 | ]; |
---|
83 | |
---|
84 | natcasesort( $exif_types ); |
---|
85 | |
---|
86 | return $exif_types; |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * @return string |
---|
91 | */ |
---|
92 | public function get_exif_datatype() { |
---|
93 | return $this->exif_datatype; |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | * @param string $exif_datatype |
---|
98 | * |
---|
99 | * @return bool |
---|
100 | */ |
---|
101 | public function set_exif_datatype( $exif_datatype ) { |
---|
102 | $this->exif_datatype = $exif_datatype; |
---|
103 | |
---|
104 | return true; |
---|
105 | } |
---|
106 | |
---|
107 | public function format( $value, $original_value ) { |
---|
108 | $exif_datatype = $this->get_exif_datatype(); |
---|
109 | $value = isset( $value[ $exif_datatype ] ) ? $value[ $exif_datatype ] : ''; |
---|
110 | |
---|
111 | if ( false != $value ) { |
---|
112 | switch ( $exif_datatype ) { |
---|
113 | case 'created_timestamp' : |
---|
114 | $value = ac_format_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $value ); |
---|
115 | |
---|
116 | break; |
---|
117 | case 'keywords' : |
---|
118 | $value = ac_helper()->array->implode_recursive( ', ', $value ); |
---|
119 | |
---|
120 | break; |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | return $value; |
---|
125 | } |
---|
126 | |
---|
127 | } |
---|