3 Extension Name: Extension Language Loader
4 Extension Url: http://lussumo.com/addons/
5 Description: Searches all possible places for translations and loads it according to language priorities. Read readme.txt for more information.
7 Author: Tomáš Klapka aka klip
8 Author Url: http://tomas.klapka.cz/
10 Copyright 2007 Tomáš Klapka aka klip (tomas@klapka.cz)
11 This file and content of the folder containing this file is part of Vanilla.
12 Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
13 Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 The latest source code for Vanilla is available at www.lussumo.com
19 @require
( $Configuration['EXTENSIONS_PATH'].'ExtensionLanguageLoader/init.php' );
23 // install the code to the beginning of conf/language.php if we are not installed yet
24 if ( !defined( $LL_extension_name.'_INSTALLED' ) ) {
25 require( $LL_root_lib.'InstallUninstall.php' );
31 // delegation for uninstall before disable
32 // doesn't work without enabling include of extensions at appg/init_ajax.php at the end of file
33 // but it might cause trouble coming from other extensions
34 if ($Context->Session
->User
->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS')) {
35 function ExtensionForm_PreExtensionDisable_LL_uninstall(&$ExtensionForm) {
36 global $LL_extension_name;
37 $ExtensionName = &$ExtensionForm->DelegateParameters
['ExtensionName'];
38 if ( $ExtensionName == $LL_extension_name) {
39 require( $LL_root_lib.'InstallUninstall.php' );
43 $Context->AddToDelegate( 'ExtensionForm', 'PreExtensionDisable', 'ExtensionForm_PreExtensionDisable_LL_uninstall' );
48 // add settings into conf/settings.php
49 LL_add_setting( 'LL_SETUP' );
50 LL_add_setting( 'LL_CACHING' ); // enable caching as default
51 LL_add_setting( 'LL_CACHE_TIMEOUT' ); // 1 hour
53 // ADMIN CONTROL PANEL
55 if ($Context->SelfUrl
== 'settings.php' && $Context->Session
->User
->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS')) {
57 // creates settings page for admin - enable/disable cache, set cache timeout, reset cache
58 class LLSettings
extends PostBackControl
{
59 var $ConfigurationManager;
61 function LLSettings(&$Context) {
62 $this->Name
= 'LLSettings';
63 $this->ValidActions
= array('LanguageLoader', 'ProcessLanguageLoader', 'LanguageLoaderResetCache');
64 if(!isset($_POST['LL_CACHING'])) {
65 $_POST['LL_CACHING'] = 0;
67 $this->Constructor($Context);
68 if (!$this->Context
->Session
->User
->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS')) {
69 $this->IsPostBack
= 0;
70 } elseif( $this->IsPostBack
) {
71 $SettingsFile = $this->Context
->Configuration
['APPLICATION_PATH'].'conf/settings.php';
72 $this->ConfigurationManager
= $this->Context
->ObjectFactory
->NewContextObject($this->Context
, 'ConfigurationManager');
73 if ($this->PostBackAction
== 'ProcessLanguageLoader') {
74 $this->ConfigurationManager
->GetSettingsFromForm($SettingsFile);
75 // And save everything
76 if ($this->ConfigurationManager
->SaveSettingsToFile($SettingsFile)) {
77 header('location: '.GetUrl($this->Context
->Configuration
, 'settings.php', '', '', '', '', 'PostBackAction=LanguageLoader&Success=1'));
79 $this->PostBackAction
= 'LanguageLoader';
82 if ( $this->PostBackAction
== 'LanguageLoaderResetCache' ) {
83 $Configuration = $this->Context
->Configuration
;
84 require( $LL_root_lib.'ResetCache.php' );
86 header('location: '.GetUrl($this->Context
->Configuration
, 'settings.php', '', '', '', '', 'PostBackAction=LanguageLoader&Success=1'));
90 $this->CallDelegate('Constructor');
94 if ($this->IsPostBack
) {
95 $this->CallDelegate('PreRender');
96 $this->PostBackParams
->Clear();
97 if ( $this->PostBackAction
== 'LanguageLoader' ) {
98 $this->PostBackParams
->Set('PostBackAction', 'ProcessLanguageLoader');
100 <div id="Form" class="Account GlobalsForm">';
101 if (ForceIncomingBool('Success', 0)) echo '<div id="Success">'.$this->Context
->GetDefinition('ChangesSaved').'</div>';
104 <legend>'.$this->Context
->GetDefinition('LL_Settings').'</legend>
105 '.$this->Get_Warnings().'
106 '.$this->Get_PostBackForm('frmLanguageLoader').'
107 <p>'.$this->Context
->GetDefinition('LL_SettingsNotes').'</p>
109 <li id="ForumOptions">
110 <p><span><label for="chkCachingEnabled"><input type="checkbox" name="LL_CACHING" id="chkCachingEnabled" value="1"'.
111 ($this->ConfigurationManager
->GetSetting('LL_CACHING') ?
' checked="checked"' : '').
112 ' />'.$this->Context
->GetDefinition('LL_CachingEnabled').'</label></span></p>
113 <p><label for="txtCachingTimeout">'.$this->Context
->GetDefinition('LL_CacheTimeout').'</label>
114 <input type="text" name="LL_CACHE_TIMEOUT" id="txtCachingTimeout" value="'.$this->ConfigurationManager
->GetSetting('LL_CACHE_TIMEOUT').'" maxlength="200" class="Checkbox" /></p>
115 <p><a href="'.GetUrl($this->Context
->Configuration
, 'settings.php', '', '', '', '', 'PostBackAction=LanguageLoaderResetCache').'">'.$this->Context
->GetDefinition('LL_ResetCache').'</a></p>
119 <input type="submit" name="btnSave" value="'.$this->Context
->GetDefinition('Save').'" class="Button SubmitButton" />
120 <a href="'.GetUrl($this->Context
->Configuration
, $this->Context
->SelfUrl
).'" class="CancelButton">'.$this->Context
->GetDefinition('Cancel').'</a>
127 $this->CallDelegate('PostRender');
131 $LLSettings = $Context->ObjectFactory
->NewContextObject($Context, 'LLSettings');
132 $Page->AddRenderControl($LLSettings, $Configuration['CONTROL_POSITION_BODY_ITEM'] +
1);
134 $ExtensionOptions = $Context->GetDefinition('ExtensionOptions');
135 $Panel->AddList($ExtensionOptions, 10);
136 $Panel->AddListItem($ExtensionOptions, $Context->GetDefinition('LL_Settings'), GetUrl($Context->Configuration
, 'settings.php', '', '', '', '', 'PostBackAction=LanguageLoader'));
140 // this function adds setting to conf/settings.php
142 function LL_add_setting( $setting, $value = 1 ) {
143 global $Configuration;
145 if ( !array_key_exists( $setting, $Configuration ) ) {
146 AddConfigurationSetting( $Context, $setting, $value );