1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135 |
- <?php
- function wysiwyg_entity_info() {
- $types['wysiwyg_profile'] = array(
- 'label' => t('Wysiwyg profile'),
- 'base table' => 'wysiwyg',
- 'controller class' => 'WysiwygProfileController',
- 'fieldable' => FALSE,
-
-
-
- 'static cache' => FALSE,
- 'entity keys' => array(
- 'id' => 'format',
- ),
- );
- return $types;
- }
- class WysiwygProfileController extends DrupalDefaultEntityController {
-
- function attachLoad(&$queried_entities, $revision_id = FALSE) {
-
- foreach ($queried_entities as $key => $record) {
- $queried_entities[$key]->settings = unserialize($record->settings);
- }
-
- parent::attachLoad($queried_entities, $revision_id);
- }
- }
- function wysiwyg_menu() {
- $items['admin/config/content/wysiwyg'] = array(
- 'title' => 'Wysiwyg profiles',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('wysiwyg_profile_overview'),
- 'description' => 'Configure client-side editors.',
- 'access arguments' => array('administer filters'),
- 'file' => 'wysiwyg.admin.inc',
- );
- $items['admin/config/content/wysiwyg/profile'] = array(
- 'title' => 'List',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- );
- $items['admin/config/content/wysiwyg/profile/%wysiwyg_profile/edit'] = array(
- 'title' => 'Edit',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('wysiwyg_profile_form', 5),
- 'access arguments' => array('administer filters'),
- 'file' => 'wysiwyg.admin.inc',
- 'tab_root' => 'admin/config/content/wysiwyg/profile',
- 'tab_parent' => 'admin/config/content/wysiwyg/profile/%wysiwyg_profile',
- 'type' => MENU_LOCAL_TASK,
- );
- $items['admin/config/content/wysiwyg/profile/%wysiwyg_profile/delete'] = array(
- 'title' => 'Remove',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('wysiwyg_profile_delete_confirm', 5),
- 'access arguments' => array('administer filters'),
- 'file' => 'wysiwyg.admin.inc',
- 'tab_root' => 'admin/config/content/wysiwyg/profile',
- 'tab_parent' => 'admin/config/content/wysiwyg/profile/%wysiwyg_profile',
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 10,
- );
-
- $items['wysiwyg/%'] = array(
- 'page callback' => 'wysiwyg_dialog',
- 'page arguments' => array(1),
- 'delivery callback' => 'wysiwyg_deliver_dialog_page',
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- 'file' => 'wysiwyg.dialog.inc',
- );
- return $items;
- }
- function wysiwyg_element_info() {
-
- $types['wysiwyg_dialog_page'] = array(
- '#theme' => 'wysiwyg_dialog_page',
- '#theme_wrappers' => array('html'),
- '#show_messages' => TRUE,
- );
- return $types;
- }
- function wysiwyg_theme() {
- return array(
- 'wysiwyg_profile_overview' => array(
- 'render element' => 'form',
- ),
- 'wysiwyg_admin_button_table' => array(
- 'render element' => 'form',
- ),
-
- 'wysiwyg_dialog_page' => array(
- 'render element' => 'page',
- 'file' => 'wysiwyg.dialog.inc',
- 'template' => 'wysiwyg-dialog-page',
- ),
- );
- }
- function wysiwyg_help($path, $arg) {
- switch ($path) {
- case 'admin/config/content/wysiwyg':
- $output = '<p>' . t('A Wysiwyg profile is associated with a text format. A Wysiwyg profile defines which client-side editor is loaded with a particular text format, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor-specific functions.') . '</p>';
- return $output;
- }
- }
- function wysiwyg_form_alter(&$form, &$form_state) {
-
- if (isset($form['body_field'])) {
- unset($form['body_field']['teaser_js']);
- }
- }
- function wysiwyg_element_info_alter(&$types) {
- $types['text_format']['#pre_render'][] = 'wysiwyg_pre_render_text_format';
- }
- function wysiwyg_pre_render_text_format($element) {
-
-
-
- if (!isset($element['format']) || !empty($element['value']['#disabled'])) {
- return $element;
- }
-
-
- if (isset($element['#wysiwyg']) && !$element['#wysiwyg']) {
- return $element;
- }
- $format_field = &$element['format'];
- $field = &$element['value'];
- $settings = array(
- 'field' => $field['#id'],
- );
-
-
-
-
-
-
- $resizable = 0;
- if (!empty($field['#resizable'])) {
- $resizable = 1;
- drupal_add_js('misc/textarea.js');
- }
-
- foreach ($format_field['format']['#options'] as $format_id => $format_name) {
- $format = 'format' . $format_id;
-
- $settings[$format] = array(
- 'editor' => 'none',
- 'status' => 1,
- 'toggle' => 1,
- 'resizable' => $resizable,
- );
-
- $profile = wysiwyg_get_profile($format_id);
- if ($profile) {
- $loaded = TRUE;
- $settings[$format]['editor'] = $profile->editor;
- $settings[$format]['status'] = (int) wysiwyg_user_get_status($profile);
- if (isset($profile->settings['show_toggle'])) {
- $settings[$format]['toggle'] = (int) $profile->settings['show_toggle'];
- }
-
- $theme = wysiwyg_get_editor_themes($profile, (isset($profile->settings['theme']) ? $profile->settings['theme'] : ''));
-
- wysiwyg_add_plugin_settings($profile);
-
- wysiwyg_add_editor_settings($profile, $theme);
- }
- }
-
- if (!$format_field['format']['#access']) {
- $format_field['wysiwyg'] = array(
- '#type' => 'hidden',
- '#name' => $format_field['format']['#name'],
- '#value' => $format_id,
- '#attributes' => array(
- 'id' => $format_field['format']['#id'],
- 'class' => array('wysiwyg'),
- ),
- );
- $format_field['wysiwyg']['#attached']['js'][] = array(
- 'data' => array(
- 'wysiwyg' => array(
- 'triggers' => array(
- $format_field['format']['#id'] => $settings,
- ),
- ),
- ),
- 'type' => 'setting',
- );
- }
-
- else {
- $format_field['format']['#attributes']['class'][] = 'wysiwyg';
- $format_field['format']['#attached']['js'][] = array(
- 'data' => array(
- 'wysiwyg' => array(
- 'triggers' => array(
- $format_field['format']['#id'] => $settings,
- ),
- ),
- ),
- 'type' => 'setting',
- );
- }
-
-
- if (isset($loaded) && $resizable) {
- $field['#resizable'] = FALSE;
- }
- return $element;
- }
- function wysiwyg_get_profile($format) {
- if ($profile = wysiwyg_profile_load($format)) {
- if (wysiwyg_load_editor($profile)) {
- return $profile;
- }
- }
- return FALSE;
- }
- function wysiwyg_load_editor($profile) {
- static $settings_added;
- static $loaded = array();
- $path = drupal_get_path('module', 'wysiwyg');
- $name = $profile->editor;
-
- if (!isset($loaded[$name])) {
-
- $editor = wysiwyg_get_editor($name);
- if ($editor) {
- $default_library_options = array(
- 'type' => 'file',
- 'scope' => 'header',
- 'defer' => FALSE,
- 'cache' => TRUE,
- 'preprocess' => TRUE,
- );
-
-
- if (isset($profile->settings['library']) && isset($editor['libraries'][$profile->settings['library']])) {
- $library = $profile->settings['library'];
- $files = $editor['libraries'][$library]['files'];
- }
- else {
-
- $library = key($editor['libraries']);
- $files = array_shift($editor['libraries']);
- $files = $files['files'];
- }
-
- if (!empty($editor['init callback'])) {
- $init = $editor['init callback']($editor, $library, $profile);
- if (!empty($init)) {
-
-
- $uri = 'public://js/wysiwyg/wysiwyg_' . $name . '_' . drupal_hash_base64($init) . '.js';
- $init_exists = file_exists($uri);
- if (!$init_exists) {
- $js_path = dirname($uri);
- file_prepare_directory($js_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
- }
-
-
- if (!$init_exists && !file_unmanaged_save_data($init, $uri, FILE_EXISTS_REPLACE)) {
- drupal_add_js($init, array('type' => 'inline') + $default_library_options);
- }
- else {
- drupal_add_js(file_create_url($uri), $default_library_options);
- }
- }
- }
- foreach ($files as $file => $options) {
- if (is_array($options)) {
- $options += $default_library_options;
- drupal_add_js($editor['library path'] . '/' . $file, $options);
- }
- else {
- drupal_add_js($editor['library path'] . '/' . $options);
- }
- }
-
-
- if (isset($editor['load callback']) && function_exists($editor['load callback'])) {
- $editor['load callback']($editor, $library);
- }
-
- $files = array();
- if (isset($editor['js files'])) {
- $files = $editor['js files'];
- }
- foreach ($files as $file) {
- drupal_add_js($editor['js path'] . '/' . $file);
- }
-
- $files = array();
- if (isset($editor['css files'])) {
- $files = $editor['css files'];
- }
- foreach ($files as $file) {
- drupal_add_css($editor['css path'] . '/' . $file);
- }
- $loaded[$name] = TRUE;
- }
- else {
- $loaded[$name] = FALSE;
- }
- }
-
- if (!isset($settings_added) && $loaded[$name]) {
- drupal_add_js(array('wysiwyg' => array(
- 'configs' => array(),
- 'plugins' => array(),
- 'disable' => t('Disable rich-text'),
- 'enable' => t('Enable rich-text'),
- )), 'setting');
-
-
- drupal_add_js($path . '/wysiwyg.init.js', array('group' => JS_LIBRARY));
-
-
- drupal_add_js($path . '/editors/js/none.js');
-
-
-
-
-
-
- drupal_add_js($path . '/wysiwyg.js', array('scope' => 'footer'));
- $settings_added = TRUE;
- }
- return $loaded[$name];
- }
- function wysiwyg_add_editor_settings($profile, $theme) {
- static $formats = array();
- if (!isset($formats[$profile->format])) {
- $config = wysiwyg_get_editor_config($profile, $theme);
-
-
- if ($config) {
- drupal_add_js(array('wysiwyg' => array('configs' => array($profile->editor => array('format' . $profile->format => $config)))), 'setting');
- }
- $formats[$profile->format] = TRUE;
- }
- }
- function wysiwyg_add_plugin_settings($profile) {
- static $plugins = array();
- static $processed_plugins = array();
- static $processed_formats = array();
-
-
- if (isset($processed_formats[$profile->format])) {
- return;
- }
- $processed_formats[$profile->format] = TRUE;
- $editor = wysiwyg_get_editor($profile->editor);
-
-
- if (!array_key_exists($editor['name'], $plugins)) {
- $plugins[$editor['name']] = wysiwyg_get_plugins($editor['name']);
- }
-
- if (empty($plugins[$editor['name']])) {
- return;
- }
-
- $proxy = (isset($editor['proxy plugin']) ? key($editor['proxy plugin']) : '');
-
- if (isset($editor['plugin settings callback'])) {
-
- $profile_plugins_native = array();
- foreach ($plugins[$editor['name']] as $plugin => $meta) {
-
- if ($plugin === $proxy) {
- continue;
- }
-
- if (isset($profile->settings['buttons'][$plugin])) {
- $profile_plugins_native[$plugin] = $meta;
- }
- }
-
-
- $settings_native = call_user_func($editor['plugin settings callback'], $editor, $profile, $profile_plugins_native);
- if ($settings_native) {
- drupal_add_js(array('wysiwyg' => array('plugins' => array('format' . $profile->format => array('native' => $settings_native)))), 'setting');
- }
- }
-
- if ($proxy && isset($editor['proxy plugin settings callback'])) {
- $profile_plugins_drupal = array();
- foreach (wysiwyg_get_all_plugins() as $plugin => $meta) {
- if (isset($profile->settings['buttons'][$proxy][$plugin])) {
-
-
-
- if (!isset($processed_plugins[$proxy][$plugin])) {
- $profile_plugins_drupal[$plugin] = $processed_plugins[$proxy][$plugin] = $meta;
-
- drupal_add_js($meta['js path'] . '/' . $meta['js file']);
-
- if (isset($meta['settings'])) {
- drupal_add_js(array('wysiwyg' => array('plugins' => array('drupal' => array($plugin => $meta['settings'])))), 'setting');
- }
- }
- else {
- $profile_plugins_drupal[$plugin] = $processed_plugins[$proxy][$plugin];
- }
- }
- }
-
-
- $settings_drupal = call_user_func($editor['proxy plugin settings callback'], $editor, $profile, $profile_plugins_drupal);
- if ($settings_drupal) {
- drupal_add_js(array('wysiwyg' => array('plugins' => array('format' . $profile->format => array('drupal' => $settings_drupal)))), 'setting');
- }
- }
- }
- function wysiwyg_get_editor_themes(&$profile, $selected_theme = NULL) {
- static $themes = array();
- if (!isset($themes[$profile->editor])) {
- $editor = wysiwyg_get_editor($profile->editor);
- if (isset($editor['themes callback']) && function_exists($editor['themes callback'])) {
- $themes[$editor['name']] = $editor['themes callback']($editor, $profile);
- }
-
- else {
- $themes[$editor['name']] = array('default');
- }
- }
-
- if (isset($selected_theme)) {
-
- if (!in_array($selected_theme, $themes[$profile->editor])) {
- $selected_theme = $profile->settings['theme'] = $themes[$profile->editor][0];
- }
- }
- return isset($selected_theme) ? $selected_theme : $themes[$profile->editor];
- }
- function wysiwyg_get_plugins($editor_name) {
- $plugins = array();
- if (!empty($editor_name)) {
- $editor = wysiwyg_get_editor($editor_name);
-
- if (isset($editor['plugin callback']) && function_exists($editor['plugin callback'])) {
- $plugins = $editor['plugin callback']($editor);
- }
-
- $plugins = array_merge($plugins, module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version']));
-
-
- if (isset($editor['proxy plugin'])) {
- $plugins += $editor['proxy plugin'];
- $proxy = key($editor['proxy plugin']);
- foreach (wysiwyg_get_all_plugins() as $plugin_name => $info) {
- $plugins[$proxy]['buttons'][$plugin_name] = $info['title'];
- }
- }
- }
- return $plugins;
- }
- function wysiwyg_get_editor_config($profile, $theme) {
- $editor = wysiwyg_get_editor($profile->editor);
- $settings = array();
- if (!empty($editor['settings callback']) && function_exists($editor['settings callback'])) {
- $settings = $editor['settings callback']($editor, $profile->settings, $theme);
-
- $context = array('editor' => $editor, 'profile' => $profile, 'theme' => $theme);
- drupal_alter('wysiwyg_editor_settings', $settings, $context);
- }
- return $settings;
- }
- function wysiwyg_get_css() {
- static $files;
- if (isset($files)) {
- return $files;
- }
-
- if (!empty($_POST)) {
- drupal_theme_initialize();
- }
- $files = array();
- foreach (drupal_add_css() as $filepath => $info) {
- if ($info['group'] >= CSS_THEME && $info['media'] != 'print') {
- if ($info['type'] == 'external') {
- $files[] = $filepath;
- }
- elseif (file_exists($filepath)) {
- $files[] = base_path() . $filepath;
- }
- }
- }
- return $files;
- }
- function wysiwyg_profile_load($format) {
- $profiles = wysiwyg_profile_load_all();
- return (isset($profiles[$format]) ? $profiles[$format] : FALSE);
- }
- function wysiwyg_profile_load_all() {
-
-
-
- $profiles = &drupal_static(__FUNCTION__);
- if (!isset($profiles)) {
-
- if ($cached = cache_get('wysiwyg_profiles')) {
- $profiles = $cached->data;
- }
- else {
- $profiles = entity_load('wysiwyg_profile', FALSE);
- cache_set('wysiwyg_profiles', $profiles);
- }
- }
- return $profiles;
- }
- function wysiwyg_profile_delete($format) {
- db_delete('wysiwyg')
- ->condition('format', $format)
- ->execute();
- }
- function wysiwyg_profile_cache_clear() {
- entity_get_controller('wysiwyg_profile')->resetCache();
- drupal_static_reset('wysiwyg_profile_load_all');
- cache_clear_all('wysiwyg_profiles', 'cache');
- }
- function wysiwyg_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
- $account = $form['#user'];
- $user_formats = filter_formats($account);
- $options = array();
- $options_default = array();
- foreach (wysiwyg_profile_load_all() as $format => $profile) {
-
- if (!empty($profile->settings['user_choose']) && isset($user_formats[$format])) {
- $options[$format] = check_plain($user_formats[$format]->name);
- if (wysiwyg_user_get_status($profile, $account)) {
- $options_default[] = $format;
- }
- }
- }
- if (!empty($options)) {
- $form['wysiwyg']['wysiwyg_status'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Text formats enabled for rich-text editing'),
- '#options' => $options,
- '#default_value' => $options_default,
- );
- }
- }
- function wysiwyg_user_insert(&$edit, $account, $category) {
- wysiwyg_user_update($edit, $account, $category);
- }
- function wysiwyg_user_update(&$edit, $account, $category) {
- if (isset($edit['wysiwyg_status'])) {
- db_delete('wysiwyg_user')
- ->condition('uid', $account->uid)
- ->execute();
- $query = db_insert('wysiwyg_user')
- ->fields(array('uid', 'format', 'status'));
- foreach ($edit['wysiwyg_status'] as $format => $status) {
- $query->values(array(
- 'uid' => $account->uid,
- 'format' => $format,
- 'status' => (int) (bool) $status,
- ));
- }
- $query->execute();
- }
- }
- function wysiwyg_user_get_status($profile, $account = NULL) {
- global $user;
- if (!isset($account)) {
- $account = $user;
- }
-
-
- if (!isset($account->wysiwyg_status)) {
- $account->wysiwyg_status = db_query("SELECT format, status FROM {wysiwyg_user} WHERE uid = :uid", array(
- ':uid' => $account->uid,
- ))->fetchAllKeyed();
- }
- if (!empty($profile->settings['user_choose']) && isset($account->wysiwyg_status[$profile->format])) {
- $status = $account->wysiwyg_status[$profile->format];
- }
- else {
- $status = isset($profile->settings['default']) ? $profile->settings['default'] : TRUE;
- }
- return (bool) $status;
- }
- function wysiwyg_get_editor($name) {
- $editors = wysiwyg_get_all_editors();
- return isset($editors[$name]) && $editors[$name]['installed'] ? $editors[$name] : FALSE;
- }
- function wysiwyg_get_all_editors() {
- static $editors;
- if (isset($editors)) {
- return $editors;
- }
- $editors = wysiwyg_load_includes('editors', 'editor');
- foreach ($editors as $editor => $properties) {
-
- $editors[$editor] += array(
- 'title' => '',
- 'vendor url' => '',
- 'download url' => '',
- 'editor path' => wysiwyg_get_path($editors[$editor]['name']),
- 'library path' => wysiwyg_get_path($editors[$editor]['name']),
- 'libraries' => array(),
- 'version callback' => NULL,
- 'themes callback' => NULL,
- 'settings form callback' => NULL,
- 'settings callback' => NULL,
- 'plugin callback' => NULL,
- 'plugin settings callback' => NULL,
- 'versions' => array(),
- 'js path' => $editors[$editor]['path'] . '/js',
- 'css path' => $editors[$editor]['path'] . '/css',
- );
-
- if (!($editors[$editor]['installed'] = file_exists($editors[$editor]['library path']))) {
- continue;
- }
-
- if (function_exists($editors[$editor]['version callback'])) {
- $editors[$editor]['installed version'] = $editors[$editor]['version callback']($editors[$editor]);
- }
- if (empty($editors[$editor]['installed version'])) {
- $editors[$editor]['error'] = t('The version of %editor could not be detected.', array('%editor' => $properties['title']));
- $editors[$editor]['installed'] = FALSE;
- continue;
- }
-
- ksort($editors[$editor]['versions']);
- $version = 0;
- foreach ($editors[$editor]['versions'] as $supported_version => $version_properties) {
- if (version_compare($editors[$editor]['installed version'], $supported_version, '>=')) {
- $version = $supported_version;
- }
- }
- if (!$version) {
- $editors[$editor]['error'] = t('The installed version %version of %editor is not supported.', array('%version' => $editors[$editor]['installed version'], '%editor' => $editors[$editor]['title']));
- $editors[$editor]['installed'] = FALSE;
- continue;
- }
-
- $editors[$editor] = array_merge($editors[$editor], $editors[$editor]['versions'][$version]);
- unset($editors[$editor]['versions']);
- }
- return $editors;
- }
- function wysiwyg_get_all_plugins() {
- static $plugins;
- if (isset($plugins)) {
- return $plugins;
- }
- $plugins = wysiwyg_load_includes('plugins', 'plugin');
- foreach ($plugins as $name => $properties) {
- $plugin = &$plugins[$name];
-
- $plugin += array(
- 'title' => $plugin['name'],
- 'vendor url' => '',
- 'js path' => $plugin['path'] . '/' . $plugin['name'],
- 'js file' => $plugin['name'] . '.js',
- 'css path' => $plugin['path'] . '/' . $plugin['name'],
- 'css file' => $plugin['name'] . '.css',
- 'icon path' => $plugin['path'] . '/' . $plugin['name'] . '/images',
- 'icon file' => $plugin['name'] . '.png',
- 'dialog path' => $plugin['name'],
- 'dialog settings' => array(),
- 'settings callback' => NULL,
- 'settings form callback' => NULL,
- );
-
- $plugin['settings'] += array(
- 'path' => base_path() . $plugin['path'] . '/' . $plugin['name'],
- );
-
- if (!($plugin['installed'] = file_exists($plugin['js path'] . '/' . $plugin['js file']))) {
- continue;
- }
- }
- return $plugins;
- }
- function wysiwyg_load_includes($type = 'editors', $hook = 'editor', $file = NULL) {
-
- $directories = wysiwyg_get_directories($type);
- $directories['wysiwyg'] = drupal_get_path('module', 'wysiwyg') . '/' . $type;
- $file_list = array();
- foreach ($directories as $module => $path) {
- $file_list[$module] = drupal_system_listing("/{$file}.inc\$/", $path, 'name', 0);
- }
-
- $info = array();
- foreach (array_filter($file_list) as $module => $files) {
- foreach ($files as $file) {
- include_once './' . $file->uri;
- $result = _wysiwyg_process_include($module, $module . '_' . $file->name, dirname($file->uri), $hook);
- if (is_array($result)) {
- $info = array_merge($info, $result);
- }
- }
- }
- return $info;
- }
- function wysiwyg_get_path($library, $base_path = FALSE) {
- static $libraries;
- if (!isset($libraries)) {
- $libraries = wysiwyg_get_libraries();
- }
- if (!isset($libraries[$library])) {
-
- return 'sites/all/libraries/' . $library;
- }
- $path = ($base_path ? base_path() : '');
- $path .= $libraries[$library];
- return $path;
- }
- function wysiwyg_get_libraries() {
- global $profile;
-
-
-
-
-
- if (!isset($profile)) {
- $profile = variable_get('install_profile', 'default');
- }
- $directory = 'libraries';
- $searchdir = array();
- $config = conf_path();
-
-
-
-
- if (file_exists("profiles/$profile/$directory")) {
- $searchdir[] = "profiles/$profile/$directory";
- }
-
- $searchdir[] = 'sites/all/' . $directory;
-
- if (file_exists("$config/$directory")) {
- $searchdir[] = "$config/$directory";
- }
-
-
- $directories = array();
- $nomask = array('CVS');
- foreach ($searchdir as $dir) {
- if (is_dir($dir) && $handle = opendir($dir)) {
- while (FALSE !== ($file = readdir($handle))) {
- if (!in_array($file, $nomask) && $file[0] != '.') {
- if (is_dir("$dir/$file")) {
- $directories[$file] = "$dir/$file";
- }
- }
- }
- closedir($handle);
- }
- }
- return $directories;
- }
- function wysiwyg_get_directories($plugintype) {
- $directories = array();
- foreach (module_implements('wysiwyg_include_directory') as $module) {
- $result = module_invoke($module, 'wysiwyg_include_directory', $plugintype);
- if (isset($result) && is_string($result)) {
- $directories[$module] = drupal_get_path('module', $module) . '/' . $result;
- }
- }
- return $directories;
- }
- function _wysiwyg_process_include($module, $identifier, $path, $hook) {
- $function = $identifier . '_' . $hook;
- if (!function_exists($function)) {
- return NULL;
- }
- $result = $function();
- if (!isset($result) || !is_array($result)) {
- return NULL;
- }
-
- foreach ($result as $editor => $properties) {
- $result[$editor]['module'] = $module;
- $result[$editor]['name'] = $editor;
- $result[$editor]['path'] = $path;
- }
- return $result;
- }
- function wysiwyg_features_api() {
- return array(
- 'wysiwyg' => array(
- 'name' => t('Wysiwyg profiles'),
- 'default_hook' => 'wysiwyg_default_profiles',
- 'default_file' => FEATURES_DEFAULTS_INCLUDED,
- 'feature_source' => TRUE,
- 'file' => drupal_get_path('module', 'wysiwyg') . '/wysiwyg.features.inc',
- ),
- );
- }
|