non security modules update

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-20 16:32:07 +02:00
parent 6a8d30db08
commit 37fbabab56
466 changed files with 32690 additions and 9652 deletions

View File

@@ -34,11 +34,8 @@ $conf['locale_custom_strings_en'][''] = array(
);
BUGS, FEATURES, QUESTIONS
=========================
Post any bugs, features or questions to the issue queue:
http://drupal.org/project/issues/email_registration

View File

@@ -2,7 +2,7 @@
/**
* @file
* Documentation for email_registration API.
* Documentation for email_registration module API.
*/
/**
@@ -17,16 +17,19 @@
* to generate a username (return a string to be used as the username, NULL
* to have email_registration generate it).
*
* @param $edit
* @param array $edit
* The array of form values submitted by the user.
* @param $account
* @param object $account
* The user object on which the operation is being performed.
*
* @return
* @return string
* A string defining a generated username.
*/
function hook_email_registration_name($edit, $account) {
return 'u' . $account->uid;
// Your hook implementation should ensure that the resulting string
// works as a username. You can use email_registration_cleanup_username($name)
// to clean up the name.
return email_registration_cleanup_username('u' . $account->uid);
}
/**

View File

@@ -3,9 +3,9 @@ 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"
; Information added by Drupal.org packaging script on 2014-04-23
version = "7.x-1.2"
core = "7.x"
project = "email_registration"
datestamp = "1358554303"
datestamp = "1398265775"

View File

@@ -24,6 +24,8 @@ function email_registration_user_insert(&$edit, &$account, $category = NULL) {
if (empty($names)) {
// Strip off everything after the @ sign.
$new_name = preg_replace('/@.*$/', '', $edit['mail']);
// Clean up the username.
$new_name = email_registration_cleanup_username($new_name, $account->uid);
}
else {
// One would expect a single implementation of the hook, but if there
@@ -42,46 +44,30 @@ function email_registration_user_insert(&$edit, &$account, $category = NULL) {
$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.
* Given a starting point returns a legal, unique Drupal username.
*
* @param $name
* A name from which to base the final user name. May contain illegal characters; these will be stripped.
* 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 $uid
* (optional) Uid to ignore when searching for unique user (e.g. if we update the username after the
* {users} row is inserted)
* @param string $name
* A name from which to base the final user name. May contain illegal
* characters; these will be stripped.
* @param int $uid
* (optional) Uid to ignore when searching for unique user
* (e.g. if we update the username after the {users} row is inserted)
*
* @return
* @return string
* A unique user name based on $name.
*
* @see user_validate_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;
function email_registration_unique_username($name, $uid) {
// Iterate until we find a unique name.
$i = 0;
do {
@@ -93,12 +79,47 @@ function email_registration_unique_username($name, $uid = 0) {
return $new_name;
}
/**
* Function to clean up username.
*
* e.g.
* Replace two or more spaces with a single underscore
* Strip illegal characters.
*
* @param string $name
* The username to be cleaned up.
*
* @return string
* Cleaned up username.
*/
function email_registration_cleanup_username($name, $uid = NULL) {
// 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;
if (!empty($uid)) {
// Put uid on the end of the name.
$name = $name . '_' . $uid;
}
// Truncate to a reasonable size.
$name = (drupal_strlen($name) > (USERNAME_MAX_LENGTH - 10)) ? drupal_substr($name, 0, USERNAME_MAX_LENGTH - 11) : $name;
return $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']['#type'] = 'hidden';
$form['account']['name']['#value'] = 'email_registration_' . user_password();
$form['account']['mail']['#title'] = t('E-mail');
}
@@ -108,7 +129,6 @@ function email_registration_form_user_register_form_alter(&$form, &$form_state)
*/
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.');
}
/**
@@ -131,11 +151,12 @@ function email_registration_form_user_login_block_alter(&$form, &$form_state) {
/**
* 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.
// Keep the email value in form state for further 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;
@@ -146,6 +167,6 @@ function email_registration_user_login_validate($form, &$form_state) {
/**
* Implements hook_form_FORM_ID_alter().
*/
function email_registration_form_user_profile_form_alter($form, &$form_state) {
function email_registration_form_user_profile_form_alter(&$form, &$form_state) {
$form['account']['name']['#title'] = t('Display name');
}

View File

@@ -2,7 +2,7 @@
/**
* @file
* email registration simpletest
* Contains EmailRegistrationTestCase.
*/
class EmailRegistrationTestCase extends DrupalWebTestCase {
@@ -20,7 +20,7 @@ class EmailRegistrationTestCase extends DrupalWebTestCase {
/**
* Implementation of setUp().
*/
function setUp() {
public function setUp() {
parent::setUp('email_registration');
// Configure to allow set password.
@@ -30,7 +30,7 @@ class EmailRegistrationTestCase extends DrupalWebTestCase {
/**
* Test various behaviors for anonymous users.
*/
function testRegistration() {
public function testRegistration() {
variable_set('user_register', USER_REGISTER_VISITORS);
// Try to register a user.
$name = $this->randomName();
@@ -49,8 +49,12 @@ class EmailRegistrationTestCase extends DrupalWebTestCase {
);
$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.'));
// Get the uid.
$accounts = user_load_multiple(array(), array('mail' => $name . '@example.com'));
$new_user = reset($accounts);
// Confirm the user was created and logged in with expected username.
$this->assertRaw('<title>' . $name . '_' . $new_user->uid . ' | Drupal</title>', t('User properly created, logged in.'));
// Now try the immediate login.
$this->drupalLogout();
@@ -64,6 +68,6 @@ class EmailRegistrationTestCase extends DrupalWebTestCase {
);
$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,4 @@
*.patch
*.diff
.idea/
.idea/*

View File

@@ -8,15 +8,15 @@
/**
* Generates the settings form for the FAQ module.
*
* @param $op
* @param string $op
* Default value is NULL; determines what are the permissions of the current
* user on the FAQ.
* @return
*
* @return string
* 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;
@@ -25,7 +25,7 @@ function faq_settings_page($op = NULL) {
/**
* Define a form to edit the page header and descriptive text.
*
* @return
* @return array
* The general settings form code stored in the $form variable, before
* converted to HTML.
*/
@@ -48,7 +48,12 @@ function faq_general_settings_form($form) {
$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'))),
'#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),
);
@@ -58,7 +63,7 @@ function faq_general_settings_form($form) {
/**
* Define the elements for the FAQ Settings page - Questions tab.
*
* @return
* @return array
* The form code inside the $form array.
*/
function faq_questions_settings_form($form, &$form_state) {
@@ -259,7 +264,7 @@ function faq_questions_settings_form($form, &$form_state) {
/**
* Define the elements for the FAQ Settings page - categories tab.
*
* @return
* @return array
* The form code inside the $form array.
*/
function faq_categories_settings_form($form, &$form_state) {
@@ -459,9 +464,10 @@ function faq_categories_settings_form_submit($form, &$form_state) {
/**
* Define the elements for the FAQ Settings page - order tab.
*
* @param $form_state
* @param array $form_state
* Store the submitted form values.
* @return
*
* @return array
* The form code, before being converted to HTML format.
*/
function faq_order_settings_form($form, $form_state, $category = NULL) {
@@ -541,7 +547,7 @@ function faq_order_settings_form($form, $form_state, $category = NULL) {
// $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));
// $query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight));
if (empty($category)) {
$category = 0;
@@ -594,16 +600,16 @@ function faq_order_settings_form($form, $form_state, $category = NULL) {
);
}
return $form;
}
/**
* Function set the rebuild of the form in the FAQ Settings - Weight tab.
*
* @param $form
* @param array $form
* Array, containing the form structure.
* @param &$form_state
*
* @param array &$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.
@@ -615,9 +621,10 @@ function faq_order_settings_choose_cat_form_submit($form, &$form_state) {
/**
* Save the options set by the user in the FAQ Settings - Weight tab.
*
* @param $form
* @param array $form
* Array, containing the form structure.
* @param &$form_state
*
* @param array &$form_state
* $form_state['values'] stores the submitted values from the form.
*/
function faq_order_settings_reorder_form_submit($form, &$form_state) {
@@ -663,4 +670,3 @@ function faq_order_settings_reorder_form_submit($form, &$form_state) {
drupal_set_message(t('Configuration has been updated.'));
}
}

View File

@@ -20,11 +20,11 @@ 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
configure = admin/config/content/faq
; Information added by drupal.org packaging script on 2013-09-30
version = "7.x-1.0-rc2+8-dev"
; Information added by Drupal.org packaging script on 2015-03-27
version = "7.x-1.0"
core = "7.x"
project = "faq"
datestamp = "1380577865"
datestamp = "1427455703"

View File

@@ -8,7 +8,7 @@
/**
* Define the 'faq_weights' and 'faq_questions' table structures.
*
* @return
* @return array
* The schema which contains the structure for the faq module's tables.
*/
function faq_schema() {
@@ -73,7 +73,6 @@ function faq_schema() {
'primary key' => array('nid', 'vid'),
);
return $schema;
}
@@ -85,6 +84,7 @@ function faq_schema() {
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();
@@ -93,7 +93,13 @@ function faq_install() {
// 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);
// Add the detailed question field.
_faq_add_custom_fields();
// Shift all fields below the body field one down and put detailed question field where the body field was.
_faq_shift_fields_down();
}
/**
@@ -136,12 +142,38 @@ function faq_uninstall() {
// Block settings.
variable_del('faq_block_recent_faq_count');
variable_del('faq_block_random_faq_count');
// Custom breadcrumbs control
// Custom breadcrumbs control.
variable_del('faq_custom_breadcrumbs');
// Deprecated.
variable_del('faq_more_link');
// Remove content type and the fields created.
$faq_type = 'faq';
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(':type' => $faq_type));
$nodeids = array();
foreach ($result as $row) {
$nodeids[] = $row->nid;
}
node_delete_multiple($nodeids);
_faq_delete_custom_fields();
node_type_delete($faq_type);
field_purge_batch(500);
// Remove content type and the fields created.
$faq_type = 'faq';
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(':type' => $faq_type));
$nodeids = array();
foreach ($result as $row) {
$nodeids[] = $row->nid;
}
node_delete_multiple($nodeids);
_faq_delete_custom_fields();
node_type_delete($faq_type);
field_purge_batch(500);
// Clear the cache tables.
cache_clear_all('*', 'cache', TRUE);
cache_clear_all('*', 'cache_filter', TRUE);
@@ -237,7 +269,13 @@ function faq_update_2() {
*/
function faq_update_6003() {
$ret = array();
db_add_field('faq_questions', 'detailed_question', array('type' => 'text', 'size' => 'normal', 'not null' => TRUE));
db_add_field('faq_questions', 'detailed_question',
array(
'type' => 'text',
'size' => 'normal',
'not null' => TRUE,
)
);
db_update('faq_questions')
->expression('detailed_question', 'question')
@@ -250,7 +288,13 @@ function faq_update_6003() {
* 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));
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.');
}
@@ -264,3 +308,288 @@ function faq_update_7001() {
return t('Deleted obsolete variables.');
}
/**
* Convert old-style detailed questions to new fields.
*/
function faq_update_7002(&$sandbox) {
// Number of nodes to update each pass.
define('BATCH_SIZE_7002', '5');
// Do this the first time.
if (!isset($sandbox['progress'])) {
// Initialize sandbox structure for multi-pass update.
$sandbox['progress'] = 0;
$sandbox['current_idx'] = 0;
// Get faq nodes and run the query as user 1.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'faq')
->addMetaData('account', user_load(1));
$result = $query->execute();
if (isset($result['node'])) {
$sandbox['faq_items_nids'] = array_keys($result['node']);
$sandbox['max'] = count($sandbox['faq_items_nids']);
}
else {
$sandbox['faq_items_nids'] = array();
$sandbox['max'] = 0;
}
// Add the detailed question field.
_faq_add_custom_fields();
// Adjust the weight of the field so that it is above the answer (body).
_faq_shift_fields_down();
}
$count = 0;
// Convert old-style detailed questions to new full field.
while (($nid = $sandbox['faq_items_nids'][$sandbox['current_idx']]) && $count < BATCH_SIZE_7002) {
// Load the full node to be updated.
$node = node_load($nid);
// Load the detailed question.
$dq = isset($node->detailed_question) ? $node->detailed_question : '';
if ($dq == '') {
$select = db_select('faq_questions', 'f');
$dq = $select->condition('f.nid', $node->nid)->fields('f', array('detailed_question'))->execute()->fetchField();
}
// Get the default text filter format from DB as this might be integer if upgraded site or tekststring if new D7 site.
// Default filter format: Filtered HTML.
$filter_formats = filter_formats();
$filter_formats_keys = array_keys($filter_formats);
$filter_format = reset($filter_formats_keys);
// Get the language(s) from the body, making sure we have the same set for detailed question too.
$langs = array_keys($node->body);
// Add proper taxonomy fields.
$txonselect = db_select('taxonomy_index', 't');
$taxres = $txonselect->fields('t', array('tid'))->condition('t.nid', $node->nid)->execute();
foreach ($taxres as $taxon) {
$term = taxonomy_term_load($taxon->tid);
$vocab = taxonomy_vocabulary_load($term->vid);
foreach ($langs as $language) {
// Find out if there is a field added with the vocabulary of this term.
if (isset($node->{$vocab->module . "_" . $vocab->machine_name})) {
$node->{$vocab->module . "_" . $vocab->machine_name}[$language][$term->tid] = (array) $term;
}
}
}
// Add detailed question field for all languages.
foreach ($langs as $language) {
$node->field_detailed_question[$language][0]['value'] = $dq;
$node->field_detailed_question[$language][0]['format'] = $filter_format;
$node->field_detailed_question[$language][0]['safe_value'] = check_markup($dq, $filter_format, $language);
}
// Save resulting node.
node_save($node);
// Should not be more than BATCH_SIZE_7002.
$count++;
// Progress counter.
$sandbox['progress']++;
// Node array index pointer.
$sandbox['current_idx']++;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
return t('Custom field added, @count questions converted into fields.', array('@count' => $sandbox['max'] + 1));
}
/**
* Code examples modified.
*
* @see http://www.sitepoint.com/creating-a-new-drupal-node-type/
* @see http://www.thecarneyeffect.co.uk/creating-custom-content-type-adding-fields-programmatically-drupal-7
*/
function _faq_add_custom_fields() {
foreach (_faq_installed_fields() as $field) {
field_create_field($field);
}
foreach (_faq_installed_instances() as $fieldinstance) {
$fieldinstance['entity_type'] = 'node';
$fieldinstance['bundle'] = 'faq';
field_create_instance($fieldinstance);
}
}
/**
* Return the detailed question field definition.
*/
function _faq_installed_fields() {
$t = get_t();
return array(
'detailed_question' => array(
'translatable' => '0',
'entity_types' => array(),
'settings' => array(),
'storage' => array(
'type' => 'field_sql_storage',
'settings' => array(),
'module' => 'field_sql_storage',
'active' => '1',
'details' => array(
'sql' => array(
'FIELD_LOAD_CURRENT' => array(
'field_data_field_detailed_question' => array(
'value' => 'field_detailed_question_value',
'format' => 'field_detailed_question_format',
),
),
'FIELD_LOAD_REVISION' => array(
'field_revision_field_detailed_question' => array(
'value' => 'field_detailed_question_value',
'format' => 'field_detailed_question_format',
),
),
),
),
),
'foreign keys' => array(
'format' => array(
'table' => 'filter_format',
'columns' => array(
'format' => 'format',
),
),
),
'indexes' => array(
'format' => array(
'format',
),
),
'field_name' => 'field_detailed_question',
'type' => 'text_long',
'module' => 'text',
'active' => '1',
'locked' => '0',
'cardinality' => '1',
'deleted' => '0',
'columns' => array(
'value' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'format' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'bundles' => array(
'node' => array(
'page',
),
),
),
);
}
/**
* Returns the detailed question field instance.
*/
function _faq_installed_instances() {
$t = get_t();
// Position in the question and answer page. Body (Answer) is 0 and Question (Title) is -4.
return array(
'detailed_question' => array(
'label' => 'Detailed question',
'widget' => array(
'weight' => '-3',
'type' => 'text_textarea',
'module' => 'text',
'active' => 1,
'settings' => array(
'rows' => '5',
),
),
'settings' => array(
'text_processing' => '1',
'user_register_form' => FALSE,
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'text_default',
'weight' => '-3',
'settings' => array(),
'module' => 'text',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'text_default',
'weight' => '-3',
'settings' => array(),
'module' => 'text',
),
),
'required' => 0,
'description' => 'Enter the detailed question text',
'default_value' => NULL,
'field_name' => 'field_detailed_question',
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => '0',
),
);
}
/**
* Cleanup custom fields on uninstall.
*/
function _faq_delete_custom_fields() {
foreach (array_keys(_faq_installed_fields()) as $field) {
field_delete_field($field);
}
$instances = field_info_instances('node', 'faq');
foreach ($instances as $instance_name => $fieldinstance) {
field_delete_instance($fieldinstance);
}
}
/**
* Shift fields down.
*/
function _faq_shift_fields_down() {
// Adjust the weight of the field so that it is above the answer (body).
$instance = field_read_instance('node', 'field_detailed_question', 'faq');
// Get all bundle instances.
$instances = field_info_instances('node', 'faq');
$body_widget_weight = $instances['body']['widget']['weight'];
$body_default_weight = $instances['body']['display']['default']['weight'];
$body_teaser_weight = $instances['body']['display']['teaser']['weight'];
// Move all of them one down so that.
foreach ($instances as $field => $settings) {
if ($settings['widget']['weight'] >= $body_widget_weight) {
$settings['widget']['weight']++;
}
if ($settings['display']['default']['weight'] >= $body_default_weight) {
$settings['display']['default']['weight']++;
}
if ($settings['display']['teaser']['weight'] >= $body_teaser_weight) {
$settings['display']['teaser']['weight']++;
}
field_update_instance($settings);
}
$instance['widget']['weight'] = $body_widget_weight;
$instance['display']['default']['weight'] = $body_default_weight;
$instance['display']['teaser']['weight'] = $body_teaser_weight;
field_update_instance($instance);
}

View File

@@ -67,25 +67,26 @@
$('div.faq-qa-hide', context).hide();
}
$('div.faq-qa-header .faq-header:not(.faq-processed)', context).addClass('faq-processed').click(function() {
var $this = $(this);
if (faq_category_hide_qa_accordion) {
$('div.faq-qa-header .faq-header').not($(this)).removeClass('faq-category-qa-visible');
$('.faq-category-qa-visible').not($('.faq-category-qa-visible').closest('.faq-category-group').has($this).children('div.faq-qa-hide')).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");
$('div.faq-qa-hide').not($this.parent().siblings('div.faq-qa-hide')).not($('div.faq-qa-hide').closest('.faq-category-group').has($this).children('div.faq-qa-hide')).addClass("collapsed");
if (!faq_category_hide_qa_accordion) {
$(this).parent().next('div.faq-qa-hide').slideToggle('fast', function() {
$this.parent().siblings('div.faq-qa-hide').slideToggle('fast', function() {
$(this).parent().toggleClass('expanded');
});
}
$(this).parent().next('div.faq-qa-hide').toggleClass("collapsed");
$this.parent().siblings('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) {
if (mainScrollTop > $this.offset().top) {
$('html, body', context).animate({
scrollTop: $(this).offset().top
scrollTop: $this.offset().top
}, 1);
}
@@ -122,7 +123,6 @@
});
});
}
}
}
};
})(jQuery);

View File

@@ -18,6 +18,7 @@ function faq_help($path, $arg) {
'<p>' . t("The 'Frequently Asked Questions' settings configuration screen will allow users with 'administer faq' permissions to specify different layouts of the questions and answers.") . '</p>' .
'<p>' . t("All users with 'view faq page' permissions will be able to view the generated FAQ page.") . '</p>';
return $output;
case 'admin/modules#description':
return t('Allows the user to configure the layout of questions and answers on a FAQ page.');
}
@@ -183,7 +184,7 @@ function faq_menu() {
* Implements hook_node_info().
*
* Defines the FAQ node/content type.
* @return
* @return array
* An array, containing the title, module name and the description.
*/
function faq_node_info() {
@@ -192,6 +193,7 @@ function faq_node_info() {
'name' => t('FAQ'),
'base' => 'faq',
'description' => t('A frequently asked question and its answer.'),
'has_title' => TRUE,
'title_label' => t('Question'),
),
);
@@ -200,77 +202,41 @@ function faq_node_info() {
/**
* Implements hook_form().
*
* @param &$node
* @param object $node
* The node being added or edited.
* @param &$param
*
* @param array $form_state
* The hook can set this variable to an associative array of attributes to add
* to the enclosing <form> tag.
* @return
*
* @return array
* The form elements in the $form array.
*/
function faq_form($node, $form_state) {
$type = node_type_get_type($node);
// Set defaults.
if (empty($node->detailed_question)) {
$node->detailed_question = '';
}
$form = node_content_form($node, $form_state);
$form['title']['#description'] = t('Question to be answered. This will appear in all question listings, such as the FAQ blocks.');
// Detailed question.
if (variable_get('faq_question_long_form', 1) || variable_get('faq_question_length', 'short') == 'long') {
$form['detailed_question'] = array(
'#type' => 'textarea',
'#title' => t('Question details'),
'#default_value' => $node->detailed_question,
'#rows' => 3,
'#description' => t('Longer question text. This will be displayed in all layouts where the answer appears, in addition to the shorter question text.'),
);
}
// Answer.
if (!empty($type->body_label)) {
field_attach_form('node', $node, $form, $form_state, $node->language);
}
// dpm($form);
return $form;
}
/**
* Implements hook_field_extra_fields().
*/
function faq_field_extra_fields() {
$extra['node']['faq'] = array(
'form' => array(
'detailed_question' => array(
'label' => t('Question details'),
'description' => t('Longer question text'),
'weight' => -5,
),
),
);
return $extra;
}
/**
* Implements hook_insert().
*
* Inserts the faq node question text into the 'faq_questions' table.
*
* @param $node
* @param object $node
* The node object.
*/
function faq_insert($node) {
$items = field_get_items('node', $node, 'field_detailed_question');
$detailed_question = reset($items);
db_insert('faq_questions')
->fields(array(
'nid' => $node->nid,
'vid' => $node->vid,
'question' => $node->title,
'detailed_question' => $node->detailed_question,
'detailed_question' => $detailed_question['value'],
))
->execute();
}
@@ -280,7 +246,7 @@ function faq_insert($node) {
*
* Updates the faq node question text in the 'faq_questions' table.
*
* @param $node
* @param object $node
* The node object.
*/
function faq_update($node) {
@@ -288,11 +254,16 @@ function faq_update($node) {
faq_insert($node);
}
else {
// Empty detailed question as default.
$detailed_question = array('value' => '');
if ($items = field_get_items('node', $node, 'field_detailed_question')) {
$detailed_question = reset($items);
}
// Just to be safe, we do a merge query instead of an update query.
db_merge('faq_questions')
->fields(array(
'question' => $node->title,
'detailed_question' => $node->detailed_question,
'detailed_question' => $detailed_question['value'],
))
->key(array(
'nid' => $node->nid,
@@ -306,9 +277,6 @@ function faq_update($node) {
* Implements hook_delete().
*
* Deletes an FAQ node from the database.
*
* @param &$node
* Which node to delete.
*/
function faq_delete($node) {
db_delete('faq_weights')
@@ -324,11 +292,16 @@ function faq_delete($node) {
*
* Initialises $node->question using the value in the 'faq_questions' table.
*
* @param $node
* The node object.
* @param array $nodes
* The node objects array.
*/
function faq_load($nodes) {
return;
// @codingStandardsIgnoreStart
/*
foreach ($nodes as $nid => &$node) {
// @todo: change logic to load faq nodes - do not rely on specific faq table
$result = db_query('SELECT question, detailed_question FROM {faq_questions} WHERE nid = :nid AND vid = :vid', array(
':nid' => $node->nid,
':vid' => $node->vid,
@@ -346,6 +319,8 @@ function faq_load($nodes) {
$node->$property = $value;
}
}
*/
// @codingStandardsIgnoreEnd
}
/**
@@ -362,28 +337,39 @@ function faq_node_revision_delete($node) {
* Implements hook_view().
*/
function faq_view($node, $view_mode) {
drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css');
$language = $node->language;
if (isset($node->body[$language]) && $node->body[$language]) {
$node->detailed_question = check_markup($node->detailed_question, $node->body[$language][0]['format'], $language);
if (!isset($node->body[$language][0])) drupal_set_message('<pre>'.print_r($node->body, TRUE).'</pre>');
}
else {
$node->detailed_question = check_markup($node->detailed_question, NULL, $language);
$detailed_question = FALSE;
// Get the detailed question.
if ($field_items = field_get_items('node', $node, 'field_detailed_question')) {
$detailed_question = reset($field_items);
}
if ( !empty($node->detailed_question)
&& variable_get('faq_question_length', 'short') == 'both'
&& ( variable_get('faq_display', 'questions_top') == 'hide_answer'
|| drupal_match_path($_GET['q'], 'node/' . $node->nid)
)
) {
$node->content['detailed_question'] = array(
'#markup' => '<div class="faq-detailed-question">' . $node->detailed_question . '</div>',
'#weight' => '-1',
);
// Only show the detailed question if there is something to show.
if ($detailed_question && !empty($detailed_question['value'])) {
$show_question = FALSE;
if ($view_mode == 'full') {
// The detailed question is always shown on the full node.
$show_question = TRUE;
}
else {
// On other pages, consider the admin settings.
if (variable_get('faq_question_length', 'short') == 'both' && variable_get('faq_display', 'questions_top') == 'hide_answer') {
$show_question = TRUE;
}
}
// Should be handled by theming - create field--field_detailed_question.tpl.php.
if ($show_question) {
// We're here if we are showing the question.
$node->content['field_detailed_question'] = array(
'#markup' => theme('field_detailed_question', $detailed_question),
);
}
else {
// We switch off the visibility of the detailed question.
hide($node->content['field_detailed_question']);
}
}
return $node;
@@ -402,14 +388,17 @@ function faq_views_api() {
/**
* Function to display the faq page.
*
* @param $tid
* @param int $tid
* Default is 0, determines if the questions and answers on the page
* will be shown according to a category or non-categorized.
* @param $faq_display
*
* @param string $faq_display
* Optional parameter to override default question layout setting.
* @param $category_display
*
* @param string $category_display
* Optional parameter to override default category layout setting.
* @return
*
* @return string|NULL
* The output variable which contains an HTML formatted page with FAQ
* questions and answers.
*/
@@ -419,7 +408,12 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
}
// Things to provide translations for.
$default_values = array(t('Frequently Asked Questions'), t('Back to Top'), t('Q:'), t('A:'));
$default_values = array(
t('Frequently Asked Questions'),
t('Back to Top'),
t('Q:'),
t('A:'),
);
$output = $output_answers = '';
drupal_add_css(drupal_get_path('module', 'faq') . '/faq.css');
@@ -432,7 +426,7 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
// Configure the breadcrumb trail.
if (!empty($tid) && $current_term = taxonomy_term_load($tid)) {
if (!drupal_lookup_path('alias', arg(0) . '/' . $tid) && module_exists('pathauto')) {
if (variable_get('faq_auto_generate_alias', TRUE) && !drupal_lookup_path('alias', arg(0) . '/' . $tid) && module_exists('pathauto')) {
$alias = pathauto_create_alias('faq', 'insert', arg(0) . '/' . arg(1), array('term' => $current_term));
if ($alias) {
drupal_goto($alias['alias']);
@@ -443,7 +437,6 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
}
}
if (empty($faq_display)) {
$faq_display = variable_get('faq_display', 'questions_top');
}
@@ -487,11 +480,16 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
if ($default_sorting == 'ASC') {
$default_weight = 1000000;
}
// 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.
// @codingStandardsIgnoreStart
// @todo Doesn't work in Postgres.
//$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight));
// @codingStandardsIgnoreEnd
$query->orderBy('effective_weight', 'ASC')
->orderBy('n.sticky', 'DESC');
if ($default_sorting == 'ASC') {
@@ -504,7 +502,6 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
$query->condition('n.language', i18n_select_langcodes());
}
// Only need the nid column.
$nids = $query->execute()->fetchCol();
$data = node_load_multiple($nids);
@@ -529,16 +526,13 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.new_page.inc';
$output = theme('faq_new_page', array('data' => $data));
break;
} // End of switch.
}
}
// Categorize questions.
else {
$hide_child_terms = variable_get('faq_hide_child_terms', FALSE);
// If we're viewing a specific category/term.
if (!empty($tid)) {
if ($term = taxonomy_term_load($tid)) {
@@ -555,13 +549,13 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
}
}
$list_style = variable_get('faq_category_listing', 'ul');
$vocabularies = taxonomy_get_vocabularies('faq');
$vocab_omit = variable_get('faq_omit_vocabulary', array());
$items = array();
$vocab_items = array();
$valid_vocab = FALSE;
foreach ($vocabularies as $vid => $vobj) {
if (isset($vocab_omit[$vid]) && $vocab_omit[$vid] != 0) {
continue;
@@ -581,25 +575,28 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
else {
$tree = taxonomy_get_tree($vid, 0, NULL, TRUE);
}
foreach ($tree as $term) {
switch ($category_display) {
case 'hide_qa':
case 'categories_inline':
if (faq_taxonomy_term_count_nodes($term->tid)) {
_display_faq_by_category($faq_display, $category_display, $term, 1, $output, $output_answers);
}
break;
} // End of switch (category_display).
} // End of foreach term.
} // End of if $category_display != new_page.
} // End of foreach vocab.
}
}
}
}
if ($category_display == "new_page") {
$output = theme('item_list', array('items' => $items, 'title' => NULL, 'type' => $list_style));
$output = theme('item_list',
array(
'items' => $items,
'title' => NULL,
'type' => $list_style,
)
);
}
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');
@@ -611,24 +608,35 @@ function faq_page($tid = 0, $faq_display = '', $category_display = '') {
if ($format) {
$faq_description = check_markup($faq_description, $format);
}
return theme('faq_page', array('content' => $output, 'answers' => $output_answers, 'description' => $faq_description));
return theme('faq_page',
array(
'content' => $output,
'answers' => $output_answers,
'description' => $faq_description,
)
);
}
/**
* Display FAQ questions and answers filtered by category.
*
* @param $faq_display
* @param string $faq_display
* Define the way the FAQ is being shown; can have the values:
* 'questions top',hide answers','questions inline','new page'.
* @param $category_display
*
* @param string $category_display
* The layout of categories which should be used.
* @param $term
*
* @param object $term
* The category / term to display FAQs for.
* @param $display_header
*
* @param int $display_header
* Set if the header will be shown or not.
* @param &$output
*
* @param string &$output
* Reference which holds the content of the page, HTML formatted.
* @param &$output_answer
*
* @param string &$output_answers
* Reference which holds the answers from the FAQ, when showing questions
* on top.
*/
@@ -654,8 +662,12 @@ function _display_faq_by_category($faq_display, $category_display, $term, $displ
// 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.
// @codingStandardsIgnoreStart
// @todo Doesn't work in Postgres.
//$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight));
// @codingStandardsIgnoreEnd
$query->orderBy('effective_weight', 'ASC')
->orderBy('n.sticky', 'DESC');
if ($default_sorting == 'ASC') {
@@ -669,7 +681,6 @@ function _display_faq_by_category($faq_display, $category_display, $term, $displ
$query->condition("{$td_alias}.language", i18n_select_langcodes());
}
// We only want the first column, which is nid, so that we can load all
// related nodes.
$nids = $query->execute()->fetchCol();
@@ -696,41 +707,79 @@ function _display_faq_by_category($faq_display, $category_display, $term, $displ
$faq_path = drupal_get_path('module', 'faq') . '/includes';
switch ($faq_display) {
case 'questions_top':
include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.questions_top.inc';
// @todo fix workaround: have to share result.
$output .= theme('faq_category_questions_top', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term));
$output_answers .= theme('faq_category_questions_top_answers', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term));
$output .= theme('faq_category_questions_top',
array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
)
);
$output_answers .= theme('faq_category_questions_top_answers',
array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
)
);
break;
case 'hide_answer':
include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.hide_answer.inc';
$output .= theme('faq_category_hide_answer', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term));
$output .= theme('faq_category_hide_answer',
array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
)
);
break;
case 'questions_inline':
include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.questions_inline.inc';
$output .= theme('faq_category_questions_inline', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term));
$output .= theme('faq_category_questions_inline',
array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
)
);
break;
case 'new_page':
include_once DRUPAL_ROOT . '/' . $faq_path . '/faq.new_page.inc';
$output .= theme('faq_category_new_page', array('data' => $data, 'display_header' => $display_header, 'category_display' => $category_display, 'term' => $term, 'class' => $faq_class, 'parent_term' => $term));
$output .= theme('faq_category_new_page',
array(
'data' => $data,
'display_header' => $display_header,
'category_display' => $category_display,
'term' => $term,
'class' => $faq_class,
'parent_term' => $term,
)
);
break;
} // End of switch (faq_display).
}
// Handle indenting of categories.
while ($depth > 0) {
$output .= '</div>';
$depth--;
}
}
/**
@@ -739,6 +788,9 @@ function _display_faq_by_category($faq_display, $category_display, $term, $displ
function faq_theme() {
$path = drupal_get_path('module', 'faq') . '/includes';
return array(
'field_detailed_question' => array(
'render element' => 'element',
),
'faq_draggable_question_order_table' => array(
'render element' => 'form',
),
@@ -752,13 +804,27 @@ function faq_theme() {
'path' => $path,
'file' => 'faq.questions_top.inc',
'template' => 'faq-category-questions-top',
'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL),
'variables' => array(
'data' => NULL,
'display_header' => 0,
'category_display' => NULL,
'term' => NULL,
'class' => NULL,
'parent_term' => NULL,
),
),
'faq_category_questions_top_answers' => array(
'path' => $path,
'file' => 'faq.questions_top.inc',
'template' => 'faq-category-questions-top-answers',
'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL),
'variables' => array(
'data' => NULL,
'display_header' => 0,
'category_display' => NULL,
'term' => NULL,
'class' => NULL,
'parent_term' => NULL,
),
),
'faq_hide_answer' => array(
'path' => $path,
@@ -770,7 +836,14 @@ function faq_theme() {
'path' => $path,
'file' => 'faq.hide_answer.inc',
'template' => 'faq-category-hide-answer',
'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL),
'variables' => array(
'data' => NULL,
'display_header' => 0,
'category_display' => NULL,
'term' => NULL,
'class' => NULL,
'parent_term' => NULL,
),
),
'faq_questions_inline' => array(
'path' => $path,
@@ -782,7 +855,14 @@ function faq_theme() {
'path' => $path,
'file' => 'faq.questions_inline.inc',
'template' => 'faq-category-questions-inline',
'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL),
'variables' => array(
'data' => NULL,
'display_header' => 0,
'category_display' => NULL,
'term' => NULL,
'class' => NULL,
'parent_term' => NULL,
),
),
'faq_new_page' => array(
'path' => $path,
@@ -794,10 +874,21 @@ function faq_theme() {
'path' => $path,
'file' => 'faq.new_page.inc',
'template' => 'faq-category-new-page',
'variables' => array('data' => NULL, 'display_header' => 0, 'category_display' => NULL, 'term' => NULL, 'class' => NULL, 'parent_term' => NULL),
'variables' => array(
'data' => NULL,
'display_header' => 0,
'category_display' => NULL,
'term' => NULL,
'class' => NULL,
'parent_term' => NULL,
),
),
'faq_page' => array(
'variables' => array('content' => '', 'answers' => '', 'description' => NULL),
'variables' => array(
'content' => '',
'answers' => '',
'description' => NULL,
),
),
);
}
@@ -840,11 +931,17 @@ function faq_block_view($delta) {
$items[] = l(faq_tt("taxonomy:term:$tid:name", $name), 'faq-page/' . $tid);
}
$list_style = variable_get('faq_category_listing', 'ul');
$block['content'] = theme('item_list', array('items' => $items, 'title' => NULL, 'type' => $list_style));
$block['content'] = theme('item_list',
array(
'items' => $items,
'title' => NULL,
'type' => $list_style,
)
);
}
}
break;
} // End switch($delta).
}
return $block;
}
@@ -852,11 +949,13 @@ function faq_block_view($delta) {
/**
* Return a HTML formatted list of terms indented according to the term depth.
*
* @param $vid
* @param int $vid
* Vocabulary id.
* @param $tid
*
* @param int $tid
* Term id.
* @return
*
* @return string
* Return a HTML formatted list of terms indented according to the term depth.
*/
function _get_indented_faq_terms($vid, $tid) {
@@ -945,7 +1044,7 @@ function _get_indented_faq_terms($vid, $tid) {
/**
* Get a list of terms associated with the FAQ nodes.
*
* @return
* @return string
* Return the HTML-formatted content.
*/
function faq_get_terms() {
@@ -957,13 +1056,14 @@ function faq_get_terms() {
$vocab_items = _get_indented_faq_terms($vid, 0);
$items = array_merge($items, $vocab_items);
}
return theme('item_list', array('items' => $items));
}
/**
* Format the output for the faq_site_map() function.
*
* @return
* @return array
* Return a list of FAQ categories if categorization is enabled, otherwise
* return a list of faq nodes.
*/
@@ -994,8 +1094,12 @@ function faq_get_faq_list() {
// 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.
// @codingStandardsIgnoreStart
// @todo Doesn't work in Postgres.
//$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight));
// @codingStandardsIgnoreEnd
$query->orderBy('effective_weight', 'ASC')
->orderBy('n.sticky', 'DESC');
if ($default_sorting == 'ASC') {
@@ -1023,6 +1127,9 @@ function faq_get_faq_list() {
}
if (!function_exists('array_diff_key')) {
/**
* Override array_diff_key function.
*/
function array_diff_key() {
$arrs = func_get_args();
$result = array_shift($arrs);
@@ -1040,13 +1147,16 @@ if (!function_exists('array_diff_key')) {
/**
* Helper function to setup the faq question.
*
* @param &$data
* @param array &$data
* Array reference to store display data in.
* @param $node
*
* @param object $node
* The node object.
* @param $path
*
* @param string $path
* The path/url which the question should link to if links are disabled.
* @param $anchor
*
* @param string $anchor
* Link anchor to use in question links.
*/
function faq_view_question(&$data, $node, $path = NULL, $anchor = NULL) {
@@ -1083,9 +1193,24 @@ function faq_view_question(&$data, $node, $path = NULL, $anchor = NULL) {
}
$question = '<span datatype="" property="dc:title">' . $question . '</span>';
if (variable_get('faq_display', 'questions_top') != 'hide_answer' && !empty($node->detailed_question) && variable_get('faq_question_length', 'short') == 'both') {
$node->detailed_question = check_markup($node->detailed_question, 'filtered_html', '', FALSE);
$question .= '<div class="faq-detailed-question">' . $node->detailed_question . '</div>';
// Get the language of the body field.
$language = 'und';
foreach ($node->body as $lang => $values) {
if ($values[0]['value']) {
$language = $lang;
}
}
// Get the detailed question.
$detailed_question = '';
if ($dq = field_get_items('node', $node, 'field_detailed_question')) {
$detailed_question = reset($dq);
}
if (variable_get('faq_display', 'questions_top') != 'hide_answer'
&& !empty($detailed_question['value'])
&& variable_get('faq_question_length', 'short') == 'both') {
$question .= '<div class="faq-detailed-question">' . $detailed_question['safe_value'] . '</div>';
}
$data['question'] = $question;
}
@@ -1093,19 +1218,22 @@ function faq_view_question(&$data, $node, $path = NULL, $anchor = NULL) {
/**
* Helper function to setup the faq answer.
*
* @param &$data
* @param array &$data
* Array reference to store display data in.
* @param $node
*
* @param object $node
* The node object.
* @param $back_to_top
*
* @param array $back_to_top
* An array containing the "back to top" link.
* @param $teaser
*
* @param bool $teaser
* Whether or not to use teasers.
* @param $links
*
* @param array $links
* Whether or not to show node links.
*/
function faq_view_answer(&$data, $node, $back_to_top, $teaser, $links) {
$view_mode = $teaser ? 'teaser' : 'full';
$langcode = $GLOBALS['language_content']->language;
@@ -1149,14 +1277,12 @@ function faq_view_answer(&$data, $node, $back_to_top, $teaser, $links) {
$node_links = ($links ? $build['links']['node']['#links'] : (!empty($back_to_top) ? array($build['links']['node']['#links']['faq_back_to_top']) : NULL));
unset($build['links']);
unset($build['#theme']); // We don't want node title displayed.
// We don't want node title displayed.
unset($build['#theme']);
$content = drupal_render($build);
// Unset unused $node text so that a bad theme can not open a security hole.
// $node->body = NULL;
// $node->teaser = NULL;
$data['body'] = $content;
$data['links'] = !empty($node_links) ? theme('links', array('links' => $node_links, 'attributes' => array('class' => 'links inline'))) : '';
}
@@ -1164,11 +1290,12 @@ function faq_view_answer(&$data, $node, $back_to_top, $teaser, $links) {
/**
* Helper function to setup the "back to top" link.
*
* @param $path
* @param string $path
* The path/url where the "back to top" link should bring the user too. This
* could be the 'faq-page' page or one of the categorized faq pages, e.g 'faq-page/123'
* where 123 is the tid.
* @return
*
* @return array
* An array containing the "back to top" link.
*/
function faq_init_back_to_top($path) {
@@ -1190,22 +1317,31 @@ function faq_init_back_to_top($path) {
/**
* Helper function for retrieving the sub-categories faqs.
*
* @param $term
* @param object $term
* The category / term to display FAQs for.
* @param $theme_function
*
* @param string $theme_function
* Theme function to use to format the Q/A layout for sub-categories.
* @param $default_weight
*
* @param int $default_weight
* Is 0 for $default_sorting = DESC; is 1000000 for $default_sorting = ASC.
* @param $default_sorting
*
* @param string $default_sorting
* If 'DESC', nodes are sorted by creation date descending; if 'ASC', nodes
* are sorted by creation date ascending.
* @param $category_display
*
* @param string $category_display
* The layout of categories which should be used.
* @param $class
*
* @param string $class
* CSS class which the HTML div will be using. A special class name is
* required in order to hide and questions / answers.
* @param $parent_term
*
* @param string $parent_term
* The original, top-level, term we're displaying FAQs for.
*
* @return string
* Returns markup.
*/
function faq_get_child_categories_faqs($term, $theme_function, $default_weight, $default_sorting, $category_display, $class, $parent_term = NULL) {
$output = array();
@@ -1237,8 +1373,12 @@ function faq_get_child_categories_faqs($term, $theme_function, $default_weight,
// 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.
// @codingStandardsIgnoreStart
// @todo Doesn't work in Postgres.
//$query->addExpression('COALESCE(w.weight, CAST(:default_weight as SIGNED))', 'effective_weight', array(':default_weight' => $default_weight));
// @codingStandardsIgnoreEnd
$query->orderBy('effective_weight', 'ASC')
->orderBy('n.sticky', 'DESC');
if ($default_sorting == 'ASC') {
@@ -1257,7 +1397,16 @@ function faq_get_child_categories_faqs($term, $theme_function, $default_weight,
$nids = $query->execute()->fetchCol();
$data = node_load_multiple($nids);
$output[] = theme($theme_function, array('data' => $data, 'display_header' => 1, 'category_display' => $category_display, 'term' => $child_term, 'class' => $class, 'parent_term' => $parent_term));
$output[] = theme($theme_function,
array(
'data' => $data,
'display_header' => 1,
'category_display' => $category_display,
'term' => $child_term,
'class' => $class,
'parent_term' => $parent_term,
)
);
}
}
@@ -1267,13 +1416,13 @@ function faq_get_child_categories_faqs($term, $theme_function, $default_weight,
/**
* Helper function to setup the list of sub-categories for the header.
*
* @param $term
* @param object $term
* The term to setup the list of child terms for.
* @return
*
* @return array
* An array of sub-categories.
*/
function faq_view_child_category_headers($term) {
$child_categories = array();
$list = taxonomy_get_children($term->tid);
@@ -1311,8 +1460,8 @@ function faq_pathauto($op) {
$settings['patterndefault'] = t('faq-page/[term:tid]');
$settings['batch_update_callback'] = 'faq_pathauto_bulkupdate';
$settings['token_type'] = 'term';
return (object) $settings;
default:
break;
}
@@ -1435,8 +1584,11 @@ function faq_taxonomy_term_delete($term) {
/**
* Function to set up the FAQ breadcrumbs for a given taxonomy term.
*
* @param $term
* @param object $term
* The taxonomy term object.
*
* @return array|NULL
* Breadcrumbs.
*/
function faq_set_breadcrumb($term = NULL) {
$breadcrumb = array();
@@ -1499,10 +1651,16 @@ function faq_filter_info() {
return $filters;
}
/**
* Filter settings.
*/
function _faq_filter_settings($form, &$form_state, $filter, $format, $defaults, $filters) {
return array();
}
/**
* Filter string.
*/
function _faq_filter_process($text) {
$text = preg_replace_callback('/\[faq:?([^\]]*)\]/', '_faq_faq_page_filter_replacer', $text);
// Remove comments, as they're not supported by all input formats.
@@ -1524,6 +1682,13 @@ function _faq_faq_page_filter_replacer($matches) {
$tid = 0;
$faq_display = '';
$category_display = '';
$default_display = array(
'questions_top',
'hide_answer',
'questions_inline',
'new_page',
);
$default_category_display = array('hide_qa', 'new_page', 'categories_inline');
if (drupal_strlen($matches[1])) {
list($tid, $faq_display, $category_display) = explode(',', $matches[1] . ',,');
$tid = (int) trim($tid);
@@ -1531,10 +1696,10 @@ function _faq_faq_page_filter_replacer($matches) {
$category_display = trim($category_display);
// These two checks ensure that a typo in the faq_display or
// category_display string still results in the FAQ showing.
if ($faq_display && !in_array($faq_display, array('questions_top', 'hide_answer', 'questions_inline', 'new_page'))) {
if ($faq_display && !in_array($faq_display, $default_display)) {
$faq_display = '';
}
if ($category_display && !in_array($category_display, array('hide_qa', 'new_page', 'categories_inline'))) {
if ($category_display && !in_array($category_display, $default_category_display)) {
$category_display = '';
}
}
@@ -1607,6 +1772,34 @@ function theme_faq_page($variables) {
return $output;
}
/**
* Theme function for the detailed questionfield.
*
* @param array $variables
* Variables array.
*
* @return string
* Markup.
*/
function theme_field_detailed_question($variables) {
// Render the label, if it's not hidden.
$output = '';
if (isset($variables['label']) && !$variables['label_hidden'] && $variables['label']) {
$output .= '<div class="field-label"' . $variables['title_attributes'] . '>' . $variables['label'] . ':&nbsp;</div>';
}
// Render the items.
$output .= '<div class="faq-detailed-question">' . $variables['safe_value'] . '</div>';
// Render the top-level DIV.
if (isset($variables['classes']) && isset($variables['attributes'])) {
$output = '<div class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</div>';
}
return $output;
}
/**
* Theme function for question ordering drag and drop table.
*/
@@ -1628,8 +1821,13 @@ function theme_faq_draggable_question_order_table($variables) {
'class' => array('draggable'),
);
}
$output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'question-sort')));
$output = theme('table',
array(
'header' => $header,
'rows' => $rows,
'attributes' => array('id' => 'question-sort'),
)
);
$output .= drupal_render_children($form);
return $output;
}

View File

@@ -207,12 +207,21 @@ class CreateFaqTestCase extends FaqTestCase {
/**
* Test creating a FAQ node
*
* This test creates a faq with detailed question shown and labeled questions and answers
*/
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);
// Show the detailed question
$this->drupalGet('admin/config/content/faq/questions');
// Set faq to allow long question text and labeled questions and answers
$this->drupalPost('admin/config/content/faq/questions', array('faq_question_long_form' => '1', 'faq_qa_mark' => '1'), t('Save configuration'));
$this->drupalPost('admin/config/content/faq/questions', array('faq_question_length' => 'both'), t('Save configuration'));
$this->afaq_user = $this->drupalCreateUser(array('create faq content', 'view faq page'));
$this->drupalLogin($this->afaq_user);
// Verify that the faq page is visible and available but empty
$this->drupalGet('faq-page');
@@ -223,18 +232,23 @@ class CreateFaqTestCase extends FaqTestCase {
$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["field_detailed_question[$langcode][0][value]"] = $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'])));
// Check that faq is found on the correct taxonomy term page too
$this->drupalGet('taxonomy/term/' . $this->term->tid);
$this->assertText(t('@title', 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["field_detailed_question[$langcode][0][value]"] = $this->randomName(16);
$this->faq2["body[$langcode][0][value]"] = $this->randomName(16);
$this->drupalPost('node/add/faq', $this->faq2, t('Save'));
@@ -261,7 +275,8 @@ class CreateFaqTestCase extends FaqTestCase {
// Navigate to FAQ node created on FAQ page
$this->clickLink(t($this->faq1['title']));
$this->assertText(t($this->faq1["body[$langcode][0][value]"]));
$this->assertText(t($this->faq1["field_detailed_question[$langcode][0][value]"]), t('Detailed question visible')); // Dependant on the question setting
$this->assertText(t($this->faq1["body[$langcode][0][value]"]), t('Answer visible'));
// Enable categorisation of FAQ nodes
// Create and log in user with create and administer FAQ permissions
@@ -317,7 +332,7 @@ class CRAUDFaqTestCase extends FaqTestCase {
$edit = array();
$edit['title'] = $this->randomName(8);
$edit[$this->instance['field_name'] . '['. LANGUAGE_NONE .']'] = $this->randomName(8);
$edit['detailed_question'] = $this->randomName(64);
$edit['field_detailed_question['. LANGUAGE_NONE .'][0][value]'] = $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'])));

View File

@@ -1,5 +1,10 @@
<?php
/**
* @file
* FAQ module variables file.
*/
/**
* Implements hook_variable_info().
*/
@@ -42,4 +47,3 @@ function faq_variable_info($options) {
return $variable;
}

View File

@@ -50,12 +50,15 @@
* The sub-categories faqs, recursively themed (by this template).
*/
// @todo should be moved to better place.
// @codingStandardsIgnoreStart
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
// @codingStandardsIgnoreEnd
?><div class="faq-category-group">
<!-- category header with title, link, image, description, and count of
@@ -130,7 +133,5 @@ else {
<?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

@@ -46,12 +46,15 @@
* The sub-categories faqs, recursively themed (by this template).
*/
// @todo should be moved to better place.
// @codingStandardsIgnoreStart
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
// @codingStandardsIgnoreEnd
?><div class="faq-category-group">
<!-- category header with title, link, image, description, and count of
@@ -119,8 +122,5 @@ else {
</<?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

@@ -53,13 +53,15 @@
* The sub-categories faqs, recursively themed (by this template).
*/
// @todo should be moved to better place.
// @codingStandardsIgnoreStart
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
// @codingStandardsIgnoreEnd
?>
<a id="faq-top"></a>
<div class="faq-category-group">
@@ -143,7 +145,5 @@ else {
<?php endforeach; ?>
<?php endif; ?>
</div> <!-- Close div -->
</div> <!-- Close div: faq-qa / faq-qa-hide -->
</div> <!-- Close div: faq-category-group -->

View File

@@ -53,17 +53,19 @@
* The sub-categories faqs, recursively themed (by this template).
*/
// @todo should be moved to better place.
// @codingStandardsIgnoreStart
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
$depth = 0;
// @codingStandardsIgnoreEnd
?>
?><?php if ($display_answers): ?>
<?php if ($display_answers): ?>
<?php if ($answer_category_name): ?>
<?php while ($depth < $category_depth): ?>
<div class="faq-category-indent">
@@ -135,5 +137,4 @@ $depth = 0;
</div> <!-- Close div: faq-category-indent -->
<?php $depth--; endwhile; ?>
<?php endif; ?>
<?php
endif; // if display_answers
<?php endif; ?>

View File

@@ -60,13 +60,15 @@
* The sub-categories faqs, recursively themed (by this template).
*/
// @todo should be moved to better place.
// @codingStandardsIgnoreStart
if ($category_depth > 0) {
$hdr = 'h4';
}
else {
$hdr = 'h3';
}
// @codingStandardsIgnoreEnd
?>
<a id="faq-top"></a>
<div class="faq-category-menu">
@@ -115,14 +117,14 @@ else {
<div class="<?php print $container_class; ?>">
<?php // include subcategories ?>
<?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 /* List question links. */ ?>
<?php if (!empty($question_list)): ?>
<div class="item-list">
<<?php print $question_list_style; ?> class="faq-ul-questions-top">
@@ -149,14 +151,14 @@ else {
<div class="clear-block"></div>
<?php endif; ?>
<?php // List questions (in title link) and answers (in body). ?>
<?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? ?>
<div class="faq-question">
<?php if (!empty($question_label)) : ?>
<strong class="faq-question-label">
<?php print $question_label; ?>
@@ -185,5 +187,4 @@ else {
<?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 endif; ?>

View File

@@ -21,7 +21,7 @@
?><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. ?>
<?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']; ?>

View File

@@ -16,5 +16,4 @@
* Pre-formatted list.
*/
?>
<?php
print $list;
<?php print $list; ?>

View File

@@ -26,7 +26,6 @@
<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)): ?>

View File

@@ -35,7 +35,7 @@
<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. ?>
<?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">
@@ -54,7 +54,6 @@
<?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 /* Increment $key to move on to the next position. */ ?>
<?php $key++; ?>
<?php
endwhile;
<?php endwhile; ?>

View File

@@ -8,7 +8,7 @@
/**
* Create FAQ page if set to show/hide answer when question is clicked.
*
* @param &$variables
* @param array &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_hide_answer(&$variables) {
@@ -35,7 +35,7 @@ function template_preprocess_faq_hide_answer(&$variables) {
/**
* Create categorized FAQ page if set to show answer when question is clicked.
*
* @param &$variables
* @param array &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_category_hide_answer(&$variables) {
@@ -76,7 +76,6 @@ function template_preprocess_faq_category_hide_answer(&$variables) {
$show_term_page_children = TRUE;
}
// Get number of questions, and account for hidden sub-categories.
$count = 0;
if ($display_faq_count && $hide_child_terms) {
@@ -94,7 +93,7 @@ function template_preprocess_faq_category_hide_answer(&$variables) {
$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");
$variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq-page/$term->tid");
}
else {
$variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
@@ -145,4 +144,3 @@ function template_preprocess_faq_category_hide_answer(&$variables) {
$variables['nodes'] = $nodes;
$variables['question_count'] = $count;
}

View File

@@ -8,7 +8,7 @@
/**
* Create FAQ page if set to show the answer in a new page.
*
* @param &$variables
* @param array &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_new_page(&$variables) {
@@ -23,16 +23,22 @@ function template_preprocess_faq_new_page(&$variables) {
$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")));
$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
* @param array &$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'];
@@ -84,7 +90,7 @@ function template_preprocess_faq_category_new_page(&$variables) {
// 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");
$variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq-page/$term->tid");
}
else {
$variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
@@ -132,4 +138,3 @@ function template_preprocess_faq_category_new_page(&$variables) {
$variables['question_list_style'] = variable_get('faq_question_listing', 'ul');
$variables['question_count'] = $count;
}

View File

@@ -8,7 +8,7 @@
/**
* Create the FAQ page if set to show the questions inline.
*
* @param &$variables
* @param array &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_questions_inline(&$variables) {
@@ -46,7 +46,7 @@ function template_preprocess_faq_questions_inline(&$variables) {
/**
* Create categorized FAQ page if set to show/hide the questions inline.
*
* @param &$variables
* @param array &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_category_questions_inline(&$variables) {
@@ -87,7 +87,6 @@ function template_preprocess_faq_category_questions_inline(&$variables) {
$show_term_page_children = TRUE;
}
// Configure "back to top" link.
$back_to_top = faq_init_back_to_top($this_page);
@@ -115,7 +114,7 @@ function template_preprocess_faq_category_questions_inline(&$variables) {
// 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");
$variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq-page/$term->tid");
}
else {
$variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
@@ -166,4 +165,3 @@ function template_preprocess_faq_category_questions_inline(&$variables) {
$variables['nodes'] = $nodes;
$variables['question_count'] = $count;
}

View File

@@ -8,9 +8,10 @@
/**
* Create the structure of the page, when the questions are to be shown on top.
*
* @param &$variables
* @param array &$variables
* Array reference of arguments given to the theme() function.
* @return
*
* @return array
* A variable holding the HTML formatted page.
*/
function template_preprocess_faq_questions_top(&$variables) {
@@ -51,13 +52,22 @@ function template_preprocess_faq_questions_top(&$variables) {
$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")));
$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
* @param array &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_category_questions_top(&$variables) {
@@ -76,7 +86,7 @@ function template_preprocess_faq_category_questions_top(&$variables) {
$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'] = '';
@@ -126,7 +136,7 @@ function template_preprocess_faq_category_questions_top(&$variables) {
$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");
$variables['header_title'] = l(faq_tt("taxonomy:term:$term->tid:name", $term->name), "faq-page/$term->tid");
}
else {
$variables['header_title'] = check_plain(faq_tt("taxonomy:term:$term->tid:name", $term->name));
@@ -199,7 +209,7 @@ function template_preprocess_faq_category_questions_top(&$variables) {
/**
* Create categorized answers for FAQ page if set to show the questions on top.
*
* @param &$variables
* @param array &$variables
* Array reference of arguments given to the theme() function.
*/
function template_preprocess_faq_category_questions_top_answers(&$variables) {
@@ -271,7 +281,6 @@ function template_preprocess_faq_category_questions_top_answers(&$variables) {
$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();
@@ -290,4 +299,3 @@ function template_preprocess_faq_category_questions_top_answers(&$variables) {
$variables['display_header'] = TRUE;
}
}

View File

@@ -1,5 +1,10 @@
<?php
/**
* @file
* Provides the view implementation.
*/
/**
* Implements hook_views_data().
*/
@@ -8,8 +13,8 @@ function faq_views_data() {
$data['faq_questions']['table']['group'] = t('FAQ');
$data['faq_questions']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
'left_field' => 'vid',
'field' => 'vid',
),
);
$data['faq_questions']['question'] = array(
@@ -41,7 +46,6 @@ function faq_views_data() {
),
);
// faq_weights table.
$data['faq_weights']['table']['group'] = t('FAQ');
$data['faq_weights']['table']['join'] = array(
@@ -124,4 +128,3 @@ function faq_views_data() {
return $data;
}

View File

@@ -11,7 +11,7 @@
function faq_views_default_views() {
$export = array();
$view = new view;
$view = new view();
$view->name = 'faq';
$view->description = 'FAQ listings';
$view->tag = 'default';
@@ -417,4 +417,3 @@ function faq_views_default_views() {
return $export;
}

View File

@@ -7,11 +7,11 @@ Maintainers:
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
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
@@ -26,3 +26,12 @@ 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.
Developers
-----------
If you wish to use Friendly Register with your module:
1) Add the friendly-register-name or friendly-register-mail class to your
field(s).
2) In your module, call friendly_register_load_resources() after adding the
classes. This will usually happen inside the function that adds the classes.
See friendly_register_form_user_register_form_alter() for an example.

View File

@@ -2,9 +2,9 @@ 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"
; Information added by drupal.org packaging script on 2013-10-20
version = "7.x-1.1"
core = "7.x"
project = "friendly_register"
datestamp = "1331094642"
datestamp = "1382296452"

View File

@@ -51,9 +51,35 @@ function friendly_register_cron() {
}
/**
* Implements hook_FORM_form_alter().
* Implements hook_form_FORM_ID_alter().
*/
function friendly_register_form_user_register_form_alter(&$form, &$form_state, $form_id) {
foreach (array('name', 'mail') as $field) {
$class = 'friendly-register-' . $field;
if (isset($form['account'][$field]['#attributes']['class'])) {
$form['account'][$field]['#attributes']['class'][] = $class;
}
elseif (isset($form['account'][$field]['#attributes'])) {
$form['account'][$field]['#attributes']['class'] = array(
$class,
);
}
else {
$form['account'][$field]['#attributes'] = array(
'class' => array(
$class,
),
);
}
}
friendly_register_load_resources();
}
/**
* Utility function for load required resources.
*/
function friendly_register_load_resources() {
$path = drupal_get_path('module', 'friendly_register');
drupal_add_js($path . '/js/friendly_register.js', 'file');
drupal_add_css($path . '/css/friendly_register.css');

View File

@@ -33,7 +33,7 @@
if (data.available == 'incomplete') {
$('#edit-mail-check').remove();
return;
}
}
var message;
if (data.available) {
message = email.avail;
@@ -60,14 +60,14 @@
var userName = new Object();
userName.oldValue = '';
userName.ajaxPath = Drupal.settings.basePath + 'ajax/check-user/';
userName.field = $('#user-register-form #edit-name', context);
userName.field = $('.friendly-register-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.field = $('.friendly-register-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});