-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiField.php
105 lines (84 loc) · 3.11 KB
/
multiField.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
<?php
# get correct id for plugin
$thisfile = basename(__FILE__, ".php");
# add in this plugin's language file
i18n_merge('multiField') || i18n_merge('multiField', 'en_US');
# register plugin
register_plugin(
$thisfile, //Plugin id
'MultiField 🏖️', //Plugin name
'4.1', //Plugin version
'Multicolor', //Plugin author
'#', //author website
i18n_r('multiField/DESCRIPTION'), //Plugin description
'plugins', //page type - on which admin tab to display
'multiField' //main function (administration)
);
# add a link in the admin tab 'theme'
add_action('plugins-sidebar', 'createSideMenu', array($thisfile, i18n_r('multiField/SETTINGS').' 🏖️'));
function multiField()
{
if (isset($_GET['creator'])) {
include(GSPLUGINPATH . 'multiField/view/addNew.inc.php');
}elseif (isset($_GET['migrate'])) {
include(GSPLUGINPATH . 'multiField/view/migrate.inc.php');
}elseif (isset($_GET['position'])) {
include(GSPLUGINPATH . 'multiField/view/position.inc.php');
}else {
include(GSPLUGINPATH . 'multiField/view/list.inc.php');
}
echo '<div id="paypal" style="margin-top:10px; background: #fafafa; border:solid 1px #ddd; padding: 10px;box-sizing: border-box; text-align: center;">
<p style="margin-bottom:10px;">'.i18n_r('multiField/PAYPAL').' </p>
<a href="https://www.paypal.com/donate/?hosted_button_id=TW6PXVCTM5A72"><img alt="" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0"></a>
</div>';
}
add_action('edit-extras', 'extrasMultiField');
function extrasMultiField()
{
include(GSPLUGINPATH . 'multiField/view/extras.inc.php');
};
add_action('changedata-save', 'save');
function save()
{
global $url;
if (isset($_POST['submitted'])) {
$file = file_get_contents(GSDATAOTHERPATH . 'multiField/' . $url . '.json');
$multiFieldType = $_POST['type-multifield'];
$multiFieldLabel = $_POST['label-multifield'];
$multiField = $_POST['multifield'];
$ars = array();
foreach ($multiField as $key => $value) {
$ars[$multiFieldLabel[$key]] = ["label" => $multiFieldLabel[$key], "value" => htmlentities(htmlentities($value)), "type" => $multiFieldType[$key]];
};
$final = json_encode($ars, true);
if (file_exists(GSDATAOTHERPATH . 'multiField/') == null) {
mkdir(GSDATAOTHERPATH . 'multiField/', 0755);
}
file_put_contents(GSDATAOTHERPATH . 'multiField/' . $url . '.json', $final);
};
};
//frontend
function multiFields($name)
{
$file = GSDATAOTHERPATH . 'multiField/' . return_page_slug() . '.json';
if (file_exists($file)) {
$final = json_decode(file_get_contents($file), true);
foreach ($final as $key => $value) {
if ($final[$key]['label'] == $name) {
echo html_entity_decode(html_entity_decode($final[$key]['value']));
}
}
}
}
function r_multiFields($name)
{
$file = GSDATAOTHERPATH . 'multiField/' . return_page_slug() . '.json';
if (file_exists($file)) {
$final = json_decode(file_get_contents($file), true);
foreach ($final as $key => $value) {
if ($final[$key]['label'] == $name) {
return html_entity_decode(html_entity_decode($final[$key]['value']));
}
}
}
}