Created
November 12, 2012 11:07
-
-
Save joachimesque/4058720 to your computer and use it in GitHub Desktop.
adding a more complete image link kirbytext tag by extending the functionalities (requires the thumbs plugin to work)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __construct($text, $markdown=true) { | |
parent::__construct($text, $markdown); | |
// define custom tags | |
$this->addTags('imglink'); | |
$this->addAttributes('legend', 'crop', 'quality', 'rel', 'class', 'size'); | |
} | |
// input tag shoule be : | |
// (imglink: image.jpg size: big class: two columns rel: whatever legend: look at my image) | |
// | |
function imglink($params) { | |
$img = $params['imglink']; | |
// define default values for attributes | |
$defaults = array( | |
'size' => '1', // size ratio of the thumbnail, 1 = small, 2 = med, 3 = big, 4 = original | |
'class' => '', // no class by default | |
'rel' => '', // rel is used for the lightbox gallery linking or whatever | |
'legend' => '', // I could use the image's own description… | |
'text' => $img, // this is the image's name (with extension) | |
'crop' => false, // for the thumbnail generation through $thumb | |
'quality' => 90 // see above | |
); | |
// is this the magic that'll allow me to conjure up the current page? | |
global $site; | |
$page = ($this->obj) ? $this->obj : $site->pages()->active(); | |
// merge the given parameters with the default values | |
$options = array_merge($defaults, $params); | |
$currentImage = $page->images()->find($img); | |
// size options generate a pixel size | |
switch ($options['size']) { | |
case '1': | |
case 'small': | |
$pixel_size = '240'; | |
break; | |
case '2': | |
case 'med': | |
$pixel_size = '480'; | |
break; | |
case '3': | |
case 'big': | |
$pixel_size = '720'; | |
break; | |
case '4': | |
case 'original': | |
default: | |
$pixel_size = '960'; | |
break; | |
} | |
$line = '<a href="' . $currentImage->url() . '" class="lightbox_reactive '. $options['class'] . '" rel="'. $options['rel'] . '" title="'. $options['legend'] .'">'; | |
$line .= '<img src="'; | |
$line .= thumb($currentImage, array( | |
'width' => $pixel_size, | |
'crop' => $options['crop'], | |
'quality' => $options['quality'] | |
), false); | |
$line .= '" class="scale-with-grid" alt="'. $options['legend'] .'" />'; | |
if ($options['legend'] != '') { | |
$line .= '<span class="legend">' . $options['legend'] . '</span>'; | |
} | |
$line .= '</a>'; | |
// build the link tag | |
return $line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment