It looks like you're new here. If you want to get involved, click one of these buttons!
<?php if (!defined('APPLICATION')) exit();
// Define the plugin:
// the 'GuestRestriction' is the name of the Plugin folder
$PluginInfo['GuestRestriction'] = array(
// just the name to display of the plugin below
'Name' => 'Guest Restriction',
// a brief description
'Description' => 'This plugin prevents guests from viewing discussion, onlty title is viewable.',
// each time you update plugin update version so you can upload it.
'Version' => '1.0',
'Author' => "Peregrine" // the author
);
// extend the garden Plugin class and create GuestRestrictionPlugin // class name is created by adding name of plugin folder "GuestRestriction" + "Plugin"
class GuestRestrictionPlugin extends Gdn_Plugin {
// where you put your code logic
// this allows you to enable and disable plugin
public function Setup() {
}
}
- we want to do things on the individual discussion page for each comment.
- How did I find where to put this
- I searched for FireEvent in helper_ functions.php in
- the /vanilla/applications/vanilla/views/discussion folder.
// this function executes on the discussion page
public function DiscussionController_BeforeCommentMeta_Handler($Sender) {
}
public function DiscussionController_BeforeCommentMeta_Handler($Sender) {
// get current session info
$Session = Gdn::Session();
// this tests to see is user is logged in
if (!($Session->IsValid())) {
}
}
}
public function DiscussionController_BeforeCommentMeta_Handler($Sender) {
// get current session info
$Session = Gdn::Session();
// this tests to see is user is logged in
if (!($Session->IsValid())) {
// if the user is NOT logged in - add this css file which resides
// in the /plugins/GuestRestriction design folder
$Sender->AddCssFile('guestrestriction.css', 'plugins/GuestRestriction');
}
}
/vanilla/plugins/GuestRestriction/design
we name it 'guestrestriction.css,
/vanilla/plugins/GuestRestriction/design/guestrestriction.css contains
.Comment .Message {
display:none;
}
this isolates any classes of Message that are descendants of class Comment and makes them invisible by setting display to none. I found this by looking in firebug or chrome developer tools.
// this function essentially produces the same results // of Discussion View when viewing Category
public function CategoriesController_BeforeDiscussionMeta_Handler(&$Sender) {
// the call to discussioncontroller at the BeforeDiscussionMeta event
// How did I find where to put this - I searched for FireEvent
//in helper functions in
// the /vanilla/applications/vanilla/views/discussion folder.
$this->DiscussionController_BeforeCommentMeta_Handler($Sender);
}
factoid: Most questions have been previously answered, try the search box first, please provide your Vanilla version Number!
Peregrine's Addons - donations gladly accepted for "successful solutions" and addons - kind of like tipping a waiter at a restaurant
aery
Gtricks Forum in 2.1 :) ✭✭✭
Thanks @peregrine
Now I will try to make some plugins based on your skelton :)
Answers
If you "like" this, download the complete example plugin here.
http://vanillaforums.org/addon/guestrestriction-plugin
and now one of "You" can add it to the wiki, if you found it helpful.
factoid: Most questions have been previously answered, try the search box first, please provide your Vanilla version Number!
Peregrine's Addons - donations gladly accepted for "successful solutions" and addons - kind of like tipping a waiter at a restaurant
- Spam
- Abuse
- Troll
4 • Off Topic Insightful 4Awesome LOL •looking forward to your plugins!
factoid: Most questions have been previously answered, try the search box first, please provide your Vanilla version Number!
Peregrine's Addons - donations gladly accepted for "successful solutions" and addons - kind of like tipping a waiter at a restaurant
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •i think i am starting to understand how it works. oh it will be awesome as soon as i totally get it!
thanks so much @peregrine
edit: i just wish i had more time on my hands, damn :p
- Spam
- Abuse
- Troll
1 • Off Topic Insightful 1Awesome LOL •fh111 - Once you get the time looking forward to some new plugins!. I'm happy if this added any more insight in to writing some basic plugins. Once I learned a bit about the naming and syntax of the plugin, it really did become a lot clearer and grepping for Fire to find events gave me a clue as to what events are possible.
factoid: Most questions have been previously answered, try the search box first, please provide your Vanilla version Number!
Peregrine's Addons - donations gladly accepted for "successful solutions" and addons - kind of like tipping a waiter at a restaurant
- Spam
- Abuse
- Troll
2 • Off Topic Insightful 2Awesome LOL •Part 2: Modifying an Existing Plugin.
Lets say instead of blanking out the message for guests (users who are not logged in), you want to replace the message in the body with a link that directs the user to log-in.
Steps required to modify the plugin.
1) In this case i know that the message is added in helper_ functions.php in
Go back into default.php
remove or comment out the two functions
2) create the new function
3) add the logic to replace the message.
4) resynch with the category controller
5) Now users who are not logged in will see the link "This message can be viewed if you log in" that points to the signin process.
factoid: Most questions have been previously answered, try the search box first, please provide your Vanilla version Number!
Peregrine's Addons - donations gladly accepted for "successful solutions" and addons - kind of like tipping a waiter at a restaurant
- Spam
- Abuse
- Troll
2 • Off Topic Insightful 2Awesome LOL •Nice tutorial @peregrine! I was going to say... hiding restricted content with CSS is not really hiding it. But looks like you changed this function to server-side.
I just made my first plugin and would love some eyes on it: http://vanillaforums.org/discussion/20373/tag-cloud-plugin
Next step is to delve into event hooks and whatnot...
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •@leafmonster It was more of an exploratory to try to explain the ins and outs of a simple plugin rather than the virtues of the plugin itself.
One more plugin developer added to the bunch!
factoid: Most questions have been previously answered, try the search box first, please provide your Vanilla version Number!
Peregrine's Addons - donations gladly accepted for "successful solutions" and addons - kind of like tipping a waiter at a restaurant
- Spam
- Abuse
- Troll
1 • Off Topic Insightful 1Awesome LOL •whenever i click the redirection link, the page cannot be displayed.
do i have to change the link to my domain?
http://localhost/vanilla/entry/signin?Target=discussions- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •btw! thanks for making my request possible :)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Yes - unless you have everybody signin at your house or on a keyboard at your physical server location. :)
on line 6 in step 3 above. // note: put whatever url you want below.
revision of comment, should say // note: put whatever url you want below. and obviously you must point it to a valid url**
just for reference..... to point to your own domain for signup. highlight the sigin link on your site and right click and copy the link into this position.
this annotation is for how-to write a plugin - not how to write php, or css, or how to make a link. It does demand some knowledge of php, css, and a bit of how to write some code logic.
factoid: Most questions have been previously answered, try the search box first, please provide your Vanilla version Number!
Peregrine's Addons - donations gladly accepted for "successful solutions" and addons - kind of like tipping a waiter at a restaurant
- Spam
- Abuse
- Troll
1 • Off Topic Insightful 1Awesome LOL •How to put a setting option in your plugin. (there are numerous ways to do this - this technique will add a settings option aside the enable button in the dashboard.
1 - add the SettingsUrl to the array in default.php
'SettingsUrl' => '/dashboard/plugin/guestrestiction',
like so:
2 - add a views directory to your plugin
vanilla/plugins/GuestRestriction/views
create a file gr-settings.php
vanilla/plugins/GuestRestriction/views/gr-settings.php
3 - modify the default.php to reflect and retrieve the config settings you just created in the view above
we modify this function so it now retrieves configurations settings form config.php
4. Add a function to default.php that directs you the view you created above in step 2. Once again make sure the two config option names match.
public function PluginController_GuestRestriction_Create(&$Sender, $Args = array()) {
factoid: Most questions have been previously answered, try the search box first, please provide your Vanilla version Number!
Peregrine's Addons - donations gladly accepted for "successful solutions" and addons - kind of like tipping a waiter at a restaurant
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Pt. 3 - add sidemenu to the dashboard for the plugin with a slight change to arguments.
change this
public function PluginController_GuestRestriction_Create(&$Sender, $Args = array()) {to this (lose the ampersand and the arguments array).
factoid: Most questions have been previously answered, try the search box first, please provide your Vanilla version Number!
Peregrine's Addons - donations gladly accepted for "successful solutions" and addons - kind of like tipping a waiter at a restaurant
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •