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