PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/handlers/class.atkdocumenthandler.inc

https://github.com/ibuildingsnl/ATK
PHP | 117 lines | 52 code | 16 blank | 49 comment | 7 complexity | 2bf94aa181ac5e01fa81715ed2037fce MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, LGPL-3.0
  1. <?php
  2. /**
  3. * atkDocumentHandler class file
  4. *
  5. * @package atk
  6. * @subpackage handlers
  7. *
  8. * @author guido <guido@ibuildings.nl>
  9. *
  10. * @copyright (c) 2005 Ibuildings.nl BV
  11. * @license http://www.achievo.org/atk/licensing/ ATK open source license
  12. *
  13. * @version $Revision: 4296 $
  14. * $Id$
  15. */
  16. /**
  17. * Handler class for the document action
  18. *
  19. * @author guido <guido@ibuildings.nl>
  20. * @package atk
  21. * @subpackage handlers
  22. */
  23. class atkDocumentHandler extends atkActionHandler
  24. {
  25. /**
  26. * The action handler.
  27. */
  28. function action_document()
  29. {
  30. // Add "Action document" to debug log to indicate this function is entered
  31. atkdebug("Action document");
  32. // Load and instantiate the documentwriter
  33. atkimport("atk.document.atkdocumentwriter");
  34. $openDocumentWriter = &atkDocumentWriter::getInstance("opendocument");
  35. // ATKSelector must be available to perform this action
  36. if ($this->m_postvars["atkselector"] == "")
  37. {
  38. atkerror("Selector parameter not available.");
  39. return false;
  40. }
  41. // ATKDocTpl must be available to perform this action
  42. if (!isset($this->m_postvars["atkdoctpl"]))
  43. {
  44. atkerror("atkdoctpl parameter not available.");
  45. return false;
  46. }
  47. $tpl_file = $this->getFilenameForTemplate($this->m_postvars["atkdoctpl"]);
  48. // Check for invalid characters in filename, modulename and nodename in order to prevent hacking
  49. if (ereg("[<>\\/|;]", $module . $node . $this->m_postvars["atkdoctpl"]) !== false)
  50. {
  51. atkerror("Invalid filename given.");
  52. return false;
  53. }
  54. // Check if the file exists
  55. if (!is_file($tpl_file))
  56. {
  57. atkerror("Given file does not exist.");
  58. return false;
  59. }
  60. // Assign the record variables to the OpenOffice.org DocumentWriter
  61. if (method_exists($this->m_node, "assignDocumentVars"))
  62. $this->m_node->assignDocumentVars($openDocumentWriter, $this->m_postvars["atkselector"]);
  63. else
  64. $this->assignDocumentVars($openDocumentWriter, $this->m_postvars["atkselector"]);
  65. // Send the document to the browser
  66. if (!$openDocumentWriter->display($tpl_file, $this->m_postvars["atkdoctpl"]))
  67. return false;
  68. // Halt further execution to prevent atk rendering it's interface causing to corrupt the opendocument file
  69. exit;
  70. }
  71. /**
  72. * Default document assignment function (assigns the given record and
  73. * the generic vars)
  74. *
  75. * @param atkDocumentWriter $documentWriter DocumentWriter to which the variables should be assigned
  76. * @param String $selector String containing the selector used to get the document from the database
  77. */
  78. function assignDocumentVars(&$documentWriter, $selector)
  79. {
  80. // Load the selected record from the database
  81. $record = $this->m_node->selectDb($selector, "", "", $this->m_viewExcludes, "", "document");
  82. // Assign the record to the documentWriter
  83. $documentWriter->assignDocumentSingleRecord($this->m_node, $record[0]);
  84. // Also assign the generic (date) vars tot the documentWriter
  85. $documentWriter->assignDocumentGenericVars();
  86. }
  87. /**
  88. * Compose the filename to be used (doctemplatedir/module/node/<docmentfilename)
  89. *
  90. * @param String $template
  91. * @return String
  92. */
  93. function getFilenameForTemplate($template)
  94. {
  95. $basepath = atkconfig("doctemplatedir", "doctemplates/");
  96. $module = $this->m_node->m_module;
  97. $node = $this->m_node->m_type;
  98. return $basepath . $module . "/" . $node . "/" . $template;
  99. }
  100. }
  101. ?>