update for flag 3.x
- table flags becomes flag - replace all content_type and content_id by entity_type and entity_id - changed flag_lists.install (new rows name entity_type & entity_id) and flags table name become flag - factory_by_content_type('node') became factory_by_entity_type('node') - flag_lists.views_default.inc (entity_id & entity_type) Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
04d628c609
commit
c259bc4543
@ -110,7 +110,7 @@ function flag_lists_add_js($type = NULL) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New flag. Load the template row.
|
// 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->leftJoin('flag_lists_types', 'fl', 'f.name = fl.name');
|
||||||
$query->fields('f')
|
$query->fields('f')
|
||||||
->fields('fl')
|
->fields('fl')
|
||||||
@ -119,7 +119,7 @@ function flag_lists_add_js($type = NULL) {
|
|||||||
$row = $query->execute()
|
$row = $query->execute()
|
||||||
->fetchObject();
|
->fetchObject();
|
||||||
|
|
||||||
$newflag = flag_flag::factory_by_content_type('node');
|
$newflag = flag_flag::factory_by_entity_type('node');
|
||||||
|
|
||||||
$flag = $newflag->factory_by_row($row);
|
$flag = $newflag->factory_by_row($row);
|
||||||
// The template fid becomes the flag_lists parent flag.
|
// The template fid becomes the flag_lists parent flag.
|
||||||
@ -243,7 +243,7 @@ function flag_lists_form_submit($form, $form_state, $account = NULL) {
|
|||||||
else {
|
else {
|
||||||
// New flag. Load the template row.
|
// New flag. Load the template row.
|
||||||
$type = $form_state['values']['type'];
|
$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->leftJoin('flag_lists_types', 'fl', 'f.name = fl.name');
|
||||||
$query->fields('f')
|
$query->fields('f')
|
||||||
->fields('fl')
|
->fields('fl')
|
||||||
@ -252,7 +252,7 @@ function flag_lists_form_submit($form, $form_state, $account = NULL) {
|
|||||||
$row = $query->execute()
|
$row = $query->execute()
|
||||||
->fetchObject();
|
->fetchObject();
|
||||||
|
|
||||||
$newflag = flag_flag::factory_by_content_type('node');
|
$newflag = flag_flag::factory_by_entity_type('node');
|
||||||
|
|
||||||
$flag = $newflag->factory_by_row($row);
|
$flag = $newflag->factory_by_row($row);
|
||||||
// The template fid becomes the flag_lists parent flag.
|
// The template fid becomes the flag_lists parent flag.
|
||||||
|
@ -30,7 +30,7 @@ function flag_lists_schema() {
|
|||||||
'unsigned' => TRUE,
|
'unsigned' => TRUE,
|
||||||
'not null' => TRUE,
|
'not null' => TRUE,
|
||||||
),
|
),
|
||||||
'content_type' => array(
|
'entity_type' => array(
|
||||||
'type' => 'varchar',
|
'type' => 'varchar',
|
||||||
'length' => '32',
|
'length' => '32',
|
||||||
'not null' => TRUE,
|
'not null' => TRUE,
|
||||||
@ -72,13 +72,13 @@ function flag_lists_schema() {
|
|||||||
'not null' => TRUE,
|
'not null' => TRUE,
|
||||||
'default' => 0,
|
'default' => 0,
|
||||||
),
|
),
|
||||||
'content_type' => array(
|
'entity_type' => array(
|
||||||
'type' => 'varchar',
|
'type' => 'varchar',
|
||||||
'length' => '32',
|
'length' => '32',
|
||||||
'not null' => TRUE,
|
'not null' => TRUE,
|
||||||
'default' => '',
|
'default' => '',
|
||||||
),
|
),
|
||||||
'content_id' => array(
|
'entity_id' => array(
|
||||||
'type' => 'int',
|
'type' => 'int',
|
||||||
'unsigned' => TRUE,
|
'unsigned' => TRUE,
|
||||||
'not null' => TRUE,
|
'not null' => TRUE,
|
||||||
@ -106,11 +106,11 @@ function flag_lists_schema() {
|
|||||||
),
|
),
|
||||||
'primary key' => array('fcid'),
|
'primary key' => array('fcid'),
|
||||||
'unique keys' => array(
|
'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(
|
'indexes' => array(
|
||||||
'content_type_content_id' => array('content_type', 'content_id'),
|
'entity_type_entity_id' => array('entity_type', 'entity_id'),
|
||||||
'content_type_uid_sid' => array('content_type', 'uid', 'sid'),
|
'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$schema['flag_lists_counts'] = array(
|
$schema['flag_lists_counts'] = array(
|
||||||
@ -122,13 +122,13 @@ function flag_lists_schema() {
|
|||||||
'not null' => TRUE,
|
'not null' => TRUE,
|
||||||
'default' => 0,
|
'default' => 0,
|
||||||
),
|
),
|
||||||
'content_type' => array(
|
'entity_type' => array(
|
||||||
'type' => 'varchar',
|
'type' => 'varchar',
|
||||||
'length' => '32',
|
'length' => '32',
|
||||||
'not null' => TRUE,
|
'not null' => TRUE,
|
||||||
'default' => '',
|
'default' => '',
|
||||||
),
|
),
|
||||||
'content_id' => array(
|
'entity_id' => array(
|
||||||
'type' => 'int',
|
'type' => 'int',
|
||||||
'unsigned' => TRUE,
|
'unsigned' => TRUE,
|
||||||
'not null' => TRUE,
|
'not null' => TRUE,
|
||||||
@ -143,10 +143,10 @@ function flag_lists_schema() {
|
|||||||
'disp-width' => '10',
|
'disp-width' => '10',
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'primary key' => array('fid', 'content_id'),
|
'primary key' => array('fid', 'entity_id'),
|
||||||
'indexes' => array(
|
'indexes' => array(
|
||||||
'fid_content_type' => array('fid', 'content_type'),
|
'fid_entity_type' => array('fid', 'entity_type'),
|
||||||
'content_type_content_id' => array('content_type', 'content_id'),
|
'entity_type_entity_id' => array('entity_type', 'entity_id'),
|
||||||
'count' => array('count'),
|
'count' => array('count'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -190,13 +190,13 @@ function flag_lists_install() {
|
|||||||
function flag_lists_uninstall() {
|
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('flags', 'f', 'fl.name = f.name');
|
$query->leftJoin('flag', 'f', 'fl.name = f.name');
|
||||||
$query->addField('fl', 'fid', 'fid');
|
$query->addField('fl', 'fid', 'fid');
|
||||||
$query->distinct();
|
$query->distinct();
|
||||||
$fids = $query->execute();
|
$fids = $query->execute();
|
||||||
|
|
||||||
foreach ($fids as $fid) {
|
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_content')->condition('fid', $fid->fid);
|
||||||
db_delete('flag_types')->condition('fid', $fid->fid);
|
db_delete('flag_types')->condition('fid', $fid->fid);
|
||||||
db_delete('flag_counts')->condition('fid', $fid->fid);
|
db_delete('flag_counts')->condition('fid', $fid->fid);
|
||||||
|
@ -214,7 +214,7 @@ function theme_flag_lists_user_list($variables) {
|
|||||||
$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->content_type == 'node') {
|
||||||
$node = node_load($item->content_id);
|
$node = node_load($item->entity_id);
|
||||||
$items[] = l($node->title, 'node/' . $node->nid);
|
$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.
|
* 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') {
|
if (!empty($flag->module) && $flag->module == 'flag_lists') {
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'flag':
|
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')
|
$query = db_select('flag_lists_flags', 'fl')
|
||||||
->fields('fl')
|
->fields('fl')
|
||||||
->condition('fl.uid', $account->uid);
|
->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->leftJoin('flag_lists_types', 'ft', 'ft.name = f.name');
|
||||||
$query->addField('ft', 'type');
|
$query->addField('ft', 'type');
|
||||||
if ($content_type) {
|
if ($content_type) {
|
||||||
@ -1011,12 +1011,12 @@ function theme_flag_lists_list($variables) {
|
|||||||
// Make sure we have a node.
|
// Make sure we have a node.
|
||||||
if (is_object($node) && user_access('create flag lists')) {
|
if (is_object($node) && user_access('create flag lists')) {
|
||||||
$content_type = $node->type;
|
$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.
|
// 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')) {
|
elseif (arg(0) == 'node' && is_numeric(arg(1)) && user_access('create flag lists')) {
|
||||||
$content_id = arg(1);
|
$entity_id = arg(1);
|
||||||
$query = db_select('node')->condition('nid', $content_id);
|
$query = db_select('node')->condition('nid', $entity_id);
|
||||||
$query->addField('node', 'type');
|
$query->addField('node', 'type');
|
||||||
$content_type = $query->execute()->fetchField();
|
$content_type = $query->execute()->fetchField();
|
||||||
}
|
}
|
||||||
@ -1034,19 +1034,19 @@ function theme_flag_lists_list($variables) {
|
|||||||
// 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, $content_id, $user->uid, 0) ? 'unflag' : 'flag';
|
$action = _flag_lists_is_flagged($flag, $entity_id, $user->uid, 0) ? 'unflag' : 'flag';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$action = $flag->is_flagged($content_id) ? 'unflag' : 'flag';;
|
$action = $flag->is_flagged($entity_id) ? 'unflag' : 'flag';;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we need the ops?
|
// Do we need the ops?
|
||||||
if ($ops && $flag->module == 'flag_lists') {
|
if ($ops && $flag->module == 'flag_lists') {
|
||||||
$ops_links = theme('flag_lists_ops', array('flag' => $flag));
|
$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 {
|
else {
|
||||||
$link = $flag->theme($action, $content_id);
|
$link = $flag->theme($action, $entity_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a list, fix the link.
|
// 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.
|
* The full flag object of for the flag link being generated.
|
||||||
* @param $action
|
* @param $action
|
||||||
* The action this link will perform. Either 'flag' or 'unflag'.
|
* 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.
|
* The ID of the node, comment, user, or other object being flagged.
|
||||||
* @return
|
* @return
|
||||||
* An array defining properties of the link.
|
* 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();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1224,30 +1224,61 @@ function flag_lists_flag_link_types() {
|
|||||||
|
|
||||||
|
|
||||||
function flag_lists_flag_default_flags($name = 'fl_template') {
|
function flag_lists_flag_default_flags($name = 'fl_template') {
|
||||||
return array(
|
// return array(
|
||||||
array(
|
// array(
|
||||||
'api_version' => 2,
|
// 'api_version' => 2,
|
||||||
'name' => $name,
|
// 'name' => $name,
|
||||||
'module' => 'flag_lists',
|
// 'module' => 'flag_lists',
|
||||||
'content_type' => 'node',
|
// 'content_type' => 'node',
|
||||||
'global' => 0,
|
// 'global' => 0,
|
||||||
'show_on_page' => 0,
|
// 'show_on_page' => 0,
|
||||||
'show_on_teaser' => 0,
|
// 'show_on_teaser' => 0,
|
||||||
'show_on_form' => 0,
|
// 'show_on_form' => 0,
|
||||||
// The following UI labels aren't wrapped in t() because they are written
|
// // 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
|
// // to the DB in English. They are passed to t() later, thus allowing for
|
||||||
// multilingual sites.
|
// // multilingual sites.
|
||||||
'title' => 'Flag lists template',
|
// 'title' => 'Flag lists template',
|
||||||
'flag_short' => 'Add to your [flag_lists:title] [flag_lists:term]',
|
// '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_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]',
|
// '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_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_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_message' => 'This post has been removed from your [flag_lists:title] [flag_lists:term]',
|
||||||
'types' => array(),
|
// 'types' => array(),
|
||||||
'link_type' => 'toggle',
|
// '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(
|
->fields(array(
|
||||||
'pfid' => $flag->pfid,
|
'pfid' => $flag->pfid,
|
||||||
'uid' => $flag->uid,
|
'uid' => $flag->uid,
|
||||||
'content_type' => $flag->content_type,
|
'entity_type' => $flag->entity_type,
|
||||||
'name' => $flag->name,
|
'name' => $flag->name,
|
||||||
'title' => $flag->title,
|
'title' => $flag->title,
|
||||||
'options' => $flag->get_serialized_options($flag),
|
'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
|
* 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.
|
* 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;
|
global $user;
|
||||||
|
|
||||||
// Shorten up the variables that affect the behavior of this page.
|
// 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']);
|
$has_js = isset($_GET['has_js']);
|
||||||
|
|
||||||
// Check the flag token, then perform the flagging.
|
// 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.');
|
$error = t('Bad token. You seem to have followed an invalid link.');
|
||||||
}
|
}
|
||||||
elseif ($user->uid == 0 && !$has_js) {
|
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.
|
// Identify it as ours.
|
||||||
$flag->module = 'flag_lists';
|
$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.
|
// 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 = flag_lists_get_flag($flag_name);
|
||||||
// $flag->link_type = 'toggle';
|
// $flag->link_type = 'toggle';
|
||||||
$sid = flag_get_sid($user->uid);
|
$sid = flag_get_sid($user->uid);
|
||||||
$new_action = _flag_lists_is_flagged($flag, $content_id, $user->uid, $sid) ? 'unflag' : 'flag';
|
$new_action = _flag_lists_is_flagged($flag, $entity_id, $user->uid, $sid) ? 'unflag' : 'flag';
|
||||||
$new_link = $flag->theme($new_action, $content_id, TRUE);
|
$new_link = $flag->theme($new_action, $entity_id, TRUE);
|
||||||
flag_lists_fix_link($new_link, $new_action);
|
flag_lists_fix_link($new_link, $new_action);
|
||||||
drupal_json_output(array(
|
drupal_json_output(array(
|
||||||
'status' => TRUE,
|
'status' => TRUE,
|
||||||
'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' => $content_id,
|
'contentId' => $entity_id,
|
||||||
'contentType' => $flag->content_type,
|
'contentType' => $flag->content_type,
|
||||||
'flagName' => $flag->name,
|
'flagName' => $flag->name,
|
||||||
'flagStatus' => $action,
|
'flagStatus' => $action,
|
||||||
@ -1397,7 +1428,7 @@ function flag_lists_page($action = NULL, $flag_name = NULL, $content_id = NULL)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$flag = flag_lists_get_flag($flag->fid);
|
$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();
|
drupal_goto();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1413,7 +1444,7 @@ function flag_lists_fix_link(&$link, $action) {
|
|||||||
*
|
*
|
||||||
* @param $action
|
* @param $action
|
||||||
* Either 'flag' or 'unflag'.
|
* Either 'flag' or 'unflag'.
|
||||||
* @param $content_id
|
* @param $entity_id
|
||||||
* The ID of the item to flag or unflag.
|
* The ID of the item to flag or unflag.
|
||||||
* @param $account
|
* @param $account
|
||||||
* The user on whose behalf to flag. Leave empty for the current user.
|
* 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
|
* FALSE if some error occured (e.g., user has no permission, flag isn't
|
||||||
* applicable to the item, etc.), TRUE otherwise.
|
* 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)) {
|
if (!isset($account)) {
|
||||||
$account = $GLOBALS['user'];
|
$account = $GLOBALS['user'];
|
||||||
}
|
}
|
||||||
@ -1431,7 +1462,7 @@ function flag_lists_fix_link(&$link, $action) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!$skip_permission_check) {
|
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.
|
// User has no permission to flag/unflag this object.
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -1439,7 +1470,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($content_id)) {
|
if (!$flag->applies_to_content_id($entity_id)) {
|
||||||
return FALSE;
|
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
|
// Perform the flagging or unflagging of this flag. We invoke hook_flag here
|
||||||
// because we do our own flagging.
|
// 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 ($action == 'unflag') {
|
||||||
if ($flagged) {
|
if ($flagged) {
|
||||||
$fcid = _flag_lists_unflag($flag, $content_id, $uid, $sid);
|
$fcid = _flag_lists_unflag($flag, $entity_id, $uid, $sid);
|
||||||
module_invoke_all('flag', 'unflag', $flag, $content_id, $account, $fcid);
|
module_invoke_all('flag', 'unflag', $flag, $entity_id, $account, $fcid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($action == 'flag') {
|
elseif ($action == 'flag') {
|
||||||
if (!$flagged) {
|
if (!$flagged) {
|
||||||
$fcid = _flag_lists_flag($flag, $content_id, $uid, $sid);
|
$fcid = _flag_lists_flag($flag, $entity_id, $uid, $sid);
|
||||||
module_invoke_all('flag', 'flag', $flag, $content_id, $account, $fcid);
|
module_invoke_all('flag', 'flag', $flag, $entity_id, $account, $fcid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1487,12 +1518,12 @@ function flag_lists_fix_link(&$link, $action) {
|
|||||||
* bypass it.
|
* 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')
|
$query = db_select('flag_lists_content')
|
||||||
->condition('fid', $flag->fid)
|
->condition('fid', $flag->fid)
|
||||||
->condition('uid', $uid)
|
->condition('uid', $uid)
|
||||||
->condition('sid', $sid)
|
->condition('sid', $sid)
|
||||||
->condition('content_id', $content_id);
|
->condition('entity_id', $entity_id);
|
||||||
$query->addField('flag_lists_content', 'fid');
|
$query->addField('flag_lists_content', 'fid');
|
||||||
return $query->execute()->fetchField();
|
return $query->execute()->fetchField();
|
||||||
}
|
}
|
||||||
@ -1504,19 +1535,19 @@ function flag_lists_fix_link(&$link, $action) {
|
|||||||
* flag_lists_do_flag() function instead.
|
* 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')
|
$fcid = db_insert('flag_lists_content')
|
||||||
->fields(array(
|
->fields(array(
|
||||||
'fid' => $flag->fid,
|
'fid' => $flag->fid,
|
||||||
'content_type' => $flag->content_type,
|
'entity_type' => $flag->entity_type,
|
||||||
'content_id' => $content_id,
|
'entity_id' => $entity_id,
|
||||||
'uid' => $uid,
|
'uid' => $uid,
|
||||||
'sid' => $sid,
|
'sid' => $sid,
|
||||||
'timestamp' => REQUEST_TIME,
|
'timestamp' => REQUEST_TIME,
|
||||||
))
|
))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
_flag_lists_update_count($flag, $content_id);
|
_flag_lists_update_count($flag, $entity_id);
|
||||||
return $fcid;
|
return $fcid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1527,10 +1558,10 @@ function flag_lists_fix_link(&$link, $action) {
|
|||||||
* flag_lists_do_flag() function instead.
|
* 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')
|
$query = db_select('flag_lists_content')
|
||||||
->condition('fid', $flag->fid)
|
->condition('fid', $flag->fid)
|
||||||
->condition('content_id', $content_id)
|
->condition('entity_id', $entity_id)
|
||||||
->condition('uid', $uid)
|
->condition('uid', $uid)
|
||||||
->condition('sid', $sid);
|
->condition('sid', $sid);
|
||||||
$query->addField('flag_lists_content', 'fcid');
|
$query->addField('flag_lists_content', 'fcid');
|
||||||
@ -1539,7 +1570,7 @@ function flag_lists_fix_link(&$link, $action) {
|
|||||||
db_delete('flag_lists_content')
|
db_delete('flag_lists_content')
|
||||||
->condition('fcid', $fcid)
|
->condition('fcid', $fcid)
|
||||||
->execute();
|
->execute();
|
||||||
_flag_lists_update_count($flag, $content_id);
|
_flag_lists_update_count($flag, $entity_id);
|
||||||
}
|
}
|
||||||
return $fcid;
|
return $fcid;
|
||||||
}
|
}
|
||||||
@ -1547,11 +1578,11 @@ function flag_lists_fix_link(&$link, $action) {
|
|||||||
/**
|
/**
|
||||||
* Updates the flag count for this content
|
* 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')
|
$count = db_select('flag_lists_content', 'f')
|
||||||
->fields('f')
|
->fields('f')
|
||||||
->condition('fid', $flag->fid)
|
->condition('fid', $flag->fid)
|
||||||
->condition('content_id', $content_id)
|
->condition('entity_id', $entity_id)
|
||||||
->countQuery()
|
->countQuery()
|
||||||
->execute()
|
->execute()
|
||||||
->fetchField();
|
->fetchField();
|
||||||
@ -1559,7 +1590,7 @@ function flag_lists_fix_link(&$link, $action) {
|
|||||||
if (empty($count)) {
|
if (empty($count)) {
|
||||||
$num_deleted = db_delete('flag_lists_counts')
|
$num_deleted = db_delete('flag_lists_counts')
|
||||||
->condition('fid', $flag->fid)
|
->condition('fid', $flag->fid)
|
||||||
->condition('content_id', $content_id)
|
->condition('entity_id', $entity_id)
|
||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1568,14 +1599,14 @@ function flag_lists_fix_link(&$link, $action) {
|
|||||||
'count' => $count,
|
'count' => $count,
|
||||||
))
|
))
|
||||||
->condition('fid', $flag->fid)
|
->condition('fid', $flag->fid)
|
||||||
->condition('content_id', $content_id)
|
->condition('entity_id', $entity_id)
|
||||||
->execute();
|
->execute();
|
||||||
if (empty($num_updated)) {
|
if (empty($num_updated)) {
|
||||||
db_insert('flag_lists_counts')
|
db_insert('flag_lists_counts')
|
||||||
->fields(array(
|
->fields(array(
|
||||||
'fid' => $flag->fid,
|
'fid' => $flag->fid,
|
||||||
'content_type' => $flag->content_type,
|
'entity_type' => $flag->entity_type,
|
||||||
'content_id' => $content_id,
|
'entity_id' => $entity_id,
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
))
|
))
|
||||||
->execute();
|
->execute();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user