noodles/src/Image.php

91 lines
2.7 KiB
PHP
Raw Normal View History

2021-09-08 22:53:13 +00:00
<?php
/**
2021-09-08 23:05:05 +00:00
* @brief noodles, a plugin for Dotclear 2
2022-11-17 20:00:42 +00:00
*
* @package Dotclear
2021-09-08 23:05:05 +00:00
* @subpackage Plugin
2022-11-17 20:00:42 +00:00
*
2021-09-08 23:05:05 +00:00
* @author Jean-Christian Denis and contributors
2022-11-17 20:00:42 +00:00
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2023-05-04 20:51:48 +00:00
declare(strict_types=1);
namespace Dotclear\Plugin\noodles;
use dcCore;
use Dotclear\Helper\File\Path;
2021-09-09 07:12:31 +00:00
2023-05-04 20:51:48 +00:00
class Image
2021-09-08 22:53:13 +00:00
{
2023-05-04 20:51:48 +00:00
/** @var string The current class major version */
public const VERSION = '2';
2021-09-08 22:53:13 +00:00
2023-05-04 20:51:48 +00:00
/**
* @return array<string, array{dir: null|string, url: null|string}> The Image possible paths
*/
public static function getArray(): array
{
2023-05-04 20:51:48 +00:00
if (is_null(dcCore::app()->blog)
|| !dcCore::app()->url->getBase('noodles_file')
2021-09-09 07:12:31 +00:00
) {
return [
2021-11-01 09:28:22 +00:00
'theme' => ['dir' => null, 'url' => null],
2021-09-09 07:12:31 +00:00
'public' => ['dir' => null, 'url' => null],
'module' => ['dir' => null, 'url' => null],
];
}
2021-09-08 22:53:13 +00:00
2023-05-04 20:51:48 +00:00
$public_url = dcCore::app()->blog->settings->get('system')->get('public_url');
if (!is_string($public_url)) {
$public_url = '';
}
2021-09-09 07:12:31 +00:00
return [
'theme' => [
2023-05-04 20:51:48 +00:00
'dir' => Path::real(dcCore::app()->blog->themes_path . '/' . dcCore::app()->blog->settings->get('system')->get('theme') . '/img') . '/' . My::IMAGE,
'url' => dcCore::app()->blog->settings->get('system')->get('themes_url') . dcCore::app()->blog->settings->get('system')->get('theme') . '/img/' . My::IMAGE,
2021-09-09 07:12:31 +00:00
],
'public' => [
2023-05-04 20:51:48 +00:00
'dir' => Path::real(dcCore::app()->blog->public_path) . '/' . My::IMAGE,
'url' => dcCore::app()->blog->host . Path::clean($public_url) . '/' . My::IMAGE,
2021-09-09 07:12:31 +00:00
],
'module' => [
2023-05-04 20:51:48 +00:00
'dir' => Path::real(My::path() . '/default-templates/img') . '/' . My::IMAGE,
'url' => dcCore::app()->blog->url . dcCore::app()->url->getBase('noodles_file') . '/img/' . My::IMAGE,
2022-11-17 20:00:42 +00:00
],
2021-09-09 07:12:31 +00:00
];
}
2021-09-08 22:53:13 +00:00
2023-05-04 20:51:48 +00:00
/**
* @return null|string The image URL
*/
public static function getUrl(): ?string
{
2023-05-04 20:51:48 +00:00
$files = self::getArray();
2021-11-01 09:28:22 +00:00
foreach ($files as $k => $file) {
2023-05-04 20:51:48 +00:00
if (is_string($files[$k]['dir']) && file_exists($files[$k]['dir'])) {
return $files[$k]['url'];
2021-11-01 09:28:22 +00:00
}
}
2021-11-01 09:28:22 +00:00
return null;
}
2021-09-08 22:53:13 +00:00
2023-05-04 20:51:48 +00:00
/**
* @return null|string The image path
*/
public static function getPath(): ?string
{
2023-05-04 20:51:48 +00:00
$files = self::getArray();
2021-11-01 09:28:22 +00:00
foreach ($files as $k => $file) {
2023-05-04 20:51:48 +00:00
if (is_string($files[$k]['dir']) && file_exists($files[$k]['dir'])) {
return $files[$k]['dir'];
2021-11-01 09:28:22 +00:00
}
}
2021-11-01 09:28:22 +00:00
return null;
}
2022-11-17 20:00:42 +00:00
}