154 lines
5.8 KiB
PHP
154 lines
5.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Возвращает IP юзера.
|
|
* @return string
|
|
*/
|
|
function get_the_user_ip() {
|
|
if (
|
|
! empty( $_SERVER['HTTP_CLIENT_IP'] ) &&
|
|
filter_var($_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)
|
|
) {
|
|
//check ip from share internet
|
|
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
|
} elseif (
|
|
! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) &&
|
|
filter_var($_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)
|
|
) {
|
|
//to check ip is pass from proxy
|
|
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
} else {
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
|
}
|
|
return $ip;
|
|
}
|
|
|
|
/**
|
|
* Список игр.
|
|
*/
|
|
function gamelist($atts){
|
|
wp_enqueue_script(
|
|
'gamelist',
|
|
get_stylesheet_directory_uri() . '/js/gamelist.js',
|
|
array(
|
|
'jquery',
|
|
),
|
|
'1.0',
|
|
true
|
|
);
|
|
$nominations = array(
|
|
'основная номинация' => 'Основная номинация',
|
|
'перевод' => 'Переводы',
|
|
'вне конкурса' => 'Вне конкурса'
|
|
);
|
|
|
|
$a = shortcode_atts( array(
|
|
'action' => 'kril'.date('Y'),
|
|
), $atts );
|
|
$action = $a['action'];
|
|
$ip = get_the_user_ip();
|
|
$params = array(
|
|
'action' => $action,
|
|
'ip' => $ip,
|
|
);
|
|
$list = wp_remote_get('http://forum.ifiction.ru/extern.php?'.http_build_query($params));
|
|
$list = json_decode(wp_remote_retrieve_body($list));
|
|
|
|
$retval = '<p><div class="order-buttons btn-group btn-group-toggle" data-toggle="buttons">';
|
|
$retval .= '
|
|
<label class="btn btn-outline-info" role="button">
|
|
<input type="radio" name="order" value="name" autocomplete="off">
|
|
Алфавитный порядок
|
|
</label>
|
|
<label class="btn btn-outline-info" role="button">
|
|
<input type="radio" name="order" value="random" autocomplete="off">
|
|
Случайный порядок
|
|
</label>
|
|
<label class="btn btn-outline-info active" role="button">
|
|
<input type="radio" name="order" value="personal" autocomplete="off" checked>
|
|
Личный порядок
|
|
</label>
|
|
';
|
|
$retval .= '</div>';
|
|
$retval .= '<small>Личный порядок - это случайно перемешанный список, который всегда будет вашим.</small></p>';
|
|
$retval .= '<p>Быстрый переход по номинациям: <ul><li><a class="nQuickLink" href="#bookmark2">переводы</a></li><li><a class="nQuickLink" href="#bookmark3">игры вне конкурса</a></li></ul></p>';
|
|
$retval .= '<p>Чтобы проголосовать или прокомментировать игру, щёлкните на её название. Баллы также можно выставить в общем списке на <a href="http://forum.ifiction.ru/viewforum.php?id=36&list=2">форуме ifiction.ru.</a></p>';
|
|
|
|
$i = 1;
|
|
foreach ($list as $list_nom) {
|
|
$nomination = $nominations[$list_nom->category];
|
|
$games = $list_nom->games;
|
|
$retval .= '<small class="float-right"><a id="hideLink_'.$i.'" href="javascript:hideNom(\''.$i.'\')">(свернуть)</a></small>';
|
|
$retval .= '<h2 class="nNomination">'.$nomination.'</h2>';
|
|
$retval .= '<a name="bookmark'.$i.'"></a>';
|
|
$retval .= '<div class="gamelist gamelist_'.$i.'">';
|
|
$j = 0;
|
|
foreach ($games as $game) {
|
|
$j++;
|
|
$platform = $game->platform;
|
|
$title = $game->full_title;
|
|
$rating = $game->rating;
|
|
$url = $game->url;
|
|
$authors = $game->authors;
|
|
$description = $game->description;
|
|
$files = $game->files;
|
|
$thumbnail = NULL;
|
|
if (isset($game->posters) && isset($game->posters[0])) {
|
|
$thumbnail = $game->posters[0];
|
|
}
|
|
|
|
$retval .= '<div class="nKrilGame" data-order="'.$j.'">';
|
|
$retval .= '<div class="nGameHeader">';
|
|
if (isset($rating) && !empty($rating) && $rating !== '0+' && $rating !== '6+') {
|
|
$retval .= '<div class="nRating">'.$rating.'</div>';
|
|
}
|
|
$retval .= '<span class="nGameNum"></span>';
|
|
$retval .= '<div class="nGameName">'.
|
|
'<a target="_blank" href="'.$url.'">'.$title.'</a></div>';
|
|
$retval .= '<div class="nMeta">';
|
|
$retval .= '<p><span class="sr-only">Авторы:</span><span class="nAuthors">'.$authors.'</span></p>';
|
|
$retval .= '</div></div><div class="nGameInfo">';
|
|
$retval .= '<div class="nGamePic">';
|
|
if (isset($thumbnail) && !empty($thumbnail)) {
|
|
$retval .= '<p><img src="'.$thumbnail.'"></p>';
|
|
}
|
|
|
|
/*
|
|
switch ($platform) {
|
|
case 'INSTEAD':
|
|
$retval .= infoalert('Для запуска архива вам потребуется <a href="https://instead-hub.github.io/#download" target="_blank">интерпретатор INSTEAD.</a>');
|
|
break;
|
|
case 'FireURQ':
|
|
$retval .= infoalert('Для запуска архива вам потребуется <a href="https://ifwiki.ru/files/Fireurq.zip" target="_blank">интерпретатор FireURQ.</a>');
|
|
break;
|
|
}
|
|
*/
|
|
|
|
$retval .= '</div>';
|
|
$retval .= '<div class="nGameDescr">'.$description;
|
|
$retval .= '<p><strong>Платформа:</strong> '.$platform.'</p>';
|
|
$retval .= '<div class="nLinks">';
|
|
foreach ($files as $file) {
|
|
$subtitle = $file->subtitle;
|
|
if (!empty($subtitle)) {
|
|
$subtitle = str_replace('<p>', '', $subtitle);
|
|
$subtitle = str_replace('</p>', '', $subtitle);
|
|
}
|
|
$retval .= '<p><a href="'.$file->url.'" target="_blank">'.$file->title.'</a>';
|
|
if (!empty($subtitle)) {
|
|
$retval .= '<br><small>'.$subtitle.'</small>';
|
|
}
|
|
$retval .= '</p>';
|
|
}
|
|
$retval .= '</div></div></div></div>';
|
|
} // end foreach game
|
|
$retval .= '</div>';
|
|
$i++;
|
|
} // end foreach nomination
|
|
return $retval;
|
|
}
|
|
|
|
function infoalert($text) {
|
|
return '<p class="alert alert-info"><small>'.$text.'</small></p>';
|
|
}
|