Projet

Général

Profil

Révision 76e2e7c3

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/flag/flag.api.php
58 58
 */
59 59
function hook_flag_default_flags() {
60 60
  $flags = array();
61
  $flags['bookmarks'] = array (
61
  $flags['bookmarks'] = array(
62 62
    'entity_type' => 'node',
63 63
    'title' => 'Bookmarks',
64 64
    'global' => FALSE,
65
    'types' => array (
65
    'types' => array(
66 66
      0 => 'article',
67 67
      1 => 'blog',
68 68
    ),
......
75 75
    'unflag_denied_text' => '',
76 76
    'link_type' => 'toggle',
77 77
    'weight' => 0,
78
    'show_in_links' => array (
78
    'show_in_links' => array(
79 79
      'full' => TRUE,
80 80
      'token' => FALSE,
81 81
    ),
......
90 90
  return $flags;
91 91
}
92 92

  
93
/**
94
 * Alter the definition of default flags.
95
 *
96
 * @param array &$flags
97
 *   An array keyed by flag machine name containing flag definitions.
98
 */
99
function hook_flag_default_flags_alter(&$flags) {
100
  if (!empty($flags['bookmark'])) {
101
    $flags['bookmark']['title'] = 'Bananana Bookmark';
102
  }
103
}
104

  
93 105
/**
94 106
 * Allow modules to alter a flag when it is initially loaded.
95 107
 *
96
 * @see flag_get_flags().
108
 * @see flag_get_flags()
97 109
 */
98 110
function hook_flag_alter(&$flag) {
99 111

  
......
183 195
      $count = count($flags[$flag->name]);
184 196
      if ($count >= 2) {
185 197
        // Users may flag only 2 nodes with this flag.
186
        return(array('access-denied' => t('You may only flag 2 nodes with the test flag.')));
198
        return (array('access-denied' => t('You may only flag 2 nodes with the test flag.')));
187 199
      }
188 200
    }
189 201
  }
drupal7/sites/all/modules/flag/flag.info
29 29
files[] = includes/views/flag_plugin_argument_validate_flaggability.inc
30 30
files[] = tests/flag.test
31 31

  
32
; Information added by Drupal.org packaging script on 2014-03-18
33
version = "7.x-3.4"
32
; Information added by Drupal.org packaging script on 2014-05-03
33
version = "7.x-3.5"
34 34
core = "7.x"
35 35
project = "flag"
36
datestamp = "1395128956"
36
datestamp = "1399113834"
37 37

  
drupal7/sites/all/modules/flag/flag.info.inc
1 1
<?php
2 2

  
3 3
/**
4
 * @file Contains Entity API property information.
4
 * @file
5
 * Contains Entity API property information.
5 6
 */
6 7

  
7 8
/**
drupal7/sites/all/modules/flag/flag.install
113 113
        'not null' => TRUE,
114 114
        'default' => 0,
115 115
        'disp-size' => 11,
116
      )
116
      ),
117 117
    ),
118 118
    'primary key' => array('flagging_id'),
119 119
    'unique keys' => array(
......
121 121
    ),
122 122
    'indexes' => array(
123 123
      'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
124
      'entity_type_entity_id_uid_sid' => array('entity_type', 'entity_id', 'uid', 'sid'),
124
      'entity_type_entity_id_uid_sid' => array(
125
        'entity_type',
126
        'entity_id',
127
        'uid',
128
        'sid',
129
      ),
125 130
      'entity_id_fid' => array('entity_id', 'fid'),
126 131
    ),
127 132
  );
......
190 195
        'not null' => TRUE,
191 196
        'default' => 0,
192 197
        'disp-size' => 11,
193
      )
198
      ),
194 199
    ),
195 200
    'primary key' => array('fid', 'entity_id'),
196 201
    'indexes' => array(
......
296 301
function flag_update_6201() {
297 302
  // Remove "content type" from one key, see http://drupal.org/node/612602.
298 303
  db_drop_unique_key('flag_content', 'fid_content_type_content_id_uid');
299
  db_add_unique_key('flag_content', 'fid_content_id_uid', array('fid', 'content_id', 'uid'));
304
  db_add_unique_key('flag_content', 'fid_content_id_uid', array(
305
    'fid',
306
    'content_id',
307
    'uid',
308
  ));
300 309

  
301 310
  // Add a count index, see http://drupal.org/node/489610.
302 311
  db_add_index('flag_counts', 'count', array('count'));
......
311 320
  db_drop_index('flag_content', 'content_type_uid');
312 321

  
313 322
  // Add the column.
314
  db_add_field('flag_content', 'sid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
323
  db_add_field('flag_content', 'sid', array(
324
    'type' => 'int',
325
    'unsigned' => TRUE,
326
    'not null' => TRUE,
327
    'default' => 0,
328
  ));
315 329

  
316 330
  // Re-add the removed keys.
317
  db_add_unique_key('flag_content', 'fid_content_id_uid_sid', array('fid', 'content_id', 'uid', 'sid'));
318
  db_add_index('flag_content', 'content_type_uid_sid', array('content_type', 'uid', 'sid'));
331
  db_add_unique_key('flag_content', 'fid_content_id_uid_sid', array(
332
    'fid',
333
    'content_id',
334
    'uid',
335
    'sid',
336
  ));
337
  db_add_index('flag_content', 'content_type_uid_sid', array(
338
    'content_type',
339
    'uid',
340
    'sid',
341
  ));
319 342
}
320 343

  
321 344
/**
......
357 380
    db_drop_unique_key('flag_content', 'content_type_content_id_uid_sid');
358 381
  }
359 382

  
360
  db_add_index('flag_content', 'content_type_content_id_uid_sid', array('content_type', 'content_id', 'uid', 'sid'));
383
  db_add_index('flag_content', 'content_type_content_id_uid_sid', array(
384
    'content_type',
385
    'content_id',
386
    'uid',
387
    'sid',
388
  ));
361 389
}
362 390

  
363 391
/**
364 392
 * Adds column last_updated to flag_counts table.
365 393
 */
366 394
function flag_update_6207() {
367
  db_add_field('flag_counts', 'last_updated', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-size' => 11), array('indexes' => array('last_updated' => array('last_updated'))));
395
  db_add_field('flag_counts', 'last_updated', array(
396
    'type' => 'int',
397
    'unsigned' => TRUE,
398
    'not null' => TRUE,
399
    'default' => 0,
400
    'disp-size' => 11),
401
    array('indexes' => array('last_updated' => array('last_updated'))));
368 402
}
369 403

  
370 404
/**
......
482 516
      ),
483 517
      'indexes' => array(
484 518
        'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
485
        'entity_type_content_id_uid_sid' => array('entity_type', 'content_id', 'uid', 'sid'),
519
        'entity_type_content_id_uid_sid' => array(
520
          'entity_type',
521
          'content_id',
522
          'uid',
523
          'sid',
524
        ),
486 525
        'content_id_fid' => array('content_id', 'fid'),
487 526
      ),
488 527
    )
......
510 549
        'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
511 550
      ),
512 551
      'indexes' => array(
513
        'entity_type_entity_id_uid_sid' => array('entity_type', 'entity_id', 'uid', 'sid'),
552
        'entity_type_entity_id_uid_sid' => array(
553
          'entity_type',
554
          'entity_id',
555
          'uid',
556
          'sid',
557
        ),
514 558
        'entity_id_fid' => array('entity_id', 'fid'),
515 559
      ),
516 560
    )
......
569 613
      'indexes' => array(
570 614
        'fid_entity_type' => array('fid', 'entity_type'),
571 615
        'entity_type_content_id' => array('entity_type', 'content_id'),
572
      )
616
      ),
573 617
    )
574 618
  );
575 619

  
......
671 715
    }
672 716

  
673 717
    // Update show_on_comment and show_on_entity properties to use new view
674
    // mode settings. Since the old logic was to show on all view modes, do that.
718
    // mode settings. Since the old logic was to show on all view modes, do
719
    // that.
675 720
    if (!empty($flag->show_on_entity) || !empty($flag->show_on_comment)) {
676 721
      if ($entity_info = entity_get_info($flag->entity_type)) {
677 722
        foreach ($entity_info['view modes'] as $view_mode => $value) {
drupal7/sites/all/modules/flag/flag.module
160 160
// @todo: flag_reset_flag():
161 161
// - it should delete the flaggings.
162 162
// - (it has other issues; see http://drupal.org/node/894992.)
163
// - (is problematic: it might not be possible to delete all data in a single page request.)
163
// - (is problematic: it might not be possible to delete all data in a single
164
//   page request.)
164 165

  
165 166
// @todo: Discuss: Note that almost all functions/identifiers dealing with
166 167
// flaggings *aren't* prefixed by "flag_". For example:
167
//  - The menu argument is %flagging, not %flag_flagging.
168
//  - The entity type is "flagging", not "flag_flagging".
169
// On the one hand this succinct version is readable and nice. On the other hand, it isn't
170
// very "correct".
168
// - The menu argument is %flagging, not %flag_flagging.
169
// - The entity type is "flagging", not "flag_flagging".
170
// On the one hand this succinct version is readable and nice. On the other
171
// hand, it isn't very "correct".
171 172

  
172 173
/**
173 174
 * Implements hook_entity_query_alter().
......
182 183

  
183 184
  // Alter only flagging queries with bundle conditions.
184 185
  if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'flagging' && isset($conditions['bundle'])) {
185
    $query->addTag('flagging_flag_names'); // Add tag to alter query.
186
    // Add tag to alter query.
187
    $query->addTag('flagging_flag_names');
186 188
    // Make value and operator of the bundle condition accessible
187 189
    // in hook_query_TAG_alter.
188 190
    $query->addMetaData('flag_name_value', $conditions['bundle']['value']);
......
253 255
  );
254 256

  
255 257
  $items[FLAG_ADMIN_PATH . '/manage/%flag'] = array(
256
    'load arguments' => array(TRUE), // Allow for disabled flags.
258
    // Allow for disabled flags.
259
    'load arguments' => array(TRUE),
257 260
    'page callback' => 'drupal_get_form',
258 261
    'page arguments' => array('flag_form', FLAG_ADMIN_PATH_START + 1),
259 262
    'access callback' => 'user_access',
......
265 268
    'title arguments' => array(FLAG_ADMIN_PATH_START + 1),
266 269
  );
267 270
  $items[FLAG_ADMIN_PATH . '/manage/%flag/edit'] = array(
268
    'load arguments' => array(TRUE), // Allow for disabled flags.
271
    // Allow for disabled flags.
272
    'load arguments' => array(TRUE),
269 273
    'title' => 'Edit flag',
270 274
    'type' => MENU_DEFAULT_LOCAL_TASK,
271 275
    'weight' => -10,
......
289 293
    'type' => MENU_CALLBACK,
290 294
  );
291 295
  $items[FLAG_ADMIN_PATH . '/manage/%flag/update'] = array(
292
    'load arguments' => array(TRUE), // Allow for disabled flags.
296
    // Allow for disabled flags.
297
    'load arguments' => array(TRUE),
293 298
    'title' => 'Update',
294 299
    'page callback' => 'flag_update_page',
295 300
    'page arguments' => array(FLAG_ADMIN_PATH_START + 1),
......
416 421
    case FLAG_ADMIN_PATH:
417 422
      $output = '<p>' . t('This page lists all the <em>flags</em> that are currently defined on this system.') . '</p>';
418 423
      return $output;
424

  
419 425
    case FLAG_ADMIN_PATH . '/add':
420 426
      $output = '<p>' . t('Select the type of flag to create. An individual flag can only affect one type of object. This cannot be changed once the flag is created.') . '</p>';
421 427
      return $output;
428

  
422 429
    case FLAG_ADMIN_PATH . '/manage/%/fields':
423 430
      // Get the existing link types that provide a flagging form.
424 431
      $link_types = flag_get_link_types();
......
572 579
function flag_create_handler($entity_type) {
573 580
  $definition = flag_fetch_definition($entity_type);
574 581
  if (isset($definition) && class_exists($definition['handler'])) {
575
    $handler = new $definition['handler'];
582
    $handler = new $definition['handler']();
576 583
  }
577 584
  else {
578
    $handler = new flag_broken;
585
    $handler = new flag_broken();
579 586
  }
580 587
  $handler->entity_type = $entity_type;
581 588
  $handler->construct();
......
662 669
        $extra[$flag->entity_type][$bundle_name]['form']['flag'] = array(
663 670
          'label' => t('Flags'),
664 671
          'description' => t('Checkboxes for toggling flags'),
665
          'weight' => 10
672
          'weight' => 10,
666 673
        );
667 674
      }
668 675

  
......
730 737
 * Warning: will not work on entity types that are not fieldable, as this relies
731 738
 * on a field module hook.
732 739
 *
733
 * @see flag_field_attach_submit().
740
 * @see flag_field_attach_submit()
734 741
 */
735 742
function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
736 743
  list($id) = entity_extract_ids($entity_type, $entity);
......
839 846
/**
840 847
 * Implements hook_field_attach_submit().
841 848
 *
842
 * @see flag_field_attach_form().
849
 * @see flag_field_attach_form()
843 850
 */
844 851
function flag_field_attach_submit($entity_type, $entity, $form, &$form_state) {
845 852
  // This is invoked for each flag_field_attach_form(), but possibly more than
......
877 884
/**
878 885
 * Shared saving routine between flag_field_attach_insert/update().
879 886
 *
880
 * @see flag_field_attach_form().
887
 * @see flag_field_attach_form()
881 888
 */
882 889
function flag_field_attach_save($entity_type, $entity) {
883 890
  list($id) = entity_extract_ids($entity_type, $entity);
......
918 925

  
919 926
      list($entity_id) = entity_extract_ids($entity_type, $entity);
920 927
      if (!$flag->access($entity_id) && (!$flag->is_flagged($entity_id) || !$flag->access($entity_id, 'flag'))) {
921
        // User has no permission to use this flag or flag does not apply to this
922
        // object. The link is not skipped if the user has "flag" access but
923
        // not "unflag" access (this way the unflag denied message is shown).
928
        // User has no permission to use this flag or flag does not apply to
929
        // this object. The link is not skipped if the user has "flag" access
930
        // but not "unflag" access (this way the unflag denied message is
931
        // shown).
924 932
        continue;
925 933
      }
926 934

  
927
      $element['#links']['flag-'. $name] = array(
935
      $element['#links']['flag-' . $name] = array(
928 936
        'title' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id),
929 937
        'html' => TRUE,
930 938
      );
......
981 989
    // The pseudofield output.
982 990
    if ($flag->show_as_field) {
983 991
      $entity->content['flag_' . $flag->name] = array(
984
       '#markup' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array('needs_wrapping_element' => TRUE)),
992
        '#markup' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array('needs_wrapping_element' => TRUE)),
985 993
      );
986 994
    }
987 995
  }
......
1359 1367
  $object = $flag->fetch_entity($entity_id);
1360 1368

  
1361 1369
  // Generic "all flags" actions.
1362
  foreach (trigger_get_assigned_actions('flag_' . $action)  as $aid => $action_info) {
1363
    // The 'if ($aid)' is a safeguard against http://drupal.org/node/271460#comment-886564
1370
  foreach (trigger_get_assigned_actions('flag_' . $action) as $aid => $action_info) {
1371
    // The 'if ($aid)' is a safeguard against
1372
    // http://drupal.org/node/271460#comment-886564
1364 1373
    if ($aid) {
1365 1374
      actions_do($aid, $object, $context);
1366 1375
    }
......
1559 1568
  $flag =& $variables['flag'];
1560 1569
  $action = $variables['action'];
1561 1570
  $entity_id = $variables['entity_id'];
1562
  $errors = join('<br />', $variables['errors']);
1571
  $errors = implode('<br />', $variables['errors']);
1563 1572
  $flag_css_name = str_replace('_', '-', $flag->name);
1564 1573

  
1565 1574
  // Generate the link URL.
......
1629 1638
      $variables['message_classes_array'][] = 'flag-' . $variables['status'] . '-message';
1630 1639
      $variables['message_text'] = $flag->get_label($inverse_action . '_message', $entity_id);
1631 1640
      $variables['flag_classes_array'][] = $variables['status'];
1632
      // By default we make our JS code remove, after a few seconds, only success messages.
1641
      // By default we make our JS code remove, after a few seconds, only
1642
      // success messages.
1633 1643
      $variables['message_classes_array'][] = 'flag-auto-remove';
1634 1644
    }
1635 1645
  }
......
1725 1735
      ->countQuery()
1726 1736
      ->execute()
1727 1737
      ->fetchField();
1728
    $counts[$flag->name][$entity_type] =  $result;
1738
    $counts[$flag->name][$entity_type] = $result;
1729 1739
  }
1730 1740

  
1731 1741
  return $counts[$flag->name][$entity_type];
......
1894 1904
    $query = db_select('flag', 'f');
1895 1905
    $query->leftJoin('flag_types', 'fn', 'fn.fid = f.fid');
1896 1906
    $result = $query
1897
      ->fields('f', array('fid', 'entity_type', 'name', 'title', 'global', 'options'))
1907
      ->fields('f', array(
1908
        'fid',
1909
        'entity_type',
1910
        'name',
1911
        'title',
1912
        'global',
1913
        'options',
1914
      ))
1898 1915
      ->fields('fn', array('type'))
1899 1916
      ->execute();
1900 1917
    foreach ($result as $row) {
......
1919 1936
        // Ensure overridden flags are associated with their parent module.
1920 1937
        $flags[$name]->module = $default_flag->module;
1921 1938

  
1922
        // Update the flag with any properties that are "locked" by the code version.
1939
        // Update the flag with any properties that are "locked" by the code
1940
        // version.
1923 1941
        if (isset($default_flag->locked)) {
1924 1942
          $flags[$name]->locked = $default_flag->locked;
1925 1943
          foreach ($default_flag->locked as $property) {
......
1988 2006
  $default_flags = array();
1989 2007
  $flag_status = variable_get('flag_default_flag_status', array());
1990 2008

  
2009
  $default_flags_info = array();
1991 2010
  foreach (module_implements('flag_default_flags') as $module) {
1992 2011
    $function = $module . '_flag_default_flags';
1993 2012
    foreach ($function() as $flag_name => $flag_info) {
1994 2013
      // Backward compatibility: old exported default flags have their names
1995
      // in $flag_info instead, so we use the += operator to not overwrite it.
1996
      $flag_info += array(
2014
      // in $flag_info instead, so we use the + operator to not overwrite it.
2015
      $default_flags_info[$flag_name] = $flag_info + array(
1997 2016
        'name' => $flag_name,
1998 2017
        'module' => $module,
1999 2018
      );
2000
      $flag = flag_flag::factory_by_array($flag_info);
2019
    }
2020
  }
2001 2021

  
2002
      // Disable flags that are not at the current API version.
2003
      if (!$flag->is_compatible()) {
2004
        $flag->status = FALSE;
2005
      }
2022
  // Allow modules to alter definitions using hook_flag_default_flags_alter().
2023
  drupal_alter('flag_default_flags', $default_flags_info);
2006 2024

  
2007
      // Add flags that have been enabled.
2008
      if ((!isset($flag_status[$flag->name]) && (!isset($flag->status) || $flag->status)) || !empty($flag_status[$flag->name])) {
2009
        $flag->status = TRUE;
2010
        $default_flags[$flag->name] = $flag;
2011
      }
2012
      // Add flags that have been disabled.
2013
      elseif ($include_disabled) {
2014
        $flag->status = FALSE;
2015
        $default_flags[$flag->name] = $flag;
2016
      }
2025
  foreach ($default_flags_info as $flag_info) {
2026
    $flag = flag_flag::factory_by_array($flag_info);
2027

  
2028
    // Disable flags that are not at the current API version.
2029
    if (!$flag->is_compatible()) {
2030
      $flag->status = FALSE;
2031
    }
2032

  
2033
    // Add flags that have been enabled.
2034
    if ((!isset($flag_status[$flag->name]) && (!isset($flag->status) || $flag->status)) || !empty($flag_status[$flag->name])) {
2035
      $flag->status = TRUE;
2036
      $default_flags[$flag->name] = $flag;
2037
    }
2038
    // Add flags that have been disabled.
2039
    elseif ($include_disabled) {
2040
      $flag->status = FALSE;
2041
      $default_flags[$flag->name] = $flag;
2017 2042
    }
2018 2043
  }
2019 2044

  
......
2067 2092
 * @return
2068 2093
 *   If returning a single item's flags (that is, when $entity_id isn't NULL),
2069 2094
 *   an array of the structure
2070
 *   [flag_name] => (flagging_id => [flagging_id], uid => [uid], entity_id => [entity_id], timestamp => [timestamp], ...)
2095
 *   [flag_name] => (
2096
 *     flagging_id => [flagging_id],
2097
 *     uid => [uid],
2098
 *     entity_id => [entity_id],
2099
 *     timestamp => [timestamp],
2100
 *     ...)
2071 2101
 *
2072 2102
 *   If returning all items' flags, an array of arrays for each flag:
2073 2103
 *   [flag_name] => [entity_id] => Object from above.
2074
 *
2075 2104
 */
2076 2105
function flag_get_user_flags($entity_type, $entity_id = NULL, $uid = NULL, $sid = NULL) {
2077 2106
  $flagged_content = &drupal_static(__FUNCTION__);
......
2250 2279
    $query->orderBy('timestamp', 'ASC');
2251 2280
  }
2252 2281
  else {
2253
    $query->orderBy('timestamp', 'DESC') ;
2282
    $query->orderBy('timestamp', 'DESC');
2254 2283
  }
2255 2284

  
2256
  // Execute the query
2285
  // Execute the query.
2257 2286
  $result = $query->execute();
2258 2287

  
2259 2288
  $i = 1;
......
2289 2318
  }
2290 2319
  module_invoke_all('flag_reset', $flag, $entity_id, $rows);
2291 2320

  
2292
  $query = db_delete('flagging')->condition('fid' , $flag->fid);
2321
  $query = db_delete('flagging')->condition('fid', $flag->fid);
2293 2322
  // Update the flag_counts table.
2294 2323
  $count_query = db_delete('flag_counts')->condition('fid', $flag->fid);
2295 2324
  if ($entity_id) {
......
2608 2637
 * @ingroup callbacks
2609 2638
 */
2610 2639
function flag_properties_get_user_sid($entity, array $options, $name, $entity_type, $property_info) {
2611
  $sid =  flag_get_sid($entity->uid, FALSE);
2640
  $sid = flag_get_sid($entity->uid, FALSE);
2612 2641
  return $sid;
2613 2642
}
drupal7/sites/all/modules/flag/flag.rules.inc
81 81
      '#required' => empty($info['optional']),
82 82
      '#multiple' => FALSE,
83 83
      '#default_value' => $settings[$name],
84
      '#empty' => t('There is no suiting flag available.')
84
      '#empty' => t('There is no suiting flag available.'),
85 85
    );
86 86
    return $form;
87 87
  }
......
375 375
      'access callback' => 'flag_rules_integration_access',
376 376
    );
377 377
  }
378
  // For backward compatibility sake. This was the original name of the 'fetch node by user'.
378
  // For backward compatibility sake. This was the original name of the
379
  // 'fetch node by user'.
379 380
  $items['flag_fetch_entity_by_user'] = $items['flag_fetch_node_by_user'];
380
  $items['flag_fetch_entity_by_user']['label'] .= ' '. t('(Legacy)');
381
  $items['flag_fetch_entity_by_user']['label'] .= ' ' . t('(Legacy)');
381 382
  return $items;
382 383
}
383 384

  
......
424 425
}
425 426

  
426 427
/**
427
 * Base action implementation: Fetch entities who were flagged a user.
428
 * Base action implementation: Fetch entities flagged by a user.
428 429
 */
429 430
function flag_rules_action_fetch_entity_by_user($flag, $entity) {
430
  $user = entity_metadata_wrapper('user', $entity);
431
  $sid = $user->flag_sid->value();
432 431
  $query = db_select('flagging', 'fc')
433 432
    ->fields('fc', array('entity_id'))
434 433
    ->condition('entity_type', $flag->entity_type)
435
    ->condition('uid', $user->uid->value())
436 434
    ->condition('fid', $flag->fid);
437
  // Filter out any bad session ids and any users that aren't anonymous.
438
  if (!empty($sid) && $sid != -1) {
439
    $query->condition('sid', $sid);
435
  // For global flags the user parameter is ignored, so we add the
436
  // extra 'uid' condition when the flag is NOT global.
437
  if (!$flag->global) {
438
    $user = entity_metadata_wrapper('user', $entity);
439
    $sid = $user->flag_sid->value();
440
    $query = $query->condition('uid', $user->uid->value());
441
    // Filter out any bad session ids and any users that aren't anonymous.
442
    if (!empty($sid) && $sid != -1) {
443
      $query->condition('sid', $sid);
444
    }
440 445
  }
441 446
  $result = $query->execute();
442 447
  $flagged = $result->fetchCol();
......
469 474
}
470 475

  
471 476
/**
472
 * Base action implementation: Fetch count of flags for a particular entity type.
477
 * Base action implementation: Fetch count of flags for a particular entity
478
 * type.
473 479
 *
474 480
 * During a flagging, the current flagging will be included in the count.
475 481
 * During an unflagging, the current flagging being removed will not yet have
......
509 515
            'type' => 'flag',
510 516
            'label' => t('Flag'),
511 517
            'flag_type' => $type,
512
            'description' => t('The flag to check for.')
518
            'description' => t('The flag to check for.'),
513 519
          ),
514 520
          $type => array(
515 521
            'type' => $type,
......
545 551
            'type' => 'flag',
546 552
            'label' => t('Flag'),
547 553
            'flag_type' => $type,
548
            'description' => t('The flag to check for.')
554
            'description' => t('The flag to check for.'),
549 555
          ),
550 556
          $type => array(
551 557
            'type' => $type,
......
566 572
}
567 573

  
568 574
/**
569
 * Options list callback for the operator parameter of the flagging threshold condition.
575
 * Options list callback for the operator parameter of the flagging threshold
576
 * condition.
570 577
 */
571 578
function flag_rules_condition_threshold_operator_options() {
572 579
  return array(
......
588 595
  $count = $flag->get_count($flag->get_entity_id($entity));
589 596

  
590 597
  switch ($operator) {
591
    case '>' : return $count >  $number;
598
    case '>': return $count > $number;
592 599
    case '>=': return $count >= $number;
593
    case '=' : return $count == $number;
594
    case '<' : return $count <  $number;
600
    case '=': return $count == $number;
601
    case '<': return $count < $number;
595 602
    case '<=': return $count <= $number;
596 603
  }
597 604
}
drupal7/sites/all/modules/flag/flag.tokens.inc
123 123
        case 'name':
124 124
          $replacements[$original] = $sanitize ? check_plain($flag->name) : $flag->name;
125 125
          break;
126

  
126 127
        case 'title':
127 128
          $replacements[$original] = $sanitize ? check_plain($flag->get_title()) : $flag->get_title();
128 129
          break;
......
149 150
        case 'action':
150 151
          $replacements[$original] = $action->action;
151 152
          break;
153

  
152 154
        case 'entity-url':
153 155
          $replacements[$original] = $sanitize ? check_url($action->entity_url) : $action->entity_url;
154 156
          break;
157

  
155 158
        case 'entity-title':
156 159
          $replacements[$original] = $sanitize ? check_plain($action->entity_title) : $action->entity_title;
157 160
          break;
161

  
158 162
        case 'entity-type':
159 163
          $replacements[$original] = $action->entity_type;
160 164
          break;
165

  
161 166
        case 'entity-id':
162 167
          $replacements[$original] = $action->entity_id;
163 168
          break;
169

  
164 170
        case 'count':
165 171
          $replacements[$original] = $action->count;
166 172
          break;
drupal7/sites/all/modules/flag/flag_actions.info
7 7

  
8 8
files[] = flag.install
9 9
files[] = flag_actions.module
10
; Information added by Drupal.org packaging script on 2014-03-18
11
version = "7.x-3.4"
10
; Information added by Drupal.org packaging script on 2014-05-03
11
version = "7.x-3.5"
12 12
core = "7.x"
13 13
project = "flag"
14
datestamp = "1395128956"
14
datestamp = "1399113834"
15 15

  
drupal7/sites/all/modules/flag/flag_actions.module
379 379
  $fieldset = array(
380 380
    '#type' => 'fieldset',
381 381
    '#title' => t('Add a new flag action'),
382
    '#children' => '<div class="container-inline">'. drupal_render($form['flag']) . drupal_render($form['submit']) .'</div>',
382
    '#children' => '<div class="container-inline">' . drupal_render($form['flag']) . drupal_render($form['submit']) . '</div>',
383 383
    '#parents' => array('add_action'),
384 384
    '#attributes' => array(),
385 385
    '#groups' => array('add_action' => array()),
......
397 397
 *   If editing an action, an action ID must be passed in.
398 398
 * @param $flag_name
399 399
 *   If adding a new action to a flag, a flag name must be specified.
400
 *
401 400
 */
402 401
function flag_actions_form($form, &$form_state, $aid = NULL, $flag_name = NULL) {
403 402
  // This is a multistep form. Get the callback value if set and continue.
......
422 421

  
423 422
  $form['new'] = array(
424 423
    '#type' => 'value',
425
    '#value' => isset($callback) ? FALSE: TRUE,
424
    '#value' => isset($callback) ? FALSE : TRUE,
426 425
  );
427 426

  
428 427
  if (!isset($callback)) {
......
430 429

  
431 430
    $actions = $flag->get_valid_actions();
432 431
    $options = array();
433
    foreach($actions as $key => $action) {
432
    foreach ($actions as $key => $action) {
434 433
      $options[$key] = $action['label'];
435 434
    }
436 435

  
......
449 448
  }
450 449
  elseif (!isset($action)) {
451 450
    $actions = $flag->get_valid_actions();
452
    $action = (object)$actions[$callback];
451
    $action = (object) $actions[$callback];
453 452
    $action->parameters = array();
454 453
    $action->event = 'flag';
455 454
    $action->threshold = 10;
......
512 511
  }
513 512

  
514 513
  // Merge in the standard flag action form.
515
  $action_form = $callback .'_form';
514
  $action_form = $callback . '_form';
516 515
  $edit = array();
517 516
  if (function_exists($action_form)) {
518 517
    $edit += $action->parameters;
......
524 523
  }
525 524

  
526 525
  // Add a few customizations to existing flag actions.
527
  $flag_actions_form = 'flag_actions_'. $callback .'_form';
526
  $flag_actions_form = 'flag_actions_' . $callback . '_form';
528 527
  if (function_exists($flag_actions_form)) {
529 528
    $flag_actions_form($form, $flag, $edit);
530 529
  }
drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.info
4 4
dependencies[] = flag
5 5
package = Flags
6 6

  
7
; Information added by Drupal.org packaging script on 2014-03-18
8
version = "7.x-3.4"
7
; Information added by Drupal.org packaging script on 2014-05-03
8
version = "7.x-3.5"
9 9
core = "7.x"
10 10
project = "flag"
11
datestamp = "1395128956"
11
datestamp = "1399113834"
12 12

  
drupal7/sites/all/modules/flag/flag_bookmark/flag_bookmark.install
13 13
 */
14 14
function flag_bookmark_enable() {
15 15
  // Load the flag API in case we want to use it when enabling.
16
  include_once(drupal_get_path('module', 'flag') . '/flag.module');
16
  include_once drupal_get_path('module', 'flag') . '/flag.module';
17 17

  
18 18
  if (!flag_get_flags()) {
19 19
    // Install a demonstration flag only if no flag exists. This is to prevent
......
21 21
    // flag is overwritten or re-created.
22 22
    $flag = flag_flag::factory_by_entity_type('node');
23 23
    $configuration = array(
24
        'name' => 'bookmarks',
25
        'global' => 0,
26
        'show_in_links' => array(
27
          'full' => 1,
28
          'teaser' => 1,
29
        ),
30
        'show_on_form' => 1,
31
        // The following UI labels aren't wrapped in t() because they are written
32
        // to the DB in English. They are passed to t() later, thus allowing for
33
        // multilingual sites.
34
        'title' => 'Bookmarks',
35
        'flag_short' => 'Bookmark this',
36
        'flag_long' => 'Add this post to your bookmarks',
37
        'flag_message' => 'This post has been added to your bookmarks',
38
        'unflag_short' => 'Unbookmark this',
39
        'unflag_long' => 'Remove this post from your bookmarks',
40
        'unflag_message' => 'This post has been removed from your bookmarks',
41
        'types' => _flag_bookmark_install_get_suggested_node_types(),
24
      'name' => 'bookmarks',
25
      'global' => 0,
26
      'show_in_links' => array(
27
        'full' => 1,
28
        'teaser' => 1,
29
      ),
30
      'show_on_form' => 1,
31
      // The following UI labels aren't wrapped in t() because they are written
32
      // to the DB in English. They are passed to t() later, thus allowing for
33
      // multilingual sites.
34
      'title' => 'Bookmarks',
35
      'flag_short' => 'Bookmark this',
36
      'flag_long' => 'Add this post to your bookmarks',
37
      'flag_message' => 'This post has been added to your bookmarks',
38
      'unflag_short' => 'Unbookmark this',
39
      'unflag_long' => 'Remove this post from your bookmarks',
40
      'unflag_message' => 'This post has been removed from your bookmarks',
41
      'types' => _flag_bookmark_install_get_suggested_node_types(),
42 42
    );
43 43
    $flag->form_input($configuration);
44 44
    $flag->save();
......
53 53
}
54 54

  
55 55
/**
56
 * Returns some node types to which the demonstration 'bookmarks' flag will apply.
56
 * Returns some node types to which the demonstration 'bookmarks' flag will
57
 * apply.
57 58
 */
58 59
function _flag_bookmark_install_get_suggested_node_types() {
59 60
  $preferred = array('article', 'story', 'forum', 'blog');
......
64 65
  }
65 66
  return $existing;
66 67
}
67

  
drupal7/sites/all/modules/flag/includes/flag.actions.inc
15 15
        'label' => t('Object has been flagged with any flag'),
16 16
      ),
17 17
      'flag_unflag' => array(
18
        'label' => t('Object has been unflagged with any flag')
18
        'label' => t('Object has been unflagged with any flag'),
19 19
      ),
20 20
    ),
21 21
  );
drupal7/sites/all/modules/flag/includes/flag.admin.inc
77 77

  
78 78
  foreach ($flags as $flag) {
79 79
    $ops = array(
80
      'flags_edit' =>  array('title' => t('edit'), 'href' => $flag->admin_path('edit')),
81
      'flags_fields' =>  array('title' => t('manage fields'), 'href' => $flag->admin_path('fields')),
82
      'flags_delete' =>  array('title' => t('delete'), 'href' => $flag->admin_path('delete')),
83
      'flags_export' =>  array('title' => t('export'), 'href' => $flag->admin_path('export')),
80
      'flags_edit' => array('title' => t('edit'), 'href' => $flag->admin_path('edit')),
81
      'flags_fields' => array('title' => t('manage fields'), 'href' => $flag->admin_path('fields')),
82
      'flags_delete' => array('title' => t('delete'), 'href' => $flag->admin_path('delete')),
83
      'flags_export' => array('title' => t('export'), 'href' => $flag->admin_path('export')),
84 84
    );
85 85
    if (!module_exists('field_ui')) {
86 86
      unset($ops['flags_fields']);
......
116 116
  if (count($flags) > 1) {
117 117
    $header[] = t('Weight');
118 118
  }
119
  $header = array_merge($header, array(t('Flag type'), t('Roles'), t('Entity bundles'), t('Global?'), t('Operations')));
119
  $header = array_merge($header, array(
120
    t('Flag type'),
121
    t('Roles'),
122
    t('Entity bundles'),
123
    t('Global?'),
124
    t('Operations'),
125
  ));
120 126
  $output .= theme('table', array(
121 127
    'header' => $header,
122 128
    'rows' => $rows,
......
142 148
      $ops = array();
143 149
      if (!$flag->is_compatible()) {
144 150
        $flag_updates_needed = TRUE;
145
        $ops['flags_update'] = array('title' => '<strong>' . t('update code') . '</strong>', 'href' => $flag->admin_path('update'), 'html' => TRUE);
151
        $ops['flags_update'] = array(
152
          'title' => '<strong>' . t('update code') . '</strong>',
153
          'href' => $flag->admin_path('update'),
154
          'html' => TRUE,
155
        );
146 156
      }
147 157
      else {
148 158
        $ops['flags_enable'] = array('title' => t('enable'), 'href' => $flag->admin_path('edit'));
......
163 173
  }
164 174

  
165 175
  if (!empty($rows)) {
166
    $header = array(t('Disabled Flags'), t('Module'), t('Flag type'), t('Operations'));
176
    $header = array(
177
      t('Disabled Flags'),
178
      t('Module'),
179
      t('Flag type'),
180
      t('Operations'),
181
    );
167 182
    $output .= theme('table', array('header' => $header, 'rows' => $rows));
168 183
  }
169 184

  
......
379 394
    '#title' => t('Token replacement'),
380 395
    '#type' => 'fieldset',
381 396
    '#description' =>
382
      '<p>' . t('The above six texts may contain any of the tokens listed below. For example, <em>"Flag link text"</em> could be entered as:') . '</p>' .
383
      theme('item_list', array(
384
        'items' => array(
385
          t('Add &lt;em&gt;[node:title]&lt;/em&gt; to your favorites'),
386
          t('Add this [node:type] to your favorites'),
387
          t('Vote for this proposal ([node:flag-vote-count] people have already done so)'),
388
        ),
389
        'attributes' => array('class' => 'token-examples'),
390
      )) .
391
      '<p>' . t('These tokens will be replaced with the appropriate fields from the node (or user, or comment).') . '</p>' .
392
      theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types())),
397
    '<p>' . t('The above six texts may contain any of the tokens listed below. For example, <em>"Flag link text"</em> could be entered as:') . '</p>' .
398
    theme('item_list', array(
399
      'items' => array(
400
        t('Add &lt;em&gt;[node:title]&lt;/em&gt; to your favorites'),
401
        t('Add this [node:type] to your favorites'),
402
        t('Vote for this proposal ([node:flag-vote-count] people have already done so)'),
403
      ),
404
      'attributes' => array('class' => 'token-examples'),
405
    )) .
406
    '<p>' . t('These tokens will be replaced with the appropriate fields from the node (or user, or comment).') . '</p>' .
407
    theme('flag_tokens_browser', array('types' => $flag->get_labels_token_types())),
393 408
    '#collapsible' => TRUE,
394 409
    '#collapsed' => TRUE,
395 410
  );
drupal7/sites/all/modules/flag/includes/flag.cookie_storage.inc
2 2

  
3 3
/**
4 4
 * @file
5
 *   Contains the FlagCookieStorage class.
5
 * Contains the FlagCookieStorage class.
6 6
 */
7 7

  
8 8
/**
drupal7/sites/all/modules/flag/includes/flag.export.inc
15 15
 *   in hook_flag_default_flags().
16 16
 */
17 17
function flag_export_flags($flags = array(), $module = '', $indent = '') {
18
  module_load_include('inc', 'features', 'features.export'); // For features_var_export() (optional).
18
  // For features_var_export() (optional).
19
  module_load_include('inc', 'features', 'features.export');
19 20
  $output = $indent . '$flags = array();' . "\n";
20 21
  foreach ($flags as $item) {
21 22
    if (is_object($item)) {
......
269 270
    if (substr($class, 0, 11) == 'FlagUpdate_') {
270 271
      // @todo: change this to work with the static class when we drop support
271 272
      // for PHP 5.2: see commit d5b517.
272
      $update_handler = new $class;
273
      $update_handler = new $class();
273 274
      // Cast to string, as decimals as array keys seem to be rounded down to
274 275
      // ints, WTF PHP?
275 276
      $version = (string) $update_handler->old_api_version;
......
364 365
    }
365 366

  
366 367
    // Update show_on_comment and show_on_entity properties to use new view
367
    // mode settings. Since the old logic was to show on all view modes, do that.
368
    // mode settings. Since the old logic was to show on all view modes, do
369
    // that.
368 370
    if (!empty($flag->show_on_entity) || !empty($flag->show_on_comment)) {
369 371
      if ($entity_info = entity_get_info($flag->entity_type)) {
370 372
        foreach ($entity_info['view modes'] as $view_mode => $value) {
drupal7/sites/all/modules/flag/includes/flag.pages.inc
93 93

  
94 94
  $question = $flag->get_label($action . '_confirmation', $entity_id);
95 95
  $path = isset($_GET['destination']) ? $_GET['destination'] : '<front>';
96
  $yes = $flag->get_label($action . '_short', $entity_id);
96
  $yes = strip_tags($flag->get_label($action . '_short', $entity_id));
97 97

  
98 98
  if ($action == 'flag') {
99 99
    // If the action 'flag', we're potentially about to create a new
......
101 101
    $flagging = $flag->new_flagging($entity_id);
102 102
    field_attach_form('flagging', $flagging, $form, $form_state);
103 103
    $form['#flagging'] = $flagging;
104

  
105
    // Take the same approach as Core entity forms: shove all the entity
106
    // properties into the form as values so that entity_form_field_validate()
107
    // can build a pseudoentity from $form_values in the validate handler.
108
    foreach (array(
109
      'flag_name',
110
      'entity_type',
111
      'entity_id',
112
      'uid',
113
    ) as $key) {
114
      $form[$key] = array(
115
        '#type' => 'value',
116
        '#value' => isset($flagging->$key) ? $flagging->$key : NULL,
117
      );
118
    }
104 119
  }
105 120

  
106 121
  return confirm_form($form, $question, $path, '', $yes);
107 122
}
108 123

  
124
/**
125
 * Validate handler for the flag confirm form.
126
 *
127
 * Validate any Field API fields on the Flagging.
128
 *
129
 * @see flag_confirm()
130
 */
131
function flag_confirm_validate($form, &$form_state) {
132
  // Only validate the entity fields when we're saving an entity.
133
  $action = $form_state['values']['action'];
134
  if ($action == 'flag') {
135
    entity_form_field_validate('flagging', $form, $form_state);
136
  }
137
}
138

  
109 139
/**
110 140
 * Submit handler for the flag confirm form.
111 141
 *
drupal7/sites/all/modules/flag/includes/flag/flag_comment.inc
2 2

  
3 3
/**
4 4
 * @file
5
 *   Contains the flag_comment class.
5
 * Contains the flag_comment class.
6 6
 */
7 7

  
8 8
/**
drupal7/sites/all/modules/flag/includes/flag/flag_entity.inc
2 2

  
3 3
/**
4 4
 * @file
5
 *   Contains the flag_entity class.
5
 * Contains the flag_entity class.
6 6
 */
7 7

  
8 8
/**
......
58 58
    }
59 59
    // Select the first display option by default if this is a new flag.
60 60
    if (empty($this->fid)) {
61
      $first_view_mode = reset(array_keys($entity_view_modes));
61
      $first_view_mode_keys = array_keys($entity_view_modes);
62
      $first_view_mode = reset($first_view_mode_keys);
62 63
      $defaults[$first_view_mode] = $first_view_mode;
63 64
    }
64 65

  
......
159 160
    );
160 161
  }
161 162

  
163
  /**
164
   * Invoke a Rules event in reaction to a flagging or unflagging.
165
   *
166
   * @param $action
167
   *   Either 'flag' or 'unflag'.
168
   * @param $flagging
169
   *  The flagging entity that is to be removed.
170
   * @param $entity_id
171
   *  The entity ID of entity being unflagged.
172
   * @param $account
173
   *  The account performing the unflagging.
174
   */
175
  protected function invoke_rules_event($action, $flagging, $entity_id, $account) {
176
    switch ($action) {
177
      case 'flag':
178
        $event_name = 'flag_flagged_' . $this->name;
179
        break;
180
      case 'unflag':
181
        $event_name = 'flag_unflagged_' . $this->name;
182
        break;
183
    }
184

  
185
    $variables = array(
186
      'flag' => $this,
187
      'flagged_' . $this->entity_type => $entity_id,
188
      'flagging_user' => $account,
189
      'flagging' => $flagging,
190
    );
191
    rules_invoke_event_by_args($event_name, $variables);
192
  }
193

  
162 194
  /**
163 195
   * Returns the entity id, if it already exists.
164 196
   */
drupal7/sites/all/modules/flag/includes/flag/flag_flag.inc
2 2

  
3 3
/**
4 4
 * @file
5
 *  Contains the flag_flag class.
6
 *  Flag type classes use an object oriented style inspired by that
7
 *  of Views 2.
5
 * Contains the flag_flag class.
6
 * Flag type classes use an object oriented style inspired by that
7
 * of Views 2.
8 8
 */
9 9

  
10 10
/**
11
 * This abstract class represents a flag, or, in Views 2 terminology, "a handler".
11
 * This abstract class represents a flag, or, in Views 2 terminology,
12
 * "a handler".
12 13
 *
13 14
 * This is the base class for all flag implementations. Notable derived
14 15
 * classes are flag_node and flag_comment.
......
29 30
 * - flag_flag::factory_by_array(), creates a flag handler from a configuration
30 31
 *   array. This is used by flag_get_default_flags() and the flag import form.
31 32
 * - flag_flag::factory_by_entity_type(), creates an empty flag handler for the
32
 *   given entity type. This is used when a new or dummy flag handler is required
33
 *   and there is no configuration yet.
33
 *   given entity type. This is used when a new or dummy flag handler is
34
 *   required and there is no configuration yet.
34 35
 *
35 36
 * The factory methods in turn all call the low-level function
36 37
 * flag_create_handler(), which obtains the correct handler for the flag, or if
......
94 95
  );
95 96

  
96 97
  /**
97
   * An associative array containing textual errors that may be created during validation.
98
   * An associative array containing textual errors that may be created during
99
   * validation.
98 100
   *
99 101
   * The array keys should reflect the type of error being set. At this time,
100 102
   * the only "special" behavior related to the array keys is that
......
103 105
   *
104 106
   * @var array
105 107
   */
106
  var $errors = array();
108
  public $errors = array();
107 109

  
108 110
  /**
109 111
   * Creates a flag from a database row. Returns it.
......
135 137
    }
136 138

  
137 139
    if (!empty($row->type)) {
138
      // The loop loading from the database should further populate this property.
140
      // The loop loading from the database should further populate this
141
      // property.
139 142
      $flag->types[] = $row->type;
140 143
    }
141 144

  
......
189 192
      'unflag_long' => '',
190 193
      'unflag_message' => '',
191 194
      'unflag_denied_text' => '',
192
      // The link type used by the flag, as defined in hook_flag_link_type_info().
195
      // The link type used by the flag, as defined in
196
      // hook_flag_link_type_info().
193 197
      'link_type' => 'toggle',
194 198
      'weight' => 0,
195 199
    );
......
245 249
   */
246 250
  function form_input($form_values) {
247 251
    // Load the form fields indiscriminately unto the flag (we don't care about
248
    // stray FormAPI fields because we aren't touching unknown properties anyway.
252
    // stray FormAPI fields because we aren't touching unknown properties
253
    // anyway).
249 254
    foreach ($form_values as $field => $value) {
250 255
      $this->$field = $value;
251 256
    }
......
626 631
   *   TRUE if the flag is enabled for this type and subtype.
627 632
   */
628 633
  function access_entity_enabled($entity_type, $content_subtype = NULL) {
629
   $entity_type_matches = ($this->entity_type == $entity_type);
630
   $sub_type_matches = FALSE;
631
   if (!isset($content_subtype) || !count($this->types)) {
632
     // Subtype automatically matches if we're not asked about it,
633
     // or if the flag applies to all subtypes.
634
     $sub_type_matches = TRUE;
635
   }
636
   else {
637
     $sub_type_matches = in_array($content_subtype, $this->types);
638
   }
639
   return $entity_type_matches && $sub_type_matches;
640
 }
634
    $entity_type_matches = ($this->entity_type == $entity_type);
635
    $sub_type_matches = FALSE;
636
    if (!isset($content_subtype) || !count($this->types)) {
637
      // Subtype automatically matches if we're not asked about it,
638
      // or if the flag applies to all subtypes.
639
      $sub_type_matches = TRUE;
640
    }
641
    else {
642
      $sub_type_matches = in_array($content_subtype, $this->types);
643
    }
644
    return $entity_type_matches && $sub_type_matches;
645
  }
641 646

  
642 647
  /**
643 648
   * Determine whether the flag should show a flag link in entity links.
......
685 690
   *   - to update field data an existing flagging. The $action parameter should
686 691
   *     be set to 'flag'. The Flagging entity will need to be loaded first with
687 692
   *     flagging_load().
693
   *  As with Drupal core API functions for saving entities, no validation of
694
   *  Field API fields is performed here. It is the responsibility of the caller
695
   *  to take care of Field API validation, using either
696
   *  field_attach_form_validate() or field_attach_validate().
688 697
   *
689 698
   * @return
690 699
   *   FALSE if some error occured (e.g., user has no permission, flag isn't
......
695 704
    if (!isset($account)) {
696 705
      $account = $GLOBALS['user'];
697 706
    }
698
    if (!$account) {
699
      return FALSE;
700
    }
701 707

  
702 708
    // Check access and applicability.
703 709
    if (!$skip_permission_check) {
......
736 742
      }
737 743
    }
738 744

  
739
    // Set our uid and sid to the flagging object.
745
    // @todo: Discuss: Core wraps everything in a try { }, should we?
746

  
747
    $existing_flagging_id = $this->_is_flagged($entity_id, $uid, $sid);
748
    $flagged = (bool) $existing_flagging_id;
749

  
750
    // Ensure we have a Flagging entity and it is correctly formed.
740 751
    if (isset($flagging)) {
752
      // We were given a Flagging entity.
753
      // Ensure that it has the uid and sid that we were also given.
741 754
      $flagging->uid = $uid;
742 755
      $flagging->sid = $sid;
743
    }
744 756

  
745
    // @todo: Discuss: Should we call field_attach_validate()? None of the
746
    // entities in core does this (fields entered through forms are already
747
    // validated).
748
    //
749
    // @todo: Discuss: Core wraps everything in a try { }, should we?
757
      // This is an ugly hack to preserve previous behaviour.
758
      $flagging->given_as_parameter = TRUE;
759
    }
760
    else {
761
      // We were not given a Flagging entity.
762
      if ($flagged) {
763
        // Load the existing Flagging entity.
764
        $flagging = flagging_load($existing_flagging_id);
765
      }
766
      else {
767
        // Construct a new Flagging entity to flag with.
768
        $flagging = $this->new_flagging($entity_id, $uid, $sid);
769
      }
770
    }
750 771

  
751 772
    // Perform the flagging or unflagging of this flag.
752
    $existing_flagging_id = $this->_is_flagged($entity_id, $uid, $sid);
753
    $flagged = (bool) $existing_flagging_id;
754 773
    if ($action == 'unflag') {
755
      if ($this->uses_anonymous_cookies()) {
756
        $this->_unflag_anonymous($entity_id);
757
      }
758 774
      if ($flagged) {
759
        if (!isset($flagging)) {
760
          $flagging = flagging_load($existing_flagging_id);
761
        }
762
        $transaction = db_transaction();
763
        try {
764
          // Note the order: We decrease the count first so hooks have accurate
765
          // data, then invoke hooks, then delete the flagging entity.
766
          $this->_decrease_count($entity_id);
767
          module_invoke_all('flag_unflag', $this, $entity_id, $account, $flagging);
768
          // Invoke Rules event.
769
          if (module_exists('rules')) {
770
            $event_name = 'flag_unflagged_' . $this->name;
771
            // We only support flags on entities.
772
            if (entity_get_info($this->entity_type)) {
773
              $variables = array(
774
                'flag' => $this,
775
                'flagged_' . $this->entity_type => $entity_id,
776
                'flagging_user' => $account,
777
                'flagging' => $flagging,
778
              );
779
              rules_invoke_event_by_args($event_name, $variables);
780
            }
781
          }
782
          $this->_delete_flagging($flagging);
783
          $this->_unflag($entity_id, $flagging->flagging_id);
784
        }
785
        catch (Exception $e) {
786
          $transaction->rollback();
787
          watchdog_exception('flag', $e);
788
          throw $e;
789
        }
775
        $this->flagging_delete($flagging, $entity_id, $account);
790 776
      }
777
      // We do nothing in the case of an attempt to unflag something that isn't
778
      // actually flagged.
791 779
    }
792 780
    elseif ($action == 'flag') {
793
      if ($this->uses_anonymous_cookies()) {
794
        $this->_flag_anonymous($entity_id);
795
      }
796

  
797
      // By definition there is no flagging entity yet, but we may have been
798
      // passed one in to save.
799
      if (!isset($flagging)) {
800
        // Construct a new flagging object if we weren't passed one.
801
        $flagging = $this->new_flagging($entity_id, $uid, $sid);
802
      }
803

  
804
      // Invoke hook_entity_presave().
805
      // In the case that we have been passed in a flagging entity to update,
806
      // this is technically still a presave, even though the {flagging} table
807
      // itself is not changed.
808
      module_invoke_all('entity_presave', $flagging, 'flagging');
809

  
810 781
      if (!$flagged) {
811
        // The entity is unflagged.
812

  
813
        // Save the flagging entity (just our table).
814
        $this->_flag($flagging);
815
        $this->_increase_count($entity_id);
816
        // We're writing out a flagging entity even when we aren't passed one
817
        // (e.g., when flagging via JavaScript toggle links); in this case
818
        // Field API will assign the fields their default values.
819
        $this->_insert_flagging($flagging);
820
        module_invoke_all('flag_flag', $this, $entity_id, $account, $flagging);
821
        // Invoke Rules event.
822
        if (module_exists('rules')) {
823
          $event_name = 'flag_flagged_' . $this->name;
824
          // We only support flags on entities.
825
          if (entity_get_info($this->entity_type)) {
826
            $variables = array(
827
              'flag' => $this,
828
              'flagged_' . $this->entity_type => $entity_id,
829
              'flagging_user' => $account,
830
              'flagging' => $this->get_flagging($entity_id, $account->uid),
831
            );
832
            rules_invoke_event_by_args($event_name, $variables);
833
          }
834
        }
782
        $this->flagging_insert($flagging, $entity_id, $account);
835 783
      }
836 784
      else {
837
        // Nothing to do. Item is already flagged.
838
        //
839
        // Except in the case a $flagging object is one that was passed in: in
840
        // this case we're being requested to update the flagging. This occurs,
841
        // for example, when the user updates the flagging entity form.
842
        if (!empty($flagging->flagging_id)) {
843
          $this->_update_flagging($flagging);
844
        }
785
        $this->flagging_update($flagging, $entity_id, $account);
845 786
      }
846 787
    }
847 788

  
......
849 790
  }
850 791

  
851 792
  /**
852
   * The entity CRUD methods _{insert,update,delete}_flagging() are for private
853
   * use by the flag() method.
793
   * Create a new Flagging to flag an entity.
854 794
   *
855
   * The reason programmers should not call them directly is because a flagging
856
   * operation is also accompanied by some bookkeeping (calling hooks, updating
857
   * counters) or access control. These tasks are handled by the flag() method.
795
   * @param $flagging
796
   *  The flagging entity that is to be removed.
797
   * @param $entity_id
798
   *  The entity ID of entity being unflagged.
799
   * @param $account
800
   *  The account performing the unflagging.
858 801
   */
859
  private function _insert_flagging($flagging) {
802
  private function flagging_insert($flagging, $entity_id, $account) {
803
    if ($this->uses_anonymous_cookies()) {
804
      $this->_flag_anonymous($entity_id);
805
    }
806

  
807
    // Invoke presave hooks.
860 808
    field_attach_presave('flagging', $flagging);
809
    // Invoke hook_entity_presave().
810
    module_invoke_all('entity_presave', $flagging, 'flagging');
811

  
812
    // Set the timestamp.
813
    $flagging->timestamp = REQUEST_TIME;
814

  
815
    // Save the flagging entity.
816
    drupal_write_record('flagging', $flagging);
817

  
818
    // Clear various caches; we don't want code running after us to report
819
    // wrong counts or false flaggings.
820
    drupal_static_reset('flag_get_user_flags');
821
    drupal_static_reset('flag_get_entity_flags');
822
    // Despite being named in the same pattern as the count API functions, these
823
    // query the {flagging} table, so are reset here.
824
    drupal_static_reset('flag_get_entity_flag_counts');
825
    drupal_static_reset('flag_get_user_flag_counts');
826

  
827
    $this->_increase_count($entity_id);
828
    // We're writing out a flagging entity even when we aren't passed one
829
    // (e.g., when flagging via JavaScript toggle links); in this case
830
    // Field API will assign the fields their default values.
831

  
832
    // Invoke insert hooks.
861 833
    field_attach_insert('flagging', $flagging);
862 834
    // Invoke hook_entity_insert().
863 835
    module_invoke_all('entity_insert', $flagging, 'flagging');
836

  
837
    module_invoke_all('flag_flag', $this, $entity_id, $account, $flagging);
838
    // Invoke Rules event.
839
    if (module_exists('rules')) {
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff