Skip to content

Commit

Permalink
feat(form): icon dropdown list included in the project
Browse files Browse the repository at this point in the history
svg no longer in  Font Awesome 6; an API is provided to get data we need, but it timeouts too often with 5 seconds
  • Loading branch information
btry committed Mar 9, 2022
1 parent 85609c4 commit 1902cb2
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 128 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ vendor/
/.gtm/
lib/

# Ignore content of data except for the index
data/*
!data/index.php

# Ignore content of data except for the index
css_compiled/*
!css_compiled/remove.txt
Expand Down
67 changes: 0 additions & 67 deletions ajax/target_actor.php

This file was deleted.

13 changes: 0 additions & 13 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,19 +610,6 @@ function plugin_formcreator_dynamicReport($params) {
return false;
}

function plugin_formcreator_hook_update_plugin(CommonDBTM $item) {
if ($item->fields['directory'] != 'formcreator') {
return;
}

if ($item->fields['state'] != Plugin::ACTIVATED) {
return;
}

// This is Formcreator, and its state switched to enabled
PluginFormcreatorCommon::buildFontAwesomeData();
}

/**
* Hook for timeline_actions; display a new action for a CommonITILObject
* @see CommonITILObject
Expand Down
37 changes: 2 additions & 35 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ public static function prepareBooleanKeywords(string $keywords) : string {
*
* @return array
*/
public static function getFontAwesomePictoNames() : array {
public static function getFontAwesomePictoNames(): array {
static $list = null;

$list = $list ?? require_once(GLPI_PLUGIN_DOC_DIR . '/formcreator/' . self::getPictoFilename());
$list = $list ?? require_once(Plugin::getPhpDir('formcreator') . '/data/' . self::getPictoFilename());
return $list;
}

Expand Down Expand Up @@ -541,39 +541,6 @@ public static function cleanOldCaptchas($expiration = 600) {
}
}

public static function buildFontAwesomeData() {
$fontAwesomeDir = GLPI_ROOT . '/public/lib/fortawesome/fontawesome-free/webfonts';
$outFile = GLPI_PLUGIN_DOC_DIR . '/formcreator/font-awesome.php';
@mkdir(dirname($outFile));
if (!is_readable($fontAwesomeDir) || !is_writable(dirname($outFile))) {
return false;
}

$faSvgFiles = [
'fa' => "$fontAwesomeDir/fa-regular-400.svg",
'fab' => "$fontAwesomeDir/fa-brands-400.svg",
'fas' => "$fontAwesomeDir/fa-solid-900.svg",
];

$fanames = [];
$searchRegex = '#glyph-name=\"([^\"]*)\"#i';
foreach ($faSvgFiles as $key => $svgSource) {
$svg = file_get_contents($svgSource);
$matches = null;
preg_match_all($searchRegex, $svg, $matches);
foreach ($matches[1] as $name) {
$fanames["$key fa-$name"] = $name;
}
$list = '<?php' . PHP_EOL . 'return ' . var_export($fanames, true) . ';';
$size = file_put_contents($outFile, $list);
if ($size != strlen($list)) {
return false;
}
}

return true;
}

/**
* get path to CSS file
*
Expand Down
1 change: 0 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ function plugin_formcreator_permanent_hook() {
$PLUGIN_HOOKS['item_update']['formcreator'] = [
Ticket::class => 'plugin_formcreator_hook_update_ticket',
TicketValidation::class => 'plugin_formcreator_hook_update_ticketvalidation',
Plugin::class => 'plugin_formcreator_hook_update_plugin',
Profile::class => 'plugin_formcreator_hook_update_profile',
];
$PLUGIN_HOOKS['item_delete']['formcreator'] = [
Expand Down
8 changes: 0 additions & 8 deletions tests/1-install/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public function testUpgradedPlugin() {

// Check the version saved in configuration
$this->checkConfig();
$this->checkFontAwesomeData();
$this->testPluginName();

$fresh_tables = $DB->listTables("glpi_plugin_${pluginName}_%");
Expand Down Expand Up @@ -188,13 +187,6 @@ public function checkAutomaticAction() {
$this->integer((int) $cronTask->fields['state'])->isEqualTo(0);
}

public function checkFontAwesomeData() {
$pluginName = TEST_PLUGIN_NAME;

$file = GLPI_ROOT . '/files/_plugins/' . $pluginName . '/font-awesome.php';
$this->boolean(is_readable($file))->isTrue();
}

/**
* Undocumented function
*
Expand Down

0 comments on commit 1902cb2

Please sign in to comment.