Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder: Plugins & Add-ons:
Tutorial for plugin ?

 

First page Previous page 1 2 3 Next page Last page  View All


Djulia
User

Feb 3, 2010, 4:29 AM

Post #1 of 54 (98596 views)
Shortcut
Tutorial for plugin ? Can't Post

Hi,

I would like to create a simple function that I would like to activate or deactivate in the section plugins ?

There would be a tutorial to explain how to create (to activate) a plugin?

Thanks for the feedback!

Djulia



Dave
Staff / Moderator


Feb 3, 2010, 10:16 PM

Post #2 of 54 (98575 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

Hi Djulia,

I can write something up. Do you just want to automatically load your plugin or do you want to use one of the plugin hooks? Or, put another way, what do you want your plugin to do?

For the most part you can just create a php file in the /plugins/ folder with this header:


Code
<?php 
/*
Plugin Name: your plugin name
Description: your plugin description
Version: 1.00
Requires at least: 2.00
*/

function yourfunction() {
...
}

?>


Once you do that you'll be able to see it and "activate" it in the plugins menu. Once activated it will be loaded by admin.php and any of your viewer pages.

The "Requires at least" line refers to CMSB versions. You can't activate a plugin unless you have at least that version.

Hope that helps! Let me know any additional details you need.

Dave Edis - Senior Developer
interactivetools.com
 


Djulia
User

Feb 4, 2010, 10:03 AM

Post #3 of 54 (98559 views)
Shortcut
Re: [Dave] Tutorial for plugin ? [In reply to] Can't Post

Hi Dave,

I wrote my plugin!

But, I did not really understand the use of addFilter.
That seems to be an important parameter.
It is the insertion point ?

Thanks to risk you in the explanations!

Djulia

Below my plugin, it will be perhaps useful for other users!
He alerts by email the admin if a user connects himself.

Attachments: alertAdminLogin.php (1.17 KB)


Dave
Staff / Moderator


Feb 4, 2010, 11:40 AM

Post #4 of 54 (98547 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

Hi Djulia,

Looks good. I added this semicolon to make it work for me:

Code
. "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}\n"; 


addFilter() and addAction() are almost the same but addFilter() must always return something. It's used to modify a value (such as the footer text), where-as addAction() just runs some code.

Let me know if you have any other questions about how everything works! :)

Dave Edis - Senior Developer
interactivetools.com
 


Dave
Staff / Moderator


Feb 6, 2010, 4:50 PM

Post #5 of 54 (98511 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

Also, for v2.03 (in development) I've updated it to call session_destroy() on logout. That should allow you to make you code simpler for future plugins (since the counter will automatically get reset when a new session is created).

Dave Edis - Senior Developer
interactivetools.com
 


Djulia
User

Feb 11, 2010, 9:49 AM

Post #6 of 54 (97339 views)
Shortcut
Re: [Dave] Tutorial for plugin ? [In reply to] Can't Post

Thanks Dave for the update! :)

That functions perfectly with version 2.03.

Djulia



(This post was edited by Djulia on Feb 11, 2010, 9:55 AM)
Attachments: alertAdminLogin.php (1.17 KB)


Dave
Staff / Moderator


Feb 15, 2010, 9:43 AM

Post #7 of 54 (96228 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

Nice! :)

Dave Edis - Senior Developer
interactivetools.com
 


Djulia
User

Apr 2, 2010, 12:07 AM

Post #8 of 54 (89235 views)
Shortcut
Re: [Dave] Tutorial for plugin ? [In reply to] Can't Post

Hi Dave,

The post of Terry motivated me to improve a plugin that I had written.
It sends an email notification when a record is added or modified ...

CMSB impresses me each day by its flexibility!

But, I still block with the use of css.

Djulia

Attachments: alertSavedRecord.php (2.08 KB)


flamerz
User

Apr 2, 2010, 3:10 PM

Post #9 of 54 (89064 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

wow.. this one is a must have.

good job.


hvbuilder
User

Apr 10, 2010, 12:39 PM

Post #10 of 54 (84874 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

Hello,

I upgraded to version 2.03 and installed your plugin, but I do not receive an email when a record is added or changed. Is there something else I need to do?

Thanks,

James


Djulia
User

Apr 10, 2010, 1:03 PM

Post #11 of 54 (84869 views)
Shortcut
Re: [hvbuilder] Tutorial for plugin ? [In reply to] Can't Post

Hello,

You can check if the email of the administrator is correct in CMSB ( General Settings > Email Settings) ?

You can also check that the function mail works correctly ?
http://www.php.net/manual/en/function.mail.php

Djulia


GraphicLingoes
User

Sep 7, 2010, 3:34 PM

Post #12 of 54 (34728 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

I'm building my own plugin that will allow the admin to send a pre-formatted email to new users once they have activated their account. I'd like to display a message after the email has been sent. Can I call an alert function and pass it some text for the message so it will show on top of the page like the "Record saved." message?

Thanks for your help
Mike
Graphic Lingoes
www.graphiclingoes.com


Djulia
User

Sep 7, 2010, 11:45 PM

Post #13 of 54 (34676 views)
Shortcut
Re: [GraphicLingoes] Tutorial for plugin ? [In reply to] Can't Post

Hi Mike,

It is not preferable to create your function with (in) the Membership plugin ?

If not, you can detail your approach ?

Thanks,
Djulia



GraphicLingoes
User

Sep 8, 2010, 9:35 AM

Post #14 of 54 (34627 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post


In Reply To
Hi Mike,

It is not preferable to create your function with (in) the Membership plugin ?




Hi Djulia,

I'm not creating a function in the Membership Plugin, I have created my own plugin and uploaded it to the plugins folder and activated it. My question is, is there a function that I can call that will allow me to reproduce a confirmation alert such as the "Record saved." alert that shows at the top of the screen when a record is saved. I know what css class is being used to create the look and feel of the alert and I have been able to echo html code with the css class applied to a div to show my alert at the bottom of the screen, but I would rather show the alert at the top. Any ideas on how to do this, right now in my custom plugin I'm using applyFilter to "execute_econds" hook so html I echo shows in the footer.

Does this make sense?
Thanks

Graphic Lingoes
www.graphiclingoes.com

(This post was edited by GraphicLingoes on Sep 8, 2010, 11:38 AM)


GraphicLingoes
User

Sep 8, 2010, 12:29 PM

Post #15 of 54 (34603 views)
Shortcut
Re: [GraphicLingoes] Tutorial for plugin ? [In reply to] Can't Post

Okay, so I found the function "notice($message)" that sets the notice for the "displayAlertsAndNotices()" function but when I add that to my code it doesn't seem to work? I'm adding "notice("Email sent.")". Any ideas?
Graphic Lingoes
www.graphiclingoes.com


Djulia
User

Sep 8, 2010, 1:36 PM

Post #16 of 54 (34594 views)
Shortcut
Re: [GraphicLingoes] Tutorial for plugin ? [In reply to] Can't Post

You can use this function : _displayNotificationType(type, message).

if (!$mailResult) { _displayNotificationType('attention', 'Mail Error:' .$php_errormsg);
else { _displayNotificationType('information', 'Send Email Ok');}

But, I do not know how to obtain positioning in top of the page.

I think that it is possible to use addFilter.

Perhaps what interactivetools can help us ?



(This post was edited by Djulia on Sep 8, 2010, 1:45 PM)


GraphicLingoes
User

Sep 8, 2010, 1:49 PM

Post #17 of 54 (34589 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

Thanks Djulia,

I came up with something very similar, but have also been stumped as to how to get it to show at the top of the screen. Logic would tell me that if I use the notice($message) approach that the displayAlertsAndNotices() function should know what to show, but my guess is the clearAlertsAndNotices() function is being called somewhere after I set the message with notice($message).
Graphic Lingoes
www.graphiclingoes.com

(This post was edited by GraphicLingoes on Sep 8, 2010, 5:28 PM)


GraphicLingoes
User

Sep 8, 2010, 2:04 PM

Post #18 of 54 (34584 views)
Shortcut
Re: [GraphicLingoes] Tutorial for plugin ? [In reply to] Can't Post

Okay, figured it out. Chris had explained to me in an earlier email to check out the hook names through out the system and I didn't comprehend it until now, anyway to get the message I needed I used the hook for "viewer_postinit" so in my plugin I have

addFilter('viewer_postinit', ena_setEmailSentNotice);

function ena_setEmailSentNotice() {
if(isset($_GET['_pluginAction']) && $_GET['_pluginAction'] == 'sendEmail') {
return notice('Email sent.');
}

This will not be the final code, but this is how I got the notice to show at the top of the page.
Graphic Lingoes
www.graphiclingoes.com


Djulia
User

Sep 8, 2010, 2:13 PM

Post #19 of 54 (34583 views)
Shortcut
Re: [GraphicLingoes] Tutorial for plugin ? [In reply to] Can't Post

Great ! :)

Your plugin seems interesting ! It will be public ?

There is a filter for record_saved_message (?).

Djulia


GraphicLingoes
User

Sep 8, 2010, 2:22 PM

Post #20 of 54 (34580 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

Yes I'll make it public once it's completed. I saw the hook for "saved_message..." but that only works if there is a "save" variable in the url and since the action wasn't really a save I didn't want to cludge it together to work that way.
Graphic Lingoes
www.graphiclingoes.com


Djulia
User

Sep 8, 2010, 2:26 PM

Post #21 of 54 (34578 views)
Shortcut
Re: [GraphicLingoes] Tutorial for plugin ? [In reply to] Can't Post

This functions perfectly for me.

addFilter('record_saved_message', '_custom_record_saved_message', null, 1);

function _custom_record_saved_message($record_saved_message) {
return "Record saved ! Email sent !";
}

Djulia


GraphicLingoes
User

Sep 8, 2010, 4:05 PM

Post #22 of 54 (34569 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

When did you call it? Did you have to save the record to get the message? I've added a link to the list so the message is a response to a click on the link not a save.
Graphic Lingoes
www.graphiclingoes.com


Chris
Staff / Moderator


Sep 8, 2010, 4:10 PM

Post #23 of 54 (34568 views)
Shortcut
Re: [Djulia] Tutorial for plugin ? [In reply to] Can't Post

Hi folks,

It is thoroughly awesome that you two are working together and writing plugins!

It seems like you two have everything figured out already!

@GraphicLingoes: Using 'admin_head' instead of 'viewer_postinit' might be safer, since it's the closest hook before the call to displayAlertsAndNotices() in lib/menus/header.php

If you are super curious, you could try to figure out when and why your notice was getting cleared by either dumping out a backtrace from clearAlertsAndNotices(), or adding a trace lines before each call to it. Of course, that's not really going to help you solve the problem any better, maybe just understand why you had to solve it. ;)


Please let me know if either of you have any questions and keep up the great work! :D
Chris


GraphicLingoes
User

Sep 8, 2010, 5:24 PM

Post #24 of 54 (34557 views)
Shortcut
Re: [chris] Tutorial for plugin ? [In reply to] Can't Post

Hi Chris,
thanks for the suggestion ("admin_head"). I've updated my code. I actually tried that earlier before I really understood the difference between addFilter and addAction and I kept getting wierd results because I wasn't returning anything with addFilter. Works perfectly now, thanks!
Graphic Lingoes
www.graphiclingoes.com

(This post was edited by GraphicLingoes on Sep 9, 2010, 9:33 AM)


GraphicLingoes
User

Sep 9, 2010, 7:58 PM

Post #25 of 54 (34419 views)
Shortcut
Re: [GraphicLingoes] Tutorial for plugin ? [In reply to] Can't Post

#######################################################################
NOTE: There is a newer version of the plugin available on the second page of this post.
Updated post 10/14/2010
#######################################################################

Hello everyone,

I've attached the final version for the first round of the Email New Account Activated plugin that I build with the help of CMSB staff and @Djulia. I hope you find it useful. So what does this plugin do? What it does is add a link to the "accounts" list labeled "email account activated" for admin users only. When you click on that link a pre-formatted email from the plugin code is sent to email address of the line in the list of records you clicked on.

The reason I built this plugin was I'm using the "Membership Plugin" from CMSB which I have customized a little for a client. My client did not want accounts to be active until they had a chance to review who they were and approve them. So what I did was add a check box to the accounts section called "Active" that is defaulted to unchecked which is inactive. It's a simple concept, when my client checks off the box the account becomes active. I then added some code to each member page to check if they are active or not. If not the member is re-directed to a page explaining that they are not active yet. I know there is some overhead that gets added with this check on every page, but the client wanted to be able to lock someone out of their member section in real time so I had to do it.

So when my client reviews the new member and checks off the box that they are active, of course, they wanted an easy way to notify the client that they are active. This is how the plugin was born. They said to me, "Mike it would be great if we could have a link right here that allowed us to click once to send a template email to the client and be done with it". Being the pepole pleaser that I am I had to say yes and now we have a new plugin.

Enjoy!
Mike


TIPS:
- You can specify what list the link shows in in the "gl_ena_addLink" function.
- You can change the $message variable for the email to say whatever you want, but if you are not familiar with how concatenation works you may want to read up on it here first http://www.w3schools.com/PHP/php_string.asp
- The "notice($message) function will change the blue alert that displays after the email is sent to say whatever you want so you could for example put "notice("Your alert text here")".
Graphic Lingoes
www.graphiclingoes.com

(This post was edited by GraphicLingoes on Oct 14, 2010, 1:26 PM)
Attachments: gl_emailNewAccountActivated.php (3.89 KB)

First page Previous page 1 2 3 Next page Last page  View All