/** * @see \wcf\action\IAction::execute() */ public final function execute() { parent::execute(); $methodName = 'step' . StringUtil::firstCharToUpperCase($this->step); if (!method_exists($this, $methodName)) { throw new AJAXException("Class '" . get_class($this) . "' does not implement the required method '" . $methodName . "'"); } // execute step $this->{$methodName}(); $this->executed(); // send JSON-encoded response header('Content-type: application/json'); echo JSON::encode($this->data); exit; }
/** * @see wcf\system\package\plugin\AbstractOptionPackageInstallationPlugin::saveOption() */ protected function saveOption($option, $categoryName, $existingOptionID = 0) { // default values $optionName = $optionType = $defaultValue = $validationPattern = $outputClass = $selectOptions = $enableOptions = $permissions = $options = ''; $required = $editable = $visible = $searchable = $disabled = $askDuringRegistration = 0; $showOrder = null; // get values if (isset($option['name'])) { $optionName = $option['name']; } if (isset($option['optiontype'])) { $optionType = $option['optiontype']; } if (isset($option['defaultvalue'])) { $defaultValue = $option['defaultvalue']; } if (isset($option['validationpattern'])) { $validationPattern = $option['validationpattern']; } if (isset($option['required'])) { $required = intval($option['required']); } if (isset($option['askduringregistration'])) { $askDuringRegistration = intval($option['askduringregistration']); } if (isset($option['editable'])) { $editable = intval($option['editable']); } if (isset($option['visible'])) { $visible = intval($option['visible']); } if (isset($option['searchable'])) { $searchable = intval($option['searchable']); } if (isset($option['showorder'])) { $showOrder = intval($option['showorder']); } if (isset($option['outputclass'])) { $outputClass = $option['outputclass']; } if (isset($option['selectoptions'])) { $selectOptions = $option['selectoptions']; } if (isset($option['enableoptions'])) { $enableOptions = $option['enableoptions']; } if (isset($option['disabled'])) { $disabled = intval($option['disabled']); } $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName'); if (isset($option['permissions'])) { $permissions = $option['permissions']; } if (isset($option['options'])) { $options = $option['options']; } // check if optionType exists $className = 'wcf\\system\\option\\' . StringUtil::firstCharToUpperCase($optionType) . 'OptionType'; if (!class_exists($className)) { throw new SystemException("unable to find class '" . $className . "'"); } // collect additional tags and their values $additionalData = array(); foreach ($option as $tag => $value) { if (!in_array($tag, self::$reservedTags)) { $additionalData[$tag] = $value; } } // get optionID if it was installed by this package already $sql = "SELECT\t*\n\t\t\tFROM \twcf" . WCF_N . "_" . $this->tableName . "\n\t\t\tWHERE \toptionName = ?\n\t\t\tAND\tpackageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($optionName, $this->installation->getPackageID())); $result = $statement->fetchArray(); // build data array $data = array('categoryName' => $categoryName, 'optionType' => $optionType, 'defaultValue' => $defaultValue, 'validationPattern' => $validationPattern, 'selectOptions' => $selectOptions, 'enableOptions' => $enableOptions, 'required' => $required, 'askDuringRegistration' => $askDuringRegistration, 'editable' => $editable, 'visible' => $visible, 'outputClass' => $outputClass, 'searchable' => $searchable, 'showOrder' => $showOrder, 'disabled' => $disabled, 'permissions' => $permissions, 'options' => $options, 'additionalData' => serialize($additionalData)); // update option if (!empty($result['optionID']) && $this->installation->getAction() == 'update') { $userOption = new UserOption(null, $result); $userOptionEditor = new UserOptionEditor($userOption); $userOptionEditor->update($data); } else { // append option name $data['optionName'] = $optionName; $data['packageID'] = $this->installation->getPackageID(); UserOptionEditor::create($data); } }
/** * Returns class name for option type. * * @param string $optionType * @return string */ 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 (!$isValid) { return null; } if (!ClassUtil::isInstanceOf($className, 'wcf\system\option\IOptionType')) { throw new SystemException("'".$className."' does not implement 'wcf\system\option\IOptionType'"); } return $className; }
/** * Builds cache name. * * @param \wcf\system\cache\builder\ICacheBuilder $cacheBuilder * @param array $parameters * @return string */ protected function getCacheName(ICacheBuilder $cacheBuilder, array $parameters = array()) { $className = explode('\\', get_class($cacheBuilder)); $application = array_shift($className); $cacheName = str_replace('CacheBuilder', '', array_pop($className)); if (!empty($parameters)) { $cacheName .= '-' . $this->getCacheIndex($parameters); } return $application . '_' . StringUtil::firstCharToUpperCase($cacheName); }
/** * @see wcf\system\package\plugin\AbstractOptionPackageInstallationPlugin::saveOption() */ protected function saveOption($option, $categoryName, $existingOptionID = 0) { // default values $optionName = $optionType = $defaultValue = $adminDefaultValue = $validationPattern = $enableOptions = $permissions = $options = ''; $showOrder = null; // get values if (isset($option['name'])) { $optionName = $option['name']; } if (isset($option['optiontype'])) { $optionType = $option['optiontype']; } if (isset($option['defaultvalue'])) { $defaultValue = $option['defaultvalue']; } if (isset($option['admindefaultvalue'])) { $adminDefaultValue = $option['admindefaultvalue']; } if (isset($option['validationpattern'])) { $validationPattern = $option['validationpattern']; } if (!empty($option['showorder'])) { $showOrder = intval($option['showorder']); } $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName'); if (isset($option['enableoptions'])) { $enableOptions = $option['enableoptions']; } if (isset($option['permissions'])) { $permissions = $option['permissions']; } if (isset($option['options'])) { $options = $option['options']; } // check if optionType exists $className = 'wcf\\system\\option\\user\\group\\' . StringUtil::firstCharToUpperCase($optionType) . 'UserGroupOptionType'; if (!class_exists($className)) { throw new SystemException("unable to find class '" . $className . "'"); } // collect additional tags and their values $additionalData = array(); foreach ($option as $tag => $value) { if (!in_array($tag, self::$reservedTags)) { $additionalData[$tag] = $value; } } // check if the otion exist already and was installed by this package $sql = "SELECT\toptionID\n\t\t\tFROM \twcf" . WCF_N . "_user_group_option\n\t\t\tWHERE \toptionName = ?\n\t\t\tAND\tpackageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($optionName, $this->installation->getPackageID())); $row = $statement->fetchArray(); $data = array('categoryName' => $categoryName, 'optionType' => $optionType, 'defaultValue' => $defaultValue, 'adminDefaultValue' => $adminDefaultValue, 'validationPattern' => $validationPattern, 'showOrder' => $showOrder, 'enableOptions' => $enableOptions, 'permissions' => $permissions, 'options' => $options, 'additionalData' => serialize($additionalData)); if (!empty($row['optionID'])) { $groupOption = new UserGroupOption(null, $row); $groupOptionEditor = new UserGroupOptionEditor($groupOption); $groupOptionEditor->update($data); } else { // add new option $data['packageID'] = $this->installation->getPackageID(); $data['optionName'] = $optionName; $groupOptionEditor = UserGroupOptionEditor::create($data); $optionID = $groupOptionEditor->optionID; // get default group ("everyone") $sql = "SELECT\tgroupID\n\t\t\t\tFROM\twcf" . WCF_N . "_user_group\n\t\t\t\tWHERE\tgroupType = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(UserGroup::EVERYONE)); $row = $statement->fetchArray(); // save default value $sql = "INSERT INTO\twcf" . WCF_N . "_user_group_option_value\n\t\t\t\t\t\t(groupID, optionID, optionValue)\n\t\t\t\tVALUES\t\t(?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($row['groupID'], $optionID, $defaultValue)); if ($adminDefaultValue && $defaultValue != $adminDefaultValue) { $sql = "SELECT\tgroupID\n\t\t\t\t\tFROM\twcf" . WCF_N . "_user_group_option_value\n\t\t\t\t\tWHERE\toptionID = (\n\t\t\t\t\t\t\tSELECT\toptionID\n\t\t\t\t\t\t\tFROM\twcf" . WCF_N . "_user_group_option\n\t\t\t\t\t\t\tWHERE\toptionName = ?\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND optionValue = '1'"; $statement2 = WCF::getDB()->prepareStatement($sql); $statement2->execute(array('admin.general.canUseAcp')); $acpGroups = array(); while ($row = $statement2->fetchArray()) { $acpGroups[] = $row['groupID']; } $statement2->execute(array('admin.user.canEditGroup')); while ($row = $statement2->fetchArray()) { if (!in_array($row['groupID'], $acpGroups)) { continue; } $statement->execute(array($row['groupID'], $optionID, $adminDefaultValue)); } } } }
/** * @see wcf\data\IDatabaseObjectAction::validateAction() */ public function validateAction() { // validate if user is logged in if (!WCF::getUser()->userID && !in_array($this->getActionName(), $this->allowGuestAccess)) { throw new PermissionDeniedException(); } // validate action name if (!method_exists($this, $this->getActionName())) { throw new SystemException("unknown action '".$this->getActionName()."'"); } $actionName = 'validate'.StringUtil::firstCharToUpperCase($this->getActionName()); if (!method_exists($this, $actionName)) { throw new PermissionDeniedException(); } // execute action call_user_func_array(array($this, $actionName), $this->getParameters()); }
/** * @see wcf\data\IDatabaseObjectAction::validateAction() */ public function validateAction() { // validate if user is logged in if (!WCF::getUser()->userID && !in_array($this->getActionName(), $this->allowGuestAccess)) { throw new ValidateActionException("Please login before executing this action"); } // validate action name if (!method_exists($this, $this->getActionName())) { throw new ValidateActionException("unknown action '" . $this->getActionName() . "'"); } $actionName = 'validate' . StringUtil::firstCharToUpperCase($this->getActionName()); if (!method_exists($this, $actionName)) { throw new ValidateActionException("validation of action '" . $this->getActionName() . "' failed"); } // execute action call_user_func_array(array($this, $actionName), $this->getParameters()); }
/** * Returns an object of the requested group option type. * * @param string $type * @return wcf\system\option\user\group\IUserGroupOptionType */ protected function getTypeObject($type) { if (!isset($this->typeObjects[$type])) { $className = 'wcf\system\option\user\group\\'.StringUtil::firstCharToUpperCase($type).'UserGroupOptionType'; // validate class if (!class_exists($className)) { throw new SystemException("unable to find class '".$className."'"); } if (!ClassUtil::isInstanceOf($className, 'wcf\system\option\user\group\IUserGroupOptionType')) { throw new SystemException("'".$className."' does not implement 'wcf\system\option\user\group\IUserGroupOptionType'"); } // create instance $this->typeObjects[$type] = new $className(); } return $this->typeObjects[$type]; }
/** * Returns the class name of a plugin. * * @param string $type * @param string $tag * @return string class name */ public function getPluginClassName($type, $tag) { return $this->pluginNamespace . StringUtil::firstCharToUpperCase($tag) . StringUtil::firstCharToUpperCase(StringUtil::toLowerCase($type)) . 'TemplatePlugin'; }
/** * @see wcf\system\package\plugin\AbstractOptionPackageInstallationPlugin::saveOption() */ protected function saveOption($option, $categoryName, $existingOptionID = 0) { // default values $optionName = $optionType = $defaultValue = $validationPattern = $selectOptions = $enableOptions = $permissions = $options = ''; $showOrder = null; $hidden = $supportI18n = $requireI18n = 0; // get values if (isset($option['name'])) { $optionName = $option['name']; } if (isset($option['optiontype'])) { $optionType = $option['optiontype']; } if (isset($option['defaultvalue'])) { $defaultValue = WCF::getLanguage()->get($option['defaultvalue']); } if (isset($option['validationpattern'])) { $validationPattern = $option['validationpattern']; } if (isset($option['enableoptions'])) { $enableOptions = $option['enableoptions']; } if (isset($option['showorder'])) { $showOrder = intval($option['showorder']); } if (isset($option['hidden'])) { $hidden = intval($option['hidden']); } $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName'); if (isset($option['selectoptions'])) { $selectOptions = $option['selectoptions']; } if (isset($option['permissions'])) { $permissions = $option['permissions']; } if (isset($option['options'])) { $options = $option['options']; } if (isset($option['supporti18n'])) { $supportI18n = $option['supporti18n']; } 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 . "'"); } // collect additional tags and their values $additionalData = array(); foreach ($option as $tag => $value) { if (!in_array($tag, self::$reservedTags)) { $additionalData[$tag] = $value; } } // build update or create data $data = array('categoryName' => $categoryName, 'optionType' => $optionType, 'validationPattern' => $validationPattern, 'selectOptions' => $selectOptions, 'showOrder' => $showOrder, 'enableOptions' => $enableOptions, 'hidden' => $hidden, 'permissions' => $permissions, 'options' => $options, 'supportI18n' => $supportI18n, 'requireI18n' => $requireI18n, 'additionalData' => serialize($additionalData)); // try to find an existing option for updating $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_" . $this->tableName . "\n\t\t\tWHERE\toptionName = ?\n\t\t\t\tAND packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($optionName, $this->installation->getPackageID())); $row = $statement->fetchArray(); // result was 'false' thus create a new item if (!$row) { $data['optionName'] = $optionName; $data['packageID'] = $this->installation->getPackageID(); $data['optionValue'] = $defaultValue; OptionEditor::create($data); } else { // update existing item $optionObj = new Option(null, $row); $optionEditor = new OptionEditor($optionObj); $optionEditor->update($data); } }
/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { // encode html $content = self::trim($content); // get attributes $this->mapAttributes($openingTag); // fetch highlighter-classname $className = '\\wcf\\system\\bbcode\\highlighter\\PlainHighlighter'; // no highlighting for strings over a certain size, to prevent DoS // this serves as a safety net in case one of the regular expressions // in a highlighter causes PCRE to exhaust resources, such as the stack if (strlen($content) < 16384) { if ($this->codeType) { $className = '\\wcf\\system\\bbcode\\highlighter\\' . StringUtil::firstCharToUpperCase(mb_strtolower($this->codeType)) . 'Highlighter'; switch (mb_substr($className, strlen('\\wcf\\system\\bbcode\\highlighter\\'))) { case 'ShellHighlighter': $className = '\\wcf\\system\\bbcode\\highlighter\\BashHighlighter'; break; case 'C++Highlighter': $className = '\\wcf\\system\\bbcode\\highlighter\\CHighlighter'; break; case 'JavascriptHighlighter': $className = '\\wcf\\system\\bbcode\\highlighter\\JsHighlighter'; break; case 'LatexHighlighter': $className = '\\wcf\\system\\bbcode\\highlighter\\TexHighlighter'; break; } } else { // try to guess highlighter if (mb_strpos($content, '<?php') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\PhpHighlighter'; } else { if (mb_strpos($content, '<html') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\HtmlHighlighter'; } else { if (mb_strpos($content, '<?xml') === 0) { $className = '\\wcf\\system\\bbcode\\highlighter\\XmlHighlighter'; } else { if (mb_strpos($content, 'SELECT') === 0 || mb_strpos($content, 'UPDATE') === 0 || mb_strpos($content, 'INSERT') === 0 || mb_strpos($content, 'DELETE') === 0) { $className = '\\wcf\\system\\bbcode\\highlighter\\SqlHighlighter'; } else { if (mb_strpos($content, 'import java.') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\JavaHighlighter'; } else { if (mb_strpos($content, "---") !== false && mb_strpos($content, "\n+++") !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\DiffHighlighter'; } else { if (mb_strpos($content, "\n#include ") !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\CHighlighter'; } else { if (mb_strpos($content, '#!/usr/bin/perl') === 0) { $className = '\\wcf\\system\\bbcode\\highlighter\\PerlHighlighter'; } else { if (mb_strpos($content, 'def __init__(self') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\PythonHighlighter'; } else { if (Regex::compile('^#!/bin/(ba|z)?sh')->match($content)) { $className = '\\wcf\\system\\bbcode\\highlighter\\BashHighlighter'; } else { if (mb_strpos($content, '\\documentclass') !== false) { $className = '\\wcf\\system\\bbcode\\highlighter\\TexHighlighter'; } else { if (Regex::compile('[-\\+\\.,\\[\\]\\>\\<]{9}')->match($content)) { // 9 times a brainfuck char in a row -> seems to be brainfuck $className = '\\wcf\\system\\bbcode\\highlighter\\BrainfuckHighlighter'; } } } } } } } } } } } } } } if (!class_exists($className)) { $className = '\\wcf\\system\\bbcode\\highlighter\\PlainHighlighter'; } if ($parser->getOutputType() == 'text/html') { $highlightedContent = self::fixMarkup(explode("\n", $className::getInstance()->highlight($content))); // show template WCF::getTPL()->assign(array('lineNumbers' => self::makeLineNumbers($content, $this->startLineNumber), 'startLineNumber' => $this->startLineNumber, 'content' => $highlightedContent, 'highlighter' => $className::getInstance(), 'filename' => $this->filename, 'lines' => substr_count($content, "\n") + 1)); return WCF::getTPL()->fetch('codeBBCodeTag'); } else { if ($parser->getOutputType() == 'text/simplified-html') { return WCF::getLanguage()->getDynamicVariable('wcf.bbcode.code.text', array('highlighterTitle' => $className::getInstance()->getTitle(), 'lines' => substr_count($content, "\n") + 1)); } } }
/** * @see \wcf\data\IDatabaseObjectAction::validateAction() */ public function validateAction() { // validate if user is logged in if (!WCF::getUser()->userID && !in_array($this->getActionName(), $this->allowGuestAccess)) { throw new PermissionDeniedException(); } else { if (!RequestHandler::getInstance()->isACPRequest() && in_array($this->getActionName(), $this->requireACP)) { // attempt to invoke method, but origin is not the ACP throw new PermissionDeniedException(); } } // validate action name if (!method_exists($this, $this->getActionName())) { throw new SystemException("unknown action '" . $this->getActionName() . "'"); } $actionName = 'validate' . StringUtil::firstCharToUpperCase($this->getActionName()); if (!method_exists($this, $actionName)) { throw new PermissionDeniedException(); } // execute action call_user_func_array(array($this, $actionName), $this->getParameters()); // fire event action EventHandler::getInstance()->fireAction($this, 'validateAction'); }