PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/templates/yoo_inspire/layouts/module.php

https://bitbucket.org/kraymitchell/apex
PHP | 174 lines | 121 code | 26 blank | 27 comment | 49 complexity | fa8dd49bd3c9f7c1e76ae0cf6e0bd67f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * @package yoo_inspire
  4. * @author YOOtheme http://www.yootheme.com
  5. * @copyright Copyright (C) YOOtheme GmbH
  6. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL
  7. */
  8. // init vars
  9. $id = $module->id;
  10. $position = $module->position;
  11. $title = $module->title;
  12. $showtitle = $module->showtitle;
  13. $content = $module->content;
  14. $split_color = '';
  15. $subtitle = '';
  16. $title_template = '';
  17. // init params
  18. foreach (array('suffix', 'style', 'color', 'badge', 'icon', 'dropdownwidth') as $var) {
  19. $$var = isset($params[$var]) ? $params[$var] : null;
  20. }
  21. // set default module types
  22. if ($style == '') {
  23. if ($module->position == 'top-a') $style = 'blank';
  24. if ($module->position == 'top-b') $style = 'line';
  25. if ($module->position == 'bottom-a') $style = 'line';
  26. if ($module->position == 'bottom-b') $style = 'line';
  27. if ($module->position == 'bottom-c') $style = 'line';
  28. if ($module->position == 'innertop') $style = 'line';
  29. if ($module->position == 'innerbottom') $style = 'line';
  30. if ($module->position == 'sidebar-a') $style = 'line';
  31. if ($module->position == 'sidebar-b') $style = 'line';
  32. }
  33. // test module styles here
  34. //$style = '';
  35. //$color = '';
  36. //$badge = '';
  37. //$icon = '';
  38. //$content = '';
  39. // force module style
  40. if (in_array($module->position, array('absolute', 'breadcrumbs', 'logo', 'banner', 'search', 'debug'))) {
  41. $style = 'raw';
  42. $showtitle = 0;
  43. }
  44. if (in_array($module->position, array('headerbar', 'toolbar-r' ,'toolbar-l', 'footer'))) {
  45. $style = '';
  46. $showtitle = 0;
  47. }
  48. if ($module->position == 'menu') {
  49. $style = $module->menu ? 'raw' : 'dropdown';
  50. }
  51. // set module template using the style
  52. switch ($style) {
  53. case 'box':
  54. $template = 'default-1';
  55. $style = 'mod-'.$style;
  56. $style .= ($color) ? ' mod-box-'.$color : '';
  57. $subtitle = 1;
  58. $title_template = '<h3 class="module-title">%s</h3>';
  59. break;
  60. case 'fabric':
  61. $template = 'default-2';
  62. $style = 'mod-'.$style;
  63. $subtitle = 1;
  64. $title_template = '<h3 class="module-title">%s</h3>';
  65. break;
  66. case 'stripes':
  67. $template = 'default-2';
  68. $style = 'mod-'.$style;
  69. $subtitle = 1;
  70. $title_template = '<h3 class="module-title">%s</h3>';
  71. break;
  72. case 'line':
  73. $template = 'default-1';
  74. $style = 'mod-'.$style;
  75. $style .= ($color) ? ' mod-line-'.$color : '';
  76. $subtitle = 1;
  77. $title_template = '<h3 class="module-title">%s</h3>';
  78. break;
  79. case 'dropdown':
  80. $template = 'dropdown';
  81. $subtitle = 1;
  82. break;
  83. case 'raw':
  84. $template = 'raw';
  85. break;
  86. default:
  87. $template = 'default-1';
  88. $style = $suffix;
  89. $suffix = '';
  90. $title_template = '<h3 class="module-title">%s</h3>';
  91. }
  92. $style.=" ".$suffix;
  93. // set badge if exists
  94. if ($badge) {
  95. $badge = '<div class="badge badge-'.$badge.'"></div>';
  96. }
  97. // split title in two colors
  98. if ($split_color) {
  99. $pos = mb_strpos($title, ' ');
  100. if ($pos !== false) {
  101. $title = '<span class="color">'.mb_substr($title, 0, $pos).'</span>'.mb_substr($title, $pos);
  102. }
  103. }
  104. // create subtitle
  105. if ($subtitle) {
  106. $pos = mb_strpos($title, '||');
  107. if ($pos !== false) {
  108. $title = '<span class="title">'.mb_substr($title, 0, $pos).'</span><span class="subtitle">'.mb_substr($title, $pos + 2).'</span>';
  109. }
  110. }
  111. // create title icon if exists
  112. if ($icon) {
  113. $title = '<span class="icon icon-'.$icon.'"></span>'.$title.'';
  114. }
  115. // create title template
  116. if ($title_template) {
  117. $title = sprintf($title_template, $title);
  118. }
  119. // set dropdownwidth if exists
  120. if ($dropdownwidth) {
  121. $dropdownwidth = 'style="width: '.$dropdownwidth.'px;"';
  122. }
  123. // render menu
  124. if ($module->menu) {
  125. // set menu renderer
  126. if (isset($params['menu'])) {
  127. $renderer = $params['menu'];
  128. } else if (in_array($module->position, array('menu'))) {
  129. $renderer = 'dropdown';
  130. } else if (in_array($module->position, array('toolbar-l', 'toolbar-r', 'footer'))) {
  131. $renderer = 'default';
  132. } else {
  133. $renderer = 'accordion';
  134. }
  135. // set menu style
  136. if ($renderer == 'dropdown') {
  137. $module->menu_style = 'menu-dropdown';
  138. } else if ($renderer == 'accordion') {
  139. $module->menu_style = 'menu-sidebar';
  140. } else if ($renderer == 'default') {
  141. $module->menu_style = 'menu-line';
  142. } else {
  143. $module->menu_style = null;
  144. }
  145. $content = $this['menu']->process($module, array_unique(array('pre', 'default', $renderer, 'post')));
  146. }
  147. // render module
  148. echo $this->render("modules/templates/{$template}", compact('style', 'badge', 'showtitle', 'title', 'content', 'dropdownwidth'));