/web/system/BlocksModule/MenutreeUtil.php
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
- <?php
- /**
- * Copyright Zikula Foundation 2009 - Zikula Application Framework
- *
- * This work is contributed to the Zikula Foundation under one or more
- * Contributor Agreements and licensed to You under the following license:
- *
- * @license GNU/LGPLv3 (or at your option, any later version).
- * @package Zikula
- *
- * Please see the NOTICE file distributed with this source code for further
- * information regarding copyright and licensing.
- */
- namespace BlocksModule;
- use PageUtil, DataUtil, ModUtil, FileUtil, ThemeUtil;
- class MenutreeUtil
- {
- public static function getIdOffset($id = null)
- {
- $item = !is_null($id) && !empty($id) ? $id : 1;
- return $item*10000;
- }
- public static function getTemplates()
- {
- $templates = array();
- $tpls = array();
- // restricted templates, array for possible future changes
- $sysTpls = array('Block/menutree/modify.tpl',
- 'Block/menutree/include_help.tpl');
- // module templates
- $modulesTpls = FileUtil::getFiles('system/BlocksModule/Resources/view/Block/menutree', false, true, 'tpl', false);
- $configTpls = FileUtil::getFiles('config/templates/BlocksModule/Block/menutree', false, true, 'tpl', false);
- $tpls['modules'] = array_merge($modulesTpls, $configTpls);
- // themes templates - get user and admin themes
- $userThemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_USER);
- $adminThemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_ADMIN);
- $themesTpls = array();
- foreach ($userThemes as $ut) {
- $themesTpls[$ut['name']] = FileUtil::getFiles('themes/'.$ut['name'].'/Resources/view/modules/BlocksModule/menutree', false, true, 'tpl', false);
- }
- foreach ($adminThemes as $at) {
- if (!array_key_exists($at['name'], $themesTpls)) {
- $themesTpls[$at['name']] = FileUtil::getFiles('themes/'.$at['name'].'/Resources/view/modules/BlocksModule/menutree', false, true, 'tpl', false);
- }
- }
- // get tpls which exist in every theme
- $tpls['themes']['all'] = call_user_func_array('array_intersect', $themesTpls);
- // get tpls which exist in some themes
- $tpls['themes']['some'] = array_unique(call_user_func_array('array_merge', $themesTpls));
- $tpls['themes']['some'] = array_diff($tpls['themes']['some'], $tpls['themes']['all'], $tpls['modules'], $sysTpls);
- $templates = array_unique(array_merge($tpls['modules'], $tpls['themes']['all']));
- $templates = array_diff($templates, $sysTpls);
- sort($templates);
- // prepare array values
- $templatesValues = array();
- foreach ($templates as $t) {
- $templatesValues[] = 'menutree/'.$t;
- }
- // fill array keys using values
- $templates = array_combine($templatesValues, $templates);
- $someThemes = __('Only in some themes');
- if (!empty($tpls['themes']['some'])) {
- sort($tpls['themes']['some']);
- foreach ($tpls['themes']['some'] as $k => $t) {
- $tpls['themes']['some'][$k] = 'menutree/'.$t;
- }
- $templates[$someThemes] = array_combine($tpls['themes']['some'], $tpls['themes']['some']);
- }
- return self::normalize($templates);
- }
- public static function getStylesheets()
- {
- $stylesheets = array();
- $styles = array();
- // restricted stylesheets, array for possible future changes
- $sysStyles = array('system/BlocksModule/Resources/public/css/menutree/adminstyle.css',
- 'system/BlocksModule/Resources/public/css/menutree/contextmenu.css',
- 'system/BlocksModule/Resources/public/css/menutree/tree.css');
- // module stylesheets
- $modulesStyles = FileUtil::getFiles('system/Blocks/Resources/public/css/menutree', false, false, 'css', false);
- $configStyles = FileUtil::getFiles('config/style/Blocks/menutree', false, false, 'css', false);
- $styles['modules'] = array_merge($modulesStyles, $configStyles);
- // themes stylesheets - get user and admin themes
- $userThemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_USER);
- $adminThemes = ThemeUtil::getAllThemes(ThemeUtil::FILTER_ADMIN);
- $themesStyles = array();
- foreach ($userThemes as $ut) {
- $themesStyles[$ut['name']] = FileUtil::getFiles('themes/'.$ut['name'].'/Resources/public/css/Blocks/menutree', false, false, 'css', false);
- }
- foreach ($adminThemes as $at) {
- if (!array_key_exists($at['name'], $themesStyles)) {
- $themesStyles[$at['name']] = FileUtil::getFiles('themes/'.$at['name'].'/Resources/public/css/Blocks/menutree', false, false, 'css', false);
- }
- }
- // get stylesheets which exist in every theme
- $styles['themes']['all'] = call_user_func_array('array_intersect', $themesStyles);
- // get stylesheets which exist in some themes
- $styles['themes']['some'] = array_unique(call_user_func_array('array_merge', $themesStyles));
- $styles['themes']['some'] = array_diff($styles['themes']['some'], $styles['themes']['all'], $styles['modules'], $sysStyles);
- $stylesheets = array_unique(array_merge($styles['modules'],$styles['themes']['all']));
- $stylesheets = array_diff($stylesheets,$sysStyles);
- sort($stylesheets);
- // fill array keys using values
- $stylesheets = array_combine($stylesheets, $stylesheets);
- $someThemes = __('Only in some themes');
- if (!empty($styles['themes']['some'])) {
- sort($styles['themes']['some']);
- $stylesheets[$someThemes] = array_combine($styles['themes']['some'],$styles['themes']['some']);
- }
- return self::normalize($stylesheets);
- }
- protected static function normalize($array)
- {
- $normalizedArray = array();
- foreach ($array as $k => $v) {
- if (is_array($v)) {
- foreach ($v as $k2 => $v2) {
- $k2 = str_replace('\\', '/', $k2);
- $v2 = str_replace('\\', '/', $v2);
- $normalizedArray[$k][$k2] = $v2;
- }
- } else {
- $k = str_replace('\\', '/', $k);
- $v = str_replace('\\', '/', $v);
- $normalizedArray[$k] = $v;
- }
- }
- return $normalizedArray;
- }
- }