context_condition_user_page.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Expose user pages as a context condition.
  4. */
  5. class context_condition_user_page extends context_condition {
  6. function condition_values() {
  7. $values = array();
  8. $values['view'] = t('User profile');
  9. $values['form'] = t('User account form');
  10. $values['register'] = t('Registration form');
  11. return $values;
  12. }
  13. function options_form($context) {
  14. $defaults = $this->fetch_from_context($context, 'options');
  15. return array(
  16. 'mode' => array(
  17. '#title' => t('Active for'),
  18. '#type' => 'select',
  19. '#options' => array(
  20. 'all' => t('Any user'),
  21. 'current' => t('Only the current user'),
  22. 'other' => t('Only other users'),
  23. ),
  24. '#default_value' => isset($defaults['mode']) ? $defaults['mode'] : 'all',
  25. ),
  26. );
  27. }
  28. function execute($account, $op) {
  29. global $user;
  30. foreach ($this->get_contexts($op) as $context) {
  31. if ($op === 'register') {
  32. $this->condition_met($context);
  33. }
  34. else {
  35. $options = $this->fetch_from_context($context, 'options');
  36. $mode = !empty($options['mode']) ? $options['mode'] : 'all';
  37. switch ($options['mode']) {
  38. case 'current':
  39. if ($account->uid == $user->uid) {
  40. $this->condition_met($context);
  41. }
  42. break;
  43. case 'other':
  44. if ($account->uid != $user->uid) {
  45. $this->condition_met($context);
  46. }
  47. break;
  48. case 'all':
  49. default:
  50. $this->condition_met($context);
  51. break;
  52. }
  53. }
  54. }
  55. }
  56. }