/** * Prepares JSON-encoded values for disabling or enabling dependent options. * * @param wcf\data\option\Option $option * @return array */ protected function parseEnableOptions(Option $option) { $disableOptions = $enableOptions = ''; if (!empty($option->enableOptions)) { $options = $option->parseMultipleEnableOptions(); foreach ($options as $key => $optionData) { $tmp = explode(',', $optionData); foreach ($optionData as $item) { if ($item{0} == '!') { if (!empty($disableOptions)) $disableOptions .= ','; $disableOptions .= "{ value: '".$key."', option: '".StringUtil::substring($item, 1)."' }"; } else { if (!empty($enableOptions)) $enableOptions .= ','; $enableOptions .= "{ value: '".$key."', option: '".$item."' }"; } } } } return array( 'disableOptions' => $disableOptions, 'enableOptions' => $enableOptions ); }
/** * @see wcf\system\option\IOptionType::validate() */ public function validate(Option $option, $newValue) { if (!empty($newValue)) { $options = $option->parseSelectOptions(); if (!isset($options[$newValue])) { throw new UserInputException($option->optionName, 'validationFailed'); } } }
/** * @see wcf\system\option\IOptionType::validate() */ public function validate(Option $option, $newValue) { if (!is_array($newValue)) $newValue = array(); $options = $option->parseSelectOptions(); foreach ($newValue as $value) { if (!isset($options[$value])) { throw new UserInputException($option->optionName, 'validationFailed'); } } }
/** * Returns a list of options. * * @return array<wcf\data\option\Option> */ public static function getOptions() { $sql = "SELECT * FROM wcf".WCF_N."_option"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); $options = array(); while ($row = $statement->fetchArray()) { $option = new Option(null, $row); $options[$option->getConstantName()] = $option; } return $options; }
/** * @see \wcf\action\IAction::execute(); */ public function execute() { parent::execute(); // header @header('Content-type: text/xml'); // file name @header('Content-disposition: attachment; filename="options.xml"'); // no cache headers @header('Pragma: no-cache'); @header('Expires: 0'); // content echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<options>\n"; $options = Option::getOptions(); foreach ($options as $option) { if ($option->hidden) { continue; } // ignore hidden options echo "\t<option>\n"; echo "\t\t<name><![CDATA[" . StringUtil::escapeCDATA($option->optionName) . "]]></name>\n"; echo "\t\t<value><![CDATA[" . StringUtil::escapeCDATA($option->optionValue) . "]]></value>\n"; echo "\t</option>\n"; } echo '</options>'; $this->executed(); exit; }
/** * @see wcf\system\option\IOptionType::getFormElement() */ public function getFormElement(Option $option, $value) { $options = Option::parseEnableOptions($option->enableOptions); WCF::getTPL()->assign(array( 'disableOptions' => $options['disableOptions'], 'enableOptions' => $options['enableOptions'], 'option' => $option, 'value' => $value )); return WCF::getTPL()->fetch('booleanOptionType'); }
/** * Checks visibility of an option. * * @param wcf\data\option\Option $option * @return boolean */ protected function checkVisibility(Option $option) { return $option->isVisible(); }
/** * Rebuilds the option file. */ public static function rebuild() { $buffer = ''; // file header $buffer .= "<?php\n/**\n* generated at ".gmdate('r')."\n*/\n"; // get all options $options = Option::getOptions(); foreach ($options as $optionName => $option) { $buffer .= "if (!defined('".$optionName."')) define('".$optionName."', ".(($option->optionType == 'boolean' || $option->optionType == 'integer') ? intval($option->optionValue) : "'".addcslashes($option->optionValue, "'\\")."'").");\n"; } unset($options); // file footer $buffer .= "\n"; // open file $file = new File(WCF_DIR.'options.inc.php'); // write buffer $file->write($buffer); // close file $file->close(); @$file->chmod(0777); }
/** * @see \wcf\system\option\OptionHandler::checkVisibility() */ protected function checkVisibility(Option $option) { if ($option->isDisabled) { return false; } // in registration if ($this->inRegistration && !$option->askDuringRegistration && !$option->required && ($option->optionName != 'birthday' || !REGISTER_MIN_USER_AGE)) { return false; } // search mode if ($this->searchMode && !$option->searchable) { return false; } if ($this->conditionMode && !$this->getTypeObject($option->optionType) instanceof ISearchableConditionUserOption) { return false; } if ($this->user !== null) { $option->setUser($this->user); } if ($this->editMode) { return $option->isEditable(); } else { if (!$this->conditionMode) { return $option->isVisible(); } } return true; }
/** * Compiles LESS stylesheets into one CSS-stylesheet and writes them * to filesystem. Please be aware not to append '.css' within $filename! * * @param string $filename * @param array<string> $files * @param array<string> $variables * @param string $individualLess * @param \wcf\system\Callback $callback */ protected function compileStylesheet($filename, array $files, array $variables, $individualLess, Callback $callback) { foreach ($variables as &$value) { if (StringUtil::startsWith($value, '../')) { $value = '~"' . $value . '"'; } } unset($value); // add options as LESS variables if (PACKAGE_ID) { foreach (Option::getOptions() as $constantName => $option) { if (in_array($option->optionType, static::$supportedOptionType)) { $variables['wcf_option_' . mb_strtolower($constantName)] = '~"' . $option->optionValue . '"'; } } } else { // workaround during setup $variables['wcf_option_attachment_thumbnail_height'] = '~"210"'; $variables['wcf_option_attachment_thumbnail_width'] = '~"280"'; $variables['wcf_option_signature_max_image_height'] = '~"150"'; } // build LESS bootstrap $less = $this->bootstrap($variables); foreach ($files as $file) { $less .= $this->prepareFile($file); } // append individual CSS/LESS if ($individualLess) { $less .= $individualLess; } try { $content = $this->compiler->compile($less); } catch (\Exception $e) { throw new SystemException("Could not compile LESS: " . $e->getMessage(), 0, '', $e); } $content = $callback($content); // compress stylesheet $lines = explode("\n", $content); $content = $lines[0] . "\n" . $lines[1] . "\n"; for ($i = 2, $length = count($lines); $i < $length; $i++) { $line = trim($lines[$i]); $content .= $line; switch (substr($line, -1)) { case ',': $content .= ' '; break; case '}': $content .= "\n"; break; } if (substr($line, 0, 6) == '@media') { $content .= "\n"; } } // write stylesheet file_put_contents($filename . '.css', $content); FileUtil::makeWritable($filename . '.css'); // convert stylesheet to RTL $content = StyleUtil::convertCSSToRTL($content); // write stylesheet for RTL file_put_contents($filename . '-rtl.css', $content); FileUtil::makeWritable($filename . '-rtl.css'); }
/** * @see wcf\system\option\OptionHandler::checkVisibility() */ protected function checkVisibility(Option $option) { if ($this->user !== null) { $option->setUser($this->user); } if ($this->inRegistration && !$option->askDuringRegistration && !$option->required) { return false; } return $option->isVisible($this->overrideVisibility); }
/** * Checks visibility of an option. * * @param wcf\data\option\Option $option * @return boolean */ protected function checkVisibility(Option $option) { return $option->isVisible($this->overrideVisibility); }
/** * Returns the select options for the given option. * * @param \wcf\dat\option\Option $option * @return array<string> */ protected function getSelectOptions(Option $option) { return $option->parseSelectOptions(); }
/** * Compiles LESS stylesheets. * * @param \cms\data\stylesheet\Stylesheet $stylesheet * @param integer $styleID */ public function compile(Stylesheet $stylesheet, $styleID = null) { $styles = StyleHandler::getInstance()->getStyles(); // compile stylesheet for all installed styles if ($styleID === null) { foreach ($styles as $style) { $this->compile($stylesheet, $style->styleID); } return; } $style = $styles[$styleID]; // get style variables $variables = $style->getVariables(); if (isset($variables['individualLess'])) { unset($variables['individualLess']); } // add style image path $imagePath = '../images/'; if ($style->imagePath) { $imagePath = FileUtil::getRelativePath(WCF_DIR . 'style/', WCF_DIR . $style->imagePath); $imagePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator($imagePath)); } $variables['style_image_path'] = "'{$imagePath}'"; // apply overrides if (isset($variables['overrideLess'])) { $lines = explode("\n", StringUtil::unifyNewlines($variables['overrideLess'])); foreach ($lines as $line) { if (preg_match('~^@([a-zA-Z]+): ?([@a-zA-Z0-9 ,\\.\\(\\)\\%\\#-]+);$~', $line, $matches)) { $variables[$matches[1]] = $matches[2]; } } unset($variables['overrideLess']); } // add options as LESS variables foreach (Option::getOptions() as $constantName => $option) { if (in_array($option->optionType, array('boolean', 'integer'))) { $variables['wcf_option_' . mb_strtolower($constantName)] = '~"' . $option->optionValue . '"'; } } // compile $this->compiler->setVariables($variables); $content = "/* stylesheet for '" . $stylesheet->getTitle() . "', generated on " . gmdate('r') . " -- DO NOT EDIT */\n\n"; $content .= $this->compiler->compile($stylesheet->less); // compress stylesheet $lines = explode("\n", $content); $content = $lines[0] . "\n" . $lines[1] . "\n"; for ($i = 2, $length = count($lines); $i < $length; $i++) { $line = trim($lines[$i]); $content .= $line; switch (substr($line, -1)) { case ',': $content .= ' '; break; case '}': $content .= "\n"; break; } if (substr($line, 0, 6) == '@media') { $content .= "\n"; } } // write stylesheet $filename = $stylesheet->getLocation($styleID); file_put_contents($filename, $content); FileUtil::makeWritable($filename); // write rtl stylesheet $content = StyleUtil::convertCSSToRTL($content); $filename = $stylesheet->getLocation($styleID, true); file_put_contents($filename, $content); FileUtil::makeWritable($filename); }
/** * @see wcf\system\option\OptionHandler::checkVisibility() */ protected function checkVisibility(Option $option) { if ($option->isDisabled) { return false; } // in registration if ($this->inRegistration && !$option->askDuringRegistration && !$option->required) { return false; } // search mode if ($this->searchMode && !$option->searchable) { return false; } if ($this->user !== null) { $option->setUser($this->user); } if ($this->editMode) { return $option->isEditable(); } else { return $option->isVisible(); } }
/** * Rebuilds cached options * * @param string filename * @param integer $packageID */ public static function rebuildFile($filename, $packageID = PACKAGE_ID) { $buffer = ''; // file header $buffer .= "<?php\n/**\n* generated at " . gmdate('r') . "\n*/\n"; // get all options $options = Option::getOptions($packageID); foreach ($options as $optionName => $option) { $buffer .= "if (!defined('" . $optionName . "')) define('" . $optionName . "', " . ($option['optionType'] == 'boolean' || $option['optionType'] == 'integer' ? intval($option['optionValue']) : "'" . addcslashes($option['optionValue'], "'\\") . "'") . ");\n"; } unset($options); // file footer $buffer .= "?>"; // open file $file = new File($filename); // write buffer $file->write($buffer); unset($buffer); // close file $file->close(); @$file->chmod(0777); }
/** * Rebuilds the option file. */ public static function rebuild() { $writer = new AtomicWriter(WCF_DIR . 'options.inc.php'); // file header $writer->write("<?php\n/**\n* generated at " . gmdate('r') . "\n*/\n"); // get all options $options = Option::getOptions(); foreach ($options as $optionName => $option) { $writer->write("if (!defined('" . $optionName . "')) define('" . $optionName . "', " . ($option->optionType == 'boolean' || $option->optionType == 'integer' ? intval($option->optionValue) : "'" . addcslashes($option->optionValue, "'\\") . "'") . ");\n"); } unset($options); // file footer $writer->write("\n"); $writer->flush(); $writer->close(); FileUtil::makeWritable(WCF_DIR . 'options.inc.php'); WCF::resetZendOpcache(WCF_DIR . 'options.inc.php'); }
public function getApiKey() { $options = Option::getOptions(); return $options['WBB_TAPATALK_API_KEY']->optionValue; }