New module 'Better Formats'

This commit is contained in:
Manuel Cillero 2017-07-26 12:59:04 +02:00
parent 5af0c1f42e
commit ba9e434758
11 changed files with 1950 additions and 0 deletions

View file

@ -0,0 +1,274 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
verbatim copies of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to
share and change it. By contrast, the GNU General Public License is
intended to guarantee your freedom to share and change free software--to
make sure the software is free for all its users. This General Public License
applies to most of the Free Software Foundation's software and to any other
program whose authors commit to using it. (Some other Free Software
Foundation software is covered by the GNU Library General Public License
instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the
freedom to distribute copies of free software (and charge for this service if
you wish), that you receive source code or can get it if you want it, that you
can change the software or use pieces of it in new free programs; and that
you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to
deny you these rights or to ask you to surrender the rights. These restrictions
translate to certain responsibilities for you if you distribute copies of the
software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for
a fee, you must give the recipients all the rights that you have. You must make
sure that they, too, receive or can get the source code. And you must show
them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2)
offer you this license which gives you legal permission to copy, distribute
and/or modify the software.
Also, for each author's protection and ours, we want to make certain that
everyone understands that there is no warranty for this free software. If the
software is modified by someone else and passed on, we want its recipients
to know that what they have is not the original, so that any problems
introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We
wish to avoid the danger that redistributors of a free program will individually
obtain patent licenses, in effect making the program proprietary. To prevent
this, we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification
follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND
MODIFICATION
0. This License applies to any program or other work which contains a notice
placed by the copyright holder saying it may be distributed under the terms
of this General Public License. The "Program", below, refers to any such
program or work, and a "work based on the Program" means either the
Program or any derivative work under copyright law: that is to say, a work
containing the Program or a portion of it, either verbatim or with
modifications and/or translated into another language. (Hereinafter, translation
is included without limitation in the term "modification".) Each licensee is
addressed as "you".
Activities other than copying, distribution and modification are not covered
by this License; they are outside its scope. The act of running the Program is
not restricted, and the output from the Program is covered only if its contents
constitute a work based on the Program (independent of having been made
by running the Program). Whether that is true depends on what the Program
does.
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this License
and to the absence of any warranty; and give any other recipients of the
Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you
may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it,
thus forming a work based on the Program, and copy and distribute such
modifications or work under the terms of Section 1 above, provided that you
also meet all of these conditions:
a) You must cause the modified files to carry prominent notices stating that
you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or in
part contains or is derived from the Program or any part thereof, to be
licensed as a whole at no charge to all third parties under the terms of this
License.
c) If the modified program normally reads commands interactively when run,
you must cause it, when started running for such interactive use in the most
ordinary way, to print or display an announcement including an appropriate
copyright notice and a notice that there is no warranty (or else, saying that
you provide a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this License.
(Exception: if the Program itself is interactive but does not normally print such
an announcement, your work based on the Program is not required to print
an announcement.)
These requirements apply to the modified work as a whole. If identifiable
sections of that work are not derived from the Program, and can be
reasonably considered independent and separate works in themselves, then
this License, and its terms, do not apply to those sections when you distribute
them as separate works. But when you distribute the same sections as part
of a whole which is a work based on the Program, the distribution of the
whole must be on the terms of this License, whose permissions for other
licensees extend to the entire whole, and thus to each and every part
regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to
work written entirely by you; rather, the intent is to exercise the right to
control the distribution of derivative or collective works based on the
Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of a
storage or distribution medium does not bring the other work under the scope
of this License.
3. You may copy and distribute the Program (or a work based on it, under
Section 2) in object code or executable form under the terms of Sections 1
and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source
code, which must be distributed under the terms of Sections 1 and 2 above
on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to give
any third party, for a charge no more than your cost of physically performing
source distribution, a complete machine-readable copy of the corresponding
source code, to be distributed under the terms of Sections 1 and 2 above on
a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to distribute
corresponding source code. (This alternative is allowed only for
noncommercial distribution and only if you received the program in object
code or executable form with such an offer, in accord with Subsection b
above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source code
means all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation and
installation of the executable. However, as a special exception, the source
code distributed need not include anything that is normally distributed (in
either source or binary form) with the major components (compiler, kernel,
and so on) of the operating system on which the executable runs, unless that
component itself accompanies the executable.
If distribution of executable or object code is made by offering access to
copy from a designated place, then offering equivalent access to copy the
source code from the same place counts as distribution of the source code,
even though third parties are not compelled to copy the source along with the
object code.
4. You may not copy, modify, sublicense, or distribute the Program except as
expressly provided under this License. Any attempt otherwise to copy,
modify, sublicense or distribute the Program is void, and will automatically
terminate your rights under this License. However, parties who have received
copies, or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it.
However, nothing else grants you permission to modify or distribute the
Program or its derivative works. These actions are prohibited by law if you
do not accept this License. Therefore, by modifying or distributing the
Program (or any work based on the Program), you indicate your acceptance
of this License to do so, and all its terms and conditions for copying,
distributing or modifying the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these terms and
conditions. You may not impose any further restrictions on the recipients'
exercise of the rights granted herein. You are not responsible for enforcing
compliance by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues), conditions
are imposed on you (whether by court order, agreement or otherwise) that
contradict the conditions of this License, they do not excuse you from the
conditions of this License. If you cannot distribute so as to satisfy
simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the Program at all.
For example, if a patent license would not permit royalty-free redistribution
of the Program by all those who receive copies directly or indirectly through
you, then the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply and
the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or
other property right claims or to contest validity of any such claims; this
section has the sole purpose of protecting the integrity of the free software
distribution system, which is implemented by public license practices. Many
people have made generous contributions to the wide range of software
distributed through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing to
distribute software through any other system and a licensee cannot impose
that choice.
This section is intended to make thoroughly clear what is believed to be a
consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain
countries either by patents or by copyrighted interfaces, the original copyright
holder who places the Program under this License may add an explicit
geographical distribution limitation excluding those countries, so that
distribution is permitted only in or among countries not thus excluded. In such
case, this License incorporates the limitation as if written in the body of this
License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will be
similar in spirit to the present version, but may differ in detail to address new
problems or concerns.
Each version is given a distinguishing version number. If the Program specifies
a version number of this License which applies to it and "any later version",
you have the option of following the terms and conditions either of that
version or of any later version published by the Free Software Foundation. If
the Program does not specify a version number of this License, you may
choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs
whose distribution conditions are different, write to the author to ask for
permission. For software which is copyrighted by the Free Software
Foundation, write to the Free Software Foundation; we sometimes make
exceptions for this. Our decision will be guided by the two goals of
preserving the free status of all derivatives of our free software and of
promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE,
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT
PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR
AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR
ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OR INABILITY TO USE THE
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA
OR DATA BEING RENDERED INACCURATE OR LOSSES
SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN
IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS

View file

@ -0,0 +1,95 @@
Better formats is a module to add more flexibility to Drupal's core input format system.
Features
* Set the default format per role.
* Set the default format per content type.
* Control allowed formats per content type.
* Hide format tips.
* Hide format selection, forcing the default to be used.
* Expand the selection fieldset by default.
* Disable the expand/collapse of the selection fieldset.
* Set selection fieldset title.
* Set default formats for nodes, comments, and blocks separately.
* Works with CCK textareas.
* Panels comment support.
* I18n module support.
* and more.
-------------------------------------------------------------------
Installation:
1. Copy the module folder to your server.
2. Enable the module via the modules page.
-------------------------------------------------------------------
Simple 4-step usage:
1. Go to user permissions (/admin/user/permissions) and set your permissions.
2. Navigate to Site Configuration > Input formats (/admin/settings/filters)
3. There you will find 2 tabs where you can change your settings.
Defaults (/admin/settings/filters/defauts)
Settings (/admin/settings/filters/settings)
4. If you enable the "Control formats per node type" option. Go to your content
type admin page to set those settings (example /admin/content/node-type/page).
The settings are under the Input format settings fieldset.
-------------------------------------------------------------------
Important:
When setting default formats ensure that you arranged the roles correctly
placing roles in their order of precedence. This is used to determine what
default a user will get when they have more than 1 role.
NOTE:
All logged in users are automatically assigned the authenticated user role
so this role must be below all other roles that you want to set a default for or
they will get the authenticated user role default instead.
Example:
Let's say you have the 2 roles that come with Drupal and have added an
'admin' role. You would most likely want to arrange the roles in this order:
admin
authenticated user
anonymous user
-------------------------------------------------------------------
Extended usage and notes:
* The default format will only be set on NEW nodes and comments. The format
selected when the form is submitted is used for future editing purposes.
* The module is designed to always fall back to default settings when needed.
This means that when you enable the module before you change any settings,
it will use your current Drupal settings. Also when you enable conrol per node
type it will use your global settings until you save the content type with new
settings.
* The permissions "collapse format fieldset by default" and
"collapsible format selection" will only work if "Show format selection" is
also given. This is because those 2 perms only have an effect when there is
a format selection.
* The permission "collapse format fieldset by default" will only work if
"collapsible format selection" is also given. This is because the
fieldset can only be collapsed by default if it is collapsible.
* If you dis-allow a format that is already being used by content, the module
will do its best to set the correct format. The precidence of the formats are:
1. Existing format selected when last saved
2. Content type default format
3. Global default format
4. First allowed format
5. Drupal core site default format
* User 1 is treated the same as all other users when it comes to a default
format. If user 1 has not been assigned any roles then it will be assigned
the authenticated user role's default format. If you want user 1 to have the
default of another role assign that role to user 1.
* Ensure you read the important notes in the previous section marked important.
It explains how you must order your roles to effectively get your defaults.

View file

@ -0,0 +1,110 @@
<?php
// $Id: better-formats-defaults-admin-form.tpl.php,v 1.3.2.7 2009/09/27 14:27:13 dragonwize Exp $
/**
* @file
* Default theme implementation to configure Better Formats defaults admin page.
*
* Available variables:
* - $form_submit: Form submit button.
*
* Each $node_default_rows contains a row
*
* Each $data in $node_default_rows contains:
* - $data->role: Role name.
* - $data->format_select: Drop-down menu for setting format.
* - $data->weight_select: Drop-down menu for setting weights.
*/
?>
<?php
// Add table javascript
drupal_add_tabledrag('node-format-defaults', 'order', 'sibling', 'better-formats-role-node-weight');
drupal_add_tabledrag('comment-format-defaults', 'order', 'sibling', 'better-formats-role-comment-weight');
drupal_add_tabledrag('block-format-defaults', 'order', 'sibling', 'better-formats-role-block-weight');
?>
<div class="description">
<?php print '<p><strong>' . t('Defaults only affect NEW content NOT existing content.') . '</strong></p>'; ?>
<?php print '<p><strong>' . t('Place roles in order of precedence by dragging more important roles to the top.') . '</strong></p>'; ?>
</div>
<fieldset>
<legend><strong><?php print t('Node defaults'); ?></strong></legend>
<table id="node-format-defaults">
<thead>
<tr>
<th><?php print t('Role'); ?></th>
<th><?php print t('Default format'); ?></th>
<th><?php print t('Weight'); ?></th>
</tr>
</thead>
<tbody>
<?php $row = 0; ?>
<?php foreach ($node_default_rows as $rid => $data): ?>
<tr class="draggable <?php print $row % 2 ? 'odd' : 'even'; ?>">
<td class=""><?php print $data->role; ?></td>
<td><?php print $data->format_select; ?></td>
<td><?php print $data->weight_select; ?></td>
</tr>
<?php $row++; ?>
<?php endforeach; ?>
</tbody>
</table>
</fieldset>
<fieldset>
<legend><strong><?php print t('Comment defaults'); ?></strong></legend>
<table id="comment-format-defaults">
<thead>
<tr>
<th><?php print t('Role'); ?></th>
<th><?php print t('Default format'); ?></th>
<th><?php print t('Weight'); ?></th>
</tr>
</thead>
<tbody>
<?php $row = 0; ?>
<?php foreach ($comment_default_rows as $rid => $data): ?>
<tr class="draggable <?php print $row % 2 ? 'odd' : 'even'; ?>">
<td class=""><?php print $data->role; ?></td>
<td><?php print $data->format_select; ?></td>
<td><?php print $data->weight_select; ?></td>
</tr>
<?php $row++; ?>
<?php endforeach; ?>
</tbody>
</table>
</fieldset>
<?php if ($_GET['q'] === 'admin/settings/filters/defaults'): ?>
<fieldset>
<legend><strong><?php print t('Block defaults'); ?></strong></legend>
<?php if (isset($block_default_rows)): ?>
<table id="block-format-defaults">
<thead>
<tr>
<th><?php print t('Role'); ?></th>
<th><?php print t('Default format'); ?></th>
<th><?php print t('Weight'); ?></th>
</tr>
</thead>
<tbody>
<?php $row = 0; ?>
<?php foreach ($block_default_rows as $rid => $data): ?>
<tr class="draggable <?php print $row % 2 ? 'odd' : 'even'; ?>">
<td class=""><?php print $data->role; ?></td>
<td><?php print $data->format_select; ?></td>
<td><?php print $data->weight_select; ?></td>
</tr>
<?php $row++; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</fieldset>
<?php endif; ?>
<div class="description">
<?php print '<p>' . t('* Only formats that a role has permission to use are shown in the default format drop downs.') . '</p>'; ?>
</div>
<?php print $form_submit; ?>

View file

@ -0,0 +1,11 @@
; $Id: better_formats.info,v 1.1.2.2 2009/02/25 06:44:17 dragonwize Exp $
name = Better Formats
description = Enhances the core input format system by managing input format defaults and settings.
core = 6.x
; Information added by drupal.org packaging script on 2010-02-05
version = "6.x-1.2"
core = "6.x"
project = "better_formats"
datestamp = "1265402405"

View file

@ -0,0 +1,160 @@
<?php
// $Id: better_formats.install,v 1.7.2.7 2009/05/31 06:24:40 dragonwize Exp $
/**
* @file
* Installs the better_formats module.
*
* Creates a database for use of multi-layered default formats and sets
* default settings.
*/
/**
* Implementation of hook_schema().
*/
function better_formats_schema() {
$schema['better_formats_defaults'] = array(
'fields' => array(
'rid' => array(
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'format' => array(
'type' => 'int',
'size' => 'medium',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type_weight' => array(
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'unsigned' => TRUE,
'not null' => TRUE,
),
'weight' => array(
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'unsigned' => FALSE,
'not null' => TRUE,
),
),
'primary key' => array('rid', 'type'),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function better_formats_install() {
// Create tables.
drupal_install_schema('better_formats');
// Increase module weight to prevent compatibility issues.
$sql = "UPDATE {system}
SET weight = 100
WHERE name = 'better_formats'";
db_query($sql);
// Insert format defaults.
$roles = user_roles();
$sql = "INSERT INTO {better_formats_defaults}
VALUES (%d, '%s', %d, %d, %d)";
foreach ($roles as $rid => $role) {
db_query($sql, $rid, 'node', 0, 1, 0);
db_query($sql, $rid, 'comment', 0, 1, 0);
db_query($sql, $rid, 'block', 0, 1, 25);
}
// Set default perms to be like core defaults.
$default_perms = ', show format selection for nodes, show format selection for comments, show format selection for blocks, show format tips, show more format tips link, collapsible format selection, collapse format fieldset by default';
// Get current core perms.
$sql = "SELECT *
FROM {permission}
WHERE rid IN (1,2)";
$result = db_query($sql);
$role_perms = array();
while ($row = db_fetch_object($result)) {
$role_perms[$row->rid] = $row;
}
// If a role has no permissions set it will not have a row in the database.
// Assume that roles do not need perms set for BF as well if none are set.
if (!empty($role_perms)) {
// Add perms to core roles (anonymous user, authenticated user).
foreach ($role_perms as $perms) {
$sql = "UPDATE {permission}
SET perm = '%s'
WHERE pid = %d";
db_query($sql, $perms->perm . $default_perms, $perms->pid);
}
// Clear the cache.
cache_clear_all();
}
}
/**
* Implementation of hook_uninstall().
*/
function better_formats_uninstall() {
// Remove tables.
drupal_uninstall_schema('better_formats');
// Delete settings from varible table.
$sql = "DELETE FROM {variable}
WHERE name LIKE 'better_formats%'";
db_query($sql);
}
/**
* Update from 1.0 to 1.1.
*/
function better_formats_update_6110() {
$ret = array();
// Insert block format defaults.
$roles = user_roles();
$sql = "INSERT INTO {better_formats_defaults}
VALUES (%d, '%s', %d, %d, %d)";
foreach ($roles as $rid => $role) {
$result = db_query($sql, $rid, 'block', 0, 1, 25);
$ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql));
}
// Split show format selection permission.
// Get permissions by role.
$sql = "SELECT *
FROM {permission}";
$result = db_query($sql);
$row_perms = array();
while ($row = db_fetch_object($result)) {
$role_perms[$row->rid] = $row;
}
if (!empty($role_perms)) {
// Add perms to core roles (anonymous user, authenticated user).
foreach ($role_perms as $perms) {
// Only enable spit permissions if previous was enabled.
$replace = ', show format selection for nodes, show format selection for comments, show format selection for blocks,';
$perms->perm = str_replace(', show format selection,', $replace, $perms->perm);
$sql = "UPDATE {permission}
SET perm = '%s'
WHERE pid = %d";
$result = db_query($sql, $perms->perm, $perms->pid);
$ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql));
}
// Clear the cache.
cache_clear_all();
}
return $ret;
}

View file

@ -0,0 +1,638 @@
<?php
// $Id: better_formats.module,v 1.23.2.17 2010/02/05 13:59:18 dragonwize Exp $
/**
* @file
* Enhances Drupal's core input format settings.
*
* Allows setting of defaults per role and content type,
* controls format display options, works with CCK fields.
*/
/**
* Implementation of hook_help().
*/
function better_formats_help($path, $arg) {
switch ($path) {
case 'admin/help/better_formats':
$output = '<p>' . t('See the module README.txt file in the better_formats module directory for help.') . '</p>';
break;
default:
$output = '';
}
return $output;
}
/**
* Implementation of hook_perm().
*/
function better_formats_perm() {
return array(
'show format selection for nodes',
'show format selection for comments',
'show format selection for blocks',
'show format tips',
'show more format tips link',
'collapse format fieldset by default',
'collapsible format selection',
);
}
/**
* Implementation of hook_menu().
*/
function better_formats_menu() {
$items = array();
$items['admin/settings/filters/settings'] = array(
'title' => 'Settings',
'description' => 'Manage input formats',
'page callback' => 'drupal_get_form',
'page arguments' => array('better_formats_settings_admin_form'),
'access arguments' => array('administer filters'),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
'file' => 'better_formats_settings.admin.inc',
);
$items['admin/settings/filters/defaults'] = array(
'title' => 'Defaults',
'description' => 'Manage input formats',
'page callback' => 'drupal_get_form',
'page arguments' => array('better_formats_defaults_admin_form'),
'access arguments' => array('administer filters'),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
'file' => 'better_formats_defaults.admin.inc',
);
return $items;
}
/**
* Implementation of hook_theme().
*/
function better_formats_theme() {
return array(
'better_formats_defaults_admin_form' => array(
'template' => 'better-formats-defaults-admin-form',
'file' => 'better_formats_defaults.admin.inc',
'arguments' => array('form' => NULL),
),
'better_formats_filter_tips_more_info' => array(
'arguments' => array(),
),
);
}
/**
* Implementation of hook_form_alter().
*/
function better_formats_form_alter(&$form, $form_state, $form_id) {
// Alter new node and comment forms.
// Using $form['#id'] instead of $form_id because $form_id is in the form of
// 'TYPE_node_form' which varies with the content type while $form['#id']
// is always 'node-form'.
switch ($form['#id']) {
case 'comment-form':
case 'panels-comment-form':
better_formats_set_comment_format($form);
break;
case 'node-form':
better_formats_set_node_format($form);
break;
case 'block-add-block-form':
case 'block-admin-configure':
better_formats_set_block_format($form);
break;
}
// Alter role add/delete and node type forms.
switch ($form_id) {
case 'node_type_form':
if (variable_get('better_formats_per_node_type', FALSE)) {
better_formats_node_type_form($form, $form_state);
}
break;
case 'user_admin_new_role':
if (!in_array('better_formats_new_role', $form['#submit'])) {
$form['#submit'][] = 'better_formats_new_role';
}
break;
case 'user_admin_role':
if (isset($form_state['post']['op']) && $form_state['post']['op'] == 'Delete role') {
$form['#submit'][] = 'better_formats_delete_role';
}
break;
}
}
/**
* FAPI form to add to the content type edit form.
*
* @see better_formats_node_type_form_validate()
* @see better_formats_node_type_form_submit()
*/
function better_formats_node_type_form(&$form, $form_state) {
// Add JS to enhance form.
drupal_add_js(drupal_get_path('module', 'better_formats') . '/better_formats_node_type_form.js');
$node_type = $form['#node_type']->type;
// Build array of all formats for allowed checkboxes.
$formats = filter_formats();
foreach ($formats as $format) {
$format_boxes[$format->format] = $format->name;
}
$key = 'better_formats';
$form[$key] = array(
'#type' => 'fieldset',
'#title' => t('Input format settings'),
'#access' => user_access('administer filters'),
'#collapsible' => TRUE,
// Setting collapsed to false because the wieght will not be hidden otherwise
// the fieldset will be collapsed via JS if enabled.
'#collapsed' => FALSE,
'#attributes' => array('class' => 'input-format-settings'),
);
$allowed_key = $key . '_allowed';
$form[$key][$allowed_key] = array(
'#type' => 'checkboxes',
'#title' => t('Allowed formats'),
'#default_value' => variable_get($allowed_key . '_' . $node_type, array()),
'#options' => $format_boxes,
'#description' => t('Limit the formats users have to choose from even if they have permission to use that format. This will NOT allow a user to use a format they do not have access rights to use. It will only hide additional formats they do have access rights to. If no boxes are checked, all formats that the user has permission to use will be allowed.'),
'#attributes' => array('class' => 'bf-allowed-formats'),
);
$dform = array(
'#tree' => TRUE,
'#theme' => 'better_formats_defaults_admin_form',
);
module_load_include('admin.inc', 'better_formats', 'better_formats_defaults');
$nform = better_formats_get_role_default_fields('node', $node_type);
$cform = better_formats_get_role_default_fields('comment', $node_type);
$form[$key]['better_formats_defaults'] = array_merge($dform, $nform, $cform);
// Attach our validate and submit handlers.
$form['#validate'][] = 'better_formats_node_type_form_validate';
$form['#submit'][] = 'better_formats_node_type_form_submit';
}
/**
* Handles validation of the addition to the content type edit form.
*
* @see better_formats_node_type_form()
* @see better_formats_node_type_form_submit()
*/
function better_formats_node_type_form_validate($form, &$form_state) {
module_load_include('admin.inc', 'better_formats', 'better_formats_defaults');
better_formats_defaults_admin_form_validate($form, $form_state);
}
/**
* Handles submission of the addition to the content type edit form.
*
* @see better_formats_node_type_form()
* @see better_formats_node_type_form_validate()
*/
function better_formats_node_type_form_submit($form, &$form_state) {
$node_type = trim($form_state['values']['type']);
// Remove current db entries.
$sql = "DELETE FROM {better_formats_defaults}
WHERE type='comment/%s' OR type='node/%s'";
db_query($sql, $node_type, $node_type);
// Insert defualt values into DB.
$sql = "INSERT INTO {better_formats_defaults}
VALUES (%d, '%s', %d, %d, %d)";
foreach ($form_state['values']['better_formats_defaults'] as $key => $values) {
if (strpos($key, 'node-') === 0 || strpos($key, 'comment-') === 0) {
list($type, $rid) = explode('-', $key);
db_query($sql, $rid, $type . '/' . $node_type, $values['format'], 2, $values['weight']);
}
}
// Node module automatically stores all settings in variable table.
// BF saves format defaults to its own table so delete the unneeded variable.
variable_del('better_formats_defaults_' . $node_type);
}
/**
* Creates base format default entry for a newly created role.
*
* @see better_formats_form_alter()
*/
function better_formats_new_role($form, &$form_state) {
// Get the ID for the role just created.
$sql = "SELECT rid
FROM {role}
ORDER BY rid DESC";
$row = db_fetch_object(db_query_range($sql, 0, 1));
$rid = $row->rid;
// Create stubs in per role table.
$sql = "INSERT INTO {better_formats_defaults}
VALUES (%d, '%s', %d, %d, %d)";
db_query($sql, $rid, 'node', 0, 1, 25);
db_query($sql, $rid, 'comment', 0, 1, 25);
db_query($sql, $rid, 'block', 0, 1, 25);
}
/**
* Deletes role format default entries for roles being deleted.
*
* @see better_formats_form_alter()
*/
function better_formats_delete_role($form, &$form_state) {
// Delete role from format manager table.
$sql = "DELETE FROM {better_formats_defaults}
WHERE rid = %d";
db_query($sql, $form['rid']['#value']);
}
/**
* Implementation of hook_node_type().
*/
function better_formats_node_type($op, $info) {
if ($op === 'delete') {
// Delete per node type settings on node type delete.
$sql = "DELETE FROM {better_formats_defaults}
WHERE type IN ('node/%s', 'comment/%s')";
db_query($sql, $info->type, $info->type);
// Delete node type variables.
variable_del('better_formats_allowed_' . $info->type);
}
}
/**
* Implementation of hook_elements().
*
* Adds a process function to CCK's text module FAPI elements.
*/
function better_formats_elements() {
return array(
'text_textfield' => array(
'#process' => array('better_formats_text_process'),
),
'text_textarea' => array(
'#process' => array('better_formats_text_process'),
),
);
}
/**
* Processes a CCK text elements.
*
* Resets the filter area with bettter_formats default.
* This function is used to affect CCK text module fields not core fields.
*
* @see text_textfield_process()
* @see text_textarea_process()
*/
function better_formats_text_process($element, $edit, $form_state, $form) {
$field = $form['#field_info'][$element['#field_name']];
if (!empty($field['text_processing'])) {
// Get core default for new or selected format for existing.
$filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format';
$format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : $element['#default_value'][$filter_key];
$parents = array_merge($element['#parents'] , array($filter_key));
$default = better_formats_get_default_format('node', $form['type']['#value']);
// Overwrite format default if new node.
if (!isset($form_state['values']['nid']) || empty($format)) {
$format = $default;
}
$format = filter_resolve_format($format);
// Set default format for cck textarea.
$element['#value'][$filter_key] = $format;
// Set filter selection form.
$element[$filter_key] = better_formats_filter_form($format, $default, 'node', $form['type']['#value'], 1, $parents);
}
return $element;
}
/**
* Processes formats for core node body fields.
*
* @see better_formats_form_alter()
*/
function better_formats_set_node_format(&$form) {
// Set core body field.
if (isset($form['body_field'])) {
// Get default for new entries.
$default = better_formats_get_default_format('node', $form['type']['#value']);
if (empty($form['nid']['#value']) && !isset($form['#parameters'][1]['node_preview'])) {
// Set format to default for new entries.
$format = $default;
}
else {
// Get existing format for core body field.
$format = better_formats_get_current_format($form['body_field']['format']);
}
// Overwrite the filter form with our own.
$form['body_field']['format'] = better_formats_filter_form($format, $default, 'node', $form['type']['#value']);
}
}
/**
* Processes formats for core node comment form.
*
* @see better_formats_form_alter()
*/
function better_formats_set_comment_format(&$form) {
if (isset($form['comment_filter']['format'])) {
$node = node_load($form['nid']['#value']);
// Get BF default format.
$default = better_formats_get_default_format('comment', $node->type);
if (empty($form['cid']['#value'])) {
// Set format to default for new entries.
$format = $default;
}
else {
// Get existing format for comment.
$format = better_formats_get_current_format($form['comment_filter']['format']);
}
// Overwrite the filter form with our own.
$form['comment_filter']['format'] = better_formats_filter_form($format, $default, 'comment', $node->type);
}
}
/**
* Processes formats for core block form.
*
* @see better_formats_form_alter()
*/
function better_formats_set_block_format(&$form) {
if (isset($form['block_settings']['body_field']['format'])) {
// Get BF default format.
$default = better_formats_get_default_format('block');
if (empty($form['delta']['#value'])) {
// Set format to default for new entries.
$format = $default;
}
else {
// Get existing format for block.
$format = better_formats_get_current_format($form['block_settings']['body_field']['format']);
}
// Overwrite the filter form with our own.
$form['block_settings']['body_field']['format'] = better_formats_filter_form($format, $default, 'block');
}
}
/**
* Returns the format for an existing node or comment.
*
* @param $form
* FAPI form array.
* @return
* Format ID.
*
* @see better_formats_set_node_format()
* @see better_formats_set_comment_format()
*/
function better_formats_get_current_format($form) {
// Default format to site default in case of error.
$format = FILTER_FORMAT_DEFAULT;
foreach (element_children($form) as $key) {
$element = $form[$key];
if ($element['#type'] === 'radio' && isset($element['#default_value'])) {
$format = $element['#default_value'];
break;
}
if ($element['#type'] === 'value' && isset($element['#value'])) {
$format = $element['#value'];
break;
}
}
return $format;
}
/**
* Returns the default format for an new node or comment.
*
* @param $mode
* 'node', 'comment', or 'block'. Describes the top level type of default.
* @return
* Format ID.
*
* @see better_formats_set_node_format()
* @see better_formats_set_comment_format()
* @see better_formats_textarea_process()
*/
function better_formats_get_default_format($mode, $node_type = '') {
static $format;
// Default our type to the mode (node or comment).
$type = $mode;
// Check if per node type is enabled and set type accordingly.
$per_node_type = variable_get('better_formats_per_node_type', FALSE);
if ($per_node_type && $node_type) {
$type = $mode . '/' . $node_type;
}
// Only pull from the DB if we have not already checked for this specific type.
if (!isset($format[$type])) {
global $user;
$types = $type;
$format = array();
$roles = implode(',', array_keys($user->roles));
// Prepare types for SQL.
if ($mode !== 'block' && $per_node_type && $node_type) {
$types .= "','" . $mode;
}
// Get user's lowest weight role default.
$sql = "SELECT format
FROM {better_formats_defaults}
WHERE rid IN (%s) AND type IN ('$types')
ORDER BY type_weight DESC, weight ASC";
$row = db_fetch_object(db_query_range($sql, $roles, 0, 1));
$format[$type] = filter_resolve_format($row->format);
}
return $format[$type];
}
/**
* Better Formats version of filter_form().
*
* Copied from filter.module with slight modification to handle options for
* hiding filter selection and/or tips.
* The $node_type param was added to the signature to enable condition by
* content type.
*
* @see filter_form()
*/
function better_formats_filter_form($value = FILTER_FORMAT_DEFAULT, $default_format, $mode = 'node', $node_type = '', $weight = 1, $parents = array('format')) {
$value = filter_resolve_format($value);
$formats = filter_formats();
$show_selection = user_access('show format selection for ' . $mode . 's');
$show_tips = user_access('show format tips');
$show_tips_link = user_access('show more format tips link');
$per_node_type = variable_get('better_formats_per_node_type', FALSE);
$allowed_formats = variable_get('better_formats_allowed_' . $node_type, FALSE);
// Check if there are node type restrictions on allowed formats.
// If there are no retrictions set, we use the site globals as default.
if ($per_node_type && $allowed_formats) {
foreach ($formats as $key => $format) {
if (!in_array($format->format, $allowed_formats)) {
unset($formats[$key]);
}
}
}
// Ensure that our default value is allowed or change default to one that is.
if (isset($formats[$value])) {
// Use existing or BF default value if available.
$default = $value;
}
else if (isset($formats[$default_format])) {
// Use currently set BF default as a fallback.
$default = $default_format;
}
else if (!empty($formats)) {
// Current and default format are not allowed, so use first allowed format.
reset($formats);
$default = key($formats);
}
else {
// Use core site default as a fallback if all else fails.
$default = filter_resolve_format(FILTER_FORMAT_DEFAULT);
}
if (count($formats) > 1 && $show_selection) {
$collapsed = user_access('collapse format fieldset by default');
$collapsible = user_access('collapsible format selection');
$fieldset_title = variable_get('better_formats_fieldset_title', '');
if (module_exists('i18n_strings') && $fieldset_title) {
$fieldset_title = tt($fieldset_title);
}
else {
$fieldset_title = $fieldset_title ? $fieldset_title : t('Input format');
}
$form = array(
'#type' => 'fieldset',
'#title' => $fieldset_title,
'#collapsible' => $collapsible,
'#collapsed' => $collapsed,
'#weight' => $weight,
'#element_validate' => array('filter_form_validate'),
);
// Multiple formats available: display radio buttons with tips.
foreach ($formats as $format) {
// Generate the parents as the autogenerator does, so we will have a
// unique id for each radio button.
$parents_for_id = array_merge($parents, array($format->format));
$form[$format->format] = array(
'#type' => 'radio',
'#title' => $format->name,
'#default_value' => $default,
'#return_value' => $format->format,
'#parents' => $parents,
'#id' => form_clean_id('edit-' . implode('-', $parents_for_id)),
);
if ($show_tips) {
$form[$format->format]['#description'] = theme('filter_tips', _filter_tips($format->format, FALSE));
}
else {
// Ensure expected filter_form() structure.
// see http://drupal.org/node/344169
$form[$format->format]['#description'] = '';
}
}
if ($show_tips_link) {
$extra = theme('better_formats_filter_tips_more_info');
$form[] = array('#value' => $extra);
}
else {
// Ensure expected filter_form() structure.
// see http://drupal.org/node/344169
$form[] = array('#value' => '');
}
}
else {
// Only one format available or hiding the form: use a hidden form item.
$format = $formats[$default];
$form[$format->format] = array(
'#type' => 'value',
'#value' => $format->format,
'#parents' => $parents,
);
if ($show_tips) {
$tips = _filter_tips($format->format, FALSE);
$form['format']['guidelines'] = array(
'#title' => t('Formatting guidelines'),
'#value' => theme('filter_tips', $tips, FALSE),
);
}
else {
// Ensure expected filter_form() structure.
// see http://drupal.org/node/344169
$form['format']['guidelines'] = array(
'#title' => t('Formatting guidelines'),
'#value' => '',
);
}
// Only show long tips link if there are guidelines to the format.
if ($show_tips_link) {
$extra = theme('better_formats_filter_tips_more_info');
$form[] = array('#value' => $extra);
}
else {
// Ensure expected filter_form() structure.
// see http://drupal.org/node/344169
$form[] = array('#value' => '');
}
}
return $form;
}
/**
* Theme function for fitler tips more info.
*
* This is copied from theme_fitler_tips_more_info() with small modifications.
*
* @return
* Filter tips more info HTML.
*/
function theme_better_formats_filter_tips_more_info() {
$text = variable_get('better_formats_long_tips_link_text', '');
if (module_exists('i18n_strings') && $text) {
$text = tt($text);
}
else {
$text = $text ? $text : t('More information about formatting options');
}
return '<p>' . l($text, 'filter/tips') . '</p>';
}

View file

@ -0,0 +1,237 @@
<?php
// $Id: better_formats_defaults.admin.inc,v 1.3.2.11 2010/02/05 13:52:48 dragonwize Exp $
/**
* @file
* Contains FAPI and theme functions for the format defaults form.
*/
/**
* Builds the form for the filters admin.
*
* @return
* FAPI array
*
* @see better_formats_defaults_admin_form_validate()
* @see better_formats_defaults_admin_form_submit()
*/
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');
$bform = better_formats_get_role_default_fields('block');
$form = array_merge($form, $nform, $cform, $bform);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save defaults'),
);
return $form;
}
/**
* Validates better_formats_admin_filter_form.
*
* @see better_formats_defaults_admin_form()
* @see better_formats_defaults_admin_form_submit()
*/
function better_formats_defaults_admin_form_validate($form, &$form_state) {
$formats = filter_formats();
foreach ($formats as $fid => $format) {
$roles[$fid] = explode(',', $format->roles);
}
// Get roles that have administer filters permission.
$admin_roles = better_formats_get_roles_by_perm('administer filters');
foreach ($form_state['values'] as $key => $values) {
if (strpos($key, 'node-') === 0 || strpos($key, 'comment-') === 0 || strpos($key, 'block-') === 0) {
list($type, $rid) = explode('-', $key);
if (in_array($rid, $admin_roles)) {
// Role has the 'administer filters' permission so it can use all formats.
continue;
}
$fid = $values['format'];
$site_default = filter_resolve_format(FILTER_FORMAT_DEFAULT);
if ($fid != 0 && !in_array($rid, $roles[$fid]) && $fid !== $site_default) {
form_set_error($key, t('Role does not have access to selected format.'));
}
}
}
}
/**
* Updates database from better_formats_admin_filter_form.
*
* @see better_formats_defaults_admin_form()
* @see better_formats_defaults_admin_form_validate()
*/
function better_formats_defaults_admin_form_submit($form, &$form_state) {
// Update DB.
$sql = "UPDATE {better_formats_defaults}
SET format=%d, weight=%d
WHERE rid=%d AND type='%s'";
foreach ($form_state['values'] as $key => $values) {
if (strpos($key, 'node-') === 0 || strpos($key, 'comment-') === 0 || strpos($key, 'block-') === 0) {
list($type, $rid) = explode('-', $key);
db_query($sql, $values['format'], $values['weight'], $rid, $type);
}
}
drupal_set_message(t('Defaults have been saved.'));
}
/**
* Builds FAPI form elements for the default format selection.
*
* @param $mode
* 'node', 'comment', or 'block'. Top most level type for requested default.
* @param $node_type
* Type of node this request is for.
* @return
* FAPI array for the default select field.
*/
function better_formats_get_role_default_fields($mode, $node_type = '') {
$form = array();
$format_options = better_formats_get_formats_per_role();
$type = $types = $mode;
$per_node_type = variable_get('better_formats_per_node_type', FALSE);
if ($per_node_type && $node_type) {
$type = $mode . '/' . $node_type;
$types = $type . "','" . $mode;
}
// get data from db
$sql = "SELECT bf.*, role.name
FROM {better_formats_defaults} AS bf
INNER JOIN {role} AS role
ON bf.rid = role.rid
WHERE bf.type IN ('$types')
ORDER BY bf.type_weight DESC, bf.weight, role.rid";
$result = db_query($sql);
$roles_set = array();
while ($role = db_fetch_object($result)) {
if (in_array($role->rid, $roles_set)) {
continue;
}
$roles_set[] = $role->rid;
$key = $mode . '-' . $role->rid;
$form[$key]['role'] = array(
'#value' => $role->name,
);
$form[$key]['format'] = array(
'#type' => 'select',
'#options' => $format_options[$role->rid],
'#default_value' => $role->format,
'#attributes' => array('class' => 'bf-default-formats'),
);
$form[$key]['weight'] = array(
'#type' => 'weight',
'#delta' => 25,
'#default_value' => $role->weight,
);
}
return $form;
}
/**
* Retrieve the formats available to users by role.
*
* Gets all formats then creates an array keyed by role IDs
* that lists the formats available to that role. This is determined
* by Drupal core's format permissions set at
* admin/settings/filters/[filter_id].
*
* @return
* Multi-dim array with role IDs for keys and list of allowed formats.
*
* @see better_formats_get_role_default_fields()
*/
function better_formats_get_formats_per_role() {
$formats = filter_formats();
$roles = user_roles();
// Get roles that have administer filters permission.
$admin_roles = better_formats_get_roles_by_perm('administer filters');
$site_default_format = filter_resolve_format(FILTER_FORMAT_DEFAULT);
foreach ($formats as $format) {
$roles_allowed = $format->roles ? explode(',', trim($format->roles, ',')) : array();
foreach ($roles as $rid => $role) {
$format_options[$rid][0] = t('Site default');
if ($format->format == $site_default_format || in_array($rid, $admin_roles) || in_array($rid, $roles_allowed)) {
$format_options[$rid][$format->format] = $format->name;
}
}
}
return $format_options;
}
/**
* Get a list of roles that have a permission.
*
* @param $perm
* Permission string to get roles for.
* @param $reset
* Boolean to clear static cache.
* @return
* An array of role IDs that have the requested permission.
*/
function better_formats_get_roles_by_perm($perm, $reset = FALSE) {
static $roles;
if ($reset || !isset($roles[$perm])) {
$sql = "SELECT rid
FROM {permission}
WHERE perm LIKE '%$perm%'
ORDER BY rid";
$result = db_query($sql);
$roles[$perm] = array();
while ($row = db_fetch_object($result)) {
$roles[$perm][] = $row->rid;
}
}
return $roles[$perm];
}
/**
* Process variables for better-defaults-admin-form.tpl.php.
*
* @param $vars
* The $variables array contains the following arguments:
* - $form
*/
function template_preprocess_better_formats_defaults_admin_form(&$vars) {
foreach (element_children($vars['form']) as $key) {
$form_row = &$vars['form'][$key];
//$type = strpos($key, 'node-') === 0 ? 'node' : 'comment';
$type = substr($key, 0, strpos($key, '-'));
if (isset($form_row['role'])) {
// Set special classes needed for table drag and drop.
$form_row['weight']['#attributes']['class'] = 'better-formats-role-' . $type . '-weight';
$row = new stdClass();
$row->role = drupal_render($form_row['role']);
$row->format_select = drupal_render($form_row['format']);
$row->weight_select = drupal_render($form_row['weight']);
$vars[$type . '_default_rows'][$key] = $row;
}
}
$vars['form_submit'] = drupal_render($vars['form']);
}

View file

@ -0,0 +1,77 @@
// $Id: better_formats_node_type_form.js,v 1.4.2.3 2009/05/31 17:53:41 dragonwize Exp $
/**
* @file
* Enhances the default format selection on content type edit forms.
*
* Fixes bug that shows weight field when drag and drop is enabled
* 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 betterFormatsInit() {
// Set default settings check for use of global allowed formats.
Drupal.settings.betterFormats = {"numChecked" : $('input.bf-allowed-formats:checked').length};
// 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.
var formatBoxes = $('input.bf-allowed-formats');
formatBoxes.click(function() {
betterFormatsToggleFormats($(this));
});
if (Drupal.settings.betterFormats.numChecked > 0) {
formatBoxes.each(function() {
betterFormatsToggleFormats($(this), true);
});
}
}
/**
* 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 betterFormatsToggleFormats(el, init) {
// Hide all formats except site default when the first box is checked.
if (Drupal.settings.betterFormats.numChecked === 0) {
$('select.bf-default-formats option[value != "0"][value != "' + el.val() + '"]').removeAttr('selected').hide();
}
$('select.bf-default-formats option[value = "' + el.val() + '"]').each(function() {
var option = $(this);
if (el.attr('checked')) {
option.show();
}
else {
option.removeAttr('selected').hide();
}
});
// Do not modify count on intial run.
if (!init) {
if (el.attr('checked')) {
Drupal.settings.betterFormats.numChecked += 1;
}
else if (Drupal.settings.betterFormats.numChecked > 0) {
// Keep num_checked from going below zero.
Drupal.settings.betterFormats.numChecked -= 1;
}
}
// Show all globally allowed formats if no boxes are checked.
if (Drupal.settings.betterFormats.numChecked === 0) {
// Show global formats available to roles because no format allowed boxes are checked.
$('select.bf-default-formats option').show();
}
}
$(document).ready(betterFormatsInit);

View file

@ -0,0 +1,47 @@
<?php
// $Id: better_formats_settings.admin.inc,v 1.6.2.3 2009/02/25 06:44:17 dragonwize Exp $
/**
* @file
* Contains FAPI and theme functions for the format settings form.
*/
/**
* FAPI form builder for admin/settings/filters/settings page.
*
* @see better_formats_menu()
*/
function better_formats_settings_admin_form() {
$form = array();
$form['display'] = array(
'#type' => 'fieldset',
'#title' => t('Display'),
);
$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['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'),
'#description' => t('Change the format full tips link text. Defaults to "More information about formatting options"'),
);
$form['control'] = array(
'#type' => 'fieldset',
'#title' => t('Control'),
);
$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),
);
return system_settings_form($form);
}

View file

@ -0,0 +1,124 @@
<?php
// $Id: better_formats_anonymous_user.test,v 1.1.2.1 2009/07/25 16:23:44 dragonwize Exp $
/**
* @file
* Tests for the Better Formats module.
*
*/
class BetterFormatsTestCase extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('Better formats tests'),
'description' => t('Test some of the BetterFormats features.'),
'group' => t('Better Formats'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('better_formats');
}
/**
* Test various behaviors for anonymous users.
*/
function testBetterFormatsFunctionalTest() {
// Create a user with permission to view the actions administration pages.
$admin = $this->drupalCreateUser(array('administer permissions', 'administer filters'));
$this->drupalLogin($admin);
// Hide the format tips link.
$this->setPermission('anonymous user', array('show more format tips link' => FALSE, 'access comments' => TRUE, 'access content' => TRUE, 'post comments' => TRUE, 'post comments without approval' => TRUE));
$this->node = $this->drupalCreateNode(array('type' => 'story', 'promote' => 1, 'comment' => 2));
$this->drupalLogout();
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertNoText('More information about formatting options.', 'Show more format tips link removed.');
// Default for comments, hiding format selection on comments.
$this->drupalLogin($admin);
// Let anon use full html - it's crazy, but it's just simpletest
$edit = array();
$edit['roles[1]'] = TRUE;
$this->drupalPost('admin/settings/filters/2', $edit, t('Save configuration'));
// Set full html as default for anon on comments - again, crazy, but...
$edit = array();
$edit['comment-1[format]'] = 2;
$this->drupalPost('admin/settings/filters/defaults', $edit, t('Save defaults'));
$this->setPermission('anonymous user', array('show format selection for comments' => FALSE, 'create page content' => TRUE));
$this->drupalLogout();
// Now, do we see the signature for Full HTML on the comment page?
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertNoText('Allowed HTML tags:', 'Filter tips removed on comments.');
$this->assertText('Web page addresses and e-mail addresses turn into links automatically.', 'Filter tips removed on comments.');
// And do we see the Filtered HTML on a node page?
$this->drupalGet('node/add/page');
$this->assertText('Allowed HTML tags:', 'Filter tips still on a page.');
// Collapsible format selection collapsed by default.
$this->drupalLogin($admin);
$this->setPermission('anonymous user', array('show format selection for comments' => TRUE));
$this->drupalLogout();
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertText('Filtered HTML', 'Allow format selection on comments.');
$this->assertRaw('<fieldset class=" collapsible collapsed"><legend>Input format</legend>', 'Collapsible format selection fieldset found.');
$this->assertRaw('<input type="radio" id="edit-format-2-1" name="format" value="2" checked="checked" class="form-radio" /> Full HTML', 'Default for comments to Full HTML.');
// Not collapsed by default.
$this->drupalLogin($admin);
$this->setPermission('anonymous user', array('collapse format fieldset by default' => FALSE));
$this->drupalLogout();
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertRaw('<fieldset class=" collapsible"><legend>Input format</legend>', 'Collapsible format selection fieldset found.');
// Not even collapsible.
$this->drupalLogin($admin);
$this->setPermission('anonymous user', array('collapsible format selection' => FALSE));
$this->drupalLogout();
$this->drupalGet('comment/reply/' . $this->node->nid);
$this->assertRaw('<fieldset><legend>Input format</legend>', 'Collapsible format selection fieldset found.');
// Check to see that the show format selection on nodes works.
$this->drupalLogin($admin);
$this->setPermission('anonymous user', array('show format selection for nodes' => FALSE));
$this->drupalLogout();
$this->drupalGet('node/add/page');
$this->assertNoRaw('<input type="radio" id="edit-format-1-1" name="format" value="1" checked="checked" class="form-radio" /> Filtered HTML</label>', 'No radios on a page.');
}
/**
* Set permission.
*
* @param string $role User role to set permissions for.
* @param array $permissions Key-value array of permissions to set.
*/
function setPermission($role, $permissions) {
// Get role id (rid) for specified role.
$rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", array('%s' => $role)));
if ($rid === FALSE) {
$this->fail(t(' [permission] Role "' . $role . '" not found.'));
}
// Create edit array from permission.
$edit = array();
foreach ($permissions as $name => $value) {
$edit[$rid . '[' . $name . ']'] = $value;
}
$this->drupalPost('admin/user/permissions', $edit, t('Save permissions'));
$this->assertText(t('The changes have been saved.'), t(' [permission] Saved changes.'));
}
}

View file

@ -0,0 +1,177 @@
# $Id: uk.po,v 1.1.2.2 2009/05/18 21:52:00 podarok Exp $
#
# Ukrainian translation of Drupal (general)
# Copyright YEAR NAME <EMAIL@ADDRESS>
# Generated from files:
# better-formats-defaults-admin-form.tpl.php,v 1.3.2.2 2009/03/17 08:16:52 dragonwize
# better_formats_defaults.admin.inc,v 1.3.2.5 2009/03/17 08:16:52 dragonwize
# better_formats_settings.admin.inc,v 1.6.2.3 2009/02/25 06:44:17 dragonwize
# better_formats.module,v 1.23.2.9 2009/03/18 15:24:30 dragonwize
# better_formats.info,v 1.1.2.2 2009/02/25 06:44:17 dragonwize
#
msgid ""
msgstr ""
"Project-Id-Version: better_formats uk Ukrainian Translation\n"
"POT-Creation-Date: 2009-05-19 00:12+0300\n"
"PO-Revision-Date: 2009-05-19 00:40+0200\n"
"Last-Translator: podarok <podarok@ua.fm>\n"
"Language-Team: uk <podarok@ua.fm>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: Ukrainian\n"
"X-Poedit-Country: UKRAINE\n"
"X-Poedit-SourceCharset: utf-8\n"
#: better-formats-defaults-admin-form.tpl.php:24
msgid "Only formats that a role has permission to use are shown."
msgstr "Відображаються лише доступні для ролі формати"
#: better-formats-defaults-admin-form.tpl.php:26
msgid "Node Defaults"
msgstr "Базове для Нод"
#: better-formats-defaults-admin-form.tpl.php:30;54
msgid "Role"
msgstr "Роль"
#: better-formats-defaults-admin-form.tpl.php:31;55
msgid "Default Format"
msgstr "Базовий формат"
#: better-formats-defaults-admin-form.tpl.php:32;56
msgid "Weight"
msgstr "Вага"
#: better-formats-defaults-admin-form.tpl.php:50
msgid "Comment Defaults"
msgstr "Базове для коментарів"
#: better_formats_defaults.admin.inc:30
msgid "Save defaults"
msgstr "Зберегти базово"
#: better_formats_defaults.admin.inc:59
msgid "Role does not have access to selected format."
msgstr "Роль немає доступу до обраного формату"
#: better_formats_defaults.admin.inc:84
msgid "Defaults have been saved."
msgstr "Базові параметри збережено"
#: better_formats_defaults.admin.inc:171
msgid "Site default"
msgstr "Базове для сайту"
#: better_formats_settings.admin.inc:19
msgid "Display"
msgstr "Відображення"
#: better_formats_settings.admin.inc:24
msgid "Selection title"
msgstr "Вибір назви"
#: better_formats_settings.admin.inc:25
msgid "Change the format selection title. Defaults to \"Input format\""
msgstr "Змінити заголовок вибору формату. Базово \"Формат вводу\""
#: better_formats_settings.admin.inc:30
msgid "More format tips link text"
msgstr "Текст посилання \"Більше форматів\""
#: better_formats_settings.admin.inc:31
msgid "Change the format full tips link text. Defaults to \"More information about formatting options\""
msgstr "Змінити текст посилання \"інформація про формати\". Базово \"Більше інформації про можливості форматування\""
#: better_formats_settings.admin.inc:37
msgid "Control"
msgstr "Керування"
#: better_formats_settings.admin.inc:41
msgid "Control formats per node type"
msgstr "Керування форматами в залежності вид типу матеріалу"
#: better_formats_settings.admin.inc:42
msgid "Control formats allowed and default formats per node type. Global settings will be used until a content type admin page is saved."
msgstr "Керування форматами дозволено і базово формати залежать від типу матеріалу. Глобальні параметри будуть використані до моменту збереження адміністратором типу матеріалу."
#: better_formats.module:18
msgid "See the module README.txt file in the better_formats module directory for help."
msgstr "Читайте README.txt модуля better_formats для додаткової допомоги"
#: better_formats.module:22
msgid "Set the global default formats per role for NEW nodes and comments. These settings will be applied to all nodes and comments in the site unless overriden by specific content type defaults."
msgstr "Встановлення глобально базових форматів в залежності від ролі для нових матеріалів та коментарів. Ці параметрі будуть використані до всіх матеріалів та коментарів до моменту переназначення базово для специфічних типів матеріалів."
#: better_formats.module:23
msgid "Arrange the roles to provide weight that will determine what format is selected when a user has more than one role. Remember, that all logged in users are automatically given the authenticated user role in addition to their other assigned roles. For example, if you have an admin role place it at the top and generally you would want your anonymous user role at the bottom."
msgstr "Розміщення ролей для надання ваги, що буде визначати який формат обрано, якщо в користувача є кілька ролей. Пам'ятайте, що всі залоговані користувачі автоматично є \"зареєстрованими ролями\" на додаток до їхніх назначених ролей. Для прикладу, якщо Ви помістите роль адміна на верх списка, то роль анонімного користувача потрібно розташовувати в самому низу."
#: better_formats.module:153
msgid "Input format settings"
msgstr "Параметри формату вводу"
#: better_formats.module:164
msgid "Allowed formats"
msgstr "Дозволені формати"
#: better_formats.module:167
msgid "Limit the formats users have to choose from even if they have permission to use that format. This will NOT allow a user to use a format they do not have access rights to use. It will only hide additional formats they do have access rights to. If no boxes are checked, all formats that the user has permission to use will be allowed."
msgstr "Обмеження форматів, дозволених користувачам, навіть якщо вони мають доступ використання. Це не дозволить користувачу використовувати формат, заборонений правами! Це лише приховає додаткові формати, які дозволено! Якщо не відмічено жодне - всі формати, що дозволені користувачу будуть увімкнені."
#: better_formats.module:503
msgid "Input format"
msgstr "Формат вводу"
#: better_formats.module:561;569
msgid "Formatting guidelines"
msgstr "Рекомендації щодо форматування"
#: better_formats.module:603
msgid "More information about formatting options"
msgstr "Детальніше про опції форматування"
#: better_formats.module:37
msgid "show format selection"
msgstr "показувати вібир формату"
#: better_formats.module:38
msgid "show format tips"
msgstr "показувати підказки для формату"
#: better_formats.module:39
msgid "show more format tips link"
msgstr "показувати посилання \"більше форматів\""
#: better_formats.module:40
msgid "collapse format fieldset by default"
msgstr "базово - звернути поле форматів"
#: better_formats.module:41
msgid "collapsible format selection"
msgstr "вибір форматів - з можливістю звертання"
#: better_formats.module:52
msgid "Settings"
msgstr "Налаштування"
#: better_formats.module:53;63
msgid "Manage input formats"
msgstr "Керування форматами вводу"
#: better_formats.module:62
msgid "Defaults"
msgstr "Базове"
#: better_formats.module:0
msgid "better_formats"
msgstr "better_formats"
#: better_formats.info:0
msgid "Better Formats"
msgstr "Вдосконалені Формати"
#: better_formats.info:0
msgid "Enhances the core input format system by managing input format defaults and settings."
msgstr "Розширює базову систему форматів можливістю керування вхідними форматами і параметрами"