Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
dist/
vendor/
.gh_token
*.min.*
*.min.*
var/
.tokensave
24 changes: 18 additions & 6 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function plugin_treeview_install()
}

// No autoload when plugin is not activated
require __DIR__ . '/inc/profile.class.php';
require_once __DIR__ . '/inc/profile.class.php';

PluginTreeviewProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);

Expand Down Expand Up @@ -158,6 +158,7 @@ function plugin_treeview_upgrade11to12()
if ($DB->fieldExists('glpi_plugin_treeview_profiles', 'interface')) {
$query .= ' DROP `interface`,';
}

if ($DB->fieldExists('glpi_plugin_treeview_profiles', 'is_default')) {
$query .= ' DROP `is_default`';
}
Expand All @@ -180,26 +181,33 @@ function plugin_treeview_upgrade12to13()
$query = 'ALTER TABLE `glpi_plugin_treeview_displayprefs` ';

if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'ID')) {
$query .= " CHANGE `ID` `id` int {$default_key_sign} NOT NULL auto_increment,";
$query .= sprintf(' CHANGE `ID` `id` int %s NOT NULL auto_increment,', $default_key_sign);
}

if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'folderLinks')) {
$query .= " CHANGE `folderLinks` `folderLinks` tinyint NOT NULL default '0',";
}

if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'useSelection')) {
$query .= " CHANGE `useSelection` `useSelection` tinyint NOT NULL default '0',";
}

if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'useLines')) {
$query .= " CHANGE `useLines` `useLines` tinyint NOT NULL default '0',";
}

if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'useIcons')) {
$query .= " CHANGE `useIcons` `useIcons` tinyint NOT NULL default '0',";
}

if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'closeSameLevel')) {
$query .= " CHANGE `closeSameLevel` `closeSameLevel` tinyint NOT NULL default '0',";
}

if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'itemName')) {
$query .= " CHANGE `itemName` `itemName` int NOT NULL default '0',";
}

if ($DB->fieldExists('glpi_plugin_treeview_displayprefs', 'locationName')) {
$query .= " CHANGE `locationName` `locationName` int NOT NULL default '0'";
}
Expand All @@ -211,8 +219,9 @@ function plugin_treeview_upgrade12to13()
$query = 'ALTER TABLE `glpi_plugin_treeview_profiles` ';

if ($DB->fieldExists('glpi_plugin_treeview_profiles', 'ID')) {
$query .= " CHANGE `ID` `id` int {$default_key_sign} NOT NULL auto_increment";
$query .= sprintf(' CHANGE `ID` `id` int %s NOT NULL auto_increment', $default_key_sign);
}

$DB->doQuery($query);
}

Expand All @@ -222,14 +231,17 @@ function plugin_treeview_upgrade12to13()
$query = 'ALTER TABLE `glpi_plugin_treeview_preferences` ';

if ($DB->fieldExists('glpi_plugin_treeview_preferences', 'ID')) {
$query .= " CHANGE `ID` `id` int {$default_key_sign} NOT NULL auto_increment,";
$query .= sprintf(' CHANGE `ID` `id` int %s NOT NULL auto_increment,', $default_key_sign);
}

if ($DB->fieldExists('glpi_plugin_treeview_preferences', 'user_id')) {
$query .= " CHANGE `user_id` `users_id` int {$default_key_sign} NOT NULL default '0' COMMENT 'RELATION to glpi_users (id)',";
$query .= sprintf(" CHANGE `user_id` `users_id` int %s NOT NULL default '0' COMMENT 'RELATION to glpi_users (id)',", $default_key_sign);
}

if ($DB->fieldExists('glpi_plugin_treeview_preferences', 'show')) {
$query .= " CHANGE `show` `show_on_load` int NOT NULL default '0'";
}

$DB->doQuery($query);
}
}
Expand Down Expand Up @@ -261,7 +273,7 @@ function plugin_treeview_uninstall()
];

foreach ($tables as $table) {
$query = "DROP TABLE IF EXISTS `$table`;";
$query = sprintf('DROP TABLE IF EXISTS `%s`;', $table);
$DB->doQuery($query);
}

Expand Down
37 changes: 20 additions & 17 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,18 @@ public static function getTypeName($nb = 0)

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
switch ($item->getType()) {
case "Config":
return self::createTabEntry(self::getTypeName(), 0, $item::getType(), self::getIcon());
if ($item->getType() === "Config") {
return self::createTabEntry(self::getTypeName(), 0, $item::getType(), self::getIcon());
}

return '';
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
$config = new self();
switch ($item->getType()) {
case "Config":
$config->showConfigForm();
if ($item->getType() === "Config") {
$config->showConfigForm();
}

return true;
Expand Down Expand Up @@ -205,8 +204,8 @@ public function buildTreeview()
$treeview_url = $CFG_GLPI['root_doc'] . "/plugins/treeview";

//necessary files needed for the tree to work.
echo "<link rel='stylesheet' type='text/css' href='$treeview_url/public/css/dtree.css' type='text/css'>";
echo "<script type='text/javascript' src='$treeview_url/public/lib/dtree/dtree.js'></script>";
echo sprintf("<link rel='stylesheet' type='text/css' href='%s/public/css/dtree.css' type='text/css'>", $treeview_url);
echo sprintf("<script type='text/javascript' src='%s/public/lib/dtree/dtree.js'></script>", $treeview_url);

echo "<div class='dtree'>";
echo "<script type='text/javascript'>";
Expand Down Expand Up @@ -261,7 +260,8 @@ public function getNodesFromDb()
$result = $it->current();

$max_level = $result['max_level'];
$tv_id = $max_id = $result['max_id'];
$tv_id = $result['max_id'];
$max_id = $result['max_id'];
$tv_id++;

// Is this the first time we load the page?
Expand Down Expand Up @@ -315,7 +315,7 @@ public function getNodesFromDb()

// Is this location requested by the user to be opened
if (in_array($r['id'], $nodes)) {
echo 'd.add(' . $r['id'] . ', ' . $r['locations_id'] . ', ' . json_encode(htmlspecialchars($l_name, ENT_QUOTES, 'UTF-8')) .
echo 'd.add(' . $r['id'] . ', ' . $r['locations_id'] . ', ' . json_encode(htmlspecialchars((string) $l_name, ENT_QUOTES, 'UTF-8')) .
", true, -1,'');\n";
$dontLoad = 'true';
// Then add aloso its items
Expand All @@ -333,12 +333,13 @@ public function getNodesFromDb()
'WHERE' => [
'locations_id' => $r['id'],
],
'ORDER' => ["$itemtable.name"],
'ORDER' => [$itemtable . '.name'],
];

if ($item->maybeTemplate()) {
$criteria['WHERE']['is_template'] = 0;
}

if ($item->maybeDeleted()) {
$criteria['WHERE']['is_deleted'] = 0;
}
Expand All @@ -362,9 +363,10 @@ public function getNodesFromDb()
foreach ($result_location as $row) {
$name_location = $row['completename'];
}

$value = $r['id'];
$token = Session::getNewCSRFToken();
$getParam = "?is_deleted=0&criteria[0][field]=$field_num&criteria[0][searchtype]=equals&criteria[0][value]=$value&search=Rechercher&start=0&_glpi_csrf_token=$token";
$getParam = sprintf('?is_deleted=0&criteria[0][field]=%d&criteria[0][searchtype]=equals&criteria[0][value]=%s&search=Rechercher&start=0&_glpi_csrf_token=%s', $field_num, $value, $token);

$searchUrl = Toolbox::getItemTypeSearchURL($type) . $getParam;

Expand All @@ -376,13 +378,14 @@ public function getNodesFromDb()
$opt = Plugin::doHookFunction('treeview_search_url_parent_node', $params);

// Add items parent node
echo "d.add($tv_id," . $r['id'] . ',' . json_encode(htmlspecialchars($item::getTypeName(2), ENT_QUOTES, 'UTF-8')) .
", $dontLoad, '" . $type . "', '" . $opt['searchurl'] . "', '', '', '" .
echo sprintf('d.add(%s,', $tv_id) . $r['id'] . ',' . json_encode(htmlspecialchars($item::getTypeName(2), ENT_QUOTES, 'UTF-8')) .
sprintf(", %s, '", $dontLoad) . $type . "', '" . $opt['searchurl'] . "', '', '', '" .
$type::getIcon() . "', '" . $type::getIcon() . "');\n";

if ($openedType == $type && $nodes[count($nodes) - 1] == $tv_id) {
$openedType = $tv_id;
}

$tv_id++;
}

Expand Down Expand Up @@ -429,14 +432,14 @@ public function getNodesFromDb()
$opt = Plugin::doHookFunction('treeview_params', $params);

// Add the item
echo 'd.add(' . $tv_id++ . ", $pid, " . json_encode(htmlspecialchars($opt['name'], ENT_QUOTES, 'UTF-8')) . ", true, -1, '" .
echo 'd.add(' . $tv_id++ . sprintf(', %s, ', $pid) . json_encode(htmlspecialchars($opt['name'], ENT_QUOTES, 'UTF-8')) . ", true, -1, '" .
$opt['url'] . "', '', '', '" . $opt['pic'] . "','" . $opt['pic'] . "');\n";
}
}

// Add only the location without its items
} else {
echo 'd.add(' . $r['id'] . ',' . $r['locations_id'] . ',' . json_encode(htmlspecialchars($l_name, ENT_QUOTES, 'UTF-8')) .
echo 'd.add(' . $r['id'] . ',' . $r['locations_id'] . ',' . json_encode(htmlspecialchars((string) $l_name, ENT_QUOTES, 'UTF-8')) .
", false, -1,'', '', '', '', '', false, true);\n";
}
}
Expand All @@ -448,7 +451,7 @@ public function getNodesFromDb()

// Open the tree to the desired node
if ($openedType != -1) {
echo 'd.openTo(' . htmlspecialchars($openedType) . ");\n";
echo 'd.openTo(' . htmlspecialchars((string) $openedType) . ");\n";
} else {
echo 'd.openTo(' . $nodes[count($nodes) - 1] . ");\n";
}
Expand Down
1 change: 1 addition & 0 deletions inc/preference.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
if (!$pref_ID) {
$pref_ID = $pref->addDefaultPreference(Session::getLoginUserID());
}

$pref->showFormUserPreference($pref->getFormURL(), $pref_ID);
}

Expand Down
1 change: 1 addition & 0 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
if (!$prof->GetfromDB($ID)) {
$prof->createAccess($item);
}

$prof->showForm($ID);
}

Expand Down
86 changes: 21 additions & 65 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,71 +28,27 @@
* -------------------------------------------------------------------------
*/

use Rector\Configuration\RectorConfigBuilder;

require_once __DIR__ . '/../../src/Plugin.php';

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\CodeQuality\Rector as CodeQuality;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector as DeadCode;
use Rector\ValueObject\PhpVersion;
$baseline_file = __DIR__ . '/../../PluginsRector.php';
if (!file_exists($baseline_file)) {
throw new RuntimeException(
sprintf(
'Unable to find "%s". Running rector on a plugin requires a GLPI development checkout that ships PluginsRector.php.',
$baseline_file,
),
);
}

$baseline = require $baseline_file;

/** @var RectorConfigBuilder $config */
$config = $baseline([
__DIR__ . '/front',
__DIR__ . '/inc',
__DIR__ . '/public',
]);

return RectorConfig::configure()
->withPaths([
__DIR__ . '/front',
__DIR__ . '/inc',
__DIR__ . '/public',
])
->withPhpVersion(PhpVersion::PHP_82)
->withCache(
cacheClass: FileCacheStorage::class,
cacheDirectory: sys_get_temp_dir() . '/treeview-rector',
)
->withRootFiles()
->withParallel(timeoutSeconds: 300)
->withImportNames(removeUnusedImports: true)
->withRules([
CodeQuality\Assign\CombinedAssignRector::class,
CodeQuality\BooleanAnd\RemoveUselessIsObjectCheckRector::class,
CodeQuality\BooleanAnd\SimplifyEmptyArrayCheckRector::class,
CodeQuality\BooleanNot\ReplaceMultipleBooleanNotRector::class,
CodeQuality\Catch_\ThrowWithPreviousExceptionRector::class,
CodeQuality\Empty_\SimplifyEmptyCheckOnEmptyArrayRector::class,
CodeQuality\Expression\InlineIfToExplicitIfRector::class,
CodeQuality\Expression\TernaryFalseExpressionToIfRector::class,
CodeQuality\For_\ForRepeatedCountToOwnVariableRector::class,
CodeQuality\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector::class,
CodeQuality\Foreach_\ForeachToInArrayRector::class,
CodeQuality\Foreach_\SimplifyForeachToCoalescingRector::class,
CodeQuality\Foreach_\UnusedForeachValueToArrayKeysRector::class,
CodeQuality\FuncCall\ChangeArrayPushToArrayAssignRector::class,
CodeQuality\FuncCall\CompactToVariablesRector::class,
CodeQuality\FuncCall\InlineIsAInstanceOfRector::class,
CodeQuality\FuncCall\IsAWithStringWithThirdArgumentRector::class,
CodeQuality\FuncCall\RemoveSoleValueSprintfRector::class,
CodeQuality\FuncCall\SetTypeToCastRector::class,
CodeQuality\FuncCall\SimplifyFuncGetArgsCountRector::class,
CodeQuality\FuncCall\SimplifyInArrayValuesRector::class,
CodeQuality\FuncCall\SimplifyStrposLowerRector::class,
CodeQuality\FuncCall\UnwrapSprintfOneArgumentRector::class,
CodeQuality\Identical\BooleanNotIdenticalToNotIdenticalRector::class,
CodeQuality\Identical\SimplifyArraySearchRector::class,
CodeQuality\Identical\SimplifyConditionsRector::class,
CodeQuality\Identical\StrlenZeroToIdenticalEmptyStringRector::class,
CodeQuality\If_\CombineIfRector::class,
CodeQuality\If_\CompleteMissingIfElseBracketRector::class,
CodeQuality\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class,
CodeQuality\If_\ExplicitBoolCompareRector::class,
CodeQuality\If_\ShortenElseIfRector::class,
CodeQuality\If_\SimplifyIfElseToTernaryRector::class,
CodeQuality\If_\SimplifyIfNotNullReturnRector::class,
CodeQuality\If_\SimplifyIfNullableReturnRector::class,
CodeQuality\If_\SimplifyIfReturnBoolRector::class,
CodeQuality\Include_\AbsolutizeRequireAndIncludePathRector::class,
CodeQuality\LogicalAnd\AndAssignsToSeparateLinesRector::class,
CodeQuality\LogicalAnd\LogicalToBooleanRector::class,
CodeQuality\NotEqual\CommonNotEqualRector::class,
CodeQuality\Ternary\UnnecessaryTernaryExpressionRector::class,
DeadCode\Assign\RemoveUnusedVariableAssignRector::class,
])
->withPhpSets(php74: true) // apply PHP sets up to PHP 7.4
;
return $config;
7 changes: 4 additions & 3 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function plugin_init_treeview()
Plugin::registerClass(PluginTreeviewProfile::class, ['addtabon' => [Profile::class]]);
Plugin::registerClass(PluginTreeviewConfig::class, ['addtabon' => [Config::class]]);

$PLUGIN_HOOKS[Hooks::CHANGE_PROFILE]['treeview'] = [PluginTreeviewProfile::class, 'changeprofile'];
$PLUGIN_HOOKS[Hooks::CHANGE_PROFILE]['treeview'] = PluginTreeviewProfile::changeprofile(...);

if (
isset($_SESSION['glpi_plugin_treeview_profile'])
Expand All @@ -59,7 +59,7 @@ function plugin_init_treeview()
$PLUGIN_HOOKS[Hooks::MENU_TOADD]['treeview']['tools'] = PluginTreeviewPreference::class;

$PLUGIN_HOOKS[Hooks::PRE_ITEM_PURGE]['treeview'] = [
'Profile' => [PluginTreeviewProfile::class, 'cleanProfiles'],
'Profile' => PluginTreeviewProfile::cleanProfiles(...),
];

$PLUGIN_HOOKS[Hooks::CHANGE_ENTITY]['treeview'] = 'plugin_change_entity_Treeview';
Expand Down Expand Up @@ -95,6 +95,7 @@ function plugin_init_treeview()
$config = new PluginTreeviewConfig();
$config->hideTreeview();
}

// Add specific files to add to the header : javascript or css
$PLUGIN_HOOKS[Hooks::ADD_CSS]['treeview'] = 'css/treeview.css';
}
Expand All @@ -105,7 +106,7 @@ function plugin_init_treeview()
}

$currentPage = explode('/', $_SERVER['PHP_SELF']);
if (array_pop($currentPage) == 'index.php') {
if (array_pop($currentPage) === 'index.php') {
$PLUGIN_HOOKS[Hooks::DISPLAY_LOGIN]['treeview'] = [
'PluginTreeviewConfig',
'loginPageToTop',
Expand Down
Loading