Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
How to check if user is logged in?
I've got a problem that's above my head and would appreciate some help. On http://idrinkyourmilkshake.com, I've embedded a sound file in menu.php, like this:
<embed src="milkshake.mp3" align="absmiddle" autostart="true" width="225" height=16><noembed><bgsound src="milkshake.mp3" autostart="true" width="225" height=20></noembed><br>
It's set to autoplay because people who come by the site the first time expect to hear the clip -- I really don't want to lose that.
BUT as you can imagine, having the file play on every refresh gets really old when you're browsing and posting the discussions. So, I'm looking for a way to check if the user is logged in, and if so, I'd like to embed the same thing with autostart turned off.
Can somebody tell me what the code would be for menu.php to check if the user is logged in and then display either version of the embed code?
Thank you much!
0
This discussion has been closed.
Comments
See how the banner works here.
Somewhere in the Render function, you'll type:
if ( $this->Context->Session->UserID == 0 ) {...}
If not, just paste your final code here, in html and between <code> tags.
It should end like this (tested: your html code is echoed correctly):
<?php /* Extension Name: Embed Sound For Guests Extension Url: http://lussumo.com/community Description: Embeds a sound file in pages viewed by guests. Version: 0.0.1 Author: Grahack Author Url: n/a */ // embed the sound only in the following pages $SoundPages = array( 'index.php', 'categories.php', 'comments.php', 'search.php' ); // name or path of the sound file, as in src="???" define( 'SoundFile', 'milkshake.mp3' ); if ( in_array($Context->SelfUrl, $SoundPages )) { class EmbedSound extends Control { function EmbedSound( &$Context ) { $this->Name = 'EmbedSound'; $this->Control( $Context ); } function Render() { if ($this->Context->Session->UserID > 0) $Guest = false; else $Guest = true; echo "\n"; echo '<embed src="'.SoundFile.'" align="absmiddle" autostart="'.($Guest?'true':'false').'" width="225" height=16 />'; echo "\n"; echo '<noembed><bgsound src="'.SoundFile.'" autostart="'.($Guest?'true':'false').'" width="225" height=20></noembed><br>'; echo "\n"; } } $EmbedSound = new EmbedSound($Context); $Page->AddRenderControl($EmbedSound, $Configuration["CONTROL_POSITION_HEAD"]+1); }
I allowed myself to close the embed tag the short way (html validation).
You have to configure the pages where you want to here the sound and the name of the file.
If it works, I'll upload it for the community.
HOW
Yes it's the content of a classical default.php file that you'll have to create in an EmbedSoundForGuests folder, under the extensions folder. Then settings, extensions, activation with the checkbox, as usual. You can go ahead, it shouldn't break your site, maybe you'll have to correct the path to your sound file.
WHERE
CONTROL_POSITION_HEAD + 1 seems to place the embed tag right after the body tag.
FINAL CODE
That was before I decided to code it. I left it because it's always (quite) true: people here can test little and simple bits of code for you.
But the quickest way to test is to install a local server on your machine.
So does it work well now?
<?php /* Extension Name: Embed Sound For Guests Extension Url: http://lussumo.com/community Description: Embeds a sound file in pages viewed by guests. Version: 0.0.1 Author: Grahack Author Url: n/a */ // embed the sound only in the following pages $SoundPages = array( 'index.php', 'categories.php', 'comments.php', 'search.php' ); // name or path of the sound file, as in src="???" define( 'SoundFile', 'milkshake.mp3' ); if ( in_array($Context->SelfUrl, $SoundPages )) { class EmbedSound extends Control { function EmbedSound( &$Context ) { $this->Name = 'EmbedSound'; $this->Control( $Context ); } function Render() { if ($this->Context->Session->UserID > 0) $Guest = false; else $Guest = true; echo "\n"; echo '<div align="center"><br><embed src="'.SoundFile.'" align="absmiddle" autostart="'.($Guest?'true':'false').'" width="225" height=16 />'; echo "\n"; echo '<noembed><bgsound src="'.SoundFile.'" autostart="'.($Guest?'true':'false').'" width="225" height=20></noembed></div>'; echo "\n"; } } $EmbedSound = new EmbedSound($Context); $Page->AddRenderControl($EmbedSound, $Configuration["CONTROL_POSITION_MENU"]+1); }
There's nothing bad that can happen!
// Vanilla Control Positions $Configuration['CONTROL_POSITION_HEAD'] = '100'; $Configuration['CONTROL_POSITION_MENU'] = '200'; $Configuration['CONTROL_POSITION_BANNER'] = '200'; $Configuration['CONTROL_POSITION_PANEL'] = '300'; $Configuration['CONTROL_POSITION_NOTICES'] = '400'; $Configuration['CONTROL_POSITION_BODY_ITEM'] = '500'; $Configuration['CONTROL_POSITION_FOOT'] = '600'; $Configuration['CONTROL_POSITION_PAGE_END'] = '700';
Vanilla controls are printed after being sorted. The extension we wrote together just adds a new control. You just have to find the right value.