The only bit of weird behavior I'm seeing is that if I log in as Admin and change the settings in the profile page, it seems to change the defaults in the Dashboard. (But if I change the Dashboard, it doesn't change the Admin settings in the Admin profile.)
Hardly a real problem, but an interesting drug interaction.
I like this idea. This would go in as basically a fourth public function in the plugin?
no, a replacement for the existing function.
The only bit of weird behavior I'm seeing is that if I log in as Admin and change the settings in the profile page, it seems to change the defaults in the Dashboard. (But if I change the Dashboard, it doesn't change the Admin settings in the Admin profile.)
But if I change the Dashboard, it doesn't change the Admin settings in the Admin profile
it shouldn't as you would hope,
The only bit of weird behavior I'm seeing is that if I log in as Admin and change the settings in the profile page, it seems to change the defaults in the Dashboard
You would need to put a check in Public function UserModel_AfterGetSession_Handler($Sender) {
to return immediately if you are viewing dashboard.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Should probably just add the data to the form so it will auto-populate. I forgot to unpack the layout user meta for some reason as well. My modified version is below:
public function UserModel_AfterGetSession_Handler($Sender) {
$User = $Sender->EventArguments['User'];
// override the default controller route temporarily if it has been set
$Controller = $this->GetUserMeta($User->UserID, 'DefaultController', FALSE, TRUE);
if($Controller) {
Gdn::Router()->SetRoute('DefaultController', $Controller, 'Internal', FALSE);
}
// override the default layout temporarily
$DiscussionsLayout = $this->GetUserMeta($User->UserID, 'DiscussionsLayout', C('Vanilla.Discussions.Layout', 'modern'), TRUE);
$CategoriesLayout = $this->GetUserMeta($User->UserID, 'CategoriesLayout', C('Vanilla.Categories.Layout', 'modern'), TRUE);
SaveToConfig('Vanilla.Discussions.Layout', $DiscussionsLayout, array('Save' => FALSE));
SaveToConfig('Vanilla.Categories.Layout', $CategoriesLayout, array('Save' => FALSE));
}
public function ProfileController_EditMyAccountAfter_Handler($Sender) {
$User = $Sender->User;
// Load their current settings
$Controller = $this->GetUserMeta($User->UserID, 'DefaultController', FALSE, TRUE);
$DiscussionsLayout = $this->GetUserMeta($User->UserID, 'DiscussionsLayout', FALSE, TRUE);
$CategoriesLayout = $this->GetUserMeta($User->UserID, 'CategoriesLayout', FALSE, TRUE);
// Save the settings to the form
$Sender->Form->SetValue('DefaultController', $Controller);
$Sender->Form->SetValue('DiscussionsLayout', $DiscussionsLayout);
$Sender->Form->SetValue('CategoriesLayout', $CategoriesLayout);
$ControllerOptions = array(
'discussions' => 'Discussion List',
'categories' => 'Category List'
);
$LayoutOptions = array(
'modern' => T('Modern non-table-based layout'),
'table' => T('Classic table layout used by traditional forums')
);
echo '<li class="Homepage">';
echo $Sender->Form->Label('Homepage View', 'DefaultController');
echo $Sender->Form->DropDown('DefaultController', $ControllerOptions, array('IncludeNull' => TRUE));
echo $Sender->Form->Label('Discussions View', 'DiscussionsLayout');
echo $Sender->Form->DropDown('DiscussionsLayout', $LayoutOptions, array('IncludeNull' => TRUE));
$LayoutOptions['mixed'] = T('All categories listed with a selection of 5 recent discussions under each');
echo $Sender->Form->Label('Categories View', 'CategoriesLayout');
echo $Sender->Form->DropDown('CategoriesLayout', $LayoutOptions, array('IncludeNull' => TRUE));
echo '</li>';
}
public function UserModel_AfterSave_Handler($Sender) {
$FormValues = $Sender->EventArguments['FormPostValues'];
$UserID = val('UserID', $FormValues, 0);
// Require valid user ID
if(!is_numeric($UserID) || $UserID <= 0) {
return;
}
$DefaultController = val('DefaultController', $FormValues, FALSE);
if($DefaultController) {
$this->SetUserMeta($UserID, 'DefaultController', $DefaultController);
}
$DiscussionsLayout = val('DiscussionsLayout', $FormValues, FALSE);
if($DiscussionsLayout) {
$this->SetUserMeta($UserID, 'DiscussionsLayout', $DiscussionsLayout);
}
$CategoriesLayout = val('CategoriesLayout', $FormValues, FALSE);
if($CategoriesLayout) {
$this->SetUserMeta($UserID, 'CateogoriesLayout', $CategoriesLayout);
}
}
The key differences are I set the value on the form to what I got from the user table. I also passed in TRUE in the GetUserMeta() method so it automatically unfolds the data rather than return an array.
you could make another historical change to hg's most recent version and it will fix your dashboard issue
and when you name it either name it default.php or class.CustomHomepage.Plugin.php
public function UserModel_AfterGetSession_Handler($Sender) {
$qs = $_SERVER['QUERY_STRING'];
if (preg_match("#dashboard/settings/#",$qs)) {
return;
}
$User = $Sender->EventArguments['User'];
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Should probably just add the data to the form so it will auto-populate. I forgot to unpack the layout user meta for some reason as well.
I did it the hard way. to heck with using the already builtin stuff just kidding.
you are the master @hgtonight ! very nice shortcuts.
good testing and experimenting and great idea for a plugin @DoyceT
also after complete ironing out, it should be added to add-ons - it is a very nice plugin with features unlike other plugins with good examples and efficiently coded by hg.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Edit, looks like I cross-posted. So here is one final suggestion, only modify the routes and layout if we are on the appropriate controller!
public function UserModel_AfterGetSession_Handler($Sender) {
$Request = Gdn::Request();
if($Request->Path() == '') {
$User = $Sender->EventArguments['User'];
// override the default controller route temporarily if it has been set
$Controller = $this->GetUserMeta($User->UserID, 'DefaultController', FALSE, TRUE);
if($Controller) {
Gdn::Router()->SetRoute('DefaultController', $Controller, 'Internal', FALSE);
}
}
}
public function Gdn_Dispatcher_AfterControllerCreate_Handler($Sender) {
$User = Gdn::Session()->User;
$Controller = $Sender->EventArguments['Controller'];
// override the default layout temporarily if applicable
switch($Controller->ControllerName) {
case 'discussionscontroller':
$DiscussionsLayout = $this->GetUserMeta($User->UserID, 'DiscussionsLayout', C('Vanilla.Discussions.Layout', NULL), TRUE);
SaveToConfig('Vanilla.Discussions.Layout', $DiscussionsLayout, array('Save' => FALSE));
break;
case 'categoriescontroller':
$CategoriesLayout = $this->GetUserMeta($User->UserID, 'CategoriesLayout', C('Vanilla.Categories.Layout', NULL), TRUE);
SaveToConfig('Vanilla.Categories.Layout', $CategoriesLayout, array('Save' => FALSE));
break;
}
}
public function ProfileController_EditMyAccountAfter_Handler($Sender) {
$User = $Sender->User;
// Load their current settings
$Controller = $this->GetUserMeta($User->UserID, 'DefaultController', FALSE, TRUE);
$DiscussionsLayout = $this->GetUserMeta($User->UserID, 'DiscussionsLayout', FALSE, TRUE);
$CategoriesLayout = $this->GetUserMeta($User->UserID, 'CategoriesLayout', FALSE, TRUE);
// Save the settings to the form
$Sender->Form->SetValue('DefaultController', $Controller);
$Sender->Form->SetValue('DiscussionsLayout', $DiscussionsLayout);
$Sender->Form->SetValue('CategoriesLayout', $CategoriesLayout);
$ControllerOptions = array(
'discussions' => 'Discussion List',
'categories' => 'Category List'
);
$LayoutOptions = array(
'modern' => T('Modern non-table-based layout'),
'table' => T('Classic table layout used by traditional forums')
);
echo '<li class="Homepage">';
echo $Sender->Form->Label('Homepage View', 'DefaultController');
echo $Sender->Form->DropDown('DefaultController', $ControllerOptions, array('IncludeNull' => TRUE));
echo $Sender->Form->Label('Discussions View', 'DiscussionsLayout');
echo $Sender->Form->DropDown('DiscussionsLayout', $LayoutOptions, array('IncludeNull' => TRUE));
$LayoutOptions['mixed'] = T('All categories listed with a selection of 5 recent discussions under each');
echo $Sender->Form->Label('Categories View', 'CategoriesLayout');
echo $Sender->Form->DropDown('CategoriesLayout', $LayoutOptions, array('IncludeNull' => TRUE));
echo '</li>';
}
public function UserModel_AfterSave_Handler($Sender) {
$FormValues = $Sender->EventArguments['FormPostValues'];
$UserID = val('UserID', $FormValues, 0);
// Require valid user ID
if(!is_numeric($UserID) || $UserID <= 0) {
return;
}
$DefaultController = val('DefaultController', $FormValues, FALSE);
if($DefaultController) {
$this->SetUserMeta($UserID, 'DefaultController', $DefaultController);
}
$DiscussionsLayout = val('DiscussionsLayout', $FormValues, FALSE);
if($DiscussionsLayout) {
$this->SetUserMeta($UserID, 'DiscussionsLayout', $DiscussionsLayout);
}
$CategoriesLayout = val('CategoriesLayout', $FormValues, FALSE);
if($CategoriesLayout) {
$this->SetUserMeta($UserID, 'CategoriesLayout', $CategoriesLayout);
}
}
This version will only load the user preferences if we are on the appropriate controller. It also will only change the default controller if the request path is empty. This gets rid of some edges cases I didn't think about in regards to changing the system wide homepage options.
@peregrine said:
also after complete ironing out, it should be added to add-ons - it is a very nice plugin with features unlike other plugins with good examples and efficiently coded by hg.
I think this is a pretty good example of collaborative work: shows the initial version, the benefit of multiple eyes and different ideas.
@DoyceT@peregrine and I came up with different solutions to solve that problem. My latest example overrides the layout configs when on the appropriate controller. This means it won't (or shouldn't ; ) interfere with the dashboard at all.
Alright, just for posterity, here's the final version I ended up with, all of which seems to be working exactly as advertised.
I have a .zip file of the plugin directory (including vrijvlinder's excellent icon), so now I suppose I just need to figure out how to add a plugin to the directory.
<?php if (!defined('APPLICATION')) exit(); ?>
<?php
$PluginInfo['CustomHomepage'] = array(
'Name' => 'Custom Homepage',
'Description' => 'This plugin allows users to set their own choices for which homepage they will see when they connect to the forum.',
'Version' => '0.2',
'Author' => "Doyce Testerman - but really peregrine and hgtonight - plus vrijvlinder for the awesome icon.",
'AuthorEmail' => 'doyce.testerman@gmail.com',
'AuthorUrl' => 'http://vanillaforums.org/discussion/27138/any-to-give-users-their-own-selection-of-homepage-layout'
);
?>
<?php
class CustomHomepagePlugin extends Gdn_Plugin {
public function UserModel_AfterGetSession_Handler($Sender) {
$Request = Gdn::Request();
if($Request->Path() == '') {
$User = $Sender->EventArguments['User'];
// override the default controller route temporarily if it has been set
$Controller = $this->GetUserMeta($User->UserID, 'DefaultController', FALSE, TRUE);
if($Controller) {
Gdn::Router()->SetRoute('DefaultController', $Controller, 'Internal', FALSE);
}
}
}
public function Gdn_Dispatcher_AfterControllerCreate_Handler($Sender) {
$User = Gdn::Session()->User;
$Controller = $Sender->EventArguments['Controller'];
// override the default layout temporarily if applicable
switch($Controller->ControllerName) {
case 'discussionscontroller':
$DiscussionsLayout = $this->GetUserMeta($User->UserID, 'DiscussionsLayout', C('Vanilla.Discussions.Layout', NULL), TRUE);
SaveToConfig('Vanilla.Discussions.Layout', $DiscussionsLayout, array('Save' => FALSE));
break;
case 'categoriescontroller':
$CategoriesLayout = $this->GetUserMeta($User->UserID, 'CategoriesLayout', C('Vanilla.Categories.Layout', NULL), TRUE);
SaveToConfig('Vanilla.Categories.Layout', $CategoriesLayout, array('Save' => FALSE));
break;
}
}
public function ProfileController_EditMyAccountAfter_Handler($Sender) {
$User = $Sender->User;
// Load their current settings
$Controller = $this->GetUserMeta($User->UserID, 'DefaultController', FALSE, TRUE);
$DiscussionsLayout = $this->GetUserMeta($User->UserID, 'DiscussionsLayout', FALSE, TRUE);
$CategoriesLayout = $this->GetUserMeta($User->UserID, 'CategoriesLayout', FALSE, TRUE);
// Save the settings to the form
$Sender->Form->SetValue('DefaultController', $Controller);
$Sender->Form->SetValue('DiscussionsLayout', $DiscussionsLayout);
$Sender->Form->SetValue('CategoriesLayout', $CategoriesLayout);
$ControllerOptions = array(
'discussions' => 'Discussion List',
'categories' => 'Category List'
);
$LayoutOptions = array(
'modern' => T('Modern non-table-based layout'),
'table' => T('Classic table layout used by traditional forums')
);
echo '<li class="Homepage">';
echo $Sender->Form->Label('Homepage View', 'DefaultController');
echo $Sender->Form->DropDown('DefaultController', $ControllerOptions, array('IncludeNull' => TRUE));
echo $Sender->Form->Label('Discussions View', 'DiscussionsLayout');
echo $Sender->Form->DropDown('DiscussionsLayout', $LayoutOptions, array('IncludeNull' => TRUE));
$LayoutOptions['mixed'] = T('All categories listed with a selection of 5 recent discussions under each');
echo $Sender->Form->Label('Categories View', 'CategoriesLayout');
echo $Sender->Form->DropDown('CategoriesLayout', $LayoutOptions, array('IncludeNull' => TRUE));
echo '</li>';
}
public function UserModel_AfterSave_Handler($Sender) {
$FormValues = $Sender->EventArguments['FormPostValues'];
$UserID = val('UserID', $FormValues, 0);
// Require valid user ID
if(!is_numeric($UserID) || $UserID <= 0) {
return;
}
$DefaultController = val('DefaultController', $FormValues, FALSE);
if($DefaultController) {
$this->SetUserMeta($UserID, 'DefaultController', $DefaultController);
}
$DiscussionsLayout = val('DiscussionsLayout', $FormValues, FALSE);
if($DiscussionsLayout) {
$this->SetUserMeta($UserID, 'DiscussionsLayout', $DiscussionsLayout);
}
$CategoriesLayout = val('CategoriesLayout', $FormValues, FALSE);
if($CategoriesLayout) {
$this->SetUserMeta($UserID, 'CategoriesLayout', $CategoriesLayout);
}
}
}
I'm trying to upload the .zip file via http://vanillaforums.org/addon/add? (zip contains the .php file and the .png icon), but I'm getting an error message
This page is only for adding Vanilla 2 addons. If you want to add a Vanilla 1 addon click here.
So I'm going to leave it for a bit and see if I can figure out what I'm doing wrong. Need to go pick up the dog.
I attached the zip in case one of you can spot some obvious mistake I'm making.
Comments
Guys, peregrine's tweaks worked perfectly. I can't thank you enough for your help on this.
Here's another mod. so when the user looks their selections again in edit profile, it shows what they previously selected.
there might be a cleaner way but this works for me.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
I like this idea. This would go in as basically a fourth public function in the plugin?
Edit: Sorry, I see - it's a change to the second Public function already in the plugin.
The only bit of weird behavior I'm seeing is that if I log in as Admin and change the settings in the profile page, it seems to change the defaults in the Dashboard. (But if I change the Dashboard, it doesn't change the Admin settings in the Admin profile.)
Hardly a real problem, but an interesting drug interaction.
no, a replacement for the existing function.
it shouldn't as you would hope,
You would need to put a check in Public function UserModel_AfterGetSession_Handler($Sender) {
to return immediately if you are viewing dashboard.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Gotcha.
And, as I said, really that's an entirely manageable feature of the plug-in.
So, just for the sake of historical record, here's the full plugin file I ended up with, in case it's of use to anyone else.
/plugins/CustomHomepage/class.customhomepageplugin.php
That is a good idea @peregrine!
Should probably just add the data to the form so it will auto-populate. I forgot to unpack the layout user meta for some reason as well. My modified version is below:
The key differences are I set the value on the form to what I got from the user table. I also passed in
TRUE
in theGetUserMeta()
method so it automatically unfolds the data rather than return an array.Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
you could make another historical change to hg's most recent version and it will fix your dashboard issue
and when you name it either name it default.php or class.CustomHomepage.Plugin.php
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
I did it the hard way. to heck with using the already builtin stuff just kidding.
you are the master @hgtonight ! very nice shortcuts.
good testing and experimenting and great idea for a plugin @DoyceT
also after complete ironing out, it should be added to add-ons - it is a very nice plugin with features unlike other plugins with good examples and efficiently coded by hg.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Edit, looks like I cross-posted. So here is one final suggestion, only modify the routes and layout if we are on the appropriate controller!
This version will only load the user preferences if we are on the appropriate controller. It also will only change the default controller if the request path is empty. This gets rid of some edges cases I didn't think about in regards to changing the system wide homepage options.
EDIT - Looks like I cross-posted again. LOL
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
I take some small pride in coming up with a topic that has the two of you interested enough to keep cross-posting.
I think this is a pretty good example of collaborative work: shows the initial version, the benefit of multiple eyes and different ideas.
All we need is a sweet icon from @vrijvlinder
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Thanks, @hgtonight - I'm going to put your latest into my version of the plugin, but before I do, would it make sense to swap in @peregrine's lines from this post - http://vanillaforums.org/discussion/comment/210227/#Comment_210227 - for lines 1 to 4 in your latest example?
@DoyceT @peregrine and I came up with different solutions to solve that problem. My latest example overrides the layout configs when on the appropriate controller. This means it won't (or shouldn't ; ) interfere with the dashboard at all.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
That's what I was hoping you'd say (since it means I half-understood the code).
Here is a custom homes icon
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
Alright, just for posterity, here's the final version I ended up with, all of which seems to be working exactly as advertised.
I have a .zip file of the plugin directory (including vrijvlinder's excellent icon), so now I suppose I just need to figure out how to add a plugin to the directory.
I suggest you use the same name for the folder and the plugin
CustomHomepage on all so it won't have problems disabling.
Add this before the last }
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
call the icon icon.png in your zip.
make sure your folder is called CustomHomepage'
and you probably just want to call the file default.php
and zip it and upload it.
then add some screenshots and add the icon to the page.
that's it.
you may need to change the author to your screenname if it doesn't let you upload.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Thanks!
I'm trying to upload the .zip file via http://vanillaforums.org/addon/add? (zip contains the .php file and the .png icon), but I'm getting an error message
So I'm going to leave it for a bit and see if I can figure out what I'm doing wrong. Need to go pick up the dog.
I attached the zip in case one of you can spot some obvious mistake I'm making.