source of /sprout/Helpers/RteLibraryImages.php<?php /* * Copyright (C) 2017 Karmabunny Pty Ltd. * * This file is a part of SproutCMS. * * SproutCMS is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Foundation, either * version 2 of the License, or (at your option) any later version. * * For more information, visit <http://getsproutcms.com>. */ namespace Sprout\Helpers; use Kohana; /** * Richtext library for media repository sounds, they launch in a popup audio player **/ class RteLibraryImages extends RteLibrary { protected $name = 'Media repository - images'; private $db; public function __construct() { } /** * Do a library browse * * @return array of RteLibContainer and RteLibObject objects **/ public function browse($path) { if ($path == '') { // Get categories $q = "SELECT cat.id, cat.name FROM ~files_cat_list AS cat INNER JOIN ~files_cat_join AS joiner ON joiner.cat_id = cat.id INNER JOIN ~files AS files ON joiner.file_id = files.id WHERE files.type = ? AND cat.show_admin = 1 GROUP BY cat.id ORDER BY cat.name"; $res = Pdb::query($q, [FileConstants::TYPE_IMAGE], 'pdo'); // Convert into 'Container' objects for rendering foreach ($res as $row) { $out[] = new RteLibContainer($row['id'], $row['name']); } $res->closeCursor(); return $out; } else if (count($path_parts) == 1) { // file list for files in category $cat_id = (int) $path_parts[0]; $q = "SELECT files.name, files.filename, files.date_modified FROM ~files AS files INNER JOIN ~files_cat_join AS joiner ON joiner.file_id = files.id WHERE joiner.cat_id = ? AND files.type = ? ORDER BY files.name"; $res = Pdb::query($q, [$cat_id, FileConstants::TYPE_IMAGE], 'pdo'); $size = Kohana::config('file.imagelink_size'); if (! $size) $size = 'r500x500'; // Convert to 'Object' objects for rendering foreach ($res as $row) { $out[] = new RteLibObject( $row['filename'], $row['name'], 'href' => File::resizeUrl($row['filename'], $size), 'title' => $row['name'], ), 'date' => $row['date_modified'], 'size' => File::size($row['filename']), ) ); } $res->closeCursor(); return $out; } } /** * Do a library search * * @return array of RteLibContainer and RteLibObject objects **/ public function search($term) { $conditions[] = ['files.name', 'CONTAINS', $term]; $conditions[] = ['files.filename', 'CONTAINS', $term]; $params = [FileConstants::TYPE_IMAGE]; $where = Pdb::buildClause($conditions, $params, 'OR'); $q = "SELECT files.name, files.filename, files.date_modified FROM ~files AS files INNER JOIN ~files_cat_join AS joiner ON joiner.file_id = files.id WHERE files.type = ? AND ({$where}) ORDER BY files.name"; $res = Pdb::query($q, $params, 'pdo'); $size = Kohana::config('file.imagelink_size'); if (! $size) $size = 'r500x500'; // Convert to 'Object' objects for rendering foreach ($res as $row) { $out[] = new RteLibObject( $row['filename'], $row['name'], 'href' => File::resizeUrl($row['filename'], $size), 'title' => $row['name'], ), 'date' => $row['date_modified'], 'size' => File::size($row['filename']), ) ); } $res->closeCursor(); return $out; } }
|