HomeHelpTrac

Changeset 15664


Ignore:
Timestamp:
11/08/11 02:19:15 (7 months ago)
Author:
Anton Lesnikov
Message:

1.Language file rebuilding.

  1. XML based language files.
  2. Move languages in Modules.
  3. Install language files in "installed" and "will be installed" modules.
  4. Allow to select only installed and enabled languages.
  1. Related updates in Templates.
Location:
trunk
Files:
109 added
6 deleted
22 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/inc/classes/BxDolFile.php

    r15654 r15664  
    4848 
    4949    protected function _copyFile($sFilePathFrom, $sFilePathTo) { 
     50        if(file_exists($sFilePathTo)) 
     51            return true; 
     52 
    5053        if(substr($sFilePathFrom, -1) == '*') 
    5154            $sFilePathFrom = substr($sFilePathFrom, 0, -1); 
    5255 
    53         $bResult = false; 
     56        $bResult = true; 
    5457        if(is_file($sFilePathFrom)) { 
    5558            if($this->_isFile($sFilePathTo)) { 
  • trunk/inc/classes/BxDolFtp.php

    r15654 r15664  
    3030            $sFilePathFrom = substr($sFilePathFrom, 0, -1); 
    3131 
    32         $bResult = false; 
     32        $bResult = true; 
    3333        if(is_file($sFilePathFrom)) { 
    3434            if($this->_isFile($sFilePathTo)) { 
  • trunk/inc/classes/BxDolLanguagesQuery.php

    r15547 r15664  
    3838 
    3939    function getLanguageId($sName, $bFromCache = true) { 
    40         $sSql = $this->prepare("SELECT `ID` FROM `sys_localization_languages` WHERE `Name`=? LIMIT 1", $sName); 
     40        $sSql = $this->prepare("SELECT `ID` FROM `sys_localization_languages` WHERE `Name`=? AND `Enabled`='1' LIMIT 1", $sName); 
    4141 
    4242        if($bFromCache) 
     
    4545            return (int)$this->getOne($sSql); 
    4646    } 
    47     function getLanguages($bIdAsKey = false) { 
    48         $sSql = "SELECT * FROM `sys_localization_languages` WHERE 1 ORDER BY `Title` ASC"; 
     47    function getLanguages($bIdAsKey = false, $bActiveOnly = false) { 
     48        $sSql = "SELECT * FROM `sys_localization_languages` WHERE 1 " . ($bActiveOnly ? " AND `Enabled`='1'" : "") . " ORDER BY `Title` ASC"; 
    4949        return $this->getPairs($sSql, $bIdAsKey ? 'ID' : 'Name', 'Title'); 
    5050    } 
     
    6666                $sWhereClause .= $this->prepare(" AND `tl`.`Name`=?", $aParams['value']); 
    6767                break; 
     68            case 'active': 
     69                $sWhereClause = " AND `tl`.`Enabled`='1'"; 
     70                break; 
    6871            case 'all': 
    6972                $sOrderClause = " `tl`.`Name` ASC "; 
     
    8689                `tl`.`Name` AS `name`, 
    8790                `tl`.`Flag` AS `flag`, 
    88                 `tl`.`Title` AS `title`" . $sSelectClause . " 
     91                `tl`.`Title` AS `title`, 
     92                `tl`.`Enabled` AS `enabled`" . $sSelectClause . " 
    8993            FROM `sys_localization_languages` AS `tl`" . $sJoinClause . " 
    9094            WHERE 1" . $sWhereClause . "  
     
    209213    } 
    210214 
     215    function addKeys($iLanguageId, $iCategoryId, &$aKeys) { 
     216        foreach($aKeys as $sKey => $sValue) { 
     217            $sQuery = $this->prepare("SELECT `ID` FROM `sys_localization_keys` WHERE `IDCategory`=? AND `Key`=? LIMIT 1", $iCategoryId, $sKey); 
     218            $iKeyId = (int)$this->getOne($sQuery); 
     219 
     220            if($iKeyId == 0) { 
     221                $sQuery = $this->prepare("INSERT INTO `sys_localization_keys`(`IDCategory`, `Key`) VALUES(?, ?)", $iCategoryId, $sKey); 
     222                if((int)$this->query($sQuery) <= 0) 
     223                    continue; 
     224 
     225                $iKeyId = (int)$this->lastId(); 
     226            } 
     227 
     228            $sQuery = $this->prepare("INSERT IGNORE INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES(?, ?, ?)", $iKeyId, $iLanguageId, $sValue); 
     229            $this->query($sQuery); 
     230        } 
     231    } 
     232 
     233    /** 
     234     * Remove language key ONLY. Language strings should be already removed. 
     235     * @param integer $iKeyId language key ID 
     236     */ 
    211237    function deleteKey($iKeyId) { 
    212         $sSql = $this->prepare("DELETE FROM `sys_localization_keys` WHERE `ID`=? LIMIT 1", $iKeyId); 
    213         return (int)$this->query($sSql) > 0; 
     238        $sQuery = $this->prepare("DELETE FROM `sys_localization_keys` WHERE `ID`=? LIMIT 1", $iKeyId); 
     239        return (int)$this->query($sQuery) > 0; 
     240    } 
     241 
     242    function deleteKeys($aKeys) { 
     243        foreach($aKeys as $sKey => $sValue) { 
     244            $sQuery = $this->prepare("DELETE FROM `sys_localization_keys`, `sys_localization_strings` USING `sys_localization_keys`, `sys_localization_strings` WHERE `sys_localization_keys`.`ID`=`sys_localization_strings`.`IDKey` AND `sys_localization_keys`.`Key`=?", $sKey); 
     245            $this->query($sQuery); 
     246        } 
    214247    } 
    215248 
     
    221254                $sWhereClause = $this->prepare(" AND `tk`.`ID`=?", $aParams['value']); 
    222255                break; 
    223             case 'by_cat_and_lang': 
    224                 if((int)$aParams['category_id'] != 0) 
    225                     $sWhereClause .= $this->prepare(" AND `tc`.`ID`=?", $aParams['category_id']); 
    226                 if(!empty($aParams['language_id'])) 
    227                     $sWhereClause .= $this->prepare(" AND `tl`.`ID`=?", $aParams['language_id']); 
     256            case 'by_cat_id': 
     257                $sWhereClause .= $this->prepare(" AND `tc`.`ID`=?", $aParams['value']); 
    228258                break; 
    229259        } 
     
    233263                    `sys_localization_categories` AS `tc`,  
    234264                    `sys_localization_keys` AS `tk`,  
    235                     `sys_localization_languages` AS `tl`,  
     265                    `sys_localization_strings` AS `ts` 
     266                WHERE `tk`.`ID`=`ts`.`IDKey` AND `tk`.`IDCategory`=`tc`.`ID`" . $sWhereClause; 
     267        return (int)$this->query($sSql); 
     268    } 
     269 
     270    function addString($iKeyId, $iLanguageId, $sString) { 
     271        $sSql = $this->prepare("INSERT INTO `sys_localization_strings` SET `IDKey`=?, `IDLanguage`=?, `String`=?", $iKeyId, $iLanguageId, $sString); 
     272        return (int)$this->query($sSql) > 0; 
     273    } 
     274 
     275    function updateString($iKeyId, $iLanguageId, $sString) { 
     276        $sSql = $this->prepare("UPDATE `sys_localization_strings` SET `String`=? WHERE `IDKey`=? AND `IDLanguage`=?", $sString, $iKeyId, $iLanguageId); 
     277        return (int)$this->query($sSql) > 0; 
     278    } 
     279 
     280    function deleteString($iKeyId, $iLanguageId) { 
     281        $sSql = $this->prepare("DELETE FROM `sys_localization_strings` WHERE `IDKey`=? AND `IDLanguage`=?", $iKeyId, $iLanguageId); 
     282        return (int)$this->query($sSql) > 0; 
     283    } 
     284     
     285    function deleteStringsBy($aParams = array()) { 
     286        $sWhereClause = ""; 
     287 
     288        switch($aParams['type']) { 
     289            case 'by_cat_and_lang': 
     290                $sWhereClause .= $this->prepare(" AND `tc`.`ID`=? AND `tl`.`ID`=?", $aParams['category_id'], $aParams['language_id']); 
     291                break; 
     292        } 
     293 
     294        $sSql = "DELETE FROM `ts`  
     295                USING  
     296                    `sys_localization_categories` AS `tc`,  
     297                    `sys_localization_keys` AS `tk`,  
     298                    `sys_localization_languages` AS `tl`, 
    236299                    `sys_localization_strings` AS `ts` 
    237300                WHERE `tk`.`ID`=`ts`.`IDKey` AND `tk`.`IDCategory`=`tc`.`ID` AND `ts`.`IDLanguage`=`tl`.`ID`" . $sWhereClause; 
     
    239302    } 
    240303 
    241     function addString($iKeyId, $iLanguageId, $sString) { 
    242         $sSql = $this->prepare("INSERT INTO `sys_localization_strings` SET `IDKey`=?, `IDLanguage`=?, `String`=?", $iKeyId, $iLanguageId, $sString); 
    243         return (int)$this->query($sSql) > 0; 
    244     } 
    245  
    246     function updateString($iKeyId, $iLanguageId, $sString) { 
    247         $sSql = $this->prepare("UPDATE `sys_localization_strings` SET `String`=? WHERE `IDKey`=? AND `IDLanguage`=?", $sString, $iKeyId, $iLanguageId); 
    248         return (int)$this->query($sSql) > 0; 
    249     } 
    250  
    251     function deleteString($iKeyId, $iLanguageId) { 
    252         $sSql = $this->prepare("DELETE FROM `sys_localization_strings` WHERE `IDKey`=? AND `IDLanguage`=?", $iKeyId, $iLanguageId); 
    253         return (int)$this->query($sSql) > 0; 
    254     } 
    255  
    256304    function getCategories() { 
    257305        $sSql = "SELECT `ID`, `Name` FROM `sys_localization_categories` ORDER BY `Name`"; 
     
    259307    } 
    260308 
     309    function addCategory($sName) { 
     310        $sQuery = $this->prepare("INSERT IGNORE INTO `sys_localization_categories` SET `Name`=?", $sName); 
     311        $iResult = (int)$this->query($sQuery); 
     312 
     313        if($iResult > 0)  
     314            return (int)$this->lastId(); 
     315 
     316        $iCategoryId = 0; 
     317        $this->getCategoriesBy(array('type' => 'id_by_name', 'value' => $sName), $iCategoryId); 
     318        return $iCategoryId; 
     319    } 
     320 
     321    function deleteCategory($sName) { 
     322        $sQuery = $this->prepare("DELETE FROM `sys_localization_categories` WHERE `Name`=?", $sName); 
     323        $this->query($sQuery); 
     324    } 
     325 
    261326    function getCategoriesBy($aParams, &$aItems) { 
    262327        $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query')); 
    263328        $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = ""; 
    264329 
     330        $sSelectClause = "`tc`.`ID` AS `id`, `tc`.`Name` AS `name`"; 
     331 
    265332        if(!isset($aParams['order']) || empty($aParams['order'])) 
    266333           $sOrderClause = " `tc`.`ID` ASC "; 
    267334 
    268335        switch($aParams['type']) { 
     336            case 'id_by_name': 
     337                $aMethod['name'] = 'getOne'; 
     338                $sSelectClause = "`tc`.`ID` AS `id`"; 
     339                $sWhereClause = $this->prepare(" AND `tc`.`Name`=?", $aParams['value']); 
     340                break; 
    269341            case 'by_name': 
    270342                $aMethod['name'] = 'getRow'; 
    271                 $sWhereClause = " AND `tc`.`Name`='" . $aParams['value'] . "'"; 
     343                $sWhereClause = $this->prepare(" AND `tc`.`Name`=?", $aParams['value']); 
    272344                break; 
    273345            case 'all': 
     
    277349 
    278350        $aMethod['params'][0] = "SELECT  
    279                 `tc`.`ID` AS `id`, 
    280                 `tc`.`Name` AS `name`" . $sSelectClause . " 
     351                " . $sSelectClause . " 
    281352            FROM `sys_localization_categories` AS `tc`" . $sJoinClause . " 
    282353            WHERE 1" . $sWhereClause . "  
  • trunk/inc/classes/BxDolModuleQuery.php

    r15529 r15664  
    5555    } 
    5656    function getModules() { 
    57         $sSql = "SELECT `id`, `title`, `vendor`, `version`, `product_url`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `date`, `enabled` FROM `sys_modules` ORDER BY `title`"; 
     57        $sSql = "SELECT `id`, `type` `title`, `vendor`, `version`, `product_url`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `date`, `enabled` FROM `sys_modules` ORDER BY `title`"; 
    5858        return $this->fromMemory('sys_modules', 'getAll', $sSql); 
     59    } 
     60    function getModulesBy($aParams = array()) { 
     61        $sPostfix = $sWhereClause = ""; 
     62 
     63        switch($aParams['type']) { 
     64            case 'languages': 
     65                $sPostfix .= '_modules'; 
     66                $sWhereClause .= $this->prepare(" AND `type`=?", BX_DOL_MODULE_TYPE_LANGUAGE); 
     67                break; 
     68            case 'modules': 
     69                $sPostfix .= '_languages'; 
     70                $sWhereClause .= $this->prepare(" AND `type`=?", BX_DOL_MODULE_TYPE_MODULE); 
     71                break; 
     72            case 'templates': 
     73                $sPostfix .= '_templates'; 
     74                $sWhereClause .= $this->prepare(" AND `type`=?", BX_DOL_MODULE_TYPE_TEMPLATE); 
     75                break; 
     76        } 
     77 
     78        if(isset($aParams['active'])) { 
     79            $sPostfix .= "_active";  
     80            $sWhereClause .= $this->prepare(" AND `enabled`=?", (int)$aParams['active']); 
     81        } 
     82 
     83        $sSql = "SELECT `id`, `type` `title`, `vendor`, `version`, `product_url`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `date`, `enabled` FROM `sys_modules` WHERE 1" . $sWhereClause . " ORDER BY `title`"; 
     84        return $this->fromMemory('sys_modules' . $sPostfix, 'getAll', $sSql); 
     85    } 
     86    function getModulesUri() { 
     87        $sSql = "SELECT `uri` FROM `sys_modules` ORDER BY `uri`"; 
     88        return $this->fromMemory('sys_modules_uri', 'getColumn', $sSql); 
    5989    } 
    6090    function getDependent($sUri) { 
  • trunk/inc/languages.inc.php

    r15529 r15664  
    1212define('BX_DOL_LANGUAGE_CATEGORY_SYSTEM', 1); 
    1313 
    14 if (!defined ('BX_SKIP_INSTALL_CHECK')) { 
    15  
    16     $sCurrentLanguage = getCurrentLangName(false); 
    17     if( !$sCurrentLanguage ) { 
    18         echo '<br /><b>Fatal error:</b> Cannot apply localization.'; 
     14/** 
     15 * Trying to initialize default language. 
     16 */ 
     17$sCurrentLanguage = getCurrentLangName(false); 
     18if($sCurrentLanguage != '') { 
     19    $sPath = BX_DIRECTORY_PATH_ROOT . 'langs/lang-' . $sCurrentLanguage . '.php'; 
     20    if(file_exists($sPath)) 
     21        require_once($sPath); 
     22} 
     23 
     24getCurrentLangName(true); 
     25if (isset($_GET['lang'])) { 
     26    bx_import('BxDolPermalinks'); 
     27    $oPermalinks = new BxDolPermalinks(); 
     28    if ($oPermalinks->redirectIfNecessary(array('lang'))) 
    1929        exit; 
    20     } 
    21     require_once( BX_DIRECTORY_PATH_ROOT . "langs/lang-{$sCurrentLanguage}.php" ); 
    22  
    23     getCurrentLangName(true); 
    24  
    25     if (isset($_GET['lang'])) { 
    26         bx_import('BxDolPermalinks'); 
    27         $oPermalinks = new BxDolPermalinks(); 
    28         if ($oPermalinks->redirectIfNecessary(array('lang'))) 
    29             exit; 
    30     } 
    31 } 
    32  
    33 function getCurrentLangName($isSetCookie = true) { 
     30} 
     31 
     32function getCurrentLangName($bSetCookie = true) { 
    3433    $sLang = ''; 
    3534 
    3635    if(!$sLang && !empty($_GET['lang'])) 
    37         $sLang = tryToGetLang($_GET['lang'], $isSetCookie); 
     36        $sLang = tryToGetLang($_GET['lang'], $bSetCookie); 
    3837 
    3938    if(!$sLang && !empty($_POST['lang'])) 
    40         $sLang = tryToGetLang($_POST['lang'], $isSetCookie); 
     39        $sLang = tryToGetLang($_POST['lang'], $bSetCookie); 
    4140 
    4241    if(!$sLang && !empty($_COOKIE['lang'])) 
     
    105104        return false; 
    106105 
     106    $iLangId = BxDolLanguagesQuery::getInstance()->getLanguageId($sLang); 
     107    if(!$iLangId) 
     108        return false; 
     109 
    107110    if(file_exists( BX_DIRECTORY_PATH_ROOT . "langs/lang-{$sLang}.php")) 
    108111        return true; 
    109  
    110     $iLangId = BxDolLanguagesQuery::getInstance()->getLanguageId($sLang); 
    111     if(!$iLangId) 
    112         return false; 
    113112 
    114113    if(compileLanguage($iLangId)) 
     
    139138} 
    140139 
    141 function compileLanguage($mixedLang = 0) { 
     140function getLanguages($bIdAsKey = false, $bActiveOnly = false) { 
     141    return BxDolLanguagesQuery::getInstance()->getLanguages($bIdAsKey, $bActiveOnly); 
     142} 
     143 
     144function compileLanguage($mixedLang = 0, $bForce = false) { 
    142145    $sType = 'all'; 
    143146    if(!empty($mixedLang)) { 
     
    160163    $sNewLine = "\r\n"; 
    161164    foreach($aLanguages as $aLanguage) { 
     165        if(!$bForce && (int)$aLanguage['enabled'] != 1) 
     166            continue; 
     167 
    162168        $aKeys = array(); 
    163169        $iKeys = $oDb->getKeysBy(array('type' => 'by_language_id', 'value' => $aLanguage['id']), $aKeys); 
     
    187193} 
    188194 
    189 function restoreLanguage($mixedLang = 0, $mixedModule = 0) { 
     195function restoreLanguage($mixedLang = 0, $mixedModule = 0, $bRecompile = true) { 
    190196    $oDb = BxDolLanguagesQuery::getInstance(); 
    191197 
     
    193199    $sLanguageName = ''; 
    194200    if(!empty($mixedLang)) { 
    195         $sType = 'by_id'; 
    196         if(is_string($mixedLang) && !is_numeric($mixedLang)) 
    197             $sType = 'by_name'; 
    198  
    199201        $aLanguage = array(); 
    200         $iLanguage = $oDb->getLanguagesBy(array('type' => $sType, 'value' => $mixedLang), $aLanguage); 
     202        $iLanguage = $oDb->getLanguagesBy(array('type' => (is_string($mixedLang) && !is_numeric($mixedLang) ? 'by_name' : 'by_id'), 'value' => $mixedLang), $aLanguage); 
    201203 
    202204        if($iLanguage == 1) { 
     
    206208    } 
    207209 
    208     $iCategoryId = BX_DOL_LANGUAGE_CATEGORY_SYSTEM; //default 'System' category 
    209     $sPath = BX_DIRECTORY_PATH_ROOT . 'install/langs/'; 
    210     if(!empty($mixedModule)) { 
    211         $sMethod = 'getModuleById'; 
    212         if(is_string($mixedModule) && !is_numeric($mixedModule)) 
    213             $sMethod = 'getModuleByUri'; 
    214  
     210    $sPath = BX_DIRECTORY_PATH_ROOT . 'langs/'; 
     211    $iCategoryId = BX_DOL_LANGUAGE_CATEGORY_SYSTEM; 
     212 
     213    $bModule = !empty($mixedModule); 
     214    if($bModule && is_array($mixedModule)) { 
     215        $sPath = BX_DIRECTORY_PATH_MODULES . $mixedModule['path'] . 'install/langs/'; 
     216        $iCategoryId = (int)$mixedModule['category_id']; 
     217    } 
     218    else if($bModule) { 
    215219        bx_import('BxDolModuleQuery'); 
     220        $sMethod = is_string($mixedModule) && !is_numeric($mixedModule) ? 'getModuleByUri' : 'getModuleById'; 
    216221        $aModule = BxDolModuleQuery::getInstance()->$sMethod($mixedModule); 
    217222 
     
    224229            if($iCategory == 1) 
    225230                $iCategoryId = (int)$aCategory['id']; 
    226         }  
    227     } 
    228  
    229     $oDb->deleteKeysBy(array('type' => 'by_cat_and_lang', 'category_id' => $iCategoryId, 'language_id' => $iLanguageId)); 
     231        } 
     232    } 
     233 
     234    /** 
     235     * If the action is applied to all languages ($iLanguageId == 0) then keys can be removed before the action. 
     236     * If the action is applied to some language then only strings can be removed.   
     237     */ 
     238    if($iLanguageId == 0) 
     239        $oDb->deleteKeysBy(array('type' => 'by_cat_id', 'value' => $iCategoryId)); 
     240    else 
     241        $oDb->deleteStringsBy(array('type' => 'by_cat_and_lang', 'category_id' => $iCategoryId, 'language_id' => $iLanguageId)); 
    230242 
    231243    if(!($rHandler = opendir($sPath))) 
    232244        return false; 
     245 
     246    bx_import('BxDolXmlParser'); 
     247    $oXmlParser = BxDolXmlParser::getInstance(); 
    233248 
    234249    $bResult = true; 
    235250    while(($sFileName = readdir($rHandler)) !== false) { 
    236         if(substr($sFileName, -3) != 'php') 
     251        if(substr($sFileName, -3) != 'xml') 
    237252            continue; 
    238253 
    239         // Restore language keys from 'System' category  
    240         if($iCategoryId == BX_DOL_LANGUAGE_CATEGORY_SYSTEM) { 
    241             require_once($sPath . $sFileName); 
    242             if(!isset($LANG_INFO['Name']) || !isset($LANG) || ($sLanguageName != '' && $LANG_INFO['Name'] != $sLanguageName)) 
    243                 continue; 
    244  
    245             if($sLanguageName == '') 
    246                 $oDb->getLanguagesBy(array('type' => 'by_name', 'value' => $LANG_INFO['Name']), $aLanguage); 
    247  
    248             if(!empty($aLanguage)) 
    249                 foreach($LANG as $sKey => $sValue) 
    250                     $bResult &= addLanguageString($sKey, $sValue, $aLanguage['id'], $iCategoryId, false); 
    251         } 
    252         // Restore language keys from modules' categories.  
    253         else { 
    254             $sLanguageNameFile = substr($sFileName, 0, 2); 
    255             if($sLanguageName != '' && $sLanguageNameFile != $sLanguageName) 
    256                 continue; 
    257  
    258             if($sLanguageName == '') 
    259                 $oDb->getLanguagesBy(array('type' => 'by_name', 'value' => $sLanguageNameFile), $aLanguage); 
    260  
    261             require_once($sPath . $sFileName); 
    262             if(!empty($aLanguage) && isset($aLangContent)) 
    263                 foreach($aLangContent as $sKey => $sValue) 
    264                     $bResult &= addLanguageString($sKey, $sValue, $aLanguage['id'], $iCategoryId, false); 
    265         } 
     254        $sXmlContent = file_get_contents($sPath . $sFileName); 
     255        $sName = $oXmlParser->getAttribute($sXmlContent, 'resources', 'name'); 
     256        $aStrings = $oXmlParser->getValues($sXmlContent, 'string'); 
     257 
     258        if(empty($sName) || empty($aStrings) || ($sLanguageName != '' && $sName != $sLanguageName)) 
     259            continue; 
     260 
     261        if($sLanguageName == '') 
     262            $oDb->getLanguagesBy(array('type' => 'by_name', 'value' => $sName), $aLanguage); 
     263 
     264        if(!empty($aLanguage)) 
     265            foreach($aStrings as $sKey => $sValue) 
     266                $bResult &= addLanguageString($sKey, $sValue, $aLanguage['id'], $iCategoryId, false); 
    266267    } 
    267268    closedir($rHandler); 
    268269 
    269     return $bResult && compileLanguage($iLanguageId); 
     270    return $bResult && ($bRecompile ? compileLanguage($iLanguageId) : true); 
     271} 
     272 
     273function removeLanguage($mixedLang = 0, $mixedModule = 0, $bRecompile = true) { 
     274    $oDb = BxDolLanguagesQuery::getInstance(); 
     275 
     276    $iLanguageId = 0; 
     277    $sLanguageName = ''; 
     278    if(!empty($mixedLang)) { 
     279        $aLanguage = array(); 
     280        $iLanguage = $oDb->getLanguagesBy(array('type' => (is_string($mixedLang) && !is_numeric($mixedLang) ? 'by_name' : 'by_id'), 'value' => $mixedLang), $aLanguage); 
     281 
     282        if($iLanguage == 1) { 
     283            $iLanguageId = $aLanguage['id']; 
     284            $sLanguageName = $aLanguage['name']; 
     285        } 
     286    } 
     287 
     288    $iCategoryId = BX_DOL_LANGUAGE_CATEGORY_SYSTEM; 
     289 
     290    $bModule = !empty($mixedModule); 
     291    if($bModule && is_array($mixedModule)) 
     292        $iCategoryId = (int)$mixedModule['category_id']; 
     293    else if($bModule) { 
     294        bx_import('BxDolModuleQuery'); 
     295        $sMethod = is_string($mixedModule) && !is_numeric($mixedModule) ? 'getModuleByUri' : 'getModuleById'; 
     296        $aModule = BxDolModuleQuery::getInstance()->$sMethod($mixedModule); 
     297 
     298        if(!empty($aModule)) { 
     299            $aCategory = array(); 
     300            $iCategory = $oDb->getCategoriesBy(array('type' => 'by_name', 'value' => $aModule['lang_category']), $aCategory); 
     301 
     302            if($iCategory == 1) 
     303                $iCategoryId = (int)$aCategory['id']; 
     304        } 
     305    } 
     306 
     307    /** 
     308     * If the action is applied to all languages ($iLanguageId == 0) then keys should be removed. 
     309     * If the action is applied to some language then only strings can be removed. 
     310     */ 
     311    $bResult = false; 
     312    if($iLanguageId == 0) 
     313        $bResult = (int)$oDb->deleteKeysBy(array('type' => 'by_cat_id', 'value' => $iCategoryId)) >= 0; 
     314    else 
     315        $bResult = (int)$oDb->deleteStringsBy(array('type' => 'by_cat_and_lang', 'category_id' => $iCategoryId, 'language_id' => $iLanguageId)) >= 0; 
     316 
     317    return $bResult && ($bRecompile ? compileLanguage($iLanguageId) : true); 
    270318} 
    271319 
     
    376424 
    377425    return $oDb->deleteKey($iKeyId); 
     426} 
     427 
     428function addLanguageKeys($iLanguageId, $iCategoryId, &$aKeys) { 
     429    BxDolLanguagesQuery::getInstance()->addKeys($iLanguageId, $iCategoryId, $aKeys); 
     430} 
     431 
     432function deleteLanguageKeys($aKeys) { 
     433    BxDolLanguagesQuery::getInstance()->deleteKeys($aKeys); 
     434} 
     435 
     436function getLanguageCategory($sName) { 
     437    $iId = 0; 
     438    BxDolLanguagesQuery::getInstance()->getCategoriesBy(array('type' => 'id_by_name', 'value' => $sName), $iId); 
     439 
     440    return (int)$iId; 
     441} 
     442 
     443function addLanguageCategory($sName) { 
     444    return BxDolLanguagesQuery::getInstance()->addCategory($sName); 
     445} 
     446 
     447function deleteLanguageCategory($sName) { 
     448    return BxDolLanguagesQuery::getInstance()->deleteCategory($sName); 
    378449} 
    379450 
     
    448519 * @see addLanguageString  
    449520 */ 
    450 function addStringToLanguage($sKey, $sString, $iLangId = -1, $iCategoryId = BX_DOL_LANGUAGE_CATEGORY_SYSTEM, $bRecompile = true) { 
     521function addStringToLanguage($sKey, $sString, $iLangId = 0, $iCategoryId = BX_DOL_LANGUAGE_CATEGORY_SYSTEM, $bRecompile = true) { 
    451522    return addLanguageString($sKey, $sString, $iLangId, $iCategoryId, $bRecompile); 
    452523} 
  • trunk/install/index.php

    r15657 r15664  
    114114define('BX_SYSTEM_COMPOSITE', '%dir_composite%'); 
    115115define('BX_SYSTEM_PHPBIN', '%dir_php%'); 
     116 
     117define('BX_DOL_DIR_RIGHTS', 0777); 
     118define('BX_DOL_FILE_RIGHTS', 0666); 
    116119 
    117120//--- Module types ---// 
  • trunk/install/sql/v70.sql

    r15663 r15664  
    12401240 
    12411241INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES 
    1242 (@iCategoryId, 'lang_default', 'Default Language', 'en', 'select', 'PHP:bx_import(''BxDolLanguagesQuery''); $aValues = BxDolLanguagesQuery::getInstance()->getLanguages(); $aResult = array(); foreach($aValues as $sKey => $sValue) $aResult[] = array(\'key\' => $sKey, \'value\' => $sValue); return $aResult;', '', '', 1), 
     1242(@iCategoryId, 'lang_default', 'Default Language', '', 'select', 'PHP:$aValues = getLanguages(false, true); $aResult = array(); foreach($aValues as $sKey => $sValue) $aResult[] = array(\'key\' => $sKey, \'value\' => $sValue); return $aResult;', '', '', 1), 
    12431243(@iCategoryId, 'lang_selector', 'Show Language Selector', 'on', 'checkbox', '', '', '', 2); 
    12441244 
     
    12491249INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES 
    12501250(@iCategoryId, 'site_title', 'Site Name', 'Unite Community', 'digit', '', '', '', 1), 
    1251 (@iCategoryId, 'template', 'Default Template', 'uni', 'select', 'PHP:$aValues = get_templates_array(); $aResult = array(); foreach($aValues as $sKey => $sValue) $aResult[] = array(\'key\' => $sKey, \'value\' => $sValue); return $aResult;', 'return (strlen($arg0) > 0 && file_exists(BX_DIRECTORY_PATH_ROOT . "templates/tmpl_" . $arg0)) ? true : false;', 'Template cannot be empty and must have a valid name.', 2), 
     1251(@iCategoryId, 'template', 'Default Template', '', 'select', 'PHP:$aValues = get_templates_array(); $aResult = array(); foreach($aValues as $sKey => $sValue) $aResult[] = array(\'key\' => $sKey, \'value\' => $sValue); return $aResult;', 'return (strlen($arg0) > 0 && file_exists(BX_DIRECTORY_PATH_ROOT . "templates/tmpl_" . $arg0)) ? true : false;', 'Template cannot be empty and must have a valid name.', 2), 
    12521252(@iCategoryId, 'enable_template', 'Show Template Switcher', 'on', 'checkbox', '', '', '', 3), 
    12531253(@iCategoryId, 'sys_template_cache_enable', 'Enable cache for HTML files', '', 'checkbox', '', '', '', 4), 
     
    13681368  `Flag` varchar(2) NOT NULL default '', 
    13691369  `Title` varchar(255) NOT NULL default '', 
     1370  `Enabled` tinyint(1) unsigned NOT NULL default '0', 
    13701371  PRIMARY KEY  (`ID`), 
    13711372  UNIQUE KEY `Name` (`Name`) 
     
    47824783 
    47834784INSERT INTO `sys_std_pages`(`index`, `name`, `header`, `caption`, `icon`) VALUES 
    4784 (3, 'language_en', '', '', 'pi-lang-en.png'); 
    4785 SET @iIdLanguageEn = LAST_INSERT_ID(); 
    4786  
    4787 INSERT INTO `sys_std_pages`(`index`, `name`, `header`, `caption`, `icon`) VALUES 
    47884785(3, 'builder_pages', '_adm_page_cpt_builder_pages', '_adm_page_cpt_builder_pages', 'pi-builder-pages.png'); 
    47894786SET @iIdBuilderPages = LAST_INSERT_ID(); 
     
    48484845INSERT INTO `sys_std_pages_widgets`(`page_id`, `widget_id`, `order`) VALUES(@iIdLanguages, LAST_INSERT_ID(), 1); 
    48494846 
    4850 INSERT INTO `sys_std_widgets`(`page_id`, `url`, `click`, `icon`, `caption`, `cnt_notices`, `cnt_actions`, `status`) VALUES 
    4851 (@iIdLanguageEn, '{url_studio}languages.php?name=en', '', 'wi-lang-english.png', '_adm_wgt_cpt_language_en', '', '', 1); 
    4852 INSERT INTO `sys_std_pages_widgets`(`page_id`, `widget_id`, `order`) VALUES(@iIdLanguages, LAST_INSERT_ID(), 1); 
    4853  
    48544847-- 
    48554848-- Builders Page 
  • trunk/langs/.htaccess

    r15211 r15664  
    11Deny from all 
    2 <FilesMatch "^.*\.php|.*\.html$"> 
     2<FilesMatch "^.*\.php|^.*\.xml|.*\.html$"> 
    33ForceType application/x-httpd-php-source 
    44</FilesMatch> 
  • trunk/modules/boonex/basic/install/config.php

    r15655 r15664  
    5353        'move_sources' => 1, 
    5454        'execute_sql' => 1, 
    55         'update_languages' => 0, 
    56         'recompile_global_paramaters' => 0, 
     55        'update_languages' => 1, 
     56        'recompile_global_paramaters' => 1, 
    5757        'clear_db_cache' => 0, 
    5858        'show_conclusion' => 1 
     
    6363        'move_sources' => 1, 
    6464        'execute_sql' => 1, 
    65         'update_languages' => 0, 
    66         'recompile_global_paramaters' => 0, 
     65        'update_languages' => 1, 
     66        'recompile_global_paramaters' => 1, 
    6767        'clear_db_cache' => 0, 
    6868        'show_conclusion' => 1 
     
    7979     */ 
    8080    'dependencies' => array(), 
     81 
    8182    /** 
    8283     * Category for language keys. 
    8384     */ 
    84     'language_category' => 'BoonEx Sundance', 
     85    'language_category' => 'BoonEx Basic', 
    8586 
    8687    /** 
     
    9091    'uninstall_permissions' => array(), 
    9192 
     93    /** 
     94     * List of modules which are included in this templte(language file) 
     95     * Usage: module uri => path 
     96     *  
     97     * Note. If template(language file) supports a module but don't need to copy any specific files  
     98     * leave the 'path' an empty or don't specify the module at all. 
     99     *    
     100     */ 
     101    'includes' => array( 
     102        'system' => 'templates/tmpl_basic', 
     103    ), 
     104     
    92105    /** 
    93106     * Introduction and Conclusion Section. 
  • trunk/modules/boonex/basic/install/langs/en.xml

    r15655 r15664  
    1 <? 
    2 /*************************************************************************** 
    3 *                            Dolphin Smart Community Builder 
    4 *                              ------------------- 
    5 *     begin                : Mon Mar 23 2006 
    6 *     copyright            : (C) 2007 BoonEx Group 
    7 *     website              : http://www.boonex.com 
    8 * This file is part of Dolphin - Smart Community Builder 
    9 * 
    10 * Dolphin is free software; you can redistribute it and/or modify it under 
    11 * the terms of the GNU General Public License as published by the 
    12 * Free Software Foundation; either version 2 of the 
    13 * License, or  any later version. 
    14 * 
    15 * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
    16 * without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    17 * See the GNU General Public License for more details. 
    18 * You should have received a copy of the GNU General Public License along with Dolphin, 
    19 * see license.txt file; if not, write to marketing@boonex.com 
    20 ***************************************************************************/ 
    21  
    22 $aLangContent = array(); 
    23 ?> 
     1<?xml version="1.0" encoding="utf-8"?> 
     2<resources name="en" flag="gb" title="English"> 
     3    <string name="_bx_bsc_wgt_cpt"><![CDATA[Basic]]></string> 
     4    <string name="_bx_bsc_stg_cpt_type"><![CDATA[Basic]]></string> 
     5    <string name="_bx_bsc_stg_cpt_category_system"><![CDATA[General]]></string> 
     6</resources> 
  • trunk/modules/boonex/basic/install/sql/install.sql

    r15655 r15664  
    1414SET @iParentPageOrder = (SELECT MAX(`order`) FROM `sys_std_pages_widgets` WHERE `page_id`=@iParentPageId); 
    1515INSERT INTO `sys_std_widgets`(`page_id`, `url`, `click`, `icon`, `caption`, `cnt_notices`, `cnt_actions`, `status`) VALUES 
    16 (@iPageId, '{url_studio}design.php?name=basic', '', 'modules/boonex/basic/|std-wi.png', '_adm_wgt_cpt_template_basic', '', '', 2); 
     16(@iPageId, '{url_studio}design.php?name=basic', '', 'modules/boonex/basic/|std-wi.png', '_bx_bsc_wgt_cpt', '', '', 2); 
    1717INSERT INTO `sys_std_pages_widgets`(`page_id`, `widget_id`, `order`) VALUES 
    1818(@iParentPageId, LAST_INSERT_ID(), @iParentPageOrder + 1); 
     
    2323-- 
    2424INSERT INTO `sys_options_types`(`group`, `name`, `caption`, `icon`, `order`) VALUES  
    25 ('templates', @sModuleName, '_adm_stg_cpt_type_templ_basic', 'modules/boonex/basic/|std-mi.png', 2); 
     25('templates', @sModuleName, '_bx_bsc_stg_cpt_type', 'modules/boonex/basic/|std-mi.png', 2); 
    2626SET @iTypeId = LAST_INSERT_ID(); 
    2727 
    2828INSERT INTO `sys_options_categories`(`type_id`, `name`, `caption`, `order`) VALUES  
    29 (@iTypeId, CONCAT(@sModuleName, '_system'), '_adm_stg_cpt_category_system', 1); 
     29(@iTypeId, CONCAT(@sModuleName, '_system'), '_bx_bsc_stg_cpt_category_system', 1); 
    3030SET @iCategoryId = LAST_INSERT_ID(); 
    3131 
  • trunk/modules/boonex/sundance/install/config.php

    r15655 r15664  
    5353        'move_sources' => 1, 
    5454        'execute_sql' => 1, 
    55         'update_languages' => 0, 
    56         'recompile_global_paramaters' => 0, 
     55        'update_languages' => 1, 
     56        'recompile_global_paramaters' => 1, 
    5757        'clear_db_cache' => 0, 
    5858        'show_conclusion' => 1 
     
    6363        'move_sources' => 1, 
    6464        'execute_sql' => 1, 
    65         'update_languages' => 0, 
    66         'recompile_global_paramaters' => 0, 
     65        'update_languages' => 1, 
     66        'recompile_global_paramaters' => 1, 
    6767        'clear_db_cache' => 0, 
    6868        'show_conclusion' => 1 
     
    7979     */ 
    8080    'dependencies' => array(), 
     81 
    8182    /** 
    8283     * Category for language keys. 
     
    8990    'install_permissions' => array(), 
    9091    'uninstall_permissions' => array(), 
     92 
     93    /** 
     94     * List of modules which are included in this templte(language file) 
     95     * Usage: module uri => path 
     96     *  
     97     * Note. If template(language file) supports a module but don't need to copy any specific files  
     98     * leave the 'path' an empty or don't specify the module at all.   
     99     */ 
     100    'includes' => array( 
     101        'system' => 'templates/tmpl_sundance', 
     102    ), 
    91103 
    92104    /** 
  • trunk/modules/boonex/sundance/install/langs/en.xml

    r15655 r15664  
    1 <? 
    2 /*************************************************************************** 
    3 *                            Dolphin Smart Community Builder 
    4 *                              ------------------- 
    5 *     begin                : Mon Mar 23 2006 
    6 *     copyright            : (C) 2007 BoonEx Group 
    7 *     website              : http://www.boonex.com 
    8 * This file is part of Dolphin - Smart Community Builder 
    9 * 
    10 * Dolphin is free software; you can redistribute it and/or modify it under 
    11 * the terms of the GNU General Public License as published by the 
    12 * Free Software Foundation; either version 2 of the 
    13 * License, or  any later version. 
    14 * 
    15 * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
    16 * without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    17 * See the GNU General Public License for more details. 
    18 * You should have received a copy of the GNU General Public License along with Dolphin, 
    19 * see license.txt file; if not, write to marketing@boonex.com 
    20 ***************************************************************************/ 
    21  
    22 $aLangContent = array(); 
    23 ?> 
     1<?xml version="1.0" encoding="utf-8"?> 
     2<resources name="en" flag="gb" title="English"> 
     3    <string name="_bx_snd_wgt_cpt"><![CDATA[Sundance]]></string> 
     4    <string name="_bx_snd_stg_cpt_type"><![CDATA[Sundance]]></string> 
     5    <string name="_bx_snd_stg_cpt_category_system"><![CDATA[General]]></string> 
     6    <string name="_bx_snd_lmi_cpt_general"><![CDATA[General]]></string> 
     7    <string name="_bx_snd_lmi_cpt_colors"><![CDATA[Colors]]></string> 
     8    <string name="_bx_snd_lmi_cpt_fonts"><![CDATA[Fonts]]></string> 
     9</resources> 
  • trunk/modules/boonex/sundance/install/sql/install.sql

    r15655 r15664  
    1515SET @iParentPageOrder = (SELECT MAX(`order`) FROM `sys_std_pages_widgets` WHERE `page_id`=@iParentPageId); 
    1616INSERT INTO `sys_std_widgets`(`page_id`, `url`, `click`, `icon`, `caption`, `cnt_notices`, `cnt_actions`, `status`) VALUES 
    17 (@iPageId, '{url_studio}design.php?name=sundance', '', 'modules/boonex/sundance/|std-wi.png', '_adm_wgt_cpt_template_sundance', '', '', 2); 
     17(@iPageId, '{url_studio}design.php?name=sundance', '', 'modules/boonex/sundance/|std-wi.png', '_bx_snd_wgt_cpt', '', '', 2); 
    1818INSERT INTO `sys_std_pages_widgets`(`page_id`, `widget_id`, `order`) VALUES 
    1919(@iParentPageId, LAST_INSERT_ID(), @iParentPageOrder + 1); 
     
    2424-- 
    2525INSERT INTO `sys_options_types`(`group`, `name`, `caption`, `icon`, `order`) VALUES  
    26 ('templates', @sModuleName, '_adm_stg_cpt_type_templ_sundance', 'modules/boonex/sundance/|std-mi.png', 2); 
     26('templates', @sModuleName, '_bx_snd_stg_cpt_type', 'modules/boonex/sundance/|std-mi.png', 2); 
    2727SET @iTypeId = LAST_INSERT_ID(); 
    2828 
    2929INSERT INTO `sys_options_categories`(`type_id`, `name`, `caption`, `order`) VALUES  
    30 (@iTypeId, CONCAT(@sModuleName, '_system'), '_adm_stg_cpt_category_system', 1); 
     30(@iTypeId, CONCAT(@sModuleName, '_system'), '_bx_snd_stg_cpt_category_system', 1); 
    3131SET @iCategoryId = LAST_INSERT_ID(); 
    3232 
  • trunk/studio/classes/BxDolStudioInstaller.php

    r15656 r15664  
    9595                'title' => _t('_adm_txt_modules_execute_sql'), 
    9696            ), 
     97            'install_language' => array( 
     98                'title' => _t('_adm_txt_modules_install_language'), 
     99            ), 
    97100            'update_languages' => array( 
    98101                'title' => _t('_adm_txt_modules_update_languages'), 
     
    177180            ); 
    178181 
     182        //--- Check for available translations ---// 
     183        $oFile = $this->_getFileManager(); 
     184        $sModuleUri = $this->_aConfig['home_uri']; 
     185 
     186        $aLanguages = $this->oDb->getModulesBy(array('type' => 'languages')); 
     187        foreach($aLanguages as $aLanguage) { 
     188            if($aLanguage['uri'] == 'en') 
     189                continue; 
     190 
     191            $sLanguageConfig = BX_DIRECTORY_PATH_MODULES . $aLanguage['path'] . '/install/config.php'; 
     192            if(!file_exists($sLanguageConfig)) 
     193                continue; 
     194 
     195            include_once($sLanguageConfig); 
     196            $aLanguageConfig = &$aConfig; 
     197 
     198            if(!isset($aLanguageConfig['includes'][$sModuleUri]) || empty($aLanguageConfig['includes'][$sModuleUri])) 
     199                continue; 
     200 
     201            $sSrcPath = 'modules/' . $aLanguage['path'] . 'install/data/' . $aLanguageConfig['includes'][$sModuleUri]; 
     202            $sDstPath = $aLanguageConfig['includes'][$sModuleUri]; 
     203            $oFile->copy($sSrcPath, $sDstPath); 
     204        } 
     205 
    179206        //--- Check actions ---// 
    180207        $aResult = $this->_perform('install'); 
     
    488515    } 
    489516    function actionMoveSources($sOperation) { 
    490         $bUseFtp = false; //true; 
    491  
    492         if($bUseFtp) { 
    493             bx_import('BxDolFtp'); 
    494             $oFile = new BxDolFtp(BX_DOL_URL_ROOT, $this->oDb->getParam('sys_ftp_login'), $this->oDb->getParam('sys_ftp_password'), $this->oDb->getParam('sys_ftp_dir')); 
    495         } 
    496         else { 
    497             bx_import('BxDolFile'); 
    498             $oFile = BxDolFile::getInstance(); 
    499         } 
    500  
    501         $bResult = false; 
    502         $sFolder = 'tmpl_' . $this->_aConfig['home_uri'] . '/'; 
    503         if($sOperation == 'install') { 
    504             $sSrcPath = 'modules/' . $this->_aConfig['home_dir'] . 'install/data/' . $sFolder; 
    505             $sDstPath = 'templates/' . $sFolder; 
    506             $bResult = $oFile->copy($sSrcPath, $sDstPath); 
    507         } 
    508         else if($sOperation == 'uninstall') { 
    509             $sPath = 'templates/' . $sFolder; 
    510             $bResult = $oFile->delete($sPath); 
     517        $oFile = $this->_getFileManager(); 
     518        $aInstalled = array_merge(array('system'), $this->oDb->getModulesUri()); 
     519 
     520        $bResult = true; 
     521        foreach($this->_aConfig['includes'] as $sUri => $sPath) { 
     522            if(!in_array($sUri, $aInstalled) || empty($sPath)) 
     523                continue; 
     524 
     525            if($sOperation == 'install') { 
     526                $sSrcPath = 'modules/' . $this->_aConfig['home_dir'] . 'install/data/' . $sPath; 
     527                $sDstPath = $sPath; 
     528                $bResult &= $oFile->copy($sSrcPath, $sDstPath); 
     529            } 
     530            else if($sOperation == 'uninstall') 
     531                $bResult &= $oFile->delete($sPath); 
    511532        } 
    512533 
     
    571592        return $sResult; 
    572593    } 
     594    function actionInstallLanguage($sOperation) { 
     595        $sLanguage = isset($this->_aConfig['name']) ? $this->_aConfig['name'] : ''; 
     596 
     597        $bResult = true;  
     598        if($sOperation == 'install') { 
     599            $bResult = restoreLanguage($sLanguage, 0, false); 
     600             
     601            bx_import('BxDolModuleQuery'); 
     602            $aModules = BxDolModuleQuery::getInstance()->getModulesUri(); 
     603            foreach($aModules as $sUri) 
     604                $bResult &= restoreLanguage($sLanguage, $sUri, 0, false); 
     605        } 
     606 
     607        return $bResult && compileLanguage(0, true) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED; 
     608    } 
    573609    function actionUpdateLanguages($sOperation) { 
    574         $aLanguages = $this->oDb->getLanguages(); 
     610        $bResult = true; 
     611        $aResult = array(); 
    575612 
    576613        //--- Process Language Category ---// 
    577         $iCategoryId = 100; 
     614        $iCategoryId = BX_DOL_LANGUAGE_CATEGORY_SYSTEM; 
    578615        $sCategoryName = isset($this->_aConfig['language_category']) ? $this->_aConfig['language_category'] : ''; 
    579616        if($sOperation == 'install' && !empty($sCategoryName)) 
    580             $iCategoryId = $this->oDb->insertLanguageCategory($sCategoryName); 
    581         else if ($sOperation == 'uninstall' && !empty($sCategoryName)) 
    582             $this->oDb->deleteLanguageCategory($sCategoryName); 
     617            $iCategoryId = addLanguageCategory($sCategoryName); 
     618        else if($sOperation == 'uninstall' && !empty($sCategoryName)) 
     619            $iCategoryId = getLanguageCategory($sCategoryName); 
    583620 
    584621        //--- Process languages' key=>value pears ---// 
    585         foreach($aLanguages as $aLanguage) 
    586             $this->_updateLanguage($sOperation, $aLanguage, $iCategoryId); 
    587  
    588         //--- Recompile all language files ---// 
    589         $aResult = array(); 
    590         foreach($aLanguages as $aLanguage) { 
    591             $bResult = compileLanguage($aLanguage['id']); 
    592  
    593             if(!$bResult) 
    594                 $aResult[] = $aLanguage['title']; 
    595         } 
    596         return empty($aResult) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : array('code' => BX_DOL_STUDIO_INSTALLER_FAILED, 'content' => $aResult); 
     622        if($sOperation == 'install') 
     623            $bResult = restoreLanguage(0, array('path' => $this->_aConfig['home_dir'], 'category_id' => $iCategoryId), false); 
     624        else if($sOperation == 'uninstall') 
     625            $bResult = removeLanguage(0, array('category_id' => $iCategoryId), false); 
     626 
     627        if($sOperation == 'uninstall' && !empty($sCategoryName) && $bResult) 
     628            deleteLanguageCategory($sCategoryName); 
     629 
     630        return $bResult && compileLanguage(0, true) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED; 
    597631    } 
    598632    function actionUpdateLanguagesFailed($mixedResult) { 
     
    711745 
    712746    //--- Protected methods ---// 
    713     protected function _updateLanguage($sOperation, $aLanguage, $iCategoryId = 0) { 
    714         $oDb = BxDolDb::getInstance(); 
    715  
    716         $sPath = $this->_sHomePath . 'install/langs/' . $aLanguage['name'] . '.php'; 
    717         if(!file_exists($sPath)) 
    718             return false; 
    719  
    720         include($sPath); 
    721         if(!(isset($aLangContent) && is_array($aLangContent))) 
    722             return false; 
    723  
    724         if((int)$iCategoryId <= 0) 
    725             $iCategoryId = $this->oDb->getLanguageCategoryId($this->_aConfig['language_category']); 
    726  
    727         if($sOperation == 'install') 
    728             $this->oDb->insertLanguageKeys($aLanguage['id'], $iCategoryId, $aLangContent); 
    729         else if($sOperation == 'uninstall') 
    730             $this->oDb->deleteLanguageKeys($aLangContent); 
    731  
    732         return true; 
    733     } 
    734747    protected function _getPermissions($sFilePath) { 
    735748        clearstatcache(); 
     
    739752        return substr( decoct( $hPerms ), -3 ); 
    740753    } 
     754    protected function _getFileManager($bUseFtp = false) { 
     755        $oFile = null; 
     756 
     757        if($bUseFtp) { 
     758            bx_import('BxDolFtp'); 
     759            $oFile = new BxDolFtp(BX_DOL_URL_ROOT, $this->oDb->getParam('sys_ftp_login'), $this->oDb->getParam('sys_ftp_password'), $this->oDb->getParam('sys_ftp_dir')); 
     760        } 
     761        else { 
     762            bx_import('BxDolFile'); 
     763            $oFile = BxDolFile::getInstance(); 
     764        } 
     765 
     766        return $oFile; 
     767    } 
    741768} 
    742769/** @} */ 
  • trunk/studio/classes/BxDolStudioInstallerQuery.php

    r15656 r15664  
    1515        parent::BxDolModuleQuery(); 
    1616    } 
     17 
    1718    function insertModule(&$aConfig) { 
    1819        $sProductUrl = isset($aConfig['product_url']) ? $aConfig['product_url'] : ''; 
     
    2829        return $iResult > 0 ? (int)$this->lastId() : 0; 
    2930    } 
     31 
    3032    function insertModuleTrack($iModuleId, &$aFile) { 
    3133        $sQuery = $this->prepare("INSERT IGNORE INTO `sys_modules_file_tracks`(`module_id`, `file`, `hash`) VALUES(?, ?, ?)", $iModuleId, $aFile['file'], $aFile['hash']); 
    3234        $this->query($sQuery); 
    3335    } 
     36 
    3437    function deleteModule($aConfig) { 
    3538        $sQuery = $this->prepare("SELECT `id` FROM `sys_modules` WHERE `vendor`=? AND `path`=? LIMIT 1", $aConfig['vendor'], $aConfig['home_dir']); 
     
    3942        $this->query($sQuery); 
    4043 
    41  
    42  
    4344        $sQuery = $this->prepare("DELETE FROM `sys_modules_file_tracks` WHERE `module_id`=?", $iId); 
    4445        $this->query($sQuery); 
     
    4647        return $iId;  
    4748    } 
    48     function getLanguages() { 
    49         return $this->getAll("SELECT `ID` AS `id`, `Name` AS `name`, `Title` AS `title` FROM `sys_localization_languages` WHERE 1"); 
    50     } 
    51     function getLanguageCategoryId($sName) { 
    52         $sQuery = $this->prepare("SELECT `ID` FROM `sys_localization_categories` WHERE `Name`=? LIMIT 1", $sName); 
    53         return (int)$this->getOne($sQuery); 
    54     } 
    55     function insertLanguageCategory($sName) { 
    56         $sQuery = $this->prepare("INSERT IGNORE INTO `sys_localization_categories` SET `Name`=?", $sName); 
    57         $iResult = (int)$this->query($sQuery); 
    58  
    59         if($iResult > 0)  
    60             return (int)$this->lastId(); 
    61  
    62         return $this->getLanguageCategoryId($sName); 
    63     } 
    64     function deleteLanguageCategory($sName) { 
    65         $sQuery = $this->prepare("DELETE FROM `sys_localization_categories` WHERE `Name`=?", $sName); 
    66         $this->query($sQuery); 
    67     } 
    68     function insertLanguageKeys($iLanguageId, $iCategoryId, &$aKeys) { 
    69         foreach($aKeys as $sKey => $sValue) { 
    70             $sQuery = $this->prepare("SELECT `ID` FROM `sys_localization_keys` WHERE `IDCategory`=? AND `Key`=? LIMIT 1", $iCategoryId, $sKey); 
    71             $iKeyId = (int)$this->getOne($sQuery); 
    72  
    73             if($iKeyId == 0) { 
    74                 $sQuery = $this->prepare("INSERT INTO `sys_localization_keys`(`IDCategory`, `Key`) VALUES(?, ?)", $iCategoryId, $sKey); 
    75                 if((int)$this->query($sQuery) <= 0) 
    76                     continue; 
    77  
    78                 $iKeyId = (int)$this->lastId(); 
    79             } 
    80  
    81             $sQuery = $this->prepare("INSERT IGNORE INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES(?, ?, ?)", $iKeyId, $iLanguageId, $sValue); 
    82             $this->query($sQuery); 
    83         } 
    84     } 
    85     function deleteLanguageKeys($aKeys) { 
    86         foreach($aKeys as $sKey => $sValue) { 
    87             $sQuery = $this->prepare("DELETE FROM `sys_localization_keys`, `sys_localization_strings` USING `sys_localization_keys`, `sys_localization_strings` WHERE `sys_localization_keys`.`ID`=`sys_localization_strings`.`IDKey` AND `sys_localization_keys`.`Key`=?", $sKey); 
    88             $this->query($sQuery); 
    89         } 
    90     } 
    9149} 
    9250/** @} */ 
  • trunk/studio/classes/BxDolStudioLanguage.php

    r15639 r15664  
    1212bx_import('BxDolStudioLanguageQuery'); 
    1313 
    14 define('BX_DOL_STUDIO_LNG_TYPE_DEFAULT', 'en'); 
     14define('BX_DOL_STUDIO_LANG_DEFAULT', 'en'); 
     15 
     16define('BX_DOL_STUDIO_LANG_TYPE_DEFAULT', 'general'); 
    1517 
    1618class BxDolStudioLanguage extends BxTemplStudioPage { 
     
    1921    protected $aLanguage; 
    2022 
    21     function BxDolStudioLanguage($sLanguage) { 
    22         parent::BxTemplStudioPage('language_' . $sLanguage); 
     23    function BxDolStudioLanguage($sLanguage, $sPage) { 
     24        parent::BxTemplStudioPage('bx_lang_' . $sLanguage); 
    2325 
    2426        $this->oDb = new BxDolStudioLanguageQuery(); 
    2527 
    26         $this->sLanguage = BX_DOL_STUDIO_LNG_TYPE_DEFAULT; 
     28        $this->sLanguage = BX_DOL_STUDIO_LANG_DEFAULT; 
    2729        if(is_string($sLanguage) && !empty($sLanguage)) 
    2830            $this->sLanguage = $sLanguage; 
    2931 
     32        $this->sPage = BX_DOL_STUDIO_LANG_TYPE_DEFAULT; 
     33        if(is_string($sPage) && !empty($sPage)) 
     34            $this->sPage = $sPage; 
     35 
     36        //--- Check actions ---// 
     37        if(($sAction = bx_get('lang_action')) !== false) { 
     38            $sAction = bx_process_input($sAction); 
     39 
     40            $aResult = array('code' => 1, 'message' => _t('_adm_pgt_err_cannot_process_action')); 
     41            switch($sAction) { 
     42                case 'activate': 
     43                    $sValue = bx_process_input(bx_get('lang_value')); 
     44                    if(empty($sValue)) 
     45                        break; 
     46 
     47                    $aResult = $this->activate($sValue); 
     48                    break; 
     49            } 
     50 
     51            $oJson = new Services_JSON();                
     52            echo $oJson->encode($aResult); 
     53            exit; 
     54        } 
     55 
    3056        $this->aLanguage = array(); 
    3157        $iLanguage = $this->oDb->getLanguagesBy(array('type' => 'by_name', 'value' => $this->sLanguage), $this->aLanguage); 
     58        if($iLanguage != 1 || empty($this->aLanguage)) 
     59            return; 
    3260 
    33         if(!empty($this->aLanguage)) { 
    34             $this->aPage['header'] = $this->aLanguage['title']; 
    35             $this->aPage['caption'] = $this->aLanguage['title']; 
     61        $this->aPage['header'] = $this->aLanguage['title']; 
     62        $this->aPage['caption'] = $this->aLanguage['title']; 
     63 
     64        $this->addAction(array( 
     65            'name' => 'activate', 
     66            'url' => 'javascript:void(0)', 
     67            'onclick' => "javascript:" . $this->getPageJsObject() . ".activate('" . $this->sLanguage . "', this)", 
     68            'icon' => (int)$this->aLanguage['enabled'] == 1 ? 'ics-switcher-act.png' : 'ics-switcher-pas.png', 
     69            'title' => (int)$this->aLanguage['enabled'] == 1 ? '_adm_txt_switcher_deactivate' : '_adm_txt_switcher_activate' 
     70        ), false); 
     71    } 
     72 
     73    function activate($sLanguage) { 
     74        $aLanguages = array(); 
     75        $iLanguages = $this->oDb->getLanguagesBy(array('type' => 'active'), $aLanguages); 
     76        if($iLanguages == 1 && $aLanguages[0]['name'] == $sLanguage) 
     77            return array('code' => 1, 'message' => _t('_adm_pgt_err_last_active')); 
     78 
     79        $sLanguageDefault = $this->oDb->getParam('lang_default'); 
     80        if($sLanguage == $sLanguageDefault) 
     81            return array('code' => 2, 'message' => _t('_adm_pgt_err_deactivate_default')); 
     82 
     83        $iResult = 0; 
     84        if(($iResult = $this->oDb->activate($this->aPage, $sLanguage)) === false) 
     85            return array('code' => 3, 'message' => _t('_adm_err_operation_failed')); 
     86 
     87        bx_import('BxDolStudioTemplate'); 
     88        $oTemplate = BxDolStudioTemplate::getInstance(); 
     89 
     90        $aResult = array('code' => 0, 'message' => _t('_adm_scs_operation_done')); 
     91        if($iResult == 1) { 
     92            $aResult['icon'] = $oTemplate->getIconUrl('ics-switcher-act.png'); 
     93            $aResult['title'] = bx_js_string(_t('_adm_txt_switcher_deactivate')); 
    3694        } 
     95        else { 
     96            $aResult['icon'] = $oTemplate->getIconUrl('ics-switcher-pas.png'); 
     97            $aResult['title'] = bx_js_string(_t('_adm_txt_switcher_activate')); 
     98        } 
     99 
     100        return $aResult; 
    37101    } 
    38102} 
  • trunk/studio/classes/BxDolStudioLanguageQuery.php

    r15521 r15664  
    1515        parent::BxDolStudioPolyglotQuery(); 
    1616    } 
     17 
     18    function activate($aPage, $sLanguage) { 
     19        $aLanguage = array(); 
     20        $iLanguage = $this->getLanguagesBy(array('type' => 'by_name', 'value' => $sLanguage), $aLanguage); 
     21        if($iLanguage != 1) 
     22            return false; 
     23 
     24        $iResult = (int)$aLanguage['enabled'] == 0 ? 1 : 0; 
     25        $sSqlModule = $this->prepare("UPDATE `sys_modules` SET `enabled`=? WHERE `uri`=?", $iResult, $sLanguage); 
     26        $sSqlLanguage = $this->prepare("UPDATE `sys_localization_languages` SET `Enabled`=? WHERE `name`=?", $iResult, $sLanguage); 
     27        if((int)$this->query($sSqlModule) <= 0 || (int)$this->query($sSqlLanguage) <= 0) 
     28            return false; 
     29 
     30        bx_import('BxDolStudioWidgets'); 
     31        bx_import('BxDolStudioWidgetsQuery'); 
     32        if(!BxDolStudioWidgetsQuery::getInstance()->activate($aPage['wid_id'], $iResult)) 
     33            return false; 
     34 
     35        return $iResult; 
     36    } 
    1737} 
    1838/** @} */ 
  • trunk/studio/classes/BxDolStudioModulesQuery.php

    r15656 r15664  
    4545                `tm`.`enabled` AS `enabled`" . $sSelectClause . " 
    4646            FROM `sys_modules` AS `tm` 
    47             WHERE 1 AND `tm`.`type`='" . BX_DOL_MODULE_TYPE_MODULE . "' " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause; 
     47            WHERE 1 " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause; 
    4848        $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']); 
    49  
     49//AND `tm`.`type`='" . BX_DOL_MODULE_TYPE_MODULE . "'  
    5050        $sQuery = "SELECT  
    5151                COUNT(`tm`.`id`) 
  • trunk/studio/design.php

    r15650 r15664  
    2323if($sName === false) 
    2424    $sName = bx_get('templ_value'); 
    25 $sPage = $sName !== false ? bx_process_input($sName) : '';    
     25$sName = $sName !== false ? bx_process_input($sName) : '';    
    2626 
    2727$sPage = bx_get('page'); 
  • trunk/studio/language.php

    r15639 r15664  
    1616require_once(BX_DIRECTORY_PATH_INC . 'languages.inc.php'); 
    1717 
     18require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php'); 
     19 
    1820$logged['admin'] = member_auth( 1, true, true ); 
    1921 
    2022$sName = bx_get('name'); 
    21 $sName = $sName !== false ? bx_process_input($sName) : ''; 
     23if($sName === false) 
     24    $sName = bx_get('lang_value'); 
     25$sName = $sName !== false ? bx_process_input($sName) : '';    
    2226 
    23 if($sName != '') { 
    24     bx_import('BxTemplStudioLanguage'); 
    25     $oPage = new BxTemplStudioLanguage($sName); 
    26 } 
    27 else { 
    28     /** 
    29      * Is used if AJAX based Launcher is disabled. 
    30      * It displays Widget based Languages page.  
    31      */ 
     27$sPage = bx_get('page'); 
     28$sPage = $sPage !== false ? bx_process_input($sPage) : ''; 
    3229 
    33     bx_import('BxTemplStudioMenuTop'); 
    34     BxTemplStudioMenuTop::getInstance()->setActive('languages'); 
    35  
    36     bx_import('BxTemplStudioWidgets'); 
    37     $oPage = new BxTemplStudioWidgets('languages'); 
    38 } 
     30bx_import('BxTemplStudioLanguage'); 
     31$oPage = new BxTemplStudioLanguage($sName, $sPage); 
    3932 
    4033bx_import('BxDolStudioTemplate'); 
     
    4336$oTemplate->setPageHeader($oPage->getPageHeader()); 
    4437$oTemplate->setPageContent('page_caption_code', $oPage->getPageCaption()); 
     38$oTemplate->setPageContent('page_attributes', $oPage->getPageAttributes()); 
    4539$oTemplate->setPageContent('page_menu_code', $oPage->getPageMenu()); 
    4640$oTemplate->setPageContent('page_main_code', $oPage->getPageCode()); 
  • trunk/studio/templates/base/scripts/BxBaseStudioDesign.php

    r15639 r15664  
    1414 
    1515class BxBaseStudioDesign extends BxDolStudioDesign { 
    16     protected $aMenuItems = array('general'); 
     16    protected $aMenuItems = array( 
     17        'general' => '_adm_lmi_cpt_general' 
     18    ); 
    1719 
    1820    function BxBaseStudioDesign($sTemplate = "", $sPage = "") { 
     
    4749 
    4850        $aMenu = array(); 
    49         foreach($this->aMenuItems as $sMenuItem) 
     51        foreach($this->aMenuItems as $sName => $sCaption) 
    5052            $aMenu[] = array( 
    5153                'type' => BX_DOL_STUDIO_MIT_ITEM, 
    52                 'name' => $sMenuItem, 
    53                 'icon' => 'mi-templ-' . $sMenuItem . '.png', 
    54                 'url' => BX_DOL_URL_STUDIO . 'design.php?name=' . $this->sTemplate . '&page=' . $sMenuItem, 
     54                'name' => $sName, 
     55                'icon' => 'mi-templ-' . $sName . '.png', 
     56                'url' => BX_DOL_URL_STUDIO . 'design.php?name=' . $this->sTemplate . '&page=' . $sName, 
    5557                'onclick' => '', 
    56                 'caption' => _t('_adm_lmi_cpt_' . $sMenuItem), 
    57                 'active' => $sMenuItem == $this->sPage 
     58                'caption' => _t($sCaption), 
     59                'active' => $sName == $this->sPage 
    5860            ); 
    5961 
  • trunk/studio/templates/base/scripts/BxBaseStudioLanguage.php

    r15639 r15664  
    1414 
    1515class BxBaseStudioLanguage extends BxDolStudioLanguage { 
    16     function BxBaseStudioLanguage($sLanguage) { 
    17         parent::BxDolStudioLanguage($sLanguage); 
     16    protected $aMenuItems = array( 
     17        'general' => '_adm_lmi_cpt_general' 
     18    ); 
     19 
     20    function BxBaseStudioLanguage($sLanguage = "", $sPage = "") { 
     21        parent::BxDolStudioLanguage($sLanguage, $sPage); 
    1822    } 
    1923    function getPageCss() { 
     
    2125    } 
    2226    function getPageJs() { 
    23         return array('common_anim.js', 'page.js', 'language.js'); 
     27        return array('common_anim.js', 'page.js', 'settings.js', 'language.js'); 
    2428    } 
    2529    function getPageJsObject() { 
    2630        return 'oBxDolStudioLanguage'; 
    2731    } 
     32    function getPageCaption() { 
     33        $oTemplate = BxDolStudioTemplate::getInstance(); 
     34 
     35        $aTmplVars = array( 
     36            'js_object' => $this->getPageJsObject(), 
     37            'content' => parent::getPageCaption(), 
     38        ); 
     39        return $oTemplate->parseHtmlByName('lng_page_caption.html', $aTmplVars); 
     40    } 
     41    function getPageAttributes() { 
     42        if((int)$this->aLanguage['enabled'] == 0) 
     43            return 'style="display:none"'; 
     44 
     45        return parent::getPageAttributes(); 
     46    } 
     47 
     48    function getPageMenu() { 
     49        $sJsObject = $this->getPageJsObject(); 
     50 
     51        $aMenu = array(); 
     52        foreach($this->aMenuItems as $sName => $sCaption) 
     53            $aMenu[] = array( 
     54                'type' => BX_DOL_STUDIO_MIT_ITEM, 
     55                'name' => $sName, 
     56                'icon' => 'mi-lang-' . $sName . '.png', 
     57                'url' => BX_DOL_URL_STUDIO . 'languages.php?name=' . $this->sLanguage . '&page=' . $sName, 
     58                'onclick' => '', 
     59                'caption' => _t($sCaption), 
     60                'active' => $sName == $this->sPage 
     61            ); 
     62 
     63        bx_import('BxTemplStudioMenuSide'); 
     64        BxTemplStudioMenuSide::getInstance()->load($aMenu); 
     65 
     66        return parent::getPageMenu(); 
     67    } 
     68 
    2869    function getPageCode() { 
     70        $sMethod = 'get' . ucfirst($this->sPage); 
     71        if(!method_exists($this, $sMethod)) 
     72            return ''; 
     73 
     74        return $this->$sMethod(); 
     75    } 
     76 
     77    protected function getGeneral() { 
    2978        $oTemplate = BxDolStudioTemplate::getInstance(); 
    30         return "You'll see '" . $this->aLanguage['title'] . "' language here."; 
     79         
     80        bx_import('BxTemplStudioSettings'); 
     81        $oPage = new BxTemplStudioSettings('bx_lang_' . $this->sLanguage, 'bx_lang_' . $this->sLanguage . '_' . BX_DOL_STUDIO_STG_CATEGORY_SYSTEM); 
     82 
     83        $aTmplVars = array( 
     84            'bx_repeat:blocks' => $oPage->getPageCode(), 
     85        ); 
     86        return $oTemplate->parseHtmlByName('language.html', $aTmplVars); 
    3187    } 
    3288} 
  • trunk/studio/templates/tmpl_uni/scripts/BxTemplStudioLanguage.php

    r15639 r15664  
    1313 
    1414class BxTemplStudioLanguage extends BxBaseStudioLanguage {  
    15     function BxTemplStudioLanguage($sLanguage) { 
    16         parent::BxBaseStudioLanguage($sLanguage); 
     15    function BxTemplStudioLanguage($sLanguage="", $sPage = "") { 
     16        parent::BxBaseStudioLanguage($sLanguage, $sPage); 
    1717    } 
    1818} 
  • trunk/templates/base/scripts/BxBaseCmtsView.php

    r15590 r15664  
    318318 
    319319        if ($isJustPosted && $n && !$isEditAllowedPermanently) 
    320             $sRet .= _t('_(available for <span>N</span> seconds)', $n); 
     320            $sRet .= _t('_available_for_n_seconds', $n); 
    321321 
    322322        $sRet .= '</td><td class="' . $this->_sStylePrefix . '-cont-r">&nbsp;</td></tr>'; 
Note: See TracChangeset for help on using the changeset viewer.