/** * @see wcf\system\option\IOptionType::getData() */ public function getData(Option $option, $newValue) { $number = StringUtil::replace(WCF::getLanguage()->get('wcf.global.thousandsSeparator'), '', $newValue); $d = preg_quote(WCF::getLanguage()->get('wcf.global.decimalPoint'), '~'); if (!preg_match('~^(?:\d*)(?:'.$d.')?\d+~', $number, $matches)) return 0; $number = $matches[0]; if (preg_match('/[kmgt]i?b$/i', $newValue, $multiplier)) { switch (StringUtil::toLowerCase($multiplier[0])) { case 'tb': $number *= 1000; case 'gb': $number *= 1000; case 'mb': $number *= 1000; case 'kb': $number *= 1000; break; case 'tib': $number *= 1024; case 'gib': $number *= 1024; case 'mib': $number *= 1024; case 'kib': $number *= 1024; break; } } return $number; }
/** * Adds a file to the Zip archive. * * @param string $data content of the file * @param string $name filename * @param integer $date file creation time as unix timestamp */ public function addFile($data, $name, $date = 0) { // replace backward slashes with forward slashes in the filename $name = StringUtil::replace("\\", "/", $name); // calculate the size of the file being uncompressed $sizeUncompressed = strlen($data); // get data checksum $crc = crc32($data); // compress the file data $compressedData = gzcompress($data); // calculate the size of the file being compressed $compressedData = substr($compressedData, 2, -4); $sizeCompressed = strlen($compressedData); // construct the general header for the file record complete with checksum information, etc. $header = "PK"; $header .= ""; $header .= ""; $header .= ""; $header .= pack("V", $crc); $header .= pack("V", $sizeCompressed); $header .= pack("V", $sizeUncompressed); $header .= pack("v", strlen($name)); $header .= pack("v", 0); $header .= $name; // store the compressed data immediately following the file header $header .= $compressedData; // complete the file record by adding an additional footer directly following the file data //$header .= pack("V", $crc); //$header .= pack("V", $sizeCompressed); //$header .= pack("V", $sizeUncompressed); // store the completed file record in the $headers array $this->headers[] = $header; // calculate the new offset for the central index record $newOffset = strlen(implode('', $this->headers)); // construct the record $record = "PK"; $record .= ""; $record .= ""; $record .= $this->getDosDatetime($date); $record .= pack("V", $crc); $record .= pack("V", $sizeCompressed); $record .= pack("V", $sizeUncompressed); $record .= pack("v", strlen($name)); $record .= pack("v", 0); $record .= pack("v", 0); $record .= pack("v", 0); $record .= pack("v", 0); $record .= pack("V", 32); $record .= pack("V", $this->lastOffset); // update the offset for the next record to be stored $this->lastOffset = $newOffset; $record .= $name; // store the record in the $data array $this->data[] = $record; }
/** * Imports a style. * * @param string $filename * @param integer $packageID * @param StyleEditor $style * @return StyleEditor */ public static function import($filename, $packageID = PACKAGE_ID, StyleEditor $style = null) { // open file $tar = new Tar($filename); // get style data $data = self::readStyleData($tar); $styleData = array( 'styleName' => $data['name'], 'variables' => $data['variables'], 'styleVersion' => $data['version'], 'styleDate' => $data['date'], 'copyright' => $data['copyright'], 'license' => $data['license'], 'authorName' => $data['authorName'], 'authorURL' => $data['authorURL'] ); // create template group $templateGroupID = 0; if (!empty($data['templates'])) { $templateGroupName = $originalTemplateGroupName = $data['name']; $templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName); if (empty($templateGroupFolderName)) $templateGroupFolderName = 'generic'.StringUtil::substring(StringUtil::getRandomID(), 0, 8); $originalTemplateGroupFolderName = $templateGroupFolderName; // get unique template pack name $i = 1; while (true) { $sql = "SELECT COUNT(*) AS count FROM wcf".WCF_N."_template_group WHERE templateGroupName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($templateGroupName)); $row = $statement->fetchArray(); if (!$row['count']) break; $templateGroupName = $originalTemplateGroupName . '_' . $i; $i++; } // get unique folder name $i = 1; while (true) { $sql = "SELECT COUNT(*) AS count FROM wcf".WCF_N."_template_group WHERE templateGroupFolderName = ? AND parentTemplatePackID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( FileUtil::addTrailingSlash($templateGroupFolderName), 0 )); $row = $statement->fetchArray(); if (!$row['count']) break; $templateGroupFolderName = $originalTemplateGroupFolderName . '_' . $i; $i++; } $templateGroup = TemplateGroupEditor::create(array( 'templateGroupName' => $templateGroupName, 'templateGroupFolderName' => FileUtil::addTrailingSlash($templateGroupFolderName) )); $styleData['templateGroupID'] = $templateGroup->templateGroupID; } // import preview image if (!empty($data['image'])) { $fileExtension = StringUtil::substring($data['image'], StringUtil::lastIndexOf($data['image'], '.')); $index = $tar->getIndexByFilename($data['image']); if ($index !== false) { $filename = WCF_DIR.'images/stylePreview-'.$style->styleID.'.'.$fileExtension; $tar->extract($index, $filename); @chmod($filename, 0777); if (file_exists($filename)) { $styleData['image'] = $filename; } } } // import images if (!empty($data['images']) && $data['imagesPath'] != 'images/') { // create images folder if necessary $imagesLocation = self::getFileLocation($data['imagesPath']); $styleData['imagePath'] = FileUtil::getRelativePath(WCF_DIR, $imagesLocation); $index = $tar->getIndexByFilename($data['images']); if ($index !== false) { // extract images tar $destination = FileUtil::getTemporaryFilename('images_'); $tar->extract($index, $destination); // open images tar $imagesTar = new Tar($destination); $contentList = $imagesTar->getContentList(); foreach ($contentList as $key => $val) { if ($val['type'] == 'file') { $imagesTar->extract($key, $imagesLocation.basename($val['filename'])); @chmod($imagesLocation.basename($val['filename']), 0666); } } // delete tmp file $imagesTar->close(); @unlink($destination); } } // import templates if (!empty($data['templates'])) { $index = $tar->getIndexByFilename($data['templates']); if ($index !== false) { // extract templates tar $destination = FileUtil::getTemporaryFilename('templates_'); $tar->extract($index, $destination); // open templates tar and group templates by package $templatesTar = new Tar($destination); $contentList = $templatesTar->getContentList(); $packageToTemplates = array(); foreach ($contentList as $val) { if ($val['type'] == 'file') { $folders = explode('/', $val['filename']); $packageName = array_shift($folders); if (!isset($packageToTemplates[$packageName])) { $packageToTemplates[$packageName] = array(); } $packageToTemplates[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders)); } } // copy templates foreach ($packageToTemplates as $package => $templates) { // try to find package $sql = "SELECT * FROM wcf".WCF_N."_package WHERE package = ? AND isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( $package, 1 )); while ($row = $statement->fetchArray()) { // get template path $templatesDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$row['packageDir']).'templates/'.$templateGroupFolderName); // create template path if (!file_exists($templatesDir)) { @mkdir($templatesDir, 0777); @chmod($templatesDir, 0777); } // copy templates foreach ($templates as $template) { $templatesTar->extract($template['index'], $templatesDir.$template['filename']); TemplateEditor::create(array( 'packageID' => $row['packageID'], 'templateName' => StringUtil::replace('.tpl', '', $template['filename']), 'templateGroupID' => $templateGroupID )); } } } // delete tmp file $templatesTar->close(); @unlink($destination); } } $tar->close(); // save style if ($style !== null) { $style->update($styleData); } else { $styleData['packageID'] = $packageID; $style = new StyleEditor(self::create($styleData)); } // handle descriptions if (!empty($data['description'])) { self::saveLocalizedDescriptions($style, $data['description']); } if ($data['default']) { $style->setAsDefault(); } return $style; }
/** * Handles request input variables. */ public function handleRequest() { $variables = array(); foreach ($_REQUEST as $key => $value) { if (StringUtil::indexOf($key, $this->getName() . '_') !== false) { $key = StringUtil::replace($this->getName() . '_', '', $key); $variables[$key] = $value; } } if (!empty($variables)) { foreach ($this->containers as $container) { $container->handleRequest($variables); } } }
/** * Converts javascript special characters. * * @param string $string * @return string $string */ public static function encodeJS($string) { if (is_object($string)) { $string = $string->__toString(); } // escape backslash $string = StringUtil::replace("\\", "\\\\", $string); // escape singe quote $string = StringUtil::replace("'", "\\'", $string); // escape new lines $string = StringUtil::replace("\n", '\\n', $string); // escape slashes $string = StringUtil::replace("/", '\\/', $string); return $string; }
/** * Searches in templates. * * @param string $search search query * @param string $replace * @param array $templateIDs * @param boolean $invertTemplates * @param boolean $useRegex * @param boolean $caseSensitive * @param boolean $invertSearch * @return array results */ public static function search($search, $replace = null, $templateIDs = null, $invertTemplates = 0, $useRegex = 0, $caseSensitive = 0, $invertSearch = 0) { // get available template ids $results = array(); $availableTemplateIDs = array(); $sql = "SELECT templateName, templateID, templateGroupID, packageID FROM wcf".WCF_N."_template ".($replace !== null ? "WHERE templateGroupID <> 0" : ""); $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); while ($row = $statement->fetchArray()) { if (!isset($availableTemplateIDs[$row['templateName'].'-'.$row['templateGroupID']]) || PACKAGE_ID == $row['packageID']) { $availableTemplateIDs[$row['templateName'].'-'.$row['templateGroupID']] = $row['templateID']; } } // get templates if (empty($availableTemplateIDs)) return $results; $conditions = new PreparedStatementConditionBuilder(); $conditions->add("template.templateID IN (?)", array($availableTemplateIDs)); if ($templateIDs !== null) $conditions->add("template.templateID ".($invertTemplates ? "NOT " : "")." IN (?)", array($templateIDs)); $sql = "SELECT template.*, group.templateGroupFolderName, package.packageDir FROM wcf".WCF_N."_template template LEFT JOIN wcf".WCF_N."_template_group group ON (group.templateGroupID = template.templateGroupID) LEFT JOIN wcf".WCF_N."_package package ON (package.packageID = template.packageID) ".$conditions." ORDER BY templateName ASC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); unset($availableTemplateIDs); while ($row = $statement->fetchArray()) { $template = new TemplateEditor(null, $row); if ($replace === null) { // search if ($useRegex) $matches = (intval(preg_match('/'.$search.'/s'.(!$caseSensitive ? 'i' : ''), $template->getSource())) !== 0); else { if ($caseSensitive) $matches = (StringUtil::indexOf($template->getSource(), $search) !== false); else $matches = (StringUtil::indexOfIgnoreCase($template->getSource(), $search) !== false); } if (($matches && !$invertSearch) || (!$matches && $invertSearch)) { $results[] = $row; } } else { // search and replace $matches = 0; if ($useRegex) { $newSource = preg_replace('/'.$search.'/s'.(!$caseSensitive ? 'i' : ''), $replace, $template->getSource(), -1, $matches); } else { if ($caseSensitive) $newSource = StringUtil::replace($search, $replace, $template->getSource(), $matches); else $newSource = StringUtil::replaceIgnoreCase($search, $replace, $template->getSource(), $matches); } if ($matches > 0) { $template->setSource($newSource); $row['matches'] = $matches; $results[] = $row; } } } return $results; }
/** * @see wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); I18nHandler::getInstance()->readValues(); if (isset($_POST['className'])) $this->className = StringUtil::trim($_POST['className']); if (isset($_POST['description'])) $this->description = StringUtil::trim($_POST['description']); if (isset($_POST['startMinute'])) $this->startMinute = StringUtil::replace(' ', '', $_POST['startMinute']); if (isset($_POST['startHour'])) $this->startHour = StringUtil::replace(' ', '', $_POST['startHour']); if (isset($_POST['startDom'])) $this->startDom = StringUtil::replace(' ', '', $_POST['startDom']); if (isset($_POST['startMonth'])) $this->startMonth = StringUtil::replace(' ', '', $_POST['startMonth']); if (isset($_POST['startDow'])) $this->startDow = StringUtil::replace(' ', '', $_POST['startDow']); }
/** * return quote post content * * @param Object $oMbqEtForumPost * @return String */ public function getQuotePostContent($oMbqEtForumPost = null) { //ref wcf\system\message\quote\MessageQuoteManager::renderQuote() $oPost = $oMbqEtForumPost->mbqBind['oViewablePost']->getDecoratedObject(); $escapedUsername = StringUtil::replace(array("\\", "'"), array("\\\\", "\\'"), $oPost->getUsername()); $escapedLink = StringUtil::replace(array("\\", "'"), array("\\\\", "\\'"), $oPost->getLink()); return "[quote='" . $escapedUsername . "','" . $escapedLink . "']" . $oMbqEtForumPost->postContent->oriValue . "[/quote]"; }
/** * Sends the mail to given user. * * @param wcf\data\user\User $user */ protected function sendMail(User $user) { // send mail try { $mail = new Mail(array($user->username => $user->email), $this->userMailData['subject'], StringUtil::replace('{$username}', $user->username, $this->mailData['text']), $this->mailData['from']); if ($this->mailData['enableHTML']) { $mail->setContentType('text/html'); } $mail->send(); } catch (SystemException $e) { } // ignore errors }
/** * Searches in templates. * * @param string $search search query * @param string $replace * @param array $templateIDs * @param boolean $invertTemplates * @param boolean $useRegex * @param boolean $caseSensitive * @param boolean $invertSearch * @return array results */ public static function search($search, $replace = null, $templateIDs = null, $invertTemplates = 0, $useRegex = 0, $caseSensitive = 0, $invertSearch = 0) { // get available template ids $results = array(); $availableTemplateIDs = array(); $sql = "SELECT\t\ttemplate.templateName, template.templateID, template.templateGroupID, template.packageID\n\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tON\t\t(package_dependency.dependency = template.packageID)\n\t\t\tWHERE \t\tpackage_dependency.packageID = ?\n\t\t\t\t\t" . ($replace !== null ? "AND template.templateGroupID <> 0" : "") . "\n\t\t\tORDER BY\tpackage_dependency.priority ASC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(PACKAGE_ID)); while ($row = $statement->fetchArray()) { if (!isset($availableTemplateIDs[$row['templateName'] . '-' . $row['templateGroupID']]) || PACKAGE_ID == $row['packageID']) { $availableTemplateIDs[$row['templateName'] . '-' . $row['templateGroupID']] = $row['templateID']; } } // get templates if (!count($availableTemplateIDs)) { return $results; } $conditions = new PreparedStatementConditionBuilder(); $conditions->add("template.templateID IN (?)", array($availableTemplateIDs)); if ($templateIDs !== null) { $conditions->add("template.templateID " . ($invertTemplates ? "NOT " : "") . " IN (?)", array($templateIDs)); } $sql = "SELECT\t\ttemplate.*, group.templateGroupFolderName, package.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_template template\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_template_group group\n\t\t\tON\t\t(group.templateGroupID = template.templateGroupID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = template.packageID)\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\ttemplateName ASC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); unset($availableTemplateIDs); while ($row = $statement->fetchArray()) { $template = new TemplateEditor(null, $row); if ($replace === null) { // search if ($useRegex) { $matches = intval(preg_match('/' . $search . '/s' . (!$caseSensitive ? 'i' : ''), $template->getSource())) !== 0; } else { if ($caseSensitive) { $matches = StringUtil::indexOf($template->getSource(), $search) !== false; } else { $matches = StringUtil::indexOfIgnoreCase($template->getSource(), $search) !== false; } } if ($matches && !$invertSearch || !$matches && $invertSearch) { $results[] = $row; } } else { // search and replace $matches = 0; if ($useRegex) { $newSource = preg_replace('/' . $search . '/s' . (!$caseSensitive ? 'i' : ''), $replace, $template->getSource(), -1, $matches); } else { if ($caseSensitive) { $newSource = StringUtil::replace($search, $replace, $template->getSource(), $matches); } else { $newSource = StringUtil::replaceIgnoreCase($search, $replace, $template->getSource(), $matches); } } if ($matches > 0) { $template->setSource($newSource); $row['matches'] = $matches; $results[] = $row; } } } return $results; }
/** * Builds a new request. * * @param string $application */ protected function buildRequest($application) { try { $routeData = RouteHandler::getInstance()->getRouteData(); // handle landing page for frontend requests if (!$this->isACPRequest()) { $landingPage = PageMenu::getInstance()->getLandingPage(); if ($landingPage !== null && RouteHandler::getInstance()->isDefaultController()) { // check if redirect URL matches current URL $redirectURL = $landingPage->getLink(); if (StringUtil::replace(RouteHandler::getHost(), '', $redirectURL) == $_SERVER['REQUEST_URI']) { $routeData['controller'] = $landingPage->getController(); } else { // redirect to landing page HeaderUtil::redirect($landingPage->getLink(), true); exit; } } } $controller = $routeData['controller']; // validate class name if (!preg_match('~^[a-z0-9_]+$~i', $controller)) { throw new SystemException("Illegal class name '".$controller."'"); } // find class $classData = $this->getClassData($controller, 'page', $application); if ($classData === null) $classData = $this->getClassData($controller, 'form', $application); if ($classData === null) $classData = $this->getClassData($controller, 'action', $application); if ($classData === null) { throw new SystemException("unable to find class for controller '".$controller."'"); } else if (!class_exists($classData['className'])) { throw new SystemException("unable to find class '".$classData['className']."'"); } $this->activeRequest = new Request($classData['className'], $classData['controller'], $classData['pageType']); } catch (SystemException $e) { throw new IllegalLinkException(); } }
/** * Logs the unzipped files. */ protected function logFiles() { $this->initDB(); $this->getInstalledFiles(WCF_DIR); $acpTemplateInserts = $fileInserts = array(); foreach (self::$installedFiles as $file) { $match = array(); if (preg_match('!/acp/templates/([^/]+)\\.tpl$!', $file, $match)) { // acp template $acpTemplateInserts[] = $match[1]; } else { // regular file $fileInserts[] = StringUtil::replace(WCF_DIR, '', $file); } } // save acp template log if (!empty($acpTemplateInserts)) { $sql = "INSERT INTO\twcf" . WCF_N . "_acp_template\n\t\t\t\t\t\t(templateName)\n\t\t\t\tVALUES\t\t(?)"; $statement = self::getDB()->prepareStatement($sql); self::getDB()->beginTransaction(); foreach ($acpTemplateInserts as $acpTemplate) { $statement->executeUnbuffered(array($acpTemplate)); } self::getDB()->commitTransaction(); } // save file log if (!empty($fileInserts)) { $sql = "INSERT INTO\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\t\t\t(filename)\n\t\t\t\tVALUES\t\t(?)"; $statement = self::getDB()->prepareStatement($sql); self::getDB()->beginTransaction(); foreach ($fileInserts as $file) { $statement->executeUnbuffered(array($file)); } self::getDB()->commitTransaction(); } $this->gotoNextStep('installLanguage'); }
/** * Imports a style. * * @param string $filename * @param integer $packageID * @param StyleEditor $style * @return StyleEditor */ public static function import($filename, $packageID = PACKAGE_ID, StyleEditor $style = null) { // open file $tar = new Tar($filename); // get style data $data = self::readStyleData($tar); // get image locations $iconsLocation = FileUtil::addTrailingSlash($data['variables']['global.icons.location']); $imagesLocation = $data['variables']['global.images.location']; // create template group $templateGroupID = 0; if (!empty($data['templates'])) { $templateGroupName = $data['name']; $templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName); if (empty($templateGroupFolderName)) { $templateGroupFolderName = 'generic' . StringUtil::substring(StringUtil::getRandomID(), 0, 8); } $originalTemplatePackFolderName = $templateGroupFolderName; // get unique template pack name $i = 1; do { $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_template_group\n\t\t\t\t\tWHERE\ttemplateGroupName = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($templateGroupName)); $row = $statement->fetchArray(); if (!$row['count']) { break; } $templateGroupName = $originalTemplatePackName . '_' . $i; //TODO: undefined variable $i++; } while (true); // get unique folder name $i = 1; do { $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_template_group\n\t\t\t\t\tWHERE\ttemplateGroupFolderName = ?\n\t\t\t\t\t\tAND parentTemplatePackID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(FileUtil::addTrailingSlash($templateGroupFolderName), 0)); $row = $statement->fetchArray(); if (!$row['count']) { break; } $templateGroupFolderName = $originalTemplatePackFolderName . '_' . $i; $i++; } while (true); $templateGroup = TemplateGroupEditor::create(array('templateGroupName' => $templateGroupName, 'templateGroupFolderName' => FileUtil::addTrailingSlash($templateGroupFolderName))); $templateGroupID = $templateGroup->templateGroupID; } // save style $styleData = array('styleName' => $data['name'], 'variables' => $data['variables'], 'templateGroupID' => $templateGroupID, 'styleDescription' => $data['description'], 'styleVersion' => $data['version'], 'styleDate' => $data['date'], 'image' => ($data['image'] ? 'images/' : '') . $data['image'], 'copyright' => $data['copyright'], 'license' => $data['license'], 'authorName' => $data['authorName'], 'authorURL' => $data['authorURL']); if ($style !== null) { $style->update($styleData); } else { $styleData['packageID'] = $packageID; $style = self::create($styleData); } // import preview image if (!empty($data['image'])) { $i = $tar->getIndexByFilename($data['image']); if ($i !== false) { $tar->extract($i, WCF_DIR . 'images/' . $data['image']); @chmod(WCF_DIR . 'images/' . $data['image'], 0777); } } // import images if (!empty($data['images'])) { // create images folder if necessary if (!file_exists(WCF_DIR . $imagesLocation)) { @mkdir(WCF_DIR . $data['variables']['global.images.location'], 0777); @chmod(WCF_DIR . $data['variables']['global.images.location'], 0777); } $i = $tar->getIndexByFilename($data['images']); if ($i !== false) { // extract images tar $destination = FileUtil::getTemporaryFilename('images_'); $tar->extract($i, $destination); // open images tar $imagesTar = new Tar($destination); $contentList = $imagesTar->getContentList(); foreach ($contentList as $key => $val) { if ($val['type'] == 'file') { $imagesTar->extract($key, WCF_DIR . $imagesLocation . basename($val['filename'])); @chmod(WCF_DIR . $imagesLocation . basename($val['filename']), 0666); } } // delete tmp file $imagesTar->close(); @unlink($destination); } } // import icons if (!empty($data['icons']) && $iconsLocation != 'icon/') { $i = $tar->getIndexByFilename($data['icons']); if ($i !== false) { // extract icons tar $destination = FileUtil::getTemporaryFilename('icons_'); $tar->extract($i, $destination); // open icons tar and group icons by package $iconsTar = new Tar($destination); $contentList = $iconsTar->getContentList(); $packageToIcons = array(); foreach ($contentList as $val) { if ($val['type'] == 'file') { $folders = explode('/', $val['filename']); $packageName = array_shift($folders); if (!isset($packageToIcons[$packageName])) { $packageToIcons[$packageName] = array(); } $packageToIcons[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders)); } } // copy icons foreach ($packageToIcons as $package => $icons) { // try to find package $sql = "SELECT\t*\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = ?\n\t\t\t\t\t\t\tAND isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($package, 1)); while ($row = $statement->fetchArray()) { // get icon path $iconDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . $iconsLocation; // create icon path if (!file_exists($iconDir)) { @mkdir($iconDir, 0777); @chmod($iconDir, 0777); } // copy icons foreach ($icons as $icon) { $iconsTar->extract($icon['index'], $iconDir . $icon['filename']); } } } // delete tmp file $iconsTar->close(); @unlink($destination); } } // import templates if (!empty($data['templates'])) { $i = $tar->getIndexByFilename($data['templates']); if ($i !== false) { // extract templates tar $destination = FileUtil::getTemporaryFilename('templates_'); $tar->extract($i, $destination); // open templates tar and group templates by package $templatesTar = new Tar($destination); $contentList = $templatesTar->getContentList(); $packageToTemplates = array(); foreach ($contentList as $val) { if ($val['type'] == 'file') { $folders = explode('/', $val['filename']); $packageName = array_shift($folders); if (!isset($packageToTemplates[$packageName])) { $packageToTemplates[$packageName] = array(); } $packageToTemplates[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders)); } } // copy templates foreach ($packageToTemplates as $package => $templates) { // try to find package $sql = "SELECT\t*\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = ?\n\t\t\t\t\t\t\tAND isApplication = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($package, 1)); while ($row = $statement->fetchArray()) { // get icon path $templatesDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . 'templates/' . $templateGroupFolderName); // create template path if (!file_exists($templatesDir)) { @mkdir($templatesDir, 0777); @chmod($templatesDir, 0777); } // copy templates foreach ($templates as $template) { $templatesTar->extract($template['index'], $templatesDir . $template['filename']); TemplateEditor::create(array('packageID' => $row['packageID'], 'templateName' => StringUtil::replace('.tpl', '', $template['filename']), 'templateGroupID' => $templateGroupID)); } } } // delete tmp file $templatesTar->close(); @unlink($destination); } } $tar->close(); return $style; }
/** * Replaces all php tags. * * @param string $string * @return string */ public function replacePHPTags($string) { if (StringUtil::indexOf($string, '<?') !== false) { $string = StringUtil::replace('<?php', '@@PHP_START_TAG@@', $string); $string = StringUtil::replace('<?', '@@PHP_SHORT_START_TAG@@', $string); $string = StringUtil::replace('?>', '@@PHP_END_TAG@@', $string); $string = StringUtil::replace('@@PHP_END_TAG@@', "<?php echo '?>'; ?>\n", $string); $string = StringUtil::replace('@@PHP_SHORT_START_TAG@@', "<?php echo '<?'; ?>\n", $string); $string = StringUtil::replace('@@PHP_START_TAG@@', "<?php echo '<?php'; ?>\n", $string); } return $string; }
/** * Starts the extracting of the files. */ protected function install() { $this->createTargetDir(); // open source archive $tar = new Tar($this->source); // distinct directories and files $directories = array(); $files = array(); foreach ($tar->getContentList() as $index => $file) { if (empty($this->folder) || StringUtil::indexOf($file['filename'], $this->folder) === 0) { if (!empty($this->folder)) { $file['filename'] = StringUtil::replace($this->folder, '', $file['filename']); } // remove leading slash $file['filename'] = FileUtil::removeLeadingSlash($file['filename']); if ($file['type'] == 'folder') { // remove trailing slash $directories[] = FileUtil::removeTrailingSlash($file['filename']); } else { $files[$index] = $file['filename']; } } } $this->checkFiles($files); // now create the directories $errors = array(); foreach ($directories as $dir) { try { $this->createDir($dir); } catch (SystemException $e) { $errors[] = array('file' => $dir, 'code' => $e->getCode(), 'message' => $e->getMessage()); } } // now untar all files foreach ($files as $index => $file) { try { $this->createFile($file, $index, $tar); } catch (SystemException $e) { $errors[] = array('file' => $file, 'code' => $e->getCode(), 'message' => $e->getMessage()); } } if (count($errors) > 0) { throw new SystemException('error(s) during the installation of the files.', $errors); } $this->logFiles($files); // close tar $tar->close(); }
/** * @see wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); if (isset($_POST['className'])) { $this->className = StringUtil::trim($_POST['className']); } if (isset($_POST['description'])) { $this->description = StringUtil::trim($_POST['description']); } if (isset($_POST['startMinute'])) { $this->startMinute = StringUtil::replace(' ', '', $_POST['startMinute']); } if (isset($_POST['startHour'])) { $this->startHour = StringUtil::replace(' ', '', $_POST['startHour']); } if (isset($_POST['startDom'])) { $this->startDom = StringUtil::replace(' ', '', $_POST['startDom']); } if (isset($_POST['startMonth'])) { $this->startMonth = StringUtil::replace(' ', '', $_POST['startMonth']); } if (isset($_POST['startDow'])) { $this->startDow = StringUtil::replace(' ', '', $_POST['startDow']); } }
/** * get_quote_conversation * * @param Object $oMbqEtPcMsg * @return Mixed */ public function getQuoteConversation($oMbqEtPcMsg) { //ref wcf\system\message\quote\MessageQuoteManager::renderQuote() $oConversationMessage = $oMbqEtPcMsg->mbqBind['oViewableConversationMessage']->getDecoratedObject(); $escapedUsername = StringUtil::replace(array("\\", "'"), array("\\\\", "\\'"), $oConversationMessage->getUsername()); $escapedLink = StringUtil::replace(array("\\", "'"), array("\\\\", "\\'"), $oConversationMessage->getLink()); return "[quote='" . $escapedUsername . "','" . $escapedLink . "']" . $oMbqEtPcMsg->msgContent->oriValue . "[/quote]"; }
/** * Checks the version number of the installed package against the "fromversion" * number of the update. * * The "fromversion" number may contain wildcards (asterisks) which means * that the update covers the whole range of release numbers where the asterisk * wildcards digits from 0 to 9. * For example, if "fromversion" is "1.1.*" and this package updates to * version 1.2.0, all releases from 1.1.0 to 1.1.9 may be updated using * this package. * * @param string $currentVersion * @param string $fromVersion * @return boolean */ public static function checkFromversion($currentVersion, $fromversion) { if (StringUtil::indexOf($fromversion, '*') !== false) { // from version with wildcard // use regular expression $fromversion = StringUtil::replace('\*', '.*', preg_quote($fromversion, '!')); if (preg_match('!^'.$fromversion.'$!i', $currentVersion)) { return true; } } else { if (self::compareVersion($currentVersion, $fromversion, '=')) { return true; } } return false; }
/** * @see wcf\page\AbstractPage::__run() */ public function __run() { $classNameParts = explode('\\', get_called_class()); $className = array_pop($classNameParts); // autoset controllers if (empty($this->addController)) { $this->addController = StringUtil::replace('ListPage', 'Add', $className); } if (empty($this->editController)) { $this->editController = StringUtil::replace('ListPage', 'Edit', $className); } parent::__run(); }
/** * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() */ public function install() { parent::install(); // extract sql file from archive if ($queries = $this->getSQL($this->instruction['value'])) { $package = $this->installation->getPackage(); if ($package->parentPackageID) { // package is a plugin; get parent package $package = $package->getParentPackage(); } if ($package->isApplication == 1) { // package is application $packageAbbr = Package::getAbbreviation($package->package); $tablePrefix = WCF_N . '_' . $package->instanceNo . '_'; // Replace the variable xyz1_1 with $tablePrefix in the table names. $queries = StringUtil::replace($packageAbbr . '1_1_', $packageAbbr . $tablePrefix, $queries); } // replace wcf1_ with the actual WCF_N value $queries = str_replace("wcf1_", "wcf" . WCF_N . "_", $queries); // check queries $parser = new PackageInstallationSQLParser($queries, $this->installation->getPackage(), $this->installation->getAction()); $conflicts = $parser->test(); if (!empty($conflicts)) { if (isset($conflicts['CREATE TABLE']) || isset($conflicts['DROP TABLE'])) { if (!PackageInstallationFormManager::findForm($this->installation->queue, 'overwriteDatabaseTables')) { $container = new GroupFormElementContainer(); if (isset($conflicts['CREATE TABLE'])) { $text = implode('<br />', $conflicts['CREATE TABLE']); $label = WCF::getLanguage()->get('wcf.acp.package.error.sql.createTable'); $description = WCF::getLanguage()->get('wcf.acp.package.error.sql.createTable.description'); $element = new LabelFormElement($container); $element->setLabel($label); $element->setText($text); $element->setDescription($description); $container->appendChild($element); } if (isset($conflicts['DROP TABLE'])) { $text = implode('<br />', $conflicts['DROP TABLE']); $label = WCF::getLanguage()->get('wcf.acp.package.error.sql.dropTable'); $description = WCF::getLanguage()->get('wcf.acp.package.error.sql.dropTable.description'); $element = new LabelFormElement($container); $element->setLabel($label); $element->setText($text); $element->setDescription($description); $container->appendChild($element); } $document = new FormDocument('overwriteDatabaseTables'); $document->appendContainer($container); PackageInstallationFormManager::registerForm($this->installation->queue, $document); return $document; } else { /* * At this point the user decided to continue the installation (he would called the rollback * otherwise), thus we do not care about the form anymore */ } } // ask user here // search default value in session if (!WCF::getSession()->getVar('overrideAndDontAskAgain')) { // show page if (!empty($_POST['override']) || !empty($_POST['overrideAndDontAskAgain'])) { if (!empty($_POST['overrideAndDontAskAgain'])) { WCF::getSession()->register('overrideAndDontAskAgain', true); WCF::getSession()->update(); } } else { WCF::getTPL()->assign('conflicts', $conflicts); WCF::getTPL()->display('packageInstallationCheckOverrideTables'); exit; } } } // execute queries $parser->execute(); // log changes $parser->log(); } }
/** * Installs current package. * * @param array $nodeData */ protected function installPackage(array $nodeData) { $installationStep = new PackageInstallationStep(); // check requirements if (!empty($nodeData['requirements'])) { foreach ($nodeData['requirements'] as $package => $requirementData) { // get existing package if ($requirementData['packageID']) { $sql = "SELECT packageName, packageVersion FROM wcf".WCF_N."_package WHERE packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($requirementData['packageID'])); } else { // try to find matching package $sql = "SELECT packageName, packageVersion FROM wcf".WCF_N."_package WHERE package = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($package)); } $row = $statement->fetchArray(); // package is required but not available if ($row === false) { throw new SystemException("Package '".$package."' is required by '".$nodeData['packageName']."', but is neither installed nor shipped."); } // check version requirements if ($requirementData['minVersion']) { if (Package::compareVersion($row['packageVersion'], $requirementData['minVersion']) < 0) { throw new SystemException("Package '".$nodeData['packageName']."' requires the package '".$row['packageName']."' in version '".$requirementData['minVersion']."', but version '".$row['packageVersion']."'"); } } } } unset($nodeData['requirements']); if (!$this->queue->packageID) { // create package entry $package = PackageEditor::create($nodeData); // update package id for current queue $queueEditor = new PackageInstallationQueueEditor($this->queue); $queueEditor->update(array( 'packageID' => $package->packageID )); // save excluded packages if (count($this->getArchive()->getExcludedPackages()) > 0) { $sql = "INSERT INTO wcf".WCF_N."_package_exclusion (packageID, excludedPackage, excludedPackageVersion) VALUES (?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($this->getArchive()->getExcludedPackages() as $excludedPackage) { $statement->execute(array($package->packageID, $excludedPackage['name'], (!empty($excludedPackage['version']) ? $excludedPackage['version'] : ''))); } } // if package is plugin to com.woltlab.wcf it must not have any other requirement $requirements = $this->getArchive()->getRequirements(); // insert requirements and dependencies $requirements = $this->getArchive()->getAllExistingRequirements(); if (!empty($requirements)) { $sql = "INSERT INTO wcf".WCF_N."_package_requirement (packageID, requirement) VALUES (?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($requirements as $identifier => $possibleRequirements) { if (count($possibleRequirements) == 1) { $requirement = array_shift($possibleRequirements); } else { $requirement = $possibleRequirements[$this->selectedRequirements[$identifier]]; } $statement->execute(array($package->packageID, $requirement['packageID'])); } } // reload queue $this->queue = new PackageInstallationQueue($this->queue->queueID); $this->package = null; if ($package->isApplication) { $host = StringUtil::replace(RouteHandler::getProtocol(), '', RouteHandler::getHost()); $path = RouteHandler::getPath(array('acp')); // insert as application ApplicationEditor::create(array( 'domainName' => $host, 'domainPath' => $path, 'cookieDomain' => $host, 'cookiePath' => $path, 'packageID' => $package->packageID )); } } if ($this->getPackage()->isApplication && $this->getPackage()->package != 'com.woltlab.wcf' && $this->getAction() == 'install') { if (empty($this->getPackage()->packageDir)) { $document = $this->promptPackageDir(); if ($document !== null && $document instanceof FormDocument) { $installationStep->setDocument($document); } $installationStep->setSplitNode(); } } return $installationStep; }
/** * 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 = StringUtil::replace('CacheBuilder', '', array_pop($className)); if (!empty($parameters)) { $cacheName .= '-' . $this->getCacheIndex($parameters); } return $application . '_' . StringUtil::firstCharToUpperCase($cacheName); }