当前位置: 首页>>代码示例>>PHP>>正文


PHP FileUtil::getSafeMode方法代码示例

本文整理汇总了PHP中FileUtil::getSafeMode方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::getSafeMode方法的具体用法?PHP FileUtil::getSafeMode怎么用?PHP FileUtil::getSafeMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileUtil的用法示例。


在下文中一共展示了FileUtil::getSafeMode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setSource

 /**
  * Saves the source of this template.
  * 
  * @param	string		$source 
  */
 public function setSource($source)
 {
     $path = $this->getPath();
     // create dir
     $folder = dirname($path);
     if (!file_exists($folder) && !FileUtil::getSafeMode()) {
         mkdir($folder, 0777);
     }
     // set source
     require_once WCF_DIR . 'lib/system/io/File.class.php';
     $file = new File($path);
     $file->write($source);
     $file->close();
     @$file->chmod(0777);
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:20,代码来源:TemplateEditor.class.php

示例2: import

 /**
  * Imports a style.
  * 
  * @param	string		$filename
  * @param	integer		$packageID
  * @param	StyleEditor	$style
  * @return	StyleEditor
  */
 public static function import($filename, $packageID = PACKAGE_ID, $style = null)
 {
     // open file
     require_once WCF_DIR . 'lib/system/io/Tar.class.php';
     $tar = new Tar($filename);
     // get style data
     $data = self::readStyleData($tar);
     // fix safe_mode problem
     $iconsLocation = FileUtil::addTrailingSlash($data['variables']['global.icons.location']);
     $imagesLocation = $data['variables']['global.images.location'];
     if (FileUtil::getSafeMode() && !empty($data['images']) && !file_exists(WCF_DIR . $imagesLocation)) {
         $oldImagesLocation = $imagesLocation;
         $imagesLocation = 'images/' . str_replace('/', '-', preg_replace('!^images/!', '', $imagesLocation));
         foreach ($data['variables'] as $name => $value) {
             $data['variables'][$name] = str_replace($oldImagesLocation, $imagesLocation, $value);
         }
         $data['variables']['global.images.location'] = 'images/';
         if (strpos($data['variables']['page.logo.image'], '../') !== false) {
             $data['variables']['page.logo.image'] = 'images/' . basename($data['variables']['page.logo.image']);
         }
     }
     // create template pack
     $templatePackID = 0;
     if (!empty($data['templates'])) {
         // create template pack
         $originalTemplatePackName = $templatePackName = $data['name'];
         $templatePackFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templatePackName);
         if (empty($templatePackFolderName)) {
             $templatePackFolderName = 'generic' . StringUtil::substring(StringUtil::getRandomID(), 0, 8);
         }
         $originalTemplatePackFolderName = $templatePackFolderName;
         // get unique template pack name
         $i = 1;
         do {
             $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_template_pack\n\t\t\t\t\tWHERE\ttemplatePackName = '" . escapeString($templatePackName) . "'";
             $row = WCF::getDB()->getFirstRow($sql);
             if (!$row['count']) {
                 break;
             }
             $templatePackName = $originalTemplatePackName . '_' . $i;
             $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_pack\n\t\t\t\t\tWHERE\ttemplatePackFolderName = '" . escapeString(FileUtil::addTrailingSlash($templatePackFolderName)) . "'\n\t\t\t\t\t\tAND parentTemplatePackID = 0";
             $row = WCF::getDB()->getFirstRow($sql);
             if (!$row['count']) {
                 break;
             }
             $templatePackFolderName = $originalTemplatePackFolderName . '_' . $i;
             $i++;
         } while (true);
         $sql = "INSERT INTO\twcf" . WCF_N . "_template_pack\n\t\t\t\t\t\t(templatePackName, templatePackFolderName)\n\t\t\t\tVALUES\t\t('" . escapeString($templatePackName) . "', '" . FileUtil::addTrailingSlash(escapeString($templatePackFolderName)) . "')";
         WCF::getDB()->sendQuery($sql);
         $templatePackID = WCF::getDB()->getInsertID("wcf" . WCF_N . "_template_pack", 'templatePackID');
     }
     // save style
     if ($style !== null) {
         $style->update($data['name'], $data['variables'], $templatePackID, $data['description'], $data['version'], $data['date'], ($data['image'] ? 'images/' : '') . $data['image'], $data['copyright'], $data['license'], $data['authorName'], $data['authorURL']);
     } else {
         $style = self::create($data['name'], $data['variables'], $templatePackID, $data['description'], $data['version'], $data['date'], ($data['image'] ? 'images/' : '') . $data['image'], $data['copyright'], $data['license'], $data['authorName'], $data['authorURL'], 0, $packageID);
     }
     // 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) && !FileUtil::getSafeMode()) {
             @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);
                 }
             }
//.........这里部分代码省略.........
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:101,代码来源:StyleEditor.class.php

示例3: checkSafeMode

 /**
  * Checks if PHP's safe_mode is enabled, and if so, cares for ftp access.
  * 
  * @return	resource	$ftp
  */
 public function checkSafeMode()
 {
     if (FileUtil::getSafeMode() == 1 && function_exists('ftp_connect')) {
         // has this form already been submitted?
         if (isset($_POST['send']) && !empty($_POST['send'])) {
             $send = $_POST['send'];
         } else {
             $send = false;
         }
         $ftpHost = '';
         $ftpUser = '';
         $ftpPassword = '';
         $errorField = '';
         $errorType = '';
         try {
             if ($send) {
                 // get ftp hostname, username and password from POST data, if available
                 if (isset($_POST['ftpHost']) && !empty($_POST['ftpHost'])) {
                     $ftpHost = $_POST['ftpHost'];
                     WCF::getSession()->register('ftpHost', $ftpHost);
                 }
                 if (isset($_POST['ftpUser']) && !empty($_POST['ftpUser'])) {
                     $ftpUser = $_POST['ftpUser'];
                     WCF::getSession()->register('ftpUser', $ftpUser);
                 }
                 if (isset($_POST['ftpPassword']) && !empty($_POST['ftpPassword'])) {
                     $ftpPassword = $_POST['ftpPassword'];
                     WCF::getSession()->register('ftpPassword', $ftpPassword);
                 }
             }
             // else try to read them from session variables; if still not available,
             // mark the respective field as being erroneous.
             if (empty($ftpHost)) {
                 $ftpHost = WCF::getSession()->getVar('ftpHost');
                 if (empty($ftpHost) && $send == true) {
                     throw new UserInputException('ftpHost');
                 }
             }
             if (empty($ftpUser)) {
                 $ftpUser = WCF::getSession()->getVar('ftpUser');
                 if (empty($ftpUser) && $send == true) {
                     throw new UserInputException('ftpUser');
                 }
             }
             if (empty($ftpPassword)) {
                 $ftpPassword = WCF::getSession()->getVar('ftpPassword');
             }
             if (!empty($ftpHost) && !empty($ftpUser)) {
                 // open ftp connection.
                 try {
                     $ftp = FTPUtil::initFtpAccess($ftpHost, $ftpUser, $ftpPassword);
                     return $ftp;
                 } catch (SystemException $e) {
                     $errCode = $e->getCode();
                     switch ($errCode) {
                         case 14000:
                             throw new UserInputException('ftpHost', 'cannotConnect');
                         case 14002:
                             throw new UserInputException('ftpUser', 'cannotLogin');
                     }
                 }
             }
         } catch (UserInputException $e) {
             $errorField = $e->getField();
             $errorType = $e->getType();
             // go back to the prompt and tell the user that something went wrong.
             FTPUtil::promptFtpAccess($ftpHost, $ftpUser, $ftpPassword, $errorField, $errorType);
         }
         // if ftp username and password are not available, prompt the user.
         if (empty($ftpUser) && empty($ftpPassword)) {
             FTPUtil::promptFtpAccess();
         }
     } else {
         return null;
     }
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:81,代码来源:PackageInstallationQueue.class.php

示例4: promptFtp

 /**
  * Prompts for ftp access data.
  */
 protected function promptFtp()
 {
     // safe mode is not active or ftp extension is not loaded
     // skip ftp prompting
     if (FileUtil::getSafeMode() != 1 || !extension_loaded('ftp')) {
         return;
     }
     // get username and password
     if (isset($_POST['ftpHost'])) {
         $ftpHost = $_POST['ftpHost'];
     } else {
         $ftpHost = 'localhost';
     }
     if (isset($_POST['ftpUser'])) {
         $ftpUser = $_POST['ftpUser'];
     } else {
         $ftpUser = '';
     }
     if (isset($_POST['ftpPassword'])) {
         $ftpPassword = $_POST['ftpPassword'];
     } else {
         $ftpPassword = '';
     }
     $error = false;
     if (!empty($ftpUser)) {
         try {
             // create new ftp connection
             self::$ftpConnection = new FTP($ftpHost);
             self::$ftpConnection->login($ftpUser, $ftpPassword);
             return;
         } catch (SystemException $e) {
             $error = true;
         }
     }
     WCF::getTPL()->assign('ftpPassword', $ftpPassword);
     WCF::getTPL()->assign('ftpUser', $ftpUser);
     WCF::getTPL()->assign('ftpHost', $ftpHost);
     WCF::getTPL()->assign('error', $error);
     WCF::getTPL()->assign('nextStep', 'unzipFiles');
     WCF::getTPL()->display('stepPromptFtp');
     exit;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:45,代码来源:WCFSetup.class.php

示例5: execute

 /**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // header
     $buffer = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
     $buffer .= "<systeminfo xmlns=\"http://www.woltlab.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.woltlab.com/XSD/systeminfo.xsd\">\n";
     // system block
     $buffer .= "\t<system>\n";
     // os block
     $buffer .= "\t\t<os>\n";
     // os type
     $buffer .= "\t\t\t<type><![CDATA[" . StringUtil::escapeCDATA(StringUtil::toLowerCase(PHP_OS)) . "]]></type>\n";
     // try to get os version
     $osVersion = @exec('cat /proc/version');
     // Linux
     if (empty($osVersion)) {
         $osVersion = @exec('uname -a');
     }
     // FreeBSD / Darwin
     if (empty($osVersion)) {
         $osVersion = @exec('ver');
     }
     // Windows
     $buffer .= "\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA($osVersion) . "]]></version>\n";
     $buffer .= "\t\t</os>\n";
     // webserver block
     $buffer .= "\t\t<webserver>\n";
     // webserver type
     $webserver = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
     $webserverType = 'other';
     if (stripos($webserver, 'apache') !== false) {
         $webserverType = 'apache';
     } else {
         if (stripos($webserver, 'iis') !== false) {
             $webserverType = 'iis';
         } else {
             if (stripos($webserver, 'lighttpd') !== false) {
                 $webserverType = 'lighttpd';
             } else {
                 if (stripos($webserver, 'zeus') !== false) {
                     $webserverType = 'zeus';
                 }
             }
         }
     }
     $buffer .= "\t\t\t<type><![CDATA[" . $webserverType . "]]></type>\n";
     // webserver version
     $buffer .= "\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA($webserver) . "]]></version>\n";
     // webserver modules
     $modules = '';
     if (function_exists('apache_get_modules')) {
         $modules = @implode(', ', apache_get_modules());
     }
     $buffer .= "\t\t\t<modules><![CDATA[" . StringUtil::escapeCDATA($modules) . "]]></modules>\n";
     $buffer .= "\t\t</webserver>\n";
     // php block
     $buffer .= "\t\t<php>\n";
     // version
     $buffer .= "\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA(PHP_VERSION) . "]]></version>\n";
     // integration
     $buffer .= "\t\t\t<integration><![CDATA[" . StringUtil::escapeCDATA(php_sapi_name()) . "]]></integration>\n";
     // safe-mode?
     $buffer .= "\t\t\t<safemode><![CDATA[" . FileUtil::getSafeMode() . "]]></safemode>\n";
     // suhosin?
     $buffer .= "\t\t\t<suhosin><![CDATA[" . intval(extension_loaded('suhosin')) . "]]></suhosin>\n";
     // php modules
     $buffer .= "\t\t\t<modules><![CDATA[" . StringUtil::escapeCDATA(implode(', ', get_loaded_extensions())) . "]]></modules>\n";
     $buffer .= "\t\t</php>\n";
     // sql block
     $buffer .= "\t\t<sql>\n";
     // type
     $buffer .= "\t\t\t<type><![CDATA[" . StringUtil::escapeCDATA(str_replace('Database', '', WCF::getDB()->getDBType())) . "]]></type>\n";
     // version
     $buffer .= "\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA(WCF::getDB()->getVersion()) . "]]></version>\n";
     $buffer .= "\t\t</sql>\n";
     $buffer .= "\t</system>\n\n";
     // wcf block
     $buffer .= "\t<wcf>\n";
     $buffer .= "\t\t<packages>\n";
     $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_package\n\t\t\tORDER BY\tpackage";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $buffer .= "\t\t\t<package>\n";
         $buffer .= "\t\t\t\t<name><![CDATA[" . StringUtil::escapeCDATA($row['package']) . "]]></name>\n";
         $buffer .= "\t\t\t\t<version><![CDATA[" . StringUtil::escapeCDATA($row['packageVersion']) . "]]></version>\n";
         $buffer .= "\t\t\t</package>\n";
     }
     $buffer .= "\t\t</packages>\n";
     $buffer .= "\t</wcf>\n";
     $buffer .= "</systeminfo>";
     // output
     header('Content-Type: application/xml; charset=' . CHARSET);
     header('Content-Disposition: attachment; filename="systeminfo.xml"');
     header('Content-Length: ' . strlen($buffer));
     print $buffer;
     $this->executed();
     exit;
//.........这里部分代码省略.........
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:101,代码来源:SystemInformationXMLExportAction.class.php


注:本文中的FileUtil::getSafeMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。