'com_name',
'comcomname' => 'com_com_name',
'version' => 'com_version',
'lang_admin' => 'dir_lang_admin',
'lang_site' => 'dir_lang_site',
'installxml'=>'installxml',
'description' => 'description',
'ebc_author' => 'author',
'authoremail' => 'authoremail',
'authorurl' => 'authorurl',
'license' => 'license',
'copyright' => 'copyright'
, 'creationdate' => 'creationDate'
);
private $_credit_vars = array();
private $_langs = array();
private $_copys = array();
private $_menu = array();
private $_submenu = array();
private $_scope = '';
private $_entryFile = '';
private $_f_date = '';
private $_download_link = '';
private $downloadLinks = array();
private $_steps = array();
private $_log = array();
private $_buildopts = array();
private $_profiler = null;
private $logger = null;
private $project;
public $_errors = array();
/**
* Constructor
*
* @access public
* @return void
*/
public function __construct()
{
jimport('joomla.filesystem.file');
}// function
/**
* Create the package
*
* @param unknown_type $project
*
* @return bool true on success
*/
public function create($project)
{
$this->project = $project;
$this->base = JPATH_SITE;
$this->build_dir = substr(JPATH_COMPONENT, strlen(JPATH_SITE) + 1 ).DS.'builds';
$this->setDate(date("ymd_Hi"));
//--Init buildopts
$buildopts = JRequest::getVar('buildopts',array());
$this->initBuildOpts($buildopts);
//--Setup logging
JLoader::import('helpers.logger', JPATH_COMPONENT);
$logName = date('ymd_Hi').'_packing.log';
$this->logger = new easyLogger($logName, $buildopts);
$this->logger->log( 'STARTING at:
'.$this->base.'
Build dir:
'.$this->build_dir);
$this->setTempDir();
$this->copyCopys();
$this->copyLanguage();
$this->copyPackageElements();
//--Deleting 'old' manifest..
$this->deleteManifest();
if( ! $this->_createManifest($project) )
{
$this->_errors[] = 'unable to create manifest';
return false;
}
$this->createZip();
$this->removeBuildDir();
$this->logger->log('FINISHED');
$this->logger->writeLog();
return true;
}// function
private function initBuildOpts( $buildopts )
{
$this->_buildopts['verbose'] =( in_array('verbose', $buildopts) ) ? true : false;
$this->_buildopts['files'] =( in_array('files', $buildopts) ) ? true : false;
$this->_buildopts['archive_zip'] =( in_array('archive_zip', $buildopts) ) ? true : false;
$this->_buildopts['archive_tgz'] =( in_array('archive_tgz', $buildopts) ) ? true : false;
$this->_buildopts['archive_bz'] =( in_array('archive_bz', $buildopts) ) ? true : false;
//--Init profiler
$this->_buildopts['profiling'] = false;
if( in_array('profile', $buildopts) )
{
jimport('joomla.error.profiler');
$this->_profiler =& JProfiler::getInstance( 'EasyZipper' );
$this->_buildopts['profiling'] = true;
}
}//function
/**
* Tries to find the package manifest file
*
* @access private
* @return boolean True on success, False on error
* @since 1.0
*/
function deleteManifest()
{
// Get an array of all the xml files from teh installation directory
$xmlfiles = JFolder::files($this->_temp_dir, '.xml$', 1, true);
// If at least one xml file exists
if (!empty($xmlfiles))
{
foreach ($xmlfiles as $file)
{
// Is it a valid joomla installation manifest file?
$manifest = $this->_isManifest($file);
if (!is_null($manifest))
{
###JFile::move($file, $file.'.backup');
if( JFile::delete($file))
{
$this->logger->log( 'File deleted '.$file);
return true;
}
else
{
$this->logger->log( 'Unable to delete file '.$file, 'ERROR');
return false;
}
}
}//foreach
// None of the xml files found were valid install files
# JError::raiseWarning(1, 'JInstaller::install: '.JText::_('ERRORNOTFINDJOOMLAXMLSETUPFILE'));
return false;
}
else
{
// No xml files were found in the install folder
# JError::raiseWarning(1, 'JInstaller::install: '.JText::_('ERRORXMLSETUP'));
return false;
}
}//function
/**
* Is the xml file a valid Joomla installation manifest file
*
* @access private
* @param string $file An xmlfile path to check
* @return mixed A JSimpleXML document, or null if the file failed to parse
* @since 1.5
*/
function &_isManifest($file)
{
// Initialize variables
$null = null;
$xml =& JFactory::getXMLParser('Simple');
// If we cannot load the xml file return null
if (!$xml->loadFile($file)) {
// Free up xml parser memory and return null
unset ($xml);
return $null;
}
/*
* Check for a valid XML root tag.
*/
$root =& $xml->document;
if (!is_object($root) || ($root->name() != 'install')) {
// Free up xml parser memory and return null
unset ($xml);
return $null;
}
// Valid manifest file return the object
return $xml;
}
private function _createManifest( $project )
{
//--Get manifest class
JLoader::import('helpers.manifest', JPATH_COMPONENT);
$manifest = new Manifest();
$project->basepath = $this->_temp_dir;
$project->creationDate = date("d-M-Y");
$this->logger->log('Starting manifest');
if( $manifest->create($project))
{
$this->logger->logFileWrite('', $project->basepath.DS.$project->installxml, $manifest->getNormalizedString());
}
else
{
$this->logger->log('Error creating manifest file: '.$manifest->getError(),'Error creating manifest file');
//TODO ABORT
return false;
}
return true;
}// function
/**
* Set the temp directory
*/
private function setTempDir()
{
$config =& JFactory::getConfig();
$this->_temp_dir = $config->getValue('config.tmp_path');
$this->_temp_dir .= DS.uniqid($this->project->com_name);
if( JFolder::create($this->_temp_dir) )
{
$this->logger->log('TempDir created
'.$this->_temp_dir);
return true;
}
else
{
$this->logger->log('ERROR creating TempDir
'.$this->_temp_dir, 'ERROR');
return false;
}
}// function
/**
* parse the config file
*/
function _parseConfig()
{
foreach( $this->_configfile as $line )
{
//TODO separator char is a space.. switch to '=' ?
$args = explode( ' ', $line );
$command = strtolower( trim($args[0]) );
if( ! $command ) continue;
foreach( $this->_build_vars as $k => $v )
{
if( $command == $k )
{
$value = trim( substr( $line, strlen( $command )));
$this->_credit_vars[$v] = $value;
$this->logger->log('ADD _credit_var: '. $v.' : '.$value.'
');
continue 2;
}
}//foreach
switch( $command )
{
case 'langs':
$this->_langs = explode(',', trim($args[1]));
foreach( $this->_langs as $k=>$v )
{ $this->logger->log('Found Lang: '.$k.') '.$v.'
'); }
break;
case 'ecopy':
$i =( count($this->_copys) ) ? count($this->_copys) : 0;
$this->_copys[$i]['source'] = JPath::clean( trim($args[1]) );
$this->_copys[$i]['dest'] =(isset($args[2])) ? JPath::clean( trim($args[2]) ): '';
$this->logger->log( '$copy['.$i.']source: '.$this->_copys[$i]['source'].'
');
$this->logger->log( '$copy['.$i.']dest: '.$this->_copys[$i]['dest'].'
');
break;
case 'menu':
$this->_menu['img'] = trim($args[1]);
$this->_menu['link'] = trim($args[2]);
//--menu['text'] can contain spaces, so asume all other args to be ['text']..
//--for that text must be in last place !
$this->_menu['text'] = trim(substr($line, strpos($line, $args[3]) ));
$this->logger->log( 'menu entry found: '.$line);
break;
case 'submenu':
$i =( count($this->_submenu) ) ? count($this->_submenu) : 0;
$this->_submenu[$i]['img'] = trim($args[1]);
$this->_submenu[$i]['link'] = trim($args[2]);
//--menu['text'] can contain spaces, so asume all other args to be ['text']..
//--for that text must be in last place !
$this->_submenu[$i]['text'] = trim(substr($line, strpos($line, $args[3]) ));
$this->logger->log( 'submenu entry found: '.$line);
break;
case 'comscope':
$this->_scope = trim($args[1]);
$this->logger->log( 'scope entry found: '.$line);
break;
case 'comtype':
$this->_com_type = trim($args[1]);
$this->logger->log( 'com_type entry found: '.$line);
break;
case 'entryfile':
$this->_entryFile = trim($args[1]);
$this->logger->log( 'entryfile entry found: '.$line);
break;
default:
if( $command )
{ $this->logger->log( 'UNKNOWN '.$args[0]); }
break;
}//switch
}//foreach
return true;
}// function
function getParsedConfig( $configfile )
{
if( ! $configfile )
{
echo 'no config..';
return false;
}
return $this->_parseEEConfig( $configfile );
}// function
function _parseEEConfig( $configfile )
{
$parsed = array();
$parsed['copys'] = array();
$parsed['menu'] = array();
$parsed['submenu'] = array();
foreach( $configfile as $line )
{
$args = explode(' ', $line);
$command = strtolower( trim($args[0]) );
if( ! $command ) { continue; }
foreach( $this->_build_vars as $k=>$v )
{
if( $command == $k )
{
$parsed['buildvars'][$v] = trim($args[1]);
continue 2;
}
}//foreach
switch( $command )
{
case 'langs':
$parsed ['langs'] = explode(',', trim($args[1]));
break;
case 'ecopy':
$i =( count($parsed ['copys']) ) ? count($parsed ['copys']) : 0;
$parsed ['copys'][$i]['source'] = trim($args[1]);
$parsed ['copys'][$i]['dest'] =(isset($args[2])) ? trim($args[2]) : '';
break;
case 'menu':
$parsed ['menu']['img'] = trim($args[1]);
$parsed ['menu']['link'] = trim($args[2]);
$parsed ['menu']['text'] = trim($args[3]);
break;
case 'submenu':
$i =( count($parsed ['submenu']) ) ? count($parsed ['submenu']) : 0;
$parsed ['submenu'][$i]['img'] = trim($args[1]);
$parsed ['submenu'][$i]['link'] = trim($args[2]);
$parsed ['submenu'][$i]['text'] = trim($args[3]);
break;
default:
if( trim($args[0]))
{
$parsed['unknown'][] = $args[0];
}
break;
}//switch
}//foreach
if( defined('ECR_DEBUG') )
{
//echo '
'; //print_r($parsed); //echo ''; } return $parsed; }// function /** * Copy files and folders */ private function copyCopys( ) { foreach( $this->project->copys as $copy ) { $copy['source'] = str_replace('/', DS, $copy['source']); $copy['dest'] = str_replace('/', DS, $copy['dest']); $tmp_dest = $this->_temp_dir.DS.$copy['dest']; JFolder::create($tmp_dest); if( is_dir( $this->base.DS.$copy['source'] )) { //--source is a directory //--copy with force overwrite.. if( JFolder::copy( $this->base.DS.$copy['source'], $tmp_dest, '', true )) { $this->logger->log('COPY DIR
'; print_r($this->_profiler->getBuffer()); echo ''; } } return true; }// function public function displayDownloadLink() { if( count($this->downloadLinks) ) { echo '
'.JText::_('No download available').'
'; } }// function public function getErrorLog() { return $this->_errors; }// function public function setDate( $date ) { $this->_f_date = $date; }// function }//class