HTMLArea/Xinha is not installed, download Xinha from http://xinha.gogo.co.nz/cgi-bin/trac.cgi/wiki/DownloadsPage(recommended) or HTMLArea from cvs.
');
}
break;
case "admin/settings/htmlarea/plugins/css":
$output .= t('the css module allows the administrator to add one or more
dropdown boxes to the toolbar which allow the assigning of a
style to an area of test.
- dropbox - the that will be assigned to the pull down list
on the toolbar.
- context - using a HTML tag will it will only be allowed to
be used on text that exists within this tag.
- weight - sets the order of the pulldown menus on the
toolbar.
- delete - allow the administrator to delete a pulldown
menu.
adding a new drop box will allow create an addition input
table to allow the adding of the titles and css tags.
- title - The name that will be displayed on the select
list.
- css - the name of the css that exists in the style
sheet.
- weight - sets the order of the pulldown menus on the
toolbar.
- delete - allow the administrator to delete a pulldown
menu.
');
break;
}
return $output;
}
function htmlarea_menu() {
$items = array();
$items[] = array("path" => "admin/settings/htmlarea/main", "title" => t("htmlarea"),
"callback" => "htmlarea_settings",
"access" => user_access("administer site configuration"),
"type" => MENU_DEFAULT_LOCAL_TASK, "weight" => "-10");
$items[] = array("path" => "admin/settings/htmlarea/toolbar",
"title" => t("toolbar"),
"callback" => "htmlarea_settings_toolbar",
"access" => user_access("administer site configuration"),
"type" => MENU_LOCAL_TASK, "weight" => "-1");
$items[] = array("path" => "admin/settings/htmlarea/textarea",
"title" => t("textareas"),
"callback" => "htmlarea_settings_textarea",
"access" => user_access("administer site configuration"),
"type" => MENU_LOCAL_TASK);
$items[] = array("path" => "admin/settings/htmlarea/plugins",
"title" => t("plugins"),
"callback" => "htmlarea_settings_plugins",
"access" => user_access("administer site configuration"),
"type" => MENU_LOCAL_TASK);
$items[] = array("path" => "admin/settings/htmlarea/plugins/select",
"title" => t("select"),
"callback" => "htmlarea_settings_plugins",
"access" => user_access("administer site configuration"),
"type" => MENU_DEFAULT_LOCAL_TASK,
"weight" => -10);
$items[] = array("path" => "admin/settings/htmlarea/fontnames",
"title" => t("font names"),
"callback" => "htmlarea_settings_array",
"callback arguments" => "fontnames",
"access" => user_access("administer site configuration"),
"type" => MENU_LOCAL_TASK);
$items[] = array("path" => "admin/settings/htmlarea/fontsize",
"title" => t("font size"),
"callback" => "htmlarea_settings_array",
"callback arguments" => "fontsize",
"access" => user_access("administer site configuration"),
"type" => MENU_LOCAL_TASK);
$items[] = array("path" => "admin/settings/htmlarea/formatblock",
"title" => t("format block"),
"callback" => "htmlarea_settings_array",
"callback arguments" => "formatblock",
"access" => user_access("administer site configuration"),
"type" => MENU_LOCAL_TASK);
$plugins = variable_get("htmlarea_plugins", array());
foreach ($plugins as $plugin => $enabled) {
if ($enabled) {
$items = array_merge($items, module_invoke_all("htmlarea_plugin", $plugin, "menu"));
}
}
$items[] = array("path" => "admin/settings/htmlarea/custom",
"title" => t("custom js"),
"callback" => "htmlarea_settings_custom",
"access" => user_access("administer site configuration"),
"weight" => 10,
"type" => MENU_LOCAL_TASK);
return $items;
}
function htmlarea_perm() {
return array("upload images", "use htmlarea");
}
function htmlarea_textarea($op, $name) {
global $htmlarea_init, $htmlarea_fields, $htmlarea_codeview;
if ($op == "post") {
$real_name = $name;
$name = _htmlarea_parse_name($name);
if (_htmlarea_is_changed($name)) {
$htmlarea_init[] = "var $name = null;";
if (!$htmlarea_codeview) {
$htmlarea_fields[] = " attacheditor($name, '$name');";
}
}
}
}
function htmlarea_onload() {
if (_htmlarea_is_changed()) {
return array("HTMLArea.init()");
}
return array();
}
function htmlarea_footer() {
global $htmlarea_init, $htmlarea_fields, $base_url;
if (_htmlarea_is_changed()) {
if (variable_get("htmlarea_add_rev", FALSE)) {
$output[] = '';
}
$plugins = variable_get("htmlarea_plugins", array());
if ($plugins['HtmlTidy']) {
$output[] = "";
$output[] = "";
}
$output[] = "";
$output[] = "";
if ($plugins != array()) {
$output[] = "";
}
$output = array_merge($output, array(""));
return $output;
}
return array();
}
function htmlarea_user($type, $edit, &$user, $category = NULL) {
switch ($type) {
case "form":
if ( ($category == 'account') && (user_access('use htmlarea')) ) {
$output = form_checkbox(t('Enable rich text editor while authoring'), 'htmlarea_isenabled', 1, isset($user->htmlarea_isenabled) ? $user->htmlarea_isenabled : 1);
return array(array ('title' => t('text area settings'), 'data' => $output));
}
return NULL;
case 'validate':
return array('htmlarea_isenabled' => $edit['htmlarea_isenabled']);
}
}
function htmlarea_htmlarea_plugin($plugin, $op) {
switch($op) {
case "menu":
switch(strtolower($plugin)) {
case 'css':
$items[] = array("path" => "admin/settings/htmlarea/plugins/" .strtolower($plugin),
"title" => t("css"),
"callback" => "htmlarea_settings_plugins_css",
"access" => user_access("administer site configuration"),
"type" => MENU_LOCAL_TASK);
break;
case "help created":
$items[] = array("path" => "admin/settings/htmlarea/plugins/" .strtolower($plugin),
"title" => t(strtolower($plugin)),
"callback" => "htmlarea_settings_plugins_help",
"callback arguments" => $plugin,
"access" => user_access("administer site configuration"),
"type" => MENU_LOCAL_TASK);
break;
}
return $items;
break;
case "execute":
switch(strtolower($plugin)) {
case "css":
$plugins = variable_get("htmlarea_plugins_css", array());
$param = " editor.registerPlugin(\"$plugin\", {\n";
$param.= " combos : [\n";
$combos = array();
foreach ($plugins as $k => $v) {
$temp = " { label : \"" .$v['data'] ."\",\n";
$temp.= " options : { \"— None —\" : \"\"";
if (is_array($v['css']) && $v['css'] != array()) {
$temp.= ",\n";
$css = array();
foreach ($v['css'] as $ck => $cv) {
$css[] = " \"" .$cv['data'] ."\" : \"" .$cv['value'] ."\"";
}
$temp.= implode(",\n", $css) ."\n";
}
$temp.= " }";
if ($v['context'] != "") {
$temp.= ",\n context : \"" .$v['context'] ."\"\n";
}
$temp.= "\n }";
$combos[] = $temp;
}
$param.= implode(",\n", $combos) ."\n";
$param.= " ]\n";
$param.= " });";
$output[] = $param;
break;
default:
$output[] = " editor.registerPlugin(\"$plugin\");";
break;
}
return $output;
break;
}
}
function htmlarea_settings() {
if (variable_get("filter_html", 0)) {
$output .= form_item(t("Filter HTML tags"), t("The Filter HTML Tags is Enabled, This conflicts with htmlarea. "). l(t("Please disable"), "admin/system/filters"));
}
$output.= form_checkbox(t("Default for New Textareas"), "htmlarea_default", true, variable_get("htmlarea_default", true), t("Default setting which determines if a new textarea will be converted into a htmlarea"));
$output.= form_checkbox(t("Default for New Users"), "htmlarea_user_default", true, variable_get("htmlarea_user_default", true), t("Default setting which determines if a new user will be allowed to use htmlarea"));
$output.= form_checkbox(t("kill word on paste"), "htmlarea_killwordonpaste", true, variable_get("htmlarea_killwordonpaste", false), t("This option configures htmlarea so that when pasting from word documents will clean up the word html"));
$output.= form_checkbox(t("add revision to web page"), "htmlarea_add_rev", TRUE, variable_get("htmlarea_add_rev", FALSE), t("If you have any problems with htmlarea check this box, and the revision will be added to the html. When you submit a bug report please upload the html source from the web browser to enable better support."));
$output.= form_checkbox(t("insert linebreaks in toolbar"), "htmlarea_add_linebreak", TRUE, variable_get("htmlarea_add_linebreak", FALSE), t("If you are using the forked version of htmlarea from http://code.gogo.co.nz/products/htmlarea_fork.html the linebreaks have been corrected and work as they should. Enabling this will cause problems with the original version, and some plugins."));
$output.= form_textfield(t("Page Style"), "htmlarea_bodystyle", variable_get("htmlarea_bodystyle", "body { background-color: #fff; font-family: arial,helvetica,sans-serif; }"), 100, 100, t("Set the style of the htmlarea body"));
return $output;
}
function htmlarea_settings_textarea() {
if (user_access("administer nodes")) {
if ($_POST["op"] == t("Save configuration")) {
drupal_set_message(htmlarea_settings_textarea_save($_POST["edit"]));
}
$output .= htmlarea_settings_textarea_view();
}
else {
drupal_set_message(message_access());
}
print theme("page", $output, t("textareas"));
}
function htmlarea_settings_textarea_save($edit) {
foreach ($edit["status"] as $name => $status) {
db_query("UPDATE {htmlarea} SET status = '%d' WHERE textarea = '%s'", $status, $name);
}
return t("the configuration options have been saved.");
}
function htmlarea_settings_textarea_view() {
$rows = array();
$header = array(t("name"), t("status"));
$result = pager_query("SELECT textarea, status FROM {htmlarea} ORDER BY textarea", 50);
while ($htmlarea = db_fetch_object($result)) {
$rows[] = array($htmlarea->textarea, array("data" => form_checkbox("", "status][$htmlarea->textarea", 1, $htmlarea->status), "align" => "center"));
}
$rows[] = array(array("data" => theme("pager", NULL, 50, 0), "colspan" => 2));
$output .= theme("table", $header, $rows);
$output .= form_submit(t("Save configuration"));
return form($output);
}
function htmlarea_settings_toolbar() {
$edit = $_POST['edit'];
$op = $_POST['op'];
if($edit) {
if ($op == t('Add separator')) {
$_POST['edit']['htmlarea_toolbar'][] = array('data' => 'separator', 'weight' => '-1', 'enabled' => '1');
$_POST['op'] = t('Save configuration');
}
elseif ($op == t('Add space')) {
$_POST['edit']['htmlarea_toolbar'][] = array('data' => 'space', 'weight' => '-1', 'enabled' => '1');
$_POST['op'] = t('Save configuration');
}
elseif ($op == t('Add linebreak')) {
$_POST['edit']['htmlarea_toolbar'][] = array('data' => 'linebreak', 'weight' => '-1', 'enabled' => '1');
$_POST['op'] = t('Save configuration');
}
system_settings_save($edit);
}
$toolbar = _htmlarea_build_toolbar(true);
usort($toolbar, "_htmlarea_sort");
$header = array(array('data' => t('function')), array('data' => t('enabled')), array('data' => t('weight')));
foreach ($toolbar as $k => $v) {
if (!($v['enabled'] == 0 && ($v['data'] == 'space' ||$v['data'] == 'separator' ||$v['data'] == 'linebreak'))) {
$rows[] = array(array('data' => t($v['data']) .form_hidden("htmlarea_toolbar][$k][data", $v['data'])), array('data' => form_checkbox('', "htmlarea_toolbar][$k][enabled", 1, $v['enabled']), 'align' => 'center'), array('data' => form_weight('',"htmlarea_toolbar][$k][weight", $v['weight'], 20)));
}
}
$output.= theme('table', $header, $rows);
$output.= form_submit(t('Add separator'));
$output.= form_submit(t('Add space'));
$output.= form_submit(t('Add linebreak'));
$output = system_settings_form($output);
print theme('page', $output, t('toolbar'));
}
function htmlarea_settings_plugins() {
$edit = $_POST['edit'];
if($edit) {
system_settings_save($edit);
}
// build list of plugins
if (is_dir(_htmlarea_get_jsdir() ."/plugins") && $handle = opendir(_htmlarea_get_jsdir() ."/plugins")) {
$header = array(t("plugin"), t("enable"));
$mask = array('.', '..', 'CVS');
$plugins = variable_get("htmlarea_plugins", array());
while($file = readdir($handle)) {
if (!in_array($file, $mask) && is_dir(_htmlarea_get_jsdir() ."/plugins/$file")) {
$row = array(array("data" => $file, "align" => "left"), array("data" => form_checkbox("", "htmlarea_plugins][$file", 1, $plugins[$file])));
$rows[] = $row;
}
}
closedir($handle);
if ($rows) {
$output.= theme("table", $header, $rows);
}
}
$output = system_settings_form($output);
print theme("page", $output, t("plugins"));
}
function htmlarea_settings_plugins_css() {
$edit = $_POST['edit'];
if($edit) {
foreach ($edit["htmlarea_plugins_css"] as $k => $v) {
if ($v['delete'] == '1' || $v['data'] == '') {
unset($_POST['edit']["htmlarea_plugins_css"][$k]);
}
else {
if ($v['css']) {
foreach ($v['css'] as $ck => $cv) {
if ($cv['delete'] == '1' || $cv['data'] == '') {
unset($_POST['edit']["htmlarea_plugins_css"][$k]['css'][$ck]);
}
unset($_POST['edit']['htmlarea_plugins_css'][$k]['css'][$ck]['delete']);
}
usort($_POST['edit']['htmlarea_plugins_css'][$k]['css'], '_htmlarea_sort');
}
unset($_POST['edit']['htmlarea_plugins_css'][$k]['delete']);
}
}
usort($_POST['edit']['htmlarea_plugins_css'], '_htmlarea_sort');
system_settings_save($edit);
}
$plugins = variable_get("htmlarea_plugins_css", array());
$header = array(array('data' => t('dropbox')), array('data' => t('context')), array('data' => t('weight')), array('data' => t('delete'), 'align' => 'center'));
$header_css = array(array('data' => t('title')), array('data' => t("css")), array('data' => t('weight')), array('data' => t('delete'), 'align' => 'center'));
usort($plugins, "_htmlarea_sort");
foreach ($plugins as $k => $v) {
$rows[] = array(array('data' => form_textfield('', "htmlarea_plugins_css][$k][data", $v['data'], 30, 30)), array('data' => form_textfield('', "htmlarea_plugins_css][$k][context", $v['context'], 30, 30)), array('data' => form_weight('', "htmlarea_plugins_css][$k][weight", $v['weight'])), array('data' => form_checkbox('', "htmlarea_plugins_css][$k][delete", 1, 0), 'align' => 'center'));
$rows_css = array();
if ($v['css']) {
foreach ($v['css'] as $ck => $cv) {
$rows_css[] = array(array('data' => form_textfield('', "htmlarea_plugins_css][$k][css][$ck][data", $cv['data'], 30, 30)), array('data' => form_textfield('', "htmlarea_plugins_css][$k][css][$ck][value", $cv['value'], 30, 30)), array('data' => form_weight('', "htmlarea_plugins_css][$k][css][$ck][weight", $cv['weight'])), array('data' => form_checkbox('', "htmlarea_plugins_css][$k][css][$ck][delete", 1, 0), 'align' => 'center'));
}
}
$ck = count($v['css'])+1;
$rows_css[] = array(array('data' => form_textfield('', "htmlarea_plugins_css][$k][css][$ck][data", "", 30, 30)), array('data' => form_textfield('', "htmlarea_plugins_css][$k][css][$ck][value", '', 30, 30)), array('data' => form_weight('', "htmlarea_plugins_css][$k][css][$ck][weight", 0)), array('data' => ' '));
$output.= form_item($v['data'], theme("table", $header_css, $rows_css));
}
$k = count($plugins)+1;
$rows[] = array(array('data' => form_textfield('', "htmlarea_plugins_css][$k][data", "", 30, 30)), array('data' => form_textfield('', "htmlarea_plugins_css][$k][context", "", 30, 30)), array('data' => form_weight('', "htmlarea_plugins_css][$k][weight")), array('data' => ' '));
$output = form_item('', theme("table", $header, $rows), t("list of
different drop boxes that will be added to the toolbar")) .$output;
print theme("page", system_settings_form($output));
}
function htmlarea_settings_plugins_help($plugin) {
print theme("page", "");
}
function htmlarea_settings_array($arg) {
$edit = $_POST['edit'];
if($edit) {
foreach ($edit["htmlarea_$arg"] as $k => $v) {
if ($v['delete'] == '1' || $v['data'] == '') {
unset($_POST['edit']["htmlarea_$arg"][$k]);
}
}
system_settings_save($edit);
}
switch($arg) {
case "fontnames":
$header_data = t('font name');
$header_value = t('font family');
$page_title = t('font names');
break;
case "fontsize":
$header_data = t('font size');
$header_value = t('size');
$page_title = t('font size');
break;
case "formatblock":
$header_data = t('format block');
$header_value = t('value');
$page_title = t('format block');
break;
}
$header = array(array('data' => $header_data), array('data' => $header_value), array('data' => t('weight')), array('data' => t('delete')));
$data = variable_get("htmlarea_$arg", _htmlarea_defaults($arg));
usort($data, "_htmlarea_sort");
foreach ($data as $k => $v) {
$rows[] = array(array('data' => form_textfield('', "htmlarea_$arg][$k][data", $v['data'], 20, 20)), array('data' => form_textfield('', "htmlarea_$arg][$k][value", $v['value'], 40, 80)), array('data' => form_weight('', "htmlarea_$arg][$k][weight", $v['weight'])), array('data' => form_checkbox('', "htmlarea_$arg][$k][delete", 1, 0), 'align' => 'center'));
}
$k = count($rows);
$rows[] = array(array('data' => form_textfield('', "htmlarea_$arg][$k][data", '', 20, 20)), array('data' => form_textfield('', "htmlarea_$arg][$k][value", '', 40, 80)), array('data' => form_weight('', "htmlarea_$arg][$k][weight", '')), array('data' => ' '));
$output.= theme("table", $header, $rows);
$output = system_settings_form($output);
print theme("page", $output, $page_title);
}
function htmlarea_settings_custom() {
$edit = $_POST['edit'];
if($edit) {
system_settings_save($edit);
}
$output.= form_textarea(t('custom javascript'), 'htmlarea_customjs', variable_get('htmlarea_customjs', ''), 80, 15, t('Enter any javascript that you wish to include in the attacheditor() before the htmlarea is generated.'));
$output = system_settings_form($output);
print theme("page", $output, t("custom javascript"));
}
function htmlarea_nodeapi(&$node, $op, $arg = 0) {
global $htmlarea_codeview;
$htmlarea_codeview = false;
switch($op) {
case "form pre":
if ($node->format == 2) {
$htmlarea_codeview = true;
}
// convert all [image] tags to
tags
/* I really need to do this in htmlarea and not here.
if (module_exist("image") && variable_get("image_filter_enabled", 0) && _htmlarea_is_changed("body")) {
$node->body = image_filter("process", $node->body);
} */
break;
case "validate":
// now we need to convert the
tages to [image:] tags
/* as above
if (module_exist("image") && variable_get("image_filter_enabled", 0) && _htmlarea_is_changed("body")) {
$node->teaser = _htmlarea_reverse_filter_img($node->teaser);
$node->body = _htmlarea_reverse_filter_img($node->body);
} */
break;
}
}
/*
* Internal Functions
*/
/**
* find where the js has been put.
*/
function _htmlarea_get_jsdir() {
static $path;
if ($path) {
return $path;
}
elseif (file_exists("misc/htmlarea/htmlarea.js")) {
$path = "misc/htmlarea";
}
elseif (file_exists(drupal_get_path("module", "htmlarea") ."/xinha/htmlarea.js")) {
$path = drupal_get_path("module", "htmlarea") ."/xinha";
}
elseif (file_exists(drupal_get_path("module", "htmlarea") ."/xinha-latest/htmlarea.js")) {
$path = drupal_get_path("module", "htmlarea") ."/xinha-latest";
}
elseif (file_exists(drupal_get_path("module", "htmlarea") ."/htmlarea/htmlarea.js")) {
$path = drupal_get_path("module", "htmlarea") ."/htmlarea";
}
elseif (file_exists(drupal_get_path("module", "htmlarea") ."/HTMLArea-CVS/htmlarea.js")) {
$path = drupal_get_path("module", "htmlarea") ."/HTMLArea-CVS";
}
else {
$path = false;
}
return $path;
}
function _htmlarea_reverse_filter_img($text) {
global $base_url;
if (preg_match_all("/
/i", $text, $match)) {
foreach($match[0] as $k => $v) {
if (preg_match("/src=\".*?\/image\/view\/(\d+)\?.*?\"/i", $match[1][$k], $m)) {
$repl = "[image:$m[1]";
if (preg_match("/align=\"(.*?)\"/i", $match[1][$k], $m)) {
$repl.= " align=$m[1]";
}
if (preg_match("/hspace=\"(.*?)\"/i", $match[1][$k], $m)) {
$repl.= " hspace=$m[1]";
}
if (preg_match("/vspace=\"(.*?)\"/i", $match[1][$k], $m)) {
$repl.= " vspace=$m[1]";
}
if (preg_match("/border=\"(.*?)\"/i", $match[1][$k], $m)) {
$repl.= " border=$m[1]";
}
if (preg_match("/height=\"(.*?)\"/i", $match[1][$k], $m)) {
$repl.= " height=$m[1]";
}
if (preg_match("/width=\"(.*?)\"/i", $match[1][$k], $m)) {
$repl.= " width=$m[1]";
}
if (!strstr($repl, "width") && !strstr($repl, "height")) {
if (preg_match("/style=\"(.*?)\"/i", $match[1][$k], $m)) {
if (preg_match("/width: (\d+)px/i", $m[1], $s)) {
$repl.= " width=$s[1]";
}
if (preg_match("/height: (\d+)px/i", $m[1], $s)) {
$repl.= " height=$s[1]";
}
}
}
$repl.= "]";
$text = str_replace($match[0][$k], $repl, $text);
}
}
}
return $text;
}
function _htmlarea_defaults($field) {
global $base_url, $htmlarea_codeview;
switch($field) {
case "options":
return array(
array("data" => "fontname", "weight" => "0", "enabled" => "0"),
array("data" => "fontsize", "weight" => "0", "enabled" => "0"),
array("data" => "formatblock", "weight" => "0", "enabled" => "0"),
array("data" => "bold", "weight" => "1", "enabled" => "1"),
array("data" => "italic", "weight" => "1", "enabled" => "1"),
array("data" => "underline", "weight" => "1", "enabled" => "1"),
array("data" => "strikethrough", "weight" => "2", "enabled" => "1"),
array("data" => "separator", "weight" => "2", "enabled" => "1"),
array("data" => "subscript", "weight" => "2", "enabled" => "1"),
array("data" => "superscript", "weight" => "2", "enabled" => "1"),
array("data" => "separator", "weight" => "3", "enabled" => "1"),
array("data" => "copy", "weight" => "4", "enabled" => "0"),
array("data" => "cut", "weight" => "4", "enabled" => "0"),
array("data" => "paste", "weight" => "4", "enabled" => "0"),
array("data" => "undo", "weight" => "4", "enabled" => "0"),
array("data" => "redo", "weight" => "5", "enabled" => "0"),
array("data" => "removeformat", "weight" => "5", "enabled" => "0"),
array("data" => "killword", "weight" => "6", "enabled" => "0"),
array("data" => "linebreak", "weight" => "8", "enabled" => "1"),
array("data" => "justifyleft", "weight" => "6", "enabled" => "1"),
array("data" => "justifycenter", "weight" => "7", "enabled" => "1"),
array("data" => "justifyright", "weight" => "7", "enabled" => "1"),
array("data" => "justifyfull", "weight" => "8", "enabled" => "1"),
array("data" => "separator", "weight" => "3", "enabled" => "1"),
array("data" => "orderedlist", "weight" => "8", "enabled" => "1"),
array("data" => "unorderedlist", "weight" => "8", "enabled" => "1"),
array("data" => "outdent", "weight" => "9", "enabled" => "1"),
array("data" => "indent", "weight" => "10", "enabled" => "1"),
array("data" => "separator", "weight" => "10", "enabled" => "1"),
array("data" => "forecolor", "weight" => "11", "enabled" => "1"),
array("data" => "hilitecolor", "weight" => "11", "enabled" => "1"),
array("data" => "textindicator", "weight" => "11", "enabled" => "1"),
array("data" => "separator", "weight" => "12", "enabled" => "1"),
array("data" => "createlink", "weight" => "13", "enabled" => "1"),
array("data" => "insertimage", "weight" => "13", "enabled" => "0"),
array("data" => "inserttable", "weight" => "13", "enabled" => "1"),
array("data" => "inserthorizontalrule", "weight" => "14", "enabled" => "0"),
array("data" => "htmlmode", "weight" => "15", "enabled" => "1"),
array("data" => "popupeditor", "weight" => "15", "enabled" => "1"),
array("data" => "showhelp", "weight" => "15", "enabled" => "1"),
array("data" => "about", "weight" => "16", "enabled" => "1"));
break;
case "fontnames":
return array(
array('data' => 'Arial', 'value' => 'arial,helvetica,sans-serif', 'weight' => '0'),
array('data' => 'Courier New', 'value' => 'courier new,courier,monospace', 'weight' => '0'),
array('data' => 'Georgia', 'value' => 'georgia,times new roman,times,serif', 'weight' => '0'),
array('data' => 'Tahoma', 'value' => 'tahoma,arial,helvetica,sans-serif', 'weight' => '0'),
array('data' => 'Times New Roman', 'value' => 'times new roman,times,serif', 'weight' => '0'),
array('data' => 'Verdana', 'value' => 'verdana,arial,helvetica,sans-serif', 'weight' => '0'),
array('data' => 'Impact', 'value' => 'impact', 'weight' => '1'),
array('data' => 'WingDings', 'value' => 'wingdings', 'weight' => '1')
);
break;
case "fontsize":
return array(
array('data' => '1 (8 pt)', 'value' => '1', 'weight' => '0'),
array('data' => '2 (10 pt)', 'value' => '2', 'weight' => '0'),
array('data' => '3 (12 pt)', 'value' => '3', 'weight' => '0'),
array('data' => '4 (14 pt)', 'value' => '4', 'weight' => '0'),
array('data' => '5 (18 pt)', 'value' => '5', 'weight' => '0'),
array('data' => '6 (24 pt)', 'value' => '6', 'weight' => '0'),
array('data' => '7 (36 pt)', 'value' => '7', 'weight' => '0')
);
break;
case "formatblock":
return array(
array('data' => 'Heading 1', 'value' => 'h1', 'weight' => '0'),
array('data' => 'Heading 2', 'value' => 'h2', 'weight' => '0'),
array('data' => 'Heading 3', 'value' => 'h3', 'weight' => '0'),
array('data' => 'Heading 4', 'value' => 'h4', 'weight' => '0'),
array('data' => 'Heading 5', 'value' => 'h5', 'weight' => '0'),
array('data' => 'Heading 6', 'value' => 'h6', 'weight' => '0'),
array('data' => 'Normal', 'value' => 'p', 'weight' => '1'),
array('data' => 'Address', 'value' => 'address', 'weight' => '2'),
array('data' => 'Formated', 'value' => 'pre', 'weight' => '2')
);
break;
case "attacheditor":
$lines = array();
$toolbar = _htmlarea_build_toolbar(false);
if (isset($toolbar[0]) && !is_array($toolbar[0])) {
variable_del("htmlarea_toolbar");
$toolbar = variable_get('htmlarea_toolbar', _htmlarea_defaults('options'));
}
foreach ($toolbar as $v) {
if ($v['enabled']) {
if ($v['data'] != 'linebreak' || ($v['data'] == 'linebreak' && variable_get("htmlarea_add_linebreak", false))) {
$buttons[] = "\"" .$v['data'] ."\"";
}
if ($v['data'] == 'linebreak') {
if (isset($buttons)) {
$lines[] = " [ " .implode(", ", $buttons) ." ]";
unset($buttons);
}
}
}
}
if ($buttons) {
$lines[] = " [ " .implode(", ", $buttons) ." ]";
}
$plugins = variable_get("htmlarea_plugins", array());
$fontname = variable_get("htmlarea_fontnames", NULL);
$fontsize = variable_get("htmlarea_fontsize", NULL);
$formatblock = variable_get("htmlarea_formatblock", NULL);
$jssub = array("attacheditor = function(editor, name) {",
" editor = new HTMLArea(\"edit-\"+name);",
/*
* it is required for IE to add the '/' after the
* $base_url otherwise the relative link stuffs up.
*/
" editor.config.baseURL = \"$base_url/\";",
" editor.config.sizeIncludesToolbar = false;",
// " editor.config.editMode = '". ($htmlarea_codeview ? "textmode" : "wysiwyg") . "';",
" editor.config.autofocus = false;",
" editor.config.pageStyle = \"". variable_get("htmlarea_bodystyle", "background-color: #fff; font-family: arial,helvetica,sans-serif; font-size: x-small"). "\";",
" editor.config.toolbar = [");
$jssub[] = implode(",\n", $lines);
$jssub[] = " ];";
if (variable_get("htmlarea_killwordonpaste", false)) {
$jssub[] = " editor.config.killWordOnPaste = true;";
}
if ($fontname) {
$jssub[] = " editor.config.fontname = {";
$jssub[] = " \"— font —\": '',";
usort($fontname, "_htmlarea_sort");
foreach ($fontname as $v) {
$fl[] = " \"" .$v['data'] ."\": '" .$v['value'] ."'";
}
$jssub[] = implode(",\n", $fl);
$jssub[] = " };";
}
if ($fontsize) {
$jssub[] = " editor.config.fontsize = {";
$jssub[] = " \"— size —\": '',";
usort($fontsize, "_htmlarea_sort");
foreach ($fontsize as $v) {
$fs[] = " \"" .$v['data'] ."\": '" .$v['value'] ."'";
}
$jssub[] = implode(",\n", $fs);
$jssub[] = " };";
}
if ($formatblock) {
$jssub[] = " editor.config.formatblock = {";
$jssub[] = " \"— format —\": '',";
usort($formatblock, "_htmlarea_sort");
foreach ($formatblock as $v) {
$fb[] = " \"" .$v['data'] ."\": '" .$v['value'] ."'";
}
$jssub[] = implode(",\n", $fb);
$jssub[] = " };";
}
foreach ($plugins as $plugin => $enabled) {
if ($enabled) {
$jssub = array_merge($jssub, module_invoke_all("htmlarea_plugin", $plugin, "execute"));
}
}
return array_merge($jssub, array(variable_get('htmlarea_customjs', ""), " editor.generate();", "};"));
}
}
function _htmlarea_build_toolbar($cfg = false) {
$toolbar = variable_get("htmlarea_toolbar", NULL);
if (!$toolbar) {
$toolbar = _htmlarea_calc_weights(_htmlarea_defaults('options'));
}
elseif ($cfg) {
$icons = array(); $calcweights = false;
foreach ($toolbar as $item) {
$icons[] = $item['data'];
}
foreach (_htmlarea_calc_weights(_htmlarea_defaults('options')) as $item) {
if ($item['data'] != 'linebreak' &&
$item['data'] != 'space' &&
$item['data'] != 'separator' &&
!in_array($item['data'], $icons)) {
$toolbar[] = $item;
$calcweights = true;
}
}
if ($calcweights) {
$toolbar = _htmlarea_calc_weights($toolbar);
}
}
return $toolbar;
}
function _htmlarea_calc_weights($toolbar, $weight = 0) {
$last = null;
foreach ($toolbar as $k => $v) {
if ($last != null && strcmp($last, $v['data']) > 0) {
$weight++;
}
$last = $v['data'];
$toolbar[$k]['weight'] = $weight;
}
if ($weight > 20) {
$toolbar = _htmlarea_calc_weights($toolbar, $weight - 20);
}
return $toolbar;
}
function _htmlarea_is_changed($name = "") {
global $user;
if (_htmlarea_bad_browser() || (isset($user->htmlarea_isenabled) && $user->htmlarea_isenabled == 0) || (!isset($user->htmlarea_isenabled) && !variable_get("htmlarea_user_default", true)) || !_htmlarea_get_jsdir()) {
return false;
}
if (!user_access('use htmlarea')) { return false; } /* Do not show if not allowed */
$path = _htmlarea_get_path();
if ($name == "") {
// We are being called from the _onload() hook so we need to be quick.
return (db_num_rows(db_query("SELECT textarea FROM {htmlarea} WHERE textarea LIKE '%s.%%' AND status = '1'", $path)) ? true : false);
}
else {
$name = _htmlarea_parse_name($name);
$path .= ".". $name;
$result = db_query("SELECT status FROM {htmlarea} WHERE textarea = '%s'", $path);
if (db_num_rows($result)) {
$t = db_fetch_object($result);
return $t->status;
}
else {
// This textarea doesn't exist, insert it into the database
db_query("INSERT INTO {htmlarea} (textarea, status) VALUES ('%s', %d)", $path, variable_get("htmlarea_default", true));
watchdog("special", "created unique textarea '$path' from '" .$_GET["q"] ."'");
return variable_get("htmlarea_default", true);
}
}
}
function _htmlarea_get_path() {
$path = $_GET["q"];
$path = explode("/", $path);
foreach ($path as $k => $v) {
if (is_numeric($path[$k])) {
unset($path[$k]);
}
}
$path = implode("/", $path);
return $path;
}
function _htmlarea_parse_name($name) {
if ($pos = strpos($name, ']')) {
$name = substr($name, 0, $pos);
}
return $name;
}
function _htmlarea_sort($a, $b) {
return ($a['weight'] > $b['weight'] ? 1 : ($a['weight'] < $b['weight'] ? -1 : (strcmp($a['data'], $b['data']))));
}
// This is a temporary function to get around a bug in htmlarea 3.0beta
// which will crash IE5.00 browsers
function _htmlarea_bad_browser() {
if (strpos($_SERVER['HTTP_USER_AGENT'], "Safari")) {
return true;
}
if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE 5.0")) {
return true;
}
return false;
}
?>