PageRenderTime 118ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/web/system/BlocksModule/MenutreeUtil.php

https://github.com/antoniom/core
PHP | 157 lines | 105 code | 27 blank | 25 comment | 7 complexity | a36bbb7d898ac4c874fb09a38848801f MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, MIT
  1. <?php
  2. /**
  3. * Copyright Zikula Foundation 2009 - Zikula Application Framework
  4. *
  5. * This work is contributed to the Zikula Foundation under one or more
  6. * Contributor Agreements and licensed to You under the following license:
  7. *
  8. * @license GNU/LGPLv3 (or at your option, any later version).
  9. * @package Zikula
  10. *
  11. * Please see the NOTICE file distributed with this source code for further
  12. * information regarding copyright and licensing.
  13. */
  14. namespace BlocksModule;
  15. use PageUtil, DataUtil, ModUtil, FileUtil, ThemeUtil;
  16. class MenutreeUtil
  17. {
  18. public static function getIdOffset($id = null)
  19. {
  20. $item = !is_null($id) && !empty($id) ? $id : 1;
  21. return $item*10000;
  22. }
  23. public static function getTemplates()
  24. {
  25. $templates = array();
  26. $tpls = array();
  27. // restricted templates, array for possible future changes
  28. $sysTpls = array('Block/menutree/modify.tpl',
  29. 'Block/menutree/include_help.tpl');
  30. // module templates
  31. $modulesTpls = FileUtil::getFiles('system/BlocksModule/Resources/view/Block/menutree', false, true, 'tpl', false);
  32. $configTpls = FileUtil::getFiles('config/templates/BlocksModule/Block/menutree', false, true, 'tpl', false);
  33. $tpls['modules'] = array_merge($modulesTpls, $configTpls);
  34. // themes templates - get user and admin themes
  35. $userThemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_USER);
  36. $adminThemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_ADMIN);
  37. $themesTpls = array();
  38. foreach ($userThemes as $ut) {
  39. $themesTpls[$ut['name']] = FileUtil::getFiles('themes/'.$ut['name'].'/Resources/view/modules/BlocksModule/menutree', false, true, 'tpl', false);
  40. }
  41. foreach ($adminThemes as $at) {
  42. if (!array_key_exists($at['name'], $themesTpls)) {
  43. $themesTpls[$at['name']] = FileUtil::getFiles('themes/'.$at['name'].'/Resources/view/modules/BlocksModule/menutree', false, true, 'tpl', false);
  44. }
  45. }
  46. // get tpls which exist in every theme
  47. $tpls['themes']['all'] = call_user_func_array('array_intersect', $themesTpls);
  48. // get tpls which exist in some themes
  49. $tpls['themes']['some'] = array_unique(call_user_func_array('array_merge', $themesTpls));
  50. $tpls['themes']['some'] = array_diff($tpls['themes']['some'], $tpls['themes']['all'], $tpls['modules'], $sysTpls);
  51. $templates = array_unique(array_merge($tpls['modules'], $tpls['themes']['all']));
  52. $templates = array_diff($templates, $sysTpls);
  53. sort($templates);
  54. // prepare array values
  55. $templatesValues = array();
  56. foreach ($templates as $t) {
  57. $templatesValues[] = 'menutree/'.$t;
  58. }
  59. // fill array keys using values
  60. $templates = array_combine($templatesValues, $templates);
  61. $someThemes = __('Only in some themes');
  62. if (!empty($tpls['themes']['some'])) {
  63. sort($tpls['themes']['some']);
  64. foreach ($tpls['themes']['some'] as $k => $t) {
  65. $tpls['themes']['some'][$k] = 'menutree/'.$t;
  66. }
  67. $templates[$someThemes] = array_combine($tpls['themes']['some'], $tpls['themes']['some']);
  68. }
  69. return self::normalize($templates);
  70. }
  71. public static function getStylesheets()
  72. {
  73. $stylesheets = array();
  74. $styles = array();
  75. // restricted stylesheets, array for possible future changes
  76. $sysStyles = array('system/BlocksModule/Resources/public/css/menutree/adminstyle.css',
  77. 'system/BlocksModule/Resources/public/css/menutree/contextmenu.css',
  78. 'system/BlocksModule/Resources/public/css/menutree/tree.css');
  79. // module stylesheets
  80. $modulesStyles = FileUtil::getFiles('system/Blocks/Resources/public/css/menutree', false, false, 'css', false);
  81. $configStyles = FileUtil::getFiles('config/style/Blocks/menutree', false, false, 'css', false);
  82. $styles['modules'] = array_merge($modulesStyles, $configStyles);
  83. // themes stylesheets - get user and admin themes
  84. $userThemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_USER);
  85. $adminThemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_ADMIN);
  86. $themesStyles = array();
  87. foreach ($userThemes as $ut) {
  88. $themesStyles[$ut['name']] = FileUtil::getFiles('themes/'.$ut['name'].'/Resources/public/css/Blocks/menutree', false, false, 'css', false);
  89. }
  90. foreach ($adminThemes as $at) {
  91. if (!array_key_exists($at['name'], $themesStyles)) {
  92. $themesStyles[$at['name']] = FileUtil::getFiles('themes/'.$at['name'].'/Resources/public/css/Blocks/menutree', false, false, 'css', false);
  93. }
  94. }
  95. // get stylesheets which exist in every theme
  96. $styles['themes']['all'] = call_user_func_array('array_intersect', $themesStyles);
  97. // get stylesheets which exist in some themes
  98. $styles['themes']['some'] = array_unique(call_user_func_array('array_merge', $themesStyles));
  99. $styles['themes']['some'] = array_diff($styles['themes']['some'], $styles['themes']['all'], $styles['modules'], $sysStyles);
  100. $stylesheets = array_unique(array_merge($styles['modules'],$styles['themes']['all']));
  101. $stylesheets = array_diff($stylesheets,$sysStyles);
  102. sort($stylesheets);
  103. // fill array keys using values
  104. $stylesheets = array_combine($stylesheets, $stylesheets);
  105. $someThemes = __('Only in some themes');
  106. if (!empty($styles['themes']['some'])) {
  107. sort($styles['themes']['some']);
  108. $stylesheets[$someThemes] = array_combine($styles['themes']['some'],$styles['themes']['some']);
  109. }
  110. return self::normalize($stylesheets);
  111. }
  112. protected static function normalize($array)
  113. {
  114. $normalizedArray = array();
  115. foreach ($array as $k => $v) {
  116. if (is_array($v)) {
  117. foreach ($v as $k2 => $v2) {
  118. $k2 = str_replace('\\', '/', $k2);
  119. $v2 = str_replace('\\', '/', $v2);
  120. $normalizedArray[$k][$k2] = $v2;
  121. }
  122. } else {
  123. $k = str_replace('\\', '/', $k);
  124. $v = str_replace('\\', '/', $v);
  125. $normalizedArray[$k] = $v;
  126. }
  127. }
  128. return $normalizedArray;
  129. }
  130. }