You are here

function _tinymce_get_buttons in TinyMCE 5

Same name and namespace in other branches
  1. 5.2 tinymce.module \_tinymce_get_buttons()
  2. 6.2 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.module
Return an HTML form for profile configuration.

File

./tinymce.module, line 385
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')) {
          $metadata[$name]['buttons'] = array_merge((array) $metadata[$name]['buttons'], $plugin[$k]);
        }
      }
    }
    return $metadata;
  }
  return $plugins;
}