Repository navigation
Expand file tree
/
Copy pathplugin-bootstrap.php
More file actions
150 lines (126 loc) · 6.2 KB
/
Copy pathplugin-bootstrap.php
File metadata and controls
150 lines (126 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Name: plugin-bootstrap.php
* Author: Roger C. Guilherme
* Created: 2026-07-01
* Description: This file is part of the ODDS plugin for the ABCD application. It serves as the bootstrap file for the plugin, handling auto-installation of necessary ISIS database files, setting up dependencies, and registering core hooks to integrate the plugin seamlessly into the ABCD system. The script ensures that the ODDS database is created if it does not exist and adds a link to the ODDS management interface in the central navigation menu.
*
* * @package ABCD_Plugins_ODDS
* @requires PHP 8.1+
*
* changelog:
* 20260701 rogercgui Initial creation of LanguageManager class.
*
* */
$bridge = PluginBridge::getInstance();
$dbPath = $bridge->get('db_path');
if (!empty($dbPath)) {
$targetBaseDir = rtrim($dbPath, '/\\') . '/odds';
$basesDatFile = rtrim($dbPath, '/\\') . '/bases.dat';
$sourceTemplate = __DIR__ . '/install/odds';
// 1. Auto-installation logic for the ISIS database files
if (!is_dir($targetBaseDir) && is_dir($sourceTemplate)) {
mkdir($targetBaseDir, 0775, true);
$targetParDir = rtrim($dbPath, '/\\') . DIRECTORY_SEPARATOR . 'par';
if (!is_dir($targetParDir)) {
mkdir($targetParDir, 0775, true);
}
// OS Detection to select the correct ISIS binary data folder
$isWindows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
$validDataFolder = $isWindows ? 'data-win' : 'data-lin';
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($sourceTemplate, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item) {
$subPath = $iterator->getSubPathName();
$pathParts = explode(DIRECTORY_SEPARATOR, $subPath);
$topFolder = $pathParts[0];
// Ignore the data folder belonging to the incompatible OS
if (($topFolder === 'data-win' && !$isWindows) || ($topFolder === 'data-lin' && $isWindows)) {
continue;
}
// Route files to their respective physical destinations
if ($topFolder === $validDataFolder) {
$pathParts[0] = 'data';
$targetSubPath = implode(DIRECTORY_SEPARATOR, $pathParts);
$targetPath = $targetBaseDir . DIRECTORY_SEPARATOR . $targetSubPath;
} elseif ($topFolder === 'par') {
// Route parameter files directly to the global bases/par/ folder
array_shift($pathParts);
if (empty($pathParts)) continue; // Skip the 'par' directory itself
$targetPath = $targetParDir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $pathParts);
} else {
// Standard folders (def, pfts, etc.) go to bases/odds/
$targetPath = $targetBaseDir . DIRECTORY_SEPARATOR . $subPath;
}
if ($item->isDir()) {
if (!is_dir($targetPath)) {
mkdir($targetPath, 0775, true);
}
} else {
$parentDir = dirname($targetPath);
if (!is_dir($parentDir)) {
mkdir($parentDir, 0775, true);
}
copy($item->getPathname(), $targetPath);
}
}
// 2. Safely register the database inside bases.dat
if (file_exists($basesDatFile)) {
$basesDatContent = file_get_contents($basesDatFile);
if (strpos($basesDatContent, 'odds|') === false) {
// Ensure correct line-ending handling for the flat file append
$lineSeparator = (str_ends_with($basesDatContent, "\n") || str_ends_with($basesDatContent, "\r")) ? "" : PHP_EOL;
$entry = $lineSeparator . "odds|ODDS - Online Document Delivery Service" . PHP_EOL;
file_put_contents($basesDatFile, $entry, FILE_APPEND | LOCK_EX);
}
}
}
}
// 3. Register Core Hooks
// Inject ODDS Management link into the central navigation menu
abcd_add_hook('central_menu', function(string $menuHtml) use ($bridge): string {
$lang = $bridge->get('lang', 'en');
// The link safely redirects the librarian to the standard cataloguing tool for the odds database
$menuHtml .= '<a href="/central/settings/plugin_admin.php?plugin=odds" class="menuButton utilsButton">';
$menuHtml .= '<span><strong>' . ($msgstr["configure_ODDS"] ?? 'Configure ODDS') . ' ABCD</strong></span>';
$menuHtml .= '</a>';
return $menuHtml;
});
/**
* Register ODDS translation button in the main translation menu
*/
abcd_add_hook('abcd_translation_menu', function(string $menuHtml) use ($bridge): string {
global $msgstr;
$lang = $bridge->get('lang', 'en');
$label = $msgstr["odds"] ?? 'ODDS';
$menuHtml .= '<a href="../lang/translate.php?lang=' . urlencode($lang) . '&table=odds.tab&plugin=odds" class="menuButton moduleButton">';
$menuHtml .= '<span><strong>' . htmlspecialchars($label) . '</strong></span>';
$menuHtml .= '</a>';
return $menuHtml;
});
/**
* Register ODDS Help Information button in the main translation menu
*/
abcd_add_hook('abcd_translation_menu', function (string $menuHtml) use ($bridge): string {
global $msgstr;
$lang = $bridge->get('lang', 'en');
$label = $msgstr["odds_help_info"] ?? 'ODDS Help Information';
$menuHtml .= '<a href="../lang/translate.php?lang=' . urlencode($lang) . '&table=odds_help_info.tab&plugin=odds&type=textarea" class="menuButton moduleButton">';
$menuHtml .= '<span><strong>' . htmlspecialchars($label) . '</strong></span>';
$menuHtml .= '</a>';
return $menuHtml;
});
/**
* Register ODDS compare button in the translation menu
*/
abcd_add_hook('abcd_compare_translation_menu', function(string $menuHtml) use ($bridge): string {
global $msgstr;
$lang = $bridge->get('lang', 'en');
$label = $msgstr["odds"] ?? 'ODDS';
$menuHtml .= '<a href="../lang/compare_admin.php?lang=' . urlencode($lang) . '&table=odds.tab&plugin=odds" class="menuButton moduleButton">';
$menuHtml .= '<span><strong>' . htmlspecialchars($label) . '</strong></span>';
$menuHtml .= '</a>';
return $menuHtml;
});