name, 'admin/settings/signwriter/profile/'. $profile->id); $rows[] = array( 'name' => l(theme_signwriter_text($profile->name, $profile, array('style' => 'vertical-align:middle')), 'admin/settings/signwriter/profile/'. $profile->id, array('html' => TRUE)), 'edit' => l(t('edit'), 'admin/settings/signwriter/profile/'. $profile->id), 'delete' => l(t('delete'), "admin/settings/signwriter/profile/$profile->id/delete")); } if (empty($rows)) { $rows[] = array(array('data' => t('No profiles'), 'colspan' => '3', 'class' => 'message')); } $rows[] = array(array('data' => l(t('Add a profile'), 'admin/settings/signwriter/profile/add'), 'colspan' => '3')); $header = array(array('data' => t('Profiles'), 'colspan' => '3')); $form[$formtag] = array( '#value' => theme('table', $header, $rows), ); } /** * Deletes a signwriter profile. * * @param $profile * The profile object to delete. */ function _signwriter_delete_profile($profile) { if (db_query('DELETE FROM {signwriter} WHERE id = %d', $profile->id)) { drupal_set_message(t("Deleted the '@name' profile.", array('@name' => $profile->name))); } else { drupal_set_message(t("Deleting the '@name' profile failed!", array('@name' => $profile->name)), 'warning'); } } /** * Save a profile or update a profile in the database. * * @param $profile * The profile object to save */ function signwriter_save_profile($profile, $update) { $s = drupal_write_record('signwriter', $profile, $update ? "id" : NULL); // drupal_set_message('signwriter_save_profile::drupal_write_record =
'.print_r($s, TRUE).''); // drupal_set_message('signwriter_save_profile::$profile =
'.print_r($profile, TRUE).''); return $profile->id; } /** * adds the signwriter menuprofile to the settings form */ function _signwriter_add_menuprofiles_to_form(&$form, $formtag = "menuprofiles") { $profiles = signwriter_load_menuprofiles(); $rows = array(); foreach ($profiles as $profile) { $rows[] = array( 'name' => $profile->name, //'sample' => theme_signwriter_text($profile->name, $profile, array('style' => 'vertical-align:middle')), //'sample' => _signwritermenu_overview($profile), 'sample' => $profile->name, 'edit' => l(t('edit'), 'admin/settings/signwriter/menuprofile/'. $profile->id), 'delete' => l(t('delete'), "admin/settings/signwriter/menuprofile/$profile->id/delete") ); } if (empty($rows)) { $rows[] = array(array('data' => t('No profiles'), 'colspan' => '4', 'class' => 'message')); } $rows[] = array( array('data' => l(t('Add a menu profile'), 'admin/settings/signwriter/menuprofile/add'), 'colspan' => '4' ), ); $header = array( 'name' => t('Profile'), 'sample' => t('Sample'), 'actions' => t('Actions'), //'actions2' => "", ); $form[$formtag] = array( '#value' => theme('table', $header, $rows) ); } /** * Deletes a signwriter profile. * * @param $profile * The profile object to delete. */ function _signwriter_delete_menuprofile($profile) { if (db_query("DELETE FROM {signwriter_menu} WHERE id = %d", $profile->id)) { drupal_set_message(t("Deleted the '@name' profile.", array('@name' => $profile->name))); } else { drupal_set_message(t("Deleting the '@name' profile failed!", array('@name' => $profile->name)), 'warning'); } } /** * Save a profile or update a profile in the database. * * @param $profile * The profile object to save */ function _signwriter_save_menuprofile($profile, $update) { $values = serialize($profile->data); if (empty($profile->id)) { db_query("INSERT INTO {signwriter_menu} (name,data) VALUES ('%s','%s')", $profile->name, $values); return db_result(db_query("SELECT LAST_INSERT_ID()")); } else { db_query("UPDATE {signwriter_menu} SET name='%s', data='%s' WHERE id=%d", $profile->name, $values, $profile->id); return $profile->id; } } /** * The main admin>>settings>>signwriter page */ function signwriter_settings_form($form_state) { $form = array(); if (!function_exists('imagetypes')) { $form['error'] = array( '#value' => theme('page', t('It appears that you do not have the GD image library installed. GD is enabled by default in PHP >= 4.3, but can be enabled at compile time in earlier versions. If your php installation is on windows, try uncommenting the line which reads \'extension=php_gd2.dll\' in your php.ini. For more information see the !phpimagedoc', array('!phpimagedoc' => l('PHP Image library documentation.', 'http://php.net/image')))), ); return $form; } else { _signwriter_add_profiles_to_form($form); $form['paths'] = array('#type' => 'fieldset', '#title' => t('Paths'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['paths']['signwriter_cachedir'] = array( '#type' => 'textfield', '#title' => t('Cache Directory'), '#description' => t('This is the directory that signwriter will store its generated images in. It must be publicly accessible; the default is \'files/signwriter-cache\'. Make sure that your webserver process is able to create and write to this directory. Files can be deleted from this directory at any time.'), '#default_value' => variable_get('signwriter_cachedir', file_directory_path() .'/signwriter'), ); $form['paths']['signwriter_cachecleanperiod'] = array( '#type' => 'radios', '#title' => t('Cache cleanup period'), '#description' => t('Choose how often the images in the signwriter cache directory should be purged.'), '#default_value' => variable_get('signwriter_cachecleanperiod', '100 years'), '#options' => array('1 day' => t('Daily'), '1 week' => t('Weekly'), '100 years' => t('Never')), ); $form['paths']['signwriter_cachecleannow'] = array( '#type' => 'submit', '#value' => t('Clean signwriter cache now'), ); $form['paths']['signwriter_fontpath'] = array( '#type' => 'textfield', '#title' => t('Font Search Path'), '#description' => t('Add a : separated list of directories to search for your font files. Signwriter will automatically search the drupal directory, your files directory, and your current theme\'s directory.'), '#default_value' => variable_get('signwriter_fontpath', ''), ); $form['pages'] = array('#type' => 'fieldset', '#title' => t('Pages'), '#collapsible' => TRUE, '#collapsed' => FALSE); $options = array(t('Use on every page except the listed pages.'), t('Use on only the listed pages.')); $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '
TRUE
(PHP-mode, experts only).');
$description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => ''));
}
$form['pages']['signwriter_pages_type'] = array(
'#type' => 'radios',
'#title' => t('Use signwriter on specific pages'),
'#options' => $options,
'#default_value' => variable_get('signwriter_pages_type', 0),
);
$form['pages']['signwriter_pages_list'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
'#default_value' => variable_get('signwriter_pages_list', ''),
'#description' => $description,
);
$form['signwriter_specialcharnotice'] = array(
'#type' => 'checkbox',
'#title' => t('Special character notice'),
'#description' => t('Each time time a string is to be rendered it is checked for special characters outside the ASCII character set. If any are found and the current user has the permission to configure signwriter, output a notice how to allow these characters.'),
'#default_value' => variable_get('signwriter_specialcharnotice', TRUE),
);
$titleoptions = array('disabled' => t('Disabled (headers unchanged)'));
$profiles = signwriter_load_profiles();
foreach ($profiles as $profile) {
$titleoptions[$profile->id] = theme_signwriter_text($profile->name, $profile, array('style' => 'vertical-align:middle'));
}
$form['hooks'] = array(
'#type' => 'fieldset',
'#title' => t('Template Hooks'),
'#description' => t('Choose a profile for each specific signwriter_preprocess hook to replace normal /text) headers with signwritten versions.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
$form['hooks']['signwriter_pagehookprofile'] = array(
'#type' => 'radios',
'#title' => t('Page titles'),
'#default_value' => variable_get('signwriter_pagehookprofile', 'disabled'),
'#options' => $titleoptions,
);
$form['hooks']['signwriter_blockhookprofile'] = array(
'#type' => 'radios',
'#title' => t('Block titles'),
'#default_value' => variable_get('signwriter_blockhookprofile', 'disabled'),
'#options' => $titleoptions,
);
if (module_exists('panels')) {
$form['hooks']['signwriter_panelshooktitleprofile'] = array(
'#type' => 'radios',
'#title' => t('Panels titles'),
'#default_value' => variable_get('signwriter_panelshooktitleprofile', 'disabled'),
'#options' => $titleoptions,
);
}
//.... Menu related settings
_signwriter_add_menuprofiles_to_form($form);
//.... Build profile popup menu
$menuprofiles = signwriter_load_menuprofiles();
$menuoptions = array(false => t("Standard (not signwriter enhanced)"));
foreach ($menuprofiles as $menuprofile)
$menuoptions[$menuprofile->id] = $menuprofile->name;
//.... Build settings for earch menu
$form['signwritermenu'] = array(
'#type' => 'fieldset',
'#title' => t('Menu Settings'),
'#description' => t('Choose a profile for each menu that should use Signwritermenu for drawing menu items.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
$form['signwritermenu']['signwriter_menulevels'] = array(
'#type' => 'textfield',
'#title' => t('Maximum Menu Levels'),
'#description' => t('Number of menu levels handled by Signwriter Menu'),
'#default_value' => variable_get('signwriter_menulevels', '3'),
'#size' => 2,
);
$menusettings = variable_get("signwriter_menusettings", array());
$menus = menu_get_menus();
foreach ($menus as $key => $title) {
$form['signwritermenu']['swm_'.$key] = array(
'#type' => 'select',
'#title' => $title,
'#descripion' => t(""),
'#default_value' => $menusettings[$key],
'#options' => $menuoptions,
);
}
$form = system_settings_form($form);
$form['#submit'] = array('signwriter_settings_form_submit');
return $form;
}
}
function signwriter_settings_form_validate($form, &$form_state) {
if ($form_state['clicked_button']['#value'] == t('Clean signwriter cache now')) {
signwriter_cron(TRUE);
$form_state['rebuild'] = TRUE;
}
}
/**
* Submit signwritermenu settings
*/
function signwriter_settings_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
$menus = menu_get_menus();
$menusettings = array();
foreach ($menus as $key => $title) {
$value = $form_state['values']['swm_'.$key];
if ($value) {
$menusettings[$key] = intval($value);
}
unset($form_state['values']['swm_'.$key]);
}
unset($form_state['values']['signwriter_cachecleannow']);
if ($op == t('Reset to defaults')) {
variable_del('signwriter_menusettings');
} else {
variable_set('signwriter_menusettings', $menusettings);
}
system_settings_form_submit($form, $form_state);
cache_clear_all();
drupal_rebuild_theme_registry();
}
function _signwriter_profile_font($p, $fontoptions, $state = "") {
$fieldset = array();
$fieldset['fontfile'] = array(
'#type' => 'select',
'#title' => t('Font'),
'#description' => t('These fonts have been found on the host system. The directories searched for fonts were @fontsearch. To change the font search path, go to !signwriter_admin.', array('@fontsearch' => implode(', ', _signwriter_get_fontpaths()), '!signwriter_admin' => l('the signwriter settings page', 'admin/settings/signwriter'))),
'#options' => $fontoptions,
'#default_value' => _signwriter_get_val($p, $state.'fontfile'),
'#prefix' => '' : ' | ||
', $single ? ' | ',' | '); _signwriter_profile_onestate($v3,'',' | '); $form[$fieldset]['hov_'.$key] = $v2; $form[$fieldset]['act_'.$key] = $v3; } if ($desc) { $form[$fieldset][$key.'_desc'] = array( '#value' => $desc, '#prefix' => '
', '#suffix' => ' |
/<h.*?>.*?<\/h.*?>/
. To replace only h1 headings, use /<h1.*>.*?<\/h1>/
. To define a custom pseudo-html tag (such as <signwriter>), use: /<signwriter>.*?<\/signwriter>/
", array('@input-formats-url' => url('admin/settings/filters'), '%inputformats' => 'Administer >> Site configuration >> Input formats')),
'#size' => 20,
);
$form['save'] = array('#type' => 'submit', '#value' => t('Save'));
$form['submit'] = array('#type' => 'submit', '#value' => t('Save and edit'));
// Don't add the delete button if they are on the add new profile page
// Otherwise clicking the button will return page not found due to there not being a profile to delete.
if ($p) {
$form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
}
return $form;
}
function signwriter_profile_form_validate($form, $form_state) {
$shadow_error = t('If using a drop shadow, the Shadow X Offset and Shadow Y Offset values must not both be zero.');
if ($form_state['values']['drop_shadow']) {
if ($form_state['values']['shadow_xoffset'] == 0 && $form_state['values']['shadow_yoffset'] == 0) {
form_set_error('shadow_xoffset', $shadow_error);
form_set_error('shadow_yoffset', $shadow_error);
}
}
if (!is_numeric($form_state['values']['fontsize']) && $form_state['values']['fontsize']) {
form_set_error('fontsize', 'Font size must be numeric.');
}
/*
if (!is_numeric($form_state['values']['angle']) && $form_state['values']['angle']) {
form_set_error('angle', 'Angle must be numeric.');
}
*/
}
function signwriter_profile_form_submit($form, &$form_state) {
$profile = (object)$form_state['values'];
// To allow for font size default of 20.
if (!$profile->fontsize) {
$profile->fontsize = 20;
}
/*
if (!$profile->angle) {
$profile->angle = 0;
}
*/
$clicked_button = $form_state['clicked_button']['#value'];
if ($clicked_button == t('Delete')) {
$form_state['redirect'] = 'admin/settings/signwriter/profile/'. $profile->id .'/delete';
}
else {
$id = signwriter_save_profile($profile, $form_state['values']['id']);
$message = t("Profile '@name' saved.", array('@name' => $profile->name));
//drupal_set_message(theme('signwriter_text', $message, $profile));
drupal_set_message($message);
$form_state['redirect'] = ($clicked_button == 'Save and edit') ? 'admin/settings/signwriter/profile/'. $id : 'admin/settings/signwriter';
}
}
/**
* Ask for user confirmation before deleting a profile.
*
* @param $profile
* The profile object to delete.
*/
function signwriter_confirm_delete_profile_form(&$form_state, $profile) {
$form = array();
$form['id'] = array('#type' => 'value', '#value' => $profile->id);
return confirm_form($form,
t("Are you sure you want to delete the '%title' profile?", array('%title' => $profile->name)),
'admin/settings/signwriter',
t('Deleting a profile cannot be undone.'),
t('Delete'),
t('Cancel'));
}
/**
* Form_submit function for profile deletion.
* Executes deletion and returns the user to the main signwriter settings page.
*/
function signwriter_confirm_delete_profile_form_submit($form, &$form_state) {
$profile = signwriter_load_profile($form_state['values']['id']);
_signwriter_delete_profile($profile);
$form_state['redirect'] = 'admin/settings/signwriter';
}
/**
* Edit signwritermenu profile
*/
function signwriter_menuprofile_form(&$form_state, $p = NULL) {
// drupal_add_css('misc/farbtastic/farbtastic.css', 'module', 'all', FALSE);
// drupal_add_js('misc/farbtastic/farbtastic.js');
// drupal_add_js(drupal_get_path('module', 'signwritermenu') .'/color.js');
//.... Build signwriter popup menu and show overview
$swprofiles = signwriter_load_profiles();
$rows = array();
$menuoptions = array(false => t("Unused"));
foreach ($swprofiles as $swprofile) {
$menuoptions[$swprofile->id] = $swprofile->name;
$rows[] = array('name' => theme_signwriter_text($swprofile->name, $swprofile, array('style' => 'vertical-align:middle')));
}
$header = array(array('data' => t('Signwriter samples')));
$profileid = _signwriter_get_val($p, 'id');
$profilename = _signwriter_get_val($p, 'name');
$values = _signwriter_get_val($p, 'data');
drupal_set_title(t('Editing signwritermenu profile @profilename', array('@profilename' => $profilename)));
$form = array();
$form['samples'] = array(
'#value' => theme('table', $header, $rows),
);
$form['id'] = array(
'#type' => 'value',
'#value' => $profileid
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Profile Name'),
'#required' => TRUE,
'#default_value' => $profilename,
'#size' => 40,
);
$levels = variable_get('signwriter_menulevels', '3');
for ($i=1;$i<=$levels;$i++)
{
$form['set'.$i] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#title' => t('Settings for Menu Items level '.$i)
);
$form['set'.$i]['item-'.$i] = array(
'#type' => 'select',
'#title' => t("Signwriter Profile"),
'#descripion' => t("Signwriter profile to be used to display regular menu items"),
'#default_value' => $values[$i],
'#options' => $menuoptions,
);
}
$form['save'] = array('#type' => 'submit', '#value' => t('Save'));
$form['submit'] = array('#type' => 'submit', '#value' => t('Save and edit'));
// Don't add the delete button if they are on the add new profile page
// Otherwise clicking the button will return page not found due to there not being a profile to delete.
if ($p) {
$form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
}
return $form;
}
function signwriter_menuprofile_form_submit($form, &$form_state) {
$profile->id = $form_state['values']['id'];
$profile->name = $form_state['values']['name'];
$profile->data = array();
$levels = variable_get('signwriter_menulevels', '3');
for ($i=1;$i<=$levels;$i++) {
$item = intval($form_state['values']['item-'.$i]);
$profile->data[$i] = $item;
}
$clicked_button = $form_state['clicked_button']['#value'];
if ($clicked_button == t('Delete')) {
$form_state['redirect'] = 'admin/settings/signwriter/menuprofile/'. $profile->id .'/delete';
}
else {
$id = _signwriter_save_menuprofile($profile, $form_state['values']['id']);
$message = t("Profile '@name' saved.", array('@name' => $profile->name));
$form_state['redirect'] = ($clicked_button == 'Save and edit') ? 'admin/settings/signwriter/menuprofile/'. $id : 'admin/settings/signwriter';
}
}
/**
* Ask for user confirmation before deleting a profile.
*
* @param $profile
* The profile object to delete.
*/
function signwriter_confirm_delete_menuprofile_form(&$form_state, $profile) {
$form = array();
$form['id'] = array('#type' => 'value', '#value' => $profile->id);
return confirm_form($form,
t("Are you sure you want to delete the '%title' profile?", array('%title' => $profile->name)),
'admin/settings/signwriter',
t('Deleting a profile cannot be undone.'),
t('Delete'),
t('Cancel'));
}
/**
* Form_submit function for profile deletion.
* Executes deletion and returns the user to the main signwriter settings page.
*/
function signwriter_confirm_delete_menuprofile_form_submit($form, &$form_state) {
$profile = signwriter_load_menuprofile($form_state['values']['id']);
_signwriter_delete_menuprofile($profile);
$form_state['redirect'] = 'admin/settings/signwriter';
}