Révision 76e2e7c3
Ajouté par Assos Assos il y a environ 10 ans
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 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules