paristemi
[ class tree: paristemi ] [ index: paristemi ] [ all elements ]

Source for file util_files.php

Documentation is available at util_files.php

  1. <?php
  2. /**
  3. * <b>Utility Class : File Manipulation & Creation</b><br />
  4. * A collection of utility functions for working with files.
  5. * Creation: PDFs and Images
  6. * Manipulation: Gets URLs and Gathers File Sizes
  7. * @author Kristen O'Brien <kristen_paristemi-com>
  8. * @copyright Copyright 2004, Kristen O'Brien
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @link http://www.paristemi.com Paristemi Main Site
  11. * @package paristemi
  12. * @subpackage paristemi_util
  13. * @since Build 0.7
  14. * @version Build 0.7
  15. * @filesource
  16. */
  17. /**
  18. * Include the constants file and all of the files in the include list
  19. */
  20. if(ltrim(dirname($_SERVER['SCRIPT_FILENAME'])) == "" || !file_exists($_SERVER['DOCUMENT_ROOT']."/constants.php")) {
  21. if(!file_exists("../constants.php")) { require_once("../public_html/constants.php"); }
  22. else { require_once("../constants.php"); }
  23. }
  24. else { require_once($_SERVER['DOCUMENT_ROOT']."/constants.php"); }
  25. if($SHOW_PDF_DL) { require_once($SERVER_DIRECTORY.$INCLUDE_PATH.$PDF_CLASS); }
  26.  
  27. /**
  28. * Utility Class : File Manipulation & Creation
  29. * A collection of utility functions for working with files.
  30. * Creation: PDFs and Images
  31. * Manipulation: Gets URLs and Gathers File Sizes
  32. * @author Kristen O'Brien <kristen_paristemi-com>
  33. * @copyright Copyright &copy; 2004, Kristen O'Brien
  34. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  35. * @link http://www.paristemi.com Paristemi Main Site
  36. * @package paristemi
  37. * @subpackage paristemi_util
  38. * @since Build 0.7
  39. * @version Build 0.7
  40. * @filesource
  41. */
  42. class UtilFiles {
  43. // Utilities for file manipulation/creation
  44.  
  45. function PreparePDFString($string) {
  46. return
  47. str_replace('<a href="','<c:alink:',
  48. str_replace('" target="_blank','',
  49. str_replace('">','>',
  50. str_replace('</a>','</c:alink>',
  51. str_replace("<br />","",
  52. str_replace("&nbsp;"," ",
  53. str_replace("<span class=\"filesize\"","",
  54. str_replace("<span class=\"speaker\">","<b><i>",
  55. str_replace("</span>","</b></i>",
  56. str_replace("</em>","</i>",
  57. str_replace("<em>","<i>",$string)))))))))));
  58. }
  59. function CreatePDF($title,$text,$footer,$sublink,$font="Helvetica.afm") {
  60. $pdf =& new Cezpdf();
  61. $pdf->selectFont($GLOBALS['SERVER_DIRECTORY'].$GLOBALS['INCLUDE_PATH']
  62. .$GLOBALS['PDF_FONT_DIR'].$font);
  63. $pdf->ezText('',14);
  64. $pdf->ezText(UtilFiles::PreparePDFString($title),16);
  65. $pdf->ezText('',14);
  66. $pdf->ezText(UtilFiles::PreparePDFString($text),12);
  67. $pdf->ezText('',20);
  68. $pdf->ezText(UtilFiles::PreparePDFString($footer),12);
  69. $pdf->ezText('',20);
  70. $pdf->ezText($GLOBALS['CHURCH_NAME'],14);
  71. $pdf->ezText('<c:alink:'.$GLOBALS['HTTP_DOCUMENT_ROOT'].'>'.
  72. $GLOBALS['HTTP_DOCUMENT_ROOT'].'</c:alink>',14);
  73. $pdf->ezText('(<c:alink:'.trim($sublink).'>'.trim($sublink).'</c:alink>)',10);
  74. $pdf->ezStream();
  75. }
  76. function createImageText($id,$area,$height=20,$width=200,$bgcolor="255,255,255",
  77. $textcolor="0,0,255",$font=2,$x=2,$y=2) {
  78. $gdinfo = gd_info();
  79. if (isset($gdinfo['GIF Support'])) {
  80. if($gdinfo['GIF Support']) {
  81. return '<img src="'.$GLOBALS['HTTP_DOCUMENT_ROOT'].
  82. $GLOBALS['INCLUDE_PATH'].$GLOBALS['MAKE_IMAGE_INCLUDE'].
  83. '?imgtype=gif&amp;id='.$id.'&amp;area='.
  84. $area.'&amp;width='.$width.'&amp;height='.$height.'&amp;bgcolor='.$bgcolor.
  85. '&amp;textcolor='.$textcolor.'&amp;font='.$font.'&amp;x='.$x.'&amp;y='.$y.'">';
  86. }
  87. }
  88. else if(isset($gdinfo['JPG Support'])) {
  89. if($gdinfo['JPG Support']) {
  90. return '<img src="'.$GLOBALS['HTTP_DOCUMENT_ROOT'].
  91. $GLOBALS['INCLUDE_PATH'].$GLOBALS['MAKE_IMAGE_INCLUDE'].
  92. '?imgtype=jpg&amp;id='.$id.'&amp;area='.
  93. $area.'&amp;width='.$width.'&amp;height='.$height.'&amp;bgcolor='.$bgcolor.
  94. '&amp;textcolor='.$textcolor.'&amp;font='.$font.'&amp;x='.$x.'&amp;y='.$y.'">';
  95. }
  96. }
  97. else if($gdinfo['PNG Support']) {
  98. if($gdinfo['PNG Support']) {
  99. return '<img src="'.$GLOBALS['HTTP_DOCUMENT_ROOT'].
  100. $GLOBALS['INCLUDE_PATH'].$GLOBALS['MAKE_IMAGE_INCLUDE'].
  101. '?imgtype=png&amp;id='.$id.'&amp;area='.
  102. $area.'&amp;width='.$width.'&amp;height='.$height.'&amp;bgcolor='.$bgcolor.
  103. '&amp;textcolor='.$textcolor.'&amp;font='.$font.'&amp;x='.$x.'&amp;y='.$y.'">';
  104. }
  105. }
  106. else { return null; }
  107. }
  108.  
  109. // From dave at birko dot cjb dot net (PHP Filesize Comment)
  110.  
  111. function fsize($size) {
  112. $a = array("B","KB","MB","GB","TB","PB"); $pos = 0;
  113. while ($size >= 1024) { $size /= 1024; $pos++; }
  114. return round($size,2)." ".$a[$pos];
  115. }
  116. function ParseServerFromURL($url) {
  117. $url = substr($url,strpos($url,"http://")+7,strlen($url));
  118. return substr($url,0,strpos($url,"/"));
  119. }
  120. function ParseFileFromURL($url) {
  121. $url = substr($url,strpos($url,"http://")+7,strlen($url));
  122. return substr($url,strpos($url,"/"),strlen($url));
  123. }
  124. //socket code from AlCapone (http://forums.devshed.com/member.php?action=getinfo&userid=12092)
  125.  
  126. function GetFilesize($file,$usebytes=0) {
  127. if(strcmp(UtilFiles::ParseServerFromURL($file),$GLOBALS['SERVER_NAME']) == 0) {
  128. $file = UtilFiles::ParseFileFromURL($file);
  129. $file = $GLOBALS['SERVER_DIRECTORY'].substr($file,1,strlen($file));
  130. if(file_exists($file)) {
  131. if($usebytes) { return filesize($file); }
  132. else { return UtilFiles::fsize(filesize($file)); }
  133. }
  134. else { return null; }
  135. }
  136. else {
  137. $fsize = 0;
  138. $fp = fsockopen(UtilFiles::ParseServerFromURL($file),80,$errno,$errstr,30);
  139. if($fp) {
  140. fputs($fp,"HEAD ".UtilFiles::ParseFileFromURL($file)." HTTP/1.0\r\n\r\n");
  141. while(!feof($fp)) {
  142. $line=fgets($fp,128);
  143. if(eregi("^Content-Length: ([0-9]+)",$line,$a)) { $fsize=$a[1]; }
  144. }
  145. fclose($fp);
  146. }
  147. if($usebytes) { return $fsize; }
  148. else { return UtilFiles::fsize($fsize); }
  149. }
  150. }
  151. }
  152.  
  153. ?>

Documentation generated on Mon, 10 May 2004 12:11:09 -0700 by phpDocumentor 1.3.0RC3