views_php_handler_area.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * A handler to provide an area that is constructed by the administrator using PHP.
  4. *
  5. * @ingroup views_area_handlers
  6. */
  7. class views_php_handler_area extends views_handler_area {
  8. /**
  9. * Implements views_object#option_definition().
  10. */
  11. function option_definition() {
  12. $options = parent::option_definition();
  13. $options['php_output'] = array('default' => "<h4>Example PHP code</h4>\n<p>Time: <?php print date('H:i', time());?></p>\n");
  14. return $options;
  15. }
  16. /**
  17. * Implements views_handler#option_definition().
  18. */
  19. function options_form(&$form, &$form_state) {
  20. parent::options_form($form, $form_state);
  21. $form += views_php_form_element($this,
  22. FALSE,
  23. array('php_output', t('Output code'), t('Code to construct the output of this area.'), TRUE),
  24. array('$view', '$handler', '$results')
  25. );
  26. }
  27. /**
  28. * Implements views_handler_area#render().
  29. */
  30. function render($empty = FALSE) {
  31. // Ecexute output PHP code.
  32. if ((!$empty || !empty($this->options['empty'])) && !empty($this->options['php_output'])) {
  33. $function = create_function('$view, $handler, $results', ' ?>' . $this->options['php_output'] . '<?php ');
  34. ob_start();
  35. $function($this->view, $this, $this->view->result);
  36. return ob_get_clean();
  37. }
  38. return '';
  39. }
  40. }