PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/bx/plugins/gallery/file.php

https://github.com/whiletrue/fluxcms
PHP | 112 lines | 87 code | 22 blank | 3 comment | 23 complexity | 6c21db6f3bfce1df5a769ce9af7ad74c MD5 | raw file
  1. <?php
  2. class bx_plugins_gallery_file {
  3. static function getInstance($dom,$path,$id) {
  4. return new bx_plugins_gallery_file($dom,$path,$id);
  5. }
  6. function __construct ($dom,$path, $id) {
  7. $this->root = $id;
  8. $this->dom = $dom;
  9. }
  10. function getImagesAndAlbums(& $options) {
  11. $dir = new ImageDirectoryIterator($options['root']);
  12. $files = array();
  13. foreach ($dir as $file) {
  14. $f = new StdClass();
  15. $f->name = $file->getFileName();
  16. $f->isDot = $file->isDot();
  17. $f->isDir = $file->isDir();
  18. $f->isReadable = $file->isReadable();
  19. $f->isImage = $file->isImage();
  20. $files[$f->name] = $f;
  21. }
  22. ksort($files);
  23. foreach ($files as $file) {
  24. $name = $file->name;
  25. $lang = $GLOBALS['POOL']->config->getOutputLanguage();
  26. if(!$file->isDot && $file->isReadable && substr($name,0,1) !== ".") {
  27. if ($file->isDir) {
  28. $node = $this->dom->createElement('album');
  29. $node->setAttribute('name', $name);
  30. $node->setAttribute('href', $name.'/');
  31. $prefix = $GLOBALS['POOL']->config->getTablePrefix();
  32. $subgallery = "/".$options['path'].$name."/";
  33. $query = "select * from ".$prefix."properties where path like '".$subgallery."%' and name = 'preview' and value = '1'";
  34. foreach ( $GLOBALS['POOL']->db->queryCol($query) as $pic) {
  35. $pic = str_replace($subgallery,"",$pic);
  36. if (strpos($pic,"/") === false) {
  37. $node->setAttribute("preview",$pic);
  38. }
  39. }
  40. $options['albums']->appendChild($node);
  41. $options['numberOfAlbums']++;
  42. } else if ($file->isImage) {
  43. if(($options['mode']=='image' ) || ($options['numberOfImages'] + 1 > ($options['currentPage'] - 1) * $options['imagesPerPage']) && ($options['numberOfImages'] + 1<= ($options['currentPage']) * $options['imagesPerPage'])) {
  44. $node = $this->dom->createElement('image');
  45. $node->setAttribute('href', $name);
  46. $node->setAttribute('id', $name);
  47. //bx_helpers_debug::webdump($options['path'].$name);
  48. /* this code would allow captions and title in overviews as well... */
  49. $preview = bx_resourcemanager::getProperty("/".$options['path'].$name,"preview",'bx:'.$lang);
  50. //bx_helpers_debug::webdump($preview);
  51. if ($preview) {
  52. $node->appendChild($this->dom->createTextNode(html_entity_decode($preview,ENT_COMPAT,"UTF-8")));
  53. }
  54. if ($options['mode'] != 'image' && $options['descriptionInOverview']) {
  55. $description = bx_resourcemanager::getProperty("/".$options['path'].$name,"description",'bx:'.$lang);
  56. if ($description) {
  57. $node->appendChild($this->dom->createTextNode(html_entity_decode($description,ENT_COMPAT,"UTF-8")));
  58. }
  59. }
  60. if ($options['mode'] != 'image' && $options['titleInOverview']) {
  61. $title = bx_resourcemanager::getProperty("/".$options['path'].$name,"title",'bx:'.$lang);
  62. if ($title) {
  63. $node->setAttribute('imageTitle', html_entity_decode($title,ENT_COMPAT,"UTF-8"));
  64. }
  65. }
  66. if ($name == $options['basename']) {
  67. $title = bx_resourcemanager::getProperty("/".$options['path'].$name,"title",'bx:'.$lang);
  68. $description = bx_resourcemanager::getProperty("/".$options['path'].$name,"description",'bx:'.$lang);
  69. if ($title) {
  70. $title = html_entity_decode($title,ENT_COMPAT,"UTF-8");
  71. $this->dom->documentElement->setAttribute('imageTitle', $title);
  72. }
  73. if ($description) {
  74. $description = html_entity_decode($description,ENT_COMPAT,"UTF-8");
  75. $this->dom->documentElement->setAttribute('imageDescription', $description);
  76. }
  77. $this->dom->documentElement->setAttribute('imageHref', $name);
  78. $this->dom->documentElement->setAttribute('imageId', $name);
  79. $options['numberOfCurrentImage'] = $options['numberOfImages'] + 1 ;
  80. $this->dom->documentElement->setAttribute('numberOfCurrentImage', $options['numberOfCurrentImage']);
  81. }
  82. $options['images']->appendChild($node);
  83. }
  84. $options['numberOfImages']++;
  85. }
  86. }
  87. }
  88. return true;
  89. }
  90. }