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