Exemple #1
0
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;
}
Exemple #2
0
 /**
  * restore
  *
  * @param (string) $backupFile
  * @return unknown
  */
 function restore($backupFile)
 {
     $backupFile = FileSystemHelper::clean($backupFile);
     if (!JFile::exists($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);
     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);
 }
 /**
  * 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);
 }
Exemple #4
0
 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;
 }
Exemple #5
0
 /**
  * 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;
 }
Exemple #6
0
 /**
  * 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);
 }
Exemple #7
0
 function _buildUpgradePackage($src, $dst, $objectFilter)
 {
     $FileSystemHelper = new FileSystemHelper();
     $src = $FileSystemHelper->clean($src);
     $dst = $FileSystemHelper->clean($dst);
     if (JFolder::exists($src)) {
         if (!JFolder::exists($dst)) {
             JFolder::create($dst, 0755);
         }
         $dir = opendir($src);
         while (false !== ($file = readdir($dir))) {
             if ($file != '.' && $file != '..') {
                 if (JFolder::exists($src . '/' . $file)) {
                     if (isset($objectFilter->{$file})) {
                         $this->_buildUpgradePackage($src . '/' . $file, $dst . '/' . $file, $objectFilter->{$file});
                     }
                 } else {
                     if (isset($objectFilter->{$file}) && in_array($objectFilter->{$file}, array('new', 'updated'))) {
                         JFile::copy($src . '/' . $file, $dst . '/' . $file);
                     }
                 }
             }
         }
         closedir($dir);
     } elseif (JFile::exists($src)) {
         $file = basename($src);
         if (JFolder::exists($dst)) {
             $dst = $FileSystemHelper->clean($dst . '/' . $file);
         }
         if (isset($objectFilter->{$file}) && in_array($objectFilter->{$file}, array('new', 'updated'))) {
             JFile::copy($src, $dst);
         }
     }
 }
 /**
  * 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;
 }
Exemple #9
0
 /**
  * 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);
 }
Exemple #10
0
 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;
 }
 function _buildUpgradePackage($src, $dst, $objectFilter)
 {
     $src = FileSystemHelper::clean($src);
     $dst = FileSystemHelper::clean($dst);
     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 . $file);
         }
         if (isset($objectFilter->{$file}) && in_array($objectFilter->{$file}, array('new', 'updated'))) {
             copy($src, $dst);
         }
     }
 }
Exemple #12
0
function jaucGetDataFolder($path)
{
    $path = FileSystemHelper::clean($path . DS);
    $rootPath = FileSystemHelper::clean($_SERVER['DOCUMENT_ROOT']);
    return strpos($path, $rootPath) === 0 ? $path : JPATH_ROOT . DS . $path;
}
Exemple #13
0
 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);
 }