How to get s9y to detect that it is in the backend?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
NeilW
Regular
Posts: 51
Joined: Sat Jun 20, 2015 6:56 am
Contact:

How to get s9y to detect that it is in the backend?

Post by NeilW »

From within the front end template's config.inc.php file, I am trying to create a simple IF statement to say to the admin files when opening the backend...

If in the admin backend...

Do this....

Else... (On the front end blog)

Do that...

Does anyone know how to structure the IF statement to do this??

I have tried;

if (defined('IN_serendipity_admin')

and;

if (IN_serendipity_admin === true) {

and even;

$string = 'serendipity';
$fullstring = $_SERVER['REQUEST_URI'];
if (strpos($fullstring,$string) !== false) {

But none of them seem to be recognised and/or acted on when the back end is being opened.

Any help would be greatly appreciated.

Thank you.

- Neil
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by Don Chambers »

How about this:

Code: Select all

if ($serendipity['GET']['adminModule'] == 'templates' || $serendipity['POST']['adminModule'] == 'templates') {
=Don=
NeilW
Regular
Posts: 51
Joined: Sat Jun 20, 2015 6:56 am
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by NeilW »

Hi Don,

That seemed to work thank you, but not quite.

I have been working with onli to get my front end right and we have found the way.

The only problem was that after putting the if statement that I mentioned at the top of this post to bring my php menu into a Smarty variable I was previously getting this error when opening the admin backend;
The Serendipity JavaScript-library could not be loaded. This can happen due to PHP or Plugin errors, or even a malformed browser cache. To check the exact error please open http://mysite.com/blog/ ... _editor.js manually in your browser and check for error messages.
In using your code above, that error no longer appears and all looks good - EXCEPT, when I go into either "New Entry" or "Edit Entry" I get the following error message at the very top of the page;
Error redirect: == SERENDIPITY ERROR ==
implode() [function.implode]: Invalid arguments passed in /home/mysite/public_html/blog/plugins/serendipity_event_freetag/serendipity_event_freetag.php on line 1046


Additionally, when I go into the "Themes" menu, the front end seems to bomb.

This may also be caused by the above error, I guess????

Just one other thing that could help resolve the whole thing, is that with your IF above and the previous one I was using, I now notice that the URL to the javascript files seems incomplete.

All other paths in the header are formatted as src="http://mysite.com/blog/templates/some.js" but at the moment three paths to js files are just showing as;

Code: Select all

<script src="/blog/templates/2k11/admin/js/modernizr-2.8.3.min.js"></script>
    <script src="/blog/templates/jquery.js"></script>
    <script src="/blog/templates/2k11/admin/js/plugins.js"></script>
Not sure if this is normal and why the scripts could not be originally found?

Thanks again,

- Neil
NeilW
Regular
Posts: 51
Joined: Sat Jun 20, 2015 6:56 am
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by NeilW »

Hi Don,

Obviously the Freetag plugin was causing that initial "Error redirect", so I have uninstalled it and will worry about tags later.

Also, I notice that even when the full URL is not provided to the Java Scripts under different conditions, the scripts still work.

I am ahead of where I was last week through the very much appreciated assistance from onli, but the very last hump we have to get over has us both scratching our heads.

Up to the point of doing this, everything was working fine except I needed to bring my main menu into the blog page with Smarty so that I could then put custom header code above it.

So we put the following extra few lines into the Clean-Blog config.inc.php file to bring my php menu in as a Smarty variable.

Code: Select all

ob_start();
include('/home/mysite/public_html/global/includes/menu-bar.php');
$menuNeil = ob_get_contents();
ob_end_clean();
$serendipity['smarty']->assign('menuNeil', $menuNeil);
}
We then put the tag {$menuNeil} into the entries.tpl file.

That worked great on the blog pages. My menu worked fine and I could then put a Smarty tag above that to bring in my custom header code.

Everything was perfect, until I tried to open the backend Admin. When I did, it was trying to open my blog main menu. Why - the two code additions were in the Clean-Blog files, not the backend 2k11??? Anyway, it crashed entry to the backend.

So because the above blog menu only relates to the front end Clean-Blog, we have tried to tell s9y to only assign the menu to the Smarty variable $menuNeil if it is the front end being opened, not the backend. That is why I am looking for the if statement. Either if we are opening the front end blog, run the code to create the $menuNeil variable, or if we are opening the backend, don't run the code.

But this is where it gets really weird. :? The above code by itself brings the menu into the front end and crash's the back end.

I add your suggestion of...

Code: Select all

if ($serendipity['GET']['adminModule'] == 'templates' || $serendipity['POST']['adminModule'] == 'templates') {
... above the code and put a closing curly-brace at the bottom and I can get into the backend without problems - except it crashes when I try to enter the "Themes" menu.

The front end blog Menu does not render. - I think I can understand that because from my limited knowledge it looks like we are saying that if we are in the back end, run the code. So if the backend is bringing the code in without the IF statement and crashing before the log in screen, how come with an if statement saying to bring it in causes it not to crash except for at the theme menu?

So to try to tell s9y to only bring the code in if it is not the back end, I tried;

Code: Select all

if ($serendipity['GET']['adminModule'] !== 'templates' || $serendipity['POST']['adminModule'] !== 'templates') {
Great! Doing this now brings my front end menu into my blog. But the back end crashes again before log-in again.

NOTE: All these back end crashes are being caused by it trying to bring in my front end menu even though it apparently has no instruction to do so. From what I can figure out, the above code is only populating the $menuNeil variable - not telling it to be displayed.

It is only in the entries.tpl that we are using the {$menuNeil} tag. I am totally lost why the back end want's anything to do with it.

So mate, any help you can give me to get the back end to totally ignore my menu and for the front end to pick it up, would be greatly appreciated.

Cheers,

- Neil
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by onli »

Hi Neil
The freetag-error is annoying but probably unrelated. Deactivate the "Activate Find-tags-as-you-type" option in the plugins configuration.
NeilW wrote:All other paths in the header are formatted as src="http://mysite.com/blog/templates/some.js" but at the moment three paths to js files are just showing as;
Are the paths working, can you enter into the files?

*Edit*: I fear that Don misunderstood what you want. The if won't trigger only in the frontend, if i see that right, but in the template section, which is why you see the crash only there now.
NeilW
Regular
Posts: 51
Joined: Sat Jun 20, 2015 6:56 am
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by NeilW »

Thanks onli,

I will make that adjustment to the freetag plugin after reinstalling it.

It was probably more my phrasing of the question than Don misunderstanding it, but yes, we only want that code if we are in the front end blog. It has to be totally isolated from the back end.

But from what I have been doing to try to fix this myself I have the fear that the back end will still bring it in regardless - which, as I mentioned above, seems weird because we have not done anything to associate the $menuNeil variable with the back end.
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by onli »

NeilW wrote:But from what I have been doing to try to fix this myself I have the fear that the back end will still bring it in regardless - which, as I mentioned above, seems weird because we have not done anything to associate the $menuNeil variable with the back end.
Oh, call me confused. Thought that was clear to you? The problem is that on your server/setup, the ob_start() we are doing - that channels the include call into the variable - does not work. The menu is not emitted by the variable, it is echoed - printed out - by the include and thus by the config.inc.php.

I don't know why that happens, but that is the whole problem. If we could just fix that, we wouldn't even need the if.
NeilW
Regular
Posts: 51
Joined: Sat Jun 20, 2015 6:56 am
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by NeilW »

Hi confused, :lol:

Well one of us is anyway. :wink: No I really didn't realise that, which tends to explain a lot.

It would be interesting why it happens with particular servers.

The one I use is pretty much a standard commercially shared Linex server, so you would think that all things would be fairly normal.

I did notice that many of the sy9 scripts and pages that I have opened are Windoze formatted rather than Unix, so I would not be surprised if the server/setup for the scripts has been optimised for Windoze - hence the problem. :(
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by Don Chambers »

Would this work for the if condition:

Code: Select all

if (serendipity_userLoggedIn() && serendipity_checkPermission('adminTemplates')) {
// whatever
}
EDIT: But seems Onli is saying ob_start() is what isn't working..... hmmm..

Wouldn't it be a lot easier to modify the template's index.tpl to include a duplicate of the menu? I realize that is not ideal, but I also know it would work.
=Don=
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by onli »

The menu is generated by php-code that checks persmissions from the outer CMS, that is why it is not easy do to in the template. We could call those functions, set them as variables in smarty and then modify the entries.inc.tpl template to build the menu, right?

One thing that can cause ob_*() to fail is when the code after the ob_start() produces an php-error. Neil, is it possible that this is the problem, is the php-file failing somewhere? That should be emitted on those pages or in the log.

If there is nothing, you could try Don's if (it is a good try!) and if that does not work, I'd help you with smartifying the menu.
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by Don Chambers »

Onli has forgotten more about php than I will ever know....

but what if this whole thing was inside a function that was only ever called within the appropriate smarty tpl? This is probably overly complicated, but what if it looked something like this:

Code: Select all

function SiteWideMenu($menu_path) {
    ob_start();
    include($menu_path);
    $menuNeil = ob_get_contents();
    ob_end_clean();
    return $menuNeil;
}

$serendipity['smarty']->register_function('show_site_menu', 'SiteMenu');

function SiteMenu($params, &$smarty) {
        return SiteWideMenu($params['menu_path']);
}
Then in the smarty template, something like this to display the menu:

Code: Select all

{show_site_menu menu_path='/home/mysite/public_html/global/includes/menu-bar.php'}
This SHOULD eliminate any need for an if condition I think. I have no idea if that will actually work, but hopefully there is enough going on for one of the smarter coders to understand what I am trying to do with it.... :mrgreen:
=Don=
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by onli »

:D very nice idea, that should work indeed!
NeilW
Regular
Posts: 51
Joined: Sat Jun 20, 2015 6:56 am
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by NeilW »

Thanks guys,

That last idea sounds promising then as I still have back end failures to this point.

But being a newbie to all of this, can you please be specific as to exactly where I include that code?
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by Don Chambers »

NeilW wrote:Thanks guys,

That last idea sounds promising then as I still have back end failures to this point.

But being a newbie to all of this, can you please be specific as to exactly where I include that code?
in your theme's config.inc.php, in lieu of what you were using earlier.
=Don=
NeilW
Regular
Posts: 51
Joined: Sat Jun 20, 2015 6:56 am
Contact:

Re: How to get s9y to detect that it is in the backend?

Post by NeilW »

OK, yes just nutted that out, but the problem now is that the whole bloody thing seems to work perfectly now and I am not used to that! :lol: :lol:

Thanks guys it seems we have cracked it, I will push ahead now and hopefully all will remain good.
Post Reply