mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-03 22:27:54 +02:00
Merge pull request #6525 from marc1706/ticket/16944
[ticket/16944] Use icon bundle to load Iconify locally
This commit is contained in:
commit
f9863f9b34
@ -26,6 +26,9 @@ installLang = {
|
||||
<!-- IF S_ALLOW_CDN --><script>window.jQuery || document.write('\x3Cscript src="{T_ASSETS_PATH}/javascript/jquery-3.6.0.min.js">\x3C/script>');</script><!-- ENDIF -->
|
||||
<script src="{T_ASSETS_PATH}/javascript/core.js?assets_version={T_ASSETS_VERSION}"></script>
|
||||
<!-- INCLUDEJS admin.js -->
|
||||
|
||||
{$ICONIFY_ICONS}
|
||||
<script src="{T_ASSETS_PATH}/iconify/iconify.min.js?assets_version={T_ASSETS_VERSION}"></script>
|
||||
{$SCRIPTS}
|
||||
|
||||
</body>
|
||||
|
@ -45,8 +45,10 @@
|
||||
<script src="{T_ASSETS_PATH}/javascript/core.js?assets_version={T_ASSETS_VERSION}"></script>
|
||||
<!-- INCLUDEJS ajax.js -->
|
||||
<!-- INCLUDEJS admin.js -->
|
||||
{% INCLUDEJS T_ASSETS_PATH ~ '/iconify/iconify.min.js' %}
|
||||
|
||||
<!-- EVENT acp_overall_footer_after -->
|
||||
{$ICONIFY_ICONS}
|
||||
{$SCRIPTS}
|
||||
|
||||
{% EVENT acp_overall_footer_body_after %}
|
||||
|
@ -19,8 +19,10 @@
|
||||
<script src="{T_JQUERY_LINK}"></script>
|
||||
<!-- IF S_ALLOW_CDN --><script>window.jQuery || document.write('\x3Cscript src="{T_ASSETS_PATH}/javascript/jquery-3.6.0.min.js?assets_version={T_ASSETS_VERSION}">\x3C/script>');</script><!-- ENDIF -->
|
||||
<script src="{T_ASSETS_PATH}/javascript/core.js?assets_version={T_ASSETS_VERSION}"></script>
|
||||
{% INCLUDEJS T_ASSETS_PATH ~ '/iconify/iconify.min.js' %}
|
||||
|
||||
<!-- EVENT acp_simple_footer_after -->
|
||||
{$ICONIFY_ICONS}
|
||||
{$SCRIPTS}
|
||||
|
||||
{% EVENT acp_simple_footer_body_after %}
|
||||
|
14
phpBB/assets/iconify/iconify.min.js
vendored
Normal file
14
phpBB/assets/iconify/iconify.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -39,6 +39,8 @@
|
||||
"doctrine/dbal": "~3.3.6",
|
||||
"google/recaptcha": "~1.1",
|
||||
"guzzlehttp/guzzle": "~6.3",
|
||||
"iconify/json-tools": "^1.0",
|
||||
"iconify/json": "^2.2",
|
||||
"marc1706/fast-image-size": "^1.1",
|
||||
"s9e/text-formatter": "^2.0",
|
||||
"symfony/config": "^6.3",
|
||||
|
73
phpBB/composer.lock
generated
73
phpBB/composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "b44d1db175f1f55f55c4b9326cf02f6f",
|
||||
"content-hash": "063704733ec296bc16753ef1e07b9c8f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "bantu/ini-get-wrapper",
|
||||
@ -1781,6 +1781,77 @@
|
||||
],
|
||||
"time": "2023-04-17T16:00:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "iconify/json",
|
||||
"version": "2.2.140",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/iconify/icon-sets.git",
|
||||
"reference": "9815726deffc97bcfebc19acc697ef93bd8cbaf4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/iconify/icon-sets/zipball/9815726deffc97bcfebc19acc697ef93bd8cbaf4",
|
||||
"reference": "9815726deffc97bcfebc19acc697ef93bd8cbaf4",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Iconify\\IconsJSON\\": "lib"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "Iconify icons collection in JSON format",
|
||||
"homepage": "https://iconify.design/icon-sets/",
|
||||
"support": {
|
||||
"issues": "https://github.com/iconify/icon-sets/issues",
|
||||
"source": "https://github.com/iconify/icon-sets/tree/2.2.140"
|
||||
},
|
||||
"time": "2023-11-10T07:05:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "iconify/json-tools",
|
||||
"version": "1.0.10",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/iconify/json-tools.php.git",
|
||||
"reference": "3d24f282b309cb17e3cb80192ae071dd47bce9e0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/iconify/json-tools.php/zipball/3d24f282b309cb17e3cb80192ae071dd47bce9e0",
|
||||
"reference": "3d24f282b309cb17e3cb80192ae071dd47bce9e0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"iconify/json": "1.*",
|
||||
"phpunit/phpunit": "9.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Iconify\\JSONTools\\": "lib"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "Functions for manipulating Iconify JSON SVG collections.",
|
||||
"homepage": "https://iconify.design/",
|
||||
"support": {
|
||||
"issues": "https://github.com/iconify/json-tools.php/issues",
|
||||
"source": "https://github.com/iconify/json-tools.php/tree/1.0.10"
|
||||
},
|
||||
"time": "2020-12-16T13:04:11+00:00"
|
||||
},
|
||||
{
|
||||
"name": "justinrainbow/json-schema",
|
||||
"version": "v5.2.13",
|
||||
|
@ -1,4 +1,5 @@
|
||||
imports:
|
||||
- { resource: services_assets.yml }
|
||||
- { resource: services_attachment.yml }
|
||||
- { resource: services_auth.yml }
|
||||
- { resource: services_avatar.yml }
|
||||
|
12
phpBB/config/default/container/services_assets.yml
Normal file
12
phpBB/config/default/container/services_assets.yml
Normal file
@ -0,0 +1,12 @@
|
||||
services:
|
||||
assets.bag:
|
||||
class: phpbb\template\assets_bag
|
||||
shared: false
|
||||
arguments:
|
||||
- '@assets.iconify_bundler'
|
||||
|
||||
assets.iconify_bundler:
|
||||
class: phpbb\assets\iconify_bundler
|
||||
shared: false
|
||||
arguments:
|
||||
- '@log'
|
@ -5,6 +5,7 @@ services:
|
||||
template.twig.environment:
|
||||
class: phpbb\template\twig\environment
|
||||
arguments:
|
||||
- '@assets.bag'
|
||||
- '@config'
|
||||
- '@filesystem'
|
||||
- '@path_helper'
|
||||
|
@ -9,6 +9,18 @@ imports:
|
||||
- { resource: ../../default/container/services_twig.yml }
|
||||
|
||||
services:
|
||||
assets.bag:
|
||||
class: phpbb\template\assets_bag
|
||||
shared: false
|
||||
arguments:
|
||||
- '@assets.iconify_bundler'
|
||||
|
||||
assets.iconify_bundler:
|
||||
class: phpbb\assets\iconify_bundler
|
||||
shared: false
|
||||
arguments:
|
||||
- ~
|
||||
|
||||
cache.driver:
|
||||
class: '%cache.driver.class%'
|
||||
arguments:
|
||||
@ -76,6 +88,7 @@ services:
|
||||
template.twig.environment:
|
||||
class: phpbb\template\twig\environment
|
||||
arguments:
|
||||
- '@assets.bag'
|
||||
- '@config'
|
||||
- '@filesystem'
|
||||
- '@path_helper'
|
||||
|
@ -331,7 +331,7 @@ class acp_styles
|
||||
$rows = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Uinstall each style
|
||||
// Uninstall each style
|
||||
$uninstalled = array();
|
||||
foreach ($rows as $style)
|
||||
{
|
||||
|
@ -162,6 +162,7 @@ class bbcode
|
||||
$phpbb_container->get('config'),
|
||||
new \phpbb\template\context(),
|
||||
new \phpbb\template\twig\environment(
|
||||
$phpbb_container->get('assets.bag'),
|
||||
$phpbb_container->get('config'),
|
||||
$phpbb_container->get('filesystem'),
|
||||
$phpbb_container->get('path_helper'),
|
||||
|
@ -737,6 +737,7 @@ class messenger
|
||||
}
|
||||
|
||||
$template_environment = new \phpbb\template\twig\environment(
|
||||
$phpbb_container->get('assets.bag'),
|
||||
$phpbb_container->get('config'),
|
||||
$phpbb_container->get('filesystem'),
|
||||
$phpbb_container->get('path_helper'),
|
||||
|
@ -671,6 +671,8 @@ $lang = array_merge($lang, array(
|
||||
'LOG_USERS_APPROVED' => '<strong>Users approved in usergroup</strong> %1$s<br />» %2$s',
|
||||
'LOG_USERS_PENDING' => '<strong>Users requested to join group “%1$s” and need to be approved</strong><br />» %2$s',
|
||||
|
||||
'LOG_ICON_INVALID' => '<strong>Invalid icon supplied:</strong> Icon <i>%1$s</i> does not seem to exist.',
|
||||
'LOG_ICON_COLLECTION_INVALID' => '<strong>Invalid icon collection supplied:</strong> Icon collection with prefix <i>%1$s</i> does not seem to exist.',
|
||||
'LOG_IMAGE_GENERATION_ERROR' => '<strong>Error while creating image</strong><br />» Error in %1$s on line %2$s: %3$s',
|
||||
|
||||
'LOG_INACTIVE_ACTIVATE' => '<strong>Activated inactive users</strong><br />» %s',
|
||||
|
250
phpBB/phpbb/assets/iconify_bundler.php
Normal file
250
phpBB/phpbb/assets/iconify_bundler.php
Normal file
@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\assets;
|
||||
|
||||
use Iconify\JSONTools\Collection;
|
||||
use phpbb\log\log_interface;
|
||||
|
||||
class iconify_bundler
|
||||
{
|
||||
/** @var log_interface */
|
||||
protected $log;
|
||||
|
||||
/** @var string[] Icons list */
|
||||
protected $icons_list = [];
|
||||
|
||||
/**
|
||||
* Constructor for iconify bundler
|
||||
*
|
||||
* @param log_interface|null $log Logger
|
||||
*/
|
||||
public function __construct(?log_interface $log)
|
||||
{
|
||||
$this->log = $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run iconify bundler
|
||||
*
|
||||
* @return string Iconify bundle
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Sort icons first
|
||||
sort($this->icons_list, SORT_NATURAL);
|
||||
|
||||
$organized_icons = $this->organize_icons_list();
|
||||
|
||||
$output = $this->load_icons_data($organized_icons);
|
||||
if (!$output)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$output = '(function() {
|
||||
function add(data) {
|
||||
try {
|
||||
if (typeof self.Iconify === \'object\' && self.Iconify.addCollection) {
|
||||
self.Iconify.addCollection(data);
|
||||
return;
|
||||
}
|
||||
if (typeof self.IconifyPreload === \'undefined\') {
|
||||
self.IconifyPreload = [];
|
||||
}
|
||||
self.IconifyPreload.push(data);
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
' . $output . '
|
||||
})();' . "\n";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add icon to icons list
|
||||
*
|
||||
* @param string $icon_name
|
||||
* @return void
|
||||
*/
|
||||
protected function add_icon(string $icon_name): void
|
||||
{
|
||||
if (!in_array($icon_name, $this->icons_list))
|
||||
{
|
||||
$this->icons_list[] = $icon_name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add multiple icons to icons list
|
||||
*
|
||||
* @param array $icons
|
||||
* @return void
|
||||
*/
|
||||
public function add_icons(array $icons): void
|
||||
{
|
||||
foreach ($icons as $icon)
|
||||
{
|
||||
$this->add_icon($icon);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Organize icons list by prefix
|
||||
*
|
||||
* Result is an object, where key is prefix, value is array of icon names
|
||||
*
|
||||
* @return array Organized icons list
|
||||
*/
|
||||
protected function organize_icons_list(): array
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach ($this->icons_list as $icon_name)
|
||||
{
|
||||
// Split icon to prefix and name
|
||||
$icon = $this->name_to_icon($icon_name);
|
||||
if ($icon === null)
|
||||
{
|
||||
// Invalid name or icon name does not have provider
|
||||
if ($this->log)
|
||||
{
|
||||
$this->log->add('critical', ANONYMOUS, '', 'LOG_ICON_INVALID', false, [$icon_name]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$prefix = $icon['prefix'];
|
||||
$name = $icon['name'];
|
||||
|
||||
// Add icon to results
|
||||
if (!isset($results[$prefix]))
|
||||
{
|
||||
$results[$prefix] = [$name];
|
||||
continue;
|
||||
}
|
||||
if (!in_array($name, $results[$prefix]))
|
||||
{
|
||||
$results[$prefix][] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert icon name from string to object.
|
||||
*
|
||||
* Object properties:
|
||||
* - provider (ignored in this example)
|
||||
* - prefix
|
||||
* - name
|
||||
*
|
||||
* This function was converted to PHP from @iconify/utils/src/icon/name.ts
|
||||
* See https://github.com/iconify/iconify/blob/master/packages/utils/src/icon/name.ts
|
||||
*
|
||||
* @param string $icon_name Icon name
|
||||
* @return array|null Icon data or null if icon is invalid
|
||||
*/
|
||||
protected function name_to_icon(string $icon_name): ?array
|
||||
{
|
||||
$provider = '';
|
||||
$colonSeparated = explode(':', $icon_name);
|
||||
|
||||
// Check for provider with correct '@' at start
|
||||
if (substr($icon_name, 0, 1) === '@')
|
||||
{
|
||||
// First part is provider
|
||||
if (count($colonSeparated) < 2 || count($colonSeparated) > 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
$provider = substr(array_shift($colonSeparated), 1);
|
||||
}
|
||||
|
||||
// Check split by colon: "prefix:name", "provider:prefix:name"
|
||||
if (!$colonSeparated || count($colonSeparated) > 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (count($colonSeparated) > 1)
|
||||
{
|
||||
// "prefix:name"
|
||||
$name = array_pop($colonSeparated);
|
||||
$prefix = array_pop($colonSeparated);
|
||||
return [
|
||||
// Allow provider without '@': "provider:prefix:name"
|
||||
'provider' => count($colonSeparated) > 0 ? $colonSeparated[0] : $provider,
|
||||
'prefix' => $prefix,
|
||||
'name' => $name,
|
||||
];
|
||||
}
|
||||
|
||||
// Attempt to split by dash: "prefix-name"
|
||||
$dashSeparated = explode('-', $colonSeparated[0]);
|
||||
if (count($dashSeparated) > 1)
|
||||
{
|
||||
return [
|
||||
'provider' => $provider,
|
||||
'prefix' => array_shift($dashSeparated),
|
||||
'name' => implode('-', $dashSeparated),
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load icons date for supplied icons array
|
||||
*
|
||||
* @param array $icons
|
||||
* @return string
|
||||
*/
|
||||
protected function load_icons_data(array $icons): string
|
||||
{
|
||||
// Load icons data
|
||||
$output = '';
|
||||
foreach ($icons as $prefix => $iconsList)
|
||||
{
|
||||
// Load icon set
|
||||
$collection = new Collection($prefix);
|
||||
$collection_file = Collection::findIconifyCollection($prefix);
|
||||
if (!file_exists($collection_file) || !$collection->loadFromFile($collection_file))
|
||||
{
|
||||
$this->log?->add('critical', ANONYMOUS, '', 'LOG_ICON_COLLECTION_INVALID', false, [$prefix]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Make sure all icons exist
|
||||
foreach ($iconsList as $key => $name)
|
||||
{
|
||||
if (!$collection->iconExists($name))
|
||||
{
|
||||
$this->log?->add('critical', ANONYMOUS, '', 'LOG_ICON_INVALID', false, [$prefix . ':' . $name]);
|
||||
unset($iconsList[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Get data for all icons as string
|
||||
$output .= $collection->scriptify([
|
||||
'icons' => $iconsList,
|
||||
'callback' => 'add',
|
||||
'optimize' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@
|
||||
|
||||
namespace phpbb\template;
|
||||
|
||||
use phpbb\assets\iconify_bundler;
|
||||
|
||||
class assets_bag
|
||||
{
|
||||
/** @var asset[] */
|
||||
@ -21,6 +23,17 @@ class assets_bag
|
||||
/** @var asset[] */
|
||||
protected $scripts = [];
|
||||
|
||||
/** @var string[] */
|
||||
protected $iconify_icons = [];
|
||||
|
||||
/**
|
||||
* Constructor for assets bag
|
||||
*
|
||||
* @param iconify_bundler $iconify_bundler
|
||||
*/
|
||||
public function __construct(protected iconify_bundler $iconify_bundler)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Add a css asset to the bag
|
||||
*
|
||||
@ -41,6 +54,30 @@ class assets_bag
|
||||
$this->scripts[] = $asset;
|
||||
}
|
||||
|
||||
public function add_iconify_icon(string $icon): void
|
||||
{
|
||||
$this->iconify_icons[] = $icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject iconify icons into template
|
||||
*
|
||||
* @param string $output Output before injection
|
||||
* @param string $variable_name Variable name for injection
|
||||
* @param bool $use_cdn Flag whether to use CDN or local data
|
||||
*
|
||||
* @return string Output after injection
|
||||
*/
|
||||
public function inject_iconify_icons(string $output, string $variable_name, bool $use_cdn): string
|
||||
{
|
||||
if (str_contains($output, $variable_name))
|
||||
{
|
||||
$output = str_replace($variable_name, $use_cdn ? '' : $this->get_iconify_content(), $output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all css assets
|
||||
*
|
||||
@ -92,4 +129,22 @@ class assets_bag
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTML code to include all iconify icons
|
||||
*
|
||||
* @return string HTML code for iconify bundle
|
||||
*/
|
||||
public function get_iconify_content(): string
|
||||
{
|
||||
$output = '';
|
||||
if (count($this->iconify_icons))
|
||||
{
|
||||
$output .= '<script>';
|
||||
$this->iconify_bundler->add_icons($this->iconify_icons);
|
||||
$output .= $this->iconify_bundler->run();
|
||||
$output .= '</script>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
@ -13,26 +13,32 @@
|
||||
|
||||
namespace phpbb\template\twig;
|
||||
|
||||
use phpbb\config\config;
|
||||
use phpbb\event\dispatcher_interface;
|
||||
use phpbb\extension\manager;
|
||||
use phpbb\filesystem\filesystem;
|
||||
use phpbb\path_helper;
|
||||
use phpbb\template\assets_bag;
|
||||
use Twig\Loader\LoaderInterface;
|
||||
|
||||
class environment extends \Twig\Environment
|
||||
{
|
||||
/** @var \phpbb\config\config */
|
||||
/** @var config */
|
||||
protected $phpbb_config;
|
||||
|
||||
/** @var \phpbb\filesystem\filesystem */
|
||||
/** @var filesystem */
|
||||
protected $filesystem;
|
||||
|
||||
/** @var \phpbb\path_helper */
|
||||
/** @var path_helper */
|
||||
protected $phpbb_path_helper;
|
||||
|
||||
/** @var \Symfony\Component\DependencyInjection\ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
/** @var \phpbb\extension\manager */
|
||||
/** @var manager */
|
||||
protected $extension_manager;
|
||||
|
||||
/** @var \phpbb\event\dispatcher_interface */
|
||||
/** @var dispatcher_interface */
|
||||
protected $phpbb_dispatcher;
|
||||
|
||||
/** @var string */
|
||||
@ -50,16 +56,17 @@ class environment extends \Twig\Environment
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\config\config $phpbb_config The phpBB configuration
|
||||
* @param \phpbb\filesystem\filesystem $filesystem
|
||||
* @param \phpbb\path_helper $path_helper phpBB path helper
|
||||
* @param assets_bag $assets_bag Assets bag
|
||||
* @param config $phpbb_config The phpBB configuration
|
||||
* @param filesystem $filesystem
|
||||
* @param path_helper $path_helper phpBB path helper
|
||||
* @param string $cache_path The path to the cache directory
|
||||
* @param \phpbb\extension\manager|null $extension_manager phpBB extension manager
|
||||
* @param \Twig\Loader\LoaderInterface|null $loader Twig loader interface
|
||||
* @param \phpbb\event\dispatcher_interface|null $phpbb_dispatcher Event dispatcher object
|
||||
* @param manager|null $extension_manager phpBB extension manager
|
||||
* @param LoaderInterface|null $loader Twig loader interface
|
||||
* @param dispatcher_interface|null $phpbb_dispatcher Event dispatcher object
|
||||
* @param array $options Array of options to pass to Twig
|
||||
*/
|
||||
public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig\Loader\LoaderInterface $loader = null, \phpbb\event\dispatcher_interface $phpbb_dispatcher = null, $options = array())
|
||||
public function __construct(assets_bag $assets_bag, config $phpbb_config, filesystem $filesystem, path_helper $path_helper, $cache_path, manager $extension_manager = null, LoaderInterface $loader = null, dispatcher_interface $phpbb_dispatcher = null, $options = array())
|
||||
{
|
||||
$this->phpbb_config = $phpbb_config;
|
||||
|
||||
@ -70,7 +77,7 @@ class environment extends \Twig\Environment
|
||||
|
||||
$this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path();
|
||||
|
||||
$this->assets_bag = new assets_bag();
|
||||
$this->assets_bag = $assets_bag;
|
||||
|
||||
$options = array_merge(array(
|
||||
'cache' => (defined('IN_INSTALL')) ? false : $cache_path,
|
||||
@ -97,7 +104,7 @@ class environment extends \Twig\Environment
|
||||
/**
|
||||
* Get phpBB config
|
||||
*
|
||||
* @return \phpbb\config\config
|
||||
* @return config
|
||||
*/
|
||||
public function get_phpbb_config()
|
||||
{
|
||||
@ -117,7 +124,7 @@ class environment extends \Twig\Environment
|
||||
/**
|
||||
* Get the filesystem object
|
||||
*
|
||||
* @return \phpbb\filesystem\filesystem
|
||||
* @return filesystem
|
||||
*/
|
||||
public function get_filesystem()
|
||||
{
|
||||
@ -137,7 +144,7 @@ class environment extends \Twig\Environment
|
||||
/**
|
||||
* Get the phpbb path helper object
|
||||
*
|
||||
* @return \phpbb\path_helper
|
||||
* @return path_helper
|
||||
*/
|
||||
public function get_path_helper()
|
||||
{
|
||||
@ -204,6 +211,7 @@ class environment extends \Twig\Environment
|
||||
{
|
||||
$context['definition']->set('SCRIPTS', '__SCRIPTS_' . $placeholder_salt . '__');
|
||||
$context['definition']->set('STYLESHEETS', '__STYLESHEETS_' . $placeholder_salt . '__');
|
||||
$context['definition']->set('ICONIFY_ICONS', '__ICONIFY_ICONS_' . $placeholder_salt . '__');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,6 +259,7 @@ class environment extends \Twig\Environment
|
||||
{
|
||||
$output = str_replace('__STYLESHEETS_' . $placeholder_salt . '__', $this->assets_bag->get_stylesheets_content(), $output);
|
||||
$output = str_replace('__SCRIPTS_' . $placeholder_salt . '__', $this->assets_bag->get_scripts_content(), $output);
|
||||
$output = $this->assets_bag->inject_iconify_icons($output, '__ICONIFY_ICONS_' . $placeholder_salt . '__', $this->phpbb_config['allow_cdn']);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
@ -89,6 +89,8 @@ class icon extends AbstractExtension
|
||||
case 'iconify':
|
||||
$source = explode(':', $icon);
|
||||
$source = $source[0];
|
||||
$environment->get_assets_bag()->add_iconify_icon($icon);
|
||||
|
||||
break;
|
||||
|
||||
case 'png':
|
||||
|
@ -76,7 +76,7 @@
|
||||
<script src="{T_ASSETS_PATH}/javascript/core.js?assets_version={T_ASSETS_VERSION}"></script>
|
||||
<!-- INCLUDEJS forum_fn.js -->
|
||||
<!-- INCLUDEJS ajax.js -->
|
||||
<script src="https://code.iconify.design/1/1.0.6/iconify.min.js"></script>
|
||||
{% INCLUDEJS T_ASSETS_PATH ~ '/iconify/iconify.min.js' %}
|
||||
|
||||
<!-- IF S_COOKIE_NOTICE -->
|
||||
<script src="{T_ASSETS_PATH}/cookieconsent/cookieconsent.min.js?assets_version={T_ASSETS_VERSION}"></script>
|
||||
@ -108,6 +108,7 @@
|
||||
<!-- EVENT overall_footer_after -->
|
||||
|
||||
<!-- IF S_PLUPLOAD --><!-- INCLUDE plupload.html --><!-- ENDIF -->
|
||||
{$ICONIFY_ICONS}
|
||||
{$SCRIPTS}
|
||||
|
||||
<!-- EVENT overall_footer_body_after -->
|
||||
|
@ -46,10 +46,10 @@
|
||||
<script src="{T_ASSETS_PATH}/javascript/core.js?assets_version={T_ASSETS_VERSION}"></script>
|
||||
<!-- INCLUDEJS forum_fn.js -->
|
||||
<!-- INCLUDEJS ajax.js -->
|
||||
<script src="https://code.iconify.design/1/1.0.0-rc7/iconify.min.js"></script>
|
||||
{% INCLUDEJS T_ASSETS_PATH ~ '/iconify/iconify.min.js' %}
|
||||
|
||||
<!-- EVENT simple_footer_after -->
|
||||
|
||||
{$ICONIFY_ICONS}
|
||||
{$SCRIPTS}
|
||||
|
||||
{% EVENT simple_footer_body_after %}
|
||||
|
141
tests/assets/iconify_bundler_test.php
Normal file
141
tests/assets/iconify_bundler_test.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\tests\unit\assets;
|
||||
|
||||
class iconify_bundler_test extends \phpbb_test_case
|
||||
{
|
||||
/** @var array Log content */
|
||||
protected $log_content = [];
|
||||
|
||||
/** @var \phpbb\assets\iconify_bundler */
|
||||
protected $bundler;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$log = $this->getMockBuilder('\phpbb\log\dummy')
|
||||
->onlyMethods(['add'])
|
||||
->getMock();
|
||||
$log->method('add')
|
||||
->willReturnCallback(function ($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array()) {
|
||||
$this->log_content[] = $log_operation;
|
||||
});
|
||||
|
||||
$this->bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
}
|
||||
|
||||
public function data_test_generate_bundle()
|
||||
{
|
||||
return [
|
||||
[
|
||||
['fa:address-card-o'],
|
||||
['"prefix":"fa"', '"address-card-o"'],
|
||||
],
|
||||
[
|
||||
['fa:address-card-o', 'fa-regular:credit-card'],
|
||||
['"prefix":"fa"', '"address-card-o"', '"prefix":"fa-regular"', '"credit-card"'],
|
||||
],
|
||||
[
|
||||
['fa:address-card-o', 'fa:foo-bar'],
|
||||
['"prefix":"fa"', '"address-card-o"'],
|
||||
['LOG_ICON_INVALID'],
|
||||
],
|
||||
[
|
||||
['fa:address-card-o', 'fa-regular:credit-card', 'fa-regular:credit-card'],
|
||||
['"prefix":"fa"', '"address-card-o"', '"prefix":"fa-regular"', '"credit-card"'],
|
||||
],
|
||||
[
|
||||
['fa:address-card-o', 'fa-regular:credit-card', 'fa-regular:angry'],
|
||||
['"prefix":"fa"', '"address-card-o"', '"prefix":"fa-regular"', '"credit-card"', '"angry"'],
|
||||
],
|
||||
[
|
||||
['fa:address-card-o', 'fa:bell', 'fa-regular:credit-card', 'fa-regular:angry'],
|
||||
['"prefix":"fa"', '"address-card-o"', '"bell"', '"prefix":"fa-regular"', '"credit-card"', '"angry"'],
|
||||
],
|
||||
[
|
||||
['@test'],
|
||||
[],
|
||||
['LOG_ICON_INVALID'],
|
||||
],
|
||||
[
|
||||
['fa:address-foo-o'],
|
||||
['"prefix":"fa"', '"icons":[]'],
|
||||
['LOG_ICON_INVALID'],
|
||||
],
|
||||
[
|
||||
['foo:bar'],
|
||||
[],
|
||||
['LOG_ICON_COLLECTION_INVALID']
|
||||
],
|
||||
[
|
||||
['@iconify:fa:address-card-o'],
|
||||
['"prefix":"fa"', '"address-card-o"'],
|
||||
],
|
||||
[
|
||||
['@iconify:someother:fa:address-card-o'],
|
||||
[],
|
||||
['LOG_ICON_INVALID'],
|
||||
],
|
||||
[
|
||||
['iconify:fa:address-card-o'],
|
||||
['"prefix":"fa"', '"address-card-o"'],
|
||||
],
|
||||
[
|
||||
['iconify:fa:fa:address-card-o'],
|
||||
[],
|
||||
['LOG_ICON_INVALID'],
|
||||
],
|
||||
[
|
||||
['test'],
|
||||
[],
|
||||
['LOG_ICON_INVALID'],
|
||||
],
|
||||
[
|
||||
[''],
|
||||
[],
|
||||
['LOG_ICON_INVALID'],
|
||||
],
|
||||
[
|
||||
['fa-address-card-o'],
|
||||
['"prefix":"fa"', '"address-card-o"'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_test_generate_bundle
|
||||
*/
|
||||
public function test_generate_bundle($icons, $expected, $log_content = [])
|
||||
{
|
||||
$this->bundler->add_icons($icons);
|
||||
$bundle = $this->bundler->run();
|
||||
foreach ($expected as $expected_part)
|
||||
{
|
||||
$this->assertStringContainsString($expected_part, $bundle, 'Failed asserting that generated bundle contains ' . $expected_part);
|
||||
}
|
||||
|
||||
if (!count($expected))
|
||||
{
|
||||
$this->assertEquals($bundle, '', 'Failed asserting that generated bundle is empty');
|
||||
}
|
||||
|
||||
if (count($log_content))
|
||||
{
|
||||
$this->assertEquals($this->log_content, $log_content, 'Failed asserting that log content is correct');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->assertEmpty($this->log_content, 'Failed asserting that log content is empty');
|
||||
}
|
||||
}
|
||||
}
|
@ -116,9 +116,13 @@ abstract class phpbb_controller_common_helper_route extends phpbb_database_test_
|
||||
$container = new phpbb_mock_container_builder();
|
||||
$container->setParameter('core.environment', PHPBB_ENVIRONMENT);
|
||||
$cache_path = $phpbb_root_path . 'cache/twig';
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$context = new \phpbb\template\context();
|
||||
$loader = new \phpbb\template\twig\loader('');
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$this->config,
|
||||
$this->filesystem,
|
||||
$this->phpbb_path_helper,
|
||||
|
@ -66,8 +66,14 @@ class phpbb_email_parsing_test extends phpbb_test_case
|
||||
);
|
||||
$phpbb_container->set('ext.manager', $extension_manager);
|
||||
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$phpbb_container->set('assets.bag', $assets_bag);
|
||||
|
||||
$context = new \phpbb\template\context();
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$config,
|
||||
$filesystem,
|
||||
$phpbb_path_helper,
|
||||
|
@ -66,7 +66,11 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
|
||||
$this->phpbb_root_path,
|
||||
$this->phpEx
|
||||
);
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$this->config,
|
||||
$filesystem,
|
||||
$phpbb_path_helper,
|
||||
|
@ -95,7 +95,11 @@ class phpbb_template_extension_test extends phpbb_template_template_test_case
|
||||
$cache_path = $phpbb_root_path . 'cache/twig';
|
||||
$context = new \phpbb\template\context();
|
||||
$loader = new \phpbb\template\twig\loader([]);
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$config,
|
||||
$filesystem,
|
||||
$phpbb_path_helper,
|
||||
|
@ -58,7 +58,11 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case
|
||||
$cache_path = $phpbb_root_path . 'cache/twig';
|
||||
$context = new \phpbb\template\context();
|
||||
$loader = new \phpbb\template\twig\loader('');
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$config,
|
||||
$filesystem,
|
||||
$path_helper,
|
||||
|
@ -152,7 +152,11 @@ Zeta test event in all',
|
||||
$cache_path = $phpbb_root_path . 'cache/twig';
|
||||
$context = new \phpbb\template\context();
|
||||
$loader = new \phpbb\template\twig\loader('');
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$config,
|
||||
$filesystem,
|
||||
$path_helper,
|
||||
|
@ -44,7 +44,11 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
|
||||
$cache_path = $phpbb_root_path . 'cache/twig';
|
||||
$context = new \phpbb\template\context();
|
||||
$loader = new \phpbb\template\twig\loader('');
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$config,
|
||||
$filesystem,
|
||||
$this->phpbb_path_helper,
|
||||
|
@ -95,7 +95,11 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||
$cache_path = $phpbb_root_path . 'cache/twig';
|
||||
$context = new \phpbb\template\context();
|
||||
$loader = new \phpbb\template\twig\loader('');
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$config,
|
||||
$filesystem,
|
||||
$path_helper,
|
||||
|
@ -45,7 +45,11 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
|
||||
$cache_path = $phpbb_root_path . 'cache/twig';
|
||||
$context = new \phpbb\template\context();
|
||||
$loader = new \phpbb\template\twig\loader('');
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$config,
|
||||
$filesystem,
|
||||
$this->phpbb_path_helper,
|
||||
|
@ -63,7 +63,11 @@ class twig_test extends \phpbb_test_case
|
||||
$cache_path = $phpbb_root_path . 'cache/twig';
|
||||
$context = new \phpbb\template\context();
|
||||
$loader = new \phpbb\template\twig\loader('');
|
||||
$log = new \phpbb\log\dummy();
|
||||
$iconify_bundler = new \phpbb\assets\iconify_bundler($log);
|
||||
$assets_bag = new \phpbb\template\assets_bag($iconify_bundler);
|
||||
$twig = new \phpbb\template\twig\environment(
|
||||
$assets_bag,
|
||||
$config,
|
||||
$filesystem,
|
||||
$path_helper,
|
||||
|
Loading…
x
Reference in New Issue
Block a user