This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
/
jomres_webinstall.php
2098 lines (1919 loc) · 76.7 KB
/
jomres_webinstall.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
if (!defined('DS'))
{
$detect_os = strtoupper($_SERVER["SERVER_SOFTWARE"]); // converted to uppercase
$isWin32 = strpos($detect_os, "WIN32");
$IIS = strpos($detect_os, "IIS");
$signature = strtoupper($_SERVER["SERVER_SIGNATURE"]);
$apacheSig = strpos($signature, "APACHE");
$dir = dirname(realpath(__FILE__));
if ( strpos($dir,":\\" ) )
define("DS" , "\\");
else
{
if ( $isWin32 === false || $apacheSig == true)
define("DS" , "/");
else
define("DS" , "\\");
}
}
define('JOMRESINSTALLPATH_TMP', dirname(__FILE__).DS."tmp" );
define('JOMRESINSTALLPATH_BASE', JOMRESINSTALLPATH_TMP.DS."jomres_install" );
define('JOMRESINSTALLPATH_WEBINSTALL', JOMRESINSTALLPATH_BASE.DS."jomres_install" );
define('JOMRESPATH_BASE',dirname(__FILE__).DS."jomres");
define('JOMRESINSTALLPATH_PACK_DIRECTORY', JOMRESINSTALLPATH_BASE.DS."unpacked");
$foldersToTestForWritability[]=JOMRESINSTALLPATH_TMP.DS;
$foldersToTestForWritability[]=JOMRESINSTALLPATH_BASE.DS;
$foldersToTestForWritability[]=JOMRESINSTALLPATH_WEBINSTALL.DS;
$foldersToTestForWritability[]=JOMRESPATH_BASE.DS;
$foldersToTestForWritability[]=JOMRESINSTALLPATH_PACK_DIRECTORY.DS;
foreach ($foldersToTestForWritability as $folder)
{
$result=jomresStatusTestFolderIsWritable($folder);
if (!$result['result'])
$results["folder_tests"][] = array("success"=>false,"message"=>$result['message']);
else
$results["folder_tests"][] = array("success"=>true,"message"=>"We tested <i>".$folder."</i> and we were able to write successfully to that folder");
}
if (!file_exists('configuration.php') )
{
if (!file_exists('wp-config.php') )
$results["configuration_tests"][] = array("success"=>false,"message"=>"We cannot detect a copy of configuration.php or wp-config.php, please ensure that you are running this script within Wordpress's or Joomla's root folder.");
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"We have detected a copy of wp-config.php, you seem to be running this installation from Wordpress's root folder.");
}
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"We have detected a copy of configuration.php, you seem to be running this installation from Joomla's root folder.");
if (strnatcmp(phpversion(),'5.3.0') < 0)
$results["configuration_tests"][] = array("success"=>false,"message"=>"Your PHP version is too low, you need to be running at least 5.3.0 to use Jomres.");
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"You are running a version of PHP equal to, or higher than, 5.3.0");
/* if (!class_exists('ZipArchive'))
$results["configuration_tests"][] = array("success"=>false,"message"=>"Your PHP installation does not have access to the ZipArchive class. Please see <a href=\"http://www.php.net/manual/en/zip.installation.php\" target=\"_blank\">this page</a> for more information, or ask your hosts to investigate the matter for you.");
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"You have access to PHP's zip archive. Hooray.");
*/
if (!function_exists('json_decode') )
$results["configuration_tests"][] = array("success"=>false,"message"=>"Function : json_decode is not available. Please ask your hosts how you can enable this function.");
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"Function : json_decode is available.");
if (!function_exists('curl_init') )
$results["configuration_tests"][] = array("success"=>false,"message"=>"Function : curl_init is not available. To use the web installer PHP needs access to the CURL library functionality to download and install Jomres. You may need to ask your hosts to enable this php functionality. Alternatively, if you're running on localhost, you will need to enable the PHP extension mod_curl.");
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"Function : curl_init is available. CURL is used throughout Jomres for things like Jomres installation and upgrading, setting up exchange rates, talking to Google maps etc.");
if (!function_exists('gregoriantojd') )
$results["configuration_tests"][] = array("success"=>false,"message"=>"Function : gregoriantojd is not available. Please ask your hosts how you can enable this function in your PHP installation.");
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"Function : gregoriantojd is available.");
/*
No longer an issue now that we've made this change https://jomres.trac.cvsdude.com/Jomres_core_v4/changeset/2794
if (!function_exists('bcmod') )
$results["configuration_tests"][] = array("success"=>false,"message"=>"Function : bcmod is not available. Please ask your hosts how you can enable this function in your PHP installation.");
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"Function : bcmod is available."); */
if (!function_exists('imagejpeg'))
$results["configuration_tests"][] = array("success"=>false,"message"=>"Function : Your PHP installation does not have JPEG support (GD) enabled. Please ask your hosts how you can enable this function in your PHP installation.");
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"Function : JPEG support is enabled in PHP.");
// Firewall test
if (function_exists('curl_init') )
{
$curl_handle = curl_init("http://updates.jomres4.net/getlatest.php");
curl_setopt($curl_handle, CURLOPT_HEADER,0);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER ,1);
$latestJomres = curl_exec($curl_handle);
curl_close($curl_handle);
if (strlen($latestJomres) == 0)
$results["configuration_tests"][] = array("success"=>false,"message"=>'We are unable to comunicate with the updates server, you might have a firewall preventing your server from communicating with the jomres.net servers. If you\'re on a web server as part of your hosting package you may need to ask your hosts how to resolve this, if you are on a Windows machine you may be able to modify your firewall settings to allow connections to certain servers. You need to configure your firewall allow your server to communicate with the domains "updates.jomres4.net", "plugins.jomres4.net" and "license-server.jomres.net"');
else
$results["configuration_tests"][] = array("success"=>true,"message"=>"Firewall tests passed sucessfully.");
}
if (!isset($_REQUEST['start']) )
$pagetitle = "Testing your server's configuration";
else
$pagetitle = "Starting your Jomres download";
echo '
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<title>Jomres installation/upgrade</title>
<style>
.steps a {
padding: 10px 12px 10px 25px;
margin-right: 5px;
background: #efefef;
position: relative;
display: inline-block;
color:#000;
text-decoration:none;
}
.steps a:hover {cursor: pointer; cursor: hand;}
.steps a:before {
width: 0;
height: 0;
border-top: 20px inset transparent;
border-bottom: 20px inset transparent;
position: absolute;
content: "";
top: 0;
left: 0;
}
.steps a:after {
width: 0;
height: 0;
border-top: 20px inset transparent;
border-bottom: 20px inset transparent;
border-left: 20px solid #efefef;
position: absolute;
content: "";
top: 0;
right: -20px;
z-index: 2;
}
/*.steps a:last-child:after,*/
.steps a:first-child:before {
border: none;
}
.steps a:first-child {
padding-left:15px;
-webkit-border-radius: 4px 0 0 4px;
-moz-border-radius: 4px 0 0 4px;
border-radius: 4px 0 0 4px;
}
.steps a:last-child {
-webkit-border-radius: 0 4px 4px 0;
-moz-border-radius: 0 4px 4px 0;
border-radius: 0 4px 4px 0;
}
.steps .current {
background: #007ACC;
color: #fff;
}
.steps .current:after {
border-left-color: #007ACC;
}
</style>
<script>
$(function() {
// setTimeout() function will be fired after page is loaded
// it will wait for 5 sec. and then will fire
// $(".alert-success").hide() function
setTimeout(function() {
$(".alert-success").delay(500).fadeOut(\'slow\');
$(".alert-warning").delay(500).fadeOut(\'slow\');
}, 5000);
});
</script>
</head>
<body>
<div class="container">
<div class="navbar-header"></div>
<img src="https://www.jomres.net/images/jomres.png" class="img-rounded"/>
<div class="alert alert-warning">'.$pagetitle.'</div>
';
$server_tests_pass = true;
$folder_check_results = '';
$configuration_check_results = '';
foreach ($results as $key=>$messages)
{
foreach ($messages as $message)
{
if (!$message['success'])
{
if ($key == "configuration_tests")
$configuration_check_results .= '<div class="alert alert-error">'.$message['message'].'</div>';
else
$folder_check_results .= '<div class="alert alert-error">'.$message['message'].'</div>';
$server_tests_pass = false;
}
else
{
if ($key == "configuration_tests")
$configuration_check_results .= '<div class="alert alert-success"><strong>Congratulations.</strong> '.$message['message'].'</div>';
else
$folder_check_results .= '<div class="alert alert-success"><strong>Congratulations.</strong> '.$message['message'].'</div>';
}
}
}
// Not currently needed
if (!$server_tests_pass)
{
echo $configuration_check_results;
echo $folder_check_results;
$install_failure_message = '';
foreach ($results["configuration_tests"] as $test)
{
if (!$test['success'])
{
$install_failure_message .= $test['message']." \r\n";
}
}
// if (!$install_failure_message == "") // Will only report an error on configuration settings, we're unable to do anything about permissions errors
// @mail("webinstall_failures@jomres.net","Web installation configuration setting failed",$install_failure_message);
}
if ($server_tests_pass)
echo '<div class="alert alert-success">Congratulations, your system passed all of our checks and you are ready to install Jomres</div>';
else
echo '<div class="alert alert-error">Unfortunately, one or more system tests failed, please correct the reported issues and reload this page to rerun the tests.</div>
<form action="'.$_SERVER['PHP_SELF'].'" method=get ><input type="submit" name="reload" class="btn" style="font-size:1.2em" onClick="submit()" value="Reload"></input></form>
';
if ($server_tests_pass&& !isset($_REQUEST['start']))
{
$text = "";
if (isset($error_message))
{
echo '<div class="alert alert-error">'.$error_message.'</div>';
}
?>
<script type="text/javascript">
function submitform()
{
document.myform.submit();
}
</script>
<div class="jumbotron">
<h2> Welcome to the web installer for Jomres</h2>
</div>
<div class="well">
<div class="visible-desktop steps">
<a class="current"><span>Download Jomres</span></a>
<a><span>Prepare installation</span></a>
<a><span>Complete installation</span></a>
</div>
</div>
<div class="well">
<p>
The purpose of this script is to download Jomres direct to your web server, unpack it and perform the file and directory creation stage of your Jomres installation.
</p>
<p>
Once this has been completed you will be taken to the file install_jomres.php which is used to both install Jomres and upgrade any existing installations.
</p>
<p>
Please click the "Continue" button when you are ready to start the download.
</p>
<div class="btn-action">
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" ><input type="submit" class="btn btn-primary btn-large" onClick="submit();" value="Continue"></input><input type="hidden" name="start" value="1" /><input type="hidden" name="includebeta" value="0" /></form>
</div>
</div>
<br/>
<div class="span12">
<p>
Alternatively, if you want to install the latest build, which may or may not be an Alpha/Beta/Release Candidate click this button
</p>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" ><input type="submit" class="btn btn-danger" onClick="submit();" value="Continue"></input><input type="hidden" name="start" value="1" /><input type="hidden" name="includebeta" value="1" /></form>
</div>
<div class="span12 ">
<iframe frameborder="no" width="800px" height="220px" src="http://analytics.jomres.net/index.php?module=CoreAdminHome&action=optOut&language=en"></iframe>
</div>
<?php
}
elseif ($server_tests_pass && isset($_REQUEST['start']) )
{
$include_beta = (bool)$_REQUEST['includebeta'];
set_time_limit(0);
PiwikTracker::$URL = 'http://analytics.jomres.net/';
$piwikTracker = new PiwikTracker( $idSite = 2 );
// Sends Tracker request via http, regardless of whether the user's chosen to enable or disable tracking. If they have disabled it, then the remote server will just disregard the tracking information sent, so there's no need to check here for the tracking cookie.
$piwikTracker->doTrackGoal($idGoal = 1);
echo "Time limit set to ".ini_get('max_execution_time')." (this is just to stop the server timing out while we do the download)<br>";
global $debugging;
$testing=true;
$debugging=array();
emptyDir(JOMRESINSTALLPATH_BASE);
$curl_handle = curl_init("http://updates.jomres4.net/getlatest.php?includebeta=".(string)$include_beta);
curl_setopt($curl_handle, CURLOPT_HEADER,0); // DO NOT RETURN HTTP HEADERS
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
$latestJomres = curl_exec($curl_handle);
curl_close($curl_handle);
if (strlen($latestJomres) == 0)
{
echo "Couldn't identify new Jomres version. Quitting. It is possible that a firewall may be preventing this server from communicating with the updates server. If so, please disable it, or allow your web server to communicate with the server at \"updates.jomres4.net\", port 80. ";
exit;
}
$newfilename=JOMRESINSTALLPATH_BASE.DS."jomres.zip";
$out = fopen($newfilename, 'wb');
if ($out == FALSE)
{
print "Couldn't create new file $newfilename. Possible file permission problem?<br/>";
exit;
}
//echo "<br/>Starting download of $latestJomres<br>";
$curl_handle = curl_init($latestJomres);
curl_setopt($curl_handle, CURLOPT_FILE, $out);
curl_setopt($curl_handle, CURLOPT_HEADER, 0);
curl_setopt($curl_handle, CURLOPT_URL, $latestJomres);
curl_exec($curl_handle);
curl_close($curl_handle);
fclose($out);
@curl_close($curl_handle);
@fclose($out);
if (!file_exists($newfilename) && filesize($newfilename)>0 )
{
echo "Something went wrong downloading Jomres. Quitting";
return;
}
$proceed = false;
if (is_dir(JOMRESINSTALLPATH_PACK_DIRECTORY))
$proceed = true;
elseif (mkdir(JOMRESINSTALLPATH_PACK_DIRECTORY))
$proceed = true;
if ($proceed)
{
if (class_exists('ZipArchive'))
{
$zip = new ZipArchive();
$zip->open($newfilename);
if ($zip->open($newfilename) === TRUE)
{
//echo "Unzipping ".JOMRESINSTALLPATH_BASE.DS."jomres.zip to ".JOMRESINSTALLPATH_PACK_DIRECTORY."<br/>";
$zip->extractTo(JOMRESINSTALLPATH_PACK_DIRECTORY);
$zip->close();
}
}
else
{
$zip = new dUnzip2($newfilename);
// Activate debug
$zip->debug = false;
// Unzip all the contents of the zipped file to the new folder/directory
$zip->getList();
$zip->unzipAll(JOMRESINSTALLPATH_PACK_DIRECTORY);
}
//echo "Moving files from ".JOMRESINSTALLPATH_PACK_DIRECTORY." to ".dirname(__FILE__).DS."jomres"."<br/>";
dirmv(JOMRESINSTALLPATH_PACK_DIRECTORY, JOMRESPATH_BASE, true, $funcloc = DS);
//echo "Completed the download and extraction. Please ensure that you visit <a href=\"jomres/install_jomres.php\" >install_jomres.php</a> to complete the installation.<br/>";
echo ' <script>window.location.replace("jomres/install_jomres.php");</script>';
emptyDir(JOMRESINSTALLPATH_BASE);
emptyDir(JOMRESINSTALLPATH_PACK_DIRECTORY);
@rmdir(JOMRESINSTALLPATH_BASE);
@rmdir(JOMRESINSTALLPATH_PACK_DIRECTORY);
echo "Please remember to ensure that you've deleted the contents of the ".JOMRESINSTALLPATH_BASE." directory once you are ready to start using Jomres.";
}
}
echo '
</div>
</body>
</html>';
// Ends here
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function jomresStatusTestFolderIsWritable($path)
{
$tmpFile="temp.txt";
$tmpDir="jomres_test_dir";
if (!is_dir($path) )
{
if (!mkdir($path))
return array("result"=>false,"message"=>"Directory ".$path." doesn't exist and we cannot create it.");
}
if (!is_writable($path) )
return array("result"=>false,"message"=>"Directory ".$path." isn't writable");
if (!touch($path.$tmpFile) )
return array("result"=>false,"message"=>"Could not write ".$path.$tmpFile);
if (!file_exists($path.$tmpFile) )
return array("result"=>false,"message"=>"Could not find ".$path.$tmpFile." after seeming to be able to create it.");
if (!unlink($path.$tmpFile) )
return array("result"=>false,"message"=>"Could not delete ".$path.$tmpFile);
if (!mkdir($path.$tmpDir) )
return array("result"=>false,"message"=>"Could not make temporary folder ".$path.$tmpDir);
if (!rmdir($path.$tmpDir) )
return array("result"=>false,"message"=>"Could not remove temporary folder ".$path.$tmpDir);
return array("result"=>true,"message"=>"Pass");
}
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// http://www.php.net/manual/en/function.unlink.php#79940
function emptyDir($dir)
{
if(!$dh = @opendir($dir)) return;
while (false !== ($obj = readdir($dh)))
{
if($obj=='.' || $obj=='..') continue;
if (!@unlink($dir.DS.$obj)) emptyDir($dir.DS.$obj, true);
}
closedir($dh);
if ($dir != JOMRESINSTALLPATH_BASE)
@rmdir($dir);
}
// http://www.php.net/manual/en/function.rename.php#61152
function dirmv($source, $dest, $overwrite = false, $funcloc = NULL)
{
$debugging=array();
/*
if(is_null($funcloc))
{
$dest .= '/' . strrev(substr(strrev($source), 0, strpos(strrev($source), null)));
$funcloc = '/';
}
*/
if(!is_dir( $dest . $funcloc))
mkdir( $dest . $funcloc); // make subdirectory before subdirectory is copied
//echo "Opening " . $source . $funcloc."<br/>";
if($handle = opendir( $source . $funcloc))
{ // if the folder exploration is sucsessful, continue
//echo "Opened ". $source . $funcloc."<br/>";
while(false !== ($file = readdir($handle)))
{ // as long as storing the next file to $file is successful, continue
if($file != '.' && $file != '..')
{
$path = $source . $funcloc . $file;
$path2 = $dest . $funcloc . $file;
if(is_file( $path))
{
if(!is_file( $path2))
{
if(!@rename( $path, $path2))
{
echo '<font color="red">File ('.$path.') could not be moved, likely a permissions problem.</font><br/>';
}
}
else
if($overwrite)
{
if(!@unlink( $path2))
{
echo 'Unable to overwrite file ("'.$path2.'"), likely to be a permissions problem.<br/>';
}
else
{
if(!@rename( $path, $path2))
{
echo '<font color="red">File ('.$path.') could not be moved while overwritting, likely a permissions problem.</font><br/>';
}
else
$debugging[]= "Moved ".$path."<br/> to ".$path2."<br/>";
}
}
else
echo "Not allowed to overwrite" .$path2."<br/>";
}
elseif(is_dir( $path))
{
dirmv($source, $dest, $overwrite, $funcloc . $file . '/'); //recurse!
rmdir( $path);
}
}
}
closedir($handle);
}
//echo "Finished upgrade <br/>";
} // end of dirmv()
// Piwik tracking code included to help us to understand whether or not the installer worked as expected. As both jomres_webinstall.php and install_jomres.php are deleted after installation it makes sense to include the class here, instead of a library file.
/**
* Piwik - Open source web analytics
*
* Client to record visits, page views, Goals, Ecommerce activity (product views, add to carts, Ecommerce orders) in a Piwik server.
* This is a PHP Version of the piwik.js standard Tracking API.
* For more information, see http://piwik.org/docs/tracking-api/
*
* This class requires:
* - json extension (json_decode, json_encode)
* - CURL or STREAM extensions (to issue the http request to Piwik)
*
* @license released under BSD License http://www.opensource.org/licenses/bsd-license.php
* @version $Id: PiwikTracker.php 4787 2011-05-23 11:09:58Z matt $
* @link http://piwik.org/docs/tracking-api/
*
* @category Piwik
* @package PiwikTracker
*/
/**
* @package PiwikTracker
*/
class PiwikTracker
{
/**
* Piwik base URL, for example http://example.org/piwik/
* Must be set before using the class by calling
* PiwikTracker::$URL = 'http://yourwebsite.org/piwik/';
*
* @var string
*/
static public $URL = '';
/**
* API Version
*
* @ignore
* @var int
*/
const VERSION = 1;
/**
* @ignore
*/
public $DEBUG_APPEND_URL = '';
/**
* Visitor ID length
*
* @ignore
*/
const LENGTH_VISITOR_ID = 16;
/**
* Builds a PiwikTracker object, used to track visits, pages and Goal conversions
* for a specific website, by using the Piwik Tracking API.
*
* @param int $idSite Id site to be tracked
* @param string $apiUrl "http://example.org/piwik/" or "http://piwik.example.org/"
* If set, will overwrite PiwikTracker::$URL
*/
function __construct( $idSite, $apiUrl = false )
{
$this->cookieSupport = true;
$this->userAgent = false;
$this->localHour = false;
$this->localMinute = false;
$this->localSecond = false;
$this->hasCookies = false;
$this->plugins = false;
$this->visitorCustomVar = false;
$this->pageCustomVar = false;
$this->customData = false;
$this->forcedDatetime = false;
$this->token_auth = false;
$this->attributionInfo = false;
$this->ecommerceLastOrderTimestamp = false;
$this->ecommerceItems = array();
$this->requestCookie = '';
$this->idSite = $idSite;
$this->urlReferrer = @$_SERVER['HTTP_REFERER'];
$this->pageUrl = self::getCurrentUrl();
$this->ip = @$_SERVER['REMOTE_ADDR'];
$this->acceptLanguage = @$_SERVER['HTTP_ACCEPT_LANGUAGE'];
$this->userAgent = @$_SERVER['HTTP_USER_AGENT'];
if(!empty($apiUrl)) {
self::$URL = $apiUrl;
}
$this->visitorId = substr(md5(uniqid(rand(), true)), 0, self::LENGTH_VISITOR_ID);
}
/**
* Sets the current URL being tracked
*
* @param string Raw URL (not URL encoded)
*/
public function setUrl( $url )
{
$this->pageUrl = $url;
}
/**
* Sets the URL referrer used to track Referrers details for new visits.
*
* @param string Raw URL (not URL encoded)
*/
public function setUrlReferrer( $url )
{
$this->urlReferrer = $url;
}
/**
* @deprecated
* @ignore
*/
public function setUrlReferer( $url )
{
$this->setUrlReferrer($url);
}
/**
* Sets the attribution information to the visit, so that subsequent Goal conversions are
* properly attributed to the right Referrer URL, timestamp, Campaign Name & Keyword.
*
* This must be a JSON encoded string that would typically be fetched from the JS API:
* piwikTracker.getAttributionInfo() and that you have JSON encoded via JSON2.stringify()
*
* @param string $jsonEncoded JSON encoded array containing Attribution info
* @see function getAttributionInfo() in http://dev.piwik.org/trac/browser/trunk/js/piwik.js
*/
public function setAttributionInfo( $jsonEncoded )
{
$decoded = json_decode($jsonEncoded, $assoc = true);
if(!is_array($decoded))
{
throw new Exception("setAttributionInfo() is expecting a JSON encoded string, $jsonEncoded given");
}
$this->attributionInfo = $decoded;
}
/**
* Sets Visit Custom Variable.
* See http://piwik.org/docs/custom-variables/
*
* @param int Custom variable slot ID from 1-5
* @param string Custom variable name
* @param string Custom variable value
* @param string Custom variable scope. Possible values: visit, page
*/
public function setCustomVariable($id, $name, $value, $scope = 'visit')
{
if(!is_int($id))
{
throw new Exception("Parameter id to setCustomVariable should be an integer");
}
if($scope == 'page')
{
$this->pageCustomVar[$id] = array($name, $value);
}
elseif($scope == 'visit')
{
$this->visitorCustomVar[$id] = array($name, $value);
}
else
{
throw new Exception("Invalid 'scope' parameter value");
}
}
/**
* Returns the currently assigned Custom Variable stored in a first party cookie.
*
* This function will only work if the user is initiating the current request, and his cookies
* can be read by PHP from the $_COOKIE array.
*
* @param int Custom Variable integer index to fetch from cookie. Should be a value from 1 to 5
* @param string Custom variable scope. Possible values: visit, page
*
* @return array|false An array with this format: array( 0 => CustomVariableName, 1 => CustomVariableValue )
* @see Piwik.js getCustomVariable()
*/
public function getCustomVariable($id, $scope = 'visit')
{
if($scope == 'page')
{
return isset($this->pageCustomVar[$id]) ? $this->pageCustomVar[$id] : false;
}
else if($scope != 'visit')
{
throw new Exception("Invalid 'scope' parameter value");
}
if(!empty($this->visitorCustomVar[$id]))
{
return $this->visitorCustomVar[$id];
}
$customVariablesCookie = 'cvar.'.$this->idSite.'.';
$cookie = $this->getCookieMatchingName($customVariablesCookie);
if(!$cookie)
{
return false;
}
if(!is_int($id))
{
throw new Exception("Parameter to getCustomVariable should be an integer");
}
$cookieDecoded = json_decode($cookie, $assoc = true);
if(!is_array($cookieDecoded)
|| !isset($cookieDecoded[$id])
|| !is_array($cookieDecoded[$id])
|| count($cookieDecoded[$id]) != 2)
{
return false;
}
return $cookieDecoded[$id];
}
/**
* Sets the Browser language. Used to guess visitor countries when GeoIP is not enabled
*
* @param string For example "fr-fr"
*/
public function setBrowserLanguage( $acceptLanguage )
{
$this->acceptLanguage = $acceptLanguage;
}
/**
* Sets the user agent, used to detect OS and browser.
* If this function is not called, the User Agent will default to the current user agent.
*
* @param string $userAgent
*/
public function setUserAgent($userAgent)
{
$this->userAgent = $userAgent;
}
/**
* Tracks a page view
*
* @param string $documentTitle Page title as it will appear in the Actions > Page titles report
* @return string Response
*/
public function doTrackPageView( $documentTitle )
{
$url = $this->getUrlTrackPageView($documentTitle);
return $this->sendRequest($url);
}
/**
* Records a Goal conversion
*
* @param int $idGoal Id Goal to record a conversion
* @param int $revenue Revenue for this conversion
* @return string Response
*/
public function doTrackGoal($idGoal, $revenue = false)
{
$url = $this->getUrlTrackGoal($idGoal, $revenue);
return $this->sendRequest($url);
}
/**
* Tracks a download or outlink
*
* @param string $actionUrl URL of the download or outlink
* @param string $actionType Type of the action: 'download' or 'link'
* @return string Response
*/
public function doTrackAction($actionUrl, $actionType)
{
// Referrer could be udpated to be the current URL temporarily (to mimic JS behavior)
$url = $this->getUrlTrackAction($actionUrl, $actionType);
return $this->sendRequest($url);
}
/**
* Adds an item in the Ecommerce order.
*
* This should be called before doTrackEcommerceOrder(), or before doTrackEcommerceCartUpdate().
* This function can be called for all individual products in the cart (or order).
* SKU parameter is mandatory. Other parameters are optional (set to false if value not known).
* Ecommerce items added via this function are automatically cleared when doTrackEcommerceOrder() or getUrlTrackEcommerceOrder() is called.
*
* @param string $sku (required) SKU, Product identifier
* @param string $name (optional) Product name
* @param string $category (optional) Product category
* @param float|int $price (optional) Individual product price (supports integer and decimal prices)
* @param int $quantity (optional) Product quantity. If not specified, will default to 1 in the Reports
*/
public function addEcommerceItem($sku, $name = false, $category = false, $price = false, $quantity = false)
{
if(empty($sku))
{
throw new Exception("You must specify a SKU for the Ecommerce item");
}
$this->ecommerceItems[$sku] = array( $sku, $name, $category, $price, $quantity );
}
/**
* Tracks a Cart Update (add item, remove item, update item).
*
* On every Cart update, you must call addEcommerceItem() for each item (product) in the cart,
* including the items that haven't been updated since the last cart update.
* Items which were in the previous cart and are not sent in later Cart updates will be deleted from the cart (in the database).
*
* @param float $grandTotal Cart grandTotal (typically the sum of all items' prices)
*/
public function doTrackEcommerceCartUpdate($grandTotal)
{
$url = $this->getUrlTrackEcommerceCartUpdate($grandTotal);
return $this->sendRequest($url);
}
/**
* Tracks an Ecommerce order.
*
* If the Ecommerce order contains items (products), you must call first the addEcommerceItem() for each item in the order.
* All revenues (grandTotal, subTotal, tax, shipping, discount) will be individually summed and reported in Piwik reports.
* Only the parameters $orderId and $grandTotal are required.
*
* @param string|int $orderId (required) Unique Order ID.
* This will be used to count this order only once in the event the order page is reloaded several times.
* orderId must be unique for each transaction, even on different days, or the transaction will not be recorded by Piwik.
* @param float $grandTotal (required) Grand Total revenue of the transaction (including tax, shipping, etc.)
* @param float $subTotal (optional) Sub total amount, typically the sum of items prices for all items in this order (before Tax and Shipping costs are applied)
* @param float $tax (optional) Tax amount for this order
* @param float $shipping (optional) Shipping amount for this order
* @param float $discount (optional) Discounted amount in this order
*/
public function doTrackEcommerceOrder($orderId, $grandTotal, $subTotal = false, $tax = false, $shipping = false, $discount = false)
{
$url = $this->getUrlTrackEcommerceOrder($orderId, $grandTotal, $subTotal, $tax, $shipping, $discount);
return $this->sendRequest($url);
}
/**
* Sets the current page view as an item (product) page view, or an Ecommerce Category page view.
*
* This must be called before doTrackPageView() on this product/category page.
* It will set 3 custom variables of scope "page" with the SKU, Name and Category for this page view.
* Note: Custom Variables of scope "page" slots 3, 4 and 5 will be used.
*
* On a category page, you may set the parameter $category only and set the other parameters to false.
*
* Tracking Product/Category page views will allow Piwik to report on Product & Categories
* conversion rates (Conversion rate = Ecommerce orders containing this product or category / Visits to the product or category)
*
* @param string $sku Product SKU being viewed
* @param string $name Product Name being viewed
* @param string $category Category being viewed. On a Product page, this is the product's category
*/
public function setEcommerceView($sku = false, $name = false, $category = false)
{
if(!empty($sku)) {
$this->pageCustomVar[3] = array('_pks', $sku);
}
if(!empty($name)) {
$this->pageCustomVar[4] = array('_pkn', $name);
}
if(!empty($category)) {
$this->pageCustomVar[5] = array('_pkc', $category);
}
}
/**
* Returns URL used to track Ecommerce Cart updates
* Calling this function will reinitializes the property ecommerceItems to empty array
* so items will have to be added again via addEcommerceItem()
* @ignore
*/
public function getUrlTrackEcommerceCartUpdate($grandTotal)
{
$url = $this->getUrlTrackEcommerce($grandTotal);
return $url;
}
/**
* Returns URL used to track Ecommerce Orders
* Calling this function will reinitializes the property ecommerceItems to empty array
* so items will have to be added again via addEcommerceItem()
* @ignore
*/
public function getUrlTrackEcommerceOrder($orderId, $grandTotal, $subTotal = false, $tax = false, $shipping = false, $discount = false)
{
if(empty($orderId))
{
throw new Exception("You must specifiy an orderId for the Ecommerce order");
}
$url = $this->getUrlTrackEcommerce($grandTotal, $subTotal, $tax, $shipping, $discount);
$url .= '&ec_id=' . urlencode($orderId);
$this->ecommerceLastOrderTimestamp = $this->getTimestamp();
return $url;
}
/**
* Returns URL used to track Ecommerce orders
* Calling this function will reinitializes the property ecommerceItems to empty array
* so items will have to be added again via addEcommerceItem()
* @ignore
*/
protected function getUrlTrackEcommerce($grandTotal, $subTotal = false, $tax = false, $shipping = false, $discount = false)
{
if(!is_numeric($grandTotal))
{
throw new Exception("You must specifiy a grandTotal for the Ecommerce order (or Cart update)");
}
$url = $this->getRequest( $this->idSite );
$url .= '&idgoal=0';
if(!empty($grandTotal))
{
$url .= '&revenue='.$grandTotal;
}
if(!empty($subTotal))
{
$url .= '&ec_st='.$subTotal;
}
if(!empty($tax))
{
$url .= '&ec_tx='.$tax;
}
if(!empty($shipping))
{
$url .= '&ec_sh='.$shipping;
}
if(!empty($discount))
{
$url .= '&ec_dt='.$discount;
}
if(!empty($this->ecommerceItems))
{
// Removing the SKU index in the array before JSON encoding
$items = array();
foreach($this->ecommerceItems as $item)
{
$items[] = $item;
}
$url .= '&ec_items='. urlencode(json_encode($items));
}
$this->ecommerceItems = array();
return $url;
}
/**
* @see doTrackPageView()
* @param string $documentTitle Page view name as it will appear in Piwik reports
* @return string URL to piwik.php with all parameters set to track the pageview
*/
public function getUrlTrackPageView( $documentTitle = false )
{
$url = $this->getRequest( $this->idSite );
if(!empty($documentTitle)) {
$url .= '&action_name=' . urlencode($documentTitle);
}
return $url;
}
/**
* @see doTrackGoal()
* @param string $actionUrl URL of the download or outlink
* @param string $actionType Type of the action: 'download' or 'link'
* @return string URL to piwik.php with all parameters set to track the goal conversion
*/
public function getUrlTrackGoal($idGoal, $revenue = false)
{
$url = $this->getRequest( $this->idSite );
$url .= '&idgoal=' . $idGoal;
if(!empty($revenue)) {
$url .= '&revenue=' . $revenue;
}
return $url;
}