-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepend.php
31 lines (27 loc) · 1.1 KB
/
prepend.php
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
<?php
/**
* Run any prepends located in the /usr/local/hestia/plugins directory based on priority naming schema
*/
$folderPath = "/usr/local/hestia/plugins";
$prependsArray = array();
// Scan the plugins directory for any prepend files
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folderPath));
foreach( $iterator as $file) {
if ( $file->getExtension() == "php" ) {
$fileKey = pathinfo( $file->getFilename(), PATHINFO_FILENAME );
$filePath = $file->getPathname();
if ( strpos( $fileKey, 'prepend' ) === 0 && strpos( $filePath, '.disabled/prepend' ) === false ) {
if ( $fileKey === 'prepend' ) $fileKey = 'prepend_10';
if (preg_match('/^prepend_\d$/', $fileKey)) { // lead zero if nec.
$fileKey = 'prepend_0' . substr($fileKey, -1);
}
$prependsArray[$filePath] = $fileKey;
}
}
}
// Sort numerically by the priority number
asort($prependsArray);
// Load and execute the prepend files in the order they were sorted
foreach( $prependsArray as $key => $value ) {
require_once( $key );
}