Skip to content
Snippets Groups Projects
Commit 1f998ebf authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

[gh-307] Merging test into staging -c1486 -c1488

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@1493 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent 4c23c3bc
No related branches found
No related tags found
No related merge requests found
...@@ -88,17 +88,17 @@ function unl_get_site_settings($uri) { ...@@ -88,17 +88,17 @@ function unl_get_site_settings($uri) {
if (!is_readable($settings_file)) { if (!is_readable($settings_file)) {
throw new Exception('No settings.php exists for site at ' . $uri); throw new Exception('No settings.php exists for site at ' . $uri);
} }
if (is_readable(DRUPAL_ROOT . '/sites/all/settings.php')) { if (is_readable(DRUPAL_ROOT . '/sites/all/settings.php')) {
require DRUPAL_ROOT . '/sites/all/settings.php'; require DRUPAL_ROOT . '/sites/all/settings.php';
} }
require $settings_file; require $settings_file;
unset($uri); unset($uri);
unset($settings_file); unset($settings_file);
return get_defined_vars(); return get_defined_vars();
} }
/** /**
* Custom function that returns TRUE if the given table is shared with another site. * Custom function that returns TRUE if the given table is shared with another site.
...@@ -114,22 +114,65 @@ function unl_table_is_shared($table_name) { ...@@ -114,22 +114,65 @@ function unl_table_is_shared($table_name) {
return FALSE; return FALSE;
} }
/**
* Custom function that formats a string of HTML using Tidy
* @param string $string
*/
function unl_tidy($string) {
if (class_exists('Tidy') && variable_get('unl_tidy')) {
$tidy = new Tidy();
// Tidy options: http://tidy.sourceforge.net/docs/quickref.html
$options = array(
// HTML, XHTML, XML Options
'doctype' => 'omit',
'new-blocklevel-tags' => 'article,aside,header,footer,section,nav,hgroup,address,figure,figcaption,output',
'new-inline-tags' => 'video,audio,canvas,ruby,rt,rp,time,code,kbd,samp,var,mark,bdi,bdo,wbr,details,datalist,source,summary',
'output-xhtml' => true,
'show-body-only' => true,
// Pretty Print
'indent' => true,
'indent-spaces' => 2,
'vertical-space' => false,
'wrap' => 140,
'wrap-attributes' => false,
// Misc
'force-output' => true,
'quiet' => true,
'tidy-mark' => false,
);
// Prevent Tidy from trying to move <script> to the head if it is the first thing
if (strtolower(substr(trim($string), 0, 7)) == '<script' || substr(trim($string), 0, 4) == '<!--') {
$string = "&nbsp; <!-- Tidy: Start field with something other than script or comment to remove this -->\n" . $string;
}
$tidy->parseString($string, $options, 'utf8');
if ($tidy->cleanRepair()) {
return $tidy;
}
}
return $string;
}
/** /**
* A shared-table safe method that returns TRUE if the user is a member of the super-admin role. * A shared-table safe method that returns TRUE if the user is a member of the super-admin role.
*/ */
function unl_user_is_administrator() { function unl_user_is_administrator() {
$user = $GLOBALS['user']; $user = $GLOBALS['user'];
// If the role table is shared, use parent site's user_admin role, otherwise use the local value. // If the role table is shared, use parent site's user_admin role, otherwise use the local value.
if (unl_table_is_shared('role')) { if (unl_table_is_shared('role')) {
$admin_role_id = unl_shared_variable_get('user_admin_role'); $admin_role_id = unl_shared_variable_get('user_admin_role');
} else {
$admin_role_id = variable_get('user_admin_role');
} }
else {
$admin_role_id = variable_get('user_admin_role');
}
if ($user && in_array($admin_role_id, array_keys($user->roles))) { if ($user && in_array($admin_role_id, array_keys($user->roles))) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
...@@ -4,24 +4,33 @@ function unl_config($form, &$form_state) { ...@@ -4,24 +4,33 @@ function unl_config($form, &$form_state) {
$form['root'] = array( $form['root'] = array(
'#tree' => TRUE, '#tree' => TRUE,
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => 'UNL Settings', '#title' => 'UNL Settings',
); );
$form['root']['unl_use_base_tag'] = array( $form['root']['unl_use_base_tag'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => 'Use Base Tag', '#title' => 'Use base tag',
'#description' => 'Insert the HTML Base tag in the head of all pages on this site.', '#description' => 'Insert the HTML Base tag in the head of all pages on this site.',
'#default_value' => variable_get('unl_use_base_tag', TRUE), '#default_value' => variable_get('unl_use_base_tag', TRUE),
); );
$form['root']['unl_clean_file_url'] = array( $form['root']['unl_clean_file_url'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => 'Clean File URLs', '#title' => 'Clean file URLs',
'#description' => 'Enable this once mod_rewrite has been set up to support clean file URLs', '#description' => 'Enable this once mod_rewrite has been set up to support clean file URLs.',
'#default_value' => variable_get('unl_clean_file_url'), '#default_value' => variable_get('unl_clean_file_url'),
); );
if (class_exists('Tidy')) {
$form['root']['unl_tidy'] = array(
'#type' => 'checkbox',
'#title' => 'Clean up text area HTML',
'#description' => 'Tidy will be used to process HTML in text areas on the node edit form.',
'#default_value' => variable_get('unl_tidy'),
);
}
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => 'Update', '#value' => 'Update',
...@@ -33,4 +42,7 @@ function unl_config($form, &$form_state) { ...@@ -33,4 +42,7 @@ function unl_config($form, &$form_state) {
function unl_config_submit($form, &$form_state) { function unl_config_submit($form, &$form_state) {
variable_set('unl_use_base_tag', $form_state['values']['root']['unl_use_base_tag']); variable_set('unl_use_base_tag', $form_state['values']['root']['unl_use_base_tag']);
variable_set('unl_clean_file_url', $form_state['values']['root']['unl_clean_file_url']); variable_set('unl_clean_file_url', $form_state['values']['root']['unl_clean_file_url']);
if (class_exists('Tidy')) {
variable_set('unl_tidy', $form_state['values']['root']['unl_tidy']);
}
} }
...@@ -172,6 +172,23 @@ function unl_node_prepare($node) { ...@@ -172,6 +172,23 @@ function unl_node_prepare($node) {
$node->menu['expanded'] = 1; $node->menu['expanded'] = 1;
} }
/**
* Implementation of hook_node_presave().
*/
function unl_node_presave($node) {
// Tidy html in fields that are text areas
foreach(field_info_instances('node', $node->type) as $field) {
if (substr($field['widget']['type'], 0, 13) == 'text_textarea') {
$field_name = $field['field_name'];
$lang = $node->language;
$node_field = $node->$field_name;
$tidied_value = unl_tidy($node_field[$lang][0]['value']);
$node_field[$lang][0]['value'] = $tidied_value;
$node->$field_name = $node_field;
}
}
}
/** /**
* Implementation of hook_wywiwyg_plugin() found in wysiwyg.api.php * Implementation of hook_wywiwyg_plugin() found in wysiwyg.api.php
*/ */
...@@ -610,15 +627,6 @@ function unl_form_alter(&$form, $form_state, $form_id) { ...@@ -610,15 +627,6 @@ function unl_form_alter(&$form, $form_state, $form_id) {
$admin_role_id = unl_shared_variable_get('user_admin_role', -1); $admin_role_id = unl_shared_variable_get('user_admin_role', -1);
if (!in_array($admin_role_id, array_keys($GLOBALS['user']->roles))) { if (!in_array($admin_role_id, array_keys($GLOBALS['user']->roles))) {
switch ($form_id) { switch ($form_id) {
// Don't allow editing of non-custom content types on admin/structure/types, i.e. don't allow subsites to edit the content types coming from modules or the UNL shared content types
// case 'node_type_form' :
// case 'field_ui_field_overview_form' :
// case 'field_ui_display_overview_form' :
// if (!$form['custom']['#value']) {
// drupal_access_denied();
// exit;
// }
// break;
// Add additional validation on admin/people/permissions/roles/edit/% // Add additional validation on admin/people/permissions/roles/edit/%
case 'user_admin_role' : case 'user_admin_role' :
$form['#validate'][] = 'unl_user_admin_role_validate'; $form['#validate'][] = 'unl_user_admin_role_validate';
...@@ -700,18 +708,22 @@ function unl_form_alter(&$form, $form_state, $form_id) { ...@@ -700,18 +708,22 @@ function unl_form_alter(&$form, $form_state, $form_id) {
} }
} }
/** // Node Edit Form
* On the node edit form, hide the "Provide a menu link" checkbox since we'll if (isset($form['#node_edit_form']) && $form['#node_edit_form']) {
* be using the menu to build a site hierarchy. Instead, add a button that will // Tidy existing html in fields that are text areas
* determine whether or not the menu link is visible or not. foreach(field_info_instances($form['#entity_type'], $form['#bundle']) as $field) {
*/ if (substr($field['widget']['type'], 0, 13) == 'text_textarea') {
if (substr($form_id, -10) == '_node_form') { $field_name = $field['field_name'];
$form['menu']['#title'] = 'Site hierarchy'; $form[$field_name]['und'][0]['#default_value'] = unl_tidy($form[$field_name]['und'][0]['#default_value']);
}
}
// Hide the "Provide a menu link" checkbox since we'll be using the menu to build a site hierarchy.
// Instead, add a button that will determine whether or not the menu link is visible.
$form['menu']['#title'] = 'Site hierarchy';
$form['menu']['enabled']['#default_value'] = TRUE; $form['menu']['enabled']['#default_value'] = TRUE;
$form['menu']['enabled']['#prefix'] = '<div style="display: none;">'; $form['menu']['enabled']['#prefix'] = '<div style="display: none;">';
$form['menu']['enabled']['#suffix'] = '</div>'; $form['menu']['enabled']['#suffix'] = '</div>';
$form['menu']['link']['link_title']['#required'] = TRUE; $form['menu']['link']['link_title']['#required'] = TRUE;
$mlid = $form['menu']['link']['mlid']['#value']; $mlid = $form['menu']['link']['mlid']['#value'];
...@@ -731,7 +743,7 @@ function unl_form_alter(&$form, $form_state, $form_id) { ...@@ -731,7 +743,7 @@ function unl_form_alter(&$form, $form_state, $form_id) {
$form['actions']['submit']['#submit'][] = 'unl_node_form_submit'; $form['actions']['submit']['#submit'][] = 'unl_node_form_submit';
// Also turn on revisioning by default // Also turn on revisioning
$form['revision_information']['revision']['#default_value'] = TRUE; $form['revision_information']['revision']['#default_value'] = TRUE;
unset($form['revision_information']['revision']['#states']); unset($form['revision_information']['revision']['#states']);
} }
...@@ -947,7 +959,6 @@ function _unl_cron_import_wdn_registry_sites() { ...@@ -947,7 +959,6 @@ function _unl_cron_import_wdn_registry_sites() {
); );
} }
foreach ($sites_to_create as $wdn_site_id => $site_to_create) { foreach ($sites_to_create as $wdn_site_id => $site_to_create) {
try { try {
db_insert('unl_sites')->fields($site_to_create)->execute(); db_insert('unl_sites')->fields($site_to_create)->execute();
...@@ -1223,7 +1234,7 @@ function unl_still_alive() { ...@@ -1223,7 +1234,7 @@ function unl_still_alive() {
/** /**
* Custom function to return the current admin theme for use with hook_menu_alter(). * Custom function to return the current admin theme for use with hook_menu_alter().
*/ */
function _unl_get_admin_theme(){ function _unl_get_admin_theme() {
return variable_get('admin_theme', '0'); return variable_get('admin_theme', '0');
} }
...@@ -1362,8 +1373,7 @@ function unl_block_view($delta = '') { ...@@ -1362,8 +1373,7 @@ function unl_block_view($delta = '') {
* Implements hook_block_view('my_sites'). * Implements hook_block_view('my_sites').
* Displays the list of sites/roles for the current user. * Displays the list of sites/roles for the current user.
*/ */
function unl_block_view_my_sites() function unl_block_view_my_sites() {
{
if (user_is_anonymous()) { if (user_is_anonymous()) {
return array(); return array();
} }
...@@ -1403,8 +1413,7 @@ class UnlPublicStreamWrapper extends DrupalPublicStreamWrapper { ...@@ -1403,8 +1413,7 @@ class UnlPublicStreamWrapper extends DrupalPublicStreamWrapper {
* Implements hook_query_alter() * Implements hook_query_alter()
* Currently used to filter out users with no roles at "admin/people". * Currently used to filter out users with no roles at "admin/people".
*/ */
function unl_query_alter(QueryAlterableInterface $query) function unl_query_alter(QueryAlterableInterface $query) {
{
// If this query is coming from the "People" admin page // If this query is coming from the "People" admin page
if (current_path() == 'admin/people') { if (current_path() == 'admin/people') {
// Find the prefix for the "users" table // Find the prefix for the "users" table
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment