Hulp bij bouwen plugin script
Ik probeer een script aan te passen die gemaakt is voor Joomla. Deze plugin maakt onderdeel uit van een component van Joomsuite. De plugin die ik wil maken die moet van een bepaalde tabel het artikel-id ophalen en weergeven.
Meer niet. De plugin die ik hiervoor wil gebruiken is een plugin die bedoeld is om een email ades van de user weer te geven. User kan deze desgewenst aanpassen.
Wie kan mij hiermee helpen.
script email.php
Code (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
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
<?php
// Check to ensure this file is included in Joomla!
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgJoomsuite_content_fieldsEmail extends JPlugin
{
function plgJoomsuite_content_fieldsEmail( &$subject, $params )
{
parent::__construct( $subject, $params );
}
function onRenderField(&$obj, &$params, $type)
{
if($type != 'email') return;
$def = JRequest::getVar('fields', null, 'default', 'array');
if($def[$obj->id]) $obj->field_value = $def[$obj->id];
$user = JFactory::getUser();
?>
<input type="text" style="width:<?php echo $params->get('field_size')?>" name="fields[<?php echo $obj->id?>]"
value="<?php echo ($obj->field_value ? stripslashes($obj->field_value) : ($params->get('user_default') ? $user->get('email'): NULL)) ?>"/>
<?php
}
function onBeforeSave(&$value, &$params, $type, $id, $row, &$error)
{
if($type != 'email') return;
if(!$value) return;
jimport('joomla.utilities.mail');
if(!JMailHelper::isEmailAddress($value))
{
JError::raiseWarning(500, 'Email is not correct');
$error = 1;
}
}
function onRenderFieldValue(&$out, &$field, &$params, $type, $user)
{
if(!$field->field_value) return;
if($type != 'email') return;
$icon = '';
if($params->get('show_icon')) $icon = JHTML::image(JURI::base().
'/components/com_resource/images/mail.gif', 'mail icon', array('align' => 'absmiddle'));
if($params->get('encode')){
$email = $field->field_value;
$field->field_value = '';
$len = strlen($email);
for ($i=0;$i<$len;$i++)
{
$r = rand(0, 1);
$field->field_value .= ($r ? "&#" . ord($email{$i}) .';' : $email{$i} );
}
}
if($params->get('show')) $text = $field->field_value; else $text = JText::_('Email');
$out = $icon.' '.JHTML::link('mailto:'.$field->field_value, $text);
}
}
[/code]
script email.xml
[code]
[code]<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="joomsuite_content_fields" method="upgrade">
<name>Content Field - Email</name>
<author>JoomSuite</author>
<creationDate>May 2008</creationDate>
<copyright>Copyright (C) 2005 - 2008 JoomSuite. All rights reserved.</copyright>
<license>Commercial</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.joomsuite.com</authorUrl>
<version>1.3</version>
<description>Plugin for JoomSuite Content add new field type (Email)</description>
<files>
<filename plugin="email">email.php</filename>
</files>
<params>
<param name="encode" type="radio" default="1" label="Obfuscate Email" description="">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="show" type="radio" default="0" label="Show email" description="">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="user_default" type="radio" default="1" label="Insert User's email as default" description="">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
</params>
</install>
Mijn eigen kennis van PHP is marginaal
// Check to ensure this file is included in Joomla!
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgJoomsuite_content_fieldsEmail extends JPlugin
{
function plgJoomsuite_content_fieldsEmail( &$subject, $params )
{
parent::__construct( $subject, $params );
}
function onRenderField(&$obj, &$params, $type)
{
if($type != 'email') return;
$def = JRequest::getVar('fields', null, 'default', 'array');
if($def[$obj->id]) $obj->field_value = $def[$obj->id];
$user = JFactory::getUser();
?>
<input type="text" style="width:<?php echo $params->get('field_size')?>" name="fields[<?php echo $obj->id?>]"
value="<?php echo ($obj->field_value ? stripslashes($obj->field_value) : ($params->get('user_default') ? $user->get('email'): NULL)) ?>"/>
<?php
}
function onBeforeSave(&$value, &$params, $type, $id, $row, &$error)
{
if($type != 'email') return;
if(!$value) return;
jimport('joomla.utilities.mail');
if(!JMailHelper::isEmailAddress($value))
{
JError::raiseWarning(500, 'Email is not correct');
$error = 1;
}
}
function onRenderFieldValue(&$out, &$field, &$params, $type, $user)
{
if(!$field->field_value) return;
if($type != 'email') return;
$icon = '';
if($params->get('show_icon')) $icon = JHTML::image(JURI::base().
'/components/com_resource/images/mail.gif', 'mail icon', array('align' => 'absmiddle'));
if($params->get('encode')){
$email = $field->field_value;
$field->field_value = '';
$len = strlen($email);
for ($i=0;$i<$len;$i++)
{
$r = rand(0, 1);
$field->field_value .= ($r ? "&#" . ord($email{$i}) .';' : $email{$i} );
}
}
if($params->get('show')) $text = $field->field_value; else $text = JText::_('Email');
$out = $icon.' '.JHTML::link('mailto:'.$field->field_value, $text);
}
}
[/code]
script email.xml
[code]
[code]<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="joomsuite_content_fields" method="upgrade">
<name>Content Field - Email</name>
<author>JoomSuite</author>
<creationDate>May 2008</creationDate>
<copyright>Copyright (C) 2005 - 2008 JoomSuite. All rights reserved.</copyright>
<license>Commercial</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.joomsuite.com</authorUrl>
<version>1.3</version>
<description>Plugin for JoomSuite Content add new field type (Email)</description>
<files>
<filename plugin="email">email.php</filename>
</files>
<params>
<param name="encode" type="radio" default="1" label="Obfuscate Email" description="">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="show" type="radio" default="0" label="Show email" description="">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="user_default" type="radio" default="1" label="Insert User's email as default" description="">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
</params>
</install>
Mijn eigen kennis van PHP is marginaal
Gewijzigd op 01/01/1970 01:00:00 door Steve
Bedankt voor de tip :-)