Accessing value of "secure"-checkbox in templates

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Foaly*
Translator
Translator
Posts: 150
Joined: Sun Mar 29, 2009 3:32 pm
Location: London

Accessing value of "secure"-checkbox in templates

Post by Foaly* »

Hi.

First of all: right board?

There's a new checkbox for (de)activating HTTPS in the options-tab of a page's edit mask. (How) can I access the value in templates? Do I have to use a UDT?

Image

CMS Made Simple 1.7.1 "Escada"
Last edited by Foaly* on Thu Jun 03, 2010 3:58 pm, edited 1 time in total.
NaN

Re: Accessing value of "secure"-checkbox in templates

Post by NaN »

Try this:

Code: Select all


{$content_obj->Secure()}

or

Code: Select all


{$content_obj->mSecure}

soundZ
Forum Members
Forum Members
Posts: 14
Joined: Fri Nov 14, 2008 6:24 am

Re: Accessing value of "secure"-checkbox in templates

Post by soundZ »

Hm... that's interesting... Is there also an easy way to read read this value (mSecure) in PHP in a userdefined tag?

Thanks
soundZ
NaN

Re: Accessing value of "secure"-checkbox in templates

Post by NaN »

Since it is a template var you can pass it as a param to an UDT:

Code: Select all


{your_udt content_obj=$content_obj}

and in your UDT you can access it

Code: Select all


$secure = $params['content_obj']->Secure();

I'm pretty sure there is another - better - way to do this but since in future CMSms releases many methods and properties of the core will be declared as private i'm not sure what function should be used here.

Don't use the mSecure variable because this will be such a private var that won't be accessible from outside of the content object context in further releases. Anyway i'm even not sure if the Secure() function will be accessible in new CMSms releases. Hope some of the devs can clearify this.
Accessing content object related properties may be useful for plugins or modules. So i hope there will be a way to access those even in new releases.
soundZ
Forum Members
Forum Members
Posts: 14
Joined: Fri Nov 14, 2008 6:24 am

Re: Accessing value of "secure"-checkbox in templates

Post by soundZ »

Hey NaN!

Many thanks for your quick hint! That's a nice trick and it helped me solving an annoying SSL-bug:

When switching back from an HTTPS page to an HTTP page, the HTTPS stays alive... :(
The following tag is a workaround for this problem. I hope in new releases of CMSms the bug will be solved so it's not important (for this case) if the Secure() method will be public or private  8)

Here's the tag code (create a file 'function.sslbugfix.php' and copy it to 'plugins' in your CMSms installation or create a UDT:

Code: Select all

function smarty_cms_function_sslbugfix($params){
    $page_secure = $params['content_obj']->Secure();
    if($page_secure == 0 && isset($_SERVER['HTTPS'])){
        $httpurl = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        header("location: $httpurl");
        die();
    }
}
At the very top of your template insert:

Code: Select all

{sslbugfix content_obj=$content_obj}
That's it :-)

I'm sure that there are much nicer and cleaner ways to do it, but I can't find them ;D Maybe someone can use this snippet of code, maybe not... :-)

Thanks again for the help
soundZ
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Accessing value of "secure"-checkbox in templates

Post by calguy1000 »

...That's a nice trick and it helped me solving an annoying SSL-bug: When switching back from an HTTPS page to an HTTP page, the HTTPS stays alive...
@soundZ You have provided ABSOLUTELY NO INFORMATION, and there have been no bug reports filed (as of this date) regarding SSL functionality in CMSMS.  Additionally, the SSL functionality in recent versions of CMSMS is working to my knowledge without complaint, so before you use the word 'bug', in association with CMSMS please provide sufficient information to allow the dev team to reproduce your problem.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
soundZ
Forum Members
Forum Members
Posts: 14
Joined: Fri Nov 14, 2008 6:24 am

Re: Accessing value of "secure"-checkbox in templates

Post by soundZ »

Hey calguy1000,

sorry I thought the problem is known 'cause there are other users (in the german section of this forum) trying to solve the problem. But you're right: I haven't checked any bug lists or so  ;D (Where would be the right place to do so?)

The problem in detail:
I've a brandnew 1.8.2 "Toliara" installation.
Some pages of the new site are marked as 'https' in the backend, others are not.
By clicking an https-marked page in the site menu the specific https-url (ssl_url) is called as root. That works very well!
But from now on ALL page links (for example in the pagemenu) on the https-page are based on the ssl_url. So you stay in ssl-mode, even if you are clicking a page NOT marked as 'https' in the backend.

I hope that's helpfull somehow...
thanks and greetings from germany
soundZ
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Accessing value of "secure"-checkbox in templates

Post by jmcgin51 »

soundZ wrote: I haven't checked any bug lists or so  ;D (Where would be the right place to do so?)
http://dev.cmsmadesimple.org/projects/cmsmadesimple
jomoweb
Forum Members
Forum Members
Posts: 49
Joined: Wed Jan 31, 2007 9:27 pm

Re: Accessing value of "secure"-checkbox in templates

Post by jomoweb »

I had the same issue today, and submitted a bug.  This looks like just a matter of using relative links.

If you click on the relative link from an https:// page, the https:// will stay there.  I also get an error when I navigate away that the page uses items that are not secure in most browsers.
soundZ
Forum Members
Forum Members
Posts: 14
Joined: Fri Nov 14, 2008 6:24 am

Re: Accessing value of "secure"-checkbox in templates

Post by soundZ »

Oh, I'm a little bit late... and I see, I'm not alone with the 'bug'...

As I can read, the problem will be fixed in the next release of CMSms, thanks for that in special and the great work on CMSms in general!
soundZ
Post Reply

Return to “CMSMS Core”