Mango



Thread: Created a new plugin: where to announce it?

Created on: 12/31/09 05:02 AM

New topic Reply    Page: 1  

Replies: 20
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

12/31/09 5:02 AM

To keep it short, I wanted to let you all know that I created a small plugin: viewCount. See http://www.coldfusiondeveloper.nl/post.cfm/mangoblog-plugin-viewcount

It is not perfect, since the html is appended with jQuery instead of by cfml, but I couldn't find a better way within the mango system.
Anyway, I hope this can be added to the plugin list...
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
visual28


visual28's Gravatar
Joined: 05/18/08
Posts: 421

12/31/09 9:36 AM

I tried to post to your site but the spam filter rejected it. So here are my thoughts....

----

Sounds like an excellent start. I might suggest you use the built in events to improve upon this and make it so that anyone can use it. You might also want to store the hits in a database table rather than a text file.

For example, you can create a new table on plugin initialization to store all the post/page hits. Then you can use "beforePostContentEnd" to do your hit counter increment and display the results to the page.

There might be a better way to do this. I am also thinking that a custom event might work even better since it would allow you to place the counter anywhere on the page.

The benefit to this is that you can count the hits to a post or page, but elect not display them on the page if you wish. Then you can also build an admin widget to display those stats. Win-win!

Another benefit is that you can track pages that do not use standard urls e.g. "/post.cfm/..." You can also track pages too.

-
Mark - www.visual28.com | www.mangowear.com
Link | Top | Bottom
Laura

Wizard
Laura's Gravatar
Joined: 01/29/05
Posts: 1236

12/31/09 1:13 PM

Hi frinky,
Thanks for developing this, many people wanted it.
I haven't looked at your code, but from what Mark says, I agree.

The way I always thought this should work is as follows:

- count is stored in a custom field per post, so that it is easily accessible from themes and you can easily set it.

- counter is incremented on the event: beforePostTemplate if you want to track views to the full post page or postGetContent, which may not be completely accurate if you want to track full post page views (because you may show the full content when there is no excerpt in the home page).
The drawback of using beforePostTemplate is that you don't have the post object, just the name and you have to look it up yourself and handle non-existing posts, but it has the advantage that you can get the post in admin mode without the wrapper.

Either way, when you save the post, you need to do it in an async event.

There is only one problem though with the custom field. If you save the post to set the incremented number, then you will incur a revision, which you don't want. I'll have to think how to circumvent that.

Finally, you can listen to beforePostContentEnd to show the view count. That is the usual event used to show things in the post footer. If the info is stored in a custom field, then you don't need to have a custom event to show it elsewhere in the theme.

If you don't want to save the count in a custom field because of what I said before (the revision issue), you can save it in a table. But I would still populate the post with the custom field when it is retrieved from DB by listening to the Collection events listed here: http://www.mangoblog.org/docs/how-to/extending-mango/creating-a-plugin/built-in-events
Link | Top | Bottom
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

01/01/10 10:20 AM

Thanks for the replies! For starters, I wanted to add this functionality fast and easy for myself, and I didn't have any mangoBlog coding experience.

But your posts made me enthusiastic to expand the plugin a little, and I'm now at a point where I have some questions...

The new version can be seen here: http://www.coldfusiondeveloper.nl/components/plugins/user/viewCount/viewsource.cfm?file=pluginhandler.cfc

Changes:
- database usage
- exclusion for search engine crawlers
- only count same IP+postID once per x hours
- 2 custom events: showViewCount and updateViewCount.

As you can see, I'm now using a database table as Mark suggested. I could be building a DAO for the interaction, but I wanted to keep it simple.
--> Where can I find what datasource name should be used? Somewhere in the settings?

I've seen different [mango:Event ...] tags in different templates. The template I was working with didn't have the 'beforePostContentEnd' event, and therefor I used the jquery approach.
Don't these differences make the blog software a bit unreliable? In case you like yellow, you don't get the counter, and if you like red, you get it twice... I do understand you can change the templates by hand, but out-of-the-box equality is preferable I'd say.

@Laura: I've done it 'my way' as you can see. I don't understand the internals of mangoBlog yet, so I found it easier to do it this way. Hope you don't mind :-)

Todo's for me:
- Admin page for settings: 'exclude search engine crawlers yes/no'; 'nr. of hours between counting the same IP'
- (same) Admin page: overview of page views of all posts
- Admin settings implemented in the pluginHandler
- Check if the "if not exists" sql also works on mySQL and/or Oracle

I'd like to hear where I can find the dsn... Thanks!
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
visual28


visual28's Gravatar
Joined: 05/18/08
Posts: 421

01/01/10 10:56 AM

Looking good.

The differences in the templates make them both a blessing and a curse I know but it does make the most sense. In this case, I think Laura was recommending the use of the event "beforePostTemplate" because it's an internal event, and not one that is template specific so it's reliable for your plugin.

In regards to the DSN, I think there is a different way to access data from your standard cfquery. One that does not require you to need the DSN. Take a look at Adam Tuttle's "popularPosts" plugin as well as his "Scribe" plugin. You can find them posted here: http://fusiongrokker.com/page/projects

It goes something like this:
<cfset sql = "SELECT column_name FROM COLUMNS WHERE TABLE_NAME=FOO />


It's not something I'm familiar with so I cannot tell you much more than this. It looked fairly straight forward, and mango does the rest, so I think you will not have any problem with it.

Maybe Laura can help out a bit more after this.

-
Mark - www.visual28.com | www.mangowear.com
Link | Top | Bottom
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

01/01/10 11:18 AM

Thanks for the reply! I did already see an interface for executing standard sql, but since I was using cfqueryparams, I hoped I could just use cfquery directly.

@Laura: what's the best thing to do here?

Btw: the admin is almost done ;-)
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

01/01/10 4:27 PM

Well, in the end I decided to use the queryInterface which was available anyway. Thanks for pointing it out Mark!

Version 1.1 is now available, with extra checks, options, an admin page, and... it counts the post views :-)

http://www.coldfusiondeveloper.nl/post.cfm/mangoblog-plugin-viewcount

@Laura: could you add this one to the plugin list?
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

01/15/10 4:44 AM

I am looking for beta-testers for version 1.2, who are using mySQL with mangoBlog.
Please check out the blog post http://www.coldfusiondeveloper.nl/post.cfm/mangoblog-plugin-viewcount

Thanks!
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
Shive


Shive's Gravatar
Joined: 06/01/09
Posts: 3

02/15/10 11:22 AM

When I try to activate the plugin, I get the error that it can't be set up because "Variable CUSTOMQUERY is undefined". This is the only plugin that gives me that error. Am I missing something?

Thanks!
Kevin
Link | Top | Bottom
Shive


Shive's Gravatar
Joined: 06/01/09
Posts: 3

02/15/10 11:29 AM

UPDATE: I realized I was not using the most current version, so I updated to 1.4.3. Now the error says "Tried to return query result when there was no result".

Thanks again.
Kevin
Link | Top | Bottom
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

02/15/10 1:23 PM

Have you tried de-activating and then re-activating the plugin?
It uses database interaction, and I assume the plugin didn't yet create the tables.
If you could mail me your website's url at paul at ongevraagdadvies.nl, I could also take a look at the detailed error in yoursite.com/components/utilities/logs/error.log.html / yoursite.com/components/utilities/logs/warning.log.html

Regards,
Paul
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
visual28


visual28's Gravatar
Joined: 05/18/08
Posts: 421

02/16/10 7:58 AM

Just an FYI 1.4.3 does not store plugin errors in that public location any longer. They are stored in the database. You will need to get Adam's "Log Viewer" plugin and send the errors by email.

-
Mark - www.visual28.com | www.mangowear.com
Link | Top | Bottom
johngag


johngag's Gravatar
Joined: 10/28/08
Posts: 15

02/16/10 12:34 PM

Just to let u know I got the exact same error as Shive. I havnt looked at the logs yet but I will post what I find
Link | Top | Bottom
Laura

Wizard
Laura's Gravatar
Joined: 01/29/05
Posts: 1236

02/16/10 12:40 PM

To help you debugging, that error appears when you use the query interface to make a query that does not return a record set (UPDATE, DELETE, CREATE TABLE) and you tell the query interface that you want the results, resulting in a null pointer exception. You just need to make sure that the third argument for makeQuery() is false.
Link | Top | Bottom
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

02/16/10 1:53 PM

Thanks for your posts!
I updated the plugin to version 1.2.4 to fix this issue: http://www.coldfusiondeveloper.nl/post.cfm/mangoblog-plugin-viewcount

Or use the zip file directly: http://www.coldfusiondeveloper.nl/viewCount/viewCount-plugin-Mangoblog-v1.2.4.zip

Please let me know if there are any other issues!
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
johngag


johngag's Gravatar
Joined: 10/28/08
Posts: 15

02/16/10 2:02 PM

Ok, it is recording the views now but the admin is not showing.
Link | Top | Bottom
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

02/16/10 2:18 PM

Hi John, could you install the log viewer plugin (zip: http://mangologviewer.riaforge.org/index.cfm?event=action.download), and tell me what's the error? You can mail me at paul at ongevraagdadvies.nl. Thanks for your help!
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

02/17/10 6:56 PM

Thanks to John, I now released v1.2.5.
I actually managed to zip up an old file in v1.2.4, which made an old error return :-/
All should be well now.
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
johngag


johngag's Gravatar
Joined: 10/28/08
Posts: 15

02/17/10 7:02 PM

I can confirm that it is now working properly. Thanks a lot for this nice plugin! ;)
Link | Top | Bottom
frinky


frinky's Gravatar
Joined: 06/28/09
Posts: 30

02/17/10 7:05 PM

Well, I'm actually pretty happy to see you didn't abandon it all-together ;-) Thanks for debugging and mailing!
- - Freelance Coldfusion developer from The Netherlands!
Link | Top | Bottom
Shive


Shive's Gravatar
Joined: 06/01/09
Posts: 3

02/17/10 9:01 PM

Nicely done. It seems to work just fine now with MSSQL!
Link | Top | Bottom

New Post

Please login to post a response.