Created
September 25, 2012 09:07
-
-
Save mrkodssldrf/3780761 to your computer and use it in GitHub Desktop.
Fetch a themeimage by urlsegment for PyroCMS
This file contains hidden or 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
<?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