You are here

function sweaver_show_editor in Sweaver 7

Same name and namespace in other branches
  1. 6 sweaver.module \sweaver_show_editor()

Function to check if we are going to show the editor.

4 calls to sweaver_show_editor()
sweaver_custom_theme in ./sweaver.module
Implements hook_custom_theme().
sweaver_init in ./sweaver.module
Implements hook_init().
sweaver_page_alter in ./sweaver.module
Implements hook_page_alter().
sweaver_plugin_toolbar::sweaver_menu_access_callback in plugins/sweaver_plugin_toolbar/sweaver_plugin_toolbar.inc
Menu access callback.

File

./sweaver.module, line 564
Sweaver functions.

Code

function sweaver_show_editor($cache = TRUE, $plugins = TRUE) {
  static $run = FALSE;
  static $return = FALSE;
  $_return = $return;
  if (!$run || !$cache) {
    if ($cache) {
      $run = TRUE;
    }

    // Let's do the check for the editor early.
    if (variable_get('sweaver_enabled', TRUE)) {

      // Path visibility.
      $path = drupal_get_path_alias($_GET['q']);
      $page_match = drupal_match_path($path, variable_get('sweaver_paths', SWEAVER_PATHS_EXCLUDE));
      if ($path != $_GET['q']) {
        $page_match = $page_match || drupal_match_path($_GET['q'], variable_get('sweaver_paths', SWEAVER_PATHS_EXCLUDE));
      }
      $page_match = !(0 xor $page_match);
      if (user_access('use editor') && $page_match) {
        $_return = TRUE;
        if ($plugins) {
          $sweaver = Sweaver::get_instance();
          foreach (array_keys($sweaver
            ->get_plugins_registry(TRUE)) as $plugin_name) {
            $sweaver_plugin = $sweaver
              ->get_plugin($plugin_name);

            // Allow plugins to set editor to no show
            if ($sweaver_plugin
              ->show_editor() === FALSE) {
              $_return = FALSE;
            }
          }
        }
      }
    }
  }
  if ($cache) {
    $return = $_return;
  }
  return $_return;
}