FINAL suepr merge step : added all modules to this super repos

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 16:46:59 +02:00
7585 changed files with 1723356 additions and 18 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,182 @@
<?php
/**
* @file
* Provides form with AJAX REGISTER module settings.
*/
/**
* Administrative settings form.
*/
function ajax_register_admin_form($form, $form_state) {
$form['ajax_register_modal'] = array(
'#type' => 'fieldset',
'#title' => t('Modal window settings'),
);
$form['ajax_register_modal']['ajax_register_modal_width'] = array(
'#type' => 'textfield',
'#title' => t('Modal window width'),
'#size' => 4,
'#field_suffix' => 'px',
'#default_value' => variable_get('ajax_register_modal_width', 550),
);
$form['ajax_register_modal']['ajax_register_modal_background_opacity'] = array(
'#type' => 'select',
'#title' => t('Background opacity'),
'#options' => array(
'0' => '0%',
'0.1' => '10%',
'0.2' => '20%',
'0.3' => '30%',
'0.4' => '40%',
'0.5' => '50%',
'0.6' => '60%',
'0.7' => '70%',
'0.8' => '80%',
'0.9' => '90%',
'1' => '100%',
),
'#default_value' => variable_get('ajax_register_modal_background_opacity', '0.7'),
);
$form['ajax_register_modal']['ajax_register_modal_background_color'] = array(
'#type' => 'textfield',
'#title' => t('Background color'),
'#size' => 6,
'#maxlength' => 6,
'#field_prefix' => '#',
'#default_value' => variable_get('ajax_register_modal_background_color', '000000'),
);
$form['ajax_register_modal']['ajax_register_hide_captcha'] = array(
'#type' => 'checkbox',
'#title' => t('Hide captcha in modal dialog'),
'#description' => t('Capctha protects your site from spambots.
But they have no js enabled, so spambots will never see modal dialog and will be redirected to normal login/register form with captcha.'),
'#default_value' => variable_get('ajax_register_hide_captcha', FALSE),
);
if (!module_exists('captcha')) {
$form['ajax_register_modal']['ajax_register_hide_captcha']['#disabled'] = TRUE;
$form['ajax_register_modal']['ajax_register_hide_captcha']['#title'] .= ' (' . t('requires CAPTCHA module') . ')';
}
$form['ajax_register_forms'] = array(
'#type' => 'fieldset',
'#title' => t('Form settings'),
);
$form['ajax_register_forms']['ajax_register_form_enable_modal_links'] = array(
'#type' => 'checkbox',
'#title' => t('Enable links in modal window'),
'#description' => t('Check if links to another forms should appear in modal form'),
'#default_value' => variable_get('ajax_register_form_enable_modal_links', TRUE),
);
// Login form settings.
$form['ajax_register_forms']['login'] = array(
'#type' => 'fieldset',
'#title' => t('Login'),
);
// Add redirect settings to the login form type.
ajax_register_add_redirect_settings($form['ajax_register_forms']['login'], $form_state, 'login');
// Register form settings.
$form['ajax_register_forms']['register'] = array(
'#type' => 'fieldset',
'#title' => t('Register'),
);
// Add redirect settings to the register form type.
ajax_register_add_redirect_settings($form['ajax_register_forms']['register'], $form_state, 'register');
// Password form settings.
$form['ajax_register_forms']['password'] = array(
'#type' => 'fieldset',
'#title' => t('Password'),
);
// Add redirect settings to the password form type.
ajax_register_add_redirect_settings($form['ajax_register_forms']['password'], $form_state, 'password');
// Return the form.
return system_settings_form($form);
}
/**
* Adds standard redirect options to admin form for different form types.
*/
function ajax_register_add_redirect_settings(&$form, &$form_state, $form_type) {
// Provide a list of redirect behaviors.
$redirect_behaviors = array(
'default' => t('Default'),
'refresh' => t('Refresh'),
'custom' => t('Custom'),
);
// Only provide the no redirect behavior for non-login forms.
if ($form_type != 'login') {
$redirect_behaviors['none'] = t('No Redirect');
}
// Provide descriptions for redirect behaviors.
$redirect_descriptions = array(
t('Default') => t('After successful submission of the form, the redirect path is handled by Drupal and will redirect the user to whatever the !form_state_redirect variable is set to. NOTE: This option may be required if there are additional modules or features that handle the redirect logic.', array(
'!form_state_redirect' => $form_state['redirect'],
)),
t('Refresh') => t('After successful submission of the form, the page will be refreshed.'),
t('Custom') => t('After successful submission of the form, users will be redirected to this manually set custom URL.'),
);
// Only provide the no redirect behavior for non-login forms.
if ($form_type != 'login') {
$redirect_descriptions[t('No Redirect')] = t('After successful submission of the form, the modal window will simply close and not redirect the user to any location.');
}
// Theme descriptions as an item list.
$items = array();
foreach ($redirect_descriptions as $title => $description) {
$items[] = '<strong>' . $title . '</strong> - ' . $description;
}
$redirect_description = theme('item_list', array('items' => $items));
// Provide a wrapper for ajax callback.
$form['redirect'] = array(
'#prefix' => '<div id="ajax-register-forms-' . $form_type . '-redirect">',
'#suffix' => '</div>',
);
// Determine the default value for the dropdown.
$selected = variable_get('ajax_register_' . $form_type . '_redirect_behavior', 'default');
if (isset($form_state['values']['ajax_register_' . $form_type . '_redirect_behavior'])) {
$selected = $form_state['values']['ajax_register_' . $form_type . '_redirect_behavior'];
}
$form['redirect']['ajax_register_' . $form_type . '_redirect_behavior'] = array(
'#form_type' => $form_type,
'#type' => 'select',
'#title' => 'Redirect Behavior',
'#description' => $redirect_description,
'#options' => $redirect_behaviors,
'#default_value' => $selected,
'#ajax' => array(
'callback' => 'ajax_register_admin_form_redirect_callback',
'wrapper' => 'ajax-register-forms-' . $form_type . '-redirect',
),
);
// Only show the redirect URL if the behavior type is custom.
if ($selected == 'custom') {
$form['redirect']['ajax_register_' . $form_type . '_redirect_url'] = array(
'#type' => 'textfield',
'#title' => t('Redirect URL'),
'#description' => t('Enter the URL that the user will be redirected to after a successful login.'),
'#default_value' => variable_get('ajax_register_' . $form_type . '_redirect_url', ''),
// Make this field required, since this is a custom redirect behavior.
'#required' => TRUE,
);
}
}
/**
* Ajax callback to re-render the selected form type's redirect options.
*/
function ajax_register_admin_form_redirect_callback($form, $form_state) {
$form_type = isset($form_state['triggering_element']['#form_type']) ? $form_state['triggering_element']['#form_type'] : FALSE;
if ($form_type) {
return $form['ajax_register_forms'][$form_type]['redirect'];
}
}

View File

@@ -0,0 +1,13 @@
name = Ajax Login-Register
description = Provides a block that enables the user to register and login with an ajax popup.
core = 7.x
configure = admin/config/user-interface/ajax_register
dependencies[] = ctools
; Information added by drupal.org packaging script on 2012-12-16
version = "7.x-4.0-rc13"
core = "7.x"
project = "ajax_register"
datestamp = "1355656856"

View File

@@ -0,0 +1,73 @@
<?php
/**
* @file
* Install, update and uninstall functions for the AJAX REGISTER module.
*/
/**
* Implements hook_install().
*/
function ajax_register_install() {
//Make sure we're heavy so our form_alter hook gets executed last.
db_update('system')
->fields(array('weight' => 1000))
->condition('name', 'ajax_register')
->execute();
}
/**
* Implements hook_uninstall().
*/
function ajax_register_uninstall() {
db_query("DELETE FROM {variable} WHERE name LIKE 'ajax_register_%'");
cache_clear_all('variables', 'cache_bootstrap');
}
/**
* Make sure we're heavy so our form_alter hook gets executed last.
*/
function ajax_register_update_7406() {
db_update('system')
->fields(array('weight' => 1000))
->condition('name', 'ajax_register')
->execute();
}
/**
* Rename existing redirect variables and create new redirect behavior variable from redirect url.
*/
function ajax_register_update_7407() {
// Login and register redirect behaviors should initially refresh the page.
// This has always been the default functionality provided by the module.
$login_behavior = 'refresh';
$register_behavior = 'refresh';
// Set the password redirect to none, as this was the default behavior.
$password_behavior = 'none';
// Load the existing variables and then delete them.
$login_redirect_url = variable_get('ajax_register_login_form_redirect', '');
variable_del('ajax_register_login_form_redirect');
if (!empty($login_redirect_url)) {
$login_behavior = 'custom';
}
$register_redirect_url = variable_get('ajax_register_register_form_redirect', '');
variable_del('ajax_register_register_form_redirect');
if (!empty($register_redirect_url)) {
$register_behavior = 'custom';
}
elseif ($register_redirect_url == '<noredirect>') {
$register_behavior = 'none';
$register_redirect_url = '';
}
// Save the new variables.
variable_set('ajax_register_login_redirect_behavior', $login_behavior);
variable_set('ajax_register_register_redirect_behavior', $register_behavior);
variable_set('ajax_register_password_redirect_behavior', $password_behavior);
// Only set the new custom URL redirects if they're not actually empty.
if (!empty($login_redirect_url)) {
variable_set('ajax_register_login_redirect_url', $login_redirect_url);
}
if (!empty($register_redirect_url)) {
variable_set('ajax_register_register_redirect_url', $register_redirect_url);
}
}

View File

@@ -0,0 +1,455 @@
<?php
/**
* Implements hook_menu().
*/
function ajax_register_menu() {
$items['ajax_register/%/%ctools_js'] = array(
'page callback' => 'ajax_register_page_callback',
'page arguments' => array(1, 2),
'access callback' => 'ajax_register_page_access',
'access arguments' => array(1, 2),
'delivery callback' => 'ajax_deliver',
'theme callback' => 'ajax_base_page_theme',
'type' => MENU_CALLBACK,
'file' => 'ajax_register.pages.inc',
);
$items['admin/config/user-interface/ajax_register'] = array(
'title' => 'Ajax Register',
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_register_admin_form'),
'access arguments' => array('administer site configuration'),
'file' => 'ajax_register.admin.inc',
);
return $items;
}
/**
* Check access to ajax page callback.
*/
function ajax_register_page_access($form, $type) {
$allowed_forms = array('login', 'register', 'password');
$allowed_types = array('ajax', 'nojs');
if (in_array($form, $allowed_forms) && in_array($type, $allowed_types) && user_is_anonymous()) {
return TRUE;
}
return FALSE;
}
/**
* Implements hook_block_info().
*/
function ajax_register_block_info() {
// Block with three links (login, register, restore password).
$blocks['ajax_register_block'] = array(
'info' => t('Ajax Register links'),
'cache' => DRUPAL_CACHE_GLOBAL,
);
return $blocks;
}
/**
* Implements hook_block_configure().
*/
function ajax_register_block_configure() {
// User allowed to disable ajax links.
$form['ajax_register_enabled_links'] = array(
'#type' => 'checkboxes',
'#title' => t('Enabled links'),
'#options' => array(
'login' => t('Login'),
'register' => t('Create new account'),
'password' => t('Request new password'),
),
'#default_value' => variable_get('ajax_register_enabled_links', array('login', 'register', 'password')),
);
$form['ajax_register_show_links_inline'] = array(
'#type' => 'checkbox',
'#title' => t('Display links inline'),
'#default_value' => variable_get('ajax_register_show_links_inline', TRUE),
);
return $form;
}
/**
* Implements hook_block_save().
*/
function ajax_register_block_save($delta = '', $edit = array()) {
// Remove empty elements from array.
$links = $edit['ajax_register_enabled_links'];
foreach ($links as $key => $link) {
if (!$link) {
unset($links[$key]);
}
}
// Save variables to database.
variable_set('ajax_register_enabled_links', $links);
variable_set('ajax_register_show_links_inline', $edit['ajax_register_show_links_inline']);
}
/**
* Implements hook_block_view().
*/
function ajax_register_block_view() {
// Show links only to anonymous users.
if (user_is_anonymous()) {
// Get enabled ajax links.
$enabled_links = variable_get('ajax_register_enabled_links', array('login', 'register', 'password'));
if (!$enabled_links) {
// Hide block if user didn't choose at least one link.
return FALSE;
}
// Include css and js for modal dialog.
_ajax_register_include_modal();
// Add a links to the block.
$block['content'] = array(
'#theme' => 'item_list',
'#items' => _ajax_register_ajax_links($enabled_links),
'#attributes' => array('class' => array('ajax-register-links'))
);
// Display links inline.
if (variable_get('ajax_register_show_links_inline', TRUE)) {
$block['content']['#attributes']['class'][] = 'inline';
}
return $block;
}
}
/**
* Implements hook_menu_site_status_alter().
*/
function ajax_register_menu_site_status_alter(&$menu_site_status, $path) {
// Disable offline mode for ajax response for User Login and User Pass forms'.
if ($menu_site_status == MENU_SITE_OFFLINE) {
if (user_is_anonymous()) {
switch ($path) {
case 'system/ajax':
if (isset($_POST['form_id']) && in_array($_POST['form_id'], array('user_login', 'user_pass'))) {
$menu_site_status = MENU_SITE_ONLINE;
break;
}
}
}
}
}
/**
* Implements hook_form_alter().
*/
function ajax_register_form_alter(&$form, &$form_state, $form_id) {
// Create array with enabled ajax links.
$enabled_links = array('login', 'register', 'password');
switch ($form_id) {
case 'user_login_block':
// Add links processed with CTools modal.
$form['links'] = array(
'#theme' => 'item_list',
'#items' => _ajax_register_ajax_links($enabled_links, $form_id),
'#attributes' => array('class' => array('ajax-register-links')),
);
// Add html wrapper to form and #ajax to form submit.
_ajax_register_add_ajax($form, $form_id);
// Do not add to the user login block anything more.
break;
case 'user_login':
case 'user_pass':
case 'user_register_form':
// Do not process form with AJAX that should be processed with CTools modal.
$modal_links_enabled = variable_get('ajax_register_form_enable_modal_links', TRUE);
if (!empty($form_state['ajax']) && $modal_links_enabled) {
// Add links processed with CTools modal.
$form['links'] = array(
'#theme' => 'item_list',
'#items' => _ajax_register_ajax_links($enabled_links, $form_id),
'#attributes' => array('class' => array('ajax-register-links', 'inline')),
'#weight' => -200,
'#prefix' => '<div class="ajax-register-links-wrapper">',
'#suffix' => '</div>',
);
// Unset captcha from modal form.
$hide_captcha = variable_get('ajax_register_hide_captcha', FALSE);
if ($hide_captcha) {
unset($form['captcha']);
}
}
else {
// Add html wrapper to form and #ajax to form submit.
_ajax_register_add_ajax($form, $form_id);
}
}
}
/**
* Add form wrapper and #ajax attribute to forms.
*/
function _ajax_register_add_ajax(&$form, $type) {
// Add ajax wrapper to form.
$html_id = 'ajax-register-' . str_replace('_', '-', $type) . '-wrapper';
// Save previos form prefix if it is exists.
if (!empty($form['#prefix'])) {
$form['#prefix'] .= '<div id="' . $html_id . '">';
}
else {
$form['#prefix'] = '<div id="' . $html_id . '">';
}
// Save previos form suffix if it is exists.
if (!empty($form['#suffix'])) {
$form['#suffix'] = '</div>' . $form['#suffix'];
}
else {
$form['#suffix'] = '</div>';
}
// User login block and user login form have same ajax callback;
if ($type == 'user_login_block') {
$type = 'user_login';
}
// Add ajax functionality to form submit button.
$form['actions']['submit']['#ajax'] = array(
'callback' => 'ajax_register_' . $type . '_ajax_callback',
'wrapper' => $html_id,
'event' => 'click',
);
// Add ctools modal style.
$form['actions']['submit']['#attributes']['class'][] = 'ctools-modal-ctools-ajax-register-style';
}
/**
* Ajax callback for USER LOGIN form.
*/
function ajax_register_user_login_ajax_callback($form, $form_state) {
if (!form_get_errors()) {
$commands = _ajax_register_execute_form('login', $form_state);
return array('#type' => 'ajax', '#commands' => $commands);
}
// Reload form if it didn't pass validation.
return $form;
}
/**
* Ajax callback for USER PASS form.
*/
function ajax_register_user_pass_ajax_callback($form, $form_state) {
if (!form_get_errors()) {
$commands = _ajax_register_execute_form('password', $form_state);
return array('#type' => 'ajax', '#commands' => $commands);
}
// Reload form if it didn't pass validation.
return $form;
}
/**
* Ajax callback for USER REGISTER form.
*/
function ajax_register_user_register_form_ajax_callback($form, $form_state) {
if (!form_get_errors()) {
$commands = _ajax_register_execute_form('register', $form_state);
return array('#type' => 'ajax', '#commands' => $commands);
}
// Reload form if it didn't pass validation.
return $form;
}
/**
* Executes form.
*/
function _ajax_register_execute_form($form_type, $form_state) {
// Include additinal ajax commands.
ctools_include('ajax');
ctools_include('modal');
$redirect_behavior = variable_get('ajax_register_' . $form_type . '_redirect_behavior', 'default');
$redirect_url = variable_get('ajax_register_' . $form_type . '_redirect_url', '');
// Use the form state's redirect url for default behavior.
if ($redirect_behavior == 'default' && !empty($form_state['redirect'])) {
if (is_array($form_state['redirect'])) {
$redirect_url = call_user_func_array('url', $form_state['redirect']);
// Remove leading slash from the url.
$redirect_url = drupal_substr($redirect_url, 1);
}
else {
$redirect_url = $form_state['redirect'];
}
}
elseif (($redirect_behavior == 'custom' && !empty($redirect_url)) || $redirect_behavior == 'none') {
// Do nothing other than preventing the fallback.
}
// Refresh the page as a fallback redirect behavior.
// This can happen if the form state does not have a redirect.
else {
$redirect_behavior = 'refresh';
}
// Provide additional logic and titles for different form types.
switch ($form_type) {
case 'password':
$title = t('Successful password request');
break;
case 'register':
$title = t('Successful registration');
break;
case 'login':
$title = t('Successful login');
$message = 'Login was successful. ';
if ($redirect_behavior == 'refresh') {
$message .= 'Page will now be reloaded.';
}
elseif ($redirect_behavior == 'default' || $redirect_behavior == 'custom') {
$message .= 'Page will now be redirected.';
}
drupal_set_message(check_plain(t($message)));
$commands[] = ctools_modal_command_display($title, theme('status_messages'));
break;
}
// Send ajax command to modal based on redirect behavior.
switch ($redirect_behavior) {
case 'none':
$commands[] = ctools_modal_command_display($title, theme('status_messages'));
break;
case 'refresh':
$commands[] = ctools_ajax_command_reload();
break;
default:
// Redirect to URL supplied from default or custom redirect behavior.
$commands[] = ctools_ajax_command_redirect($redirect_url);
break;
}
return $commands;
}
/**
* Return ajax links for user login, register or password request.
*
* @param $links_enabled
* Array with possible links could be enabled ('login', 'register', 'password).
* @param null $form_id
* Form where this links are builded.
* @return array
* List of ajax links.
*/
function _ajax_register_ajax_links($links_enabled, $form_id = NULL) {
// Include css and js for modal dialog.
_ajax_register_include_modal();
$links = array();
// Build classes for ajax modal link.
$classes = array();
$classes[] = 'ctools-use-modal';
$classes[] = 'ctools-modal-ctools-ajax-register-style';
// Provide default options for ajax modal link.
$options = array(
'attributes' => array(
'class' => $classes,
'rel' => 'nofollow',
)
);
// Add login button.
if (in_array('login', $links_enabled) && (stripos($form_id, 'user_login') === FALSE)) {
$options['attributes']['title'] = t('Login');
$links[] = l(t('Login'), 'ajax_register/login/nojs', $options);
}
// Add register button.
if (in_array('register', $links_enabled) && $form_id != 'user_register_form') {
$options['attributes']['title'] = t('Create new account');
$links[] = l(t('Create new account'), 'ajax_register/register/nojs', $options);
}
// Add request password button.
if (in_array('password', $links_enabled) && $form_id != 'user_pass') {
$options['attributes']['title'] = t('Request new password');
$links[] = l(t('Request new password'), 'ajax_register/password/nojs', $options);
}
return $links;
}
/**
* Add css and javascript for modal dialog.
*/
function _ajax_register_include_modal() {
static $added = FALSE;
if ($added == FALSE) {
// Do not add css and scripts again.
$added = TRUE;
// Include the CTools tools that we need.
ctools_include('modal');
ctools_include('ajax');
ctools_modal_add_js();
// Create our own javascript that will be used to theme a modal.
$ajax_register_style = array(
'ctools-ajax-register-style' => array(
'modalSize' => array(
'type' => 'fixed',
'width' => (int) trim(variable_get('ajax_register_modal_width', 550)),
'height' => 140,
'contentRight' => 30,
'contentBottom' => 0,
),
'modalOptions' => array(
'opacity' => (float) variable_get('ajax_register_modal_background_opacity', '0.8'),
'background-color' => '#' . variable_get('ajax_register_modal_background_color', '000000'),
),
'closeText' => '',
'throbber' => theme('image', array('path' => ctools_image_path('ajax-loader.gif', 'ajax_register'))),
'animation' => 'fadeIn',
'animationSpeed' => 'fast',
),
);
drupal_add_js($ajax_register_style, 'setting');
// Add module css and js.
ctools_add_css('ajax-register', 'ajax_register');
ctools_add_js('ajax-register', 'ajax_register');
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* @file
* Page callback for ajax links.
*/
/**
* Returns USER LOGIN / REGITER / PASSWORD form.
* @param $form_type
* Type of form that should be loaded.
* @param $js
* Show whether user has enabled js in his browser.
*/
function ajax_register_page_callback($form_type, $js) {
// Check whether js is enabled.
if ($js) {
// Include ctools modal plugin.
ctools_include('modal');
$form_state = array('ajax' => TRUE);
// Array with ajax response.
$commands = array();
if ($form_type == 'password') {
// Show USER PASSWORD form.
module_load_include('pages.inc', 'user');
$form_state['title'] = t('Request new password');
$commands = ctools_modal_form_wrapper('user_pass', $form_state);
}
elseif ($form_type == 'register') {
// Show USER REGISTER form.
$form_state['title'] = t('Create new account');
$commands = ctools_modal_form_wrapper('user_register_form', $form_state);
}
elseif ($form_type == 'login') {
// Show USER LOGIN form.
$form_state['title'] = t('Login');
$commands = ctools_modal_form_wrapper('user_login', $form_state);
}
// If form was submited.
if (!empty($form_state['executed'])) {
$commands = _ajax_register_execute_form($form_type, $form_state);
}
return array('#type' => 'ajax', '#commands' => $commands);
}
else {
// If user has no js support redirect him to standart drupal forms.
drupal_goto('user/' . $form_type);
}
}

View File

@@ -0,0 +1,40 @@
/*** change some ctools styles ***/
#modalBackdrop {
position: fixed !important;
}
div.ctools-modal-content .modal-content {
padding: 15px;
}
div.ctools-modal-content .modal-content .modal-throbber-wrapper img {
padding: 2em 0 3em;
margin: 0;
}
div.ctools-modal-content .form-item label {
float: none;
width: auto;
}
div.ctools-modal-content a.close {
margin-top: 3px;
}
/*** module styles ***/
.ajax-register-links-wrapper {
text-align: right;
font-size: 12px;
}
.ajax-register-links-wrapper .ajax-register-links li {
padding-left: 1em;
}
.ajax-register-links-wrapper .ajax-register-links li a {
border-bottom: 1px dashed #ccc;
}
.ajax-register-links .ajax-progress {
display: none;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -0,0 +1,26 @@
(function ($) {
Drupal.behaviors.ajaxRegister = {
attach: function (context){
// Make modal window height scaled automatically.
$('.ctools-modal-content, #modal-content', context).height('auto');
// Position code lifted from http://www.quirksmode.org/viewport/compatibility.html
if (self.pageYOffset) { // all except Explorer
var wt = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
var wt = document.documentElement.scrollTop;
}
else if (document.body) { // all other Explorers
var wt = document.body.scrollTop;
}
// Fix CTools bug: calculate correct 'top' value.
var mdcTop = wt + ( $(window).height() / 2 ) - ($('#modalContent', context).outerHeight() / 2);
$('#modalContent', context).css({top: mdcTop + 'px'});
}
}
})(jQuery);

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,70 @@
-- SUMMARY --
The Duplicate Mail module has a block to display system wide duplicate email
addresses in user accounts, and a view with a block display for use on
individual user account pages that displays only the accounts that have the same
email address as that account.
For a full description of the module, visit the project page:
http://drupal.org/project/duplicatemail
To submit bug reports and feature suggestions, or to track changes:
http://drupal.org/project/issues/duplicatemail
-- REQUIREMENTS --
Views module.
-- INSTALLATION --
* Install as usual, see http://drupal.org/node/70151 for further information.
-- CONFIGURATION --
* This module lists user account information, including email addresses.
Restrict access to this information by configuring the blocks to only display
for a siteadmin type of role. (Picking a role other than anonymous or
authenticated will make it so anonymous or simple authenticated users cannot
see the blocks.) Configure block role visibility in Administer >> Site
Building >> Blocks and configure the Duplicate Mail blocks under Role specific
visibility settings.
Also, change the region from Disabled to some other region. Right sidebar
works well for the system wide block. And content or content top works well
for the individual block generated by views.
-- TROUBLESHOOTING --
* If the blocks do not display, check the following:
- Make sure you save the block settings page after moving the blocks to a new
region.
-- FAQ --
Q: It's impossible to get accounts with duplicate emails; why have this module?
A: There are a few modules that bypass that safeguard and allow duplicate
emails. And, during an import of users using the migrate module, accounts
can be created using emails already in use by other accounts.
This module is useful for listing only the accounts with duplicate emails
so that the users can be contacted to correct the situation, the accounts can
be merged, or just for information purposes to find out how many duplicates
there are.
-- CONTACT --
Current maintainers:
* Cathy Theys (YesCT) - http://drupal.org/user/258568
This project has been sponsored by:
* Yes! Training and Education
Visit http://YesTrainingAndEducation.com for more information.

View File

@@ -0,0 +1,11 @@
name = Duplicate Mail
description = "Views and Blocks to help deal with accounts with duplicate email addresses."
dependencies[] = views
core = 7.x
; Information added by drupal.org packaging script on 2013-09-30
version = "7.x-1.x-dev"
core = "7.x"
project = "duplicatemail"
datestamp = "1380575858"

View File

@@ -0,0 +1,86 @@
<?php
/**
* @file
* This is a helper module to add blocks and menu items and function
* to help deal with accounts that might have duplicate email addresses.
* It is based on the examples module block_example: an example outlining
* how a module can define blocks to be displayed on each page.
*/
/**
* Implements hook_views_api().
*/
function duplicatemail_views_api() {
return array(
'api' => 3,
);
}
/**
* Implements hook_block_info().
*
* This hook both declares what blocks are provided by the module, and
* generates the contents of the blocks themselves.
*/
function duplicatemail_block_info() {
return array(
'duplicatemail-list' => array(
'info' => t('Duplicate Mail: system wide, lists accounts that have the same email as another account'),
'cache' => DRUPAL_CACHE_GLOBAL,
)
);
}
/**
* Implements hook_block_view().
*/
function duplicatemail_block_view($delta) {
switch ($delta) {
case 'duplicatemail-list':
return array(
'subject' => t('Duplicate emails'),
'content' => duplicatemail_list(),
);
break;
}
}
/**
* A block content function.
*/
function duplicatemail_list() {
$mails = db_query('SELECT mail FROM {users} GROUP BY mail HAVING count(mail) > 1')->fetchCol();
// Bail out early if there are no duplicates.
if (!$mails) {
return t('All accounts have unique email addresses.');
}
// Grab all the user data for accounts with addresses identified as
// duplicates. This is a little convoluted, but it lets us grab all the user
// data in one shot.
$uids = db_select('users', 'u')
->fields('u', array('uid'))
->condition('mail', $mails, 'IN')
->orderBy('mail')
->execute()
->fetchCol();
$duplicate_users = user_load_multiple($uids);
$duplicate_mails = array();
foreach ($duplicate_users as $duplicate_user) {
$duplicate_mails[$duplicate_user->mail][] = $duplicate_user;
}
// Turn the data we've got into markup.
$output = t('Accounts with duplicate email address:') . '<br />';
foreach ($duplicate_mails as $mail => $users) {
$output .= "$mail<br />";
foreach ($users as $duplicate_user) {
$output .= l($duplicate_user->name, "user/{$duplicate_user->uid}");
$output .= '<br />';
}
}
return $output;
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* @file
* Views export of duplicate mail user blocks.
*/
/**
* Implementation of hook_views_default_views().
*/
function duplicatemail_views_default_views() {
$view = new view();
$view->name = 'duplicatesview';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Duplicate Mail';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Duplicate Mail: Block from views, for individual accounts';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
'mail' => 'mail',
'edit_node' => 'edit_node',
'name' => 'name',
'uid' => 'uid',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
'mail' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'edit_node' => array(
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'name' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'uid' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
);
/* Field: User: E-mail */
$handler->display->display_options['fields']['mail']['id'] = 'mail';
$handler->display->display_options['fields']['mail']['table'] = 'users';
$handler->display->display_options['fields']['mail']['field'] = 'mail';
/* Field: User: Edit link */
$handler->display->display_options['fields']['edit_node']['id'] = 'edit_node';
$handler->display->display_options['fields']['edit_node']['table'] = 'users';
$handler->display->display_options['fields']['edit_node']['field'] = 'edit_node';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
/* Field: User: Uid */
$handler->display->display_options['fields']['uid']['id'] = 'uid';
$handler->display->display_options['fields']['uid']['table'] = 'users';
$handler->display->display_options['fields']['uid']['field'] = 'uid';
/* Contextual filter: User: E-mail */
$handler->display->display_options['arguments']['mail']['id'] = 'mail';
$handler->display->display_options['arguments']['mail']['table'] = 'users';
$handler->display->display_options['arguments']['mail']['field'] = 'mail';
$handler->display->display_options['arguments']['mail']['default_action'] = 'default';
$handler->display->display_options['arguments']['mail']['default_argument_type'] = 'php';
$handler->display->display_options['arguments']['mail']['default_argument_options']['code'] = 'if ($account = menu_get_object(\'user\')) {
return $account->mail;
}
';
$handler->display->display_options['arguments']['mail']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['mail']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['mail']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['mail']['limit'] = '0';
/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$views[$view->name] = $view;
return $views;
}

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,44 @@
Email Registration allows users to register and login with their e-mail address
instead of using a separate username in addition to the e-mail address. It will
automatically generate a username based on the e-mail address but that behavior
can be overridden with a custom hook implementation in a site specific module.
INSTALLATION
============
Required step:
1. Enable the module as you normally would.
Optional steps:
2. You will probably want to change the welcome e-mail
(Administer -> User Management -> User Settings) and replace instances of
the token !username with !mailto
3. This automatically generated username is still displayed name for posts,
comments, etc. You can allow your useres to change their username by
going to: (Administer -> User Management -> Access Control) and granting
the permission to "change own username"
This privilege allows a user to change their username in "My Account".
4. If a user enters an invalid email or password they will see a message:
"Sorry, unrecognized username or password. Have you forgotten your password?"
That message is confusing because it mentions username when all other
language on the page mentions entering their E-mail. This can be easily
overridden in your settings.php file with an entry like this:
$conf['locale_custom_strings_en'][''] = array(
'Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>' => 'Sorry, unrecognized e-mail or password. <a href="@password">Have you forgotten your password?</a>',
);
BUGS, FEATURES, QUESTIONS
=========================
Post any bugs, features or questions to the issue queue:
http://drupal.org/project/issues/email_registration

View File

@@ -0,0 +1,34 @@
<?php
/**
* @file
* Documentation for email_registration API.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Implement this hook to generate a username for email_registration module.
*
* Other modules may implement hook_email_registration_name($edit, $account)
* to generate a username (return a string to be used as the username, NULL
* to have email_registration generate it).
*
* @param $edit
* The array of form values submitted by the user.
* @param $account
* The user object on which the operation is being performed.
*
* @return
* A string defining a generated username.
*/
function hook_email_registration_name($edit, $account) {
return 'u' . $account->uid;
}
/**
* @} End of "addtogroup hooks".
*/

View File

@@ -0,0 +1,11 @@
name = Email Registration
description = Allows users to register with an e-mail address as their username.
files[] = email_registration.test
core = 7.x
; Information added by drupal.org packaging script on 2013-01-19
version = "7.x-1.1"
core = "7.x"
project = "email_registration"
datestamp = "1358554303"

View File

@@ -0,0 +1,25 @@
<?php
/**
* @file
* Checks requirements for the email_registration.module.
*/
/**
* Implements hook_requirements().
*/
function email_registration_requirements() {
$t = get_t();
$requirements = array();
if (module_exists('logintoboggan') && variable_get('logintoboggan_login_with_email', 0)) {
$requirements['email_registration'] = array(
'title' => $t('Email Registration / LoginToboggan Conflict'),
'value' => $t('Conflict'),
'description' => $t('There is a conflict between %email_registration and %logintoboggan. You should disable the "Allow users to login using their e-mail address" option from %logintoboggan.', array('%email_registration' => 'Email registration', '%logintoboggan' => 'Login Toboggan')),
'severity' => REQUIREMENT_ERROR,
);
}
return $requirements;
}

View File

@@ -0,0 +1,151 @@
<?php
/**
* @file
* Allows users to register with an e-mail address as their username.
*/
/**
* Implements hook_user_insert().
*/
function email_registration_user_insert(&$edit, &$account, $category = NULL) {
// Don't create a new username if one is already set.
if (!empty($account->name) && strpos($account->name, 'email_registration_') !== 0) {
return;
}
// Other modules may implement hook_email_registration_name($edit, $account)
// to generate a username (return a string to be used as the username, NULL
// to have email_registration generate it).
$names = module_invoke_all('email_registration_name', $edit, $account);
// Remove any empty entries.
$names = array_filter($names);
if (empty($names)) {
// Strip off everything after the @ sign.
$new_name = preg_replace('/@.*$/', '', $edit['mail']);
}
else {
// One would expect a single implementation of the hook, but if there
// are multiples out there use the last one.
$new_name = array_pop($names);
}
// Ensure whatever name we have is unique.
$new_name = email_registration_unique_username($new_name, $account->uid);
// Replace with generated username.
db_update('users')
->fields(array('name' => $new_name))
->condition('uid', $account->uid)
->execute();
$edit['name'] = $new_name;
$account->name = $new_name;
return;
}
/**
* Given a starting point for a Drupal username (e.g. the name portion of an
* email address) return a legal, unique Drupal username. This function is
* designed to work on the results of the /user/register or /admin/people/create
* forms which have already called user_validate_name, valid_email_address
* or a similar function. If your custom code is creating users, you should
* ensure that the email/name is already validated using something like that.
*
* @param $name
* A name from which to base the final user name. May contain illegal characters; these will be stripped.
*
* @param $uid
* (optional) Uid to ignore when searching for unique user (e.g. if we update the username after the
* {users} row is inserted)
*
* @return
* A unique user name based on $name.
*
* @see user_validate_name().
*
*/
function email_registration_unique_username($name, $uid = 0) {
// Strip illegal characters.
$name = preg_replace('/[^\x{80}-\x{F7} a-zA-Z0-9@_.\'-]/', '', $name);
// Strip leading and trailing spaces.
$name = trim($name);
// Convert any other series of spaces to a single underscore.
$name = preg_replace('/ +/', '_', $name);
// If there's nothing left use a default.
$name = ('' === $name) ? t('user') : $name;
// Truncate to reasonable size.
$name = (drupal_strlen($name) > (USERNAME_MAX_LENGTH - 10)) ? drupal_substr($name, 0, USERNAME_MAX_LENGTH - 11) : $name;
// Iterate until we find a unique name.
$i = 0;
do {
$new_name = empty($i) ? $name : $name . '_' . $i;
$found = db_query_range("SELECT uid from {users} WHERE uid <> :uid AND name = :name", 0, 1, array(':uid' => $uid, ':name' => $new_name))->fetchAssoc();
$i++;
} while (!empty($found));
return $new_name;
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function email_registration_form_user_register_form_alter(&$form, &$form_state) {
$form['account']['name']['#type'] = 'value';
$form['account']['name']['#value'] = 'email_registration_' . user_password();
$form['account']['mail']['#title'] = t('E-mail');
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function email_registration_form_user_pass_alter(&$form, &$form_state) {
$form['name']['#title'] = t('E-mail');
$form['name']['#description'] = t('A password reset message will be sent to your e-mail address.');
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function email_registration_form_user_login_alter(&$form, &$form_state) {
$form['name']['#title'] = t('E-mail');
$form['name']['#description'] = t('Enter your e-mail address.');
$form['name']['#element_validate'][] = 'email_registration_user_login_validate';
$form['pass']['#description'] = t('Enter the password that accompanies your e-mail.');
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function email_registration_form_user_login_block_alter(&$form, &$form_state) {
$form['name']['#title'] = t('E-mail');
$form['name']['#element_validate'][] = 'email_registration_user_login_validate';
}
/**
* Form element validation handler for the user login form.
* Allows users to authenticate by email, which is our preferred method.
*/
function email_registration_user_login_validate($form, &$form_state) {
if (isset($form_state['values']['name'])) {
// Keep the email value in form state for furher validation.
$form_state['values']['email'] = $form_state['values']['name'];
if ($name = db_query('SELECT name FROM {users} WHERE LOWER(mail) = LOWER(:name)', array(':name' => $form_state['values']['name']))->fetchField()) {
$form_state['values']['name'] = $name;
}
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function email_registration_form_user_profile_form_alter($form, &$form_state) {
$form['account']['name']['#title'] = t('Display name');
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* @file
* email registration simpletest
*/
class EmailRegistrationTestCase extends DrupalWebTestCase {
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('Email registration.'),
'description' => t('Test the email registration module.'),
'group' => t('Email registration'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('email_registration');
// Configure to allow set password.
variable_set('user_email_verification', FALSE);
}
/**
* Test various behaviors for anonymous users.
*/
function testRegistration() {
variable_set('user_register', USER_REGISTER_VISITORS);
// Try to register a user.
$name = $this->randomName();
$pass = $this->randomName(10);
$register = array(
'mail' => $name . '@example.com',
'pass[pass1]' => $pass,
'pass[pass2]' => $pass,
);
$this->drupalPost('/user/register', $register, t('Create new account'));
$this->drupalLogout();
$login = array(
'name' => $name . '@example.com',
'pass' => $pass,
);
$this->drupalPost('user/login', $login, t('Log in'));
// Really basic confirmation that the user was created and logged in.
$this->assertRaw('<title>' . $name . ' | Drupal</title>', t('User properly created, logged in.'));
// Now try the immediate login.
$this->drupalLogout();
variable_set('user_email_verification', 0);
$name = $this->randomName();
$pass = $this->randomName(10);
$register = array(
'mail' => $name . '@example.com',
'pass[pass1]' => $pass,
'pass[pass2]' => $pass,
);
$this->drupalPost('/user/register', $register, t('Create new account'));
$this->assertRaw('Registration successful. You are now logged in.', t('User properly created, immediately logged in.'));
}
}

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,34 @@
EMAIL REQUIRED:
========================
This module is for site owners that do not want to require that users
validate their email address when creating an account - because we all
know that's extremely annoying for users to do. But, we still want to
try to minimize spam as much as possible.
With this module enabled, you should not be requiring email verification
upon user registration. This module allows you to set any number of
page paths that will require the user to verify their email address in
order to access. Some examples could be node/add/* or messages/new, etc.
If the user has not yet verfied their email address, when they navigate
to those pages, they will be redirected to a page where they can request
a verification link.
Clicking that sends a tokenized link to the user's email address. Once
clicked, the user now has a validated email address. They will never have
to do this again, unless they change their email address.
*Be aware* that anonymous users will never get redirected because we
can't verify their email address. The purpose of this module is to limit
features that authenticated users can use until they verify their email
address. Act accordingly!
----
To get set up, install the module and configure it at:
admin/config/people/email-required
There are permissions available that can allow you to exclude certain
roles from having to verify.
See email_recurring.api.php for API functions.

View File

@@ -0,0 +1,44 @@
<?php
/**
* The admin settings form
*/
function email_required_admin_settings($form) {
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Settings'),
);
$form['settings']['email_required_paths'] = array(
'#type' => 'textarea',
'#title' => t('Paths that require a verified email address'),
'#description' => t('Supply a list of page paths on different lines which will require a user have a verified email addess in order to access.'),
'#default_value' => variable_get('email_required_paths', NULL),
);
// Email text defaults
$text = _email_required_email_text();
$form['email'] = array(
'#type' => 'fieldset',
'#title' => t('Email template'),
'#description' => t('Create a template for email verification messages.'),
);
$form['email']['email_required_email_subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#default_value' => $text['subject'],
);
$form['email']['email_required_email_body'] = array(
'#type' => 'textarea',
'#title' => t('Body'),
'#default_value' => $text['body'],
'#description' => t('Use !link to place the verification link.'),
);
$form['email']['email_required_token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array('user'),
);
return system_settings_form($form);
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* Implements hook_email_required_access_alter().
*
* Alter which users are considered to have verified email addresses
*
* @see
* email_required_user_is_validated()
*
* @param $account
* The user account, or uid, we're checking
* @param $admin
* TRUE if users with adequate permissions should be allowed to bypass
* @param &$access
* The current access status for this user. Modify this.
*/
function hook_email_required_access_alter($account, $admin, &$access) {
if ($account->uid == 5) {
$access = FALSE;
}
}

View File

@@ -0,0 +1,11 @@
name = "Email required"
description = "Forces email validation only for certain page paths."
core = "7.x"
dependencies[] = "token"
; Information added by drupal.org packaging script on 2012-04-28
version = "7.x-1.0"
core = "7.x"
project = "email_required"
datestamp = "1335587755"

View File

@@ -0,0 +1,54 @@
<?php
/**
* Implements of hook_schema().
*/
function email_required_schema() {
$schema = array();
$schema['email_required'] = array(
'description' => 'Track which users have validated their email address.',
'fields' => array(
'uid' => array(
'description' => 'The unique ID of the content, such as either the {cid}, {uid}, or {nid}.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'hash' => array(
'description' => 'The hash that will be needed to verify the email',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'created' => array(
'description' => 'The UNIX time stamp representing when the hash was made.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'verified' => array(
'description' => 'The UNIX time stamp representing when the email was verified.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('uid'),
);
return $schema;
}
/**
* Implements hook_uninstall().
*/
function email_required_uninstall() {
variable_del('email_required_paths');
variable_del('email_required_email_subject');
variable_del('email_required_email_body');
}

View File

@@ -0,0 +1,358 @@
<?php
/**
* Implements hook_menu().
*/
function email_required_menu() {
$items = array();
$items['email/verify'] = array(
'title' => 'Email verifications',
'description' => 'Form to submit for email verification',
'page callback' => 'drupal_get_form',
'page arguments' => array('email_required_verification_form'),
'access callback' => 'email_required_verification_form_access',
'file' => 'email_required.pages.inc',
'type' => MENU_CALLBACK,
);
$items['email/verify/%user/%'] = array(
'title' => 'Email verification',
'description' => 'Path to verify your email address',
'page callback' => 'email_required_verification_page',
'page arguments' => array(2, 3),
'access callback' => 'email_required_verification_page_access',
'access arguments' => array(2, 3),
'file' => 'email_required.pages.inc',
'type' => MENU_CALLBACK,
);
$items['admin/config/people/email-required'] = array(
'title' => 'Email verification',
'description' => 'Configure when users will need to verify their email address',
'page callback' => 'drupal_get_form',
'page arguments' => array('email_required_admin_settings'),
'access arguments' => array('administer email required'),
'file' => 'email_required.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_init().
*/
function email_required_init() {
// If authenticated
if (user_is_logged_in()) {
// See if we have paths to enforce a required email
if ($paths = variable_get('email_required_paths', NULL)) {
// Determine the current path
$path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
// See if we have a match
if (drupal_match_path($path, $paths)) {
// See if the user has to validate their email
if (!email_required_user_is_validated()) {
// See if we can capture the referred page
$options = array();
if (isset($_SERVER['HTTP_REFERER']) && $referer = $_SERVER['HTTP_REFERER']) {
$referer = str_replace(url('<front>', array('absolute' => TRUE)), '', $referer);
$options['query'] = array('destination' => $referer);
}
// Redirect to the verify form
drupal_goto('email/verify', $options);
}
}
}
}
}
/**
* Implements hook_mail().
*/
function email_required_mail($key, &$message, $params) {
global $user;
// Get email text
$text = _email_required_email_text();
// Inject a verification link
$text['body'] = str_replace('!link', email_required_generate_link($user, TRUE), $text['body']);
// Attach to the message, and replace tokens
$message['subject'] = token_replace($text['subject'], array('user' => $user));
$message['body'] = array(token_replace($text['body'], array('user' => $user)));
}
/**
* Implements hook_permission().
*/
function email_required_permission() {
return array(
'administer email required' => array(
'title' => t('Administer email required'),
'description' => t('Configure the settings for this module.'),
),
'bypass email required' => array(
'title' => t('Bypass email verification'),
'description' => t('These users will not have to verify their email. Anonyous users will never have to.'),
),
);
}
/**
* Implements hook_user_presave().
*/
function email_required_user_presave(&$edit, $account, $category) {
// See if the user exists yet
if ($account->uid) {
// See if the email address has changed
if (strtolower($edit['mail']) != strtolower($account->mail)) {
// Mark this user as no longer having a verified email address
email_required_delete_hash($account);
}
}
}
/**
* Generate a URL to verify an email address
*
* @param $user
* A user object or uid
* @param $absolute
* TRUE if the link should be absolute.
* @return
* A link to verify an email address, or FALSE if one cannot be made.
*/
function email_required_generate_link($user = NULL, $absolute = FALSE) {
// Get the uid
$uid = _email_required_get_uid($user);
// Get the hash string
if ($hash = email_required_load_hash($user, TRUE)) {
// Provide the link
return url("email/verify/{$uid}/{$hash->hash}", array('absolute' => $absolute));
}
return FALSE;
}
/**
* Delete a hash entry for a given user
*
* @param $user
* A user object or uid
*/
function email_required_delete_hash($user = NULL) {
// Delete the hash entry
db_delete('email_required')
->condition('uid', _email_required_get_uid($user))
->execute();
}
/**
* Create a hash entry for a given user
*
* This will delete any existing entries so call with caution
*
* @param $user
* A user object
* @return
* A hash object
*/
function email_required_create_hash($user = NULL) {
if (!$user) {
global $user;
}
// Create the hash object
$hash = array(
'uid' => _email_required_get_uid($user),
'hash' => _email_required_hash($user),
'created' => REQUEST_TIME,
'verified' => 0,
);
// Delete any existing hashes for this user
email_required_delete_hash($user);
// Insert it
db_insert('email_required')
->fields($hash)
->execute();
return $hash;
}
/**
* Validate a user's hash
*
* @param $user
* A user object or uid
*/
function email_required_validate_hash($user = NULL) {
// Delete the hash entry
db_update('email_required')
->fields(array('verified' => REQUEST_TIME))
->condition('uid', _email_required_get_uid($user))
->execute();
}
/**
* Get a user's hash object
*
* @param $user
* A user object or uid
* @param $reset
* TRUE if the static cache should be skipped, otherwise FALSE.
* @return
* A hash object
*/
function email_required_load_hash($user = NULL, $reset = FALSE) {
static $hashes = array();
// Determine the uid
$uid = _email_required_get_uid($user);
// Check the cache
if ($reset || !isset($hashes[$uid])) {
// Fetch the hash entry
$hashes[$uid] =
db_select('email_required', 'e')
->fields('e', array('uid', 'hash', 'created', 'verified'))
->condition('uid', $uid)
->execute()
->fetchObject();
}
return $hashes[$uid];
}
/**
* Determine if a given user has validated their email
*
* @param $user
* A user object or uid
* @param $admin
* TRUE if users with adequate permissions will be considered
* validated regardless
* @return
* TRUE if the user is validated, otherwise FALSE.
*/
function email_required_user_is_validated($user = NULL, $admin = TRUE) {
static $validated = array();
// Determine the uid
$uid = _email_required_get_uid($user);
// Generate a cache key
$key = $uid . ($admin ? ':admins' : '');
// Check the cache
if (!isset($validated[$key])) {
// Assume false
$validated[$key] = FALSE;
// Check higher permissions first, if desired
if ($admin && (user_access('administer email required') || user_access('bypass email required'))) {
$validated[$key] = TRUE;
}
// Load the hash to check
else if ($hash = email_required_load_hash($user)) {
if ($hash->verified) {
$validated[$key] = TRUE;
}
}
// Allow modules to alter this
drupal_alter('email_required_validated', $user, $admin, $validated[$key]);
}
return $validated[$key];
}
/**
* Access callback for the verification form
*/
function email_required_verification_form_access() {
global $user;
// No anonymous allowed
if (!$user->uid) {
return FALSE;
}
return email_required_user_is_validated($user) ? FALSE : TRUE;
}
/**
* Access callback for the verification page
*
* @param $account
* A user object specified in the link
* @param $string
* The hash string on the URL
*/
function email_required_verification_page_access($account, $string) {
global $user;
// If the user is logged in, they can only verify themselves
if ($user->uid && ($account->uid != $user->uid)) {
return FALSE;
}
// We'll check for the existance of a hash, and the validity of it
// in the page callback, because we don't want a 403 if the hash
// has been purged
return TRUE;
}
/**
* Wrapper for user_pass_rehash()
*
* Generate a a hash that will be used in the verification URL
*
* @param $user
* A user object or ID
* @return
* A hash
*/
function _email_required_hash($user) {
return user_pass_rehash($user->pass, REQUEST_TIME, $user->name);
}
/**
* Helper function to determine the user id to use
*
* @param $user
* A user object, or user ID, or NULL if you want to use
* the current user.
* @return
* A user ID
*/
function _email_required_get_uid($user = NULL) {
if (!$user) {
global $user;
}
return is_object($user) ? $user->uid : $user;
}
/**
* Helper function to return email strings
*
* @return
* An array containing the 'subject' and 'body for the
* verification email
*/
function _email_required_email_text() {
// Load the defaults
$text = array(
'subject' => variable_get('email_required_subject', NULL),
'body' => variable_get('email_required_body', NULL),
);
// See if we need a subject
if (!$text['subject']) {
$text['subject'] = '[[site:name]] ' . t('Verify your email address');
}
// See if we need a body
if (!$text['body']) {
$text['body'] = '[user:name],' . "\n\n";
$text['body'] .= t('You have requested to have your email address validated at !sitename.', array('!sitename' => '[site:name]')) . "\n\n";
$text['body'] .= t('Click the link below to validate your email address:') . "\n\n";
$text['body'] .= '!link' . "\n\n";
$text['body'] .= t('You will never have to validate your email address again, unless you change it.') . "\n\n";
$text['body'] .= '- [site:name]';
}
return $text;
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* Form to submit for an email verification
*/
function email_required_verification_form($form, &$form_state) {
global $user;
drupal_set_title(t('You must verify your email address to continue'));
$form['warning'] = array(
'#type' => 'item',
'#markup' => t('The page you requested requires that you first verify your email address. Clicking the button below will send an email to the address associated with your account. It will contain a link that, when clicked, will verify your email address. You will only have to do this once.'),
);
$form['email'] = array(
'#type' => 'item',
'#markup' => t('Your current email address is %email. !link to change it before verifying.', array('%email' => $user->mail, '!link' => l(t('Click here'), "user/{$user->uid}/edit", array('query' => array('destination' => 'email/verify'))))),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send the verification email'),
);
return $form;
}
/**
* Submit handler for the email verification form
*/
function email_required_verification_form_submit(&$form, &$form_state) {
global $user;
// Insert a new hash
email_required_create_hash($user);
// Send the email
drupal_mail('email_required', 'verification', $user->mail, user_preferred_language($user));
// Set a message
drupal_set_message(t('A verification email has been sent to you.'));
// Log the action
watchdog('email_required', 'Verification email sent to !user (!uid)', array('!user' => $user->name, '!uid' => $user->uid));
// Go home
$form_state['redirect'] = '<front>';
}
/**
* Page callback for verification hash links
*
* @param $account
* A user object specified in the link
* @param $string
* The hash string on the URL
*/
function email_required_verification_page($account, $string) {
global $user;
$output = '';
// See if the user is already validated
if (email_required_user_is_validated($account)) {
$output .= t('You have already validated your email address.');
}
// Load the hash for this user and see if it's a match
else if (($hash = email_required_load_hash($account)) && ($hash->hash == $string)) {
// Verify the email address
email_required_validate_hash($account);
// Log the action
watchdog('email_required', '!user (!uid) has validated their email address.', array('!user' => $account->name, '!uid' => $account->uid));
// Set a message
$output = t('Your email address has been verified.');
// Set the title
drupal_set_title(t('Verified!'));
}
else {
$output .= t('Invalid verification link. It is possible that this link has expired. !link to have another one emailed to you.', array('!link' => l(t('Click here'), 'email/verify')));
}
$output .= "<br/><br/>" . l(t('Return to the homepage'), '<front>');
return $output;
}

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,88 @@
CONTENTS OF THIS FILE
----------------------
* Introduction
* Installation
* Configuration
* Known Issues
- No FAQs appear after module upgrade
- <p> tags appear in FAQ question text
- Clicking on category links takes user to front page
INTRODUCTION
------------
Maintainer: Stella Power (http://drupal.org/user/66894)
Documentation: http://drupal.org/node/129209
The Frequently Asked Questions (faq) module allows users with the 'administer
faq' permission to create question and answer pairs which they want displayed on
the 'faq-page' page. The 'faq-page' page is automatically generated from the
FAQ nodes configured and the layout of this page can be modified on the settings
page. Users will need the 'view faq page' permission to view the 'faq-page'
page.
An alternative to the built-in 'faq-page' is to use one of the example Views
layouts provided which you can easily customise to your needs using the Views
UI. Note, the configuration settings for the module do not apply to the Views
layouts.
INSTALLATION
------------
1. Copy faq folder to modules directory.
2. At admin/modules enable the faq module.
3. Enable permissions at admin/people/permissions.
4. Configure the module at admin/config/content/faq - not used for Views
layouts.
5. You can use the default faq page at "faq-page" or enable one of the page
layouts in the example Views. For the Views pages you can change the url if
needed, but if you wish to change the url for the built-in page (faq-page)
you need to create a url alias at admin/config/search/path.
UPGRADE NOTICE
---------------
When using categorized FAQ nodes, the disabling of the FAQ module causes the
vocabulary to lose the association with the FAQ content type. This results in no
FAQ nodes being displayed when you re-enable the FAQ module. Before opening an
issue, please verify that this setting is still in place.
CONFIGURATION
-------------
Once the module is activated, you can create your question and answer pairs by
creating FAQ nodes (Create content >> FAQ). This allows you to edit the
question and answer text. In addition, if the 'Taxonomy' module is enabled and
there are some terms configured for the FAQ node type, it will also be possible
to put the questions into different categories when editing.
KNOWN ISSUES
-------------
No FAQs appear after module upgrade
-----------------------------------
When using categorized FAQ nodes, the disabling of the FAQ module causes the
vocabulary to lose the association with the FAQ content type. This results in no
FAQ nodes being displayed when you re-enable the FAQ module. Before opening an
issue, please verify that this setting is still in place.
<p> tags appear in FAQ question text
------------------------------------
When using WYSIWYG editors, such as TinyMCE and FCKeditor, <p> and other HTML
tags may appear in the displayed question text. This is because the faq title or
question input box is a textarea and not a textfield, so the faq module can
accommodate longer question texts. The p-tags come from the WYSIWYG editor used
and not the FAQ module. This is because TinyMCE, and other WYSIWYG editors,
attach themselves to all textareas on a given page. Details on how to prevent
this can be found at http://drupal.org/node/294708
Clicking on category links takes user to front page
---------------------------------------------------
Reported for Drupal 5, unconfirmed for Drupal 6.
Instead of being taken to the categorized faq page, the front page is displayed
when the user clicks on a faq category. This is something to do with the
pathauto module and can be easily fixed by doing a bulk update of paths for the
faq vocabulary.

View File

@@ -0,0 +1,666 @@
<?php
/**
* @file
* Administrative page callbacks for the faq module.
*/
/**
* Generates the settings form for the FAQ module.
*
* @param $op
* Default value is NULL; determines what are the permissions of the current
* user on the FAQ.
* @return
* The output, which contains the HTML code for the settings form generated by
* drupal_get_form() function.
*/
function faq_settings_page($op = NULL) {
$output = drupal_get_form('faq_general_settings_form');
return $output;
}
/**
* Define a form to edit the page header and descriptive text.
*
* @return
* The general settings form code stored in the $form variable, before
* converted to HTML.
*/
function faq_general_settings_form($form) {
$form['faq_title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => variable_get('faq_title', 'Frequently Asked Questions'),
);
$form['body_filter']['faq_description'] = array(
'#type' => 'textarea',
'#title' => t('FAQ Description'),
'#default_value' => variable_get('faq_description', ''),
'#description' => t('Your FAQ description. This will be placed at the top of the page, above the questions and can serve as an introductory text.'),
'#rows' => 5,
'#format' => variable_get('faq_description_format', NULL),
);
$form['faq_custom_breadcrumbs'] = array(
'#type' => 'checkbox',
'#title' => t('Create custom breadcrumbs for the FAQ'),
'#description' => t('This option set the breadcrumb path to "%home > %faqtitle > category trail".', array('%home' => t('Home'), '%faqtitle' => variable_get('faq_title', 'Frequently Asked Questions'))),
'#default_value' => variable_get('faq_custom_breadcrumbs', TRUE),
);
return system_settings_form($form);
}
/**
* Define the elements for the FAQ Settings page - Questions tab.
*
* @return
* The form code inside the $form array.
*/
function faq_questions_settings_form($form, &$form_state) {
$form['faq_category_display'] = array(
'#type' => 'hidden',
'#value' => variable_get('faq_category_display', 'categories_inline'),
);
$form['faq_use_categories'] = array(
'#type' => 'hidden',
'#value' => variable_get('faq_use_categories', FALSE),
);
$display_options['questions_inline'] = t('Questions inline');
$display_options['questions_top'] = t('Clicking on question takes user to answer further down the page');
$display_options['hide_answer'] = t('Clicking on question opens/hides answer under question');
$display_options['new_page'] = t('Clicking on question opens the answer in a new page');
$form['faq_display'] = array(
'#type' => 'radios',
'#options' => $display_options,
'#title' => t('Page layout'),
'#description' => t('This controls how the questions and answers are displayed on the page and what happens when someone clicks on the question.'),
'#default_value' => variable_get('faq_display', 'questions_top'),
);
$form['faq_questions_misc'] = array(
'#type' => 'fieldset',
'#title' => t('Miscellaneous layout settings'),
'#collapsible' => TRUE,
);
$form['faq_questions_misc']['faq_question_listing'] = array(
'#type' => 'select',
'#options' => array(
'ol' => t('Ordered list'),
'ul' => t('Unordered list'),
),
'#title' => t('Questions listing style'),
'#default_value' => variable_get('faq_question_listing', 'ul'),
'#states' => array(
'visible' => array(
':input[name="faq_display"], dummy-0' => array('!value' => 'hide_answer'),
':input[name="faq_display"], dummy-1' => array('!value' => 'questions_inline'),
),
),
);
$form['faq_questions_misc']['faq_qa_mark'] = array(
'#type' => 'checkbox',
'#title' => t('Label questions and answers'),
'#description' => t('It labels all questions on the faq page with the "question label" setting and all answers with the "answer label" setting. For example these could be set to "Q:" and "A:".'),
'#default_value' => variable_get('faq_qa_mark', FALSE),
'#states' => array(
'visible' => array(
':input[name="faq_display"], dummy-0' => array('!value' => 'hide_answer'),
':input[name="faq_display"], dummy-1' => array('!value' => 'new_page'),
),
),
);
$form['faq_questions_misc']['faq_question_label'] = array(
'#type' => 'textfield',
'#title' => t('Question Label'),
'#default_value' => variable_get('faq_question_label', 'Q:'),
'#states' => array(
'visible' => array(
':input[name="faq_display"], dummy-0' => array('!value' => 'hide_answer'),
':input[name="faq_display"], dummy-1' => array('!value' => 'new_page'),
':input[name="faq_qa_mark"]' => array('checked' => TRUE),
),
),
);
$form['faq_questions_misc']['faq_answer_label'] = array(
'#type' => 'textfield',
'#title' => t('Answer Label'),
'#default_value' => variable_get('faq_answer_label', 'A:'),
'#states' => array(
'visible' => array(
':input[name="faq_display"], dummy-0' => array('!value' => 'hide_answer'),
':input[name="faq_display"], dummy-1' => array('!value' => 'new_page'),
':input[name="faq_qa_mark"]' => array('checked' => TRUE),
),
),
);
$form['faq_questions_misc']['faq_question_long_form'] = array(
'#type' => 'checkbox',
'#title' => t('Allow long question text to be configured'),
'#default_value' => variable_get('faq_question_long_form', 1),
);
$form['faq_questions_misc']['faq_question_length'] = array(
'#type' => 'radios',
'#title' => t('Question length'),
'#options' => array(
'long' => t('Display longer text'),
'short' => t('Display short text'),
'both' => t('Display both short and long questions'),
),
'#description' => t('The length of question text to display on the FAQ page. The short question will always be displayed in the FAQ blocks.'),
'#default_value' => variable_get('faq_question_length', 'short'),
'#states' => array(
'visible' => array(
':input[name="faq_question_long_form"]' => array('checked' => TRUE),
),
),
);
$form['faq_questions_misc']['faq_hide_qa_accordion'] = array(
'#type' => 'checkbox',
'#title' => t('Use accordion effect'),
'#description' => t('This enables an "accordion" style effect where when a question is clicked, the answer appears beneath, and is then hidden when another question is opened.'),
'#default_value' => variable_get('faq_hide_qa_accordion', FALSE),
'#states' => array(
'visible' => array(
':input[name="faq_display"]' => array('value' => 'hide_answer'),
),
),
);
$form['faq_questions_misc']['faq_show_expand_all'] = array(
'#type' => 'checkbox',
'#title' => t('Show "expand / collapse all" links for collapsed questions'),
'#default_value' => variable_get('faq_show_expand_all', FALSE),
'#states' => array(
'invisible' => array(
':input[name="faq_display"]' => array('!value' => 'hide_answer'),
':input[name="faq_use_categories"]' => array('checked' => FALSE),
':input[name="faq_category_display"]' => array('!value' => 'hide_qa'),
),
),
);
$form['faq_questions_misc']['faq_use_teaser'] = array(
'#type' => 'checkbox',
'#title' => t('Use answer teaser'),
'#default_value' => variable_get('faq_use_teaser', FALSE),
'#states' => array(
'invisible' => array(
':input[name="faq_display"]' => array('value' => 'new_page'),
),
),
);
$form['faq_questions_misc']['faq_show_node_links'] = array(
'#type' => 'checkbox',
'#title' => t('Show node links'),
'#description' => t('This enables the display of links under the answer text on the faq page. Examples of these links include "Read more", "Add comment".'),
'#default_value' => variable_get('faq_show_node_links', FALSE),
'#states' => array(
'invisible' => array(
':input[name="faq_display"]' => array('value' => 'new_page'),
),
),
);
$form['faq_questions_misc']['faq_back_to_top'] = array(
'#type' => 'textfield',
'#title' => t('"Back to Top" link text'),
'#description' => t('This allows the user to change the text displayed for the links which return the user to the top of the page. Defaults to "Back to Top". Leave blank to have no link.'),
'#default_value' => variable_get('faq_back_to_top', 'Back to Top'),
'#states' => array(
'invisible' => array(
':input[name="faq_display"]' => array('value' => 'new_page'),
),
),
);
$form['faq_questions_misc']['faq_disable_node_links'] = array(
'#type' => 'checkbox',
'#title' => t('Disable question links to nodes'),
'#description' => t('This allows the user to prevent the questions being links to the faq node.'),
'#default_value' => variable_get('faq_disable_node_links', FALSE),
'#states' => array(
'invisible' => array(
':input[name="faq_display"]' => array('value' => 'new_page'),
),
),
);
$form['faq_questions_misc']['faq_default_sorting'] = array(
'#type' => 'select',
'#title' => t('Default sorting for unordered FAQs'),
'#options' => array(
'DESC' => t('Date Descending'),
'ASC' => t('Date Ascending'),
),
'#description' => t("This controls the default ordering behaviour for new FAQ nodes which haven't been assigned a position."),
'#default_value' => variable_get('faq_default_sorting', 'DESC'),
);
return system_settings_form($form);
}
/**
* Define the elements for the FAQ Settings page - categories tab.
*
* @return
* The form code inside the $form array.
*/
function faq_categories_settings_form($form, &$form_state) {
$categorization_enabled = variable_get('faq_use_categories', FALSE);
$vocabularies = array();
$vocab_omit = array();
$vocab_options = array();
// Display error messages if the taxonomy module isn't enabled or if there is
// no valid FAQ vocabulary.
if (!module_exists("taxonomy")) {
drupal_set_message(t('Categorization of questions will not work without the "taxonomy" module being enabled.'), 'error');
}
else {
$vocabularies = taxonomy_get_vocabularies('faq');
$vocab_omit = variable_get('faq_omit_vocabulary', array());
foreach ($vocabularies as $vid => $vobj) {
$vocab_options[$vid] = $vobj->name;
}
}
// Set up a hidden variable.
$form['faq_display'] = array(
'#type' => 'hidden',
'#value' => variable_get('faq_display', 'questions_top'),
);
$form['faq_use_categories'] = array(
'#type' => 'checkbox',
'#title' => t('Categorize questions'),
'#description' => t('This allows the user to display the questions according to the categories configured on the add/edit FAQ page. Use of sub-categories is only recommended for large lists of questions. The Taxonomy module must be enabled.'),
'#default_value' => $categorization_enabled,
);
$category_options['none'] = t("Don't display");
$category_options['categories_inline'] = t('Categories inline');
$category_options['hide_qa'] = t('Clicking on category opens/hides questions and answers under category');
$category_options['new_page'] = t('Clicking on category opens the questions/answers in a new page');
$form['faq_category_display'] = array(
'#type' => 'radios',
'#options' => $category_options,
'#title' => t('Categories layout'),
'#description' => t('This controls how the categories are displayed on the page and what happens when someone clicks on the category.'),
'#default_value' => variable_get('faq_category_display', 'categories_inline'),
'#states' => array(
'visible' => array(
':input[name="faq_use_categories"]' => array('checked' => TRUE),
),
),
);
$form['faq_category_misc'] = array(
'#type' => 'fieldset',
'#title' => t('Miscellaneous layout settings'),
'#collapsible' => TRUE,
'#states' => array(
'visible' => array(
':input[name="faq_use_categories"]' => array('checked' => TRUE),
),
),
);
$form['faq_category_misc']['faq_category_listing'] = array(
'#type' => 'select',
'#options' => array(
'ol' => t('Ordered list'),
'ul' => t('Unordered list'),
),
'#title' => t('Categories listing style'),
'#description' => t('This allows to select how the categories listing is presented. An ordered listing would number the categories, whereas an unordered list will have a bullet to the left of each category.'),
'#default_value' => variable_get('faq_category_listing', 'ul'),
'#states' => array(
'visible' => array(
':input[name="faq_category_display"]' => array('value' => 'new_page'),
),
),
);
$form['faq_category_misc']['faq_category_hide_qa_accordion'] = array(
'#type' => 'checkbox',
'#title' => t('Use accordion effect'),
'#description' => t('This enables an "accordion" style effect where when a category is clicked, the questions appears beneath, and is then hidden when another category is opened.'),
'#default_value' => variable_get('faq_category_hide_qa_accordion', FALSE),
'#states' => array(
'visible' => array(
':input[name="faq_category_display"]' => array('value' => 'hide_qa'),
),
),
);
$form['faq_category_misc']['faq_count'] = array(
'#type' => 'checkbox',
'#title' => t('Show FAQ count'),
'#description' => t('This displays the number of questions in a category after the category name.'),
'#default_value' => variable_get('faq_count', FALSE),
);
$form['faq_category_misc']['faq_answer_category_name'] = array(
'#type' => 'checkbox',
'#title' => t('Display category name for answers'),
'#description' => t('This allows the user to toggle the visibility of the category name above each answer section.'),
'#default_value' => variable_get('faq_answer_category_name', FALSE),
'#states' => array(
'visible' => array(
':input[name="faq_display"]' => array('value' => 'hide_qa'),
),
),
);
$form['faq_category_misc']['faq_group_questions_top'] = array(
'#type' => 'checkbox',
'#title' => t("Group questions and answers"),
'#default_value' => variable_get('faq_group_questions_top', FALSE),
'#states' => array(
'visible' => array(
':input[name="faq_category_display"]' => array('value' => 'categories_inline'),
':input[name="faq_display"]' => array('value' => 'hide_qa'),
),
),
);
$form['faq_category_misc']['faq_hide_child_terms'] = array(
'#type' => 'checkbox',
'#title' => t('Only show sub-categories when parent category is selected'),
'#description' => t('This allows the user more control over how and when sub-categories are displayed.'),
'#default_value' => variable_get('faq_hide_child_terms', FALSE),
'#states' => array(
'invisible' => array(
':input[name="faq_category_display"]' => array('value' => 'categories_inline'),
),
),
);
$form['faq_category_misc']['faq_show_term_page_children'] = array(
'#type' => 'checkbox',
'#title' => t('Show sub-categories on FAQ category pages'),
'#description' => t("Sub-categories with 'faq' nodes will be displayed on the per category FAQ page. This will also happen if 'Only show sub-categories when parent category is selected' is set."),
'#default_value' => variable_get('faq_show_term_page_children', FALSE),
'#states' => array(
'visible' => array(
':input[name="faq_hide_child_terms"]' => array('checked' => FALSE),
':input[name="faq_category_display"]' => array('!value' => 'categories_inline'),
),
),
);
if (module_exists('taxonomy') && !empty($vocab_options)) {
$form['faq_category_advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced category settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#states' => array(
'visible' => array(
':input[name="faq_use_categories"]' => array('checked' => TRUE),
),
),
);
$form['faq_category_advanced']['faq_omit_vocabulary'] = array(
'#type' => 'checkboxes',
'#title' => t('Omit vocabulary'),
'#description' => t('Terms from these vocabularies will be <em>excluded</em> from the FAQ pages.'),
'#default_value' => variable_get('faq_omit_vocabulary', array()),
'#options' => $vocab_options,
'#multiple' => TRUE,
);
}
$form['#submit'][] = 'faq_categories_settings_form_submit';
return system_settings_form($form);
}
/**
* Display an error if no valid FAQ vocabularies available.
*/
function faq_categories_settings_form_submit($form, &$form_state) {
if ($form_state['values']['faq_use_categories'] && isset($form_state['values']['faq_omit_vocabulary'])) {
$vocabularies = taxonomy_get_vocabularies('faq');
$vocab_omit = $form_state['values']['faq_omit_vocabulary'];
$valid_vocab = FALSE;
foreach ($vocabularies as $vid => $vobj) {
if (empty($vocab_omit[$vid])) {
$valid_vocab = TRUE;
}
}
if (!$valid_vocab) {
drupal_set_message(t('Categories are enabled but no vocabulary is associated with the FAQ content type. Either create a vocabulary or disable categorization in order for questions to appear.'), 'error');
}
}
}
/**
* Define the elements for the FAQ Settings page - order tab.
*
* @param $form_state
* Store the submitted form values.
* @return
* The form code, before being converted to HTML format.
*/
function faq_order_settings_form($form, $form_state, $category = NULL) {
$order = $date_order = '';
drupal_add_js(array('faq' => array('faq_hide_qa_accordion' => variable_get('faq_hide_qa_accordion', FALSE))), array('type' => 'setting', 'scope' => JS_DEFAULT));
drupal_add_js(array('faq' => array('faq_category_hide_qa_accordion' => variable_get('faq_category_hide_qa_accordion', FALSE))), array('type' => 'setting', 'scope' => JS_DEFAULT));
drupal_add_js(drupal_get_path('module', 'faq') . '/faq.js');
drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css');
$use_categories = variable_get('faq_use_categories', FALSE);
if (!$use_categories) {
$step = "order";
}
elseif (!isset($form_state['values']) && empty($category)) {
$step = "categories";
}
else {
$step = "order";
}
$form['step'] = array(
'#type' => 'value',
'#value' => $step,
);
// Categorized q/a.
if ($step == "categories") {
// Get list of categories.
$vocabularies = taxonomy_get_vocabularies('faq');
$options = array();
foreach ($vocabularies as $vid => $vobj) {
$tree = taxonomy_get_tree($vid);
foreach ($tree as $term) {
if (!faq_taxonomy_term_count_nodes($term->tid)) {
continue;
}
$options[$term->tid] = faq_tt("taxonomy:term:$term->tid:name", $term->name);
$form['choose_cat']['faq_category'] = array(
'#type' => 'select',
'#title' => t('Choose a category'),
'#description' => t('Choose a category that you wish to order the questions for.'),
'#options' => $options,
'#multiple' => FALSE,
);
$form['choose_cat']['search'] = array(
'#type' => 'submit',
'#value' => t('Search'),
'#submit' => array('faq_order_settings_choose_cat_form_submit'),
);
}
}
}
else {
$default_sorting = variable_get('faq_default_sorting', 'DESC');
$default_weight = 0;
if ($default_sorting != 'DESC') {
$default_weight = 1000000;
}
$options = array();
if (!empty($form_state['values']['faq_category'])) {
$category = $form_state['values']['faq_category'];
}
// Uncategorized ordering.
$query = db_select('node', 'n')
->fields('n', array('nid', 'title'))
->addTag('node_access')
->condition('n.type', 'faq')
->condition('n.status', 1);
// Works, but involves variable concatenation - safe though, since
// $default_weight is an integer.
$query->addExpression("COALESCE(w.weight, $default_weight)", 'effective_weight');
// Doesn't work in Postgres.
//$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight));
if (empty($category)) {
$category = 0;
$w_alias = $query->leftJoin('faq_weights', 'w', 'n.nid = %alias.nid AND %alias.tid = :category', array(':category' => $category));
$query->orderBy('effective_weight', 'ASC')
->orderBy('n.sticky', 'DESC')
->orderBy('n.created', $default_sorting == 'DESC' ? 'DESC' : 'ASC');
}
// Categorized ordering.
else {
$ti_alias = $query->innerJoin('taxonomy_index', 'ti', '(n.nid = %alias.nid)');
$w_alias = $query->leftJoin('faq_weights', 'w', 'n.nid = %alias.nid AND %alias.tid = :category', array(':category' => $category));
$query->condition('ti.tid', $category);
$query->orderBy('effective_weight', 'ASC')
->orderBy('n.sticky', 'DESC')
->orderBy('n.created', $default_sorting == 'DESC' ? 'DESC' : 'ASC');
}
$options = $query->execute()->fetchAll();
$form['weight']['faq_category'] = array(
'#type' => 'value',
'#value' => $category,
);
// Show table ordering form.
$form['order_no_cats']['#tree'] = TRUE;
$form['order_no_cats']['#theme'] = 'faq_draggable_question_order_table';
$i = 0;
foreach ($options as $record) {
$form['order_no_cats'][$i]['nid'] = array(
'#type' => 'hidden',
'#value' => $record->nid,
);
$form['order_no_cats'][$i]['title'] = array('#markup' => check_plain($record->title));
$form['order_no_cats'][$i]['sort'] = array(
'#type' => 'weight',
'#delta' => count($options),
'#default_value' => $i,
);
$i++;
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save order'),
'#weight' => 3,
'#submit' => array('faq_order_settings_reorder_form_submit'),
);
}
return $form;
}
/**
* Function set the rebuild of the form in the FAQ Settings - Weight tab.
*
* @param $form
* Array, containing the form structure.
* @param &$form_state
* The 'rebuild' key inside $form_state['rebuild'] structure, overrides the
* 'redirect' key: when it is set to TRUE, the form will be rebuilt from
* scratch and displayed on screen.
*/
function faq_order_settings_choose_cat_form_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}
/**
* Save the options set by the user in the FAQ Settings - Weight tab.
*
* @param $form
* Array, containing the form structure.
* @param &$form_state
* $form_state['values'] stores the submitted values from the form.
*/
function faq_order_settings_reorder_form_submit($form, &$form_state) {
if ($form_state['values']['op'] == t('Save order') && !empty($form_state['values']['order_no_cats'])) {
foreach ($form_state['values']['order_no_cats'] as $i => $faq) {
$nid = $faq['nid'];
$index = $faq['sort'];
db_merge('faq_weights')
->fields(array(
'weight' => $index,
))
->key(array(
'tid' => $form_state['values']['faq_category'],
'nid' => $nid,
))
->execute();
$result = NULL;
// If node translation module enabled, update order of the translation
// node counterparts.
if (module_exists('translation')) {
$node = node_load($nid);
if ($node->tnid) {
$translations = translation_node_get_translations($node->tnid);
if (!empty($translations)) {
foreach ($translations as $language => $tnode) {
db_merge('faq_weights')
->fields(array(
'weight' => $index,
))
->key(array(
'tid' => $form_state['values']['faq_category'],
'nid' => $tnode->nid,
))
->execute();
}
}
}
}
}
drupal_set_message(t('Configuration has been updated.'));
}
}

View File

@@ -0,0 +1,62 @@
.faq-category-indent {
padding-left: 20px;
}
.faq-more-link {
font-size: 0.85em;
margin-left: 30em;
margin-top: 0;
margin-bottom: -1.25em;
text-align: right;
}
.faq-top-link {
font-size: 0.8em;
margin-top:0;
margin-bottom: 0;
padding-bottom: 1.0em;
}
.faq-question {
padding-top: 5px;
padding-left: 20px;
}
.faq-answer {
padding-left: 40px;
}
.faq-answer .faq-answer-label {
float: left;
margin-right: 0.5em;
}
.faq-dl-hide-answer {
padding-bottom: 15px;
}
img.faq-tax-image {
float: left;
padding: 0px 3px 0px 3px;
}
div.faq-detailed-question {
font-style: italic;
}
.faq .collapsible {
display: block;
}
.faq .collapsed {
display: none;
}
.faq #faq-expand-all {
text-align: right;
display: none;
}
.faq #faq-expand-all a.faq-expand-all-link,
.faq #faq-expand-all a.faq-collapse-all-link {
display: none;
}

View File

@@ -0,0 +1,30 @@
name = Frequently Asked Questions
description = "Manages configuration of questions for a FAQ page."
core = 7.x
files[] = faq.admin.inc
files[] = faq.install
files[] = faq.module
files[] = faq.test
files[] = includes/faq-category-hide-answer.tpl.php
files[] = includes/faq-category-new-page.tpl.php
files[] = includes/faq-category-questions-inline.tpl.php
files[] = includes/faq-category-questions-top-answers.tpl.php
files[] = includes/faq-category-questions-top.tpl.php
files[] = includes/faq-hide-answer.tpl.php
files[] = includes/faq-new-page.tpl.php
files[] = includes/faq-questions-inline.tpl.php
files[] = includes/faq-questions-top.tpl.php
files[] = includes/faq.hide_answer.inc
files[] = includes/faq.new_page.inc
files[] = includes/faq.questions_inline.inc
files[] = includes/faq.questions_top.inc
files[] = views/faq.views.inc
configure = /admin/config/content/faq
; Information added by drupal.org packaging script on 2013-09-30
version = "7.x-1.0-rc2+8-dev"
core = "7.x"
project = "faq"
datestamp = "1380577865"

View File

@@ -0,0 +1,266 @@
<?php
/**
* @file
* FAQ module install file.
*/
/**
* Define the 'faq_weights' and 'faq_questions' table structures.
*
* @return
* The schema which contains the structure for the faq module's tables.
*/
function faq_schema() {
$schema['faq_weights'] = array(
'description' => 'A table containing the weight of each faq node by category.',
'fields' => array(
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The primary identifier for a term or category. This will be 0 for non-categorized nodes.',
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The primary identifier for a node.',
),
'weight' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'description' => 'A number representing the weight of a node. Nodes with lower weight values will appear above those with higher weight values.',
),
),
'primary key' => array('nid', 'tid'),
);
$schema['faq_questions'] = array(
'description' => 'A table containing the long question text of each faq node revision.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The primary identifier for a node.',
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The primary identifier for a node revision.',
),
'question' => array(
'type' => 'text',
'size' => 'normal',
'not null' => TRUE,
'description' => 'The faq short question text.',
),
'detailed_question' => array(
'type' => 'text',
'size' => 'normal',
'not null' => FALSE,
'description' => 'The faq long question text.',
),
),
'primary key' => array('nid', 'vid'),
);
return $schema;
}
/**
* Implements hook_install().
*
* Inserts the FAQ module's schema in the SQL database.
*/
function faq_install() {
variable_set('node_type_faq', array('status'));
$t = get_t();
// Ensure the FAQ node type is available.
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['faq']);
// Change the default label on the body field.
$body_instance = field_info_instance('node', 'body', 'faq');
$body_instance['label'] = $t('Answer');
field_update_instance($body_instance);
}
/**
* Implements hook_uninstall().
*
* Remove the variables, nodes and schema corresponding to the FAQ module.
*/
function faq_uninstall() {
// Delete the variables we created.
// General settings.
variable_del('faq_title');
variable_del('faq_description');
variable_del('faq_description_format');
// Questions page.
variable_del('faq_display');
variable_del('faq_question_listing');
variable_del('faq_qa_mark');
variable_del('faq_question_label');
variable_del('faq_answer_label');
variable_del('faq_question_length');
variable_del('faq_hide_qa_accordion');
variable_del('faq_show_expand_all');
variable_del('faq_use_teaser');
variable_del('faq_show_node_links');
variable_del('faq_back_to_top');
variable_del('faq_disable_node_links');
variable_del('faq_default_sorting');
// Categories page.
variable_del('faq_use_categories');
variable_del('faq_category_display');
variable_del('faq_category_listing');
variable_del('faq_category_hide_qa_accordion');
variable_del('faq_count');
variable_del('faq_answer_category_name');
variable_del('faq_group_questions_top');
variable_del('faq_hide_child_terms');
variable_del('faq_show_term_page_children');
variable_del('faq_omit_vocabulary');
variable_del('faq_enable_term_links');
// Block settings.
variable_del('faq_block_recent_faq_count');
variable_del('faq_block_random_faq_count');
// Custom breadcrumbs control
variable_del('faq_custom_breadcrumbs');
// Deprecated.
variable_del('faq_more_link');
// Clear the cache tables.
cache_clear_all('*', 'cache', TRUE);
cache_clear_all('*', 'cache_filter', TRUE);
cache_clear_all('*', 'cache_menu', TRUE);
cache_clear_all('*', 'cache_page', TRUE);
}
/**
* Create 'faq_weights' table in order to upgrade from older installations.
*/
function faq_update_1() {
$schema['faq_weights'] = array(
'description' => 'A table containing the weight of each faq node by category.',
'fields' => array(
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'weight' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('nid', 'tid'),
);
$ret = array();
db_create_table('faq_weights', $schema['faq_weights']);
return t('FAQ weighting table created.');
}
/**
* Create 'faq_questions' table in order to upgrade from older installations.
*/
function faq_update_2() {
$schema['faq_questions'] = array(
'description' => 'A table containing the long question text of each faq node revision.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The primary identifier for a node.',
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The primary identifier for a node revision.',
),
'question' => array(
'type' => 'text',
'size' => 'normal',
'not null' => TRUE,
'description' => 'The faq long question text.',
),
),
'primary key' => array('nid', 'vid'),
);
db_create_table('faq_questions', $schema['faq_questions']);
// Pre-populate the questions table from the existing nodes.
$select = db_select('node', 'n');
$select->innerJoin('node_revisions', 'r', 'n.nid = %alias.nid');
$select
->fields('r', array('nid', 'vid', 'title'))
->condition('n.type', 'faq');
db_insert('faq_questions')
->fields(array('nid', 'vid', 'question'))
->from($select)
->execute();
return t('FAQ Questions table created.');
}
/**
* Add the 'detailed_question' column to the 'faq_questions' table.
*/
function faq_update_6003() {
$ret = array();
db_add_field('faq_questions', 'detailed_question', array('type' => 'text', 'size' => 'normal', 'not null' => TRUE));
db_update('faq_questions')
->expression('detailed_question', 'question')
->execute();
return t('Detailed question column added. Existing nodes have been given the same detailed question as current question.');
}
/**
* Make'detailed_question' column nullable.
*/
function faq_update_7000() {
db_change_field('faq_questions', 'detailed_question', 'detailed_question', array('type' => 'text', 'size' => 'normal', 'not null' => FALSE));
return t('Detailed question field can now be null.');
}
/**
* Delete obsolete variables.
*/
function faq_update_7001() {
variable_del('faq_block_recent_faq_count');
variable_del('faq_block_random_faq_count');
variable_del('faq_enable_term_links');
return t('Deleted obsolete variables.');
}

View File

@@ -0,0 +1,128 @@
(function ($) {
Drupal.behaviors.initFaqModule = {
attach: function (context) {
// Hide/show answer for a question.
var faq_hide_qa_accordion = Drupal.settings.faq.faq_hide_qa_accordion;
$('div.faq-dd-hide-answer', context).addClass("collapsible collapsed");
if (!faq_hide_qa_accordion) {
$('div.faq-dd-hide-answer:not(.faq-processed)', context).addClass('faq-processed').hide();
}
$('div.faq-dt-hide-answer:not(.faq-processed)', context).addClass('faq-processed').click(function() {
if (faq_hide_qa_accordion) {
$('div.faq-dt-hide-answer').not($(this)).removeClass('faq-qa-visible');
}
$(this).toggleClass('faq-qa-visible');
$(this).parent().addClass('faq-viewed');
$('div.faq-dd-hide-answer').not($(this).next('div.faq-dd-hide-answer')).addClass("collapsed");
if (!faq_hide_qa_accordion) {
$(this).next('div.faq-dd-hide-answer').slideToggle('fast', function() {
$(this).parent().toggleClass('expanded');
});
}
$(this).next('div.faq-dd-hide-answer').toggleClass("collapsed");
// Change the fragment, too, for permalink/bookmark.
// To keep the current page from scrolling, refs
// http://stackoverflow.com/questions/1489624/modifying-document-location-hash-without-page-scrolling/1489802#1489802
var hash = $(this).find('a').attr('id');
var fx, node = $('#' + hash);
if (node.length) {
fx = $('<div></div>')
.css({position: 'absolute', visibility: 'hidden', top: $(window).scrollTop() + 'px'})
.attr('id', hash)
.appendTo(document.body);
node.attr('id', '');
}
document.location.hash = hash;
if (node.length) {
fx.remove();
node.attr('id', hash);
}
// Scroll the page if the collapsed FAQ is not visible.
// If we have the toolbar so the title may be hidden by the bar.
var mainScrollTop = Math.max($('html', context).scrollTop(), $('body', context).scrollTop());
// We compute mainScrollTop because the behaviour is different on FF, IE and CR
if (mainScrollTop > $(this).offset().top) {
$('html, body', context).animate({
scrollTop: $(this).offset().top
}, 1);
}
return false;
});
// Show any question identified by a fragment
if (/^#\w+$/.test(document.location.hash)) {
$('div.faq-dt-hide-answer ' + document.location.hash).parents('.faq-dt-hide-answer').triggerHandler('click');
}
// Hide/show q/a for a category.
var faq_category_hide_qa_accordion = Drupal.settings.faq.faq_category_hide_qa_accordion;
$('div.faq-qa-hide', context).addClass("collapsible collapsed");
if (!faq_category_hide_qa_accordion) {
$('div.faq-qa-hide', context).hide();
}
$('div.faq-qa-header .faq-header:not(.faq-processed)', context).addClass('faq-processed').click(function() {
if (faq_category_hide_qa_accordion) {
$('div.faq-qa-header .faq-header').not($(this)).removeClass('faq-category-qa-visible');
}
$(this).toggleClass('faq-category-qa-visible');
$('div.faq-qa-hide').not($(this).parent().next('div.faq-qa-hide')).addClass("collapsed");
if (!faq_category_hide_qa_accordion) {
$(this).parent().next('div.faq-qa-hide').slideToggle('fast', function() {
$(this).parent().toggleClass('expanded');
});
}
$(this).parent().next('div.faq-qa-hide').toggleClass("collapsed");
// Scroll the page if the collapsed FAQ is not visible.
// If we have the toolbar so the title may be hidden by the bar.
var mainScrollTop = Math.max($('html', context).scrollTop(), $('body', context).scrollTop());
// We compute mainScrollTop because the behaviour is different on FF, IE and CR
if (mainScrollTop > $(this).offset().top) {
$('html, body', context).animate({
scrollTop: $(this).offset().top
}, 1);
}
return false;
});
// Show expand all link.
if (!faq_hide_qa_accordion && !faq_category_hide_qa_accordion) {
$('#faq-expand-all', context).show();
$('#faq-expand-all a.faq-expand-all-link', context).show();
// Add collapse link click event.
$('#faq-expand-all a.faq-collapse-all-link:not(.faq-processed)', context).addClass('faq-processed').click(function () {
$(this).hide();
$('#faq-expand-all a.faq-expand-all-link').show();
$('div.faq-qa-hide').slideUp('slow', function() {
$(this).removeClass('expanded');
});
$('div.faq-dd-hide-answer').slideUp('slow', function() {
$(this).removeClass('expanded');
});
});
// Add expand link click event.
$('#faq-expand-all a.faq-expand-all-link:not(.faq-processed)', context).addClass('faq-processed').click(function () {
$(this).hide();
$('#faq-expand-all a.faq-collapse-all-link').show();
$('div.faq-qa-hide').slideDown('slow', function() {
$(this).addClass('expanded');
});
$('div.faq-dd-hide-answer').slideDown('slow', function() {
$(this).addClass('expanded');
});
});
}
}
}
})(jQuery);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,368 @@
<?php
/**
* @file
* Test FAQ functionality Base test class. All tests inherits this one.
* Hugely based on code from the test file block.test by boombatower
*/
/**
* Base class that is extended by test cases
*/
class FaqTestCase extends DrupalWebTestCase {
protected $admin_user, $faq_user;
protected $taxonomy;
protected $term, $faq1, $faq2;
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('FAQ functionality'),
'description' => t('Base class. No tests here.'),
'group' => t('Frequently Asked Questions'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
// Install FAQ Module.
parent::setUp('taxonomy', 'faq');
// Create and log in user with administer taxonomy permissions.
$this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'administer faq', 'administer faq order', 'administer blocks'));
$this->drupalLogin($this->admin_user);
$this->faq_user = $this->drupalCreateUser(array('create faq content', 'edit any faq content', 'delete any faq content', 'view faq page', 'access content'));
// Set up the vocab and terms.
$this->setupTaxonomy();
// Categorize questions.
$this->drupalPost('admin/config/content/faq/categories', array('faq_use_categories' => '1'), t('Save configuration'));
// Set answer_user as default expert.
$roles = $this->faq_user->roles;
end($roles); // Set to last role (the unique one)
// Start all tests logged out.
$this->drupalLogout();
}
/**
* Tear the whole thing down again
*/
function tearDown() {
// Things to tidy up like vars and stuff
parent::tearDown();
}
/**
* Generates a random string of ASCII numeric characters (values 48 to 57).
*
* @param $length
* Length of random string to generate .
* @return
* Randomly generated string.
*/
protected static function randomNumber($length = 8) {
$str = '';
for ($i = 0; $i < $length; $i++) {
$str .= chr(mt_rand(48, 57));
}
return $str;
}
/**
* Verify that current user has no access to page.
*
* @param $url
* URL to verify.
*/
function faqVerifyNoAccess($url) {
// Test that page returns 403 Access Denied
$this->drupalGet($url);
$this->assertResponse(403);
}
/**
* Set up the taxonomy - all vocabularies and stuff
* Values also stored in protected variable $tax
*/
function setupTaxonomy() {
// Create vocabulary.
$this->vocabulary = $vocabulary = new stdClass();
$vocabulary->name = $this->randomName(8);
$vocabulary->description = $this->randomName(64);
$vocabulary->machine_name = drupal_strtolower($this->randomName());
$vocabulary->help = '';
$vocabulary->nodes = array('faq' => 'faq');
$vocabulary->weight = mt_rand(0, 10);
taxonomy_vocabulary_save($vocabulary);
$field = array(
'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $this->vocabulary->machine_name,
'parent' => 0,
),
),
),
);
field_create_field($field);
$this->instance = array(
'field_name' => 'taxonomy_' . $this->vocabulary->machine_name,
'bundle' => 'faq',
'entity_type' => 'node',
'widget' => array(
'type' => 'taxonomy_autocomplete',
),
'display' => array(
'default' => array(
'type' => 'taxonomy_term_reference_link',
),
),
);
field_create_instance($this->instance);
// Add term
// Click the last occurrence of the link.
$this->term = $term = new stdClass();
$term->name = $this->randomName(8);
$term->description = $this->randomName(64);
// Use the first available text format.
$term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField();
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
}
/**
* Test accessing the FAQ page
*/
}
class FaqAccessTestClass extends FaqTestCase {
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('Access to FAQ pages'),
'description' => t('Access to pages by anonymous user and logged in user with rights.'),
'group' => t('Frequently Asked Questions'),
);
}
function testFaqAccess() {
// Verify that anonymous user has no access to the faq page
$this->faqVerifyNoAccess('faq-page');
// Create and login user
$normal_user = $this->drupalCreateUser();
$this->drupalLogin($normal_user);
// Verify that logged in user has no access to the faq page
$this->faqVerifyNoAccess('faq-page');
$this->drupalLogout();
$view_faq_user = $this->drupalCreateUser(array('view faq page'));
$this->drupalLogin($view_faq_user);
// Verify that the faq page is visible and available but empty
$this->drupalGet('faq-page');
$this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
}
}
class CreateFaqTestCase extends FaqTestCase {
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('Create FAQ node'),
'description' => t('Add, edit and delete FAQ nodes when FAQ module is enabled.'),
'group' => t('Frequently Asked Questions'),
);
}
/**
* Test creating a FAQ node
*/
function testFaqCreate() {
// Create and log in user with create FAQ permissions
$this->admin_user = $this->drupalCreateUser(array('create faq content', 'view faq page'));
$this->drupalLogin($this->admin_user);
// Verify that the faq page is visible and available but empty
$this->drupalGet('faq-page');
$this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
// Fill in the Create FAQ node 1 form and post it
$langcode = LANGUAGE_NONE;
$this->faq1 = array();
$this->faq1['title'] = 'faq1_'. $this->randomName(8);
$this->faq1[$this->instance['field_name'] . '[' . $langcode .']'] = $this->term->name;
$this->faq1['detailed_question'] = $this->randomName(16);
$this->faq1["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/faq', $this->faq1, t('Save'));
// Check that new FAQ node has actually been created
$this->assertText(t('FAQ @title has been created.', array('@title' => $this->faq1['title'])));
// Fill in the Create FAQ node 2 form and post it
$this->faq2 = array();
$this->faq2['title'] = 'faq2_'. $this->randomName(8);
$this->faq2[$this->instance['field_name'] . '[' . $langcode .']'] = $this->randomName(8); // Add new term
$this->faq2['detailed_question'] = $this->randomName(16);
$this->faq2["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/faq', $this->faq2, t('Save'));
// Check that new FAQ node has actually been created
$this->assertText(t('FAQ @title has been created.', array('@title' => $this->faq2['title'])));
// New user
$this->drupalLogout();
// Verify that logged in user has no access to the faq page
$this->faqVerifyNoAccess('faq-page');
// Check that the FAQ page is available and that the correct term is listed as grouping for the new FAQ node
$view_faq_user = $this->drupalCreateUser(array('view faq page'));
$this->drupalLogin($view_faq_user);
$this->drupalGet('faq-page');
$this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
$this->assertText($this->faq1['title'], t('Created FAQ node 1 available on FAQ page.'));
$this->assertText($this->faq1[$this->instance['field_name'] . '[' . $langcode .']'], t('Term for node 1 available on FAQ page.'));
$this->assertText($this->faq2['title'], t('Created FAQ node 2 available on FAQ page.'));
$this->assertText($this->faq2[$this->instance['field_name'] . '[' . $langcode .']'], t('Term for node 2 available on FAQ page.'));
// Navigate to FAQ node created on FAQ page
$this->clickLink(t($this->faq1['title']));
$this->assertText(t($this->faq1["body[$langcode][0][value]"]));
// Enable categorisation of FAQ nodes
// Create and log in user with create and administer FAQ permissions
$this->admin_user = $this->drupalCreateUser(array('create faq content', 'view faq page', 'administer faq'));
$this->drupalLogin($this->admin_user);
// faq_use_categories
$faqcfg = array();
$faqcfg['faq_use_categories'] = '1'; // Enable categorised FAQs
$this->drupalPost('admin/config/content/faq/categories', $faqcfg, t('Save configuration'));
$this->drupalLogout();
$this->drupalLogin($view_faq_user);
$this->drupalGet('faq-page');
$this->assertText(t('Frequently Asked Questions'), t('FAQ page is available for view faq page permissions.'));
$this->assertText($this->faq1['title'], t('Created FAQ node 1 available on FAQ page.'));
$this->assertText($this->faq1[$this->instance['field_name'] . '[' . $langcode .']'], t('Term for node 1 not available on FAQ page.'));
$this->assertText($this->faq2['title'], t('Created FAQ node 2 available on FAQ page.'));
$this->assertText($this->faq2[$this->instance['field_name'] . '[' . $langcode .']'], t('Term for node 2 not available on FAQ page.'));
// TODO: Add update and Delete of FAQ nodes
}
}
class CRAUDFaqTestCase extends FaqTestCase {
/**
* Implementation of getInfo().
*/
public static function getInfo() {
return array(
'name' => t('CRUD Question'),
'description' => t('Create, read, update and delete a question'),
'group' => t('Frequently Asked Questions'),
);
}
/**
* Test creating an FAQ and verify its status
*/
public function testFaqCreate() {
// Verify that logged in user has no access to the faq page
$this->faqVerifyNoAccess('faq-page');
// Log in user with create FAQ permissions
$this->drupalLogin($this->faq_user);
// Create a FAQ node.
$edit = array();
$edit['title'] = $this->randomName(8);
$edit[$this->instance['field_name'] . '['. LANGUAGE_NONE .']'] = $this->randomName(8);
$edit['detailed_question'] = $this->randomName(64);
$edit['body['. LANGUAGE_NONE .'][0][value]'] = $this->randomString(264);
$this->drupalPost('node/add/faq', $edit, t('Save'));
$this->assertText(t('FAQ @title has been created.', array('@title' => $edit['title'])));
// Check status for FAQ node - should be published
$node = $this->drupalGetNodeByTitle($edit['title']);
$this->assertTrue($node->status);
$this->drupalLogout();
// Verify that anonymous user has no access to the unanswered node display
// $this->faqVerifyNoAccess('node/' . $node->nid);
$this->drupalGet('node/' . $node->nid . '/edit'); // Open edit page with node
// $this->assertResponse(200);
// Create and log in user with view FAQ permissions
$faq_view_user = $this->drupalCreateUser(array('view faq page'));
$this->drupalLogin($faq_view_user);
// Verify visibility on faq page
$this->drupalGet('faq-page'); // Load faq page
$this->assertText($edit['title']); // Node should be listed here
$this->drupalGet('node/' . $node->nid); // It should also be possible to open the node directly
// Update FAQ
// Log in user with answer question. Must also have edit any faq content and view faq page permissions.
$this->drupalLogin($this->faq_user);
$edit2['title'] = 'title-' . $this->randomName(8);
$edit2['body['. LANGUAGE_NONE .'][0][value]'] = 'body-' . $this->randomName(64);
$this->drupalPost('node/' . $node->nid . '/edit', $edit2, t('Save'));
$this->assertText(t('FAQ @title has been updated.', array('@title' => $edit2['title'])));
$this->assertText($edit2['title'], 'Title has changed');
$this->assertText($edit2['body['. LANGUAGE_NONE .'][0][value]'], 'Body has changed');
// Delete FAQ
// Try deleting faq by edit faq permission
$this->drupalPost('node/' . $node->nid . '/edit', array(), t('Delete'));
// Log in user with delete FAQ permissions
$this->drupalLogin($this->admin_user);
$this->drupalPost('node/' . $node->nid . '/edit', array(), t('Delete'));
$this->assertText(t('Are you sure you want to delete @title?', array('@title' => $edit2['title'])));
$this->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
$this->assertText(t('FAQ @title has been deleted.', array('@title' => $edit2['title'])));
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* Implements hook_variable_info().
*/
function faq_variable_info($options) {
$variable['faq_title'] = array(
'title' => t('FAQ page title', array(), $options),
'description' => t('FAQ page title', array(), $options),
'type' => 'string',
'access' => 'administer faq',
);
$variable['faq_description'] = array(
'title' => t('FAQ page description', array(), $options),
'description' => t('FAQ page description', array(), $options),
'type' => 'string',
'access' => 'administer faq',
);
$variable['faq_question_label'] = array(
'title' => t('FAQ question label', array(), $options),
'description' => t('FAQ question label', array(), $options),
'type' => 'string',
'access' => 'administer faq',
);
$variable['faq_answer_label'] = array(
'title' => t('FAQ answer label', array(), $options),
'description' => t('FAQ answer label', array(), $options),
'type' => 'string',
'access' => 'administer faq',
);
$variable['faq_back_to_top'] = array(
'title' => t('FAQ "back to top" link', array(), $options),
'description' => t('FAQ "back to top" link', array(), $options),
'type' => 'string',
'access' => 'administer faq',
);
return $variable;
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* @file
* Template file for the FAQ page if set to show/hide categorized answers when
* the question is clicked.
*/
/**
* Available variables:
*
* $display_header
* Boolean value controlling whether a header should be displayed.
* $header_title
* The category title.
* $category_depth
* The term or category depth.
* $description
* The current page's description.
* $term_image
* The HTML for the category image. This is empty if the taxonomy image module
* is not enabled or there is no image associated with the term.
* $display_faq_count
* Boolean value controlling whether or not the number of faqs in a category
* should be displayed.
* $question_count
* The number of questions in category.
* $nodes
* An array of nodes to be displayed.
* Each node stored in the $nodes array has the following information:
* $node['question'] is the question text.
* $node['body'] is the answer text.
* $node['links'] represents the node links, e.g. "Read more".
* $use_teaser
* Whether $node['body'] contains the full body or just the teaser text.
* $container_class
* The class attribute of the element containing the sub-categories, either
* 'faq-qa' or 'faq-qa-hide'. This is used by javascript to open/hide
* a category's faqs.
* $subcat_list
* An array of sub-categories. Each sub-category stored in the $subcat_list
* array has the following information:
* $subcat['link'] is the link to the sub-category.
* $subcat['description'] is the sub-category description.
* $subcat['count'] is the number of questions in the sub-category.
* $subcat['term_image'] is the sub-category (taxonomy) image.
* $subcat_list_style
* The style of the sub-category list, either ol or ul (ordered or unordered).
* $subcat_body_list
* The sub-categories faqs, recursively themed (by this template).
*/
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
?><div class="faq-category-group">
<!-- category header with title, link, image, description, and count of
questions inside -->
<div class="faq-qa-header">
<?php if ($display_header): ?>
<<?php print $hdr; ?> class="faq-header">
<?php print $term_image; ?>
<?php print $header_title; ?>
<?php if ($display_faq_count): ?>
(<?php print $question_count; ?>)
<?php endif; ?>
</<?php print $hdr; ?>>
<?php else: ?>
<?php print $term_image; ?>
<?php endif; ?>
<?php if (!empty($description)): ?>
<div class="faq-qa-description"><?php print $description ?></div>
<?php endif; ?>
<?php if (!empty($term_image)): ?>
<div class="clear-block"></div>
<?php endif; ?>
</div> <!-- Close div: faq-qa-header -->
<?php if (!empty($subcat_list)): ?>
<!-- list subcategories, with title, link, description, count -->
<div class="item-list">
<<?php print $subcat_list_style; ?> class="faq-category-list">
<?php foreach ($subcat_list as $i => $subcat): ?>
<li>
<?php print $subcat['link']; ?>
<?php if ($display_faq_count): ?>
(<?php print $subcat['count']; ?>)
<?php endif; ?>
<?php if (!empty($subcat['description'])): ?>
<div class="faq-qa-description"><?php print $subcat['description']; ?></div>
<?php endif; ?>
<div class="clear-block"></div>
</li>
<?php endforeach; ?>
</<?php print $subcat_list_style; ?>>
</div> <!-- Close div: item-list -->
<?php endif; ?>
<div class="<?php print $container_class; ?>">
<!-- include subcategories -->
<?php if (count($subcat_body_list)): ?>
<?php foreach ($subcat_body_list as $i => $subcat_html): ?>
<div class="faq-category-indent"><?php print $subcat_html; ?></div>
<?php endforeach; ?>
<?php endif; ?>
<!-- list questions (in title link) and answers (in body) -->
<div class="faq-dl-hide-answer">
<?php if (count($nodes)): ?>
<?php foreach ($nodes as $i => $node): ?>
<div class="faq-question-answer">
<div class="faq-question faq-dt-hide-answer">
<?php print $node['question']; ?>
</div> <!-- Close div: faq-question faq-dt-hide-answer -->
<div class="faq-answer faq-dd-hide-answer">
<?php print $node['body']; ?>
<?php if (isset($node['links'])): ?>
<?php print $node['links']; ?>
<?php endif; ?>
</div> <!-- Close div: faq-answer faq-dd-hide-answer -->
</div> <!-- Close div: faq-question-answer -->
<?php endforeach; ?>
<?php endif; ?>
</div> <!-- Close div: faq-dl-hide-answer -->
</div> <!-- Close div: faq-qa / faq-qa-hide -->
</div> <!-- Close div: faq-category-group -->

View File

@@ -0,0 +1,126 @@
<?php
/**
* @file
* Template file for the FAQ page if set to show the categorized answer in a
* new page.
*/
/**
* Available variables:
*
* $display_header
* Boolean value controlling whether a header should be displayed.
* $header_title
* The category title.
* $category_depth
* The term or category depth.
* $description
* The current page's description.
* $term_image
* The HTML for the category image. This is empty if the taxonomy image module
* is not enabled or there is no image associated with the term.
* $display_faq_count
* Boolean value controlling whether or not the number of faqs in a category
* should be displayed.
* $question_count
* The number of questions in category.
* $question_list
* An array of questions.
* $question_list_style, either ol or ul
* The style of the question list, either ol or ul (ordered or unordered).
* $container_class
* The class attribute of the element containing the sub-categories, either
* 'faq-qa' or 'faq-qa-hide'. This is used by javascript to open/hide
* a category's faqs.
* $subcat_list
* An array of sub-categories. Each sub-category stored in the $subcat_list
* array has the following information:
* $subcat['link'] is the link to the sub-category.
* $subcat['description'] is the sub-category description.
* $subcat['count'] is the number of questions in the sub-category.
* $subcat['term_image'] is the sub-category (taxonomy) image.
* $subcat_list_style
* The style of the sub-category list, either ol or ul (ordered or unordered).
* $subcat_body_list
* The sub-categories faqs, recursively themed (by this template).
*/
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
?><div class="faq-category-group">
<!-- category header with title, link, image, description, and count of
questions inside -->
<div class="faq-qa-header">
<?php if ($display_header): ?>
<<?php print $hdr; ?> class="faq-header">
<?php print $term_image; ?>
<?php print $header_title; ?>
<?php if ($display_faq_count): ?>
(<?php print $question_count; ?>)
<?php endif; ?>
</<?php print $hdr; ?>>
<?php else: ?>
<?php print $term_image; ?>
<?php endif; ?>
<?php if (!empty($description)): ?>
<div class="faq-qa-description"><?php print $description ?></div>
<?php endif; ?>
<?php if (!empty($term_image)): ?>
<div class="clear-block"></div>
<?php endif; ?>
</div> <!-- Close div: faq-qa-header -->
<!-- list subcategories, with title, link, description, count -->
<?php if (!empty($subcat_list)): ?>
<div class="item-list">
<<?php print $subcat_list_style; ?> class="faq-category-list">
<?php foreach ($subcat_list as $i => $subcat): ?>
<li>
<?php print $subcat['link']; ?>
<?php if ($display_faq_count): ?>
(<?php print $subcat['count']; ?>)
<?php endif; ?>
<?php if (!empty($subcat['description'])): ?>
<div class="faq-qa-description"><?php print $subcat['description']; ?></div>
<?php endif; ?>
<div class="clear-block"></div>
</li>
<?php endforeach; ?>
</<?php print $subcat_list_style; ?>>
</div> <!-- Close div: item-list -->
<?php endif; ?>
<div class="<?php print $container_class; ?>">
<!-- include subcategories -->
<?php if (count($subcat_body_list)): ?>
<?php foreach ($subcat_body_list as $i => $subcat_html): ?>
<div class="faq-category-indent"><?php print $subcat_html; ?></div>
<?php endforeach; ?>
<?php endif; ?>
<!-- list questions (in title link) and answers (in body) -->
<?php if (!empty($question_list)): ?>
<div class="item-list">
<<?php print $question_list_style; ?> class="faq-category-list">
<?php foreach ($question_list as $i => $question_link): ?>
<li>
<?php print $question_link; ?>
</li>
<?php endforeach; ?>
</<?php print $question_list_style; ?>>
</div> <!-- Close div: item-list -->
<?php endif; ?>
</div> <!-- Close div: faq-qa / faq-qa-hide -->
</div> <!-- Close div: faq-category-group -->

View File

@@ -0,0 +1,149 @@
<?php
/**
* @file
* Template file for the FAQ page if set to show categorized questions inline.
*/
/**
* Available variables:
*
* $display_header
* Boolean value controlling whether a header should be displayed.
* $header_title
* The category title.
* $category_depth
* The term or category depth.
* $description
* The current page's description.
* $term_image
* The HTML for the category image. This is empty if the taxonomy image module
* is not enabled or there is no image associated with the term.
* $display_faq_count
* Boolean value controlling whether or not the number of faqs in a category
* should be displayed.
* $question_count
* The number of questions in category.
* $nodes
* An array of nodes to be displayed.
* Each node stored in the $nodes array has the following information:
* $node['question'] is the question text.
* $node['body'] is the answer text.
* $node['links'] represents the node links, e.g. "Read more".
* $use_teaser
* Whether $node['body'] contains the full body or just the teaser text.
* $container_class
* The class attribute of the element containing the sub-categories, either
* 'faq-qa' or 'faq-qa-hide'. This is used by javascript to open/hide
* a category's faqs.
* $question_label
* The label to prepend to the question text.
* $answer_label
* The label to prepend to the answer text.
* $subcat_list
* An array of sub-categories. Each sub-category stored in the $subcat_list
* array has the following information:
* $subcat['link'] is the link to the sub-category.
* $subcat['description'] is the sub-category description.
* $subcat['count'] is the number of questions in the sub-category.
* $subcat['term_image'] is the sub-category (taxonomy) image.
* $subcat_list_style
* The style of the sub-category list, either ol or ul (ordered or unordered).
* $subcat_body_list
* The sub-categories faqs, recursively themed (by this template).
*/
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
?>
<a id="faq-top"></a>
<div class="faq-category-group">
<!-- category header with title, link, image, description, and count of
questions inside -->
<div class="faq-qa-header">
<?php if ($display_header): ?>
<<?php print $hdr; ?> class="faq-header">
<?php print $term_image; ?>
<?php print $header_title; ?>
<?php if ($display_faq_count): ?>
(<?php print $question_count; ?>)
<?php endif; ?>
</<?php print $hdr; ?>>
<?php else: ?>
<?php print $term_image; ?>
<?php endif; ?>
<?php if (!empty($description)): ?>
<div class="faq-qa-description"><?php print $description ?></div>
<?php endif; ?>
<?php if (!empty($term_image)): ?>
<div class="clear-block"></div>
<?php endif; ?>
</div> <!-- Close div: faq-qa-header -->
<!-- list subcategories, with title, link, description, count -->
<?php if (!empty($subcat_list)): ?>
<div class="item-list">
<<?php print $subcat_list_style; ?> class="faq-category-list">
<?php foreach ($subcat_list as $i => $subcat): ?>
<li>
<?php print $subcat['link']; ?>
<?php if ($display_faq_count): ?>
(<?php print $subcat['count']; ?>)
<?php endif; ?>
<?php if (!empty($subcat['description'])): ?>
<div class="faq-qa-description"><?php print $subcat['description']; ?></div>
<?php endif; ?>
<div class="clear-block"></div>
</li>
<?php endforeach; ?>
</<?php print $subcat_list_style; ?>>
</div> <!-- Close div: item-list -->
<?php endif; ?>
<div class="<?php print $container_class; ?>">
<!-- include subcategories -->
<?php if (count($subcat_body_list)): ?>
<?php foreach ($subcat_body_list as $i => $subcat_html): ?>
<div class="faq-category-indent"><?php print $subcat_html; ?></div>
<?php endforeach; ?>
<?php endif; ?>
<!-- list questions (in title link) and answers (in body) -->
<div>
<?php if (count($nodes)): ?>
<?php foreach ($nodes as $i => $node): ?>
<div class="faq-question">
<?php if (!empty($question_label)): ?>
<strong class="faq-question-label">
<?php print $question_label; ?>
</strong>
<?php endif; ?>
<?php print $node['question']; ?>
</div> <!-- Close div: faq-question -->
<div class="faq-answer">
<?php if (!empty($answer_label)): ?>
<strong class="faq-answer-label">
<?php print $answer_label; ?>
</strong>
<?php endif; ?>
<?php print $node['body']; ?>
<?php if (isset($node['links'])): ?>
<?php print $node['links']; ?>
<?php endif; ?>
</div> <!-- Close div: faq-answer -->
<?php endforeach; ?>
<?php endif; ?>
</div> <!-- Close div -->
</div> <!-- Close div: faq-qa / faq-qa-hide -->
</div> <!-- Close div: faq-category-group -->

View File

@@ -0,0 +1,139 @@
<?php
/**
* @file
* Template file for the answers section of the FAQ page if set to show
* categorized questions at the top of the page.
*/
/**
* Available variables:
*
* $display_answers
* Whether or not there should be any output.
* $display_header
* Boolean value controlling whether a header should be displayed.
* $header_title
* The category title.
* $category_name
* The name of the category.
* $answer_category_name
* Whether the category name should be displayed with the answers.
* $group_questions_top
* Whether the questions and answers should be grouped together.
* $category_depth
* The term or category depth.
* $description
* The current page's description.
* $term_image
* The HTML for the category image. This is empty if the taxonomy image module
* is not enabled or there is no image associated with the term.
* $display_faq_count
* Boolean value controlling whether or not the number of faqs in a category
* should be displayed.
* $question_count
* The number of questions in category.
* $nodes
* An array of nodes to be displayed.
* Each node stored in the $nodes array has the following information:
* $node['question'] is the question text.
* $node['body'] is the answer text.
* $node['links'] represents the node links, e.g. "Read more".
* $use_teaser
* Whether $node['body'] contains the full body or just the teaser text.
* $question_label
* The question label, intended to be pre-pended to the question text.
* $answer_label
* The answer label, intended to be pre-pended to the answer text.
* $container_class
* The class attribute of the element containing the sub-categories, either
* 'faq-qa' or 'faq-qa-hide'. This is used by javascript to open/hide
* a category's faqs.
* $subcat_body_list
* The sub-categories faqs, recursively themed (by this template).
*/
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
$depth = 0;
?><?php if ($display_answers): ?>
<?php if ($answer_category_name): ?>
<?php while ($depth < $category_depth): ?>
<div class="faq-category-indent">
<?php $depth++; endwhile; ?>
<?php endif; ?>
<div class="faq-category-menu">
<?php if ($display_header): ?>
<<?php print $hdr; ?> class="faq-header">
<?php print $term_image; ?>
<?php print $category_name; ?>
</<?php print $hdr; ?>>
<div class="clear-block"></div>
<div class="faq-category-group">
<div>
<?php endif; ?>
<?php if (!$answer_category_name || $display_header): ?>
<!-- Include subcategories. -->
<?php if (count($subcat_body_list)): ?>
<?php foreach ($subcat_body_list as $i => $subcat_html): ?>
<?php print $subcat_html; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if (!$display_header): ?>
<div class="faq-category-group">
<div>
<?php endif; ?>
<!-- List questions (in title link) and answers (in body). -->
<?php if (count($nodes)): ?>
<?php foreach ($nodes as $i => $node): ?>
<div class="faq-question">
<?php if (!empty($question_label)): ?>
<strong class="faq-question-label">
<?php print $question_label; ?>
</strong>
<?php endif; ?>
<?php print $node['question']; ?>
</div> <!-- Close div: faq-question -->
<div class="faq-answer">
<?php if (!empty($answer_label)): ?>
<strong class="faq-answer-label">
<?php print $answer_label; ?>
</strong>
<?php endif; ?>
<?php print $node['body']; ?>
<?php if (isset($node['links'])): ?>
<?php print $node['links']; ?>
<?php endif; ?>
</div> <!-- Close div: faq-answer -->
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
</div> <!-- Close div -->
</div> <!-- Close div: faq-category-group -->
</div>
<?php if ($answer_category_name): ?>
<?php while ($depth > 0): ?>
</div> <!-- Close div: faq-category-indent -->
<?php $depth--; endwhile; ?>
<?php endif; ?>
<?php
endif; // if display_answers

View File

@@ -0,0 +1,189 @@
<?php
/**
* @file
* Template file for the questions section of the FAQ page if set to show
* categorized questions at the top of the page.
*/
/**
* Available variables:
*
* $display_header
* Boolean value controlling whether a header should be displayed.
* $header_title
* The category title.
* $category_name
* The name of the category.
* $answer_category_name
* Whether the category name should be displayed with the answers.
* $group_questions_top
* Whether the questions and answers should be grouped together.
* $category_depth
* The term or category depth.
* $description
* The current page's description.
* $term_image
* The HTML for the category image. This is empty if the taxonomy image module
* is not enabled or there is no image associated with the term.
* $display_faq_count
* Boolean value controlling whether or not the number of faqs in a category
* should be displayed.
* $question_count
* The number of questions in category.
* $nodes
* An array of nodes to be displayed.
* Each node stored in the $nodes array has the following information:
* $node['question'] is the question text.
* $node['body'] is the answer text.
* $node['links'] represents the node links, e.g. "Read more".
* $use_teaser
* Whether $node['body'] contains the full body or just the teaser text.
* $container_class
* The class attribute of the element containing the sub-categories, either
* 'faq-qa' or 'faq-qa-hide'. This is used by javascript to open/hide
* a category's faqs.
* $question_list
* An array of question links.
* $question_list_style
* The style of the question list, ul for unordered, ol for ordered.
* $subcat_list
* An array of sub-categories. Each sub-category stored in the $subcat_list
* array has the following information:
* $subcat['link'] is the link to the sub-category.
* $subcat['description'] is the sub-category description.
* $subcat['count'] is the number of questions in the sub-category.
* $subcat['term_image'] is the sub-category (taxonomy) image.
* $subcat_list_style
* The style of the sub-category list, either ol or ul (ordered or unordered).
* $subcat_body_list
* The sub-categories faqs, recursively themed (by this template).
*/
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
?>
<a id="faq-top"></a>
<div class="faq-category-menu">
<!-- category header with title, link, image, description, and count of questions inside -->
<div class="faq-qa-header">
<?php if ($display_header): ?>
<<?php print $hdr; ?> class="faq-header">
<?php print $term_image; ?>
<?php print $header_title; ?>
<?php if ($display_faq_count): ?>
(<?php print $question_count; ?>)
<?php endif; ?>
</<?php print $hdr; ?>>
<?php else: ?>
<?php print $term_image; ?>
<?php endif; ?>
<?php if (!empty($description)): ?>
<div class="faq-qa-description"><?php print $description ?></div>
<?php endif; ?>
<?php if (!empty($term_image)): ?>
<div class="clear-block"></div>
<?php endif; ?>
</div> <!-- Close div: faq-qa-header -->
<?php if (!empty($subcat_list)): ?>
<!-- list subcategories, with title, link, description, count -->
<div class="item-list">
<<?php print $subcat_list_style; ?> class="faq-category-list">
<?php foreach ($subcat_list as $i => $subcat): ?>
<li>
<?php print $subcat['link']; ?>
<?php if ($display_faq_count): ?>
(<?php print $subcat['count']; ?>)
<?php endif; ?>
<?php if (!empty($subcat['description'])): ?>
<div class="faq-qa-description"><?php print $subcat['description']; ?></div>
<?php endif; ?>
<div class="clear-block"></div>
</li>
<?php endforeach; ?>
</<?php print $subcat_list_style; ?>>
</div> <!-- Close div: item-list -->
<?php endif; ?>
<div class="<?php print $container_class; ?>">
<?php // include subcategories ?>
<?php if (count($subcat_body_list)): ?>
<?php foreach ($subcat_body_list as $i => $subcat_html): ?>
<div class="faq-category-indent"><?php print $subcat_html; ?></div>
<?php endforeach; ?>
<?php endif; ?>
<?php // list question links ?>
<?php if (!empty($question_list)): ?>
<div class="item-list">
<<?php print $question_list_style; ?> class="faq-ul-questions-top">
<?php foreach ($question_list as $i => $question_link): ?>
<li>
<?php print $question_link; ?>
</li>
<?php endforeach; ?>
</<?php print $question_list_style; ?>>
</div> <!-- Close div: item-list -->
<?php endif; ?>
<?php if (!$group_questions_top && $category_display != 'hide_qa'): ?>
</div> <!-- Close div: faq-qa / faq-qa-hide -->
</div> <!-- Close div: faq-category-menu -->
<?php endif; ?>
<?php if ($answer_category_name): ?>
<!-- Display header before answers in some layouts. -->
<<?php print $hdr; ?> class="faq-header">
<?php print $term_image; ?>
<?php print $category_name; ?>
</<?php print $hdr; ?>>
<div class="clear-block"></div>
<?php endif; ?>
<?php // List questions (in title link) and answers (in body). ?>
<div class="faq-category-group">
<div>
<?php if (count($nodes)): ?>
<?php foreach ($nodes as $i => $node): ?>
<div class="faq-question"><?php // Strong question label here? ?>
<?php if (!empty($question_label)) : ?>
<strong class="faq-question-label">
<?php print $question_label; ?>
</strong>
<?php endif; ?>
<?php print $node['question']; ?>
</div> <!-- Close div: faq-question -->
<div class="faq-answer">
<?php if (!empty($answer_label)) : ?>
<strong class="faq-answer-label">
<?php print $answer_label; ?>
</strong>
<?php endif; ?>
<?php print $node['body']; ?>
<?php if (isset($node['links'])): ?>
<?php print $node['links']; ?>
<?php endif; ?>
</div> <!-- Close div: faq-answer -->
<?php endforeach; ?>
<?php endif; ?>
</div> <!-- Close div -->
</div> <!-- Close div: faq-category-group -->
<?php if ($group_questions_top || $category_display == 'hide_qa'): ?>
</div> <!-- Close div: faq-qa / faq-qa-hide -->
</div> <!-- Close div: faq-category-menu -->
<?php
endif;

View File

@@ -0,0 +1,39 @@
<?php
/**
* @file
* Template file for the FAQ page if set to show/hide the answers when the
* question is clicked.
*/
/**
* Available variables:
*
* $nodes
* The array of nodes to be displayed.
* Each $node array contains the following information:
* $node['question'] is the question text.
* $node['body'] is the answer text.
* $node['links'] represents the node links, e.g. "Read more".
* $use_teaser
* Is true if $node['body'] is a teaser.
*/
?><div>
<?php if (count($nodes)): ?>
<?php foreach ($nodes as $node): ?>
<?php // Cycle through each of the nodes. We now have the variable $node to work with. ?>
<div class="faq-question-answer">
<div class="faq-question faq-dt-hide-answer">
<?php print $node['question']; ?>
</div> <!-- Close div: faq-question faq-dt-hide-answer -->
<div class="faq-answer faq-dd-hide-answer">
<?php print $node['body']; ?>
<?php if (isset($node['links'])): ?>
<?php print $node['links']; ?>
<?php endif; ?>
</div> <!-- Close div: faq-answer faq-dd-hide-answer -->
</div> <!-- Close div: faq-question-answer -->
<?php endforeach; ?>
<?php endif; ?>
</div> <!-- Close div -->

View File

@@ -0,0 +1,20 @@
<?php
/**
* @file
* Template file for the FAQ page if set to show the answer in a new page.
*/
/**
* Available variables:
*
* $list_style
* The style of the list, either ol or ul (ordered list or unordered list).
* $list_items
* An array of nodes to be displayed in the list.
* $list
* Pre-formatted list.
*/
?>
<?php
print $list;

View File

@@ -0,0 +1,53 @@
<?php
/**
* @file
* Template file for the FAQ page if set to show the questions inline.
*/
/**
* Available variables:
*
* $nodes
* The array of nodes to be displayed.
* Each node stored in the $nodes array has the following information:
* $node['question'] is the question text.
* $node['body'] is the answer text.
* $node['links'] represents the node links, e.g. "Read more".
* $question_label
* The question label, intended to be pre-pended to the question text.
* $answer_label
* The answer label, intended to be pre-pended to the answer text.
* $use_teaser
* Tells whether $node['body'] contains the full body or just the teaser
*/
?>
<a id="faq-top"></a>
<div>
<?php if (count($nodes)): ?>
<?php foreach ($nodes as $node): ?>
<?php // Cycle through the $nodes array so that we now have a $node variable to work with. ?>
<br />
<div class="faq-question">
<?php if (!empty($question_label)): ?>
<strong class="faq-question-label">
<?php print $question_label; ?>
</strong>
<?php endif; ?>
<?php print $node['question']; ?>
</div> <!-- Close div: faq-question -->
<div class="faq-answer">
<?php if (!empty($answer_label)): ?>
<strong class="faq-answer-label">
<?php print $answer_label; ?>
</strong>
<?php endif; ?>
<?php print $node['body']; ?>
<?php if (isset($node['links'])): ?>
<?php print $node['links']; ?>
<?php endif; ?>
</div> <!-- Close div: faq-answer -->
<?php endforeach; ?>
<?php endif; ?>
</div> <!-- Close div -->

View File

@@ -0,0 +1,60 @@
<?php
/**
* @file
* Template file for the FAQ page if set to show the questions in a list at the
* top.
*/
/**
* Available variables:
*
* $questions_list
* Pre-formatted list of questions.
* $questions
* An array of questions to use for producing the question list at the top.
* $answers
* An array of answers to use for producing the main body of text.
* $answers[$key]['question'] is the question text.
* $answers[$key]['body'] is the answer text.
* $answers[$key]['links'] represents the node links, e.g. "Read more".
* $use_teaser
* Is true if $answer['body'] is a teaser.
* $list_style
* Represents the style of list, ul for unordered, ol for ordered.
* $question_label
* The question label, intended to be pre-pended to the question text.
* $answer_label
* The answer label, intended to be pre-pended to the answer text.
* $limit
* Represents the number of items.
*/
?>
<a id="faq-top"></a>
<?php print $questions_list ?>
<br />
<?php $key = 0; ?>
<?php while ($key < $limit): ?>
<?php // Cycle through all the answers and "more" links. $key will represent the applicable position in the arrays. ?>
<div class="faq-question">
<?php if (!empty($question_label)): ?>
<strong class="faq-question-label">
<?php print $question_label; ?>
</strong>
<?php endif; ?>
<?php print $answers[$key]['question']; ?>
</div> <!-- Close div: faq-question -->
<div class="faq-answer">
<?php if (!empty($answer_label)): ?>
<strong class="faq-answer-label">
<?php print $answer_label; ?>
</strong>
<?php endif; ?>
<?php print $answers[$key]['body']; ?>
<?php print $answers[$key]['links']; ?>
</div> <!-- Close div: faq-answer -->
<?php // Increment $key to move on to the next position. ?>
<?php $key++; ?>
<?php
endwhile;

View File

@@ -0,0 +1,148 @@
<?php
/**
* @file
* FAQ page callbacks for the "hide answer" layouts.
*/
/**
* Create FAQ page if set to show/hide answer when question is clicked.
*
* @param &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_hide_answer(&$variables) {
$data = $variables['data'];
$this_page = $_GET['q'];
// Fetch configuration.
$teaser = variable_get('faq_use_teaser', FALSE);
$links = variable_get('faq_show_node_links', FALSE);
$disable_node_links = variable_get('faq_disable_node_links', FALSE);
$nodes = array();
$count = 0;
foreach ($data as $node) {
$anchor = 'n' . $node->nid;
faq_view_question($nodes[$count], $node, $this_page, $anchor);
faq_view_answer($nodes[$count], $node, array(), $teaser, $links);
$count++;
}
$variables['use_teaser'] = $teaser;
$variables['nodes'] = $nodes;
}
/**
* Create categorized FAQ page if set to show answer when question is clicked.
*
* @param &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_category_hide_answer(&$variables) {
$data = $variables['data'];
$category_display = $variables['category_display'];
$term = $variables['term'];
$parent_term = $variables['parent_term'];
$class = $variables['class'];
// Fetch configuration.
$teaser = variable_get('faq_use_teaser', FALSE);
$variables['use_teaser'] = $teaser;
$links = variable_get('faq_show_node_links', FALSE);
$disable_node_links = variable_get('faq_disable_node_links', FALSE);
$display_faq_count = variable_get('faq_count', FALSE);
$hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
$show_term_page_children = variable_get('faq_show_term_page_children', FALSE);
$default_sorting = variable_get('faq_default_sorting', 'DESC');
// Initialise some variables.
$default_weight = 0;
if ($default_sorting != 'DESC') {
$default_weight = 1000000;
}
$this_page = $_GET['q'];
$get_child_terms = 0;
// Check if we're on a faq page.
if (arg(0) == 'faq-page') {
// Check if we're on a categorized faq page.
if (is_numeric(arg(1))) {
$get_child_terms = arg(1);
}
}
// Force some settings in case we're processing a special faq question list
// created by a custom call to faq_page().
elseif (!empty($parent_term)) {
$get_child_terms = $parent_term->tid;
$show_term_page_children = TRUE;
}
// Get number of questions, and account for hidden sub-categories.
$count = 0;
if ($display_faq_count && $hide_child_terms) {
$count = faq_taxonomy_term_count_nodes($term->tid);
}
$variables['display_faq_count'] = $display_faq_count;
// Get taxonomy image.
$variables['term_image'] = '';
if (module_exists('taxonomy_image')) {
$variables['term_image'] = taxonomy_image_display($term->tid, array('class' => 'faq-tax-image'));
}
// Configure header.
$variables['category_depth'] = $term->depth;
$variables['category_name'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
if ($category_display == 'hide_qa') {
$variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq/$term->tid");
}
else {
$variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
}
// Configure category description.
$variables['description'] = check_markup(faq_tt("taxonomy:term:$term->tid:description", $term->description));
// Get list of sub-categories if necessary.
$child_categories = array();
if (($show_term_page_children || $hide_child_terms) && $category_display == 'new_page') {
$child_categories = faq_view_child_category_headers($term);
}
$variables['subcat_list'] = $child_categories;
$variables['subcat_list_style'] = variable_get('faq_category_listing', 'ul');
// Configure class (faq-qa or faq-qa-hide).
if ($get_child_terms == $term->tid) {
$variables['container_class'] = 'faq-qa';
}
else {
$variables['container_class'] = $class;
}
// Configure sub-category bodies (theme recursively).
$variables['subcat_body_list'] = array();
if (($get_child_terms && $category_display == 'categories_inline') || ((($show_term_page_children && $this_page != 'faq-page') || $hide_child_terms) && $category_display == 'hide_qa')) {
$variables['subcat_body_list'] = faq_get_child_categories_faqs($term, 'faq_category_hide_answer', $default_weight, $default_sorting, $category_display, $variables['class'], $parent_term);
}
if (!count($data)) {
$variables['question_count'] = $count;
$variables['nodes'] = array();
return;
}
$nodes = array();
foreach ($data as $node) {
if (!$hide_child_terms) {
$count++;
}
$node_var = array();
$anchor = 't' . $term->tid . 'n' . $node->nid;
faq_view_question($node_var, $node, $this_page, $anchor);
faq_view_answer($node_var, $node, array(), $teaser, $links);
$nodes[] = $node_var;
}
$variables['nodes'] = $nodes;
$variables['question_count'] = $count;
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* @file
* FAQ page callbacks for the "new page" layouts.
*/
/**
* Create FAQ page if set to show the answer in a new page.
*
* @param &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_new_page(&$variables) {
$items = array();
$data = $variables['data'];
foreach ($data as $node) {
$items[] = l($node->title, "node/$node->nid");
}
$list_style = variable_get('faq_question_listing', 'ul');
$variables['list_style'] = $list_style;
$variables['list_items'] = $items;
$variables['list'] = theme('item_list', array('items' => $items, 'title' => NULL, 'type' => $list_style, 'attributes' => array("class" => "faq-question-listing")));
}
/**
* Create categorized FAQ page if set to show answer in a new page.
*
* @param &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_category_new_page(&$variables) {
$data = $variables['data'];
$category_display = $variables['category_display'];
$term = $variables['term'];
$parent_term = $variables['parent_term'];
$class = $variables['class'];
$this_page = $_GET['q'];
// Fetch configuration.
$display_faq_count = variable_get('faq_count', FALSE);
$hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
$show_term_page_children = variable_get('faq_show_term_page_children', FALSE);
// Initialise some variables.
$get_child_terms = 0;
// Check if we're on a faq page.
if (arg(0) == 'faq-page') {
// Check if we're on a categorized faq page.
if (is_numeric(arg(1))) {
$get_child_terms = arg(1);
}
}
// Force some settings in case we're processing a special faq question list
// created by a custom call to faq_page().
elseif (!empty($parent_term)) {
$get_child_terms = $parent_term->tid;
$show_term_page_children = TRUE;
}
$default_sorting = variable_get('faq_default_sorting', 'DESC');
$default_weight = 0;
if ($default_sorting != 'DESC') {
$default_weight = 1000000;
}
// Get number of questions, and account for hidden sub-categories.
$count = 0;
if ($display_faq_count && $hide_child_terms) {
$count = faq_taxonomy_term_count_nodes($term->tid);
}
$variables['display_faq_count'] = $display_faq_count;
// Get taxonomy image.
$variables['term_image'] = '';
if (module_exists('taxonomy_image')) {
$variables['term_image'] = taxonomy_image_display($term->tid, array('class' => 'faq-tax-image'));
}
// Configure header.
$variables['category_depth'] = $term->depth;
if ($category_display == 'hide_qa') {
$variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq/$term->tid");
}
else {
$variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
}
// Configure category description.
$variables['description'] = check_markup(faq_tt("taxonomy:term:$term->tid:description", $term->description));
// Get list of sub-categories if necessary.
$child_categories = array();
if (($show_term_page_children || $hide_child_terms) && $category_display == 'new_page') {
$child_categories = faq_view_child_category_headers($term);
}
$variables['subcat_list'] = $child_categories;
$variables['subcat_list_style'] = variable_get('faq_category_listing', 'ul');
// Configure class (faq-qa or faq-qa-hide).
if ($get_child_terms == $term->tid) {
$variables['container_class'] = 'faq-qa';
}
else {
$variables['container_class'] = $class;
}
// Configure sub-category bodies (theme recursively).
$variables['subcat_body_list'] = array();
if (($get_child_terms && $category_display == 'categories_inline') || ((($show_term_page_children && $this_page != 'faq-page') || $hide_child_terms) && $category_display == 'hide_qa')) {
$variables['subcat_body_list'] = faq_get_child_categories_faqs($term, 'faq_category_new_page', $default_weight, $default_sorting, $category_display, $variables['class'], $parent_term);
}
if (!count($data)) {
$variables['question_count'] = $count;
$variables['nodes'] = array();
return;
}
$nodes = array();
foreach ($data as $node) {
if (!$hide_child_terms) {
$count++;
}
$nodes[] = l($node->title, "node/$node->nid");
}
$variables['question_list'] = $nodes;
$variables['question_list_style'] = variable_get('faq_question_listing', 'ul');
$variables['question_count'] = $count;
}

View File

@@ -0,0 +1,169 @@
<?php
/**
* @file
* FAQ page callbacks for the "questions inline" layouts.
*/
/**
* Create the FAQ page if set to show the questions inline.
*
* @param &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_questions_inline(&$variables) {
$data = $variables['data'];
// Fetch configuration.
$disable_node_links = variable_get('faq_disable_node_links', FALSE);
$teaser = variable_get('faq_use_teaser', FALSE);
$links = variable_get('faq_show_node_links', FALSE);
// Configure "back to top" link.
$this_page = $_GET['q'];
$back_to_top = faq_init_back_to_top($this_page);
// Configure labels.
$variables['question_label'] = '';
$variables['answer_label'] = '';
if (variable_get('faq_qa_mark', FALSE)) {
$variables['question_label'] = check_plain(variable_get('faq_question_label', "Q:"));
$variables['answer_label'] = check_plain(variable_get('faq_answer_label', "A:"));
}
$nodes = array();
$count = 0;
foreach ($data as $node) {
$anchor = 'n' . $node->nid;
faq_view_question($nodes[$count], $node, NULL, $anchor);
faq_view_answer($nodes[$count], $node, $back_to_top, $teaser, $links);
$count++;
}
$variables['use_teaser'] = $teaser;
$variables['nodes'] = $nodes;
}
/**
* Create categorized FAQ page if set to show/hide the questions inline.
*
* @param &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_category_questions_inline(&$variables) {
$data = $variables['data'];
$category_display = $variables['category_display'];
$term = $variables['term'];
$parent_term = $variables['parent_term'];
$class = $variables['class'];
// Fetch configuration.
$teaser = variable_get('faq_use_teaser', FALSE);
$links = variable_get('faq_show_node_links', FALSE);
$disable_node_links = variable_get('faq_disable_node_links', FALSE);
$display_faq_count = variable_get('faq_count', FALSE);
$hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
$show_term_page_children = variable_get('faq_show_term_page_children', FALSE);
$default_sorting = variable_get('faq_default_sorting', 'DESC');
// Initialise some variables.
$variables['use_teaser'] = $teaser;
$default_weight = 0;
if ($default_sorting != 'DESC') {
$default_weight = 1000000;
}
$this_page = $_GET['q'];
$get_child_terms = 0;
// Check if we're on a faq page.
if (arg(0) == 'faq-page') {
// Check if we're on a categorized faq page.
if (is_numeric(arg(1))) {
$get_child_terms = arg(1);
}
}
// Force some settings in case we're processing a special faq question list
// created by a custom call to faq_page().
elseif (!empty($parent_term)) {
$get_child_terms = $parent_term->tid;
$show_term_page_children = TRUE;
}
// Configure "back to top" link.
$back_to_top = faq_init_back_to_top($this_page);
// Configure labels.
$variables['question_label'] = '';
$variables['answer_label'] = '';
if (variable_get('faq_qa_mark', FALSE)) {
$variables['question_label'] = check_plain(variable_get('faq_question_label', "Q:"));
$variables['answer_label'] = check_plain(variable_get('faq_answer_label', "A:"));
}
// Get number of questions, and account for hidden sub-categories.
$count = 0;
if ($display_faq_count && $hide_child_terms) {
$count = faq_taxonomy_term_count_nodes($term->tid);
}
$variables['display_faq_count'] = $display_faq_count;
// Get taxonomy image.
$variables['term_image'] = '';
if (module_exists('taxonomy_image')) {
$variables['term_image'] = taxonomy_image_display($term->tid, array('class' => 'faq-tax-image'));
}
// Configure header.
$variables['category_depth'] = $term->depth;
if ($category_display == 'hide_qa') {
$variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq/$term->tid");
}
else {
$variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
}
// Configure category description.
$variables['description'] = check_markup(faq_tt("taxonomy:term:$term->tid:description", $term->description));
// Get list of sub-categories if necessary.
$child_categories = array();
if (($show_term_page_children || $hide_child_terms) && $category_display == 'new_page') {
$child_categories = faq_view_child_category_headers($term);
}
$variables['subcat_list'] = $child_categories;
$variables['subcat_list_style'] = variable_get('faq_category_listing', 'ul');
// Configure class (faq-qa or faq-qa-hide).
if ($get_child_terms == $term->tid) {
$variables['container_class'] = 'faq-qa';
}
else {
$variables['container_class'] = $class;
}
// Configure sub-category bodies (theme recursively).
$variables['subcat_body_list'] = array();
if (($get_child_terms && $category_display == 'categories_inline') || ((($show_term_page_children && $this_page != 'faq-page') || $hide_child_terms) && $category_display == 'hide_qa')) {
$variables['subcat_body_list'] = faq_get_child_categories_faqs($term, 'faq_category_questions_inline', $default_weight, $default_sorting, $category_display, $variables['class'], $parent_term);
}
if (!count($data)) {
$variables['question_count'] = $count;
$variables['nodes'] = array();
return;
}
$nodes = array();
foreach ($data as $node) {
if (!$hide_child_terms) {
$count++;
}
$node_var = array();
$anchor = 't' . $term->tid . 'n' . $node->nid;
faq_view_question($node_var, $node, NULL, $anchor);
faq_view_answer($node_var, $node, $back_to_top, $teaser, $links);
$nodes[] = $node_var;
}
$variables['nodes'] = $nodes;
$variables['question_count'] = $count;
}

View File

@@ -0,0 +1,293 @@
<?php
/**
* @file
* FAQ page callbacks for the "questions top" layouts.
*/
/**
* Create the structure of the page, when the questions are to be shown on top.
*
* @param &$variables
* Array reference of arguments given to the theme() function.
* @return
* A variable holding the HTML formatted page.
*/
function template_preprocess_faq_questions_top(&$variables) {
$data = $variables['data'];
// Fetch configuration.
$teaser = variable_get('faq_use_teaser', FALSE);
$links = variable_get('faq_show_node_links', FALSE);
$disable_node_links = variable_get('faq_disable_node_links', FALSE);
// Configure labels.
$variables['question_label'] = '';
$variables['answer_label'] = '';
if (variable_get('faq_qa_mark', FALSE)) {
$variables['question_label'] = check_plain(variable_get('faq_question_label', "Q:"));
$variables['answer_label'] = check_plain(variable_get('faq_answer_label', "A:"));
}
// Configure "back to top" link.
$this_page = $_GET['q'];
$back_to_top = faq_init_back_to_top($this_page);
// Loop through results.
$questions = array();
$answers = array();
$key = 0;
foreach ($data as $node) {
$anchor = 'n' . $node->nid;
$questions[$key] = l($node->title, $this_page, array('fragment' => $anchor));
faq_view_question($answers[$key], $node, NULL, $anchor);
faq_view_answer($answers[$key], $node, $back_to_top, $teaser, $links);
$key++;
}
$variables['limit'] = $key;
$list_style = variable_get('faq_question_listing', 'ul');
$variables['list_style'] = $list_style;
$variables['use_teaser'] = $teaser;
$variables['questions'] = $questions;
$variables['answers'] = $answers;
$variables['questions_list'] = theme('item_list', array('items' => $questions, 'title' => NULL, 'type' => $list_style, 'attributes' => array("class" => "faq-ul-questions-top")));
}
/**
* Create categorized questions for FAQ page if set to show questions on top.
*
* @param &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_category_questions_top(&$variables) {
$data = $variables['data'];
$category_display = $variables['category_display'];
$term = $variables['term'];
$parent_term = $variables['parent_term'];
$class = $variables['class'];
// Fetch configuration.
$teaser = variable_get('faq_use_teaser', FALSE);
$links = variable_get('faq_show_node_links', FALSE);
$disable_node_links = variable_get('faq_disable_node_links', FALSE);
$display_faq_count = variable_get('faq_count', FALSE);
$hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
$show_term_page_children = variable_get('faq_show_term_page_children', FALSE);
$group_questions_top = variable_get('faq_group_questions_top', FALSE);
$default_sorting = variable_get('faq_default_sorting', 'DESC');
// Configure labels.
$variables['question_label'] = '';
$variables['answer_label'] = '';
if (variable_get('faq_qa_mark', FALSE)) {
$variables['question_label'] = check_plain(variable_get('faq_question_label', "Q:"));
$variables['answer_label'] = check_plain(variable_get('faq_answer_label', "A:"));
}
// Initialise some variables.
$default_weight = 0;
if ($default_sorting != 'DESC') {
$default_weight = 1000000;
}
$this_page = $_GET['q'];
$get_child_terms = 0;
// Check if we're on a faq page.
if (arg(0) == 'faq-page') {
// Check if we're on a categorized faq page.
if (is_numeric(arg(1))) {
$get_child_terms = arg(1);
}
}
// Force some settings in case we're processing a special faq question list
// created by a custom call to faq_page().
elseif (!empty($parent_term)) {
$get_child_terms = $parent_term->tid;
$show_term_page_children = TRUE;
}
// Configure "back to top" link.
$back_to_top = faq_init_back_to_top($this_page);
// Get number of questions, and account for hidden sub-categories.
$count = 0;
if ($display_faq_count && $hide_child_terms) {
$count = faq_taxonomy_term_count_nodes($term->tid);
}
$variables['display_faq_count'] = $display_faq_count;
// Get taxonomy image.
$variables['term_image'] = '';
if (module_exists('taxonomy_image')) {
$variables['term_image'] = taxonomy_image_display($term->tid, array('class' => 'faq-tax-image'));
}
// Configure header.
$variables['category_depth'] = $term->depth;
$variables['category_name'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
if ($category_display == 'hide_qa') {
$variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq/$term->tid");
}
else {
$variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
}
// Configure category description.
$variables['description'] = check_markup(faq_tt("taxonomy:term:$term->tid:description", $term->description));
// Get list of sub-categories if necessary.
$child_categories = array();
if (($show_term_page_children || $hide_child_terms) && $category_display == 'new_page') {
$child_categories = faq_view_child_category_headers($term);
}
$variables['subcat_list'] = $child_categories;
$variables['subcat_list_style'] = variable_get('faq_category_listing', 'ul');
// Configure class (faq-qa or faq-qa-hide).
if ($get_child_terms == $term->tid) {
$variables['container_class'] = 'faq-qa';
}
else {
$variables['container_class'] = $class;
}
// Configure sub-category bodies (theme recursively).
$variables['subcat_body_list'] = array();
if (($get_child_terms && $category_display == 'categories_inline') || ((($show_term_page_children && $this_page != 'faq-page') || $hide_child_terms) && $category_display == 'hide_qa')) {
$variables['subcat_body_list'] = faq_get_child_categories_faqs($term, 'faq_category_questions_top', $default_weight, $default_sorting, $category_display, $variables['class'], $parent_term);
}
$variables['group_questions_top'] = $group_questions_top;
if (!count($data)) {
$variables['question_count'] = $count;
$variables['nodes'] = array();
$variables['answer_category_name'] = FALSE;
return;
}
$questions = array();
$nodes = array();
foreach ($data as $node) {
if (!$hide_child_terms) {
$count++;
}
$node_var = array();
$anchor = 't' . $term->tid . 'n' . $node->nid;
faq_view_question($node_var, $node, NULL, $anchor);
if ($group_questions_top || $category_display == 'hide_qa') {
faq_view_answer($node_var, $node, $back_to_top, $teaser, $links);
}
$nodes[] = $node_var;
$questions[] = l($node->title, $this_page, array('fragment' => $anchor));
}
$variables['question_count'] = $count;
$variables['use_teaser'] = $teaser;
$variables['question_list'] = $questions;
$variables['question_list_style'] = variable_get('faq_question_listing', 'ul');
if ($group_questions_top || $category_display == "hide_qa") {
$variables['nodes'] = $nodes;
$variables['answer_category_name'] = variable_get('faq_answer_category_name', FALSE);
}
else {
$variables['nodes'] = array();
$variables['answer_category_name'] = FALSE;
}
}
/**
* Create categorized answers for FAQ page if set to show the questions on top.
*
* @param &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_category_questions_top_answers(&$variables) {
$data = $variables['data'];
$category_display = $variables['category_display'];
$term = $variables['term'];
$parent_term = $variables['parent_term'];
$class = $variables['class'];
// Fetch configuration.
$teaser = variable_get('faq_use_teaser', FALSE);
$links = variable_get('faq_show_node_links', FALSE);
$disable_node_links = variable_get('faq_disable_node_links', FALSE);
$hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
$show_term_page_children = variable_get('faq_show_term_page_children', FALSE);
$group_questions_top = variable_get('faq_group_questions_top', FALSE);
$default_sorting = variable_get('faq_default_sorting', 'DESC');
// Configure labels.
$variables['question_label'] = '';
$variables['answer_label'] = '';
if (variable_get('faq_qa_mark', FALSE)) {
$variables['question_label'] = check_plain(variable_get('faq_question_label', "Q:"));
$variables['answer_label'] = check_plain(variable_get('faq_answer_label', "A:"));
}
// Initialise some variables.
$default_weight = 0;
if ($default_sorting != 'DESC') {
$default_weight = 1000000;
}
$variables['group_questions_top'] = $group_questions_top;
if ($group_questions_top || $category_display == "hide_qa") {
$variables['display_answers'] = FALSE;
$variables['category_depth'] = 0;
return;
}
$variables['display_answers'] = TRUE;
$this_page = $_GET['q'];
$get_child_terms = 0;
// Check if we're on a faq page.
if (arg(0) == 'faq-page') {
// Check if we're on a categorized faq page.
if (is_numeric(arg(1))) {
$get_child_terms = arg(1);
}
}
// Force some settings in case we're processing a special faq question list
// created by a custom call to faq_page().
elseif (!empty($parent_term)) {
$get_child_terms = $parent_term->tid;
$show_term_page_children = TRUE;
}
// Configure "back to top" link.
$back_to_top = faq_init_back_to_top($this_page);
// Get taxonomy image.
$variables['term_image'] = '';
if (module_exists('taxonomy_image')) {
$variables['term_image'] = taxonomy_image_display($term->tid, array('class' => 'faq-tax-image'));
}
// Configure sub-category bodies (theme recursively).
$variables['subcat_body_list'] = array();
if (($get_child_terms && $category_display == 'categories_inline') || ((($show_term_page_children && $this_page != 'faq-page') || $hide_child_terms) && $category_display == 'hide_qa')) {
$variables['subcat_body_list'] = faq_get_child_categories_faqs($term, 'faq_category_questions_top_answers', $default_weight, $default_sorting, $category_display, $variables['class'], $parent_term);
}
$nodes = array();
foreach ($data as $node) {
$node_var = array();
$anchor = 't' . $term->tid . 'n' . $node->nid;
faq_view_question($node_var, $node, NULL, $anchor);
faq_view_answer($node_var, $node, $back_to_top, $teaser, $links);
$nodes[] = $node_var;
}
$variables['use_teaser'] = $teaser;
$variables['nodes'] = $nodes;
$variables['category_name'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
$variables['category_depth'] = $term->depth;
$variables['display_header'] = FALSE;
$variables['answer_category_name'] = variable_get('faq_answer_category_name', FALSE);
if ($variables['answer_category_name'] && faq_taxonomy_term_count_nodes($term->tid)) {
$variables['display_header'] = TRUE;
}
}

View File

@@ -0,0 +1,127 @@
<?php
/**
* Implements hook_views_data().
*/
function faq_views_data() {
// faq_questions table.
$data['faq_questions']['table']['group'] = t('FAQ');
$data['faq_questions']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
$data['faq_questions']['question'] = array(
'title' => t('FAQ short question'),
'help' => t('The short question text for FAQ nodes.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['faq_questions']['detailed_question'] = array(
'title' => t('FAQ detailed question'),
'help' => t('The long question text for FAQ nodes.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
// faq_weights table.
$data['faq_weights']['table']['group'] = t('FAQ');
$data['faq_weights']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
'taxonomy_term_data' => array(
'left_field' => 'tid',
'field' => 'tid',
),
);
$data['faq_weights']['weight'] = array(
'title' => t('FAQ weight'),
'help' => t('The weight of the FAQ node.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
$data['faq_weights']['tid'] = array(
'title' => t('FAQ category tid'),
'help' => t('The tid of the FAQ node.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
'zero is null' => FALSE,
),
'filter' => array(
'title' => t('Tid'),
'handler' => 'views_handler_filter_numeric',
'hierarchy table' => 'taxonomy_term_hierarchy',
'numeric' => TRUE,
'skip base' => 'taxonomy_term_data',
'allow empty' => TRUE,
'zero is null' => FALSE,
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'label' => t('category'),
'base' => 'taxonomy_index',
'base field' => 'tid',
'skip base' => 'taxonomy_term_data',
),
);
$data['faq_weights']['category'] = array(
'title' => t('FAQ category'),
'help' => t('The term of the FAQ node.'),
'real field' => 'tid',
'field' => array(
'handler' => 'views_handler_field_term_node_tid',
'click sortable' => TRUE,
'zero is null' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_term_node_tid',
'name table' => 'taxonomy_term_data',
'name field' => 'name',
'empty field name' => t('Uncategorized'),
'numeric' => TRUE,
'skip base' => 'taxonomy_term_data',
'zero is null' => TRUE,
),
'filter' => array(
'title' => t('Term'),
'handler' => 'views_handler_filter_term_node_tid',
'hierarchy table' => 'taxonomy_term_hierarchy',
'numeric' => TRUE,
'skip base' => 'taxonomy_term_data',
'allow empty' => TRUE,
'zero is null' => FALSE,
),
);
return $data;
}

View File

@@ -0,0 +1,420 @@
<?php
/**
* @file
* faq.views_default.inc
*/
/**
* Implementation of hook_views_default_views().
*/
function faq_views_default_views() {
$export = array();
$view = new view;
$view->name = 'faq';
$view->description = 'FAQ listings';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'FAQ';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'FAQ';
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['use_more_always'] = TRUE;
$handler->display->display_options['use_more_text'] = 'View all FAQs';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Sort criterion: Content: Sticky */
$handler->display->display_options['sorts']['sticky']['id'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['table'] = 'node';
$handler->display->display_options['sorts']['sticky']['field'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['order'] = 'DESC';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
'faq' => 'faq',
);
/* Filter criterion: Content translation: Language */
$handler->display->display_options['filters']['language']['id'] = 'language';
$handler->display->display_options['filters']['language']['table'] = 'node';
$handler->display->display_options['filters']['language']['field'] = 'language';
$handler->display->display_options['filters']['language']['value'] = array(
'***CURRENT_LANGUAGE***' => '***CURRENT_LANGUAGE***',
'und' => 'und',
);
/* Display: Block - Recent FAQs */
$handler = $view->new_display('block', 'Block - Recent FAQs', 'faq_recent');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'Recent FAQs';
$handler->display->display_options['defaults']['use_more'] = FALSE;
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['use_more_always'] = TRUE;
$handler->display->display_options['use_more_text'] = 'View all FAQs';
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['style_options']['grouping'] = '';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['block_description'] = 'Recent FAQs';
/* Display: Block - Random FAQs */
$handler = $view->new_display('block', 'Block - Random FAQs', 'faq_random');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'Random FAQs';
$handler->display->display_options['defaults']['use_more'] = FALSE;
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['use_more_always'] = TRUE;
$handler->display->display_options['use_more_text'] = 'View all FAQs';
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['hide_empty'] = 0;
$handler->display->display_options['row_options']['default_field_elements'] = 1;
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['sorts'] = FALSE;
/* Sort criterion: Global: Random */
$handler->display->display_options['sorts']['random']['id'] = 'random';
$handler->display->display_options['sorts']['random']['table'] = 'views';
$handler->display->display_options['sorts']['random']['field'] = 'random';
$handler->display->display_options['block_description'] = 'Random FAQs';
/* Display: Page - Questions Inline */
$handler = $view->new_display('page', 'Page - Questions Inline', 'page');
$handler->display->display_options['enabled'] = FALSE;
$handler->display->display_options['path'] = 'faq-questions-inline';
/* Display: Page - Questions Top */
$handler = $view->new_display('page', 'Page - Questions Top', 'page_1');
$handler->display->display_options['enabled'] = FALSE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['hide_empty'] = 0;
$handler->display->display_options['row_options']['default_field_elements'] = 1;
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['label'] = '';
$handler->display->display_options['fields']['nid']['exclude'] = TRUE;
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nid']['alter']['external'] = 0;
$handler->display->display_options['fields']['nid']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['nid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['nid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
$handler->display->display_options['fields']['nid']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['nid']['link_to_node'] = 0;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 1;
$handler->display->display_options['fields']['title']['alter']['text'] = '<h3><a id="n[nid]">[title]</a></h3>';
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
/* Field: Content: Body */
$handler->display->display_options['fields']['body']['id'] = 'body';
$handler->display->display_options['fields']['body']['table'] = 'field_data_body';
$handler->display->display_options['fields']['body']['field'] = 'body';
$handler->display->display_options['fields']['body']['label'] = '';
$handler->display->display_options['fields']['body']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['body']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['body']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['body']['alter']['external'] = 0;
$handler->display->display_options['fields']['body']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['body']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['body']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['body']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['body']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['body']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['body']['alter']['trim'] = 0;
$handler->display->display_options['fields']['body']['alter']['html'] = 0;
$handler->display->display_options['fields']['body']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['body']['element_default_classes'] = 1;
$handler->display->display_options['fields']['body']['hide_empty'] = 0;
$handler->display->display_options['fields']['body']['empty_zero'] = 0;
$handler->display->display_options['fields']['body']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['body']['field_api_classes'] = 0;
$handler->display->display_options['path'] = 'faq-questions-top';
/* Display: Attachment - Questions Top */
$handler = $view->new_display('attachment', 'Attachment - Questions Top', 'attachment_1');
$handler->display->display_options['enabled'] = FALSE;
$handler->display->display_options['defaults']['use_more'] = FALSE;
$handler->display->display_options['use_more_always'] = TRUE;
$handler->display->display_options['use_more_text'] = 'View all FAQs';
$handler->display->display_options['defaults']['link_display'] = FALSE;
$handler->display->display_options['link_display'] = 'page_1';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['hide_empty'] = 0;
$handler->display->display_options['row_options']['default_field_elements'] = 1;
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['label'] = '';
$handler->display->display_options['fields']['nid']['exclude'] = TRUE;
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nid']['alter']['external'] = 0;
$handler->display->display_options['fields']['nid']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['nid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['nid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
$handler->display->display_options['fields']['nid']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['nid']['link_to_node'] = 0;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 1;
$handler->display->display_options['fields']['title']['alter']['path'] = 'faq-questions-top#n[nid]';
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
$handler->display->display_options['displays'] = array(
'page_1' => 'page_1',
'default' => 0,
'page' => 0,
'block' => 0,
'block_1' => 0,
);
$handler->display->display_options['inherit_exposed_filters'] = 1;
/* Display: Page - New Page */
$handler = $view->new_display('page', 'Page - New Page', 'page_2');
$handler->display->display_options['enabled'] = FALSE;
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['hide_empty'] = 0;
$handler->display->display_options['row_options']['default_field_elements'] = 1;
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
$handler->display->display_options['path'] = 'faq-new-page';
/* Display: Page - Categories Inline - New Page */
$handler = $view->new_display('page', 'Page - Categories Inline - New Page', 'page_3');
$handler->display->display_options['enabled'] = FALSE;
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['style_options']['grouping'] = 'field_category';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['hide_empty'] = 0;
$handler->display->display_options['row_options']['default_field_elements'] = 1;
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: Content: Category */
$handler->display->display_options['fields']['field_category']['id'] = 'field_category';
$handler->display->display_options['fields']['field_category']['table'] = 'field_data_field_category';
$handler->display->display_options['fields']['field_category']['field'] = 'field_category';
$handler->display->display_options['fields']['field_category']['label'] = '';
$handler->display->display_options['fields']['field_category']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_category']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['field_category']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['field_category']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['field_category']['alter']['external'] = 0;
$handler->display->display_options['fields']['field_category']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['field_category']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['field_category']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['field_category']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['field_category']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['field_category']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['field_category']['alter']['trim'] = 0;
$handler->display->display_options['fields']['field_category']['alter']['html'] = 0;
$handler->display->display_options['fields']['field_category']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_category']['element_default_classes'] = 1;
$handler->display->display_options['fields']['field_category']['hide_empty'] = 0;
$handler->display->display_options['fields']['field_category']['empty_zero'] = 0;
$handler->display->display_options['fields']['field_category']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['field_category']['type'] = 'taxonomy_term_reference_plain';
$handler->display->display_options['fields']['field_category']['field_api_classes'] = 0;
$handler->display->display_options['path'] = 'faq-categories-inline-new-page';
$translatables['faq'] = array(
t('Master'),
t('FAQ'),
t('View all FAQs'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Items per page'),
t('- All -'),
t('Offset'),
t('Block - Recent FAQs'),
t('Recent FAQs'),
t('Block - Random FAQs'),
t('Random FAQs'),
t('Page - Questions Inline'),
t('more'),
t('Page - Questions Top'),
t('<h3><a id="n[nid]">[title]</a></h3>'),
t('Attachment - Questions Top'),
t('faq-questions-top#n[nid]'),
t('Page - New Page'),
t('Page - Categories Inline - New Page'),
);
$export[$view->name] = $view;
return $export;
}

View File

@@ -0,0 +1,6 @@
Forgotten Login 7.x-1.x, xxxx-xx-xx
---------------------------------------
Forgotten Login 7.x-1.0, 2011-06-28
---------------------------------------
Initial release of Drupal 7 version.

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,23 @@
WHAT IS FORGOTTEN LOGIN?
------------
Without realizing it, your Drupal site is losing customers / subscribers because
they can't log in. A surprising proportion of people fail to understand that the
user login form provides a request password facility. To overcome this, we have
written "Forgotten Login", which monitors and reacts to failed logins.
It is designed to help users of your site who have attempted and failed to login
X number of times, after which a customizable e-mail is automatically sent to
the user with the Drupal one time login URL so they can login and reset their
password.
This module is valuable for any ecommerce, ubercart or membership based website
where users are valuable. It emits the fact that you care about your users.
INSTALLATION
------------
* Copy the module to the usual place and enable it.
* Go to admin/config/people/forgotten_login and configure the e-mail settings

View File

@@ -0,0 +1,11 @@
name = "Forgotten Login"
description = "Automatically sends an e-mail to a user who fails to login."
core = 7.x
configure = admin/config/people/forgotten_login
; Information added by drupal.org packaging script on 2012-01-15
version = "7.x-1.1"
core = "7.x"
project = "forgotten_login"
datestamp = "1326654040"

View File

@@ -0,0 +1,47 @@
<?php
/**
* @file
* Install, update and uninstall functions for the Forgotten Login module.
*/
/**
* Implements hook_install().
*/
function forgotten_login_install() {
$spec = array(
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'initial' => 0,
);
db_add_field('users', 'forgotten_login_attempts', $spec);
$t = get_t();
$t_args = array('@settings_page_url' => url('admin/config/people/forgotten_login'));
drupal_set_message($t('Forgotten login module has been installed. You will need to visit the <a href="@settings_page_url">settings page</a> to set a login attempts limit before this module will do anything.', $t_args));
}
/**
* Implements hook_uninstall().
*/
function forgotten_login_uninstall() {
db_drop_field('users', 'forgotten_login_attempts');
}
/**
* Implements hook_schema_alter().
*/
function forgotten_login_schema_alter(&$schema) {
// Add field to existing schema.
$schema['users']['fields']['forgotten_login_attempts'] = array(
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'How many failed login attempts the user has made.',
);
}

View File

@@ -0,0 +1,208 @@
<?php
/**
* Implements hook_menu().
*/
function forgotten_login_menu() {
$items = array();
$items['admin/config/people/forgotten_login'] = array(
'title' => 'Forgotten Login',
'description' => 'Configure the settings for Forgotten Login module.',
'access arguments' => array('administer forgotten login'),
'page callback' => 'drupal_get_form',
'page arguments' => array('forgotten_login_admin_settings'),
);
return $items;
}
/**
* Implements hook_permission().
*/
function forgotten_login_permission() {
return array(
'administer forgotten login' => array(
'title' => t('Administer Forgotten Login'),
'description' => t('Change the settings for Forgotten Login.'),
),
);
}
/**
* Implements hook_help().
*/
function forgotten_login_help($path, $arg) {
switch ($path) {
case 'admin/config/people/forgotten_login':
return '<p>' . t('Forgotten login will automatically send an e-mail to a user who fails to login more than the configured amount of times. The (default) value of 0 failed attempts will stop the module working and reset the failed attempts count for all users.') . '</p>';
}
}
/**
* Creates the form for setting the forgotten login email settings
*
* @ingroup forms
*/
function forgotten_login_admin_settings() {
$form = array();
$form['forgotten_login_failed_attempts'] = array(
'#type' => 'textfield',
'#title' => t('Failed attempts'),
'#description' => t('After how many attempts should the automatic e-mail be sent. Setting this to 0 will disable the email.'),
'#default_value' => variable_get('forgotten_login_failed_attempts', 0),
'#required' => TRUE,
);
$form['forgotten_login_email_from'] = array(
'#type' => 'textfield',
'#title' => t('Email From'),
'#description' => t('Who the forgotten password e-mail should come from'),
'#default_value' => variable_get('forgotten_login_email_from', variable_get('site_mail', '')),
'#required' => TRUE,
);
$tokens = '!username, !site, !login_url, !mailto, !date';
$form['forgotten_login_email_subject'] = array(
'#type' => 'textfield',
'#title' => t('Email Subject'),
'#description' => t('The subject of the forgotten password e-mail. Available tokens are: @tokens', array('@tokens' => $tokens)),
'#default_value' => variable_get('forgotten_login_email_subject', variable_get('site_name', '') . ': Forgotten password'),
'#required' => TRUE,
);
$default_content = "Hi !username,\n\nYou appear to be having difficulty signing in to !site. To help, we have sent you a link which will give you access to your account:\n\n!login_url\n\nRegards,\n!site";
$form['forgotten_login_email_content'] = array(
'#type' => 'textarea',
'#rows' => 10,
'#title' => t('Email Content'),
'#description' => t('The content of the forgotten password e-mail. Available tokens are: @tokens', array('@tokens' => $tokens)),
'#default_value' => variable_get('forgotten_login_email_content', $default_content),
'#required' => TRUE,
);
$form['#submit'] = array('forgotten_login_admin_settings_submit');
return system_settings_form($form);
}
/**
* Form validater for the forgotten login email settings.
*
* @see forgotten_login_admin_settings()
* @see forgotten_login_admin_settings_submit()
* @ingroup forms
*/
function forgotten_login_admin_settings_validate($form, &$form_state) {
$values = $form_state['values'];
$failed_attempts = $values['forgotten_login_failed_attempts'];
if (!preg_match('/^[0-9]+$/', $failed_attempts)) {
form_set_error('forgotten_login_failed_attempts', t('The number of failed attempts must be numeric and positive'));
}
}
/**
* Form submit function for the forgotten login email settings. Simply sets
* all users' login attempts to 0 if the module is "disabled".
*
* @see forgotten_login_admin_settings()
* @see forgotten_login_admin_settings_validate()
* @ingroup forms
*/
function forgotten_login_admin_settings_submit($form, &$form_state) {
if ($form_state['values']['forgotten_login_failed_attempts'] == 0) {
db_query('UPDATE {users} SET forgotten_login_attempts = 0');
}
}
/**
* Implements hook_form_alter().
*
* Adds a validation handler to handle failed logins
*
* @see forgotten_login_check_login().
*/
function forgotten_login_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_login' || $form_id == 'user_login_block') {
if (!is_array($form['#validate'])) {
$form['#validate'] = array($form['#validate']);
}
$form['#validate'][] = 'forgotten_login_check_login';
}
}
/**
* Implements hook_user_login().
*/
function forgotten_login_user_login(&$edit, &$account) {
// On a valid login, simply reset the login attempts back to 0
$args = array('uid' => $account->uid);
db_query('UPDATE {users} SET forgotten_login_attempts = 0 WHERE uid = :uid', $args);
}
/**
* Validate function for the user_login and user_login_block forms.
*
* This function is called after the user's details are validated, if they
* don't have a UID now, they failed to login.
*/
function forgotten_login_check_login($form, &$form_state) {
global $user;
if ($user->uid == 0) {
// Check the trigger value here - if it's 0 we're disabled so no need to proceed
$trigger_value = variable_get('forgotten_login_failed_attempts', 0);
if ($trigger_value == 0) {
return;
}
// Attempt to find the uid for the account they tried to log in to
$uid = db_query('SELECT u.uid FROM {users} u WHERE u.status <> 0 AND u.name = :name', array(':name' => $form_state['values']['name']))->fetchField();
if ($uid == FALSE) {
// No user id found...
return;
}
// Increment the login attempts value
db_query('UPDATE {users} SET forgotten_login_attempts = forgotten_login_attempts + 1 WHERE uid = :uid', array(':uid' => $uid));
// Check the value and send an email if needed
$attempts = db_query('SELECT forgotten_login_attempts FROM {users} WHERE uid = :uid', array(':uid' => $uid))->fetchField();
// We only check for an exact value so we send the email once until a valid login happens
if ($attempts == $trigger_value) {
global $language;
$account = user_load($uid);
$params = array('account' => $account);
$language = $language ? $language : user_preferred_language($account);
$message = drupal_mail('forgotten_login', 'forgotten_login_email', $account->mail, $language, $params);
if ($message['result']) {
if (module_exists('rules')) {
rules_invoke_event('forgotten_login_email_sent', $account);
}
watchdog('forgotten_login', 'User %account was sent a login link after a total of %logins failed attempts.', array('%account' => $account->name, '%logins' => $attempts));
}
}
}
}
/**
* Implementation of hook_mail().
*/
function forgotten_login_mail($key, &$message, $params) {
$language = $message['language'];
$variables = array();
// Create the tokens from D6's user_mail_tokens() to help upgrades.
$variables['!username'] = $params['account']->name;
$variables['!site'] = variable_get('site_name', 'Drupal');
$variables['!login_url'] = user_pass_reset_url($params['account']);
$variables['!mailto'] = $params['account']->mail;
$variables['!date'] = date(time());
$default_content = "Hi !username,\n\nYou appear to be having difficulty signing in to !site. To help, we have sent you a link which will give you access to your account:\n\n!login_url\n\nRegards,\n!site";
$message['subject'] = strtr(variable_get('forgotten_login_email_subject', variable_get('site_name', '') . ': Forgotten password'), $variables);
$message['body'] = array(strtr(variable_get('forgotten_login_email_content', $default_content), $variables));
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* @file
* Rules integration for forgotten login.
*
* @addtogroup rules
* @{
*/
/**
* Implements hook_rules_event_info().
*/
function forgotten_login_rules_event_info() {
$events = array();
$events['forgotten_login_email_sent'] = array(
'label' => t('Forgotten login email sent'),
'group' => t('Forgotten Login'),
'variables' => array(
'user' => array(
'type' => 'user',
'label' => t('Failed login account'),
),
),
);
return $events;
}
/**
* @}
*/

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,28 @@
--------------------------------------------------------------------------------
Friendly Register
--------------------------------------------------------------------------------
Maintainers:
* Andrew M Riley
Project homepage: http://drupal.org/project/friendly_register
Friendly Register module allows users to see if a username or email address has
already been used during registration before they submit the form. This module
checks the database and returns an error if the username is already in use. In
addition to checking the username the module checks if there is already an
account using that email address, if there is, a message is displayed with
links to the login or reset password pages.
Installation
------------
* Install this module into the appropriate modules directory.
* Enable this module.
* Make sure you have cron running on a regular basis (at least once per 24 hours)
Permissions
-----------
There is only one permission for this module and it is completely optional. Set
"Ignore Flood Checking" for a role if you wish them to not be checked by the
300 query a day limit. I would recommend against giving the "anonymous" role
this permission.

View File

@@ -0,0 +1,11 @@
#edit-name-check,
#edit-mail-check {
padding-left: 20px;
background: transparent url(../img/status.png) no-repeat;
height: 16px;
}
#edit-name-check.error,
#edit-mail-check.error {
background-position: 0 -16px;
}

View File

@@ -0,0 +1,10 @@
name = Friendly Register
description = "Allows for users to see if a username or email is available before submitting the registration form."
core = 7.x
; Information added by drupal.org packaging script on 2012-03-07
version = "7.x-1.0"
core = "7.x"
project = "friendly_register"
datestamp = "1331094642"

View File

@@ -0,0 +1,56 @@
<?php
/**
* @file
* Allows users to get feedback on username and email without submitting the form.
*/
/**
* Implements hook_schema().
*/
function friendly_register_schema() {
$schema = array();
$schema['friendly_register_flood'] = array(
'description' => 'This table is use to limit flooding of requests.',
'fields' => array(
'ip' => array(
'description' => 'The IP address (both IP v4 and v6)',
'type' => 'char',
'length' => 40,
'not null' => TRUE,
),
'hits' => array(
'description' => 'Total number of hits this IP address has caused.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'lasthit' => array(
'description' => 'The date time (unix epoch) of the last hit.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
'indexes' => array(
'ip' => array('ip', 'hits'),
'lasthit' => array('lasthit'),
),
);
return $schema;
}
function friendly_register_update_7100() {
db_drop_index('friendly_register_flood', 'ip');
db_change_field('friendly_register_flood', 'ip', 'ip',
array('type' => 'char', 'length' => 40, 'not null' => TRUE),
array('indexes' => array(
'ip' => array(
'ip',
'hits',
),
'lasthit' => array(
'lasthit',
)
)));
}

View File

@@ -0,0 +1,113 @@
<?php
/**
* @file
* Primary logic for the friendly_register module that allows for checking of username and email.
*/
define('FRIENDLY_REGISTER_MAX_HITS', 300);
define('FRIENDLY_REGISTER_EXPIRES', 86400);
/**
* Implements hook_menu().
*/
function friendly_register_menu() {
$items['ajax/check-email'] = array(
'page callback' => 'friendly_register_check_email',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ajax/check-user'] = array(
'page callback' => 'friendly_register_check_user',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_permission().
*/
function friendly_register_permission() {
return array(
'ignore flood' => array(
'title' => t('Ignore Flood Checking'),
'description' => t('Allows users to have unlimited checks against friendly register.'),
'restrict access' => FALSE,
),
);
}
/**
* Implements hook_cron().
*/
function friendly_register_cron() {
$expires = REQUEST_TIME - FRIENDLY_REGISTER_EXPIRES;
db_delete('friendly_register_flood')
->condition('lasthit', $expires, '<=')
->execute();
}
/**
* Implements hook_FORM_form_alter().
*/
function friendly_register_form_user_register_form_alter(&$form, &$form_state, $form_id) {
$path = drupal_get_path('module', 'friendly_register');
drupal_add_js($path . '/js/friendly_register.js', 'file');
drupal_add_css($path . '/css/friendly_register.css');
}
function friendly_register_check_email($address) {
// Check if it is a valid email address. No need to check if it is not
if (valid_email_address($address)) {
drupal_json_output(_friendly_register_check_field('mail', $address));
}
else {
// This flag will return incomplete so the user doesn't see an error
// if they are just starting to enter in their email address
drupal_json_output(array('available' => 'incomplete'));
}
}
function friendly_register_check_user($username) {
drupal_json_output(_friendly_register_check_field('name', $username));
}
function _friendly_register_check_field($field_name, $value) {
if (_friendly_register_check_flood()) {
$result = db_query("SELECT uid FROM {users} WHERE " . $field_name . " = :value", array(':value' => $value))->fetchField();
return array('available' => ($result == NULL));
}
else {
return array('flood' => TRUE);
}
}
function _friendly_register_check_flood() {
if (user_access('ignore flood')) {
return TRUE;
}
else {
$ip = ip_address();
$q = 'SELECT hits FROM {friendly_register_flood} WHERE ip = :ip';
$hits = db_query($q, array(':ip' => $ip))->fetchField();
if ($hits == NULL) {
$id = db_insert('friendly_register_flood')
->fields(array(
'ip' => $ip,
'hits' => 1,
'lasthit' => REQUEST_TIME,
))->execute();
}
else {
db_update('friendly_register_flood')
->expression('hits', 'hits + 1')
->expression('lasthit', REQUEST_TIME)
->condition('ip', $ip)
->execute();
}
return $hits < FRIENDLY_REGISTER_MAX_HITS;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B

View File

@@ -0,0 +1,118 @@
(function ($) {
Drupal.friendly_register = Drupal.friendly_register || {};
Drupal.friendly_register.flood = false;
Drupal.friendly_register.timeout = null;
Drupal.friendly_register.checkUserName = function (userName) {
$.getJSON(userName.ajaxPath + userName.oldValue, function(data) {
if (!data.flood) {
var message;
var cssclass;
if (data.available) {
message = userName.avail;
cssclass = 'ok';
} else {
message = userName.notAvail;
cssclass = 'error';
}
$('#edit-name-check').remove();
userName.field.after('<div id="edit-name-check" class="' + cssclass + '"><span class="text">' + message + '</span></div>');
} else {
Drupal.friendly_register.flood = true;
$('#edit-name-check').remove();
clearTimeout(Drupal.friendly_register.timeout);
}
});
};
Drupal.friendly_register.checkEmail = function (email) {
$.getJSON(email.ajaxPath + email.oldValue, function(data) {
if (!data.flood) {
if (data.available == 'incomplete') {
$('#edit-mail-check').remove();
return;
}
var message;
if (data.available) {
message = email.avail;
cssclass = 'ok';
} else {
message = email.notAvail;
cssclass = 'error';
}
$('#edit-mail-check').remove();
email.field.after('<div id="edit-mail-check" class="' + cssclass + '"><span class="text">' + message + '</span></div>');
} else {
Drupal.friendly_register.flood = true;
$('#edit-mail-check').remove();
clearTimeout(Drupal.friendly_register.timeout);
}
});
};
Drupal.behaviors.friendly_register = {
attach: function (context, settings) {
var loginURL = Drupal.settings.basePath + 'user';
var resetURL = Drupal.settings.basePath + 'user/password';
var userName = new Object();
userName.oldValue = '';
userName.ajaxPath = Drupal.settings.basePath + 'ajax/check-user/';
userName.field = $('#user-register-form #edit-name', context);
userName.avail = Drupal.t('This username is available.');
userName.notAvail = Drupal.t('This username is not available.');
var email = new Object();
email.oldValue = '';
email.ajaxPath = Drupal.settings.basePath + 'ajax/check-email/';
email.field = $('#user-register-form #edit-mail', context);
email.avail = Drupal.t('This email address has not been used.');
email.notAvail = Drupal.t('This email address is already in use, please <a href="@login">try logging in</a> with that email address or <a href="@reset">resetting your password</a>.', {'@login': loginURL, '@reset': resetURL});
userName.field.focus(function () {
if (Drupal.friendly_register.flood) {
return;
}
Drupal.friendly_register.timeout = setInterval(function (){
var newValue = userName.field.val();
if (newValue != userName.oldValue) {
userName.oldValue = newValue;
Drupal.friendly_register.checkUserName(userName);
}
}, 1000);
})
.blur(function () {
clearTimeout(Drupal.friendly_register.timeout);
var newValue = userName.field.val();
if (!Drupal.friendly_register.flood && newValue != userName.oldValue) {
userName.oldValue = newValue;
Drupal.friendly_register.checkUserName(userName);
}
});
email.field.focus(function () {
if (Drupal.friendly_register.flood) {
return;
}
Drupal.friendly_register.timeout = setInterval(function (){
var newValue = email.field.val();
if (newValue != email.oldValue) {
email.oldValue = newValue;
Drupal.friendly_register.checkEmail(email);
}
}, 1000);
})
.blur(function () {
clearTimeout(Drupal.friendly_register.timeout);
var newValue = email.field.val();
if (!Drupal.friendly_register.flood && newValue != email.oldValue) {
email.oldValue = newValue;
Drupal.friendly_register.checkEmail(email);
}
});
}
};
})(jQuery);

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,3 @@
.genpass-password {
white-space: nowrap;
}

View File

@@ -0,0 +1,11 @@
name = Generate Password
description = Generate a password when adding a new user.
core = 7.x
configure = admin/config/people/accounts
; Information added by drupal.org packaging script on 2012-02-20
version = "7.x-1.0"
core = "7.x"
project = "genpass"
datestamp = "1329772844"

View File

@@ -0,0 +1,12 @@
<?php
/*
* Implements hook_uninstall().
*/
function genpass_uninstall() {
variable_del('genpass_algorithm');
variable_del('genpass_display');
variable_del('genpass_entropy');
variable_del('genpass_length');
variable_del('genpass_mode');
}

View File

@@ -0,0 +1,282 @@
<?php
define('GENPASS_REQUIRED', 0);
define('GENPASS_OPTIONAL', 1);
define('GENPASS_RESTRICTED', 2);
define('GENPASS_DISPLAY_NONE', 0);
define('GENPASS_DISPLAY_ADMIN', 1);
define('GENPASS_DISPLAY_USER', 2);
define('GENPASS_DISPLAY_BOTH', 3);
/**
* Implements of hook_init().
*/
function genpass_init() {
drupal_add_css(drupal_get_path('module', 'genpass') . '/genpass.css');
}
/**
* Defines default characters allowed for passwords.
*/
function _GENPASS_REQUIRED_entropy() {
return 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789!#$%&()*+,-./:;<=>?@[]^_{|}~';
}
/**
* Generate a new password using the preferred password generation algorithm.
*
* @return a fresh password.
*/
function genpass_generate() {
return module_invoke(genpass_algorithm_module(), 'password');
}
/**
* Generate a new password using genpass's internal password generation
* algorithm.
* Based on the original D6 user_password function (with more characters)
*
* @return a fresh password according to the settings made in /admin/user/settings
*
* @see genpass_form_alter()
*/
function genpass_password() {
$pass = '';
$length = variable_get('genpass_length', 8);
$allowable_characters = variable_get('genpass_entropy', _GENPASS_REQUIRED_entropy());
// Zero-based count of characters in the allowable list:
$len = strlen($allowable_characters) - 1;
// Loop the number of times specified by $length.
for ($i = 0; $i < $length; $i++) {
// Each iteration, pick a random character from the
// allowable string and append it to the password:
$pass .= $allowable_characters[mt_rand(0, $len)];
}
return $pass;
}
/**
* Helper function to find a item in the user form, since its position
* within the form-array depends on the profile module (account-category).
*/
function &_genpass_get_form_item(&$form, $field) {
if (isset($form['account'][$field])) {
return $form['account'][$field];
}
else {
return $form[$field];
}
}
/**
* Implementation of hook_form_alter()
*/
function genpass_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
// User admin settings form at admin/config/people/accounts
case 'user_admin_settings':
$form['registration_cancellation']['genpass_mode'] = array(
'#type' => 'radios',
'#title' => t('Password handling'),
'#default_value' => variable_get('genpass_mode', GENPASS_REQUIRED),
'#options' => array(
GENPASS_REQUIRED => t('Users <strong>must</strong> enter a password on registration. This is disabled if e-mail verification is enabled above.'),
GENPASS_OPTIONAL => t('Users <strong>may</strong> enter a password on registration. If left empty, a random password will be generated. This always applies when an administer is creating the account.'),
GENPASS_RESTRICTED => t('Users <strong>cannot</strong> enter a password on registration; a random password will be generated. This always applies for the regular user registration form if e-mail verification is enabled above.'),
),
'#description' => t('Choose a password handling mode for new users.'),
);
$form['registration_cancellation']['genpass_length'] = array(
'#type' => 'textfield',
'#title' => t('Generated password length'),
'#default_value' => variable_get('genpass_length', 8),
'#size' => 2,
'#maxlength' => 2,
'#description' => t('Set the length of generated passwords here. Allowed range: 5 to 32.'),
);
$form['registration_cancellation']['genpass_entropy'] = array(
'#type' => 'textfield',
'#title' => t('Generated password entropy'),
'#size' => 100,
'#default_value' => variable_get('genpass_entropy', _GENPASS_REQUIRED_entropy()),
'#description' => t('Give a list of possible characters for a generated password. Note that the list must contain at least X different characters where X is defined by the length you have given above.'),
);
// Provide a selection mechanism to choose the preferred algorithm for
// generating passwords. Any module which implements hook_password() is
// displayed here.
$form['registration_cancellation']['genpass_algorithm'] = array(
'#type' => 'radios',
'#title' => t('Password generation algorithm'),
'#default_value' => genpass_algorithm_module(),
'#options' => genpass_add_samples(genpass_algorithm_modules()),
'#description' => t('If third party modules define a password generation algorithm, you can select which one to use. Note that algorithms other than genpass will ignore the preferred entropy and password length. The currently selected algorithm produced the password @pw.', array('@pw' => genpass_generate())),
);
$form['registration_cancellation']['genpass_display'] = array(
'#type' => 'radios',
'#title' => t('Generated password display'),
'#default_value' => variable_get('genpass_display', GENPASS_DISPLAY_BOTH),
'#options' => array(
GENPASS_DISPLAY_NONE => t('Do not display.'),
GENPASS_DISPLAY_ADMIN => t('Display when site administrators create new user accounts.'),
GENPASS_DISPLAY_USER => t('Display when users create their own accounts.'),
GENPASS_DISPLAY_BOTH => t('Display to both site administrators and users.'),
),
'#description' => t('Whether or not the generated password should display after a user account is created.'),
);
$form['#validate'][] = 'genpass_user_admin_settings_validate';
// Move the "When cancelling a user account" field down.
$form['registration_cancellation']['user_cancel_method']['#weight'] = 1;
break;
// User registration form at admin/people/create
case 'user_register_form':
$mode = variable_get('genpass_mode', GENPASS_REQUIRED);
// Add validation function, where password may get set
$form['#validate'][] = 'genpass_register_validate';
// Administrator is creating the user
if ($_GET['q'] == 'admin/user/user/create') {
// Switch to optional mode
$mode = GENPASS_OPTIONAL;
// Help avoid obvious consequence of password being optional
$notify_item =& _genpass_get_form_item($form, 'notify');
$notify_item['#description'] = t('This is recommended when auto-generating the password; otherwise, neither you nor the new user will know the password.');
}
// Pass mode to validation function
$form['genpass_mode'] = array(
'#type' => 'value',
'#value' => $mode,
);
$pass_item =& _genpass_get_form_item($form, 'pass');
switch ($mode) {
// If password is optional, don't require it, and give the user an
// indication of what will happen if left blank
case GENPASS_OPTIONAL:
$pass_item['#required'] = FALSE;
$pass_item['#description'] = (empty($pass_item['#description']) ? '' : $pass_item['#description'] . ' ') . t('If left blank, a password will be generated for you.');
break;
// If password is restricted, remove access
case GENPASS_RESTRICTED:
$pass_item['#access'] = FALSE;
$pass_item['#required'] = FALSE;
break;
}
break;
}
}
/**
* User settings validation.
*/
function genpass_user_admin_settings_validate($form, &$form_state) {
// Validate length of password
$length = $form_state['values']['genpass_length'];
if (!is_numeric($length) || $length < 5 || $length > 32) {
form_set_error('genpass_length', t('The length of a generated password must be between 5 and 32.'));
return;
}
// Validate allowed characters
$chars = array_unique(preg_split('//', $form_state['values']['genpass_entropy'], -1, PREG_SPLIT_NO_EMPTY));
if (count($chars) < $length) {
form_set_error('genpass_entropy', t('The list of possible characters is not long or unique enough.'));
return;
}
return $form;
}
/**
* User registration validation.
*/
function genpass_register_validate($form, &$form_state) {
if (empty($form_state['values']['pass']) && !form_get_errors()) {
// Generate and set password
$pass = genpass_generate();
$pass_item =& _genpass_get_form_item($form, 'pass');
form_set_value($pass_item, $pass, $form_state);
$display = variable_get('genpass_display', GENPASS_DISPLAY_BOTH);
// Administrator created the user.
if ($_GET['q'] == 'admin/people/create') {
$message = t('Since you did not provide a password, it was generated automatically for this account.');
if (in_array($display, array(GENPASS_DISPLAY_ADMIN, GENPASS_DISPLAY_BOTH))) {
$message .= ' ' . t('The password is: <strong class="genpass-password">!password</strong>', array('!password' => $pass));
}
}
// Optional - User did not provide password, so it was generated
elseif ($form_state['values']['genpass_mode'] == GENPASS_OPTIONAL) {
$message = t('Since you did not provide a password, it was generated for you.');
if (in_array($display, array(GENPASS_DISPLAY_USER, GENPASS_DISPLAY_BOTH))) {
$message .= ' ' . t('Your password is: <strong class="genpass-password">!password</strong>', array('!password' => $pass));
}
}
// Restricted - User was forced to receive a generated password
elseif ($form_state['values']['genpass_mode'] == GENPASS_RESTRICTED && in_array($display, array(GENPASS_DISPLAY_USER, GENPASS_DISPLAY_BOTH))) {
$message = t('The following password was generated for you: <strong class="genpass-password">!password</strong>', array('!password' => $pass));
}
if (!empty($message)) {
drupal_set_message($message);
}
}
return $form;
}
/**
* Return an array of all modules which implement hook_password.
*
* @return array of module names.
*/
function genpass_algorithm_modules() {
// Fetch a list of all modules which implement the password generation hook.
// To be in this list, a module must implement a hook, and return random
// passwords as strings.
$return = array();
foreach (module_implements('password') as $module) {
$return[$module] = $module;
}
return $return;
}
/**
* Return the currently activated module for generating passwords. Does some
* validation to make sure the variable contains a valid module name.
*
* @return the name of the module whose implementation of hook_password is
* currently the preferred implementation.
*/
function genpass_algorithm_module() {
$modules = genpass_algorithm_modules();
$module = variable_get('genpass_algorithm', 'genpass');
if (in_array($module, array_keys($modules))) {
return $module;
}
else {
return 'genpass';
}
}
/**
* Adds some sample passwords to each module in an array.
*/
function genpass_add_samples($array) {
$return = array();
foreach ($array as $module => $name) {
$return[$module] = $module . ' (' . t('examples') . ': <strong>' . htmlentities(module_invoke($module, 'password')) . '</strong>, <strong>' . htmlentities(module_invoke($module, 'password')) . '</strong>)';
}
return $return;
}

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,4 @@
Moshe Weitzman <weitzman AT tejasa DOT com>
ARDAS group <info AT ardas DOT dp DOT ua>
rsvelko from segments.at
mithy <http://drupal.org/user/258911/>

View File

@@ -0,0 +1,67 @@
The Login Destination module provides a way to customize the destination that a
user is redirected to after logging in, registering to the site, using a
one-time login link or logging out.
The configuration consists of specifying so called login destination rules that
are evaluated when the login or logout takes place. Those rules are evaluated
against certain conditions and the user is taken to the destination specified
by the first matching rule. If the destination is empty, no redirect is
performed aka user is taken to the default destination. You can define pages
from which a user logs in/out to be a matching criterion. You can also select
certain user roles that are matched against those of a user. Note that only one
role has to match in order for the redirect to take place. If no roles are
selected the redirect is performed regardless of user roles. You can also
provide your own conditions by specifying PHP snippets (the PHP Filter has to
be enabled). The snippet should return TRUE if the condition matches and FALSE
otherwise.
There are no separate triggers for login and registration; instead you can
differentiate them by the specifying the pages that a user comes from:
- user - the user login form.
- user/register - the user registration form.
- user/*/edit - one-time login link, after the user has set the password.
- other - the login block or login forms embedded by other modules.
Please note that a user will be redirected when they register, even though they
may not be logged in afterwards immediately (e.g. because of email validation).
You can use this behavior to send the user to a page that contains further
instructions.
The destination you specify can be an internal page or an external URL.
Remember to precede the url with http://. You can also use the <front> tag to
redirect to the front page or the <current> tag to redirect to the page where
the user was before login/logout, aka the current page. In case of
login/register form the page from which the user entered the form is treaded as
the current page. Note that if you provide your own login/logout links you have
to add the 'current' GET parameter to them so Login Destination knows where
your users come from.
In some cases you will also need to provide the destination in a dynamic way by
using PHP snippets (the PHP Filter has to be enabled). The snippet's return
variable can be a string, for straight pages and urls, or an array for more
advanced options. The array should be in a form that the url function will
understand, e.g. %example. For more information, see the online API entry for
<a href="@url">url function</a>. In most cases you will use it to specify GET
parameters and an anchor ("#"). Please study the examples below:
Take the user to the administration panel with underlying blog page:
<?php return array('blog', array('fragment' => 'overlay=admin/config', ), ); ?>
Take the user to the front page and specify some custom parameters:
<?php return array('<front>', array('query' => array('param1' => 'value1',
'param2' => 'value2', ), ), ); ?>
Take the user to the default page:
<?php return NULL; ?>
It also possible to set some advanced parameters on the setting page. Every
time in Drupal you can specify the 'destination' GET parameter in url to
redirect the user to a custom page. If you check the option
'Preserve the destination parameter' Login Destination will give priority to
this parameter over its own module settings. However with this option enabled
the redirect from the login block will not work. In some rare cases you can
also redirect the user just after using the one-time login link, before given
the possibility to change their password. Do this by checking the
'Redirect immediately after using one-time login link' option.

View File

@@ -0,0 +1,357 @@
<?php
/**
* @file
* Admin page callback file for the Login Destination module.
*/
/**
* List destination rules.
*/
function login_destination_overview() {
$header = array(
t('Destination'),
t('Triggers'),
t('Pages'),
t('Roles'),
array('data' => t('Operations'), 'colspan' => 2),
);
$rows = array();
// Get all login destination rules from the database.
$result = db_select('login_destination', 'l')
->fields('l', array('id', 'triggers', 'roles', 'pages_type', 'pages', 'destination'))
->orderBy('weight')
->execute()
->fetchAll();
// Loop through the categories and add them to the table.
foreach ($result as $data) {
$triggers = array_map('check_plain', unserialize($data->triggers));
if (empty($triggers))
$triggers = array();
$roles = array_map('check_plain', unserialize($data->roles));
if (empty($roles))
$roles = array();
$rows[] = array(
theme('login_destination_destination', array('destination' => $data->destination)),
theme('login_destination_triggers', array('items' => $triggers)),
theme('login_destination_pages', array('pages' => $data->pages, 'pages_type' => $data->pages_type)),
theme('login_destination_roles', array('items' => $roles)),
l(t('Edit'), 'admin/config/people/login-destination/edit/' . $data->id),
l(t('Delete'), 'admin/config/people/login-destination/delete/' . $data->id),
);
}
if (!$rows) {
$rows[] = array(array(
'data' => t('No rules available.'),
'colspan' => 6,
));
}
$build['login-destination_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
return $build;
}
function theme_login_destination_destination($variables) {
$output = nl2br(check_plain($variables['destination']));
if (empty($output)) {
$output = '<i>' . t('Empty') . '</i>';
}
return $output;
}
function theme_login_destination_triggers($variables) {
$items = array_map('check_plain', $variables['items']);
if (empty($items)) {
return '<i>' . t('All triggers') . '</i>';
}
$output = '';
foreach ($items as &$item) {
switch ($item) {
case 'login':
$item = 'Login';
break;
case 'logout':
$item = 'Logout';
break;
}
$output .= $item . "<br/>";
}
return $output;
}
function theme_login_destination_pages($variables) {
$type = $variables['pages_type'];
if ($type == LOGIN_DESTINATION_REDIRECT_PHP) {
return nl2br(check_plain($variables['pages']));
}
$pages = trim($variables['pages']);
if (empty($pages)) {
if ($type == LOGIN_DESTINATION_REDIRECT_NOTLISTED) {
return '<i>' . t('All pages') . '</i>';
}
else {
return '<i>' . t('No pages') . '</i>';
}
}
$pages = explode("\n", preg_replace('/\r/', '', check_plain($variables['pages'])));
$output = '';
foreach ($pages as &$page) {
if ($type == LOGIN_DESTINATION_REDIRECT_NOTLISTED) {
$output .= "~ ";
}
$output .= $page . "<br/>";
}
return $output;
}
function theme_login_destination_roles($variables) {
$items = array_values(array_intersect_key(_login_destination_role_options(), $variables['items']));
if (empty($items)) {
return '<i>' . t('All roles') . '</i>';
}
return theme('item_list', array('items' => $items));
}
/**
* Category edit page.
*/
function login_destination_edit_form($form, &$form_state, array $rule = array()) {
// default values
$rule += array(
'triggers' => array(),
'roles' => array(),
'pages_type' => LOGIN_DESTINATION_REDIRECT_NOTLISTED,
'pages' => '',
'destination_type' => LOGIN_DESTINATION_STATIC,
'destination' => '<front>',
'id' => NULL,
'weight' => 0,
);
$access = user_access('use PHP for settings');
$type = $rule['destination_type'];
if ($type == LOGIN_DESTINATION_SNIPPET && !$access) {
$form['destination_type'] = array(
'#type' => 'value',
'#value' => LOGIN_DESTINATION_SNIPPET,
);
$form['destination'] = array(
'#type' => 'value',
'#value' => $rule['destination'],
);
}
else {
$options = array(
LOGIN_DESTINATION_STATIC => t('Internal page or external URL'),
);
$description = t("Specify page by using its path. Example path is %blog for the blog page. %front is the front page. %current is the current page. Precede with http:// for an external URL. Leave empty to redirect to a default page.", array('%blog' => 'blog', '%front' => '<front>', '%current' => '<current>'));
if (module_exists('php') && $access) {
$options += array(LOGIN_DESTINATION_SNIPPET => t('Page returned by this PHP code (experts only)'));
$description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. It should return either a string value or an array of params that the %function function will understand, e.g. %example. For more information, see the online API entry for <a href="@url">url function</a>. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '<?php ?>', '%function' => 'url($path = \'\', array $options = array())', '%example' => '<?php return array(\'blog\', array(\'fragment\' => \'overlay=admin/config\', ), ); ?>', '@url' => 'http://api.drupal.org/api/drupal/includes--common.inc/function/url/7'));
}
$form['destination_type'] = array(
'#type' => 'radios',
'#title' => 'Redirect to page',
'#default_value' => $type,
'#options' => $options,
);
$form['destination'] = array(
'#type' => 'textarea',
'#default_value' => $rule['destination'],
'#description' => $description,
);
}
$triggers = array_map('check_plain', $rule['triggers']);
if (empty($triggers)) {
$triggers = array();
}
$form['triggers'] = array(
'#type' => 'checkboxes',
'#title' => t('Redirect upon triggers'),
'#options' => array('login' => 'Login, registration, one-time login link', 'logout' => 'Logout'),
'#default_value' => $triggers,
'#description' => 'Redirect only upon selected trigger(s). If you select no triggers, all of them will be used.',
);
$type = $rule['pages_type'];
if ($type == LOGIN_DESTINATION_REDIRECT_PHP && !$access) {
$form['pages_type'] = array(
'#type' => 'value',
'#value' => LOGIN_DESTINATION_REDIRECT_PHP,
);
$form['pages'] = array(
'#type' => 'value',
'#value' => $rule['destination'],
);
}
else {
$options = array(
LOGIN_DESTINATION_REDIRECT_NOTLISTED => t('All pages except those listed'),
LOGIN_DESTINATION_REDIRECT_LISTED => t('Only the listed pages'),
);
$description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. %login is the login form. %register is the registration form. %reset is the one-time login (e-mail validation).", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>', '%login' => 'user', '%register' => 'user/register', '%reset' => 'user/*/edit'));
if (module_exists('php') && $access) {
$options += array(LOGIN_DESTINATION_REDIRECT_PHP => t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'));
$description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '<?php ?>'));
}
$form['pages_type'] = array(
'#type' => 'radios',
'#title' => t('Redirect from specific pages'),
'#default_value' => $type,
'#options' => $options,
);
$form['pages'] = array(
'#type' => 'textarea',
'#default_value' => $rule['pages'],
'#description' => $description,
);
}
$default_role_options = array_map('check_plain', $rule['roles']);
if (empty($default_role_options)) {
$default_role_options = array();
}
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Redirect users with roles'),
'#options' => _login_destination_role_options(),
'#default_value' => $default_role_options,
'#description' => 'Redirect only the selected role(s). If you select no roles, all users will be redirected.',
);
$form['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => $rule['weight'],
'#description' => t('When evaluating login destination rules, those with lighter (smaller) weights get evaluated before rules with heavier (larger) weights.'),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
if ($rule['id']) {
$form['id'] = array(
'#type' => 'hidden',
'#value' => $rule['id'],
);
}
return $form;
}
/**
* Validate the contact category edit page form submission.
*/
function login_destination_edit_form_validate($form, &$form_state) {
}
/**
* Process the contact category edit page form submission.
*/
function login_destination_edit_form_submit($form, &$form_state) {
$form_state['values']['triggers'] = serialize(array_filter($form_state['values']['triggers']));
$form_state['values']['roles'] = serialize(array_filter($form_state['values']['roles']));
if (empty($form_state['values']['id'])) {
drupal_write_record('login_destination', $form_state['values']);
}
else {
drupal_write_record('login_destination', $form_state['values'], array('id'));
}
drupal_set_message(t('Login destination to %destination has been saved.', array('%destination' => $form_state['values']['destination'])));
$form_state['redirect'] = 'admin/config/people/login-destination';
}
/**
* Form builder for deleting a login destination.
*/
function login_destination_delete_form($form, &$form_state, array $rule) {
$form['login_destination'] = array(
'#type' => 'value',
'#value' => $rule,
);
return confirm_form(
$form,
t('Are you sure you want to delete the login destination %destination ?', array('%destination' => $rule['destination'])),
'admin/config/people/login-destination',
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
/**
* Submit handler for the confirm delete login destination form.
*/
function login_destination_delete_form_submit($form, &$form_state) {
$rule = $form['login_destination']['#value'];
db_delete('login_destination')
->condition('id', $rule['id'])
->execute();
drupal_set_message(t('The login destination %destination has been deleted.', array('%destination' => $rule['destination'])));
$form_state['redirect'] = 'admin/config/people/login-destination';
}
/**
* Settings page.
*/
function login_destination_settings() {
$form = array();
$form['settings']['login_destination_preserve_destination'] = array(
'#type' => 'checkbox',
'#default_value' => variable_get('login_destination_preserve_destination', FALSE),
'#title' => t('Preserve the destination parameter'),
'#description' => t("The 'destination' GET parameter will have priority over the settings of this module. With this setting enabled, redirect from the user login block will not work."),
);
$form['settings']['login_destination_immediate_redirect'] = array(
'#type' => 'checkbox',
'#default_value' => variable_get('login_destination_immediate_redirect', FALSE),
'#title' => t('Redirect immediately after using one-time login link'),
'#description' => t("User will be redirected before given the possibility to change their password."),
);
return system_settings_form($form);
}

View File

@@ -0,0 +1,13 @@
name = Login Destination
description = Customize the destination that the user is redirected to after login.
core = 7.x
files[] = login_destination.module
files[] = login_destination.admin.inc
configure = admin/config/people/login-destination
; Information added by drupal.org packaging script on 2012-12-18
version = "7.x-1.1"
core = "7.x"
project = "login_destination"
datestamp = "1355853150"

View File

@@ -0,0 +1,140 @@
<?php
/**
* @file
* Install, update and uninstall functions for the Login Destination module.
*/
/**
* Implements hook_schema().
*/
function login_destination_schema() {
$schema['login_destination'] = array(
'description' => 'Login Destination rules.',
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary Key: Unique ID.',
),
'triggers' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Triggers on which to perform redirect',
),
'roles' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Roles to perform redirect for',
),
'pages_type' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Flag to indicate from which pages to redirect. (0 = all pages except listed pages, 1 = only listed pages, 2 = Use custom PHP code)',
),
'pages' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Pages from which to redirect',
),
'destination_type' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Flag to indicate the destination type. (0 = static URL, 1 = PHP code)',
),
'destination' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Redirect destination',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => "The rule's weight.",
),
),
'primary key' => array('id'),
'indexes' => array(
'list' => array('weight'),
),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function login_destination_install() {
// update the alter option of 'user/logout' to TRUE (menu_save invokes necessary hooks)
$result = db_query("SELECT mlid, menu_name FROM {menu_links} WHERE link_path = 'user/logout' OR link_path = 'user/login' OR link_path = 'user' ORDER BY mlid ASC");
foreach($result as $res) {
$item = menu_link_load($res->mlid);
$item['options']['alter'] = TRUE;
db_update('menu_links')
->fields(array(
'options' => serialize($item['options']),
))
->condition('mlid', $item['mlid'])
->execute();
}
}
/**
* Implementation of hook_uninstall().
*/
function login_destination_uninstall() {
variable_del('login_destination_preserve_destination');
variable_del('login_destination_profile_redirect');
}
function login_destination_update_7000() {
$type = variable_get('ld_condition_type', 'always');
$snippet = variable_get('ld_condition_snippet', '');
if ($type == 'snippet') {
$form_state['values']['pages_type'] = 2;
// We introduced php tags.
$form_state['values']['pages'] = '<?php ' . $snippet . '?>';
}
elseif ($type == 'pages') {
$form_state['values']['pages_type'] = 1;
$form_state['values']['pages'] = $snippet;
}
else {
$form_state['values']['pages_type'] = 0;
$form_state['values']['pages'] = $snippet;
}
$type = variable_get('ld_url_type', 'static');
$snippet = variable_get('ld_url_destination', '');
if ($type == 'snippet') {
$form_state['values']['destination_type'] = 1;
// syntax for return value has changed.
$form_state['values']['destination'] = '<?php /* ' . $snippet . ' */ ?>';
}
else {
$form_state['values']['destination_type'] = 0;
$form_state['values']['destination'] = $snippet;
}
$form_state['values']['triggers'] = serialize(array('login'));
$form_state['values']['roles'] = serialize(array());
drupal_write_record('login_destination', $form_state['values']);
variable_set('login_destination_preserve_destination', variable_get('ld_destination', 0));
variable_del('ld_condition_type');
variable_del('ld_condition_snippet');
variable_del('ld_destination');
variable_del('ld_url_type');
variable_del('ld_url_destination');
}

View File

@@ -0,0 +1,504 @@
<?php
/**
* @file
* Control where users are directed to, once they login
*/
// Page constants
define('LOGIN_DESTINATION_REDIRECT_NOTLISTED', 0);
define('LOGIN_DESTINATION_REDIRECT_LISTED', 1);
define('LOGIN_DESTINATION_REDIRECT_PHP', 2);
// Destination constants
define('LOGIN_DESTINATION_STATIC', 0);
define('LOGIN_DESTINATION_SNIPPET', 1);
/**
* Implement hook_help().
*/
function login_destination_help($path, $arg) {
switch ($path) {
case 'admin/help#login_destination':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Login Destination module allows you to customize the destination that the user is redirected to after logging in, registering to the site, using a one-time login link or logging out. The destination can be an internal page or an external URL. You may specify certain conditions like pages or user roles and make the destination depend upon them. You may also use a PHP snippets to provide custom conditions and destinations. Note that PHP Filter module has to be enabled and you have to be granted the "Use PHP for settings" permissions to be able to enter PHP code.') . '</p>';
return $output;
case 'admin/config/people/login-destination':
return '<p>' . t('Login destination rules are evaluated each time a user logs in, registers to the site, uses a one-time login link or logs out. Each rule consists of the destination, path conditions and user roles conditions. First matching rule gets executed.') . '</p>';
}
}
/**
* Implements hook_menu().
*/
function login_destination_menu() {
$items['admin/config/people/login-destination'] = array(
'title' => 'Login destinations',
'description' => 'Customize the destination that the user is redirected to after login.',
'page callback' => 'login_destination_overview',
'access arguments' => array('administer users'),
'file' => 'login_destination.admin.inc',
'weight' => 10,
);
$items['admin/config/people/login-destination/add'] = array(
'title' => 'Add login destination rule',
'page callback' => 'drupal_get_form',
'page arguments' => array('login_destination_edit_form'),
'access arguments' => array('administer users'),
'type' => MENU_LOCAL_ACTION,
'weight' => 1,
'file' => 'login_destination.admin.inc',
);
$items['admin/config/people/login-destination/edit/%login_destination'] = array(
'title' => 'Edit login destination rule',
'page callback' => 'drupal_get_form',
'page arguments' => array('login_destination_edit_form', 5),
'access arguments' => array('administer users'),
'file' => 'login_destination.admin.inc',
);
$items['admin/config/people/login-destination/delete/%login_destination'] = array(
'title' => 'Delete login destination rule',
'page callback' => 'drupal_get_form',
'page arguments' => array('login_destination_delete_form', 5),
'access arguments' => array('administer users'),
'file' => 'login_destination.admin.inc',
);
$items['admin/config/people/login-destination/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/config/people/login-destination/settings'] = array(
'title' => 'Settings',
'description' => 'Change Login Destination settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('login_destination_settings'),
'access arguments' => array('administer users'),
'type' => MENU_LOCAL_TASK,
'file' => 'login_destination.admin.inc',
'weight' => 10,
);
return $items;
}
/**
* Load a login destination.
*/
function login_destination_load($id) {
$result = db_select('login_destination', 'l')
->fields('l')
->condition('id', $id)
->execute()
->fetchAssoc();
$result['triggers'] = unserialize($result['triggers']);
if (empty($result['triggers'])) {
$result['triggers'] = array();
}
$result['roles'] = unserialize($result['roles']);
if (empty($result['roles'])) {
$result['roles'] = array();
}
return $result;
}
/**
* Implements hook_theme
*/
function login_destination_theme() {
return array(
'login_destination_destination' => array(
'variables' => array('destination' => NULL),
'file' => 'login_destination.admin.inc',
),
'login_destination_pages' => array(
'variables' => array('pages' => NULL, 'pages_type' => 0),
'file' => 'login_destination.admin.inc',
),
'login_destination_triggers' => array(
'variables' => array('items' => NULL),
'file' => 'login_destination.admin.inc',
),
'login_destination_roles' => array(
'variables' => array('items' => NULL),
'file' => 'login_destination.admin.inc',
),
);
}
/**
* Implements hook_form_alter
*/
function login_destination_form_alter(&$form, &$form_state, $form_id) {
// We redirect by using the drupal_goto_alter hook. If we simply
// call drupal_goto() it may break compability with other modules. If we set
// the $_GET['destination'] variable we will loose the possibility to redirect
// to an external URL.
// Please note the the system_goto_action() calls drupal_goto()
// More on this issue http://drupal.org/node/732542.
// If we add the $form_state['redirect'] here it will be overriden by the
// user_login_submit(). So we add a submit handler instead and will set the
// redirect later. Our submit handler will be executed after the execution
// of user_login_submit(). This is because form_submit() functions are
// appended to form before hook_form_alter() is executed.
// We will execute also after LoginToboggan's function as it replaces the
// original submit function from user module.
switch ($form_id) {
case 'user_register_form': // user register page
case 'user_login': // user login page
$form['#validate'][] = 'login_destination_validate';
break;
}
switch ($form_id) {
case 'user_profile_form': // one-time login, password reset
if (isset($_GET['pass-reset-token'])) {
// Redirect only from user_pass_reset
// You have to explicitally turn on the option to always redirect from
// the profile page. This is for constistency.
$form['#submit'][] = 'login_destination_submit';
break;
}
}
}
/**
* Helper submit function.
*/
function login_destination_validate($form, &$form_state) {
// LoginToboggan's unified page is rendered dynamically. Fix it.
switch ($form['#form_id']) {
case 'user_register_form':
if (drupal_match_path($_GET['q'], 'user')) {
$_GET['q'] = 'user/register';
}
break;
case 'user_login':
if (drupal_match_path($_GET['q'], 'user/register')) {
$_GET['q'] = 'user';
}
break;
}
// Fix the current page in case of 403 page.
if ($form['#form_id'] == 'user_login') {
if(drupal_get_http_header('Status') == '403 Forbidden') {
$_GET['current'] = $_GET['destination'];
}
}
}
/**
* Helper submit function.
*/
function login_destination_submit($form, &$form_state) {
login_destination_perform_redirect('login');
}
/**
* Implements hook_menu_link_alter
*/
function login_destination_menu_link_alter(&$item) {
// Flag a link to be altered by hook_translated_menu_link_alter().
// This is called only on menu rebuild, so we have to add this information
// manually to the database on install. Clearing caches also helps.
$paths = array('user/logout', 'user/login', 'user');
if (in_array($item['link_path'], $paths)) {
$item['options']['alter'] = TRUE;
}
}
/**
* Implements hook_translated_menu_link_alter
*/
function login_destination_translated_menu_link_alter(&$item, $map) {
global $user;
$paths = array('user/login', 'user');
// Append the current path to URL.
if ($item['link_path'] == 'user/logout' || (in_array($item['link_path'], $paths) && user_is_anonymous())) {
$item['localized_options']['query'] = array('current' => $_GET['q']);
}
}
/**
* Implements hook_page_alter
*/
function login_destination_page_alter(&$page) {
// Substitute toolbar's pre_render function to change links.
if (isset($page['page_top']['toolbar']['#pre_render'])) {
$page['page_top']['toolbar']['#pre_render'][0] = 'login_destination_toolbar_pre_render';
}
}
/**
* Helper function to change toolbar's links.
*/
function login_destination_toolbar_pre_render($toolbar) {
$toolbar = toolbar_pre_render($toolbar);
// Add current param to be able to evaluate previous page.
$toolbar['toolbar_user']['#links']['logout']['query'] = array('current' => $_GET['q']);
return $toolbar;
}
/**
* Implements hook_user_login
*/
function login_destination_user_login(&$edit, $account) {
if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset' || variable_get('login_destination_immediate_redirect', FALSE)) {
login_destination_perform_redirect('login');
}
}
/**
* Implements hook_user_insert
*/
function login_destination_user_insert(&$edit, $account, $category) {
global $user;
if (!$user->uid) {
// If the user is already logged in, it means probably that they create a
// user account and not the user registers themselves.
login_destination_perform_redirect('login');
}
}
/**
* Implements hook_user_logout
*/
function login_destination_user_logout($account) {
login_destination_perform_redirect('logout', _login_destination_get_current('logout'));
}
/**
* Implements hook_drupal_goto_alter
*/
function login_destination_drupal_goto_alter(&$path, &$options, &$http_response_code) {
// Note that this functionality cannot be backported do 6.x as Drupal 6 does
// not call drupal_alter for drupal_goto.
// This actually may be used also by templates.
if (isset($GLOBALS['destination'])) {
$destination = $GLOBALS['destination'];
// alter drupal_goto
if (is_array($destination)) {
$path = $destination[0];
$options = array();
if (count($destination) > 1) {
$options = $destination[1];
}
}
else {
$path = $destination;
}
}
}
/**
* Pass destination to drupal_goto.
*/
function login_destination_prepare_goto($destination) {
// Check if $_GET['destination'] should overwrite us
if (!isset($_GET['destination']) || !variable_get('login_destination_preserve_destination', FALSE)) {
$GLOBALS['destination'] = $destination;
}
}
/**
* Evaluate rules and perform redirect.
* This function is intended to be used by external modules.
* @param <type> $trigger
* @param <type> $current if null $_GET['q'] is used
*/
function login_destination_perform_redirect($trigger = '', $current = NULL) {
$destination = login_destination_get_destination($trigger, $current);
// Check if we redirect
if ($destination !== FALSE) {
login_destination_prepare_goto($destination);
}
}
/**
* Process all destination rules and return destination path.
* This function is intended to be used by external modules.
*/
function login_destination_get_destination($trigger = '', $current = NULL) {
// Get all the login destination rules from the database.
$result = db_select('login_destination', 'l')
//->addTag('translatable')
->fields('l', array('triggers', 'roles', 'pages_type', 'pages', 'destination_type', 'destination'))
->orderBy('weight')
->execute()
->fetchAll();
if ($current == NULL) {
$current = $_GET['q'];
}
// examine path matches
foreach ($result as $data) {
// try to match the subsequent rule
if (_login_destination_match_rule($data, $trigger, $current)) {
// Note: Matching rule with empty destination will cancel redirect.
return _login_destination_evaluate_rule($data, $trigger);
}
}
// no rule matched
return FALSE;
}
/**
* Evaluate the code with forms context.
*
* This function hides the calling function's scope from eval().
*/
function _login_destination_eval($code) {
// We could use the php_eval(), but would not be able get array return value.
// We always check for the existance of PHP Filter module for security.
return eval('?>' . $code);
}
/**
* A helper function to provide role options
*/
function _login_destination_role_options() {
// user role selection, without anonymous and authentificated user roles.
$role_options = array_map('check_plain', user_roles(TRUE));
unset($role_options[DRUPAL_AUTHENTICATED_RID]);
return $role_options;
}
/**
* Get the current path (before trigger was invoked).
*/
function _login_destination_get_current($trigger = '') {
if (isset($_GET['current'])) {
return check_plain($_GET['current']);
}
if ($trigger == 'login') {
return $_GET['q'];
}
// front by default
return '';
}
/**
* A helper function to determine whether redirection should happen.
*
* @return bool TRUE - apply redirect, FALSE - not to apply redirect.
*/
function _login_destination_match_rule($rule, $trigger = '', $current = NULL) {
global $user;
$type = $rule->pages_type;
$pages = $rule->pages;
$triggers = unserialize($rule->triggers);
if (empty($triggers))
$triggers = array();
$roles = unserialize($rule->roles);
if (empty($roles))
$roles = array();
// remove non-existent roles
$roles = array_intersect_key(_login_destination_role_options(), $roles);
// examine trigger match
if (!(empty($triggers) || array_key_exists($trigger, $triggers))) {
return FALSE;
}
// examine role matches
$roles_intersect = array_intersect_key($roles, $user->roles);
if (!empty($roles) && empty($roles_intersect)) {
return FALSE;
}
if ($type < LOGIN_DESTINATION_REDIRECT_PHP) {
$pages = drupal_strtolower($pages);
$alias = drupal_strtolower(drupal_get_path_alias($current));
$page_match = drupal_match_path($alias, $pages);
if ($alias != $current) {
$page_match = $page_match || drupal_match_path($current, $pages);
}
$page_match = !($type xor $page_match);
}
elseif (module_exists('php')) {
// Do not execute php if the PHP Filter is off.
$page_match = _login_destination_eval($pages);
}
else {
$page_match = FALSE;
}
return $page_match;
}
/**
* A helper function to evaluate destination path.
*/
function _login_destination_evaluate_rule($rule, $trigger = '') {
if ($rule->destination_type == LOGIN_DESTINATION_STATIC) {
// take only 1st line
if (preg_match("!^(.*?)$!", $rule->destination, $matches) === 1 ) {
$path = $matches[1];
if (empty($path)) {
return FALSE;
}
// Current path
elseif ($path == '<current>') {
return _login_destination_get_current($trigger);
}
// External URL
elseif (strpos($path, '://') !== FALSE) {
return $path;
}
// Internal URL
else {
$destination = drupal_parse_url($path);
$options = array();
$options['query'] = $destination['query'];
$options['fragment'] = $destination['fragment'];
// drupal_goto cares about <front>
return array($destination['path'], $options);
}
}
else {
// error - multiple lines
return '';
}
}
elseif (module_exists('php')) {
// We cannot use the php_eval because we expect array here, but for the
// matter of consistent UI we don't do it with the PHP Filter module off.
$result = _login_destination_eval($rule->destination);
if (empty($result)) {
return FALSE;
}
return $result;
}
else {
// PHP code and PHP filter disabled.
return FALSE;
}
}

View File

@@ -0,0 +1,62 @@
*******************************************************
INSTALL.txt for logintoboggan.module for Drupal
*******************************************************
INSTALLATION:
Place entire loggintoboggan module folder into
(a) your sites/all/modules directory
(b) your sites/[my site]/modules directory.
Enable the module at Administration » Modules
Configure logintoboggan settings at
Administration » Configuration » System » LoginToboggan
The module changes the functionality of the login block AND provides a new
LoginToboggan logged in block'.
Configure each block at Administration » Structure » Blocks as follows...
1. Configure the 'User login' block for LoginToboggan functionality:
Change title if required; using <none> can make for a very neat login system,
when combined with the javascript functionality: clicking upon "Login/register"
reveals the login form in sliding fashion. To select this functionality, select
'Collapsible form' under "Block type". Selecting 'Link' under "Block type"
sends user to a login form, returning them to original page after successful
login.
2. Configure 'LoginToboggan logged in block'
Tip: by leaving the title blank, the 'LoginToboggan logged in block' is slim
and neat.
Done!
CAVEATS:
1. Use the 'Delete unvalidated users after' feature with extreme caution!
This feature can be handy, but if misconfigured can cause unexpected damage
to your user data -- specifically deleting users! Two things to guard
against:
a. Be very careful when editing the 'Non-authenticated role' setting.
If you set it to anything other than the 'authenticated user' role,
LoginToboggan will happily start deleting any users you have in that
role that were created prior to the purge interval. If you want to
avoid problems, it's best to never change that setting after you've
initially set it up.
b. LoginToboggan has mechanisms in place that prevent a user from being
re-added to the Non-authenticated role after a user has been validated.
Note that these protections are only present in core's interface -- if
you have another module enabled which does any role manipulation
(either via the user interface or programatically), you must find your
own way to ensure that it doesn't add any users back into the
Non-authenticated role.
Also note that the feature is only enabled if the 'Set password' option is
also enabled.

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,40 @@
*******************************************************
README.txt for logintoboggan.module for Drupal
*******************************************************
Co-developed by Jeff Robbins (jjeff) and Chad Phillips (hunmonk) with several
features added by Raven Brooks (rbrooks00).
The Login Toboggan module improves the Drupal login system in an external
module by offering the following features:
1. Allow users to login using either their username OR their email address.
2. Allow users to login immediately.
3. Provide a login form on Access Denied pages for non-logged-in
(anonymous) users.
4. The module provides two login block options: One uses JavaScript to
display the form within the block immediately upon clicking "log in".
The other brings the user to a separate page, but returns the user to
their original page upon login.
5. Customize the registration form with two e-mail fields to ensure
accuracy.
6. Optionally redirect the user to a specific page when using the
'immediate login' feature.
7. Optionally redirect the user to a specific page upon validation of their
e-mail address.
8. Optionally display a user message indicating a successful login.
9. Optionally combine both the login and registration form on one page.
10. Optionally display a 'Request new password' link on the user login form.
11. Optionally have unvalidated users purged from the system at a pre-defined
interval
(please read the CAVEATS section of INSTALL.txt for important information
on configuringthis feature!).
Users who choose their own password can be automatically assigned to a selected
'non-authenticated' role. This role could have more permissions than anonymous
but less than authenticated - thus preventing spoof accounts and spammers. The
user will only be removed from the non-authenticated role and granted
authenticated permissions when they verify their account via a special email
link, or when an administrator removes them from the non-authenticated role.

View File

@@ -0,0 +1,13 @@
*******************************************************
UPGRADING.txt for logintoboggan.module for Drupal
*******************************************************
6.x to 7.x:
1. Core changed the way it identifies blocks internally. The update functions
should handle the transition.
2. A new option for a unified login/register page has been added. See the
'Present a unified login/registration page' setting in the 'Log in' section
of LoginToboggan settings.

View File

@@ -0,0 +1,11 @@
********************************************************************************
README.txt for logintoboggan_content_access_integration.module for Drupal
********************************************************************************
Developed by Geoff Appleby (gapple - http://drupal.org/user/490940).
The Login Toboggan / Content Access Integration module provides information to
Content Access module so that it is able to handle Non-validated users correctly
when optimizing permissions.
If you do not make use of the Non-validated user role option this module is
not required, but will not cause any ill-effects.

View File

@@ -0,0 +1,14 @@
name = "LoginToboggan Content Access Integration"
description = "Integrates LoginToboggan with Content Access module, so that Non-validated users are handled correctly"
core = "7.x"
dependencies[] = logintoboggan
dependencies[] = content_access
; Information added by drupal.org packaging script on 2013-02-04
version = "7.x-1.3+6-dev"
core = "7.x"
project = "logintoboggan"
datestamp = "1359940268"

View File

@@ -0,0 +1,60 @@
<?php
/**
* Implementation of hook_enable().
*
* Check if the LoginToboggan 'Non-validated' role is used, and node access
* permissions may need to be rebuilt.
*
* @todo Automatically rebuild records only for content types that will need it.
*/
function logintoboggan_content_access_integration_enable(){
if (logintoboggan_validating_id() == DRUPAL_AUTHENTICATED_RID) {
return;
}
$rebuild = array();
foreach (content_access_get_settings() as $permission => $content_types) {
foreach ($content_types as $content_type => $roles) {
if (!is_array($roles)){
// This is not actually a node access permission (e.g. per_node).
continue;
}
// If permissions were set for Anonymous and Authenticated but not
// Non-authenticated, Non-Authenticated was erroneously given access, and
// will be denied on next rebuild.
$roles_set = array_diff(array(DRUPAL_AUTHENTICATED_RID, DRUPAL_ANONYMOUS_RID), $roles);
if (empty($roles_set) && !in_array(logintoboggan_validating_id(), $roles)) {
drupal_set_message(
t(
'The "@content_type" content type has the "@permission" permission set for Anonymous and Authenticated roles, but not Non-Authenticated. ' .
'You should grant this permission to the Non-Authenticated role if all users should continue to have access. ',
array( '@content_type' => $content_type, '@permission' => $permission)
) .
l(t('Go to the Access Control Settings page.'), 'admin/content/node-type/' . $content_type . '/access'),
'warning'
);
}
if (in_array($content_type, $rebuild)) {
// We already checked this content type for another permission.
continue;
}
// If permissions were set for Authenticated and Non-authenticated roles,
// the Non-authenticated role would not have been added to the
// node access records. (Except if Anonymous is set too, where in both
// cases the permissions should be optimized to 'all').
$roles_set = array_diff(array(DRUPAL_AUTHENTICATED_RID, logintoboggan_validating_id()), $roles);
if (empty($roles_set) && !in_array(DRUPAL_ANONYMOUS_RID, $roles)) {
$rebuild[] = $content_type;
}
}
}
if ($rebuild) {
node_access_needs_rebuild(TRUE);
}
}

View File

@@ -0,0 +1,10 @@
<?php
/**
* Implementation of hook_content_access_special_roles().
*/
function logintoboggan_content_access_integration_content_access_special_roles(){
if (logintoboggan_validating_id() != DRUPAL_AUTHENTICATED_RID) {
return array(logintoboggan_validating_id());
}
}

View File

@@ -0,0 +1,25 @@
Introduction
===========
It is a very simple module which provides an integration between widely
used modules "LoginToboggan" and "Rules".
Installation
============
1. Enable the module in the module listing page.
2. In LoginToboggan settings check "Set password" option.
3. Thats it!!
For best results, you may want to uncheck the "Immediate login" option on
LoginToboggan settings. This is just for cosmetic reasons, as in most use
cases you might want users to click on the verification link first before
actually letting them in the site.
Usage
=====
Create a rule. You will now see "When the user account is validated"
event under LoginToboggan category.
In this event, the validated user's account information is available.
Use this event to implement various automation tasks.
Currently maintained by Sudhir (porwal.lucky@gmail.com)

View File

@@ -0,0 +1,14 @@
name = "LoginToboggan Rules Integration"
description = "Integrates LoginToboggan with Rules module"
core = "7.x"
dependencies[] = logintoboggan
dependencies[] = rules
; Information added by drupal.org packaging script on 2013-02-04
version = "7.x-1.3+6-dev"
core = "7.x"
project = "logintoboggan"
datestamp = "1359940268"

View File

@@ -0,0 +1,22 @@
<?php
/**
* @file
* Logintoboggan Rules module
*
* This module provides integration of LoginToboggan module with Rules module
*/
/**
* Implement hook_user()
*
*/
function logintoboggan_rules_user_update(&$edit, $account) {
if (!empty($account->logintoboggan_email_validated)) {
rules_invoke_event('logintoboggan_validated', $account);
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* Implement hook_rules_event_info().
* @ingroup rules
*/
function logintoboggan_rules_rules_event_info() {
return array(
'logintoboggan_validated' => array(
'label' => t("When the user account is validated."),
'group' => 'LoginToboggan',
'variables' => array(
'account' => array(
'type' => 'user',
'label' => t("The validated user's account"),
),
),
'group' => t('User'),
),
);
}

View File

@@ -0,0 +1,13 @@
name = "LoginToboggan Variable Integration"
description = "Integrates LoginToboggan with Variable module"
core = "7.x"
dependencies[] = logintoboggan
dependencies[] = variable
; Information added by drupal.org packaging script on 2013-02-04
version = "7.x-1.3+6-dev"
core = "7.x"
project = "logintoboggan"
datestamp = "1359940268"

View File

@@ -0,0 +1,107 @@
<?php
/**
* Implements hook_variable_info().
*/
function logintoboggan_variable_variable_info($options) {
$variables = array(
'logintoboggan_confirm_email_at_registration' => array(
'title' => t('Use two e-mail fields on registration form', array(), $options),
'description' => t('User will have to type the same e-mail address into both fields. This helps to confirm that they\'ve typed the correct address.', array(), $options),
'default' => 0,
'type' => 'boolean',
'group' => 'user_settings',
'localize' => FALSE,
),
'logintoboggan_immediate_login_on_register' => array(
'title' => t('Immediate login', array(), $options),
'description' => t('If set, the user will be logged in immediately after registering.', array(), $options),
'default' => TRUE,
'type' => 'boolean',
'group' => 'user_settings',
'localize' => FALSE,
),
'logintoboggan_login_successful_message' => array(
'title' => t('Display login successful message', array(), $options),
'description' => t('If enabled, users will receive a \'Log in successful\' message upon login.', array(), $options),
'default' => 0,
'type' => 'boolean',
'group' => 'user_settings',
'localize' => FALSE,
),
'logintoboggan_login_with_email' => array(
'title' => t('Allow users to login using their e-mail address', array(), $options),
'description' => t('Users will be able to enter EITHER their username OR their e-mail address to log in.', array(), $options),
'default' => 0,
'type' => 'boolean',
'group' => 'user_settings',
'localize' => FALSE,
),
'logintoboggan_minimum_password_length' => array(
'title' => t('Minimum password length', array(), $options),
'description' => t('The minimum number of password characters required on the registration form.', array(), $options),
'default' => 0,
'type' => 'number',
'group' => 'user_settings',
'localize' => FALSE,
),
'logintoboggan_override_destination_parameter' => array(
'title' => t('Override destination parameter', array(), $options),
'description' => t('Normally, when a Drupal redirect is performed, priority is given to the \'destination\' parameter from the originating URL. With this setting enabled, LoginToboggan will attempt to override this behavior.', array(), $options),
'default' => 1,
'type' => 'boolean',
'group' => 'user_settings',
'localize' => FALSE,
),
'logintoboggan_pre_auth_role' => array(
'title' => t('Non-authenticated role', array(), $options),
'description' => t('The role that is assigned to users that have supplied a password during the registration process but have not yet clicked on the link in their welcome email.', array(), $options),
'default' => DRUPAL_AUTHENTICATED_RID,
'type' => 'number',
'group' => 'user_settings',
'localize' => FALSE,
),
'logintoboggan_purge_unvalidated_user_interval' => array(
'title' => t('Unvalidated user purge interval', array(), $options),
'description' => t('The time interval in seconds after which users will be deleted who have registered but not yet clicked on the link in their welcome email.', array(), $options),
'default' => 0,
'type' => 'number',
'group' => 'user_settings',
'localize' => FALSE,
),
'logintoboggan_redirect_on_confirm' => array(
'title' => t('Redirect path on confirmation', array(), $options),
'description' => t('The path the user will be redirected to after confiming their account.', array(), $options),
'default' => '',
'type' => 'url',
'group' => 'user_settings',
'localize' => TRUE,
),
'logintoboggan_redirect_on_register' => array(
'title' => t('Redirect path on registration', array(), $options),
'description' => t('The path the user will be redirected to after registering.', array(), $options),
'default' => '',
'type' => 'url',
'group' => 'user_settings',
'localize' => TRUE,
),
'logintoboggan_unified_login' => array(
'title' => t('Present a unified login/registration page', array(), $options),
'description' => t('Use one page for both login and registration instead of Drupal\'s tabbed login/registration/password pages.', array(), $options),
'default' => '0',
'type' => 'boolean',
'group' => 'user_settings',
'localize' => FALSE,
),
'logintoboggan_user_email_verification' => array(
'title' => t('Supply password when registering', array(), $options),
'description' => t('Allows users to type in their password in the registration form.', array(), $options),
'default' => !variable_get('user_email_verification', TRUE) ? 1 : 0,
'type' => 'boolean',
'group' => 'user_settings',
'localize' => FALSE,
),
);
return $variables;
}

View File

@@ -0,0 +1,16 @@
div.toboggan-login-link-container {
text-align: right;
}
div.toboggan-block-message {
text-align: right;
}
div.user-login-block {
text-align: right;
}
div.user-login-block a {
text-align: right;
}

View File

@@ -0,0 +1,211 @@
<?php
/**
* @file
* Administration functions for LoginToboggan module.
*/
function logintoboggan_main_settings() {
$_disabled = t('Disabled');
$_enabled = t('Enabled');
$form['login'] = array(
'#type' => 'fieldset',
'#title' => t('Log in'),
);
$form['login']['logintoboggan_login_with_email'] = array(
'#type' => 'radios',
'#title' => t('Allow users to login using their e-mail address'),
'#default_value' => variable_get('logintoboggan_login_with_email', 0),
'#options' => array($_disabled, $_enabled),
'#description' => t('Users will be able to enter EITHER their username OR their e-mail address to log in.'),
);
$form['login']['logintoboggan_unified_login'] = array(
'#type' => 'checkbox',
'#title' => t('Present a unified login/registration page'),
'#default_value' => variable_get('logintoboggan_unified_login', 0),
'#description' => t("Use one page for both login and registration instead of Drupal's tabbed login/registration/password pages."),
);
$form['registration'] = array(
'#type' => 'fieldset',
'#title' => t('Registration'),
);
$form['registration']['logintoboggan_confirm_email_at_registration'] = array(
'#type' => 'radios',
'#title' => t('Use two e-mail fields on registration form'),
'#default_value' => variable_get('logintoboggan_confirm_email_at_registration', 0),
'#options' => array($_disabled, $_enabled),
'#description' => t('User will have to type the same e-mail address into both fields. This helps to confirm that they\'ve typed the correct address.'),
);
if (module_exists('help')) {
$help_text = t(" More help in writing the e-mail message can be found at <a href=\"!help\">LoginToboggan help</a>.", array('!help' => url('admin/help/logintoboggan')));
}
else {
$help_text = '';
}
$form['registration']['logintoboggan_user_email_verification'] = array(
'#type' => 'checkbox',
'#title' => t('Set password'),
'#default_value' => !variable_get('user_email_verification', TRUE) ? 1 : 0,
'#description' => t("This will allow users to choose their initial password when registering (note that this setting is a mirror of the <a href=\"!settings\">Require e-mail verification when a visitor creates an account</a> setting, and is merely here for convenience). If selected, users will be assigned to the role below. They will not be assigned to the 'authenticated user' role until they confirm their e-mail address by following the link in their registration e-mail. It is HIGHLY recommended that you set up a 'pre-authorized' role with limited permissions for this purpose. <br />NOTE: If you enable this feature, you should edit the <a href=\"!settings\">Welcome (no approval required)</a> text.", array('!settings' => url('admin/config/people/accounts'))) . $help_text,
);
// Grab the roles that can be used for pre-auth. Remove the anon role, as it's not a valid choice.
$roles = user_roles(TRUE);
$form ['registration']['logintoboggan_pre_auth_role'] = array(
'#type' => 'select',
'#title' => t('Non-authenticated role'),
'#options' => $roles,
'#default_value' => variable_get('logintoboggan_pre_auth_role', DRUPAL_AUTHENTICATED_RID),
'#description' => t('If "Set password" is selected, users will be able to login before their e-mail address has been authenticated. Therefore, you must choose a role for new non-authenticated users -- you may wish to <a href="!url">add a new role</a> for this purpose. Users will be removed from this role and assigned to the "authenticated user" role once they follow the link in their welcome e-mail. <strong>WARNING: changing this setting after initial site setup can cause undesirable results, including unintended deletion of users -- change with extreme caution!</strong>', array('!url' => url('admin/people/permissions/roles'))),
);
$purge_options = array(
0 => t('Never delete'),
86400 => t('1 Day'),
172800 => t('2 Days'),
259200 => t('3 Days'),
345600 => t('4 Days'),
432000 => t('5 Days'),
518400 => t('6 Days'),
604800 => t('1 Week'),
1209600 => t('2 Weeks'),
2592000 => t('1 Month'),
7776000 => t('3 Months'),
15379200 => t('6 Months'),
30758400 => t('1 Year'),
);
$form['registration']['logintoboggan_purge_unvalidated_user_interval'] = array(
'#type' => 'select',
'#title' => t('Delete unvalidated users after'),
'#options' => $purge_options,
'#default_value' => variable_get('logintoboggan_purge_unvalidated_user_interval', 0),
'#description' => t("If enabled, users that are still in the 'Non-authenticated role' set above will be deleted automatically from the system, if the set time interval since their initial account creation has passed. This can be used to automatically purge spambot registrations. Note: this requires cron, and also requires that the 'Set password' option above is enabled. <strong>WARNING: changing this setting after initial site setup can cause undesirable results, including unintended deletion of users -- change with extreme caution! (please read the CAVEATS section of INSTALL.txt for important information on configuring this feature)</strong>")
);
$form['registration']['logintoboggan_immediate_login_on_register'] = array(
'#type' => 'checkbox',
'#title' => t('Immediate login'),
'#default_value' => variable_get('logintoboggan_immediate_login_on_register', TRUE),
'#description' => t("If set, the user will be logged in immediately after registering. Note this only applies if the 'Set password' option above is enabled."),
);
$form['registration']['redirect'] = array(
'#type' => 'fieldset',
'#title' => t('Redirections'),
'#collapsible' => true,
'#collapsed' => false,
);
$form['registration']['redirect']['logintoboggan_redirect_on_register'] = array(
'#type' => 'textfield',
'#title' => t('Redirect path on registration'),
'#default_value' => variable_get('logintoboggan_redirect_on_register', ''),
'#description' => t('Normally, after a user registers a new account, they will be taken to the front page, or to their user page if you specify <cite>Immediate login</cite> above. Leave this setting blank if you wish to keep the default behavior. If you wish the user to go to a page of your choosing, then enter the path for it here. For instance, you may redirect them to a static page such as <cite>node/35</cite>, or to the <cite>&lt;front&gt;</cite> page. You may also use <em>%uid</em> as a variable, and the user\'s user ID will be substituted in the path.'),
);
$form['registration']['redirect']['logintoboggan_redirect_on_confirm'] = array(
'#type' => 'textfield',
'#title' => t('Redirect path on confirmation'),
'#default_value' => variable_get('logintoboggan_redirect_on_confirm', ''),
'#description' => t('Normally, after a user confirms their new account, they will be taken to their user page. Leave this setting blank if you wish to keep the default behavior. If you wish the user to go to a page of your choosing, then enter the path for it here. For instance, you may redirect them to a static page such as <cite>node/35</cite>, or to the <cite>&lt;front&gt;</cite> page. You may also use <em>%uid</em> as a variable, and the user\'s user ID will be substituted in the path. In the case where users are not creating their own passwords, it is suggested to use <cite>user/%uid/edit</cite> here, so the user may set their password immediately after validating their account.'),
);
$form['registration']['redirect']['logintoboggan_override_destination_parameter'] = array(
'#type' => 'checkbox',
'#title' => t('Override destination parameter'),
'#default_value' => variable_get('logintoboggan_override_destination_parameter', 1),
'#description' => t("Normally, when a Drupal redirect is performed, priority is given to the 'destination' parameter from the originating URL. With this setting enabled, LoginToboggan will attempt to override this behavior with any values set above."),
);
$form['other'] = array('#type' => 'fieldset',
'#title' => t('Other'),
'#tree' => FALSE,
);
$site403 = variable_get('site_403', '');
if ($site403 == '') {
$disabled = $default = '0';
}
elseif ($site403 == 'toboggan/denied') {
$disabled = '0';
$default = 'toboggan/denied';
}
else {
$disabled = $default = $site403;
}
$options = array($disabled => $_disabled, 'toboggan/denied' => $_enabled);
$form['other']['logintoboggan_site_403'] = array(
'#type' => 'radios',
'#title' => t('Present login form on access denied (403)'),
'#options' => $options,
'#default_value' => $default,
'#description' => t('Anonymous users will be presented with a login form along with an access denied message.')
);
$form['other']['logintoboggan_login_successful_message'] = array(
'#type' => 'radios',
'#title' => t('Display login successful message'),
'#options' => array($_disabled, $_enabled),
'#default_value' => variable_get('logintoboggan_login_successful_message', 0),
'#description' => t('If enabled, users will receive a \'Log in successful\' message upon login.')
);
$min_pass_options = array(t('None'));
for ($i = 2; $i < 30; $i++) {
$min_pass_options[$i] = $i;
}
$form['other']['logintoboggan_minimum_password_length'] = array(
'#type' => 'select',
'#title' => t('Minimum password length'),
'#options' => $min_pass_options,
'#default_value' => variable_get('logintoboggan_minimum_password_length', 0),
'#description' => t('LoginToboggan automatically performs basic password validation for illegal characters. If you would additionally like to have a minimum password length requirement, select the length here, or set to \'None\' for no password length validation.')
);
return system_settings_form($form);
}
/**
* Implement hook_form_logintoboggan_main_settings_alter().
*
* @ingroup logintoboggan_core
*/
function logintoboggan_form_logintoboggan_main_settings_alter(&$form, &$form_state) {
// Ensure a valid submit array.
$form['#submit'] = is_array($form['#submit']) ? $form['#submit'] : array();
// Make this submit handler run first.
array_unshift($form['#submit'], 'logintoboggan_main_settings_submit');
}
/**
* Takes custom settings on the main settings page, transforms them into the
* appropriate core setting, and cleans up the custom values.
*/
function logintoboggan_main_settings_submit($form, &$form_state) {
// User email verification setting.
$user_email_verification = $form_state['values']['logintoboggan_user_email_verification'] ? FALSE : TRUE;
variable_set('user_email_verification', $user_email_verification);
unset($form_state['values']['logintoboggan_user_email_verification']);
// Site 403 setting.
$site_403 = $form_state['values']['logintoboggan_site_403'] == '0' ? '' : $form_state['values']['logintoboggan_site_403'];
variable_set('site_403', $site_403);
unset($form_state['values']['logintoboggan_site_403']);
// If the unified login setting has been changed, we need to rebuild the
// menu cache.
if ($form['login']['logintoboggan_unified_login']['#default_value'] != $form['login']['logintoboggan_unified_login']['#value']) {
drupal_set_message(t('Unified login setting was changed, menus have been rebuilt.'));
// For some reason, a regular menu_rebuild() still leaves the old callbacks
// cached -- doing it in a shutdown function seems to correct that issue.
drupal_register_shutdown_function('menu_rebuild');
}
}

View File

@@ -0,0 +1,63 @@
div.toboggan-container {
text-align: center;
}
div.toboggan-login-link-container {
text-align: left;
}
div.toboggan-login-link-container a {
text-decoration: none;
}
div.toboggan-block-message {
text-align: left;
}
div.user-login-block {
text-align: left;
}
div.user-login-block a {
text-align: left;
}
/* Unified login */
.toboggan-unified #login-message {
text-align: center;
font-size: 2em;
line-height: 1.2;
}
.toboggan-unified #login-links {
text-align: center;
font-size: 1.5em;
line-height: 2.7;
}
.toboggan-unified #login-links a {
padding: .5em;
border: 1px #666 solid;
background-color: #EEE;
}
.toboggan-unified #login-links a:hover {
background-color: #DDD;
}
.toboggan-unified #login-links a.lt-active,
.toboggan-unified #login-links a.lt-active:hover {
background-color: #FFF19A;
border: 2px #333 solid;
}
.toboggan-unified.login #register-form {
display: none;
}
.toboggan-unified.register #login-form {
display: none;
}

View File

@@ -0,0 +1,15 @@
name = "LoginToboggan"
description = "Improves Drupal's login system."
core = "7.x"
configure = admin/config/system/logintoboggan
stylesheets[all][] = logintoboggan.css
; Information added by drupal.org packaging script on 2013-02-04
version = "7.x-1.3+6-dev"
core = "7.x"
project = "logintoboggan"
datestamp = "1359940268"

Some files were not shown because too many files have changed in this diff Show More