function jaucGetDataFolder($path) { $FileSystemHelper = new FileSystemHelper(); $path = $FileSystemHelper->clean($path . '/'); $rootPath = $FileSystemHelper->clean($_SERVER['DOCUMENT_ROOT']); return strpos($path, $rootPath) === 0 ? $path : JPATH_ROOT . '/' . $path; }
/** * restore * * @param (string) $backupFile * @return unknown */ function restore($backupFile) { $FileSystemHelper = new FileSystemHelper(); $backupFile = $FileSystemHelper->clean($backupFile); if (!JFile::exists($backupFile)) { return false; } //create temp file with replaced #__ by db prefix $tmpDir = $FileSystemHelper->tmpDir(null, 'ja', 0755); $tmpFile = $tmpDir . basename($backupFile); $sql = file_get_contents($backupFile); $sql = preg_replace('/\\`\\#__([a-zA-Z_0-9]*)\\`/', "`" . $this->_prefix . "\$1`", $sql); JFile::write($tmpFile, $sql); //echo $tmpFile; $command = sprintf("%s -u%s %s %s < %s", $this->_mysqlPath, $this->_user, $this->_pass, $this->_db, $tmpFile); //echo $command; return $this->_exec($command, $this->_pass); }
/** * Deletes paths from the current path * * @param string $listFolder The image directory to delete a file from * @since 1.5 */ function delete() { global $mainframe; JRequest::checkToken('request') or jexit('Invalid Token'); // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); // Get some data from the request $tmpl = JRequest::getCmd('tmpl'); $paths = JRequest::getVar('rm', array(), '', 'array'); $folder = JRequest::getVar('folder', '', '', 'path'); // Initialize variables $msg = array(); $ret = true; if (count($paths)) { foreach ($paths as $path) { if ($path !== JFile::makeSafe($path)) { JError::raiseWarning(100, JText::_('Unable to delete:') . htmlspecialchars($path, ENT_COMPAT, 'UTF-8') . ' ' . JText::_('WARNDIRNAME')); continue; } $fullPath = JPath::clean(JA_WORKING_DATA_FOLDER . DS . $folder . DS . $path); if (is_file($fullPath)) { $ret |= !JFile::delete($fullPath); } else { if (is_dir($fullPath)) { $files = JFolder::files($fullPath, '.', true); $canDelete = true; foreach ($files as $file) { if ($file != 'index.html') { $canDelete = false; } } if ($canDelete) { $ret |= !JFolder::delete($fullPath); } else { //allow remove folder not empty on local repository $ret2 = FileSystemHelper::rm($fullPath, true); $ret |= $ret2; if ($ret2 == false) { JError::raiseWarning(100, JText::_('Unable to delete:') . $fullPath); } } } } } } if ($tmpl == 'component') { // We are inside the iframe $mainframe->redirect('index.php?option=' . JACOMPONENT . '&view=repolist&folder=' . $folder . '&tmpl=component'); } else { $mainframe->redirect('index.php?option=' . JACOMPONENT . '&view=repolist&folder=' . $folder); } }
public static function GetRecentlyModified($root, $path = "") { $aryDirs = FileSystemHelper::GetAllDirectories($root, $path); $aryPages = array(); foreach ($aryDirs as $d) { if (Page::isPage($d)) { $aryPages[$d] = filemtime(getXMLPath($d)); } } arSort($aryPages, SORT_NUMERIC); return $aryPages; }
function getDirectoryDataFromCache($cacheFilePath) { $directories = array(); $files = array(); if (is_file($cacheFilePath)) { $xml = new \SimpleXMLElement(file_get_contents($cacheFilePath)); $files = FileSystemHelper::pullImagesFromXML($xml); $directories = FileSystemHelper::pullFoldersFromXML($xml); } $output['file'] = $files; $output['dir'] = $directories; return $output; }
public function deleteDisableModules() { $modules = array_keys(Yii::app()->getModules()); $module_path = Yii::getPathOfAlias('application.modules'); foreach (scandir($module_path) as $module_dir) { if ($module_dir[0] == ".") { continue; } if (!in_array($module_dir, $modules)) { FileSystemHelper::deleteDirRecursive($module_path . DS . $module_dir); } } }
/** * Generates PDF preview image and saves it. * @param string $pdfFilePath full path to pdf file. * @param string $destImagePath full path of image file that must be saved. * @throws InvalidParamException if cannot write file. */ public static function savePreview($pdfFilePath, $destImagePath) { $decodedDestImagePath = FileSystemHelper::decodeFilename($destImagePath); if ($decodedDestImagePath === false) { $extension = null; } else { $extension = FileSystemHelper::extension($decodedDestImagePath); $extension = FileSystemHelper::encodeFilename($extension); } $content = static::getPreview($pdfFilePath, $extension); if (false === @file_put_contents($destImagePath, $content)) { throw new InvalidParamException("Cannot save file: {$destImagePath}"); } }
private function loadVars() { //Directories $dir = array(); $this->vars['current_directory'] = ''; //We listen to query strings to deduce the folder the user is going for // forinstance: nickwalker.us/photos?hello would mean they want to look into the folder /photos/hello $this->vars['current_directory'] = normalizePath($_SERVER['QUERY_STRING']); $this->vars['gallery_url'] = dirname($_SERVER['REQUEST_URI']); $this->vars['current_folder_name'] = $this->getDirectoryName($this->vars['current_directory']); $this->vars['description'] = FileSystemHelper::getFolderDescription($this->photosPathFromRoot . $this->vars['current_directory']); // Populates $this->vars['file_list'] and $this->vars['folder_list'] $this->loadDirectoryInformation($this->photosPathFromRoot . $this->vars['current_directory']); //var_dump($this->vars); }
public static function getRecentlyModified($below, $maxrows = null, $contentType = "", $dateEnd = null) { if ($dateEnd == null) { $dateEnd = localtime(); } $aryFiles = FileSystemHelper::getRecentlyModified($below); $aryPages = array(); foreach ($aryFiles as $p => $d) { if ($maxrows == null || count($aryFiles) < $maxrows) { $objPage = new Page($p); if ($contentType == "" || $objPage->getContentType() == $contentType) { $aryPages[] = $objPage; } } } return $aryPages; }
/** * restore * * @param (string) $backupFile * @return unknown */ function restore($backupFile) { $backupFile = FileSystemHelper::clean($backupFile); if (!is_file($backupFile)) { return false; } //create temp file with replaced #__ by db prefix $tmpDir = FileSystemHelper::tmpDir(null, 'ja', 0777); $tmpFile = $tmpDir . basename($backupFile); $sql = file_get_contents($backupFile); $sql = preg_replace('/\\`\\#__([a-zA-Z_0-9]*)\\`/', "`" . $this->_prefix . "\$1`", $sql); $fp = fopen($tmpFile, 'wb'); fwrite($fp, $sql); fclose($fp); //echo $tmpFile; $command = sprintf("%s -u%s %s %s < %s", $this->_mysqlPath, $this->_user, $this->_pass, $this->_db, $tmpFile); //echo $command; return $this->_exec($command, $this->_pass); }
public function beforeDelete($event) { $model = $this->getOwner(); if (method_exists($model, "uploadFiles")) { $files = $model->uploadFiles(); foreach ($files as $attr => $params) { if (!$model->{$attr}) { continue; } $dir = $params["dir"]; if (substr($dir, 0, strlen($_SERVER['DOCUMENT_ROOT'])) != $_SERVER['DOCUMENT_ROOT']) { $dir = $_SERVER['DOCUMENT_ROOT'] . $dir; } if (substr($dir, -1) != '/') { $dir .= '/'; } FileSystemHelper::deleteFileWithSimilarNames($dir, $model->{$attr}); } } }
private function _save($options) { $model = ActiveRecord::model($options['model'])->findByPk($options['id']); //may be you will be need set some attributes before update if (isset($options['attributes'])) { $model->attributes = $options['attributes']; } $attribute = $options['attribute']; $model->{$attribute} = $options['value']; if ($model->saveAttributes(array($attribute))) { if (isset($options['unlink_file'])) { $file = Yii::getPathOfAlias('webroot') . '/' . $options['unlink_file']; if (is_file($file) && FileSystemHelper::isAllowForUnlink($file)) { FileSystemHelper::deleteFileWithSimilarNames(pathinfo($file, PATHINFO_DIRNAME), pathinfo($file, PATHINFO_BASENAME)); } } echo $model->{$attribute}; } else { echo $model->getError($attribute); } }
/** * Return a set of the CRC depends on path is file or directory * * @param $path string path of the directory to be dump crc * @param $ignore array list of ignore pattern * * @return Object */ function dumpCRCObject($path, $ignore = null) { $FileSystemHelper = new FileSystemHelper(); $path = $FileSystemHelper->clean($path); if ($this->isIgnore(basename($path), $ignore)) { return false; } if (JFile::exists($path)) { return $this->getCheckSum($path); } if (!JFolder::exists($path)) { return false; } $ignore = empty($ignore) ? $this->ignorePattern : $ignore; $dirCheckSum = new stdClass(); $fileCheckSum = new stdClass(); $d = dir($path); $entries = $this->_scanDir($path, 0); foreach ($entries as $entry) { if (!$this->isIgnore($entry, $ignore)) { if (JFolder::exists($path . '/' . $entry)) { $fileCheckSum->{$entry} = $this->dumpCRCObject($path . '/' . $entry, $ignore); } else { $fileCheckSum->{$entry} = $this->getCheckSum($path . '/' . $entry); } } } $dirCheckSum->files = $fileCheckSum; return $fileCheckSum; }
/** * Save file content after compare files and resolve conflict. * * When upgrading extentions, some files are maybe in conflicted status (edited by both user (file in user' site) and developer (file in new version)). * So after upgrading extension to new version, User will can user comparing tool to compare versions of conflicted files, resolve conflicted, * then they can save its content. * */ function saveFile() { $side = JRequest::getVar('side', ''); $side = strtolower($side); $backUrl = JRequest::getVar('backUrl', $this->getLink()); $sameContent = JRequest::getInt('sameContent', 0); $message = ""; if (count($_POST) && ($side == 'left' || $side == 'right')) { $sideUpper = ucfirst($side); $file = $_POST['file' . $sideUpper]; $file = FileSystemHelper::clean($file); $otherSide = $side == 'left' ? 'right' : 'left'; $otherSideUpper = ucfirst($otherSide); $otherSideEditabled = JRequest::getInt("editabled" . $otherSideUpper, 0); $fileOther = $_POST['file' . $otherSideUpper]; if (!$otherSideEditabled && $sameContent && JFile::exists($fileOther)) { //if compared side is not editabled //and two sides is the same content //therefore, content of this side is the same with original content of compared side $copyBinary = true; } if (JFile::exists($file)) { if ($copyBinary) { JFile::copy($fileOther, $file); } elseif (isset($_POST['src' . $sideUpper])) { $src = html_entity_decode($_POST['src' . $sideUpper]); JFile::write($file, $src); } $message = JText::sprintf("SUCCESS_WROTE_TO_FILE_S", $file); } else { $message = JText::_("CONTENT_IS_NOT_WROTE_BECAUSE_MISSING_SOME_INFORMATION"); } } $this->setRedirect($backUrl, $message); }
function getLocalConflictBasePath($product) { $FileSystemHelper = new FileSystemHelper(); $path = $this->getLocalBasePath($product) . "backup/"; if (!JFolder::exists($path)) { if (!$FileSystemHelper->createDirRecursive($path, 0755)) { return false; } } return $path; }
private function _buildUpgradePackage($src, $dst, $objectFilter) { if (is_dir($src)) { if (!is_dir($dst)) { mkdir($dst, 0777, true); } $dir = opendir($src); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($src . DS . $file)) { if (isset($objectFilter->{$file})) { $this->_buildUpgradePackage($src . DS . $file, $dst . DS . $file, $objectFilter->{$file}); } } else { if (isset($objectFilter->{$file}) && in_array($objectFilter->{$file}, array('new', 'updated'))) { copy($src . DS . $file, $dst . DS . $file); } } } } closedir($dir); } elseif (is_file($src)) { $file = basename($src); if (is_dir($dst)) { $dst = FileSystemHelper::clean($dst . DS) . basename($file); } if (isset($objectFilter->{$file}) && in_array($objectFilter->{$file}, array('new', 'updated'))) { copy($src, $dst); } } }
<!-- @@name: Latest Items --> <?php $root = getPath(""); $path = $PAGE->path; $paths = FileSystemHelper::GetRecentlyModified($root, $path); ?> <?php $i = 0; $numMaxItems = 10; ?> <div class="container"> <h2>Latest Items</h2> <?php foreach ($paths as $path => $date) { ?> <?php $child = new Page($path); ?> <?php if ($i < $numMaxItems) { ?> <h3><a href="<?php echo $child->getURL();
function saveFile() { $side = JRequest::getVar('side', ''); $side = strtolower($side); $backUrl = JRequest::getVar('backUrl', $this->getLink()); $sameContent = JRequest::getInt('sameContent', 0); $message = ""; if (count($_POST) && ($side == 'left' || $side == 'right')) { $sideUpper = ucfirst($side); $file = $_POST['file' . $sideUpper]; $file = FileSystemHelper::clean($file); $otherSide = $side == 'left' ? 'right' : 'left'; $otherSideUpper = ucfirst($otherSide); $otherSideEditabled = JRequest::getInt("editabled" . $otherSideUpper, 0); $fileOther = $_POST['file' . $otherSideUpper]; if (!$otherSideEditabled && $sameContent && is_file($fileOther)) { //if compared side is not editabled //and two sides is the same content //therefore, content of this side is the same with original content of compared side $copyBinary = true; } if (is_file($file)) { if ($copyBinary) { JFile::copy($fileOther, $file); } elseif (isset($_POST['src' . $sideUpper])) { $fp = fopen($file, 'wb'); $src = html_entity_decode($_POST['src' . $sideUpper]); fwrite($fp, $src); fclose($fp); } $message = JText::sprintf("Success, wrote to file (%s)", $file); } else { $message = JText::_("Content is not wrote because missing some information"); } /*echo "<pre>"; print_r($_POST); echo "</pre>"; die();*/ } $this->setRedirect($backUrl, $message); }
function jaucGetDataFolder($path) { $path = FileSystemHelper::clean($path . DS); $rootPath = FileSystemHelper::clean($_SERVER['DOCUMENT_ROOT']); return strpos($path, $rootPath) === 0 ? $path : JPATH_ROOT . DS . $path; }
/** * getting list of files in given folder with specific filter * * @param string $path * @param string $filter - regular expression patter (PCRE style) * @param mixed $recurse - True to recursively search into sub-folders, or an integer to specify the maximum depth. * @param boolean $fullpath - True to return the full path to the file. * @param boolean $exclude - Array with names of files and folder which should not be shown in the result. * @return array Files in the given folder. */ function files($path, $filter = '.', $recurse = false, $fullpath = false, $exclude = array('.svn', 'CVS')) { // Initialize variables $arr = array(); // Check to make sure the path valid and clean $path = FileSystemHelper::clean($path); // Is the path a folder? if (!JFolder::exists($path)) { return false; } // read the source directory $handle = opendir($path); while (($file = readdir($handle)) !== false) { if ($file != '.' && $file != '..' && !in_array($file, $exclude)) { $dir = $path . DS . $file; $isDir = JFolder::exists($dir); if ($isDir) { if ($recurse) { if (is_integer($recurse)) { $arr2 = FileSystemHelper::files($dir, $filter, $recurse - 1, $fullpath); } else { $arr2 = FileSystemHelper::files($dir, $filter, $recurse, $fullpath); } $arr = array_merge($arr, $arr2); } } else { if (preg_match("/{$filter}/", $file)) { if ($fullpath) { $arr[] = $path . DS . $file; } else { $arr[] = $file; } } } } } closedir($handle); asort($arr); return $arr; }
/** * get path to specific file of extensions * */ function getFilePath($file) { $location = $this->getLocation(); $FileSystemHelper = new FileSystemHelper(); if ($location === false) { return false; } if ($this->type == 'component') { if (substr($file, 0, strlen('site')) == 'site') { //file on front-end if (isset($location['site'])) { $file = preg_replace("/^site\\//", "", $file); $file = $location['site'] . $file; } } else { //file on back-end if (isset($location['admin'])) { $file = preg_replace("/^admin\\//", "", $file); $file = $location['admin'] . $file; } } } else { foreach ($location as $path) { if (JFile::exists($path)) { if (basename($path) == basename($file)) { $file = $path; break; } } else { $fileTmp = $FileSystemHelper->clean($path . $file); if (JFile::exists($fileTmp)) { $file = $fileTmp; break; } else { //exception case (with plugin) $path2 = dirname($path) . '/'; $fileTmp2 = $FileSystemHelper->clean($path2 . $file); if (JFile::exists($fileTmp2)) { $file = $fileTmp2; break; } } } } } return $FileSystemHelper->clean($file); }
public static function delete($page) { // set page order $objPage = new Page($page); $objOrder = new PageOrder(listDeleteAt($page, listLen($page, "/"), "/")); $objOrder->delete($objPage->getName()); $objOrder->save(); // delete page FileSystemHelper::delTree(getPath($page)); }
function getResults() { $result = ""; if (count($this->results) > 0) { $result .= "\n\t\t\t<table class=\"ja-uc-child\">\n\t\t <tr>\n\t\t <th width=\"30\"> </th>\n\t\t <th width=\"150\">" . JText::_("EXTENSION_NAME") . "</th>\n\t\t <th>" . JText::_("TYPE") . "</th>\n\t\t <th>" . JText::_("VERSION") . "</th>\n\t\t <th>" . JText::_("RESULT") . "</th>\n\t\t </tr>"; foreach ($this->results as $item) { $error = intval($item['error']); $ext = $item['ext']; if (!$error) { $css = "upload-success"; $relLocation = substr($item['location'], strlen(JA_WORKING_DATA_FOLDER)); $relLocation = FileSystemHelper::clean($relLocation, "/"); $url = "index.php?option=com_jaextmanager&view=repo&folder={$relLocation}"; $linkRepo = " <a href=\"{$url}\" onclick=\"opener.location='{$url}'; return false;\" target=\"_parent\" title=\"" . addslashes($item['location']) . "\">" . JText::_("REPOSITORY") . "</a>"; $message = JText::sprintf('THE_S_S__VESION_S_IS_SUCCESSFULLY_UPLOADED_TO_LOCAL_REPOSITORY', $ext->type, $ext->name, $ext->version); $message .= JText::sprintf('GO_TO_S_TO_SEE_THE_UPLOADED_FILES_OF_THIS_EXTENSIONSSMALL', $linkRepo); } else { $css = "upload-error"; $message = $item["message"]; } $result .= "\n\t\t\t <tr class=\"" . $css . "\">\n\t\t\t <td class=\"icon\"> </td>\n\t\t\t <td><span title=\"" . $ext->extKey . "\">" . $ext->name . "</span></td>\n\t\t\t <td>" . $ext->type . "</td>\n\t\t\t <td>" . $ext->version . "</td>\n\t\t\t <td>" . $message . "</td>\n\t\t\t </tr>"; } $result .= "</table>"; } return $result; }
function getLocalConflictBasePath($product) { $path = $this->getLocalBasePath($product) . "backup" . DS; if (!is_dir($path)) { if (!FileSystemHelper::createDirRecursive($path, 0777)) { return false; } } return $path; }
/** * get path to specific file of extensions * */ function getFilePath($file) { $location = $this->getLocation(); if ($this->type == 'component') { if (substr($file, 0, strlen('site')) == 'site') { //file on front-end $file = preg_replace("/^site\\//", "", $file); $file = $location['site'] . $file; } else { //file on back-end $file = preg_replace("/^admin\\//", "", $file); $file = $location['admin'] . $file; } } else { foreach ($location as $path) { if (is_file($path)) { if (basename($path) == basename($file)) { $file = $path; break; } } else { $fileTmp = FileSystemHelper::clean($path . $file); if (is_file($fileTmp)) { $file = $fileTmp; break; } else { //exception case (with plugin) $path2 = dirname($path) . DS; $fileTmp2 = FileSystemHelper::clean($path2 . $file); if (is_file($fileTmp2)) { $file = $fileTmp2; break; } } } } } return FileSystemHelper::clean($file); }
function getResults() { $result = ""; if (count($this->results) > 0) { $result .= "\n\t\t\t<table class=\"ja-uc-child\">\n\t\t <tr>\n\t\t <th width=\"30\"> </th>\n\t\t <th width=\"150\">" . JText::_("Extension Name") . "</th>\n\t\t <th>" . JText::_("Type") . "</th>\n\t\t <th>" . JText::_("Version") . "</th>\n\t\t <th>" . JText::_("Result") . "</th>\n\t\t </tr>"; foreach ($this->results as $item) { $error = intval($item['error']); $ext = $item['ext']; if (!$error) { $css = "upload-success"; $relLocation = substr($item['location'], strlen(JA_WORKING_DATA_FOLDER)); $relLocation = FileSystemHelper::clean($relLocation, "/"); $url = "index.php?option=com_jaextmanager&view=repo&folder={$relLocation}"; $linkRepo = " <a href=\"{$url}\" onclick=\"opener.location='{$url}'; return false;\" target=\"_parent\" title=\"" . addslashes($item['location']) . "\">" . JText::_("Repository") . "</a>"; $message = JText::sprintf('The %s "%s - vesion %s" is successfully uploaded to local repository.', $ext->type, $ext->name, $ext->version); $message .= JText::sprintf('<br /><small>Go to "%s" to see the uploaded files of this extensions.</small></td>', $linkRepo); } else { $css = "upload-error"; $message = $item["message"]; } $result .= "\n\t\t\t <tr class=\"" . $css . "\">\n\t\t\t <td class=\"icon\"> </td>\n\t\t\t <td><span title=\"" . $ext->extKey . "\">" . $ext->name . "</span></td>\n\t\t\t <td>" . $ext->type . "</td>\n\t\t\t <td>" . $ext->version . "</td>\n\t\t\t <td>" . $message . "</td>\n\t\t\t </tr>"; } $result .= "</table>"; } return $result; }