php Piwik-Filesystem类(方法)实例源码

下面列出了php Piwik-Filesystem 类(方法)源码代码实例,从而了解它的用法。

作者:CaptainShar    项目:SSAD_Projec   
private static function deleteIfLastModifiedBefore14August2014($path)
 {
     $modifiedTime = filemtime($path);
     if ($modifiedTime && $modifiedTime < 1408000000) {
         Filesystem::deleteFileIfExists($path);
     }
 }

作者:FluentDevelopmen    项目:piwi   
public function removeGoneFiles($source, $target)
 {
     Filesystem::unlinkTargetFilesNotPresentInSource($source . '/core', $target . '/core');
     foreach ($this->getPluginsFromDirectoy($source) as $pluginDir) {
         Filesystem::unlinkTargetFilesNotPresentInSource($source . $pluginDir, $target . $pluginDir);
     }
 }

作者:brienomatt    项目:elmsl   
/**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return array
  * @throws \RunTimeException
  */
 protected function getPluginName(InputInterface $input, OutputInterface $output)
 {
     $self = $this;
     $validate = function ($pluginName) use($self) {
         if (empty($pluginName)) {
             throw new \RunTimeException('You have to enter a plugin name');
         }
         if (!Filesystem::isValidFilename($pluginName)) {
             throw new \RunTimeException(sprintf('The plugin name %s is not valid', $pluginName));
         }
         $pluginPath = $self->getPluginPath($pluginName);
         if (file_exists($pluginPath)) {
             throw new \RunTimeException('A plugin with this name already exists');
         }
         return $pluginName;
     };
     $pluginName = $input->getOption('name');
     if (empty($pluginName)) {
         $dialog = $this->getHelperSet()->get('dialog');
         $pluginName = $dialog->askAndValidate($output, 'Enter a plugin name: ', $validate);
     } else {
         $validate($pluginName);
     }
     $pluginName = ucfirst($pluginName);
     return $pluginName;
 }

作者:piwi    项目:piwi   
public function dispatch()
 {
     $module = Common::getRequestVar('module', '', 'string');
     $action = Common::getRequestVar('action', '', 'string');
     if ($module == 'CoreUpdater' || $module == 'Proxy' || $module == 'Installation' || $module == 'LanguagesManager' && $action == 'saveLanguage') {
         return;
     }
     $updater = new PiwikCoreUpdater();
     $updates = $updater->getComponentsWithNewVersion(array('core' => Version::VERSION));
     if (!empty($updates)) {
         Filesystem::deleteAllCacheOnUpdate();
     }
     if ($updater->getComponentUpdates() !== null) {
         if (FrontController::shouldRethrowException()) {
             throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n");
         } elseif ($module === 'API') {
             $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $_GET + $_POST));
             $response = new ResponseBuilder($outputFormat);
             $e = new Exception('Database Upgrade Required. Your Piwik database is out-of-date, and must be upgraded before you can continue.');
             echo $response->getResponseException($e);
             Common::sendResponseCode(503);
             exit;
         } else {
             Piwik::redirectToModule('CoreUpdater');
         }
     }
 }

作者:dorelljame    项目:piwi   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $piwikLanguages = \Piwik\Plugins\LanguagesManager\API::getInstance()->getAvailableLanguages();
     $aliasesUrl = 'https://raw.githubusercontent.com/unicode-cldr/cldr-core/master/supplemental/aliases.json';
     $aliasesData = Http::fetchRemoteFile($aliasesUrl);
     $aliasesData = json_decode($aliasesData, true);
     $aliasesData = $aliasesData['supplemental']['metadata']['alias']['languageAlias'];
     $writePath = Filesystem::getPathToPiwikRoot() . '/plugins/Intl/lang/%s.json';
     foreach ($piwikLanguages as $langCode) {
         if ($langCode == 'dev') {
             continue;
         }
         $requestLangCode = $transformedLangCode = $this->transformLangCode($langCode);
         if (array_key_exists($requestLangCode, $aliasesData)) {
             $requestLangCode = $aliasesData[$requestLangCode]['_replacement'];
         }
         // fix some locales
         $localFixes = array('pt' => 'pt-PT', 'pt-br' => 'pt', 'zh-cn' => 'zh-Hans', 'zh-tw' => 'zh-Hant');
         if (array_key_exists($langCode, $localFixes)) {
             $requestLangCode = $localFixes[$langCode];
         }
         setlocale(LC_ALL, $langCode);
         $translations = array();
         $this->fetchLanguageData($output, $transformedLangCode, $requestLangCode, $translations);
         $this->fetchTerritoryData($output, $transformedLangCode, $requestLangCode, $translations);
         $this->fetchCalendarData($output, $transformedLangCode, $requestLangCode, $translations);
         $this->fetchLayoutDirection($output, $transformedLangCode, $requestLangCode, $translations);
         $this->fetchUnitData($output, $transformedLangCode, $requestLangCode, $translations);
         $this->fetchNumberFormattingData($output, $transformedLangCode, $requestLangCode, $translations);
         ksort($translations['Intl']);
         file_put_contents(sprintf($writePath, $langCode), json_encode($translations, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
     }
 }

作者:a4tunad    项目:piwi   
protected function execute(InputInterface $input, OutputInterface $output)
 {
     $commandName = $input->getFirstArgument();
     $enable = false !== strpos($commandName, 'enable');
     $full = $input->getOption('full');
     $config = Config::getInstance();
     $development = $config->Development;
     if ($enable) {
         $development['enabled'] = 1;
         if ($full) {
             $development['disable_merged_assets'] = 1;
         }
         $message = 'Development mode enabled';
     } else {
         $development['enabled'] = 0;
         if ($full) {
             $development['disable_merged_assets'] = 0;
         }
         $message = 'Development mode disabled';
     }
     $config->Development = $development;
     $config->forceSave();
     Filesystem::deleteAllCacheOnUpdate();
     $this->writeSuccessMessage($output, array($message));
 }

作者:bossrabbi    项目:piwi   
static function update()
 {
     $errors = array();
     try {
         $checker = new DoNotTrackHeaderChecker();
         // enable DoNotTrack check in PrivacyManager if DoNotTrack plugin was enabled
         if (\Piwik\Plugin\Manager::getInstance()->isPluginActivated('DoNotTrack')) {
             $checker->activate();
         }
         // enable IP anonymization if AnonymizeIP plugin was enabled
         if (\Piwik\Plugin\Manager::getInstance()->isPluginActivated('AnonymizeIP')) {
             IPAnonymizer::activate();
         }
     } catch (\Exception $ex) {
         // pass
     }
     // disable & delete old plugins
     $oldPlugins = array('DoNotTrack', 'AnonymizeIP');
     foreach ($oldPlugins as $plugin) {
         try {
             \Piwik\Plugin\Manager::getInstance()->deactivatePlugin($plugin);
         } catch (\Exception $e) {
         }
         $dir = PIWIK_INCLUDE_PATH . "/plugins/{$plugin}";
         if (file_exists($dir)) {
             Filesystem::unlinkRecursive($dir, true);
         }
         if (file_exists($dir)) {
             $errors[] = "Please delete this directory manually (eg. using your FTP software): {$dir} \n";
         }
     }
     if (!empty($errors)) {
         throw new \Exception("Warnings during the update: <br>" . implode("<br>", $errors));
     }
 }

作者:jos    项目:CGE-File-Sharin   
static function update()
 {
     Updater::updateDatabase(__FILE__, self::getSql());
     $obsoleteDirectories = array('/plugins/AdminHome', '/plugins/Home', '/plugins/PluginsAdmin');
     foreach ($obsoleteDirectories as $dir) {
         if (file_exists(PIWIK_INCLUDE_PATH . $dir)) {
             Filesystem::unlinkRecursive(PIWIK_INCLUDE_PATH . $dir, true);
         }
     }
 }

作者:FluentDevelopmen    项目:piwi   
public function doUpdate(Updater $updater)
 {
     $updater->executeMigrationQueries(__FILE__, $this->getMigrationQueries($updater));
     $obsoleteDirectories = array('/plugins/AdminHome', '/plugins/Home', '/plugins/PluginsAdmin');
     foreach ($obsoleteDirectories as $dir) {
         if (file_exists(PIWIK_INCLUDE_PATH . $dir)) {
             Filesystem::unlinkRecursive(PIWIK_INCLUDE_PATH . $dir, true);
         }
     }
 }

作者:KiwiJuice    项目:handball-dacha   
private static function loadCoreTranslationFile($language)
 {
     $path = PIWIK_INCLUDE_PATH . '/lang/' . $language . '.json';
     if (!Filesystem::isValidFilename($language) || !is_readable($path)) {
         throw new Exception(Piwik::translate('General_ExceptionLanguageFileNotFound', array($language)));
     }
     $data = file_get_contents($path);
     $translations = json_decode($data, true);
     self::mergeTranslationArray($translations);
     self::setLocale();
     self::$loadedLanguage = $language;
 }

作者:FluentDevelopmen    项目:piwi   
public function delete()
 {
     if ($this->exists()) {
         try {
             Filesystem::remove($this->getAbsoluteLocation());
         } catch (Exception $e) {
             throw new Exception("Unable to delete merged file : " . $this->getAbsoluteLocation() . ". Please delete the file and refresh");
         }
         // try to remove compressed version of the merged file.
         Filesystem::remove($this->getAbsoluteLocation() . ".deflate", true);
         Filesystem::remove($this->getAbsoluteLocation() . ".gz", true);
     }
 }

作者:jos    项目:CGE-File-Sharin   
/**
  * Sends an HTTP request using best available transport method.
  *
  * @param string $aUrl The target URL.
  * @param int $timeout The number of seconds to wait before aborting the HTTP request.
  * @param string|null $userAgent The user agent to use.
  * @param string|null $destinationPath If supplied, the HTTP response will be saved to the file specified by
  *                                     this path.
  * @param int|null $followDepth Internal redirect count. Should always pass `null` for this parameter.
  * @param bool $acceptLanguage The value to use for the `'Accept-Language'` HTTP request header.
  * @param array|bool $byteRange For `Range:` header. Should be two element array of bytes, eg, `array(0, 1024)`
  *                              Doesn't work w/ `fopen` transport method.
  * @param bool $getExtendedInfo If true returns the status code, headers & response, if false just the response.
  * @param string $httpMethod The HTTP method to use. Defaults to `'GET'`.
  * @throws Exception if the response cannot be saved to `$destinationPath`, if the HTTP response cannot be sent,
  *                   if there are more than 5 redirects or if the request times out.
  * @return bool|string If `$destinationPath` is not specified the HTTP response is returned on success. `false`
  *                     is returned on failure.
  *                     If `$getExtendedInfo` is `true` and `$destinationPath` is not specified an array with
  *                     the following information is returned on success:
  *
  *                     - **status**: the HTTP status code
  *                     - **headers**: the HTTP headers
  *                     - **data**: the HTTP response data
  *
  *                     `false` is still returned on failure.
  * @api
  */
 public static function sendHttpRequest($aUrl, $timeout, $userAgent = null, $destinationPath = null, $followDepth = 0, $acceptLanguage = false, $byteRange = false, $getExtendedInfo = false, $httpMethod = 'GET')
 {
     // create output file
     $file = null;
     if ($destinationPath) {
         // Ensure destination directory exists
         Filesystem::mkdir(dirname($destinationPath));
         if (($file = @fopen($destinationPath, 'wb')) === false || !is_resource($file)) {
             throw new Exception('Error while creating the file: ' . $destinationPath);
         }
     }
     $acceptLanguage = $acceptLanguage ? 'Accept-Language: ' . $acceptLanguage : '';
     return self::sendHttpRequestBy(self::getTransportMethod(), $aUrl, $timeout, $userAgent, $destinationPath, $file, $followDepth, $acceptLanguage, $acceptInvalidSslCertificate = false, $byteRange, $getExtendedInfo, $httpMethod);
 }

作者:diosmosi    项目:piwi   
public function execute()
 {
     $label = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsWritable');
     $file = new File(PIWIK_DOCUMENT_ROOT . '/piwik.js');
     if ($file->hasWriteAccess()) {
         return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK, ''));
     }
     $comment = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsNotWritable');
     if (!SettingsServer::isWindows()) {
         $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/piwik.js');
         $command = "<br/><code> chmod +w {$realpath}<br/> chown " . Filechecks::getUserAndGroup() . " " . $realpath . "</code><br />";
         $comment .= $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsMakeWritable', $command);
     }
     return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment));
 }

作者:FluentDevelopmen    项目:piwi   
public function execute()
 {
     $label = $this->translator->translate('Installation_Filesystem');
     if (!Filesystem::checkIfFileSystemIsNFS()) {
         return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK));
     }
     $isPiwikInstalling = !Config::getInstance()->existsLocalConfig();
     if ($isPiwikInstalling) {
         $help = 'Installation_NfsFilesystemWarningSuffixInstall';
     } else {
         $help = 'Installation_NfsFilesystemWarningSuffixAdmin';
     }
     $comment = sprintf('%s<br />%s', $this->translator->translate('Installation_NfsFilesystemWarning'), $this->translator->translate($help));
     return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment));
 }

作者:CaptainShar    项目:SSAD_Projec   
public function dispatch()
 {
     $module = Common::getRequestVar('module', '', 'string');
     $action = Common::getRequestVar('action', '', 'string');
     $updater = new PiwikCoreUpdater();
     $updates = $updater->getComponentsWithNewVersion(array('core' => Version::VERSION));
     if (!empty($updates)) {
         Filesystem::deleteAllCacheOnUpdate();
     }
     if ($updater->getComponentUpdates() !== null && $module != 'CoreUpdater' && $module != 'Proxy' && $module != 'Installation' && !($module == 'LanguagesManager' && $action == 'saveLanguage')) {
         if (FrontController::shouldRethrowException()) {
             throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n");
         } else {
             Piwik::redirectToModule('CoreUpdater');
         }
     }
 }

作者:FluentDevelopmen    项目:piwi   
public function doUpdate(Updater $updater)
 {
     $errors = array();
     // Deleting old libs
     $obsoleteDirectories = array(PIWIK_INCLUDE_PATH . '/libs/Smarty', PIWIK_INCLUDE_PATH . '/libs/Event');
     foreach ($obsoleteDirectories as $dir) {
         if (file_exists($dir)) {
             Filesystem::unlinkRecursive($dir, true);
         }
         if (file_exists($dir)) {
             $errors[] = "Please delete this directory manually (eg. using your FTP software): {$dir} \n";
         }
     }
     if (!empty($errors)) {
         throw new \Exception("Warnings during the update: <br>" . implode("<br>", $errors));
     }
 }

作者:jos    项目:CGE-File-Sharin   
public static function update()
 {
     $errors = array();
     // Deleting old plugins
     $obsoleteDirectories = array(PIWIK_INCLUDE_PATH . '/plugins/Referers', PIWIK_INCLUDE_PATH . '/plugins/PDFReports');
     foreach ($obsoleteDirectories as $dir) {
         if (file_exists($dir)) {
             Filesystem::unlinkRecursive($dir, true);
         }
         if (file_exists($dir)) {
             $errors[] = "Please delete this directory manually (eg. using your FTP software): {$dir} \n";
         }
     }
     if (!empty($errors)) {
         throw new \Exception("Warnings during the update: <br>" . implode("<br>", $errors));
     }
 }

作者:carriercom    项目:piwi   
protected function getPathToLogo($pathOnly, $defaultLogo, $themeLogo, $customLogo)
 {
     $pathToPiwikRoot = Filesystem::getPathToPiwikRoot();
     $logo = $defaultLogo;
     $themeName = \Piwik\Plugin\Manager::getInstance()->getThemeEnabled()->getPluginName();
     $themeLogo = sprintf($themeLogo, $themeName);
     if (file_exists($pathToPiwikRoot . '/' . $themeLogo)) {
         $logo = $themeLogo;
     }
     if ($this->isEnabled() && file_exists($pathToPiwikRoot . '/' . $customLogo)) {
         $logo = $customLogo;
     }
     if (!$pathOnly) {
         return SettingsPiwik::getPiwikUrl() . $logo;
     }
     return $pathToPiwikRoot . '/' . $logo;
 }

作者:KiwiJuice    项目:handball-dacha   
/**
  * Generate Apache .htaccess files to restrict access
  */
 public static function createHtAccessFiles()
 {
     // deny access to these folders
     $directoriesToProtect = array('/config', '/core', '/lang', '/tmp');
     foreach ($directoriesToProtect as $directoryToProtect) {
         Filesystem::createHtAccess(PIWIK_INCLUDE_PATH . $directoryToProtect, $overwrite = true);
     }
     // Allow/Deny lives in different modules depending on the Apache version
     $allow = "<IfModule mod_access.c>\nAllow from all\n</IfModule>\n<IfModule !mod_access_compat>\n<IfModule mod_authz_host.c>\nAllow from all\n</IfModule>\n</IfModule>\n<IfModule mod_access_compat>\nAllow from all\n</IfModule>\n";
     $deny = "<IfModule mod_access.c>\nDeny from all\n</IfModule>\n<IfModule !mod_access_compat>\n<IfModule mod_authz_host.c>\nDeny from all\n</IfModule>\n</IfModule>\n<IfModule mod_access_compat>\nDeny from all\n</IfModule>\n";
     // more selective allow/deny filters
     $allowAny = "<Files \"*\">\n" . $allow . "Satisfy any\n</Files>\n";
     $allowStaticAssets = "<Files ~ \"\\.(test\\.php|gif|ico|jpg|png|svg|js|css|swf)\$\">\n" . $allow . "Satisfy any\n</Files>\n";
     $denyDirectPhp = "<Files ~ \"\\.(php|php4|php5|inc|tpl|in|twig)\$\">\n" . $deny . "</Files>\n";
     $directoriesToProtect = array('/js' => $allowAny, '/libs' => $denyDirectPhp . $allowStaticAssets, '/vendor' => $denyDirectPhp . $allowStaticAssets, '/plugins' => $denyDirectPhp . $allowStaticAssets, '/misc/user' => $denyDirectPhp . $allowStaticAssets);
     foreach ($directoriesToProtect as $directoryToProtect => $content) {
         Filesystem::createHtAccess(PIWIK_INCLUDE_PATH . $directoryToProtect, $overwrite = true, $content);
     }
 }

作者:carriercom    项目:piwi   
static function update()
 {
     $obsoleteFiles = array(PIWIK_INCLUDE_PATH . '/core/Db/Mysqli.php');
     foreach ($obsoleteFiles as $obsoleteFile) {
         if (file_exists($obsoleteFile)) {
             @unlink($obsoleteFile);
         }
     }
     $obsoleteDirectories = array(PIWIK_INCLUDE_PATH . '/core/Db/Pdo');
     foreach ($obsoleteDirectories as $dir) {
         if (file_exists($dir)) {
             Filesystem::unlinkRecursive($dir, true);
         }
     }
     // force regeneration of cache files
     Piwik::setUserHasSuperUserAccess();
     $allSiteIds = API::getInstance()->getAllSitesId();
     Cache::regenerateCacheWebsiteAttributes($allSiteIds);
 }


问题


面经


文章

微信
公众号

扫码关注公众号