sector-8.x-2.0-alpha4/modules/sector_wysiwyg_utils/sector_wysiwyg_utils.module
modules/sector_wysiwyg_utils/sector_wysiwyg_utils.module
<?php
/**
* @file
* Module for adding classes to blocks.
*/
/**
* Implements hook_editor_js_settings_alter().
*
*Adds the Maori macrons to the special characters list.
*
*/
function sector_wysiwyg_utils_editor_js_settings_alter(array &$settings) {
// Loads the default special characters. These have to be loaded, when trying
// to just append the new characters to the end of the existing list it acted
// as an override and wiped this list.
$default_special_chars = array(
'!','"','#','$','%','&',"'",'(',')','*','+','-','.','/',
'0','1','2','3','4','5','6','7','8','9',':',';',
'<','=','>','?','@',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
'P','Q','R','S','T','U','V','W','X','Y','Z',
'[',']','^','_','`',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x','y','z',
'{','|','}','~',
"€", "‘", "’", "“", "”", "–", "—", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "®", "¯", "°", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "Œ", "œ", "Ŵ", "Ŷ", "ŵ", "ŷ", "‚", "‛", "„", "…", "™", "►", "•", "→", "⇒", "⇔", "♦", "≈",
);
// The new Maroi macrons list
$added_special_chars = array("Ā", "ā", "Ē", "ē", "Ī", "ī", "Ō", "ō", "Ū", "ū");
// Merge the two lists to get the final character list.
$new_special_chars_list = array_merge($default_special_chars, $added_special_chars);
// Loads all formats, and applies the new list to each.
foreach (array_keys($settings['editor']['formats']) as $text_format_id) {
$settings['editor']['formats'][$text_format_id]['editorSettings']['specialChars'] = $new_special_chars_list;
}
}
/**
* Implements hook_preprocess_field.
*
* For media, the output of filesize and mimetype is unsatisfactory. E.G.
* filesize is in bytes. So rewrite that.
* @param $variables
*/
function sector_wysiwyg_utils_preprocess_field(&$variables) {
switch ($variables['element']['#field_name']) {
case 'field_filesize':
if(!empty($variables['element']['0']['#context']['value'])) {
// Get current filesize
$filesize = $variables['element']['0']['#context']['value'];
// Set new filesize.
$variables['items'][0]['content'] = format_size($filesize);
}
break;
case 'field_mimetype':
if(!empty($variables['element']['0']['#context']['value'])) {
// Get current mime.
$mimetype = $variables['element']['0']['#context']['value'];
// Set new mime.
$variables['items'][0]['content'] = _niceMimeType($mimetype);
}
break;
default:
break;
}
}
/**
* Helper function.
*
* Gets a nicer version of the mimetype.
*/
function _niceMimeType($originalMimeType) {
$newMimeType = $originalMimeType;
switch ($originalMimeType) {
case 'application/pdf':
$newMimeType = 'PDF';
break;
case 'application/msword':
$newMimeType = 'DOC';
break;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
$newMimeType = 'DOCX';
break;
case 'text/plain':
$newMimeType = 'TXT';
break;
case 'application/rtf':
$newMimeType = 'RTF';
break;
case 'application/vnd.ms-powerpoint':
$newMimeType = 'PPT';
break;
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
$newMimeType = 'PPTX';
break;
case 'application/vnd.ms-excel':
$newMimeType = 'XLS';
break;
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
$newMimeType = 'XLSX';
break;
case 'application/xml':
$newMimeType = 'XML';
break;
case 'text/csv':
$newMimeType = 'CSV';
break;
case 'application/zip':
case 'application/octet-stream':
$newMimeType = 'ZIP';
break;
default:
break;
}
return $newMimeType;
}
