_hideLangs = $hideLangs;
$this->_com_name = $project->com_com_name;
$this->_languages = $this->setLangs($project->langs);
$this->project = $project;
$this->_scope = $scope;
$this->_showCore = JRequest::getVar('showCore', '');
if( $scope == 'menu' )
{
$this->readMenu();
}
else
{
$this->_fileList = $this->_buildFileList($project->copys, $scope);
}
}//function
public function checkFile($fileName, $lang, $scope)
{
$file = new JObject();
$file->fileName = $fileName;
$file->lang = $lang;
$file->scope = $scope;
$file->exists =( JFile::exists($fileName) ) ? true : false;
$file->isUFT8 = false;
$file->hasBOM = false;
if( ! $file->exists )
{
return $file;
}
//--Check if file is UTF-8 encoded
$file->isUFT8 = $this->is_utf8(JFile::read($fileName));
//--Detect BOM
$file->hasBOM = $this->detectBOM_utf8($fileName);
return $file;
}//function
/**
* sets the languages.
* ensures that en-GB is always in first place.
*
* @param array $languages
* @return array
*/
private function setLangs($languages)
{
if( ! is_array($languages) )
{
return array();
}
if( ! in_array('en-GB', $languages) )
{
JError::raiseWarning(100, 'Default language en-GB is not present');
return array();
}
//--assure that default 'en-GB' is in first place
$result = array('en-GB');
foreach ($languages as $language)
{
if( $language != 'en-GB')
{
$result[] = $language;
}
}//foreach
return $result;
}//function
public function getTranslation($lang, $key)
{
$path =( $this->_scope == 'admin' || $this->_scope == 'menu' ) ? JPATH_ADMINISTRATOR : JPATH_SITE;
$this->_readStrings($path);
$translation =( isset($this->_strings[$key][$lang])) ? $this->_strings[$key][$lang] : '';
return $translation;
}//function
/**
* gets the saved versions.
*
* @param string $lang
* @return array(object) array of versions
*/
public function getVersions( $lang )
{
$versions = array();
$admin =( $this->_scope == 'admin' || $this->_scope == 'menu' ) ? 'administrator'.DS : '';
$menu =( $this->_scope == 'menu' ) ? '.menu' : '';
$fileName = $lang.'.'.$this->_com_name.$menu.'.ini';
$path = JPATH_ROOT.DS.$admin.'language'.DS.$lang;
if( ! JFile::exists($path.DS.$fileName) )
{
JError::raiseWarning(100, JText::sprintf('The file %s could not be found in path %s', $fileName, $path));
return $versions;
}
$r = 1;
while( $r > 0 )
{
$test = $fileName.'.r'.$r;
if( JFile::exists($path.DS.$test) )
{
$version = new JObject();
$lastMod = date ("d-M-y H:i.", filectime($path.DS.$test));
// $lastMod = JHTML::_( 'date', filemtime($path.DS.$test), JText::_('DATE_FORMAT_LC4') );
$size = $this->byte_convert( filesize($path.DS.$test));
// $stat = stat($path.DS.$test);
$version->fileName = $test;
$version->revNo = substr(JFile::getExt($test),1);
$version->lastMod = $lastMod;
# $version->stat = $stat;
$version->size = $size;
$versions[] = $version;
$r++;
}
else
{
$r = 0;
}
}//while
return $versions;
}//function
public function getLanguages()
{
return $this->_languages;
}//function
public function getHideLangs()
{
return $this->_hideLangs;
}//function
public function getDefinitions()
{
return $this->_definitions;
}//function
public function getStrings()
{
return $this->_strings;
}//function
public function getCoreStrings()
{
return $this->_coreStrings;
}//function
public function getDefaultFile()
{
return $this->_default_file;
}//function
/**
* displays the actual file and a selected version side by side
*
* @param int $revNo
* @param string $lang
*/
public function displayVersion($revNo, $lang)
{
$path =( $this->_scope == 'admin' || $this->_scope == 'menu' ) ? JPATH_ADMINISTRATOR : JPATH_SITE;
$menu =( $this->_scope == 'menu' ) ? '.menu' : '';
$path .= DS.'language'.DS.$lang;
$sRev = '.r'.$revNo;
$fileNameOrig = $lang.'.'.$this->_com_name.$menu.'.ini';
$fileNameRev = $lang.'.'.$this->_com_name.$menu.'.ini.r'.$revNo;
$fileOrig = '';
$fileRev = '';
if( JFile::exists($path.DS.$fileNameOrig))
{
$fileOrig = JFile::read($path.DS.$fileNameOrig);
if( $fileOrig )
{
$fileOrig = explode("\n", $fileOrig);
}
}
if( JFile::exists($path.DS.$fileNameRev))
{
$fileRev = JFile::read($path.DS.$fileNameRev);
if($fileRev)
{
$fileRev = explode("\n", $fileRev);
}
}
JLoader::import('helpers.DifferenceEngine', JPATH_COMPONENT);
//--we are adding a blank line to the end.. this is somewhat 'required' by PHPdiff
if( $fileOrig[count($fileOrig)-1] != '')
{
$fileOrig[] = '';
}
if( $fileRev[count($fileRev)-1] != '')
{
$fileRev[] = '';
}
$dwDiff = new Diff( $fileRev, $fileOrig);
$dwFormatter = new TableDiffFormatter();
?>
';
return false;
}
}//function
/**
* Searches for a UTF-8 BOM/Signature in a given file and removes it
* @param $file string filename
* @return bool true if a BOM is detected and removed
* @author: http://develobert.blogspot.com/
*/
public function removeBOM_utf8($filename)
{
$filename = JPATH_ROOT.$filename;
$size = filesize($filename);
if( $size < 3 )
{
// BOM not possible
return true;
}
if($fh = fopen($filename, 'r+b'))
{
if(bin2hex(fread($fh, 3)) == 'efbbbf')
{
if($size == 3 && ftruncate($fh, 0))
{
// Empty other than BOM
fclose($fh);
return true;
}
else if($buffer = fread($fh, $size))
{
//-- BOM found
// Shift file contents to beginning of file
if(ftruncate($fh, strlen($buffer)) && rewind($fh))
{
if(fwrite($fh, $buffer))
{
fclose($fh);
return true;
}
}
}
}
else
{
// No BOM found
fclose($fh);
return true;
}
}
else
{
echo 'unable to open file '.$filename.'
';
return false;
}
}//function
private function byte_convert($bytes)
{
$symbol = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
$exp = 0;
$converted_value = 0;
if( $bytes > 0 )
{
$exp = floor( log($bytes)/log(1024) );
$converted_value = ( $bytes/pow(1024,floor($exp)) );
}
return sprintf( '%.2f '.$symbol[$exp], $converted_value );
}//function
function correctTranslation( $defaultLanguage, $translatedLanguage )
{
$correctedLanguage = array();
//--read the header from translated language
foreach( $translatedLanguage as $line )
{
$corrected = new JObject();
if( $line->key == '#')
{
$corrected->key = '#';
$corrected->value = $line->value;
$correctedLanguage[] = $corrected;
}
else
{
break;
}
}//foreach
$isHeader = true;
foreach( $defaultLanguage as $line )
{
$corrected = new JObject();
if( $line->key == '#')
{
if( ! $isHeader )
{
$corrected->key = '#';
$corrected->value = $line->value;
$correctedLanguage[] = $corrected;
}
}
else
{
$isHeader = false;
$trans = '**TRANSLATE**';
foreach ($translatedLanguage as $tLine)
{
if( $tLine->key == $line->key )
{
$trans = $tLine->value;
break;
}
}//foreach
$corrected->key = $line->key;
$corrected->value = $trans;
$correctedLanguage[] = $corrected;
}
}//foreach
return $correctedLanguage;
}//function
function saveFile($lang, $fileContents)
{
$path =( $this->_scope == 'admin' || $this->_scope == 'menu' ) ? JPATH_ADMINISTRATOR : JPATH_SITE;
$subPath = 'language'.DS.$lang;
$menu =( $this->_scope == 'menu' ) ? '.menu' : '';
$fileName = $path.DS.$subPath.DS.$lang.'.'.$this->_com_name.$menu.'.ini';
//--Save a version ?
$saveVersion = JRequest::getVar('save_version', '1' );
if( $saveVersion )
{
if( ! $this->_saveVersion($fileName) )
{
return false;
}
}
$fileContents = implode("\n", $fileContents);
if ( ! JFile::write($fileName, $fileContents) )
{
JError::raiseWarning(100,JText::_('Unable to write file').$fileName);
return false;
}
JError::raiseNotice(100, JText::_('The file has been saved'));
return true;
}//function
function saveTranslation($lang, $key, $translation, $position=0)
{
$path =( $this->_scope == 'admin' || $this->_scope == 'menu' ) ? JPATH_ADMINISTRATOR : JPATH_SITE;
$subPath = 'language'.DS.$lang;
$menu =( $this->_scope == 'menu' ) ? '.menu' : '';
$plugin =( $this->project->comtype == 'plugin' ) ? 'plg_'.$this->project->comscope.'_' : '';
$fileName = $path.DS.$subPath.DS.$lang.'.'.$plugin.$this->_com_name.$menu.'.ini';
$origFile = $this->parseFile($fileName);
$resultFile = array();
$pos = 1;
$found = false;
foreach ($origFile as $line)
{
switch($line->key)
{
case '#':
case '-':
$resultFile[] = $line->value;
$pos ++;
break;
default:
if( $line->key == $key )
{
//--Found it
$resultFile[] = $line->key.'='.$translation;
$pos ++;
$found = true;
}
else
{
$resultFile[] = $line->key.'='.$line->value;
}
break;
}//switch
}//foreach
if( ! $found )
{
//--New translation - append
$resultFile[] = $key.'='.$translation;
}
$fileContents = implode("\n", $resultFile);
//--Save a version ?
$saveVersion = JRequest::getVar('save_version', '1' );
if( $saveVersion )
{
if( ! $this->_saveVersion($fileName) )
{
return false;
}
}
if ( ! JFile::write($fileName, $fileContents) )
{
JError::raiseWarning(100, JText::_('Unable to write file').$fileName);
return false;
}
return true;
}//function
function deleteTranslation($lang, $key)
{
$path =( $this->_scope == 'admin' || $this->_scope == 'menu' ) ? JPATH_ADMINISTRATOR : JPATH_SITE;
$subPath = 'language'.DS.$lang;
$menu =( $this->_scope == 'menu' ) ? '.menu' : '';
$plugin =( $this->project->comtype == 'plugin' ) ? 'plg_'.$this->project->comscope.'_' : '';
$fileName = $path.DS.$subPath.DS.$lang.'.'.$plugin.$this->_com_name.$menu.'.ini';
$origFile = $this->parseFile($fileName);
$resultFile = array();
$pos = 1;
$found = false;
foreach ($origFile as $line)
{
switch($line->key)
{
case '#':
case '-':
$resultFile[] = $line->value;
$pos ++;
break;
default:
if( $line->key == $key )
{
//--Found it
# $resultFile[] = $line->key.'='.$translation;
# $pos ++;
$found = true;
}
else
{
$resultFile[] = $line->key.'='.$line->value;
}
break;
}//switch
}//foreach
if( ! $found )
{
//--New translation - append
JError::raiseWarning(100, JText::_('Key not found').' : '.$key);
return false;
}
$fileContents = implode("\n", $resultFile);
//--Save a version ?
$saveVersion = JRequest::getVar('save_version', '1' );
if( $saveVersion )
{
if( ! $this->_saveVersion($fileName) )
{
return false;
}
}
if ( ! JFile::write($fileName, $fileContents) )
{
JError::raiseWarning(100, JText::_('Unable to write file').$fileName);
return false;
}
return true;
}//function
/**
* reads the strings from language files
*
* @param string $path
*/
function _readStrings($path, $core=false)
{
foreach ($this->_languages as $lang)
{
if( in_array($lang, $this->_hideLangs ))
{
continue;
}
//--Read the file
$file = $this->_getFile($lang, $path, $core);
if( ! $file )
{
continue;
}
foreach( $file as $line )
{
$line = trim($line);
if( strpos($line, '#') === 0)
{
//--Comment line
if( $core )
{
//--Don't care about core comments ;)
continue;
}
if( strpos($line, '@version' ))
{
//--Version string found
if( $lang == $this->_default_lang )
{
$this->_default_file[] = array('version'=>$line);
}
continue;
}
if( $lang == $this->_default_lang )
{
$this->_default_file[] = array('comment'=>$line);
}
continue;
}
$eqpos = strpos($line, '=');
if( $eqpos )
{
//--Found a pair
$key = substr($line, 0, $eqpos);
$value = substr($line, $eqpos + 1);
if( ! array_key_exists($key, $this->_strings) && ! $core )
{
$this->_default_file[] = array('key' => array($key => $value));
}
if( $core )
{
$this->_coreStrings[$key][$lang] = $value;
}
else
{
$this->_strings[$key][$lang] = $value;
}
continue;
}
if( $lang == $this->_default_lang && ! $core )
{
$this->_default_file[] = array('etc' => $line);
}
}//foreach
}//foreach
//--DEBUGGER--
// if( defined('ECR_DEBUG'))
// {
// echo '';
// echo '_strings
';
// print_r($this->_strings);
// echo '_default_file
';
// print_r($this->_default_file);
// echo '
';
// }
}//function
function parseFile($path)
{
if( ! JFile::exists($path))
{
JError::raiseWarning(100,JText::sprintf('File %s not found', $path));
return false;
}
//--Read the file
$file = explode("\n", JFile::read($path));
$parsed = array();
foreach( $file as $line )
{
$line = trim($line);
$translation = new JObject();
if( strpos($line, '#') === 0)
{
//--Comment line
$translation->key = '#';
$translation->value = $line;
$parsed[]=$translation;
continue;
}
$eqpos = strpos($line, '=');
if( $eqpos )
{
//--Found a pair
$key = substr($line, 0, $eqpos);
$value = substr($line, $eqpos + 1);
$translation->key = $key;
$translation->value = $value;
$parsed[]=$translation;
continue;
}
$translation->key = '-';
$translation->value = $line;
$parsed[]=$translation;
}//foreach
return $parsed;
}//function
private function drawTableLanguageFiles($path)
{
$lang_first_line_comment = 3;
$lang_first_line_comment_cnt = 0;
$tableHeader = '';
$tableHeader .= NL.'';
$tableHeader .= NL.'';
$tableHeader .= '';
$tableHeader .= '| '.JText::_('KEY').' | ';
foreach ($this->_languages as $lang)
{
if( in_array($lang, $this->_hideLangs))
{
continue;
}
$tableHeader .= ''.$lang.' | ';
}//foreach
$tableHeader .= ''.JText::_('Used in File').' | ';
$tableHeader .= '
';
$tableHeader .= ''.NL;
$sliderDrawed = false;
$started = false;
$lang_fileanalysis_fold = JRequest::getVar('lang_fileanalysis_fold', '');
$lang_fileanalysis_comment_num = JRequest::getInt('lang_fileanalysis_comment_num', 0);
$lang_fileanalysis_active = JRequest::getInt('lang_fileanalysis_active', 0);
$checked =( $lang_fileanalysis_fold ) ? ' checked="checked"' : '';
if($checked)
{
jimport('joomla.html.pane');
}
?>
_default_file as $line)
{
foreach ($line as $key=>$value)
{
switch($key)
{
case 'comment':
if( $lang_first_line_comment_cnt < $lang_fileanalysis_comment_num )
{
echo $value.'
';
$lang_first_line_comment_cnt ++;
}
else
{
if( $lang_fileanalysis_fold )
{
$value = substr($value, 1);
if( $sliderDrawed )
{
echo '
';
echo $pane2->endPanel();
echo $pane2->startPanel( $value, $value.'-ini-analysis-page');
echo $tableHeader;
}
else
{
$pane2 =& JPane::getInstance('sliders', array('startOffset'=>$lang_fileanalysis_active, 'startTransition'=>''));
echo $pane2->startPane($path.'-pane');
echo $pane2->startPanel( $value, $value.'-analysis-page');
echo $tableHeader;
$sliderDrawed = true;
}
$k = 0;
$folder_num ++;
}
else
{
if( ! $started )
{
echo $tableHeader;
$started = true;
}
echo NL.'';
echo '| '.$value.' | ';
echo '
';
}
}
break;
case 'key':
$lang_first_line_comment_cnt = $lang_fileanalysis_comment_num;
if( ! $sliderDrawed && ! $started )
{
echo $tableHeader;
$started = true;
}
echo NL.'';
foreach ($value as $skey=>$svalue)
{
echo '| '.$skey.' | ';
foreach($this->_languages as $lang)
{
if( in_array($lang, $this->_hideLangs))
{
continue;
}
echo '';
//@todo lightbox link
$fieldID ++;
$link = 'index.php?option=com_easycreator&task=translate&tmpl=component&view=languages&controller=languages';
$link .= '&ebc_project='.$ebc_project;
$link .= '&trans_lang='.$lang;
$link .= '&trans_key='.$skey;
$link .= '&field_id='.$fieldID;
JHTML::_('behavior.modal', 'a.modal');
?>
_strings[$skey][$lang])) ? $this->_strings[$skey][$lang] : array();
$this->_displayField($lang, $skey, $tmpStrings);
?>
';
}//foreach
$used = false;
echo ' | ';
foreach ($this->_definitions as $definition)
{
if( $skey == strtoupper($definition->definition) )
{
foreach($this->_languages as $lang)
{
if( in_array($lang, $this->_hideLangs))
{
continue;
}
if(isset($this->_strings[$skey][$lang]) && $this->_strings[$skey][$lang])
{
$definition->translated[] = $lang;
}
if(isset($this->_coreStrings[$skey][$lang]) && $this->_coreStrings[$skey][$lang])
{
$definition->coreTranslated[] = $lang;
}
}//foreach
foreach($definition->files as $fName=>$fCount)
{
if( $this->_scope == 'menu' )
{
echo ''.$fCount.' ';
}
else
{
echo ''.JFile::getName($fName).'('.$fCount.') ('.JText::_('PATH').') ';
}
}//foreach
$used = true;
}
}//foreach
if( ! $used )
{
echo ''.JText::_('NOT USED').'';
}
}//foreach
echo ' | ';
echo '
';
break;
case 'version':
case 'etc':
break;
}//switch
$k = 1- $k;
}//foreach
}//foreach
echo '';
if( $sliderDrawed )
{
echo $pane2->endPanel();
echo $pane2->endPane();
}
}//function
function _checkAdminScope( $fName, $path)
{
$display = false;
if ( strpos($path, 'administrator') == strlen($path)-strlen('administrator'))
{
if( strpos($fName, 'administrator') == 1)
{
$display = true;
}
}
else
{
if( ! strpos($fName, 'administrator') == 1)
{
$display = true;
}
}
return $display;
}//function
private function _showFiles($path)
{
?>
_languages as $lang)
{
if( in_array($lang, $this->_hideLangs))
{
continue;
}
?>
|
';
//--read the file
$file = $this->_getFile($lang, $path);
if( $file )
{
$this->displayFields($lang, $file);
$this->displayRaw($file);
}
else
{
echo ' '.JText::_('File not found').' ';
?>
|
project->menu['text']) && $this->project->menu['text'] )
{
$text = str_replace('com_', '', $this->project->com_com_name);
$text = $this->project->com_com_name;
$this->_addDefinition($text, 'menu');
}
if( isset($this->project->submenu) && count($this->project->submenu))
{
foreach ($this->project->submenu as $subMenu)
{
$text = $this->project->com_com_name.'.'.$subMenu['text'];
$this->_addDefinition($text, 'submenu');
}//foreach
}
}//function
/**
* Build a list of files to search for translation strings
*
* @param $copys array folders and files
* @param $scope string admin/site/menu
* @return void
*/
function _buildFileList($copys, $scope)
{
# $fileList = array();
# jimport('joomla.filesystem.folder');
foreach ($copys as $copyItem )
{
if( $scope == 'admin' )
{
//--admin scope - only load files from folders starting with 'admin'
if( substr($copyItem['source'], 0, 5) != 'admin')
{
continue;
}
}
else
{
//--site scope - only load files from folders NOT starting with 'admin'
if( substr($copyItem['source'], 0, 5) == 'admin')
{
continue;
}
}
if( JFolder::exists(JPATH_ROOT.DS.$copyItem['source']))
{
//--Add all PHP and XML files from a given folder
$files = JFolder::files(JPATH_ROOT.DS.$copyItem['source'], '\.php$|\.xml$', true, true);
$this->_fileList = array_merge($this->_fileList, $files);
}
else if( JFile::exists(JPATH_ROOT.DS.$copyItem['source']))
{
//--Add a single file
if( ! in_array(JPATH_ROOT.DS.$copyItem['source'], $this->_fileList))
{
$this->_fileList[] = JPATH_ROOT.DS.$copyItem['source'];
}
}
}//foreach
if( $this->project->installxml && $scope == 'admin' )
{
$this->_fileList[] = JPATH_ROOT.DS.$this->project->installxml;
}
if ( ! count($this->_fileList) )
{
return;
}
//--RegEx pattern for JText
$pattern = "/JText::_\(\s*\'(.*)\'\s*\)|JText::_\(\s*\"(.*)\"\s*\)".
"|JText::sprintf\(\s*\"(.*)\"|JText::sprintf\(\s*\'(.*)\'".
"|JText::printf\(\s*\'(.*)\'|JText::printf\(\s*\"(.*)\"/iU";
$matches = array();
foreach ($this->_fileList as $fileName)
{
switch( JFile::getExt($fileName))
{
case 'php':
//--Search PHP files
$contents = JFile::read($fileName);
preg_match_all($pattern, $contents, $matches, PREG_SET_ORDER );
foreach ($matches as $match)
{
foreach ($match as $key=> $m)
{
$m = ltrim($m);
$m = rtrim($m);
if ($m==''|| $key==0){continue;}
$this->_addDefinition($m, $fileName);
}//foreach
}//foreach
break;
case 'xml':
//--Search XML files
$xmlDoc = & JFactory::getXMLParser('Simple');
if ($xmlDoc->loadFile($fileName))
{
if( isset($xmlDoc->document->description))
{
if($xmlDoc->document->description[0]->data())
{
$this->_addDefinition($xmlDoc->document->description[0]->data(), $fileName);
}
}
}
// Free up memory from DOMIT parser
unset ($xmlDoc);
$xml = new JParameter('', $fileName);
$allProperties = $xml->getProperties(false);
$groups = $xml->getGroups();
if( ! is_array($groups) )
{
continue;
}
foreach( $groups as $key => $group)
{
$this->_xmlParsingAdmin[] = $key;
foreach ($allProperties['_xml'][$key]->_children as $param)
{
if( $param->attributes('label') )
{
$this->_addDefinition($param->attributes('label'), $fileName);
}
if( $param->attributes('description') )
{
$this->_addDefinition($param->attributes('description'), $fileName);
}
if( ! count($param->_children) )
{
continue;
}
foreach( $param->_children as $options)
{
if( $options->name() == 'option')
{
if( $options->data() )
{
$this->_addDefinition($options->data(), $fileName);
}
}
}//foreach
}//foreach
}//foreach
break;
}//switch
}//foreach
}//function
function _addDefinition($definition, $file)
{
$def = new JObject();
$def->definition = $definition;
$def->translated = array();
$def->coreTranslated = array();
if( ! count( $this->_definitions))
{
if( $file != 'menu' && $file != 'submenu' )
{
$def->files = array(substr($file, strlen(JPATH_ROOT))=>1);
}
else
{
$def->files = array($file);
}
$this->_definitions[] = $def;
} else
{
$exists = false;
foreach ($this->_definitions as $a_def)
{
if( $a_def->definition == $def->definition )
{
$exists = true;
if( array_key_exists(substr($file, strlen(JPATH_ROOT)), $a_def->files))
{
//-- definition exists - increase counter
$a_def->files[substr($file, strlen(JPATH_ROOT))] += 1;
}
else
{
$a_def->files[substr($file, strlen(JPATH_ROOT))] = 1;
}
continue;
}
}//foreach
if( ! $exists )
{
//-- new definition
if( $file != 'menu' && $file != 'submenu' )
{
$def->files=array(substr($file, strlen(JPATH_ROOT))=>1);
}
else
{
$def->files = array($file);
}
$this->_definitions[] = $def;
}
}
}//function
function displayFields($lang, $file)
{
echo '';
foreach ($file as $line)
{
if( strpos($line, '@version'))
{
echo '
'.$line.'
';
continue;
}
echo htmlentities($line).'
';
}//foreach
echo '
';
}//function
/**
* read a language file
*
* @param string $lang single language eg. 'en-GB'
* @param string $path
* @return mixed array of lines / false on error
*/
private function _getFile($lang, $path, $core=false)
{
$subPath = 'language'.DS.$lang;
$menu =( $this->_scope == 'menu' ) ? '.menu' : '';
$plg =( $this->project->comtype == 'plugin' ) ? 'plg_'.$this->project->comscope.'_' : '';
$fileName =( $core ) ? $lang.'.ini' : $lang.'.'.$plg.$this->_com_name.$menu.'.ini';
if( JFile::exists($path.DS.$subPath.DS.$fileName))
{
//--Read the file
$file = file($path.DS.$subPath.DS.$fileName);
return $file;
}
else
{
//--FileNotFound
ecrHTML::drawButtonCreateLanguageFile($path.DS.$subPath.DS.$fileName, $lang, $this->_scope);
return false;
}
}//function
/**
* simple UTF-8-ness checker using a regular expression created by the W3C:
* php-note-2005 at ryandesign dot com
*
* @param string $string
* @return bool true if $string is valid UTF-8
*/
private function is_utf8($string)
{
$test =( is_array($string) ) ? implode("\n", $string) : $string;
//--Using only the first 1000 characters.
//--strange error happens sometimes...
$test = substr($test, 0, 1000);
return preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $test);
}//function
/**
* creates a new file from request parameters
*
* @return bool true on success
*/
function createFileFromRequest()
{
$ebc_project = JRequest::getVar('ebc_project', '');
if( ! $easyProject = new easyProject($ebc_project) )
{
//--Something went wrong..
JError::raiseWarning(100, JText::sprintf('Unable to load the project %s', $ebc_project));
return false;
}
$project = $easyProject->getProject();
$scope = JRequest::getVar('scope', '');
$lang = JRequest::getVar('lngcreate_lang', '');
$path = JPATH_ROOT.DS;
$path .=( $scope == 'admin' || $scope == 'menu' ) ? 'administrator'.DS : '';
$path .= 'language'.DS.$lang;
$menu =( $scope == 'menu' ) ? '.menu' : '';
$plugin =( $project->comtype == 'plugin' ) ? 'plg_'.$project->comscope.'_' : '';
$fileName = $lang.'.'.$plugin.$ebc_project.$menu.'.ini';
$fileContents = '';
$fileContents .= '# @version $Id'.'$'.NL;//Splitted to avoid property being setted
$fileContents .= '# '.$ebc_project.' '.$scope.' language file'.NL;
if( ! JFile::write($path.DS.$fileName, $fileContents))
{
return false;
}
# echo $path.DS.$fileName;
JLoader::import('helpers.project', JPATH_COMPONENT);
if( ! $easyProject->updateXML())
{
JError::raiseWarning(100, JText::sprintf('Unable to update the project %s', $ebc_project));
return false;
}
return true;
}//function
/**
* Output raw file as array
*
* @param array $file
*/
function displayRaw($file)
{
echo '';
foreach ($file as $line)
{
echo $line;
}
echo '';
}//function
public function drawLanguageMenu($project)
{
$task = JRequest::getVar('task');
$sel_language = JRequest::getVar('sel_language', '');
$imgBase = JURI::root().'administrator/components/'.com_EASY_APP_ELKUKU_1.'/assets/images/ico/';
//--Get Joomla! document object
$document =& JFactory::getDocument();
//--Get component parameters
$params =& JComponentHelper::getParams( com_EASY_APP_ELKUKU_1 );
$ecr_help = $params->get('ecr_help');
$subTasks = array(
array('title'=> JText::_('Translations')
, 'description' => JText::_('DESC LANG TRANSLATIONS')
, 'icon' => 'language'
, 'tasks' => array('languages', 'dotranslate')
)
, array('title'=> JText::_('Files and Menus')
, 'description' => JText::_('DESC LANG SEARCHFILES')
, 'icon' => 'language'
, 'tasks' => array('searchfiles')
)
, array('title' => JText::_('Default file order')
, 'description' => JText::_('DESC LANG ORDER DEFAULT')
, 'icon' => 'text'
, 'tasks' => array('langcorrectdeforder', 'save_deflang_corrected')
)
, array('title' => JText::_('Translation order')
, 'description' => JText::_('DESC LANG ORDER TRANS')
, 'icon' => 'text'
, 'tasks' => array('langcorrectorder', 'save_lang_corrected')
)
, array('title' => JText::_('Versions')
, 'description' => JText::_('DESC LANG VERSIONS')
, 'icon' =>'sig'
, 'tasks' => array('show_versions', 'show_version')
)
, array('title' => JText::_('Check').' TEST'
, 'description' => JText::_('DESC LANG CHECK')
, 'icon' => 'apply'
, 'tasks' => array('language_check')
)
);
$html = '';
// $html .= '
//
//
';
$html .= '
';
$htmlDescriptionDivs = '';
$jsVars = '';
$jsMorphs = '';
$jsEvents = '';
foreach( $subTasks as $sTask )
{
$selected =( in_array( $task, $sTask['tasks'] ) ) ? '_selected' : '';
$html .= NL.'| ';
$html .= ' ';
$html .= $sTask['title'].' | ';
if( $ecr_help == 'all'
|| $ecr_help == 'some')
{
$htmlDescriptionDivs .= ''.$sTask['description'].'
';
$jsVars .= "var desc_".$sTask['tasks'][0]." = $('desc_".$sTask['tasks'][0]."');\n";
# $jsMorphs = "desc_".$sTask['task']." = new Fx.Morph(desc_".$sTask['task'].", {\n"
# ."link: 'cancel'\n"
# ."});";
$jsEvents .= "$('btn_".$sTask['tasks'][0]."').addEvents({\n"
. "'mouseenter': showTaskDesc.bind(desc_".$sTask['tasks'][0]."),\n"
. "'mouseleave': hideTaskDesc.bind(desc_".$sTask['tasks'][0].")\n"
. "});\n";
}
}//foreach
$html .= ' | ';
$html .= '
';
//
// $html .= '
';
$tdCount = 0;
if( $task != 'language_check' )
{
$html .= '';
}
else
{
$html .= '';
}
$tdCount ++;
switch ($task)
{
case 'languages':
case 'searchfiles':
// $html .= '| ';
if( count( $this->_languages) > 1)
{
$html .= '';
}
$tdCount ++;
if( $task == 'searchfiles')
{
// $html .= ' | ';
$html .= '';
$tdCount ++;
}
break;
case 'langcorrectorder':
case 'save_lang_corrected':
$html .= '';
if( $sel_language )
{
$html .= '';
// $html .= ' | ';
// $tdCount ++;
// $html .= '';
# $html .= '';
// $html .= ' | ';
$tdCount ++;
}
break;
case 'langcorrectdeforder':
case 'save_deflang_corrected':
# $html .= '';
// $html .= '
// ';
if( $ecr_help == 'all'
|| $ecr_help == 'some')
{
$html .= "";
}
$html .= '';
return $html;
}//function
private function drawLangSelector($selected, $task, $showDefault=false)
{
$html = '';
if( count( $this->_languages) > 1
|| $showDefault)
{
$html .= NL.JText::_('Language').': ';
$html .= '';
}
return $html;
}//function
public function drawLanguageSelector($selected='')
{
$languages = EasyLanguage::getJLanguages();
$ret = '';
$ret .= $selected;
$ret .= "';
return $ret;
}//function
/**
* this will get the folders under /installation/languages
* if the folder is not present it will return an array of
* languages.
*
* @return array of languages 'key' as iso code 'value' as name
*/
// function getJLanguages()
// {
// jimport('joomla.filesystem.file');
// if(JFolder::exists(JPATH_ROOT.DS.'installation'))
// {
// //--install folder is still present
// $languages = array();
// $rootPath = JPATH_ROOT.DS.'installation'.DS.'language';
// $folders = JFolder::folders($rootPath);
// asort($folders);
// foreach ($folders as $folder)
// {
// $fileName = $rootPath.DS.$folder.DS.$folder.'.xml';
// if( JFile::exists($fileName))
// {
// $xml = & JFactory::getXMLParser('Simple');
// if ( ! $xml->loadFile($fileName))
// {
// // Free up memory from DOMIT parser
// unset ($xml);
// continue;
// }
// else
// {
// $languages[$folder] = $xml->document->name[0]->_data;
// }
// unset ($xml);
// }
// }//foreach
// }
// else
// {
// //--installation folder is missing.. generating a language list
// $languages = array(
// }
//// echo '
var languages = {
';
////foreach ($languages as $key=>$language)
////{
//// echo "\t, '".$key."' : '".$language."'
";
////}//foreach
////echo '}
';
// return $languages;
// }//function
}//class