1
difenduandada
2024-10-15 7fd2948ee35c8e147ed35ce6d8502f94a98ddd22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
 
require_once( TEMPLATE_PATH . '/functions.php' );
 
// if ( !isset($_GET['slug']) || !$_GET['slug'] ) {
//     require( ABSPATH . 'includes/page-homepage.php' );
//     return;
// }
 
if(count($url_params) != 2){
    // The number of parameter is not match
    require( ABSPATH . 'includes/page-404.php' );
    return;
}
 
$_GET['slug'] = htmlspecialchars($_GET['slug']);
 
Game::update_views( $_GET['slug'] );
$game = Game::getBySlug( $_GET['slug'] );
 
if($game && !$game->published){
    // This game is drafted
    if(is_login() && USER_ADMIN){
        // Show message for admin user
        echo '<div class="alert alert-warning alert-draft" style="z-index: 1000;">The game has not been published yet and is currently in draft mode.</div>';
    } else {
        $game = null;
        // Show 404 page for visitor
    }
}
 
if($game){
    if($lang_code != 'en'){
        // If use translation (localization)
        // Begin translate the content if has translation
        $translated_fields = get_content_translation('game', $game->id, $lang_code, 'all');
        if(!is_null($translated_fields)){
            $game->title = isset($translated_fields['title']) ? $translated_fields['title'] : $game->title;
            $game->description = isset($translated_fields['description']) ? $translated_fields['description'] : $game->description;
            $game->instructions = isset($translated_fields['instructions']) ? $translated_fields['instructions'] : $game->instructions;
        }
    }
    
    $page_title = $game->title . ' | '.SITE_DESCRIPTION;
    $meta_description = str_replace(array('"', "'"), "", strip_tags($game->description));
 
    require( TEMPLATE_PATH . '/game.php' );
} else {
    require( ABSPATH . 'includes/page-404.php' );
}
 
?>