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

Classes

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