noodles/inc/lib.image.path.php

83 lines
2.5 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
*/
2021-09-09 07:12:31 +00:00
if (!defined('DC_RC_PATH')) {
return null;
}
2021-09-08 22:53:13 +00:00
class noodlesLibImagePath
{
public static $version = '1.1';
2021-09-08 22:53:13 +00:00
2022-11-17 20:00:42 +00:00
public static function getArray($m = '')
{
2022-11-17 20:00:42 +00:00
if (!dcCore::app()->plugins->moduleExists($m)
|| !dcCore::app()->url->getBase($m . 'module')
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
2021-09-09 07:12:31 +00:00
return [
'theme' => [
2022-11-17 20:00:42 +00:00
'dir' => path::real(dcCore::app()->blog->themes_path . '/' . dcCore::app()->blog->settings->system->theme . '/img') . '/' . $m . '-default-image.png',
'url' => dcCore::app()->blog->settings->system->themes_url . dcCore::app()->blog->settings->system->theme . '/img/' . $m . '-default-image.png',
2021-09-09 07:12:31 +00:00
],
'public' => [
2022-11-17 20:00:42 +00:00
'dir' => path::real(dcCore::app()->blog->public_path) . '/' . $m . '-default-image.png',
'url' => dcCore::app()->blog->host . path::clean(dcCore::app()->blog->settings->system->public_url) . '/' . $m . '-default-image.png',
2021-09-09 07:12:31 +00:00
],
'module' => [
2022-11-17 20:00:42 +00:00
'dir' => path::real(dcCore::app()->plugins->moduleRoot($m) . '/default-templates/img') . '/' . $m . '-default-image.png',
'url' => dcCore::app()->blog->url . dcCore::app()->url->getBase($m . 'module') . '/img/' . $m . '-default-image.png',
],
2021-09-09 07:12:31 +00:00
];
}
2021-09-08 22:53:13 +00:00
2022-11-17 20:00:42 +00:00
public static function getUrl($m = '')
{
2022-11-17 20:00:42 +00:00
$files = self::getArray($m);
2021-11-01 09:28:22 +00:00
foreach ($files as $k => $file) {
if (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
2022-11-17 20:00:42 +00:00
public static function getPath($m = '')
{
2022-11-17 20:00:42 +00:00
$files = self::getArray($m);
2021-11-01 09:28:22 +00:00
foreach ($files as $k => $file) {
if (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;
}
2021-09-08 22:53:13 +00:00
2022-11-17 20:00:42 +00:00
public static function getSize($m = '')
{
2022-11-17 20:00:42 +00:00
if (!($img = self::getPath($m))) {
2021-09-09 07:12:31 +00:00
return ['w' => 16, 'h' => 16];
}
2021-11-01 09:28:22 +00:00
$info = getimagesize($img);
return ['w' => $info[0], 'h' => floor($info[1] / 3)];
}
2022-11-17 20:00:42 +00:00
}