View source
<?php
include_once 'panopoly_wysiwyg.features.inc';
include_once 'panopoly_wysiwyg.features.wysiwyg.inc';
function panopoly_wysiwyg_apps_app_info() {
return array(
'configure form' => 'panopoly_wysiwyg_configure_form',
);
}
function panopoly_wysiwyg_configure_form($form, &$form_state) {
$form = array();
$form['panopoly_wysiwyg_show_format_details'] = array(
'#title' => t('Show Text Formatter Details'),
'#type' => 'select',
'#required' => TRUE,
'#options' => array(
'1' => 'Show',
'0' => 'Do Not Show',
),
'#default_value' => variable_get('panopoly_wysiwyg_show_format_details', 0),
'#description' => t('Do you want Panopoly to show the help text and text format guidelines?'),
);
return system_settings_form($form);
}
function panopoly_wysiwyg_ctools_plugin_directory($module, $plugin) {
return 'plugins/' . $plugin;
}
function panopoly_wysiwyg_wysiwyg_plugin($editor) {
switch ($editor) {
case 'tinymce':
return array(
'pdw' => array(
'path' => drupal_get_path('module', 'panopoly_wysiwyg') . '/plugins/wysiwyg/pdw',
'filename' => 'editor_plugin.js',
'buttons' => array(
'pdw_toggle' => t('Kitchen Sink'),
),
'url' => 'http://www.neele.name/pdw_toggle_toolbars/',
'load' => TRUE,
),
'spellchecker' => array(
'internal' => TRUE,
'buttons' => array(
'spellchecker' => t('Spell Check'),
),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker',
'load' => TRUE,
),
'inlinepopups' => array(
'internal' => TRUE,
'url' => 'http://www.tinymce.com/wiki.php/Plugin:inlinepopups',
'load' => TRUE,
),
);
}
}
function panopoly_wysiwyg_element_info_alter(&$type) {
if (isset($type['text_format'])) {
$type['text_format']['#process'][] = 'panopoly_wysiwyg_filter_process_format';
}
}
function panopoly_wysiwyg_filter_process_format($element) {
$element['format']['format']['#attributes']['class'][] = 'ctools-auto-submit-exclude';
if (!variable_get('panopoly_wysiwyg_show_format_details', FALSE)) {
$element['format']['#weight'] = 1;
$element['format']['#prefix'] = '<div class="clearfix"><div class="format-toggle">';
$element['format']['#suffix'] = '</div></div>';
unset($element['format']['#type']);
$element['format']['format']['#title'] = 'Editor: ';
$element['format']['help']['#access'] = FALSE;
$element['format']['guidelines']['#access'] = FALSE;
}
return $element;
}
function panopoly_wysiwyg_module_implements_alter(&$implementations, $hook) {
if ($hook == 'wysiwyg_editor_settings_alter') {
$group = $implementations['panopoly_wysiwyg'];
unset($implementations['panopoly_wysiwyg']);
$implementations['panopoly_wysiwyg'] = $group;
}
}
function panopoly_wysiwyg_alter_wysiwyg_editor_settings(&$settings, $context) {
switch ($context['editor']['name']) {
case 'tinymce':
$settings['skin'] = 'cirkuit';
$settings['spellchecker_languages'] = '+English=en';
if (isset($context['profile']->settings['buttonorder'])) {
$default_buttons = preg_replace('/separator,separator/', 'PAGEBREAK', $context['profile']->settings['buttonorder']);
}
else {
$enabled_buttons = preg_split('/,/', $settings['theme_advanced_buttons1']);
$default_buttons = array(
'bold',
'italic',
'strikethrough',
'|',
'bullist',
'numlist',
'blockquote',
'|',
'justifyleft',
'justifycenter',
'justifyright',
'|',
'linkit',
'unlink',
'drupal_break',
'|',
'fullscreen',
'spellchecker',
'drupal_media',
'captionfilter',
'pdw_toggle',
'PAGEBREAK',
'formatselect',
'|',
'underline',
'|',
'justifyfull',
'|',
'forecolor',
'|',
'pastetext',
'pasteword',
'removeformat',
'|',
'charmap',
'|',
'outdent',
'indent',
'|',
'undo',
'redo',
);
foreach ($default_buttons as $button) {
if (in_array($button, $enabled_buttons)) {
unset($enabled_buttons[array_search($button, $enabled_buttons)]);
}
elseif ($button != '|' && $button != 'PAGEBREAK') {
unset($default_buttons[array_search($button, $default_buttons)]);
}
}
if (count($enabled_buttons) > 0) {
$default_buttons[] = 'PAGEBREAK';
$default_buttons = array_merge($default_buttons, $enabled_buttons);
}
$default_buttons = implode(',', $default_buttons);
}
$default_buttons_list = preg_split('/,PAGEBREAK,/', $default_buttons);
$rows_count = count($default_buttons_list);
for ($i = 0; $i < $rows_count; $i++) {
$settings['theme_advanced_buttons' . ($i + 1)] = !empty($default_buttons_list[$i]) ? $default_buttons_list[$i] : NULL;
}
$settings['pdw_toggle_on'] = '1';
$settings['pdw_toggle_toolbars'] = $rows_count > 1 ? implode(',', range(2, $rows_count)) : '2';
$settings['plugins'] .= ',inlinepopups';
$settings['dialog_type'] = 'modal';
if (empty($settings['extended_valid_elements'])) {
$settings['extended_valid_elements'] = 'img[!src|title|alt|style|width|height|class|hspace|vspace|view_mode|format|fid]';
}
else {
$settings['extended_valid_elements'] = array_merge(explode(',', $settings['extended_valid_elements']), array(
'img[!src|title|alt|style|width|height|class|hspace|vspace|view_mode|format|fid]',
));
$settings_array = array();
foreach ($settings['extended_valid_elements'] as $tag) {
if (strpos("[", $tag) !== FALSE) {
list($tag, $allowed_attributes) = explode('[', $tag);
$allowed_attributes = explode('|', trim($allowed_attributes, ']'));
foreach ($allowed_attributes as $key => $attribute) {
$settings_array[$tag][$attribute] = $attribute;
}
}
}
$valid_elements = array();
foreach ($settings_array as $tag => $allowed_attributes) {
$attributes = in_array('*', $allowed_attributes) ? '*' : implode('|', $allowed_attributes);
$valid_elements[] = $tag . '[' . $attributes . ']';
}
$settings['extended_valid_elements'] = implode(',', $valid_elements);
}
break;
case 'markitup':
drupal_add_css($context['editor']['library path'] . '/markitup/sets/html/style.css');
drupal_add_js($context['editor']['library path'] . '/markitup/sets/html/set.js');
$header_buttons = array(
'header-begin' => array(
'className' => 'markItUpSeparator',
),
'h1' => array(
'name' => t('Heading 1'),
'className' => 'markitup-h1',
'key' => '1',
'openWith' => '<h1(!( class="[![Class]!]")!)>',
'closeWith' => '</h1>',
'placeHolder' => 'Your title here...',
),
'h2' => array(
'name' => t('Heading 2'),
'className' => 'markitup-h2',
'key' => '2',
'openWith' => '<h2(!( class="[![Class]!]")!)>',
'closeWith' => '</h2>',
'placeHolder' => 'Your title here...',
),
'h3' => array(
'name' => t('Heading 3'),
'className' => 'markitup-h3',
'key' => '3',
'openWith' => '<h3(!( class="[![Class]!]")!)>',
'closeWith' => '</h3>',
'placeHolder' => 'Your title here...',
),
'h4' => array(
'name' => t('Heading 4'),
'className' => 'markitup-h4',
'key' => '4',
'openWith' => '<h4(!( class="[![Class]!]")!)>',
'closeWith' => '</h4>',
'placeHolder' => 'Your title here...',
),
'paragraph' => array(
'name' => t('Paragraph'),
'className' => 'markitup-paragraph',
'key' => 'p',
'openWith' => '<p(!( class="[![Class]!]")!)>',
'closeWith' => '</p>',
),
'header-end' => array(
'className' => 'markItUpSeparator',
),
);
$list_styles = array(
'list-bullet' => array(
'name' => t('Unordered List'),
'className' => 'markitup-list-bullet',
'openWith' => "<ul>\n",
'closeWith' => '</ul>',
),
'list-numeric' => array(
'name' => t('Ordered List'),
'className' => 'markitup-list-numeric',
'openWith' => "<ol>\n",
'closeWith' => '</ol>',
),
);
foreach ($header_buttons as $tag => $details) {
$settings['markupSet'][$tag] = $details;
$context['profile']->settings['buttons']['html'][$tag] = 1;
}
foreach ($list_styles as $tag => $details) {
$settings['markupSet'][$tag] = $details;
$context['profile']->settings['buttons']['html'][$tag] = 1;
}
break;
}
}
function panopoly_wysiwyg_wysiwyg_editor_settings_alter(&$settings, $context) {
if (strpos($context['profile']->format, 'panopoly_') === 0) {
panopoly_wysiwyg_alter_wysiwyg_editor_settings($settings, $context);
}
elseif ($context['profile']->editor == 'tinymce') {
if (!isset($settings['pdw_toggle_on'])) {
$settings['pdw_toggle_on'] = '1';
}
if (!isset($settings['pdw_toggle_toolbars'])) {
$toolbars = array();
if (!empty($settings['theme_advanced_buttons2'])) {
$toolbars[] = '2';
}
if (!empty($settings['theme_advanced_buttons3'])) {
$toolbars[] = '3';
}
if (empty($toolbars)) {
$settings['plugins'] = implode(',', array_diff(explode(',', $settings['plugins']), array(
'-pdw',
)));
}
else {
$settings['pdw_toggle_toolbars'] = implode(',', $toolbars);
}
}
}
}
function panopoly_wysiwyg_form_wysiwyg_profile_form_alter(&$form, &$form_state, $form_id) {
if (module_exists('wysiwyg_button_order')) {
$form['#after_build'][] = 'panopoly_wysiwyg_button_order_help';
}
}
function panopoly_wysiwyg_button_order_help($form) {
if (isset($form['buttonorder'])) {
$form['buttonorder']['#description'] = '<p>Add two separators in a row to force buttons to a new row.</p>';
}
return $form;
}
function panopoly_wysiwyg_filter_info() {
$filters = array();
$filters['panopoly_images_fix_captions'] = array(
'title' => t('Add Panopoly image classes to caption wrappers'),
'description' => t('This filter must come AFTER Caption Filter. Adds the image style class from the img tag to div.caption.'),
'process callback' => '_panopoly_wysiwyg_process_caption_filter',
);
return $filters;
}
function _panopoly_wysiwyg_process_caption_filter($text, $filter, $format, $langcode, $cache, $cache_id) {
$text = '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><body>' . $text . '</body>';
if (function_exists('libxml_use_internal_errors')) {
$use_errors = libxml_use_internal_errors(TRUE);
}
$doc = new DOMDocument();
$doc
->loadHTML($text);
$xpath = new DOMXpath($doc);
$captions = $xpath
->query("//div[contains(concat(' ',normalize-space(@class),' '),' caption ')]");
foreach ($captions as $caption) {
$imgs = $caption
->getElementsByTagName("img");
foreach ($imgs as $img) {
$img_classes = $img
->getAttribute("class");
$img_path = $img
->getAttribute("src");
$server_path = str_replace('http://' . $_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $img_path);
$doc_path = explode('?', $server_path);
$img_info = image_get_info($doc_path[0]);
preg_match("/panopoly-image-[a-z]+/", $img_classes, $panopoly_image_class);
}
if (empty($panopoly_image_class)) {
return $text;
}
$caption_classes = $caption
->getAttribute('class');
if (!empty($caption_classes)) {
$caption_classes = $caption_classes . ' ' . $panopoly_image_class[0];
}
$caption
->setAttribute('class', $caption_classes);
}
$text = $doc
->saveHTML();
$text = preg_replace('/^.*?<body>/s', '', $text);
$text = preg_replace('/<\\/body>.*$/s', '', $text);
if (function_exists('libxml_use_internal_errors')) {
libxml_clear_errors();
libxml_use_internal_errors($use_errors);
}
return $text;
}