Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2012-12-07 15:32:07

ecklesroad
Plugin Author
From: Bemidji, MN
Registered: 2008-02-22
Posts: 119
Website

Re: cbe_if_prod_status - do something according to production status

Great plugin in Testing and Debug mode, but it prevents output in Live mode. Switching to Live in 4.5.4 TXP just outputs a blank page when this plugin is enabled.

Offline

#12 2012-12-07 16:04:11

Gocom
Plugin Author
Registered: 2006-07-14
Posts: 4,524
Website

Re: cbe_if_prod_status - do something according to production status

ecklesroad wrote:

Great plugin in Testing and Debug mode, but it prevents output in Live mode. Switching to Live in 4.5.4 TXP just outputs a blank page when this plugin is enabled.

It’s likely due to the output buffer modification the plugin does to inject meta tag to the page template. When the site is not in debugging mode, the output buffer callback function returns NULL, which replaces the page contents. It should be returning FALSE to bypass and use the default contents. Other option would be to check the site’s production status before hooking the output buffer handler.

To fix the plugin you could add return false; at the end of cbe_if_prod_start function. Alternatively robots directive can be set with a HTTP header, making template modification unnecessary. As such, you could replace the plugin’s code apart from the tag function with:

if (get_pref('production_status') != 'live')
{
	header('X-Robots-Tag', 'noindex');
}

Last edited by Gocom (2012-12-07 16:06:37)

Offline

#13 2013-01-28 14:44:22

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 344
Website

Re: cbe_if_prod_status - do something according to production status

ecklesroad a écrit:

Great plugin in Testing and Debug mode, but it prevents output in Live mode. Switching to Live in 4.5.4 TXP just outputs a blank page when this plugin is enabled.

Fixed.
Finally.

Offline

#14 2013-01-28 23:18:03

ecklesroad
Plugin Author
From: Bemidji, MN
Registered: 2008-02-22
Posts: 119
Website

Re: cbe_if_prod_status - do something according to production status

Awesome!

Offline

#15 2013-07-22 04:16:05

ecklesroad
Plugin Author
From: Bemidji, MN
Registered: 2008-02-22
Posts: 119
Website

Re: cbe_if_prod_status - do something according to production status

Hi Claire, I found a bug that I can not seem to figure out, I was playing around with a clean install on my local WAMP server and I got this error when using cbe_if_prod_status:

General error Warning: ob_start(): first array member is not a valid class name or object on line 24
C:\wamp\www\xxxxx\textpattern\lib\txplib_misc.php(812) : eval()'d code:24 ob_start()
cbe_if_prod_start()
C:\wamp\www\xxxxx\textpattern\lib\txplib_misc.php:854 call_user_func_array()
C:\wamp\www\xxxxx\textpattern\publish.php:526 callback_event()
C:\wamp\www\xxxxx\index.php:83 textpattern()

Which is

function cbe_if_prod_start()
{
    ob_start( array( &$this, 'cbe_meta_prod_status' ) ) ;
}

in the plugin. I use this plugin on a few sites and i have never seen this error until now, which leads me to think it’s something with my local server. I don’t know what &$this is in reference to.

Offline

#16 2013-07-22 08:17:20

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 344
Website

Re: cbe_if_prod_status - do something according to production status

It’s probably a piece of code I copied-pasted, and forgot to completely check because it was working.
I have not been able to reproduce the bug, but I verified that this works (actually, there is no need to do otherwise):

function cbe_if_prod_start()
{
    ob_start( 'cbe_meta_prod_status' ) ;
}

Does it solve your problem?

Offline

#17 2013-07-22 09:55:45

Gocom
Plugin Author
Registered: 2006-07-14
Posts: 4,524
Website

Re: cbe_if_prod_status - do something according to production status

The callback is referencing $this, the current object, which doesn’t work as expected as there is no common object to reference. The $this is inside function so it doesn’t give anything.

As I mentioned, the output buffer modification stuff can be skipped altogether. Robots can be sent as a HTTP header too, meaning you can simply replace the whole plugin with:

/**
 * Sends no-index directive when site is in a debugging or a testing mode.
 */

if (get_pref('production_status') !== 'live')
{
    header('X-Robots-Tag', 'noindex, nofollow');
}

/**
 * Tests the production status.
 *
 * @param array  $atts  Attributes
 * @param string $thing Contained statement
 */

function cbe_if_prod_status($atts, $thing)
{
    extract(lAtts(array(
        'value' => 'debug, testing',
    ), $atts));

    return parse(EvalElse($thing, in_list(get_pref('production_status'), $value)));
}

I’ve also removed references to globals (they may not be in Textpattern forever), and cbe_if_prod_status accepts comma-separated list of values.

If you still want to inject tag to the page, you can drop the ob_end_flush() stuff, and possible even ob_start() too. There is already a buffer active which you can use to capture the output. You can also use ob_start(), but instead either omit the handler (checks outside the handler, which improves performance too) or return false when its not needed. You don’t need the output handler when the site is in Live status; you don’t want to register it at all. E.g.

/**
 * Registers robots meta injector when site is in testing or debugging mode.
 */

if (get_pref('production_status') !== 'live')
{
    register_callback('cbe_meta_prod_status', 'textpattern_end');
}

/**
 * Replaces the current output buffer contents.
 */

function cbe_meta_prod_status()
{
    if ($ob = ob_get_contents())
    {
        ob_clean();
        echo str_replace('<head>', '<head>'.n.'<meta name="robots" content="noindex, nofollow" />', $ob);
    }
}

Last edited by Gocom (2013-07-22 10:06:05)

Offline

#18 2013-07-22 13:55:15

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 344
Website

Re: cbe_if_prod_status - do something according to production status

Sorry, Jukka, seems you have been preaching in the desert for a while :(

It’s a pity that I couldn’t make header() work, so I persist with meta injection.
Comma-separated list of values, and “testing, debug” as default value for cbe_if_prod_status are adopted.
So is v0.2 out right now.

Thanks a lot for your contribution!

Offline

#19 2015-09-25 17:29:23

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: cbe_if_prod_status - do something according to production status

Today, I was on a client meeting, and I wanted to presume how well ranked (on Google) was a site I’ve developed for another client. So I did a (long-tail, generic-keyword, relevant) search for which I knew the website will appear on the first page, almost on the first positions.
I immediately begin to sweat a little when the website didn’t come up on the SERPs: not in the first page, not in the second one, not in the third one… The website disappeared from Google SERPs. And both in Bing and DuckDuckGo was also a bit harder than usual to find it.

So, after the client meeting, I came back to home and began to troubleshoot the issue.
A few minutes digging into the (generated) code, I found this line right at the top:

<meta name="robots" content="noindex, nofollow" /> 

How did that one slipped through? I was pretty sure some plugin was involved. By now, you might already guess which one ;)

Yes, I know: the help document for the plugin clearly states that, when on “Testing” mode, the plugin will include such line in the output. And, of course, I forgot to switch back the website to “Live” mode after some minor changes I did two weeks ago. My fault, I know.

My suggestion? Make this “feature” an optional setting (opt-in, disabled by default). There may be valid reasons to run a website in “Testing” mode during a while. Or even, the client (or me! :P) could make the little mistake of switching it to “Testing” mode and forget to switch it back to “Live”. If so, paying the price of being removed from Google index for such a minor mistake… it’s not a price I’d like to pay again.

My 2 cents.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#20 2015-09-25 19:43:11

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,253
Website

Re: cbe_if_prod_status - do something according to production status

Ouch. That kind of thing could happen to me too. I just hadn’t discovered the plugin (thanks Julián for bringing it up and thanks Claire for making it).

In addition to your recommendation (which I would agree with), you could use the plugin to display a warning banner on the public-facing site (perhaps just to logged in users using rvm_privileged) that the site is in debug/testing mode.

I do something similar to remind admins that they are in maintenance mode which is also easy to forget to switch off when you are logged in as an admin user.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB