author | Dan |
Sat, 16 May 2009 09:57:00 -0400 | |
changeset 3 | f0a844799a0c |
parent 2 | 178d22e361d6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/**!info** |
|
3 |
{ |
|
4 |
"Plugin Name" : "Enanium backgrounds", |
|
5 |
"Plugin URI" : "http://enanocms.org/plugin/enaniumbg", |
|
6 |
"Description" : "Provides several additional background images for Enanium.", |
|
7 |
"Author" : "Dan Fuhry", |
|
8 |
"Version" : "1.1.6", |
|
9 |
"Author URI" : "http://enanocms.org/" |
|
10 |
} |
|
11 |
**!*/ |
|
12 |
||
13 |
// $plugins->attachHook('enanium_search_form', 'enanium_paint_bg_controls();'); |
|
14 |
$plugins->attachHook('enanium_main_header', 'enanium_paint_bg_controls();'); |
|
15 |
$plugins->attachHook('compile_template', 'enanium_add_headers();'); |
|
1 | 16 |
$plugins->attachHook('acl_rule_init', '$this->addAdminNode("adm_cat_appearance", "enaniumbg_acppage", "EnaniumConfig", scriptPath . "/plugins/enaniumbg/icons/garden.png");'); |
0 | 17 |
|
2
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
18 |
$ebg_system_images = array('default', 'aqua', 'blinds', 'dune', 'freshflower', 'garden', 'greenmeadow', 'ladybird', 'raindrops', 'storm', 'twowings', 'wood', 'yellowflower'); |
3 | 19 |
$ebg_images = array('default'); |
0 | 20 |
|
21 |
$ebg_outsiders = array(); |
|
22 |
if ( $dr = @opendir(ENANO_ROOT . '/plugins/enaniumbg') ) |
|
23 |
{ |
|
24 |
while ( $dh = @readdir($dr) ) |
|
25 |
{ |
|
1 | 26 |
if ( $dh == '.' || $dh == '..' || is_dir(ENANO_ROOT . "/plugins/enaniumbg/$dh") ) |
0 | 27 |
continue; |
28 |
||
1 | 29 |
if ( !preg_match('/\.jpg$/', $dh) ) |
0 | 30 |
continue; |
31 |
||
32 |
$dh = preg_replace('/\.jpg$/', '', $dh); |
|
33 |
||
2
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
34 |
if ( in_array($dh, $ebg_system_images) ) |
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
35 |
{ |
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
36 |
$ebg_images[] = $dh; |
1 | 37 |
continue; |
2
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
38 |
} |
1 | 39 |
|
0 | 40 |
if ( !file_exists(ENANO_ROOT . "/plugins/enaniumbg/icons/$dh.png") ) |
41 |
continue; |
|
42 |
||
43 |
$ebg_outsiders[] = $dh; |
|
44 |
} |
|
45 |
closedir($dr); |
|
46 |
} |
|
47 |
unset($dh, $dr); |
|
48 |
||
49 |
function enanium_paint_bg_controls() |
|
50 |
{ |
|
2
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
51 |
global $ebg_system_images, $ebg_images, $ebg_outsiders; |
0 | 52 |
global $lang; |
53 |
||
1 | 54 |
if ( !getConfig('enanium_show_switcher', 1) ) |
55 |
return; |
|
56 |
||
0 | 57 |
?> |
58 |
<div id="enanium_bg_list"> |
|
59 |
<?php |
|
2
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
60 |
foreach ( $ebg_system_images as $i => $image ) |
0 | 61 |
{ |
2
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
62 |
if ( !in_array($image, $ebg_images) ) |
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
63 |
continue; |
178d22e361d6
Now skips any of the included/localized backgrounds if they don't exist.
Dan
parents:
1
diff
changeset
|
64 |
|
1 | 65 |
$sel = ( $image == getConfig('enanium_bg', 'default') ) ? ' class="selected"' : ''; |
0 | 66 |
echo '<a' . $sel . ' href="#bg:' . $image . '" id="ebg_' . $image . '" onclick="enanium_change_bg(\'' . $image . '\', this); return false;" title="' . $lang->get('enaniumbg_' . $image) . '">'; |
67 |
echo enanium_generate_sprite(scriptPath . '/plugins/enaniumbg/icons/sprite.png', 16, 16, 0, $i * 16); |
|
68 |
echo '</a>'; |
|
69 |
} |
|
1 | 70 |
foreach ( $ebg_outsiders as $image ) |
71 |
{ |
|
72 |
$sel = ( $image == getConfig('enanium_bg', 'default') ) ? ' class="selected"' : ''; |
|
73 |
echo '<a' . $sel . ' href="#bg:' . $image . '" id="ebg_' . $image . '" onclick="enanium_change_bg(\'' . $image . '\', this); return false;" title="' . htmlspecialchars(ucwords(str_replace('_', ' ', $image))) . '">'; |
|
74 |
echo '<img alt=" " src="' . scriptPath . '/plugins/enaniumbg/icons/' . $image . '.png" />'; |
|
75 |
echo '</a>'; |
|
76 |
} |
|
0 | 77 |
?> |
78 |
</div> |
|
79 |
<?php |
|
80 |
} |
|
81 |
||
82 |
function enanium_add_headers() |
|
83 |
{ |
|
84 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
1 | 85 |
global $ebg_images, $ebg_outsiders; |
0 | 86 |
global $lang; |
87 |
||
88 |
if ( $template->theme != 'enanium' ) |
|
89 |
return; |
|
90 |
||
1 | 91 |
$repeat = getConfig('enanium_background_repeat', 'no-repeat'); |
92 |
$attachment = getConfig('enanium_background_attachment', 'fixed'); |
|
93 |
$position = getConfig('enanium_background_position', 'center top'); |
|
94 |
||
95 |
if ( getConfig('enanium_show_switcher', 1) ) |
|
96 |
{ |
|
97 |
$template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/enaniumbg/enaniumbg.css" />'); |
|
98 |
||
99 |
$addheader = <<<EOF |
|
100 |
<script type="text/javascript"> |
|
101 |
var enanium_bg_repeat = '$repeat'; |
|
102 |
var enanium_bg_attachment = '$attachment'; |
|
103 |
var enanium_bg_position = '$position'; |
|
104 |
</script> |
|
105 |
EOF; |
|
106 |
$template->add_header($addheader); |
|
107 |
$template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/enaniumbg/enaniumbg.js"></script>'); |
|
108 |
} |
|
109 |
||
110 |
if ( ($img = getConfig('enanium_bg', 'default')) !== 'default' ) |
|
111 |
{ |
|
112 |
if ( !file_exists(ENANO_ROOT . "/plugins/enaniumbg/$img.jpg") ) |
|
113 |
return; |
|
114 |
||
115 |
$scriptpath = scriptPath; |
|
116 |
$addheader = <<<EOF |
|
117 |
<style type="text/css"> |
|
118 |
body { |
|
119 |
background-image: url({$scriptpath}/plugins/enaniumbg/{$img}.jpg); |
|
120 |
background-color: #000000; |
|
121 |
background-repeat: $repeat; |
|
122 |
background-attachment: $attachment; |
|
123 |
background-position: $position; |
|
124 |
} |
|
125 |
td#cell-content { |
|
126 |
background-color: transparent; |
|
127 |
background-image: url({$scriptpath}/plugins/enaniumbg/transw70.png); |
|
128 |
} |
|
129 |
</style> |
|
130 |
EOF; |
|
131 |
$template->add_header($addheader); |
|
132 |
} |
|
0 | 133 |
} |
134 |
||
135 |
function enanium_generate_sprite($sprite, $width, $height, $start_x, $start_y) |
|
136 |
{ |
|
137 |
$start_x = 0 - $start_x; |
|
138 |
$start_y = 0 - $start_y; |
|
139 |
return '<img alt=" " src="' . cdnPath . '/images/spacer.gif" width="' . $width . '" height="' . $height . '" style="background-image: url(\'' . $sprite . '\'); background-repeat: no-repeat; background-position: ' . $start_x . 'px ' . $start_y . 'px;" />'; |
|
140 |
} |
|
141 |
||
1 | 142 |
function page_Admin_EnaniumConfig() |
143 |
{ |
|
144 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
145 |
global $lang; |
|
146 |
||
147 |
if ( isset($_POST['enanium_bg']) ) |
|
148 |
{ |
|
149 |
$bg = $_POST['enanium_bg']; |
|
3 | 150 |
if ( file_exists(ENANO_ROOT . "/plugins/enaniumbg/$bg.jpg") || $bg === 'default' ) |
1 | 151 |
setConfig('enanium_bg', $bg); |
152 |
||
153 |
$val = isset($_POST['show_switcher']) ? '1' : '0'; |
|
154 |
setConfig('enanium_show_switcher', $val); |
|
155 |
||
156 |
setConfig('enanium_background_repeat', $_POST['background_repeat']); |
|
157 |
setConfig('enanium_background_attachment', $_POST['background_attachment']); |
|
158 |
setConfig('enanium_background_position', $_POST['background_position']); |
|
159 |
||
160 |
echo '<div class="info-box">' . $lang->get('enaniumbg_acp_msg_changes_saved') . '</div>'; |
|
161 |
} |
|
162 |
||
163 |
acp_start_form(); |
|
164 |
?> |
|
165 |
<div class="tblholder"> |
|
166 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
167 |
<tr> |
|
168 |
<th colspan="2"><?php echo $lang->get('enaniumbg_acp_th'); ?></th> |
|
169 |
</tr> |
|
170 |
<tr> |
|
171 |
<td class="row2" style="width: 50%;"> |
|
172 |
<?php echo $lang->get('enaniumbg_acp_field_default_bg'); ?><br /> |
|
173 |
<small><?php echo $lang->get('enaniumbg_acp_field_default_bg_hint'); ?></small> |
|
174 |
</td> |
|
175 |
<td class="row1" style="width: 50%;"> |
|
176 |
<select name="enanium_bg"> |
|
177 |
<?php |
|
178 |
global $ebg_images, $ebg_outsiders; |
|
179 |
if ( !empty($ebg_outsiders) ) |
|
180 |
{ |
|
181 |
foreach ( $ebg_outsiders as $image ) |
|
182 |
{ |
|
183 |
$sel = $image == getConfig('enanium_bg', 'default') ? 'selected="selected" ' : ''; |
|
184 |
echo '<option ' . $sel . 'value="' . $image . '">' . ucwords(str_replace('_', ' ', $image)) . '</option>'; |
|
185 |
} |
|
186 |
echo '<option disabled="disabled" value="">--------------------</option>'; |
|
187 |
} |
|
188 |
foreach ( $ebg_images as $image ) |
|
189 |
{ |
|
190 |
$sel = $image == getConfig('enanium_bg', 'default') ? 'selected="selected" ' : ''; |
|
191 |
echo '<option ' . $sel . 'value="' . $image . '">' . $lang->get("enaniumbg_$image") . '</option>'; |
|
192 |
} |
|
193 |
?> |
|
194 |
</select> |
|
195 |
</td> |
|
196 |
</tr> |
|
197 |
<tr> |
|
198 |
<td class="row2"> |
|
199 |
<label for="ebg_chk_show_switcher"><?php echo $lang->get('enaniumbg_acp_field_show_switcher'); ?></label><br /> |
|
200 |
<small><?php echo $lang->get('enaniumbg_acp_field_show_switcher_hint'); ?></small> |
|
201 |
</td> |
|
202 |
<td class="row1"> |
|
203 |
<input id="ebg_chk_show_switcher" type="checkbox" name="show_switcher" <?php echo getConfig('enanium_show_switcher', 1) == '1' ? 'checked="checked" ' : ''; ?>/> |
|
204 |
</td> |
|
205 |
</tr> |
|
206 |
<tr> |
|
207 |
<td class="row2"> |
|
208 |
<?php echo $lang->get('enaniumbg_acp_field_tile'); ?><br /> |
|
209 |
<small><?php echo $lang->get('enaniumbg_acp_field_tile_hint'); ?></small> |
|
210 |
</td> |
|
211 |
<td class="row1"> |
|
212 |
<label> |
|
213 |
<input type="radio" name="background_repeat" value="repeat" <?php echo getConfig('enanium_background_repeat', 'no-repeat') == 'repeat' ? 'checked="checked" ' : ''; ?>/> |
|
214 |
<?php echo $lang->get('enaniumbg_acp_field_tile_tile'); ?> |
|
215 |
</label><br /> |
|
216 |
<label> |
|
217 |
<input type="radio" name="background_repeat" value="no-repeat" <?php echo getConfig('enanium_background_repeat', 'no-repeat') == 'no-repeat' ? 'checked="checked" ' : ''; ?>/> |
|
218 |
<?php echo $lang->get('enaniumbg_acp_field_tile_norepeat'); ?> |
|
219 |
</label> |
|
220 |
</td> |
|
221 |
</tr> |
|
222 |
<tr> |
|
223 |
<td class="row2"> |
|
224 |
<?php echo $lang->get('enaniumbg_acp_field_scroll'); ?><br /> |
|
225 |
<small><?php echo $lang->get('enaniumbg_acp_field_scroll_hint'); ?></small> |
|
226 |
</td> |
|
227 |
<td class="row1"> |
|
228 |
<label> |
|
229 |
<input type="radio" name="background_attachment" value="fixed" <?php echo getConfig('enanium_background_attachment', 'fixed') == 'fixed' ? 'checked="checked" ' : ''; ?>/> |
|
230 |
<?php echo $lang->get('enaniumbg_acp_field_scroll_fixed'); ?> |
|
231 |
</label><br /> |
|
232 |
<label> |
|
233 |
<input type="radio" name="background_attachment" value="scroll" <?php echo getConfig('enanium_background_attachment', 'fixed') == 'scroll' ? 'checked="checked" ' : ''; ?>/> |
|
234 |
<?php echo $lang->get('enaniumbg_acp_field_scroll_scroll'); ?> |
|
235 |
</label> |
|
236 |
</td> |
|
237 |
</tr> |
|
238 |
<tr> |
|
239 |
<td class="row2"> |
|
240 |
<?php echo $lang->get('enaniumbg_acp_field_anchor'); ?> |
|
241 |
</td> |
|
242 |
<td class="row1"> |
|
243 |
<table border="0" style="background-color: transparent; width: 120px; padding: 5px; border: 1px solid #404040;"> |
|
244 |
<?php |
|
245 |
foreach ( array('top', 'center', 'bottom') as $ypos ) |
|
246 |
{ |
|
247 |
echo '<tr>'; |
|
248 |
foreach ( array('left', 'center', 'right') as $xpos ) |
|
249 |
{ |
|
250 |
?><td style="width: 40px; line-height: 30px; text-align: center;"><input type="radio" name="background_position" value="<?php echo "$xpos $ypos"; ?>" <?php echo getConfig('enanium_background_position', 'center top') == "$xpos $ypos" ? 'checked="checked" ' : ''; ?>/><?php |
|
251 |
} |
|
252 |
echo '</tr>'; |
|
253 |
} |
|
254 |
?> |
|
255 |
</table> |
|
256 |
</td> |
|
257 |
</tr> |
|
258 |
<tr> |
|
259 |
<th class="subhead" colspan="2"> |
|
260 |
<input type="submit" value="<?php echo $lang->get('etc_save_changes'); ?>" /> |
|
261 |
</th> |
|
262 |
</tr> |
|
263 |
</table> |
|
264 |
</div> |
|
265 |
</form> |
|
266 |
<?php |
|
267 |
} |
|
268 |
||
0 | 269 |
/**!language** |
270 |
<code> |
|
271 |
{ |
|
272 |
eng: { |
|
273 |
categories: ['meta', 'enaniumbg'], |
|
274 |
strings: { |
|
275 |
meta: { |
|
276 |
enaniumbg: 'Enanium backgrounds', |
|
277 |
}, |
|
278 |
enaniumbg: { |
|
279 |
default: 'Default', |
|
280 |
aqua: 'Aqua', |
|
281 |
blinds: 'Blinds', |
|
282 |
dune: 'Dune', |
|
283 |
freshflower: 'Fresh flower', |
|
284 |
garden: 'Garden', |
|
285 |
greenmeadow: 'Greenmeadow', |
|
286 |
ladybird: 'Ladybird', |
|
287 |
raindrops: 'Raindrops', |
|
288 |
storm: 'Storm', |
|
289 |
twowings: 'Two Wings', |
|
290 |
wood: 'Wood', |
|
1 | 291 |
yellowflower: 'Yellow flower', |
292 |
||
293 |
acp_th: 'Enanium background configuration', |
|
294 |
acp_field_default_bg: 'Default background:', |
|
295 |
acp_field_default_bg_hint: '<b>Tip:</b> You can add more backgrounds to Enanium! Upload a JPEG image to plugins/enaniumbg/. Then, upload a 16x16 icon of the image, with the same filename, to plugins/enaniumbg/icons/. The plugin will automatically add the image to the list here and to the switcher, if enabled.', |
|
296 |
acp_field_show_switcher: 'Show background switcher:', |
|
297 |
acp_field_show_switcher_hint: 'If the switcher is turned off, the background selected above will always be used.', |
|
298 |
||
299 |
acp_field_tile: 'Allow background to be tiled:', |
|
300 |
acp_field_tile_hint: 'If this is off, the background will be letterboxed and/or pillarboxed if the screen is too small.', |
|
301 |
acp_field_tile_tile: 'Tile', |
|
302 |
acp_field_tile_norepeat: 'Don\'t tile', |
|
303 |
||
304 |
acp_field_scroll: 'Scroll background image with page:', |
|
305 |
acp_field_scroll_hint: 'This may produce undesired results if "%this.enaniumbg_acp_field_tile_norepeat%" is selected.', |
|
306 |
acp_field_scroll_fixed: 'Background fixed and always in view', |
|
307 |
acp_field_scroll_scroll: 'Scroll background', |
|
308 |
||
309 |
acp_field_anchor: 'Background position anchor:', |
|
310 |
||
311 |
acp_msg_changes_saved: 'Your changes have been saved.', |
|
312 |
acppage: 'Enanium configuration', |
|
0 | 313 |
} |
314 |
} |
|
315 |
} |
|
316 |
} |
|
317 |
</code> |
|
318 |
**!*/ |
|
319 |