compiler.class.inc.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  1. <?php
  2. // Copyright (C) 2011-2013 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. require_once(APPROOT.'setup/setuputils.class.inc.php');
  19. class DOMFormatException extends Exception
  20. {
  21. }
  22. /**
  23. * Compiler class
  24. */
  25. class MFCompiler
  26. {
  27. protected $oFactory;
  28. protected $aRootClasses;
  29. protected $aLog;
  30. public function __construct($oModelFactory)
  31. {
  32. $this->oFactory = $oModelFactory;
  33. $this->aLog = array();
  34. }
  35. protected function Log($sText)
  36. {
  37. $this->aLog[] = $sText;
  38. }
  39. protected function DumpLog($oPage)
  40. {
  41. foreach ($this->aLog as $sText)
  42. {
  43. $oPage->p($sText);
  44. }
  45. }
  46. public function GetLog()
  47. {
  48. return $this->aLog;
  49. }
  50. public function Compile($sTargetDir, $oP = null, $bUseSymbolicLinks = false)
  51. {
  52. $sFinalTargetDir = $sTargetDir;
  53. if ($bUseSymbolicLinks)
  54. {
  55. // Skip the creation of a temporary dictionary, not compatible with symbolic links
  56. $sTempTargetDir = $sFinalTargetDir;
  57. }
  58. else
  59. {
  60. // Create a temporary directory
  61. // Once the compilation is 100% successful, then move the results into the target directory
  62. $sTempTargetDir = tempnam(SetupUtils::GetTmpDir(), 'itop-');
  63. unlink($sTempTargetDir); // I need a directory, not a file...
  64. SetupUtils::builddir($sTempTargetDir); // Here is the directory
  65. }
  66. try
  67. {
  68. $this->DoCompile($sTempTargetDir, $sFinalTargetDir, $oP = null, $bUseSymbolicLinks);
  69. }
  70. catch (Exception $e)
  71. {
  72. if ($sTempTargetDir != $sFinalTargetDir)
  73. {
  74. // Cleanup the temporary directory
  75. SetupUtils::rrmdir($sTempTargetDir);
  76. }
  77. throw $e;
  78. }
  79. if ($sTempTargetDir != $sFinalTargetDir)
  80. {
  81. // Move the results to the target directory
  82. SetupUtils::movedir($sTempTargetDir, $sFinalTargetDir);
  83. }
  84. }
  85. protected function DoCompile($sTempTargetDir, $sFinalTargetDir, $oP = null, $bUseSymbolicLinks = false)
  86. {
  87. $aAllClasses = array(); // flat list of classes
  88. // Determine the target modules for the MENUS
  89. //
  90. $aMenuNodes = array();
  91. $aMenusByModule = array();
  92. foreach ($this->oFactory->ListActiveChildNodes('menus', 'menu') as $oMenuNode)
  93. {
  94. $sMenuId = $oMenuNode->getAttribute('id');
  95. $aMenuNodes[$sMenuId] = $oMenuNode;
  96. $sModuleMenu = $oMenuNode->getAttribute('_created_in');
  97. $aMenusByModule[$sModuleMenu][] = $sMenuId;
  98. }
  99. // Determine the target module (exactly one!) for USER RIGHTS
  100. //
  101. $sUserRightsModule = '';
  102. $oUserRightsNode = $this->oFactory->GetNodes('user_rights')->item(0);
  103. if ($oUserRightsNode)
  104. {
  105. $sUserRightsModule = $oUserRightsNode->getAttribute('_created_in');
  106. $this->Log("User Rights module found: $sUserRightsModule");
  107. }
  108. // List root classes
  109. //
  110. $this->aRootClasses = array();
  111. foreach ($this->oFactory->ListRootClasses() as $oClass)
  112. {
  113. $this->Log("Root class (with child classes): ".$oClass->getAttribute('id'));
  114. $this->aRootClasses[$oClass->getAttribute('id')] = $oClass;
  115. }
  116. // Compile, module by module
  117. //
  118. $aModules = $this->oFactory->GetLoadedModules();
  119. foreach($aModules as $foo => $oModule)
  120. {
  121. $sModuleName = $oModule->GetName();
  122. $sModuleVersion = $oModule->GetVersion();
  123. $sModuleRootDir = $oModule->GetRootDir();
  124. if ($sModuleRootDir != '')
  125. {
  126. $sModuleRootDir = realpath($sModuleRootDir);
  127. $sRelativeDir = basename($sModuleRootDir);
  128. // Push the other module files
  129. SetupUtils::copydir($sModuleRootDir, $sTempTargetDir.'/'.$sRelativeDir, $bUseSymbolicLinks);
  130. }
  131. $sCompiledCode = '';
  132. $oConstants = $this->oFactory->ListConstants($sModuleName);
  133. if ($oConstants->length > 0)
  134. {
  135. foreach($oConstants as $oConstant)
  136. {
  137. $sCompiledCode .= $this->CompileConstant($oConstant)."\n";
  138. }
  139. }
  140. $oClasses = $this->oFactory->ListClasses($sModuleName);
  141. $iClassCount = $oClasses->length;
  142. if ($iClassCount == 0)
  143. {
  144. $this->Log("Found module without classes declared: $sModuleName");
  145. }
  146. else
  147. {
  148. foreach($oClasses as $oClass)
  149. {
  150. $sClass = $oClass->getAttribute("id");
  151. $aAllClasses[] = $sClass;
  152. try
  153. {
  154. $sCompiledCode .= $this->CompileClass($oClass, $sTempTargetDir, $sFinalTargetDir, $sRelativeDir, $oP);
  155. }
  156. catch (DOMFormatException $e)
  157. {
  158. throw new Exception("Failed to process class '$sClass', from '$sModuleRootDir': ".$e->getMessage());
  159. }
  160. }
  161. }
  162. if (!array_key_exists($sModuleName, $aMenusByModule))
  163. {
  164. $this->Log("Found module without menus declared: $sModuleName");
  165. }
  166. else
  167. {
  168. $sCompiledCode .=
  169. <<<EOF
  170. //
  171. // Menus
  172. //
  173. global \$__comp_menus__; // ensure that the global variable is indeed global !
  174. EOF;
  175. // Preliminary: determine parent menus not defined within the current module
  176. $aMenusToLoad = array();
  177. $aParentMenus = array();
  178. foreach($aMenusByModule[$sModuleName] as $sMenuId)
  179. {
  180. $oMenuNode = $aMenuNodes[$sMenuId];
  181. if ($sParent = $oMenuNode->GetChildText('parent', null))
  182. {
  183. $aMenusToLoad[] = $sParent;
  184. $aParentMenus[] = $sParent;
  185. }
  186. // Note: the order matters: the parents must be defined BEFORE
  187. $aMenusToLoad[] = $sMenuId;
  188. }
  189. $aMenusToLoad = array_unique($aMenusToLoad);
  190. foreach($aMenusToLoad as $sMenuId)
  191. {
  192. $oMenuNode = $aMenuNodes[$sMenuId];
  193. if ($oMenuNode->getAttribute("xsi:type") == 'MenuGroup')
  194. {
  195. // Note: this algorithm is wrong
  196. // 1 - the module may appear empty in the current module, while children are defined in other modules
  197. // 2 - check recursively that child nodes are not empty themselves
  198. // Future algorithm:
  199. // a- browse the modules and build the menu tree
  200. // b- browse the tree and blacklist empty menus
  201. // c- before compiling, discard if blacklisted
  202. if (!in_array($oMenuNode->getAttribute("id"), $aParentMenus))
  203. {
  204. // Discard empty menu groups
  205. continue;
  206. }
  207. }
  208. try
  209. {
  210. $sCompiledCode .= $this->CompileMenu($oMenuNode, $sTempTargetDir, $sFinalTargetDir, $sRelativeDir, $oP);
  211. }
  212. catch (DOMFormatException $e)
  213. {
  214. throw new Exception("Failed to process menu '$sMenuId', from '$sModuleRootDir': ".$e->getMessage());
  215. }
  216. }
  217. }
  218. // User rights
  219. //
  220. if ($sModuleName == $sUserRightsModule)
  221. {
  222. $sCompiledCode .= $this->CompileUserRights($oUserRightsNode);
  223. }
  224. // Create (overwrite if existing) the compiled file
  225. //
  226. if (strlen($sCompiledCode) > 0)
  227. {
  228. // We have compiled something: write the result file
  229. //
  230. $sResultFile = $sTempTargetDir.'/'.$sRelativeDir.'/model.'.$sModuleName.'.php';
  231. if (is_file($sResultFile))
  232. {
  233. $this->Log("Updating $sResultFile for module $sModuleName in version $sModuleVersion ($iClassCount classes)");
  234. }
  235. else
  236. {
  237. $sResultDir = dirname($sResultFile);
  238. if (!is_dir($sResultDir))
  239. {
  240. $this->Log("Creating directory $sResultDir");
  241. mkdir($sResultDir, 0777, true);
  242. }
  243. $this->Log("Creating $sResultFile for module $sModuleName in version $sModuleVersion ($iClassCount classes)");
  244. }
  245. // Compile the module into a single file
  246. //
  247. $sId = $sModuleName;
  248. $sCurrDate = date(DATE_ISO8601);
  249. $sAuthor = 'iTop compiler';
  250. $sLicence = 'http://opensource.org/licenses/AGPL-3.0';
  251. $sFileHeader =
  252. <<<EOF
  253. <?php
  254. //
  255. // File generated by ... on the $sCurrDate
  256. // Please do not edit manually
  257. //
  258. /**
  259. * Classes and menus for $sModuleName (version $sModuleVersion)
  260. *
  261. * @author $sAuthor
  262. * @license $sLicence
  263. */
  264. EOF;
  265. $ret = file_put_contents($sResultFile, $sFileHeader.$sCompiledCode);
  266. if ($ret === false)
  267. {
  268. $iLen = strlen($sFileHeader.$sCompiledCode);
  269. $fFree = @disk_free_space(dirname($sResultFile));
  270. $aErr = error_get_last();
  271. throw new Exception("Failed to write '$sResultFile'. Last error: '{$aErr['message']}', content to write: $iLen bytes, available free space on disk: $fFree.");
  272. }
  273. }
  274. else
  275. {
  276. $this->Log("Compilation of module $sModuleName in version $sModuleVersion produced not code at all. No file written.");
  277. }
  278. } // foreach module
  279. // Compile the dictionaries -out of the modules
  280. //
  281. $sDictDir = $sTempTargetDir.'/dictionaries';
  282. if (!is_dir($sDictDir))
  283. {
  284. $this->Log("Creating directory $sDictDir");
  285. mkdir($sDictDir, 0777, true);
  286. }
  287. $oDictionaries = $this->oFactory->ListActiveChildNodes('dictionaries', 'dictionary');
  288. foreach($oDictionaries as $oDictionaryNode)
  289. {
  290. $this->CompileDictionary($oDictionaryNode, $sTempTargetDir, $sFinalTargetDir);
  291. }
  292. // Compile the branding
  293. //
  294. $oBrandingNode = $this->oFactory->GetNodes('branding')->item(0);
  295. $this->CompileBranding($oBrandingNode, $sTempTargetDir, $sFinalTargetDir);
  296. } // DoCompile()
  297. /**
  298. * Helper to form a valid ZList from the array built by GetNodeAsArrayOfItems()
  299. */
  300. protected function ArrayOfItemsToZList(&$aItems)
  301. {
  302. $aTransformed = array();
  303. foreach ($aItems as $key => $value)
  304. {
  305. if (is_null($value))
  306. {
  307. $aTransformed[] = $key;
  308. }
  309. else
  310. {
  311. if (is_array($value))
  312. {
  313. $this->ArrayOfItemsToZList($value);
  314. }
  315. $aTransformed[$key] = $value;
  316. }
  317. }
  318. $aItems = $aTransformed;
  319. }
  320. /**
  321. * Helper to format the flags for an attribute, in a given state
  322. * @param object $oAttNode DOM node containing the information to build the flags
  323. * Returns string PHP flags, based on the OPT_ATT_ constants, or empty (meaning 0, can be omitted)
  324. */
  325. protected function FlagsToPHP($oAttNode)
  326. {
  327. static $aNodeAttributeToFlag = array(
  328. 'mandatory' => 'OPT_ATT_MANDATORY',
  329. 'read_only' => 'OPT_ATT_READONLY',
  330. 'must_prompt' => 'OPT_ATT_MUSTPROMPT',
  331. 'must_change' => 'OPT_ATT_MUSTCHANGE',
  332. 'hidden' => 'OPT_ATT_HIDDEN',
  333. );
  334. $aFlags = array();
  335. foreach ($aNodeAttributeToFlag as $sNodeAttribute => $sFlag)
  336. {
  337. $bFlag = ($oAttNode->GetOptionalElement($sNodeAttribute) != null);
  338. if ($bFlag)
  339. {
  340. $aFlags[] = $sFlag;
  341. }
  342. }
  343. $sRes = implode(' | ', $aFlags);
  344. return $sRes;
  345. }
  346. /**
  347. * Helper to format the tracking level for linkset (direct or indirect attributes)
  348. * @param string $sTrackingLevel Value set from within the XML
  349. * Returns string PHP flag
  350. */
  351. protected function TrackingLevelToPHP($sAttType, $sTrackingLevel)
  352. {
  353. static $aXmlToPHP_Links = array(
  354. 'none' => 'LINKSET_TRACKING_NONE',
  355. 'list' => 'LINKSET_TRACKING_LIST',
  356. 'details' => 'LINKSET_TRACKING_DETAILS',
  357. 'all' => 'LINKSET_TRACKING_ALL',
  358. );
  359. static $aXmlToPHP_Others = array(
  360. 'none' => 'ATTRIBUTE_TRACKING_NONE',
  361. 'all' => 'ATTRIBUTE_TRACKING_ALL',
  362. );
  363. switch ($sAttType)
  364. {
  365. case 'AttributeLinkedSetIndirect':
  366. case 'AttributeLinkedSet':
  367. $aXmlToPHP = $aXmlToPHP_Links;
  368. break;
  369. default:
  370. $aXmlToPHP = $aXmlToPHP_Others;
  371. }
  372. if (!array_key_exists($sTrackingLevel, $aXmlToPHP))
  373. {
  374. throw new DOMFormatException("Tracking level: unknown value '$sTrackingLevel', expecting a value in {".implode(', ', array_keys($aXmlToPHP))."}");
  375. }
  376. return $aXmlToPHP[$sTrackingLevel];
  377. }
  378. /**
  379. * Helper to format the edit-mode for direct linkset
  380. * @param string $sEditMode Value set from within the XML
  381. * Returns string PHP flag
  382. */
  383. protected function EditModeToPHP($sEditMode)
  384. {
  385. static $aXmlToPHP = array(
  386. 'none' => 'LINKSET_EDITMODE_NONE',
  387. 'add_only' => 'LINKSET_EDITMODE_ADDONLY',
  388. 'actions' => 'LINKSET_EDITMODE_ACTIONS',
  389. 'in_place' => 'LINKSET_EDITMODE_INPLACE',
  390. 'add_remove' => 'LINKSET_EDITMODE_ADDREMOVE',
  391. );
  392. if (!array_key_exists($sEditMode, $aXmlToPHP))
  393. {
  394. throw new DOMFormatException("Edit mode: unknown value '$sEditMode'");
  395. }
  396. return $aXmlToPHP[$sEditMode];
  397. }
  398. /**
  399. * Format a path (file or url) as an absolute path or relative to the module or the app
  400. */
  401. protected function PathToPHP($sPath, $sModuleRelativeDir, $bIsUrl = false)
  402. {
  403. if ($sPath == '')
  404. {
  405. $sPHP = "''";
  406. }
  407. elseif (substr($sPath, 0, 2) == '$$')
  408. {
  409. // Absolute
  410. $sPHP = self::QuoteForPHP(substr($sPath, 2));
  411. }
  412. elseif (substr($sPath, 0, 1) == '$')
  413. {
  414. // Relative to the application
  415. if ($bIsUrl)
  416. {
  417. $sPHP = "utils::GetAbsoluteUrlAppRoot().".self::QuoteForPHP(substr($sPath, 1));
  418. }
  419. else
  420. {
  421. $sPHP = "APPROOT.".self::QuoteForPHP(substr($sPath, 1));
  422. }
  423. }
  424. else
  425. {
  426. // Relative to the module
  427. if ($bIsUrl)
  428. {
  429. $sPHP = "utils::GetAbsoluteUrlAppRoot().".self::QuoteForPHP($sModuleRelativeDir.''.$sPath);
  430. }
  431. else
  432. {
  433. $sPHP = "dirname(__FILE__).'/$sPath'";
  434. }
  435. }
  436. return $sPHP;
  437. }
  438. protected function GetPropString($oNode, $sTag, $sDefault = null)
  439. {
  440. $val = $oNode->GetChildText($sTag);
  441. if (is_null($val))
  442. {
  443. if (is_null($sDefault))
  444. {
  445. return null;
  446. }
  447. else
  448. {
  449. $val = $sDefault;
  450. }
  451. }
  452. return "'".$val."'";
  453. }
  454. protected function GetMandatoryPropString($oNode, $sTag)
  455. {
  456. $val = $oNode->GetChildText($sTag);
  457. if (!is_null($val) && ($val !== ''))
  458. {
  459. return "'".$val."'";
  460. }
  461. else
  462. {
  463. throw new DOMFormatException("missing (or empty) mandatory tag '$sTag' under the tag '".$oNode->nodeName."'");
  464. }
  465. }
  466. protected function GetPropBoolean($oNode, $sTag, $bDefault = null)
  467. {
  468. $val = $oNode->GetChildText($sTag);
  469. if (is_null($val))
  470. {
  471. if (is_null($bDefault))
  472. {
  473. return null;
  474. }
  475. else
  476. {
  477. return $bDefault ? 'true' : 'false';
  478. }
  479. }
  480. return $val == 'true' ? 'true' : 'false';
  481. }
  482. protected function GetPropNumber($oNode, $sTag, $nDefault = null)
  483. {
  484. $val = $oNode->GetChildText($sTag);
  485. if (is_null($val))
  486. {
  487. if (is_null($nDefault))
  488. {
  489. return null;
  490. }
  491. else
  492. {
  493. $val = $nDefault;
  494. }
  495. }
  496. return (string)$val;
  497. }
  498. /**
  499. * Adds quotes and escape characters
  500. */
  501. protected function QuoteForPHP($sStr, $bSimpleQuotes = false)
  502. {
  503. if ($bSimpleQuotes)
  504. {
  505. $sEscaped = str_replace(array('\\', "'"), array('\\\\', "\\'"), $sStr);
  506. $sRet = "'$sEscaped'";
  507. }
  508. else
  509. {
  510. $sEscaped = str_replace(array('\\', '"', "\n"), array('\\\\', '\\"', '\\n'), $sStr);
  511. $sRet = '"'.$sEscaped.'"';
  512. }
  513. return $sRet;
  514. }
  515. protected function CompileConstant($oConstant)
  516. {
  517. $sName = $oConstant->getAttribute('id');
  518. $sType = $oConstant->getAttribute('xsi:type');
  519. $sText = $oConstant->GetText(null);
  520. switch ($sType)
  521. {
  522. case 'integer':
  523. if (is_null($sText))
  524. {
  525. // No data given => null
  526. $sScalar = 'null';
  527. }
  528. else
  529. {
  530. $sScalar = (string)(int)$sText;
  531. }
  532. break;
  533. case 'float':
  534. if (is_null($sText))
  535. {
  536. // No data given => null
  537. $sScalar = 'null';
  538. }
  539. else
  540. {
  541. $sScalar = (string)(float)$sText;
  542. }
  543. break;
  544. case 'bool':
  545. if (is_null($sText))
  546. {
  547. // No data given => null
  548. $sScalar = 'null';
  549. }
  550. else
  551. {
  552. $sScalar = ($sText == 'true') ? 'true' : 'false';
  553. }
  554. break;
  555. case 'string':
  556. default:
  557. $sScalar = $this->QuoteForPHP($sText, true);
  558. }
  559. $sPHPDefine = "define('$sName', $sScalar);";
  560. return $sPHPDefine;
  561. }
  562. protected function CompileClass($oClass, $sTempTargetDir, $sFinalTargetDir, $sModuleRelativeDir, $oP)
  563. {
  564. $sClass = $oClass->getAttribute('id');
  565. $oProperties = $oClass->GetUniqueElement('properties');
  566. // Class caracteristics
  567. //
  568. $aClassParams = array();
  569. $aClassParams['category'] = $this->GetPropString($oProperties, 'category', '');
  570. $aClassParams['key_type'] = "'autoincrement'";
  571. if ((bool) $this->GetPropNumber($oProperties, 'is_link', 0))
  572. {
  573. $aClassParams['is_link'] = 'true';
  574. }
  575. if ($oNaming = $oProperties->GetOptionalElement('naming'))
  576. {
  577. $oNameAttributes = $oNaming->GetUniqueElement('attributes');
  578. $oAttributes = $oNameAttributes->getElementsByTagName('attribute');
  579. $aNameAttCodes = array();
  580. foreach($oAttributes as $oAttribute)
  581. {
  582. $aNameAttCodes[] = $oAttribute->getAttribute('id');
  583. }
  584. if (count($aNameAttCodes) > 1)
  585. {
  586. // New style...
  587. $sNameAttCode = "array('".implode("', '", $aNameAttCodes)."')";
  588. }
  589. elseif (count($aNameAttCodes) == 1)
  590. {
  591. // New style...
  592. $sNameAttCode = "'$aNameAttCodes[0]'";
  593. }
  594. else
  595. {
  596. $sNameAttCode = "''";
  597. }
  598. }
  599. else
  600. {
  601. $sNameAttCode = "''";
  602. }
  603. $aClassParams['name_attcode'] = $sNameAttCode;
  604. $oLifecycle = $oClass->GetOptionalElement('lifecycle');
  605. if ($oLifecycle)
  606. {
  607. $sStateAttCode = $oLifecycle->GetChildText('attribute');
  608. }
  609. else
  610. {
  611. $sStateAttCode = "";
  612. }
  613. $aClassParams['state_attcode'] = "'$sStateAttCode'";
  614. if ($oReconciliation = $oProperties->GetOptionalElement('reconciliation'))
  615. {
  616. $oReconcAttributes = $oReconciliation->getElementsByTagName('attribute');
  617. $aReconcAttCodes = array();
  618. foreach($oReconcAttributes as $oAttribute)
  619. {
  620. $aReconcAttCodes[] = $oAttribute->getAttribute('id');
  621. }
  622. $sReconcKeys = "array('".implode("', '", $aReconcAttCodes)."')";
  623. }
  624. else
  625. {
  626. $sReconcKeys = "array()";
  627. }
  628. $aClassParams['reconc_keys'] = $sReconcKeys;
  629. $aClassParams['db_table'] = $this->GetPropString($oProperties, 'db_table', '');
  630. $aClassParams['db_key_field'] = $this->GetPropString($oProperties, 'db_key_field', 'id');
  631. if (array_key_exists($sClass, $this->aRootClasses))
  632. {
  633. $sDefaultFinalClass = 'finalclass';
  634. }
  635. else
  636. {
  637. $sDefaultFinalClass = '';
  638. }
  639. $aClassParams['db_finalclass_field'] = $this->GetPropString($oProperties, 'db_final_class_field', $sDefaultFinalClass);
  640. if (($sDisplayTemplate = $oProperties->GetChildText('display_template')) && (strlen($sDisplayTemplate) > 0))
  641. {
  642. $sDisplayTemplate = $sModuleRelativeDir.'/'.$sDisplayTemplate;
  643. $aClassParams['display_template'] = "utils::GetAbsoluteUrlModulesRoot().'$sDisplayTemplate'";
  644. }
  645. $this->CompileFiles($oProperties, $sTempTargetDir.'/'.$sModuleRelativeDir, $sFinalTargetDir.'/'.$sModuleRelativeDir, '');
  646. if (($sIcon = $oProperties->GetChildText('icon')) && (strlen($sIcon) > 0))
  647. {
  648. $sIcon = $sModuleRelativeDir.'/'.$sIcon;
  649. $aClassParams['icon'] = "utils::GetAbsoluteUrlModulesRoot().'$sIcon'";
  650. }
  651. $oOrder = $oProperties->GetOptionalElement('order');
  652. if ($oOrder)
  653. {
  654. $oColumnsNode = $oOrder->GetUniqueElement('columns');
  655. $oColumns = $oColumnsNode->getElementsByTagName('column');
  656. $aSortColumns = array();
  657. foreach($oColumns as $oColumn)
  658. {
  659. $aSortColumns[] = "'".$oColumn->getAttribute('id')."' => ".(($oColumn->getAttribute('ascending') == 'true') ? 'true' : 'false');
  660. }
  661. if (count($aSortColumns) > 0)
  662. {
  663. $aClassParams['order_by_default'] = "array(".implode(", ", $aSortColumns).")";
  664. }
  665. }
  666. if ($oIndexes = $oProperties->GetOptionalElement('indexes'))
  667. {
  668. $aIndexes = array();
  669. foreach($oIndexes->getElementsByTagName('index') as $oIndex)
  670. {
  671. $sIndexId = $oIndex->getAttribute('id');
  672. $oAttributes = $oIndex->GetUniqueElement('attributes');
  673. foreach($oAttributes->getElementsByTagName('attribute') as $oAttribute)
  674. {
  675. $aIndexes[$sIndexId][] = $oAttribute->getAttribute('id');
  676. }
  677. }
  678. $aClassParams['indexes'] = var_export($aIndexes, true);
  679. }
  680. // Finalize class params declaration
  681. //
  682. $aClassParamsPHP = array();
  683. foreach($aClassParams as $sKey => $sPHPValue)
  684. {
  685. $aClassParamsPHP[] = " '$sKey' => $sPHPValue,";
  686. }
  687. $sClassParams = implode("\n", $aClassParamsPHP);
  688. // Comment on top of the class declaration
  689. //
  690. $sCodeComment = $oProperties->GetChildText('comment');
  691. // Fields
  692. //
  693. $sAttributes = '';
  694. foreach($this->oFactory->ListFields($oClass) as $oField)
  695. {
  696. try
  697. {
  698. // $oField
  699. $sAttCode = $oField->getAttribute('id');
  700. $sAttType = $oField->getAttribute('xsi:type');
  701. $aDependencies = array();
  702. $oDependencies = $oField->GetOptionalElement('dependencies');
  703. if (!is_null($oDependencies))
  704. {
  705. $oDepNodes = $oDependencies->getElementsByTagName('attribute');
  706. foreach($oDepNodes as $oDepAttribute)
  707. {
  708. $aDependencies[] = "'".$oDepAttribute->getAttribute('id')."'";
  709. }
  710. }
  711. $sDependencies = 'array('.implode(', ', $aDependencies).')';
  712. $aParameters = array();
  713. if ($sAttType == 'AttributeLinkedSetIndirect')
  714. {
  715. $aParameters['linked_class'] = $this->GetMandatoryPropString($oField, 'linked_class', '');
  716. $aParameters['ext_key_to_me'] = $this->GetMandatoryPropString($oField, 'ext_key_to_me', '');
  717. $aParameters['ext_key_to_remote'] = $this->GetMandatoryPropString($oField, 'ext_key_to_remote', '');
  718. $aParameters['allowed_values'] = 'null';
  719. $aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0);
  720. $aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0);
  721. $aParameters['duplicates'] = $this->GetPropBoolean($oField, 'duplicates', false);
  722. $aParameters['depends_on'] = $sDependencies;
  723. }
  724. elseif ($sAttType == 'AttributeLinkedSet')
  725. {
  726. $aParameters['linked_class'] = $this->GetMandatoryPropString($oField, 'linked_class', '');
  727. $aParameters['ext_key_to_me'] = $this->GetMandatoryPropString($oField, 'ext_key_to_me', '');
  728. $aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0);
  729. $aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0);
  730. $sEditMode = $oField->GetChildText('edit_mode');
  731. if (!is_null($sEditMode))
  732. {
  733. $aParameters['edit_mode'] = $this->EditModeToPHP($sEditMode);
  734. }
  735. if ($sOql = $oField->GetChildText('filter'))
  736. {
  737. $sEscapedOql = self::QuoteForPHP($sOql);
  738. $aParameters['allowed_values'] = "new ValueSetObjects($sEscapedOql)";
  739. }
  740. else
  741. {
  742. $aParameters['allowed_values'] = 'null';
  743. }
  744. $aParameters['depends_on'] = $sDependencies;
  745. }
  746. elseif ($sAttType == 'AttributeExternalKey')
  747. {
  748. $aParameters['targetclass'] = $this->GetPropString($oField, 'target_class', '');
  749. // deprecated: $aParameters['jointype'] = 'null';
  750. if ($sOql = $oField->GetChildText('filter'))
  751. {
  752. $sEscapedOql = self::QuoteForPHP($sOql);
  753. $aParameters['allowed_values'] = "new ValueSetObjects($sEscapedOql)"; // or "new ValueSetObjects('SELECT xxxx')"
  754. }
  755. else
  756. {
  757. $aParameters['allowed_values'] = 'null'; // or "new ValueSetObjects('SELECT xxxx')"
  758. }
  759. $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql', '');
  760. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  761. $aParameters['on_target_delete'] = $oField->GetChildText('on_target_delete');
  762. $aParameters['depends_on'] = $sDependencies;
  763. $aParameters['max_combo_length'] = $this->GetPropNumber($oField, 'max_combo_length');
  764. $aParameters['min_autocomplete_chars'] = $this->GetPropNumber($oField, 'min_autocomplete_chars');
  765. $aParameters['allow_target_creation'] = $this->GetPropBoolean($oField, 'allow_target_creation');
  766. $aParameters['display_style'] = $this->GetPropString($oField, 'display_style', 'select');
  767. }
  768. elseif ($sAttType == 'AttributeHierarchicalKey')
  769. {
  770. if ($sOql = $oField->GetChildText('filter'))
  771. {
  772. $sEscapedOql = self::QuoteForPHP($sOql);
  773. $aParameters['allowed_values'] = "new ValueSetObjects($sEscapedOql)"; // or "new ValueSetObjects('SELECT xxxx')"
  774. }
  775. else
  776. {
  777. $aParameters['allowed_values'] = 'null'; // or "new ValueSetObjects('SELECT xxxx')"
  778. }
  779. $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql', '');
  780. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  781. $aParameters['on_target_delete'] = $oField->GetChildText('on_target_delete');
  782. $aParameters['depends_on'] = $sDependencies;
  783. $aParameters['max_combo_length'] = $this->GetPropNumber($oField, 'max_combo_length');
  784. $aParameters['min_autocomplete_chars'] = $this->GetPropNumber($oField, 'min_autocomplete_chars');
  785. $aParameters['allow_target_creation'] = $this->GetPropBoolean($oField, 'allow_target_creation');
  786. }
  787. elseif ($sAttType == 'AttributeExternalField')
  788. {
  789. $aParameters['allowed_values'] = 'null';
  790. $aParameters['extkey_attcode'] = $this->GetMandatoryPropString($oField, 'extkey_attcode', '');
  791. $aParameters['target_attcode'] = $this->GetMandatoryPropString($oField, 'target_attcode', '');
  792. }
  793. elseif ($sAttType == 'AttributeURL')
  794. {
  795. $aParameters['target'] = $this->GetPropString($oField, 'target', '');
  796. $aParameters['allowed_values'] = 'null';
  797. $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql', '');
  798. $aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');
  799. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  800. $aParameters['depends_on'] = $sDependencies;
  801. }
  802. elseif ($sAttType == 'AttributeEnum')
  803. {
  804. $oValues = $oField->GetUniqueElement('values');
  805. $oValueNodes = $oValues->getElementsByTagName('value');
  806. $aValues = array();
  807. foreach($oValueNodes as $oValue)
  808. {
  809. // new style... $aValues[] = self::QuoteForPHP($oValue->textContent);
  810. $aValues[] = $oValue->textContent;
  811. }
  812. // new style... $sValues = 'array('.implode(', ', $aValues).')';
  813. $sValues = '"'.implode(',', $aValues).'"';
  814. $aParameters['allowed_values'] = "new ValueSetEnum($sValues)";
  815. $aParameters['display_style'] = $this->GetPropString($oField, 'display_style', 'list');
  816. $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql', '');
  817. $aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');
  818. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  819. $aParameters['depends_on'] = $sDependencies;
  820. }
  821. elseif ($sAttType == 'AttributeBlob')
  822. {
  823. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  824. $aParameters['depends_on'] = $sDependencies;
  825. }
  826. elseif ($sAttType == 'AttributeStopWatch')
  827. {
  828. $oStates = $oField->GetUniqueElement('states');
  829. $oStateNodes = $oStates->getElementsByTagName('state');
  830. $aStates = array();
  831. foreach($oStateNodes as $oState)
  832. {
  833. $aStates[] = '"'.$oState->GetAttribute('id').'"';
  834. }
  835. $aParameters['states'] = 'array('.implode(', ', $aStates).')';
  836. $aParameters['goal_computing'] = $this->GetPropString($oField, 'goal', 'DefaultMetricComputer'); // Optional, no deadline by default
  837. $aParameters['working_time_computing'] = $this->GetPropString($oField, 'working_time', ''); // Blank (different than DefaultWorkingTimeComputer)
  838. $oThresholds = $oField->GetUniqueElement('thresholds');
  839. $oThresholdNodes = $oThresholds->getElementsByTagName('threshold');
  840. $aThresholds = array();
  841. foreach($oThresholdNodes as $oThreshold)
  842. {
  843. $iPercent = $this->GetPropNumber($oThreshold, 'percent');
  844. $oActions = $oThreshold->GetUniqueElement('actions');
  845. $oActionNodes = $oActions->getElementsByTagName('action');
  846. $aActions = array();
  847. foreach($oActionNodes as $oAction)
  848. {
  849. $oParams = $oAction->GetOptionalElement('params');
  850. $aActionParams = array();
  851. if ($oParams)
  852. {
  853. $oParamNodes = $oParams->getElementsByTagName('param');
  854. foreach($oParamNodes as $oParam)
  855. {
  856. $aActionParams[] = self::QuoteForPHP($oParam->textContent);
  857. }
  858. }
  859. $sActionParams = 'array('.implode(', ', $aActionParams).')';
  860. $sVerb = $this->GetPropString($oAction, 'verb');
  861. $aActions[] = "array('verb' => $sVerb, 'params' => $sActionParams)";
  862. }
  863. $sActions = 'array('.implode(', ', $aActions).')';
  864. $aThresholds[] = $iPercent." => array('percent' => $iPercent, 'actions' => $sActions)";
  865. }
  866. $aParameters['thresholds'] = 'array('.implode(', ', $aThresholds).')';
  867. }
  868. elseif ($sAttType == 'AttributeSubItem')
  869. {
  870. $aParameters['target_attcode'] = $this->GetMandatoryPropString($oField, 'target_attcode');
  871. $aParameters['item_code'] = $this->GetMandatoryPropString($oField, 'item_code');
  872. }
  873. else
  874. {
  875. $aParameters['allowed_values'] = 'null'; // or "new ValueSetEnum('SELECT xxxx')"
  876. $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql', '');
  877. $aParameters['default_value'] = $this->GetPropString($oField, 'default_value', '');
  878. $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false);
  879. $aParameters['depends_on'] = $sDependencies;
  880. }
  881. // Optional parameters (more for historical reasons)
  882. // Added if present...
  883. //
  884. $aParameters['validation_pattern'] = $this->GetPropString($oField, 'validation_pattern');
  885. $aParameters['width'] = $this->GetPropNumber($oField, 'width');
  886. $aParameters['height'] = $this->GetPropNumber($oField, 'height');
  887. $aParameters['digits'] = $this->GetPropNumber($oField, 'digits');
  888. $aParameters['decimals'] = $this->GetPropNumber($oField, 'decimals');
  889. $aParameters['always_load_in_tables'] = $this->GetPropBoolean($oField, 'always_load_in_tables', false);
  890. $sTrackingLevel = $oField->GetChildText('tracking_level');
  891. if (!is_null($sTrackingLevel))
  892. {
  893. $aParameters['tracking_level'] = $this->TrackingLevelToPHP($sAttType, $sTrackingLevel);
  894. }
  895. $aParams = array();
  896. foreach($aParameters as $sKey => $sValue)
  897. {
  898. if (!is_null($sValue))
  899. {
  900. $aParams[] = '"'.$sKey.'"=>'.$sValue;
  901. }
  902. }
  903. $sParams = implode(', ', $aParams);
  904. $sAttributes .= " MetaModel::Init_AddAttribute(new $sAttType(\"$sAttCode\", array($sParams)));\n";
  905. }
  906. catch(Exception $e)
  907. {
  908. throw new DOMFormatException("Field: '$sAttCode', (type: $sAttType), ".$e->getMessage());
  909. }
  910. }
  911. // Lifecycle
  912. //
  913. $sLifecycle = '';
  914. if ($oLifecycle)
  915. {
  916. $sLifecycle .= "\t\t// Lifecycle (status attribute: $sStateAttCode)\n";
  917. $sLifecycle .= "\t\t//\n";
  918. $oStimuli = $oLifecycle->GetUniqueElement('stimuli');
  919. foreach ($oStimuli->getElementsByTagName('stimulus') as $oStimulus)
  920. {
  921. $sStimulus = $oStimulus->getAttribute('id');
  922. $sStimulusClass = $oStimulus->getAttribute('xsi:type');
  923. $sLifecycle .= " MetaModel::Init_DefineStimulus(new ".$sStimulusClass."(\"".$sStimulus."\", array()));\n";
  924. }
  925. $oStates = $oLifecycle->GetUniqueElement('states');
  926. foreach ($oStates->getElementsByTagName('state') as $oState)
  927. {
  928. $sState = $oState->getAttribute('id');
  929. $oInitialStatePath = $oState->GetOptionalElement('initial_state_path');
  930. if ($oInitialStatePath)
  931. {
  932. $aInitialStatePath = array();
  933. foreach ($oInitialStatePath->getElementsByTagName('state_ref') as $oIntermediateState)
  934. {
  935. $aInitialStatePath[] = "'".$oIntermediateState->GetText()."'";
  936. }
  937. $sInitialStatePath = 'Array('.implode(', ', $aInitialStatePath).')';
  938. }
  939. $sLifecycle .= " MetaModel::Init_DefineState(\n";
  940. $sLifecycle .= " \"".$sState."\",\n";
  941. $sLifecycle .= " array(\n";
  942. $sLifecycle .= " \"attribute_inherit\" => '',\n";
  943. $sLifecycle .= " \"attribute_list\" => array(\n";
  944. $oFlags = $oState->GetUniqueElement('flags');
  945. foreach ($oFlags->getElementsByTagName('attribute') as $oAttributeNode)
  946. {
  947. $sFlags = $this->FlagsToPHP($oAttributeNode);
  948. if (strlen($sFlags) > 0)
  949. {
  950. $sAttCode = $oAttributeNode->GetAttribute('id');
  951. $sLifecycle .= " '$sAttCode' => $sFlags,\n";
  952. }
  953. }
  954. $sLifecycle .= " ),\n";
  955. if (!is_null($oInitialStatePath))
  956. {
  957. $sLifecycle .= " \"initial_state_path\" => $sInitialStatePath,\n";
  958. }
  959. $sLifecycle .= " )\n";
  960. $sLifecycle .= " );\n";
  961. $oTransitions = $oState->GetUniqueElement('transitions');
  962. foreach ($oTransitions->getElementsByTagName('transition') as $oTransition)
  963. {
  964. $sStimulus = $oTransition->GetChildText('stimulus');
  965. $sTargetState = $oTransition->GetChildText('target');
  966. $oActions = $oTransition->GetUniqueElement('actions');
  967. $aVerbs = array();
  968. foreach ($oActions->getElementsByTagName('action') as $oAction)
  969. {
  970. $sVerb = $oAction->GetChildText('verb');
  971. $aVerbs[] = "'$sVerb'";
  972. }
  973. $sActions = implode(', ', $aVerbs);
  974. $sLifecycle .= " MetaModel::Init_DefineTransition(\"$sState\", \"$sStimulus\", array(\"target_state\"=>\"$sTargetState\", \"actions\"=>array($sActions), \"user_restriction\"=>null));\n";
  975. }
  976. }
  977. }
  978. // ZLists
  979. //
  980. $aListRef = array(
  981. 'details' => 'details',
  982. 'standard_search' => 'search',
  983. 'list' => 'list'
  984. );
  985. $oPresentation = $oClass->GetUniqueElement('presentation');
  986. $sZlists = '';
  987. foreach ($aListRef as $sListCode => $sListTag)
  988. {
  989. $oListNode = $oPresentation->GetOptionalElement($sListTag);
  990. if ($oListNode)
  991. {
  992. $aAttributes = $oListNode->GetNodeAsArrayOfItems();
  993. $this->ArrayOfItemsToZList($aAttributes);
  994. $sZAttributes = var_export($aAttributes, true);
  995. $sZlists .= " MetaModel::Init_SetZListItems('$sListCode', $sZAttributes);\n";
  996. }
  997. }
  998. // Methods
  999. $sMethods = "";
  1000. $oMethods = $oClass->GetUniqueElement('methods');
  1001. foreach($oMethods->getElementsByTagName('method') as $oMethod)
  1002. {
  1003. $sMethodCode = $oMethod->GetChildText('code');
  1004. if ($sMethodComment = $oMethod->GetChildText('comment', null))
  1005. {
  1006. $sMethods .= "\n\t$sMethodComment\n".$sMethodCode."\n";
  1007. }
  1008. else
  1009. {
  1010. $sMethods .= "\n\n".$sMethodCode."\n";
  1011. }
  1012. }
  1013. // Let's make the whole class declaration
  1014. //
  1015. $sPHP = "\n\n$sCodeComment\n";
  1016. $sParentClass = $oClass->GetChildText('php_parent');
  1017. $oPhpParent = $oClass->GetUniqueElement('php_parent', false);
  1018. if ($oPhpParent)
  1019. {
  1020. $sParentClass = $oPhpParent->GetChildText('name', '');
  1021. if ($sParentClass == '')
  1022. {
  1023. throw new Exception("Failed to process class '".$oClass->getAttribute('id')."', missing required tag 'name' under 'php_parent'.");
  1024. }
  1025. $sIncludeFile = $oPhpParent->GetChildText('file', '');
  1026. if ($sIncludeFile != '')
  1027. {
  1028. $sPHP .= "\nrequire_once('$sIncludeFile'); // Implementation of the class $sParentClass\n";
  1029. }
  1030. //TODO fix this !!!
  1031. // $sFullPath = $this->sSourceDir.'/'.$sModuleRelativeDir.'/'.$sIncludeFile;
  1032. // if (!file_exists($sFullPath))
  1033. // {
  1034. // throw new Exception("Failed to process class '".$oClass->getAttribute('id')."', from '$sModuleRelativeDir'. The required include file: '$sFullPath' does not exist.");
  1035. // }
  1036. }
  1037. else
  1038. {
  1039. $sParentClass = $oClass->GetChildText('parent', 'DBObject');
  1040. }
  1041. if ($oProperties->GetChildText('abstract') == 'true')
  1042. {
  1043. $sPHP .= 'abstract class '.$oClass->getAttribute('id');
  1044. }
  1045. else
  1046. {
  1047. $sPHP .= 'class '.$oClass->getAttribute('id');
  1048. }
  1049. $sPHP .= " extends $sParentClass\n";
  1050. $sPHP .=
  1051. <<<EOF
  1052. {
  1053. public static function Init()
  1054. {
  1055. \$aParams = array
  1056. (
  1057. $sClassParams
  1058. );
  1059. MetaModel::Init_Params(\$aParams);
  1060. MetaModel::Init_InheritAttributes();
  1061. $sAttributes
  1062. $sLifecycle
  1063. $sZlists
  1064. }
  1065. $sMethods
  1066. }
  1067. EOF;
  1068. return $sPHP;
  1069. }// function CompileClass()
  1070. protected function CompileMenu($oMenu, $sTempTargetDir, $sFinalTargetDir, $sModuleRelativeDir, $oP)
  1071. {
  1072. $this->CompileFiles($oMenu, $sTempTargetDir.'/'.$sModuleRelativeDir, $sFinalTargetDir.'/'.$sModuleRelativeDir, $sModuleRelativeDir);
  1073. $sMenuId = $oMenu->getAttribute("id");
  1074. $sMenuClass = $oMenu->getAttribute("xsi:type");
  1075. $sParent = $oMenu->GetChildText('parent', null);
  1076. if ($sParent)
  1077. {
  1078. $sParentSpec = "\$__comp_menus__['$sParent']->GetIndex()";
  1079. }
  1080. else
  1081. {
  1082. $sParentSpec = '-1';
  1083. }
  1084. $fRank = (float) $oMenu->GetChildText('rank');
  1085. switch($sMenuClass)
  1086. {
  1087. case 'WebPageMenuNode':
  1088. $sUrl = $oMenu->GetChildText('url');
  1089. $sUrlSpec = $this->PathToPHP($sUrl, $sModuleRelativeDir, true /* Url */);
  1090. $sNewMenu = "new WebPageMenuNode('$sMenuId', $sUrlSpec, $sParentSpec, $fRank);";
  1091. break;
  1092. case 'DashboardMenuNode':
  1093. $sTemplateFile = $oMenu->GetChildText('definition_file', '');
  1094. if ($sTemplateFile != '')
  1095. {
  1096. $sTemplateSpec = $this->PathToPHP($sTemplateFile, $sModuleRelativeDir);
  1097. }
  1098. else
  1099. {
  1100. $oDashboardDefinition = $oMenu->GetOptionalElement('definition');
  1101. if ($oDashboardDefinition == null)
  1102. {
  1103. throw(new DOMFormatException('Missing definition for Dashboard menu "'.$sMenuId.'" expecting either a tag "definition_file" or "definition".'));
  1104. }
  1105. $sFileName = strtolower(str_replace(array(':', '/', '\\', '*'), '_', $sMenuId)).'_dashboard_menu.xml';
  1106. $sTemplateSpec = $this->PathToPHP($sFileName, $sModuleRelativeDir);
  1107. $oXMLDoc = new DOMDocument('1.0', 'UTF-8');
  1108. $oXMLDoc->formatOutput = true; // indent (must be loaded with option LIBXML_NOBLANKS)
  1109. $oXMLDoc->preserveWhiteSpace = true; // otherwise the formatOutput option would have no effect
  1110. $oRootNode = $oXMLDoc->createElement('dashboard'); // make sure that the document is not empty
  1111. $oRootNode->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
  1112. $oXMLDoc->appendChild($oRootNode);
  1113. foreach($oDashboardDefinition->childNodes as $oNode)
  1114. {
  1115. $oDefNode = $oXMLDoc->importNode($oNode, true); // layout, cells, etc Nodes and below
  1116. $oRootNode->appendChild($oDefNode);
  1117. }
  1118. $oXMLDoc->save($sTempTargetDir.'/'.$sModuleRelativeDir.'/'.$sFileName);
  1119. }
  1120. $sNewMenu = "new DashboardMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank);";
  1121. break;
  1122. case 'ShortcutContainerMenuNode':
  1123. $sNewMenu = "new ShortcutContainerMenuNode('$sMenuId', $sParentSpec, $fRank);";
  1124. break;
  1125. case 'OQLMenuNode':
  1126. $sOQL = self::QuoteForPHP($oMenu->GetChildText('oql'));
  1127. $bSearch = ($oMenu->GetChildText('do_search') == '1') ? 'true' : 'false';
  1128. $sNewMenu = "new OQLMenuNode('$sMenuId', $sOQL, $sParentSpec, $fRank, $bSearch);";
  1129. break;
  1130. case 'NewObjectMenuNode':
  1131. $sClass = $oMenu->GetChildText('class');
  1132. $sNewMenu = "new NewObjectMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank);";
  1133. break;
  1134. case 'SearchMenuNode':
  1135. $sClass = $oMenu->GetChildText('class');
  1136. $sNewMenu = "new SearchMenuNode('$sMenuId', '$sClass', $sParentSpec, $fRank);";
  1137. break;
  1138. case 'TemplateMenuNode':
  1139. $sTemplateFile = $oMenu->GetChildText('template_file');
  1140. $sTemplateSpec = $this->PathToPHP($sTemplateFile, $sModuleRelativeDir);
  1141. if ($sEnableClass = $oMenu->GetChildText('enable_class'))
  1142. {
  1143. $sEnableAction = $oMenu->GetChildText('enable_action', 'null');
  1144. $sEnablePermission = $oMenu->GetChildText('enable_permission', 'UR_ALLOWED_YES');
  1145. $sEnableStimulus = $oMenu->GetChildText('enable_stimulus');
  1146. if ($sEnableStimulus != null)
  1147. {
  1148. $sNewMenu = "new TemplateMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission, '$sEnableStimulus');";
  1149. }
  1150. else
  1151. {
  1152. $sNewMenu = "new TemplateMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission);";
  1153. }
  1154. }
  1155. else
  1156. {
  1157. $sNewMenu = "new TemplateMenuNode('$sMenuId', $sTemplateSpec, $sParentSpec, $fRank);";
  1158. }
  1159. break;
  1160. case 'MenuGroup':
  1161. default:
  1162. if ($sEnableClass = $oMenu->GetChildText('enable_class'))
  1163. {
  1164. $sEnableAction = $oMenu->GetChildText('enable_action', 'null');
  1165. $sEnablePermission = $oMenu->GetChildText('enable_permission', 'UR_ALLOWED_YES');
  1166. $sEnableStimulus = $oMenu->GetChildText('enable_stimulus');
  1167. if ($sEnableStimulus != null)
  1168. {
  1169. $sNewMenu = "new $sMenuClass('$sMenuId', $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission, '$sEnableStimulus');";
  1170. }
  1171. else
  1172. {
  1173. $sNewMenu = "new $sMenuClass('$sMenuId', $fRank, '$sEnableClass', $sEnableAction, $sEnablePermission);";
  1174. }
  1175. }
  1176. else
  1177. {
  1178. $sNewMenu = "new $sMenuClass('$sMenuId', $fRank);";
  1179. }
  1180. }
  1181. $sIndent = '';
  1182. $aPHPMenu = array("\$__comp_menus__['$sMenuId'] = $sNewMenu");
  1183. if ($sAutoReload = $oMenu->GetChildText('auto_reload'))
  1184. {
  1185. $sAutoReload = self::QuoteForPHP($sAutoReload);
  1186. $aPHPMenu[] = "\$__comp_menus__['$sMenuId']->SetParameters(array('auto_reload' => $sAutoReload));";
  1187. }
  1188. $sAdminOnly = $oMenu->GetChildText('enable_admin_only');
  1189. if ($sAdminOnly && ($sAdminOnly == '1'))
  1190. {
  1191. $sPHP = $sIndent."if (UserRights::IsAdministrator())\n";
  1192. $sPHP .= $sIndent."{\n";
  1193. foreach($aPHPMenu as $sPHPLine)
  1194. {
  1195. $sPHP .= $sIndent." $sPHPLine\n";
  1196. }
  1197. $sPHP .= $sIndent."}\n";
  1198. }
  1199. else
  1200. {
  1201. $sPHP = '';
  1202. foreach($aPHPMenu as $sPHPLine)
  1203. {
  1204. $sPHP .= $sIndent.$sPHPLine."\n";
  1205. }
  1206. }
  1207. return $sPHP;
  1208. } // function CompileMenu
  1209. /**
  1210. * Helper to compute the grant, taking any existing grant into account
  1211. */
  1212. protected function CumulateGrant(&$aGrants, $sKey, $bGrant)
  1213. {
  1214. if (isset($aGrants[$sKey]))
  1215. {
  1216. if (!$bGrant)
  1217. {
  1218. $aGrants[$sKey] = false;
  1219. }
  1220. }
  1221. else
  1222. {
  1223. $aGrants[$sKey] = $bGrant;
  1224. }
  1225. }
  1226. protected function CompileUserRights($oUserRightsNode)
  1227. {
  1228. static $aActionsInShort = array(
  1229. 'read' => 'r',
  1230. 'bulk read' => 'br',
  1231. 'write' => 'w',
  1232. 'bulk write' => 'bw',
  1233. 'delete' => 'd',
  1234. 'bulk delete' => 'bd',
  1235. );
  1236. // Preliminary : create an index so that links will be taken into account implicitely
  1237. $aLinkToClasses = array();
  1238. $oClasses = $this->oFactory->ListAllClasses();
  1239. foreach($oClasses as $oClass)
  1240. {
  1241. $bIsLink = false;
  1242. $oProperties = $oClass->GetOptionalElement('properties');
  1243. if ($oProperties)
  1244. {
  1245. $bIsLink = (bool) $this->GetPropNumber($oProperties, 'is_link', 0);
  1246. }
  1247. if ($bIsLink)
  1248. {
  1249. foreach($this->oFactory->ListFields($oClass) as $oField)
  1250. {
  1251. $sAttType = $oField->getAttribute('xsi:type');
  1252. if (($sAttType == 'AttributeExternalKey') || ($sAttType == 'AttributeHierarchicalKey'))
  1253. {
  1254. $sOnTargetDel = $oField->GetChildText('on_target_delete');
  1255. if ($sOnTargetDel == 'DEL_AUTO')
  1256. {
  1257. $sTargetClass = $oField->GetChildText('target_class');
  1258. $aLinkToClasses[$oClass->getAttribute('id')][] = $sTargetClass;
  1259. }
  1260. }
  1261. }
  1262. }
  1263. }
  1264. // Groups
  1265. //
  1266. $aGroupClasses = array();
  1267. $oGroups = $oUserRightsNode->GetUniqueElement('groups');
  1268. foreach($oGroups->getElementsByTagName('group') as $oGroup)
  1269. {
  1270. $sGroupId = $oGroup->getAttribute("id");
  1271. $aClasses = array();
  1272. $oClasses = $oGroup->GetUniqueElement('classes');
  1273. foreach($oClasses->getElementsByTagName('class') as $oClass)
  1274. {
  1275. $sClass = $oClass->getAttribute("id");
  1276. $aClasses[] = $sClass;
  1277. //$bSubclasses = $this->GetPropBoolean($oClass, 'subclasses', true);
  1278. //if ($bSubclasses)...
  1279. }
  1280. $aGroupClasses[$sGroupId] = $aClasses;
  1281. }
  1282. // Profiles and grants
  1283. //
  1284. $aProfiles = array();
  1285. // Hardcode the administrator profile
  1286. $aProfiles[1] = array(
  1287. 'name' => 'Administrator',
  1288. 'description' => 'Has the rights on everything (bypassing any control)'
  1289. );
  1290. $aGrants = array();
  1291. $oProfiles = $oUserRightsNode->GetUniqueElement('profiles');
  1292. foreach($oProfiles->getElementsByTagName('profile') as $oProfile)
  1293. {
  1294. $iProfile = $oProfile->getAttribute("id");
  1295. $sName = $oProfile->GetChildText('name');
  1296. $sDescription = $oProfile->GetChildText('description');
  1297. $oGroups = $oProfile->GetUniqueElement('groups');
  1298. foreach($oGroups->getElementsByTagName('group') as $oGroup)
  1299. {
  1300. $sGroupId = $oGroup->getAttribute("id");
  1301. $aActions = array();
  1302. $oActions = $oGroup->GetUniqueElement('actions');
  1303. foreach($oActions->getElementsByTagName('action') as $oAction)
  1304. {
  1305. $sAction = $oAction->getAttribute("id");
  1306. $sType = $oAction->getAttribute("xsi:type");
  1307. $sGrant = $oAction->GetText();
  1308. $bGrant = ($sGrant == 'allow');
  1309. if ($sGroupId == '*')
  1310. {
  1311. $aGrantClasses = array('*');
  1312. }
  1313. else
  1314. {
  1315. $aGrantClasses = $aGroupClasses[$sGroupId];
  1316. }
  1317. foreach ($aGrantClasses as $sClass)
  1318. {
  1319. if ($sType == 'stimulus')
  1320. {
  1321. $this->CumulateGrant($aGrants, $iProfile.'_'.$sClass.'_s_'.$sAction, $bGrant);
  1322. $this->CumulateGrant($aGrants, $iProfile.'_'.$sClass.'+_s_'.$sAction, $bGrant); // subclasses inherit this grant
  1323. }
  1324. else
  1325. {
  1326. $sAction = $aActionsInShort[$sType];
  1327. $this->CumulateGrant($aGrants, $iProfile.'_'.$sClass.'_'.$sAction, $bGrant);
  1328. $this->CumulateGrant($aGrants, $iProfile.'_'.$sClass.'+_'.$sAction, $bGrant); // subclasses inherit this grant
  1329. }
  1330. }
  1331. }
  1332. }
  1333. $aProfiles[$iProfile] = array(
  1334. 'name' => $sName,
  1335. 'description' => $sDescription
  1336. );
  1337. }
  1338. $sProfiles = var_export($aProfiles, true);
  1339. $sGrants = var_export($aGrants, true);
  1340. $sLinkToClasses = var_export($aLinkToClasses, true);
  1341. $sPHP =
  1342. <<<EOF
  1343. //
  1344. // List of constant profiles
  1345. // - used by the class URP_Profiles at setup (create/update/delete records)
  1346. // - used by the addon UserRightsProfile to determine user rights
  1347. //
  1348. class ProfilesConfig
  1349. {
  1350. protected static \$aPROFILES = $sProfiles;
  1351. protected static \$aGRANTS = $sGrants;
  1352. protected static \$aLINKTOCLASSES = $sLinkToClasses;
  1353. // Now replaced by MetaModel::GetLinkClasses (working with 1.x)
  1354. // This function could be deprecated
  1355. public static function GetLinkClasses()
  1356. {
  1357. return self::\$aLINKTOCLASSES;
  1358. }
  1359. public static function GetProfileActionGrant(\$iProfileId, \$sClass, \$sAction)
  1360. {
  1361. // Search for a grant, starting from the most explicit declaration,
  1362. // then searching for less and less explicit declaration
  1363. // 1 - The class itself
  1364. //
  1365. \$sGrantKey = \$iProfileId.'_'.\$sClass.'_'.\$sAction;
  1366. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1367. {
  1368. return self::\$aGRANTS[\$sGrantKey];
  1369. }
  1370. // 2 - The parent classes, up to the root class
  1371. //
  1372. foreach (MetaModel::EnumParentClasses(\$sClass, ENUM_PARENT_CLASSES_EXCLUDELEAF, false /*bRootFirst*/) as \$sParent)
  1373. {
  1374. \$sGrantKey = \$iProfileId.'_'.\$sParent.'+_'.\$sAction;
  1375. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1376. {
  1377. return self::\$aGRANTS[\$sGrantKey];
  1378. }
  1379. }
  1380. // 3 - The related classes (if the current is an N-N link with AUTO_DEL)
  1381. //
  1382. if (array_key_exists(\$sClass, self::\$aLINKTOCLASSES))
  1383. {
  1384. // Get the grant for the remote classes. The resulting grant is:
  1385. // - One YES => YES
  1386. // - 100% undefined => undefined
  1387. // - otherwise => NO
  1388. //
  1389. // Having write allowed on the remote class implies write + delete on the N-N link class
  1390. if (\$sAction == 'd')
  1391. {
  1392. \$sRemoteAction = 'w';
  1393. }
  1394. elseif (\$sAction == 'bd')
  1395. {
  1396. \$sRemoteAction = 'bw';
  1397. }
  1398. else
  1399. {
  1400. \$sRemoteAction = \$sAction;
  1401. }
  1402. foreach (self::\$aLINKTOCLASSES[\$sClass] as \$sRemoteClass)
  1403. {
  1404. \$bUndefined = true;
  1405. \$bGrant = self::GetProfileActionGrant(\$iProfileId, \$sRemoteClass, \$sAction);
  1406. if (\$bGrant === true)
  1407. {
  1408. return true;
  1409. }
  1410. if (\$bGrant === false)
  1411. {
  1412. \$bUndefined = false;
  1413. }
  1414. }
  1415. if (!\$bUndefined)
  1416. {
  1417. return false;
  1418. }
  1419. }
  1420. // 4 - All
  1421. //
  1422. \$sGrantKey = \$iProfileId.'_*_'.\$sAction;
  1423. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1424. {
  1425. return self::\$aGRANTS[\$sGrantKey];
  1426. }
  1427. // Still undefined for this class
  1428. return null;
  1429. }
  1430. public static function GetProfileStimulusGrant(\$iProfileId, \$sClass, \$sStimulus)
  1431. {
  1432. \$sGrantKey = \$iProfileId.'_'.\$sClass.'_s_'.\$sStimulus;
  1433. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1434. {
  1435. return self::\$aGRANTS[\$sGrantKey];
  1436. }
  1437. \$sGrantKey = \$iProfileId.'_*_s_'.\$sStimulus;
  1438. if (isset(self::\$aGRANTS[\$sGrantKey]))
  1439. {
  1440. return self::\$aGRANTS[\$sGrantKey];
  1441. }
  1442. return null;
  1443. }
  1444. // returns an array of id => array of column => php value(so-called "real value")
  1445. public static function GetProfilesValues()
  1446. {
  1447. return self::\$aPROFILES;
  1448. }
  1449. }
  1450. EOF;
  1451. return $sPHP;
  1452. } // function CompileUserRights
  1453. protected function CompileDictionary($oDictionaryNode, $sTempTargetDir, $sFinalTargetDir)
  1454. {
  1455. $sLang = $oDictionaryNode->getAttribute('id');
  1456. $sEnglishLanguageDesc = $oDictionaryNode->GetChildText('english_description');
  1457. $sLocalizedLanguageDesc = $oDictionaryNode->GetChildText('localized_description');
  1458. $aEntriesPHP = array();
  1459. $oEntries = $oDictionaryNode->GetUniqueElement('entries');
  1460. foreach($oEntries->getElementsByTagName('entry') as $oEntry)
  1461. {
  1462. $sStringCode = $oEntry->getAttribute('id');
  1463. $sValue = $oEntry->GetText();
  1464. $aEntriesPHP[] = "\t'$sStringCode' => ".self::QuoteForPHP($sValue, true).",";
  1465. }
  1466. $sEntriesPHP = implode("\n", $aEntriesPHP);
  1467. $sEscEnglishLanguageDesc = self::QuoteForPHP($sEnglishLanguageDesc);
  1468. $sEscLocalizedLanguageDesc = self::QuoteForPHP($sLocalizedLanguageDesc);
  1469. $sPHPDict =
  1470. <<<EOF
  1471. <?php
  1472. //
  1473. // Dictionary built by the compiler for the language "$sLang"
  1474. //
  1475. Dict::Add('$sLang', $sEscEnglishLanguageDesc, $sEscLocalizedLanguageDesc, array(
  1476. $sEntriesPHP
  1477. ));
  1478. EOF;
  1479. $sSafeLang = str_replace(' ', '-', strtolower(trim($sLang)));
  1480. $sDictFile = $sTempTargetDir.'/dictionaries/'.$sSafeLang.'.dict.php';
  1481. file_put_contents($sDictFile, $sPHPDict);
  1482. }
  1483. // Transform the file references into the corresponding filename (and create the file in the relevant directory)
  1484. //
  1485. protected function CompileFiles($oNode, $sTempTargetDir, $sFinalTargetDir, $sRelativePath)
  1486. {
  1487. $oFileRefs = $oNode->GetNodes(".//fileref");
  1488. foreach ($oFileRefs as $oFileRef)
  1489. {
  1490. $sFileId = $oFileRef->getAttribute('ref');
  1491. if ($sFileId !== '')
  1492. {
  1493. $oNodes = $this->oFactory->GetNodes("/itop_design/files/file[@id='$sFileId']");
  1494. if ($oNodes->length == 0)
  1495. {
  1496. throw new DOMFormatException('Could not find the file with ref '.$sFileId);
  1497. }
  1498. $sName = $oNodes->item(0)->GetChildText('name');
  1499. $sData = base64_decode($oNodes->item(0)->GetChildText('data'));
  1500. $aPathInfo = pathinfo($sName);
  1501. $sFile = $sFileId.'.'.$aPathInfo['extension'];
  1502. $sFilePath = $sTempTargetDir.'/images/'.$sFile;
  1503. @mkdir($sTempTargetDir.'/images');
  1504. file_put_contents($sFilePath, $sData);
  1505. if (!file_exists($sFilePath))
  1506. {
  1507. throw new Exception('Could not write icon file '.$sFilePath);
  1508. }
  1509. $oParentNode = $oFileRef->parentNode;
  1510. $oParentNode->removeChild($oFileRef);
  1511. $oTextNode = $oParentNode->ownerDocument->createTextNode($sRelativePath.'/images/'.$sFile);
  1512. $oParentNode->appendChild($oTextNode);
  1513. }
  1514. }
  1515. }
  1516. protected function CompileLogo($oBrandingNode, $sTempTargetDir, $sFinalTargetDir, $sNodeName, $sTargetFile)
  1517. {
  1518. if (($sIcon = $oBrandingNode->GetChildText($sNodeName)) && (strlen($sIcon) > 0))
  1519. {
  1520. if (substr($sIcon, 0, 8) == 'branding')
  1521. {
  1522. $sSourceFile = $sTempTargetDir.'/'.$sIcon;
  1523. }
  1524. else
  1525. {
  1526. $sSourceFile = APPROOT.$sIcon;
  1527. }
  1528. $sTargetFile = $sTempTargetDir.'/branding/'.$sTargetFile.'.png';
  1529. if (!file_exists($sSourceFile))
  1530. {
  1531. throw new Exception("Branding $sNodeName: could not find the file $sIcon ($sSourceFile)");
  1532. }
  1533. // Note: rename makes sense only when the file given as a file ref, otherwise it may be an item of the application (thus it must be kept there)
  1534. copy($sSourceFile, $sTargetFile);
  1535. }
  1536. }
  1537. protected function CompileBranding($oBrandingNode, $sTempTargetDir, $sFinalTargetDir)
  1538. {
  1539. if ($oBrandingNode)
  1540. {
  1541. // Transform file refs into files in the images folder
  1542. SetupUtils::builddir($sTempTargetDir.'/branding');
  1543. $this->CompileFiles($oBrandingNode, $sTempTargetDir.'/branding', $sFinalTargetDir.'/branding', 'branding');
  1544. $this->CompileLogo($oBrandingNode, $sTempTargetDir, $sFinalTargetDir, 'main_logo', 'main-logo');
  1545. $this->CompileLogo($oBrandingNode, $sTempTargetDir, $sFinalTargetDir, 'login_logo', 'login-logo');
  1546. $this->CompileLogo($oBrandingNode, $sTempTargetDir, $sFinalTargetDir, 'portal_logo', 'portal-logo');
  1547. // Cleanup the images directory (made by CompileFiles)
  1548. SetupUtils::rrmdir($sTempTargetDir.'/branding/images');
  1549. }
  1550. }
  1551. }
  1552. ?>