本文整理汇总了PHP中wcf\util\StringUtil::replace方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::replace方法的具体用法?PHP StringUtil::replace怎么用?PHP StringUtil::replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wcf\util\StringUtil
的用法示例。
在下文中一共展示了StringUtil::replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
/**
* @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;
}
示例2: addFile
/**
* 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;
}
示例3: import
/**
* 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);
//.........这里部分代码省略.........
示例4: handleRequest
/**
* 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);
}
}
}
示例5: encodeJS
/**
* 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;
}
示例6: search
/**
* 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;
}
示例7: readFormParameters
/**
* @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']);
}
示例8: getQuotePostContent
/**
* 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]";
}
示例9: sendMail
/**
* 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
}
示例10: search
/**
* 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;
}
示例11: buildRequest
/**
* 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();
}
}
示例12: logFiles
/**
* 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');
}
示例13: import
/**
* 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/') {
//.........这里部分代码省略.........
示例14: replacePHPTags
/**
* 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;
}
示例15: install
/**
* 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();
}