forked from nickian/mautic-whitelabeler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whitelabeler.php
executable file
·974 lines (870 loc) · 32.4 KB
/
whitelabeler.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
<?php
class Whitelabeler {
/*
|--------------------------------------------------------------------------
| Get JSON config files from assets folder
|--------------------------------------------------------------------------
*/
public function getConfigFiles()
{
$config_files = array();
$files = scandir(__DIR__.'/assets');
foreach( $files as $file ) {
$file_extension = explode('.', $file);
$file_extension = end($file_extension);
if ( $file_extension == strtolower('json') ) {
$config_files[] = $file;
}
}
return $config_files;
}
/*
|--------------------------------------------------------------------------
| Load config.json file if it exists
|--------------------------------------------------------------------------
*/
public function loadJsonConfig($file)
{
$config = array();
if ( file_exists( __DIR__.'/assets/'.$file ) ) {
$config = json_decode(file_get_contents(__DIR__.'/assets/'.$file), true);
return $config;
} else {
return false;
}
}
/*
|--------------------------------------------------------------------------
| Find Mautic URL with cURL
|--------------------------------------------------------------------------
*/
public function findMauticUrl($url)
{
if ( function_exists('curl_version') ) {
$url = urldecode($url);
if ( substr($url, -1) == '/' ) {
$url = substr($url, 0, -1);
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url.'/favicon.ico',
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOBODY => true,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false
));
$output = curl_exec($curl);
$headers = [];
$data = explode("\n",$output);
$headers['status'] = $data[0];
array_shift($data);
foreach($data as $key => $part) {
$middle = explode(":",$part);
if ( isset($middle[1]) ) {
$headers[trim($middle[0])] = trim($middle[1]);
}
}
$http_code = explode(' ', $headers['status']);
curl_close($curl);
if ( $output == false ) {
return array(
'status' => 0,
'message' => 'Address timed out. Make sure it\'s accessible by your server\'s network.'
);
} else {
if ( $http_code[1] != 200) {
return array(
'status' => 0,
'message' => 'Mautic not found: '. $headers['status']
);
} else {
$favicon = file_get_contents($url.'/favicon.ico', false, stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)
)));
if ($favicon) {
return array(
'status' => 1,
'message' => 'OK, Mautic found.'
);
} else {
return array(
'status' => 0,
'message' => 'Mautic not found. Make sure favicon.ico exists in the domain root, check for errors in your server error log.'
);
}
}
}
} else {
return array(
'status' => 0,
'message' => 'cURL PHP extension is not installed on your server.'
);
}
}
/*
|--------------------------------------------------------------------------
| Find Mautic version by path
|--------------------------------------------------------------------------
*/
public function mauticVersion($path)
{
$data = array();
if ( substr($path, -1) == '/' ) {
$path = substr($path, 0, -1);
}
if (file_exists($path.'/app/version.txt')) {
$file = fopen($path.'/app/version.txt', 'r') or die('Unable to open file!');
$version = trim(fread($file , filesize($path.'/app/version.txt')));
if (strpos($version, '-dev') !== false) {
return array(
'status' => 0,
'message' => 'You are using a development version of Mautic ('.$version.'). Whitelabeler only supports official, non-beta releases.'
);
} else {
return $this->templateVersions($version);
}
} else {
$release_metadata = $path.'/app/release_metadata.json';
// Look for >= 3.0.0 /app/release_metadata.json
if (file_exists($release_metadata)) {
$release_metadata = $path.'/app/release_metadata.json';
$file = fopen($path.'/app/release_metadata.json', 'r') or die('Unable to open file!');
$version = json_decode(fread($file, filesize($release_metadata)), true);
$version = $version['version'];
if (strpos($version, '-dev') !== false) {
return array(
'status' => 0,
'message' => 'You are using a development version of Mautic ('.$version.'). Whitelabeler only supports official, non-beta releases.'
);
} else {
return $this->templateVersions($version);
}
// Couldn't find version.txt or release_metadata.json
} else {
return array(
'status' => 0,
'message' => $path.'/app/version.txt file not found.'
);
}
}
}
/*
|--------------------------------------------------------------------------
| Check for an asset by URL
|--------------------------------------------------------------------------
*/
public function assetExists($url)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOBODY => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false
));
$output = curl_exec($curl);
$headers = [];
$data = explode("\n",$output);
$headers['status'] = $data[0];
array_shift($data);
foreach($data as $key => $part) {
$middle = explode(":",$part);
if ( isset($middle[1]) ) {
$headers[trim($middle[0])] = trim($middle[1]);
}
}
$http_code = explode(' ', $headers['status']);
if ($http_code[1] == 200) {
return 1;
} else {
return 0;
}
}
/*
|--------------------------------------------------------------------------
| Look for an image in assets folder
|--------------------------------------------------------------------------
*/
public function imageExists($image)
{
if ( file_exists(__DIR__.'/assets/'.$image) ) {
return true;
} else {
return false;
}
}
/*
|--------------------------------------------------------------------------
| Replace Colors in Stylesheets
|--------------------------------------------------------------------------
*/
public function colors(
$path,
$version,
$logo_bg,
$primary,
$hover,
$sidebar_bg,
$sidebar_submenu_bg,
$sidebar_link,
$sidebar_link_hover,
$active_icon,
$divider_left,
$sidebar_divider,
$submenu_bullet_bg,
$submenu_bullet_shadow
) {
// Replace app.css contents with template and new colors
$app_css = $path.'/app/bundles/CoreBundle/Assets/css/app.css';
if (file_exists($app_css)) {
$app_css_template = file_get_contents('templates/'.$version.'/app/bundles/CoreBundle/Assets/css/app.css');
$app_css_new = str_replace(
// Look for these template tags.
array('{{logo_bg}}', '{{primary}}', '{{hover}}', '{{sidebar_bg}}', '{{sidebar_submenu_bg}}',
'{{sidebar_link}}', '{{sidebar_link_hover}}', '{{active_icon}}', '{{divider_left}}', '{{sidebar_divider}}',
'{{submenu_bullet_bg}}', '{{submenu_bullet_shadow}}'
),
// Replace template tags with new colors.
array($logo_bg, $primary, $hover, $sidebar_bg, $sidebar_submenu_bg, $sidebar_link, $sidebar_link_hover,
$active_icon, $divider_left, $sidebar_divider, $submenu_bullet_bg, $submenu_bullet_shadow
),
$app_css_template
);
$file = fopen($app_css, "w");
fwrite($file, $app_css_new);
fclose($file);
} else {
return array(
'status' => 0,
'message' => 'Unable to find app.css in your Mautic installation.'
);
}
// Replace libraries.css contents with template and new colors
$libraries_css = $path.'/app/bundles/CoreBundle/Assets/css/libraries/libraries.css';
if (file_exists($libraries_css)) {
$libraries_css_template = file_get_contents('templates/'.$version.'/app/bundles/CoreBundle/Assets/css/libraries/libraries.css');
$libraries_css_new = str_replace(
// Look for these template tags.
array('{{$logo_bg}}','{{primary}}','{{hover}}'),
// Replace template tags with new colors.
array($logo_bg, $primary, $hover),
$libraries_css_template
);
$file = fopen($libraries_css, "w");
fwrite($file, $libraries_css_new);
fclose($file);
return array(
'status' => 1,
'message' => 'CSS files updated with new colors!'
);
} else {
return array(
'status' => 0,
'message' => 'Unable to find libraries.css in your Mautic installation.'
);
}
}
/*
|--------------------------------------------------------------------------
| Replace "Mautic" with Company Name
|--------------------------------------------------------------------------
*/
public function companyName($path, $version, $company_name, $footer_prefix, $footer)
{
$base_copyright = '/app/bundles/CoreBundle/Views/Default/base.html.php';
$head_title = '/app/bundles/CoreBundle/Views/Default/head.html.php';
$js = '1a.content.js';
$core_js = '/app/bundles/CoreBundle/Assets/js/'.$js;
$left_panel = '/app/bundles/CoreBundle/Views/LeftPanel/index.html.php';
$login_page = '/app/bundles/UserBundle/Views/Security/base.html.php';
$errors = array();
if (file_exists($path.$base_copyright)) {
// get template
$base_copyright_template = file_get_contents('templates/'.$version.$base_copyright);
// fill template tags
if ( $footer_prefix != '' ) {
$footer_prefix_base = '. ' . $footer_prefix;
} else {
$footer_prefix_base = $footer;
}
if ( $footer != '' ) {
$footer_base = '| '.$footer;
} else {
$footer_base = $footer;
}
$base_copyright_new = str_replace(array('{{company_name}}', '{{footer_prefix}}', '{{footer}}'), array($company_name, $footer_prefix_base, $footer_base), $base_copyright_template);
// Replace Mautic file
$file = fopen($path.$base_copyright, "w");
fwrite($file, $base_copyright_new);
fclose($file);
} else {
$errors[] = 'Unable to find Mautic file: '.$base_copyright;
}
if (file_exists($path.$head_title)) {
// get template
$head_title_template = file_get_contents('templates/'.$version.$head_title);
// fill template tags
$head_title_new = str_replace('{{company_name}}', $company_name, $head_title_template);
// Replace Mautic file
$file = fopen($path.$head_title, "w");
fwrite($file, $head_title_new);
fclose($file);
} else {
$errors[] = 'Unable to find Mautic file: '.$head_title;
}
if (file_exists($path.$login_page)) {
// get template
$login_page_template = file_get_contents('templates/'.$version.$login_page);
// fill template tags
if ( $footer_prefix != '' ) {
$footer_prefix_login = '. ' . $footer_prefix;
} else {
$footer_prefix_login = $footer_prefix;
}
$login_page_new = str_replace(array('{{company_name}}', '{{footer_prefix}}', '{{footer}}'), array($company_name, $footer_prefix_login, $footer), $login_page_template);
// Replace Mautic file
$file = fopen($path.$login_page, "w");
fwrite($file, $login_page_new);
fclose($file);
} else {
$errors[] = 'Unable to find Mautic file: '.$login_page;
}
if (file_exists($path.$core_js)) {
// get template
$core_js_template = file_get_contents('templates/'.$version.$core_js);
// fill template tags
$core_js_new = str_replace('{{company_name}}', $company_name, $core_js_template);
// Replace Mautic file
$file = fopen($path.$core_js, "w");
fwrite($file, $core_js_new);
fclose($file);
} else {
$errors[] = 'Couldn\'t find core javascript file to update.';
}
if (empty($errors)) {
return array(
'status' => 1,
'message' => 'Updated company name in templates!'
);
} else {
return array(
'status' => 0,
'message' => $errors
);
}
}
/*
|--------------------------------------------------------------------------
| Resize and Save Image File
|--------------------------------------------------------------------------
*/
public function imageResize($new_width, $original, $target)
{
$info = getimagesize($original);
if ($info['mime'] == 'image/png') {
try {
$im = imagecreatefrompng($original);
} catch(Exception $e) {
echo 'Error with image: ', $e->getMessage(), "\n";
exit();
}
$srcWidth = imagesx($im);
$srcHeight = imagesy($im);
if ( $new_width <= 400 ) {
$nWidth = $info[0];
} else {
$nWidth = 400;
}
$nHeight = ($srcHeight / $srcWidth) * $nWidth;
$newImg = imagecreatetruecolor($nWidth, $nHeight);
imagealphablending($newImg, false);
imagesavealpha($newImg,true);
$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
imagefilledrectangle($newImg, 0, 0, $nWidth, $nHeight, $transparent);
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight, $srcWidth, $srcHeight);
$target = $target;
imagepng($newImg, $target);
return $target;
} else {
if ($info['mime'] == 'image/jpeg' ) {
$image_create_func = 'imagecreatefromjpeg';
$image_save_func = 'imagejpeg';
} elseif($info['mime'] == 'image/gif') {
$image_create_func = 'imagecreatefromgif';
$image_save_func = 'imagegif';
} else {
echo 'Unknown image format';
exit();
}
$img = $image_create_func($original);
list($width, $height) = getimagesize($original);
$newHeight = ($height / $width) * $new_width;
$tmp = imagecreatetruecolor($new_width, $newHeight);
imagecopyresampled($tmp, $img, 0, 0, 0, 0, $new_width, $newHeight, $width, $height);
$image_save_func($tmp, "$target");
return $target;
}
}
/*
|--------------------------------------------------------------------------
| Process and Replace Images
|--------------------------------------------------------------------------
*/
public function replaceImages(
$path,
$url,
$version,
$sidebar_image,
$sidebar_width,
$sidebar_margin, // array (top, right, left)
$login_image,
$login_width,
$login_margin, // array (top, bottom)
$favicon_image
) {
if ( $favicon_image == false ) {
$favicon_image = $login_image;
}
$media_images = $path.'/media/images';
// Update favicon
require_once('vendor/chrisjean/php-ico/class-php-ico.php');
// If favicon is .ico, move/copy the file
if ( strpos(finfo_file(finfo_open(FILEINFO_MIME_TYPE),$favicon_image), 'ico') ) { // check if the mimetype of picture contain ico (match all image/*ico* )
copy($favicon_image, $path.'/favicon.ico');
copy($path.'/favicon.ico', $media_images.'/favicon.ico');
// convert to .ico and save.
} else {
$ico_lib = new PHP_ICO($favicon_image, array(array(64, 64)));
$ico_lib->save_ico($path.'/favicon.ico');
$ico_lib->save_ico($media_images.'/favicon.ico');
}
// Update sidebar logo
$this->imageResize(250, $sidebar_image, $media_images.'/sidebar_logo.png');
$left_panel = $path.'/app/bundles/CoreBundle/Views/LeftPanel/index.html.php';
if (file_exists($left_panel)) {
$left_panel_template = file_get_contents('templates/'.$version.'/app/bundles/CoreBundle/Views/LeftPanel/index.html.php');
$left_panel_new = str_replace(
// Look for these template tags.
array('{{sidebar_image}}', '{{sidebar_width}}', '{{margin_top}}','{{margin_right}}', '{{margin_left}}'),
// Replace template tags with values.
array('media/images/sidebar_logo.png', $sidebar_width, $sidebar_margin['top'], $sidebar_margin['right'], $sidebar_margin['left']),
$left_panel_template
);
$file = fopen($left_panel, "w");
fwrite($file, $left_panel_new);
fclose($file);
} else {
return array(
'status' => 0,
'message' => $left_panel.' NOT FOUND.'
);
}
// Update login logo and create some icons from login logo
// Apple Touch Icon
$this->imageResize(192, $login_image, $media_images.'/apple-touch-icon.png');
// mautic_logo_db64.png
$this->imageResize(64, $login_image, $media_images.'/mautic_logo_db64.png');
// mautic_logo_db200.png
$this->imageResize(200, $login_image, $media_images.'/mautic_logo_db200.png');
// mautic_logo_lb200.png
$this->imageResize(200, $login_image, $media_images.'/mautic_logo_lb200.png');
$this->imageResize(400, $login_image, $media_images.'/login_logo.png');
$login_page = $path.'/app/bundles/UserBundle/Views/Security/base.html.php';
if ( file_exists($login_page) ) {
$login_page_template = file_get_contents($login_page);
$login_page_new = str_replace(
// Look for these template tags.
array('{{login_logo}}', '{{login_logo_width}}', '{{login_logo_margin_top}}', '{{login_logo_margin_bottom}}'),
// Replace template tags with values.
array('media/images/login_logo.png', $login_width, $login_margin['top'], $login_margin['bottom']),
// In this file
$login_page_template
);
$file = fopen($login_page, "w");
fwrite($file, $login_page_new);
fclose($file);
return array(
'status' => 1,
'message' => 'Logos updated! '
);
} else {
return array(
'status' => 0,
'message' => $login_page.' NOT FOUND.'
);
}
}
/*
|--------------------------------------------------------------------------
| Used to run Mautic Console Commands (taken from upgrade.php)
|--------------------------------------------------------------------------
*/
public function runSymfonyCommand($path, $command, array $args)
{
static $application;
$autoloadPath = file_exists($path.'/autoload.php') ? $path.'/autoload.php' : $path.'/app/autoload.php';
require_once $autoloadPath;
require_once $path.'/app/AppKernel.php';
$args = array_merge(
['console', $command],
$args
);
if (null == $application) {
$kernel = new \AppKernel('prod', true);
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
}
$input = new \Symfony\Component\Console\Input\ArgvInput($args);
$output = new \Symfony\Component\Console\Output\NullOutput();
$exitCode = $application->run($input, $output);
unset($input, $output);
return $exitCode === 0;
}
/*
|--------------------------------------------------------------------------
| Used to Clear Cache (taken from upgrade.php)
|--------------------------------------------------------------------------
*/
public function recursiveRemoveDirectory($directory) {
// if the path has a slash at the end we remove it here
if (substr($directory, -1) == '/') {
$directory = substr($directory, 0, -1);
}
// if the path is not valid or is not a directory ...
if (!file_exists($directory)) {
return true;
} elseif (!is_dir($directory)) {
return false;
// ... if the path is not readable
} elseif (!is_readable($directory)) {
// ... we return false and exit the function
return false;
// ... else if the path is readable
} else {
// we open the directory
$handle = opendir($directory);
// and scan through the items inside
while (false !== ($item = readdir($handle))) {
// if the filepointer is not the current directory
// or the parent directory
if ($item != '.' && $item != '..') {
// we build the new path to delete
$path = $directory.'/'.$item;
// if the new path is a directory
if (is_dir($path)) {
// we call this function with the new path
$this->recursiveRemoveDirectory($path);
// if the new path is a file
} else {
// we remove the file
@unlink($path);
}
}
}
// close the directory
closedir($handle);
// try to delete the now empty directory
if (!@rmdir($directory)) {
// return false if not possible
return false;
}
// return success
return true;
}
}
/*
|--------------------------------------------------------------------------
| Rebuild the Cache
|--------------------------------------------------------------------------
*/
public function buildCache($path)
{
return $this->runSymfonyCommand($path, 'cache:clear', ['--no-interaction', '--env=prod', '--no-debug', '--no-warmup']);
}
/*
|--------------------------------------------------------------------------
| Clear and Rebuild the Cache
|--------------------------------------------------------------------------
*/
public function clearMauticCache($path)
{
$cachePath = is_dir($path.'/var/cache/prod') ? $path.'/var/cache/prod' : 'app/cache/prod';
if (!$this->recursiveRemoveDirectory($cachePath)) {
return array(
'status' => 0,
'message' => 'Could not remove the application cache. You will need to do this manually.'
);
}
return array(
'status' => 1,
'message' => $this->buildCache($path)
);
}
/*
|--------------------------------------------------------------------------
| Rebuild Mautic Assets
|--------------------------------------------------------------------------
*/
public function rebuildAssets($path)
{
return $this->runSymfonyCommand($path, 'mautic:assets:generate', ['--no-interaction', '--env=prod', '--no-debug']);
}
/*
|--------------------------------------------------------------------------
| Get Compatible Versions of Mautic for Whitelabeling
|--------------------------------------------------------------------------
*/
public function templateVersions($version)
{
$path = 'templates';
$versions = array();
foreach (new DirectoryIterator($path) as $file) {
if ($file->isDot()) continue;
if ($file->isDir()) {
array_push($versions, $file->getFilename());
}
}
if (in_array(substr($version, 0, 3), $versions) || in_array($version, $versions)) {
return array(
'status' => 1,
'version' => $version,
'message' => 'Compatible version found ('.$version.')'
);
} else {
return array(
'status' => 0,
'message' => 'The version of Mautic you are using ('.$version.') is not currently supported.'
);
}
}
/*
|--------------------------------------------------------------------------
| Compare two versions of Mautic to see files relevant to whitelabeling
| have been changed.
|--------------------------------------------------------------------------
*/
public function compareMauticVersions($v1, $v2)
{
$comparision = array();
$base_copyright = '/app/bundles/CoreBundle/Views/Default/base.html.php';
if (file_exists($v1.$base_copyright) && file_exists($v2.$base_copyright)) {
$v1_base_copyright = sha1(file_get_contents($v1.$base_copyright));
$v2_base_copyright = sha1(file_get_contents($v2.$base_copyright));
if ( $v1_base_copyright == $v2_base_copyright ) {
$comparision[$base_copyright] = 'Same';
} else {
$comparision[$base_copyright] = 'Different';
}
} else {
$comparision[$base_copyright] = 'File Not Found';
}
$head_title = '/app/bundles/CoreBundle/Views/Default/head.html.php';
if (file_exists($v1.$head_title) && file_exists($v2.$head_title)) {
$v1_head_title = sha1(file_get_contents($v1.$head_title));
$v2_head_title = sha1(file_get_contents($v2.$head_title));
if ( $v1_head_title == $v2_head_title ) {
$comparision[$head_title] = 'Same';
} else {
$comparision[$head_title] = 'Different';
}
} else {
$comparision[$head_title] = 'File Not Found';
}
$left_panel = '/app/bundles/CoreBundle/Views/LeftPanel/index.html.php';
if (file_exists($v1.$left_panel) && file_exists($v2.$left_panel)) {
$v1_left_panel = sha1(file_get_contents($v1.$left_panel));
$v2_left_panel = sha1(file_get_contents($v2.$left_panel));
if ( $v1_left_panel == $v2_left_panel ) {
$comparision[$left_panel] = 'Same';
} else {
$comparision[$left_panel] = 'Different';
}
} else {
$comparision[$left_panel] = 'File Not Found';
}
$login_logo = '/app/bundles/UserBundle/Views/Security/base.html.php';
if (file_exists($v1.$login_logo) && file_exists($v2.$login_logo)) {
$v1_login_logo = sha1(file_get_contents($v1.$login_logo));
$v2_login_logo = sha1(file_get_contents($v2.$login_logo));
if ( $v1_login_logo == $v2_login_logo ) {
$comparision[$login_logo] = 'Same';
} else {
$comparision[$login_logo] = 'Different';
}
} else {
$comparision[$login_logo] = 'File Not Found';
}
$app_css = '/app/bundles/CoreBundle/Assets/css/app.css';
if (file_exists($v1.$app_css) && file_exists($v2.$app_css)) {
$v1_app_css = sha1(file_get_contents($v1.$app_css));
$v2_app_css = sha1(file_get_contents($v2.$app_css));
if ( $v1_app_css == $v2_app_css ) {
$comparision[$app_css] = 'Same';
} else {
$comparision[$app_css] = 'Different';
}
} else {
$comparision[$app_css] = 'File Not Found';
}
$libraries_css = '/app/bundles/CoreBundle/Assets/css/libraries/libraries.css';
if (file_exists($v1.$libraries_css) && file_exists($v2.$libraries_css)) {
$v1_libraries_css = sha1(file_get_contents($v1.$libraries_css));
$v2_libraries_css = sha1(file_get_contents($v2.$libraries_css));
if ( $v1_libraries_css == $v2_libraries_css ) {
$comparision[$libraries_css] = 'Same';
} else {
$comparision[$libraries_css] = 'Different';
}
} else {
$comparision[$libraries_css] = 'File Not Found';
}
$core_js = '/app/bundles/CoreBundle/Assets/js/1.core.js';
if (file_exists($v1.$core_js) && file_exists($v2.$core_js)) {
$v1_core_js = sha1(file_get_contents($v1.$core_js));
$v2_core_js = sha1(file_get_contents($v2.$core_js));
if ( $v1_core_js == $v2_core_js ) {
$comparision[$core_js] = 'Same';
} else {
$comparision[$core_js] = 'Different';
}
} else {
$comparision[$core_js] = 'File Not Found';
}
$content_js = '/app/bundles/CoreBundle/Assets/js/1a.content.js';
if (file_exists($v1.$content_js) && file_exists($v2.$content_js)) {
$v1_content_js = sha1(file_get_contents($v1.$content_js));
$v2_content_js = sha1(file_get_contents($v2.$content_js));
if ( $v1_content_js == $v2_content_js ) {
$comparision[$content_js] = 'Same';
} else {
$comparision[$content_js] = 'Different';
}
} else {
$comparision[$content_js] = 'File Not Found';
}
return $comparision;
}
/*
|--------------------------------------------------------------------------
| Validate configuration values from config.json
|--------------------------------------------------------------------------
*/
public function validateConfigValues($file=false)
{
if ( $file != false ) {
$config_vals = $this->loadJsonConfig($file);
} else {
$config_vals = $this->loadJsonConfig('config.json');
}
$errors = array();
// Verify the PATH in config.txt is correct and Mautic exists there
$path = $this->mauticVersion($config_vals['path']);
if ( $path['status'] != 1 ) {
$errors[] = $path['message'];
}
// Verify the URL in config.txt is correct
$url = $this->findMauticUrl($config_vals['url']);
if ( $url['status'] != 1 ) {
$errors[] = 'Invalid URL provided' . (isset($url['message']) ? ', ' . $url['message'] : '') . '.';
}
// Verify that a COMPANY name is defined in config.txt
if ( !$config_vals['company'] ) {
$errors[] = 'Please provide a company name.';
}
// Verify that a valid hex value is provided for primary in config.json
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['primary'] ) ) {
$errors[] = 'Invalid hex value provided for the primary color.';
}
// Verify that a valid hex value is provided for hover in config.json
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['hover'] ) ) {
$errors[] = 'Invalid hex value provided for the hover color.';
}
// Verify that a valid hex value is provided for logo_bg
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['logo_bg'] ) ) {
$errors[] = 'Invalid hex value provided for the sidebar logo background color.';
}
// Verify that a valid hex value is provided for sidebar_bg
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['sidebar_bg'] ) ) {
$errors[] = 'Invalid hex value provided for the sidebar background color.';
}
// Verify that a valid hex value is provided for sidebar_bg
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['sidebar_submenu_bg'] ) ) {
$errors[] = 'Invalid hex value provided for the sidebar submenu background color.';
}
// Verify that a valid hex value is provided for sidebar_link
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['sidebar_link'] ) ) {
$errors[] = 'Invalid hex value provided for the sidebar link color.';
}
// Verify that a valid hex value is provided for sidebar_link_hover
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['sidebar_link_hover'] ) ) {
$errors[] = 'Invalid hex value provided for the sidebar link hover color.';
}
// Verify that a valid hex value is provided for active_icon
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['active_icon'] ) ) {
$errors[] = 'Invalid hex value provided for the active icon color.';
}
// Verify that a valid hex value is provided for sidebar_divider
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['sidebar_divider'] ) ) {
$errors[] = 'Invalid hex value provided for the sidebar divider color.';
}
// Verify that a valid hex value is provided for submenu_bullet_bg
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['submenu_bullet_bg'] ) ) {
$errors[] = 'Invalid hex value provided for the submenu bullet background color.';
}
// Verify that a valid hex value is provided for submenu_bullet_shadow
if ( !preg_match('/#([a-fA-F0-9]{3}){1,2}\b/', $config_vals['submenu_bullet_shadow'] ) ) {
$errors[] = 'Invalid hex value provided for the submenu bullet shadow color.';
}
// Verify that sidebar_image file exists in the assets folder
if ( !$this->imageExists($config_vals['sidebar_logo']) ) {
$errors[] = 'Can\'t find the sidebar image provided ('.$config_vals['sidebar_logo'].')';
}
// Verify that a valid numeric value for sidebar_logo_width was provided
if ( !is_numeric($config_vals['sidebar_logo_width']) ) {
$errors[] = 'Invalid sidebar logo width value provided.';
}
// Verify that a valid sidebar_logo_margin_top number was provided
if ( !is_numeric($config_vals['sidebar_logo_margin_top']) ) {
$errors[] = 'Invalid sidebar_logo_margin_top value provided.';
}
// Verify that a valid sidebar_logo_margin_right number was provided
if ( !is_numeric($config_vals['sidebar_logo_margin_right']) ) {
$errors[] = 'Invalid sidebar_logo_margin_right value provided.';
}
// Verify that a valid sidebar_logo_margin_left number was provided
if ( !is_numeric($config_vals['sidebar_logo_margin_left']) ) {
$errors[] = 'Invalid sidebar_logo_margin_left value provided.';
}
// Verify that login_logo file exists in the assets folder
if ( !$this->imageExists($config_vals['login_logo']) ) {
$errors[] = 'Can\'t find the login logo image provided ('.$config_vals['login_logo'].')';
}
// Verify that a valid numeric value for sidebar_logo_width was provided
if ( !is_numeric($config_vals['login_logo_width']) ) {
$errors[] = 'Invalid login logo width value provided.';
}
// Verify that a valid login_logo_margin_top number was provided
if ( !is_numeric($config_vals['login_logo_margin_top']) ) {
$errors[] = 'Invalid login_logo_margin_top value provided.';
}
// Verify that a valid login_logo_margin_top number was provided
if ( !is_numeric($config_vals['login_logo_margin_bottom']) ) {
$errors[] = 'Invalid login_logo_margin_bottom value provided.';
}
// Verify that favicon file exists in the assets folder
if ( !$this->imageExists($config_vals['favicon']) ) {
$errors[] = 'Can\'t find the favicon image provided ('.$config_vals['favicon'].')';
}
return array(
'errors' => $errors,
'config' => $config_vals
);
}
}