noodles/inc/lib.image.path.php

79 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
*
* @package Dotclear
2021-09-08 23:05:05 +00:00
* @subpackage Plugin
*
2021-09-08 23:05:05 +00:00
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-09-08 22:53:13 +00:00
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
2021-09-09 07:12:31 +00:00
public static function getArray($core, $m = '')
{
if (!$core->plugins->moduleExists($m)
2021-09-09 07:12:31 +00:00
|| !$core->url->getBase($m . 'module')
) {
return [
'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' => [
'dir' => path::real($core->blog->themes_path . '/' . $core->blog->settings->system->theme . '/img') . '/' . $m . '-default-image.png',
2021-09-09 07:12:31 +00:00
'url' => $core->blog->settings->system->themes_url . $core->blog->settings->system->theme . '/img/' . $m . '-default-image.png'
],
'public' => [
'dir' => path::real($core->blog->public_path) . '/' . $m . '-default-image.png',
2021-09-09 07:12:31 +00:00
'url' => $core->blog->host . path::clean($core->blog->settings->system->public_url) . '/' . $m . '-default-image.png'
],
'module' => [
'dir' => path::real($core->plugins->moduleRoot($m) . '/default-templates/img') . '/' . $m . '-default-image.png',
2021-09-09 07:12:31 +00:00
'url' => $core->blog->url . $core->url->getBase($m . 'module') . '/img/' . $m . '-default-image.png'
]
];
}
2021-09-08 22:53:13 +00:00
2021-09-09 07:12:31 +00:00
public static function getUrl($core, $m = '')
{
2021-09-09 07:12:31 +00:00
$files = self::getArray($core, $m);
foreach($files as $k => $file) {
if (file_exists($files[$k]['dir']))
return $files[$k]['url'];
}
return null;
}
2021-09-08 22:53:13 +00:00
2021-09-09 07:12:31 +00:00
public static function getPath($core, $m = '')
{
2021-09-09 07:12:31 +00:00
$files = self::getArray($core, $m);
foreach($files as $k => $file) {
if (file_exists($files[$k]['dir']))
return $files[$k]['dir'];
}
return null;
}
2021-09-08 22:53:13 +00:00
2021-09-09 07:12:31 +00:00
public static function getSize($core, $m = '')
{
2021-09-09 07:12:31 +00:00
if (!($img = self::getPath($core, $m)))
return ['w' => 16, 'h' => 16];
else {
$info = getimagesize($img);
2021-09-09 07:12:31 +00:00
return ['w' => $info[0], 'h' => floor($info[1] /3)];
}
}
}