-
-
Notifications
You must be signed in to change notification settings - Fork 19
Adding Index Page Blocks
To properly add a block to the index page, you need to do several things.
I'll use the radio block that was removed on Dec 1, 2018.
In admin/block.settings.php add:
$contents[] = "
<div class='w-100'>{$lang['block_radio']}</div>
<div class='slideThree'>
<#radio_on#>
</div>
<div class='w-100'>{$lang['block_radio_set']}</div>";
after the last $contents item in section identified with:
<fieldset id='user_blocks_index' class='header'>
Adding this allows the staff to enable/disable the block.
Add the following to public/user_blocks.php:
if (isset($_POST['radio'])) {
$setbits_index_page |= block_index::RADIO;
} else {
$clrbits_index_page |= block_index::RADIO;
}
In the section of 'block_index', then add:
$checkbox_index_radio = (($user['blocks']['index_page'] & block_index::RADIO) ? ' checked' : '');
In the section '//==Index' checkboxes are, then add:
if ($BLOCKS['radio_on']) {
$contents[] = "
<div class='w-100'>Enable Radio?</div>
<div class='slideThree'>
<input type='checkbox' id='radio' name='radio' value='yes' $checkbox_index_radio>
<label for='radio'></label>
</div>
<div class='w-100'>Check this option if you want to enable the site radio.</div>";
}
after the last $contents item in section identified with:
$level1
Adding this allows the user to enable/disable the block.
Create the file blocks/index/radio.php with the contents:
<?php
require_once ROOT_DIR . 'radio.php';
$site_radio .= "
<a id='radio-hash'></a>
<div id='radio' class='box'>
<div class='bordered'>
<div class='alt_bordered bg-00 has-text-centered'>" . radioinfo($radio) . '
</div>
</div>
</div>';
Add the block information to public/index.php
if (in_array('site_radio', $available_columns) && $user['blocks']['index_page'] & block_index::RADIO && $BLOCKS['radio_on']) {
include_once BLOCK_DIR . 'index' . DIRECTORY_SEPARATOR . 'radio.php';
}
Then add the block to any of the 5 column arrays:
$above_columns = []; // shows above the 3 main columns
$below_columns = []; // shows below the 3 main columns
$left_column = []; // left column, can be empty
$center_column = []; // center column, can not be empty
$right_column = []; // right column, can not be empty
Create the file public/radio_popup.php
<?php
require_once dirname(__FILE__, 2) . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'bittorrent.php';
require_once INCL_DIR . 'user_functions.php';
require_once INCL_DIR . 'html_functions.php';
check_user_status();
$lang = load_language('global');
require_once ROOT_DIR . 'radio.php';
global $CURUSER, $site_config;
$body_class = 'background-16 h-style-9 text-9 skin-2';
$HTMLOUT = doc_head() . "
<meta property='og:title' content='{$site_config['site_name']}'>
<title>{$site_config['site_name']} Radio</title>
<link rel='stylesheet' href='" . get_file_name('vendor_css') . "'>
<link rel='stylesheet' href='" . get_file_name('css') . "'>
<link rel='stylesheet' href='" . get_file_name('main_css') . "'>
</head>
<body class='$body_class has-text-centered'>
<script>
var theme = localStorage.getItem('theme');
if (theme) {
document.body.className = theme;
}
function roll_over(img_name, img_src) {
document[img_name].src=img_src;
}
</script>
<h2>{$site_config['site_name']} Site Radio</h2>
<div>
<a href='http://{$radio['host']}:{$radio['port']}/listen.pls' onmouseover=\"roll_over('winamp', '{$site_config['pic_baseurl']}winamp_over.png')\" onmouseout=\"roll_over('winamp', '{$site_config['pic_baseurl']}winamp.png')\">
<img src='{$site_config['pic_baseurl']}winamp.png' name='winamp' alt='Click here to listen with Winamp' title='Click here to listen with Winamp'>
</a>
<a href='http://{$radio['host']}:{$radio['port']}/listen.asx' onmouseover=\"roll_over('wmp', '{$site_config['pic_baseurl']}wmp_over.png')\" onmouseout=\"roll_over('wmp', '{$site_config['pic_baseurl']}wmp.png')\">
<img src='{$site_config['pic_baseurl']}wmp.png' name='wmp' alt='Click here to listen with Windows Media Player' title='Click here to listen with Windows Media Player'>
</a>
</div>" . radioinfo($radio) . "
<div class='has-text-centered'>
<a class='altlink' href='javascript: window.close()'><b>[ Close window ]</b></a>
</div>
</body>
</html>";
echo $HTMLOUT;
Since this uses some javascript to open a modal, add this to scripts/replaced.js:
function radio() {
PopUp('radio_popup.php', 'My Radio', 800, 700, 1, 0);
}
Then create the file radio.php:
<?php
$radio = [
'host' => '',
'port' => '',
'password' => '',
];
$langs = [
'CURRENTLISTENERS' => 'Current listeners: <b>%d</b>',
'SERVERTITLE' => 'Server: <b>%s</b>',
'SERVERURL' => 'Server url: <b>%s:' . $radio['port'] . '</b>',
'SONGTITLE' => 'Current song: <b>%s</b>',
'BITRATE' => 'Bitrate: <b>%s kb</b>',
'BITRATE' => 'Bitrate: <b>%s kb</b>',
'PEAKLISTENERS' => 'Peak listeners: <b>%d</b>',
];
/**
* @param $radio
*
* @return string
*/
function radioinfo($radio)
{
global $langs, $site_config, $CURUSER, $cache;
$xml = $html = $history = '';
if ($hand = @fsockopen($radio['host'], $radio['port'], $errno, $errstr, 30)) {
fputs($hand, 'GET /admin.cgi?pass=' . $radio['password'] . "&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla/5.0 " . "(Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6\n\n");
while (!feof($hand)) {
$xml .= fgets($hand, 1024);
}
preg_match_all('/\<(SERVERTITLE|SERVERURL|SONGTITLE|STREAMSTATUS|BITRATE|CURRENTLISTENERS|PEAKLISTENERS)\>(.*?)<\/\\1\>/iU', $xml, $tempdata, PREG_SET_ORDER);
foreach ($tempdata as $t2) {
$data[$t2[1]] = isset($langs[$t2[1]]) ? sprintf($langs[$t2[1]], $t2[2]) : $t2[2];
}
unset($tempdata);
preg_match_all('/\<SONG>(.*?)<\/SONG\>/', $xml, $temph);
unset($temph[0][0], $temph[1]);
$history = [];
foreach ($temph[0] as $temph2) {
preg_match_all('/\<(TITLE|PLAYEDAT)>(.*?)<\/\\1\>/i', $temph2, $temph3, PREG_PATTERN_ORDER);
$history[] = '<b> ' . $temph3[2][1] . '</b> <sub>(' . get_date($temph3[2][0], 'DATE') . ')</sub>';
}
preg_match_all('/\<HOSTNAME>(.*?)<\/HOSTNAME>/', $xml, $temph);
if (!empty($temph[1]) && count($temph[1])) {
$users_ip = implode(', ', array_map('sqlesc', $temph[1]));
}
if ($data['STREAMSTATUS'] == 0) {
return 'Sorry ' . $CURUSER['username'] . '... : Server ' . $radio['host'] . ' is online but there is no stream';
} else {
unset($data['STREAMSTATUS']);
$md5_current_song = md5($data['SONGTITLE']);
$current_song = $cache->get('current_radio_song');
if ($current_song === false || $current_song != $md5_current_song) {
//autoshout(str_replace(array('<','>'),array('[',']'),$data['SONGTITLE'].' playing on '.strtolower($data['SERVERTITLE']).' - '.strtolower($data['SERVERURL'])));
$cache->set('current_radio_song', $md5_current_song, 0);
}
$html = '<fieldset>
<legend>' . $site_config['site_name'] . ' Radio</legend><ul>';
foreach ($data as $d) {
$html .= '<li><b>' . $d . '</b></li>';
}
$html .= '<li><b>Playlist history: </b> ' . (count($history) > 0 ? implode(', ', $history) : 'No playlist history') . '</li>';
if (empty($users_ip) === false) {
$q1 = sql_query('SELECT id, username FROM users WHERE ip IN (' . $users_ip . ') ORDER BY username ASC') or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($q1) == 0) {
$html .= '<li><b>Listeners</b>: currently no listener from site </li>';
} else {
$users = [];
while ($a1 = mysqli_fetch_assoc($q1)) {
$users[] = format_username($a1['id']);
}
$html .= '<li><b>Listeners</b>: ' . implode(', ', $users) . '</li>';
}
}
$html .= '</ul></fieldset>';
return $html;
}
} else {
$html .= '
<h2>' . $site_config['site_name'] . ' Radio</h2>
<span class="size_3 has-text-danger">
<img src="' . $site_config['pic_baseurl'] . 'off1.gif" alt="Off-Line" class="tooltipper" title="Off-Line" border="0"><br>
<b>Sorry ' . $CURUSER['username'] . ', the radio is currently offline</b>
</h2>';
}
return $html;
}
And finally add a link to the file templates/1/navbar.php:
<li class='iss_hidden'><a href='#' onclick='radio();'>{$lang['gl_radio']}</a></li>
in the section identified by:
general_links
Because this added a bit of javascript, you will need to recreate the needed files by running:
php bin/uglify.php