X-Git-Url: https://git.rapsys.eu/packbundle/blobdiff_plain/26725d855a19ef36e06956c4ab6f9e6c7ef0e6e6..ca42f395bd7fadae6aa2db553d88a5b9385238f6:/Util/FacebookUtil.php diff --git a/Util/FacebookUtil.php b/Util/FacebookUtil.php index 18f37d3..91664d1 100644 --- a/Util/FacebookUtil.php +++ b/Util/FacebookUtil.php @@ -21,86 +21,39 @@ use Symfony\Component\Routing\RouterInterface; */ class FacebookUtil { /** - * The align - * - * @var string - */ - protected string $align; - - /** - * The cache directory - * - * @var string + * The default fonts */ - protected string $cache; + const fonts = [ 'default' => 'ttf/default.ttf' ]; /** - * The fill - * - * @var string + * The default font */ - protected string $fill; + const font = 'default'; /** - * The font - * - * @var string + * The default font size */ - protected string $font; + const size = 60; /** - * The fonts array - * - * @var array + * The default width */ - protected array $fonts; + const width = 15; /** - * The public path - * - * @var string + * The default fill */ - protected string $path; + const fill = 'white'; /** - * The prefix - * - * @var string + * The default stroke */ - protected string $prefix; + const stroke = '#00c3f9'; /** - * The RouterInterface instance + * The default align */ - protected RouterInterface $router; - - /** - * The size - * - * @var int - */ - protected int $size; - - /** - * The source - * - * @var ?string - */ - protected ?string $source; - - /** - * The stroke - * - * @var string - */ - protected string $stroke; - - /** - * The width - * - * @var int - */ - protected int $width; + const align = 'center'; /** * Creates a new facebook util @@ -118,42 +71,7 @@ class FacebookUtil { * @param string $stroke The stroke * @param string $align The align */ - function __construct(RouterInterface $router, string $cache = '../var/cache', string $path = './bundles/rapsyspack', string $prefix = 'facebook', ?string $source = null, array $fonts = [ 'default' => 'ttf/default.ttf' ], string $font = 'default', int $size = 60, int $width = 15, string $fill = 'white', string $stroke = '#00c3f9', string $align = 'center') { - //Set align - $this->align = $align; - - //Set cache - $this->cache = $cache.'/'.$prefix; - - //Set fill - $this->fill = $fill; - - //Set font - $this->font = $font; - - //Set fonts - $this->fonts = $fonts; - - //Set path - $this->path = $path.'/'.$prefix; - - //Set prefix key - $this->prefix = $prefix; - - //Set router - $this->router = $router; - - //Set size - $this->size = $size; - - //Set source - $this->source = $source; - - //Set stroke - $this->stroke = $stroke; - - //Set width - $this->width = $width; + function __construct(protected RouterInterface $router, protected string $cache = '../var/cache', protected string $path = './bundles/rapsyspack', protected string $prefix = 'facebook', protected ?string $source = null, protected array $fonts = self::fonts, protected string $font = self::font, protected int $size = self::size, protected int $width = self::width, protected string $fill = self::fill, protected string $stroke = self::stroke, protected string $align = self::align) { } /** @@ -181,7 +99,7 @@ class FacebookUtil { } //Set path file - $path = $this->path.$pathInfo.'.jpeg'; + $path = $this->path.'/'.$this->prefix.$pathInfo.'.jpeg'; //Without existing path if (!is_dir($dir = dirname($path))) { @@ -204,7 +122,7 @@ class FacebookUtil { //Return image data return [ - 'og:image' => $this->router->generate('rapsys_pack_facebook', ['mtime' => $mtime, 'path' => $pathInfo], UrlGeneratorInterface::ABSOLUTE_URL), + 'og:image' => $this->router->generate('rapsyspack_facebook', ['mtime' => $mtime, 'path' => $pathInfo], UrlGeneratorInterface::ABSOLUTE_URL), 'og:image:alt' => str_replace("\n", ' ', implode(' - ', array_keys($texts))), 'og:image:height' => $height, 'og:image:width' => $width @@ -212,7 +130,7 @@ class FacebookUtil { } //Set cache path - $cache = $this->cache.$pathInfo.'.png'; + $cache = $this->cache.'/'.$this->prefix.$pathInfo.'.png'; //Without cache path if (!is_dir($dir = dirname($cache))) { @@ -430,7 +348,7 @@ class FacebookUtil { //Return image data return [ - 'og:image' => $this->router->generate('rapsys_pack_facebook', ['mtime' => stat($path)['mtime'], 'path' => $pathInfo], UrlGeneratorInterface::ABSOLUTE_URL), + 'og:image' => $this->router->generate('rapsyspack_facebook', ['mtime' => stat($path)['mtime'], 'path' => $pathInfo], UrlGeneratorInterface::ABSOLUTE_URL), 'og:image:alt' => str_replace("\n", ' ', implode(' - ', array_keys($texts))), 'og:image:height' => $height, 'og:image:width' => $width