-
Notifications
You must be signed in to change notification settings - Fork 55
/
output.php
81 lines (70 loc) · 2.45 KB
/
output.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* @version SEBLOD 3.x Core ~ $Id: output.php sebastienheraud $
* @package SEBLOD (App Builder & CCK) // SEBLOD nano (Form Builder)
* @url https://www.seblod.com
* @editor Octopoos - www.octopoos.com
* @copyright Copyright (C) 2009 - 2018 SEBLOD. All Rights Reserved.
* @license GNU General Public License version 2 or later; see _LICENSE.php
**/
defined( '_JEXEC' ) or die;
jimport( 'joomla.filesystem.file' );
jimport( 'joomla.filesystem.folder' );
// CommonHelper
class CommonHelper_Output
{
// init
public static function init( $name, $extension, $params )
{
// Init
$name_date = $params->get( 'filename_date', '' );
$tmp_path = JFactory::getConfig()->get( 'tmp_path' );
$tmp_dir = uniqid( 'cck_' );
// Set
$output = new stdClass;
$output->name = $name;
$output->suffix = ( $name_date != '' ) ? '_'.JFactory::getDate()->format( $name_date ) : '';
$output->path = $tmp_path.'/'.$tmp_dir;
$output->root = $output->path.'/'.$extension;
$output->output = $params->get( 'output', 0 );
$output->output_path = $params->get( 'output_path', '' );
$output->compression = $params->get( 'compression', 'zip' );
if ( $output->output == 2 && $output->output_path != '' && JFolder::exists( $output->output_path ) ) {
$output->output_path = $output->output_path;
} elseif ( $output->output_path != '' && $output->output_path != 'tmp/' ) {
$output->output_path = JPATH_SITE.'/'.$output->output_path;
if ( !JFolder::exists( $output->output_path ) ) {
jimport( 'cck.base.install.export' );
CCK_Export::createDir( $output->output_path );
}
} else {
$output->output_path = $tmp_path;
}
return $output;
}
// finalize
public static function finalize( $output )
{
if ( $output->compression == 'zip' ) {
require_once JPATH_ADMINISTRATOR.'/components/com_cck/helpers/pclzip/pclzip.lib.php';
$tmp = $output->path.'/'.$output->name.'.zip';
$archive = new PclZip( $tmp );
if ( $archive->create( $output->root, PCLZIP_OPT_REMOVE_PATH, $output->root ) == 0 ) {
return false;
}
$ext = '.zip';
} else {
$ext = '.'.$extension;
}
if ( JFile::exists( $tmp ) ) {
$file = $output->output_path.'/'.$output->name.$output->suffix.$ext;
JFile::move( $tmp, $file );
if ( JFolder::exists( $output->path ) ) {
JFolder::delete( $output->path );
}
return $file;
}
return false;
}
}
?>