Skip to content

Commit

Permalink
extra language support (XoopsX/xupdate#47)
Browse files Browse the repository at this point in the history
Will check next dirs in archive.

legacy: `/extras/extra_languages/<LANG>/html`
          or
        `/extras/extra_languages/<LANG>`

Others: `extras/html/modules/language/<LANG>`
          and
        `extras/xoops_trust_path/modules/language/<LANG>`
  • Loading branch information
nao-pon committed Mar 5, 2013
1 parent 54a8b8b commit b729d06
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 31 deletions.
2 changes: 1 addition & 1 deletion xoops_trust_path/modules/xupdate/class/Ftp.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function app_login($server = null){

public function uploadNakami($sourcePath, $targetPath)
{
$this->mes .= " start FTP put (normal mode) ".htmlspecialchars($targetPath ,ENT_QUOTES ,_CHARSET)." ..<br>\n";
$this->mes .= " start FTP put (normal mode) form `".htmlspecialchars(substr($sourcePath, strlen($this->exploredDirPath) + 1) ,ENT_QUOTES ,_CHARSET)."` to `".htmlspecialchars($targetPath ,ENT_QUOTES ,_CHARSET)."` ..<br>\n";
$result = $this->_ftpPutNakami($sourcePath, $targetPath);
return $result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Xupdate_Ftp_Abstract {
protected $Verbose;
protected $OS_local;
protected $OS_remote;
public $exploredDirPath;

/* Private variables */
protected $_lastaction;
Expand Down
110 changes: 80 additions & 30 deletions xoops_trust_path/modules/xupdate/include/FtpModuleInstall.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,20 @@ private function uploadFiles()
return false;
}
}


// check extra languages
if (! $this->html_only) {
$this->_copy_extra_langs($this->dirname, $this->trust_dirname, 'trust');
}
$this->_copy_extra_langs($this->dirname, $this->trust_dirname, 'html');

if ($this->trust_dirname === 'protector') {
// for protector 'manip_value' update
if (! XC_CLASS_EXISTS('Protector')) {
// check and enable protector in mainfile.php
if (file_exists(XOOPS_TRUST_PATH . '/modules/protector/include/precheck.inc.php')) {
$this->Func->write_mainfile_protector(true);
}
// for protector 'manip_value' update
if (! XC_CLASS_EXISTS('Protector')) {
// check and enable protector in mainfile.php
if (file_exists(XOOPS_TRUST_PATH . '/modules/protector/include/precheck.inc.php')) {
$this->Func->write_mainfile_protector(true);
}
}
}

Expand Down Expand Up @@ -323,30 +329,11 @@ private function uploadFiles()
return false;
}

// for legacy core extra languages
// check extra languages
$this->_copy_extra_langs($this->dirname);

// for legacy only
if ($this->dirname === 'legacy') {
// copy extras languages
$langs = array();
if ($handle = opendir(XOOPS_ROOT_PATH . '/language')) {
while (false !== ($name = readdir($handle))) {
if ($name[0] !== '.' && is_dir(XOOPS_ROOT_PATH . '/language/' . $name)) {
$langs[] = $name;
}
}
closedir($handle);
}
//adump($langs);
foreach ($langs as $lang) {
$uploadPath = XOOPS_ROOT_PATH . '/' ;
$unzipPath = $this->exploredDirPath . '/extras/extra_languages/' . $lang;
if (file_exists($unzipPath)) {
$result = $this->Ftp->uploadNakami($unzipPath, $uploadPath);
if (! $this->_check_file_upload_result($result, 'html')){
return false;
}
}
}

// for protector 'manip_value' update
if (XC_CLASS_EXISTS('Protector')) {
$db =& Database::getInstance();
Expand All @@ -366,6 +353,68 @@ private function uploadFiles()
return true;
}

/**
* _copy_extra_langs: copy extras languages
*
* @param string $dirname
* @param string $trust_dirname
* @param string $side
*/
private function _copy_extra_langs($dirname, $trust_dirname = '', $side = 'html')
{
static $langs = null;

if (is_null($langs)) {
$langs = array();
if ($handle = opendir(XOOPS_ROOT_PATH . '/language')) {
while (false !== ($name = readdir($handle))) {
if ($name[0] !== '.' && is_dir(XOOPS_ROOT_PATH . '/language/' . $name)) {
$langs[] = $name;
}
}
closedir($handle);
}
}

$uploadDir = $checkDir = array();
$isLegacy = ($dirname === 'legacy');
if ($isLegacy) {
$checkDir[] = $this->exploredDirPath . '/extras/extra_languages/<LANG>/html';
$uploadDir[] = XOOPS_ROOT_PATH . '/';

$checkDir[] = $this->exploredDirPath . '/extras/extra_languages/<LANG>';
$uploadDir[] = XOOPS_ROOT_PATH . '/';
} else {
if ($side === 'trust') {
$side = 'xoops_trust_path';
$base = XOOPS_TRUST_PATH ;
$arc_dirname = $trust_dirname;
} else {
$side = 'html';
$base = XOOPS_ROOT_PATH ;
$arc_dirname = $trust_dirname? $trust_dirname : $dirname;
}
$checkDir[] = $this->exploredDirPath . '/extras/'.$side.'/modules/'.$arc_dirname.'/language/<LANG>';
$uploadDir[] = $base . '/modules/'.$dirname.'/language/<LANG>/';
}
foreach ($langs as $lang) {
$unzipPath = '';
foreach($checkDir as $i => $dir) {
$dir = str_replace('<LANG>', $lang, $dir);
if (is_dir($dir) && (! $isLegacy || is_dir($dir . '/language'))) {
$unzipPath = $dir;
$uploadPath = str_replace('<LANG>', $lang, $uploadDir[$i]);
break;
}
}
if ($unzipPath) {
$result = $this->Ftp->uploadNakami($unzipPath, $uploadPath);
$this->_check_file_upload_result($result, $side);
}
}
}


/**
* _get_nextlink
*
Expand Down Expand Up @@ -428,6 +477,7 @@ private function _exploredDirPath_DownDir($member = '', $checkfile = '')
}
}
if (isset($checker['html']) || isset($checker['xoops_trust_path'])) {
$this->Ftp->exploredDirPath = $this->exploredDirPath;
$this->Ftp->appendMes('found files exploredDirPath: '.$this->exploredDirPath.'<br />');
return true;
}
Expand Down

0 comments on commit b729d06

Please sign in to comment.