Commit d04e5103 authored by dragonwize's avatar dragonwize
Browse files

Cleaned #372186 by sun: Code cleanup and PHP4 compatibility

parent 168716da
<?php
// $Id$
/**
* @file
* Default theme implementation to configure format manager filter admin page
* Default theme implementation to configure format manager filter admin page.
*
* Available variables:
* - $form_submit: Form submit button.
......
; $Id$
name = Better Formats
description = "Enhances the core input format system by managing input format defaults and settings."
core = 6.x
;dependencies[] =
;package =
\ No newline at end of file
......@@ -58,16 +58,16 @@ function better_formats_schema() {
* Implementation of hook_install().
*/
function better_formats_install() {
// create tables
// Create tables.
drupal_install_schema('better_formats');
// increase module weight to prevent compatibility issues
// Increase module weight to prevent compatibility issues.
$sql = "UPDATE {system}
SET weight = 100
WHERE name = 'better_formats'";
db_query($sql);
// insert defaults
// Insert format defaults.
$roles = user_roles();
$sql = "INSERT INTO {better_formats_defaults}
VALUES (%d, '%s', %d, %d, %d)";
......@@ -76,9 +76,9 @@ function better_formats_install() {
db_query($sql, $rid, 'comment', 0, 1, 0);
}
// default perms to be like core defaults
// Set default perms to be like core defaults.
$default_perms = ',show format selection,show format tips,show more format tips link,collapsible format selection,collapse format fieldset by default';
// get current core perms
// Get current core perms.
$sql = "SELECT *
FROM {permission}
WHERE rid IN (1,2)";
......@@ -87,7 +87,7 @@ function better_formats_install() {
while ($row = db_fetch_object($result)) {
$role_perms[] = $row;
}
// add perms to core roles (anonymous user, authenticated user)
// Add perms to core roles (anonymous user, authenticated user).
foreach ($role_perms as $perms) {
$sql = "UPDATE {permission}
SET perm = '%s'
......@@ -100,8 +100,10 @@ function better_formats_install() {
* Implementation of hook_uninstall().
*/
function better_formats_uninstall() {
// Remove tables.
drupal_uninstall_schema('better_formats');
// delete settings variables from varible table
// Delete settings from varible table.
$sql = "DELETE FROM {variable}
WHERE name LIKE 'better_formats%'";
db_query($sql);
......
This diff is collapsed.
......@@ -10,7 +10,7 @@
/**
* Builds the form for the filters admin.
*
* @return array
* @return
* FAPI array
*
* @see better_formats_defaults_admin_form_validate()
......@@ -20,7 +20,7 @@ function better_formats_defaults_admin_form() {
$form = array(
'#tree' => TRUE,
);
$nform = better_formats_get_role_default_fields('node');
$cform = better_formats_get_role_default_fields('comment');
$form = array_merge($form, $nform, $cform);
......@@ -44,18 +44,18 @@ function better_formats_defaults_admin_form_validate($form, &$form_state) {
foreach ($formats as $fid => $format) {
$roles[$fid] = explode(',', $format->roles);
}
// get roles that have administer filters permission
// Get roles that have administer filters permission.
$admin_roles = better_formats_get_filter_admin_roles();
foreach ($form_state['values'] as $key => $values) {
if (strpos($key, 'node-') === 0 || strpos($key, 'comment-') === 0) {
list($type, $rid) = explode('-', $key);
if (in_array($rid, $admin_roles)) {
// role has the admin filters perm so it can use all formats
// Role has the 'administer filters' permission so it can use all formats.
continue;
}
$fid = $values['format'];
if ($fid != 0 && ! in_array($rid, $roles[$fid])) {
if ($fid != 0 && !in_array($rid, $roles[$fid])) {
form_set_error($key, t('Role does not have access to selected format.'));
}
}
......@@ -69,7 +69,7 @@ function better_formats_defaults_admin_form_validate($form, &$form_state) {
* @see better_formats_defaults_admin_form_validate()
*/
function better_formats_defaults_admin_form_submit($form, &$form_state) {
// update DB
// Update DB.
$sql = "UPDATE {better_formats_defaults}
SET format=%d, weight=%d
WHERE rid=%d AND type='%s'";
......@@ -87,13 +87,13 @@ function better_formats_defaults_admin_form_submit($form, &$form_state) {
/**
* Process variables for better-defaults-admin-form.tpl.php.
*
* @param array $variables
* @param $variables
* The $variables array contains the following arguments:
* - $form
*/
function template_preprocess_better_formats_defaults_admin_form(&$variables) {
foreach (element_children($variables['form']) as $key) {
$form_row =& $variables['form'][$key];
$form_row = &$variables['form'][$key];
$type = strpos($key, 'node-') === 0 ? 'node' : 'comment';
......
......@@ -8,15 +8,18 @@
* because the field is hidden by default.
* Also hides formats that are not available per the Allowed checkboxes.
*/
/**
* Initialize Better Formats setttings and defaults.
*/
function better_formats_init() {
// set default settings check for use of global allowed formats
// Set default settings check for use of global allowed formats.
Drupal.settings.better_formats = {"num_checked" : $('input.bf-allowed-formats:checked').length};
// collapsing the input format setting after the weight columns have been hidden
// Collapsing the input format setting after the weight columns have been hidden.
$('.input-format-settings > legend > a').click();
// add hide/show events for allowed formats
// Add hide/show events for allowed formats.
var format_boxes = $('input.bf-allowed-formats');
format_boxes.click(function() {
better_formats_toggle_formats($(this));
......@@ -28,8 +31,16 @@ function better_formats_init() {
}
}
/**
* Toggle format display in dropdowns in sync with allowed checkboxes.
*
* @param el
* DOM element of event.
* @param init
* Boolean value to determine first toggle.
*/
function better_formats_toggle_formats(el, init) {
// hide all formats except site default when the first box is checked
// Hide all formats except site default when the first box is checked.
if (Drupal.settings.better_formats.num_checked === 0) {
$('select.bf-default-formats option[value != "0"][value != "' + el.val() + '"]').removeAttr('selected').hide();
}
......@@ -44,21 +55,20 @@ function better_formats_toggle_formats(el, init) {
}
});
// do not modify count on intial run
// Do not modify count on intial run.
if ( ! init) {
if (el.attr('checked')) {
Drupal.settings.better_formats.num_checked += 1;
}
else if (Drupal.settings.better_formats.num_checked > 0) {
// keep num_checked from going below zero
// Keep num_checked from going below zero.
Drupal.settings.better_formats.num_checked -= 1;
}
}
// show all globally allowed formats if no boxes are checked
// Show all globally allowed formats if no boxes are checked.
if (Drupal.settings.better_formats.num_checked === 0) {
// show global formats available to roles
// because no format allowed boxes are checked
// Show global formats available to roles because no format allowed boxes are checked.
$('select.bf-default-formats option').show();
}
}
......
......@@ -14,18 +14,17 @@
function better_formats_settings_admin_form() {
$form = array();
$key = 'better_formats_settings_display';
$form[$key] = array(
$form['display'] = array(
'#type' => 'fieldset',
'#title' => t('Display'),
);
$form[$key]['better_formats_fieldset_title'] = array(
$form['display']['better_formats_fieldset_title'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('better_formats_fieldset_title', ''),
'#title' => t('Selection title'),
'#description' => t('Change the format selection title. Defaults to "Input format"'),
);
$form[$key]['better_formats_long_tips_link_text'] = array(
$form['display']['better_formats_long_tips_link_text'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('better_formats_long_tips_link_text', ''),
'#title' => t('More format tips link text'),
......@@ -33,31 +32,16 @@ function better_formats_settings_admin_form() {
);
$key = 'better_formats_settings_control';
$form[$key] = array(
$form['control'] = array(
'#type' => 'fieldset',
'#title' => t('Control'),
);
$form[$key]['better_formats_per_node_type'] = array(
$form['control']['better_formats_per_node_type'] = array(
'#type' => 'checkbox',
'#title' => t('Control formats per node type'),
'#description' => t('Control formats allowed and default formats per node type. Global settings will be used until a content type admin page is saved.'),
'#default_value' => variable_get('better_formats_per_node_type', 0),
);
$key = 'better_formats_settings_advanced';
$form[$key] = array(
'#type' => 'fieldset',
'#title' => t('Advanced'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form[$key]['better_formats_debug'] = array(
'#type' => 'checkbox',
'#title' => t('Debug mode'),
'#description' => t('Turn on debug mode. This will output information to the message area that should be filed with issue reports when asked. Do not leave this turned on.'),
'#default_value' => variable_get('better_formats_debug', 0),
);
return system_settings_form($form);
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment