1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
29: class cModuleHandler {
30:
31: 32: 33: 34: 35:
36: private $_modulePath;
37:
38: 39: 40: 41: 42:
43: private $_path;
44:
45: 46: 47: 48: 49:
50: protected $_idmod = NULL;
51:
52: 53: 54: 55: 56:
57: private $_moduleName = NULL;
58:
59: 60: 61: 62: 63:
64: protected $_description;
65:
66: 67: 68: 69: 70:
71: protected $_type;
72:
73: 74: 75: 76: 77:
78: protected $_moduleAlias;
79:
80: 81: 82: 83: 84:
85: protected $_directories = array(
86: 'css' => 'css/',
87: 'js' => 'js/',
88: 'template' => 'template/',
89: 'image' => 'image/',
90: 'lang' => 'lang/',
91: 'php' => 'php/'
92: );
93:
94: 95: 96: 97: 98:
99: protected $_cfg = NULL;
100:
101: 102: 103: 104: 105:
106: protected $_cfgClient = NULL;
107:
108: 109: 110: 111: 112:
113: protected $_client = '0';
114:
115: 116: 117: 118: 119:
120: protected $_input = '';
121:
122: 123: 124: 125: 126:
127: protected $_output = '';
128:
129: 130: 131: 132: 133:
134: protected $_encoding = '';
135:
136: 137: 138: 139: 140: 141:
142: protected $_fileEncoding = '';
143:
144: 145: 146: 147: 148:
149: protected $_idlang = -1;
150:
151: 152: 153: 154:
155: private $_db = NULL;
156:
157: 158: 159: 160:
161: protected static $_encodingStore = array();
162:
163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174:
175: public function __construct($idmod = NULL) {
176: global $cfg, $cfgClient, $lang, $client;
177: $this->_cfg = $cfg;
178: $this->_client = $client;
179: $this->_cfgClient = $cfgClient;
180: $this->_idlang = $lang;
181: $this->_encoding = self::getEncoding();
182: $this->_fileEncoding = getEffectiveSetting('encoding', 'file_encoding', 'UTF-8');
183:
184: $this->_db = cRegistry::getDb();
185:
186: $this->_idmod = $idmod;
187:
188: $this->_initByModule($idmod);
189:
190: if ($this->_makeModuleDirectory() == false) {
191: throw new cException('Can not create main module directory.');
192: }
193: }
194:
195: public static function getEncoding($overrideLanguageId = 0) {
196: $lang = cRegistry::getLanguageId();
197:
198: if ((int) $overrideLanguageId != 0) {
199: $lang = $overrideLanguageId;
200: }
201:
202: if ((int) $lang == 0) {
203: $clientId = cRegistry::getClientId();
204:
205: $clientsLangColl = new cApiClientLanguageCollection();
206: $clientLanguages = $clientsLangColl->getLanguagesByClient($clientId);
207: sort($clientLanguages);
208:
209: if (isset($clientLanguages[0]) && (int) $clientLanguages[0] != 0) {
210: $lang = $clientLanguages[0];
211: }
212: }
213:
214: if (!isset(self::$_encodingStore[$lang])) {
215: $cApiLanguage = new cApiLanguage($lang);
216: self::$_encodingStore[$lang] = $cApiLanguage->get('encoding');
217: }
218:
219: return self::$_encodingStore[$lang];
220: }
221:
222: 223: 224: 225: 226: 227:
228: public function modulePathExistsInDirectory($name) {
229: return is_dir($this->_cfgClient[$this->_client]['module']['path'] . $name . '/');
230: }
231:
232: 233: 234: 235: 236: 237: 238: 239: 240:
241: public function saveContentToFile($templateName, $fileType, $fileContent, $saveDirectory = 'cache') {
242: $sSaveDirectory = $this->_cfgClient[$this->_client]['path']['frontend'] . $saveDirectory . '/';
243: if (!is_dir($sSaveDirectory)) {
244: return false;
245: }
246:
247: $templateName = str_replace(' ', '_', $templateName);
248: $templateName = strtolower($templateName);
249: $fileOperation = cFileHandler::write($sSaveDirectory . $templateName . '.' . $fileType, $fileContent);
250: if ($fileOperation === false) {
251: return false;
252: }
253: $url = $this->_cfgClient[$this->_client]['path']['htmlpath'] . $saveDirectory . '/' . $templateName . '.' . $fileType;
254:
255:
256: $url = str_replace('http://', '//', $url);
257:
258: return $url;
259: }
260:
261: 262: 263: 264: 265: 266:
267: public static function getCleanName($name, $defaultChar = '_') {
268:
269: $name = cApiStrCleanURLCharacters($name);
270:
271: $firstChar = substr($name, 0, 1);
272: if (!preg_match('/^[a-zA-Z0-9]|_|-$/', $firstChar)) {
273:
274: $name = $defaultChar . substr($name, 1);
275: }
276:
277: return $name;
278: }
279:
280: 281: 282: 283: 284: 285:
286: public function initWithDatabaseRow($db) {
287: if (is_object($db)) {
288: $this->_initByModule($db->f('idmod'));
289: }
290: }
291:
292: 293: 294: 295: 296:
297: protected function _initByModule($idmod = NULL) {
298: if ((int) $idmod == 0) {
299: return;
300: }
301:
302: $cApiModule = new cApiModule($idmod);
303:
304: if ($cApiModule->virgin == false) {
305: $this->_idmod = $idmod;
306: $this->_client = $cApiModule->get('idclient');
307: $this->_description = $cApiModule->get('description');
308: $this->_type = $cApiModule->get('type');
309: $this->_input = '';
310: $this->_output = '';
311:
312: $this->_moduleAlias = $cApiModule->get('alias');
313: $this->_moduleName = $cApiModule->get('name');
314: $this->_path = $this->_cfgClient[$this->_client]['module']['path'];
315: $this->_modulePath = $this->_path . $this->_moduleAlias . '/';
316: }
317: }
318:
319: 320: 321: 322: 323:
324: public function getModulePath() {
325: return $this->_modulePath;
326: }
327:
328: 329: 330: 331: 332: 333: 334: 335:
336: public function getTemplatePath($file = '') {
337: return $this->_modulePath . $this->_directories['template'] . $file;
338: }
339:
340: 341: 342: 343: 344:
345: public function getCssPath() {
346: return $this->_modulePath . $this->_directories['css'];
347: }
348:
349: 350: 351: 352: 353:
354: public function getPhpPath() {
355: return $this->_modulePath . $this->_directories['php'];
356: }
357:
358: 359: 360: 361: 362:
363: public function getJsPath() {
364: return $this->_modulePath . $this->_directories['js'];
365: }
366:
367: 368: 369: 370: 371:
372: public function getCssFileName() {
373: return $this->_moduleAlias . '.css';
374: }
375:
376: 377: 378: 379: 380: 381:
382: protected function getRandomCharacters($count) {
383: $micro1 = microtime();
384: $rand1 = rand(0, time());
385: $rand2 = rand(0, time());
386: return substr(md5($micro1 . $rand1 . $rand2), 0, $count);
387: }
388:
389: 390: 391: 392: 393: 394:
395: public function existFile($type, $fileName) {
396: return cFileHandler::exists($this->_modulePath . $this->_directories[$type] . $fileName);
397: }
398:
399: 400: 401: 402: 403: 404:
405: public function deleteFile($type, $fileName) {
406: if ($this->existFile($type, $fileName)) {
407: return unlink($this->_modulePath . $this->_directories[$type] . $fileName);
408: } else {
409: return false;
410: }
411: }
412:
413: 414: 415: 416: 417: 418: 419:
420: public function createModuleFile($type, $fileName = NULL, $content = '') {
421:
422: if (!$this->createModuleDirectory($type)) {
423: return false;
424: }
425:
426:
427: if ($fileName == NULL || $fileName == '') {
428: $fileName = $this->_moduleAlias;
429:
430: if ($type == 'template') {
431: $fileName = $fileName . '.html';
432: } else {
433: $fileName = $fileName . '.' . $type;
434: }
435: }
436:
437:
438: if ($type == 'css' || $type == 'js' || $type == 'template') {
439: if (!$this->existFile($type, $fileName)) {
440: $content = iconv($this->_encoding, $this->_fileEncoding, $content);
441: if (!$this->isWritable($this->_modulePath . $this->_directories[$type] . $fileName, $this->_modulePath . $this->_directories[$type])) {
442: return false;
443: }
444:
445: if (cFileHandler::write($this->_modulePath . $this->_directories[$type] . $fileName, $content) === false) {
446: $notification = new cGuiNotification();
447: $notification->displayNotification('error', i18n("Can't make file: ") . $fileName);
448: return false;
449: }
450: } elseif ($content != '') {
451: $content = iconv($this->_encoding, $this->_fileEncoding, $content);
452: if (!$this->isWritable($this->_modulePath . $this->_directories[$type] . $fileName, $this->_modulePath . $this->_directories[$type])) {
453: return false;
454: }
455: if (cFileHandler::write($this->_modulePath . $this->_directories[$type] . $fileName, $content) === false) {
456: $notification = new cGuiNotification();
457: $notification->displayNotification('error', i18n("Can't make file: ") . $fileName);
458: return false;
459: }
460: }
461: } else {
462: return false;
463: }
464:
465: return true;
466: }
467:
468: 469: 470: 471: 472: 473: 474: 475:
476: public function renameModuleFile($type, $oldFileName, $newFileName) {
477: if ($this->existFile($type, $newFileName)) {
478: return false;
479: }
480:
481: if (!$this->existFile($type, $oldFileName)) {
482: return false;
483: }
484:
485: return rename($this->_modulePath . $this->_directories[$type] . $oldFileName, $this->_modulePath . $this->_directories[$type] . $newFileName);
486: }
487:
488: 489: 490: 491: 492:
493: public function getJsFileName() {
494: return $this->_moduleAlias . '.js';
495: }
496:
497: 498: 499: 500: 501: 502:
503: public function getFilesContent($directory, $fileTyp, $fileName = NULL) {
504: if ($fileName == NULL) {
505: $fileName = $this->_moduleAlias . '.' . $fileTyp;
506: }
507:
508: if ($this->existFile($directory, $fileName)) {
509: $content = cFileHandler::read($this->_modulePath . $this->_directories[$directory] . $fileName);
510: $content = iconv($this->_fileEncoding, $this->_encoding . '//IGNORE', $content);
511: return $content;
512: }
513:
514: return false;
515: }
516:
517: 518: 519: 520: 521:
522: protected function _makeModuleDirectory() {
523:
524: if ((int) $this->_client == 0) {
525: return true;
526: }
527:
528: $sMainModuleDirectory = $this->_cfgClient[$this->_client]['module']['path'];
529:
530:
531: if (!is_dir($sMainModuleDirectory) && $sMainModuleDirectory != NULL) {
532: if (mkdir($sMainModuleDirectory, 0777, true) == false) {
533: return false;
534: } else {
535: cFileHandler::setDefaultDirPerms($sMainModuleDirectory);
536: }
537: }
538:
539: return true;
540: }
541:
542: 543: 544: 545: 546: 547:
548: public function getAllFilesFromDirectory($moduleDirectory) {
549: $retArray = array();
550: $dir = $this->_modulePath . $this->_directories[$moduleDirectory];
551:
552: if (is_dir($dir)) {
553: if ($dh = opendir($dir)) {
554: while (($file = readdir($dh)) !== false) {
555:
556: if ($file != '..' && $file != '.' && !is_dir($dir . $file . '/')) {
557: $retArray[] = $file;
558: }
559: }
560: }
561: }
562: return $retArray;
563: }
564:
565: 566: 567: 568: 569:
570: public function changeModuleName($name) {
571: $this->_moduleAlias = $name;
572: $this->_modulePath = $this->_path . $this->_moduleAlias . '/';
573: }
574:
575: 576: 577: 578: 579: 580:
581: public function eraseModule() {
582:
583: if (cFileHandler::exists($this->_modulePath . 'info.xml')) {
584: return cFileHandler::recursiveRmdir($this->_modulePath);
585: } else {
586: return false;
587: }
588: }
589:
590: 591: 592: 593: 594:
595: public function readInput($issource = false) {
596: if (cFileHandler::exists($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_input.php') == false) {
597: return false;
598: }
599:
600: $content = cFileHandler::read($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_input.php');
601:
602: if ($issource == true) {
603: $content = conHtmlentities($content);
604: }
605:
606: return iconv($this->_fileEncoding, $this->_encoding . '//IGNORE', $content);
607: }
608:
609: 610: 611: 612: 613:
614: public function readOutput($issource = false) {
615: if (cFileHandler::exists($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_output.php') == false) {
616: return false;
617: }
618:
619: $content = cFileHandler::read($this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_output.php');
620:
621: if ($issource == true) {
622: $content = conHtmlentities($content);
623: }
624:
625: return iconv($this->_fileEncoding, $this->_encoding . '//IGNORE', $content);
626: }
627:
628: 629: 630: 631: 632:
633: protected function createModuleDirectory($type) {
634: if (array_key_exists($type, $this->_directories)) {
635: if (!is_dir($this->_modulePath . $this->_directories[$type])) {
636: if (@mkdir($this->_modulePath . $this->_directories[$type]) == false) {
637: return false;
638: } else
639: cFileHandler::setDefaultDirPerms($this->_modulePath . $this->_directories[$type]);
640: } else {
641: return true;
642: }
643: }
644:
645: return true;
646: }
647:
648: 649: 650: 651: 652: 653: 654:
655: public function isWritable($fileName, $directory) {
656: if (cFileHandler::exists($fileName)) {
657: if (!is_writable($fileName)) {
658: return false;
659: }
660: } else {
661: if (!is_writable($directory)) {
662: return false;
663: }
664: }
665: return true;
666: }
667:
668: 669: 670: 671: 672: 673:
674: public function moduleWriteable($type) {
675: if (!cFileHandler::writeable($this->_modulePath . $this->_directories[$type])) {
676: return false;
677: } else {
678: return true;
679: }
680: }
681:
682: 683: 684: 685: 686: 687: 688:
689: public function saveOutput($output = NULL) {
690: $fileName = $this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_output.php';
691:
692: if (!$this->createModuleDirectory('php') || !$this->isWritable($fileName, $this->_modulePath . $this->_directories['php'])) {
693: return false;
694: }
695:
696: if ($output == NULL) {
697: $output = $this->_output;
698: }
699:
700: $output = iconv($this->_encoding, $this->_fileEncoding, $output);
701:
702: $fileOperation = cFileHandler::write($fileName, $output);
703:
704: if ($fileOperation === false) {
705: return false;
706: } else {
707: cFileHandler::setDefaultFilePerms($fileName);
708: return true;
709: }
710: }
711:
712: 713: 714: 715: 716: 717: 718:
719: public function saveInput($input = NULL) {
720: $fileName = $this->_modulePath . $this->_directories['php'] . $this->_moduleAlias . '_input.php';
721:
722: if (!$this->createModuleDirectory('php') || !$this->isWritable($fileName, $this->_modulePath . $this->_directories['php'])) {
723: return false;
724: }
725:
726: if ($input == NULL) {
727: $input = $this->_input;
728: }
729:
730: $input = iconv($this->_encoding, $this->_fileEncoding, $input);
731:
732: $fileOperation = cFileHandler::write($fileName, $input);
733:
734: if ($fileOperation === false) {
735: return false;
736: } else {
737: cFileHandler::setDefaultFilePerms($fileName);
738: return true;
739: }
740: }
741:
742: 743: 744: 745: 746: 747: 748: 749: 750:
751: public function saveInfoXML($moduleName = NULL, $description = NULL, $type = NULL, $alias = NULL) {
752: if ($moduleName == NULL) {
753: $moduleName = $this->_moduleName;
754: }
755:
756: if ($description == NULL) {
757: $description = $this->_description;
758: }
759:
760: if ($type == NULL) {
761: $type = $this->_type;
762: }
763:
764: if ($alias == NULL) {
765: $alias = $this->_moduleAlias;
766: }
767:
768: $oWriter = new cXmlWriter();
769: $oRootElement = $oWriter->addElement('module', '', NULL);
770:
771: $oWriter->addElement('name', conHtmlSpecialChars($moduleName), $oRootElement);
772: $oWriter->addElement('description', conHtmlSpecialChars($description), $oRootElement);
773: $oWriter->addElement('type', conHtmlSpecialChars($type), $oRootElement);
774: $oWriter->addElement('alias', conHtmlSpecialChars($alias), $oRootElement);
775:
776: return $oWriter->saveToFile($this->_modulePath, 'info.xml');
777: }
778:
779: 780: 781: 782: 783: 784: 785: 786: 787: 788:
789: public function createModule($input = '', $output = '') {
790: if ($input != '') {
791: $this->_input = $input;
792: }
793:
794: if ($output != '') {
795: $this->_output = $output;
796: }
797:
798: if ($this->modulePathExists()) {
799: return true;
800: }
801:
802: if (mkdir($this->_modulePath) == false) {
803: return false;
804: } else {
805: cFileHandler::setDefaultDirPerms($this->_modulePath);
806: }
807:
808:
809: foreach ($this->_directories as $directory) {
810: if (!is_dir($this->_modulePath . $directory)) {
811: if (mkdir($this->_modulePath . $directory) == false) {
812: return false;
813: } else {
814: cFileHandler::setDefaultDirPerms($this->_modulePath . $directory);
815: }
816: }
817: }
818:
819:
820: if ($this->saveInfoXML() == false) {
821: return false;
822: }
823:
824:
825:
826: $retInput = $this->saveInput();
827: $retOutput = $this->saveOutput();
828:
829: if ($retInput == false || $retOutput == false) {
830: return false;
831: }
832:
833: return true;
834: }
835:
836: 837: 838: 839: 840: 841: 842: 843:
844: public function renameModul($old, $new) {
845:
846: if (rename($this->_path . $old, $this->_path . $new) == false) {
847: return false;
848: } else {
849: $retInput = true;
850: $retOutput = true;
851:
852:
853: if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['php'] . $old . '_input.php'))
854: $retInput = rename($this->_path . $new . '/' . $this->_directories['php'] . $old . '_input.php', $this->_path . $new . '/' . $this->_directories['php'] . $new . '_input.php');
855:
856:
857: if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['php'] . $old . '_output.php'))
858: $retOutput = rename($this->_path . $new . '/' . $this->_directories['php'] . $old . '_output.php', $this->_path . $new . '/' . $this->_directories['php'] . $new . '_output.php');
859:
860:
861: if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['css'] . $old . '.css'))
862: rename($this->_path . $new . '/' . $this->_directories['css'] . $old . '.css', $this->_path . $new . '/' . $this->_directories['css'] . $new . '.css');
863:
864:
865: if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['js'] . $old . '.js'))
866: rename($this->_path . $new . '/' . $this->_directories['js'] . $old . '.js', $this->_path . $new . '/' . $this->_directories['js'] . $new . '.js');
867:
868:
869: if (cFileHandler::exists($this->_path . $new . '/' . $this->_directories['template'] . $old . '.html'))
870: rename($this->_path . $new . '/' . $this->_directories['template'] . $old . '.html', $this->_path . $new . '/' . $this->_directories['template'] . $new . '.html');
871:
872: if ($retInput == true && $retOutput == true) {
873: return true;
874: } else {
875: return false;
876: }
877: }
878: }
879:
880: 881: 882: 883: 884:
885: public function modulePathExists() {
886: return is_dir($this->_modulePath);
887: }
888:
889: 890: 891: 892: 893:
894: public function testInput() {
895:
896: return $this->_testCode('input');
897:
898: }
899:
900: 901: 902: 903: 904:
905: public function testOutput() {
906:
907: return $this->_testCode('output');
908:
909: }
910:
911: 912: 913: 914: 915: 916: 917:
918: protected function _testCode($inputType) {
919:
920: $result = array(
921: 'state' => false,
922: 'errorMessage' => 'Module path not exist'
923: );
924:
925: if (!$this->modulePathExists()) return $result;
926:
927: $module = new cApiModule($this->_idmod);
928: $isError = 'none';
929:
930:
931: switch ($module->get("error")) {
932: case 'none';
933: $toCheck = $inputType;
934: break;
935: case 'input';
936: if ($inputType == 'output') $toCheck = 'both';
937: break;
938: case 'output';
939: if ($inputType == 'input') $toCheck = 'both';
940: break;
941: case 'both';
942:
943: break;
944: }
945: if ($toCheck !== $module->get("error")) {
946: $module->set("error", $toCheck);
947: $module->store();
948: }
949:
950:
951: switch($inputType) {
952: case 'input':
953:
954: $code = $this->readInput();
955: $result = $this->_verifyCode($code, $this->_idmod . "i");
956: if ($result['state'] !== true) $isError = 'input';
957:
958: break;
959: case 'output':
960:
961: $code = $this->readOutput();
962: $result = $this->_verifyCode($code, $this->_idmod . "o", true);
963: if ($result['state'] !== true) $isError = 'output';
964:
965: break;
966: }
967:
968:
969: switch ($module->get("error")) {
970: case 'none';
971:
972: break;
973: case 'input';
974: if ($isError == 'none' && $inputType == 'output') $isError = 'input';
975: if ($isError == 'output') $isError = 'both';
976: break;
977: case 'output';
978: if ($isError == 'none' && $inputType == 'input') $isError = 'output';
979: if ($isError == 'input') $isError = 'both';
980: break;
981: case 'both';
982: if ($isError == 'none' && $inputType == 'input') $isError = 'output';
983: if ($isError == 'none' && $inputType == 'output') $isError = 'input';
984: break;
985: }
986:
987:
988:
989: if ($isError !== $module->get("error")) {
990: $module->set("error", $isError);
991: $module->store();
992: }
993:
994: return $result;
995:
996: }
997:
998: 999: 1000: 1001: 1002: 1003: 1004: 1005: 1006:
1007: protected function _verifyCode($code, $id, $output = false) {
1008:
1009: $result = array(
1010: 'state' => false,
1011: 'errorMessage' => NULL
1012: );
1013:
1014:
1015: $sql = 'SELECT type FROM ' . $this->_cfg['tab']['type'];
1016: $this->_db->query($sql);
1017: while ($this->_db->nextRecord()) {
1018: $code = str_replace($this->_db->f('type') . '[', '$' . $this->_db->f('type') . '[', $code);
1019: }
1020:
1021: $code = preg_replace(',\[(\d+)?CMS_VALUE\[(\d+)\](\d+)?\],i', '[\1\2\3]', $code);
1022: $code = str_replace('CMS_VALUE', '$CMS_VALUE', $code);
1023: $code = str_replace('CMS_VAR', '$CMS_VAR', $code);
1024:
1025:
1026:
1027: if ($output == true) {
1028: $code = "?>\n" . $code . "\n<?php";
1029: }
1030:
1031:
1032: $code = 'function foo' . $id . ' () {' . $code;
1033: $code .= "\n}\n";
1034:
1035:
1036:
1037: $sErs = ini_get('error_prepend_string');
1038: $sEas = ini_get('error_append_string');
1039: @ini_set('error_prepend_string', '<phperror>');
1040: @ini_set('error_append_string', '</phperror>');
1041:
1042:
1043: ob_start();
1044: $display_errors = ini_get('display_errors');
1045: @ini_set('display_errors', true);
1046: $output = eval($code);
1047: @ini_set('display_errors', $display_errors);
1048:
1049:
1050: $output = ob_get_contents();
1051: ob_end_clean();
1052:
1053:
1054: 1055: 1056: 1057: 1058:
1059:
1060:
1061: @ini_set('error_prepend_string', $sErs);
1062: @ini_set('error_append_string', $sEas);
1063:
1064:
1065: $isError = strpos($output, '<phperror>');
1066:
1067:
1068:
1069: if ($isError !== false) {
1070:
1071: $pattern = '/(<phperror>|<\/phperror>|<b>|<\/b>|<br>|<br \/>)/im';
1072: $modErrorMessage = trim(preg_replace($pattern, '', $output));
1073: $errorPart1 = substr($modErrorMessage, 0, strpos($modErrorMessage, ' in '));
1074: $errorPart2 = substr($modErrorMessage, strpos($modErrorMessage, ' on line '));
1075: $modErrorMessage = $errorPart1 . $errorPart2;
1076: $result['errorMessage'] = sprintf(i18n("Error in module. Error location: %s"), $modErrorMessage);
1077:
1078: }
1079:
1080:
1081: $bHasShortTags = false;
1082: if (preg_match('/<\?\s+/', $code)) {
1083: $bHasShortTags = true;
1084: $result['errorMessage'] = i18n('Please do not use short open tags. (Use <?php instead of <?).');
1085: }
1086:
1087:
1088: if ($bHasShortTags || $isError !== false) {
1089: $result['state'] = false;
1090: } else {
1091: $result['state'] = true;
1092: }
1093:
1094: return $result;
1095:
1096: }
1097:
1098: }