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 module collection and item class.
  4:  *
  5:  * @package Core
  6:  * @subpackage GenericDB_Model
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Timo Hummel
 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: /**
 19:  * Module collection
 20:  *
 21:  * @package Core
 22:  * @subpackage GenericDB_Model
 23:  */
 24: class cApiModuleCollection extends ItemCollection {
 25: 
 26:     /**
 27:      * Constructor Function
 28:      */
 29:     public function __construct() {
 30:         global $cfg;
 31:         parent::__construct($cfg['tab']['mod'], 'idmod');
 32:         $this->_setItemClass('cApiModule');
 33:     }
 34: 
 35:     /**
 36:      * Creates a new module item
 37:      *
 38:      * @global int $client
 39:      * @global object $auth
 40:      *
 41:      * @param string $name
 42:      * @param int $idclient
 43:      * @param string $alias
 44:      * @param string $type
 45:      * @param string $error
 46:      * @param string $description
 47:      * @param int $deletable
 48:      * @param string $template
 49:      * @param int $static
 50:      * @param string $package_guid
 51:      * @param string $package_data
 52:      * @param string $author
 53:      * @param string $created
 54:      * @param string $lastmodified
 55:      *
 56:      * @return cApiModule
 57:      */
 58:     public function create($name, $idclient = NULL, $alias = '', $type = '', $error = 'none', $description = '', $deletable = 0, $template = '', $static = 0, $package_guid = '', $package_data = '', $author = '', $created = '', $lastmodified = '') {
 59:         global $client, $auth;
 60: 
 61:         if (NULL === $idclient) {
 62:             $idclient = $client;
 63:         }
 64: 
 65:         if (empty($author)) {
 66:             $author = $auth->auth['uname'];
 67:         }
 68:         if (empty($created)) {
 69:             $created = date('Y-m-d H:i:s');
 70:         }
 71:         if (empty($lastmodified)) {
 72:             $lastmodified = date('Y-m-d H:i:s');
 73:         }
 74: 
 75:         $item = $this->createNewItem();
 76: 
 77:         $item->set('idclient', $idclient);
 78:         $item->set('name', $name);
 79:         $item->set('alias', $alias);
 80:         $item->set('type', $type);
 81:         $item->set('error', $error);
 82:         $item->set('description', $description);
 83:         $item->set('deletable', $deletable);
 84:         $item->set('template', $template);
 85:         $item->set('static', $static);
 86:         $item->set('package_guid', $package_guid);
 87:         $item->set('package_data', $package_data);
 88:         $item->set('author', $author);
 89:         $item->set('created', $created);
 90:         $item->set('lastmodified', $lastmodified);
 91:         $item->store();
 92: 
 93:         return $item;
 94:     }
 95: 
 96:     /**
 97:      * Returns list of all types by client id
 98:      *
 99:      * @param int $idclient
100:      *
101:      * @return array
102:      */
103:     public function getAllTypesByIdclient($idclient) {
104:         $types = array();
105: 
106:         $sql = "SELECT type FROM `%s` WHERE idclient = %d GROUP BY type";
107:         $sql = $this->db->prepare($sql, $this->table, $idclient);
108:         $this->db->query($sql);
109:         while ($this->db->nextRecord()) {
110:             $types[] = $this->db->f('type');
111:         }
112: 
113:         return $types;
114:     }
115: 
116:     /**
117:      * Returns list of all modules used by client id
118:      *
119:      * @param int $idclient
120:      *
121:      * @return array
122:      */
123:     public function getAllByIdclient($idclient, $oderBy = 'name') {
124:         $records = array();
125: 
126:         if (!empty($oderBy)) {
127:             $oderBy = ' ORDER BY ' . $this->db->escape($oderBy);
128:         }
129:         $sql = "SELECT * FROM `%s` WHERE idclient = %d{$oderBy}";
130:         $sql = $this->db->prepare($sql, $this->table, $idclient);
131:         $this->db->query($sql);
132:         while ($this->db->nextRecord()) {
133:             $records[$this->db->f('idmod')] = $this->db->toArray();
134:         }
135: 
136:         return $records;
137:     }
138: 
139:     /**
140:      * Checks if any modules are in use and returns the data
141:      *
142:      * @return array Returns all templates for all modules
143:      */
144:     public function getModulesInUse() {
145:         global $cfg;
146: 
147:         $db = cRegistry::getDb();
148: 
149:         $sql = 'SELECT
150:                     c.idmod, c.idtpl, t.name
151:                 FROM
152:                 ' . $cfg['tab']['container'] . ' as c,
153:                 ' . $cfg['tab']['tpl'] . " as t
154:                 WHERE
155:                     t.idtpl = c.idtpl
156:                 GROUP BY c.idmod
157:                 ORDER BY t.name";
158:         $db->query($sql);
159: 
160:         $aUsedTemplates = array();
161:         if ($db->numRows() != 0) {
162:             while ($db->nextRecord()) {
163:                 $aUsedTemplates[$db->f('idmod')][$db->f('idtpl')]['tpl_name'] = $db->f('name');
164:                 $aUsedTemplates[$db->f('idmod')][$db->f('idtpl')]['tpl_id'] = (int) $db->f('idtpl');
165:             }
166:         }
167: 
168:         return $aUsedTemplates;
169:     }
170: }
171: 
172: /**
173:  * Module item
174:  *
175:  * @package Core
176:  * @subpackage GenericDB_Model
177:  */
178: class cApiModule extends Item {
179: 
180:     /**
181:      * for finding module translations in source code of module
182:      *
183:      * @var string
184:      */
185:     private $_translationPatternText = '/mi18n([\s]*)\("((\\\\"|[^"])*)"(([\s]*),([\s]*)[^\),]+)*\)/';
186: 
187:     /**
188:      * for finding basic module translations in source code of module
189:      *
190:      * @var string
191:      */
192:     private $_translationPatternBase = '/mi18n([\s]*)\(([\s]*)"/';
193: 
194:     /**
195:      * for replacing base module translations in source code of module
196:      *
197:      * @var string
198:      */
199:     private $_translationReplacement = 'mi18n("';
200: 
201:     /**
202:      *
203:      * @var unknown_type
204:      */
205:     protected $_error;
206: 
207:     /**
208:      * Assoziative package structure array
209:      *
210:      * @var array
211:      */
212:     protected $_packageStructure;
213: 
214:     /**
215:      *
216:      * @var array
217:      */
218:     private $aUsedTemplates = array();
219: 
220:     /**
221:      * Constructor Function
222:      *
223:      * @param mixed $mId Specifies the ID of item to load
224:      */
225:     public function __construct($mId = false) {
226:         global $cfg, $cfgClient, $client;
227:         parent::__construct($cfg['tab']['mod'], 'idmod');
228: 
229:         // Using no filters is just for compatibility reasons.
230:         // That's why you don't have to stripslashes values if you store them
231:         // using ->set. You have to add slashes, if you store data directly
232:         // (data not from a form field)
233:         $this->setFilters(array(), array());
234: 
235:         if ($mId !== false) {
236:             $this->loadByPrimaryKey($mId);
237:         }
238: 
239:         if (isset($client) && $client != 0) {
240:             $this->_packageStructure = array(
241:                 'jsfiles' => $cfgClient[$client]['js']['path'],
242:                 'tplfiles' => $cfgClient[$client]['tpl']['path'],
243:                 'cssfiles' => $cfgClient[$client]['css']['path']
244:             );
245:         }
246:     }
247: 
248:     /**
249:      * Returns the translated name of the module if a translation exists.
250:      *
251:      * @return string Translated module name or original
252:      */
253:     public function getTranslatedName() {
254:         global $lang;
255: 
256:         // If we're not loaded, return
257:         if (!$this->isLoaded()) {
258:             return false;
259:         }
260: 
261:         $modname = $this->getProperty('translated-name', $lang);
262: 
263:         if ($modname === false) {
264:             return $this->get('name');
265:         } else {
266:             return $modname;
267:         }
268:     }
269: 
270:     /**
271:      * Sets the translated name of the module
272:      *
273:      * @param string $name Translated name of the module
274:      */
275:     public function setTranslatedName($name) {
276:         global $lang;
277:         $this->setProperty('translated-name', $lang, $name);
278:     }
279: 
280:     /**
281:      * This method get the input and output for translating from files and not
282:      * from db-table.
283:      *
284:      * @param array $cfg
285:      * @param int $client
286:      * @param int $lang
287:      * @return bool multitype:
288:      */
289:     function parseModuleForStringsLoadFromFile($cfg, $client, $lang) {
290:         global $client;
291: 
292:         // If we're not loaded, return
293:         if (!$this->isLoaded()) {
294:             return false;
295:         }
296: 
297:         // Fetch the code, append input to output
298:         $contenidoModuleHandler = new cModuleHandler($this->get('idmod'));
299:         $code = $contenidoModuleHandler->readOutput() . ' ';
300:         $code .= $contenidoModuleHandler->readInput();
301: 
302:         // Initialize array
303:         $strings = array();
304: 
305:         // Split the code into mi18n chunks
306:         $varr = preg_split($this->_translationPatternBase, $code, -1);
307:         array_shift($varr);
308: 
309:         if (count($varr) > 0) {
310:             foreach ($varr as $key => $value) {
311:                 // Search first closing
312:                 $closing = strpos($value, '")');
313: 
314:                 if ($closing === false) {
315:                     $closing = strpos($value, '" )');
316:                 }
317: 
318:                 if ($closing !== false) {
319:                     $value = substr($value, 0, $closing) . '")';
320:                 }
321: 
322:                 // Append mi18n again
323:                 $varr[$key] = $this->_translationReplacement . $value;
324: 
325:                 // Parse for the mi18n stuff
326:                 preg_match_all($this->_translationPatternText, $varr[$key], $results);
327: 
328:                 // Append to strings array if there are any results
329:                 if (is_array($results[1]) && count($results[2]) > 0) {
330:                     $strings = array_merge($strings, $results[2]);
331:                 }
332: 
333:                 // Unset the results for the next run
334:                 unset($results);
335:             }
336:         }
337: 
338:         // adding dynamically new module translations by content types
339:         // this function was introduced with CONTENIDO 4.8.13
340:         // checking if array is set to prevent crashing the module translation
341:         // page
342:         if (is_array($cfg['translatable_content_types']) && count($cfg['translatable_content_types']) > 0) {
343:             // iterate over all defines cms content types
344:             foreach ($cfg['translatable_content_types'] as $sContentType) {
345:                 // check if the content type exists and include his class file
346:                 if (file_exists($cfg['contenido']['path'] . 'classes/class.' . strtolower($sContentType) . '.php')) {
347:                     cInclude('classes', 'class.' . strtolower($sContentType) . '.php');
348:                     // if the class exists, has the method
349:                     // 'addModuleTranslations'
350:                     // and the current module contains this cms content type we
351:                     // add the additional translations for the module
352:                     if (class_exists($sContentType) && method_exists($sContentType, 'addModuleTranslations') && preg_match('/' . strtoupper($sContentType) . '\[\d+\]/', $code)) {
353: 
354:                         $strings = call_user_func(array(
355:                             $sContentType,
356:                             'addModuleTranslations'
357:                         ), $strings);
358:                     }
359:                 }
360:             }
361:         }
362: 
363:         /* Make the strings unique */
364:         return array_unique($strings);
365:     }
366: 
367:     /**
368:      * Parses the module for mi18n strings and returns them in an array
369:      *
370:      * @return array Found strings for this module
371:      */
372:     public function parseModuleForStrings() {
373:         if (!$this->isLoaded()) {
374:             return false;
375:         }
376: 
377:         // Fetch the code, append input to output
378:         // $code = $this->get('output');
379:         // $code .= $this->get('input');
380:         // Get the code(input,output) from files
381:         $contenidoModuleHandler = new cModuleHandler($this->get('idmod'));
382:         $code = $contenidoModuleHandler->readOutput() . ' ';
383:         $code .= $contenidoModuleHandler->readInput();
384: 
385:         // Initialize array
386:         $strings = array();
387: 
388:         // Split the code into mi18n chunks
389:         $varr = preg_split($this->_translationPatternBase, $code, -1);
390: 
391:         if (count($varr) > 1) {
392:             foreach ($varr as $key => $value) {
393:                 // Search first closing
394:                 $closing = strpos($value, '")');
395: 
396:                 if ($closing === false) {
397:                     $closing = strpos($value, '" )');
398:                 }
399: 
400:                 if ($closing !== false) {
401:                     $value = substr($value, 0, $closing) . '")';
402:                 }
403: 
404:                 // Append mi18n again
405:                 $varr[$key] = $this->_translationReplacement . $value;
406: 
407:                 // Parse for the mi18n stuff
408:                 preg_match_all($this->_translationPatternText, $varr[$key], $results);
409: 
410:                 // Append to strings array if there are any results
411:                 if (is_array($results[1]) && count($results[2]) > 0) {
412:                     $strings = array_merge($strings, $results[2]);
413:                 }
414: 
415:                 // Unset the results for the next run
416:                 unset($results);
417:             }
418:         }
419: 
420:         global $cfg;
421: 
422:         // adding dynamically new module translations by content types
423:         // this function was introduced with CONTENIDO 4.8.13
424:         // checking if array is set to prevent crashing the module translation
425:         // page
426:         if (is_array($cfg['translatable_content_types']) && count($cfg['translatable_content_types']) > 0) {
427:             // iterate over all defines cms content types
428:             foreach ($cfg['translatable_content_types'] as $sContentType) {
429:                 // check if the content type exists and include his class file
430:                 if (cFileHandler::exists($cfg['contenido']['path'] . 'classes/class.' . strtolower($sContentType) . '.php')) {
431:                     cInclude('classes', 'class.' . strtolower($sContentType) . '.php');
432:                     // if the class exists, has the method
433:                     // 'addModuleTranslations'
434:                     // and the current module contains this cms content type we
435:                     // add the additional translations for the module
436:                     if (class_exists($sContentType) && method_exists($sContentType, 'addModuleTranslations') && preg_match('/' . strtoupper($sContentType) . '\[\d+\]/', $code)) {
437: 
438:                         $strings = call_user_func(array(
439:                             $sContentType,
440:                             'addModuleTranslations'
441:                         ), $strings);
442:                     }
443:                 }
444:             }
445:         }
446: 
447:         // Make the strings unique
448:         return array_unique($strings);
449:     }
450: 
451:     /**
452:      * Checks if the module is in use
453:      *
454:      * @param int $module
455:      * @param bool $bSetData
456:      * @return bool true if the module is in use
457:      */
458:     public function moduleInUse($module, $bSetData = false) {
459:         global $cfg;
460: 
461:         $db = cRegistry::getDb();
462: 
463:         $sql = 'SELECT
464:                     c.idmod, c.idtpl, t.name
465:                 FROM
466:                 ' . $cfg['tab']['container'] . ' as c,
467:                 ' . $cfg['tab']['tpl'] . " as t
468:                 WHERE
469:                     c.idmod = '" . cSecurity::toInteger($module) . "' AND
470:                     t.idtpl=c.idtpl
471:                 GROUP BY c.idtpl
472:                 ORDER BY t.name";
473:         $db->query($sql);
474: 
475:         if ($db->numRows() == 0) {
476:             return false;
477:         } else {
478:             $i = 0;
479:             // save the datas of used templates in array
480:             if ($bSetData === true) {
481:                 while ($db->nextRecord()) {
482:                     $this->aUsedTemplates[$i]['tpl_name'] = $db->f('name');
483:                     $this->aUsedTemplates[$i]['tpl_id'] = (int) $db->f('idmod');
484:                     $i++;
485:                 }
486:             }
487: 
488:             return true;
489:         }
490:     }
491: 
492:     /**
493:      * Get the informations of used templates
494:      *
495:      * @return array template data
496:      */
497:     public function getUsedTemplates() {
498:         return $this->aUsedTemplates;
499:     }
500: 
501:     /**
502:      * Checks if the module is a pre-4.3 module
503:      *
504:      * @return bool true if this module is an old one
505:      */
506:     public function isOldModule() {
507:         // Keywords to scan
508:         $scanKeywords = array(
509:             '$cfgTab',
510:             'idside',
511:             'idsidelang'
512:         );
513: 
514:         $input = $this->get('input');
515:         $output = $this->get('output');
516: 
517:         foreach ($scanKeywords as $keyword) {
518:             if (strstr($input, $keyword)) {
519:                 return true;
520:             }
521:             if (strstr($output, $keyword)) {
522:                 return true;
523:             }
524:         }
525:     }
526: 
527:     /**
528:      *
529:      * @see Item::getField()
530:      */
531:     public function getField($field, $bSafe = true) {
532:         $value = parent::getField($field, $bSafe);
533: 
534:         switch ($field) {
535:             case 'name':
536:                 if ($value == '') {
537:                     $value = i18n('- Unnamed module -');
538:                 }
539:         }
540: 
541:         return ($value);
542:     }
543: 
544:     /**
545:      *
546:      * @param bool $bJustStore
547:      * @see Item::store()
548:      */
549:     public function store($bJustStore = false) {
550:         if ($bJustStore) {
551:             // Just store changes, e.g. if specifying the mod package
552:             $success = parent::store();
553:         } else {
554:             cInclude('includes', 'functions.con.php');
555: 
556:             $success = parent::store();
557: 
558:             conGenerateCodeForAllArtsUsingMod($this->get('idmod'));
559:         }
560: 
561:         return $success;
562:     }
563: 
564:     /**
565:      * Parse import xml file and returns its values.
566:      *
567:      * @param string $sFile Filename including path of import xml file
568:      *
569:      * @return array Array with module data from XML file
570:      */
571:     private function _parseImportFile($sFile) {
572:         $oXmlReader = new cXmlReader();
573:         $oXmlReader->load($sFile);
574: 
575:         $aData = array();
576:         $aInformation = array(
577:             'name',
578:             'description',
579:             'type',
580:             'input',
581:             'output',
582:             'alias'
583:         );
584: 
585:         foreach ($aInformation as $sInfoName) {
586:             $sPath = '/module/' . $sInfoName;
587: 
588:             $value = $oXmlReader->getXpathValue($sPath);
589:             $aData[$sInfoName] = $value;
590:         }
591: 
592:         return $aData;
593:     }
594: 
595:     /**
596:      * Save the modul properties (description,type...)
597:      *
598:      * @param string $sFile Where is the modul info.xml file
599:      * @return array
600:      */
601:     private function _getModuleProperties($sFile) {
602:         $ret = array();
603: 
604:         $aModuleData = $this->_parseImportFile($sFile);
605:         if (count($aModuleData) > 0) {
606:             foreach ($aModuleData as $key => $value) {
607:                 // the columns input/and outputs dont exist in table
608:                 if ($key != 'output' && $key != 'input') {
609:                     $ret[$key] = addslashes($value);
610:                 }
611:             }
612:         }
613: 
614:         return $ret;
615:     }
616: 
617:     /**
618:      * Imports the a module from a zip file, uses xmlparser and callbacks
619:      *
620:      * @param string $sFile Filename of data file (full path)
621:      * @param string $tempName of archive
622:      * @param bool $show_notification standard: true, mode to turn
623:      *        notifications off
624:      * @return bool
625:      */
626:     function import($sFile, $tempName, $show_notification = true) {
627:         global $cfgClient, $db, $client, $cfg, $encoding, $lang;
628:         $zip = new ZipArchive();
629:         $notification = new cGuiNotification();
630: 
631:         // file name Hello_World.zip => Hello_World
632:         // @TODO: fetch file extension correctly
633:         $modulName = substr($sFile, 0, -4);
634: 
635:         $sModulePath = $cfgClient[$client]['module']['path'] . $modulName;
636:         $sTempPath = $cfg['path']['contenido_temp'] . 'module_import_' . $modulName;
637: 
638:         // does module already exist in directory
639:         if (is_dir($sModulePath)) {
640:             if ($show_notification == true) {
641:                 $notification->displayNotification('error', i18n('Module already exists!'));
642:             }
643: 
644:             return false;
645:         }
646: 
647:         if ($zip->open($tempName)) {
648:             if ($zip->extractTo($sTempPath)) {
649:                 $zip->close();
650: 
651:                 // Check module xml information
652:                 if (cFileHandler::exists($sTempPath . '/info.xml')) {
653: 
654:                     // make new module
655:                     $modules = new cApiModuleCollection();
656: 
657:                     $module = $modules->create($modulName);
658:                     $moduleProperties = $this->_getModuleProperties($sTempPath . '/info.xml');
659: 
660:                     // set module properties and save it
661:                     foreach ($moduleProperties as $key => $value) {
662:                         $module->set($key, $value);
663:                     }
664: 
665:                     $module->store();
666:                 } else {
667:                     if ($show_notification == true) {
668:                         $notification->displayNotification('error', i18n('Import failed, could load module information!'));
669:                     }
670:                     return false;
671:                 }
672:             } else {
673:                 if ($show_notification == true) {
674:                     $notification->displayNotification('error', i18n('Import failed, could not extract zip file!'));
675:                 }
676: 
677:                 return false;
678:             }
679:         } else {
680:             if ($show_notification == true) {
681:                 $notification->displayNotification('error', i18n('Could not open the zip file!'));
682:             }
683: 
684:             return false;
685:         }
686: 
687:         // Move into module dir
688:         cDirHandler::rename($sTempPath, $sModulePath);
689: 
690:         return true;
691:     }
692: 
693:     /**
694:      * Imports the a module from a XML file, uses xmlparser and callbacks
695:      *
696:      * @param string $sFile Filename of data file (full path)
697:      * @return bool
698:      */
699:     function importModuleFromXML($sFile) {
700:         global $db, $cfgClient, $client, $cfg, $encoding, $lang;
701: 
702:         $inputOutput = array();
703:         $notification = new cGuiNotification();
704: 
705:         $aModuleData = $this->_parseImportFile($sFile);
706:         if (count($aModuleData) > 0) {
707:             foreach ($aModuleData as $key => $value) {
708:                 if ($this->get($key) != $value) {
709:                     // he columns input/and outputs dont exist in table
710:                     if ($key == 'output' || $key == 'input') {
711:                         $inputOutput[$key] = $value;
712:                     } else {
713:                         $this->set($key, addslashes($value));
714:                     }
715:                 }
716:             }
717: 
718:             $moduleName = cApiStrCleanURLCharacters($this->get('name'));
719:             $moduleAlias = cApiStrCleanURLCharacters($this->get('alias'));
720: 
721:             // Is alias empty? Use module name as alias
722:             if ($this->get('alias') == '') {
723:                 $this->set('alias', $moduleName);
724:             }
725: 
726:             if (is_dir($cfgClient[$client]['module']['path'] . $moduleAlias)) {
727:                 $notification->displayNotification('error', i18n('Module exist!'));
728:                 return false;
729:             } else {
730:                 // save it in db table
731:                 $this->store();
732:                 $contenidoModuleHandler = new cModuleHandler($this->get('idmod'));
733:                 if (!$contenidoModuleHandler->createModule($inputOutput['input'], $inputOutput['output'])) {
734:                     $notification->displayNotification('error', i18n('Could not create a module!'));
735:                     return false;
736:                 } else {
737:                     // save the modul data to modul info file
738:                     $contenidoModuleHandler->saveInfoXML();
739:                 }
740:             }
741:         } else {
742:             $notification->displayNotification('error', i18n('Could not parse xml file!'));
743: 
744:             return false;
745:         }
746: 
747:         return true;
748:     }
749: 
750:     /**
751:      * Add recursive folder to zip archive
752:      *
753:      * @param string $dir directory name
754:      * @param string $zipArchive name of the archive
755:      * @param string $zipdir
756:      */
757:     private function _addFolderToZip($dir, $zipArchive, $zipdir = '') {
758:         if (is_dir($dir)) {
759:             if (false !== $handle = cDirHandler::read($dir)) {
760:                 if (!empty($zipdir)) {
761:                     $zipArchive->addEmptyDir($zipdir);
762:                 }
763:                 
764:                 foreach ($handle as $file) {
765:                     // If it's a folder, run the function again!
766:                     if (!is_file($dir . $file)) {
767:                         // Skip parent and root directories
768:                         if (false === cFileHandler::fileNameIsDot($file)) {
769:                             $this->_addFolderToZip($dir . $file . '/', $zipArchive, $zipdir . $file . '/');
770:                         }
771:                     } else {
772:                         // Add the files
773:                         if ($zipArchive->addFile($dir . $file, $zipdir . $file) === false) {
774:                             $notification = new cGuiNotification();
775:                             $notification->displayNotification('error', sprintf(i18n('Could not add file %s to zip!'), $file));
776:                         }
777:                     }
778:                 }
779:             }
780:         }
781:     }
782: 
783:     /**
784:      * Exports the specified module to a zip file
785:      */
786:     public function export() {
787:         $notification = new cGuiNotification();
788:         $moduleHandler = new cModuleHandler($this->get('idmod'));
789: 
790:         // exist modul
791:         if ($moduleHandler->modulePathExists()) {
792:             $zip = new ZipArchive();
793:             $zipName = $this->get('alias') . '.zip';
794:             $cfg = cRegistry::getConfig();
795:             $path = $cfg['path']['contenido_temp'];
796:             if ($zip->open($path . $zipName, ZipArchive::CREATE)) {
797:                 $this->_addFolderToZip($moduleHandler->getModulePath(), $zip);
798: 
799:                 $zip->close();
800:                 // Stream the file to the client
801:                 header('Content-Type: application/zip');
802:                 header('Content-Length: ' . filesize($path . $zipName));
803:                 header("Content-Disposition: attachment; filename=\"$zipName\"");
804:                 readfile($path . $zipName);
805: 
806:                 // erase the file
807:                 unlink($path . $zipName);
808:             } else {
809:                 $notification->displayNotification('error', i18n('Could not open the zip file!'));
810:             }
811:         } else {
812:             $notification->displayNotification('error', i18n("Module don't exist on file system!"));
813:         }
814:     }
815: 
816:     /**
817:      * Userdefined setter for module fields.
818:      *
819:      * @param string $name
820:      * @param mixed $value
821:      * @param bool $bSafe Flag to run defined inFilter on passed value
822:      * @todo should return return value of overloaded method
823:      */
824:     public function setField($name, $value, $bSafe = true) {
825:         switch ($name) {
826:             case 'deletable':
827:             case 'static':
828:                 $value = ($value == 1) ? 1 : 0;
829:                 break;
830:             case 'idclient':
831:                 $value = (int) $value;
832:                 break;
833:         }
834: 
835:         parent::setField($name, $value, $bSafe);
836:     }
837: 
838:     /**
839:      * Processes container placeholder (e. g. CMS_VAR[123], CMS_VALUE[123]) in given module input code.
840:      * Tries to find the proper container tag and replaces its value against
841:      * container configuration.
842:      * @param  int  $containerNr  The container number to process
843:      * @param  string  $containerCfg  Container configuration string containing key/values pairs for all containers
844:      * @param  string  $moduleInputCode
845:      * @return  string
846:      */
847:     public static function processContainerInputCode($containerNr, $containerCfg, $moduleInputCode) {
848:         $containerConfigurations = array();
849:         if (!empty($containerCfg)) {
850:             $containerConfigurations = cApiContainerConfiguration::parseContainerValue($containerCfg);
851:         }
852: 
853:         $CiCMS_Var = '$C' . $containerNr . 'CMS_VALUE';
854:         $CiCMS_Values = array();
855: 
856:         foreach ($containerConfigurations as $key3 => $value3) {
857:             // Convert special characters and escape backslashes!
858:             $tmp = conHtmlSpecialChars($value3);
859:             $tmp = str_replace('\\', '\\\\', $tmp);
860: 
861:             $CiCMS_Values[] = $CiCMS_Var . '[' . $key3 . '] = "' . $tmp . '";';
862:             $moduleInputCode = str_replace("\$CMS_VALUE[$key3]", $tmp, $moduleInputCode);
863:             $moduleInputCode = str_replace("CMS_VALUE[$key3]", $tmp, $moduleInputCode);
864:         }
865: 
866:         $moduleInputCode = str_replace('CMS_VALUE', $CiCMS_Var, $moduleInputCode);
867:         $moduleInputCode = str_replace("\$" . $CiCMS_Var, $CiCMS_Var, $moduleInputCode);
868:         $moduleInputCode = str_replace('CMS_VAR', 'C' . $containerNr . 'CMS_VAR', $moduleInputCode);
869: 
870:         $CiCMS_Values = implode("\n", $CiCMS_Values);
871: 
872:         return $CiCMS_Values . "\n" . $moduleInputCode;
873:     }
874: 
875:     public static function processContainerForOutput($containerNr, $containerCfg, $moduleInputCode) {
876: return; // @TODO implement me
877:         $containerConfigurations = array();
878:         if (!empty($containerCfg)) {
879:             $containerConfigurations = cApiContainerConfiguration::parseContainerValue($containerCfg);
880:         }
881:     }
882: 
883: }
884: 
885: ?>
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen