[5550] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /* ----------------------------------------------------------------------------- |
---|
| 4 | class name: GPCCss |
---|
[10246] | 5 | class version : 3.1.0 |
---|
| 6 | plugin version : 3.5.0 |
---|
| 7 | date : 2011-01-31 |
---|
[5550] | 8 | |
---|
| 9 | ------------------------------------------------------------------------------ |
---|
| 10 | Author : Grum |
---|
| 11 | email : grum@piwigo.org |
---|
| 12 | website : http://photos.grum.fr |
---|
| 13 | PWG user : http://forum.phpwebgallery.net/profile.php?id=3706 |
---|
| 14 | |
---|
| 15 | << May the Little SpaceFrog be with you ! >> |
---|
| 16 | ------------------------------------------------------------------------------ |
---|
| 17 | |
---|
| 18 | :: HISTORY |
---|
| 19 | |
---|
| 20 | | release | date | |
---|
| 21 | | 3.0.0 | 2010/03/30 | * Update class & function names |
---|
| 22 | | | | |
---|
[10246] | 23 | | 3.1.0 | 2011/01/31 | * Updated for piwigo 2.2 |
---|
[5550] | 24 | | | | |
---|
| 25 | | | | |
---|
| 26 | | | | |
---|
| 27 | | | | |
---|
| 28 | |
---|
| 29 | ------------------------------------------------------------------------------ |
---|
| 30 | |
---|
| 31 | this classes provides base functions to manage css |
---|
| 32 | classe consider that $filename is under plugins/ directory |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | - constructor Css($filename) |
---|
| 36 | - (public) function fileExists() |
---|
| 37 | - (public) function makeCSS($css) |
---|
| 38 | - (public) function applyCSS() |
---|
| 39 | ---------------------------------------------------------------------- */ |
---|
| 40 | class GPCCss |
---|
| 41 | { |
---|
| 42 | private $filename; |
---|
| 43 | |
---|
[5958] | 44 | static public function applyGpcCss() |
---|
| 45 | { |
---|
| 46 | add_event_handler('loc_end_page_header', array('GPCCss', 'applyCSSFile')); |
---|
| 47 | } |
---|
| 48 | |
---|
[15340] | 49 | static public function applyCSSFile($fileName="", $dependencies=array()) |
---|
[5958] | 50 | { |
---|
| 51 | global $template; |
---|
| 52 | |
---|
| 53 | if($fileName=="") |
---|
| 54 | { |
---|
| 55 | //if no filename given, load the gpc.css file |
---|
[10252] | 56 | $fileName='./plugins/'.basename(dirname(dirname(__FILE__))).'/css/gpc'; |
---|
| 57 | GPCCore::addHeaderCSS('gpc', $fileName.'.css'); |
---|
| 58 | GPCCore::addHeaderCSS('gpc_theme', $fileName.'_'.$template->get_themeconf('name').'.css'); |
---|
[5958] | 59 | } |
---|
| 60 | elseif(file_exists($fileName)) |
---|
| 61 | { |
---|
[15340] | 62 | GPCCore::addHeaderCSS(basename(dirname($fileName)), 'plugins/'.basename(dirname($fileName)).'/'.basename($fileName).'', array_merge(array('gpc', 'gpc_theme'),$dependencies) ); |
---|
[5958] | 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
[5550] | 66 | public function __construct($filename) |
---|
| 67 | { |
---|
| 68 | $this->filename=$filename; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public function __destruct() |
---|
| 72 | { |
---|
| 73 | unset($this->filename); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /* |
---|
| 77 | make the css file |
---|
| 78 | */ |
---|
| 79 | public function makeCSS($css) |
---|
| 80 | { |
---|
| 81 | if($css!="") |
---|
| 82 | { |
---|
| 83 | $handle=fopen($this->filename, "w"); |
---|
| 84 | if($handle) |
---|
| 85 | { |
---|
| 86 | fwrite($handle, $css); |
---|
| 87 | fclose($handle); |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /* |
---|
| 93 | return true if css file exists |
---|
| 94 | */ |
---|
| 95 | public function fileExists() |
---|
| 96 | { |
---|
| 97 | return(file_exists($this->filename)); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | /* |
---|
| 101 | put a link in the template to load the css file |
---|
| 102 | this function have to be called in a 'loc_end_page_header' trigger |
---|
| 103 | |
---|
| 104 | if $text="", insert link to css file, otherwise insert directly a <style> markup |
---|
| 105 | */ |
---|
| 106 | public function applyCSS() |
---|
| 107 | { |
---|
| 108 | global $template; |
---|
| 109 | |
---|
[5958] | 110 | GPCCss::applyCSSFile($this->filename); |
---|
[5550] | 111 | } |
---|
[5958] | 112 | |
---|
| 113 | |
---|
[5550] | 114 | } //class |
---|
| 115 | |
---|
| 116 | ?> |
---|