updated core to 7.58 (right after the site was hacked)

This commit is contained in:
2018-04-20 23:48:40 +02:00
parent 18f4aba146
commit 9344a61b61
711 changed files with 99690 additions and 480 deletions

View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@@ -0,0 +1,124 @@
VERSION: 7.x-1.x development build
OVERVIEW
--------
Tac_lite stands for Taxonomy Access Control Lite. This module
grants access so that some users may see content that is
hidden from others. A simple scheme based on taxonomy, roles and
users controls which content is hidden.
Bear in mind that, like all modules which use Drupal's built-in
node_access features, this module does not prevent users from
viewing/editing nodes which Drupal's permission allow them to
view/edit. To use, configure Drupal to not grant the permission, then
configure tac_lite to grant it.
As the name implies, this module shares some functionality with an
earlier module called Taxonomy Access Control (TAC). If you are
shopping around for an access control module to use, consider that one
as you may find that it suits your needs. In my case, I wanted access
control but without some of the complexity introduced by TAC. I also
wanted more flexibility in granting access on a per user basis.
Here are some key features of tac_lite:
* Designed to be as simple as possible in installation and administration.
* Uses Drupal's node_access hooks and taxonomy module to leave the
smallest possible footprint while doing it's job. For example, it
introduces no new database tables.
* Grant permissions based on roles.
* Grant permissions per user. (Give a specific user access beyond
what his/her roles allow).
* Supports view, update and delete permissions.
USE CASE
--------
Here's how I originally used this module. This description might make
it easier to understand why one might prefer tac_lite over TAC.
My website helps me manage my work projects. I use Drupal's project
module to track issues. Some of my projects are for the public to see
(i.e. Drupal modules) others are limited to my clients and partners.
These restricted projects should be visible only to me, the client in
question, and partner(s) working on that particular project.
I've defined a vocabulary for my projects (same one used by
project.module) and I've defined a client role and a partner role.
Partners can contribute to the website, while clients can read content
but post only issues.
Using TAC (or as far as I know all other access control modules) I
would have to create a new role for each project/role combination.
That is, for the Acme project I'd have to create roles 'Acme Client'
and 'Acme Partner' in order to assign permissions just the way I want
them.
Using tac_lite, I simply associate each user with the project(s) they
are allowed to see. That is, I associate some clients and some
partners with Acme. Their role (client or partner) controls what they
can do, and the associations through tac_lite control what they can
see.
INSTALL
-------
Enable taxonomy module. It's required.
Install this package the normal way.
- put this file in a subdirectory of the modules directory.
- enable using admin interface
- no database tables to install.
USAGE
-----
Log in as an administrator. (uid==1, or a user with
administer_tac_lite permission)
Create a vocabulary which you will use to categorize private nodes.
You may want to create a vocabulary called "Privacy" with terms like
"public", "private", and "administers only".
Associate the vocabulary with node types, as you would normally do.
Go to administer >> user management >> access control >> access
control by taxonomy.
Select the category you created in the earlier step ("Privacy").
Create some content. Choose a node type you've associated with "Privacy".
Note that you can view the content you just created. Other users cannot.
Edit the account of another user. Go to the tac_lite access tab under edit.
Select a term you selected when creating the node and submit changes.
Now the user can also access the node you created.
NOTES
-----
If behavior of this or any other access control module seems to be
incorrect, try rebuilding the node access table. This may be done
under administer >> content management >> post settings. There is a
button there labelled "rebuild permissions"
Another useful tool is a sub-module of the devel module, called
devel_node_access which can give you some insight into the contents of
your node_access table. Recommended for troubleshooting.
AUTHOR
------
Dave Cohen <http://drupal.org/user/18468>
http://www.dave-cohen.com

View File

@@ -0,0 +1,11 @@
name = Taxonomy Access Control Lite
description = Simple access control based on categories.
dependencies[] = taxonomy
core = 7.x
package = Access control
; Information added by Drupal.org packaging script on 2015-10-11
version = "7.x-1.2+2-dev"
core = "7.x"
project = "tac_lite"
datestamp = "1444524081"

View File

@@ -0,0 +1,118 @@
<?php
/**
* @file
* Installation functions for tac_lite.
* TODO: All updates need proper error handling and responses
*/
/**
* Implementation of hook_install().
*
* Ensure that tac_lite hooks are invoked after taxonomy module hooks.
*/
function tac_lite_install() {
$taxonomy_weight = db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'")->fetchField();
$num_updated = db_update('system')
->fields(array(
'weight' => $taxonomy_weight + 9,
))
->condition('name', 'tac_lite')
->execute();
// Note that it is not necessary to rebuild the node access table here, as
// that will be done when module settings are saved.
}
/**
* Implements hook_uninstall().
*
* Clean up tac_lite variables.
*/
function tac_lite_uninstall() {
for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
variable_del('tac_lite_config_scheme_' . $i);
variable_del('tac_lite_grants_scheme_' . $i);
}
variable_del('tac_lite_schemes');
variable_del('tac_lite_categories');
}
/**
* Ensure that tac_lite hooks are invoked after taxonomy module hooks.
*/
function tac_lite_update_1() {
$taxonomy_weight = db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'")->fetchField();
$num_updated = db_update('system')
->fields(array(
'weight' => $taxonomy_weight + 9,
))
->condition('name', 'tac_lite')
->execute();
}
/**
* Ensure that the node_access table is thoroughly cleaned up in Drupal 5 update.
*/
function tac_lite_update_2() {
node_access_rebuild(); // Would batch mode help here?
// Assume success and return with message.
return t('Rebuilt node access table for tac_lite module.');
}
/**
* Introducing schemes. Rename tac_lite_default_grants to tac_lite_grants_scheme_1.
*/
function tac_lite_update_3() {
$num_updated = db_update('variable')
->fields(array(
'name' => 'tac_lite_grants_scheme_1',
))
->condition('name', 'tac_lite_default_grants')
->execute();
}
/**
* Start of updates to Drupal 6.x-1.2. Start using Drupal standard
* update numbers.
*/
/**
* Rename permission from "administer_tac_lite" to "administer
* tac_lite" for UI consistency.
*/
function tac_lite_update_6001() {
// TODO: Please review to make sure this is handling this update properly for this version of code. (only change was formatting and table name)
$result = db_query("SELECT * FROM {role_permission} WHERE perm LIKE '%administer_tac_lite%'");
foreach ($result as $permission) {
$perm = str_replace('administer_tac_lite', 'administer tac_lite', $permission->perm);
//db_query("UPDATE {permission} SET perm = '". db_escape_string($perm) ."' WHERE rid =". $permission->rid);
$num_updated = db_update('permission')
->fields(array(
'perm' => $perm,
))
->condition('rid', $permission->rid)
->execute();
}
}
/**
* The tac_lite.module now supports an option to apply access by taxonomy to unpublished nodes as well as published content. The default behavior is that tac_lite has no effect on unpublished content. You should review each of your tac_lite schemes and, optionally, adjust this setting before rebuilding node access permissions.
*/
function tac_lite_update_7001() {
// See https://drupal.org/node/1918272 for details.
drupal_set_message(t('Please review each of your <a href="!url">taxonomy access control schemes</a>. If necessary, adjust the new option to affect access to unpublished content. Then rebuild content access permissions.', array(
'!url' => url('admin/config/people/tac_lite'),
)));
node_access_needs_rebuild(TRUE);
}
/**
* Rebuild node_access permissions, for sites upgrading from tac_lite 1.0 (or
* 1.1) to 1.2. This will fix a bug in which some nodes were erroneously added
* to the node_access table. You will be prompted to rebuild access permissions
* after the update process is complete. (See the status report page.)
*/
function tac_lite_update_7002() {
node_access_needs_rebuild(TRUE);
}

View File

@@ -0,0 +1,735 @@
<?php
/**
* @file
* Control access to site content based on taxonomy, roles and users.
*
*
*/
/**
* Implementation of hook_help().
*/
function tac_lite_help($section) {
switch ($section) {
case 'admin/help#tac_lite':
// $output .= '<p>' . t('') . '</p>';
$output = '<p>' . t('Taxonomy Access Control Lite allows you to restrict access to site content. It uses a simple scheme based on Taxonomy, Users and Roles.') . '</p>';
$output .= '<p>' . t('This module leverages Drupal\'s node_access table allows this module to grant permission to view, update, and delete nodes. To control which users can <em>create</em> new nodes, use Drupal\'s role based permissions.') . '</p>';
$output .= '<p>' . t('It is important to understand that this module <em>grants</em> privileges, as opposed to <em>revoking</em> privileges. So, use Drupal\'s built-in permissions to hide content from certain roles, then use this module to show the content. This module cannot hide content that the user is allowed to see based on their existing privileges.') . '</p>';
$output .= '<p>' . t('There are several steps required to set up Taxonomy Access Control Lite.') . '</p>';
$output .= '<ol>';
$output .= '<li>' . t('Define one or more vocabularies whose terms will control which users have access. For example, you could define a vocabulary called \'Privacy\' with terms \'Public\' and \'Private\'.') . '</li>';
$output .= '<li>' . t('Tell this module which vocabularies control privacy. (!link)', array('!link' => l(t('administer -> people -> access control by taxonomy'), 'admin/people/access/tac_lite'))) . '</li>';
$output .= '<li>' . t('Configure one or more <em>schemes</em>. simple site may need only one scheme which grants view permission. A more complex site might require additional schemes for update and delete. Each scheme associates roles and terms. Users will be granted priviliges based on their role and the terms with which nodes are tagged.') . '</li>';
$output .= '<li>' . t('When settings are correct, <a href=!url>rebuild node_access permissions</a>.', array(
'!url' => url('admin/reports/status/rebuild'),
)) . '</li>';
$output .= '<li>' . t('Optionally, grant access to individual users. (See the <em>access by taxonomy</em> tab, under user -> edit.)') . '</li>';
$output .= '</ol>';
$output .= '<p>' . t('Troubleshooting:.') . '<ul>';
$output .= '<li>' . t('Try rebuilding node_access permissions.') . '</li>';
$output .= '<li>' . t('Try disabling tac_lite.module, rebuilding permissions. With the module disabled, users should not have the privileges you are attempting to grant with this module.') . '</li>';
$output .= '<li>' . t('The devel_node_access.module (part of <a href=!url>devel</a>) helps to see exactly what Drupal\'s node_access table is doing.', array(
'!url' => 'http://drupal.org/project/devel',
)) . '</li>';
$output .= '</ul></p>';
return $output;
break;
}
}
/**
* Implementation of hook_perm().
*/
function tac_lite_permission() {
return array(
'administer tac_lite' => array(
'title' => t('administer tac_lite'),
'description' => t('TODO Add a description for \'administer tac_lite\''),
),
);
}
/**
* Implementation of hook_menu().
*/
function tac_lite_menu() {
global $user;
$items = array();
$items['admin/config/people/tac_lite'] = array(
'title' => 'Access by Taxonomy',
'description' => "taxonomy-based permissions by tac_lite",
'page callback' => 'drupal_get_form',
'page arguments' => array('tac_lite_admin_settings'),
'weight' => 1, // after 'roles' tab
'access arguments' => array('administer tac_lite'),
);
$items['admin/config/people/tac_lite/settings'] = array(
'title' => 'Settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
'access arguments' => array('administer tac_lite'),
);
$schemes = variable_get('tac_lite_schemes', 1);
for ($i = 1; $i <= $schemes; $i++) {
$scheme = variable_get('tac_lite_config_scheme_'. $i, FALSE);
if ($scheme) {
$title = $scheme['name'];
} else {
$title = "Scheme $i";
}
$items['admin/config/people/tac_lite/scheme_' . $i] = array(
'title' => $title,
'page callback' => 'tac_lite_admin_settings_scheme',
'page arguments' => array((string)$i),
'type' => MENU_LOCAL_TASK,
'weight' => $i,
'access arguments' => array('administer tac_lite'),
);
}
return $items;
}
/**
* Returns the settings form
*/
function tac_lite_admin_settings($form, &$form_state) {
$vocabularies = taxonomy_get_vocabularies();
if (!count($vocabularies)) {
$form['body'] = array(
'#type' => 'markup',
'#markup' => t('You must <a href="!url">create a vocabulary</a> before you can use tac_lite.',
array('!url' => url('admin/structure/taxonomy/add/vocabulary'))),
);
return $form;
}
else {
$options = array();
foreach ($vocabularies as $vid => $vocab) {
$options[$vid] = $vocab->name;
}
$form['tac_lite_categories'] = array(
'#type' => 'select',
'#title' => t('Vocabularies'),
'#default_value' => variable_get('tac_lite_categories', NULL),
'#options' => $options,
'#description' => t('Select one or more vocabularies to control privacy. <br/>Use caution with hierarchical (nested) taxonomies as <em>visibility</em> settings may cause problems on node edit forms.<br/>Do not select free tagging vocabularies, they are not supported.'),
'#multiple' => TRUE,
'#required' => TRUE,
);
$scheme_options = array();
// Currently only view, edit, delete permissions possible, so 7
// permutations will be more than enough.
for ($i = 1; $i < 8; $i++)
$scheme_options[$i] = $i;
$form['tac_lite_schemes'] = array(
'#type' => 'select',
'#title' => t('Number of Schemes'),
'#description' => t('Each scheme allows for a different set of permissions. For example, use scheme 1 for read-only permission; scheme 2 for read and update; scheme 3 for delete; etc. Additional schemes increase the size of your node_access table, so use no more than you need.'),
'#default_value' => variable_get('tac_lite_schemes', 1),
'#options' => $scheme_options,
'#required' => TRUE,
);
$form['tac_lite_rebuild'] = array(
'#type' => 'checkbox',
'#title' => t('Rebuild content permissions now'),
'#default_value' => FALSE, // default false because usually only needed after scheme has been changed.
'#description' => t('Do this once, after you have fully configured access by taxonomy.'),
'#weight' => 9,
);
$ret = system_settings_form($form);
// Special handling is required when this form is submitted.
$ret['#submit'][] = '_tac_lite_admin_settings_submit';
return $ret;
}
}
/**
* This form submit callback ensures that the form values are saved, and also
* the node access database table is rebuilt.
* 2008 : Modified by Paulo to be compliant with drupal 6
*/
function _tac_lite_admin_settings_submit($form, &$form_state) {
$rebuild = $form_state['values']['tac_lite_rebuild'];
// Rebuild the node_access table.
if ($rebuild) {
node_access_rebuild(TRUE);
}
else {
drupal_set_message(t('Do not forget to <a href=!url>rebuild node access permissions</a> after you have configured taxonomy-based access.', array(
'!url' => url('admin/reports/status/rebuild'),
)), 'warning');
}
// And rebuild menus, in case the number of schemes has changed.
menu_rebuild();
variable_del('tac_lite_rebuild'); // We don't need to store this as a system variable.
}
/**
* Menu callback to create a form for each scheme.
* @param $i
* The index of the scheme that we will be creating a form for. Passed in as a page argument from the menu.
*/
function tac_lite_admin_settings_scheme($i) {
return drupal_get_form('tac_lite_admin_scheme_form', $i);
}
/**
* helper function
*/
function _tac_lite_config($scheme) {
// different defaults for scheme 1
if ($scheme === 1) {
$config = variable_get('tac_lite_config_scheme_' . $scheme, array(
'name' => t('read'),
'perms' => array('grant_view'),
));
}
else {
$config = variable_get('tac_lite_config_scheme_' . $scheme, array(
'name' => NULL,
'perms' => array(),
));
}
// Merge defaults, for backward compatibility.
$config += array(
'term_visibility' => (isset($config['perms']['grant_view']) && $config['perms']['grant_view']),
'unpublished' => FALSE,
);
// For backward compatability, use naming convention for scheme 1
if ($scheme == 1) {
$config['realm'] = 'tac_lite';
}
else {
$config['realm'] = 'tac_lite_scheme_' . $scheme;
}
return $config;
}
/**
* Returns the form for role-based privileges.
*/
function tac_lite_admin_scheme_form($form, $form_state, $i) {
$vids = variable_get('tac_lite_categories', NULL);
$roles = user_roles();
$config = _tac_lite_config($i);
$form['#tac_lite_config'] = $config;
if (count($vids)) {
$form['tac_lite_config_scheme_' . $i] = array('#tree' => TRUE);
$form['tac_lite_config_scheme_' . $i]['name'] = array(
'#type' => 'textfield',
'#title' => t('Scheme name'),
'#description' => t('A human-readable name for administrators to see. For example, \'read\' or \'read and write\'.'),
'#default_value' => $config['name'],
'#required' => TRUE,
);
// Currently, only view, update and delete are supported by node_access
$options = array(
'grant_view' => 'view',
'grant_update' => 'update',
'grant_delete' => 'delete',
);
$form['tac_lite_config_scheme_' . $i]['perms'] = array(
'#type' => 'select',
'#title' => t('Permissions'),
'#multiple' => TRUE,
'#options' => $options,
'#default_value' => $config['perms'],
'#description' => t('Select which permissions are granted by this scheme. <br/>Note when granting update, it is best to enable visibility on all terms. Otherwise a user may unknowingly remove invisible terms while editing a node.'),
'#required' => FALSE,
);
$form['tac_lite_config_scheme_' . $i]['unpublished'] = array(
'#type' => 'checkbox',
'#title' => t('Apply to unpublished content'),
'#description' => t('If checked, permissions in this scheme will apply to unpublished content. If this scheme includes the view permission, then <strong>unpublished nodes will be visible</strong> to users whose roles would grant them access to the published node.'),
'#default_value' => $config['unpublished'],
);
$form['tac_lite_config_scheme_' . $i]['term_visibility'] = array(
'#type' => 'checkbox',
'#title' => t('Visibility'),
'#description' => t('If checked, this scheme determines whether a user can view <strong>terms</strong>. Note the <em>view</em> permission in the select field above refers to <strong>node</strong> visibility. This checkbox refers to <strong>term</strong> visibility, for example in a content edit form or tag cloud.'),
'#default_value' => $config['term_visibility'],
);
$form['helptext'] = array(
'#type' => 'markup',
'#markup' => t('To grant to an individual user, visit the <em>access by taxonomy</em> tab on the account edit page.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
);
$form['helptext2'] = array(
'#type' => 'markup',
'#markup' => t('To grant by role, select the terms below.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
);
$vocabularies = taxonomy_get_vocabularies();
$all_defaults = variable_get('tac_lite_grants_scheme_' . $i, array());
$form['tac_lite_grants_scheme_' . $i] = array('#tree' => TRUE);
foreach ($roles as $rid => $role_name) {
$form['tac_lite_grants_scheme_' . $i][$rid] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => check_plain(t('Grant permission by role: !role', array('!role' => $role_name))),
'#description' => t(''),
'#collapsible' => TRUE,
);
$defaults = isset($all_defaults[$rid]) ? $all_defaults[$rid] : NULL;
foreach ($vids as $vid) {
// Build a taxonomy select form element for this vocab
$v = $vocabularies[$vid];
$tree = taxonomy_get_tree($v->vid);
$options = array(0 => '<' . t('none') . '>');
if ($tree) {
foreach ($tree as $term) {
$choice = new stdClass();
$choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
$options[] = $choice;
}
}
$default_values = isset($defaults[$vid]) ? $defaults[$vid] : NULL;
$form['tac_lite_grants_scheme_' . $i][$rid][$vid] = _tac_lite_term_select($v, $default_values);
}
}
$form['tac_lite_rebuild'] = array(
'#type' => 'checkbox',
'#title' => t('Rebuild content permissions now'),
'#default_value' => FALSE, // default false because usually only needed after scheme has been changed.
'#description' => t('Do this once, after you have fully configured access by taxonomy.'),
'#weight' => 9,
);
$form['#submit'][] = 'tac_lite_admin_scheme_form_submit';
return system_settings_form($form);
}
else {
$form['tac_lite_help'] = array(
'#type' => 'markup',
'#prefix' => '<p>', '#suffix' => '</p>',
'#markup' => t('First, select one or more vocabularies on the <a href=!url>settings tab</a>. Then, return to this page to complete configuration.', array('!url' => url('admin/config/people/tac_lite/settings'))));
return $form;
}
}
/**
* Submit function for admin settings form to rebuild the menu.
*/
function tac_lite_admin_scheme_form_submit($form, &$form_state) {
variable_set('menu_rebuild_needed', TRUE);
// Rebuild the node_access table.
if ($form_state['values']['tac_lite_rebuild']) {
node_access_rebuild(TRUE);
}
else {
drupal_set_message(t('Do not forget to <a href=!url>rebuild node access permissions</a> after you have configured taxonomy-based access.', array(
'!url' => url('admin/reports/status/rebuild'),
)), 'warning');
}
variable_del('tac_lite_rebuild'); // We don't need to store this as a system variable.
}
/**
* Implementation of hook_user_categories
*
* Creates the user edit category form for tac_lite's user-specific permissions under user/edit
*/
function tac_lite_user_categories() {
return array(
array(
'name' => 'tac_lite',
'title' => t('Access by taxonomy'),
'weight' => 5,
'access callback' => 'user_access',
'access arguments' => array('administer users'),
),
);
}
/**
* Implementation of hook_form_alter().
*
* @param $form
* Nested array of form elements that comprise the form.
* @param $form_state
* A keyed array containing the current state of the form. The arguments that drupal_get_form() was originally called with are available in the array $form_state['build_info']['args'].
* @param $form_id
* String representing the name of the form itself. Typically this is the name of the function that generated the form.
*
*/
function tac_lite_form_alter(&$form, &$form_state, $form_id){
// Catch for the tac_lite category on the user edit form.
if ($form_id == 'user_profile_form') {
if ($form['#user_category'] == 'tac_lite') {
$vocabularies = taxonomy_get_vocabularies();
$vids = variable_get('tac_lite_categories', NULL);
if (count($vids)) {
for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
$config = _tac_lite_config($i);
if ($config['name']) {
$perms = $config['perms'];
if ($config['term_visibility']) {
$perms[] = t('term visibility');
}
$form['tac_lite'][$config['realm']] = array(
'#type' => 'fieldset',
'#title' => $config['name'],
'#description' => t('This scheme controls %perms.', array('%perms' => implode(' and ', $perms))),
'#tree' => TRUE,
);
// Create a form element for each vocabulary
foreach ($vids as $vid) {
$v = $vocabularies[$vid];
// TODO: Should we be looking in form_state also for the default value?
// (Might only be necessary if we are adding in custom validation?)
$default_values = array();
if (!empty($form['#user']->data[$config['realm']])) {
if (isset($form['#user']->data[$config['realm']][$vid])) {
$default_values = $form['#user']->data[$config['realm']][$vid];
}
}
$form['tac_lite'][$config['realm']][$vid] = _tac_lite_term_select($v, $default_values);
$form['tac_lite'][$config['realm']][$vid]['#description'] =
t('Grant permission to this user by selecting terms. Note that permissions are in addition to those granted based on user roles.');
}
}
}
$form['tac_lite'][0] = array(
'#type' => 'markup',
'#markup' => '<p>' . t('You may grant this user access based on the schemes and terms below. These permissions are in addition to <a href="!url">role based grants on scheme settings pages</a>.',
array('!url' => url('admin/config/people/tac_lite/scheme_1'))) . "</p>\n",
'#weight' => -1,
);
}
else {
// TODO: Do we need to handle the situation where no vocabularies have been set up yet / none have been assigned to tac_lite?
}
return $form;
}
}
}
/**
* Implementation of hook_user_presave().
*
* Move the tac_lite data into the data object
* @param $edit
* The array of form values submitted by the user.
* @param $account
* The user object on which the operation is performed.
* @param $category
* The active category of user information being edited.
*/
function tac_lite_user_presave(&$edit, $account, $category) {
// Only proceed if we are in the tac_lite category.
if ($category == 'tac_lite'){
// Go through each scheme and copy the form value into the data element
for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
$config = _tac_lite_config($i);
if ($config['name']) {
$edit['data'][$config['realm']] = $edit[$config['realm']];
}
}
}
}
/**
* Implements hook_node_access_records().
*
* We are given a node and we return records for the node_access table. In
* our case, we inpect the node's taxonomy and grant permissions based on the
* terms.
*/
function tac_lite_node_access_records($node) {
// Get the tids we care about that are assigned to this node
$tids = _tac_lite_get_terms($node);
if (!count($tids)) {
// no relevant terms found.
// in drupal 4-7 we had to write a row into the database. In drupal 5 and later, it should be safe to do nothing.
}
else {
// if we're here, the node has terms associated with it which restrict
// access to the node.
$grants = array();
for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
$config = _tac_lite_config($i);
// Only apply grants to published nodes, or unpublished nodes if requested in the scheme
if ($node->status || $config['unpublished']) {
foreach ($tids as $tid) {
$grant = array(
'realm' => $config['realm'],
'gid' => $tid, // use term id as grant id
'grant_view' => 0,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 0,
);
foreach ($config['perms'] as $perm) {
$grant[$perm] = TRUE;
}
$grants[] = $grant;
}
}
}
return $grants;
}
}
/**
* Gets terms from a node that belong to vocabularies selected for use by tac_lite
*
* @param $node
* A node object
* @return
* An array of term ids
*/
function _tac_lite_get_terms($node) {
$tids = array();
// Get the vids that tac_lite cares about.
$vids = variable_get('tac_lite_categories', NULL);
if ($vids) {
// Load all terms found in term reference fields.
// This logic should work for all nodes (published or not).
$terms_by_vid = tac_lite_node_get_terms($node);
if (!empty($terms_by_vid)) {
foreach ($vids as $vid) {
if (!empty($terms_by_vid[$vid])) {
foreach ($terms_by_vid[$vid] as $tid => $term) {
$tids[$tid] = $tid;
}
}
}
}
// The logic above should have all terms already, but just in case we use
// the "original" logic below. The taxonomy module stopped writing to the
// taxonomy_index for unpublished nodes, so this works only for published
// nodes.
$query = db_select('taxonomy_index', 'r');
$t_alias = $query->join('taxonomy_term_data', 't', 'r.tid = t.tid');
$v_alias = $query->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
$query->fields( $t_alias );
$query->condition("r.nid", $node->nid);
$query->condition("t.vid", $vids, 'IN');
$result = $query->execute();
foreach ($result as $term) {
if (empty($tids[$term->tid])) {
watchdog('tac_lite', 'Unexpected term id %tid associated with !node. Please report this to !url.', array(
'%tid' => $term->tid,
'!node' => l($node->title, 'node/' . $node->nid),
'!url' => 'https://drupal.org/node/1918272',
), WATCHDOG_DEBUG);
}
$tids[$term->tid] = $term->tid;
}
}
elseif (user_access('administer tac_lite')) {
drupal_set_message(t('tac_lite.module enabled, but not <a href=!admin_url>configured</a>. No tac_lite terms associated with %title.', array(
'!admin_url' => url('admin/config/people/tac_lite'),
'%title' => $node->title,
)));
}
return $tids;
}
/**
* In Drupal 6.x, there was taxonomy_node_get_terms(). Drupal 7.x should
* provide the same feature, but doesn't. Here is our workaround, based on
* https://drupal.org/comment/5573176#comment-5573176.
*
* We organize our data structure by vid and tid.
*/
function tac_lite_node_get_terms($node) {
$terms = &drupal_static(__FUNCTION__);
if (!isset($terms[$node->nid])) {
// Get tids from all taxonomy_term_reference fields.
$fields = field_info_fields();
foreach ($fields as $field_name => $field) {
// Our goal is to get all terms, regardless of language, associated with the node. Does the code below do that?
if ($field['type'] == 'taxonomy_term_reference' && field_info_instance('node', $field_name, $node->type)) {
if (($items = field_get_items('node', $node, $field_name)) && is_array($items)) {
foreach ($items as $item) {
// Sometimes $item contains only tid, sometimes entire term. Thanks Drupal for remaining mysterious!
// We need to term to determine the vocabulary id.
if (!empty($item['taxonomy_term'])) {
$term = $item['taxonomy_term'];
}
else {
$term = taxonomy_term_load($item['tid']);
}
if ($term) {
$terms[$node->nid][$term->vid][$term->tid] = $term;
}
}
}
}
}
}
return isset($terms[$node->nid]) ? $terms[$node->nid] : FALSE;
}
/**
* Helper function to build a taxonomy term select element for a form.
*
* @param $v
* A vocabulary object containing a vid and name.
* @param $default_values
* An array of values to use for the default_value argument for this form element.
*/
function _tac_lite_term_select($v, $default_values = array()) {
$tree = taxonomy_get_tree($v->vid);
$options = array(0 => '<' . t('none') . '>');
if ($tree) {
foreach ($tree as $term) {
$choice = new stdClass();
$choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
$options[] = $choice;
}
}
$field_array = array(
'#type' => 'select',
'#title' => $v->name,
'#default_value' => $default_values,
'#options' => $options,
'#multiple' => TRUE,
'#description' => $v->description,
);
return $field_array;
}
/**
* Return the term ids of terms this user is allowed to access.
*
* Users are granted access to terms either because of who they are,
* or because of the roles they have.
*/
function _tac_lite_user_tids($account, $scheme) {
// grant id 0 is reserved for nodes which were not given a grant id when they were created. By adding 0 to the grant id, we let the user view those nodes.
$grants = array(0);
$config = _tac_lite_config($scheme);
$realm = $config['realm'];
if (isset($account->data[$realm]) && count($account->data[$realm])) {
// $account->$realm is array. Keys are vids, values are array of tids within that vocabulary, to which the user has access
foreach ($account->data[$realm] as $tids) {
if (count($tids)) {
$grants = array_merge($grants, $tids);
}
}
}
// add per-role grants in addition to per-user grants
$defaults = variable_get('tac_lite_grants_scheme_' . $scheme, array());
foreach ($account->roles as $rid => $role_name) {
if (isset($defaults[$rid]) && count($defaults[$rid])) {
foreach ($defaults[$rid] as $tids) {
if (count($tids)) {
$grants = array_merge($grants, $tids);
}
}
}
}
// Because of some flakyness in the form API and the form we insert under
// user settings, we may have a bogus entry with vid set
// to ''. Here we make sure not to return that.
unset($grants['']);
return $grants;
}
/**
* Implementation of hook_node_grants().
*
* Returns any grants which may give the user permission to perform the
* requested op.
*/
function tac_lite_node_grants($account, $op) {
$grants = array();
for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
$config = _tac_lite_config($i);
if (in_array('grant_' . $op, $config['perms'])) {
$grants[$config['realm']] = _tac_lite_user_tids($account, $i);
}
}
if (count($grants)) {
return $grants;
}
}
/**
* Implements hook_query_TAG_alter().
*
* Acts on queries that list terms (generally these should be tagged with 'term_access')
* to remove any terms that this user should not be able to see.
*/
function tac_lite_query_term_access_alter(QueryAlterableInterface $query) {
global $user;
// If this user has administer rights, don't filter
if (user_access('administer tac_lite')) {
return;
}
// Get our vocabularies and schemes from variables. Return if we have none.
$vids = variable_get('tac_lite_categories', NULL);
$schemes = variable_get('tac_lite_schemes', 1);
if (!$vids || !count($vids) || !$schemes) {
return;
}
// the terms this user is allowed to see
$term_visibility = FALSE;
$tids = array();
for ($i = 1; $i <= $schemes; $i++) {
$config = _tac_lite_config($i);
if ($config['term_visibility']) {
$tids = array_merge($tids, _tac_lite_user_tids($user, $i));
$term_visibility = TRUE;
}
}
if ($term_visibility) {
// HELP: What is the proper way to find the alias of the primary table here?
$primary_table = '';
$t = $query->getTables();
foreach($t as $key => $info) {
if (!$info['join type']) {
$primary_table = $info['alias'];
}
}
// Prevent query from finding terms the current user does not have permission to see.
$query->leftJoin('taxonomy_term_data', 'tac_td', $primary_table . '.tid = tac_td.tid');
$or = db_or();
$or->condition($primary_table . '.tid', $tids, 'IN');
$or->condition('tac_td.vid', $vids, 'NOT IN');
$query->condition($or);
}
}

View File

@@ -0,0 +1,12 @@
name = Taxonomy Access Control Lite Create
description = Hide taxonomy terms on node add/edit forms.
dependencies[] = tac_lite
core = 7.x
package = Access control
; Information added by Drupal.org packaging script on 2015-10-11
version = "7.x-1.2+2-dev"
core = "7.x"
project = "tac_lite"
datestamp = "1444524081"

View File

@@ -0,0 +1,128 @@
<?php
/**
* @file
* Use tac_lite to control which terms can be used when creating new
* content. Unlike tac_lite.module, which relies on Drupal's node_access
* features, this module uses hook_form_alter to change which terms are
* presented by the taxonomy module.
*
* Original implementation by markDrupal http://drupal.org/user/93970.
*/
/**
* Implementation of hook_form_alter().
*/
function tac_lite_create_form_alter(&$form, $form_state, $form_id) {
if (strpos($form_id, 'node_form') !== FALSE) {
global $user;
if (user_access('administer tac_lite')) {
// no need to restrict based on update permission in this cases
return;
}
// the vocabularies containing protected info.
$vids = variable_get('tac_lite_categories', array(0));
// the terms this user is allowed to edit
$tids = array();
for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
$config = _tac_lite_config($i);
if ((isset($config['tac_lite_create']) && $config['tac_lite_create']) ||
in_array('grant_update', $config['perms'])) {
$tids = array_merge($tids, _tac_lite_user_tids($user, $i));
}
}
// Go through all of the fields in the system to find the ones we want use
$term_fields = array();
$info = field_info_fields();
foreach($info as $key => $value){
// First check for taxonomy_term_reference fields.
if ($value['type'] == 'taxonomy_term_reference') {
// Then check to see if they are associated with this node type (entity bundle).
if (isset($value['bundles']['node'])) {
if (in_array($form['#bundle'], $value['bundles']['node'])) {
// Add an entry to our term_fields in the form of field name => vocabulary machine name
$term_fields[$key] = $value['settings']['allowed_values'][0]['vocabulary'];
}
}
}
}
// Now that we have the names of the fields, go through each one in the form.
foreach($term_fields as $field_name => $vocab_name) {
// Get the language key so we can find the correct element in the field.
$field_language = $form[$field_name]['#language'];
// Avoid PHP errors
if (empty($form[$field_name]) || empty($form[$field_name][$field_language])) {
continue;
}
// Skip auto complete fields as they are not supported.
if ($form[$field_name][$field_language]['#type'] != 'select' && $form[$field_name][$field_language]['#type'] != 'radios'){
continue;
}
// Get the vocabulary info so we can get the vid.
$v = taxonomy_vocabulary_machine_name_load($vocab_name);
// We only want to act on this field if it is tied to a vocabulary we are set to control.
if(!in_array($v->vid, $vids)) {
continue;
}
// Go through each option for this field.
foreach ($form[$field_name][$field_language]['#options'] as $term_id => $term_name) {
// Skip the "<none>" option (or anything like it).
if (!is_numeric($term_id)) {
continue;
}
// Is this option not in the list of terms this user can create with?
if (!in_array($term_id, $tids)) {
// The term is not the default value, and user is not allowed to create with it.
// HELP: What if it IS the default value? Do we not unset it?
if ($term_id != $form[$field_name][$field_language]['#default_value']) {
// Unset the option to it doesn't appear.
// TODO: It would be a nice feature to have tids that are already selected.
// go into a value element so we could merge then when saving the node.
unset($form[$field_name][$field_language]['#options'][$term_id]);
}
}
}
// If there are no options left, but this field is required then throw a 404.
if (count($form[$field_name][$field_language]['#options']) == 0 && !empty($form[$field_name]['#required'])) {
drupal_set_message(t('You have no permissions to add content to the required %name vocabulary. Please contact the site administrator if you believe you should have permission to add content.', array('%name' => $form[$field_name]['#title'])));
drupal_access_denied();
exit();
}
// Don't show if the only option left is <none>.
if (empty($form[$field_name][$field_language]['#options']) ||
(count($form[$field_name][$field_language]['#options']) == 1 && isset($form[$field_name][$field_language]['#options']['_none']))) {
$form[$field_name]['#access'] = FALSE;
}
// HELP: Is size deprecated?
/*
if (isset($form[$field_name]['#size']) && $form[$field_name]['#size'] > count($form['taxonomy'][$field_language]['#options'])) {
$form[$field_name]['#size'] = count($form[$field_name][$field_language]['#options']);
}
*/
}
}
elseif ($form_id == 'tac_lite_admin_scheme_form') {
$config = $form['#tac_lite_config'];
$scheme = $form_state['build_info']['args'][0];
if (!empty($form['tac_lite_config_scheme_' . $scheme])) {
$form['tac_lite_config_scheme_' . $scheme]['tac_lite_create'] = array(
'#type' => 'checkbox',
'#title' => 'Visibility on create and edit forms',
'#default_value' => isset($config['tac_lite_create']) ? $config['tac_lite_create'] : FALSE,
'#description' => t('Show terms when creating content. This <strong>does not</strong> control which users can create a given content type. This <strong>does</strong> control which terms appear on the node edit forms. <br/>Note that schemes granting <em>update</em> permission (above) imply <em>visibility on forms</em> as well.'),
);
}
}
}