Skip to content

Instantly share code, notes, and snippets.

@mrkodssldrf
Created September 25, 2012 09:07
Show Gist options
  • Save mrkodssldrf/3780761 to your computer and use it in GitHub Desktop.
Save mrkodssldrf/3780761 to your computer and use it in GitHub Desktop.
Fetch a themeimage by urlsegment for PyroCMS
<?php
/**
*
* Plugin to fetch a themeimage by urlsegment
*
* usage: {{image:get by="url" default="default" img-type="png"}}
*
* Attributes:
* - (optional) "by" - default: "url"
* - (optional) "default" - default: "default"
* - (optional) "img-type" - default: "png"
*
* @author Mirko Düßeldorf
* @link http://derduesseldorf.de
* @package PyroCMS
* @category Content
* @version 1.0
*/
class Plugin_Image extends Plugin {
public function get() {
$by = $this->attribute('by', 'url');
$default = $this->attribute('default', 'default');
$imageType = $this->attribute('img-type', 'png');
$uri = $this->uri->segment(1);
$image = FCPATH.$this->template->get_theme_path().'img/'.$uri.'.'.$imageType;
$defaultImage = $default.'.'.$imageType;
if(file_exists($image)) {
return '{{theme:image file="'.$image.'"}}';
}
return '{{theme:image file="'.$defaultImage.'"}}';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment