ZasobFileOdt.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. class ZasobFileOdt {
  3. var $zasob_id;
  4. var $druk_zasob_id;
  5. var $base_path;
  6. var $xsl_file;
  7. var $odt_file;
  8. var $content;
  9. function __construct($zasob_id, $base_path, $xsl_path, $druk_zasob_id = null) {
  10. $this->zasob_id = $zasob_id;
  11. $this->druk_zasob_id = ($druk_zasob_id)? $druk_zasob_id : $zasob_id;
  12. $this->base_path = $base_path;
  13. $this->xsl_path = $xsl_path;
  14. $this->odt_file = '';
  15. $this->xsl_file = '';
  16. $this->content = '';
  17. }
  18. function find_odt_file() {
  19. $tmp_druki = array();
  20. $tmp_druki = glob("{$this->base_path}/{$this->zasob_id}.*/{$this->druk_zasob_id}.*.odt", GLOB_NOSORT);
  21. if (empty($tmp_druki)) {
  22. return false;
  23. }
  24. if (count($tmp_druki) == 1) {
  25. $this->odt_file = reset($tmp_druki);
  26. } else {
  27. // TODO: sort by date and get first?
  28. $this->odt_file = end($tmp_druki);
  29. }
  30. if (!$this->odt_file) {
  31. return false;
  32. }
  33. return true;
  34. }
  35. function find_xsl_file() {
  36. $tmp_druki = glob("{$this->xsl_path}/{$this->zasob_id}.*.xsl", GLOB_NOSORT);
  37. if (empty($tmp_druki)) {
  38. return false;
  39. }
  40. if (count($tmp_druki) == 1) {
  41. $this->xsl_file = reset($tmp_druki);
  42. } else {
  43. // TODO: sort by date and get first?
  44. $this->xsl_file = end($tmp_druki);
  45. }
  46. if (!$this->xsl_file) {
  47. return false;
  48. }
  49. return true;
  50. }
  51. /**
  52. * @param $converter - require methods: oo_unzip(odt_file); oo_convert(unzip, xsl_file);
  53. */
  54. function fetch_content_from_odt_by_converter($converter) {
  55. $conv = new Odt2xhtml;
  56. $this->content = $converter->oo_convert($converter->oo_unzip($this->odt_file), $this->xsl_file);
  57. if (empty($this->content)) {
  58. return false;
  59. }
  60. }
  61. function add_data($data) {
  62. if (empty($this->content)) {
  63. return;
  64. }
  65. foreach ($data as $k_field => $v_value) {
  66. $this->content = str_replace('<span id="cell-'.$k_field.'"></span>', $v_value, $this->content);
  67. }
  68. }
  69. function get_content() {
  70. return $this->content;
  71. }
  72. }