views_php_plugin_access.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Access plugin that provides access control based on custom PHP code.
  4. *
  5. * @ingroup views_access_plugins
  6. */
  7. class views_php_plugin_access extends views_plugin_access {
  8. /**
  9. * Implements views_plugin_access#summary_title().
  10. */
  11. function summary_title() {
  12. return t('PHP');
  13. }
  14. /**
  15. * Implements views_object#option_definition().
  16. */
  17. function option_definition() {
  18. $options = parent::option_definition();
  19. $options['php_access'] = array('default' => '');
  20. return $options;
  21. }
  22. /**
  23. * Implements views_plugin#options_form().
  24. */
  25. function options_form(&$form, &$form_state) {
  26. parent::options_form($form, $form_state);
  27. $form += views_php_form_element($this,
  28. FALSE,
  29. array('php_access', t('Access code'), t('If the code returns TRUE the requesting user is granted access to the view.'), FALSE),
  30. array(
  31. '$view_name' => t('The name of the view to check.'),
  32. '$display_id' => t('The ID of the display to check.'),
  33. '$account' => t('The account to check.'),
  34. )
  35. );
  36. }
  37. /**
  38. * Implements views_plugin#options_submit().
  39. */
  40. function options_submit(&$form, &$form_state) {
  41. $form_state['values']['access_options']['php_access'] = $form_state['values']['options']['php_access'];
  42. }
  43. /**
  44. * Implements views_plugin_access#access().
  45. */
  46. function access($account) {
  47. if (!empty($this->options['php_access'])) {
  48. return views_php_check_access($this->options['php_access'], $this->view->name, $this->display->id, $account);
  49. }
  50. return TRUE;
  51. }
  52. /**
  53. * Implements views_plugin_access#get_access_callback().
  54. */
  55. function get_access_callback() {
  56. if (!empty($this->options['php_access'])) {
  57. return array('views_php_check_access', array($this->options['php_access'], $this->view->name, $this->display->id));
  58. }
  59. return TRUE;
  60. }
  61. }