SimplePortal

Customization => Custom Coding => Topic started by: ataru on April 16, 2015, 06:17:30 AM

Title: Time enabled block
Post by: ataru on April 16, 2015, 06:17:30 AM
I'd like to enable a block during determined periods.
e.g. Sunday, 26th March, from 3 PM to 5 PM

Is there any simple way to do that automatically?
Title: Re: Time enabled block
Post by: Chen Zhen on April 16, 2015, 03:50:34 PM
ataru,

  If it is a custom PHP block which has the title hidden then you can do that within the PHP code of the block.
Otherwise it will involve manual edits or perhaps a plug-in.

Is this a custom PHP block?

Regards.
Title: Re: Time enabled block
Post by: ataru on April 20, 2015, 08:12:29 AM
it's a shoutbox block.

there's no way to nest a shoutbox block into a php block, right?


ok. found it:

http://simpleportal.net/index.php?topic=5332.0
Title: Re: Time enabled block
Post by: ataru on April 20, 2015, 10:41:07 AM
How I did it:


Code: [Select]
$dataeorainizio = '2015-04-20 14:35:00'; //time to start displaying block
$minutididurata = '120'; //time (in minutes) to show block
$titoloblocco = 'A Title for this Block';
$iddelblocco = "50"

$dataoraadesso= new DateTime();
$dataoraavvioblocco = new DateTime($dataeorainizio);
$dataorachiusurablocco = new DateTime($dataeorainizio);
$dataorachiusurablocco->add(new DateInterval('PT'. $minutididurata . 'M'));
//echo $dataoraadesso->format('Y-m-d H:i:s');
//echo "<br>".$dataoraavvioblocco->format('Y-m-d H:i:s');
//echo "<br>".$dataorachiusurablocco->format('Y-m-d H:i:s').'<br>';

if ($dataoraadesso > $dataoraavvioblocco) {
    if ($dataorachiusurablocco > $dataoraadesso) {
        //echo 'show that block';
        $block = current(getBlockInfo(false, $iddelblocco, false, false));  // Load block info
        $block['label'] = $titoloblocco;
        $block['style'] = sportal_parse_style('explode', $block['style'], true);  //Parse block style parameters.
        template_block($block); // Output the block.
    } else {
        //echo 'too late';
    }
} else {
    //echo 'early';
}

;D
Title: Re: Time enabled block
Post by: ♦ Ninja ZX-10RR ♦ on April 20, 2015, 01:11:18 PM
Just LOL for the variables in Italian :P I am Italian too :) Glad that you sorted it!
Title: Re: Time enabled block
Post by: ataru on April 20, 2015, 06:21:49 PM
it's hard to duplicate some variables this way  ;)
SimplePortal 2.3.8 © 2008-2024, SimplePortal