namespace wcf\system\option;
use wcf\data\option\category\OptionCategory;
use wcf\data\option\Option;
+use wcf\system\application\ApplicationHandler;
use wcf\system\cache\CacheHandler;
use wcf\system\exception\SystemException;
use wcf\system\exception\UserInputException;
use wcf\system\language\I18nHandler;
use wcf\system\WCF;
use wcf\util\ClassUtil;
+use wcf\util\StringUtil;
/**
* Handles options.
* @category Community Framework
*/
class OptionHandler implements IOptionHandler {
+ /**
+ * list of application abbreviations
+ * @var array<string>
+ */
+ protected $abbreviations = null;
+
/**
* cache name
* @var string
/**
* Returns class name for option type.
*
- * @param string $type
+ * @param string $optionType
* @return string
*/
- protected function getClassName($type) {
- $className = 'wcf\system\option\\'.ucfirst($type).'OptionType';
+ protected function getClassName($optionType) {
+ $optionType = StringUtil::firstCharToUpperCase($optionType);
+
+ // attempt to validate against WCF first
+ $isValid = false;
+ $className = 'wcf\system\option\\'.$optionType.'OptionType';
+ if (class_exists($className)) {
+ $isValid = true;
+ }
+ else {
+ if ($this->abbreviations === null) {
+ $this->abbreviations = array();
+
+ $applications = ApplicationHandler::getInstance()->getApplications();
+ foreach ($applications as $application) {
+ $this->abbreviations[] = ApplicationHandler::getInstance()->getAbbreviation($application->packageID);
+ }
+ }
+
+ foreach ($this->abbreviations as $abbreviation) {
+ $className = $abbreviation.'\system\option\\'.$optionType.'OptionType';
+ if (class_exists($className)) {
+ $isValid = true;
+ break;
+ }
+ }
+ }
// validate class
- if (!class_exists($className)) {
+ if (!$isValid) {
return null;
}
+
if (!ClassUtil::isInstanceOf($className, 'wcf\system\option\IOptionType')) {
throw new SystemException("'".$className."' does not implement 'wcf\system\option\IOptionType'");
}
namespace wcf\system\package\plugin;
use wcf\data\option\Option;
use wcf\data\option\OptionEditor;
+use wcf\system\application\ApplicationHandler;
use wcf\system\exception\SystemException;
use wcf\system\WCF;
use wcf\util\StringUtil;
* @category Community Framework
*/
class OptionPackageInstallationPlugin extends AbstractOptionPackageInstallationPlugin {
+ /**
+ * list of application abbreviations
+ * @var array<string>
+ */
+ protected static $abbreviations = null;
+
/**
* @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
*/
if (isset($option['requirei18n'])) $requireI18n = $option['requirei18n'];
// check if optionType exists
- $className = 'wcf\system\option\\'.StringUtil::firstCharToUpperCase($optionType).'OptionType';
- if (!class_exists($className)) {
- throw new SystemException("unable to find class '".$className."'");
+ if (!$this->validateOptionType($optionType)) {
+ throw new SystemException("unable to find option type '".$optionType."'");
}
// collect additional tags and their values
$optionEditor->update($data);
}
}
+
+ /**
+ * Returns true, if option type is valid.
+ *
+ * @param integer $optionType
+ * @return boolean
+ */
+ protected function validateOptionType($optionType) {
+ $optionType = StringUtil::firstCharToUpperCase($optionType);
+
+ // attempt to validate against WCF first
+ $className = 'wcf\system\option\\'.$optionType.'OptionType';
+ if (class_exists($className)) {
+ return true;
+ }
+
+ // check for applications
+ if (self::$abbreviations === null) {
+ self::$abbreviations = array();
+
+ $applications = ApplicationHandler::getInstance()->getApplications();
+ foreach ($applications as $application) {
+ self::$abbreviations[] = ApplicationHandler::getInstance()->getAbbreviation($application->packageID);
+ }
+ }
+
+ foreach (self::$abbreviations as $abbreviation) {
+ $className = $abbreviation.'\system\option\\'.$optionType.'OptionType';
+ if (class_exists($className)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}