PageRenderTime 184ms CodeModel.GetById 26ms RepoModel.GetById 3ms app.codeStats 1ms

/templates/yoo_master/layouts/module.php

https://bitbucket.org/kraymitchell/apex
PHP | 153 lines | 102 code | 23 blank | 28 comment | 47 complexity | f9b5826c9e31f85cee9b642583dacd36 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_master
  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 = 'box';
  24. if ($module->position == 'top-b') $style = 'box';
  25. if ($module->position == 'bottom-a') $style = 'box';
  26. if ($module->position == 'bottom-b') $style = 'box';
  27. if ($module->position == 'innertop') $style = 'box';
  28. if ($module->position == 'innerbottom') $style = 'box';
  29. if ($module->position == 'sidebar-a') $style = 'box';
  30. if ($module->position == 'sidebar-b') $style = 'box';
  31. }
  32. // test module styles here
  33. //$style = '';
  34. //$color = '';
  35. //$badge = '';
  36. //$icon = '';
  37. //$title = '';
  38. //$content = '<ul class="line"><li>This is a demo text.</li><li><a href="#">Link</a></li></ul><ul class="zebra"><li>This is a demo text.</li><li><a href="#">Link</a></li></ul><a class="button-default" href="#">Read More</a><ul class="check"><li>Check List</li></ul><em>em Element</em><br /><em class="box">em with class box</em><br /><code>code Element</code><form class="short style"><div><input type="text"></div><div><textarea >Textarea text</textarea></div><div><button type="submit" name="Submit">Log in</button></div></form>';
  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. $split_color = 1;
  58. $subtitle = 1;
  59. $title_template = '<h3 class="module-title">%s</h3>';
  60. break;
  61. case 'dropdown':
  62. $template = 'dropdown';
  63. $subtitle = 1;
  64. break;
  65. case 'raw':
  66. $template = 'raw';
  67. break;
  68. default:
  69. $template = 'default-1';
  70. $style = $suffix;
  71. $suffix = '';
  72. $title_template = '<h3 class="module-title">%s</h3>';
  73. }
  74. $style.=" ".$suffix;
  75. // set badge if exists
  76. if ($badge) {
  77. $badge = '<div class="badge badge-'.$badge.'"></div>';
  78. }
  79. // split title in two colors
  80. if ($split_color) {
  81. $pos = mb_strpos($title, ' ');
  82. if ($pos !== false) {
  83. $title = '<span class="color">'.mb_substr($title, 0, $pos).'</span>'.mb_substr($title, $pos);
  84. }
  85. }
  86. // create subtitle
  87. if ($subtitle) {
  88. $pos = mb_strpos($title, '||');
  89. if ($pos !== false) {
  90. $title = '<span class="title">'.mb_substr($title, 0, $pos).'</span><span class="subtitle">'.mb_substr($title, $pos + 2).'</span>';
  91. }
  92. }
  93. // create title icon if exists
  94. if ($icon) {
  95. $title = '<span class="icon icon-'.$icon.'"></span>'.$title.'';
  96. }
  97. // create title template
  98. if ($title_template) {
  99. $title = sprintf($title_template, $title);
  100. }
  101. // set dropdownwidth if exists
  102. if ($dropdownwidth) {
  103. $dropdownwidth = 'style="width: '.$dropdownwidth.'px;"';
  104. }
  105. // render menu
  106. if ($module->menu) {
  107. // set menu renderer
  108. if (isset($params['menu'])) {
  109. $renderer = $params['menu'];
  110. } else if (in_array($module->position, array('menu'))) {
  111. $renderer = 'dropdown';
  112. } else if (in_array($module->position, array('toolbar-l', 'toolbar-r', 'footer'))) {
  113. $renderer = 'default';
  114. } else {
  115. $renderer = 'accordion';
  116. }
  117. // set menu style
  118. if ($renderer == 'dropdown') {
  119. $module->menu_style = 'menu-dropdown';
  120. } else if ($renderer == 'accordion') {
  121. $module->menu_style = 'menu-sidebar';
  122. } else if ($renderer == 'default') {
  123. $module->menu_style = 'menu-line';
  124. } else {
  125. $module->menu_style = null;
  126. }
  127. $content = $this['menu']->process($module, array_unique(array('pre', 'default', $renderer, 'post')));
  128. }
  129. // render module
  130. echo $this->render("modules/templates/{$template}", compact('style', 'badge', 'showtitle', 'title', 'content', 'dropdownwidth'));