-
Notifications
You must be signed in to change notification settings - Fork 0
/
e_shortcode.php
138 lines (114 loc) · 4.19 KB
/
e_shortcode.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
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2025 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* #######################################
* # e107 contact plugin #
* # by Jimako #
* # https://www.e107sk.com #
* #######################################
*/
if (!defined('e107_INIT'))
{
exit;
}
class econtact_shortcodes extends e_shortcode
{
static $contactPrefs = array();
public function __construct() {
self::$contactPrefs = e107::pref('econtact');
}
/**
* Shortcode to display contact email with various formatting options.
*
* Parameters:
* - source (optional): Specifies which email to use. Default is "email1".
* - type (optional): Determines the format of the output. Options include:
* - "text" (default): Displays the obfuscated email as plain text.
* - "link": Displays the email as a clickable, obfuscated mailto link.
* - "custom": Displays a custom-styled mailto link with optional CSS classes.
* - class (optional): CSS class to apply when using the "custom" type.
*
* Usage examples:
* - {CONTACT_EMAIL: type=text}
* - {CONTACT_EMAIL: source=email2&type=link}
* - {CONTACT_EMAIL: type=custom&class=btn btn-primary}
*
* @param array|null $parm Parameters for the shortcode.
* @return string Obfuscated email address based on the provided parameters.
*/
public function sc_contact_email($parm = null)
{
$tp = e107::getParser();
// Set default values for parameters
$source = $parm['source'] ?? "email1";
$type = $parm['type'] ?? "text";
$class = isset($parm['class']) ? "class='" . e107::getParser()->toAttribute($parm['class']) . "'" : "";
// Get email from preferences
$email = self::$contactPrefs["contact_{$source}"] ?? null;
// Return empty if email is not set
if (empty($email))
{
return '';
}
// Generate the output based on the 'type' parameter
switch ($type)
{
case "link":
return $tp->emailObfuscate($email);
case "custom":
$obfuscatedEmail = $tp->obfuscate($email);
return "<a {$class} href='mailto:{$email}'>{$obfuscatedEmail}</a>";
case "text":
default:
return $tp->obfuscate($email);
}
}
/**
* Shortcode to display contact information based on the type passed in $parm.
* @param array|null $parm Parameters that specify which type of contact info to display.
* @return string|null Parsed HTML output or obfuscated email/phone.
*/
public function sc_contact_info($parm = null)
{
// Fetch contact information from preferences
$contactInfo = e107::getPref('contact_info');
// Get the 'type' parameter from $parm
$type = $parm['type'] ?? null;
// If no type is specified or the contact info for that type is not set, return null
if (empty($type) || empty($contactInfo[$type]))
{
return null;
}
// Get the parser object for HTML rendering and obfuscation
$tp = e107::getParser();
// Variable to hold the return value
$ret = '';
// Handle different types of contact information
switch ($type)
{
case "organization":
// Render the organization name as a title
$ret = $tp->toHTML($contactInfo[$type], true, 'TITLE');
break;
case 'email1':
case 'email2':
case 'phone1':
case 'phone2':
case 'phone3':
case 'fax':
// Obfuscate the contact information (email or phone numbers)
$ret = $tp->obfuscate($contactInfo[$type]);
break;
default:
// Render other contact information as a body element
$ret = $tp->toHTML($contactInfo[$type], true, 'BODY');
break;
}
return $ret;
}
}