I'm not sure if this facility currently exists but I'd like to have an option where the visitors preferences are remembered when they choose a category. i.e the next time they return s9y knows what to display.
For example I'm interested in Archery, Fishing and making money.
While my posts about archery interest fellow archers they may not want to know or read about fishing.
If these were available category options on the home page, is it possible to have s9y remember that they only want to read and see archery articles if they check the tick box?
TIA
Kev Polley
Categories Remember Me
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Categories Remember Me
Hi!
Actually, such a facility does not exist yet. It could be made with a plugin though:
Put this plugin into a directory /plugins/serendipity_event_remembercat/serendipity_event_remembercat.php and install the plugin.
Please tell me if it works, it is untested.
(I also committed this functionality to the "Star Page Category" event plugin...)
Regards,
Garvin
Actually, such a facility does not exist yet. It could be made with a plugin though:
Code: Select all
<?php
@define('PLUGIN_EVENT_REMEMBERCAT_NAME', 'Remember Visitor Category');
@define('PLUGIN_EVENT_REMEMBERCAT_DESC', 'Allows your visitors to remember their last selected category');
class serendipity_event_remembercat extends serendipity_event
{
var $title = PLUGIN_EVENT_REMEMBERCAT_NAME;
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_REMEMBERCAT_NAME);
$propbag->add('description', PLUGIN_EVENT_REMEMBERCAT_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.0');
$propbag->add('requirements', array(
'serendipity' => '0.9',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('event_hooks', array(
'frontend_configure' => true,
));
$propbag->add('groups', array('FRONTEND_VIEWS'));
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'frontend_configure':
if (empty($serendipity['GET']['category']) && !empty($serendipity['COOKIE']['category'])) {
$serendipity['GET']['category'] = $serendipity['COOKIE']['category'];
}
if (is_array($serendipity['POST']['multiCat'])) {
$serendipity['GET']['category'] = implode(';', $serendipity['POST']['multiCat']);
}
if (is_array($serendipity['GET']['multiCat'])) {
$serendipity['GET']['category'] = implode(';', $serendipity['GET']['multiCat']);
}
if (!empty($serendipity['GET']['category'])) {
serendipity_setCookie('category', $serendipity['GET']['category']);
}
break;
}
}
}
}
Please tell me if it works, it is untested.
(I also committed this functionality to the "Star Page Category" event plugin...)
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/
Hi Garvin,
As usual you ARE The Man! Thank you.
Your plugin works like a dream. The only thing I needed to do was add the closing php tag.
The only real observation so far is that the category sidebar could do with some text added to it that reminds visitors if they previously selected a category and decide they want to view others, they will need to check all boxes as your code overrides the 'All Categories' link.
Don't get me wrong. It does exactly what it should but users will be users.
I'll give it a more serious test over the coming days but so far I see no real problems except the missing closing php tag.
thanks again
Kev
As usual you ARE The Man! Thank you.
Your plugin works like a dream. The only thing I needed to do was add the closing php tag.
The only real observation so far is that the category sidebar could do with some text added to it that reminds visitors if they previously selected a category and decide they want to view others, they will need to check all boxes as your code overrides the 'All Categories' link.
Don't get me wrong. It does exactly what it should but users will be users.
I'll give it a more serious test over the coming days but so far I see no real problems except the missing closing php tag.
thanks again
Kev
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Great that it works :)If you see any side effects, let me know. I am sure the code might need some pushing and poking. I'll need to think about how "All Categories" could be changed so that the cookie is not used to retrieve previous categories. But since that link is just a "back to startpage" link, it would be hard to do.
I suggest you to enable the smarty templating of the categories plugin and then create a custom plugin_category.tpl file where you add custom text for your visitors?
Best regards,
Garvin
Great that it works :)If you see any side effects, let me know. I am sure the code might need some pushing and poking. I'll need to think about how "All Categories" could be changed so that the cookie is not used to retrieve previous categories. But since that link is just a "back to startpage" link, it would be hard to do.
I suggest you to enable the smarty templating of the categories plugin and then create a custom plugin_category.tpl file where you add custom text for your visitors?
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/