You are here

function _tinymce_get_buttons in TinyMCE 6.2

Same name and namespace in other branches
  1. 5.2 tinymce.module \_tinymce_get_buttons()
  2. 5 tinymce.module \_tinymce_get_buttons()
  3. 6 tinymce.module \_tinymce_get_buttons()

Return plugin metadata from the plugin registry.

We also scrape each plugin's *.js file for the human friendly name and help text URL of each plugin.

Return value

An array for each plugin.

2 calls to _tinymce_get_buttons()
tinymce_config in ./tinymce.module
Return an array of initial tinymce config options from the current role.
tinymce_profile_form_build in ./tinymce.admin.inc
Return an HTML form for profile configuration.

File

./tinymce.module, line 417
Integrate the TinyMCE editor (http://tinymce.moxiecode.com/) into Drupal.

Code

function _tinymce_get_buttons($skip_metadata = TRUE) {
  include_once drupal_get_path('module', 'tinymce') . '/plugin_reg.php';
  $plugins = _tinymce_plugins();
  if ($skip_metadata == FALSE && is_array($plugins)) {
    foreach ($plugins as $name => $plugin) {
      $file = drupal_get_path('module', 'tinymce') . '/tinymce/jscripts/tiny_mce/plugins/' . $name . '/editor_plugin_src.js';

      // Grab the plugin metadata by scanning the *.js file.
      if (file_exists($file)) {
        $lines = file($file);
        $has_longname = FALSE;
        $has_infourl = FALSE;
        foreach ($lines as $line) {
          if ($has_longname && $has_infourl) {
            break;
          }
          if (strstr($line, 'longname')) {
            $start = strpos($line, "'") + 1;
            $end = strrpos($line, "'") - $start;
            $metadata[$name]['longname'] = substr($line, $start, $end);
            $has_longname = TRUE;
          }
          elseif (strstr($line, 'infourl')) {
            $start = strpos($line, "'") + 1;
            $end = strrpos($line, "'") - $start;
            $metadata[$name]['infourl'] = substr($line, $start, $end);
            $has_infourl = TRUE;
          }
        }
      }

      // Find out the buttons a plugin has.
      foreach ($plugin as $k => $v) {
        if (strstr($k, 'theme_advanced_buttons')) {
          if (!isset($metadata[$name]['buttons'])) {
            $metadata[$name]['buttons'] = $plugin[$k];
          }
          else {
            $metadata[$name]['buttons'] = array_merge((array) $metadata[$name]['button'], $plugin[$k]);
          }
        }
      }

      // add list of default buttons
      // source: http://wiki.moxiecode.com/index.php/TinyMCE:Control_reference
      $name = 'default';
      $buttons = array(
        "bold",
        "italic",
        "underline",
        "strikethrough",
        "justifyleft",
        "justifycenter",
        "justifyright",
        "justifyfull",
        "bullist",
        "numlist",
        "outdent",
        "indent",
        "link",
        "unlink",
        "image",
        "cleanup",
        "help",
        "code",
        "hr",
        "removeformat",
        "sub",
        "sup",
        "charmap",
        "visualaid",
        "anchor",
        "blockquote",
      );
      foreach ($buttons as $button) {
        $metadata['default']['buttons'][] = $button;
      }
    }
    return $metadata;
  }
  return $plugins;
}