-
-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathhtml.php
More file actions
executable file
·3060 lines (2850 loc) · 97.8 KB
/
Copy pathhtml.php
File metadata and controls
executable file
·3060 lines (2850 loc) · 97.8 KB
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 /*
* $Id$
*
* AbanteCart, Ideal OpenSource Ecommerce Solution
* http://www.AbanteCart.com
*
* Copyright © 2011-2025 Belavier Commerce LLC
*
* This source file is subject to Open Software License (OSL 3.0)
* License details are bundled with this package in the file LICENSE.txt.
* It is also available at this URL:
* <http://www.opensource.org/licenses/OSL-3.0>
*
* UPGRADE NOTE:
* Do not edit or add to this file if you wish to upgrade AbanteCart to newer
* versions in the future. If you wish to customize AbanteCart for your
* needs, please refer to http://www.AbanteCart.com for more information.
*/
/** @noinspection PhpMultipleClassDeclarationsInspection */
if (!defined('DIR_CORE')) {
header('Location: static_pages/');
}
/**
* Class AHtml
* @method SelectboxHtmlElement buildSelectBox(array $data)
* @method MultiSelectboxHtmlElement buildMultiSelectBox(array $data)
* @method HiddenHtmlElement buildHidden(array $data)
* @method MultiValueHtmlElement buildMultiValue(array $data)
* @method MultiValueListHtmlElement buildMultiValueList(array $data)
* @method SubmitHtmlElement buildSubmit(array $data)
* @method InputHtmlElement buildInput(array $data)
* @method PasswordHtmlElement buildPassword(array $data)
* @method TextareaHtmlElement buildTextarea(array $data)
* @method TextEditorHtmlElement buildTextEditor(array $data)
* @method CheckboxHtmlElement buildCheckbox(array $data)
* @method CheckboxGroupHtmlElement buildCheckboxGroup(array $data)
* @method FileHtmlElement buildFile(array $data)
* @method RadioHtmlElement buildRadio(array $data)
* @method ButtonHtmlElement buildButton(array $data)
* @method RatingHtmlElement buildRating(array $data)
* @method CaptchaHtmlElement buildCaptcha(array $data)
* @method ReCaptchaHtmlElement buildReCaptcha(array $data)
* @method PasswordSetHtmlElement buildPasswordSet(array $data)
* @method ResourceHtmlElement buildResource(array $data)
* @method ResourceImageHtmlElement buildResourceImage(array $data)
* @method DateHtmlElement buildDate(array $data)
* @method EmailHtmlElement buildEmail(array $data)
* @method NumberHtmlElement buildNumber(array $data)
* @method PhoneHtmlElement buildPhone(array $data)
* @method IPAddressHtmlElement buildIPAddress(array $data)
* @method CountriesHtmlElement buildCountries(array $data)
* @method ZonesHtmlElement buildZones(array $data)
* @method PaginationHtmlElement buildPagination(array $data)
* @method ModalHtmlElement buildModal(array $data)
* @method LabelHtmlElement buildLabel(array $data)
*/
class AHtml extends AController
{
/**
* @var Registry
*/
protected $registry;
/**
* @var array
*/
protected $args = [];
/**
* @var ARequest
*/
protected $request;
/**
* @param Registry $registry
*/
public function __construct($registry)
{
$this->registry = $registry;
$this->request = $this->registry->get('request');
}
/**
* Magic method for html-element classes calls
*
* @param string $function_name
* @param $args
*
* @return null|string
* @throws AException
*/
public function __call(string $function_name, $args)
{
$class_name = ltrim($function_name, 'build') . 'HtmlElement';
if (class_exists($class_name)) {
/**
* @var SelectboxHtmlElement|HiddenHtmlElement| $item
*/
$item = new $class_name($args[0]);
if (method_exists($item, 'getHtml')) {
return $item->getHtml();
} else {
unset($item);
}
}
return null;
}
/**
* PR Build sub URL
*
* @param string $rt
* @param string $params
*
* @return string
* @throws AException
*/
private function buildURL($rt, $params = '')
{
$subUrl = '';
//#PR Add admin path if we are in admin
if (IS_ADMIN) {
$subUrl .= '&s=' . ADMIN_PATH;
}
//add template if present
if (!empty($this->request->get['sf'])) {
$subUrl .= '&sf=' . $this->request->get['sf'];
}
//if in embed mode add response prefix
if ($this->registry->get('config')->get('embed_mode')) {
$subUrl .= '&embed_mode=1';
if (substr($rt, 0, 2) != 'r/') {
$rt = 'r/' . $rt;
}
}
return '?' . ($rt ? 'rt=' . $rt : '') . $params . $subUrl;
}
/**
* Get non-secure home URL.
*
* @return string
*
* Note: Non-secure URL is base on store_url setting. If this setting is using https URL, all URLs will be secure
* @throws AException
*/
public function getHomeURL()
{
$seo_prefix = $this->registry->get('config')->get('seo_prefix');
//for embed mode get home link with getURL
if ($this->registry->get('config')->get('embed_mode')) {
return $this->getURL('index/home');
} else {
//get config_url first
$home_url = $this->registry->get('config')->get('config_url') . $seo_prefix;
if (!$home_url) {
$home_url = defined('HTTP_SERVER')
? HTTP_SERVER . $seo_prefix
: 'http://' . REAL_HOST . get_url_path($_SERVER['PHP_SELF']);
}
return $home_url;
}
}
/**
* Get non-secure URL. Read note below.
*
* @param string $rt
* @param string $params
* @param string $encode
*
* @return string
*
* Note: Non-secure URL is base on store_url setting. If this setting is using https URL, all URLs will be secure
* @throws AException
*/
public function getNonSecureURL($rt, $params = '', $encode = '')
{
return $this->getURL($rt, $params, $encode, true);
}
/**
* Get URL with auto-detection for protocol
*
* @param string $rt
* @param string $params
* @param string $encode
* @param bool $nonsecure - force to be non-secure
*
* @return string
* @throws AException
*/
public function getURL($rt, $params = '', $encode = '', $nonsecure = false)
{
$seo_prefix = $this->registry->get('config')->get('seo_prefix');
//detect if request is using HTTPS
if ($nonsecure === false && HTTPS === true) {
$server = defined('HTTPS_SERVER')
? HTTPS_SERVER . $seo_prefix
: 'https://' . REAL_HOST . get_url_path($_SERVER['PHP_SELF']);
} else {
//to prevent garbage session need to check constant HTTP_SERVER
$server = defined('HTTP_SERVER')
? HTTP_SERVER . $seo_prefix
: 'http://' . REAL_HOST . get_url_path($_SERVER['PHP_SELF']);
}
if ($this->registry->get('config')->get('storefront_template_debug')
&& isset($this->request->get['tmpl_debug'])
) {
$params .= '&tmpl_debug=' . $this->request->get['tmpl_debug'];
}
// add session id for cross-domain transition in secure mode
if ($this->registry->get('config')->get('config_shared_session') && HTTPS === true) {
$params .= '&session_id=' . session_id();
}
//add token for embed mode with forbidden 3d-party cookies
if ($this->registry->get('session')->data['session_mode'] == 'embed_token') {
$params .= '&' . EMBED_TOKEN_NAME . '=' . session_id();
}
return $server . INDEX_FILE . $this->url_encode($this->buildURL($rt, $params), $encode);
}
/**
* Build secure URL with session token
*
* @param string $rt
* @param string $params
* @param string $encode
*
* @return string
* @throws AException
*/
public function getSecureURL($rt, $params = '', $encode = '')
{
$session = $this->registry->get('session');
$config = $this->registry->get('config');
$seo_prefix = $config->get('seo_prefix');
// add session id for cross-domain transition in non-secure mode
if ($config->get('config_shared_session') && HTTPS !== true) {
$params .= '&session_id=' . session_id();
}
$subUrl = $this->buildURL($rt, $params);
if (IS_ADMIN === true || (defined('IS_API') && IS_API === true)) {
//Add session token for admin and API
if (isset($session->data['token']) && $session->data['token']) {
$subUrl .= '&token=' . $this->registry->get('session')->data['token'];
}
}
//add token for embed mode with forbidden 3d-party cookies
if ($session->data['session_mode'] == 'embed_token') {
$subUrl .= '&' . EMBED_TOKEN_NAME . '=' . session_id();
}
if ($config->get('storefront_template_debug') && isset($this->request->get['tmpl_debug'])) {
$subUrl .= '&tmpl_debug=' . $this->request->get['tmpl_debug'];
}
return HTTPS_SERVER . $seo_prefix . INDEX_FILE . $this->url_encode($subUrl, $encode);
}
/**
* Build non-secure SEO URL
*
* @param string $rt
* @param string $params
* @param string $encode
*
* @return string
* @throws AException
*/
public function getSEOURL($rt, $params = '', $encode = '')
{
//skip SEO for embed mode
if ($this->registry->get('config')->get('embed_mode')) {
return $this->getURL($rt, $params);
}
$this->loadModel('tool/seo_url');
//#PR Generate SEO URL based on standard URL
//NOTE: SEO URL is non-secure url
return $this->url_encode($this->model_tool_seo_url->rewrite($this->getNonSecureURL($rt, $params)), $encode);
}
/**
* Build secure SEO URL
*
* @param string $rt
* @param string $params
* @param string $encode
*
* @return string
* @throws AException
*/
public function getSecureSEOURL($rt, $params = '', $encode = '')
{
//add token for embed mode with forbidden 3d-party cookies
if ($this->registry->get('session')->data['session_mode'] == 'embed_token') {
$params .= '&' . EMBED_TOKEN_NAME . '=' . session_id();
}
//#PR Generate SEO URL based on standard URL
$this->loadModel('tool/seo_url');
return $this->url_encode($this->model_tool_seo_url->rewrite($this->getSecureURL($rt, $params)), $encode);
}
/**
* This builds URL to the catalog to be used in admin
*
* @param string $rt
* @param string $params
* @param string $encode
* @param bool $ssl
*
* @return string
* @throws AException
*/
public function getCatalogURL($rt, $params = '', $encode = '', $ssl = false)
{
$seo_prefix = $this->registry->get('config')->get('seo_prefix');
//add token for embed mode with forbidden 3d-party cookies
if ($this->registry->get('session')->data['session_mode'] == 'embed_token') {
$params .= '&' . EMBED_TOKEN_NAME . '=' . session_id();
}
$subUrl = '?' . ($rt ? 'rt=' . $rt : '') . $params;
if ($this->registry->get('config')->get('config_ssl') == 2) {
$ssl = true;
}
if ($ssl && parse_url($this->registry->get('config')->get('config_ssl_url'), PHP_URL_SCHEME) == 'https') {
$HTTPS_SERVER = $this->registry->get('config')->get('config_ssl_url') . $seo_prefix;
} else {
$HTTPS_SERVER = HTTPS_SERVER . $seo_prefix;
}
$http = $ssl ? $HTTPS_SERVER : HTTP_SERVER . $seo_prefix;
return $http . INDEX_FILE . $this->url_encode($subUrl, $encode);
}
/**
* encode URL for & to be &
*
* @param string $url
* @param bool $encode
*
* @return string
*/
public function url_encode($url, $encode = false)
{
if ($encode) {
return str_replace('&', '&', (string)$url);
} else {
return $url;
}
}
/**
* Current URL built based on get params with ability to exclude params
*
* @param $filter_params array - array of vars to filter
*
* @return string - url without unwanted filter parameters
* @throws AException
*/
public function currentURL($filter_params = [])
{
$params_arr = $this->request->get;
//detect if there is RT in the params.
$rt = 'index/home';
if (has_value($params_arr['rt'])) {
$rt = $params_arr['rt'];
$filter_params[] = 'rt';
}
if (has_value($params_arr['s'])) {
$filter_params[] = 's';
}
$URI = '&' . $this->buildURI($params_arr, $filter_params);
return $this->getURL($rt, $URI);
}
/**
* URI encrypt parameters in URI
*
* @param $uri
*
* @return string - url without unwanted filter parameters
* @internal param array $filter_params - array of vars to filter
*/
public function encryptURI($uri)
{
$encrypted = base64_encode($uri);
if (strlen($encrypted) <= 250) {
return '__e=' . $encrypted;
} else {
return $uri;
}
}
/**
* Build URI from array provided
*
* @param $params_arr array - data array to process
* @param $filter_params array - array of vars to filter
*
* @return string - url without unwanted filter parameters
*/
public function buildURI($params_arr, $filter_params = [])
{
foreach ($filter_params as $rv) {
unset($params_arr[$rv]);
}
return urldecode(http_build_query($params_arr, '', '&'));
}
/**
* Filter query parameters from url.
*
* @param $url string - url to process
* @param $filter_params string|array - single var or array of vars
*
* @return string - url without unwanted filter query parameters
*/
public function filterQueryParams($url, $filter_params = [])
{
list($url_part, $q_part) = explode('?', $url);
parse_str($q_part, $q_vars);
//build array if passed as string
if (!is_array($filter_params)) {
$filter_params = [$filter_params];
}
foreach ($filter_params as $rv) {
unset($q_vars[$rv]);
}
foreach ($q_vars as $key => $val) {
$q_vars[$key] = $this->request->clean($val);
}
$new_qs = urldecode(http_build_query($q_vars, '', '&'));
return $url_part . '?' . $new_qs;
}
/**
* function returns text error or empty
*
* @param string $query
* @param string $keyword
*
* @return string
* @throws AException
*/
public function isSEOKeywordExists($query = '', $keyword = '')
{
if (!$keyword) {
return '';
}
$seo_key = SEOEncode($keyword);
$db = $this->registry->get('db');
$sql = "SELECT *
FROM " . $db->table('url_aliases') . "
WHERE query<>'" . $db->escape($query) . "' AND keyword='" . $db->escape($seo_key) . "'";
$result = $db->query($sql);
$kList = array_merge(
array_column($result->rows, 'keyword'),
array_map('basename', glob(DIR_ROOT . DS . '*', GLOB_ONLYDIR))
);
if (in_array($seo_key, $kList)) {
$url = HTTP_CATALOG . $seo_key;
return $this->language->getAndReplace('error_seo_keyword', '', [$url, $seo_key]);
}
return '';
}
/**
* create html code based on passed data
*
* @param $data - array with element data
* sample
* $data = array(
* 'type' => 'input' //(hidden, textarea, selectbox, file...)
* 'name' => 'input name'
* 'value' => 'input value' // can be an array for select
* 'style' => 'my-form'
* 'form' => 'form id' // needed for unique element ID *
* );
*
* @return object
* @throws AException
*/
public function buildElement($data)
{
return HtmlElementFactory::create($data);
}
/**
* @return string
* @throws AException
*/
public function getStoreSwitcher()
{
$registry = $this->registry;
$view = new AView($this->registry, 0);
//check if store_id is passed or in the session
$store_id = $registry->get('config')->get('current_store_id');
//set store selector
$stores = [];
$hidden = [];
$stores[0] = ['name' => $registry->get('language')->get('text_default')];
$registry->get('load')->model('setting/store');
/**
* @var ModelSettingStore $model
*/
$model = $registry->get('model_setting_store');
//if loaded not default store - hide store switcher
$default_store_settings = $model->getStore(0);
if ($this->registry->get('config')->get('config_url') != $default_store_settings['config_url']) {
return '';
}
$result_stores = $model->getStores();
if (sizeof($result_stores) <= 1) {
//hide store switcher if only one store
return '';
} else {
foreach ($result_stores as $rs) {
$stores[$rs['store_id']] = [
'name' => $rs['alias'] ?: $rs['name'],
'store_id' => $rs['store_id'],
];
}
foreach ($registry->get('request')->get as $name => $value) {
if ($name == 'store_id') {
continue;
}
$hidden[$name] = $value;
}
$view->assign('all_stores', $stores);
$view->assign('current_store', $stores[$store_id]['name']);
$view->assign('hiddens', $hidden);
$view->assign('text_select_store', $registry->get('language')->get('text_select_store'));
return $view->fetch('form/store_switcher.tpl');
}
}
/**
* @return string
* @throws AException
*/
public function getContentLanguageSwitcher()
{
$registry = $this->registry;
$view = new AView($this->registry, 0);
$registry->get('load')->model('localisation/language');
$results = $registry->get('model_localisation_language')->getLanguages();
$template['languages'] = [];
foreach ($results as $result) {
if ($result['status']) {
$template['languages'][] = [
'name' => $result['name'],
'code' => $result['code'],
'image' => $result['image'],
];
}
}
if (sizeof($template['languages']) > 1) {
//selected in selectbox
$template['language_code'] = $registry->get('language')->getContentLanguageCode();
foreach ($registry->get('request')->get as $name => $value) {
if ($name == 'content_language_code') {
continue;
}
$template['hiddens'][$name] = $value;
}
} else {
$template['languages'] = [];
}
$view->batchAssign($template);
return $view->fetch('form/language_switcher.tpl');
}
/**
* @return string
* @throws AException
*/
public function getContentLanguageFlags()
{
$registry = $this->registry;
$view = new AView($this->registry, 0);
$registry->get('load')->model('localisation/language');
$results = $registry->get('model_localisation_language')->getLanguages();
$template['languages'] = [];
foreach ($results as $result) {
if ($result['status']) {
$template['languages'][] = [
'name' => $result['name'],
'code' => $result['code'],
'image' => $result['image'],
];
}
}
if (sizeof($template['languages']) > 1) {
//selected in selectbox
$template['language_code'] = $registry->get('language')->getContentLanguageCode();
foreach ($registry->get('request')->get as $name => $value) {
if ($name == 'content_language_code') {
continue;
}
$template['hiddens'][$name] = $value;
}
} else {
$template['languages'] = [];
}
$view->batchAssign($template);
return $view->fetch('form/language_flags.tpl');
}
/**
* @return string
* @throws AException
*/
public function installLanguageModal(string $mode = 'render')
{
$packCartVersion = '';
$registry = $this->registry;
$view = new AView($this->registry, 0);
$languages = $registry->get('extensions')->getExtensionsList(['filter' => 'language']);
$loaded = array_column((array)$languages->rows, 'key');
$remote = [];
$fp = @fopen('https://github.com/abantecart/abantecart-languages/raw/refs/heads/master/list.txt', 'r');
if ($fp) {
while (($line = fgets($fp)) !== false) {
$remote[] = trim($line);
}
fclose($fp);
}
//detect last cart version
$url = 'https://github.com/abantecart/abantecart-languages/releases/tag/v' . VERSION;
if (isUrlAlive($url)) {
$packCartVersion = VERSION;
} elseif (VERSION_BUILT != 0) {
$versionBuilt = (int)VERSION_BUILT - 1;
while ($versionBuilt != 0) {
$url = 'https://github.com/abantecart/abantecart-languages/releases/tag/v' . MASTER_VERSION . '.' . MINOR_VERSION . '.' . $versionBuilt;
if (isUrlAlive($url)) {
$packCartVersion = MASTER_VERSION . '.' . MINOR_VERSION . '.' . $versionBuilt;
break;
}
$versionBuilt--;
}
}
//show only at least one language can be loaded
$uninstalled = array_diff($remote, $loaded);
if ($uninstalled && $packCartVersion) {
$template = [];
foreach ($uninstalled as $name) {
$langName = str_replace('default_', '', $name);
$template['packages'][$name] =
[
'name' => $langName,
'image_url' => 'https://github.com/abantecart/abantecart-languages/raw/refs/heads/master/' . $name . '/image/icon%402x.png',
'install_url' => 'https://github.com/abantecart/abantecart-languages/releases/download/v' . $packCartVersion . '/' . $name . '.tar.gz'
];
}
$template['text_load_languages'] = $this->language->get('button_load_more_languages', 'extension/extensions');
if ($mode == 'render') {
$view->batchAssign($template);
/** @see form/language_install.tpl */
return $view->fetch('form/language_install.tpl');
} else {
return $template['packages'];
}
}
return '';
}
/**
* @param string $html - text that might contain internal links #admin# or #storefront#
* $mode - 'href' create complete a tag or default just replace URL
* @param string $type - can be 'message' to convert url into <a> tag or empty
* @param bool $for_admin - force mode for converting links to admin side from storefront scope (see AIM-class etc.)
*
* @return string - html code with parsed internal URLs
* @throws AException
*/
public function convertLinks($html, $type = '', $for_admin = false)
{
$is_admin = (IS_ADMIN === true || $for_admin);
$route_sections = $is_admin ? ["admin", "storefront"] : ["storefront"];
foreach ($route_sections as $rt_type) {
preg_match_all(
'/(#' . $rt_type . '#rt=)[A-z0-9\/_\-?&=%#]{1,255}(\b|")/',
$html,
$matches,
PREG_OFFSET_CAPTURE
);
if ($matches) {
foreach ($matches[0] as $match) {
$href = str_replace('?', '&', (string)$match[0]);
if ($rt_type == 'admin') {
if ($for_admin && IS_ADMIN !== true) {
$href .= '&s=' . ADMIN_PATH;
}
$new_href = str_replace('#admin#', $this->getSecureURL('') . '&', $href);
} else {
$new_href = str_replace('#storefront#', $this->getCatalogURL('') . '&', $href);
}
$new_href = str_replace(['&', '&&', '&?'], '&', $new_href);
$new_href = str_replace('?&', '?', $new_href);
$new_href = str_replace('&', '&', $new_href);
switch ($type) {
case 'message':
$new_href = '<a href="' . $new_href . '" target="_blank">#link-text#</a>';
break;
default:
break;
}
$html = str_replace($match[0], $new_href, $html);
}
}
}
return $html;
}
}
/**
* Class HtmlElementFactory
*/
class HtmlElementFactory
{
static private $available_elements = [
'I' => [
'type' => 'input',
'method' => 'buildInput',
'class' => 'InputHtmlElement',
],
'T' => [
'type' => 'textarea',
'method' => 'buildTextarea',
'class' => 'TextareaHtmlElement',
],
'S' => [
'type' => 'selectbox',
'method' => 'buildSelectbox',
'class' => 'SelectboxHtmlElement',
],
'M' => [
'type' => 'multiselectbox',
'method' => 'buildMultiselectbox',
'class' => 'MultiSelectboxHtmlElement',
],
'R' => [
'type' => 'radio',
'method' => 'buildRadio',
'class' => 'RadioHtmlElement',
],
'C' => [
'type' => 'checkbox',
'method' => 'buildCheckbox',
'class' => 'CheckboxHtmlElement',
],
'G' => [
'type' => 'checkboxgroup',
'method' => 'buildCheckboxgroup',
'class' => 'CheckboxgroupHtmlElement',
],
'U' => [
'type' => 'file',
'method' => 'buildFile',
'class' => 'FileHtmlElement',
],
'K' => [
'type' => 'captcha',
'method' => 'buildCaptcha',
'class' => 'CaptchaHtmlElement',
],
'J' => [
'type' => 'recaptcha',
'method' => 'buildReCaptcha',
'class' => 'ReCaptchaHtmlElement',
],
'H' => [
'type' => 'hidden',
'method' => 'buildHidden',
'class' => 'HiddenHtmlElement',
],
'P' => [
'type' => 'multivalue',
'method' => 'buildMultivalue',
'class' => 'MultiValueHtmlElement',
],
'L' => [
'type' => 'multivaluelist',
'method' => 'buildMultivalueList',
'class' => 'MultivalueListHtmlElement',
],
'D' => [
'type' => 'date',
'method' => 'buildDateInput',
'class' => 'DateInputHtmlElement',
],
'E' => [
'type' => 'email',
'method' => 'buildEmail',
'class' => 'EmailHtmlElement',
],
'N' => [
'type' => 'number',
'method' => 'buildNumber',
'class' => 'NumberHtmlElement',
],
'F' => [
'type' => 'phone',
'method' => 'buildPhone',
'class' => 'PhoneHtmlElement',
],
'A' => [
'type' => 'IPaddress',
'method' => 'buildIPaddress',
'class' => 'IPaddressHtmlElement',
],
'O' => [
'type' => 'countries',
'method' => 'buildCountries',
'class' => 'CountriesHtmlElement',
],
'Z' => [
'type' => 'zones',
'method' => 'buildZones',
'class' => 'ZonesHtmlElement',
],
'B' => [
'type' => 'label',
'method' => 'buildLabel',
'class' => 'LabelHtmlElement',
],
];
static private $elements_with_options = [
'S',
'M',
'R',
'G',
'O',
'Z',
];
static private $multivalue_elements = [
'M',
'R',
'G',
];
static private $elements_with_placeholder = [
'S',
'I',
'M',
'O',
'Z',
'F',
'N',
'E',
'D',
'U',
'T',
];
/**
* return array of HTML elements supported
* array key - code of element
* [
* type - element type
* method - method in html class to get element html
* class - element class
* ]
*
* @static
* @return array
*/
static function getAvailableElements()
{
return self::$available_elements;
}
/**
* return array of elements indexes for elements which has options
*
* @static
* @return array
*/
static function getElementsWithOptions()
{
return self::$elements_with_options;
}
/**
* return array of elements indexes for elements which has options
*
* @static
* @return array
*/
static function getElementsWithPlaceholder()
{
return self::$elements_with_placeholder;
}
/**
* return array of elements indexes for elements which has options
*
* @static
* @return array
*/
static function getMultivalueElements()
{
return self::$multivalue_elements;
}
/**
* return element type
*
* @static
*
* @param $code - element code ( from $available_elements )
*
* @return null | string
*/
static function getElementType($code)
{
if (!array_key_exists($code, self::$available_elements)) {
return null;
}
return self::$available_elements[$code]['type'];
}
/**
* @param $data
*
* @return HiddenHtmlElement | MultivalueListHtmlElement | MultivalueHtmlElement | SubmitHtmlElement
* @return InputHtmlElement | PasswordHtmlElement | PaginationHtmlElement | TextareaHtmlElement
* @return SelectboxHtmlElement | MultiSelectboxHtmlElement | CheckboxHtmlElement
* @return CheckboxGroupHtmlElement | FileHtmlElement | RadioHtmlElement | ButtonHtmlElement
* @return FormHtmlElement | RatingHtmlElement | CaptchaHtmlElement | ReCaptchaHtmlElement
* @return PasswordSetHtmlElement | ResourceHtmlElement | ResourceImageHtmlElement | DateHtmlElement
* @return EmailHtmlElement | NumberHtmlElement | PhoneHtmlElement | IPaddressHtmlElement
* @return CountriesHtmlElement | ZonesHtmlElement | ModalHtmlElement
*
* @throws AException
*/
static function create($data)
{
$class = ucfirst($data['type'] . 'HtmlElement');
if (!class_exists($class)) {
throw new AException(AC_ERR_LOAD, 'Error: Could not load HTML element ' . $data['type'] . '!');
}
return new $class($data);
}
}
/**
* @abstract
* Class HtmlElement
* @property mixed $value
* @property array $options
* @property array $disabled_options
* @property bool $required
* @property bool $multilingual
* @property string $template
* @property array $history
* @property AMessage $messages
*
* @property ARequest $request
* @property AConfig $config
* @property ALoader $load
* @property ALanguageManager|ALanguage $language
* @property AHtml $html
* @property ADocument $document
* @property CSRFToken $csrftoken
* @property string $icon
*/
abstract class HtmlElement
{
/** @var array */
protected $data = [];
/** @var string */