PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/concreteOLD/blocks/image/controller.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 139 lines | 118 code | 18 blank | 3 comment | 31 complexity | 5c567ed66d943cdd3c05cbc87094d7b6 MD5 | raw file
  1. <?php
  2. Loader::block('library_file');
  3. defined('C5_EXECUTE') or die("Access Denied.");
  4. class ImageBlockController extends BlockController {
  5. protected $btInterfaceWidth = 400;
  6. protected $btInterfaceHeight = 550;
  7. protected $btTable = 'btContentImage';
  8. protected $btCacheBlockRecord = true;
  9. protected $btCacheBlockOutput = true;
  10. protected $btCacheBlockOutputOnPost = true;
  11. protected $btCacheBlockOutputForRegisteredUsers = true;
  12. protected $btWrapperClass = 'ccm-ui';
  13. protected $btExportFileColumns = array('fID','fOnstateID');
  14. /**
  15. * Used for localization. If we want to localize the name/description we have to include this
  16. */
  17. public function getBlockTypeDescription() {
  18. return t("Adds images and onstates from the library to pages.");
  19. }
  20. public function getBlockTypeName() {
  21. return t("Image");
  22. }
  23. public function getJavaScriptStrings() {
  24. return array(
  25. 'image-required' => t('You must select an image.')
  26. );
  27. }
  28. function getFileID() {return $this->fID;}
  29. function getFileOnstateID() {return $this->fOnstateID;}
  30. function getFileOnstateObject() {
  31. if ($this->fOnstateID > 0) {
  32. return File::getByID($this->fOnstateID);
  33. }
  34. }
  35. function getFileObject() {
  36. return File::getByID($this->fID);
  37. }
  38. function getAltText() {return $this->altText;}
  39. function getExternalLink() {return $this->externalLink;}
  40. function getInternalLinkCID() {return $this->internalLinkCID;}
  41. function getLinkURL() {
  42. if (!empty($this->externalLink)) {
  43. return $this->externalLink;
  44. } else if (!empty($this->internalLinkCID)) {
  45. $linkToC = Page::getByID($this->internalLinkCID);
  46. return (empty($linkToC) || $linkToC->error) ? '' : Loader::helper('navigation')->getLinkToCollection($linkToC);
  47. } else {
  48. return '';
  49. }
  50. }
  51. public function save($args) {
  52. $args['fOnstateID'] = ($args['fOnstateID'] != '') ? $args['fOnstateID'] : 0;
  53. $args['fID'] = ($args['fID'] != '') ? $args['fID'] : 0;
  54. $args['maxWidth'] = (intval($args['maxWidth']) > 0) ? intval($args['maxWidth']) : 0;
  55. $args['maxHeight'] = (intval($args['maxHeight']) > 0) ? intval($args['maxHeight']) : 0;
  56. switch (intval($args['linkType'])) {
  57. case 1:
  58. $args['externalLink'] = '';
  59. break;
  60. case 2:
  61. $args['internalLinkCID'] = 0;
  62. break;
  63. default:
  64. $args['externalLink'] = '';
  65. $args['internalLinkCID'] = 0;
  66. break;
  67. }
  68. unset($args['linkType']); //this doesn't get saved to the database (it's only for UI usage)
  69. parent::save($args);
  70. }
  71. function getContentAndGenerate($align = false, $style = false, $id = null) {
  72. $c = Page::getCurrentPage();
  73. $bID = $this->bID;
  74. $f = $this->getFileObject();
  75. $fullPath = $f->getPath();
  76. $relPath = $f->getRelativePath();
  77. $size = @getimagesize($fullPath);
  78. if (empty($size)) {
  79. echo t( 'Image Not Found. ');
  80. return '';
  81. }
  82. if ($this->maxWidth == $size[0] && $this->maxHeight == $size[1]) {
  83. $sizeStr = $size[3];
  84. } else if (!$this->forceImageToMatchDimensions && ($this->maxWidth > 0 || $this->maxHeight > 0)) {
  85. $mw = $this->maxWidth > 0 ? $this->maxWidth : $size[0];
  86. $mh = $this->maxHeight > 0 ? $this->maxHeight : $size[1];
  87. $ih = Loader::helper('image');
  88. $thumb = $ih->getThumbnail($f, $mw, $mh);
  89. $sizeStr = ' width="' . $thumb->width . '" height="' . $thumb->height . '"';
  90. $relPath = $thumb->src;
  91. } else {
  92. $sizeStr = $size[3];
  93. }
  94. $img = "<img border=\"0\" class=\"ccm-image-block\" alt=\"{$this->altText}\" src=\"{$relPath}\" {$sizeStr} ";
  95. $img .= ($align) ? "align=\"{$align}\" " : '';
  96. $img .= ($style) ? "style=\"{$style}\" " : '';
  97. if($this->fOnstateID != 0) {
  98. $fos = $this->getFileOnstateObject();
  99. $fullPathOnstate = $f->getPath();
  100. $sizehover = @getimagesize($fullPathOnstate);
  101. if ($this->maxWidth == $sizehover[0] && $this->maxHeight == $sizehover[1]) {
  102. $relPathHover = $fos->getRelativePath();
  103. } else if (!$this->forceImageToMatchDimensions && ($this->maxWidth > 0 || $this->maxHeight > 0)) {
  104. $thumbHover = $ih->getThumbnail($fos, $mw, $mh);
  105. $relPathHover = $thumbHover->src;
  106. } else {
  107. $relPathHover = $fos->getRelativePath();
  108. }
  109. $img .= " onmouseover=\"this.src = '{$relPathHover}'\" ";
  110. $img .= " onmouseout=\"this.src = '{$relPath}'\" ";
  111. }
  112. $img .= ($id) ? "id=\"{$id}\" " : "";
  113. $img .= "/>";
  114. $linkURL = $this->getLinkURL();
  115. if (!empty($linkURL)) {
  116. $img = "<a href=\"{$linkURL}\">" . $img ."</a>";
  117. }
  118. return $img;
  119. }
  120. }
  121. ?>