security updates of unpatched modules
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* This hook may be placed in a $module.flag.inc file.
|
||||
*
|
||||
* @return
|
||||
* @return array
|
||||
* An array whose keys are flag type names and whose values are properties of
|
||||
* the flag type.
|
||||
* When a flag type is for an entity, the flag type name must match the entity
|
||||
@@ -46,7 +46,7 @@ function hook_flag_type_info() {
|
||||
*
|
||||
* This hook may be placed in a $module.flag.inc file.
|
||||
*
|
||||
* @param $definitions
|
||||
* @param array $definitions
|
||||
* An array of flag definitions returned by hook_flag_type_info().
|
||||
*/
|
||||
function hook_flag_type_info_alter(&$definitions) {
|
||||
@@ -118,10 +118,10 @@ function hook_flag_alter(&$flag) {
|
||||
* them here so that their additions to the flag admin form are saved into the
|
||||
* flag object.
|
||||
*
|
||||
* @param $options
|
||||
* @param array $options
|
||||
* The array of default options for the flag type, with the options for the
|
||||
* flag's link type merged in.
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The flag object.
|
||||
*
|
||||
* @see flag_flag::options()
|
||||
@@ -133,9 +133,9 @@ function hook_flag_options_alter(&$options, $flag) {
|
||||
/**
|
||||
* Act on an object being flagged.
|
||||
*
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The flag object.
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The id of the entity the flag is on.
|
||||
* @param $account
|
||||
* The user account performing the action.
|
||||
@@ -154,7 +154,7 @@ function hook_flag_flag($flag, $entity_id, $account, $flagging) {
|
||||
*
|
||||
* @param $flag
|
||||
* The flag object.
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The id of the entity the flag is on.
|
||||
* @param $account
|
||||
* The user account performing the action.
|
||||
@@ -168,18 +168,18 @@ function hook_flag_unflag($flag, $entity_id, $account, $flagging) {
|
||||
/**
|
||||
* Perform custom validation on a flag before flagging/unflagging.
|
||||
*
|
||||
* @param $action
|
||||
* @param string $action
|
||||
* The action about to be carried out. Either 'flag' or 'unflag'.
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The flag object.
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The id of the entity the user is trying to flag or unflag.
|
||||
* @param $account
|
||||
* The user account performing the action.
|
||||
* @param $flagging
|
||||
* The flagging entity.
|
||||
*
|
||||
* @return
|
||||
* @return array|NULL
|
||||
* Optional array: textual error with the error-name as the key.
|
||||
* If the error name is 'access-denied' and javascript is disabled,
|
||||
* drupal_access_denied will be called and a 403 will be returned.
|
||||
@@ -207,11 +207,11 @@ function hook_flag_validate($action, $flag, $entity_id, $account, $skip_permissi
|
||||
* Called when displaying a single entity view or edit page. For flag access
|
||||
* checks from within Views, implement hook_flag_access_multiple().
|
||||
*
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The flag object.
|
||||
* @param $entity_id
|
||||
* The id of the entity in question.
|
||||
* @param $action
|
||||
* @param string $action
|
||||
* The action to test. Either 'flag' or 'unflag'.
|
||||
* @param $account
|
||||
* The user on whose behalf to test the flagging action.
|
||||
@@ -238,16 +238,18 @@ function hook_flag_access($flag, $entity_id, $action, $account) {
|
||||
* Called when preparing a View or list of multiple flaggable entities.
|
||||
* For flag access checks for individual entities, see hook_flag_access().
|
||||
*
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The flag object.
|
||||
* @param $entity_ids
|
||||
* @param array $entity_ids
|
||||
* An array of object ids to check access.
|
||||
* @param $account
|
||||
* The user on whose behalf to test the flagging action.
|
||||
*
|
||||
* @return
|
||||
* @return array
|
||||
* An array whose keys are the object IDs and values are booleans indicating
|
||||
* access.
|
||||
* access: TRUE to grant access, FALSE to deny it, and NULL to leave the core
|
||||
* access unchanged. If the implementation does not wish to override any
|
||||
* access, an empty array may be returned.
|
||||
*
|
||||
* @see hook_flag_access()
|
||||
* @see flag_flag:access_multiple()
|
||||
@@ -291,7 +293,7 @@ function hook_flag_link_type_info() {
|
||||
*
|
||||
* This hook may be placed in a $module.flag.inc file.
|
||||
*
|
||||
* @param $link_types
|
||||
* @param array $link_types
|
||||
* An array of the link types defined by all modules.
|
||||
*
|
||||
* @see flag_get_link_types()
|
||||
@@ -311,11 +313,11 @@ function hook_flag_link_type_info_alter(&$link_types) {
|
||||
* attributes, using the same structure as hook_link(). Note that "title" is
|
||||
* provided by the Flag configuration if not specified here.
|
||||
*
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The full flag object for the flag link being generated.
|
||||
* @param $action
|
||||
* @param string $action
|
||||
* The action this link should perform. Either 'flag' or 'unflag'.
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The ID of the node, comment, user, or other object being flagged. The type
|
||||
* of the object can be deduced from the flag type.
|
||||
*
|
||||
@@ -325,7 +327,7 @@ function hook_flag_link_type_info_alter(&$link_types) {
|
||||
* @see hook_flag_link_type_info()
|
||||
* @see template_preprocess_flag()
|
||||
*/
|
||||
function hook_flag_link() {
|
||||
function hook_flag_link($flag, $action, $entity_id) {
|
||||
|
||||
}
|
||||
|
||||
@@ -335,7 +337,7 @@ function hook_flag_link() {
|
||||
* This is invoked after all the flag database tables have had their relevant
|
||||
* entries deleted.
|
||||
*
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The flag object that has been deleted.
|
||||
*/
|
||||
function hook_flag_delete($flag) {
|
||||
@@ -345,9 +347,9 @@ function hook_flag_delete($flag) {
|
||||
/**
|
||||
* Act when a flag is reset.
|
||||
*
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The flag object.
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The entity ID on which all flaggings are to be removed. May be NULL, in
|
||||
* which case all of this flag's entities are to be unflagged.
|
||||
* @param $rows
|
||||
@@ -362,9 +364,9 @@ function hook_flag_reset($flag, $entity_id, $rows) {
|
||||
/**
|
||||
* Alter the javascript structure that describes the flag operation.
|
||||
*
|
||||
* @param $info
|
||||
* @param array $info
|
||||
* The info array before it is returned from flag_build_javascript_info().
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The full flag object.
|
||||
*
|
||||
* @see flag_build_javascript_info()
|
||||
@@ -384,7 +386,7 @@ function hook_flag_javascript_info_alter(&$info, $flag) {
|
||||
/**
|
||||
* Alter a flag object that is being prepared for exporting.
|
||||
*
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The flag object.
|
||||
*
|
||||
* @see flag_export_flags()
|
||||
|
@@ -10,7 +10,7 @@
|
||||
*
|
||||
* Defines the flag types this module implements.
|
||||
*
|
||||
* @return
|
||||
* @return array
|
||||
* An "array of arrays", keyed by object type. The 'handler' slot
|
||||
* should point to the PHP class implementing this flag.
|
||||
*/
|
||||
|
@@ -29,9 +29,9 @@ files[] = includes/views/flag_handler_relationships.inc
|
||||
files[] = includes/views/flag_plugin_argument_validate_flaggability.inc
|
||||
files[] = tests/flag.test
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-03-02
|
||||
version = "7.x-3.6"
|
||||
; Information added by Drupal.org packaging script on 2016-09-23
|
||||
version = "7.x-3.9"
|
||||
core = "7.x"
|
||||
project = "flag"
|
||||
datestamp = "1425327793"
|
||||
datestamp = "1474619065"
|
||||
|
||||
|
@@ -22,7 +22,7 @@ function flag_schema() {
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'entity_type' => array(
|
||||
'description' => 'The flag type, such as one of "node", "comment", or "user".',
|
||||
'description' => 'The flag type, for example "node", "comment", or "user".',
|
||||
'type' => 'varchar',
|
||||
'length' => '128',
|
||||
'not null' => TRUE,
|
||||
@@ -79,14 +79,14 @@ function flag_schema() {
|
||||
'default' => 0,
|
||||
),
|
||||
'entity_type' => array(
|
||||
'description' => 'The flag type, eg "node", "comment", "user".',
|
||||
'description' => 'The flag type, for example "node", "comment", or "user".',
|
||||
'type' => 'varchar',
|
||||
'length' => '128',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'entity_id' => array(
|
||||
'description' => 'The unique ID of the object, such as either the {cid}, {uid}, or {nid}.',
|
||||
'description' => 'The unique ID of the flagged entity, for example the uid, cid, or nid.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
@@ -166,14 +166,14 @@ function flag_schema() {
|
||||
'default' => 0,
|
||||
),
|
||||
'entity_type' => array(
|
||||
'description' => 'The flag type, usually one of "node", "comment", "user".',
|
||||
'description' => 'The flag type, for example "node", "comment", or "user".',
|
||||
'type' => 'varchar',
|
||||
'length' => '128',
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'entity_id' => array(
|
||||
'description' => 'The unique ID of the content, usually either the {cid}, {uid}, or {nid}.',
|
||||
'description' => 'The unique ID of the flagged entity, for example the uid, cid, or nid.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
@@ -508,30 +508,14 @@ function flag_update_7303() {
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
// Keys spec. Some are short-lived, as they are about to be dropped again
|
||||
// and have hybrid names that refer to 'content_id' still.
|
||||
// Keys spec.
|
||||
array(
|
||||
'unique keys' => array(
|
||||
'fid_content_id_uid_sid' => array('fid', 'content_id', 'uid', 'sid'),
|
||||
),
|
||||
'indexes' => array(
|
||||
'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
|
||||
'entity_type_content_id_uid_sid' => array(
|
||||
'entity_type',
|
||||
'content_id',
|
||||
'uid',
|
||||
'sid',
|
||||
),
|
||||
'content_id_fid' => array('content_id', 'fid'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Now we have to drop keys and indexes all over again!
|
||||
db_drop_unique_key('flagging', 'fid_content_id_uid_sid');
|
||||
db_drop_index('flagging', 'entity_type_content_id_uid_sid');
|
||||
db_drop_index('flagging', 'content_id_fid');
|
||||
|
||||
// Change field 'content_id' to 'entity_id'.
|
||||
db_change_field('flagging', 'content_id', 'entity_id',
|
||||
// Spec of the field. Identical to our current hook_schema(): we're not
|
||||
@@ -542,23 +526,11 @@ function flag_update_7303() {
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
// Keys spec. Identical to current hook_schema().
|
||||
array(
|
||||
'unique keys' => array(
|
||||
'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
|
||||
),
|
||||
'indexes' => array(
|
||||
'entity_type_entity_id_uid_sid' => array(
|
||||
'entity_type',
|
||||
'entity_id',
|
||||
'uid',
|
||||
'sid',
|
||||
),
|
||||
'entity_id_fid' => array('entity_id', 'fid'),
|
||||
),
|
||||
)
|
||||
);
|
||||
db_add_unique_key('flagging', 'fid_entity_id_uid_sid', array('fid', 'entity_id', 'uid', 'sid'));
|
||||
db_add_index('flagging', 'entity_type_entity_id_uid_sid', array('entity_type', 'entity_id', 'uid', 'sid'));
|
||||
db_add_index('flagging', 'entity_id_fid', array('entity_id', 'fid'));
|
||||
|
||||
// A serial field must be defined as a key, so make a temporary index on
|
||||
// 'fcid' so we can safely drop the primary key.
|
||||
|
@@ -37,20 +37,25 @@ function flag_entity_info() {
|
||||
),
|
||||
);
|
||||
|
||||
// Add bundle info but bypass flag_get_flags() as we cannot use it here, as
|
||||
// it calls entity_get_info().
|
||||
$result = db_query("SELECT name, title FROM {flag}");
|
||||
$flag_names = $result->fetchAllKeyed();
|
||||
foreach ($flag_names as $flag_name => $flag_title) {
|
||||
$return['flagging']['bundles'][$flag_name] = array(
|
||||
'label' => $flag_title,
|
||||
'admin' => array(
|
||||
'path' => FLAG_ADMIN_PATH . '/manage/%flag',
|
||||
'real path' => FLAG_ADMIN_PATH . '/manage/' . $flag_name,
|
||||
'bundle argument' => FLAG_ADMIN_PATH_START + 1,
|
||||
'access arguments' => array('administer flags'),
|
||||
),
|
||||
);
|
||||
// Check for our table before we query it. This is a workaround for a core
|
||||
// bug: https://www.drupal.org/node/1311820
|
||||
// TODO: Remove this when that bug is fixed.
|
||||
if (db_table_exists('flag')) {
|
||||
// Add bundle info but bypass flag_get_flags() as we cannot use it here, as
|
||||
// it calls entity_get_info().
|
||||
$result = db_query("SELECT name, title FROM {flag}");
|
||||
$flag_names = $result->fetchAllKeyed();
|
||||
foreach ($flag_names as $flag_name => $flag_title) {
|
||||
$return['flagging']['bundles'][$flag_name] = array(
|
||||
'label' => $flag_title,
|
||||
'admin' => array(
|
||||
'path' => FLAG_ADMIN_PATH . '/manage/%flag',
|
||||
'real path' => FLAG_ADMIN_PATH . '/manage/' . $flag_name,
|
||||
'bundle argument' => FLAG_ADMIN_PATH_START + 1,
|
||||
'access arguments' => array('administer flags'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
@@ -59,12 +64,12 @@ function flag_entity_info() {
|
||||
/**
|
||||
* Loads a flagging entity.
|
||||
*
|
||||
* @param $flagging_id
|
||||
* @param int $flagging_id
|
||||
* The 'flagging_id' database serial column.
|
||||
* @param $reset
|
||||
* @param bool $reset
|
||||
* Whether to reset the DrupalDefaultEntityController cache.
|
||||
*
|
||||
* @return
|
||||
* @return stdClass
|
||||
* The entity object, or FALSE if it can't be found.
|
||||
*/
|
||||
function flagging_load($flagging_id, $reset = FALSE) {
|
||||
@@ -78,7 +83,7 @@ function flagging_load($flagging_id, $reset = FALSE) {
|
||||
*
|
||||
* Creates an unsaved flagging object for use with $flag->flag().
|
||||
*
|
||||
* @param $values
|
||||
* @param array $values
|
||||
* An array of values as described by the entity's property info. Only
|
||||
* 'flag_name' or 'fid' must be specified, since $flag->flag() does the rest.
|
||||
*
|
||||
@@ -149,12 +154,6 @@ function flagging_save($flagging) {
|
||||
|
||||
// @todo: Implement flagging_view(). Not extremely useful. I already have it.
|
||||
|
||||
// @todo: When renaming a flag: Call field_attach_rename_bundle().
|
||||
|
||||
// @todo: When creating a flag: Call field_attach_create_bundle().
|
||||
|
||||
// @todo: When deleting a flag: Call field_attach_delete_bundle().
|
||||
|
||||
// @tood: Discuss: Should flag deleting call flag_reset_flag()? No.
|
||||
|
||||
// @todo: flag_reset_flag():
|
||||
@@ -199,6 +198,21 @@ function flag_entity_query_alter(EntityFieldQuery $query) {
|
||||
* @see flag_entity_query_alter()
|
||||
*/
|
||||
function flag_query_flagging_flag_names_alter(QueryAlterableInterface $query) {
|
||||
// Queries with this tag need to have the {flag} table joined on so they can
|
||||
// have a condition on the flag name.
|
||||
// However, we need to ensure the {flagging} table is there to join from. Not
|
||||
// all instances of EntityFieldQuery will add it; for example, with only a
|
||||
// field condition the entity base table is not added to the SelectQuery.
|
||||
$tables =& $query->getTables();
|
||||
if (!isset($tables['flagging'])) {
|
||||
// All tables that are in the query will be field tables and are equivalent,
|
||||
// so just join on the first one.
|
||||
$field_table = reset($tables);
|
||||
$field_table_alias = $field_table['alias'];
|
||||
|
||||
$query->join('flagging', 'flagging', "$field_table_alias.entity_id = flagging.fid");
|
||||
}
|
||||
|
||||
// Get value and operator for bundle condition from meta data.
|
||||
$value = $query->getMetaData('flag_name_value');
|
||||
$operator = $query->getMetaData('flag_name_operator');
|
||||
@@ -261,7 +275,6 @@ function flag_menu() {
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('administer flags'),
|
||||
'file' => 'includes/flag.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
// Make the flag title the default title for descendant menu items.
|
||||
'title callback' => '_flag_menu_title',
|
||||
'title arguments' => array(FLAG_ADMIN_PATH_START + 1),
|
||||
@@ -306,8 +319,8 @@ function flag_menu() {
|
||||
'title' => 'Flag',
|
||||
'page callback' => 'flag_page',
|
||||
'page arguments' => array(1, 2, 3),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access content'),
|
||||
'access callback' => 'flag_page_access',
|
||||
'access arguments' => array(1, 2, 3),
|
||||
'file' => 'includes/flag.pages.inc',
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
@@ -315,8 +328,8 @@ function flag_menu() {
|
||||
'title' => 'Flag confirm',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('flag_confirm', 2, 3, 4),
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access content'),
|
||||
'access callback' => 'flag_page_access',
|
||||
'access arguments' => array(2, 3, 4),
|
||||
'file' => 'includes/flag.pages.inc',
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
@@ -324,6 +337,19 @@ function flag_menu() {
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu access callback for flagging pages.
|
||||
*
|
||||
* Same parameters as flag_page().
|
||||
*
|
||||
* @see flag_page()
|
||||
* @see flag_confirm()
|
||||
*/
|
||||
function flag_page_access($action, $flag, $entity_id) {
|
||||
$access = $flag->access($entity_id, $action);
|
||||
return $access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_admin_menu_map().
|
||||
*/
|
||||
@@ -348,9 +374,9 @@ function flag_admin_menu_map() {
|
||||
/**
|
||||
* Menu loader for '%flag' arguments.
|
||||
*
|
||||
* @param $flag_name
|
||||
* @param string $flag_name
|
||||
* The machine name of the flag.
|
||||
* @param $include_disabled
|
||||
* @param bool $include_disabled
|
||||
* (optional) Whether to return a disabled flag too. Normally only enabled
|
||||
* flags are returned. Some menu items operate on disabled flags and in this
|
||||
* case you need to turn on this switch by doing:
|
||||
@@ -489,7 +515,7 @@ function flag_hook_info() {
|
||||
/**
|
||||
* Get a flag type definition.
|
||||
*
|
||||
* @param $entity_type
|
||||
* @param string $entity_type
|
||||
* (optional) The entity type to get the definition for, or NULL to return
|
||||
* all flag types.
|
||||
*
|
||||
@@ -1386,7 +1412,7 @@ function flag_flag_access($flag, $entity_id, $action, $account) {
|
||||
if ($flag->entity_type == 'comment') {
|
||||
// For non-existent comments (such as on the comment add form), assume that
|
||||
// the current user is creating the content.
|
||||
if (empty($entity_id) || !($comment = $flag->fetch_entity($entity_id))) {
|
||||
if (empty($entity_id) || !($comment = $flag->fetch_entity($entity_id)) || $entity_id == 'new') {
|
||||
return $flag->access_author == 'comment_others' ? FALSE : NULL;
|
||||
}
|
||||
|
||||
@@ -1676,7 +1702,11 @@ function _flag_link_type_descriptions() {
|
||||
// Non-Views public API
|
||||
|
||||
/**
|
||||
* Get the count of flags for a particular entity type.
|
||||
* Gets the count of flaggings for the given flag.
|
||||
*
|
||||
* For example, if you have an 'endorse' flag, this method will tell you how
|
||||
* many endorsements have been made, rather than how many things have been
|
||||
* endorsed.
|
||||
*
|
||||
* When called during a flagging or unflagging (such as from a hook
|
||||
* implementation or from Rules), the flagging or unflagging that is in the
|
||||
@@ -1692,8 +1722,8 @@ function _flag_link_type_descriptions() {
|
||||
* @param $entity_type
|
||||
* The entity type. For example, 'node'.
|
||||
*
|
||||
* @return
|
||||
* The flag count with the flag name and entity type as the array key.
|
||||
* @return int
|
||||
* The number of flaggings for the flag.
|
||||
*/
|
||||
function flag_get_entity_flag_counts($flag, $entity_type) {
|
||||
$counts = &drupal_static(__FUNCTION__);
|
||||
@@ -1716,7 +1746,10 @@ function flag_get_entity_flag_counts($flag, $entity_type) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's flag count.
|
||||
* Gets the count of the flaggings made by a user with a flag.
|
||||
*
|
||||
* For example, with a 'bookmarks' flag, this returns the number of bookmarks
|
||||
* a user has created.
|
||||
*
|
||||
* When called during a flagging or unflagging (such as from a hook
|
||||
* implementation or from Rules), the flagging or unflagging that is in the
|
||||
@@ -1727,13 +1760,15 @@ function flag_get_entity_flag_counts($flag, $entity_type) {
|
||||
* This is because this queries the {flagging} table, which only has its record
|
||||
* deleted at the very end of the unflagging process.
|
||||
*
|
||||
* However, it should be noted that this method does not serves global flags.
|
||||
*
|
||||
* @param $flag
|
||||
* The flag.
|
||||
* @param $user
|
||||
* The user object.
|
||||
*
|
||||
* @return
|
||||
* The flag count with the flag name and the uid as the array key.
|
||||
* @return int
|
||||
* The number of flaggings for the given flag and user.
|
||||
*/
|
||||
function flag_get_user_flag_counts($flag, $user) {
|
||||
$counts = &drupal_static(__FUNCTION__);
|
||||
@@ -1756,7 +1791,18 @@ function flag_get_user_flag_counts($flag, $user) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get flag counts for all flags on a node.
|
||||
* Gets flag counts for all flags on an entity.
|
||||
*
|
||||
* Provides a count of all the flaggings for a single entity. Instead
|
||||
* of a single response, this method returns an array of counts keyed by
|
||||
* the flag ID:
|
||||
*
|
||||
* @code
|
||||
* array(
|
||||
* my_flag => 42
|
||||
* another_flag => 57
|
||||
* );
|
||||
* @endcode
|
||||
*
|
||||
* When called during a flagging or unflagging (such as from a hook
|
||||
* implementation or from Rules), the count this returns takes into account the
|
||||
@@ -1767,8 +1813,10 @@ function flag_get_user_flag_counts($flag, $user) {
|
||||
* @param $entity_id
|
||||
* The entity ID (usually the node ID).
|
||||
*
|
||||
* @return
|
||||
* The flag count with the flag names as array keys.
|
||||
* @return array
|
||||
* An array giving the counts of all flaggings on the entity. The flag IDs
|
||||
* are the keys and the counts for each flag the values. Note that flags
|
||||
* that have no flaggings are not included in the array.
|
||||
*/
|
||||
function flag_get_counts($entity_type, $entity_id) {
|
||||
$counts = &drupal_static(__FUNCTION__);
|
||||
@@ -1792,7 +1840,12 @@ function flag_get_counts($entity_type, $entity_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total count of items flagged within a flag.
|
||||
* Gets the count of entities flagged by the given flag.
|
||||
*
|
||||
* For example, with a 'report abuse' flag, this returns the number of
|
||||
* entities that have been reported, not the total number of reports. In other
|
||||
* words, an entity that has been reported multiple times will only be counted
|
||||
* once.
|
||||
*
|
||||
* When called during a flagging or unflagging (such as from a hook
|
||||
* implementation or from Rules), the count this returns takes into account the
|
||||
@@ -1802,6 +1855,9 @@ function flag_get_counts($entity_type, $entity_id) {
|
||||
* The flag name for which to retrieve a flag count.
|
||||
* @param $reset
|
||||
* (optional) Reset the internal cache and execute the SQL query another time.
|
||||
*
|
||||
* @return int
|
||||
* The number of entities that are flagged with the flag.
|
||||
*/
|
||||
function flag_get_flag_counts($flag_name, $reset = FALSE) {
|
||||
$counts = &drupal_static(__FUNCTION__);
|
||||
@@ -1853,8 +1909,7 @@ function flag_get_flag($name = NULL, $fid = NULL) {
|
||||
/**
|
||||
* List all flags available.
|
||||
*
|
||||
* If node type or account are entered, a list of all possible flags will be
|
||||
* returned.
|
||||
* If all the parameters are omitted, a list of all flags will be returned.
|
||||
*
|
||||
* @param $entity_type
|
||||
* (optional) The type of entity for which to load the flags. Usually 'node'.
|
||||
@@ -1865,7 +1920,7 @@ function flag_get_flag($name = NULL, $fid = NULL) {
|
||||
* flags for will this node will be returned.
|
||||
*
|
||||
* @return
|
||||
* An array of the structure [fid] = flag_object.
|
||||
* An array of flag objects, keyed by the flag names.
|
||||
*/
|
||||
function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account = NULL) {
|
||||
$flags = &drupal_static(__FUNCTION__);
|
||||
@@ -2545,6 +2600,21 @@ function flag_ctools_plugin_directory($module, $plugin) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_attach_rename_bundle().
|
||||
*/
|
||||
function flag_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
|
||||
$flags = flag_get_flags($entity_type);
|
||||
foreach ($flags as $flag) {
|
||||
foreach ($flag->types as $key => $type) {
|
||||
if ($type == $bundle_old) {
|
||||
$flag->types[$key] = $bundle_new;
|
||||
}
|
||||
}
|
||||
$flag->save();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Entity Metadata callbacks
|
||||
|
||||
|
@@ -83,6 +83,11 @@ function flag_token_info() {
|
||||
if (module_exists('token')) {
|
||||
$entity_info = entity_get_info();
|
||||
foreach (flag_get_types() as $flag_type) {
|
||||
// If the flag type is not an entity type then skip.
|
||||
if (!isset($entity_info[$flag_type])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// The flag type is the entity type, but this is not necessarily the same
|
||||
// as the entity's token type.
|
||||
$token_type = $entity_info[$flag_type]['token type'];
|
||||
@@ -201,7 +206,7 @@ function flag_tokens($type, $tokens, array $data = array(), array $options = arr
|
||||
/**
|
||||
* Returns HTML for a tokens browser.
|
||||
*
|
||||
* @param $variables
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - types: An array naming the types of tokens to show.
|
||||
* - global_types: Whether to show global tokens.
|
||||
@@ -211,7 +216,7 @@ function theme_flag_tokens_browser($variables) {
|
||||
$global_types = $variables['global_types'];
|
||||
|
||||
if (module_exists('token')) {
|
||||
return theme('token_tree', array('token_types' => $types, 'global_types' => $global_types));
|
||||
return theme('token_tree', array('token_types' => $types, 'global_types' => $global_types, 'dialog' => TRUE));
|
||||
}
|
||||
else {
|
||||
return '<p><em>' . t("Note: You don't have the <a href='@token-url'>Token</a> module installed, so the list of available tokens isn't shown here. You don't have to install <a href='@token-url'>Token</a> to be able to use tokens, but if you have it installed, and enabled, you'll be able to enjoy an interactive tokens browser.", array('@token-url' => 'http://drupal.org/project/token')) . '</em></p>';
|
||||
|
@@ -5,11 +5,9 @@ dependencies[] = flag
|
||||
package = Flags
|
||||
configure = admin/structure/flags/actions
|
||||
|
||||
files[] = flag.install
|
||||
files[] = flag_actions.module
|
||||
; Information added by Drupal.org packaging script on 2015-03-02
|
||||
version = "7.x-3.6"
|
||||
; Information added by Drupal.org packaging script on 2016-09-23
|
||||
version = "7.x-3.9"
|
||||
core = "7.x"
|
||||
project = "flag"
|
||||
datestamp = "1425327793"
|
||||
datestamp = "1474619065"
|
||||
|
||||
|
@@ -136,17 +136,17 @@ function flag_actions_get_actions($flag_name = NULL, $reset = FALSE) {
|
||||
/**
|
||||
* Insert a new flag action.
|
||||
*
|
||||
* @param $fid
|
||||
* @param int $fid
|
||||
* The flag object ID.
|
||||
* @param $event
|
||||
* @param string $event
|
||||
* The flag event, such as "flag" or "unflag".
|
||||
* @param $threshold
|
||||
* @param int $threshold
|
||||
* The flagging threshold at which this action will be executed.
|
||||
* @param $repeat_threshold
|
||||
* @param int $repeat_threshold
|
||||
* The number of additional flaggings after which the action will be repeated.
|
||||
* @param $callback
|
||||
* @param string $callback
|
||||
* The action callback to be executed.
|
||||
* @param $parameters
|
||||
* @param array $parameters
|
||||
* The action parameters.
|
||||
*/
|
||||
function flag_actions_insert_action($fid, $event, $threshold, $repeat_threshold, $callback, $parameters) {
|
||||
@@ -165,15 +165,15 @@ function flag_actions_insert_action($fid, $event, $threshold, $repeat_threshold,
|
||||
/**
|
||||
* Update an existing flag action.
|
||||
*
|
||||
* @param $aid
|
||||
* @param int $aid
|
||||
* The flag action ID to update.
|
||||
* @param $event
|
||||
* @param string $event
|
||||
* The flag event, such as "flag" or "unflag".
|
||||
* @param $threshold
|
||||
* @param int $threshold
|
||||
* The flagging threshold at which this action will be executed.
|
||||
* @param $repeat_threshold
|
||||
* @param int $repeat_threshold
|
||||
* The number of additional flaggings after which the action will be repeated.
|
||||
* @param $parameters
|
||||
* @param array $parameters
|
||||
* The action parameters.
|
||||
*/
|
||||
function flag_actions_update_action($aid, $event, $threshold, $repeat_threshold, $parameters) {
|
||||
@@ -191,7 +191,7 @@ function flag_actions_update_action($aid, $event, $threshold, $repeat_threshold,
|
||||
/**
|
||||
* Delete a flag action.
|
||||
*
|
||||
* @param $aid
|
||||
* @param int $aid
|
||||
* The flag action ID to delete.
|
||||
*/
|
||||
function flag_actions_delete_action($aid) {
|
||||
@@ -393,9 +393,9 @@ function theme_flag_actions_add_form($variables) {
|
||||
*
|
||||
* @param $form_state
|
||||
* The form state.
|
||||
* @param $aid
|
||||
* @param int|NULL $aid
|
||||
* If editing an action, an action ID must be passed in.
|
||||
* @param $flag_name
|
||||
* @param string|NULL $flag_name
|
||||
* If adding a new action to a flag, a flag name must be specified.
|
||||
*/
|
||||
function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL) {
|
||||
|
@@ -3,10 +3,11 @@ description = Provides an example bookmark flag and supporting views.
|
||||
core = 7.x
|
||||
dependencies[] = flag
|
||||
package = Flags
|
||||
files[] = plugins/flag_bookmark_plugin_validate_user.inc
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-03-02
|
||||
version = "7.x-3.6"
|
||||
; Information added by Drupal.org packaging script on 2016-09-23
|
||||
version = "7.x-3.9"
|
||||
core = "7.x"
|
||||
project = "flag"
|
||||
datestamp = "1425327793"
|
||||
datestamp = "1474619065"
|
||||
|
||||
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views plugins for the flag bookmark module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_plugins().
|
||||
*/
|
||||
function flag_bookmark_views_plugins() {
|
||||
return array(
|
||||
'argument validator' => array(
|
||||
'flag_bookmark_plugin_owner_perm' => array(
|
||||
'title' => t("Current user ID matches argument value"),
|
||||
'handler' => 'flag_bookmark_plugin_validate_user',
|
||||
'path' => drupal_get_path('module', 'flag_bookmark') . '/plugins',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
@@ -168,12 +168,13 @@ function flag_bookmark_views_default_views() {
|
||||
'default_action' => 'empty',
|
||||
'style_plugin' => 'default_summary',
|
||||
'style_options' => array(),
|
||||
'wildcard' => 'all',
|
||||
'wildcard_substitution' => 'All',
|
||||
'exception' => array(
|
||||
'value' => '',
|
||||
),
|
||||
'title' => '%1\'s bookmarks',
|
||||
'default_argument_type' => 'fixed',
|
||||
'default_argument' => '',
|
||||
'validate_type' => 'none',
|
||||
'validate_type' => 'flag_bookmark_plugin_owner_perm',
|
||||
'validate_fail' => 'not found',
|
||||
'break_phrase' => 0,
|
||||
'not' => 0,
|
||||
|
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains the Flag Bookmark view argument validator.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validates whether an argument is a valid UID.
|
||||
*
|
||||
* @ingroup views
|
||||
*/
|
||||
class flag_bookmark_plugin_validate_user extends views_plugin_argument_validate_user {
|
||||
|
||||
/**
|
||||
* Define the options for the plugin, including the default permission.
|
||||
* @return multitype:string
|
||||
*/
|
||||
function option_definition() {
|
||||
// Initialize the base class.
|
||||
$options = parent::option_definition();
|
||||
|
||||
// Set the default permission.
|
||||
$options['bypass_perm'] = array('default' => 'administer users');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a option form for the plugin.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
// Get the options form from the base class.
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$perms = array();
|
||||
$module_info = system_get_info('module');
|
||||
|
||||
$perms[] = t(' - None - ');
|
||||
|
||||
// Produce an array of permissions keyed by module name.
|
||||
foreach (module_implements('permission') as $module) {
|
||||
$permissions = module_invoke($module, 'permission');
|
||||
foreach ($permissions as $name => $perm) {
|
||||
$perms[$module_info[$module]['name']][$name] = strip_tags($perm['title']);
|
||||
}
|
||||
}
|
||||
|
||||
asort($perms);
|
||||
|
||||
// Create the form field for the validator. Returned by reference.
|
||||
$form['bypass_perm'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $perms,
|
||||
'#title' => t('Override permission'),
|
||||
'#default_value' => $this->options['bypass_perm'],
|
||||
'#description' => t('Users with this permission bypass the argument check and are granted access.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the argument to be a proper UID.
|
||||
* @param mixed $argument
|
||||
* @return boolean
|
||||
*/
|
||||
function validate_argument($argument) {
|
||||
// The parent class takes care of all its options, returning TRUE if the
|
||||
// argument value validates to a user account, and an account that has the
|
||||
// required role.
|
||||
$argument_validates = parent::validate_argument($argument);
|
||||
|
||||
// If the parent didn't validate the argument, then we certainly can't
|
||||
// either.
|
||||
if ($argument_validates == FALSE) {
|
||||
return $argument_validates;
|
||||
}
|
||||
|
||||
// If the current user has the bypass permission, then we're done: return
|
||||
// the validation status we got from the parent.
|
||||
if (!empty($this->options['bypass_perm']) && user_access($this->options['bypass_perm'])) {
|
||||
return $argument_validates;
|
||||
}
|
||||
|
||||
// Otherwise, perform our additional check to enforce that the argument
|
||||
// user ID is the current user.
|
||||
// The parent method has stored the uid from the argument.
|
||||
return ($this->argument->argument == $GLOBALS['user']->uid);
|
||||
}
|
||||
|
||||
}
|
@@ -179,7 +179,7 @@ function flag_user_action_submit($form, $form_state) {
|
||||
*
|
||||
* @param $context
|
||||
* The current action context.
|
||||
* @param $entity_type
|
||||
* @param string $entity_type
|
||||
* The entity type applicable to this action, such as "node" or "comment".
|
||||
*/
|
||||
function flag_action_form($context, $entity_type) {
|
||||
|
@@ -232,7 +232,7 @@ function theme_flag_admin_page($variables) {
|
||||
/**
|
||||
* Menu callback for adding a new flag.
|
||||
*
|
||||
* @param $entity_type
|
||||
* @param string|NULL $entity_type
|
||||
* The entity type for the new flag, taken from the path argument. If not
|
||||
* present (i.e., '/add'), a form showing all possible flag types is shown.
|
||||
* Otherwise, this shows a form for adding af flag the given type.
|
||||
@@ -401,7 +401,7 @@ function flag_form($form, &$form_state, $flag) {
|
||||
t('Add this [node:type] to your favorites'),
|
||||
t('Vote for this proposal ([node:flag-vote-count] people have already done so)'),
|
||||
),
|
||||
'attributes' => array('class' => 'token-examples'),
|
||||
'attributes' => array('class' => array('token-examples')),
|
||||
)) .
|
||||
'<p>' . t('These tokens will be replaced with the appropriate fields from the node (or user, or comment).') . '</p>' .
|
||||
theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types())),
|
||||
@@ -693,19 +693,26 @@ function flag_form_submit($form, &$form_state) {
|
||||
// We clear caches more vigorously if the flag was new.
|
||||
_flag_clear_cache($flag->entity_type, !empty($flag->is_new));
|
||||
|
||||
if (!empty($flag->is_new)) {
|
||||
field_attach_create_bundle('flagging', $flag->name);
|
||||
}
|
||||
|
||||
// Save permissions.
|
||||
// This needs to be done after the flag cache has been cleared, so that
|
||||
// the new permissions are picked up by hook_permission().
|
||||
// This may need to move to the flag class when we implement extra permissions
|
||||
// for different flag types: http://drupal.org/node/879988
|
||||
|
||||
// If the flag machine name as changed, clean up all the obsolete permissions.
|
||||
// If the flag machine name as changed, clean up all the obsolete permissions
|
||||
// and notify FieldAPI.
|
||||
if ($flag->name != $form['#flag_name']) {
|
||||
$old_name = $form['#flag_name'];
|
||||
$permissions = array("flag $old_name", "unflag $old_name");
|
||||
foreach (array_keys(user_roles()) as $rid) {
|
||||
user_role_revoke_permissions($rid, $permissions);
|
||||
}
|
||||
|
||||
field_attach_rename_bundle('flagging', $old_name, $flag->name);
|
||||
}
|
||||
|
||||
foreach (array_keys(user_roles(!module_exists('session_api'))) as $rid) {
|
||||
@@ -796,9 +803,9 @@ function flag_check_link_types($element) {
|
||||
/**
|
||||
* Clears various caches when one or more flags are modified.
|
||||
*
|
||||
* @param $entity_types
|
||||
* @param string|array $entity_types
|
||||
* The entity types for the flags. May be a single value or an array.
|
||||
* @param $is_insert_or_delete
|
||||
* @param bool $is_insert_or_delete
|
||||
* Whether the modified flag is being inserted (saved for the first time) or
|
||||
* deleted. This results in a more vigorous clearing of caches. In
|
||||
* particular, when no flags exist yet, no Field admin UI paths exist and these
|
||||
|
@@ -8,9 +8,9 @@
|
||||
/**
|
||||
* Export a flag to code.
|
||||
*
|
||||
* @param $flags
|
||||
* @param array $flags
|
||||
* An array of flag objects, or flag name.
|
||||
* @param $module
|
||||
* @param string $module
|
||||
* Optional. The name of the module that will be created if exporting to use
|
||||
* in hook_flag_default_flags().
|
||||
*/
|
||||
@@ -247,7 +247,7 @@ function flag_update_page($flag) {
|
||||
/**
|
||||
* Update a flag before export.
|
||||
*
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* The flag object passed by reference.
|
||||
*/
|
||||
function flag_update_export(&$flag) {
|
||||
|
@@ -71,7 +71,7 @@ function flag_features_export_render($module, $data) {
|
||||
/**
|
||||
* Implements hook_features_revert().
|
||||
*
|
||||
* @param $module
|
||||
* @param string $module
|
||||
* The name of module for which to revert content.
|
||||
*/
|
||||
function flag_features_revert($module = NULL) {
|
||||
|
@@ -75,11 +75,11 @@ function flag_page($action, $flag, $entity_id) {
|
||||
/**
|
||||
* Form for confirming the (un)flagging of an entity.
|
||||
*
|
||||
* @param $action
|
||||
* @param string $action
|
||||
* Either 'flag' or 'unflag'.
|
||||
* @param $flag
|
||||
* @param flag_flag $flag
|
||||
* A loaded flag object.
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The id of the entity to operate on. The type is implicit in the flag.
|
||||
*
|
||||
* @see flag_confirm_submit()
|
||||
|
@@ -69,6 +69,86 @@ class flag_comment extends flag_entity {
|
||||
return $comment->cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides flag_flag::get_flagging_record().
|
||||
*
|
||||
* This queries for flagging records for all comments on the node for the
|
||||
* current comment, and prefills the flag_get_user_flags() static cache with
|
||||
* the result for a performance gain.
|
||||
*/
|
||||
function get_flagging_record($entity_id, $uid = NULL, $sid = NULL) {
|
||||
static $seen_comment_nids = array();
|
||||
|
||||
$comment = $this->fetch_entity($entity_id);
|
||||
|
||||
// Figure out if this is the first comment we've seen for its parent node.
|
||||
if (!isset($seen_comment_nids[$comment->nid])) {
|
||||
// Preload the flag_get_user_flags() static cache with flagging records
|
||||
// for all the comments on the node. This means that if multiple comments
|
||||
// on this node are being viewed, only one query is run for all their
|
||||
// flagging records, rather than one for each comment. This is because
|
||||
// flag_get_user_flags() can only optimized across flags on one entity.
|
||||
$flag_get_user_flags_cache = &drupal_static('flag_get_user_flags');
|
||||
|
||||
// We need to get a row for each comment, including empty ones if there is
|
||||
// no flagging, so that the cache is warmed up for all comments. Therefore
|
||||
// the query has to have the {comment} table as its base, and include the
|
||||
// comment cid field.
|
||||
$query = db_select('comment', 'c');
|
||||
$query->leftJoin('flagging', 'f',
|
||||
"c.cid = f.entity_id AND f.entity_type = 'comment'");
|
||||
$query->fields('f')
|
||||
->fields('c', array('cid'))
|
||||
->condition('c.nid', $comment->nid)
|
||||
->condition(db_or()
|
||||
// We want to include rows for comments which have no flaggings at all
|
||||
// for the current user.
|
||||
->isNull('f.flagging_id')
|
||||
// The same conditions as flag_get_user_flags()'s query.
|
||||
->condition(db_and()
|
||||
->condition(db_or()
|
||||
->condition('f.uid', $uid)
|
||||
->condition('f.uid', 0)
|
||||
)
|
||||
->condition('f.sid', $sid)
|
||||
)
|
||||
);
|
||||
|
||||
// The result set can have multiple rows for a single comment, and rows
|
||||
// which have no flagging ID, so there's nothing useful to index it by.
|
||||
$result = $query->execute()->fetchAll();
|
||||
|
||||
$flag_names = _flag_get_flag_names();
|
||||
foreach ($result as $flagging_data) {
|
||||
$cid = $flagging_data->cid;
|
||||
|
||||
// At the very least, we need an empty array for the entity ID key in
|
||||
// the cache array, so it counts as present.
|
||||
if (!isset($flag_get_user_flags_cache[$uid][$sid]['comment'][$cid])) {
|
||||
$flag_get_user_flags_cache[$uid][$sid]['comment'][$cid] = array();
|
||||
}
|
||||
|
||||
// If the flagging table gave us no data, we're done with this row.
|
||||
if (is_null($flagging_data->flagging_id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove the comment ID field from the row, so it's just the flagging
|
||||
// table row.
|
||||
unset($flagging_data->cid);
|
||||
|
||||
$flag_get_user_flags_cache[$uid][$sid]['comment'][$cid][$flag_names[$flagging_data->fid]] = $flagging_data;
|
||||
}
|
||||
|
||||
// Mark that we've seen this node so we don't process it again.
|
||||
$seen_comment_nids[$comment->nid] = TRUE;
|
||||
}
|
||||
|
||||
// Return data for the comment we were asked about.
|
||||
$user_flags = flag_get_user_flags($this->entity_type, $entity_id, $uid, $sid);
|
||||
return isset($user_flags[$this->name]) ? $user_flags[$this->name] : NULL;
|
||||
}
|
||||
|
||||
function get_labels_token_types() {
|
||||
return array_merge(array('comment', 'node'), parent::get_labels_token_types());
|
||||
}
|
||||
|
@@ -370,9 +370,9 @@ class flag_flag {
|
||||
* an object that hasn't yet been saved to the database. Subsequent calls to
|
||||
* fetch_entity() return the remembered object.
|
||||
*
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The ID of the object to cache.
|
||||
* @param $object
|
||||
* @param stdClass $object
|
||||
* The object to cache.
|
||||
*/
|
||||
function remember_entity($entity_id, $object) {
|
||||
@@ -430,13 +430,13 @@ class flag_flag {
|
||||
/**
|
||||
* Determines whether the user has the permission to use this flag.
|
||||
*
|
||||
* @param $action
|
||||
* @param string $action
|
||||
* (optional) The action to test, either "flag" or "unflag". If none given,
|
||||
* "flag" will be tested, which is the minimum permission to use a flag.
|
||||
* @param $account
|
||||
* (optional) The user object. If none given, the current user will be used.
|
||||
*
|
||||
* @return
|
||||
* @return bool
|
||||
* Boolean TRUE if the user is allowed to flag/unflag. FALSE otherwise.
|
||||
*
|
||||
* @see flag_permission()
|
||||
@@ -461,16 +461,16 @@ class flag_flag {
|
||||
* This method typically should not be overridden by child classes. Instead
|
||||
* they should implement type_access(), which is called by this method.
|
||||
*
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The entity ID to flag/unflag.
|
||||
* @param $action
|
||||
* @param string|NULL $action
|
||||
* The action to test. Either 'flag' or 'unflag'. Leave NULL to determine
|
||||
* by flag status.
|
||||
* @param $account
|
||||
* @param stdClass $account
|
||||
* The user on whose behalf to test the flagging action. Leave NULL for the
|
||||
* current user.
|
||||
*
|
||||
* @return
|
||||
* @return bool
|
||||
* Boolean TRUE if the user is allowed to flag/unflag the given entity.
|
||||
* FALSE otherwise.
|
||||
*/
|
||||
@@ -530,14 +530,14 @@ class flag_flag {
|
||||
* they should implement type_access_multiple(), which is called by this
|
||||
* method.
|
||||
*
|
||||
* @param $entity_ids
|
||||
* @param array $entity_ids
|
||||
* The array of entity IDs to check. The keys are the entity IDs, the
|
||||
* values are the actions to test: either 'flag' or 'unflag'.
|
||||
* @param $account
|
||||
* @param stdClass $account
|
||||
* (optional) The account for which the actions will be compared against.
|
||||
* If left empty, the current user will be used.
|
||||
*
|
||||
* @return
|
||||
* @return array
|
||||
* An array whose keys are the object IDs and values are booleans indicating
|
||||
* access.
|
||||
*
|
||||
@@ -621,9 +621,9 @@ class flag_flag {
|
||||
* Utility function: Checks whether a flag applies to a certain type, and
|
||||
* possibly subtype, of entity.
|
||||
*
|
||||
* @param $entity_type
|
||||
* @param string $entity_type
|
||||
* The type of entity being checked, such as "node".
|
||||
* @param $content_subtype
|
||||
* @param string|NULL $content_subtype
|
||||
* The subtype being checked. For entities this will be the bundle name (the
|
||||
* node type in the case of nodes).
|
||||
*
|
||||
@@ -671,13 +671,13 @@ class flag_flag {
|
||||
/**
|
||||
* Flags, or unflags, an item.
|
||||
*
|
||||
* @param $action
|
||||
* @param string $action
|
||||
* Either 'flag' or 'unflag'.
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The ID of the item to flag or unflag.
|
||||
* @param $account
|
||||
* @param string|NULL $account
|
||||
* The user on whose behalf to flag. Leave empty for the current user.
|
||||
* @param $skip_permission_check
|
||||
* @param bool $skip_permission_check
|
||||
* Flag the item even if the $account user don't have permission to do so.
|
||||
* @param $flagging
|
||||
* (optional) This method works in tandem with Drupal's Field subsystem.
|
||||
@@ -695,7 +695,7 @@ class flag_flag {
|
||||
* to take care of Field API validation, using either
|
||||
* field_attach_form_validate() or field_attach_validate().
|
||||
*
|
||||
* @return
|
||||
* @return bool
|
||||
* FALSE if some error occured (e.g., user has no permission, flag isn't
|
||||
* applicable to the item, etc.), TRUE otherwise.
|
||||
*/
|
||||
@@ -769,21 +769,30 @@ class flag_flag {
|
||||
}
|
||||
}
|
||||
|
||||
// Perform the flagging or unflagging of this flag.
|
||||
if ($action == 'unflag') {
|
||||
if ($flagged) {
|
||||
$this->flagging_delete($flagging, $entity_id, $account);
|
||||
// Perform the flagging or unflagging of this flag
|
||||
// along with a transaction mechanism.
|
||||
$transaction = db_transaction();
|
||||
try {
|
||||
if ($action == 'unflag') {
|
||||
if ($flagged) {
|
||||
$this->flagging_delete($flagging, $entity_id, $account);
|
||||
}
|
||||
// We do nothing in the case of an attempt to unflag something that isn't
|
||||
// actually flagged.
|
||||
}
|
||||
elseif ($action == 'flag') {
|
||||
if (!$flagged) {
|
||||
$this->flagging_insert($flagging, $entity_id, $account);
|
||||
}
|
||||
else {
|
||||
$this->flagging_update($flagging, $entity_id, $account);
|
||||
}
|
||||
}
|
||||
// We do nothing in the case of an attempt to unflag something that isn't
|
||||
// actually flagged.
|
||||
}
|
||||
elseif ($action == 'flag') {
|
||||
if (!$flagged) {
|
||||
$this->flagging_insert($flagging, $entity_id, $account);
|
||||
}
|
||||
else {
|
||||
$this->flagging_update($flagging, $entity_id, $account);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$transaction->rollback();
|
||||
watchdog_exception('flag', $e);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -980,11 +989,11 @@ class flag_flag {
|
||||
* Thanks to using a cache, inquiring several different flags about the same
|
||||
* item results in only one SQL query.
|
||||
*
|
||||
* @param $uid
|
||||
* @param int $uid
|
||||
* (optional) The user ID whose flags we're checking. If none given, the
|
||||
* current user will be used.
|
||||
*
|
||||
* @return
|
||||
* @return bool
|
||||
* TRUE if the object is flagged, FALSE otherwise.
|
||||
*/
|
||||
function is_flagged($entity_id, $uid = NULL, $sid = NULL) {
|
||||
@@ -1008,7 +1017,10 @@ class flag_flag {
|
||||
$uid = $this->global ? 0 : (!isset($uid) ? $GLOBALS['user']->uid : $uid);
|
||||
$sid = $this->global ? 0 : (!isset($sid) ? flag_get_sid($uid) : $sid);
|
||||
|
||||
// flag_get_user_flags() does caching.
|
||||
// Get all the flaggings for this user on the entity from
|
||||
// flag_get_user_flags(), which will statically cache them. This means that
|
||||
// when this method is called multiple times for all the flags on an entity,
|
||||
// only the first call incurs a database query.
|
||||
$user_flags = flag_get_user_flags($this->entity_type, $entity_id, $uid, $sid);
|
||||
return isset($user_flags[$this->name]) ? $user_flags[$this->name] : NULL;
|
||||
}
|
||||
@@ -1052,9 +1064,9 @@ class flag_flag {
|
||||
/**
|
||||
* Increases the flag count for an object and clears the static counts cache.
|
||||
*
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* For which item should the count be increased.
|
||||
* @param $number
|
||||
* @param int $number
|
||||
* The amount of counts to increasing. Defaults to 1.
|
||||
*
|
||||
* @private
|
||||
@@ -1085,9 +1097,9 @@ class flag_flag {
|
||||
/**
|
||||
* Decreases the flag count for an object and clears the static counts cache.
|
||||
*
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* For which item should the count be descreased.
|
||||
* @param $number
|
||||
* @param int $number
|
||||
* The amount of counts to decrease. Defaults to 1.
|
||||
*
|
||||
* @private
|
||||
@@ -1174,13 +1186,13 @@ class flag_flag {
|
||||
* E.g., do `print $flag->get_label('title')` instead of `print
|
||||
* $flag->title`.
|
||||
*
|
||||
* @param $label
|
||||
* @param string $label
|
||||
* The label to get, e.g. 'title', 'flag_short', 'unflag_short', etc.
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The ID in whose context to interpret tokens. If not given, only global
|
||||
* tokens will be substituted.
|
||||
*
|
||||
* @return
|
||||
* @return string
|
||||
* The processed label.
|
||||
*/
|
||||
function get_label($label, $entity_id = NULL) {
|
||||
@@ -1408,6 +1420,8 @@ class flag_flag {
|
||||
* Deletes a flag from the database.
|
||||
*/
|
||||
function delete() {
|
||||
field_attach_delete_bundle('flagging', $this->name);
|
||||
|
||||
db_delete('flag')->condition('fid', $this->fid)->execute();
|
||||
db_delete('flagging')->condition('fid', $this->fid)->execute();
|
||||
db_delete('flag_types')->condition('fid', $this->fid)->execute();
|
||||
@@ -1520,18 +1534,18 @@ class flag_flag {
|
||||
* This is a wrapper around theme('flag') that channels the call to the right
|
||||
* template file.
|
||||
*
|
||||
* @param $action
|
||||
* @param string $action
|
||||
* The action the link is about to carry out, either "flag" or "unflag".
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The ID of the object to flag.
|
||||
* @param $variables = array()
|
||||
* @param array $variables
|
||||
* An array of further variables to pass to theme('flag'). For the full list
|
||||
* of parameters, see flag.tpl.php. Of particular interest:
|
||||
* - after_flagging: Set to TRUE if this flag link is being displayed as the
|
||||
* result of a flagging action.
|
||||
* - errors: An array of error messages.
|
||||
*
|
||||
* @return
|
||||
* @return string
|
||||
* The HTML for the flag link.
|
||||
*/
|
||||
function theme($action, $entity_id, $variables = array()) {
|
||||
|
@@ -87,10 +87,10 @@ class flag_node extends flag_entity {
|
||||
/**
|
||||
* Adjust the Content ID to find the translation parent if i18n-enabled.
|
||||
*
|
||||
* @param $entity_id
|
||||
* @param int $entity_id
|
||||
* The nid for the content.
|
||||
*
|
||||
* @return
|
||||
* @return int
|
||||
* The tnid if available, the nid otherwise.
|
||||
*/
|
||||
function get_translation_id($entity_id) {
|
||||
|
@@ -140,6 +140,27 @@ function flag_views_data() {
|
||||
),
|
||||
);
|
||||
|
||||
$data['flagging']['flagging_id'] = array(
|
||||
'title' => t('Flagging ID'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_numeric',
|
||||
'click sortable' => TRUE,
|
||||
'help' => t('Display the flagging ID.'),
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
'help' => t('Sort by the flagging ID.'),
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
'help' => t('Filter by the flagging ID.'),
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_numeric',
|
||||
'help' => t('The unique ID of the flagging.'),
|
||||
),
|
||||
);
|
||||
|
||||
$data['flag_counts']['count'] = array(
|
||||
'title' => t('Flag counter'),
|
||||
'help' => t('The number of times a piece of content is flagged by any user.'),
|
||||
|
@@ -40,7 +40,7 @@ class flag_handler_argument_entity_id extends views_handler_argument_numeric {
|
||||
->condition('o.' . $views_info['join field'], $this->value, 'IN')
|
||||
->execute();
|
||||
foreach ($result as $title) {
|
||||
$titles[] = check_plain($title->$views_info['title field']);
|
||||
$titles[] = check_plain($title->{$views_info['title field']});
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
@@ -13,10 +13,10 @@ abstract class FlagTestCaseBase extends DrupalWebTestCase {
|
||||
/**
|
||||
* Helper to create a flag from an array of data and clear caches etc.
|
||||
*
|
||||
* @param $flag_data
|
||||
* @param array $flag_data
|
||||
* An array of flag data.
|
||||
*
|
||||
* @return
|
||||
* @return flag_flag
|
||||
* The flag object.
|
||||
*/
|
||||
function createFlag($flag_data) {
|
||||
@@ -1656,3 +1656,129 @@ class FlagHookInvocationsTestCase extends FlagTestCaseBase {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the optimization for comment viewing.
|
||||
*/
|
||||
class FlagCommentOptimizationTestCase extends FlagTestCaseBase {
|
||||
|
||||
/**
|
||||
* Implements getInfo().
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Comment view optimization',
|
||||
'description' => 'Tests that loading of flagging records when viewing all comments on a node works correctly.',
|
||||
'group' => 'Flag',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements setUp().
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp(array(
|
||||
'flag',
|
||||
'comment',
|
||||
'flag_comment_flag_test',
|
||||
));
|
||||
|
||||
$flag_data = array(
|
||||
'entity_type' => 'comment',
|
||||
'name' => 'test_flag',
|
||||
'title' => 'Test Flag',
|
||||
'global' => 0,
|
||||
'types' => array(),
|
||||
'flag_short' => 'Flag this item',
|
||||
'flag_long' => '',
|
||||
'flag_message' => '',
|
||||
'unflag_short' => 'Unflag this item',
|
||||
'unflag_long' => '',
|
||||
'unflag_message' => '',
|
||||
'unflag_denied_text' => 'You may not unflag this item',
|
||||
'link_type' => 'normal',
|
||||
'weight' => 0,
|
||||
'show_on_form' => 0,
|
||||
'access_author' => '',
|
||||
'show_contextual_link' => 0,
|
||||
'show_in_links' => array(
|
||||
'full' => 1,
|
||||
'teaser' => 1,
|
||||
),
|
||||
'i18n' => 0,
|
||||
'api_version' => 3,
|
||||
);
|
||||
$this->flag = $this->createFlag($flag_data);
|
||||
|
||||
// Set up comments on article nodes.
|
||||
variable_set('comment_form_location_article', COMMENT_FORM_BELOW);
|
||||
|
||||
// Create test user who can flag and unflag.
|
||||
$this->user = $this->drupalCreateUser(array(
|
||||
'access comments',
|
||||
'post comments',
|
||||
'flag test_flag',
|
||||
'unflag test_flag',
|
||||
));
|
||||
$this->drupalLogin($this->user);
|
||||
|
||||
// Create an article node.
|
||||
$title = $this->randomName(8);
|
||||
$node = array(
|
||||
'title' => $title,
|
||||
'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32)))),
|
||||
'uid' => $this->user->uid,
|
||||
'type' => 'article',
|
||||
'is_new' => TRUE,
|
||||
'comment' => COMMENT_NODE_OPEN,
|
||||
);
|
||||
$node = node_submit((object) $node);
|
||||
node_save($node);
|
||||
|
||||
$this->nid = $node->nid;
|
||||
|
||||
// Create some comments on the node.
|
||||
$this->cids = array();
|
||||
foreach (range(1, 10) as $i) {
|
||||
$comment = (object) array(
|
||||
'cid' => NULL,
|
||||
'nid' => $node->nid,
|
||||
'pid' => 0,
|
||||
'uid' => $this->user->uid,
|
||||
'status' => COMMENT_PUBLISHED,
|
||||
'subject' => $this->randomName(),
|
||||
'language' => LANGUAGE_NONE,
|
||||
'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
|
||||
);
|
||||
comment_save($comment);
|
||||
|
||||
$this->cids[$comment->cid] = $comment->cid;
|
||||
}
|
||||
|
||||
// Flag one comment.
|
||||
$this->flag->flag('flag', reset($this->cids));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test viewing multiple comments on a node is optimized.
|
||||
*/
|
||||
function testCommentView() {
|
||||
// View the node.
|
||||
$this->drupalGet('node/' . $this->nid);
|
||||
|
||||
// Inspect the tracking variable.
|
||||
// Hooks in the flag_comment_flag_test module will have populated this with
|
||||
// data at various points in the lifecycle of the loaded page.
|
||||
$tracking_variable = variable_get('flag_comment_flag_test_user_flags_cache_tracking', array());
|
||||
|
||||
$this->assertNull($tracking_variable['hook_comment_load'], "The flag_get_user_flags() static cache is empty when the comments are being loaded.");
|
||||
|
||||
// The test module's hook_entity_view() runs after flag's implementation, so
|
||||
// for the first comment view, the cache should be fully populated: all
|
||||
// comments should have an entry.
|
||||
foreach ($this->cids as $cid) {
|
||||
$this->assertNotNull($tracking_variable['hook_entity_view_1'][$this->user->uid][0]['comment'][$cid], "The static cache contained data for comment $cid when comment 1 was being viewed.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,13 @@
|
||||
name = Flag Comment Flag Test
|
||||
description = Test module for comment flags.
|
||||
dependencies[] = flag
|
||||
dependencies[] = comment
|
||||
core = 7.x
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2016-09-23
|
||||
version = "7.x-3.9"
|
||||
core = "7.x"
|
||||
project = "flag"
|
||||
datestamp = "1474619065"
|
||||
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file flag_comment_flag_test.module
|
||||
* Test module for comment flags.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_comment_load().
|
||||
*
|
||||
* This is only called once when viewing a node with comments, and before
|
||||
* hook_entity_view() is invoked. We use this to check the initial state of the
|
||||
* cache.
|
||||
*/
|
||||
function flag_comment_flag_test_comment_load($comments) {
|
||||
$flag_get_user_flags_cache = drupal_static('flag_get_user_flags');
|
||||
|
||||
// Store the value of the flag_get_user_flags() static cache in the variable,
|
||||
// so the test can retrieve it.
|
||||
$tracking_variable = variable_get('flag_comment_flag_test_user_flags_cache_tracking', array());
|
||||
$tracking_variable['hook_comment_load'] = $flag_get_user_flags_cache;
|
||||
variable_set('flag_comment_flag_test_user_flags_cache_tracking', $tracking_variable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_view().
|
||||
*
|
||||
* Use hook_entity_view() rather than hook_comment_view() so we are in the same
|
||||
* invocation as flag_entity_view().
|
||||
*/
|
||||
function flag_comment_flag_test_entity_view($entity, $type, $view_mode, $langcode) {
|
||||
if ($type == 'comment') {
|
||||
$flag_get_user_flags_cache = drupal_static('flag_get_user_flags');
|
||||
|
||||
// Store the value of the flag_get_user_flags() static cache in the variable,
|
||||
// so the test can retrieve it.
|
||||
$tracking_variable = variable_get('flag_comment_flag_test_user_flags_cache_tracking', array());
|
||||
$tracking_variable['hook_entity_view_' . $entity->cid] = $flag_get_user_flags_cache;
|
||||
variable_set('flag_comment_flag_test_user_flags_cache_tracking', $tracking_variable);
|
||||
}
|
||||
}
|
@@ -4,9 +4,9 @@ dependencies[] = flag
|
||||
core = 7.x
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-03-02
|
||||
version = "7.x-3.6"
|
||||
; Information added by Drupal.org packaging script on 2016-09-23
|
||||
version = "7.x-3.9"
|
||||
core = "7.x"
|
||||
project = "flag"
|
||||
datestamp = "1425327793"
|
||||
datestamp = "1474619065"
|
||||
|
||||
|
@@ -5,9 +5,9 @@ dependencies[] = rules
|
||||
core = 7.x
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-03-02
|
||||
version = "7.x-3.6"
|
||||
; Information added by Drupal.org packaging script on 2016-09-23
|
||||
version = "7.x-3.9"
|
||||
core = "7.x"
|
||||
project = "flag"
|
||||
datestamp = "1425327793"
|
||||
datestamp = "1474619065"
|
||||
|
||||
|
@@ -10,9 +10,9 @@
|
||||
*
|
||||
* Hook implementations should call this with their hook name and parameters.
|
||||
*
|
||||
* @param $hook_name
|
||||
* @param string $hook_name
|
||||
* The name of the hook invoked.
|
||||
* @param $function_parameters
|
||||
* @param array $function_parameters
|
||||
* The array of parameters the hook received.
|
||||
* @param $flagging
|
||||
* (optional) The flagging entity that the hook received. If this is given,
|
||||
|
@@ -5,9 +5,9 @@ dependencies[] = flag
|
||||
package = Flags
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-03-02
|
||||
version = "7.x-3.6"
|
||||
; Information added by Drupal.org packaging script on 2016-09-23
|
||||
version = "7.x-3.9"
|
||||
core = "7.x"
|
||||
project = "flag"
|
||||
datestamp = "1425327793"
|
||||
datestamp = "1474619065"
|
||||
|
||||
|
Reference in New Issue
Block a user