PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.3.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.3.0
6.3.0 6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / app / Services / MediaService.php
kirki / app / Services Last commit date
AppsService.php 1 month ago CollaborationCommentService.php 5 days ago CollaborationService.php 1 month ago CollectionItemService.php 5 days ago CollectionService.php 1 month ago ContentManagerTemplateBinder.php 1 month ago ContentManagerTemplateService.php 1 month ago EditorService.php 2 months ago FontService.php 3 weeks ago FormSubmissionService.php 5 days ago GlobalDataService.php 1 month ago MediaService.php 2 months ago PageService.php 1 month ago PageSettingsService.php 2 months ago PostService.php 1 month ago UtilityPageService.php 1 month ago
MediaService.php
53 lines
1 <?php
2
3 namespace Kirki\App\Services;
4
5 use Kirki\App\Constants\PostStatus;
6 use Kirki\App\Constants\PostTypes;
7 use function Kirki\Framework\config;
8
9 defined('ABSPATH') || exit;
10
11 use Kirki\App\DTO\Media\MediaListFilterDTO;
12 use Kirki\App\Models\Media;
13
14 class MediaService
15 {
16 /**
17 * Paginate media items.
18 *
19 * @param MediaListFilterDTO $dto
20 * @return \Kirki\Framework\Database\Query\Paginator
21 */
22 public function paginated(MediaListFilterDTO $dto)
23 {
24 $supported_media_types = config('media.supports');
25
26 $query = Media::query();
27
28 if (!empty($dto->category)) {
29 $categories = explode(',', $dto->category);
30 $mime_types = [];
31
32 foreach ($categories as $category) {
33 $category = trim($category);
34
35 if (isset($supported_media_types[$category])) {
36 $mime_types = array_merge($mime_types, $supported_media_types[$category]);
37 }
38 }
39
40 if (!empty($mime_types)) {
41 $query->where_in('post_mime_type', $mime_types);
42 }
43 }
44
45 if (!empty($dto->search)) {
46 $query->search($dto->search);
47 }
48
49 $query->order_by($dto->sort_by, $dto->sort_order);
50
51 return $query->with('meta')->paginate($dto->limit, $dto->page);
52 }
53 }