'com_name',
'comcomname' => 'com_com_name',
'version' => 'com_version',
'lang_admin' => 'dir_lang_admin',
'lang_site' => 'dir_lang_site',
'description' => 'description',
'ebc_author' => 'author',
'authoremail' => 'authoremail',
'authorurl' => 'authorurl',
'license' => 'license',
'copyright' => 'copyright'
);
var $_credit_vars = array();
var $_profiling = false;
var $_profiler = null;
private $xmlBuildVars = array(
'name' => 'com_name'
, 'version' => 'com_version'
, 'description' => 'description'
, 'license' => 'license'
, 'author' => 'ebc_author'
, 'authoremail' => 'authoremail'
, 'authorurl' => 'authorurl'
, 'copyright' => 'copyright'
);
/**
* Constructor
*
* @access public
* @return void
*/
function __construct()
{
}//function
/**
* creates the frame
* @param string - type
* @param string - name - babys name
* @param string - path - to template dir
* @param bol - profiling
* @return bol ?
*/
public function createStartup( $type, $name, $template_path )
{
jimport('joomla.filesystem.file');
//--Setup logging
JLoader::import('helpers.logger', JPATH_COMPONENT);
$logName = date('ymd_Hi').'_startup.log';
$buildopts = JRequest::getVar('buildopts',array());
$this->logger = new easyLogger($logName, $buildopts);
$this->_com_type = substr( $type, 0, 3);
$this->_com_subtype = substr( $type, 4 );
$this->_com_name = $name;
//--Plugins and templates will be created WITHOUT prefix !!?
if( $this->_com_type == 'plg' || $this->_com_type == 'tpl' )
{
$this->_com_com_name = strtolower($name);
}
else
{
$this->_com_com_name = $this->_com_type.'_'.strtolower($name);
}
$this->_base = $template_path;
$this->logger->log('Building: '.$this->_com_name.'
aka "'.$this->_com_com_name.'"
subtype: '.$this->_com_subtype);
$this->_addSubstitute('_EBC_COM_NAME_', $this->_com_name);
$this->_addSubstitute('_EBC_COM_TBL_NAME_', strtolower($this->_com_name));
$this->_addSubstitute('_EBC_COM_COM_NAME_', $this->_com_com_name);
$this->_addSubstitute('_EBC_ACT_DATE_', date("d-M-Y"));
$this->_readCredits('std');
$this->_getOptionsFromRequest();
$this->customOptions('process');
$this->_readHeader('std');
$this->_startConfigFile();
$this->processLanguage();
$this->startup();
$this->_writeConfigFile();
$this->logger->log('FINISHED');
$logName = date('ymd_Hi').'_building.log';
$this->logger->writeLog($logName);
return true;
}//function
public function customOptions($action='display')
{
static $templateOptions = null;
if( ! $templateOptions )
{
$type = JRequest::getVar('com_type');
$folder = substr( $type, 0, 3);
$template = substr( $type, 4 );
$template_path = JPATH_COMPONENT.DS.'templates'.DS.substr( $type, 0, 3).DS.substr( $type, 4 );
if( ! JFile::exists($template_path.DS.'options.php') )
{
return false;
}
require_once $template_path.DS.'options.php';
if( ! class_exists('EasyTemplateOptions') )
{
echo JText::sprintf('Required class %s not found', 'EasyTemplateOptions');
return false;
}
$templateOptions = new EasyTemplateOptions();
}
switch ($action)
{
case 'display':
if( ! method_exists('EasyTemplateOptions', 'displayOptions') )
{
echo JText::sprintf('Required method %s not found', 'displayOptions');
return false;
}
echo '
'.JText::_('Custom options').'
';
echo $templateOptions->displayOptions();
echo '
';
break;
case 'process':
if( ! method_exists('EasyTemplateOptions', 'processOptions') )
{
echo JText::sprintf('Required method %s not found', 'processOptions');
return false;
}
return $templateOptions->processOptions($this);
break;
case 'requireds':
if( ! method_exists('EasyTemplateOptions', 'getRequireds') )
{
echo JText::sprintf('Required method %s not found', 'getRequireds');
return array();
}
return $templateOptions->getRequireds();
break;
default:
echo JText::sprintf('Action %s not defined', $action);
return false;
break;
}//switch
}//function
/**
* register an existing project
*
* @param string $type
* @param string $name
* @param string $scope
* @return bool true on success
*/
function registerProject( $type, $name, $scope='' )
{
//--Setup logging
$comParams = JComponentHelper::getParams(com_EASY_APP_ELKUKU_1);
$options = array();
$bOpts = array('logging', 'hotlogging', 'files', 'profile');
foreach ($bOpts as $bOpt)
{
if( $comParams->get($bOpt) )
{
$options[] = $bOpt;
}
}
JLoader::import('helpers.logger', JPATH_COMPONENT);
$logName = date('ymd_Hi').'_packing.log';
$this->logger = new easyLogger($logName, $options);
jimport('joomla.filesystem.file');
$this->_base = JPATH_COMPONENT.DS.'templates';
$this->_com_scope = $scope;
$this->_readCredits('std');
$this->_readHeader('std');
/**
* TODO define project types in a central place - damn..
* @deprecated =;)
*/
$projectTypes = array(
'component' => 'com'
, 'module' => 'mod'
, 'plugin' => 'plg'
, 'template' => 'tpl'
);
if( ! array_key_exists($type, $projectTypes))
{
JError::raiseWarning(100, JText::sprintf('The project type %s is not defined yet', $type));
$this->_addError(JText::sprintf('The project type %s is not defined yet', $type), 'undefined type');
return false;
}
$this->_com_type = $type;
$this->_com_com_name = strtolower($name);
$this->_com_name =( substr($name, 0, 4) == $projectTypes[$type].'_') ? substr($name, 4) : $name;
$administrator =( $scope == 'admin' || $type == 'component' ) ? 'administrator/' : '';
$xmlRoot = $administrator.$type.'s/'.$this->_com_com_name;
$copies = array();
switch ($type)
{
case 'component':
$copies[] = 'ECOPY administrator/components/'.$this->_com_com_name." admin";
$copies[] = 'ECOPY components/'.$this->_com_com_name." site";
break;
case 'module':
$this->_entry_file = $name;
$copies[] = 'ECOPY '.$administrator.'modules/'.$this->_com_com_name.' '.$scope;
break;
case 'template':
$copies[] = 'ECOPY '.$administrator.'templates/'.$this->_com_com_name.' '.$scope;
break;
case 'plugin':
$this->_entry_file = $name;
$copies[] = 'ECOPY plugins/'.$scope.'/'.$this->_com_com_name.'.php site';
$copies[] = 'ECOPY plugins/'.$scope.'/'.$this->_com_com_name.'.xml site';
$xmlRoot = 'plugins/'.$scope.'/'.$this->_com_com_name.'.xml';
break;
}//switch
//--Check for un/install files
//--Check also for multiple install files..
$checks = array(
'install' => 0
, 'uninstall' => 0
);
foreach ($copies as $copy)
{
$tmpDir = explode(' ', $copy);
$tmpDir = $tmpDir[1];
if( ! is_dir(JPath::clean(JPATH_ROOT.DS.$tmpDir)) ) { continue; }
foreach ($checks as $check => $cnt)
{
//--Check for install file
$files = JFolder::files( JPath::clean(JPATH_ROOT.DS.$tmpDir), '^'.$check );
if( count($files) )
{
$copies[] = 'ECOPY '.str_replace(DS, '/', $tmpDir.DS.$files[0]);
$checks[$check] ++;
}
}//foreach
}//foreach
foreach ($checks as $check => $cnt)
{
if( $checks[$check] > 1 )
{
JError::raiseWarning(100, JText::sprintf('%s %s files have been found - this is not good !', $checks[$check], $check));
}
}//foreach
$xmlProperties = new JObject();
$xmlFilesInDir = array();
$installXmlFile = '';
if( is_dir(JPATH_ROOT.DS.str_replace('/', DS, $xmlRoot)) )
{
$xmlFilesInDir = JFolder::files(JPATH_ROOT.DS.str_replace('/', DS, $xmlRoot), '.xml$');
}
else if( file_exists(JPATH_ROOT.DS.str_replace('/', DS, $xmlRoot)) )
{
//--Single file - Plugin
$xmlFilesInDir = array('');
}
if( count($xmlFilesInDir) )
{
foreach( $xmlFilesInDir as $xmlfile )
{
$xmlFileName = JPATH_ROOT.DS.str_replace('/', DS, $xmlRoot);
$xmlFileName .=( $xmlfile ) ? DS.$xmlfile : '';
if( $data = JApplicationHelper::parseXMLInstallFile($xmlFileName) )
{
foreach( $data as $key => $value )
{
$xmlProperties->$key = $value;
}//foreach
$installXmlFile =( $xmlfile ) ? $xmlRoot.'/'.$xmlfile : $xmlRoot;
break;
}
}//foreach
}
$this->_com_name =( isset($xmlProperties->name) && $xmlProperties->name ) ? $xmlProperties->name : $this->_com_name;
$xmlReplacements = array(
'author' => 'EBC_AUTHOR'
, 'copyright' => 'COPYRIGHT'
, 'authorEmail' => 'AUTHOREMAIL'
, 'authorUrl' => 'AUTHORURL'
, 'description' => 'DESCRIPTION'
, 'version' => 'VERSION'
);
foreach ($xmlReplacements as $xmlValue => $substituteValue)
{
if( isset($xmlProperties->$xmlValue) && $xmlProperties->$xmlValue )
{
$this->_addSubstitute($substituteValue, $xmlProperties->$xmlValue);
}
}//foreach
$this->logger->log( 'Registering: '.$this->_com_name.'
aka "'.$this->_com_com_name.'"
subtype: '.$this->_com_subtype);
$this->_addSubstitute( '_EBC_COM_NAME_', $this->_com_name);
$this->_addSubstitute( '_EBC_COM_TBL_NAME_', strtolower($this->_com_name));
$this->_addSubstitute( '_EBC_COM_COM_NAME_', $this->_com_com_name);
$this->_addSubstitute( '_EBC_ACT_DATE_', date("d-M-Y"));
//--check for languages
//----admin
$langFolders = JFolder::folders(JPATH_ADMINISTRATOR.DS.'language');
$adminLanguages = array();
foreach ($langFolders as $langFolder)
{
$fileName = JPATH_ADMINISTRATOR.DS.'language'.DS.$langFolder.DS.$langFolder.'.'.$this->_com_com_name.'.ini';
#if( JFile::exists($fileName));
if( file_exists($fileName))
{
$adminLanguages[$langFolder] = $langFolder;
}
}//foreach
//----site
$langFolders = JFolder::folders(JPATH_SITE.DS.'language');
$siteLanguages = array();
foreach( $langFolders as $langFolder )
{
$fileName = JPATH_SITE.DS.'language'.DS.$langFolder.DS.$langFolder.'.'.$this->_com_com_name.'.ini';
#if( JFile::exists($fileName));
if( file_exists($fileName))
{
$siteLanguages[$langFolder] = $langFolder;
}
}//foreach
$this->_startConfigFile();
//--Add Install XML file location
$this->_buildFile .=( $installXmlFile ) ? 'INSTALLXML '.$installXmlFile.NL.NL : '';
//--Add languages to config file
$this->_buildFile .=( count($adminLanguages) ) ? 'LANG_ADMIN admin/language'.NL : '';
$this->_buildFile .=( count($siteLanguages) ) ? 'LANG_SITE site/language'.NL : '';
$languages = array_keys(array_merge($adminLanguages, $siteLanguages));
$this->_buildFile .=( count($languages) ) ? 'LANGS '.implode(',', $languages).NL.NL : '';
//--Add copies to config file
$this->_buildFile .=( count($copies) ) ? implode("\n", $copies) : '';
//--Add type and scope to config file
$this->_buildFile .= NL.'COMTYPE '.$this->_com_type.NL;
$this->_buildFile .= 'COMSCOPE '.$this->_com_scope.NL;
//--Write the config file
$this->_writeConfigFile();
$this->logger->log('FINISHED');
$this->logger->writeLog();
return true;
}//function
private function _startConfigFile()
{
//--Get the standard config file header
if( ! $configFile = JFile::read($this->_base.DS.'std'.DS.'configfile.ini'))
{
JError::raiseWarning(100, 'Standard con fig file not found in :');
JError::raiseWarning(100, $this->_base.DS.'std'.DS.'configfile.ini');
return false;
}
$configFile .= "\n\n";
$configFile .= 'COMNAME '.$this->_com_name."\n";
$configFile .= 'COMCOMNAME '.$this->_com_com_name."\n";
$configFile .= "\n";
$version =( isset($this->_substitutes['VERSION']) ) ? $this->_substitutes['VERSION'] : '1.0';
$configFile .= 'VERSION '.$version."\n";
$description =( isset($this->_substitutes['DESCRIPTION']) ) ? $this->_substitutes['DESCRIPTION'] : '';
$configFile .= 'DESCRIPTION '.$description."\n";
$configFile .= "\n";
$configFile .=( isset($this->_entry_file) ) ? 'ENTRYFILE '.$this->_entry_file."\n" : '';
//--credits
$credits = array(
'EBC_AUTHOR', 'AUTHOREMAIL', 'AUTHORURL', 'LICENSE', 'COPYRIGHT',
);
foreach( $credits as $credit )
{
$configFile .= $credit.' '.$this->_substitutes[$credit]."\n";
}//foreach
$configFile .= "\n";
$this->_buildFile = $configFile;
}// function
/**
* This will update the config file
* xml config file
* ebc config file - TODO deprecate.--
*
* @return true on success
*/
public function updateConfigFile()
{
$installXML = JRequest::getVar('installxml', '');
$buildVars = JRequest::getVar('buildvars', false);
$langs = JRequest::getVar('langs', array());
$ebc_project = JRequest::getVar('ebc_project');
$easyProject = new easyProject();
if( ! $project = $easyProject->getProject($ebc_project))
{
JError::raiseWarning(100, JText::_('Unable to load project %s', $ebc_project));
}
$xml = & JFactory::getXMLParser('Simple');
if( ! $xml->loadFile(JPATH_ROOT.DS.$installXML))
{
unset($xml);
return false;
}
//--Process credit vars
foreach ($this->xmlBuildVars as $xmlName => $reqName)
{
$req =( isset($buildVars[$reqName]) ) ? $buildVars[$reqName] : false;
if( ! $req )
{
continue;
}
$element = & $xml->document->{$xmlName}[0];
if( $element )
{
$element->setData($req);
}
}//foreach
//--Process site language
$element = & $xml->document->languages[0];
if( ! $element && count($langs))
{
//--Our project has languages but our xml file hasn't a tag yet
$xml->document->addChild('languages');
$element = & $xml->document->languages[0];
}
if( $element )
{
$children = $element->_children;
$xmlLangs = array();
if( count($children) )
{
foreach ($children as $child)
{
$tag = $child->_attributes['tag'];
if( ! in_array($tag, $langs) )
{
$element->removeChild($child);
}
else
{
$xmlLangs[] = $tag;
}
}//foreach
}
foreach ($langs as $lang)
{
if( ! in_array($lang, $xmlLangs) )
{
$lng = $element->addChild('language', array('tag'=>$lang));
$plugin =( $project->comtype == 'plugin' ) ? 'plg_'.$project->comscope.'_' : '';
$lng->setData($lang.'/'.$lang.'.'.$plugin.$buildVars['com_com_name'].'.ini');
}
}//foreach
}
//--Process admin language
$element = & $xml->document->administration[0]->languages[0];
if( $element )
{
$children = $element->_children;
if( count($children) )
{
$xmlLangs = array();
$xmlMenuLangs = array();
foreach ($children as $child)
{
if( ! in_array($child->_attributes['tag'], $langs) )
{
$element->removeChild($child);
}
else
{
if( strpos($child->data(), 'menu.ini') )
{
$xmlMenuLangs[] = $child->_attributes['tag'];
}
else
{
$xmlLangs[] = $child->_attributes['tag'];
}
}
}//foreach
}
foreach ($langs as $lang)
{
if( ! in_array($lang, $xmlLangs) )
{
$lng = $element->addChild('language', array('tag'=>$lang));
$lng->setData($lang.'/'.$lang.'.'.$buildVars['com_com_name'].'.ini');
}
if( ! in_array($lang, $xmlMenuLangs) )
{
$lng = $element->addChild('language', array('tag'=>$lang));
$lng->setData($lang.'/'.$lang.'.'.$buildVars['com_com_name'].'.menu.ini');
}
}//foreach
}
//--Write XML file to disc
if( ! JFile::write(JPATH_ROOT.DS.$installXML, $xml->document->toString(true)))
{
JError::raiseWarning(100, JText::_('Unable to write file'));
JError::raiseWarning(100, JPATH_ROOT.DS.$installXML);
}
if( defined('ECR_DEBUG'))
{
$screenOut = $xml->document->toString(true);
$screenOut = str_replace('<', '<', $screenOut);
$screenOut = str_replace('>', '>', $screenOut);
echo '';
echo '
'.$screenOut.'
';
echo '
';
}
$ebc_project = JRequest::getVar('ebc_project', '');
$template_path = JPATH_COMPONENT.DS.'templates';
$cfgFileName = JPATH_COMPONENT.DS.'builds'.DS.'scripts'.DS.$ebc_project.'.ebc';
//--Get the standard config file header
if( ! $fileContents = JFile::read(JPATH_COMPONENT.DS.'templates'.DS.'std'.DS.'configfile.ini'))
{
JError::raiseWarning(100, 'Standard con fig file not found in :');
JError::raiseWarning(100, JPATH_COMPONENT.DS.'templates'.DS.'std'.DS.'configfile.ini');
return false;
}
$fileContents .= NL.NL;
//--Process buildvars
if( $buildVars )
{
foreach( $buildVars as $k=>$v)
{
$saveName = '';
foreach( $this->_build_vars as $fileName=>$reqName )
{
if( $reqName == $k )
{
$saveName = strtoupper($fileName);
break;;
}
}//foreach
if( $saveName )
{
$fileContents .= $saveName.' '.$v.NL;
}
}//foreach
}
$fileContents .= NL;
//--com type and scope
$fileContents .= 'COMTYPE '.JRequest::getVar('comtype', '').NL;
$fileContents .= 'COMSCOPE '.JRequest::getVar('comscope', '').NL;
$fileContents .= 'INSTALLXML '.JRequest::getVar('installxml', '').NL.NL;
$fileContents .= 'ENTRYFILE '.JRequest::getVar('entryfile', '').NL.NL;
//--Menu
$menu = JRequest::getVar('menu', array());
if( isset($menu['text']) && $menu['text'])
{
$this->setDbMenuItem($menu);
}
//--Submenu
$submenu = JRequest::getVar('submenu', array());
foreach ($submenu as $menu)
{
if( isset($menu['text']) && $menu['text'])
{
$this->setDbMenuItem($menu);
}
}//foreach
$fileContents .= NL;
//--Languages
//--Convert array in comma separated list
//--Don't use implode() cause array may contain empty elements at this stage
$languages = '';
foreach( $langs as $lang )
{
if( $lang )
{
$languages .=( $languages ) ? ','.$lang : $lang;
}
}//foreach
$fileContents .=( $languages ) ? 'LANGS '.$languages.NL : '';
$fileContents .= 'LANG_ADMIN '.JRequest::getVar('dir_lang_admin', '').NL;
$fileContents .= 'LANG_SITE '.JRequest::getVar('dir_lang_site', '').NL;
$fileContents .= NL;
//--Copies
$copies = JRequest::getVar('copys', false, 'post');
foreach( $copies as $copy )
{
if( $copy['source'] )
{
$fileContents .= 'ECOPY '.$copy['source'].' '.$copy['dest'].NL;
}
}//foreach
//--Package modules
$items = JRequest::getVar('package_module', array(), 'post');
if(count($items)) $fileContents .= NL;
foreach( $items as $item )
{
$fileContents .= 'MODULE '.$item['client'].' '.$item['name'].' '.$item['title'].' '.$item['position'].' '.$item['ordering'].NL;
}//foreach
//--Package plugins
$items = JRequest::getVar('package_plugin', array(), 'post');
if(count($items)) $fileContents .= NL;
foreach( $items as $item )
{
$fileContents .= 'PLUGIN '.$item['client'].' '.$item['name'].' '.$item['title'].' '.$item['ordering'].NL;
}//foreach
if( ! JFile::write($cfgFileName, $fileContents))
{
JError::raiseWarning(100, JText::sprintf('Unable to save the file %s', $cfgFileName));
return false;
}
return true;
}// function
/**
* Updates a menu entry in database / Insert new one if not exists
*
* @param $item array
* @return bool true on success
* @todo move
*/
private function setDbMenuItem($item)
{
$db = JFactory::getDBO();
//--Test if item exists
$query = 'SELECT count(*) FROM `#__components`'
. ' WHERE id = \''.$item['dbid'].'\'';
$db->setQuery($query);
$isNew = $db->loadResult();
if( ! $isNew )
{
//--New item
$query = 'INSERT INTO `#__components`'
. ' SET'
. ' `name` = \''.$item['text'].'\''
. ', `admin_menu_alt` = \''.$item['text'].'\''
. ', `admin_menu_link` = \''.$item['link'].'\''
. ', `admin_menu_img` = \''.$item['img'].'\''
. ', `parent` = \''.$item['parent'].'\';';
}
else
{
//--Update existing item
$query = 'UPDATE `#__components`'
. ' SET '
. ' `name` = \''.$item['text'].'\''
. ', `admin_menu_alt` = \''.$item['text'].'\''
. ', `admin_menu_link` = \''.$item['link'].'\''
. ', `admin_menu_img` = \''.$item['img'].'\''
. ' WHERE `id` = '.$item['dbid'].';';
}
$db->setQuery($query);
if( ! $db->query() )
{
ecrHTML::displayMessage($db->stderr(true));
return false;
}
return true;
}//function
private function _getOptionsFromRequest( )
{
# ADD CREDIT - KEY: EBC_AUTHOR - VALUE: Nikolai Plath
# ADD CREDIT - KEY: AUTHOREMAIL - VALUE: info@nik-it.de
# ADD CREDIT - KEY: AUTHORURL - VALUE: http://www.nik-it.de
# ADD CREDIT - KEY: LICENSE - VALUE: http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# ADD CREDIT - KEY: COPYRIGHT - VALUE: Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
//credits
foreach( $this->_build_vars as $k=>$v )
{
$req = JRequest::getVar($k, '', 'post');
if( $req )
{
$key = strtoupper($k);
if( array_key_exists($key, $this->_substitutes))
{
$this->_substitutes[$key] = $req;
$this->logger->log('REPLACE CREDIT - KEY: '.$key.' - VALUE: '.$req);
}
else
{
$this->_substitutes[$key] = $req;
$this->logger->log('ADD CREDIT - KEY: '.$key.' - VALUE: '.$req);
}
}
}//foreach
/*
* Languages
*/
$this->_languages = JRequest::getVar('langs', '', 'post') ;
}// function
private function processLanguage()
{
//TODO language section
// if( ! $this->_languages )
// {
// //--No languages defined - abort
// return;
// }
/* adding default en-GB
* always adding it
* TODO change this ?? Q: allow creation of components WITHOUT language files ?
*
*/
$languages = array('en-GB');
# $languages .=( $this->_languages ) ? ','.$this->_languages : '';
if( strpos($this->_languages, ','))
{
//--We have more than one language
$languages = array_merge($languages, explode(',', $this->_languages));
}
else
{
//--We have only one language
if($this->_languages)
{
$languages[] = $this->_languages;
}
}
$this->_buildFile .= 'LANGS '.implode(',', $languages)."\n";
$this->_buildFile .= "\n";
switch( $this->_com_type )
{
case 'com':
$this->_buildFile .= 'LANG_ADMIN admin/language'."\n";
$this->_buildFile .= 'LANG_SITE site/language'."\n";
break;
case 'mod':
//TODO scope
// $this->_buildFile .= 'LANG_ADMIN admin/language'."\n";
$this->_buildFile .= 'LANG_SITE site/language'."\n";
break;
case 'plg':
//TODO scope
// $this->_buildFile .= 'LANG_ADMIN admin/language'."\n";
$this->_buildFile .= 'LANG_SITE site/language'."\n";
break;
}//switch
//--create language files in current J! install---regardless if they exist or not !
//--this may (or not) interfere with the further instalation of languages.
foreach ($languages as $language)
{
$filename = $language.'.'.$this->_com_com_name.'.ini';
$dirs = array();
switch( $this->_com_type )
{
case 'com':
$dirs[] = JPATH_SITE.DS.'language'.DS.$language;
$dirs[] = JPATH_ADMINISTRATOR.DS.'language'.DS.$language;
break;
case 'mod':
//TODO scope
$dirs[] = JPATH_SITE.DS.'language'.DS.$language;
#$dirs[] = JPATH_ADMINISTRATOR.DS.'language'.DS.$language;
break;
case 'plg':
$dirs[] = JPATH_SITE.DS.'language'.DS.$language;
break;
}//switch
foreach ($dirs as $dir)
{
//--standard contents for language file
$file_contents = '';
//--Separate this to prevent subversion from autoreplace with Id tag..
$file_contents .= '# @version $Id'.'$'.NL;
$scope =( strpos($dir, JPATH_ADMINISTRATOR) === 0 ) ? 'admin' : 'site';
$file_contents .= '# '.$scope.' language file for '.$this->_com_name.NL;
if( JFile::write($dir.DS.$filename, $file_contents) )
{
$this->logger->logFileWrite('', $dir.DS.$filename, $file_contents);
if( strpos($dir, 'administrator'.DS) )
{
$scope = 'admin';
$tDir = JPATH_ROOT.DS.'admin'.DS.'language'.DS.$language;
}
else
{
$scope = 'site';
$tDir = JPATH_ROOT.DS.'site'.DS.'language'.DS.$language;
}
$this->languageFiles[$scope][] = $tDir.DS.$filename;//substr($dir.DS.$filename, strlen($dir) + 1);
}
else
{
$this->logger->logFileWrite('', $dir.DS.$filename, $file_contents, 'ERROR');
$this->_addError('ERROR creating File
'.$dir.DS.$filename.'
','ERROR creating File');
//TODO ABORT
}
}//foreach
}//foreach
}//function
function _writeConfigFile()
{
//--write to disk !
if( JFile::write(JPATH_COMPONENT.DS.'builds'.DS.'scripts'.DS.$this->_com_com_name.'.ebc', $this->_buildFile) )
{
$this->logger->logFileWrite('', JPATH_COMPONENT.DS.'builds'.DS.'scripts'.DS.$this->_com_com_name.'.ebc', $this->_buildFile);
}
else
{
$this->logger->logFileWrite('', JPATH_COMPONENT.DS.'builds'.DS.'scripts'.DS.$this->_com_com_name.'.ebc', $this->_buildFile, 'ERROR creating File');
$this->_addError('ERROR creating File
'.JPATH_COMPONENT.DS.'builds'.DS.'scripts'.DS.$this->_com_com_name.'.ebc
','ERROR creating File');
//TODO ABORT
}
}// function
private function startup()
{
$this->logger->log( 'Process starter.ini');
$fileContents = JFile::read($this->_base.DS.$this->_com_type.DS.$this->_com_subtype.DS.'starter.ini');
if($fileContents)
{
$fileContents = explode("\n", $fileContents);
}
$project = new JObject();
$createXML = false;
$uninstallFile = '';
foreach( $fileContents as $line )
{
$line = trim($line);
if( ! $line || (strpos( $line, '#' ) === 0) )
{
// strip lines with '#' in first place - comment
continue;
}
/* use the '=' sign as separator */
$key = strtolower(substr($line, 0, strpos($line, '=')));
$value = substr($line, strpos($line, '=') + 1);
switch( $key )
{
case 'dir':
$value = str_replace('/', DS, $value);
$this->_substitute($value);
$value = strtolower( $value );
if( JFolder::create(JPATH_SITE.DS.$value) )
{
$this->logger->log('Folder created: '.JPATH_SITE.DS.$value);
}
else
{
$this->logger->log(JPATH_SITE.DS.$value, 'ERROR creating folder');
$this->_addError('ERROR creating Folder
'.JPATH_SITE.DS.$value.'
','ERROR creating Folder');
}
break;
case 'file':
$this->_substitute($value);
$value = str_replace('/', DS, $value);
if( strpos($value, 'CHANGELOG') === false
&& strpos($value, 'templateDetails') === false)
{
/*
* everything but the CHANGELOG has to be lower case
* .... and also the templateDetails.xml :..
*/
$value = strtolower( $value );
}
//--separate the commands
$commands = $this->separateCommands($value);
$f_path = $commands[0];
$f_template = $commands[1];
if( ! JFile::exists($this->_base.DS.$f_template) )
{
//--File not found !
$this->logger->log($this->_base.DS.$f_template, 'File not found');
$this->_addError('ERROR file not found
'.$this->_base.DS.$f_template.'
','ERROR file not found'.$this->_base.DS.$f_template);
//TODO abort
}
else
{
$t_template = file($this->_base.DS.$f_template);
$file_contents = '';
foreach( $t_template as $t_line )
{
//--Replace substitute tags
$this->_substitute($t_line);
$file_contents .= $t_line;
}//foreach
//--Write to disk !
if( JFile::write(JPATH_ROOT.DS.$f_path, $file_contents) )
{
$this->logger->logFileWrite($f_template, $f_path, $file_contents);
//--Remember uninstall file for later use in xml setup
if( strpos($f_template, 'uninstall.') )
{
$uninstallFile = array(JFile::getName($f_path));
}
}
else
{
$this->logger->log(JPATH_ROOT.DS.$f_path, 'ERROR creating File');
$this->_addError('ERROR creating File
'.JPATH_ROOT.DS.$f_path.'
','ERROR creating File'.JPATH_ROOT.DS.$f_path);
//TODO ABORT
}
}
break;
case 'copydir':
$this->_substitute($value);
$value = str_replace('/', DS, $value);
$commands = $this->separateCommands($value);
$source = $commands[0];
$destination = $commands[1];
//--Copy the folder !
if( JFolder::copy(JPATH_ROOT.DS.$source, JPATH_ROOT.DS.$destination))
{
$this->logger->log('Folder copied'.BR.JPATH_ROOT.DS.$source);
}
else
{
$this->logger->log(BR.JPATH_ROOT.DS.$source, 'ERROR Folder copy');
$this->_addError('ERROR copying Folder
'.JPATH_ROOT.DS.$source.'
'.JPATH_ROOT.DS.$destination.'
','ERROR copying Folder
'.JPATH_ROOT.DS.$source.'
'.JPATH_ROOT.DS.$destination);
//TODO ABORT
}
break;
case 'copyfile':
$this->_substitute($value);
$value = str_replace('/', DS, $value);
$commands = $this->separateCommands($value);
$source = $commands[0];
$destination = $commands[1];
//--Copy the file
if( JFile::copy(JPATH_ROOT.DS.$source, JPATH_ROOT.DS.$destination))
{
$this->logger->logFileWrite(JPATH_ROOT.DS.$source, JPATH_ROOT.DS.$destination);
}
else
{
$this->logger->logFileWrite(JPATH_ROOT.DS.$source, JPATH_ROOT.DS.$destination, 'ERROR');
$this->_addError('ERROR copying File
'.JPATH_ROOT.DS.$source.'
'.JPATH_ROOT.DS.$destination.'
','ERROR copying File
'.JPATH_ROOT.DS.$source.'
'.JPATH_ROOT.DS.$destination);
//TODO ABORT
}
break;
case 'query':
$db = JFactory::getDBO();
$this->_addSubstitute('_EBC_INSERTID_', $db->insertid());
if($this->_substitutes['_EBC_INSERTID_'])
{
$this->logger->log( 'Found InsertID: '.$this->_substitutes['_EBC_INSERTID_']);
}
$this->_substitute($value);
$db->setQuery($value);
if($db->Query())
{
$this->logger->logQuery($value);
}
else
{
$this->logger->logQuery($value, $db->getErrorMsg());
$this->_addError('QUERY ERROR
'.$db->getError().'
','QUERY ERROR: ');
//TODO ABORT ?
}
break;
case 'installxml':
if( ! isset($project->installxml) )
{
//--Set only if empty
$this->_substitute($value);
if($this->_com_type != 'tpl')
{
//--the name of the XML setup file for templates is 'templateDetails.xml'
//--every other will be lower case
$value = strtolower( $value );
}
$project->installxml = $value;
$this->_buildFile .= 'INSTALLXML '.$value."\n";
$createXML = true;
$this->logger->log('Set installXML to:
'.$value);
}
break;
case 'build':
$this->_substitute($value);
$value = strtolower( $value );
$this->_buildFile .= 'ECOPY '.$value."\n";
$this->logger->log('build file line found
'.$value);
break;
case 'comtype':
$value = strtolower( $value );
$this->_buildFile .= 'COMTYPE '.$value."\n";
$project->comtype = $value;
$this->logger->log('comtype line found
'.$value);
break;
case 'comscope':
$this->_substitute($value);
$value = strtolower( $value );
$this->_buildFile .= 'COMSCOPE '.$value."\n";
$project->comscope = $value;
$this->logger->log('comscope line found
'.$value);
break;
case 'entryfile':
$this->_substitute($value);
$value = strtolower( $value );
$this->_buildFile .= 'ENTRYFILE '.$value."\n";
$this->logger->log('entryfile line found
'.$value);
break;
case 'module':
$this->_substitute($value);
$value = strtolower( $value );
$this->_buildFile .= 'MODULE '.$value."\n";
$this->logger->log('module line found
'.$value);
break;
case 'plugin':
$this->_substitute($value);
$value = strtolower( $value );
$this->_buildFile .= 'PLUGIN '.$value."\n";
$this->logger->log('plugin line found
'.$value);
break;
default:
$this->logger->log($key, 'Unknown keys');
$this->_addError( 'UNKNOWN: '.$key,'found unknown');
break;
}//switch
}//foreach
if( $createXML )
{
$project->basepath = JPATH_SITE;
$project->author = JRequest::getVar('ebc_author', $this->_substitutes['EBC_AUTHOR']);
$project->com_name = JRequest::getVar('com_name', $this->_substitutes['_EBC_COM_NAME_']);
$project->com_version = JRequest::getVar('version', '1.0.0');
$project->description = JRequest::getVar('description', 'StartUp');
$project->authoremail = JRequest::getVar('authoremail', $this->_substitutes['AUTHOREMAIL']);
$project->authorurl = JRequest::getVar('authorurl', $this->_substitutes['AUTHORURL']);
$project->license = JRequest::getVar('license', $this->_substitutes['LICENSE']);
$project->copyright = JRequest::getVar('copyright', $this->_substitutes['COPYRIGHT']);
$project->creationDate = date('d-M-y');
//--Modules and Plugins
$project->modules = array();
$project->plugins = array();
//--Adding special params for new projects..
$project->isNew = true;
$project->uninstallFile =( $uninstallFile ) ? $uninstallFile : array();
$project->languageFiles = $this->languageFiles;
//--Get manifest class
JLoader::import('helpers.manifest', JPATH_COMPONENT);
$manifest = new Manifest();
$this->logger->log('Starting manifest
NOTE: INITIAL MANIFEST - NO FILES WILL BE ADDED HERE');
if( $manifest->create($project) )
{
$this->logger->logFileWrite( '', $project->basepath.DS.$project->installxml, $manifest->getNormalizedString());
}
else
{
$this->logger->log('Manifest file has NOT been created at
'.JPath::clean( $project->basepath.DS ).$project->installxml.'
'.$manifest->getError(),'Unable to create Manifest file');
$this->_addError( 'Error creating manifest file
'.$manifest->getError().'
','Error creating manifest file');
//TODO ABORT
}
}
return true;
}// function
/**
* Separates a string by spaces or tabs
*
* @param string $command
* @return array found commands
*/
function separateCommands($command)
{
if( strpos($command, "\t") )
{
$sepChar = "\t";
}
else
{
$sepChar = ' ';
}
$parts = explode( $sepChar, $command );
$ret = array();
foreach ($parts as $part)
{
if($part)
{
$ret[] = trim($part);
}
}//foreach
return $ret;
}// function
/**
* Read the header file
*/
function _readHeader( $subdir='std' )
{
$header = JFile::read($this->_base.DS.$subdir.DS.'header.php');
//replace vars in header
$this->_substitute($header);
$this->_addSubstitute('##*HEADER*##', $header);
}// function
/**
* Read the credits file
*/
function _readCredits( $subdir = 'std' )
{
$fFile = file($this->_base.DS.$subdir.DS.'credits.ini');
foreach( $fFile as $line )
{
$line = trim($line);
if( $line && ! (strpos( $line, '#' ) === 0) )
{
$key = substr($line, 0, strpos($line, '='));
$value = substr($line, strpos($line, '=')+1);
$this->logger->log('ADD CREDIT - KEY: '.$key.' - VALUE: '.$value);
$this->_addSubstitute($key, $value);
}
}//foreach
}// function
/**
* Adds a string to the substitutes array
*
* @param string $key
* @param string $value
*
* @return void
*/
function _addSubstitute( $key, $value )
{
$this->_substitutes[$key] = $value;
}// function
/**
* Replaces tags in text from substitutes array
*
* @param string $text
*
* @return string substituted string
*/
function _substitute( &$text )
{
foreach( $this->_substitutes as $k=>$v )
{
$text = str_replace($k, $v, $text);
}//foreach
return $text;
}// function
/**
* adds an error message to the error array
*
* @param string $string the error message
* @param string [$title] the title
*/
function _addError( $string, $title='' )
{
#$spacing = 60;
#$spacing =( strlen($title) > $spacing ) ? 0 : $spacing - strlen($title);
#if( $this->_profiling ){$this->_profiler->mark(str_repeat(' ', $spacing).$title);}
$this->_errors[] = $string;
}// function
/**
* html error list
*
* @return string html
*/
function printErrors()
{
if( count( $this->_errors ))
{
echo 'ERRORS !
';
echo '';
foreach( $this->_errors as $entry )
{
echo '- '.$entry.'
';
}//foreach
echo '
';
}
else
{
echo 'No errors...
';
}
return true;
}// function
/**
* get log array
*
* @return array
*/
function getLog( )
{
if( count( $this->_log ) )
{
return $this->_log;
}
else
{
return array('NO LOG SO FAR...');
}
}// function
/**
* html log output
*
* @return string html
*/
function printLog()
{
$this->logger->printLog();
}// function
}// class