1
0

NZBFile.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /* $Id: NZBFile.php 2355 2007-01-23 17:18:40Z b4rt $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * NZBFile
  17. */
  18. class NZBFile
  19. {
  20. // public fields
  21. // file
  22. var $theFile = "";
  23. // props
  24. var $files = array();
  25. var $size = 0;
  26. var $filecount = 0;
  27. // content
  28. var $content = "";
  29. // =========================================================================
  30. // public static methods
  31. // =========================================================================
  32. /**
  33. * factory
  34. *
  35. * @param $nzbname
  36. * @return NZBFile
  37. */
  38. function getInstance($nzbname = "") {
  39. return new NZBFile($nzbname);
  40. }
  41. // =========================================================================
  42. // ctor
  43. // =========================================================================
  44. /**
  45. * ctor
  46. *
  47. * @param $nzbname
  48. * @param $user
  49. * @return NZBFile
  50. */
  51. function NZBFile($nzbname = "") {
  52. $this->initialize($nzbname);
  53. }
  54. // =========================================================================
  55. // public methods
  56. // =========================================================================
  57. /**
  58. * initialize
  59. *
  60. * @param $nzbname
  61. */
  62. function initialize($nzbname) {
  63. global $cfg;
  64. // vars
  65. $this->theFile = $cfg["transfer_file_path"].$nzbname;
  66. $this->files = array();
  67. $this->size = 0;
  68. $this->filecount = 0;
  69. // load file
  70. $this->content = @file_get_contents($this->theFile);
  71. $tList = explode("\n", $this->content);
  72. if ((isset($tList)) && (is_array($tList))) {
  73. $fname = "";
  74. $fsize = 0;
  75. foreach ($tList as $tLine) {
  76. // file-start
  77. if (strpos($tLine, "<file") !== false) {
  78. $fname = preg_replace('/<file.*subject="(.*)">/i', '${1}', $tLine);
  79. $fsize = 0;
  80. }
  81. // segment
  82. if (strpos($tLine, "<segment bytes") !== false) {
  83. $bytes = preg_replace('/<segment bytes="(\d+)".*/i', '${1}', $tLine);
  84. $fsize += floatval($bytes);
  85. }
  86. // file end
  87. if (strpos($tLine, "</file>") !== false) {
  88. array_push($this->files, array(
  89. 'name' => $fname,
  90. 'size' => $fsize
  91. )
  92. );
  93. // size
  94. $this->size += $fsize;
  95. }
  96. }
  97. // count
  98. $this->filecount = count($this->files);
  99. }
  100. }
  101. /**
  102. * write Method
  103. *
  104. * @return boolean
  105. */
  106. function write() {
  107. // write file
  108. if ($handle = @fopen($this->theFile, "w")) {
  109. $resultSuccess = (@fwrite($handle, $this->content) !== false);
  110. @fclose($handle);
  111. return $resultSuccess;
  112. }
  113. return false;
  114. }
  115. }
  116. ?>