php_evaluator.cls.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  7. */
  8. /**
  9. * Executes inline PHP code during the rendering process
  10. *
  11. * @access private
  12. * @package dompdf
  13. */
  14. class PHP_Evaluator {
  15. /**
  16. * @var Canvas
  17. */
  18. protected $_canvas;
  19. function __construct(Canvas $canvas) {
  20. $this->_canvas = $canvas;
  21. }
  22. function evaluate($code, $vars = array()) {
  23. if ( !$this->_canvas->get_dompdf()->get_option("enable_php") ) {
  24. return;
  25. }
  26. // Set up some variables for the inline code
  27. $pdf = $this->_canvas;
  28. $PAGE_NUM = $pdf->get_page_number();
  29. $PAGE_COUNT = $pdf->get_page_count();
  30. // Override those variables if passed in
  31. foreach ($vars as $k => $v) {
  32. $$k = $v;
  33. }
  34. //$code = html_entity_decode($code); // @todo uncomment this when tested
  35. eval($code);
  36. }
  37. function render(Frame $frame) {
  38. $this->evaluate($frame->get_node()->nodeValue);
  39. }
  40. }