本文整理汇总了PHP中AEUtilFilesystem类的典型用法代码示例。如果您正苦于以下问题:PHP AEUtilFilesystem类的具体用法?PHP AEUtilFilesystem怎么用?PHP AEUtilFilesystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AEUtilFilesystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
public function import($file)
{
$directory = $this->getState('directory', '');
$directory = AEUtilFilesystem::translateStockDirs($directory);
// Find out how many parts there are
$multipart = 0;
$base = substr($file, 0, -4);
$ext = substr($file, -3);
$found = true;
$total_size = @filesize($directory . '/' . $file);
while ($found) {
$multipart++;
$newExtension = substr($ext, 0, 1) . sprintf('%02u', $multipart);
$newFile = $directory . '/' . $base . '.' . $newExtension;
$found = file_exists($newFile);
if ($found) {
$total_size += @filesize($newFile);
}
}
$filetime = @filemtime($directory . '/' . $file);
if (empty($filetime)) {
$filetime = time();
}
// Create a new backup record
$record = array('description' => JText::_('DISCOVER_LABEL_IMPORTEDDESCRIPTION'), 'comment' => '', 'backupstart' => date('Y-m-d H:i:s', $filetime), 'backupend' => date('Y-m-d H:i:s', $filetime + 1), 'status' => 'complete', 'origin' => 'backend', 'type' => 'full', 'profile_id' => 1, 'archivename' => $file, 'absolute_path' => $directory . '/' . $file, 'multipart' => $multipart, 'tag' => 'backend', 'filesexist' => 1, 'remote_filename' => '', 'total_size' => $total_size);
$id = null;
$id = AEPlatform::getInstance()->set_or_update_statistics($id, $record, $this);
}
示例2: __construct
public function __construct()
{
$this->object = 'dir';
$this->subtype = 'inclusion';
$this->method = 'direct';
// FIXME This filter doesn't work very well on many live hosts. Disabled for now.
parent::__construct();
return;
if (empty($this->filter_name)) {
$this->filter_name = strtolower(basename(__FILE__, '.php'));
}
// Get the saved library path and compare it to the default
$jlibdir = AEPlatform::getInstance()->get_platform_configuration_option('jlibrariesdir', '');
if (empty($jlibdir)) {
if (defined('JPATH_LIBRARIES')) {
$jlibdir = JPATH_LIBRARIES;
} elseif (defined('JPATH_PLATFORM')) {
$jlibdir = JPATH_PLATFORM;
} else {
$jlibdir = false;
}
}
if ($jlibdir !== false) {
$jlibdir = AEUtilFilesystem::TranslateWinPath($jlibdir);
$defaultLibraries = AEUtilFilesystem::TranslateWinPath(JPATH_SITE . '/libraries');
if ($defaultLibraries != $jlibdir) {
// The path differs, add it here
$this->filter_data['JPATH_LIBRARIES'] = $jlibdir;
}
} else {
$this->filter_data = array();
}
parent::__construct();
}
示例3: apply
/**
* Handle the apply task which saves settings and shows the editor again
*
*/
public function apply()
{
// CSRF prevention
if (!JRequest::getVar(JUtility::getToken(), false, 'POST')) {
JError::raiseError('403', JText::_(version_compare(JVERSION, '1.6.0', 'ge') ? 'JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN' : 'Request Forbidden'));
}
// Get the var array from the request
$var = JRequest::getVar('var', array(), 'default', 'array');
// Make it into Akeeba Engine array format
$data = array();
foreach ($var as $key => $value) {
$data[$key] = $value;
}
// Forbid stupidly selecting the site's root as the output or temporary directory
if (array_key_exists('akeeba.basic.output_directory', $data)) {
$folder = $data['akeeba.basic.output_directory'];
$folder = AEUtilFilesystem::translateStockDirs($folder, true, true);
$check = AEUtilFilesystem::translateStockDirs('[SITEROOT]', true, true);
if ($check == $folder) {
JError::raiseWarning(503, JText::_('CONFIG_OUTDIR_ROOT'));
$data['akeeba.basic.output_directory'] = '[DEFAULT_OUTPUT]';
}
}
// Merge it
$config = AEFactory::getConfiguration();
$config->mergeArray($data, false, false);
// Save configuration
AEPlatform::getInstance()->save_configuration();
$this->setRedirect(JURI::base() . 'index.php?option=' . JRequest::getCmd('option') . '&view=config', JText::_('CONFIG_SAVE_OK'));
}
示例4: unregisterAndDeleteTempFile
/**
* Unregister and delete a temporary file
* @param $fileName The filename to unregister and delte
* @param $removePrefix The prefix to remove
*/
static function unregisterAndDeleteTempFile( $fileName, $removePrefix = false )
{
$configuration =& AEFactory::getConfiguration();
if($removePrefix)
{
$fileName = str_replace( AEUtilFilesystem::TranslateWinPath($configuration->get('akeeba.basic.temporary_directory')) , '', $fileName);
if( (substr($fileName, 0, 1) == '/') || (substr($fileName, 0, 1) == '\\') )
{
$fileName = substr($fileName, 1 );
}
if( (substr($fileName, -1) == '/') || (substr($fileName, -1) == '\\') )
{
$fileName = substr($fileName, 0, -1 );
}
}
// We don't unregister the tempfile here, because on some systems (Windows &
// servers on FastCGI) the files wouldn't get deleted.
$file = $configuration->get('akeeba.basic.temporary_directory').DS.$fileName;
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "-- Removing temporary file $fileName" );
$platform = strtoupper(PHP_OS);
if( (substr($platform,0,6) == 'CYGWIN') || (substr($platform,0,3) == 'WIN') )
{
// On Windows we have to chwon() the file first to make it owned by Nobody
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "-- Windows hack: chowning $fileName" );
@chown($file, 600);
}
return @self::nullifyAndDelete($file);
}
示例5: scanFolder
protected function scanFolder($folder, &$position, $forFolders = true, $threshold_key = 'dir', $threshold_default = 50)
{
$registry = AEFactory::getConfiguration();
// Initialize variables
$arr = array();
$false = false;
if (!is_dir($folder) && !is_dir($folder . '/')) {
return $false;
}
try {
$di = new DirectoryIterator($folder);
} catch (Exception $e) {
$this->setWarning('Unreadable directory ' . $folder);
return $false;
}
if (!$di->valid()) {
$this->setWarning('Unreadable directory ' . $folder);
return $false;
}
if (!empty($position)) {
$di->seek($position);
if ($di->key() != $position) {
$position = null;
return $arr;
}
}
$counter = 0;
$maxCounter = $registry->get("engine.scan.large.{$threshold_key}_threshold", $threshold_default);
while ($di->valid()) {
if ($di->isDot()) {
$di->next();
continue;
}
if ($di->isDir() != $forFolders) {
$di->next();
continue;
}
$ds = $folder == '' || $folder == '/' || @substr($folder, -1) == '/' || @substr($folder, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
$dir = $folder . $ds . $di->getFilename();
$data = _AKEEBA_IS_WINDOWS ? AEUtilFilesystem::TranslateWinPath($dir) : $dir;
if ($data) {
$counter++;
$arr[] = $data;
}
if ($counter == $maxCounter) {
break;
} else {
$di->next();
}
}
// Determine the new value for the position
$di->next();
if ($di->valid()) {
$position = $di->key() - 1;
} else {
$position = null;
}
return $arr;
}
示例6: get_site_path
private function get_site_path()
{
// FIX 1.1.0 $mosConfig_absolute_path may contain trailing slashes or backslashes incompatible with exclusion filters
// FIX 1.2.2 Some hosts yield an empty string on realpath(JPATH_SITE)
// FIX 2.2 On Windows, realpath might fail
// FIX 2.4: Make an assumption (wild guess...)
if( (JPATH_BASE == '/administrator') || (JPATH_ROOT == '') )
{
$this->setWarning("Your site's root is an empty string. I am trying a workaround.");
$jpath_site_real = '/';
}
else
{
// Fix 2.4: Make sure that $jpath_site_real contains something even if realpath fails
$jpath_site_real = @realpath(trim(JPATH_SITE));
$jpath_site_real = ($jpath_site_real === false) ? trim(JPATH_SITE) : $jpath_site_real;
$jpath_site_real = AEUtilFilesystem::TranslateWinPath($jpath_site_real);
}
if( $jpath_site_real == '' )
{
// The JPATH_SITE is resolved to an empty string; attempt a workaround
// Windows hosts
if(DIRECTORY_SEPARATOR == '\\')
{
if( (trim(JPATH_SITE) != '') && (trim(JPATH_SITE) != '\\') && (trim(JPATH_SITE) != '/'))
{
$this->setWarning("The site's root couldn't be normalized on a Windows host. Attempting workaround (filters might not work)");
$jpath_site_real = JPATH_SITE; // Forcibly use the configured JPATH_SITE
}
else
{
$this->setWarning("The normalized path to your site's root seems to be an empty string; I will attempt a workaround (Windows host)");
$jpath_site_real = '/'; // Start scanning from filesystem root (workaround mode)
}
}
// *NIX hosts
else
{
$this->setWarning("The normalized path to your site's root seems to be an empty string; I will attempt a workaround (*NIX host)");
# Fix 2.1 Since JPATH_SITE is an empty string, shouldn't I begin scanning from the FS root, for crying out loud? What was I thinking putting JPATH_SITE there?
$jpath_site_real = '/'; // Start scanning from filesystem root (workaround mode)
}
}
// Fix 2.4.b1 : Add the trailing slash
if( (substr($jpath_site_real,-1) != '/') && !empty($jpath_site_real) )
{
$jpath_site_real .= '/';
}
return $jpath_site_real;
}
示例7: processPart
public function processPart($absolute_filename, $upload_as = null)
{
// Retrieve engine configuration data
$config = AEFactory::getConfiguration();
$account = trim($config->get('engine.postproc.azure.account', ''));
$key = trim($config->get('engine.postproc.azure.key', ''));
$container = $config->get('engine.postproc.azure.container', 0);
$directory = $config->get('volatile.postproc.directory', null);
if (empty($directory)) {
$directory = $config->get('engine.postproc.azure.directory', 0);
}
// Sanity checks
if (empty($account)) {
$this->setWarning('You have not set up your Windows Azure account name');
return false;
}
if (empty($key)) {
$this->setWarning('You have not set up your Windows Azure key');
return false;
}
if (empty($container)) {
$this->setWarning('You have not set up your Windows Azure container');
return false;
}
// Fix the directory name, if required
if (!empty($directory)) {
$directory = trim($directory);
$directory = ltrim(AEUtilFilesystem::TranslateWinPath($directory), '/');
} else {
$directory = '';
}
// Parse tags
$directory = AEUtilFilesystem::replace_archive_name_variables($directory);
$config->set('volatile.postproc.directory', $directory);
// Calculate relative remote filename
$filename = basename($absolute_filename);
if (!empty($directory) && $directory != '/') {
$filename = $directory . '/' . $filename;
}
// Store the absolute remote path in the class property
$this->remote_path = $filename;
// Connect and send
try {
$blob = new AEUtilAzure(AEUtilAzureStorage::URL_CLOUD_BLOB, $account, $key);
$policyNone = new AEUtilAzureNoRetryPolicy();
$blob->setRetryPolicy($policyNone);
$blob->putBlob($container, $filename, $absolute_filename);
} catch (Exception $e) {
$this->setWarning($e->getMessage());
return false;
}
return true;
}
示例8: treatDirectory
private static function treatDirectory($directory)
{
$site_root = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath(JPATH_ROOT));
$directory = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath($directory));
// Trim site root from beginning of directory
if (substr($directory, 0, strlen($site_root)) == $site_root) {
$directory = substr($directory, strlen($site_root));
if (substr($directory, 0, 1) == '/') {
$directory = substr($directory, 1);
}
}
return $directory;
}
示例9: unregisterAndDeleteTempFile
/**
* Unregister and delete a temporary file
* @param $fileName The filename to unregister and delte
* @param $removePrefix The prefix to remove
*/
static function unregisterAndDeleteTempFile($fileName, $removePrefix = false)
{
$configuration = AEFactory::getConfiguration();
if ($removePrefix) {
$fileName = str_replace(AEUtilFilesystem::TranslateWinPath($configuration->get('akeeba.basic.output_directory')), '', $fileName);
if (substr($fileName, 0, 1) == '/' || substr($fileName, 0, 1) == '\\') {
$fileName = substr($fileName, 1);
}
if (substr($fileName, -1) == '/' || substr($fileName, -1) == '\\') {
$fileName = substr($fileName, 0, -1);
}
}
// Make sure this file is registered
$configuration = AEFactory::getConfiguration();
$tempFiles = $configuration->get('volatile.tempfiles', false);
if ($tempFiles === false) {
$tempFiles = array();
} else {
$tempFiles = @unserialize($tempFiles);
}
$found = false;
if (!empty($tempFiles)) {
$found = in_array($fileName, $tempFiles);
}
if (!$found) {
return false;
}
$file = $configuration->get('akeeba.basic.output_directory') . '/' . $fileName;
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "-- Removing temporary file {$fileName}");
$platform = strtoupper(PHP_OS);
if (substr($platform, 0, 6) == 'CYGWIN' || substr($platform, 0, 3) == 'WIN') {
// On Windows we have to chwon() the file first to make it owned by Nobody
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "-- Windows hack: chowning {$fileName}");
@chown($file, 600);
}
$result = @self::nullifyAndDelete($file);
// Make sure the file is removed before unregistering it
if (!@file_exists($file)) {
$aPos = array_search($fileName, $tempFiles);
if ($aPos !== false) {
unset($tempFiles[$aPos]);
$configuration->set('volatile.tempfiles', serialize($tempFiles));
}
}
return $result;
}
示例10: saveEngineConfig
public function saveEngineConfig()
{
$data = $this->getState('engineconfig', array());
// Forbid stupidly selecting the site's root as the output or temporary directory
if (array_key_exists('akeeba.basic.output_directory', $data)) {
$folder = $data['akeeba.basic.output_directory'];
$folder = AEUtilFilesystem::translateStockDirs($folder, true, true);
$check = AEUtilFilesystem::translateStockDirs('[SITEROOT]', true, true);
if ($check == $folder) {
JError::raiseWarning(503, JText::_('CONFIG_OUTDIR_ROOT'));
$data['akeeba.basic.output_directory'] = '[DEFAULT_OUTPUT]';
}
}
// Merge it
$config = AEFactory::getConfiguration();
$config->mergeArray($data, false, false);
// Save configuration
AEPlatform::getInstance()->save_configuration();
}
示例11: treatDirectory
private static function treatDirectory($directory)
{
// Get the site's root
$configuration = AEFactory::getConfiguration();
if ($configuration->get('akeeba.platform.override_root', 0)) {
$root = $configuration->get('akeeba.platform.newroot', '[SITEROOT]');
if (stristr($root, '[')) {
$root = AEUtilFilesystem::translateStockDirs($root);
}
$site_root = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath($root));
} else {
$site_root = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath(JPATH_ROOT));
}
$directory = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath($directory));
// Trim site root from beginning of directory
if (substr($directory, 0, strlen($site_root)) == $site_root) {
$directory = substr($directory, strlen($site_root));
if (substr($directory, 0, 1) == '/') {
$directory = substr($directory, 1);
}
}
return $directory;
}
示例12: display
function display()
{
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.path');
// Get the folder to browse
$folder = JRequest::getString('folder', '');
$processfolder = JRequest::getInt('processfolder', 0);
if (empty($folder)) {
$folder = '';
$folder_raw = '';
$isFolderThere = false;
$isInRoot = false;
$isOpenbasedirRestricted = false;
} else {
$stock_dirs = AEPlatform::getInstance()->get_stock_directories();
arsort($stock_dirs);
if ($processfolder == 1) {
foreach ($stock_dirs as $find => $replace) {
$folder = str_replace($find, $replace, $folder);
}
}
// Normalise name, but only if realpath() really, REALLY works...
$old_folder = $folder;
$folder = @realpath($folder);
if ($folder === false) {
$folder = $old_folder;
}
if (AEUtilFilesystem::folderExists($folder)) {
$isFolderThere = true;
} else {
$isFolderThere = false;
}
JRequest::setVar('folder', $folder);
// Check if it's a subdirectory of the site's root
$isInRoot = strpos($folder, JPATH_SITE) === 0;
// Check open_basedir restrictions
$isOpenbasedirRestricted = AEUtilQuirks::checkOpenBasedirs($folder);
// -- Get the meta form of the directory name, if applicable
$folder_raw = $folder;
foreach ($stock_dirs as $replace => $find) {
$folder_raw = str_replace($find, $replace, $folder_raw);
}
}
// Writable check and contents listing if it's in site root and not restricted
if ($isFolderThere && !$isOpenbasedirRestricted) {
// Get writability status
$isWritable = is_writable($folder);
// Get contained folders
$subfolders = JFolder::folders($folder);
} else {
if ($isFolderThere && !$isOpenbasedirRestricted) {
$isWritable = is_writable($folder);
} else {
$isWritable = false;
}
$subfolders = array();
}
// Get parent directory
$pathparts = explode(DIRECTORY_SEPARATOR, $folder);
if (is_array($pathparts)) {
$path = '';
foreach ($pathparts as $part) {
$path .= empty($path) ? $part : DIRECTORY_SEPARATOR . $part;
if (empty($part)) {
if (DIRECTORY_SEPARATOR != '\\') {
$path = DIRECTORY_SEPARATOR;
}
$part = DIRECTORY_SEPARATOR;
}
$crumb['label'] = $part;
$crumb['folder'] = $path;
$breadcrumbs[] = $crumb;
}
$junk = array_pop($pathparts);
$parent = implode(DIRECTORY_SEPARATOR, $pathparts);
} else {
// Can't identify parent dir, use ourselves.
$parent = $folder;
$breadcrumbs = array();
}
$this->assign('folder', $folder);
$this->assign('folder_raw', $folder_raw);
$this->assign('parent', $parent);
$this->assign('exists', $isFolderThere);
$this->assign('inRoot', $isInRoot);
$this->assign('openbasedirRestricted', $isOpenbasedirRestricted);
$this->assign('writable', $isWritable);
$this->assign('subfolders', $subfolders);
$this->assign('breadcrumbs', $breadcrumbs);
parent::display();
}
示例13: mail_administrators
/**
* Sends an email to the administrators
*
* @return bool
*/
private function mail_administrators()
{
$this->setStep('Processing emails to administrators');
$this->setSubstep('');
// Skip email for back-end backups
if (AEPlatform::getInstance()->get_backup_origin() == 'backend') {
return true;
}
$must_email = AEPlatform::getInstance()->get_platform_configuration_option('frontend_email_on_finish', 0) != 0;
if (!$must_email) {
return true;
}
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Preparing to send e-mail to administrators");
$email = AEPlatform::getInstance()->get_platform_configuration_option('frontend_email_address', '');
$email = trim($email);
if (!empty($email)) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Using pre-defined list of emails");
$emails = explode(',', $email);
} else {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Fetching list of Super Administrator emails");
$emails = AEPlatform::getInstance()->get_administrator_emails();
}
if (!empty($emails)) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Creating email subject and body");
// Fetch user's preferences
$subject = trim(AEPlatform::getInstance()->get_platform_configuration_option('frontend_email_subject', ''));
$body = trim(AEPlatform::getInstance()->get_platform_configuration_option('frontend_email_body', ''));
// Get the statistics
$statistics = AEFactory::getStatistics();
$stat = $statistics->getRecord();
$parts = AEUtilStatistics::get_all_filenames($stat, false);
$profile_number = AEPlatform::getInstance()->get_active_profile();
$profile_name = AEPlatform::getInstance()->get_profile_name($profile_number);
$parts = AEUtilStatistics::get_all_filenames($stat, false);
$stat = (object) $stat;
$num_parts = $stat->multipart;
// Non-split archives have a part count of 0
if ($num_parts == 0) {
$num_parts = 1;
}
$parts_list = '';
if (!empty($parts)) {
foreach ($parts as $file) {
$parts_list .= "\t" . basename($file) . "\n";
}
}
// Get the remote storage status
$remote_status = '';
$post_proc_engine = AEFactory::getConfiguration()->get('akeeba.advanced.proc_engine');
if (!empty($post_proc_engine) && $post_proc_engine != 'none') {
if (empty($stat->remote_filename)) {
$remote_status = AEPlatform::getInstance()->translate('COM_AKEEBA_EMAIL_POSTPROCESSING_FAILED');
} else {
$remote_status = AEPlatform::getInstance()->translate('COM_AKEEBA_EMAIL_POSTPROCESSING_SUCCESS');
}
}
// Do we need a default subject?
if (empty($subject)) {
// Get the default subject
$subject = AEPlatform::getInstance()->translate('EMAIL_SUBJECT_OK');
} else {
// Post-process the subject
$subject = AEUtilFilesystem::replace_archive_name_variables($subject);
}
// Do we need a default body?
if (empty($body)) {
$body = AEPlatform::getInstance()->translate('EMAIL_BODY_OK');
$info_source = AEPlatform::getInstance()->translate('EMAIL_BODY_INFO');
$body .= "\n\n" . sprintf($info_source, $profile_number, $num_parts) . "\n\n";
$body .= $parts_list;
} else {
// Post-process the body
$body = AEUtilFilesystem::replace_archive_name_variables($body);
$body = str_replace('[PROFILENUMBER]', $profile_number, $body);
$body = str_replace('[PROFILENAME]', $profile_name, $body);
$body = str_replace('[PARTCOUNT]', $num_parts, $body);
$body = str_replace('[FILELIST]', $parts_list, $body);
$body = str_replace('[REMOTESTATUS]', $remote_status, $body);
}
// Sometimes $body contains literal \n instead of newlines
$body = str_replace('\\n', "\n", $body);
foreach ($emails as $email) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sending email to {$email}");
AEPlatform::getInstance()->send_email($email, $subject, $body);
}
} else {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "No email recipients found! Skipping email.");
}
return true;
}
示例14: logName
/**
* Calculates the absolute path to the log file. Instead of using the path coming from
* Akeeba Backup config, we will always use Joomla Tmp dir
*
* @param string $tag The backup run's tag
*
* @return string The absolute path to the log file
*/
public static function logName($tag = null)
{
if (empty($tag)) {
$fileName = 'akeeba.log';
} else {
$fileName = "akeeba.{$tag}.log";
}
// Get log's file name
return AEUtilFilesystem::TranslateWinPath(JPATH_ROOT . '/tmp' . DIRECTORY_SEPARATOR . $fileName);
}
示例15: q203
/**
* Q203 - MED - Default output directory in use
*
* @return bool
*/
private static function q203()
{
$stock_dirs = AEPlatform::getInstance()->get_stock_directories();
$registry =& AEFactory::getConfiguration();
$outdir = $registry->get('akeeba.basic.output_directory');
foreach ($stock_dirs as $macro => $replacement) {
$outdir = str_replace($macro, $replacement, $outdir);
}
$default = $stock_dirs['[DEFAULT_OUTPUT]'];
$outdir = AEUtilFilesystem::TranslateWinPath($outdir);
$default = AEUtilFilesystem::TranslateWinPath($default);
return $outdir == $default;
}