theme.inc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to provide access control based on user themeission strings.
  5. */
  6. /**
  7. * Plugins are described by creating a $plugin array which will be used
  8. * by the system that includes this file.
  9. */
  10. $plugin = array(
  11. 'title' => t("Current theme"),
  12. 'description' => t('Control access by checking which theme is in use.'),
  13. 'callback' => 'ctools_theme_ctools_access_check',
  14. 'default' => array('theme' => variable_get('theme_default', 'garland')),
  15. 'settings form' => 'ctools_theme_ctools_access_settings',
  16. 'summary' => 'ctools_theme_ctools_access_summary',
  17. );
  18. /**
  19. * Settings form for the 'by theme' access plugin
  20. */
  21. function ctools_theme_ctools_access_settings($form, &$form_state, $conf) {
  22. $themes = array();
  23. foreach (list_themes() as $key => $theme) {
  24. $themes[$key] = $theme->info['name'];
  25. }
  26. $form['settings']['theme'] = array(
  27. '#type' => 'select',
  28. '#options' => $themes,
  29. '#title' => t('Themes'),
  30. '#default_value' => $conf['theme'],
  31. '#description' => t('This will only be accessed if the current theme is the selected theme.'),
  32. );
  33. return $form;
  34. }
  35. /**
  36. * Check for access.
  37. */
  38. function ctools_theme_ctools_access_check($conf, $context) {
  39. if (!empty($GLOBALS['theme'])) {
  40. $theme = $GLOBALS['theme'];
  41. }
  42. else if (!empty($GLOBALS['custom_theme'])) {
  43. $theme = $GLOBALS['custom_theme'];
  44. }
  45. else if (!empty($GLOBALS['user']->theme)) {
  46. $theme = $GLOBALS['user']->theme;
  47. }
  48. else {
  49. $theme = variable_get('theme_default', 'garland');
  50. }
  51. return $conf['theme'] == $theme;
  52. }
  53. /**
  54. * Provide a summary description based upon the checked roles.
  55. */
  56. function ctools_theme_ctools_access_summary($conf, $context) {
  57. if (!isset($conf['theme'])) {
  58. return t('Error, unset theme');
  59. }
  60. $themes = list_themes();
  61. return t('Current theme is "@theme"', array('@theme' => $themes[$conf['theme']]->info['name']));
  62. }