PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/concrete/core/controllers/blocks/image.php

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