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.

Author Topic: [micro-mod]Really really really simple admin/public content splitting  (Read 6831 times)

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal

Say that you want to split admin and public in terms of the content that's to be called into action. Maybe you want to do it so you can set different styling for public and admin views, or maybe you want to strip out some things so they're not brought into the admin view because you don't really need it there? And you want to do that in a simple, unobtrusive manner? You can't do that,, now can you? sNews uses only one index file, so how could you? Well maybe with some scripting to show this and hide that and...

eh-herm.

Actually, we can. And it's really really simple. Really. Here, let me show you.

THE MOD
[The whole thing takes place in index.php. There is no modification of snews.php, no altering the db, nothing of that.]

0. Backup

1. Create a php file called admin.php (or whatever you wish to name it), and one file called public.php (or, again, whatever). In admin.php, put what ever content you wish, including the snews functions that you need for the Admin view. Then do the same with public.php, except there you use all the snews fucntions you need for your public content. The only things that are absolutely necessary, other than the session_start line, which is recommended to keep in index.php, would be:
Code: [Select]
<?php center(); ?>Remember to keep track of where you stored admin.php and public.php -- you'll need to upload them with the other files.

2. In index.php you can now rip out everything that you have put in admin.php and public.php

3. Still in index.php, you will now put the following code in the spot where you want the content to appear, both for admin and public views. The interesting part is that you could remove _everything_ from index.php, except, reasonably, the session_start line.
Here's the magic code:

Code: [Select]
<?php if ($_SESSION[db('website').'Logged_In'] == token()) {include('admin.php');} else {include('public.php');} ?>
And that's all she wrote. A complete split between admin and public views.
Here's a short example of how the index.php file could look:

Ex.:
Code: [Select]
<?php session_start(); include('snews.php'); ?>
<?php if ($_SESSION[db('website').'Logged_In'] == token()) {include('admin.php');} else {include('public.php');} ?>

I'm sure you can dream up examples of your own -- the key point is that you are free to put the magic code anywhere you like in index.php. ;)

Does this work in 1.7RC as well? Why, yes, thanks for asking! It does work almost exactly the same in 1.7RC, the only difference is the spelling of db('website'). Here is the corresponding code for sNews 1.7RC, to use in index.php:

Quote
<?php if ( $_SESSION[_SITE.'Logged_In'] == token()) {include('admin.php');} else {include('public.php');} ?>

Boom. Done.
« Last Edit: April 12, 2008, 03:44:28 am by Fred K (agentsmith) »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #1 on: April 12, 2008, 04:03:42 am »

Well done Fred... couldn't be any simpler.  :)
(+1 karma)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #2 on: April 12, 2008, 07:46:35 am »

Agent Smith seems to be in a great shape isn't he?
Bravo Fred !
And one karma, one!

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #3 on: April 12, 2008, 08:29:36 am »

I`m in the middle of trying this... what about function boosters using session?
« Last Edit: April 12, 2008, 08:43:08 am by funlw65 »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #4 on: April 12, 2008, 08:45:48 am »

@funi: Honestly -- I wouldn't know. Have you hit any problems? I haven't had any problems when testing this, but on the other hand, I don't really have any high-traffic sites (and testing has only been done locally as yet) so I have never noticed that great a difference in performance with or without boosters to be honest. Some difference yes -- the codetwist get_id booster was one that showed a noticeable difference for example -- but not so big that it's at the top of my mind. Your mileage may vary, naturally.

@Key's & Sven the Frenchman: /*bows and thanks profoundly*/
(I don't know why I haven't thought of this mod before, as many times as I've pondered various ways of splitting or restyling content depending on location... It's so simple it's annoying, almost. ;D)
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #5 on: April 12, 2008, 09:23:15 am »

Nope, no problems... I just start my engine and is not warm enough  :-[
Logged

Nicu Alecu

  • Full Member
  • ***
  • Karma: 12
  • Posts: 224
    • BLUEBYTE.ro // IT consultant
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #6 on: April 12, 2008, 09:56:04 am »

Brilliantly simple, Fred! :o Not to mention very handy too ... 8)
This one definitely deserves a +K!
I'm heading towards running a test right now ...
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #7 on: April 12, 2008, 10:04:48 am »

I was a little afraid to `destroy` my index.php :D but now I have diferent layout for admin. Karma! Will be default for my package. One problem, if you want to help me... how I can define diferent dimensions for text area when I use Eatlon theme and the same css? For admin.php I use right_wing.html layout. You can see public layout again when logging out but is ok, the clients will not complain about little space in admin area.

Textarea have autosizing property: width: 97%;  :P
« Last Edit: April 12, 2008, 10:39:19 am by funlw65 »
Logged

lessismore

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 67
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #8 on: April 12, 2008, 10:36:09 am »

clever, simple, functional, brilliant - THANKS!

My index.php was filled with many "if" admin clauses to show things like breadcrumbs, sitemap, archive, validation links, links to phpmyadmin, etc ... the main index files are going to be so much "cleaner" now.

I can see an extension of this for use in the MU version as well - a simple case on userlevels.
Logged

jlhaslip

  • Sr. Member
  • ****
  • Karma: 16
  • Posts: 374
    • My snews with AEF Forum site
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #9 on: April 12, 2008, 09:16:28 pm »

As a further 'bandwidth reduction' method, has anyone split the CSS file to handle the admin stuff in its own file?

Doing so would save the sending of the admin page CSS to the client who would likely never need/use it.

Just a thought...
Logged
Yes! I have no siggy.

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #10 on: April 12, 2008, 09:26:30 pm »

As a further 'bandwidth reduction' method, has anyone split the CSS file to handle the admin stuff in its own file?
Doing so would save the sending of the admin page CSS to the client who would likely never need/use it.
Just a thought...

I have done this with my current MEMU project. I did it more to keep all admin-related CSS out of layout and template files in projects that have several layouts or templates being used. That way I only load the admin.css file once in the templated used by the admin.  Eventually... depending on the outcome of revisions Bakercad is making in his new "Switcherizer 2" Templates mod (listed in Programming)... I hope to able to create an admin-only template as well.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #11 on: April 12, 2008, 11:30:59 pm »

As a further 'bandwidth reduction' method, has anyone split the CSS file to handle the admin stuff in its own file?

Doing so would save the sending of the admin page CSS to the client who would likely never need/use it.

Just a thought...

Yup, that's precisely the point that at the last minute made me strip out _everything_ from the index file. I have admin.php where I call in admin.css where I don't need to put a bunch of ... hacks ... and I can call in whatever scripts I need but the public doesn't. And I have public.php with public.css (including the ...hacks...) and a bunch of public scripts. So it's a good thought you had there. Keep it. ;D
Logged

poppoll

  • Full Member
  • ***
  • Karma: 47
  • Posts: 199
    • Poppoll's sNews playground
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #12 on: August 12, 2008, 03:44:05 am »

Thanks this is great!!
PP
Logged

KHL_John

  • Newbie
  • *
  • Karma: 0
  • Posts: 2
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #13 on: June 07, 2009, 03:46:06 pm »

Is there anything that speaks against moving the admin.php in a subfolder? Will there be a problem or is there already a solution?
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [micro-mod]Really really really simple admin/public content splitting
« Reply #14 on: June 09, 2009, 12:52:33 pm »

John,
As far as I know there aren't any issues with having the admin.php file in a separate folder. Here's an example setup that I use from time to time:
snews.php and index.php live in the root folder, right?
*all* other function files, admin.php included, except javascripts, live in a folder I tend to call "xxx". (Actually I use a different name, that one's just to fool bots,)

So I put this bit in index.php:
Code: [Select]
<?php ...
if(_ADMIN) { include('xxx/admin.php'); }
else { include('xxx/public.php'); }
?>

The important bit, I think, is to have the core file (snews.php) and index.php in the folder that represents your site root. Other files can basically go anywhere you like, as long as you use the correct URLs to activate them. They could live on a completely different server, even (note: haven't actually tested that, but, in theory...)

OOPs: just noticed; the code quoted above is from 1.7, not 1.6, so there would be minor differences in the 1.6 code, but the principle is the same. Sorry about the version-mix, I no longer use 1.6 anywhere.
« Last Edit: June 09, 2009, 12:56:49 pm by Fred K (agentsmith) »
Logged