class.imgmanager.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. require_once dirname(__FILE__).'/class.filemanager.php';
  23. class imgmanager extends filemanager
  24. {
  25. var $p_url;
  26. var $img_url;
  27. function imgmanager($root_path,$base_path,$img_url,$p_url)
  28. {
  29. parent::filemanager($root_path,$base_path);
  30. $this->p_url = $p_url;
  31. $this->img_url = $img_url;
  32. }
  33. function getNavBar($link='<a href="%1$s">%2$s</a>')
  34. {
  35. $f = '';
  36. $res = '&#187; '.sprintf($link,$this->p_url,__('images'));
  37. if (file_exists($this->root.$this->base_path))
  38. {
  39. $r = explode('/',$this->base_path);
  40. for ($i=1; $i<count($r); $i++) {
  41. $f .= '/'.$r[$i];
  42. $res .= '/'.sprintf($link,$this->p_url.'?p='.$f,$r[$i]);
  43. }
  44. }
  45. return $res;
  46. }
  47. function listDir($k,$v,$link='<a href="%1$s">%2$s</a>')
  48. {
  49. if ($v['d'] && $v['jail'] && $v['r'] && $v['x'] && $k != '.' && $k != '..') {
  50. return sprintf($link,$this->p_url.'?p='.$v['l'],$k);
  51. }
  52. }
  53. function listImg($k,$v,$link='<a href="%1$s"><img src="%1$s" alt="%2$s" /></a>')
  54. {
  55. $type = $this->__getType($this->root.'/'.$this->base_path.'/'.$k);
  56. $url = $this->__cleanPath($this->img_url.'/'.$this->base_path.'/'.$k);
  57. if ($type == 'img' && $v['jail'] && $v['r']) {
  58. return sprintf($link,$url,$k,$this->getThumb($k),addslashes($url));
  59. }
  60. }
  61. function getThumb($k=NULL,$absolute=false)
  62. {
  63. if ($k === NULL) {
  64. $img = $this->base_path;
  65. } else {
  66. $img = $this->base_path.'/'.$k;
  67. }
  68. $root = !$absolute ? $this->img_url : $this->root;
  69. $tn = $this->root.'/'.preg_replace('/^(.*)([.]\\w+)$/','$1.TN__$2',$img);
  70. if (file_exists($tn)) {
  71. return $this->__cleanPath($root.'/'.dirname($img).'/'.basename($tn));
  72. } else {
  73. return false;
  74. }
  75. }
  76. function isImg()
  77. {
  78. if ($this->getImgType() === false) {
  79. return false;
  80. }
  81. return true;
  82. }
  83. function getImgType()
  84. {
  85. return images::type($this->root.$this->base_path);
  86. }
  87. }
  88. ?>