本文整理汇总了PHP中JArchive类的典型用法代码示例。如果您正苦于以下问题:PHP JArchive类的具体用法?PHP JArchive怎么用?PHP JArchive使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JArchive类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preflight
/**
* method to run before an install/update/uninstall method
*
* @return void
*/
public function preflight($type, $parent)
{
// $parent is the class calling this method
//$parent->getParent()->setRedirectURL('index.php?option=com_ckeditor');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.installer.installer');
$installer = JInstaller::getInstance();
$source = $installer->getPath('source');
$packages = $source . DS . 'packages';
// Get editor package
if (is_dir($packages)) {
$editor = JFolder::files($packages, 'plg_ckeditor.zip', false, true);
}
if (!empty($editor) && is_file($editor[0])) {
$confObject = JFactory::getApplication();
$packagePath = dirname($editor[0]) . DS . 'ckeditor';
if (!JArchive::extract($editor[0], $packagePath)) {
$editor_result = JText::_('EDITOR EXTRACT ERROR');
} else {
$installer = JInstaller::getInstance();
$c_manifest = $installer->getManifest();
$c_root =& $c_manifest->document;
if (JFolder::copy($packagePath, dirname($installer->getPath('extension_site')) . DS . '..' . DS . 'plugins' . DS . 'editors', '', true)) {
$editor_result = JText::_('Success');
} else {
$editor_result = JText::_('Error');
}
}
} else {
$editor_result = JText::_('Error');
}
echo '<p>' . $editor_result . '</p>';
}
示例2: doExecute
/**
* Entry point for CLI script
*
* @return void
*
* @since 3.0
*/
public function doExecute()
{
ini_set("max_execution_time", 300);
jimport('joomla.filesystem.archive');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
$config = JFactory::getConfig();
$username = $config->get('user');
$password = $config->get('password');
$database = $config->get('db');
echo 'Exporting database...
';
exec("mysqldump --user={$username} --password={$password} --quick --add-drop-table --add-locks --extended-insert --lock-tables --all {$database} > " . JPATH_SITE . "/database-backup.sql");
$zipFilesArray = array();
$dirs = JFolder::folders(JPATH_SITE, '.', true, true);
array_push($dirs, JPATH_SITE);
echo 'Collecting files...
';
foreach ($dirs as $dir) {
$files = JFolder::files($dir, '.', false, true);
foreach ($files as $file) {
$data = JFile::read($file);
$zipFilesArray[] = array('name' => str_replace(JPATH_SITE . '/', '', $file), 'data' => $data);
}
}
$zip = JArchive::getAdapter('zip');
echo 'Creating zip...
';
$archive = JPATH_SITE . '/backups/' . date('Ymd') . '-backup.zip';
$zip->create($archive, $zipFilesArray);
echo 'Backup created ' . $archive . '
';
}
示例3: installApplicationFromUserfile
/**
* Installs an Application from a user upload.
*
* @param array $userfile The userfile to install from
* @return int 2 = update, 1 = install
*
* @throws InstallHelperException
* @since 2.0
*/
public function installApplicationFromUserfile($userfile)
{
// Make sure that file uploads are enabled in php
if (!(bool) ini_get('file_uploads')) {
throw new InstallHelperException('Fileuploads are not enabled in php.');
}
// If there is no uploaded file, we have a problem...
if (!is_array($userfile)) {
throw new InstallHelperException('No file selected.');
}
// Check if there was a problem uploading the file.
if ($userfile['error'] || $userfile['size'] < 1) {
throw new InstallHelperException('Upload error occured.');
}
// Temporary folder to extract the archive into
$tmp_directory = $this->app->path->path('tmp:') . '/';
$archivename = $tmp_directory . $userfile['name'];
if (!JFile::upload($userfile['tmp_name'], $archivename)) {
throw new InstallHelperException("Could not move uploaded file to ({$archivename})");
}
// Clean the paths to use for archive extraction
$extractdir = $tmp_directory . uniqid('install_');
jimport('joomla.filesystem.archive');
// do the unpacking of the archive
if (!JArchive::extract($archivename, $extractdir)) {
throw new InstallHelperException("Could not extract zip file to ({$tmp_directory})");
}
return $this->installApplicationFromFolder($extractdir);
}
示例4: readContentElementFile
/**
* Read content files
*
* @return void
*
* @throws Exception
*/
public function readContentElementFile()
{
NenoLog::log('Method readContentElementFile of NenoControllerGroupsElements called', 3);
jimport('joomla.filesystem.file');
NenoLog::log('Trying to move content element files', 3);
$input = JFactory::getApplication()->input;
$fileData = $input->files->get('content_element');
$destFile = JFactory::getConfig()->get('tmp_path') . '/' . $fileData['name'];
$extractPath = JFactory::getConfig()->get('tmp_path') . '/' . JFile::stripExt($fileData['name']);
// If the file has been moved successfully, let's work with it.
if (JFile::move($fileData['tmp_name'], $destFile) === true) {
NenoLog::log('Content element files moved successfully', 2);
// If the file is a zip file, let's extract it
if ($fileData['type'] == 'application/zip') {
NenoLog::log('Extracting zip content element files', 3);
$adapter = JArchive::getAdapter('zip');
$adapter->extract($destFile, $extractPath);
$contentElementFiles = JFolder::files($extractPath);
} else {
$contentElementFiles = array($destFile);
}
// Add to each content file the path of the extraction location.
NenoHelper::concatenateStringToStringArray($extractPath . '/', $contentElementFiles);
NenoLog::log('Parsing element files for readContentElementFile', 3);
// Parse element file(s)
NenoHelperBackend::parseContentElementFile(JFile::stripExt($fileData['name']), $contentElementFiles);
NenoLog::log('Cleaning temporal folder for readContentElementFile', 3);
// Clean temporal folder
NenoHelperBackend::cleanFolder(JFactory::getConfig()->get('tmp_path'));
}
NenoLog::log('Redirecting to groupselements view', 3);
$this->setRedirect('index.php?option=com_neno&view=groupselements')->redirect();
}
示例5: getbackup
function getbackup()
{
global $mainframe;
if (!JFile::exists(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup' . DS . 'backup.php')) {
JError::raiseWarning(304, 'Backup file doesn\'t exist!');
$mainframe->redirect('index.php?option=com_yos_resources_manager&view=version');
return false;
}
$version = JRequest::getCmd('version');
require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup' . DS . 'backup.php';
if (!JFile::exists($urlbackup)) {
JError::raiseWarning(400, 'File backup doesn\'t exist!');
$mainframe->redirect('index.php?option=com_yos_resources_manager&view=version');
return false;
}
// do the unpacking of the archive
$extractdir = JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup' . DS . uniqid($version . '_');
$archivename = $urlbackup;
JFolder::create($extractdir);
$result = JArchive::extract($archivename, $extractdir);
// Get Instance
$autoupdate = new AutoupdateHelper($extractdir . DS . 'update.xml', false, true, false, $extractdir);
$autoupdate->upgradeFile();
$autoupdate->cleanFileUpdate();
$mainframe->redirect('index.php?option=com_yos_resources_manager&view=version', $autoupdate->getReport());
}
示例6: upload
/**
* Support Zip files for image galleries
* @see TiendaFile::upload()
*/
function upload()
{
if ($result = parent::upload()) {
// Check if it's a supported archive
$allowed_archives = array('zip', 'tar', 'tgz', 'gz', 'gzip', 'tbz2', 'bz2', 'bzip2');
if (in_array(strtolower($this->getExtension()), $allowed_archives)) {
$dir = $this->getDirectory();
jimport('joomla.filesystem.archive');
JArchive::extract($this->full_path, $dir);
JFile::delete($this->full_path);
$this->is_archive = true;
$files = JFolder::files($dir);
// Thumbnails support
if (count($files)) {
// Name correction
foreach ($files as &$file) {
$file = new TiendaImage($dir . '/' . $file);
}
$this->archive_files = $files;
$this->physicalname = $files[0]->getPhysicalname();
}
}
}
return $result;
}
示例7: install
public function install()
{
// Request forgeries check
JRequest::checkToken() or die('Invalid Token');
$file = JRequest::getVar('rule', '', 'FILES');
$app = JFactory::getApplication();
$files = array();
// @task: If there's no tmp_name in the $file, we assume that the data sent is corrupted.
if (!isset($file['tmp_name'])) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
// There are various MIME type for compressed file. So let's check the file extension instead.
if ($file['name'] && JFile::getExt($file['name']) == 'xml') {
$files = array($file['tmp_name']);
} else {
$jConfig = DiscussHelper::getJConfig();
$path = rtrim($jConfig->get('tmp_path'), '/') . '/' . $file['name'];
// @rule: Copy zip file to temporary location
if (!JFile::copy($file['tmp_name'], $path)) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
jimport('joomla.filesystem.archive');
$tmp = md5(DiscussHelper::getDate()->toMysQL());
$dest = rtrim($jConfig->get('tmp_path'), '/') . '/' . $tmp;
if (!JArchive::extract($path, $dest)) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
$files = JFolder::files($dest, '.', true, true);
if (empty($files)) {
// Try to do a level deeper in case the zip is on the outer.
$folder = JFolder::folders($dest);
if (!empty($folder)) {
$files = JFolder::files($dest . '/' . $folder[0], true);
$dest = $dest . '/' . $folder[0];
}
}
if (empty($files)) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_RULE_FILE'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
}
if (empty($files)) {
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_RULE_INSTALL_FAILED'), DISCUSS_QUEUE_ERROR);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
foreach ($files as $file) {
$this->installXML($file);
}
DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_RULE_INSTALL_SUCCESS'), DISCUSS_QUEUE_SUCCESS);
$app->redirect('index.php?option=com_easydiscuss&view=rules&layout=install');
$app->close();
}
示例8: civicrm_setup
function civicrm_setup()
{
global $adminPath, $compileDir;
$adminPath = JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_civicrm';
$jConfig = JFactory::getConfig();
set_time_limit(4000);
// Path to the archive
$archivename = $adminPath . DIRECTORY_SEPARATOR . 'civicrm.zip';
// a bit of support for the non-alternaive joomla install
if (file_exists($archivename)) {
// ensure that the site has native zip, else abort
if (!function_exists('zip_open') || !function_exists('zip_read')) {
echo "Your PHP version is missing zip functionality. Please ask your system administrator / hosting provider to recompile PHP with zip support.<p>";
echo "If this is a new install, you will need to uninstall CiviCRM from the Joomla Extension Manager.<p>";
exit;
}
$extractdir = $adminPath;
JArchive::extract($archivename, $extractdir);
}
$scratchDir = JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'civicrm';
if (!is_dir($scratchDir)) {
JFolder::create($scratchDir, 0777);
}
$compileDir = $scratchDir . DIRECTORY_SEPARATOR . 'templates_c';
if (!is_dir($compileDir)) {
JFolder::create($compileDir, 0777);
}
$db = JFactory::getDBO();
$db->setQuery(' SELECT count( * )
FROM information_schema.tables
WHERE table_name LIKE "civicrm_domain"
AND table_schema = "' . $jConfig->getValue('config.db') . '" ');
global $civicrmUpgrade;
$civicrmUpgrade = $db->loadResult() == 0 ? FALSE : TRUE;
}
示例9: packageUnzip
function packageUnzip($file, $target)
{
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.archive');
jimport('joomla.filesystem.path');
$extract1 =& JArchive::getAdapter('zip');
$result = @$extract1->extract($file, $target);
if ($result != true) {
require_once PATH_ROOT . DS . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclzip.lib.php';
require_once PATH_ROOT . DS . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclerror.lib.php';
if (substr(PHP_OS, 0, 3) == 'WIN') {
if (!defined('OS_WINDOWS')) {
define('OS_WINDOWS', 1);
}
} else {
if (!defined('OS_WINDOWS')) {
define('OS_WINDOWS', 0);
}
}
$extract2 = new PclZip($file);
$result = @$extract2->extract(PCLZIP_OPT_PATH, $target);
}
unset($extract1, $extract2);
return $result;
}
示例10: _extract
function _extract($package, $target)
{
// First extract files
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.archive');
jimport('joomla.filesystem.path');
$adapter =& JArchive::getAdapter('zip');
$result = $adapter->extract($package, $target);
if (!is_dir($target)) {
require_once PATH_ROOT . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclzip.lib.php';
require_once PATH_ROOT . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclerror.lib.php';
$extract = new PclZip($package);
if (substr(PHP_OS, 0, 3) == 'WIN') {
if (!defined('OS_WINDOWS')) {
define('OS_WINDOWS', 1);
}
} else {
if (!defined('OS_WINDOWS')) {
define('OS_WINDOWS', 0);
}
}
$result = $extract->extract(PCLZIP_OPT_PATH, $target);
}
return $result;
}
示例11: extract
public function extract()
{
$session = JFactory::getSession();
$target = $session->get('target', '', 'liveupdate');
$tempdir = $session->get('tempdir', '', 'liveupdate');
jimport('joomla.filesystem.archive');
return JArchive::extract($target, $tempdir);
}
示例12: download
public function download()
{
$app = JFactory::getApplication();
/** @var $app JApplicationAdministrator */
$type = $this->input->get->getCmd('type');
$model = $this->getModel();
try {
switch ($type) {
case 'locations':
$output = $model->getLocations();
$fileName = 'locations.xml';
break;
case 'countries':
$output = $model->getCountries();
$fileName = 'countries.xml';
break;
case 'states':
$output = $model->getStates();
$fileName = 'states.xml';
break;
default:
// Error
$output = '';
$fileName = 'error.xml';
break;
}
} catch (Exception $e) {
JLog::add($e->getMessage());
throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM'));
}
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.path');
jimport('joomla.filesystem.archive');
$tmpFolder = JPath::clean($app->get('tmp_path'));
$date = new JDate();
$date = $date->format('d_m_Y_H_i_s');
$archiveName = JFile::stripExt(basename($fileName)) . '_' . $date;
$archiveFile = $archiveName . '.zip';
$destination = $tmpFolder . DIRECTORY_SEPARATOR . $archiveFile;
// compression type
$zipAdapter = JArchive::getAdapter('zip');
$filesToZip[] = array('name' => $fileName, 'data' => $output);
$zipAdapter->create($destination, $filesToZip, array());
$filesize = filesize($destination);
JFactory::getApplication()->setHeader('Content-Type', 'application/octet-stream', true);
JFactory::getApplication()->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
JFactory::getApplication()->setHeader('Content-Transfer-Encoding', 'binary', true);
JFactory::getApplication()->setHeader('Pragma', 'no-cache', true);
JFactory::getApplication()->setHeader('Expires', '0', true);
JFactory::getApplication()->setHeader('Content-Disposition', 'attachment; filename=' . $archiveFile, true);
JFactory::getApplication()->setHeader('Content-Length', $filesize, true);
$doc = JFactory::getDocument();
$doc->setMimeEncoding('application/octet-stream');
$app->sendHeaders();
echo file_get_contents($destination);
$app->close();
}
示例13: process
function process()
{
$this->installDir = JPATH_SITE . '/media/' . uniqid('rsinstall_');
$adapter = JArchive::getAdapter('zip');
if (!$adapter->extract($this->archive, $this->installDir)) {
return false;
}
return true;
}
示例14: install
function install()
{
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.archive');
$tmp = JPATH_ROOT . '/tmp/kinstall/';
$dest = KPATH_SITE . '/template/';
$file = JRequest::getVar('install_package', NULL, 'FILES', 'array');
if (!JRequest::checkToken()) {
$this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
$this->app->redirect(KunenaRoute::_($this->baseurl, false));
}
if (!$file || !is_uploaded_file($file['tmp_name'])) {
$this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_MISSING', $file['name']), 'notice');
} else {
$success = JFile::upload($file['tmp_name'], $tmp . $file['name']);
$success = JArchive::extract($tmp . $file['name'], $tmp);
if (!$success) {
$this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_FAILED', $file['name']), 'notice');
}
// Delete the tmp install directory
if (JFolder::exists($tmp)) {
$templates = KunenaTemplateHelper::parseXmlFiles($tmp);
if (!empty($templates)) {
foreach ($templates as $template) {
// Never overwrite default template
if ($template->directory == 'default') {
continue;
}
if (is_dir($dest . $template->directory)) {
if (is_file($dest . $template->directory . '/params.ini')) {
if (is_file($tmp . $template->directory . '/params.ini')) {
JFile::delete($tmp . $template->directory . '/params.ini');
}
JFile::move($dest . $template->directory . '/params.ini', $tmp . $template->directory . '/params.ini');
}
JFolder::delete($dest . $template->directory);
}
$error = JFolder::move($tmp . $template->directory, $dest . $template->directory);
if ($error !== true) {
$this->app->enqueueMessage(JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE') . ': ' . $error, 'notice');
}
}
$retval = JFolder::delete($tmp);
$this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_SUCCESS', $file['name']));
} else {
JError::raiseWarning(100, JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE_MISSING_FILE'));
$retval = false;
}
} else {
JError::raiseWarning(100, JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE') . ' ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_UNINSTALL') . ': ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_DIR_NOT_EXIST'));
$retval = false;
}
}
$this->app->redirect(KunenaRoute::_($this->baseurl, false));
}
示例15: extract
/**
* Extract ZIP-file
*
* @param string $path The ZIP-file
* @param string $dest The destination
*
* @return boolean True on success, false otherwise
*/
public static function extract($path, $dest = '')
{
if (!JFile::exists($path) || JFile::getExt($path) != "zip") {
return false;
}
if ($dest = '') {
$dest = JFile::stripExt($files);
}
return JArchive::getAdapter('zip')->extract($path, $dest);
}