Hi,
I have the following problem: I need
a) because of the quite high load of my blog, the simplecache-plugin.
b) as my design requires real css support (==no IE), a browser-check.
I don't want to do this with javascript, as I don't like that solution and it's probably not possible to catch all cases of user_agent-forging with it.
I tried adding some code to config.inc.php in the template (see below), but it seems this isn't executed on cached pages (or I did something wrong?). Where can I add php-code that is executed every time to set the caching-vars? (or is there already a solution for this like a plugin?)
This was my code:
if (stristr($_SERVER['HTTP_USER_AGENT'],'MSIE')
&& !stristr($_SERVER['HTTP_USER_AGENT'],'Opera')
&& !stristr($_SERVER['HTTP_USER_AGENT'],'Mac_PowerPC')
&& !stristr($_SERVER['HTTP_ACCEPT'],'text/html'))
{
$serendipity['smarty']->assign('ie', true);
$cache_options['browser']='ie';
}
else
{
$cache_options['browser']='other';
}
How to create a browser check with the simplecache-plugin
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: How to create a browser check with the simplecache-plugi
Why don't you put that PHP code snippet into the simplecache plugin itself? Maybe patch up the file so that you have a config option whether to use the browser as cache option distinction, so we can include it in the official plugin?
Best regards,
Garvin
Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Ah, I thought you were quite skilled. Sorry then for the hassle.
I just committed version 0.7 of the plugin where you can configure that the browser is parsed as a cache lite option.
You still need this config.inc.php though:
to get the smarty code.
Here's the diff for the simplecache plugin:
Have fun,
Garvin
I just committed version 0.7 of the plugin where you can configure that the browser is parsed as a cache lite option.
You still need this config.inc.php though:
Code: Select all
<?php
if (stristr($_SERVER['HTTP_USER_AGENT'],'MSIE')
&& !stristr($_SERVER['HTTP_USER_AGENT'],'Opera')
&& !stristr($_SERVER['HTTP_USER_AGENT'],'Mac_PowerPC')
&& !stristr($_SERVER['HTTP_ACCEPT'],'text/html'))
{
$serendipity['smarty']->assign('ie', true);
}
?>
Here's the diff for the simplecache plugin:
Code: Select all
Index: serendipity_event_cachesimple.php
===================================================================
RCS file: /cvsroot/php-blog/additional_plugins/serendipity_event_cachesimple/serendipity_event_cachesimple.php,v
retrieving revision 1.21
diff -u -r1.21 serendipity_event_cachesimple.php
--- serendipity_event_cachesimple.php 17 Oct 2005 12:39:16 -0000 1.21
+++ serendipity_event_cachesimple.php 9 Nov 2005 19:55:01 -0000
@@ -32,6 +32,7 @@
@define('PLUGIN_EVENT_CACHESIMPLE_NAME', 'Simple Cached/Pregenerated Pages');
@define('PLUGIN_EVENT_CACHESIMPLE_DESC', '[EXPERIMENTAL] Allows to cache/pregenerate pages. Note: Destroys dynamic capabilites and may not interoperate well with dynamic plugins. But it\'s faster, if you don\'t depend on realtime dynamics. (This plugin should be placed as early as possible in the event queue list. Only dynamic plugins like the karmavoting should be positioned before this plugin.)');
+@define('PLUGIN_EVENT_CACHESIMPLE_BROWSER', 'Use seperate IE/Mozilla caches?');
class serendipity_event_cachesimple extends serendipity_event
{
@@ -54,7 +55,6 @@
); // Leaves only index.php and rss.php
function serendipity_event_cachesimple() {
-
// garvin: Nasty shortcircuit to get Grandma's Performance Pennies.
if ($this->cacheAllowed()) {
@@ -72,7 +72,7 @@
$propbag->add('description', PLUGIN_EVENT_CACHESIMPLE_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
- $propbag->add('version', '0.6');
+ $propbag->add('version', '0.7');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
@@ -87,6 +87,22 @@
'frontend_shortcircuit' => true
));
$propbag->add('groups', array('BACKEND_FEATURES'));
+ $propbag->add('configuration', array('browser'));
+ }
+
+ function introspect_config_item($name, &$propbag) {
+ switch($name) {
+ case 'browser':
+ $propbag->add('type', 'boolean');
+ $propbag->add('name', PLUGIN_EVENT_CACHESIMPLE_BROWSER);
+ $propbag->add('description', '');
+ $propbag->add('default', false);
+ break;
+
+ default:
+ return false;
+ }
+ return true;
}
function generate_content(&$title) {
@@ -199,7 +215,7 @@
'lifeTime' => 3600,
'hashedDirectoryLevel' => 2
);
-
+
$this->cache = new Cache_Lite($options);
switch($event) {
@@ -265,6 +281,19 @@
unset($cache_options['COOKIE']['name']);
unset($cache_options['COOKIE']['url']);
unset($cache_options['COOKIE']['email']);
+
+ if (serendipity_db_bool($this->get_config('browser'))) {
+ if (stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE')
+ && !stristr($_SERVER['HTTP_USER_AGENT'], 'Opera')
+ && !stristr($_SERVER['HTTP_USER_AGENT'], 'Mac_PowerPC')
+ && !stristr($_SERVER['HTTP_ACCEPT'], 'text/html')) {
+
+ $cache_options['browser'] = 'ie';
+ } else {
+ $cache_options['browser'] = 'other';
+ }
+ }
+
$this->cache_key = 'serendipity_cachesimple_' . preg_replace('@[^0-9a-z\-_]@', '_', $_SERVER['REQUEST_URI']) . crc32(serialize($cache_options));
$this->debugMsg($this->cache_key . ' cache prepared');
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/