/components/com_rokgallery/lib/RokGallery/Model/SliceFilter.php

https://bitbucket.org/nlabyt/bcf-ball-4eb2 · PHP · 178 lines · 147 code · 25 blank · 6 comment · 13 complexity · 1667f5939f0fbd491c94e279519d3123 MD5 · raw file

  1. <?php
  2. /**
  3. * @version $Id: SliceFilter.php 39525 2011-07-05 18:58:14Z btowles $
  4. * @author RocketTheme http://www.rockettheme.com
  5. * @copyright Copyright (C) 2007 - 2012 RocketTheme, LLC
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  7. */
  8. class RokGallery_Model_SliceFilter extends RokCommon_Doctrine_Filter
  9. {
  10. protected static $slices = array();
  11. protected function getThumbInfo(RokGallery_Model_Slice $record)
  12. {
  13. if (array_key_exists($record->id, RokGallery_Model_SliceFilter::$slices)) {
  14. return RokGallery_Model_SliceFilter::$slices[$record->id];
  15. }
  16. $info = new stdClass();
  17. $info->thumb_xsize = 0;
  18. $info->thumb_ysize = 0;
  19. $info->admin_thumb_xsize = RokGallery_Config::DEFAULT_ADMIN_THUMB_XSIZE;
  20. $info->admin_thumb_ysize = RokGallery_Config::DEFAULT_ADMIN_THUMB_YSIZE;
  21. $info->mini_admin_thumb_xsize = RokGallery_Config::DEFAULT_MINI_ADMIN_THUMB_XSIZE;
  22. $info->mini_admin_thumb_ysize = RokGallery_Config::DEFAULT_MINI_ADMIN_THUMB_YSIZE;
  23. $root = RokGallery_Config::getOption(RokGallery_Config::OPTION_BASE_URL);
  24. $info->image_url = $root . $record->getRelativePath('/');
  25. $info->thumb_path = $this->getThumbPath($record, 'thumb');
  26. $info->thumb_url = $this->getThumbUrl($record, 'thumb');
  27. $this->checkThumbExists($record, $info->thumb_path,'thumb');
  28. $info->admin_thumb_path = $this->getThumbPath($record, 'admin-thumb');
  29. $info->admin_thumb_url = $this->getThumbUrl($record, 'admin-thumb');
  30. if ($this->checkThumbExists($record, $info->admin_thumb_path, 'admin-thumb') && is_file($info->admin_thumb_path)) {
  31. $imageinfo = getimagesize($info->admin_thumb_path);
  32. $info->admin_thumb_xsize = $imageinfo[0];
  33. $info->admin_thumb_ysize = $imageinfo[1];
  34. }
  35. $info->mini_admin_thumb_path = $this->getThumbPath($record, 'mini-admin-thumb');
  36. $info->mini_admin_thumb_url = $this->getThumbUrl($record, 'mini-admin-thumb');
  37. if ($this->checkThumbExists($record, $info->mini_admin_thumb_path, 'mini-admin-thumb') && is_file($info->mini_admin_thumb_path)) {
  38. $imageinfo = getimagesize($info->mini_admin_thumb_path);
  39. $info->mini_admin_thumb_xsize = $imageinfo[0];
  40. $info->mini_admin_thumb_ysize = $imageinfo[1];
  41. }
  42. RokGallery_Model_SliceFilter::$slices[$record->id] = $info;
  43. return RokGallery_Model_SliceFilter::$slices[$record->id];
  44. }
  45. public static function cleanThumbInfo()
  46. {
  47. RokGallery_Model_SliceFilter::$slices = array();
  48. }
  49. protected function getThumbPath(RokGallery_Model_Slice $record, $type)
  50. {
  51. $root = RokGallery_Config::getOption(RokGallery_Config::OPTION_ROOT_PATH);
  52. $path = $root . $record->getRelativeThumbPath(DS, $type);
  53. return $path;
  54. }
  55. protected function getThumbUrl(RokGallery_Model_Slice $record, $type)
  56. {
  57. $root = RokGallery_Config::getOption(RokGallery_Config::OPTION_THUMBNAIL_BASE_URL);
  58. $path = $root . $record->getRelativeThumbPath('/', $type);
  59. return $path;
  60. }
  61. protected function checkThumbExists(RokGallery_Model_Slice $record, $path, $type)
  62. {
  63. $ret = false;
  64. if (!file_exists($path)) {
  65. switch ($type)
  66. {
  67. case 'admin-thumb':
  68. $record->generateAdminThumbnail();
  69. $ret = true;
  70. break;
  71. case 'mini-admin-thumb':
  72. $record->generateMiniAdminThumbnail();
  73. $ret = true;
  74. break;
  75. case 'thumb':
  76. $record->generateDefaultThumbnail();
  77. $record->save();
  78. $ret = true;
  79. break;
  80. default:
  81. $ret = false;
  82. }
  83. }
  84. else if ($record->thumb_xsize == 0 && $record->thumb_ysize == 0)
  85. {
  86. $record->generateDefaultThumbnail();
  87. $record->save();
  88. }
  89. else {
  90. $ret = true;
  91. }
  92. return $ret;
  93. }
  94. protected function _getThumbPath(RokGallery_Model_Slice $record)
  95. {
  96. $info = $this->getThumbInfo($record);
  97. return $info->thumb_path;
  98. }
  99. protected function _getThumbUrl(RokGallery_Model_Slice $record)
  100. {
  101. $info = $this->getThumbInfo($record);
  102. return $info->thumb_url;
  103. }
  104. protected function _getAdminThumbPath(RokGallery_Model_Slice $record)
  105. {
  106. $info = $this->getThumbInfo($record);
  107. return $info->admin_thumb_path;
  108. }
  109. protected function _getAdminThumbUrl(RokGallery_Model_Slice $record)
  110. {
  111. $info = $this->getThumbInfo($record);
  112. return $info->admin_thumb_url;
  113. }
  114. protected function _getMiniAdminThumbPath(RokGallery_Model_Slice $record)
  115. {
  116. $info = $this->getThumbInfo($record);
  117. return $info->mini_admin_thumb_path;
  118. }
  119. protected function _getMiniAdminThumbUrl(RokGallery_Model_Slice $record)
  120. {
  121. $info = $this->getThumbInfo($record);
  122. return $info->mini_admin_thumb_url;
  123. }
  124. protected function _getImageUrl($record)
  125. {
  126. $info = $this->getThumbInfo($record);
  127. return $info->image_url;
  128. }
  129. protected function _getAdminThumbXSize(RokGallery_Model_Slice $record)
  130. {
  131. $info = $this->getThumbInfo($record);
  132. return $info->admin_thumb_xsize;
  133. }
  134. protected function _getAdminThumbYSize(RokGallery_Model_Slice $record)
  135. {
  136. $info = $this->getThumbInfo($record);
  137. return $info->admin_thumb_ysize;
  138. }
  139. protected function _getMiniAdminThumbXSize(RokGallery_Model_Slice $record)
  140. {
  141. $info = $this->getThumbInfo($record);
  142. return $info->mini_admin_thumb_xsize;
  143. }
  144. protected function _getMiniAdminThumbYSize(RokGallery_Model_Slice $record)
  145. {
  146. $info = $this->getThumbInfo($record);
  147. return $info->mini_admin_thumb_ysize;
  148. }
  149. protected function _getDoILove($record)
  150. {
  151. return RokCommon_Session::get('rokgallery.site.loves.file_' . $record->file_id, false);
  152. }
  153. }