generate_game_description()   F
last analyzed

Complexity

Conditions 20
Paths 2592

Size

Total Lines 87
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 20
eloc 39
nc 2592
nop 8
dl 0
loc 87
rs 0
c 1
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/***************************************************************************
3
 *                                games_detail.php
4
 *                            ------------------------------
5
 *   begin                : Thursday, 20 July, 2017
6
 *   copyright            : (C) 2017 Atari Legend
7
 *   email                : [email protected]
8
 *
9
 *   Id: games_detail.php,v 0.10 20/07/2017 17:37 STG
10
 ****************************************************************************/
11
12
//****************************************************************************************
13
// This is the detail page of a game.
14
//****************************************************************************************
15
16
//load all common functions
17
require "../../config/common.php";
18
require_once __DIR__."/../../common/DAO/GameReleaseDAO.php";
19
require_once __DIR__."/../../common/DAO/GameSeriesDAO.php";
20
require_once __DIR__."/../../common/DAO/ResolutionDAO.php";
21
require_once __DIR__."/../../common/DAO/SystemDAO.php";
22
require_once __DIR__."/../../common/DAO/PubDevDAO.php";
23
require_once __DIR__."/../../common/DAO/LocationDAO.php";
24
require_once __DIR__."/../../common/DAO/ProgrammingLanguageDAO.php";
25
require_once __DIR__."/../../common/DAO/GameGenreDAO.php";
26
require_once __DIR__."/../../common/DAO/PortDAO.php";
27
require_once __DIR__."/../../common/DAO/EngineDAO.php";
28
require_once __DIR__."/../../common/DAO/ControlDAO.php";
29
require_once __DIR__."/../../common/DAO/GameReleaseAkaDAO.php";
30
require_once __DIR__."/../../common/DAO/LanguageDAO.php";
31
require_once __DIR__."/../../common/DAO/EmulatorDAO.php";
32
require_once __DIR__."/../../common/DAO/TrainerOptionDAO.php";
33
require_once __DIR__."/../../common/DAO/MemoryDAO.php";
34
require_once __DIR__."/../../common/DAO/TosDAO.php";
35
require_once __DIR__."/../../common/DAO/CopyProtectionDAO.php";
36
require_once __DIR__."/../../common/DAO/DiskProtectionDAO.php";
37
require_once __DIR__."/../../common/DAO/SoundHardwareDAO.php";
38
require_once __DIR__."/../../common/DAO/GameProgressSystemDAO.php";
39
require_once __DIR__."/../../common/DAO/GameReleaseScanDAO.php";
40
require_once __DIR__."/../../common/DAO/GameDAO.php";
41
require_once __DIR__."/../../common/DAO/MediaDAO.php";
42
43
$gameReleaseDao = new \AL\Common\DAO\GameReleaseDAO($mysqli);
44
$gameSeriesDao = new \AL\Common\DAO\GameSeriesDAO($mysqli);
45
$resolutionDao = new \AL\Common\DAO\ResolutionDao($mysqli);
46
$systemDao = new \AL\Common\DAO\SystemDao($mysqli);
47
$pubDevDao = new \AL\Common\DAO\PubDevDAO($mysqli);
48
$locationDao = new \AL\Common\DAO\LocationDAO($mysqli);
49
$programmingLanguageDao = new \AL\Common\DAO\ProgrammingLanguageDAO($mysqli);
50
$gameGenreDao = new \AL\Common\DAO\GameGenreDAO($mysqli);
51
$portDao = new \AL\Common\DAO\portDAO($mysqli);
52
$engineDao = new \AL\Common\DAO\engineDAO($mysqli);
53
$controlDao = new \AL\Common\DAO\controlDAO($mysqli);
54
$gameReleaseAkaDao = new \AL\Common\DAO\GameReleaseAkaDAO($mysqli);
55
$languageDao = new \AL\Common\DAO\LanguageDAO($mysqli);
56
$emulatorDao = new \AL\Common\DAO\EmulatorDAO($mysqli);
57
$trainerOptionDao = new \AL\Common\DAO\TrainerOptionDAO($mysqli);
58
$memoryDao = new \AL\Common\DAO\MemoryDAO($mysqli);
59
$tosDao = new \AL\Common\DAO\TosDAO($mysqli);
60
$copyProtectionDao = new \AL\Common\DAO\CopyProtectionDAO($mysqli);
61
$diskProtectionDao = new \AL\Common\DAO\DiskProtectionDAO($mysqli);
62
$soundHardwareDao = new \AL\Common\DAO\SoundHardwareDAO($mysqli);
63
$gameProgressSystemDao = new \AL\Common\DAO\GameProgressSystemDAO($mysqli);
64
$gameReleaseScanDao = new \AL\Common\DAO\GameReleaseScanDAO($mysqli);
65
$gameDao = new \AL\Common\DAO\GameDAO($mysqli);
66
$mediaDao = new \AL\Common\DAO\MediaDAO($mysqli);
67
68
/**
69
 * Generates an SEO-friendly description of a game, depending on the data available
70
 *
71
 * @param $game_name Name of the game
0 ignored issues
show
Bug introduced by
The type Name was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
 * @param $game_akas Optional names the game is known as
0 ignored issues
show
Bug introduced by
The type Optional was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
73
 * @param $game_releases Game releases
0 ignored issues
show
Bug introduced by
The type Game was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
74
 * @param $game_genres Genre(s) the game belong to
0 ignored issues
show
Bug introduced by
The type Genre was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
75
 * @param $game_developers Developer(s) of the game
0 ignored issues
show
Bug introduced by
The type Developer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
76
 * @param $screenshots Number of screenshots available
77
 * @param $boxscans Number of boxscans available
78
 * @param $reviews Number of reviews available
79
 * return A text description of the game
80
 */
81
function generate_game_description(
82
    $game_name,
83
    $game_akas,
84
    $game_releases,
85
    $game_genres,
86
    $game_developers,
87
    $screenshots,
88
    $boxscans,
89
    $reviews
90
) {
91
    $desc = "$game_name is a ";
92
93
    if ($game_genres) {
94
        for ($i = 0; $i < count($game_genres); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
95
            $desc .= strtolower($game_genres[$i]->getName());
96
            if ($i+1 < count($game_genres)) {
97
                $desc .= ", ";
98
            }
99
        }
100
        $desc .= " ";
101
    }
102
103
    $desc .= "game for the Atari ST ";
104
105
    if ($game_developers) {
106
        $desc .= "developed by ".join(", ", $game_developers)." ";
107
    }
108
109
    if ($game_releases) {
110
        $years = [];
111
        foreach ($game_releases as $release) {
112
            if ($release->getDate()) {
113
                $year = date("Y", strtotime($release->getDate()));
114
                if ($release->getPublisher() != null) {
115
                    $years[] = $year." (by ".$release->getPublisher()->getName().")";
116
                } else {
117
                    // Avoid duplicate dates
118
                    if (!in_array($year, $years)) {
119
                        $years[] = $year;
120
                    }
121
                }
122
            }
123
        }
124
        if ($years) {
125
            $desc .= "released in ".join(", ", $years);
126
        }
127
    }
128
129
    // Fixup a/an for vowels: "a Atari ST game" should be "an Atari ST game"
130
    // In theory it's not really about vowels, but how the word is pronounced,
131
    // but using vowels for approximation is good enough.
132
    // Replace any " a ..." followed by a vowel with " an ..."
133
    $desc = preg_replace("/ a ([aeiou])/i", " an $1", $desc);
134
135
    // Remove last trailing space, which may happen if the game has a developer
136
    // but no release date
137
    $desc = trim($desc);
138
139
    // Append extra info (number of screenshots, reviews, etc) in brackets
140
    // after the description
141
    $extra_info = [];
142
143
    if (count($game_releases) > 1) {
144
        $extra_info[] = count($game_releases)." releases";
145
    }
146
147
    if ($screenshots) {
148
        $extra_info[] = "$screenshots screenshot".(($screenshots > 1) ? "s" : "");
149
    }
150
    if ($boxscans) {
151
        $extra_info[] = "$boxscans box scan".(($boxscans > 1) ? "s" : "");
152
    }
153
    if ($reviews) {
154
        $extra_info[] = "$reviews review".(($reviews > 1) ? "s" : "");
155
    }
156
157
    if ($extra_info) {
158
        $desc .= " (".join(", ", $extra_info).")";
159
    }
160
161
    $desc .= ".";
162
163
    if (count($game_akas) > 0) {
164
        $desc .= " It's also known as: ".join(", ", $game_akas).".";
165
    }
166
167
    return $desc;
168
}
169
170
//***********************************************************************************
171
//Let's get the general game info first.
172
//***********************************************************************************
173
$sql_game = $mysqli->query(
174
    "SELECT game_name,
175
               game.game_id,
176
               game.game_series_id
177
               FROM game
178
               WHERE game.game_id='$game_id'"
179
) or die("Error getting game info");
180
181
if ($game_info = $sql_game->fetch_array(MYSQLI_BOTH)) {
182
    $smarty->assign(
183
        'game_info', array(
184
        'game_name' => $game_info['game_name'],
185
        'game_id' => $game_info['game_id']
186
        )
187
    );
188
}
189
190
//Get the game data --> new way of working
191
$smarty->assign('game', $gameDao->getGame($game_id));
192
193
// Get the programming languages
194
$smarty->assign('programming_languages', $programmingLanguageDao->getAllProgrammingLanguages());
195
$smarty->assign('game_programming_languages', $programmingLanguageDao->getProgrammingLanguagesForGame($game_id));
196
197
$smarty->assign('resolutions', $resolutionDao->getAllResolutionsAsMap());
198
$smarty->assign('systems', $systemDao->getAllSystemsAsMap());
199
$smarty->assign('locations', $locationDao->getAllLocationsAsMap());
200
201
// Get all releases
202
$releases = $gameReleaseDao->getReleasesForGame($game_id);
203
$smarty->assign('releases', $releases);
204
205
if ($game_info["game_series_id"] != null) {
206
    $smarty->assign('series', $gameSeriesDao->getGameSeries($game_info["game_series_id"]));
207
    $smarty->assign('series_games', $gameSeriesDao->getGamesForSeries($game_info["game_series_id"]));
208
}
209
210
$system_incompatible = [];
211
$emulator_incompatible = [];
212
$system_enhanced = [];
213
$release_resolution = [];
214
$release_location = [];
215
$trainerOptions = [];
216
$memoryEnhancements = [];
217
$memoryMinimum = [];
218
$memoryIncompatible = [];
219
$tos_incompatible = [];
220
$copyProtections = [];
221
$diskProtections = [];
222
$release_language = [];
223
$releases_media = [];
224
225
foreach ($releases as $release) {
226
    $system_incompatible[$release->getId()] = $systemDao->getIncompatibleSystemIdsForRelease($release->getId());
227
    $system_enhanced[$release->getId()] = $systemDao->getEnhancedSystemsForRelease($release->getId());
228
    $release_resolution[$release->getId()] = $resolutionDao->getResolutionsForRelease($release->getId());
229
    $release_location[$release->getId()] = $locationDao->getLocationsIdsForRelease($release->getId());
230
    $release_akas[$release->getId()] = $gameReleaseAkaDao->getAllGameReleaseAkas($release->getId());
231
    $emulator_incompatible[$release->getId()] =
232
        $emulatorDao->getIncompatibleEmulatorsWithNameForRelease($release->getId());
233
    $distributors[$release->getId()] = $pubDevDao->getDistributorsForRelease($release->getId());
234
    $trainerOptions[$release->getId()] = $trainerOptionDao->getTrainerOptionsForRelease($release->getId());
235
    $memoryEnhancements[$release->getId()] = $memoryDao->getMemoryForRelease($release->getId());
236
    $memoryMinimum[$release->getId()] = $memoryDao->getMinimumMemoryForRelease($release->getId());
237
    $memoryIncompatible[$release->getId()] = $memoryDao->getMemoryIncompatibleForRelease($release->getId());
238
    $tos_incompatible[$release->getId()] = $tosDao->getIncompatibleTosForRelease($release->getId());
239
    $copyProtections[$release->getId()] = $copyProtectionDao->getCopyProtectionsForRelease($release->getId());
240
    $diskProtections[$release->getId()] = $diskProtectionDao->getDiskProtectionsForRelease($release->getId());
241
    $release_language[$release->getId()] = $languageDao->getReleaseLanguages($release->getId());
242
    $releases_media[$release->getId()] = $mediaDao->getAllMediaFromRelease($release->getId());
243
}
244
$smarty->assign('system_incompatible', $system_incompatible);
245
$smarty->assign('emulator_incompatible', $emulator_incompatible);
246
$smarty->assign('system_enhanced', $system_enhanced);
247
$smarty->assign('release_resolution', $release_resolution);
248
$smarty->assign('release_location', $release_location);
249
$smarty->assign('release_akas', $release_akas);
250
$smarty->assign('distributors', $distributors);
251
$smarty->assign('trainerOptions', $trainerOptions);
252
$smarty->assign('memoryEnhancements', $memoryEnhancements);
253
$smarty->assign('memoryMinimum', $memoryMinimum);
254
$smarty->assign('memoryIncompatible', $memoryIncompatible);
255
$smarty->assign('tos_incompatible', $tos_incompatible);
256
$smarty->assign('copyProtections', $copyProtections);
257
$smarty->assign('releaseLanguages', $release_language);
258
$smarty->assign('diskProtections', $diskProtections);
259
$smarty->assign('releases_media', $releases_media);
260
261
//***********************************************************************************
262
//get the game genres & the genres already selected for this game
263
//***********************************************************************************
264
$game_genres = $gameGenreDao->getGameGenresForGame($game_id);
265
$smarty->assign('game_genres', $game_genres);
266
267
//***********************************************************************************
268
//get the game port info
269
//***********************************************************************************
270
$port = $portDao->getPortForGame($game_id);
271
$smarty->assign('port', $port);
272
273
//***********************************************************************************
274
//get the external sound hardware
275
//***********************************************************************************
276
$soundHardware = $soundHardwareDao->getSoundHardwareForGame($game_id);
277
$smarty->assign('soundHardware', $soundHardware);
278
279
//***********************************************************************************
280
//get the progress system
281
//***********************************************************************************
282
$progressSystem = $gameProgressSystemDao->getProgressSystemForGame($game_id);
283
$smarty->assign('progressSystem', $progressSystem);
284
285
//***********************************************************************************
286
//get the engines & the engines already selected for this game
287
//***********************************************************************************
288
$game_engines = $engineDao->getGameEnginesForGame($game_id);
289
$smarty->assign('game_engines', $game_engines);
290
291
//***********************************************************************************
292
//get the controls & the controls already selected for this game
293
//***********************************************************************************
294
$game_controls = $controlDao->getGameControlsForGame($game_id);
295
$smarty->assign('game_controls', $game_controls);
296
297
//**********************************************************************************
298
//Get the author info
299
//**********************************************************************************
300
//Starting off with displaying the authors that are linked to the game and having a delete option for them */
301
$sql_game_individuals = $mysqli->query(
302
    "SELECT * FROM individuals
303
                        LEFT JOIN individual_text ON (individual_text.ind_id = individuals.ind_id)
304
                        LEFT JOIN game_individual ON (game_individual.individual_id = individuals.ind_id)
305
                        LEFT JOIN individual_role ON (game_individual.individual_role_id = individual_role.id)
306
                        WHERE game_individual.game_id='$game_id' ORDER BY individual_role.id, individuals.ind_name"
307
) or die("Error loading authors");
308
309
$nr_interviews = 0;
310
311
while ($game_individual = $sql_game_individuals->fetch_array(MYSQLI_BOTH)) {
312
    $nickname = '';
313
    $nick_id = '';
314
    $interview_id = '';
315
316
    if ($game_individual['ind_imgext'] == 'png'
317
        or $game_individual['ind_imgext'] == 'jpg'
318
        or $game_individual['ind_imgext']
319
    ) {
320
        $v_ind_image  = $individual_screenshot_path;
321
        $v_ind_image .= $game_individual['ind_id'];
322
        $v_ind_image .= '.';
323
        $v_ind_image .= $game_individual['ind_imgext'];
324
    } else {
325
        $v_ind_image = "none";
326
    }
327
328
    if (preg_match("/[a-z]/i", $game_individual['ind_profile'])) {
329
        $profile = $game_individual['ind_profile'];
330
    } else {
331
        $profile = 'none';
332
    }
333
334
    if (isset($game_individual['individual_id'])) {
335
        // Get nickname information
336
        $sql_nick = $mysqli->query("SELECT * FROM individual_nicks where ind_id=$game_individual[individual_id]")
337
            or die("problem getting nickname");
338
339
        while ($ind_nicks = $sql_nick->fetch_array(MYSQLI_BOTH)) {
340
            $ind_id = $ind_nicks['nick_id'];
341
            $sql_nickname = $mysqli->query("SELECT * FROM individuals WHERE ind_id=$ind_id");
342
343
            while ($ind_nickname = $sql_nickname->fetch_array(MYSQLI_BOTH)) {
344
                $nickname = $ind_nickname['ind_name'];
345
                $nick_id = $ind_nicks['nick_id'];
346
            }
347
        }
348
349
        //Get the interview
350
        $sql_interview = $mysqli->query(
351
            "SELECT * FROM interview_main
352
            LEFT JOIN interview_text ON (interview_main.interview_id = interview_text.interview_id)
353
            LEFT JOIN users ON (interview_main.user_id = users.user_id)
354
            WHERE ind_id=$game_individual[individual_id]"
355
        ) or die("problem getting interview");
356
        while ($interview = $sql_interview->fetch_array(MYSQLI_BOTH)) {
357
            $nr_interviews++;
358
359
            $interview_id = $interview['interview_id'];
360
361
            $interview_date = date("d/m/Y", $interview['interview_date']);
362
363
            //Structure and manipulate the comment text
364
            $int_text = $interview['interview_intro'];
365
366
            //fixxx the enters
367
            $int_text = stripslashes($int_text);
368
            $int_text = InsertALCode($int_text); // disabled this as it wrecked the design.
369
            $int_text = trim($int_text);
370
            $int_text = RemoveSmillies($int_text);
371
372
            if ($v_ind_image != 'none') {
373
                $smarty->append(
374
                    'interviews',
375
                    array( 'ind_id' => $game_individual['id'],
376
                           'ind_name' => $game_individual['ind_name'],
377
                           'ind_img' => $v_ind_image,
378
                           'int_id' => $interview['interview_id'],
379
                           'int_text' => $int_text,
380
                           'int_date' => $interview_date,
381
                           'int_user_id' => $interview['user_id'],
382
                           'int_userid' => $interview['userid']
383
                        )
384
                );
385
            }
386
        }
387
    }
388
389
    $smarty->append(
390
        'game_individual', array(
391
        'id' => $game_individual['id'],
392
        'ind_name' => $game_individual['ind_name'],
393
        'ind_id' => $game_individual['ind_id'],
394
        'ind_nick' => $nickname,
395
        'ind_nick_id' => $nick_id,
396
        'ind_profile' => $profile,
397
        'ind_img' => $v_ind_image,
398
        'interview_id' => $interview_id,
399
        'individual_role' => $game_individual['name']
400
        )
401
    );
402
}
403
404
if ($nr_interviews > 0) {
405
    $nr_interviews = $nr_interviews - 1; //*smarty index starting at 0
406
    $num = mt_rand(0, $nr_interviews);
407
    $smarty->assign("random_interview_nr", $num);
408
}
409
410
//**********************************************************************************
411
//Get the companies info
412
//**********************************************************************************
413
//let's get the developers for this game
414
$sql_developer = $mysqli->query(
415
    "SELECT * FROM game_developer
416
                  LEFT JOIN pub_dev ON ( pub_dev.pub_dev_id = game_developer.dev_pub_id )
417
                  LEFT JOIN pub_dev_text ON (pub_dev.pub_dev_id = pub_dev_text.pub_dev_id )
418
                  LEFT JOIN developer_role ON ( game_developer.developer_role_id = developer_role.id )
419
                  WHERE game_developer.game_id = '$game_id' ORDER BY pub_dev_name ASC"
420
) or die("Couldn't query developers");
421
422
$game_developers = [];
423
while ($developers = $sql_developer->fetch_array(MYSQLI_BOTH)) {
424
    $game_developers[] = rtrim($developers['pub_dev_name']);
425
    if ($developers['pub_dev_imgext'] == 'png'
426
        or $developers['pub_dev_imgext'] == 'jpg'
427
        or $developers['pub_dev_imgext'] == 'gif'
428
    ) {
429
        //$v_ind_image = $company_screenshot_path;
430
        $v_ind_image = $company_screenshot_save_path;
431
        $v_ind_image .= $developers['pub_dev_id'];
432
        $v_ind_image .= '.';
433
        $v_ind_image .= $developers['pub_dev_imgext'];
434
435
        $v_ind_image_pop = $company_screenshot_path;
436
        $v_ind_image_pop .= $developers['pub_dev_id'];
437
        $v_ind_image_pop .= '.';
438
        $v_ind_image_pop .= $developers['pub_dev_imgext'];
439
    } else {
440
        $v_ind_image = "none";
441
        $v_ind_image_pop = "none";
442
    }
443
444
    if (preg_match("/[a-z]/i", $developers['pub_dev_profile'])) {
445
        $profile = $developers['pub_dev_profile'];
446
    } else {
447
        $profile = 'none';
448
    }
449
450
    $smarty->append(
451
        'developer', array(
452
        'pub_id' => $developers['dev_pub_id'],
453
        'pub_name' => $developers['pub_dev_name'],
454
        'pub_profile' =>$profile,
455
        'extra_info' => $developers['name'],
456
        'logo' => $v_ind_image,
457
        'logo_pop' => $v_ind_image_pop,
458
        'logo_path' => $company_screenshot_path
459
        )
460
    );
461
462
    $smarty->append(
463
        'developers', array(
464
        'pub_id' => $developers['dev_pub_id'],
465
        'pub_name' => $developers['pub_dev_name'],
466
        'pub_profile' =>$profile,
467
        'extra_info' => $developers['name'],
468
        'logo' => $v_ind_image,
469
        'logo_pop' => $v_ind_image_pop,
470
        'logo_path' => $company_screenshot_path
471
        )
472
    );
473
}
474
475
//***********************************************************************************
476
//AKA's
477
//***********************************************************************************
478
$sql_aka = $mysqli->query(
479
    "SELECT * FROM game_aka
480
                           LEFT JOIN language ON (language.id = game_aka.language_id)
481
                           WHERE game_id='$game_id'"
482
) or die("Couldn't query aka games");
483
$nr_aka = 0;
484
$game_akas = [];
485
while ($aka = $sql_aka->fetch_array(MYSQLI_BOTH)) {
486
    $game_akas[] = $aka['aka_name'];
487
    $smarty->append(
488
        'aka', array(
489
        'game_aka_name' => $aka['aka_name'],
490
        'game_id' => $aka['game_id'],
491
        'language' => $aka['name'],
492
        'game_aka_id' => $aka['game_aka_id']
493
        )
494
    );
495
    $smarty->append(
496
        'akas', array(
497
        'game_aka_name' => $aka['aka_name'],
498
        'game_id' => $aka['game_id'],
499
        'language' => $aka['name'],
500
        'game_aka_id' => $aka['game_aka_id']
501
        )
502
    );
503
    $nr_aka++;
504
}
505
506
//***********************************************************************************
507
//Get the screenshots
508
//***********************************************************************************
509
//Get the screenshots for this game, if they exist
510
$sql_screenshots = $mysqli->query(
511
    "SELECT * FROM screenshot_game
512
                    LEFT JOIN screenshot_main ON (screenshot_game.screenshot_id = screenshot_main.screenshot_id)
513
                    WHERE screenshot_game.game_id = '$game_id' ORDER BY screenshot_game.screenshot_id"
514
) or die("Database error - selecting screenshots");
515
516
$count = 0;
517
518
$game_screenshots_count = 0;
519
520
while ($screenshots = $sql_screenshots->fetch_array(MYSQLI_BOTH)) {
521
    $game_screenshots_count++;
522
    //Ready screenshots path and filename
523
    $screenshot_image = $game_screenshot_save_path;
524
    $screenshot_image .= $screenshots['screenshot_id'];
525
    $screenshot_image .= '.';
526
    $screenshot_image .= $screenshots['imgext'];
527
528
    $screenshot_image_pop = $game_screenshot_path;
529
    $screenshot_image_pop .= $screenshots['screenshot_id'];
530
    $screenshot_image_pop .= '.';
531
    $screenshot_image_pop .= $screenshots['imgext'];
532
533
    $smarty->append(
534
        'screenshots', array(
535
        'count' => $count,
536
        'path' => $game_screenshot_path,
537
        'screenshot_image' => $screenshot_image,
538
        'screenshot_image_pop' => $screenshot_image_pop,
539
        'id' => $screenshots['screenshot_id']
540
        )
541
    );
542
    $count++;
543
}
544
545
$smarty->assign("nr_screenshots", $count);
546
547
//***********************************************************************************
548
//Get the boxscans
549
//***********************************************************************************
550
$IMAGE = $mysqli->query("SELECT * FROM game_boxscan WHERE game_id='$game_id' ORDER BY game_boxscan_id")
551
    or die("Database error - selecting gamebox scan");
552
553
$imagenum_rows = $IMAGE->num_rows;
554
555
// if no boxscans are attached
556
$smarty->assign('numberscans', $imagenum_rows);
557
558
$front=0;
559
560
$game_boxscans_count = 0;
561
562
if ($imagenum_rows > 0) {
563
    while ($rowimage = $IMAGE->fetch_array(MYSQLI_BOTH)) { // First check if front cover
564
        $game_boxscans_count++;
565
        if ($rowimage['game_boxscan_side'] == 0) {
566
            $front++;
567
568
            $front_image_filename = "$game_boxscan_save_path$rowimage[game_boxscan_id].$rowimage[imgext]";
569
            $front_image_pop_filename = "$game_boxscan_path$rowimage[game_boxscan_id].$rowimage[imgext]";
570
571
            $smarty->append(
572
                'boxscan', array(
573
                'game_boxscan_id' => $rowimage['game_boxscan_id'],
574
                'image' => $front_image_filename,
575
                'image_pop' => $front_image_pop_filename
576
                )
577
            );
578
        } else { // Else back covers
579
            $couple = $mysqli->query(
580
                "SELECT game_boxscan_id FROM game_box_couples "
581
                ."WHERE game_boxscan_cross=$rowimage[game_boxscan_id]"
582
            )
583
                or die("Database error - selecting gamebox scan");
584
            $couplerow        = $couple->fetch_row();
585
586
            $back_image_filename = "$game_boxscan_save_path$rowimage[game_boxscan_id].$rowimage[imgext]";
587
            $back_image_pop_filename = "$game_boxscan_path$rowimage[game_boxscan_id].$rowimage[imgext]";
588
589
            $smarty->append(
590
                'boxscan', array(
591
                'game_boxscan_id' => $rowimage['game_boxscan_id'],
592
                'image' => $back_image_filename,
593
                'image_pop' => $back_image_pop_filename
594
                )
595
            );
596
        }
597
    }
598
}
599
600
$smarty->assign("nr_box", $front);
601
602
603
// Get box scans for all release
604
// This is temporary until we revamp the games/relase details page
605
$nr_of_release_scans=0;
606
607
$smarty->assign('release_scans', []);
608
foreach ($releases as $release) {
609
    $release_scans = $gameReleaseScanDao->getScansForRelease($release->getId());
610
    foreach ($release_scans as $scan) {
611
        $smarty->append('release_scans', $scan);
612
        $nr_of_release_scans++;
613
    }
614
}
615
616
$smarty->assign("nr_release", $nr_of_release_scans);
617
618
//***********************************************************************************
619
//Get the comments
620
//***********************************************************************************
621
//Select the comments from the DB
622
$sql_comment = $mysqli->query(
623
    "SELECT *
624
                                FROM game_user_comments
625
                                LEFT JOIN comments ON ( game_user_comments.comment_id = comments.comments_id )
626
                                LEFT JOIN users ON ( comments.user_id = users.user_id )
627
                                LEFT JOIN game ON ( game_user_comments.game_id = game.game_id )
628
                                WHERE game_user_comments.game_id = '$game_id'
629
                                ORDER BY comments.timestamp desc"
630
) or die("Syntax Error! Couldn't not get the comments!");
631
632
                                // lets put the comments in a smarty array
633
634
while ($query_comment = $sql_comment->fetch_array(MYSQLI_BOTH)) {
635
    $oldcomment = $query_comment['comment'];
636
    $oldcomment = nl2br($oldcomment);
637
    $oldcomment = InsertALCode($oldcomment);
638
    $oldcomment = trim($oldcomment);
639
    $oldcomment = RemoveSmillies($oldcomment);
640
    $oldcomment = stripslashes($oldcomment);
641
642
    $comment = stripslashes($query_comment['comment']);
643
    $comment = trim($comment);
644
    $comment = RemoveSmillies($comment);
645
646
    //this is needed, because users can change their own comments on the website, however this is done with JS
647
    //(instead of a post with pure HTML) The translation of the 'enter' breaks is different in JS, so in JS I do
648
    //a conversion to a <br>. However, when we edit a comment, this <br> should not be
649
    //visible to the user, hence again, now this conversion in php
650
    $breaks = array("<br />","<br>","<br/>");
651
    $comment = str_ireplace($breaks, "\r\n", $comment);
652
653
    $date = date("d/m/y", $query_comment['timestamp']);
654
655
    $smarty->append(
656
        'comments', array(
657
            'comment' => $oldcomment,
658
            'comment_edit' => $comment,
659
            'comment_id' => $query_comment['comment_id'],
660
            'date' => $date,
661
            'game' => $query_comment['game_name'],
662
            'game_id' => $query_comment['game_id'],
663
            'user_name' => $query_comment['userid'],
664
            'user_id' => $query_comment['user_id'],
665
            'user_fb' => $query_comment['user_fb'],
666
            'user_website' => $query_comment['user_website'],
667
            'user_twitter' => $query_comment['user_twitter'],
668
            'user_af' => $query_comment['user_af'],
669
            'user_avatar_ext' => $query_comment['avatar_ext'],
670
            'show_email' => $query_comment['show_email'],
671
            'email' => $query_comment['email']
672
        )
673
    );
674
}
675
676
//***********************************************************************************
677
//Get the reviews
678
//***********************************************************************************
679
$sql_review = $mysqli->query(
680
    "
681
SELECT * FROM game
682
LEFT JOIN review_game ON (game.game_id = review_game.game_id)
683
LEFT JOIN review_main ON (review_game.review_id = review_main.review_id)
684
LEFT JOIN review_score ON (review_main.review_id = review_score.review_id)
685
LEFT JOIN users ON (review_main.user_id = users.user_id)
686
WHERE game.game_id = '$game_id' AND review_main.review_edit = '0'"
687
)
688
or die("Error - Couldn't query review data");
689
690
$game_reviews_count = 0;
691
while ($query_review = $sql_review->fetch_array(MYSQLI_BOTH)) {
692
    $game_reviews_count++;
693
    $review_date = date("F j, Y", $query_review['review_date']);
694
695
    //Structure and manipulate the review text
696
    $review_text = $query_review['review_text'];
697
698
    $pos_start = strpos($review_text, '[frontpage]');
699
    $pos_end = strpos($review_text, '[/frontpage]');
700
    $nr_char = $pos_end - $pos_start;
701
702
    $review_text  = substr($review_text, $pos_start, $nr_char);
703
    $review_text = nl2br($review_text);
704
    $review_text = InsertALCode($review_text); // disabled this as it wrecked the design.
705
    $review_text = trim($review_text);
706
    $review_text = RemoveSmillies($review_text);
707
708
    //Get a screenshots and the comments of this review
709
    $query_screenshots_review = $mysqli->query(
710
        "SELECT * FROM review_main
711
        LEFT JOIN screenshot_review ON (review_main.review_id = screenshot_review.review_id)
712
        LEFT JOIN screenshot_main ON (screenshot_review.screenshot_id = screenshot_main.screenshot_id)
713
        LEFT JOIN review_comments ON (screenshot_review.screenshot_review_id = review_comments.screenshot_review_id)
714
        WHERE review_main.review_id = '$query_review[review_id]' AND review_main.review_edit = '0'
715
        ORDER BY RAND() LIMIT 1"
716
    ) or die("Error - Couldn't query review screenshots");
717
718
    $sql_screenshots_review = $query_screenshots_review->fetch_array(MYSQLI_BOTH);
719
720
    $new_path = $game_screenshot_path;
721
    $new_path .= $sql_screenshots_review['screenshot_id'];
722
    $new_path .= ".";
723
    $new_path .= $sql_screenshots_review['imgext'];
724
725
    $smarty->append(
726
        'review', array(
727
            'user_name' => $query_review['userid'],
728
            'user_id' => $query_review['user_id'],
729
            'review_id' => $query_review['review_id'],
730
            'email' => $query_review['email'],
731
            'game_id' => $query_review['game_id'],
732
            'date' => $review_date,
733
            'game_name' => $query_review['game_name'],
734
            'text' => $review_text,
735
            'screenshot' => $new_path,
736
            'comment' => $sql_screenshots_review['comment_text']
737
        )
738
    );
739
    $smarty->append(
740
        'reviews', array(
741
            'user_name' => $query_review['userid'],
742
            'user_id' => $query_review['user_id'],
743
            'review_id' => $query_review['review_id'],
744
            'email' => $query_review['email'],
745
            'game_id' => $query_review['game_id'],
746
            'date' => $review_date,
747
            'game_name' => $query_review['game_name'],
748
            'text' => $review_text,
749
            'screenshot' => $new_path,
750
            'comment' => $sql_screenshots_review['comment_text']
751
        )
752
    );
753
}
754
755
//***********************************************************************************
756
//Get Similar game
757
//***********************************************************************************
758
//select a random similar game
759
$sql_similar = $mysqli->query(
760
    "SELECT * FROM game_similar WHERE game_similar.game_id = '$game_id' "
761
    ."ORDER BY RAND() LIMIT 1"
762
)
763
    or die("Error - Couldn't get similar game");
764
765
while ($query_similar = $sql_similar->fetch_array(MYSQLI_BOTH)) {
766
    //get the game data
767
    $query_game_similar_data = $mysqli->query(
768
        "
769
    SELECT * FROM game
770
    LEFT JOIN screenshot_game ON (game.game_id = screenshot_game.game_id)
771
    LEFT JOIN screenshot_main ON (screenshot_game.screenshot_id = screenshot_main.screenshot_id)
772
    LEFT JOIN game_developer ON (game_developer.game_id = game.game_id)
773
    LEFT JOIN pub_dev ON (pub_dev.pub_dev_id = game_developer.dev_pub_id)
774
    WHERE game.game_id = '$query_similar[game_similar_cross]'
775
    ORDER BY RAND() LIMIT 1"
776
    )
777
    or die("Error - Couldn't get similar game data");
778
779
    while ($sql_game_similar_data = $query_game_similar_data->fetch_array(MYSQLI_BOTH)) {
780
        if ($sql_game_similar_data['screenshot_id'] != '') {
781
            $new_path = $game_screenshot_path;
782
            $new_path .= $sql_game_similar_data['screenshot_id'];
783
            $new_path .= ".";
784
            $new_path .= $sql_game_similar_data['imgext'];
785
        } else {
786
            $new_path = 'none';
787
        }
788
789
        $smarty->assign(
790
            'similar', array(
791
            'game_id' => $query_similar['game_similar_cross'],
792
            'game_name' => $sql_game_similar_data['game_name'],
793
            'game_dev_name' => $sql_game_similar_data['pub_dev_name'],
794
            'game_dev_id' => $sql_game_similar_data['pub_dev_id'],
795
            'screenshot' => $new_path )
796
        );
797
    }
798
}
799
800
//***********************************************************************************
801
//Get the game facts
802
//***********************************************************************************
803
//load the facts for this games
804
$query_games_facts = $mysqli->query(
805
    "SELECT * from game_fact
806
                                     LEFT JOIN game ON (game.game_id = game_fact.game_id)
807
                                     WHERE game_fact.game_id = $game_id"
808
) or die("error in query game facts");
809
810
while ($sql_games_facts = $query_games_facts->fetch_array(MYSQLI_BOTH)) {
811
    //check if there are screenshot added to the submission
812
    $query_screenshots_facts = $mysqli->query(
813
        "SELECT * FROM screenshot_main
814
        LEFT JOIN screenshot_game_fact ON (screenshot_main.screenshot_id = screenshot_game_fact.screenshot_id)
815
        WHERE screenshot_game_fact.game_fact_id = '$sql_games_facts[game_fact_id]'"
816
    ) or die("Error - Couldn't query fact screenshots");
817
818
    while ($sql_screenshots_facts = $query_screenshots_facts->fetch_array(MYSQLI_BOTH)) {
819
        $new_path = $game_fact_screenshot_path;
820
        $new_path .= $sql_screenshots_facts['screenshot_id'];
821
        $new_path .= ".";
822
        $new_path .= $sql_screenshots_facts['imgext'];
823
824
        $smarty->append(
825
            'facts_screenshots', array(
826
            'game_fact_id' => $sql_games_facts['game_fact_id'],
827
            'game_fact_screenshot' => $new_path
828
            )
829
        );
830
    }
831
832
    $fact_text = nl2br($sql_games_facts['game_fact']);
833
    $fact_text = InsertALCode($fact_text); // disabled this as it wrecked the design.
834
    $fact_text = trim($fact_text);
835
    $fact_text = RemoveSmillies($fact_text);
836
837
    $smarty->append(
838
        'facts', array(
839
        'game_fact_id' => $sql_games_facts['game_fact_id'],
840
        'game_fact' => $fact_text
841
        )
842
    );
843
}
844
845
//*********************************************************************************************
846
// Get the amiga and C64 id's for the Lemon links
847
//*********************************************************************************************
848
$sql_vs = $mysqli->query("SELECT amiga_id, C64_id FROM game_vs WHERE atari_id = '$game_id'")
849
          or die("Error - Couldn't get the Lemon links");
850
851
while ($query_vs = $sql_vs->fetch_array(MYSQLI_BOTH)) {
852
    $smarty->append(
853
        'game_vs', array(
854
        'amiga_id' => $query_vs['amiga_id'],
855
        'C64_id' => $query_vs['C64_id']
856
        )
857
    );
858
}
859
860
$smarty->assign("game_id", $game_id);
861
$smarty->assign(
862
    "game_description", generate_game_description(
863
        $game_info['game_name'],
864
        $game_akas,
865
        $releases,
866
        $game_genres,
867
        $game_developers,
868
        $game_screenshots_count,
869
        $game_boxscans_count,
870
        $game_reviews_count
871
    )
872
);
873
874
$smarty->assign('user_avatar_path', $user_avatar_path);
875
876
//Send all smarty variables to the templates
877
if (isset($use_new_layout)) {
878
    $smarty->display("file:" . $mainsite_template_folder . "games/games_detail.new.html");
879
} else {
880
    $smarty->display("file:" . $mainsite_template_folder . "games/games_detail.html");
881
}
882
883
//close the connection
884
mysqli_close($mysqli);
885