Hello World - CSS and JS ?

Kevin B Posted in Technical Support 4 years ago

Hi there
Downloaded and installed "Hello World" successfully.
Code looks quite self explanatory, but it doesn't seem to be loading any CSS in the headers?

I've only added a basic: body { background-color: #ff0000; } to both:

css\helloworld.php
css\standalone\helloworld.php

I wasn't sure if it was supposed to be encapsulated in:

.hello-world-css {
 //css goes here
}

So tried it inside and out as below:

.hello-world-css {
 //css goes here
 body {
    background-color: #ff0000;
 }
}
body {
    background-color: #ff0000;
}

But the localhost\hello only shows the text "Hello World". As you can see from the attached, the <head> tags are not populated with anything?

Screenshot of Hello World unstyled

Latest version of OSSN and downloaded component from this site.

My aim is to have a completely new page running (without any of the system bars / menus / styling etc) with its own styling / css / java etc. But remain within the OSSN environment so I can fetch user names and send messages etc.

This was just to see how to integrate my own stuff.

Replies
gb Kevin B Replied 4 years ago

Oh!!! Sorry, I didn't get what you were saying. I understand now. I need to manually add the "api" into the "allowed_pages" array.

I just did that, and it works perfectly now, thank you again :)
So I just need to remember to make that tweak again in future if the component is ever updated.

My last question.... when I access a custom page, and Private Network redirects me to the logon page, it doesn't return me to the custom page (referrer URL) and just logs me in to the main site.

Can the Private Network component be updated to redirect to the referrer URL ?

German Michael Zülsdorff Replied 4 years ago

Although you added 'api' like

    private function allowed_Pages($part) {
            $pages = array(
                    // *1* OSSN allowed core pages
                    // only first part of url will be checked
                    array(
                        'css',
                        'js',
                        'action',
                        'administrator',
                        'uservalidate',
                        'resetlogin',
                        'index',
                        'login',
                        'avatar',
                        'userverified',
                        'two_factor_login',
                        'captcha',
                        'sharedblogs',
                        'api',
                    ),
gb Kevin B Replied 4 years ago

Hopefully this will help demonstrate:
Logged OUT using 5.1 (works fine)
Logged OUT using 5.1 (works fine)

Logged IN using 5.1 (not working)
Logged IN using 5.1 (not working)

Logged IN using 5.0 (working fine)
Logged IN using 5.0 (working fine)

gb Kevin B Replied 4 years ago

Nope. Thought it was an old variable in there - but its all correct.

I don't think I have explained it very well, as it no longer has anything to do with the order of checking/loading. That part is working perfectly now.

It has broken the API though.

With Private Network 5.0 installed - the API call returns data fine.
With Private Network 5.1 installed - the API call returns blank. Not even any errors.

This is whilst successfully logged on, and displaying the page correctly.

The "ossnloggedinuser()" function works fine as I can display the user photo and name. It is just the API that is coming back blank.

gb Kevin B Replied 4 years ago

I may have figured it out...

German Michael Zülsdorff Replied 4 years ago

There must be something in the 5.1 update that is affecting the API callback?

Yes, as noted in the release note:
The logic has changed from page loading->checking to page checking->loading.
Thus, if your script isn't executed by a logged-in user then Private Network 5.1 won't allow to load your page anymore
as long as it's not listed in the allowed_pages array.

gb Kevin B Replied 4 years ago

Hi ~Z~ Man,
Thanks for the response. I have installed the updated component, and it does indeed fix the issue.

It has, however, created a completely new one i'm afraid.

This basic curl script no longer works:

$apiKey = "{my-key}";
$recentURL = "http://10.48.1.28/api/v1.0/message_recent?";
$recentPARAM = array( 'api_key_token' => $apiKey , 'guid' => $chatUser->guid );

function CallAPI ($url,$post) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    return json_decode($result);
}

$recentMessages = CallAPI ($recentURL , $recentPARAM);

If I manually run the url directly in the browser, it returns the JSON results fine. Within the web page - its not returning any results - but its not returning any errors either. I spent about 30 minutes troubleshooting, checking PHP and Apache logs, and the OSSN error_log... to no avail.

I then deleted the Private Network component, reinstalled version 5.0 - and it works as expected.

Just to rule out a fluke, I again removed 5.0, installed 5.1 - and the API is not working again. Removed it once more, installed 5.0, and its working fine again.

There must be something in the 5.1 update that is affecting the API callback?

German Michael Zülsdorff Replied 4 years ago

I'm sorry, Kevin, I wasn't quite up-to-date:
The necessary core feature was already available with Ossn 5.3.
All you need is updating Private Network to 5.1

gb Kevin B Replied 4 years ago

Ok that's great thank you.

German Michael Zülsdorff Replied 4 years ago

Kevin,
there'll be a fix for that in Ossn 5.6.
Until then, you need to care about uninitialized objects yourself like

if(ossn_loggedin_user()) {
  echo ossn_loggedin_user()->iconURL()->small;
  .....
  .....
}