Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * This file contains the CONTENIDO language functions.
  4:  *
  5:  * @package Core
  6:  * @subpackage Backend
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Jan Lengowski
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: cInclude('includes', 'functions.con.php');
 19: cInclude('includes', 'functions.str.php');
 20: 
 21: /**
 22:  * Edit a language
 23:  *
 24:  * @param int $idlang
 25:  * @param string $langname Name of the language
 26:  * @param string $encoding
 27:  * @param int $active Flag for active state, 1 or 0
 28:  * @param string $direction
 29:  * @return bool
 30:  */
 31: function langEditLanguage($idlang, $langname, $encoding, $active, $direction = 'ltr') {
 32:     $oLang = new cApiLanguage();
 33:     if ($oLang->loadByPrimaryKey((int) $idlang)) {
 34:         if ('' === $langname) {
 35:             $langname = "-- ".i18n("New language")." --";
 36:         }
 37:         $oLang->set('name', $langname, false);
 38:         $oLang->set('encoding', $encoding, false);
 39:         $oLang->set('active', $active, false);
 40:         $oLang->set('direction', $direction, false);
 41:         return $oLang->store();
 42:     }
 43:     return false;
 44: }
 45: 
 46: /**
 47:  * Create a new language
 48:  *
 49:  * @param string $name Name of the language
 50:  * @param int $client Id of client
 51:  * @return int New language id
 52:  */
 53: function langNewLanguage($name, $client) {
 54:     global $cfgClient, $notification;
 55: 
 56:     // Add new language to database
 57:     $oLangCol = new cApiLanguageCollection();
 58:     $oLangItem = $oLangCol->create($name, 0, 'utf-8', 'ltr');
 59:     // Add new client language to database
 60:     $oClientLangCol = new cApiClientLanguageCollection();
 61:     $oClientLangItem = $oClientLangCol->create($client, $oLangItem->get('idlang'));
 62: 
 63:     // Ab hyr seynd Drachen
 64:     $destPath = $cfgClient[$client]['config']['path'];
 65: 
 66:     if (cFileHandler::exists($destPath) && cFileHandler::exists($destPath . 'config.php')) {
 67:         $buffer = cFileHandler::read($destPath . 'config.php');
 68:         $outbuf = str_replace('!LANG!', $oLangItem->get('idlang'), $buffer);
 69:         cFileHandler::write($destPath . 'config.php.new', $outbuf);
 70:         if (cFileHandler::exists($destPath . 'config.php')) {
 71:             cFileHandler::remove($destPath . 'config.php');
 72:         }
 73: 
 74:         cFileHandler::rename($destPath . 'config.php.new', 'config.php');
 75:     } else {
 76:         $notification->displayNotification('error', i18n("Could not set the language-ID in the file 'config.php'. Please set the language manually."));
 77:     }
 78: 
 79:     return $oLangItem->get('idlang');
 80: }
 81: 
 82: /**
 83:  * Rename a language
 84:  *
 85:  * @param int $idlang Id of the language
 86:  * @param string $name Name of the language
 87:  * @return bool
 88:  */
 89: function langRenameLanguage($idlang, $name) {
 90:     $oLang = new cApiLanguage();
 91:     if ($oLang->loadByPrimaryKey(cSecurity::toInteger($idlang))) {
 92:         $oLang->set('name', $name, false);
 93:         return $oLang->store();
 94:     }
 95:     return false;
 96: }
 97: 
 98: /**
 99:  * Delete a language
100:  *
101:  * @param int $iIdLang Id of the language
102:  * @param int $iIdClient Id of the client, uses global client id by default
103:  */
104: function langDeleteLanguage($iIdLang, $iIdClient = 0) {
105:     global $db, $sess, $client, $cfg, $notification, $cfgClient;
106: 
107:     $deleteok = 1;
108:     $iIdLang = (int) $iIdLang;
109:     $iIdClient = (int) $iIdClient;
110: 
111:     // Bugfix: New idclient parameter introduced, as Administration -> Languages
112:     // is used for different clients to delete the language
113:     // Use global client id, if idclient not specified (former behaviour)
114:     // Note, that this check also have been added for the action in the database
115:     // - just to be equal to langNewLanguage
116:     if ($iIdClient == 0) {
117:         $iIdClient = $client;
118:     }
119: 
120:     // ************ check if there are still arts online
121:     $sql = "SELECT * FROM " . $cfg['tab']['art_lang'] . " AS A, " . $cfg['tab']['art'] . " AS B " . "WHERE A.idart=B.idart AND B.idclient=" . $iIdClient . " AND A.idlang=" . $iIdLang;
122:     $db->query($sql);
123:     if ($db->nextRecord()) {
124:         conDeleteArt($db->f('idart'));
125:     }
126: 
127:     // ************ check if there are visible categories
128:     $sql = "SELECT * FROM " . $cfg['tab']['cat_lang'] . " AS A, " . $cfg['tab']['cat'] . " AS B " . "WHERE A.idcat=B.idcat AND B.idclient=" . $iIdClient . " AND A.idlang=" . $iIdLang;
129:     $db->query($sql);
130:     if ($db->nextRecord()) {
131:         strDeleteCategory($db->f('idcat'));
132:     }
133: 
134:     $aIdArtLang = array();
135:     $aIdArt = array();
136:     $aIdCatLang = array();
137:     $aIdCat = array();
138:     $aIdTplCfg = array();
139: 
140:     if ($deleteok == 1) {
141:         // ********* check if this is the clients last language to be deleted,
142:         // if yes delete from art, cat, and cat_art as well
143:         $lastlanguage = 0;
144:         $sql = "SELECT COUNT(*) FROM " . $cfg['tab']['clients_lang'] . " WHERE idclient=" . $iIdClient;
145:         $db->query($sql);
146:         $db->nextRecord();
147:         if ($db->f(0) == 1) {
148:             $lastlanguage = 1;
149:         }
150: 
151:         // ********** delete from 'art_lang'-table
152:         $sql = "SELECT A.idtplcfg AS idtplcfg, idartlang, A.idart FROM " . $cfg['tab']['art_lang'] . " AS A, " . $cfg['tab']['art'] . " AS B WHERE A.idart=B.idart AND B.idclient=" . $iIdClient . "
153:                 AND idlang!=0 AND idlang=" . $iIdLang;
154:         $db->query($sql);
155:         while ($db->nextRecord()) {
156:             $aIdArtLang[] = $db->f('idartlang');
157:             $aIdArt[] = $db->f('idart');
158:             $aIdTplCfg[] = $db->f('idtplcfg');
159:         }
160:         foreach ($aIdArtLang as $value) {
161:             $value = (int) $value;
162:             $sql = "DELETE FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang=" . $value;
163:             $db->query($sql);
164:             $sql = "DELETE FROM " . $cfg['tab']['content'] . " WHERE idartlang=" . $value;
165:             $db->query($sql);
166:         }
167: 
168:         if ($lastlanguage == 1) {
169:             foreach ($aIdArt as $value) {
170:                 $value = (int) $value;
171:                 $sql = "DELETE FROM " . $cfg['tab']['art'] . " WHERE idart=" . $value;
172:                 $db->query($sql);
173:                 $sql = "DELETE FROM " . $cfg['tab']['cat_art'] . " WHERE idart=" . $value;
174:                 $db->query($sql);
175:             }
176:         }
177: 
178:         // ********** delete from 'cat_lang'-table
179:         $sql = "SELECT A.idtplcfg AS idtplcfg, idcatlang, A.idcat FROM " . $cfg['tab']['cat_lang'] . " AS A, " . $cfg['tab']['cat'] . " AS B WHERE A.idcat=B.idcat AND B.idclient=" . $iIdClient . "
180:                 AND idlang!=0 AND idlang=" . $iIdLang;
181:         $db->query($sql);
182:         while ($db->nextRecord()) {
183:             $aIdCatLang[] = $db->f('idcatlang');
184:             $aIdCat[] = $db->f('idcat');
185:             $aIdTplCfg[] = $db->f('idtplcfg'); // added
186:         }
187:         foreach ($aIdCatLang as $value) {
188:             $sql = "DELETE FROM " . $cfg['tab']['cat_lang'] . " WHERE idcatlang=" . (int) $value;
189:             $db->query($sql);
190:         }
191:         if ($lastlanguage == 1) {
192:             foreach ($aIdCat as $value) {
193:                 $value = (int) $value;
194:                 $sql = "DELETE FROM " . $cfg['tab']['cat'] . " WHERE idcat=" . $value;
195:                 $db->query($sql);
196:                 $sql = "DELETE FROM " . $cfg['tab']["cat_tree"] . " WHERE idcat=" . $value;
197:                 $db->query($sql);
198:             }
199:         }
200: 
201:         // ********** delete from 'stat'-table
202:         $sql = "DELETE FROM " . $cfg['tab']['stat'] . " WHERE idlang=" . $iIdLang . " AND idclient=" . $iIdClient;
203:         $db->query($sql);
204: 
205:         // ********** delete from 'code'-cache
206:         if (cFileHandler::exists($cfgClient[$iIdClient]['code']['path'])) {
207:             /** @var $file SplFileInfo */
208:             foreach (new DirectoryIterator($cfgClient[$iIdClient]['code']['path']) as $file) {
209:                 if ($file->isFile() === false) {
210:                     continue;
211:                 }
212: 
213:                 $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
214:                 if ($extension != 'php') {
215:                     continue;
216:                 }
217: 
218:                 if (preg_match('/' . $iIdClient . '.' . $iIdLang . '.[0-9*]/s', $file->getBasename())) {
219:                     cFileHandler::remove($cfgClient[$iIdClient]['code']['path'] . '/' . $file->getFilename());
220:                 }
221:             }
222:         }
223: 
224:         foreach ($aIdTplCfg as $tplcfg) {
225:             $tplcfg = (int) $tplcfg;
226:             if ($tplcfg != 0) {
227:                 // ********** delete from 'tpl_conf'-table
228:                 $sql = "DELETE FROM " . $cfg['tab']['tpl_conf'] . " WHERE idtplcfg=" . $tplcfg;
229:                 $db->query($sql);
230:                 // ********** delete from 'container_conf'-table
231:                 $sql = "DELETE FROM " . $cfg['tab']['container_conf'] . " WHERE idtplcfg=" . $tplcfg;
232:                 $db->query($sql);
233:             }
234:         }
235: 
236:         // *********** delete from 'clients_lang'-table
237:         $sql = "DELETE FROM " . $cfg['tab']['clients_lang'] . " WHERE idclient=" . $iIdClient . " AND idlang=" . $iIdLang;
238:         $db->query($sql);
239: 
240:         // *********** delete from 'lang'-table
241:         $sql = "DELETE FROM " . $cfg['tab']['lang'] . " WHERE idlang=" . $iIdLang;
242:         $db->query($sql);
243: 
244:         // *********** delete from 'properties'-table
245:         $oPropertyColl = new cApiPropertyCollection($iIdClient);
246:         $oPropertyColl->deleteProperties('idlang', $iIdLang);
247:     } else {
248:         return $notification->returnMessageBox('error', i18n("Could not delete language"), 0);
249:     }
250: }
251: 
252: /**
253:  * Deactivate a language
254:  *
255:  * @param int $idlang
256:  * @param int $active
257:  * @return bool
258:  */
259: function langActivateDeactivateLanguage($idlang, $active) {
260:     $oLang = new cApiLanguage();
261:     if ($oLang->loadByPrimaryKey((int) $idlang)) {
262:         $oLang->set('active', (int) $active, false);
263:         return $oLang->store();
264:     }
265:     return false;
266: }
267: 
268: /**
269:  * Returns the base direction of text (ltr = left to right, rtl = right to left)
270:  * by language id
271:  *
272:  * @param int $idlang
273:  * @param cDb $db Is not in use
274:  * @return string 'ltr' or 'rtl'
275:  */
276: function langGetTextDirection($idlang, $db = NULL) {
277:     static $oLang;
278:     if (!isset($oLang)) {
279:         $oLang = new cApiLanguage();
280:     }
281:     $direction = '';
282:     if ($oLang->loadByPrimaryKey((int) $idlang)) {
283:         $direction = $oLang->get('direction');
284:     }
285:     if ($direction != 'ltr' && $direction != 'rtl') {
286:         $direction = 'ltr';
287:     }
288:     return $direction;
289: }
290: 
291: ?>
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen