Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
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: 345
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
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
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: 345
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
Member
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
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,129
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

#21 2015-09-25 20:42:04

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

Re: cbe_if_prod_status - do something according to production status

The background and intention when writing this plugin were something like “I’m exceptionally doing a hotfix on the production site, it won’t take more than a minute or two but I don’t want potential error messages to be indexed.”

And “I” is me :) I mean: the plugin works according to my philosophy, that is to say:
The keyword is “exceptionally”. You have to be very careful when doing such a thing, not only from SEO point of view: don’t forget that you are on a public site, potentially visited by many people. Don’t let search engines index an error, don’t let visitors see the mess. Ideally, the fix should be done after having being tested in a development environment and with a checklist under hand:

  • backup database
  • activate cbe_if_prod_status
  • testing mode
  • copy-paste <put form names here>
  • quickly check the public side:
    • if OK, deactivate cbe_if_prod_status + live mode
    • if NOK, restore database

In minute… or better: in seconds. If it’s more, it’s not a hotfix.

maniqui wrote #295139:

I was pretty sure some plugin was involved. By now, you might already guess which one ;)

Mmmmh… with a little help of a PEBKAC ? ^^

maniqui wrote #295139:

Make this “feature” an optional setting.

According to what I have just written… well… no, it’s useless.

jakob wrote #295146:

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.

And this can be useful.
Better: in the admin-side only. Less risk to break something (what if, for a reason or another, rvm_privileged turns to be deactivated?).

Offline

#22 2015-09-25 22:27:46

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

Re: cbe_if_prod_status - do something according to production status

Hi CeBe,
thanks for the prompt reply and your explanation.

I understand your motivation as the plugin author and I also understand your use case & usage checklist (both seems a bit contrived for my taste, though).

But let me get this straight: from my POV, you created a plugin that:

  • is aimed at web-developers (vs CMS end-users) and
  • which sole purpose is to let the web-developer to fine-control the flow/output of code in according to the website’s production status. So far, so good.
  • but then, having created this simple & fabulous plugin (and I repeat: which allows the web-developer to control the flow/outpuf of code), you decided to inject some code in the background when the production status is set to “Testing”.

Can… can you see the irony?
It’s very big, so I think you will be able to see it, but let me point it out for our audience: the plugin itself is a tool to fine-control the output code and a tool that fits perfectly for doing… what you then decided to do in the background instead, by injecting code. Oh, boy girl!

Let me say it in codespeak (it would have been could be a perfect “Example 1” for your plugin’s help):

<txp:cbe_if_prod_status value="testing">
   <meta name="robots" content="noindex, nofollow" /> 
</txp:cbe_if_prod_status>

Or even like this (which covers both “testing” and “debug” stati:

<txp:cbe_if_prod_status value="live">
<txp:else />
   <meta name="robots" content="noindex, nofollow" /> 
</txp:cbe_if_prod_status>

Voilà!
Or, as it’s said: you are eating your own dog food.

Of course, in the contrived workflow you propose (which implies backups & activating/deactivating your plugin and which I don’t fully understand, to be sincere), the above examples might not work (I dunno, do they?).

Finally, let me share my simple usage of your wonderful plugin:

<txp:cbe_if_prod_status value="live">
  <txp:aks_header strip="1" gzip="1" />
</txp:cbe_if_prod_status>

Have a nice day.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#23 2015-09-26 06:27:35

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,129
Website

Re: cbe_if_prod_status - do something according to production status

CeBe wrote #295148:

> 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.

And this can be useful.
Better: in the admin-side only. Less risk to break something (what if, for a reason or another, rvm_privileged turns to be deactivated?).

Sorry, I wasn’t clear. I don’t think you need to add this to the plugin. It’s fine doing what it does: detecting the production status. I meant this is something that dev’s can add to the front side to remind admin users (and themselves :-p) to switch back to live.

maniqui wrote #295149:

Finally, let me share my simple usage of your wonderful plugin:

<txp:cbe_if_prod_status value="live"> <txp:aks_header strip="1" gzip="1" /> </txp:cbe_if_prod_status>

I like that! I do something similar using the (sadly orphaned) ied_if_domain so that compression only happens on the live site but not on the dev site but I hadn’t thought of your application.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB