updated flag_list to 3.x version. ATTENTION DO NOT WORK ANYMORE create new folder broken

This commit is contained in:
Bachir Soussi Chiadmi 2016-10-25 20:12:36 +02:00
parent ae7349e811
commit 253524c527
21 changed files with 781 additions and 2821 deletions

View File

@ -1,14 +1,50 @@
// $id: $ Flag lists (Sep. 06, 2016)
====
Tweeked the code to follow the proposals in the API
Flag lists (Jan. 27, 2011 Flag lists (Aug. 24, 2015)
====
#2535084: Enhanced selection messages
#2539056: flag_lists_do_flag doesn't work with skip_permission_check=true
Flag lists (Jun. 10, 2015)
====
#2379621: Three Error Messages
#2379719: Undefined Property Error Message
#2380077: Hidden Undefined Property Error Message
#2379743: Ajax Message Problems
#2379701: Two Required Fields
#2389083: Ensure that Flag_lists 7.x-3.x can only be used with Flag 7.x-3.0
#2392489: uid lenght in flag_lists_flags and flag_lists_content
#2390871: New template creation
#2388741-11: Special Characters?
#2452549: Flag List 7.x-3.0-beta1 does to work with Views-generated lists - 0 item(s) added
#2453679: Add titles to view generated lists
#2454401: Views & uninstall
#2453803: Not all Flag lists operations are working
#2465553: Feature Requests: Option to customize wording; List Operations as block?
#2388741-24: Special Characters?
#2388741-28: Special Characters?
#2465553-8: Feature Requests: Option to customize wording; List Operations as block?
#2473121: Question about invoking hook_flag (This changes the name of the hooks for this module)
#2453803-5: Not all Flag lists operations are working
#2465553-13: Feature Requests: Option to customize wording; List Operations as block?
#2496007-2: Autocomplete when selecting a flag lists in a view
#2496007-3: Autocomplete when selecting a flag lists in a view
Flag lists (Jan. 27, 2011)
====
Fix bug: Incorrectly checking status of non-flag_lists flags. Fix bug: Incorrectly checking status of non-flag_lists flags.
Fix bug: Incorrectly applying hook_flag_access() on non-flag_lists flags. Fix bug: Incorrectly applying hook_flag_access() on non-flag_lists flags.
Flag lists (Jan. 14, 2011 Flag lists (Jan. 14, 2011)
====
#1002292 Fixed Tokens not replaced in add-to-list and remove-from-list js messages. #1002292 Fixed Tokens not replaced in add-to-list and remove-from-list js messages.
#1002292 Token module now a required dependency. #1002292 Token module now a required dependency.
Flag lists (Jan. 12, 2011) Flag lists (Jan. 12, 2011)
====
#1023432 by erikwebb: Fixed No default value for $account in flag_lists_fl_delete(). #1023432 by erikwebb: Fixed No default value for $account in flag_lists_fl_delete().
#1002294 by architectJpres: Fixed List block incompatible with block caching. #1002294 by architectJpres: Fixed List block incompatible with block caching.
Block caching turned off for now. Still not making db updates so you need to Block caching turned off for now. Still not making db updates so you need to
@ -76,3 +112,4 @@ allow users with "administer flags" permission to bypass flag_lists_is_owner()
checks. checks.
First run at views integration First run at views integration
Better admin table for lists Better admin table for lists

View File

@ -1,25 +0,0 @@
From d4d5acf83713c2a8413e1182294e887159c0e445 Mon Sep 17 00:00:00 2001
From: Bachir Soussi Chiadmi <bachir@g-u-i.net>
Date: Wed, 25 Sep 2013 15:25:25 +0200
Subject: [PATCH] flag 3.2 compatibility
---
flag_lists.module | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flag_lists.module b/flag_lists.module
index 13a5dd7..8b25b24 100644
--- a/flag_lists.module
+++ b/flag_lists.module
@@ -1413,7 +1413,7 @@ function flag_lists_page($action = NULL, $flag_name = NULL, $entity_id = NULL) {
// $flag->link_type = 'toggle';
$sid = flag_get_sid($user->uid);
$new_action = _flag_lists_is_flagged($flag, $entity_id, $user->uid, $sid) ? 'unflag' : 'flag';
- $new_link = $flag->theme($new_action, $entity_id, TRUE);
+ $new_link = $flag->theme($new_action, $entity_id, array("after_flagging" => TRUE));
flag_lists_fix_link($new_link, $new_action);
drupal_json_output(array(
'status' => TRUE,
--
1.8.1.5

View File

@ -1,526 +0,0 @@
diff --git a/flag_lists.admin.inc b/flag_lists.admin.inc
index a71a11cc511ebba08169b334407985c8f501bc30..71d532209d15f2171dce7d0906131572f22b97b3 100644
--- a/flag_lists.admin.inc
+++ b/flag_lists.admin.inc
@@ -110,7 +110,7 @@ function flag_lists_add_js($type = NULL) {
}
// New flag. Load the template row.
- $query = db_select('flags', 'f');
+ $query = db_select('flag', 'f');
$query->leftJoin('flag_lists_types', 'fl', 'f.name = fl.name');
$query->fields('f')
->fields('fl')
@@ -119,7 +119,7 @@ function flag_lists_add_js($type = NULL) {
$row = $query->execute()
->fetchObject();
- $newflag = flag_flag::factory_by_content_type('node');
+ $newflag = flag_flag::factory_by_entity_type('node');
$flag = $newflag->factory_by_row($row);
// The template fid becomes the flag_lists parent flag.
@@ -243,7 +243,7 @@ function flag_lists_form_submit($form, $form_state, $account = NULL) {
else {
// New flag. Load the template row.
$type = $form_state['values']['type'];
- $query = db_select('flags', 'f');
+ $query = db_select('flag', 'f');
$query->leftJoin('flag_lists_types', 'fl', 'f.name = fl.name');
$query->fields('f')
->fields('fl')
@@ -252,7 +252,7 @@ function flag_lists_form_submit($form, $form_state, $account = NULL) {
$row = $query->execute()
->fetchObject();
- $newflag = flag_flag::factory_by_content_type('node');
+ $newflag = flag_flag::factory_by_entity_type('node');
$flag = $newflag->factory_by_row($row);
// The template fid becomes the flag_lists parent flag.
diff --git a/flag_lists.install b/flag_lists.install
index bd290d10d849d116a8ca68fb6abf0dcc93136f53..a84fd496888fb65c6cdddacaf37828ede23def76 100644
--- a/flag_lists.install
+++ b/flag_lists.install
@@ -30,7 +30,7 @@ function flag_lists_schema() {
'unsigned' => TRUE,
'not null' => TRUE,
),
- 'content_type' => array(
+ 'entity_type' => array(
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
@@ -72,13 +72,13 @@ function flag_lists_schema() {
'not null' => TRUE,
'default' => 0,
),
- 'content_type' => array(
+ 'entity_type' => array(
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
- 'content_id' => array(
+ 'entity_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
@@ -106,11 +106,11 @@ function flag_lists_schema() {
),
'primary key' => array('fcid'),
'unique keys' => array(
- 'fid_content_id_uid_sid' => array('fid', 'content_id', 'uid', 'sid'),
+ 'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
),
'indexes' => array(
- 'content_type_content_id' => array('content_type', 'content_id'),
- 'content_type_uid_sid' => array('content_type', 'uid', 'sid'),
+ 'entity_type_entity_id' => array('entity_type', 'entity_id'),
+ 'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
),
);
$schema['flag_lists_counts'] = array(
@@ -122,13 +122,13 @@ function flag_lists_schema() {
'not null' => TRUE,
'default' => 0,
),
- 'content_type' => array(
+ 'entity_type' => array(
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
- 'content_id' => array(
+ 'entity_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
@@ -143,10 +143,10 @@ function flag_lists_schema() {
'disp-width' => '10',
)
),
- 'primary key' => array('fid', 'content_id'),
+ 'primary key' => array('fid', 'entity_id'),
'indexes' => array(
- 'fid_content_type' => array('fid', 'content_type'),
- 'content_type_content_id' => array('content_type', 'content_id'),
+ 'fid_entity_type' => array('fid', 'entity_type'),
+ 'entity_type_entity_id' => array('entity_type', 'entity_id'),
'count' => array('count'),
),
);
@@ -190,13 +190,13 @@ function flag_lists_install() {
function flag_lists_uninstall() {
// Remove our template flags.
$query = db_select('flag_lists_types', 'fl');
- $query->leftJoin('flags', 'f', 'fl.name = f.name');
+ $query->leftJoin('flag', 'f', 'fl.name = f.name');
$query->addField('fl', 'fid', 'fid');
$query->distinct();
$fids = $query->execute();
foreach ($fids as $fid) {
- db_delete('flags')->condition('fid', $fid->fid);
+ db_delete('flag')->condition('fid', $fid->fid);
db_delete('flag_content')->condition('fid', $fid->fid);
db_delete('flag_types')->condition('fid', $fid->fid);
db_delete('flag_counts')->condition('fid', $fid->fid);
diff --git a/flag_lists.module b/flag_lists.module
index 8fde9dd12b25e5e82ff79204fd800139460cd7e7..13a5dd77ead6832901a6fb0aac6511c0bc62eb3b 100644
--- a/flag_lists.module
+++ b/flag_lists.module
@@ -214,7 +214,7 @@ function theme_flag_lists_user_list($variables) {
$content = flag_lists_get_flagged_content($fid, $uid);
foreach ($content as $item) {
if ($item->content_type == 'node') {
- $node = node_load($item->content_id);
+ $node = node_load($item->entity_id);
$items[] = l($node->title, 'node/' . $node->nid);
}
}
@@ -811,7 +811,7 @@ function flag_lists_set_messages(&$flag) {
*
* Make sure a user can only see his/her own personal flags.
*/
-function flag_lists_flag_access($flag, $content_id, $action, $account) {
+function flag_lists_flag_access($flag, $entity_id, $action, $account) {
if (!empty($flag->module) && $flag->module == 'flag_lists') {
switch ($action) {
case 'flag':
@@ -936,7 +936,7 @@ function flag_lists_get_user_flags($content_type = NULL, $account = NULL, $use_f
$query = db_select('flag_lists_flags', 'fl')
->fields('fl')
->condition('fl.uid', $account->uid);
- $query->leftJoin('flags', 'f', 'fl.pfid = f.fid');
+ $query->leftJoin('flag', 'f', 'fl.pfid = f.fid');
$query->leftJoin('flag_lists_types', 'ft', 'ft.name = f.name');
$query->addField('ft', 'type');
if ($content_type) {
@@ -1011,12 +1011,12 @@ function theme_flag_lists_list($variables) {
// Make sure we have a node.
if (is_object($node) && user_access('create flag lists')) {
$content_type = $node->type;
- $content_id = $node->nid;
+ $entity_id = $node->nid;
}
// Or at least confirm we are on a node page and use has access.
elseif (arg(0) == 'node' && is_numeric(arg(1)) && user_access('create flag lists')) {
- $content_id = arg(1);
- $query = db_select('node')->condition('nid', $content_id);
+ $entity_id = arg(1);
+ $query = db_select('node')->condition('nid', $entity_id);
$query->addField('node', 'type');
$content_type = $query->execute()->fetchField();
}
@@ -1034,19 +1034,19 @@ function theme_flag_lists_list($variables) {
// Build the list of lists for this node.
foreach ($flags as $flag) {
if ($flag->module == 'flag_lists') {
- $action = _flag_lists_is_flagged($flag, $content_id, $user->uid, 0) ? 'unflag' : 'flag';
+ $action = _flag_lists_is_flagged($flag, $entity_id, $user->uid, 0) ? 'unflag' : 'flag';
}
else {
- $action = $flag->is_flagged($content_id) ? 'unflag' : 'flag';;
+ $action = $flag->is_flagged($entity_id) ? 'unflag' : 'flag';;
}
// Do we need the ops?
if ($ops && $flag->module == 'flag_lists') {
$ops_links = theme('flag_lists_ops', array('flag' => $flag));
- $link = $flag->theme($action, $content_id) . $ops_links;
+ $link = $flag->theme($action, $entity_id) . $ops_links;
}
else {
- $link = $flag->theme($action, $content_id);
+ $link = $flag->theme($action, $entity_id);
}
// If it's a list, fix the link.
@@ -1201,12 +1201,12 @@ function flag_lists_get_flagged_content($fid, $uid) {
* The full flag object of for the flag link being generated.
* @param $action
* The action this link will perform. Either 'flag' or 'unflag'.
- * @param $content_id
+ * @param $entity_id
* The ID of the node, comment, user, or other object being flagged.
* @return
* An array defining properties of the link.
*/
-function flag_lists_flag_link($flag, $action, $content_id) {
+function flag_lists_flag_link($flag, $action, $entity_id) {
return array();
}
@@ -1224,30 +1224,61 @@ function flag_lists_flag_link_types() {
function flag_lists_flag_default_flags($name = 'fl_template') {
- return array(
- array(
- 'api_version' => 2,
- 'name' => $name,
- 'module' => 'flag_lists',
- 'content_type' => 'node',
- 'global' => 0,
- 'show_on_page' => 0,
- 'show_on_teaser' => 0,
- 'show_on_form' => 0,
- // The following UI labels aren't wrapped in t() because they are written
- // to the DB in English. They are passed to t() later, thus allowing for
- // multilingual sites.
- 'title' => 'Flag lists template',
- 'flag_short' => 'Add to your [flag_lists:title] [flag_lists:term]',
- 'flag_long' => 'Add this post to your [flag_lists:title] [flag_lists:term]',
- 'flag_message' => 'This post has been added to your [flag_lists:title] [flag_lists:term]',
- 'unflag_short' => 'Remove this from your [flag_lists:title] [flag_lists:term]',
- 'unflag_long' => 'Remove this post from your [flag_lists:title] [flag_lists:term]',
- 'unflag_message' => 'This post has been removed from your [flag_lists:title] [flag_lists:term]',
- 'types' => array(),
- 'link_type' => 'toggle',
- ),
- );
+ // return array(
+ // array(
+ // 'api_version' => 2,
+ // 'name' => $name,
+ // 'module' => 'flag_lists',
+ // 'content_type' => 'node',
+ // 'global' => 0,
+ // 'show_on_page' => 0,
+ // 'show_on_teaser' => 0,
+ // 'show_on_form' => 0,
+ // // The following UI labels aren't wrapped in t() because they are written
+ // // to the DB in English. They are passed to t() later, thus allowing for
+ // // multilingual sites.
+ // 'title' => 'Flag lists template',
+ // 'flag_short' => 'Add to your [flag_lists:title] [flag_lists:term]',
+ // 'flag_long' => 'Add this post to your [flag_lists:title] [flag_lists:term]',
+ // 'flag_message' => 'This post has been added to your [flag_lists:title] [flag_lists:term]',
+ // 'unflag_short' => 'Remove this from your [flag_lists:title] [flag_lists:term]',
+ // 'unflag_long' => 'Remove this post from your [flag_lists:title] [flag_lists:term]',
+ // 'unflag_message' => 'This post has been removed from your [flag_lists:title] [flag_lists:term]',
+ // 'types' => array(),
+ // 'link_type' => 'toggle',
+ // ),
+ // );
+
+$flags = array();
+// Exported flag: "Flag lists template".
+$flags['fl_template'] = array(
+ 'entity_type' => 'node',
+ 'title' => 'Flag lists template',
+ 'global' => 0,
+ 'types' => array(),
+ 'flag_short' => 'Add to your [flag_lists:title] [flag_lists:term]',
+ 'flag_long' => 'Add this post to your [flag_lists:title] [flag_lists:term]',
+ 'flag_message' => 'This post has been added to your [flag_lists:title] [flag_lists:term]',
+ 'unflag_short' => 'Remove this from your [flag_lists:title] [flag_lists:term]',
+ 'unflag_long' => 'Remove this post from your [flag_lists:title] [flag_lists:term]',
+ 'unflag_message' => 'This post has been removed from your [flag_lists:title] [flag_lists:term]',
+ 'unflag_denied_text' => '',
+ 'link_type' => 'toggle',
+ 'weight' => 0,
+ 'api_version' => 3,
+ 'module' => 'flag_lists',
+ 'show_on_page' => 0,
+ 'show_on_teaser' => 0,
+ 'show_on_form' => 0,
+ 'status' => FALSE,
+ 'import_roles' => array(
+ 'flag' => array(),
+ 'unflag' => array(),
+ ),
+);
+return $flags;
+
+
}
/**
@@ -1294,7 +1325,7 @@ function flag_lists_insert($flag) {
->fields(array(
'pfid' => $flag->pfid,
'uid' => $flag->uid,
- 'content_type' => $flag->content_type,
+ 'entity_type' => $flag->entity_type,
'name' => $flag->name,
'title' => $flag->title,
'options' => $flag->get_serialized_options($flag),
@@ -1330,7 +1361,7 @@ function flag_lists_fl_delete($flag, $account = NULL) {
* Used both for the regular callback as well as the JS version. We use this
* instead of the flag module's because our flags are not in the flags table.
*/
-function flag_lists_page($action = NULL, $flag_name = NULL, $content_id = NULL) {
+function flag_lists_page($action = NULL, $flag_name = NULL, $entity_id = NULL) {
global $user;
// Shorten up the variables that affect the behavior of this page.
@@ -1341,7 +1372,7 @@ function flag_lists_page($action = NULL, $flag_name = NULL, $content_id = NULL)
$has_js = isset($_GET['has_js']);
// Check the flag token, then perform the flagging.
- if (!flag_check_token($token, $content_id)) {
+ if (!flag_check_token($token, $entity_id)) {
$error = t('Bad token. You seem to have followed an invalid link.');
}
elseif ($user->uid == 0 && !$has_js) {
@@ -1355,7 +1386,7 @@ function flag_lists_page($action = NULL, $flag_name = NULL, $content_id = NULL)
// Identify it as ours.
$flag->module = 'flag_lists';
- flag_lists_do_flag($flag, $action, $content_id);
+ flag_lists_do_flag($flag, $action, $entity_id);
}
// If an error was received, set a message and exit.
@@ -1381,14 +1412,14 @@ function flag_lists_page($action = NULL, $flag_name = NULL, $content_id = NULL)
// $flag = flag_lists_get_flag($flag_name);
// $flag->link_type = 'toggle';
$sid = flag_get_sid($user->uid);
- $new_action = _flag_lists_is_flagged($flag, $content_id, $user->uid, $sid) ? 'unflag' : 'flag';
- $new_link = $flag->theme($new_action, $content_id, TRUE);
+ $new_action = _flag_lists_is_flagged($flag, $entity_id, $user->uid, $sid) ? 'unflag' : 'flag';
+ $new_link = $flag->theme($new_action, $entity_id, TRUE);
flag_lists_fix_link($new_link, $new_action);
drupal_json_output(array(
'status' => TRUE,
'newLink' => $new_link,
// Further information for the benefit of custom JavaScript event handlers:
- 'contentId' => $content_id,
+ 'contentId' => $entity_id,
'contentType' => $flag->content_type,
'flagName' => $flag->name,
'flagStatus' => $action,
@@ -1397,7 +1428,7 @@ function flag_lists_page($action = NULL, $flag_name = NULL, $content_id = NULL)
}
else {
$flag = flag_lists_get_flag($flag->fid);
- drupal_set_message($flag->get_label($action . '_message', $content_id));
+ drupal_set_message($flag->get_label($action . '_message', $entity_id));
drupal_goto();
}
}
@@ -1413,7 +1444,7 @@ function flag_lists_fix_link(&$link, $action) {
*
* @param $action
* Either 'flag' or 'unflag'.
- * @param $content_id
+ * @param $entity_id
* The ID of the item to flag or unflag.
* @param $account
* The user on whose behalf to flag. Leave empty for the current user.
@@ -1423,7 +1454,7 @@ function flag_lists_fix_link(&$link, $action) {
* FALSE if some error occured (e.g., user has no permission, flag isn't
* applicable to the item, etc.), TRUE otherwise.
*/
- function flag_lists_do_flag($flag, $action, $content_id, $account = NULL, $skip_permission_check = FALSE) {
+ function flag_lists_do_flag($flag, $action, $entity_id, $account = NULL, $skip_permission_check = FALSE) {
if (!isset($account)) {
$account = $GLOBALS['user'];
}
@@ -1431,7 +1462,7 @@ function flag_lists_fix_link(&$link, $action) {
return FALSE;
}
if (!$skip_permission_check) {
- if (!$flag->access($content_id, $action, $account)) {
+ if (!$flag->access($entity_id, $action, $account)) {
// User has no permission to flag/unflag this object.
return FALSE;
}
@@ -1439,7 +1470,7 @@ function flag_lists_fix_link(&$link, $action) {
else {
// We are skipping permission checks. However, at a minimum we must make
// sure the flag applies to this content type:
- if (!$flag->applies_to_content_id($content_id)) {
+ if (!$flag->applies_to_content_id($entity_id)) {
return FALSE;
}
}
@@ -1460,17 +1491,17 @@ function flag_lists_fix_link(&$link, $action) {
// Perform the flagging or unflagging of this flag. We invoke hook_flag here
// because we do our own flagging.
- $flagged = _flag_lists_is_flagged($flag, $content_id, $uid, $sid);
+ $flagged = _flag_lists_is_flagged($flag, $entity_id, $uid, $sid);
if ($action == 'unflag') {
if ($flagged) {
- $fcid = _flag_lists_unflag($flag, $content_id, $uid, $sid);
- module_invoke_all('flag', 'unflag', $flag, $content_id, $account, $fcid);
+ $fcid = _flag_lists_unflag($flag, $entity_id, $uid, $sid);
+ module_invoke_all('flag', 'unflag', $flag, $entity_id, $account, $fcid);
}
}
elseif ($action == 'flag') {
if (!$flagged) {
- $fcid = _flag_lists_flag($flag, $content_id, $uid, $sid);
- module_invoke_all('flag', 'flag', $flag, $content_id, $account, $fcid);
+ $fcid = _flag_lists_flag($flag, $entity_id, $uid, $sid);
+ module_invoke_all('flag', 'flag', $flag, $entity_id, $account, $fcid);
}
}
@@ -1487,12 +1518,12 @@ function flag_lists_fix_link(&$link, $action) {
* bypass it.
*
*/
- function _flag_lists_is_flagged($flag, $content_id, $uid, $sid) {
+ function _flag_lists_is_flagged($flag, $entity_id, $uid, $sid) {
$query = db_select('flag_lists_content')
->condition('fid', $flag->fid)
->condition('uid', $uid)
->condition('sid', $sid)
- ->condition('content_id', $content_id);
+ ->condition('entity_id', $entity_id);
$query->addField('flag_lists_content', 'fid');
return $query->execute()->fetchField();
}
@@ -1504,19 +1535,19 @@ function flag_lists_fix_link(&$link, $action) {
* flag_lists_do_flag() function instead.
*
*/
- function _flag_lists_flag($flag, $content_id, $uid, $sid) {
+ function _flag_lists_flag($flag, $entity_id, $uid, $sid) {
$fcid = db_insert('flag_lists_content')
->fields(array(
'fid' => $flag->fid,
- 'content_type' => $flag->content_type,
- 'content_id' => $content_id,
+ 'entity_type' => $flag->entity_type,
+ 'entity_id' => $entity_id,
'uid' => $uid,
'sid' => $sid,
'timestamp' => REQUEST_TIME,
))
->execute();
- _flag_lists_update_count($flag, $content_id);
+ _flag_lists_update_count($flag, $entity_id);
return $fcid;
}
@@ -1527,10 +1558,10 @@ function flag_lists_fix_link(&$link, $action) {
* flag_lists_do_flag() function instead.
*
*/
- function _flag_lists_unflag($flag, $content_id, $uid, $sid) {
+ function _flag_lists_unflag($flag, $entity_id, $uid, $sid) {
$query = db_select('flag_lists_content')
->condition('fid', $flag->fid)
- ->condition('content_id', $content_id)
+ ->condition('entity_id', $entity_id)
->condition('uid', $uid)
->condition('sid', $sid);
$query->addField('flag_lists_content', 'fcid');
@@ -1539,7 +1570,7 @@ function flag_lists_fix_link(&$link, $action) {
db_delete('flag_lists_content')
->condition('fcid', $fcid)
->execute();
- _flag_lists_update_count($flag, $content_id);
+ _flag_lists_update_count($flag, $entity_id);
}
return $fcid;
}
@@ -1547,11 +1578,11 @@ function flag_lists_fix_link(&$link, $action) {
/**
* Updates the flag count for this content
*/
- function _flag_lists_update_count($flag, $content_id) {
+ function _flag_lists_update_count($flag, $entity_id) {
$count = db_select('flag_lists_content', 'f')
->fields('f')
->condition('fid', $flag->fid)
- ->condition('content_id', $content_id)
+ ->condition('entity_id', $entity_id)
->countQuery()
->execute()
->fetchField();
@@ -1559,7 +1590,7 @@ function flag_lists_fix_link(&$link, $action) {
if (empty($count)) {
$num_deleted = db_delete('flag_lists_counts')
->condition('fid', $flag->fid)
- ->condition('content_id', $content_id)
+ ->condition('entity_id', $entity_id)
->execute();
}
else {
@@ -1568,14 +1599,14 @@ function flag_lists_fix_link(&$link, $action) {
'count' => $count,
))
->condition('fid', $flag->fid)
- ->condition('content_id', $content_id)
+ ->condition('entity_id', $entity_id)
->execute();
if (empty($num_updated)) {
db_insert('flag_lists_counts')
->fields(array(
'fid' => $flag->fid,
- 'content_type' => $flag->content_type,
- 'content_id' => $content_id,
+ 'entity_type' => $flag->entity_type,
+ 'entity_id' => $entity_id,
'count' => $count,
))
->execute();

View File

@ -1,55 +0,0 @@
diff --git a/flag_lists.module b/flag_lists.module
index d829113..b3c04f0 100644
--- a/flag_lists.module
+++ b/flag_lists.module
@@ -1587,6 +1587,32 @@ function flag_lists_fix_link(&$link, $action) {
return $fcid;
}
+
+ /**
+ * Remove all entries of entity_id and type
+ *
+ * @param $entity_id
+ * Entity id which has been flagged.
+ * @param $type
+ * The entity type.
+ */
+ function _flag_lists_remove_entity($entity_id, $type) {
+ $query = db_select('flag_lists_content')
+ ->condition('entity_id', $entity_id)
+ ->condition('entity_type', $type);
+ $query->fields('flag_lists_content', array('fcid', 'fid', 'uid', 'sid'));
+ $items = $query->execute()->fetchAll();
+
+ if ($items) {
+ foreach ($items as $key => $value) {
+ db_delete('flag_lists_content')
+ ->condition('fcid', $value->fcid)
+ ->execute();
+ watchdog('flag_lists', t('Deleted entry @fcid from flat_lists_content', array('@fcid' => $value->fcid)));
+ }
+ }
+ }
+
/**
* Updates the flag count for this content
*/
@@ -1766,3 +1792,17 @@ function flag_lists_views_form_substitutions() {
$select_all_placeholder => drupal_render($select_all),
);
}
+
+
+/**
+ * Implements hook_entity_delete
+ */
+function flag_lists_entity_delete($entity, $type) {
+ foreach (flag_get_flags($type) as $flag) {
+ if (isset($entity->vid)) {
+ $items = _flag_lists_remove_entity($entity->vid, $type);
+ }
+ }
+}
+
+

View File

@ -26,6 +26,8 @@ function theme_flag_lists_admin_page($variables) {
$view = views_get_view('flag_lists', FALSE); $view = views_get_view('flag_lists', FALSE);
if (!empty($view)) { if (!empty($view)) {
$view->set_display('default'); $view->set_display('default');
$view->pre_execute();
$view->execute();
$output .= $view->render(); $output .= $view->render();
} }
} }
@ -84,12 +86,19 @@ function flag_lists_add($type = NULL) {
* Callback for adding new lists through AJAX. * Callback for adding new lists through AJAX.
*/ */
function flag_lists_add_js($type = NULL) { function flag_lists_add_js($type = NULL) {
$token = $_REQUEST['form_token'];
if ( is_null($token) || !drupal_valid_token($token, variable_get('flag_lists_name','list'))) {
drupal_json_output(array('error' => t('Are you using an old link?')));
exit();
}
if (is_null($type)) { if (is_null($type)) {
drupal_json_output(array('error' => t('Type not supplied.'))); drupal_json_output(array('error' => t('Type not supplied.')));
exit(); exit();
} }
$name = check_plain($_REQUEST['name']); $name = $_REQUEST['name'];
if (!isset($name) || empty($name)) { if (!isset($name) || empty($name)) {
drupal_json_output(array('error' => t('List name not supplied.'))); drupal_json_output(array('error' => t('List name not supplied.')));
exit(); exit();
@ -101,7 +110,7 @@ function flag_lists_add_js($type = NULL) {
} }
if (flag_lists_title_exists($name, $type)) { if (flag_lists_title_exists($name, $type)) {
drupal_json_output(array('error' => t('You already have a @name with this name for this type of content.', array('@name' => variable_get('flag_lists_name', t('list')))))); drupal_json_output(array('error' => t('You already have a @name with this name for this type of content.', array('@name' => variable_get('flag_lists_name', 'list')))));
exit(); exit();
} }
@ -162,7 +171,7 @@ function flag_lists_form($form, $form_state, $name = NULL, $type = NULL) {
} }
// Adding a new list. // Adding a new list.
if (!isset($name)) { if (!isset($name)) {
drupal_set_title(t('Add a new list')); drupal_set_title(t('Add a new @name', array('@name' => variable_get('flag_lists_name', 'list'))));
$form['edit'] = array( $form['edit'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => FALSE, '#value' => FALSE,
@ -173,7 +182,7 @@ function flag_lists_form($form, $form_state, $name = NULL, $type = NULL) {
else { else {
$flag = flag_lists_get_flag($name); $flag = flag_lists_get_flag($name);
$title_string_name = variable_get('flag_lists_name', 'list'); $title_string_name = t('@name', array('@name' => variable_get('flag_lists_name', 'list')));
$title_string = t('Edit your "@title" @name title', array('@title' => $flag->get_title(), '@name' => $title_string_name)); $title_string = t('Edit your "@title" @name title', array('@title' => $flag->get_title(), '@name' => $title_string_name));
drupal_set_title(); drupal_set_title();
@ -191,7 +200,7 @@ function flag_lists_form($form, $form_state, $name = NULL, $type = NULL) {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Title'), '#title' => t('Title'),
'#default_value' => empty($flag->title) ? '' : $flag->title, '#default_value' => empty($flag->title) ? '' : $flag->title,
'#description' => t('A short, descriptive title for this @name list. Limit to 255 characters.', array('@name' => variable_get('flag_lists_name', t('list')))), '#description' => t('A short, descriptive title for this @name list. Limit to 255 characters.', array('@name' => variable_get('flag_lists_name', 'list'))),
'#maxlength' => 255, '#maxlength' => 255,
'#required' => TRUE, '#required' => TRUE,
'#access' => empty($flag->locked['title']), '#access' => empty($flag->locked['title']),
@ -214,12 +223,12 @@ function flag_lists_form($form, $form_state, $name = NULL, $type = NULL) {
function flag_lists_form_validate($form, $form_state) { function flag_lists_form_validate($form, $form_state) {
// Ensure 255 charactor or less name. // Ensure 255 charactor or less name.
if (drupal_strlen($form_state['values']['title']) > 255) { if (drupal_strlen($form_state['values']['title']) > 255) {
form_set_error('name', t('The @name title may only be 255 characters long.', array('@name' => variable_get('flag_lists_name', t('list'))))); form_set_error('name', t('The @name title may only be 255 characters long.', array('@name' => variable_get('flag_lists_name', 'list'))));
} }
// Ensure the machine name is unique. // Ensure the machine name is unique.
if (!$form_state['values']['edit']) { if (!$form_state['values']['edit']) {
if (flag_lists_title_exists($form_state['values']['title'], $form_state['values']['type'])) { if (flag_lists_title_exists($form_state['values']['title'], $form_state['values']['type'])) {
form_set_error('title', t('You already have a @name with this name for this type of content.', array('@name' => variable_get('flag_lists_name', t('list'))))); form_set_error('title', t('You already have a @name with this name for this type of content.', array('@name' => variable_get('flag_lists_name', 'list'))));
} }
} }
} }
@ -287,7 +296,7 @@ function flag_lists_settings_form($form, $form_state) {
$form['flag_lists_name'] = array( $form['flag_lists_name'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Substitute "list" with your own terminology'), '#title' => t('Substitute "list" with your own terminology'),
'#default_value' => variable_get('flag_lists_name', t('list')), '#default_value' => t('@name', array('@name' => variable_get('flag_lists_name', 'list'))),
'#description' => t('You can choose to use another name for "list", such as "favorites" or "bookmarks". Lowercase and plural names usually work best.'), '#description' => t('You can choose to use another name for "list", such as "favorites" or "bookmarks". Lowercase and plural names usually work best.'),
'#required' => TRUE, '#required' => TRUE,
); );
@ -341,7 +350,7 @@ function flag_lists_delete_confirm($form, $form_state, $name) {
$form['fid'] = array('#type' => 'value', '#value' => $flag->fid); $form['fid'] = array('#type' => 'value', '#value' => $flag->fid);
return confirm_form($form, return confirm_form($form,
t('Are you sure you want to delete %title?', array('%title' => $flag->get_title())), t('Are you sure you want to delete @title?', array('@title' => $flag->get_title())),
isset($_GET['destination']) ? $_GET['destination'] : '/', isset($_GET['destination']) ? $_GET['destination'] : '/',
t('This action cannot be undone.'), t('This action cannot be undone.'),
t('Delete'), t('Cancel') t('Delete'), t('Cancel')
@ -359,14 +368,14 @@ function flag_lists_delete_confirm_submit($form, &$form_state) {
* Form to create a new template. * Form to create a new template.
*/ */
function flag_lists_create_template_form($form, $form_state) { function flag_lists_create_template_form($form, $form_state) {
drupal_set_title(t('Add a new list template')); drupal_set_title(t('Add a new @name template', array('@name' => variable_get('flag_lists_name', 'list'))));
$form['help'] = array( $form['help'] = array(
'#value' => t('This form creates a new, blank list template. After saving, you will be able to configure further options.'), '#value' => t('This form creates a new, blank list template. After saving, you will be able to configure further options.'),
); );
$form['name'] = array( $form['name'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Template name'), '#title' => t('Template name'),
'#description' => t('The machine-name for this template. It may be up to 32 characters long and my only contain lowercase letters, underscores, and numbers.'), '#description' => t('The machine-name for this template. It may be up to 20 characters long and my only contain lowercase letters, underscores, and numbers.'),
'#maxlength' => 255, '#maxlength' => 255,
'#required' => TRUE, '#required' => TRUE,
); );
@ -385,9 +394,9 @@ function flag_lists_create_template_form_validate($form, &$form_state) {
if (!preg_match('/^[a-z_][a-z0-9_]*$/', $form_state['values']['name'])) { if (!preg_match('/^[a-z_][a-z0-9_]*$/', $form_state['values']['name'])) {
form_set_error('name', t('The flag name may only contain lowercase letters, underscores, and numbers.')); form_set_error('name', t('The flag name may only contain lowercase letters, underscores, and numbers.'));
} }
// Ensure 32 charactor or less name. // Ensure 20 charactor or less name.
if (drupal_strlen($form_state['values']['name']) > 32) { if (drupal_strlen($form_state['values']['name']) > 20) {
form_set_error('name', t('The flag name may only be 32 characters long.')); form_set_error('name', t('The flag name may only be 20 characters long.'));
} }
// Ensure the machine name is unique. // Ensure the machine name is unique.
$flag = flag_get_flag('fl_template_' . $form_state['values']['name']); $flag = flag_get_flag('fl_template_' . $form_state['values']['name']);
@ -400,9 +409,10 @@ function flag_lists_create_template_form_validate($form, &$form_state) {
* New template submit. * New template submit.
*/ */
function flag_lists_create_template_form_submit($form, &$form_state) { function flag_lists_create_template_form_submit($form, &$form_state) {
$template = flag_lists_flag_default_flags('fl_template_' . $form_state['values']['name']); $template = flag_lists_flag_default_flags();
$flag = flag_flag::factory_by_array($template[0]); $flag = flag_flag::factory_by_array(array_shift($template));
$flag->title = t('List template') . ' ' . $form_state['values']['name']; $flag->title = t('Flag list template') . ' ' . $form_state['values']['name'];
$flag->name = 'fl_template_' . $form_state['values']['name'];
$flag->save(); $flag->save();
// Enter the new template into flag_lists_types. // Enter the new template into flag_lists_types.
db_insert('flag_lists_types') db_insert('flag_lists_types')
@ -410,11 +420,11 @@ function flag_lists_create_template_form_submit($form, &$form_state) {
'name' => $flag->name, 'name' => $flag->name,
)) ))
->execute(); ->execute();
$form_state['redirect'] = FLAG_ADMIN_PATH . '/edit/' . $flag->name; drupal_set_message(t('You must save the template below otherwise the functionality is not guaranteed!'), 'warning');
$form_state['redirect'] = FLAG_ADMIN_PATH . '/manage/' . $flag->name;
} }
/** /**
* Developer tool to generate dummy lists and listings. * Developer tool to generate dummy lists and listings.
*/ */
@ -493,7 +503,7 @@ function flag_lists_generate_lists_form_submit($form, &$form_state) {
$flags = flag_lists_get_flags(); $flags = flag_lists_get_flags();
foreach ($flags as $flag) { foreach ($flags as $flag) {
$result = db_select('flag_lists_content', 'f') $result = db_select('flag_lists_content', 'f')
->fields('f', array('fcid', 'content_id')) ->fields('f', array('fcid', 'entity_id'))
->condition('fid', $flag->fid) ->condition('fid', $flag->fid)
->execute(); ->execute();
@ -501,7 +511,7 @@ function flag_lists_generate_lists_form_submit($form, &$form_state) {
db_delete('flag_lists_content')->condition('fid', $flag->fid)->execute(); db_delete('flag_lists_content')->condition('fid', $flag->fid)->execute();
db_delete('flag_lists_counts')->condition('fid', $flag->fid)->execute(); db_delete('flag_lists_counts')->condition('fid', $flag->fid)->execute();
module_invoke_all('flag', 'unflag', $flag, $row->content_id, $account, $row->fcid); module_invoke_all('flag', 'unflag', $flag, $row->entity_id, $account, $row->fcid);
} }
} }
drupal_set_message(t('All listings were deleted.')); drupal_set_message(t('All listings were deleted.'));
@ -596,45 +606,17 @@ function flag_lists_generate_lists_form_submit($form, &$form_state) {
} }
} }
function flag_lists_autocomplete_list_callback($string = "") {
$matches = array();
if ($string) {
/** $lists = flag_lists_get_user_flags();
* Clean lists from deleted enties foreach ($lists as $list) {
*/ if (stristr($list->title,$string) !== FALSE) {
function flag_list_clean_deleted(){ $matches[$list->title] = check_plain($list->title);
drupal_set_title(t('Flag lists Clean'));
$output = '<p>' . t('This page shows all the deleted entityties id from flag lists.') . '</p>';
$total = 0;
$list = "<ul>";
$query = db_select('flag_lists_content');
$query->fields('flag_lists_content', array('entity_id', 'entity_type'));
$query->distinct();
$items = $query->execute()->fetchAll();
if ($items) {
foreach ($items as $key => $value) {
$entity = entity_load($value->entity_type, array($value->entity_id), array(), true);
// dsm($entity);
// break;
if(!isset($entity[$value->entity_id])){
$list .= "<li>".$value->entity_type ." <em>". $value->entity_id."</em> have been deleted does not exists anymore.</li>";
$total++;
} }
// db_delete('flag_lists_content')
// ->condition('entity_type', $value->entity_type)
// ->condition('entity_id', $value->entity_id)
// ->execute();
// watchdog('flag_lists', t('Deleted entry @fcid from flat_lists_content', array('@fcid' => $value->fcid)));
// }
} }
} }
$list .= "</ul>"; drupal_json_output($matches);
$output .= "<p><strong>".$total ."</strong> entities have been deleted.</p>";
$output .= $list;
return $output;
} }

View File

@ -0,0 +1,50 @@
<?php
/**
* @file
* Implements flag lists.
*/
class flag_lists extends flag_flag {
function save(&$flag) {
krumo('here');
$flag->flag_lists_save($flag);
}
/**
* Saves a flag to the database. It is a wrapper around update($flag) and insert($flag).
*/
function flag_lists_save(&$flag) {
if (isset($flag->fid)) {
flag_lists_update($flag);
$flag->is_new = FALSE;
}
else {
flag_lists_insert($flag);
$flag->is_new = TRUE;
}
// Clear the page cache for anonymous users.
// cache_clear_all('*', 'cache_page', TRUE);
}
/**
* Saves an existing flag to the database. Better use save($flag).
*/
function flag_lists_update($flag) {
db_query("UPDATE {flag_lists_flags} SET title = '%s', name = '%s' WHERE fid = %d", $flag->title, $flag->name, $flag->fid);
}
/**
* Saves a new flag to the database. Better use save($flag).
*/
function flag_lists_insert($flag) {
db_query("INSERT INTO {flag_lists_flags} (pfid, uid, content_type, name, title, options) VALUES (%d, %d, '%s', '%s', '%s', '%s')", $flag->pfid, $flag->uid, $flag->content_type, $flag->name, $flag->title, $flag->get_serialized_options($flag));
$flag->fid = db_last_insert_id('flags', 'fid');
$flag->name = 'flag_lists_'. $flag->uid .'_'. $flag->fid;
$flag->flag_lists_update($flag);
foreach ($flag->types as $type) {
db_query("INSERT INTO {flag_types} (fid, type) VALUES (%d, '%s')", $flag->fid, $type);
}
}
}

View File

@ -1,8 +1,9 @@
name = Flag lists name = Flag lists
core = 7.x core = 7.x
package = Flags package = Flags
dependencies[] = flag dependencies[] = flag (>7.x-3.0)
dependencies[] = token dependencies[] = token
dependencies[] = views
files[] = flag_lists.admin.inc files[] = flag_lists.admin.inc
files[] = flag_lists.module files[] = flag_lists.module
@ -17,11 +18,14 @@ files[] = includes/flag_lists_handler_field_ops.inc
files[] = includes/flag_lists_handler_field_template.inc files[] = includes/flag_lists_handler_field_template.inc
files[] = includes/flag_lists_handler_field_template_types.inc files[] = includes/flag_lists_handler_field_template_types.inc
files[] = includes/flag_lists_handler_filter_template.inc files[] = includes/flag_lists_handler_filter_template.inc
files[] = includes/flag_lists_handler_filter_list.inc
description = Allows users to create personal flag lists. description = Allows users to create personal flag lists.
; Information added by drupal.org packaging script on 2012-05-03
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2016-09-07
version = "7.x-3.1"
core = "7.x" core = "7.x"
project = "flag_lists" project = "flag_lists"
datestamp = "1336060255" datestamp = "1473230043"

View File

@ -26,7 +26,6 @@ function flag_lists_schema() {
), ),
'uid' => array( 'uid' => array(
'type' => 'int', 'type' => 'int',
'size' => 'small',
'unsigned' => TRUE, 'unsigned' => TRUE,
'not null' => TRUE, 'not null' => TRUE,
), ),
@ -106,7 +105,7 @@ function flag_lists_schema() {
), ),
'primary key' => array('fcid'), 'primary key' => array('fcid'),
'unique keys' => array( 'unique keys' => array(
'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'), 'fid_content_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
), ),
'indexes' => array( 'indexes' => array(
'entity_type_entity_id' => array('entity_type', 'entity_id'), 'entity_type_entity_id' => array('entity_type', 'entity_id'),
@ -191,17 +190,198 @@ function flag_lists_uninstall() {
// Remove our template flags. // Remove our template flags.
$query = db_select('flag_lists_types', 'fl'); $query = db_select('flag_lists_types', 'fl');
$query->leftJoin('flag', 'f', 'fl.name = f.name'); $query->leftJoin('flag', 'f', 'fl.name = f.name');
$query->addField('fl', 'fid', 'fid'); $query->addField('f', 'fid', 'fid');
$query->distinct(); $query->distinct();
$fids = $query->execute(); $fids = $query->execute();
foreach ($fids as $fid) { foreach ($fids as $fid) {
db_delete('flag')->condition('fid', $fid->fid); db_delete('flag')->condition('fid', $fid->fid)->execute();
db_delete('flag_content')->condition('fid', $fid->fid); db_delete('flagging')->condition('fid', $fid->fid)->execute();
db_delete('flag_types')->condition('fid', $fid->fid); db_delete('flag_types')->condition('fid', $fid->fid)->execute();
db_delete('flag_counts')->condition('fid', $fid->fid); db_delete('flag_counts')->condition('fid', $fid->fid)->execute();
}
db_delete('variable')->condition('name', 'flag_lists%', 'LIKE')->execute();
$view_to_delete = views_get_view('flag_lists');
if (!empty($view_to_delete)) {
views_delete_view($view_to_delete);
}
$view_to_delete =views_get_view('flag_lists_content');
if (!empty($view_to_delete)) {
views_delete_view($view_to_delete);
}
$view_to_delete = views_get_view('flag_lists_user_lists');
if (!empty($view_to_delete)) {
views_delete_view($view_to_delete);
}
$view_to_delete = views_get_view('flag_lists_user_list');
if (!empty($view_to_delete)) {
views_delete_view($view_to_delete);
} }
db_delete('variable')->condition('name', 'flag_lists%', 'LIKE');
drupal_set_message(t('Flag lists has been uninstalled.')); drupal_set_message(t('Flag lists has been uninstalled.'));
} }
/**
* Get rid of garbage list entries that are orphaned from a list
*/
function flag_lists_update_7000() {
$orphans = db_query("SELECT flc.fcid, flc.fid, flc.content_id, flc.uid, flcounts.content_type, count
FROM {flag_lists_content} flc
JOIN {flag_lists_counts} flcounts ON flcounts.fid=flc.fid AND flc.content_id=flcounts.content_id
LEFT JOIN {flag_lists_flags} flf ON flf.fid=flc.fid
WHERE flf.fid IS NULL");
foreach ($orphans as $orphan) {
$num_deleted = db_delete('flag_lists_content')
->condition('fid', $orphan->fid)
->condition('fcid', $orphan->fcid)
->condition('uid', $orphan->uid)
->execute();
if (!empty($num_deleted)) {
drupal_set_message("Deleting flag_id: $orphan->fid flag_content_id: $orphan->fcid");
db_update('flag_lists_counts')
->fields(array(
'count' => ($orphan->count <= 1) ? 0 : $orphan->count - 1,
))
->condition('content_type', $orphan->content_type)
->condition('fid', $orphan->fid)
->condition('content_id', $orphan->content_id)
->execute();
}
}
}
/**
* Update the flag_lists_flags table
*/
function flag_lists_update_7301() {
db_change_field('flag_lists_flags','content_type', 'entity_type',
array(
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
));
}
/**
* Update the flag_lists_content table
*/
function flag_lists_update_7302() {
db_drop_unique_key('flag_lists_content','fid_content_id_uid_sid');
db_drop_index('flag_lists_content','content_type_content_id');
db_drop_index('flag_lists_content','content_type_uid_sid');
db_change_field('flag_lists_content','content_type', 'entity_type',
array(
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
));
db_change_field('flag_lists_content','content_id', 'entity_id',
array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
db_add_unique_key('flag_lists_content',
'fid_entity_id_uid_sid',
array('fid', 'entity_id', 'uid', 'sid'));
db_add_index('flag_lists_content',
'entity_type_uid_sid',
array('entity_type', 'uid', 'sid'));
db_add_index('flag_lists_content',
'entity_type_entity_id',
array('entity_type', 'entity_id'));
}
/**
* Update the flag_lists_counts table
*/
function flag_lists_update_7303() {
db_drop_primary_key('flag_lists_counts');
db_drop_index('flag_lists_counts','fid_content_type');
db_drop_index('flag_lists_counts','content_type_content_id');
db_change_field('flag_lists_counts','content_type', 'entity_type',
array(
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
));
db_change_field('flag_lists_counts','content_id', 'entity_id',
array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '10',
),
array('primary key' => array('fid', 'entity_id')));
db_add_index('flag_lists_counts',
'fid_entity_type',
array('fid', 'entity_type'));
db_add_index('flag_lists_counts',
'entity_type_entity_id',
array('entity_type', 'entity_id'));
}
/**
* Update the views
*/
function flag_lists_update_7304() {
$myview = views_get_view('flag_lists', TRUE);
$myview->display['default']->display_options['fields']['name_2']['table'] = 'flag';
$myview->display['default']->display_options['filters']['name']['table'] = 'flag';
views_save_view($myview);
// Clear the cache for the pager
$cache = $myview->name . ':block:results:';
cache_clear_all($cache, 'cache_views_data', TRUE);
$myview = views_get_view('flag_lists_content', TRUE);
unset($myview->display['default']->display_options['relationships']['content_id']);
$myview->display['default']->display_options['relationships']['entity_id']['id'] = 'entity_id';
$myview->display['default']->display_options['relationships']['entity_id']['table'] = 'flag_lists_content';
$myview->display['default']->display_options['relationships']['entity_id']['field'] = 'entity_id';
$myview->display['default']->display_options['relationships']['entity_id']['label'] = 'Listed content';
$myview->display['default']->display_options['relationships']['entity_id']['required'] = TRUE;
views_save_view($myview);
// Clear the cache for the pager
$cache = $myview->name . ':block:results:';
cache_clear_all($cache, 'cache_views_data', TRUE);
$myview = views_get_view('flag_lists_user_list', TRUE);
$myview->display['page_1']->display_options['path'] = 'flag/lists/%';
views_save_view($myview);
// Clear the cache for the pager
$cache = $myview->name . ':block:results:';
cache_clear_all($cache, 'cache_views_data', TRUE);
}
/**
* Update the flag_lists_flags table
*/
function flag_lists_update_7305() {
db_change_field('flag_lists_flags','uid', 'uid',
array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
));
}

View File

@ -56,16 +56,6 @@ function flag_lists_menu() {
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'weight' => 3, 'weight' => 3,
); );
$items[FLAG_ADMIN_PATH . '/lists/clean'] = array(
'title' => 'Clean lists from deleted entities',
'page callback' => 'flag_list_clean_deleted',
'access callback' => 'user_access',
'access arguments' => array('administer flags'),
'file' => 'flag_lists.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 4,
);
if (module_exists('devel_generate')) { if (module_exists('devel_generate')) {
$items['admin/config/development/generate/flag-lists'] = array( $items['admin/config/development/generate/flag-lists'] = array(
'title' => 'Generate lists', 'title' => 'Generate lists',
@ -97,7 +87,17 @@ function flag_lists_menu() {
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
); );
$items['flags/lists/edit/%'] = array( // Callback for autocomplete of lists in views filter
$items['flag-lists/autocomplete_list_callback'] = array(
'title' => 'Find a list',
'page callback' => 'flag_lists_autocomplete_list_callback',
'access callback' => 'user_access',
'access arguments' => array('create flag lists'),
'file' => 'flag_lists.admin.inc',
'type' => MENU_CALLBACK,
);
$items['flag/lists/edit/%'] = array(
'title' => 'Edit a list', 'title' => 'Edit a list',
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
'page arguments' => array('flag_lists_form', 3), 'page arguments' => array('flag_lists_form', 3),
@ -106,7 +106,7 @@ function flag_lists_menu() {
'file' => 'flag_lists.admin.inc', 'file' => 'flag_lists.admin.inc',
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
); );
$items['flags/lists/delete/%'] = array( $items['flag/lists/delete/%'] = array(
'title' => 'Delete a list', 'title' => 'Delete a list',
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
'page arguments' => array('flag_lists_delete_confirm', 3), 'page arguments' => array('flag_lists_delete_confirm', 3),
@ -132,16 +132,17 @@ function flag_lists_menu() {
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
); );
$items['user/%user/flags/lists'] = array( $items['user/%user/flag/lists'] = array(
'title' => ucfirst(variable_get('flag_lists_name', 'list')), 'title' =>drupal_ucfirst(variable_get('flag_lists_name', 'list')),
'page callback' => 'flag_lists_user_page', 'page callback' => 'flag_lists_user_page',
'page arguments' => array(1), 'page arguments' => array(1),
'access callback' => 'user_access', 'access callback' => 'user_access',
'access arguments' => array('view flag lists'), 'access arguments' => array('view flag lists'),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
); );
$items['user/%user/flags/lists/%'] = array( $items['user/%user/flag/lists/%'] = array(
'title' => ucfirst(variable_get('flag_lists_name', 'list')) . ' content', 'title' =>drupal_ucfirst(variable_get('flag_lists_name', 'list')
. ' ' . 'content'),
'page callback' => 'flag_lists_user_list', 'page callback' => 'flag_lists_user_list',
'page arguments' => array(1, 4), 'page arguments' => array(1, 4),
'access callback' => 'user_access', 'access callback' => 'user_access',
@ -161,8 +162,9 @@ function flag_lists_user_page($user) {
if (!empty($view)) { if (!empty($view)) {
$view->set_display('default'); $view->set_display('default');
$view->set_arguments(array($user->uid)); $view->set_arguments(array($user->uid));
$view->pre_execute();
$output = $view->render(); $output = $view->render();
drupal_set_title(str_replace(array_keys($view->build_info['substitutions']), $view->build_info['substitutions'], $view->build_info['title'])); /* drupal_set_title(str_replace(array_keys($view->build_info['substitutions']), $view->build_info['substitutions'], $view->build_info['title'])); */
} }
return $output; return $output;
} }
@ -183,7 +185,7 @@ function theme_flag_lists_user_page($variables) {
// Build the list of flag lists for this node. // Build the list of flag lists for this node.
foreach ($flags as $flag) { foreach ($flags as $flag) {
$ops = theme('flag_lists_ops', array('flag' => $flag)); $ops = theme('flag_lists_ops', array('flag' => $flag));
$items[] = l($flag->title, "user/$uid/flags/lists/" . $flag->fid) . $ops; $items[] = l($flag->title, "user/$uid/flag/lists/" . $flag->fid) . $ops;
} }
} }
drupal_add_css(drupal_get_path('module', 'flag_lists') . '/theme/flag_lists.css'); drupal_add_css(drupal_get_path('module', 'flag_lists') . '/theme/flag_lists.css');
@ -201,8 +203,9 @@ function flag_lists_user_list($user, $fid) {
if (!empty($view)) { if (!empty($view)) {
$view->set_display('default'); $view->set_display('default');
$view->set_arguments(array($fid)); $view->set_arguments(array($fid));
$view->pre_execute();
$output = $view->render(); $output = $view->render();
drupal_set_title(str_replace(array_keys($view->build_info['substitutions']), $view->build_info['substitutions'], $view->build_info['title'])); drupal_set_title(str_replace(array_keys($view->build_info['substitutions']), $view->build_info['substitutions'], $view->build_info['title']), PASS_THROUGH);
} }
return $output; return $output;
} }
@ -223,14 +226,14 @@ function theme_flag_lists_user_list($variables) {
drupal_set_title($flag->title); drupal_set_title($flag->title);
$content = flag_lists_get_flagged_content($fid, $uid); $content = flag_lists_get_flagged_content($fid, $uid);
foreach ($content as $item) { foreach ($content as $item) {
if ($item->content_type == 'node') { if ($item->entity_type == 'node') {
$node = node_load($item->entity_id); $node = node_load($item->entity_id);
$items[] = l($node->title, 'node/' . $node->nid); $items[] = l($node->title, 'node/' . $node->nid);
} }
} }
$breadcrumb = menu_get_active_breadcrumb(); $breadcrumb = menu_get_active_breadcrumb();
$breadcrumb[] = l(t('@name lists', array('@name' => drupal_ucfirst(variable_get('flag_lists_name', t('lists'))))), 'user/' . arg(1) . '/flags/lists'); $breadcrumb[] = l(t('@name lists', array('@name' => drupal_ucfirst(variable_get('flag_lists_name', 'list')))), 'user/' . arg(1) . '/flag/lists');
drupal_set_breadcrumb($breadcrumb); drupal_set_breadcrumb($breadcrumb);
return theme('item_list', array('items' => $items)); return theme('item_list', array('items' => $items));
} }
@ -280,7 +283,8 @@ function flag_lists_permission() {
'view flag lists' => array( 'view flag lists' => array(
'title' => t('View flag lists'), 'title' => t('View flag lists'),
'description' => t(''), 'description' => t(''),
)); )
);
} }
/** /**
@ -315,8 +319,12 @@ function flag_lists_form_alter(&$form, &$form_state, $form_id) {
foreach (element_children($form['display']) as $display) { foreach (element_children($form['display']) as $display) {
$form['display'][$display]['#type'] = 'value'; $form['display'][$display]['#type'] = 'value';
} }
$form['display']['link_type']['#default_value'] = 'fl_template'; $form['display']['link_type']['#default_value'] = 'fl_template';
$form['display']['#description'] = t('Unlike normal flags, lists are only displayed in a block provided by this module or in views blocks. See <a href="/admin/build/block/list">the block admin page</a> to place the block.'); $form['display']['#description'] = t('Unlike normal flags, lists are only displayed in a block provided by this module or in views blocks. See <a href="/admin/structure/block">the block admin page</a> to place the block.');
unset($form['display']['link_options_confirm']['flag_confirmation']);
unset($form['display']['link_options_confirm']['unflag_confirmation']);
$form['display']['link_options_intro']['#children'] = '';
$form['#validate'][] = 'flag_lists_template_validate'; $form['#validate'][] = 'flag_lists_template_validate';
$form['#submit'][] = 'flag_lists_template_submit'; $form['#submit'][] = 'flag_lists_template_submit';
@ -396,17 +404,17 @@ function flag_lists_ops_form($form, &$form_state, $flo) {
// Group items into a fieldset for easier theming. // Group items into a fieldset for easier theming.
$form['flag_lists_' . $form_state['flo_operation']] = array( $form['flag_lists_' . $form_state['flo_operation']] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('List operations'), '#title' => t('@name operations', array( '@name' => drupal_ucfirst( variable_get('flag_lists_name', 'list')))),
'#tree' => TRUE, '#tree' => TRUE,
'#attributes' => array('class' => array('flag-lists-ops-fieldset')), '#attributes' => array('class' => array('flag-lists-ops-fieldset')),
); );
switch ($flo->options['flo']['operation']) { switch ($flo->options['flo']['operation']) {
case 'unflag': case 'unflag':
$null_text = 'Remove from a list'; $null_text = t('Remove from a @name', array('@name' => variable_get('flag_lists_name', 'list')));
$operation = 'unflag'; $operation = 'unflag';
$form['flag_lists_' . $form_state['flo_operation']]['list'] = array( $form['flag_lists_' . $form_state['flo_operation']]['list'] = array(
'#type' => 'button', '#type' => 'button',
'#value' => t('Remove from list'), '#value' => t('Remove from @name', array('@name' => variable_get('flag_lists_name', 'list'))),
'#ajax' => array( '#ajax' => array(
'callback' => 'flag_lists_ops_form_ajax_callback', 'callback' => 'flag_lists_ops_form_ajax_callback',
'wrapper' => 'flag-list-ops-container-' . $flo->options['flo']['operation'], 'wrapper' => 'flag-list-ops-container-' . $flo->options['flo']['operation'],
@ -414,7 +422,7 @@ function flag_lists_ops_form($form, &$form_state, $flo) {
); );
break; break;
default: default:
$null_text = 'Add to a list'; $null_text = t('Add to a @name', array('@name' => variable_get('flag_lists_name', 'list')));
$operation = 'flag'; $operation = 'flag';
drupal_add_library('system', 'ui.dialog'); drupal_add_library('system', 'ui.dialog');
$form['flag_lists_' . $form_state['flo_operation']]['list'] = array( $form['flag_lists_' . $form_state['flo_operation']]['list'] = array(
@ -442,7 +450,7 @@ function flag_lists_ops_form($form, &$form_state, $flo) {
$list_types[] = $row->type; $list_types[] = $row->type;
} }
} }
drupal_add_js(array('flag_lists' => array('types' => $list_types, 'json_path' => $base_url . '/flag-lists/add/%/js')), 'setting'); drupal_add_js(array('flag_lists' => array('types' => $list_types, 'json_path' => $base_url . '/flag-lists/add/%/js', 'listname' => variable_get('flag_lists_name', 'list'), 'form_token' => drupal_get_token(variable_get('flag_lists_name','list')))), 'setting');
break; break;
} }
@ -452,6 +460,7 @@ function flag_lists_ops_form($form, &$form_state, $flo) {
} }
if (!empty($_REQUEST['flag_lists_ops'])) { if (!empty($_REQUEST['flag_lists_ops'])) {
$ops = $_REQUEST['flag_lists_ops']; $ops = $_REQUEST['flag_lists_ops'];
$ops = is_array($ops) ? $ops : array($ops);
} }
if (!empty($ops) && !empty($list) && $form_state['values']['flag_lists_' . $form_state['flo_operation']]['operation'] == 'unflag') { if (!empty($ops) && !empty($list) && $form_state['values']['flag_lists_' . $form_state['flo_operation']]['operation'] == 'unflag') {
$hidden_deleted_values = ''; $hidden_deleted_values = '';
@ -481,21 +490,23 @@ function flag_lists_ops_form($form, &$form_state, $flo) {
return $form; return $form;
} }
function flag_lists_ops_form_ajax_callback($form, $form_state) { function flag_lists_ops_form_ajax_callback(&$form, &$form_state) {
// The form has already been submitted and updated. We can return the replaced // The form has already been submitted and updated. We can return the replaced
// item as it is. // item as it is.
$message = '';
if (!flag_lists_ops_form_validate($form, $form_state)) { if (!flag_lists_ops_form_validate($form, $form_state)) {
$message = flag_lists_ops_form_submit($form, $form_state); $message = flag_lists_ops_form_submit($form, $form_state);
} }
$form['flag_lists_' . $form_state['flo_operation']]['status_message']['#markup'] = '<div class="alert alert-success">' . $message . '</div>'; $form['flag_lists_' . $form_state['flo_operation']]['status_message']['#markup'] = '<div class="alert alert-success">' . $message . '</div>';
if ($form_state['flo_operation'] == 'flag') $form['flag_lists_' . $form_state['flo_operation']]['list']['#value'] = '0'; if ($form_state['flo_operation'] == 'flag') {
$form['flag_lists_' . $form_state['flo_operation']]['list']['#value'] = '0';
}
$form['flag_lists_' . $form_state['flo_operation']]['status_message']['#attributes']['class'][] = 'alert-success'; $form['flag_lists_' . $form_state['flo_operation']]['status_message']['#attributes']['class'][] = 'alert-success';
return $form['flag_lists_' . $form_state['flo_operation']]; return $form['flag_lists_' . $form_state['flo_operation']];
} }
function flag_lists_ops_form_validate(&$form, &$form_state) { function flag_lists_ops_form_validate($form, &$form_state) {
global $user; global $user;
$error_count = 0; $error_count = 0;
@ -509,60 +520,72 @@ function flag_lists_ops_form_validate(&$form, &$form_state) {
switch ($form_state['values']['flag_lists_' . $form_state['flo_operation']]['operation']) { switch ($form_state['values']['flag_lists_' . $form_state['flo_operation']]['operation']) {
case 'unflag': case 'unflag':
$ops = $_REQUEST['flag_lists_ops']; $user_flag_lists = flag_lists_get_user_flags();
foreach ($ops as $key => $op) { foreach ($user_flag_lists as $key => $op) {
$ops[$key] = explode('-', $op); $ops[$key] = explode('_', $key);
if (empty($ops[$key][1]) || !($flag = flag_lists_get_flag($ops[$key][1]))) { if (empty($ops[$key][3]) || !($flag = flag_lists_get_flag($ops[$key][3]))) {
form_set_error('flag_lists][remove', t('Invalid options list selected to remove from.')); form_set_error('flag_lists][remove', t('Invalid options list selected to remove from.'));
$error_count++; $error_count++;
} }
else if ($flag->uid != $user->uid) { else {
if ($flag->uid != $user->uid) {
form_set_error('flag_lists][remove', t('You are only allowed to remove content from your own lists.')); form_set_error('flag_lists][remove', t('You are only allowed to remove content from your own lists.'));
$error_count++; $error_count++;
} }
} }
}
break; break;
default: default:
if (empty($form_state['values']['flag_lists_' . $form_state['flo_operation']]['list'])) { if (empty($form_state['values']['flag_lists_' . $form_state['flo_operation']]['list'])) {
form_set_error('flag_lists][list', t('No list selected. Please select a list to add to.')); form_set_error('flag_lists][list', t('No list selected. Please select a list to add to.'));
$error_count++; $error_count++;
} }
else if (!($flag = flag_lists_get_flag($form_state['values']['flag_lists_' . $form_state['flo_operation']]['list']))) { else {
if (!($flag = flag_lists_get_flag($form_state['values']['flag_lists_' . $form_state['flo_operation']]['list']))) {
form_set_error('flag_lists][list', t('Invalid list selected. Please select a list to add to.')); form_set_error('flag_lists][list', t('Invalid list selected. Please select a list to add to.'));
$error_count++; $error_count++;
} }
else if ($flag->uid != $user->uid) { else {
if ($flag->uid != $user->uid) {
form_set_error('flag_lists][list', t('Invalid list selected. Please select a list to add to.')); form_set_error('flag_lists][list', t('Invalid list selected. Please select a list to add to.'));
$error_count++; $error_count++;
} }
}
}
break; break;
} }
return $error_count; return $error_count;
} }
function flag_lists_ops_form_submit(&$form, &$form_state) { function flag_lists_ops_form_submit($form, &$form_state) {
// Get the $ops from the originating form. // Get the $ops from the originating form.
$ops = $_REQUEST['flag_lists_ops']; $ops = $_REQUEST['flag_lists_ops'];
$ops = is_array($ops) ? $ops : array($ops);
$success_count = 0; $success_count = 0;
// Get the operation, or set it // Get the operation, or set it
switch ($form_state['values']['flag_lists_' . $form_state['flo_operation']]['operation']) { switch ($form_state['values']['flag_lists_' . $form_state['flo_operation']]['operation']) {
case 'unflag': case 'unflag':
$operation = 'unflag'; $operation = 'unflag';
$message = 'removed from'; $message = 'removed from';
foreach ($ops as $op) { $user_flag_lists = flag_lists_get_user_flags();
// Process the ID into 2 parts foreach ($user_flag_lists as $key => $op) {
list($nid, $fid) = explode('-', $op); // Iterate over all flags by this user
if (empty($nid) || empty($fid)) return; list($k1,$k2,$owner,$ofid) = explode('_', $key);
foreach ($ops as $op) {
// Iterate over all selected items
list($nid,$fid) = array_merge( explode('-', $op), array(FALSE));
if ($fid <> 0 && $fid == $ofid) {
if (($flag = flag_lists_get_flag($fid)) && ($node = node_load($nid))) { if (($flag = flag_lists_get_flag($fid)) && ($node = node_load($nid))) {
if (flag_lists_do_flag($flag, $operation, $nid)) { if (flag_lists_do_flag($flag, $operation, $nid)) {
$success_count++; $success_count++;
} }
} }
} }
}
}
break; break;
default: default:
$operation = 'flag'; $operation = 'flag';
@ -578,7 +601,12 @@ function flag_lists_ops_form_submit(&$form, &$form_state) {
break; break;
} }
$message = t('@count item(s) ' . $message . ' !title', array('@count' => $success_count, '!title' => $flag->title)); if (!empty($flag->title) && $success_count <> 0) {
$message = t('@count item(s) ' . $message . ' !listname !title', array('@count' => $success_count, '!listname' => variable_get('flag_lists_name','list'), '!title' => $flag->title));
}
else {
$message = t('No items affected.');
}
if ($_GET['q'] != 'system/ajax') { if ($_GET['q'] != 'system/ajax') {
drupal_set_message($message); drupal_set_message($message);
} }
@ -621,7 +649,10 @@ function flag_lists_template_validate($form, &$form_state) {
if (isset($content_types) && count($content_types)) { if (isset($content_types) && count($content_types)) {
$content_types = implode(', ', $content_types); $content_types = implode(', ', $content_types);
$templates = implode(', ', array_unique($templates)); $templates = implode(', ', array_unique($templates));
form_set_error('types', t('The flaggable content type(s) "@type" is(are) already assigned to the template(s) "@template." A content type may be assigned to only one template. To reassign a content type you must first remove its other assignment.', array('@type' => $content_types, '@template' => $templates))); form_set_error('types', t('The flaggable content type(s) "@type" is(are) already assigned to the template(s) "@template." A content type may be assigned to only one template. To reassign a content type you must first remove its other assignment.', array(
'@type' => $content_types,
'@template' => $templates
)));
} }
} }
@ -640,6 +671,7 @@ function flag_lists_template_submit($form, &$form_state) {
->execute(); ->execute();
} }
} }
/** /**
* Helper function to build an array of all lists available to or owned by the * Helper function to build an array of all lists available to or owned by the
* current user and that are available on the current content type. * current user and that are available on the current content type.
@ -661,7 +693,7 @@ function flag_lists_get_content_fids() {
->condition('fc.uid', $user->uid) ->condition('fc.uid', $user->uid)
->condition('fn.type', $type); ->condition('fn.type', $type);
$query->leftJoin('flag_types', 'fn', 'fn.fid = fc.fid'); $query->leftJoin('flag_types', 'fn', 'fn.fid = fc.fid');
$query->leftJoin('flags', 'f', 'fc.fid = f.fid'); $query->leftJoin('flag', 'f', 'fc.fid = f.fid');
$fc_result = $query->execute(); $fc_result = $query->execute();
foreach ($fc_result as $row) { foreach ($fc_result as $row) {
@ -672,7 +704,7 @@ function flag_lists_get_content_fids() {
// This is the flag / unflag callback // This is the flag / unflag callback
elseif (arg(0) == 'flag' && (arg(1) == 'flag' || arg(1) == 'unflag')) { elseif (arg(0) == 'flag' && (arg(1) == 'flag' || arg(1) == 'unflag')) {
// Get the flag for this request. // Get the flag for this request.
$fids[] = db_select('flags', 'f') $fids[] = db_select('flag', 'f')
->fields('f', array('fid')) ->fields('f', array('fid'))
->condition('name', arg(2)) ->condition('name', arg(2))
->execute() ->execute()
@ -681,7 +713,7 @@ function flag_lists_get_content_fids() {
// Get the regular flags for this node. The flag module will narrow by role, // Get the regular flags for this node. The flag module will narrow by role,
// etc. when flag_get_flags() is called. These flag ids are always returned. // etc. when flag_get_flags() is called. These flag ids are always returned.
$query = db_select('flags', 'f') $query = db_select('flag', 'f')
->fields('f', array('fid')) ->fields('f', array('fid'))
->condition('fc.fid', NULL); ->condition('fc.fid', NULL);
$query->leftJoin('flag_lists', 'fc', 'fc.fid = f.fid'); $query->leftJoin('flag_lists', 'fc', 'fc.fid = f.fid');
@ -704,11 +736,11 @@ function flag_lists_get_content_fids() {
function flag_lists_block_info() { function flag_lists_block_info() {
return array( return array(
'flag_lists' => array( 'flag_lists' => array(
'info' => t('Lists'), 'info' => drupal_ucfirst(t('@name', array('@name' => variable_get('flag_lists_name','list')))),
'cache' => DRUPAL_NO_CACHE, 'cache' => DRUPAL_NO_CACHE,
), ),
'flag_lists_list' => array( 'flag_lists_list' => array(
'info' => t('My lists'), 'info' => t('My @name', array('@name' => variable_get('flag_lists_name', 'list'))),
'cache' => DRUPAL_NO_CACHE, 'cache' => DRUPAL_NO_CACHE,
), ),
); );
@ -726,13 +758,13 @@ function flag_lists_block_configure($delta = '') {
'create_lists' => array( 'create_lists' => array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Show link to add new list'), '#title' => t('Show link to add new list'),
'#default_value' => variable_get('flag_lists_create_lists', 0), '#default_value' => variable_get('flag_lists_create_lists', 1),
'#description' => t('Checking this adds a link to the create new list form.'), '#description' => t('Checking this adds a link to the create new list form.'),
), ),
'ops' => array( 'ops' => array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Show edit and delete links'), '#title' => t('Show edit and delete links'),
'#default_value' => variable_get('flag_lists_ops', 0), '#default_value' => variable_get('flag_lists_ops', 1),
'#description' => t('Checking this appends edit and delete links to each list name for users with access.'), '#description' => t('Checking this appends edit and delete links to each list name for users with access.'),
), ),
'include_flags' => array( 'include_flags' => array(
@ -770,8 +802,13 @@ function flag_lists_block_view($delta = '') {
case 'flag_lists': case 'flag_lists':
if (user_access('create flag lists')) { if (user_access('create flag lists')) {
$block = array( $block = array(
'subject' => t('My lists'), 'subject' => t('My @name', array('@name' => variable_get('flag_lists_name', 'list'))),
'content' => theme('flag_lists_list', array('node' => NULL, 'create' => variable_get('flag_lists_create_lists', 0), 'ops' =>variable_get('flag_lists_ops', 0), 'use_flags' => variable_get('flag_lists_include_flags', 0))), 'content' => theme('flag_lists_list', array(
'node' => NULL,
'create' => variable_get('flag_lists_create_lists', 0),
'ops' => variable_get('flag_lists_ops', 0),
'use_flags' => variable_get('flag_lists_include_flags', 0)
)),
); );
} }
break; break;
@ -781,7 +818,7 @@ function flag_lists_block_view($delta = '') {
$account = user_load($user->uid); $account = user_load($user->uid);
$block = array( $block = array(
'subject' => t('My lists'), 'subject' => t('My @name', array('@name' => variable_get('flag_lists_name', 'list'))),
'content' => flag_lists_user_page($account), 'content' => flag_lists_user_page($account),
); );
} }
@ -807,7 +844,7 @@ function flag_lists_set_messages(&$flag) {
// Get the parent flag. These are cached by the flag module. // Get the parent flag. These are cached by the flag module.
$pflag = flag_get_flag(NULL, $flag->pfid); $pflag = flag_get_flag(NULL, $flag->pfid);
$title = $flag->title; $title = $flag->title;
$lists_name = variable_get('flag_lists_name', t('list')); $lists_name = t('@name', array('@name' => variable_get('flag_lists_name', 'list')));
$flag->flag_short = $pflag->flag_short; $flag->flag_short = $pflag->flag_short;
$flag->flag_long = $pflag->flag_long; $flag->flag_long = $pflag->flag_long;
$flag->flag_message = $pflag->flag_message; $flag->flag_message = $pflag->flag_message;
@ -822,7 +859,7 @@ function flag_lists_set_messages(&$flag) {
* Make sure a user can only see his/her own personal flags. * Make sure a user can only see his/her own personal flags.
*/ */
function flag_lists_flag_access($flag, $entity_id, $action, $account) { function flag_lists_flag_access($flag, $entity_id, $action, $account) {
if (!empty($flag->module) && $flag->module == 'flag_lists') { if ( !empty($flag->name) && (strpos($flag->name, 'flag_lists') === 0) ) {
switch ($action) { switch ($action) {
case 'flag': case 'flag':
case 'unflag': case 'unflag':
@ -902,7 +939,7 @@ function flag_lists_flag_delete($flag) {
*/ */
function flag_lists_views_api() { function flag_lists_views_api() {
return array( return array(
'api' => 2.0, 'api' => 3.0,
'path' => drupal_get_path('module', 'flag_lists') . '/includes', 'path' => drupal_get_path('module', 'flag_lists') . '/includes',
); );
} }
@ -927,7 +964,9 @@ function flag_lists_is_owner($action, $name) {
if (!user_access($action . ' own flag lists')) { if (!user_access($action . ' own flag lists')) {
return FALSE; return FALSE;
} }
if (db_select('flag_lists_flags', 'f')->fields('f')->condition('f.name', $name)->condition('f.uid', $user->uid)->countQuery()->execute()->fetchField()) { if (db_select('flag_lists_flags', 'f')->fields('f')->condition('f.name', $name)->condition('f.uid', $user->uid)
->countQuery()->execute()->fetchField()
) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -967,8 +1006,12 @@ function flag_lists_get_user_flags($content_type = NULL, $account = NULL, $use_f
if ($use_flags) { if ($use_flags) {
$flags = flag_get_flags('node', $content_type, $account); $flags = flag_get_flags('node', $content_type, $account);
// Strip out any list templates
foreach ($flags as $key => $flag) { foreach ($flags as $key => $flag) {
if (!isset($flag->module)) {
// Assume flag is from flag module
$flags[$key]->module = 'flag';
}
// Strip out any list templates
if (stristr($flag->name, 'fl_template') !== FALSE) { if (stristr($flag->name, 'fl_template') !== FALSE) {
unset($flags[$key]); unset($flags[$key]);
} }
@ -989,8 +1032,16 @@ function theme_flag_lists_ops($variables) {
$flag = $variables['flag']; $flag = $variables['flag'];
$links = array( $links = array(
'flags_edit' => array('title' => t('edit'), 'href' => 'flags/lists/edit/' . $flag->name, 'query' => drupal_get_destination()), 'flags_edit' => array(
'flags_delete' => array('title' => t('delete'), 'href' => 'flags/lists/delete/' . $flag->name, 'query' => drupal_get_destination()), 'title' => t('edit'),
'href' => 'flag/lists/edit/' . $flag->name,
'query' => drupal_get_destination()
),
'flags_delete' => array(
'title' => t('delete'),
'href' => 'flag/lists/delete/' . $flag->name,
'query' => drupal_get_destination()
),
); );
return theme('links', array('links' => $links, 'attributes' => array('class' => 'flag_lists_ops'))); return theme('links', array('links' => $links, 'attributes' => array('class' => 'flag_lists_ops')));
} }
@ -1042,6 +1093,7 @@ function theme_flag_lists_list($variables) {
global $user; global $user;
if ($flags = flag_lists_get_user_flags($content_type, $user, $use_flags)) { if ($flags = flag_lists_get_user_flags($content_type, $user, $use_flags)) {
// Build the list of lists for this node. // Build the list of lists for this node.
foreach ($flags as $flag) { foreach ($flags as $flag) {
if ($flag->module == 'flag_lists') { if ($flag->module == 'flag_lists') {
$action = _flag_lists_is_flagged($flag, $entity_id, $user->uid, 0) ? 'unflag' : 'flag'; $action = _flag_lists_is_flagged($flag, $entity_id, $user->uid, 0) ? 'unflag' : 'flag';
@ -1076,7 +1128,11 @@ function theme_flag_lists_list($variables) {
} }
drupal_add_css(drupal_get_path('module', 'flag_lists') . '/theme/flag_lists.css'); drupal_add_css(drupal_get_path('module', 'flag_lists') . '/theme/flag_lists.css');
return theme('item_list', array('items' => $items, 'type' => 'ul', 'attributes' => array('class' => 'flag-lists-links'))); return theme('item_list', array(
'items' => $items,
'type' => 'ul',
'attributes' => array('class' => 'flag-lists-links')
));
} }
@ -1221,44 +1277,22 @@ function flag_lists_flag_link($flag, $action, $entity_id) {
} }
/** /**
* Implementation of hook_flag_link_types(). * Implementation of hook_flag_link_type_info().
*/ */
function flag_lists_flag_link_types() { function flag_lists_flag_link_type_info() {
return array( return array(
'fl_template' => array( 'fl_template' => array(
'title' => t('Flag Lists toggle'), 'title' => t('Flag Lists toggle'),
'description' => t('If you are creating a Flag lists template flag, you must select this link type.'), 'description' => t('If you are creating a Flag lists template flag, you must select this link type.'),
'options' => array(),
'uses standard js' => TRUE,
'uses standard css' => TRUE,
), ),
); );
} }
function flag_lists_flag_default_flags($name = 'fl_template') { function flag_lists_flag_default_flags() {
// return array(
// array(
// 'api_version' => 2,
// 'name' => $name,
// 'module' => 'flag_lists',
// 'content_type' => 'node',
// 'global' => 0,
// 'show_on_page' => 0,
// 'show_on_teaser' => 0,
// 'show_on_form' => 0,
// // The following UI labels aren't wrapped in t() because they are written
// // to the DB in English. They are passed to t() later, thus allowing for
// // multilingual sites.
// 'title' => 'Flag lists template',
// 'flag_short' => 'Add to your [flag_lists:title] [flag_lists:term]',
// 'flag_long' => 'Add this post to your [flag_lists:title] [flag_lists:term]',
// 'flag_message' => 'This post has been added to your [flag_lists:title] [flag_lists:term]',
// 'unflag_short' => 'Remove this from your [flag_lists:title] [flag_lists:term]',
// 'unflag_long' => 'Remove this post from your [flag_lists:title] [flag_lists:term]',
// 'unflag_message' => 'This post has been removed from your [flag_lists:title] [flag_lists:term]',
// 'types' => array(),
// 'link_type' => 'toggle',
// ),
// );
$flags = array(); $flags = array();
// Exported flag: "Flag lists template". // Exported flag: "Flag lists template".
$flags['fl_template'] = array( $flags['fl_template'] = array(
@ -1287,8 +1321,6 @@ $flags['fl_template'] = array(
), ),
); );
return $flags; return $flags;
} }
/** /**
@ -1361,7 +1393,7 @@ function flag_lists_fl_delete($flag, $account = NULL) {
$flag->is_deleted = TRUE; $flag->is_deleted = TRUE;
module_invoke_all('flag_lists', $flag, $account); module_invoke_all('flag_lists', $flag, $account);
_flag_lists_clear_cache(); _flag_lists_clear_cache();
drupal_set_message(t('The @name @title has been deleted.', array('@name' => variable_get('flag_lists_name', t('list')), '@title' => $flag->title))); drupal_set_message(t('The @name @title has been deleted.', array('@name' => variable_get('flag_lists_name', 'list'), '@title' => $flag->title)));
} }
@ -1430,7 +1462,7 @@ function flag_lists_page($action = NULL, $flag_name = NULL, $entity_id = NULL) {
'newLink' => $new_link, 'newLink' => $new_link,
// Further information for the benefit of custom JavaScript event handlers: // Further information for the benefit of custom JavaScript event handlers:
'contentId' => $entity_id, 'contentId' => $entity_id,
'contentType' => $flag->content_type, 'contentType' => $flag->entity_type,
'flagName' => $flag->name, 'flagName' => $flag->name,
'flagStatus' => $action, 'flagStatus' => $action,
)); ));
@ -1480,7 +1512,7 @@ function flag_lists_fix_link(&$link, $action) {
else { else {
// We are skipping permission checks. However, at a minimum we must make // We are skipping permission checks. However, at a minimum we must make
// sure the flag applies to this content type: // sure the flag applies to this content type:
if (!$flag->applies_to_content_id($entity_id)) { if (!$flag->applies_to_entity_id($entity_id)) {
return FALSE; return FALSE;
} }
} }
@ -1505,17 +1537,19 @@ function flag_lists_fix_link(&$link, $action) {
if ($action == 'unflag') { if ($action == 'unflag') {
if ($flagged) { if ($flagged) {
$fcid = _flag_lists_unflag($flag, $entity_id, $uid, $sid); $fcid = _flag_lists_unflag($flag, $entity_id, $uid, $sid);
module_invoke_all('flag', 'unflag', $flag, $entity_id, $account, $fcid); module_invoke_all('flag_unflag', $flag, $entity_id, $account, $fcid);
return TRUE;
} }
} }
elseif ($action == 'flag') { elseif ($action == 'flag') {
if (!$flagged) { if (!$flagged) {
$fcid = _flag_lists_flag($flag, $entity_id, $uid, $sid); $fcid = _flag_lists_flag($flag, $entity_id, $uid, $sid);
module_invoke_all('flag', 'flag', $flag, $entity_id, $account, $fcid); module_invoke_all('flag_flag', $flag, $entity_id, $account, $fcid);
return TRUE;
} }
} }
return TRUE; return FALSE;
} }
@ -1585,32 +1619,6 @@ function flag_lists_fix_link(&$link, $action) {
return $fcid; return $fcid;
} }
/**
* Remove all entries of entity_id and type
*
* @param $entity_id
* Entity id which has been flagged.
* @param $type
* The entity type.
*/
function _flag_lists_remove_entity($entity_id, $type) {
$query = db_select('flag_lists_content')
->condition('entity_id', $entity_id)
->condition('entity_type', $type);
$query->fields('flag_lists_content', array('fcid', 'fid', 'uid', 'sid'));
$items = $query->execute()->fetchAll();
if ($items) {
foreach ($items as $key => $value) {
db_delete('flag_lists_content')
->condition('fcid', $value->fcid)
->execute();
watchdog('flag_lists', t('Deleted entry @fcid from flat_lists_content', array('@fcid' => $value->fcid)));
}
}
}
/** /**
* Updates the flag count for this content * Updates the flag count for this content
*/ */
@ -1668,7 +1676,11 @@ function flag_lists_template_exists($type) {
* Checks for a list title by node type. * Checks for a list title by node type.
*/ */
function flag_lists_title_exists($title, $type) { function flag_lists_title_exists($title, $type) {
return db_query("SELECT COUNT(flf.fid) FROM {flag_lists_flags} flf LEFT JOIN {flag_types} ft ON flf.pfid=ft.fid WHERE flf.title=:title AND ft.type=:type AND flf.uid=:uid", array(':title' => $title, ':type' => $type, ':uid' => $GLOBALS['user']->uid))->fetchField(); return db_query("SELECT COUNT(flf.fid) FROM {flag_lists_flags} flf LEFT JOIN {flag_types} ft ON flf.pfid=ft.fid WHERE flf.title=:title AND ft.type=:type AND flf.uid=:uid", array(
':title' => $title,
':type' => $type,
':uid' => $GLOBALS['user']->uid
))->fetchField();
} }
/** /**
@ -1718,6 +1730,7 @@ function flag_lists_token_info() {
* Implements hook_tokens(). * Implements hook_tokens().
*/ */
function flag_lists_tokens($type, $tokens, array $data = array(), array $options = array()) { function flag_lists_tokens($type, $tokens, array $data = array(), array $options = array()) {
$sanitize = !empty($options['sanitize']);
$replacements = array(); $replacements = array();
if ($type == 'flag_lists' && !empty($data['flag_lists'])) { if ($type == 'flag_lists' && !empty($data['flag_lists'])) {
@ -1725,10 +1738,10 @@ function flag_lists_tokens($type, $tokens, array $data = array(), array $options
foreach ($tokens as $name => $original) { foreach ($tokens as $name => $original) {
switch ($name) { switch ($name) {
case 'title': case 'title':
$replacements[$original] = $flag_list->title; $replacements[$original] = $sanitize ? check_plain($flag_list->title) : $flag_lists->title;
break; break;
case 'term': case 'term':
$replacements[$original] = variable_get('flag_lists_name', t('list')); $replacements[$original] = $sanitize ? check_plain(variable_get('flag_lists_name', 'list')) : variable_get('flag_lists_name', 'list');
break; break;
} }
} }
@ -1765,21 +1778,10 @@ function flag_lists_views_form_substitutions() {
$select_all = array( $select_all = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => FALSE, '#default_value' => FALSE,
'#attributes' => array('class' => array('flo-table-select-all')), '#attributes' => array('class' => array('flo-table-select-all'),
'title' => array(t('Select all'))),
); );
return array( return array(
$select_all_placeholder => drupal_render($select_all), $select_all_placeholder => drupal_render($select_all),
); );
} }
/**
* Implements hook_entity_delete
*/
function flag_lists_entity_delete($entity, $type) {
foreach (flag_get_flags($type) as $flag) {
if (isset($entity->vid)) {
$items = _flag_lists_remove_entity($entity->vid, $type);
}
}
}

View File

@ -59,7 +59,7 @@ function flag_lists_views_data_alter(&$data) {
); );
// We need fid and name form flags' data, and join. // We need fid and name form flags' data, and join.
$data['flags'] = array( $data['flag'] = array(
'table' => array( 'table' => array(
'group' => t('Flag'), 'group' => t('Flag'),
'join' => array( 'join' => array(
@ -228,8 +228,7 @@ function flag_lists_views_data() {
'handler' => 'flag_lists_handler_field_list', 'handler' => 'flag_lists_handler_field_list',
), ),
'filter' => array( 'filter' => array(
'handler' => 'views_handler_filter_string', 'handler' => 'flag_lists_handler_filter_list',
'allow empty' => TRUE,
), ),
'argument' => array( 'argument' => array(
'handler' => 'views_handler_argument_string', 'handler' => 'views_handler_argument_string',
@ -261,7 +260,7 @@ function flag_lists_views_data() {
'join' => array( 'join' => array(
'node' => array( 'node' => array(
'left_field' => 'nid', 'left_field' => 'nid',
'field' => 'content_id', 'field' => 'entity_id',
), ),
), ),
'group' => t('Flag lists'), 'group' => t('Flag lists'),
@ -275,7 +274,7 @@ function flag_lists_views_data() {
'label' => t('List user'), 'label' => t('List user'),
), ),
), ),
'content_id' => array( 'entity_id' => array(
'relationship' => array( 'relationship' => array(
'title' => t('Node'), 'title' => t('Node'),
'help' => t('The node that has been listed'), 'help' => t('The node that has been listed'),
@ -313,7 +312,7 @@ function flag_lists_views_data() {
'flag_lists_flags' => array( 'flag_lists_flags' => array(
'table' => 'flag_lists_types', 'table' => 'flag_lists_types',
'type' => 'INNER', 'type' => 'INNER',
'left_table' => 'flags', 'left_table' => 'flag',
'left_field' => 'name', 'left_field' => 'name',
'field' => 'name', 'field' => 'name',
), ),

View File

@ -168,7 +168,7 @@ function flag_lists_views_default_views() {
'exclude' => 0, 'exclude' => 0,
'link_to_list' => FALSE, 'link_to_list' => FALSE,
'id' => 'name_2', 'id' => 'name_2',
'table' => 'flags', 'table' => 'flag',
'field' => 'name', 'field' => 'name',
'relationship' => 'none', 'relationship' => 'none',
), ),
@ -259,7 +259,7 @@ function flag_lists_views_default_views() {
'reduce' => 0, 'reduce' => 0,
), ),
'id' => 'name', 'id' => 'name',
'table' => 'flags', 'table' => 'flag',
'field' => 'name', 'field' => 'name',
'relationship' => 'none', 'relationship' => 'none',
), ),
@ -843,7 +843,7 @@ function flag_lists_views_default_views() {
'type' => 'none', 'type' => 'none',
)); ));
$handler = $view->new_display('page', 'Page', 'page_1'); $handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'flags/lists/%'); $handler->override_option('path', 'flag/lists/%');
$handler->override_option('menu', array( $handler->override_option('menu', array(
'type' => 'none', 'type' => 'none',
'title' => '', 'title' => '',

View File

@ -45,7 +45,7 @@ class flag_lists_handler_field_list extends views_handler_field {
function render_link($data, $values) { function render_link($data, $values) {
if (!empty($this->options['link_to_list']) && $data !== NULL && $data !== '') { if (!empty($this->options['link_to_list']) && $data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE; $this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "user/" . $values->{$this->aliases['uid']} . "/flags/lists/" . $values->{$this->aliases['fid']}; $this->options['alter']['path'] = "user/" . $values->{$this->aliases['uid']} . "/flag/lists/" . $values->{$this->aliases['fid']};
} }
return $data; return $data;
} }

View File

@ -45,6 +45,6 @@ class flag_lists_handler_field_list_delete extends views_handler_field {
} }
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete'); $text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
return l($text, "flags/lists/delete/" . $fid, array('query' => drupal_get_destination())); return l($text, "flag/lists/delete/" . $fid, array('query' => drupal_get_destination()));
} }
} }

View File

@ -45,6 +45,6 @@ class flag_lists_handler_field_list_edit extends views_handler_field {
} }
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit'); $text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
return l($text, "flags/lists/edit/" . $fid, array('query' => drupal_get_destination())); return l($text, "flag/lists/edit/" . $fid, array('query' => drupal_get_destination()));
} }
} }

View File

@ -69,6 +69,17 @@ class flag_lists_handler_field_ops extends views_handler_field {
'#tree' => TRUE, '#tree' => TRUE,
); );
// Do we add or delete?
$operation = array();
if ($this->options['flo']['operation'] == 'flag') {
$operation[0] = 'Add';
$operation[1] = 'to';
}
else {
$operation[0] = 'Remove';
$operation[1] = 'from';
};
// At this point, the query has already been run, so we can access the results // At this point, the query has already been run, so we can access the results
// in order to get the base key value (for example, nid for nodes). // in order to get the base key value (for example, nid for nodes).
foreach ($this->view->result as $row_index => $row) { foreach ($this->view->result as $row_index => $row) {
@ -78,7 +89,13 @@ class flag_lists_handler_field_ops extends views_handler_field {
$form[$this->options['id']][$row_index] = array( $form[$this->options['id']][$row_index] = array(
'#type' => 'radio', '#type' => 'radio',
'#parents' => array($this->options['id']), '#parents' => array($this->options['id']),
'#return_value' => $entity_id, '#return_value' => $entity_id . (isset($row->flag_lists_flags_fid) ? ('-' . $row->flag_lists_flags_fid) : ''),
'#attributes' => array('title' =>
array(t('@oper this item, @entity_id, @direction the @name',
array('@oper' => $operation[0],
'@entity_id' => $entity_id,
'@direction' => $operation[1],
'@name' => variable_get('flag_lists_name','list'))))),
); );
} }
else { else {
@ -86,7 +103,12 @@ class flag_lists_handler_field_ops extends views_handler_field {
'#type' => 'checkbox', '#type' => 'checkbox',
'#return_value' => $entity_id . (isset($row->flag_lists_flags_fid) ? ('-' . $row->flag_lists_flags_fid) : ''), '#return_value' => $entity_id . (isset($row->flag_lists_flags_fid) ? ('-' . $row->flag_lists_flags_fid) : ''),
'#default_value' => FALSE, '#default_value' => FALSE,
'#attributes' => array('class' => array('flo-select')), '#attributes' => array('class' => array('flo-select'),
'title' => array(t('@oper item @entity_id @direction the @name',
array('@oper' => $operation[0],
'@entity_id' => $entity_id,
'@direction' => $operation[1],
'@name' => variable_get('flag_lists_name', 'list'))))),
); );
} }
} }

View File

@ -14,7 +14,7 @@ class flag_lists_handler_field_template extends views_handler_field {
*/ */
function construct() { function construct() {
parent::construct(); parent::construct();
$this->additional_fields['name'] = array('table' => 'flags', 'field' => 'name'); $this->additional_fields['name'] = array('table' => 'flag', 'field' => 'name');
} }
function option_definition() { function option_definition() {
@ -44,7 +44,7 @@ class flag_lists_handler_field_template extends views_handler_field {
function render_link($data, $values) { function render_link($data, $values) {
if (!empty($this->options['link_to_template']) && $data !== NULL && $data !== '') { if (!empty($this->options['link_to_template']) && $data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE; $this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "admin/build/flags/edit/" . $values->{$this->aliases['name']}; $this->options['alter']['path'] = "admin/structure/flags/manage/" . $values->{$this->aliases['name']};
} }
return $data; return $data;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @file flag_lists_handler_field_template_types.inc * @file flag_lists_handler_field_template_types.inc
* Field handler to provide a list of template node types. * Field handler to provide a list of template node types.
@ -6,14 +7,15 @@
class flag_lists_handler_field_template_types extends views_handler_field_prerender_list { class flag_lists_handler_field_template_types extends views_handler_field_prerender_list {
function construct() { function construct() {
parent::construct(); parent::construct();
$this->additional_fields['name'] = array('table' => 'flags', 'field' => 'name'); $this->additional_fields['name'] = array('table' => 'flag', 'field' => 'name');
} }
function query() { function query() {
$this->add_additional_fields(); $this->add_additional_fields();
$this->field_alias = $this->aliases['name']; $this->field_alias = $this->aliases['name'];
} }
function pre_render($values) { function pre_render(&$values) {
$names = array(); $names = array();
$this->items = array(); $this->items = array();
@ -23,7 +25,7 @@ class flag_lists_handler_field_template_types extends views_handler_field_preren
if (count($names)) { if (count($names)) {
$query = db_select('flag_lists_types', 'flt'); $query = db_select('flag_lists_types', 'flt');
$query->innerJoin('flags', 'f', 'flt.name = f.name'); $query->innerJoin('flag', 'f', 'flt.name = f.name');
$result = $query->fields('flt', array('type', 'name')) $result = $query->fields('flt', array('type', 'name'))
->condition('f.name', $names, 'IN') ->condition('f.name', $names, 'IN')
->orderBy('flt.type') ->orderBy('flt.type')

View File

@ -0,0 +1,20 @@
<?php
/**
* @file flag_lists_handler_filter_list.inc
* Filter by flag lists
*
* https://api.drupal.org/api/examples/ajax_example!ajax_example_autocomplete.inc/7
*/
class flag_lists_handler_filter_list extends views_handler_filter_string {
function value_form(&$form, &$form_state) {
parent::value_form($form, $form_state);
if ( $form['value']['#type'] == 'textfield') {
$form['value']['#autocomplete_path'] =
'flag-lists/autocomplete_list_callback';
}
}
}

View File

@ -30,24 +30,26 @@
select.addClass('new-list-processed'); select.addClass('new-list-processed');
if (Drupal.settings.flag_lists.types.length > 0) { if (Drupal.settings.flag_lists.types.length > 0) {
$(this).after('<a href="#" class="create-a-new-list">New list?</a><div class="new-list-form"><form><select name="type" class="type"></select><label for="name">List name</label><input type="textfield" name="name" class="name" /></form></div>'); $(this).after('<a href="#" class="create-a-new-list">New ' + Drupal.settings.flag_lists.listname + '?</a><div class="new-list-form"><form><select name="type" class="type"></select><label for="name">New ' + Drupal.settings.flag_lists.listname + ' name</label><input type="textfield" name="name" class="name" /></form></div>');
var dialog = $('.new-list-form', $(this).parent()).dialog({ var dialog = $('.new-list-form', $(this).parent()).dialog({
autoOpen: false, autoOpen: false,
height: 300, height: 300,
width: 350, width: 350,
modal: true, modal: true,
buttons: { buttons: {
"Create a new list": function() { "Create": function() {
var name = $('input.name', $(this)).val(); var name = $('input.name', $(this)).val();
var type = $('select.type', $(this)).val(); var type = $('select.type', $(this)).val();
name = encodeURIComponent(name);
$.getJSON(Drupal.settings.flag_lists.json_path.replace('%', type)+'?name='+name, function(data) { $.getJSON(Drupal.settings.flag_lists.json_path.replace('%', type)+ '?form_token=' + Drupal.settings.flag_lists.form_token +'&name='+name, function(data) {
if (data.error) { if (data.error) {
alert(data.error); alert(data.error);
} }
else { else {
select.append('<option value="'+data.flag.fid+'">'+data.flag.title+'</option>'); select.append('<option value="'+data.flag.fid+'">'+data.flag.title+'</option>');
$('input.name', $(this)).val(''); $('input.name', $(this)).val('');
location.reload(true);
dialog.dialog('close'); dialog.dialog('close');
} }
}); });
@ -70,9 +72,12 @@
// Put entries into the optgroup // Put entries into the optgroup
for (j in Drupal.settings.flag_lists.types) { for (j in Drupal.settings.flag_lists.types) {
var type = Drupal.settings.flag_lists.types[j]; var type = Drupal.settings.flag_lists.types[j];
$('.new-list-form form select.type').append('<option value="'+type+'" class="'+type+'">List for '+type+'</option>'); $('.new-list-form form select.type').append('<option value="'+type+'" class="'+type+'">' + Drupal.settings.flag_lists.listname + ' for '+type+'</option>');
} }
} }
if ( Drupal.settings.flag_lists.types.length <= 1) {
$('.new-list-form form select.type', context).hide();
}
}); });
} }
} }

View File

@ -1,4 +1,4 @@
.block-flag_lists .flag-message { .block-flag-lists .flag-message {
position: relative; position: relative;
clear: both; clear: both;
top:0; top:0;