Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • 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
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • 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
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserProperty
  • cApiUserPropertyCollection
  • NoteCollection
  • NoteItem
  • TODOCollection
  • TODOItem
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  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 = parent::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:      * Checks if any modules are in use and returns the data
118:      *
119:      * @return array Returns all templates for all modules
120:      */
121:     public function getModulesInUse() {
122:         global $cfg;
123: 
124:         $db = cRegistry::getDb();
125: 
126:         $sql = 'SELECT
127:                     c.idmod, c.idtpl, t.name
128:                 FROM
129:                 ' . $cfg['tab']['container'] . ' as c,
130:                 ' . $cfg['tab']['tpl'] . " as t
131:                 WHERE
132:                     t.idtpl = c.idtpl
133:                 GROUP BY c.idmod
134:                 ORDER BY t.name";
135:         $db->query($sql);
136: 
137:         $aUsedTemplates = array();
138:         if ($db->numRows() != 0) {
139:             while ($db->nextRecord()) {
140:                 $aUsedTemplates[$db->f('idmod')][$db->f('idtpl')]['tpl_name'] = $db->f('name');
141:                 $aUsedTemplates[$db->f('idmod')][$db->f('idtpl')]['tpl_id'] = (int) $db->f('idtpl');
142:             }
143:         }
144: 
145:         return $aUsedTemplates;
146:     }
147: 
148: }
149: 
150: /**
151:  * Module item
152:  *
153:  * @package Core
154:  * @subpackage GenericDB_Model
155:  */
156: class cApiModule extends Item {
157: 
158:     /**
159:      * var for finding module translations in source code of module
160:      */
161:     private $_translationPatternText = '/mi18n([\s]*)\("((\\\\"|[^"])*)"(([\s]*),([\s]*)[^\),]+)*\)/';
162: 
163:     /**
164:      * var for finding basic module translations in source code of module
165:      */
166:     private $_translationPatternBase = '/mi18n([\s]*)\(([\s]*)"/';
167: 
168:     /**
169:      * var for replacing base module translations in source code of module
170:      */
171:     private $_translationReplacement = 'mi18n("';
172: 
173:     protected $_error;
174: 
175:     /**
176:      * Assoziative package structure array
177:      *
178:      * @var array
179:      */
180:     protected $_packageStructure;
181: 
182:     /**
183:      *
184:      * @var array
185:      */
186:     private $aUsedTemplates = array();
187: 
188:     /**
189:      * Constructor Function
190:      *
191:      * @param mixed $mId Specifies the ID of item to load
192:      */
193:     public function __construct($mId = false) {
194:         global $cfg, $cfgClient, $client;
195:         parent::__construct($cfg['tab']['mod'], 'idmod');
196: 
197:         // Using no filters is just for compatibility reasons.
198:         // That's why you don't have to stripslashes values if you store them
199:         // using ->set. You have to add slashes, if you store data directly
200:         // (data not from a form field)
201:         $this->setFilters(array(), array());
202: 
203:         if ($mId !== false) {
204:             $this->loadByPrimaryKey($mId);
205:         }
206: 
207:         if (isset($client) && $client != 0) {
208:             $this->_packageStructure = array(
209:                 'jsfiles' => $cfgClient[$client]['js']['path'],
210:                 'tplfiles' => $cfgClient[$client]['tpl']['path'],
211:                 'cssfiles' => $cfgClient[$client]['css']['path']
212:             );
213:         }
214:     }
215: 
216:     /**
217:      * Returns the translated name of the module if a translation exists.
218:      *
219:      * @return string Translated module name or original
220:      */
221:     public function getTranslatedName() {
222:         global $lang;
223: 
224:         // If we're not loaded, return
225:         if (!$this->isLoaded()) {
226:             return false;
227:         }
228: 
229:         $modname = $this->getProperty('translated-name', $lang);
230: 
231:         if ($modname === false) {
232:             return $this->get('name');
233:         } else {
234:             return $modname;
235:         }
236:     }
237: 
238:     /**
239:      * Sets the translated name of the module
240:      *
241:      * @param $name string Translated name of the module
242:      */
243:     public function setTranslatedName($name) {
244:         global $lang;
245:         $this->setProperty('translated-name', $lang, $name);
246:     }
247: 
248:     /**
249:      * This method get the input and output for translating
250:      * from files and not from db-table.
251:      */
252:     function parseModuleForStringsLoadFromFile($cfg, $client, $lang) {
253:         global $client;
254: 
255:         // If we're not loaded, return
256:         if (!$this->isLoaded()) {
257:             return false;
258:         }
259: 
260:         // Fetch the code, append input to output
261:         $contenidoModuleHandler = new cModuleHandler($this->get('idmod'));
262:         $code = $contenidoModuleHandler->readOutput() . ' ';
263:         $code .= $contenidoModuleHandler->readInput();
264: 
265:         // Initialize array
266:         $strings = array();
267: 
268:         // Split the code into mi18n chunks
269:         $varr = preg_split($this->_translationPatternBase, $code, -1);
270:         array_shift($varr);
271: 
272:         if (count($varr) > 0) {
273:             foreach ($varr as $key => $value) {
274:                 // Search first closing
275:                 $closing = strpos($value, '")');
276: 
277:                 if ($closing === false) {
278:                     $closing = strpos($value, '" )');
279:                 }
280: 
281:                 if ($closing !== false) {
282:                     $value = substr($value, 0, $closing) . '")';
283:                 }
284: 
285:                 // Append mi18n again
286:                 $varr[$key] = $this->_translationReplacement . $value;
287: 
288:                 // Parse for the mi18n stuff
289:                 preg_match_all($this->_translationPatternText, $varr[$key], $results);
290: 
291:                 // Append to strings array if there are any results
292:                 if (is_array($results[1]) && count($results[2]) > 0) {
293:                     $strings = array_merge($strings, $results[2]);
294:                 }
295: 
296:                 // Unset the results for the next run
297:                 unset($results);
298:             }
299:         }
300: 
301:         // adding dynamically new module translations by content types
302:         // this function was introduced with CONTENIDO 4.8.13
303:         // checking if array is set to prevent crashing the module translation
304:         // page
305:         if (is_array($cfg['translatable_content_types']) && count($cfg['translatable_content_types']) > 0) {
306:             // iterate over all defines cms content types
307:             foreach ($cfg['translatable_content_types'] as $sContentType) {
308:                 // check if the content type exists and include his class file
309:                 if (file_exists($cfg['contenido']['path'] . 'classes/class.' . strtolower($sContentType) . '.php')) {
310:                     cInclude('classes', 'class.' . strtolower($sContentType) . '.php');
311:                     // if the class exists, has the method
312:                     // 'addModuleTranslations'
313:                     // and the current module contains this cms content type we
314:                     // add the additional translations for the module
315:                     if (class_exists($sContentType) && method_exists($sContentType, 'addModuleTranslations') && preg_match('/' . strtoupper($sContentType) . '\[\d+\]/', $code)) {
316: 
317:                         $strings = call_user_func(array(
318:                             $sContentType,
319:                             'addModuleTranslations'
320:                         ), $strings);
321:                     }
322:                 }
323:             }
324:         }
325: 
326:         /* Make the strings unique */
327:         return array_unique($strings);
328:     }
329: 
330:     /**
331:      * Parses the module for mi18n strings and returns them in an array
332:      *
333:      * @return array Found strings for this module
334:      */
335:     public function parseModuleForStrings() {
336:         if (!$this->isLoaded()) {
337:             return false;
338:         }
339: 
340:         // Fetch the code, append input to output
341:         // $code = $this->get('output');
342:         // $code .= $this->get('input');
343:         // Get the code(input,output) from files
344:         $contenidoModuleHandler = new cModuleHandler($this->get('idmod'));
345:         $code = $contenidoModuleHandler->readOutput() . ' ';
346:         $code .= $contenidoModuleHandler->readInput();
347: 
348:         // Initialize array
349:         $strings = array();
350: 
351:         // Split the code into mi18n chunks
352:         $varr = preg_split($this->_translationPatternBase, $code, -1);
353: 
354:         if (count($varr) > 1) {
355:             foreach ($varr as $key => $value) {
356:                 // Search first closing
357:                 $closing = strpos($value, '")');
358: 
359:                 if ($closing === false) {
360:                     $closing = strpos($value, '" )');
361:                 }
362: 
363:                 if ($closing !== false) {
364:                     $value = substr($value, 0, $closing) . '")';
365:                 }
366: 
367:                 // Append mi18n again
368:                 $varr[$key] = $this->_translationReplacement . $value;
369: 
370:                 // Parse for the mi18n stuff
371:                 preg_match_all($this->_translationPatternText, $varr[$key], $results);
372: 
373:                 // Append to strings array if there are any results
374:                 if (is_array($results[1]) && count($results[2]) > 0) {
375:                     $strings = array_merge($strings, $results[2]);
376:                 }
377: 
378:                 // Unset the results for the next run
379:                 unset($results);
380:             }
381:         }
382: 
383:         global $cfg;
384: 
385:         // adding dynamically new module translations by content types
386:         // this function was introduced with CONTENIDO 4.8.13
387:         // checking if array is set to prevent crashing the module translation
388:         // page
389:         if (is_array($cfg['translatable_content_types']) && count($cfg['translatable_content_types']) > 0) {
390:             // iterate over all defines cms content types
391:             foreach ($cfg['translatable_content_types'] as $sContentType) {
392:                 // check if the content type exists and include his class file
393:                 if (cFileHandler::exists($cfg['contenido']['path'] . 'classes/class.' . strtolower($sContentType) . '.php')) {
394:                     cInclude('classes', 'class.' . strtolower($sContentType) . '.php');
395:                     // if the class exists, has the method
396:                     // 'addModuleTranslations'
397:                     // and the current module contains this cms content type we
398:                     // add the additional translations for the module
399:                     if (class_exists($sContentType) && method_exists($sContentType, 'addModuleTranslations') && preg_match('/' . strtoupper($sContentType) . '\[\d+\]/', $code)) {
400: 
401:                         $strings = call_user_func(array(
402:                             $sContentType,
403:                             'addModuleTranslations'
404:                         ), $strings);
405:                     }
406:                 }
407:             }
408:         }
409: 
410:         // Make the strings unique
411:         return array_unique($strings);
412:     }
413: 
414:     /**
415:      * Checks if the module is in use
416:      *
417:      * @return bool Specifies if the module is in use
418:      */
419:     public function moduleInUse($module, $bSetData = false) {
420:         global $cfg;
421: 
422:         $db = cRegistry::getDb();
423: 
424:         $sql = 'SELECT
425:                     c.idmod, c.idtpl, t.name
426:                 FROM
427:                 ' . $cfg['tab']['container'] . ' as c,
428:                 ' . $cfg['tab']['tpl'] . " as t
429:                 WHERE
430:                     c.idmod = '" . cSecurity::toInteger($module) . "' AND
431:                     t.idtpl=c.idtpl
432:                 GROUP BY c.idtpl
433:                 ORDER BY t.name";
434:         $db->query($sql);
435: 
436:         if ($db->numRows() == 0) {
437:             return false;
438:         } else {
439:             $i = 0;
440:             // save the datas of used templates in array
441:             if ($bSetData === true) {
442:                 while ($db->nextRecord()) {
443:                     $this->aUsedTemplates[$i]['tpl_name'] = $db->f('name');
444:                     $this->aUsedTemplates[$i]['tpl_id'] = (int) $db->f('idmod');
445:                     $i++;
446:                 }
447:             }
448: 
449:             return true;
450:         }
451:     }
452: 
453:     /**
454:      * Get the informations of used templates
455:      *
456:      * @return array template data
457:      */
458:     public function getUsedTemplates() {
459:         return $this->aUsedTemplates;
460:     }
461: 
462:     /**
463:      * Checks if the module is a pre-4.3 module
464:      *
465:      * @return bool true if this module is an old one
466:      */
467:     public function isOldModule() {
468:         // Keywords to scan
469:         $scanKeywords = array(
470:             '$cfgTab',
471:             'idside',
472:             'idsidelang'
473:         );
474: 
475:         $input = $this->get('input');
476:         $output = $this->get('output');
477: 
478:         foreach ($scanKeywords as $keyword) {
479:             if (strstr($input, $keyword)) {
480:                 return true;
481:             }
482:             if (strstr($output, $keyword)) {
483:                 return true;
484:             }
485:         }
486:     }
487: 
488:     public function getField($field) {
489:         $value = parent::getField($field);
490: 
491:         switch ($field) {
492:             case 'name':
493:                 if ($value == '') {
494:                     $value = i18n('- Unnamed module -');
495:                 }
496:         }
497: 
498:         return ($value);
499:     }
500: 
501:     public function store($bJustStore = false) {
502:         if ($bJustStore) {
503:             // Just store changes, e.g. if specifying the mod package
504:             $success = parent::store();
505:         } else {
506:             cInclude('includes', 'functions.con.php');
507: 
508:             $success = parent::store();
509: 
510:             conGenerateCodeForAllArtsUsingMod($this->get('idmod'));
511:         }
512: 
513:         return $success;
514:     }
515: 
516:     /**
517:      * Parse import xml file and returns its values.
518:      *
519:      * @param string $sFile Filename including path of import xml file
520:      *
521:      * @return array Array with module data from XML file
522:      */
523:     private function _parseImportFile($sFile) {
524:         $oXmlReader = new cXmlReader();
525:         $oXmlReader->load($sFile);
526: 
527:         $aData = array();
528:         $aInformation = array(
529:             'name',
530:             'description',
531:             'type',
532:             'input',
533:             'output',
534:             'alias'
535:         );
536: 
537:         foreach ($aInformation as $sInfoName) {
538:             $sPath = '/module/' . $sInfoName;
539: 
540:             $value = $oXmlReader->getXpathValue($sPath);
541:             $aData[$sInfoName] = $value;
542:         }
543: 
544:         return $aData;
545:     }
546: 
547:     /**
548:      * Save the modul properties (description,type...)
549:      *
550:      * @param string $sFile Where is the modul info.xml file
551:      */
552:     private function _getModuleProperties($sFile) {
553:         $ret = array();
554: 
555:         $aModuleData = $this->_parseImportFile($sFile);
556:         if (count($aModuleData) > 0) {
557:             foreach ($aModuleData as $key => $value) {
558:                 // the columns input/and outputs dont exist in table
559:                 if ($key != 'output' && $key != 'input') {
560:                     $ret[$key] = addslashes($value);
561:                 }
562:             }
563:         }
564: 
565:         return $ret;
566:     }
567: 
568:     /**
569:      * Imports the a module from a XML file, uses xmlparser and callbacks
570:      *
571:      * @param string $file Filename of data file (full path)
572:      * @param boolean $show_notification standard: true, mode to turn notifications off
573:      */
574:     function import($sFile, $tempName, $show_notification = true) {
575:         global $cfgClient, $db, $client, $cfg, $encoding, $lang;
576:         $zip = new ZipArchive();
577:         $notification = new cGuiNotification();
578:         $contenidoModuleHandler = new cModuleHandler($this->get('idmod'));
579:         // file name Hello_World.zip => Hello_World
580:         // @TODO: fetch file extension correctly
581:         $modulName = substr($sFile, 0, -4);
582: 
583:         $sModulePath = $cfgClient[$client]['module']['path'] . $modulName;
584: 
585:         // exist the modul in directory
586:         if (is_dir($sModulePath)) {
587:             if ($show_notification == true) {
588:                 $notification->displayNotification('error', i18n('Module exist!'));
589:             }
590: 
591:             return false;
592:         }
593: 
594:         if ($zip->open($tempName)) {
595:             if ($zip->extractTo($sModulePath)) {
596:                 $zip->close();
597: 
598:                 // make new module
599:                 $modules = new cApiModuleCollection();
600: 
601:                 $module = $modules->create($modulName);
602:                 $moduleProperties = $this->_getModuleProperties($sModulePath . '/info.xml');
603: 
604:                 // set module properties and save it
605:                 foreach ($moduleProperties as $key => $value) {
606:                     $module->set($key, $value);
607:                 }
608: 
609:                 $module->store();
610:             } else {
611:                 if ($show_notification == true) {
612:                     $notification->displayNotification('error', i18n('Import failed, could not extract zip file!'));
613:                 }
614: 
615:                 return false;
616:             }
617:         } else {
618:             if ($show_notification == true) {
619:                 $notification->displayNotification('error', i18n('Could not open the zip file!'));
620:             }
621: 
622:             return false;
623:         }
624: 
625:         return true;
626:     }
627: 
628:     /**
629:      * Imports the a module from a XML file, uses xmlparser and callbacks
630:      *
631:      * @param string $file Filename of data file (full path)
632:      */
633:     function importModuleFromXML($sFile) {
634:         global $db, $cfgClient, $client, $cfg, $encoding, $lang;
635: 
636:         $inputOutput = array();
637:         $notification = new cGuiNotification();
638: 
639:         $aModuleData = $this->_parseImportFile($sFile);
640:         if (count($aModuleData) > 0) {
641:             foreach ($aModuleData as $key => $value) {
642:                 if ($this->get($key) != $value) {
643:                     // he columns input/and outputs dont exist in table
644:                     if ($key == 'output' || $key == 'input') {
645:                         $inputOutput[$key] = $value;
646:                     } else {
647:                         $this->set($key, addslashes($value));
648:                     }
649:                 }
650:             }
651: 
652:             $moduleAlias = cApiStrCleanURLCharacters($this->get('name'));
653:             // is alias empty??
654:             if ($this->get('alias') == '') {
655:                 $this->set('alias', $moduleAlias);
656:             }
657: 
658:             if (is_dir($cfgClient[$client]['module']['path'] . $moduleAlias)) {
659:                 $notification->displayNotification('error', i18n('Module exist!'));
660: 
661:                 return false;
662:             } else {
663:                 // save it in db table
664:                 $this->store();
665:                 $contenidoModuleHandler = new cModuleHandler($this->get('idmod'));
666:                 if (!$contenidoModuleHandler->createModule($inputOutput['input'], $inputOutput['output'])) {
667:                     $notification->displayNotification('error', i18n('Could not make a module!'));
668: 
669:                     return false;
670:                 } else {
671:                     // save the modul data to modul info file
672:                     $contenidoModuleHandler->saveInfoXML();
673:                 }
674:             }
675:         } else {
676:             $notification->displayNotification('error', i18n('Could not parse xml file!'));
677: 
678:             return false;
679:         }
680: 
681:         return true;
682:     }
683: 
684:     /**
685:      * Add recursive folder to zip archive
686:      *
687:      * @param string $dir directory name
688:      * @param string $zipArchive name of the archive
689:      * @param string $zipdir
690:      */
691:     private function _addFolderToZip($dir, $zipArchive, $zipdir = '') {
692:         if (is_dir($dir)) {
693:             if ($dh = opendir($dir)) {
694:                 // Add the directory
695:                 if (!empty($zipdir)) {
696:                     $zipArchive->addEmptyDir($zipdir);
697:                 }
698: 
699:                 // Loop through all the files
700:                 while (($file = readdir($dh)) !== false) {
701:                     // If it's a folder, run the function again!
702:                     if (!is_file($dir . $file)) {
703:                         // Skip parent and root directories
704:                         if (($file !== '.') && ($file !== '..')) {
705:                             $this->_addFolderToZip($dir . $file . '/', $zipArchive, $zipdir . $file . '/');
706:                         }
707:                     } else {
708:                         // Add the files
709:                         if ($zipArchive->addFile($dir . $file, $zipdir . $file) === false) {
710:                             $notification = new cGuiNotification();
711:                             $notification->displayNotification('error', sprintf(i18n('Could not add file %s to zip!'), $file));
712:                         }
713:                     }
714:                 }
715:             }
716:         }
717:     }
718: 
719:     /**
720:      * Exports the specified module to a zip file
721:      */
722:     public function export() {
723:         $notification = new cGuiNotification();
724:         $moduleHandler = new cModuleHandler($this->get('idmod'));
725: 
726:         // exist modul
727:         if ($moduleHandler->modulePathExists()) {
728:             $zip = new ZipArchive();
729:             $zipName = $this->get('alias') . '.zip';
730:             if ($zip->open($zipName, ZipArchive::CREATE)) {
731:                 $this->_addFolderToZip($moduleHandler->getModulePath(), $zip);
732: 
733:                 $zip->close();
734:                 // Stream the file to the client
735:                 header('Content-Type: application/zip');
736:                 header('Content-Length: ' . filesize($zipName));
737:                 header("Content-Disposition: attachment; filename=\"$zipName\"");
738:                 readfile($zipName);
739: 
740:                 // erase the file
741:                 unlink($zipName);
742:             } else {
743:                 $notification->displayNotification('error', i18n('Could not open the zip file!'));
744:             }
745:         } else {
746:             $notification->displayNotification('error', i18n("Module don't exist on file system!"));
747:         }
748:     }
749: 
750:     /**
751:      * Userdefined setter for module fields.
752:      *
753:      * @param string $name
754:      * @param mixed $value
755:      * @param bool $bSafe Flag to run defined inFilter on passed value
756:      */
757:     public function setField($name, $value, $bSafe = true) {
758:         switch ($name) {
759:             case 'deletable':
760:             case 'static':
761:                 $value = ($value == 1)? 1 : 0;
762:                 break;
763:             case 'idclient':
764:                 $value = (int) $value;
765:                 break;
766:         }
767: 
768:         parent::setField($name, $value, $bSafe);
769:     }
770: 
771: }
772: 
773: ?>
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0