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.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / components / AttachmentCard.php
tutor / components Last commit date
Constants 18 hours ago Accordion.php 18 hours ago Alert.php 18 hours ago AttachmentCard.php 18 hours ago Avatar.php 18 hours ago Badge.php 18 hours ago BaseComponent.php 18 hours ago Button.php 18 hours ago ConfirmationModal.php 18 hours ago CourseFilter.php 18 hours ago DateFilter.php 18 hours ago DropdownFilter.php 18 hours ago EmptyState.php 18 hours ago FileUploader.php 18 hours ago InputField.php 18 hours ago Modal.php 18 hours ago Nav.php 18 hours ago Pagination.php 18 hours ago Popover.php 18 hours ago PreviewTrigger.php 18 hours ago Progress.php 18 hours ago SearchFilter.php 18 hours ago Sorting.php 18 hours ago StarRating.php 18 hours ago StarRatingInput.php 18 hours ago StatusSelect.php 18 hours ago SvgIcon.php 18 hours ago Table.php 18 hours ago Tabs.php 18 hours ago Tooltip.php 18 hours ago WPEditor.php 18 hours ago
AttachmentCard.php
217 lines
1 <?php
2 /**
3 * AttachmentCard Component Class.
4 *
5 * @package Tutor\Components
6 * @author Themeum
7 * @link https://themeum.com
8 * @since 4.0.0
9 */
10
11 namespace Tutor\Components;
12
13 defined( 'ABSPATH' ) || exit;
14
15 use TUTOR\Icon;
16
17 /**
18 * Class AttachmentCard
19 *
20 * Example Usage:
21 * AttachmentCard::make()
22 * ->file_name( 'lesson-plan.pdf' )
23 * ->file_size( '1.2 MB' )
24 * ->is_downloadable( true )
25 * ->action_attr( '@click', 'downloadFile()' )
26 * ->render();
27 *
28 * @since 4.0.0
29 */
30 class AttachmentCard extends BaseComponent {
31
32 /**
33 * File name
34 *
35 * @var string
36 */
37 protected $file_name = '';
38
39 /**
40 * File size
41 *
42 * @var string
43 */
44 protected $file_size = '';
45
46 /**
47 * Is downloadable
48 *
49 * @var bool
50 */
51 protected $is_downloadable = false;
52
53 /**
54 * Title attribute
55 *
56 * @var array
57 */
58 protected $title_attr = array();
59
60 /**
61 * Meta attribute
62 *
63 * @var array
64 */
65 protected $meta_attr = array();
66
67 /**
68 * Action attribute
69 *
70 * @var array
71 */
72 protected $action_attr = array();
73
74 /**
75 * Set file name
76 *
77 * @param string $file_name file name.
78 *
79 * @return self
80 */
81 public function file_name( string $file_name ): self {
82 $this->file_name = $file_name;
83 return $this;
84 }
85
86 /**
87 * Set file size
88 *
89 * @param string $file_size file size.
90 *
91 * @return self
92 */
93 public function file_size( string $file_size ): self {
94 $this->file_size = $file_size;
95 return $this;
96 }
97
98 /**
99 * Set is downloadable
100 *
101 * @param bool $is_downloadable is downloadable.
102 *
103 * @return self
104 */
105 public function is_downloadable( bool $is_downloadable ): self {
106 $this->is_downloadable = $is_downloadable;
107 return $this;
108 }
109
110 /**
111 * Set title attribute
112 *
113 * @param string $key Attribute name.
114 * @param string $value Attribute value.
115 *
116 * @return self
117 */
118 public function title_attr( string $key, string $value ): self {
119 $this->title_attr[ $key ] = $value;
120 return $this;
121 }
122
123 /**
124 * Set meta attribute
125 *
126 * @param string $key Attribute name.
127 * @param string $value Attribute value.
128 *
129 * @return self
130 */
131 public function meta_attr( string $key, string $value ): self {
132 $this->meta_attr[ $key ] = $value;
133 return $this;
134 }
135
136 /**
137 * Set action attribute
138 *
139 * @param string $key Attribute name.
140 * @param string $value Attribute value.
141 *
142 * @return self
143 */
144 public function action_attr( string $key, string $value ): self {
145 $this->action_attr[ $key ] = $value;
146 return $this;
147 }
148
149 /**
150 * Get custom attributes string
151 *
152 * @param array $attributes attributes.
153 *
154 * @return string
155 */
156 private function get_custom_attributes_string( array $attributes ): string {
157 $compiled = array();
158
159 foreach ( $attributes as $key => $value ) {
160 $compiled[] = sprintf( '%s="%s"', esc_attr( $key ), esc_attr( $value ) );
161 }
162
163 return implode( ' ', $compiled );
164 }
165
166 /**
167 * Get component content
168 *
169 * @return string
170 */
171 public function get(): string {
172 $file_name = $this->file_name;
173 $file_size = $this->file_size;
174 $is_downloadable = $this->is_downloadable;
175 $title_attr = $this->get_custom_attributes_string( $this->title_attr );
176 $meta_attr = $this->get_custom_attributes_string( $this->meta_attr );
177 $action_attr = $this->get_custom_attributes_string( $this->action_attr );
178
179 if ( '' === $file_name && '' === $title_attr ) {
180 return '';
181 }
182
183 $icon_classes = array( 'tutor-attachment-card-icon' );
184 $icon_class_attr = implode( ' ', $icon_classes );
185
186 $action_icon = $is_downloadable ? Icon::DOWNLOAD_2 : Icon::CROSS;
187
188 ob_start();
189 ?>
190 <div class="tutor-card tutor-attachment-card">
191 <div class="<?php echo esc_attr( $icon_class_attr ); ?>" aria-hidden="true">
192 <?php SvgIcon::make()->name( Icon::RESOURCES )->size( 24 )->render(); ?>
193 </div>
194
195 <div class="tutor-attachment-card-body">
196 <div class="tutor-attachment-card-title" <?php echo $title_attr; // phpcs:ignore --already-escaped WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
197 <?php echo esc_html( $file_name ); ?>
198 </div>
199
200 <?php if ( $file_size || $meta_attr ) : ?>
201 <span class="tutor-attachment-card-meta" <?php echo $meta_attr; // phpcs:ignore --already-escaped WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
202 <?php echo esc_html( size_format( $file_size, 2 ) ); ?>
203 </span>
204 <?php endif; ?>
205 </div>
206
207 <button type="button" class="tutor-btn tutor-btn-ghost tutor-btn-x-small tutor-btn-icon" aria-label="<?php echo $is_downloadable ? esc_attr__( 'Download file', 'tutor' ) : esc_attr__( 'Remove file', 'tutor' ); ?>" <?php echo $action_attr; // phpcs:ignore --already-escaped WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
208 <?php SvgIcon::make()->name( $action_icon )->size( 16 )->render(); ?>
209 </button>
210 </div>
211 <?php
212
213 $this->component_string = ob_get_clean();
214 return $this->component_string;
215 }
216 }
217