stylizer.module 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * @file
  4. * Stylizer module
  5. *
  6. * This module allows styles to be created and managed on behalf of modules
  7. * that implement styles.
  8. *
  9. * The Stylizer tool allows recolorable styles to be created via a miniature
  10. * scripting language. Panels utilizes this to allow administrators to add
  11. * styles directly to any panel display.
  12. */
  13. /**
  14. * Implements hook_permission()
  15. */
  16. function stylizer_permission() {
  17. return array(
  18. 'administer stylizer' => array(
  19. 'title' => t("Use the Stylizer UI"),
  20. 'description' => t("Allows a user to use the CTools Stylizer UI."),
  21. ),
  22. );
  23. }
  24. /**
  25. * Implementation of hook_ctools_plugin_directory() to let the system know
  26. * we implement task and task_handler plugins.
  27. */
  28. function stylizer_ctools_plugin_directory($module, $plugin) {
  29. // Most of this module is implemented as an export ui plugin, and the
  30. // rest is in ctools/includes/stylizer.inc
  31. if ($module == 'ctools' && $plugin == 'export_ui') {
  32. return 'plugins/' . $plugin;
  33. }
  34. }
  35. /**
  36. * Implements hook_ctools_plugin_type() to inform the plugin system that
  37. * Stylizer style_base plugin types.
  38. */
  39. function stylizer_ctools_plugin_type() {
  40. return array(
  41. 'style_bases' => array(
  42. 'load themes' => TRUE,
  43. ),
  44. );
  45. }
  46. /**
  47. * Implementation of hook_panels_dashboard_blocks().
  48. *
  49. * Adds page information to the Panels dashboard.
  50. */
  51. function stylizer_panels_dashboard_blocks(&$vars) {
  52. $vars['links']['stylizer'] = array(
  53. 'title' => l(t('Custom style'), 'admin/structure/stylizer/add'),
  54. 'description' => t('Custom styles can be applied to Panel regions and Panel panes.'),
  55. );
  56. // Load all mini panels and their displays.
  57. ctools_include('export');
  58. ctools_include('stylizer');
  59. $items = ctools_export_crud_load_all('stylizer');
  60. $count = 0;
  61. $rows = array();
  62. $base_types = ctools_get_style_base_types();
  63. foreach ($items as $item) {
  64. $style = ctools_get_style_base($item->settings['style_base']);
  65. if ($style && $style['module'] == 'panels') {
  66. $type = $base_types[$style['module']][$style['type']]['title'];
  67. $rows[] = array(
  68. check_plain($item->admin_title),
  69. $type,
  70. array(
  71. 'data' => l(t('Edit'), "admin/structure/stylizer/list/$item->name/edit"),
  72. 'class' => 'links',
  73. ),
  74. );
  75. // Only show 10.
  76. if (++$count >= 10) {
  77. break;
  78. }
  79. }
  80. }
  81. if ($rows) {
  82. $content = theme('table', array('rows' => $rows, 'attributes' => array('class' => 'panels-manage')));
  83. }
  84. else {
  85. $content = '<p>' . t('There are no custom styles.') . '</p>';
  86. }
  87. $vars['blocks']['stylizer'] = array(
  88. 'title' => t('Manage styles'),
  89. 'link' => l(t('Go to list'), 'admin/structure/stylizer'),
  90. 'content' => $content,
  91. 'class' => 'dashboard-styles',
  92. 'section' => 'left',
  93. );
  94. }
  95. /**
  96. * Implementation of hook_theme to load all content plugins and pass thru if
  97. * necessary.
  98. */
  99. function stylizer_theme() {
  100. $theme = array();
  101. ctools_include('stylizer');
  102. // Register all themes given for basetypes.
  103. $plugins = ctools_get_style_bases();
  104. $base_types = ctools_get_style_base_types();
  105. foreach ($plugins as $plugin) {
  106. if (!empty($base_types[$plugin['module']][$plugin['type']]) && !empty($plugin['theme'])) {
  107. $base_type = $base_types[$plugin['module']][$plugin['type']];
  108. $theme[$plugin['theme']] = array(
  109. 'variables' => $base_type['theme variables'],
  110. 'path' => $plugin['path'],
  111. );
  112. // if no theme function exists, assume template.
  113. if (!function_exists("theme_$plugin[theme]")) {
  114. $theme[$plugin['theme']]['template'] = str_replace('_', '-', $plugin['theme']);
  115. $theme[$plugin['theme']]['file'] = $plugin['file']; // for preprocess.
  116. }
  117. }
  118. }
  119. return $theme;
  120. }