Source for file viewer.php

Documentation is available at viewer.php

  1. <?php
  2.  
  3. class pl_olga_files_viewer {
  4.  
  5. var $_debug_prefix;
  6.  
  7. var $_config;
  8. var $_topic;
  9. var $_article;
  10. var $_layout;
  11. var $_path;
  12. var $_root;
  13. var $_filename;
  14.  
  15. var $errcode;
  16. var $errstr;
  17. var $breadcrumb;
  18.  
  19. function pl_olga_files_viewer($topic, $config) {
  20.  
  21. global $argv,$midcom;
  22.  
  23. $this->_debug_prefix = "pl.olga.files viewer::";
  24.  
  25. $this->_config = $config;
  26. $this->_topic = $topic;
  27.  
  28. $this->_article = false;
  29. $this->_layout = false;
  30.  
  31. $this->errcode = MIDCOM_ERROK;
  32. $this->errstr = "";
  33.  
  34. $this->_go = false;
  35. $this->_root = $this->_config->get("root_path");
  36.  
  37. $tmp=$argv;
  38. $tmp[0]="";
  39. $this->_path=join("/",$tmp);
  40.  
  41. $this->_filename=str_replace("//","/",$this->_root."/".$this->_path);
  42.  
  43. $prefix = $midcom->prefix."/".$topic->name;
  44. foreach($tmp as $atom)
  45. if($atom){
  46. $prefix.="/".$atom;
  47. $this->breadcrumb.='/<a href="'.$prefix.'">'.$atom.'</a>';
  48. }
  49. }
  50.  
  51.  
  52. function can_handle($argc, $argv) {
  53.  
  54. debug_push($this->_debug_prefix . "can_handle");
  55. debug_pop();
  56.  
  57. $path=implode("/",$argv);
  58. if(strstr($path,"..")) return false;
  59. return true;
  60. }
  61.  
  62.  
  63. function _getArticle ($argc, $argv) {
  64.  
  65. debug_push($this->_debug_prefix . "_getArticle");
  66. debug_pop();
  67.  
  68.  
  69. }
  70.  
  71. // handle($argc, $argv)
  72. //
  73. // ....
  74. //
  75. function handle() {
  76.  
  77. global $midcom;
  78. global $pl_olga_files_layouts;
  79. debug_push($this->_debug_prefix . "handle");
  80.  
  81.  
  82.  
  83. if ($this->errcode != MIDCOM_ERROK) {
  84. debug_pop();
  85. return false;
  86. }
  87.  
  88. if(is_file($this->_filename)) {
  89. $proc=popen("file -b ".$this->_filename,"r");
  90. $filetype=fread($proc,4096);
  91. pclose($proc);
  92. if (strstr($filetype,"text")==""){
  93. $f=fopen($this->_filename,"r");
  94. $GLOBALS["midcom"]->header("Content-Type: application/octet-stream");
  95. $GLOBALS["midcom"]->header("Content-Length: ".filesize($this->_filename));
  96. fpassthru($f);
  97. exit();
  98. }
  99. }
  100.  
  101.  
  102. $GLOBALS["pl_olga_files_nap_activeid"] = $this->_topic->id;
  103. $GLOBALS['midcom']->set_pagetitle($this->_topic->extra.": ".$this->_path);
  104.  
  105. // initialize layout
  106. /* $substyle = $this->_layout->get_layout_name();
  107. if ($substyle != "default") {
  108. debug_add ("pushing substyle $substyle", MIDCOM_LOG_DEBUG);
  109. $midcom->substyle_append($substyle);
  110. }
  111. */
  112.  
  113. debug_pop();
  114. return true;
  115. }
  116.  
  117. function show() {
  118. debug_push($this->_debug_prefix . "show");
  119. global $view,$argv,$argc;
  120.  
  121. $path=str_replace("//","/",$this->_config->get("root_path")."/".$this->_path);
  122. $view["dir"]=$this->_path;
  123. $view["breadcrumb"]=$this->breadcrumb;
  124.  
  125. if (is_dir($path)) {
  126. midcom_show_style("files-dir-header");
  127. $dir=opendir($path);
  128. while ($fname=readdir($dir)) {
  129. if($fname!="." && $fname!="..") $item[]=$fname;
  130. }
  131. closedir($dir);
  132.  
  133. sort($item);
  134. for ($i=0;$i<sizeof($item);$i++){
  135. if (is_dir("$path/$item[$i]")) {
  136. $view["name"]=$item[$i];
  137. $view["mtime"]=strftime("%d %b %Y",filemtime("$path/$item[$i]"));
  138. midcom_show_style("files-dir-diritem");
  139. } else {
  140. $item1=$item[$i];
  141. $fsize=filesize("$path/$item[$i]")*1;
  142. $fsize=number_format($fsize/1024,2,","," ")." kb";
  143. $view["name"]=$item[$i];
  144. $view["size"]=$fsize;
  145. $view["mtime"]=strftime("%d %b %Y",filemtime("$path/$item[$i]"));
  146. midcom_show_style("files-dir-fileitem");
  147. }
  148. }
  149. midcom_show_style("files-dir-footer");
  150. } elseif (is_file($path)) {
  151. midcom_show_style("files-file-header");
  152. $view["file"]=join("",file($path));
  153. midcom_show_style("files-file-item");
  154. midcom_show_style("files-file-footer");
  155. }
  156. debug_pop();
  157. return true;
  158. }
  159.  
  160.  
  161. function get_metadata() {
  162.  
  163. if ($this->_article) {
  164. return array (
  165. MIDCOM_META_CREATOR => $this->_article->creator,
  166. MIDCOM_META_EDITOR => $this->_article->revisor,
  167. MIDCOM_META_CREATED => $this->_article->created,
  168. MIDCOM_META_EDITED => $this->_article->revised
  169. );
  170. }
  171. else
  172. return false;
  173. }
  174.  
  175. } // viewer
  176.  
  177. ?>

Documentation generated on Mon, 21 Nov 2005 18:22:50 +0100 by phpDocumentor 1.3.0RC3