Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Pages: [1] 2

Author Topic: [MOD] Site Offline  (Read 4412 times)

centered

  • Guest
[MOD] Site Offline
« on: January 17, 2008, 01:22:12 AM »

REQUIRES KEYROCK'S SIMPLE SECURITY MOD
http://snewscms.com/forum/index.php?topic=4396.msg29852#msg29852

This mod allows the admin to set the site offline and leave a message so you can work on the site while it is still live.. or sort of..

0. BACKUP
0a. You need the mod above: http://snewscms.com/forum/index.php?topic=4396.msg29852#msg29852

1. New db entry:
Code: [Select]
INSERT INTO settings VALUES (30, 'offline', '');

2. New languages
Code: [Select]
$l['offline'] = 'Site Offline';
$l['offline_mess'] = 'Offline Message - HTML can be included';
$l['offline_maint'] = 'Site Maintenance';

3. New function
Code: [Select]
function offline() {
$action = get_id('category');
if (!$_SESSION[db('website').'Logged_In'] == token() && s('offline') == 'on' && $action == db('loginLink')) { login(); }
else { $message = retrieve('text','articles','title','Offline'); echo $message; }}

4. In function settings()
Find:
Code: [Select]
echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="'.l('comments').'" onclick="toggle(\'sub5\')" style="cursor: pointer;">'.l('comments').'</a>');Add before it:
Code: [Select]
echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', '<a title="offline" onclick="toggle(\'offline\')" style="cursor: pointer;">'.l('offline_maint').'</a>');
echo '<div id="offline" style="display: none;">';
echo html_input('checkbox', 'offline', 'offline', '', l('offline'), '', '', '', '', (s('offline') == 'on' ? 'ok' : ''), '', '', '', '', '');
$message = retrieve('text','articles','title','Offline');
echo html_input('textarea', 'offline_mess', 'offline_mess', $message, l('offline_mess'), '', '', '', '', '', '2', '100', '', '', '');
echo '</div></fieldset>';

5. In processing()
Find:
Code: [Select]
$word_filter_change = $_POST['word_filter_change'];Add afterwards:
Code: [Select]
$offline = $_POST['offline'];
$offline_mess = $_POST['offline_mess'];
$offart =  retrieve('text','articles','title','Offline');
if (!empty($offline_mess) && empty($offart)) {
mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta) VALUES('Offline', '', '$offline_mess', '', '-999', '-999', '', '', '', 'YES', '', '')");
} else if (!empty($offline_mess) && !empty($offart)) {
mysql_query("UPDATE ".db('prefix')."articles SET text = '$offline_mess' WHERE title = 'Offline' AND position = -999 LIMIT 1");
} else if (empty($offline_mess) && !empty($offart)) {
mysql_query("DELETE FROM ".db('prefix')."articles WHERE title = 'Offline' AND position = -999 LIMIT 1;");
}

6.  in the big ufield array the next line down add the below BEFORE the );
Code: [Select]
'offline' => $offline,
7.  Up to you where you put this
in index.php, In the default install after <div id="wrap"> Add:
Code: [Select]
<?php if (!$_SESSION[db('website').'Logged_In'] == token() && s('offline') == 'on') { offline(); } else { ?>Before the last div that closes the wrap div add:
Code: [Select]
<?php ; } ?>

Done...
« Last Edit: January 17, 2008, 01:35:33 AM by equilni »
Logged

pwendel

  • Full Member
  • ***
  • Karma: 8
  • Posts: 106
    • sNews 1.6 in Danish
Re: [MOD] Site Offline
« Reply #1 on: January 17, 2008, 02:14:03 PM »

Sweet, very useful :) Great job!

Per.
Logged
"Opportunity is missed by alot of people because it comes dressed in blue overalls and looks like hard work" -- Thomas Edison (1847-1931)

centered

  • Guest
Re: [MOD] Site Offline
« Reply #2 on: January 21, 2008, 12:46:19 PM »

Thanks man!
Logged

bloop

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
Re: [MOD] Site Offline
« Reply #3 on: January 22, 2008, 06:00:41 AM »

Thank you,its so useful for maintenance.
Logged

SReimert

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
    • http://www.spiritusvitalis.com
Re: [MOD] Site Offline
« Reply #4 on: February 09, 2008, 08:02:13 PM »

The mod is awesome - very useful! But I am running into one problem. I have installed Keyrock's "[ADMIN MOD] Change your Login Panel URL as an Admin Setting" and several other ones out of which the only one affecting the same functions is the MySQL Simple Backup mod. Because of that I had to slightly change the function and that all worked out well. For people interested the function I am using is:

Code: [Select]
function offline() {
$action = get_id('category');
if (!$_SESSION[db('website').'Logged_In'] == token() && s('offline') == 'on' && $action == s('login_url')) { login(); }
else { $message = retrieve('text','articles','title','Offline'); echo $message; }}

Additionally I found that due to some reason the MySQL calls made in the processing function are incorrect for my database. First of all I needed to input a date and the publish boolean in the mod is set to 'YES' but I needed to set it to '1' instead. But that might be my setup.

But one bug still persists and I have got no clue to how to fix it. The title of my page is always "Offline - #Site Name#', no matter whether the site is online or offline and no matter what page I am visiting.

Has anyone had the same problem or does anyone know a solution - I would be much obliged!

Yours truly,

Sam
Logged

SReimert

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
    • http://www.spiritusvitalis.com
Re: [MOD] Site Offline
« Reply #5 on: February 10, 2008, 11:30:22 AM »

Sorry - I more or less fixed the problem already. On some pages the offline title actually was not there.

The problem was that there was still text in the offline text box under the admin settings page. Once I deleted that the offline title part was deleted as well.
Logged

invarbrass

  • Full Member
  • ***
  • Karma: 18
  • Posts: 117
    • http://snews.extremebittorrent.com
Re: [MOD] Site Offline
« Reply #6 on: February 10, 2008, 12:12:23 PM »

Very useful mod!  ;D Should be included in the official distro. Karma added.
Logged

centered

  • Guest
Re: [MOD] Site Offline
« Reply #7 on: February 10, 2008, 02:26:01 PM »

Sorry - I more or less fixed the problem already. On some pages the offline title actually was not there.

The problem was that there was still text in the offline text box under the admin settings page. Once I deleted that the offline title part was deleted as well.

Glad to hear you fixed your problem!
Logged

Pein

  • Newbie
  • *
  • Karma: 0
  • Posts: 28
  • n0 n33d t0 b3 l33t
Re: [MOD] Site Offline
« Reply #8 on: August 17, 2010, 01:23:38 PM »

Does this work in sNews 1.7, cuz Ive tried and nothing happens :(

:D anyone have any idea?!
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Site Offline
« Reply #9 on: August 17, 2010, 02:29:34 PM »

Does this work in sNews 1.7, cuz Ive tried and nothing happens :(
:D anyone have any idea?!

If you copied and used the code exactly as it is presented in the lead post of this thread, then you will need to change one thing in all of the queries in Step 5, the part dealing with function processing().

Search for any and all instances of db('prefix') - which will be between 2 periods - and replace them with _PRE to get the queries working properly.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Pein

  • Newbie
  • *
  • Karma: 0
  • Posts: 28
  • n0 n33d t0 b3 l33t
Re: [MOD] Site Offline
« Reply #10 on: August 19, 2010, 10:02:40 PM »

Howdy Key,

If I get it right, i must just change this db('prefix') to _PRE om the function processing()?!

Tnx :)
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: [MOD] Site Offline
« Reply #11 on: August 20, 2010, 10:23:42 AM »

There are a few more changes, here is the update
http://snewscms.com/forum/index.php?topic=9280.new#new

It is a WIP so if you have issues, let me know
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Site Offline
« Reply #12 on: August 20, 2010, 08:02:47 PM »

Howdy Key, If I get it right, i must just change this db('prefix') to _PRE in the function processing()?!

Yes.

Some History on db('prefix') :
 In the previous versions of sNews - 1.5 and 1.6 - we defined the "prefix" variable value... and the other database-related variable values... within a function named the db function - function db($variable) So,wherever we would need those values in PHP functions in the snews.php file, we would use db('value') and replace value with the actual value name.

The purpose of the "prefix" variable was so we could put the variable's value in that array and... in all PHP functions containing database queries... it would then be added to the table-name in the query so the queries would connect to whichever database tables that had tha prefix without having to change it manually in each query.

The same function (revised a bit) is still used in sNews 1.7. However, the volunteer developers working on sNews 1.7 decied they wanted to change how the "prefix" variable was used in all of the PHP function queries. So they created three new dfinitions called "Constants" ... and the second one - define('_PRE',db('prefix')); - is for the "prefix" variable. You can find them in your snews.php file by searching for - // CONSTANTS.


define('_PRE',db('prefix')); re-defines db('prefix') to be _PRE.
So, any time we are adapting something developed for sNews 1.6 with a query in it... we need to replace db('prefix') with _PRE so the queries will work with 1.7.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: [MOD] Site Offline
« Reply #13 on: August 21, 2010, 03:16:24 AM »

Doug to add to 1.6 to 1.7 mod conversions, you also need to address (like in this mod) the following:

$_SESSION[db('website').'Logged_In'] == token()  in 1.6 is now _ADMIN in 1.7
get_id(seftitle) in 1.6 is now $categorySEF, $articleSEF, etc globals in 1.7
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Site Offline
« Reply #14 on: August 21, 2010, 02:38:15 PM »

Doug to add to 1.6 to 1.7 mod conversions, you also need to address (like in this mod) the following:

$_SESSION[db('website').'Logged_In'] == token()  in 1.6 is now _ADMIN in 1.7
get_id(seftitle) in 1.6 is now $categorySEF, $articleSEF, etc globals in 1.7

Yes, I know there are other mod conversions involved.
I was only focusing on explaining the use of "prefix" with queries and why it was different between the two versions.  ;)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
Pages: [1] 2