Jump to content

Simple Maintainmode for guests


mr-fan
 Share

Recommended Posts

Hi there just a first little piece of code for a simple maintainmode.

Other CMS needs a setting or something else complicated.....and with PW you've simple tools to do that easy.

Using 2.4 but with template setup from the actual dev with

/templates/

_func.php    /functions and navigation (with MarkupsimpleNavigation.... ;)

_init.php      /init

_main.php   /template

basic-page.php

home.php

...

so i wanna simple build up a page or later set it in to maintainmode without loosing access for bots....

so at now i'm setting up my first pw project i've the following code running perfect for building up the page:

_init.php

//setting the maintainpage
$maintain = <<<EOT
<html><head>

		<title>what you wanna show</title>
                <meta content="text/html; charset=utf-8" http-equiv="content-type">
	<style>
body {
	some basic style
}
</style></head>

<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="400">
<tbody><tr>
	<td style="padding-top: 50px;" align="center" valign="top"><img src="my-fancy-logo"></td>
</tr>

<tr><td style="padding-top: 50px; text-align: center">
<p>Some text on the maintain thingi</p>
</td>
</tr>
</tbody></table>
</body></html>
EOT;

//headline or title
$headline = $page->get("headline|title");

//maincontentblock
$bodycopy = $page->body;

// if the current page has a populated 'sidebar' field, then print it,
// otherwise print the sidebar from the homepage
$homepage = $pages->get("/");
if($page->sidebar) $sidebar = $page->sidebar;
else $sidebar = $homepage->sidebar;

// Include shared functions
include_once("./_func.php");    

and in my templates that shows the different pages (aren't to much in this project)

basic-page.php

// default settings and fuctions
include("./_init.php");

if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) {
// main template for building the page
include("./_main.php");    
};

if ($user->isGuest()) {
    echo $maintain;
} else {
// main template for building the page
include("./_main.php");
};

This is just quik and dirty so if i've the time i would make a simple function within the _func.php and get the _main.php include a little bit smarter, especial with much more template files this shouldn't be redundant/repeated...

  • Further improvments could be a checkbox on a backend page /settings/ maybe.....to check on/off maintain mode.....so it would be a simple switch in the Backend even a client could do.
  • Next step could be a maintain template to get the text and content editable in the backend for everyone....should be not that hard and would made it complete!

Hope this is interesting for someone...

have fun mr-fan

- use PW is having fun every second for me since i've not the huge times for coding stuff -

  • Like 2
Link to comment
Share on other sites

Changed....

its a fragment of the index.html from the hosting provider - that i modifed just fast without checking deeper since this pages i use only when i'm setup the website.

This should be done via PW page in the backend...so i will write more about this.

I found the Maintenace Mode Module too!

http://modules.processwire.com/modules/maintenance-mode/

But i didn't get in the code that bots are routed properly?

...so i did it the dig in some little code way to learn more about PW!

Maybe i will adapt the pregmatch for the useragent and change the Maintenace Mode Module sometimes.

For now it works for me - i can build up the website if i logged in and guests will see a "wait a minute" screen.

Thanks for reading my poor little snippet ;)

Link to comment
Share on other sites

I'm confused as to why you would want bots to be able to see your content if it's under maintenance but not guests?

If you use my module, I would leave it so it blocks bots too otherwise Google could easily see a PHP error or something if you are changing things behind the scenes.

  • Like 1
Link to comment
Share on other sites

ok you are right for this bots should not get trought but bots should get a proper HTTP 503

503 Service Unavailable The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.

so this header should send to such useragents.

if they get nothing at all it should be even bad as a php error or something else?

But i'm not a great SEO expert - if i'm wrong here i'm willing to learn...

kind regards mr-fan

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...