2 namespace wcf\system\package
;
3 use wcf\data\application\Application
;
4 use wcf\data\application\ApplicationEditor
;
5 use wcf\data\language\category\LanguageCategory
;
6 use wcf\data\language\LanguageEditor
;
7 use wcf\data\language\LanguageList
;
8 use wcf\data\option\OptionEditor
;
9 use wcf\data\package\installation\queue\PackageInstallationQueue
;
10 use wcf\data\package\installation\queue\PackageInstallationQueueEditor
;
11 use wcf\data\package\Package
;
12 use wcf\data\package\PackageEditor
;
13 use wcf\system\application\ApplicationHandler
;
14 use wcf\system\cache\CacheHandler
;
15 use wcf\system\database\statement\PreparedStatement
;
16 use wcf\system\database\util\PreparedStatementConditionBuilder
;
17 use wcf\system\exception\SystemException
;
18 use wcf\system\form\container
;
19 use wcf\system\form\element
;
20 use wcf\system\form\FormDocument
;
22 use wcf\system\language\LanguageFactory
;
23 use wcf\system\menu\acp\ACPMenu
;
24 use wcf\system\request\LinkHandler
;
25 use wcf\system\request\RouteHandler
;
27 use wcf\util\FileUtil
;
28 use wcf\util\HeaderUtil
;
29 use wcf\util\StringUtil
;
32 * PackageInstallationDispatcher handles the whole installation process.
34 * @author Alexander Ebert
35 * @copyright 2001-2012 WoltLab GmbH
36 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
37 * @package com.woltlab.wcf
38 * @subpackage system.package
39 * @category Community Framework
41 class PackageInstallationDispatcher
{
43 * current installation type
46 protected $action = '';
49 * instance of PackageArchive
50 * @var wcf\system\package\PackageArchive
52 public $archive = null;
55 * instance of PackageInstallationNodeBuilder
56 * @var wcf\system\package\PackageInstallationNodeBuilder
58 public $nodeBuilder = null;
62 * @var wcf\data\package\Package
64 public $package = null;
67 * instance of PackageInstallationQueue
68 * @var wcf\system\package\PackageInstallationQueue
73 * default name of the config file
76 const CONFIG_FILE
= 'config.inc.php';
79 * Creates a new instance of PackageInstallationDispatcher.
81 * @param wcf\data\package\installation\queue\PackageInstallationQueue $queue
83 public function __construct(PackageInstallationQueue
$queue) {
84 $this->queue
= $queue;
85 $this->nodeBuilder
= new PackageInstallationNodeBuilder($this);
87 $this->action
= $this->queue
->action
;
91 * Installs node components and returns next node.
94 * @return PackageInstallationStep
96 public function install($node) {
97 $nodes = $this->nodeBuilder
->getNodeData($node);
99 // invoke node-specific actions
100 foreach ($nodes as $data) {
101 $nodeData = unserialize($data['nodeData']);
103 switch ($data['nodeType']) {
105 $step = $this->installPackage($nodeData);
109 $step = $this->executePIP($nodeData);
112 case 'optionalPackages':
113 $step = $this->selectOptionalPackages($node, $nodeData);
117 die("Unknown node type: '".$data['nodeType']."'");
121 if ($step->splitNode()) {
122 $this->nodeBuilder
->cloneNode($node, $data['sequenceNo']);
127 // mark node as completed
128 $this->nodeBuilder
->completeNode($node);
131 $node = $this->nodeBuilder
->getNextNode($node);
132 $step->setNode($node);
134 // update options.inc.php and save localized package infos
136 OptionEditor
::resetCache();
138 if ($this->action
== 'install') {
139 $this->saveLocalizedPackageInfos();
141 // remove all cache files after WCFSetup
143 CacheHandler
::getInstance()->clear(WCF_DIR
.'cache/', 'cache.*.php');
146 // rebuild application paths
147 ApplicationHandler
::rebuild();
148 ApplicationEditor
::setup();
156 * Returns current package archive.
158 * @return PackageArchive
160 public function getArchive() {
161 if ($this->archive
=== null) {
162 $this->archive
= new PackageArchive($this->queue
->archive
, $this->getPackage());
164 if (FileUtil
::isURL($this->archive
->getArchive())) {
165 // get return value and update entry in
166 // package_installation_queue with this value
167 $archive = $this->archive
->downloadArchive();
168 $queueEditor = new PackageInstallationQueueEditor($this->queue
);
169 $queueEditor->update(array(
170 'archive' => $archive
174 $this->archive
->openArchive();
177 return $this->archive
;
181 * Installs current package.
183 * @param array $nodeData
185 protected function installPackage(array $nodeData) {
186 $installationStep = new PackageInstallationStep();
188 // check requirements
189 if (!empty($nodeData['requirements'])) {
190 foreach ($nodeData['requirements'] as $package => $requirementData) {
191 // get existing package
192 if ($requirementData['packageID']) {
193 $sql = "SELECT packageName, packageVersion
194 FROM wcf".WCF_N
."_package
195 WHERE packageID = ?";
196 $statement = WCF
::getDB()->prepareStatement($sql);
197 $statement->execute(array($requirementData['packageID']));
200 // try to find matching package
201 $sql = "SELECT packageName, packageVersion
202 FROM wcf".WCF_N
."_package
204 $statement = WCF
::getDB()->prepareStatement($sql);
205 $statement->execute(array($package));
207 $row = $statement->fetchArray();
209 // package is required but not available
210 if ($row === false) {
211 throw new SystemException("Package '".$package."' is required by '".$nodeData['packageName']."', but is neither installed nor shipped.");
214 // check version requirements
215 if ($requirementData['minVersion']) {
216 if (Package
::compareVersion($row['packageVersion'], $requirementData['minVersion']) < 0) {
217 throw new SystemException("Package '".$nodeData['packageName']."' requires the package '".$row['packageName']."' in version '".$requirementData['minVersion']."', but version '".$row['packageVersion']."'");
222 unset($nodeData['requirements']);
224 if (!$this->queue
->packageID
) {
225 // create package entry
226 $package = PackageEditor
::create($nodeData);
228 // update package id for current queue
229 $queueEditor = new PackageInstallationQueueEditor($this->queue
);
230 $queueEditor->update(array(
231 'packageID' => $package->packageID
234 // save excluded packages
235 if (count($this->getArchive()->getExcludedPackages()) > 0) {
236 $sql = "INSERT INTO wcf".WCF_N
."_package_exclusion
237 (packageID, excludedPackage, excludedPackageVersion)
239 $statement = WCF
::getDB()->prepareStatement($sql);
241 foreach ($this->getArchive()->getExcludedPackages() as $excludedPackage) {
242 $statement->execute(array($package->packageID
, $excludedPackage['name'], (!empty($excludedPackage['version']) ?
$excludedPackage['version'] : '')));
246 // if package is plugin to com.woltlab.wcf it must not have any other requirement
247 $requirements = $this->getArchive()->getRequirements();
249 // insert requirements and dependencies
250 $requirements = $this->getArchive()->getAllExistingRequirements();
251 if (!empty($requirements)) {
252 $sql = "INSERT INTO wcf".WCF_N
."_package_requirement
253 (packageID, requirement)
255 $statement = WCF
::getDB()->prepareStatement($sql);
257 foreach ($requirements as $identifier => $possibleRequirements) {
258 if (count($possibleRequirements) == 1) {
259 $requirement = array_shift($possibleRequirements);
262 $requirement = $possibleRequirements[$this->selectedRequirements
[$identifier]];
265 $statement->execute(array($package->packageID
, $requirement['packageID']));
269 // build requirement map
270 Package
::rebuildPackageRequirementMap($package->packageID
);
273 $this->queue
= new PackageInstallationQueue($this->queue
->queueID
);
274 $this->package
= null;
276 if ($package->isApplication
) {
277 $host = StringUtil
::replace(RouteHandler
::getProtocol(), '', RouteHandler
::getHost());
278 $path = RouteHandler
::getPath(array('acp'));
280 // insert as application
281 ApplicationEditor
::create(array(
282 'domainName' => $host,
283 'domainPath' => $path,
284 'cookieDomain' => $host,
285 'cookiePath' => $path,
286 'packageID' => $package->packageID
291 if ($this->getPackage()->isApplication
&& $this->getPackage()->package
!= 'com.woltlab.wcf' && $this->getAction() == 'install') {
292 if (empty($this->getPackage()->packageDir
)) {
293 $document = $this->promptPackageDir();
294 if ($document !== null && $document instanceof form\FormDocument
) {
295 $installationStep->setDocument($document);
298 $installationStep->setSplitNode();
302 return $installationStep;
306 * Saves the localized package infos.
308 * @todo license and readme
310 protected function saveLocalizedPackageInfos() {
311 $package = new Package($this->queue
->packageID
);
313 // localize package information
314 $sql = "INSERT INTO wcf".WCF_N
."_language_item
315 (languageID, languageItem, languageItemValue, languageCategoryID, packageID)
316 VALUES (?, ?, ?, ?, ?)";
317 $statement = WCF
::getDB()->prepareStatement($sql);
320 $languageList = new LanguageList();
321 $languageList->sqlLimit
= 0;
322 $languageList->readObjects();
324 // workaround for WCFSetup
327 FROM wcf".WCF_N
."_language_category
328 WHERE languageCategory = ?";
329 $statement2 = WCF
::getDB()->prepareStatement($sql);
330 $statement2->execute(array('wcf.acp.package'));
331 $languageCategory = $statement2->fetchObject('wcf\data\language\category\LanguageCategory');
334 $languageCategory = LanguageFactory
::getInstance()->getCategory('wcf.acp.package');
338 $this->saveLocalizedPackageInfo($statement, $languageList, $languageCategory, $package, 'packageName');
340 // save package description
341 $this->saveLocalizedPackageInfo($statement, $languageList, $languageCategory, $package, 'packageDescription');
343 // update description and name
344 $packageEditor = new PackageEditor($package);
345 $packageEditor->update(array(
346 'packageDescription' => 'wcf.acp.package.packageDescription.package'.$this->queue
->packageID
,
347 'packageName' => 'wcf.acp.package.packageName.package'.$this->queue
->packageID
352 * Saves a localized package info.
354 * @param wcf\system\database\statement\PreparedStatement $statement
355 * @param wcf\data\language\LanguageList $languageList
356 * @param wcf\data\language\category\LanguageCategory $languageCategory
357 * @param wcf\data\package\Package $package
358 * @param string $infoName
360 protected function saveLocalizedPackageInfo(PreparedStatement
$statement, $languageList, LanguageCategory
$languageCategory, Package
$package, $infoName) {
361 $infoValues = $this->getArchive()->getPackageInfo($infoName);
363 // get default value for languages without specified information
365 if (isset($infoValues['default'])) {
366 $defaultValue = $infoValues['default'];
368 else if (isset($infoValues['en'])) {
369 // fallback to English
370 $defaultValue = $infoValues['en'];
372 else if (isset($infoValues[WCF
::getLanguage()->getFixedLanguageCode()])) {
373 // fallback to the language of the current user
374 $defaultValue = $infoValues[WCF
::getLanguage()->getFixedLanguageCode()];
376 else if ($infoName == 'packageName') {
377 // fallback to the package identifier for the package name
378 $defaultValue = $this->archive
->getPackageInfo('name');
381 foreach ($languageList as $language) {
382 $value = $defaultValue;
383 if (isset($infoValues[$language->languageCode
])) {
384 $value = $infoValues[$language->languageCode
];
387 $statement->execute(array(
388 $language->languageID
,
389 'wcf.acp.package.'.$infoName.'.package'.$package->packageID
,
391 $languageCategory->languageCategoryID
,
398 * Executes a package installation plugin.
403 protected function executePIP(array $nodeData) {
404 $step = new PackageInstallationStep();
406 // fetch all pips associated with current PACKAGE_ID and include pips
407 // previously installed by current installation queue
408 $sql = "SELECT pluginName, className
409 FROM wcf".WCF_N
."_package_installation_plugin
410 WHERE pluginName = ?";
411 $statement = WCF
::getDB()->prepareStatement($sql);
412 $statement->execute(array(
415 $row = $statement->fetchArray();
418 if (!$row ||
(strcmp($nodeData['pip'], $row['pluginName']) !== 0)) {
419 throw new SystemException("unable to find package installation plugin '".$nodeData['pip']."'");
422 // valdidate class definition
423 $className = $row['className'];
424 if (!class_exists($className)) {
425 throw new SystemException("unable to find class '".$className."'");
428 $plugin = new $className($this, $nodeData);
430 if (!($plugin instanceof \wcf\system\package\plugin\IPackageInstallationPlugin
)) {
431 throw new SystemException("'".$className."' does not implement 'wcf\system\package\plugin\IPackageInstallationPlugin'");
436 $document = $plugin->{$this->action
}();
438 catch (SplitNodeException
$e) {
439 $step->setSplitNode();
442 if ($document !== null && ($document instanceof FormDocument
)) {
443 $step->setDocument($document);
444 $step->setSplitNode();
450 protected function selectOptionalPackages($currentNode, array $nodeData) {
451 $installationStep = new PackageInstallationStep();
453 $document = $this->promptOptionalPackages($nodeData);
454 if ($document !== null && $document instanceof form\FormDocument
) {
455 $installationStep->setDocument($document);
456 $installationStep->setSplitNode();
458 // insert new nodes for each package
459 else if (is_array($document)) {
460 // get target child node
461 $node = $currentNode;
462 $queue = $this->queue
;
465 foreach ($nodeData as $package) {
466 if (in_array($package['package'], $document)) {
468 $this->nodeBuilder
->shiftNodes($currentNode, 'tempNode');
472 $queue = PackageInstallationQueueEditor
::create(array(
473 'parentQueueID' => $queue->queueID
,
474 'processNo' => $this->queue
->processNo
,
475 'userID' => WCF
::getUser()->userID
,
476 'package' => $package['package'],
477 'packageName' => $package['packageName'],
478 'archive' => $package['archive'],
479 'action' => $queue->action
482 $installation = new PackageInstallationDispatcher($queue);
483 $installation->nodeBuilder
->setParentNode($node);
484 $installation->nodeBuilder
->buildNodes();
485 $node = $installation->nodeBuilder
->getCurrentNode();
491 $this->nodeBuilder
->shiftNodes('tempNode', $node);
495 return $installationStep;
499 * Extracts files from .tar (or .tar.gz) archive and installs them
501 * @param string $targetDir
502 * @param string $sourceArchive
503 * @param FileHandler $fileHandler
504 * @return wcf\system\setup\Installer
506 public function extractFiles($targetDir, $sourceArchive, $fileHandler = null) {
507 return new \wcf\system\setup\
Installer($targetDir, $sourceArchive, $fileHandler);
511 * Returns current package.
513 * @return wcf\data\package\Package
515 public function getPackage() {
516 if ($this->package
=== null) {
517 $this->package
= new Package($this->queue
->packageID
);
520 return $this->package
;
524 * Prompts for a text input for package directory (applies for applications only)
526 * @return wcf\system\form\FormDocument
528 protected function promptPackageDir() {
529 if (!PackageInstallationFormManager
::findForm($this->queue
, 'packageDir')) {
531 $container = new container\
GroupFormElementContainer();
532 $packageDir = new element\
TextInputFormElement($container);
533 $packageDir->setName('packageDir');
534 $packageDir->setLabel(WCF
::getLanguage()->get('wcf.acp.package.packageDir.input'));
536 $path = RouteHandler
::getPath(array('wcf', 'acp'));
537 $defaultPath = FileUtil
::addTrailingSlash(FileUtil
::unifyDirSeperator($_SERVER['DOCUMENT_ROOT'] . $path));
538 $packageDir->setValue($defaultPath);
539 $container->appendChild($packageDir);
541 $document = new form\
FormDocument('packageDir');
542 $document->appendContainer($container);
544 PackageInstallationFormManager
::registerForm($this->queue
, $document);
548 $document = PackageInstallationFormManager
::getForm($this->queue
, 'packageDir');
549 $document->handleRequest();
550 $packageDir = $document->getValue('packageDir');
552 if ($packageDir !== null) {
553 // validate package dir
554 if (file_exists(FileUtil
::addTrailingSlash($packageDir) . 'global.php')) {
555 $document->setError('packageDir', WCF
::getLanguage()->get('wcf.acp.package.packageDir.notAvailable'));
560 $packageEditor = new PackageEditor($this->getPackage());
561 $packageEditor->update(array(
562 'packageDir' => FileUtil
::getRelativePath(WCF_DIR
, $packageDir)
566 $domainPath = FileUtil
::getRelativePath(FileUtil
::unifyDirSeperator($_SERVER['DOCUMENT_ROOT']), FileUtil
::unifyDirSeperator($packageDir));
568 // work-around for applications installed in document root
569 if ($domainPath == './') {
573 $domainPath = FileUtil
::addLeadingSlash(FileUtil
::addTrailingSlash($domainPath));
575 // update application path
576 $application = new Application($this->getPackage()->packageID
);
577 $applicationEditor = new ApplicationEditor($application);
578 $applicationEditor->update(array(
579 'domainPath' => $domainPath,
580 'cookiePath' => $domainPath
583 // create directory and set permissions
584 @mkdir
($packageDir, 0777, true);
585 @chmod
($packageDir, 0777);
592 protected function promptOptionalPackages(array $packages) {
593 if (!PackageInstallationFormManager
::findForm($this->queue
, 'optionalPackages')) {
594 $container = new container\
MultipleSelectionFormElementContainer();
595 $container->setName('optionalPackages');
597 foreach ($packages as $package) {
598 $optionalPackage = new element\
MultipleSelectionFormElement($container);
599 $optionalPackage->setName('optionalPackages');
600 $optionalPackage->setLabel($package['packageName']);
601 $optionalPackage->setValue($package['package']);
603 $container->appendChild($optionalPackage);
606 $document = new form\
FormDocument('optionalPackages');
607 $document->appendContainer($container);
609 PackageInstallationFormManager
::registerForm($this->queue
, $document);
613 $document = PackageInstallationFormManager
::getForm($this->queue
, 'optionalPackages');
614 $document->handleRequest();
616 return $document->getValue('optionalPackages');
621 * Returns current package id.
625 public function getPackageID() {
626 return $this->queue
->packageID
;
630 * Returns current package installation type.
634 public function getAction() {
635 return $this->action
;
639 * Opens the package installation queue and
640 * starts the installation, update or uninstallation of the first entry.
642 * @param integer $parentQueueID
643 * @param integer $processNo
645 public static function openQueue($parentQueueID = 0, $processNo = 0) {
646 $conditions = new PreparedStatementConditionBuilder();
647 $conditions->add("userID = ?", array(WCF
::getUser()->userID
));
648 $conditions->add("parentQueueID = ?", array($parentQueueID));
649 if ($processNo != 0) $conditions->add("processNo = ?", array($processNo));
650 $conditions->add("done = ?", array(0));
653 FROM wcf".WCF_N
."_package_installation_queue
655 ORDER BY queueID ASC";
656 $statement = WCF
::getDB()->prepareStatement($sql);
657 $statement->execute($conditions->getParameters());
658 $packageInstallation = $statement->fetchArray();
660 if (!isset($packageInstallation['queueID'])) {
661 $url = LinkHandler
::getInstance()->getLink('PackageList');
662 HeaderUtil
::redirect($url);
666 $url = LinkHandler
::getInstance()->getLink('Package', array(), 'action='.$packageInstallation['action'].'&queueID='.$packageInstallation['queueID']);
667 HeaderUtil
::redirect($url);
673 * Displays last confirmation before plugin installation.
675 public function beginInstallation() {
677 $requirements = $this->getArchive()->getRequirements();
678 $openRequirements = $this->getArchive()->getOpenRequirements();
680 $updatableInstances = array();
681 $missingPackages = 0;
682 foreach ($requirements as $key => $requirement) {
683 if (isset($openRequirements[$requirement['name']])) {
684 $requirements[$key]['status'] = 'missing';
685 $requirements[$key]['action'] = $openRequirements[$requirement['name']]['action'];
687 if (!isset($requirements[$key]['file'])) {
688 if ($openRequirements[$requirement['name']]['action'] === 'update') {
689 $requirements[$key]['status'] = 'missingVersion';
690 $requirements[$key]['existingVersion'] = $openRequirements[$requirement['name']]['existingVersion'];
695 $requirements[$key]['status'] = 'delivered';
699 $requirements[$key]['status'] = 'installed';
703 // get other instances
704 if ($this->action
== 'install') {
705 $updatableInstances = $this->getArchive()->getUpdatableInstances();
708 ACPMenu
::getInstance()->setActiveMenuItem('wcf.acp.menu.link.package.install');
709 WCF
::getTPL()->assign(array(
710 'archive' => $this->getArchive(),
711 'requiredPackages' => $requirements,
712 'missingPackages' => $missingPackages,
713 'updatableInstances' => $updatableInstances,
714 'excludingPackages' => $this->getArchive()->getConflictedExcludingPackages(),
715 'excludedPackages' => $this->getArchive()->getConflictedExcludedPackages(),
716 'queueID' => $this->queue
->queueID
718 WCF
::getTPL()->display('packageInstallationConfirm');
723 * Checks the package installation queue for outstanding entries.
727 public static function checkPackageInstallationQueue() {
728 $sql = "SELECT queueID
729 FROM wcf".WCF_N
."_package_installation_queue
731 AND parentQueueID = 0
733 ORDER BY queueID ASC";
734 $statement = WCF
::getDB()->prepareStatement($sql);
735 $statement->execute(array(WCF
::getUser()->userID
));
736 $row = $statement->fetchArray();
742 return $row['queueID'];
746 * Executes post-setup actions.
748 public function completeSetup() {
749 // rebuild dependencies
750 Package
::rebuildPackageDependencies($this->queue
->packageID
);
752 // mark queue as done
753 $queueEditor = new PackageInstallationQueueEditor($this->queue
);
754 $queueEditor->update(array(
759 $this->nodeBuilder
->purgeNodes();
761 // update package version
762 if ($this->action
== 'update') {
763 $packageEditor = new PackageEditor($this->getPackage());
764 $packageEditor->update(array(
765 'updateDate' => TIME_NOW
,
766 'packageVersion' => $this->archive
->getPackageInfo('version')
770 // clear language files once whole installation is completed
771 LanguageEditor
::deleteLanguageFiles();
774 CacheHandler
::getInstance()->clear(WCF_DIR
.'cache/', '*');
778 * Updates queue information.
780 public function updatePackage() {
781 if (empty($this->queue
->packageName
)) {
782 $queueEditor = new PackageInstallationQueueEditor($this->queue
);
783 $queueEditor->update(array(
784 'packageName' => $this->getArchive()->getLocalizedPackageInfo('packageName')
788 $this->queue
= new PackageInstallationQueue($this->queue
->queueID
);
793 * Validates specific php requirements.
795 * @param array $requirements
796 * @return array<array>
798 public static function validatePHPRequirements(array $requirements) {
801 // validate php version
802 if (isset($requirements['version'])) {
804 if (version_compare(PHP_VERSION
, $requirements['version'], '>=')) {
809 $errors['version'] = array(
810 'required' => $requirements['version'],
811 'installed' => PHP_VERSION
816 // validate extensions
817 if (isset($requirements['extensions'])) {
818 foreach ($requirements['extensions'] as $extension) {
819 $passed = (extension_loaded($extension)) ?
true : false;
822 $errors['extension'][] = array(
823 'extension' => $extension
830 if (isset($requirements['settings'])) {
831 foreach ($requirements['settings'] as $setting => $value) {
832 $iniValue = ini_get($setting);
834 $passed = self
::compareSetting($setting, $value, $iniValue);
836 $errors['setting'][] = array(
837 'setting' => $setting,
838 'required' => $value,
839 'installed' => ($iniValue === false) ?
'(unknown)' : $iniValue
845 // validate functions
846 if (isset($requirements['functions'])) {
847 foreach ($requirements['functions'] as $function) {
848 $function = StringUtil
::toLowerCase($function);
850 $passed = self
::functionExists($function);
852 $errors['function'][] = array(
853 'function' => $function
860 if (isset($requirements['classes'])) {
861 foreach ($requirements['classes'] as $class) {
864 // see: http://de.php.net/manual/en/language.oop5.basic.php
865 if (preg_match('~[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.~', $class)) {
866 $globalClass = '\\'.$class;
868 if (class_exists($globalClass, false)) {
874 $errors['class'][] = array(
886 * Validates if an function exists and is not blacklisted by suhosin extension.
888 * @param string $function
890 * @see http://de.php.net/manual/en/function.function-exists.php#77980
892 protected static function functionExists($function) {
893 if (extension_loaded('suhosin')) {
894 $blacklist = @ini_get
('suhosin.executor.func.blacklist');
895 if (!empty($blacklist)) {
896 $blacklist = explode(',', $blacklist);
897 foreach ($blacklist as $disabledFunction) {
898 $disabledFunction = StringUtil
::toLowerCase(StringUtil
::trim($disabledFunction));
900 if ($function == $disabledFunction) {
907 return function_exists($function);
911 * Compares settings, converting values into compareable ones.
913 * @param string $setting
914 * @param string $value
915 * @param mixed $compareValue
918 protected static function compareSetting($setting, $value, $compareValue) {
919 if ($compareValue === false) return false;
921 $value = StringUtil
::toLowerCase($value);
922 $trueValues = array('1', 'on', 'true');
923 $falseValues = array('0', 'off', 'false');
925 // handle values considered as 'true'
926 if (in_array($value, $trueValues)) {
927 return ($compareValue) ?
true : false;
929 // handle values considered as 'false'
930 else if (in_array($value, $falseValues)) {
931 return (!$compareValue) ?
true : false;
933 else if (!is_numeric($value)) {
934 $compareValue = self
::convertShorthandByteValue($compareValue);
935 $value = self
::convertShorthandByteValue($value);
938 return ($compareValue >= $value) ?
true : false;
942 * Converts shorthand byte values into an integer representing bytes.
944 * @param string $value
946 * @see http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
948 protected static function convertShorthandByteValue($value) {
949 // convert into bytes
950 $lastCharacter = StringUtil
::substring($value, -1);
951 switch ($lastCharacter) {
954 return (int)$value * 1073741824;
959 return (int)$value * 1048576;
964 return (int)$value * 1024;