forked from realdigger/SMF-Garage
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SSI_Garage.php
1895 lines (1665 loc) · 77.5 KB
/
SSI_Garage.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**********************************************************************************
* SSI_Garage.php *
***********************************************************************************
* SMF Garage: Simple Machines Forum Garage (MOD) *
* =============================================================================== *
* Software Version: SMF Garage 2.3 *
* Install for: 2.0.9-2.0.99 *
* Original Developer: RRasco (http://www.smfgarage.com) *
* Copyright 2015 by: Bruno Alves ([email protected] *
* Copyright 2007-2011 by: SMF Garage (http://www.smfgarage.com) *
* RRasco ([email protected]) *
* phpBB Garage by: Esmond Poynton ([email protected]) *
***********************************************************************************
* See the "SMF_Garage_License.txt" file for details. *
* http://www.opensource.org/licenses/BSD-3-Clause *
**********************************************************************************/
// Don't do anything if SMF is already loaded.
if (defined('SMF')) {
return true;
}
define('SMF', 'SSI_Garage');
// We're going to want a few globals... these are all set later.
global $time_start, $maintenance, $msubject, $mmessage, $mbname, $language;
global $boardurl, $boarddir, $sourcedir, $webmaster_email, $cookiename;
global $db_server, $db_name, $db_user, $db_prefix, $db_persist, $db_error_send, $db_last_error;
global $db_connection, $modSettings, $context, $sc, $user_info, $topic, $board, $txt;
global $smcFunc, $ssi_db_user, $scripturl, $ssi_db_passwd, $db_passwd, $cachedir;
global $smfgSettings;
// Remember the current configuration so it can be set back.
$ssi_magic_quotes_runtime = function_exists('get_magic_quotes_gpc') && get_magic_quotes_runtime();
if (function_exists('set_magic_quotes_runtime')) {
@set_magic_quotes_runtime(0);
}
$time_start = microtime();
// Just being safe...
foreach (array('db_character_set', 'cachedir') as $variable) {
if (isset($GLOBALS[$variable])) {
unset($GLOBALS[$variable]);
}
}
// Get the forum's settings for database and file paths.
require_once(dirname(__FILE__) . '/Settings.php');
// Make absolutely sure the cache directory is defined.
if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
$cachedir = $boarddir . '/cache';
}
$ssi_error_reporting = error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
/* Set this to one of three values depending on what you want to happen in the case of a fatal error.
false: Default, will just load the error sub template and die - not putting any theme layers around it.
true: Will load the error sub template AND put the SMF layers around it (Not useful if on total custom pages).
string: Name of a callback function to call in the event of an error to allow you to define your own methods. Will die after function returns.
*/
$ssi_on_error_method = false;
// Don't do john didley if the forum's been shut down competely.
if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) {
die($mmessage);
}
// Fix for using the current directory as a path.
if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
}
// Load the important includes.
require_once($sourcedir . '/QueryString.php');
require_once($sourcedir . '/Subs.php');
require_once($sourcedir . '/Errors.php');
require_once($sourcedir . '/Load.php');
require_once($sourcedir . '/Security.php');
// Now the garage includes.
require_once($sourcedir . '/GarageFunctions.php');
// Using an pre-PHP 5.1 version?
if (@version_compare(PHP_VERSION, '5.1') == -1) {
require_once($sourcedir . '/Subs-Compat.php');
}
// Create a variable to store some SMF specific functions in.
$smcFunc = array();
// Initate the database connection and define some database functions to use.
loadDatabase();
// Load installed 'Mods' settings.
reloadSettings();
// Clean the request variables.
cleanRequest();
// Seed the random generator?
if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
smf_seed_generator();
}
// Check on any hacking attempts.
if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
die('Hacking attempt...');
} elseif (isset($_REQUEST['ssi_theme']) && (int)$_REQUEST['ssi_theme'] == (int)$ssi_theme) {
die('Hacking attempt...');
} elseif (isset($_COOKIE['ssi_theme']) && (int)$_COOKIE['ssi_theme'] == (int)$ssi_theme) {
die('Hacking attempt...');
} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) {
die('Hacking attempt...');
}
if (isset($_REQUEST['context'])) {
die('Hacking attempt...');
}
// Make sure wireless is always off.
define('WIRELESS', false);
// Gzip output? (because it must be boolean and true, this can't be hacked.)
if (isset($ssi_gzip) && $ssi_gzip === true && @ini_get('zlib.output_compression') != '1' && @ini_get('output_handler') != 'ob_gzhandler' && @version_compare(PHP_VERSION,
'4.2.0') != -1
) {
ob_start('ob_gzhandler');
} else {
$modSettings['enableCompressedOutput'] = '0';
}
// Primarily, this is to fix the URLs...
//ob_start('ob_sessrewrite');
// Start the session... known to scramble SSI includes in cases...
if (!headers_sent()) {
loadSession();
} else {
if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()])) {
// Make a stab at it, but ignore the E_WARNINGs generated because we can't send headers.
$temp = error_reporting(error_reporting() & !E_WARNING);
loadSession();
error_reporting($temp);
}
if (!isset($_SESSION['session_value'])) {
$_SESSION['session_var'] = substr(md5(mt_rand() . session_id() . mt_rand()), 0, rand(7, 12));
$_SESSION['session_value'] = md5(session_id() . mt_rand());
}
$sc = $_SESSION['session_value'];
}
// Get rid of $board and $topic... do stuff loadBoard would do.
unset($board, $topic);
$user_info['is_mod'] = false;
$context['user']['is_mod'] = &$user_info['is_mod'];
$context['linktree'] = array();
// Load the user and their cookie, as well as their settings.
loadUserSettings();
// Load the current user's permissions....
loadPermissions();
// Load the current or SSI theme. (just use $ssi_theme = id_theme;)
loadTheme(isset($ssi_theme) ? (int)$ssi_theme : 0);
// Take care of any banning that needs to be done.
if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) {
is_not_banned();
}
// Do we allow guests in here?
if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php') {
require_once($sourcedir . '/Subs-Auth.php');
KickGuest();
obExit(null, true);
}
// Load the stuff like the menu bar, etc.
if (isset($ssi_layers)) {
$context['template_layers'] = $ssi_layers;
template_header();
} else {
setupThemeContext();
}
// Make sure they didn't muss around with the settings... but only if it's not cli.
if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') {
trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);
}
// Without visiting the forum this session variable might not be set on submit.
if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) {
$_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
}
// Call a function passed by GET.
if (isset($_GET['ssi_function']) && function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) {
call_user_func('ssi_' . $_GET['ssi_function']);
exit;
}
if (isset($_GET['ssi_function'])) {
exit;
} // You shouldn't just access SSI.php directly by URL!!
elseif (basename($_SERVER['PHP_SELF']) == 'SSI.php') {
die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
}
error_reporting($ssi_error_reporting);
if (function_exists('set_magic_quotes_runtime')) {
@set_magic_quotes_runtime($ssi_magic_quotes_runtime);
}
return true;
// SSI functions below here.....
// CSS and JS includes
function ssi_smfg_includes($output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $boardurl, $settings, $smcFunc;
$output = '
<!-- SMF Styles -->
<link rel="stylesheet" href="' . $settings['default_theme_url'] . '/style.css" type="text/css" />
<!-- jQuery Includes -->
<script type="text/javascript" src="' . $settings['default_theme_url'] . '/jquery-1.6.1.min.js"></script>
<!-- Lightbox Includes -->
<link rel="stylesheet" href="' . $settings['default_theme_url'] . '/shadowbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="' . $settings['default_theme_url'] . '/shadowbox.js"></script>
<script type="text/javascript">
$(document).ready(function(){
Shadowbox.init();
});
</script>';
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'return') {
return $output;
}
}
}
// **ONLY CSS includes
function ssi_smfg_css_includes($output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $boardurl, $settings, $smcFunc;
$output = '
<!-- SMF Styles -->
<link rel="stylesheet" href="' . $settings['default_theme_url'] . '/style.css" type="text/css" />';
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'return') {
return $output;
}
}
}
// **ONLY JS includes
function ssi_smfg_js_includes($output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $boardurl, $settings, $smcFunc;
$output = '
<!-- jQuery Includes -->
<script type="text/javascript" src="' . $settings['default_theme_url'] . '/jquery-1.6.1.min.js"></script>
<!-- Lightbox Includes -->
<link rel="stylesheet" href="' . $settings['default_theme_url'] . '/shadowbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="' . $settings['default_theme_url'] . '/shadowbox.js"></script>
<script type="text/javascript">
$(document).ready(function(){
Shadowbox.init();
});
</script>';
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'return') {
return $output;
}
}
}
// Show the featured vehicle
function ssi_smfg_featuredVehicle($width = 200, $description = 1, $output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $boardurl, $settings, $smcFunc;
// Load garage settings
loadSmfgConfig();
loadLanguage('Garage');
// Get the featured vehicle ID
$context['featured_vehicle']['id'] = getFeaturedVehicle();
if (isset($context['featured_vehicle']['id']) && !empty($context['featured_vehicle']['id'])) {
$request = $smcFunc['db_query']('', '
SELECT u.real_name, CONCAT_WS(" ", v.made_year, mk.make, md.model), v.user_id
FROM {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md, {db_prefix}members AS u
WHERE v.id = {int:id}
AND v.make_id = mk.id
AND v.model_id = md.id
AND v.user_id = u.id_member',
array(
'id' => $context['featured_vehicle']['id'],
)
);
list($context['featured_vehicle']['owner'],
$context['featured_vehicle']['vehicle'],
$context['featured_vehicle']['user_id']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
// Check if there is a hilite image
$request = $smcFunc['db_query']('', '
SELECT image_id
FROM {db_prefix}garage_vehicles_gallery
WHERE vehicle_id = {int:id}
AND hilite = 1',
array(
'id' => $context['featured_vehicle']['id'],
)
);
list($context['featured_vehicle']['image_id']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
// Select image data if there is any
$context['featured_vehicle']['image'] = "";
if (isset($context['featured_vehicle']['image_id'])) {
$request = $smcFunc['db_query']('', '
SELECT attach_location, attach_file, attach_thumb_location, attach_thumb_width, attach_thumb_height, attach_desc, is_remote
FROM {db_prefix}garage_images
WHERE attach_id = {int:image_id}',
array(
'image_id' => $context['featured_vehicle']['image_id'],
)
);
list($context['featured_vehicle']['attach_location'],
$context['featured_vehicle']['attach_file'],
$context['featured_vehicle']['attach_thumb_location'],
$context['featured_vehicle']['attach_thumb_width'],
$context['featured_vehicle']['attach_thumb_height'],
$context['featured_vehicle']['attach_desc'],
$context['featured_vehicle']['is_remote']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
// Check to see if the image is remote or not and build appropriate links
if ($context['featured_vehicle']['is_remote'] == 1) {
$context['featured_vehicle']['attach_location'] = urldecode($context['featured_vehicle']['attach_file']);
} else {
$context['featured_vehicle']['attach_location'] = $boardurl . '/' . $smfgSettings['upload_directory'] . 'cache/' . $context['featured_vehicle']['attach_location'];
}
// If there is an image attached, link to it
if (isset($context['featured_vehicle']['attach_location'])) {
$context['featured_vehicle']['image'] = "<a href=\"" . $context['featured_vehicle']['attach_location'] . "\" rel=\"shadowbox\" title=\"" . garage_title_clean($context['featured_vehicle']['vehicle']) . "\"><img src=\"" . $boardurl . "/" . $smfgSettings['upload_directory'] . 'cache/' . $context['featured_vehicle']['attach_thumb_location'] . "\" width=\"" . $context['featured_vehicle']['attach_thumb_width'] . "\" height=\"" . $context['featured_vehicle']['attach_thumb_height'] . "\" alt=\"Featured Vehicle\" /></a><br />";
}
}
}
$output = '';
// Generate output
$output .= '
<div style="width: ' . $width . 'px; white-space: nowrap;">
<table border="0" cellspacing="0" cellpadding="0" align="center" class="tborder">
<tr>
<td align="center" nowrap="nowrap"><div class="title_bar"><h4 class="titlebg"><span class="ie6_header floatleft">
' . $smfgSettings['featured_vehicle_description'] . '
</span></h4></div></td>
</tr>
<tr>
<td>
<span class="clear upperframe"><span></span></span>
<div class="roundframe"><div class="innerframe">
<table border="0" cellpadding="0" cellspacing="0" width="100%">';
if (isset($context['featured_vehicle']['id']) && !empty($context['featured_vehicle']['id'])) {
$output .= '
<tr>
<td width="100%" valign="top" align="center">
' . $context['featured_vehicle']['image'] . '<a href="' . $scripturl . '?action=garage;sa=view_vehicle;VID=' . $context['featured_vehicle']['id'] . '">' . garage_title_clean($context['featured_vehicle']['vehicle']) . '</a><br />' . $txt['smfg_owner'] . ': <a href="' . $scripturl . '?action=profile;u=' . $context['featured_vehicle']['user_id'] . '">' . $context['featured_vehicle']['owner'] . '</a></td>
</tr>';
} else {
$output .= '
<tr>
<td width="100%" valign="top" align="center">' . $txt['smfg_no_vid'] . '</td>
</tr>';
}
$output .= '
</table>
</div>
</div>
<span class="lowerframe"><span></span></span>
</td>
</tr>
</table>';
$output .= '
</div>';
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'array') {
return $context['featured_vehicle'];
}
}
}
// Show the SMF Garage stats
function ssi_smfg_garageStats($style = 0, $output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $settings, $smcFunc;
// Load garage settings
loadSmfgConfig();
loadLanguage('Garage');
// Get total number of vehicles
$request = $smcFunc['db_query']('', '
SELECT id
FROM {db_prefix}garage_vehicles',
array(// no values
)
);
$context['garageStats']['total_vehicles'] = $smcFunc['db_num_rows']($request);
$smcFunc['db_free_result']($request);
$context['total_vehicles'] = number_format($context['garageStats']['total_vehicles'], 0, '.', ',');
// Get total number of mods
$request = $smcFunc['db_query']('', '
SELECT id
FROM {db_prefix}garage_modifications',
array(// no values
)
);
$context['garageStats']['total_mods'] = $smcFunc['db_num_rows']($request);
$smcFunc['db_free_result']($request);
$context['garageStats']['total_mods'] = number_format($context['garageStats']['total_mods'], 0, '.', ',');
// Get total number of comments
$request = $smcFunc['db_query']('', '
SELECT id
FROM {db_prefix}garage_guestbooks',
array(// no values
)
);
$context['garageStats']['total_comments'] = $smcFunc['db_num_rows']($request);
$smcFunc['db_free_result']($request);
$context['garageStats']['total_comments'] = number_format($context['garageStats']['total_comments'], 0, '.', ',');
// Get total number of views
$context['garageStats']['total_views'] = 0;
$request = $smcFunc['db_query']('', '
SELECT views
FROM {db_prefix}garage_vehicles',
array(// no values
)
);
$count = 0;
while ($row = $smcFunc['db_fetch_row']($request)) {
list($context[$count]['views']) = $row;
$context['garageStats']['total_views'] += $context[$count]['views'];
$count++;
}
$smcFunc['db_free_result']($request);
$context['garageStats']['total_views'] = number_format($context['garageStats']['total_views'], 0, '.', ',');
$output = '';
if ($style == 0) {
$output .= '
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td>' . $txt['smfg_total_vehicles_caps'] . ': <b>' . $context['garageStats']['total_vehicles'] . '</b>
<br />
' . $txt['smfg_total_mods'] . ': <b>' . $context['garageStats']['total_mods'] . '</b>
<br />
' . $txt['smfg_total_comments'] . ': <b>' . $context['garageStats']['total_comments'] . '</b>
<br />
' . $txt['smfg_total_views'] . ': <b>' . $context['garageStats']['total_views'] . '</b>
</td>
</tr>
</table>';
} else {
if ($style == 1) {
$bullet = '<img src="' . $settings['images_url'] . '/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet2 = '<img src="' . $settings['images_url'] . '/TPdivider2.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$output .= '
<div class="smalltext" style="font-family: verdana, arial, sans-serif;">
' . $bullet . $txt['smfg_total_vehicles_caps'] . ': ' . $context['garageStats']['total_vehicles'] . '<br />
' . $bullet . $txt['smfg_total_mods'] . ': ' . $context['garageStats']['total_mods'] . '<br />
' . $bullet . $txt['smfg_total_comments'] . ': ' . $context['garageStats']['total_comments'] . '<br />
' . $bullet . $txt['smfg_total_views'] . ': ' . $context['garageStats']['total_views'] . '<br />
</div>';
}
}
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'array') {
return $context['garageStats'];
}
}
}
// Show the newest vehicles
function ssi_smfg_newestVehicles($title = 1, $limit = 5, $output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $smcFunc;
// Load garage settings
loadSmfgConfig();
loadLanguage('Garage');
$output = '';
$output .= '
<div style="width: 100%;">';
if ($title) {
$output .= '<div style="margin-bottom: 2px;">
<h3 style="margin: 0; font-size: 1em; padding: 5px;">' . $txt['smfg_new_vehicles'] . '</h3>';
}
// Get the five newest vehicles
// Get the VIDs first
$request = $smcFunc['db_query']('', '
SELECT v.id
FROM {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md
WHERE v.make_id = mk.id
AND v.model_id = md.id
AND mk.pending != "1"
AND md.pending != "1"
AND v.pending != "1"
ORDER BY v.date_created DESC
LIMIT 0, ' . $limit,
array(// no values
)
);
$count = 0;
while ($row = $smcFunc['db_fetch_row']($request)) {
list($context['newest_vehicles'][$count]['id']) = $row;
// Now collect data for each vehicle
$request2 = $smcFunc['db_query']('', '
SELECT v.user_id, v.date_created, CONCAT_WS(" ", v.made_year, mk.make, md.model), u.real_name
FROM {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md, {db_prefix}members AS u
WHERE v.id = {int:id}
AND v.user_id = u.id_member
AND v.make_id = mk.id
AND v.model_id = md.id',
array(
'id' => $context['newest_vehicles'][$count]['id'],
)
);
list($context['newest_vehicles'][$count]['user_id'],
$context['newest_vehicles'][$count]['date_created'],
$context['newest_vehicles'][$count]['vehicle'],
$context['newest_vehicles'][$count]['memberName']) = $smcFunc['db_fetch_row']($request2);
$smcFunc['db_free_result']($request2);
$output .= '
<div class="smalltext"><a href="' . $scripturl . '?action=garage;sa=view_vehicle;VID=' . $context['newest_vehicles'][$count]['id'] . '">' . $context['newest_vehicles'][$count]['vehicle'] . '</a></div>
<div class="smalltext">' . $txt['smfg_owner'] . ': <b><a href="' . $scripturl . '?action=profile;u=' . $context['newest_vehicles'][$count]['user_id'] . '">' . $context['newest_vehicles'][$count]['memberName'] . '</a></b></div>
<div class="smalltext">' . $txt['smfg_created'] . ': <b>' . date('M d, Y',
$context['newest_vehicles'][$count]['date_created']) . '</b></div>';
$count++;
if ($count < $limit) {
$output .= '<hr />';
}
}
$smcFunc['db_free_result']($request);
if ($title) {
$output .= '</div>';
}
$output .= '</div>';
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'array') {
return $context['newest_vehicles'];
}
}
}
// Show the last updated vehicles
function ssi_smfg_lastUpdatedVehicles($title = 1, $limit = 5, $output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $smcFunc;
// Load garage settings
loadSmfgConfig();
loadLanguage('Garage');
$output = '';
$output .= '
<div style="width: 100%;">';
if ($title) {
$output .= '<div style="margin-bottom: 2px;">
<h3 style="margin: 0; font-size: 1em; padding: 5px;">' . $txt['smfg_up_vehicles'] . '</h3>';
}
// Get the five latest updated vehicles
// Get the VIDs first
$request = $smcFunc['db_query']('', '
SELECT v.id
FROM {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md
WHERE v.make_id = mk.id
AND v.model_id = md.id
AND mk.pending != "1"
AND md.pending != "1"
AND v.pending != "1"
ORDER BY v.date_updated DESC
LIMIT 0, ' . $limit,
array(// no values
)
);
$count = 0;
while ($row = $smcFunc['db_fetch_row']($request)) {
list($context['last_updated_veh'][$count]['id']) = $row;
// Now collect data for each vehicle
$request2 = $smcFunc['db_query']('', '
SELECT v.user_id, v.date_updated, CONCAT_WS(" ", v.made_year, mk.make, md.model), u.real_name
FROM {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md, {db_prefix}members AS u
WHERE v.id = {int:id}
AND v.user_id = u.id_member
AND v.make_id = mk.id
AND v.model_id = md.id',
array(
'id' => $context['last_updated_veh'][$count]['id'],
)
);
list($context['last_updated_veh'][$count]['user_id'],
$context['last_updated_veh'][$count]['date_updated'],
$context['last_updated_veh'][$count]['vehicle'],
$context['last_updated_veh'][$count]['memberName']) = $smcFunc['db_fetch_row']($request2);
$smcFunc['db_free_result']($request2);
$output .= '
<div class="smalltext"><a href="' . $scripturl . '?action=garage;sa=view_vehicle;VID=' . $context['last_updated_veh'][$count]['id'] . '">' . $context['last_updated_veh'][$count]['vehicle'] . '</a></div>
<div class="smalltext">' . $txt['smfg_owner'] . ': <b><a href="' . $scripturl . '?action=profile;u=' . $context['last_updated_veh'][$count]['user_id'] . '">' . $context['last_updated_veh'][$count]['memberName'] . '</a></b></div>
<div class="smalltext">' . $txt['smfg_updated'] . ': <b>' . date('M d, Y',
$context['last_updated_veh'][$count]['date_updated']) . '</b></div>';
$count++;
if ($count < $limit) {
$output .= '<hr />';
}
}
$smcFunc['db_free_result']($request);
if ($title) {
$output .= '</div>';
}
$output .= '</div>';
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'array') {
return $context['last_updated_veh'];
}
}
}
// Show the newest mods
function ssi_smfg_newestMods($title = 1, $limit = 5, $output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $smcFunc;
// Load garage settings
loadSmfgConfig();
loadLanguage('Garage');
$output = '';
$output .= '
<div style="width: 100%;">';
if ($title) {
$output .= '<div style="margin-bottom: 2px;">
<h3 style="margin: 0; font-size: 1em; padding: 5px;">' . $txt['smfg_new_mods'] . '</h3>';
}
// Get the five newest modifications
// Get the VIDs first
$request = $smcFunc['db_query']('', '
SELECT m.id
FROM {db_prefix}garage_modifications AS m, {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md, {db_prefix}garage_products AS p, {db_prefix}garage_business AS b
WHERE m.vehicle_id = v.id
AND v.make_id = mk.id
AND v.model_id = md.id
AND m.product_id = p.id
AND p.business_id = b.id
AND mk.pending != "1"
AND md.pending != "1"
AND m.pending != "1"
AND v.pending != "1"
AND p.pending != "1"
AND b.pending != "1"
ORDER BY m.date_created DESC
LIMIT 0, ' . $limit,
array(// no values
)
);
$count = 0;
while ($row = $smcFunc['db_fetch_row']($request)) {
list($context['newest_mods'][$count]['id']) = $row;
// Now collect data for each mod
$request2 = $smcFunc['db_query']('', '
SELECT p.title, m.vehicle_id, CONCAT_WS(" ", v.made_year, mk.make, md.model), m.user_id, m.date_created, u.real_name
FROM {db_prefix}garage_products AS p, {db_prefix}garage_modifications AS m, {db_prefix}members AS u, {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md
WHERE m.id = {int:id}
AND m.product_id = p.id
AND m.user_id = u.id_member
AND m.vehicle_id = v.id
AND v.make_id = mk.id
AND v.model_id = md.id',
array(
'id' => $context['newest_mods'][$count]['id'],
)
);
list($context['newest_mods'][$count]['modification'],
$context['newest_mods'][$count]['vid'],
$context['newest_mods'][$count]['vehicle'],
$context['newest_mods'][$count]['user_id'],
$context['newest_mods'][$count]['date_created'],
$context['newest_mods'][$count]['memberName']) = $smcFunc['db_fetch_row']($request2);
$smcFunc['db_free_result']($request2);
$output .= '
<div class="smalltext"><a href="' . $scripturl . '?action=garage;sa=view_modification;VID=' . $context['newest_mods'][$count]['vid'] . ';MID=' . $context['newest_mods'][$count]['id'] . '">' . $context['newest_mods'][$count]['modification'] . '</a></div>
<div class="smalltext"><a href="' . $scripturl . '?action=garage;sa=view_vehicle;VID=' . $context['newest_mods'][$count]['vid'] . '#modifications">' . $context['newest_mods'][$count]['vehicle'] . '</a></div>
<div class="smalltext">' . $txt['smfg_owner'] . ': <b><a href="' . $scripturl . '?action=profile;u=' . $context['newest_mods'][$count]['user_id'] . '">' . $context['newest_mods'][$count]['memberName'] . '</a></b></div>';
$count++;
if ($count < $limit) {
$output .= '<hr />';
}
}
$smcFunc['db_free_result']($request);
if ($title) {
$output .= '</div>';
}
$output .= '</div>';
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'array') {
return $context['newest_mods'];
}
}
}
// Show the last updated mods
function ssi_smfg_lastUpdatedMods($title = 1, $limit = 5, $output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $smcFunc;
// Load garage settings
loadSmfgConfig();
loadLanguage('Garage');
$output = '';
$output .= '
<div style="width: 100%;">';
if ($title) {
$output .= '<div style="margin-bottom: 2px;">
<h3 style="margin: 0; font-size: 1em; padding: 5px;">' . $txt['smfg_up_mods'] . '</h3>';
}
// Get the five latest updated mods
// Get the VIDs first
$request = $smcFunc['db_query']('', '
SELECT m.id
FROM {db_prefix}garage_modifications AS m, {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md, {db_prefix}garage_products AS p, {db_prefix}garage_business AS b
WHERE m.vehicle_id = v.id
AND m.product_id = p.id
AND p.business_id = b.id
AND v.make_id = mk.id
AND v.model_id = md.id
AND mk.pending != "1"
AND md.pending != "1"
AND v.pending != "1"
AND m.pending != "1"
AND p.pending != "1"
AND b.pending != "1"
ORDER BY m.date_updated DESC
LIMIT 0, ' . $limit,
array(// no values
)
);
$count = 0;
while ($row = $smcFunc['db_fetch_row']($request)) {
list($context['last_updated_mods'][$count]['id']) = $row;
// Now collect data for each mod
$request2 = $smcFunc['db_query']('', '
SELECT p.title, CONCAT_WS(" ", v.made_year, mk.make, md.model), m.vehicle_id, m.user_id, m.date_updated, u.real_name
FROM {db_prefix}garage_products AS p, {db_prefix}garage_modifications AS m, {db_prefix}members AS u, {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md
WHERE m.id = {int:id}
AND m.product_id = p.id
AND m.user_id = u.id_member
AND m.vehicle_id = v.id
AND v.make_id = mk.id
AND v.model_id = md.id',
array(
'id' => $context['last_updated_mods'][$count]['id'],
)
);
list($context['last_updated_mods'][$count]['modification'],
$context['last_updated_mods'][$count]['vehicle'],
$context['last_updated_mods'][$count]['vid'],
$context['last_updated_mods'][$count]['user_id'],
$context['last_updated_mods'][$count]['date_updated'],
$context['last_updated_mods'][$count]['memberName']) = $smcFunc['db_fetch_row']($request2);
$smcFunc['db_free_result']($request2);
$output .= '
<div class="smalltext"><a href="' . $scripturl . '?action=garage;sa=view_modification;VID=' . $context['last_updated_mods'][$count]['id'] . ';MID=' . $context['last_updated_mods'][$count]['id'] . '">' . $context['last_updated_mods'][$count]['modification'] . '</a></div>
<div class="smalltext"><a href="' . $scripturl . '?action=garage;sa=view_vehicle;VID=' . $context['last_updated_mods'][$count]['vid'] . '#modifications">' . $context['last_updated_mods'][$count]['vehicle'] . '</a></div>
<div class="smalltext">' . $txt['smfg_owner'] . ': <b><a href="' . $scripturl . '?action=profile;u=' . $context['last_updated_mods'][$count]['user_id'] . '">' . $context['last_updated_mods'][$count]['memberName'] . '</a></b></div>
<div class="smalltext">' . $txt['smfg_updated'] . ': <b>' . date('M d, Y',
$context['last_updated_mods'][$count]['date_updated']) . '</b></div>';
$count++;
if ($count < $limit) {
$output .= '<hr />';
}
}
$smcFunc['db_free_result']($request);
if ($title) {
$output .= '</div>';
}
$output .= '</div>';
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'array') {
return $context['last_updated_mods'];
}
}
}
// Show the most viewed
function ssi_smfg_mostViews($title = 1, $limit = 5, $output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $smcFunc;
// Load garage settings
loadSmfgConfig();
loadLanguage('Garage');
$output = '';
$output .= '
<div style="width: 100%;">';
if ($title) {
$output .= '<div style="margin-bottom: 2px;">
<h3 style="margin: 0; font-size: 1em; padding: 5px;">' . $txt['smfg_most_views'] . '</h3>';
}
// Get the five most viewed vehicles
// Get the VIDs first
$request = $smcFunc['db_query']('', '
SELECT v.id
FROM {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md
WHERE v.make_id = mk.id
AND v.model_id = md.id
AND mk.pending != "1"
AND md.pending != "1"
AND v.pending != "1"
ORDER BY v.views DESC
LIMIT 0, ' . $limit,
array(// no values
)
);
$count = 0;
while ($row = $smcFunc['db_fetch_row']($request)) {
list($context['most_views'][$count]['id']) = $row;
// Now collect data for each vehicle
$request2 = $smcFunc['db_query']('', '
SELECT v.user_id, v.views, CONCAT_WS(" ", v.made_year, mk.make, md.model), u.real_name
FROM {db_prefix}garage_vehicles AS v, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md, {db_prefix}members AS u
WHERE v.id = {int:id}
AND v.user_id = u.id_member
AND v.make_id = mk.id
AND v.model_id = md.id',
array(
'id' => $context['most_views'][$count]['id'],
)
);
list($context['most_views'][$count]['user_id'],
$context['most_views'][$count]['views'],
$context['most_views'][$count]['vehicle'],
$context['most_views'][$count]['memberName']) = $smcFunc['db_fetch_row']($request2);
$context['most_views'][$count]['views'] = number_format($context['most_views'][$count]['views'], 0, '.', ',');
$smcFunc['db_free_result']($request2);
$output .= '
<div class="smalltext"><a href="' . $scripturl . '?action=garage;sa=view_vehicle;VID=' . $context['most_views'][$count]['id'] . '">' . $context['most_views'][$count]['vehicle'] . '</a></div>
<div class="smalltext">' . $txt['smfg_owner'] . ': <b><a href="' . $scripturl . '?action=profile;u=' . $context['most_views'][$count]['user_id'] . '">' . $context['most_views'][$count]['memberName'] . '</a></b></div>
<div class="smalltext">' . $txt['smfg_views'] . ': <b>' . $context['most_views'][$count]['views'] . '</b></div>';
$count++;
if ($count < $limit) {
$output .= '<hr />';
}
}
$smcFunc['db_free_result']($request);
if ($title) {
$output .= '</div>';
}
$output .= '</div>';
if ($output_method == 'echo') {
echo $output;
} else {
if ($output_method == 'array') {
return $context['most_views'];
}
}
}
// Show the most spent
function ssi_smfg_mostSpent($title = 1, $limit = 5, $output_method = 'echo')
{
global $smfgSettings, $txt, $scripturl, $db_prefix, $modSettings, $smcFunc;
// Load garage settings
loadSmfgConfig();
loadLanguage('Garage');
$output = '';
$output .= '
<div style="width: 100%;">';
if ($title) {
$output .= '<div style="margin-bottom: 2px;">
<h3 style="margin: 0; font-size: 1em; padding: 5px;">' . $txt['smfg_most_spent2'] . '</h3>';
}
// *************************************************************
// WARNING: The query check is being disabled to allow for the following subselect.
// It is imperative this is turned back on for security reasons.
// *************************************************************
$modSettings['disableQueryCheck'] = 1;
// *************************************************************
// Get the five vehicles with the most money spent
// Get the VIDs first
$request = $smcFunc['db_query']('', '
SELECT v.id, IFNULL(m.total_mods,0) + IFNULL(s.total_service,0) AS total_spent
FROM {db_prefix}garage_vehicles AS v
LEFT OUTER JOIN (
SELECT vehicle_id, SUM(price) + SUM(install_price) AS total_mods
FROM {db_prefix}garage_modifications AS m1, {db_prefix}garage_business AS b, {db_prefix}garage_products AS p
WHERE m1.manufacturer_id = b.id
AND m1.product_id = p.id
AND b.pending != "1"
AND m1.pending != "1"
AND p.pending != "1"
GROUP BY vehicle_id) AS m ON v.id = m.vehicle_id
LEFT OUTER JOIN (
SELECT vehicle_id, SUM(price) AS total_service
FROM {db_prefix}garage_service_history AS s1, {db_prefix}garage_business AS b1
WHERE s1.garage_id = b1.id
AND b1.pending != "1"
GROUP BY vehicle_id) AS s ON v.id = s.vehicle_id, {db_prefix}garage_makes AS mk, {db_prefix}garage_models AS md
WHERE v.make_id = mk.id
AND v.model_id = md.id
AND mk.pending != "1"
AND md.pending != "1"
AND v.pending != "1"
GROUP BY total_spent