check if mambot is published

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
yoshi
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Fri Dec 09, 2005 12:30 pm
Location: uk
Contact:

check if mambot is published

Post by yoshi » Sun Oct 07, 2007 11:23 am

hi, whats the best way to check if the mambot id published or not.?

I see a lot of mambots which still interfere with stuff evn when they are unpublished (you actually have to remove the mambot to stop it)!

So whats the code or syntax to do it properly?

Many thanks

Lee

User avatar
yoshi
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Fri Dec 09, 2005 12:30 pm
Location: uk
Contact:

Re: check if mambot is published

Post by yoshi » Sun Oct 07, 2007 12:46 pm

is it just as simple as

Code: Select all

 if( !$published ) return true;

User avatar
AmyStephen
Joomla! Guru
Joomla! Guru
Posts: 579
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: check if mambot is published

Post by AmyStephen » Sun Oct 07, 2007 2:14 pm

If you look at the code for the loadmodule plugin (plugins/content/loadmodule.php), you will find this code:

Code: Select all

// check whether plugin has been unpublished
if ( !$pluginParams->get( 'enabled', 1 ) ) {
   $row->text = preg_replace( $regex, '', $row->text );
   return true;
}


Hope that helps!
Amy :)
~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/

User avatar
yoshi
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Fri Dec 09, 2005 12:30 pm
Location: uk
Contact:

Re: check if mambot is published

Post by yoshi » Mon Oct 08, 2007 9:00 am

Amy, thanks for the reply. I have looked in several mambots but as I am not a coder I dont realy understand whats going on ;-(

I have managed to put together a mambot which does exactly what I want and the code I posted above sems to work but your seems to be a better guide.

However, as I dont know what it means, a plain english translation of your above code would be:-

Code: Select all

check if mambot is published - if yes do the replace - end?


where should this go in the code? if you put it at the very bottom of the mambot function would that not put an overhead on the page load (even with the mambot unpublished) as the whole function would still be performed before deciding not to output the result?

I hope I am making sense.

Thanks again for any help
Last edited by yoshi on Mon Oct 08, 2007 9:02 am, edited 1 time in total.

User avatar
AmyStephen
Joomla! Guru
Joomla! Guru
Posts: 579
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: check if mambot is published

Post by AmyStephen » Mon Oct 08, 2007 7:36 pm

Yoshi -

I am also just learning. The best way, IMO, to learn is to study an existing, working example. The code snippets I shared with you came directly from the plugins\content\loadmodule.php file in the Joomla! core.

That code is saying if the plugin is NOT enabled (not the ! in front of the phrase), then remove the {loadposition}xxx{/loadpostion} syntax in the article with nothing and exit the plugin.

I've used loadmodule over and over and over.

Good luck with your project and I hope you are having fun like I am!
Amy :)
~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/

User avatar
Pentacle
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: check if mambot is published

Post by Pentacle » Tue Oct 09, 2007 8:19 pm

Amy, I am a little bit confused here. If a plugin is unpublished it shouldn't be executed at all.

But wait, loadmodule plugin is not written in the new way of 1.5. I think the old way doesn't handle the publishing itself, right?
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.

User avatar
yoshi
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Fri Dec 09, 2005 12:30 pm
Location: uk
Contact:

Re: check if mambot is published

Post by yoshi » Tue Oct 09, 2007 9:12 pm

exactly my point Pentacle. it seems a lot of mambots for 1.0 actually get 'processed' for want of a better term even if their results are not output to the screen. 

User avatar
AmyStephen
Joomla! Guru
Joomla! Guru
Posts: 579
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: check if mambot is published

Post by AmyStephen » Tue Oct 09, 2007 9:48 pm

Pentacle wrote:Amy, I am a little bit confused here. If a plugin is unpublished it shouldn't be executed at all.

But wait, loadmodule plugin is not written in the new way of 1.5. I think the old way doesn't handle the publishing itself, right?


Is that so? Hmm. I don't know. I have been using loadmodule as an example.  :( Do you know of a good example of the new way?

Thanks!
Amy :)
~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/

User avatar
Pentacle
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: check if mambot is published

Post by Pentacle » Wed Oct 10, 2007 8:01 am

AmyStephen wrote:
Is that so? Hmm. I don't know. I have been using loadmodule as an example.  :( Do you know of a good example of the new way?

Thanks!
Amy :)


Hmm. Most of the core plugins (especially content) ain't touched since 1.0 I think. So Ian's slider plugin or my youtube one (not *good* but a simple example :) ) can show this behavior. I didn't use these checks about plugin is published or not. But when I disabled it, replacement wasn't taking place.

Ercan.
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.

User avatar
DeanMarshall
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Fri Aug 19, 2005 2:26 am
Location: Lancaster, Lancashire, United Kingdom
Contact:

Re: check if mambot is published

Post by DeanMarshall » Fri Oct 12, 2007 6:37 pm

Just to clarify one point - mambots/plugins are executed even when unpublished
to allow the module - where necessary - to remove the { ... } mambot tag so
as to tidy up display.

Dean
Dean Marshall - http://www.deanmarshall.co.uk/
Mambo and Joomla Consultant

Add an Amazon Store to your site: http://www.Project-TinA.com/
(coming soon)

User avatar
AmyStephen
Joomla! Guru
Joomla! Guru
Posts: 579
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: check if mambot is published

Post by AmyStephen » Fri Oct 12, 2007 7:26 pm

Even for J! v 1.5? I realize it does so in v 1.0.x but it seems like v 1.5 might be different. Otherwise, we would continue to need to check if were published, or else it would go ahead and run simply because it was installed.

Nice to see you, Dean, and I appreciate your response, always.
Amy :)
~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/

User avatar
Pentacle
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: check if mambot is published

Post by Pentacle » Fri Oct 12, 2007 9:57 pm

Right now, I'm playing with some 1.5 plugins and if it's not published, I can't do anything. Not echoing, not replacing. An explanation from the core team would be great. :)
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.

User avatar
DeanMarshall
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Fri Aug 19, 2005 2:26 am
Location: Lancaster, Lancashire, United Kingdom
Contact:

Re: check if mambot is published

Post by DeanMarshall » Fri Oct 12, 2007 11:37 pm

AmyStephen wrote:Even for J! v 1.5? I realize it does so in v 1.0.x but it seems like v 1.5 might be different. Otherwise, we would continue to need to check if were published, or else it would go ahead and run simply because it was installed.

Nice to see you, Dean, and I appreciate your response, always.
Amy :)


Hi Amy,

My comment was an off the cuff 'in general' - just trying to explain
the situation from my experience, which is mainly J1.0.x - I haven't
really dabbled that much with J1.5


A quick check of the pagebreak plugin shows this:

Code: Select all

   // check whether plugin has been unpublished
   if (   !JPluginHelper::isEnabled('content', 'pagebreak') ||
      $params->get( 'intro_only' )||
      $params->get( 'popup' ) ||
      $full)
   {
      $row->text = preg_replace( $regex, '', $row->text );
      return;
   }


Which according to the comments checks whether the plugin is unpublished
and if it is or we are on a page showing intro text only, or in a popup the
plugin tag is replaced by the empty string.


Dean
Dean Marshall - http://www.deanmarshall.co.uk/
Mambo and Joomla Consultant

Add an Amazon Store to your site: http://www.Project-TinA.com/
(coming soon)

User avatar
AmyStephen
Joomla! Guru
Joomla! Guru
Posts: 579
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: check if mambot is published

Post by AmyStephen » Fri Oct 12, 2007 11:51 pm

That's what we were noticing, as well, but we were wondering if really the plugins could be updated to remove that logic.

You know, Dean, v 1.5 is a whole lot of fun to play with. Hope you are able to find time to play soon!

Amy :)
~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/


Post Reply