Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
realname
Commits
2988e9f0
Commit
2988e9f0
authored
Jun 04, 2008
by
Nancy Wichmann
Browse files
#266633 by NancyDru for tsavino - corrected theme function for nodes.
Changed separator to pattern.
parent
9d6c6d68
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
15 deletions
+32
-15
realname.install
realname.install
+1
-1
realname.module
realname.module
+23
-14
realname_theme.inc
realname_theme.inc
+8
-0
No files found.
realname.install
View file @
2988e9f0
...
...
@@ -23,7 +23,7 @@ function realname_enable() {
* Implementation of hook_uninstall().
*/
function
realname_uninstall
()
{
variable_del
(
'realname_
sep
'
);
variable_del
(
'realname_
pattern
'
);
variable_del
(
'realname_fields'
);
variable_del
(
'realname_theme'
);
variable_del
(
'realname_nodeapi'
);
...
...
realname.module
View file @
2988e9f0
...
...
@@ -63,7 +63,7 @@ function realname_user($op, &$edit, &$account, $category = null) {
}
/**
*
Implementation of hook_nodeapi().
* Implementation of hook_nodeapi().
*/
function
realname_nodeapi
(
&
$node
,
$op
,
$a3
=
NULL
,
$a4
=
NULL
)
{
if
(
!
variable_get
(
'realname_nodeapi'
,
false
))
{
...
...
@@ -75,14 +75,14 @@ function realname_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
// Save the username that is already there.
$node
->
realname_save
=
$node
->
name
;
$account
=
user_load
(
array
(
'uid'
=>
$node
->
uid
));
$node
->
name
=
realname_make_name
(
$account
);
$node
->
realname
=
$node
->
name
=
realname_make_name
(
$account
);
break
;
case
'prepare'
:
// Node is about to be edited.
// Reset the username or save will fail.
if
(
isset
(
$node
->
realname_save
))
{
$node
->
name
=
$node
->
realname_save
;
$node
->
name
=
$node
->
realname_save
;
}
break
;
}
...
...
@@ -103,7 +103,8 @@ function realname_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
*/
function
realname_make_name
(
&
$account
)
{
$fields
=
variable_get
(
'realname_fields'
,
array
());
$sep
=
variable_get
(
'realname_sep'
,
' '
);
// $sep = variable_get('realname_sep', ' ');
$pattern
=
variable_get
(
'realname_pattern'
,
' '
);
// Has the profile been loaded?
if
(
!
isset
(
$account
->
{
$fields
[
0
][
'name'
]}))
{
...
...
@@ -111,19 +112,26 @@ function realname_make_name(&$account) {
}
$stuff
=
array
();
$i
=
0
;
foreach
(
$fields
as
$name
=>
$weight
)
{
++
$i
;
if
(
isset
(
$account
->
$name
))
{
$stuff
[]
=
$account
->
$name
;
}
$stuff
[
'%'
.
$i
]
=
check_plain
(
$account
->
$name
);
}
else
{
// If there is no value, remove the patterm piece, except the first.
$pattern
=
$i
>
1
?
str_replace
(
'%'
.
$i
,
null
,
$pattern
)
:
$pattern
;
}
}
// If no fields set, use username.
if
(
count
(
$stuff
)
==
0
)
{
$stuff
[]
=
$account
->
name
;
$stuff
[
'%1'
]
=
$account
->
name
;
}
// TODO: Make a pattern, rather than hard separator.
return
implode
(
$sep
,
$stuff
);
$string
=
trim
(
strtr
(
$pattern
,
$stuff
));
return
$string
;
}
/**
...
...
@@ -211,12 +219,12 @@ function realname_admin_settings() {
'#value'
=>
'</table>'
,
);
$form
[
'realname_
sep
'
]
=
array
(
$form
[
'realname_
pattern
'
]
=
array
(
'#type'
=>
'textfield'
,
'#field_prefix'
=>
'<strong>'
.
t
(
'
Separator
'
)
.
'</strong> '
,
'#description'
=>
t
(
'Th
is will be used between the fields to create the "Real name." The default is a single blank
.'
),
'#size'
=>
1
0
,
'#default_value'
=>
variable_get
(
'realname_
sep
'
,
'
'
),
'#field_prefix'
=>
'<strong>'
.
t
(
'
Name Pattern
'
)
.
'</strong> '
,
'#description'
=>
t
(
'Th
e determines how the fields will be used to create the "Real name." Use "%1" to refer to the first field, "%2" to refer to the second, etc.
.'
),
'#size'
=>
3
0
,
'#default_value'
=>
variable_get
(
'realname_
pattern
'
,
'
%1
'
),
);
$form
[
'realname_theme'
]
=
array
(
...
...
@@ -263,7 +271,8 @@ function realname_admin_settings_submit($form_id, $form_values) {
// Okay, save the stuff.
variable_set
(
'realname_fields'
,
$realname_fields
);
variable_set
(
'realname_sep'
,
$form_values
[
'realname_sep'
]);
// variable_set('realname_sep', $form_values['realname_sep']);
variable_set
(
'realname_pattern'
,
$form_values
[
'realname_pattern'
]);
variable_set
(
'realname_theme'
,
$form_values
[
'realname_theme'
]);
variable_set
(
'realname_nodeapi'
,
$form_values
[
'realname_nodeapi'
]);
...
...
realname_theme.inc
View file @
2988e9f0
...
...
@@ -18,6 +18,14 @@
* suggests that this is a site user. Otherwise, only the username is returned.
*/
function
phptemplate_username
(
$object
)
{
// If we have a user id but no realname, then make one.
if
(
$object
->
uid
&&
!
$object
->
realname
)
{
$account
=
user_load
(
array
(
'uid'
=>
$object
->
uid
));
$object
->
realname
=
realname_make_name
(
$object
);
}
// else {
// }
if
(
$object
->
uid
&&
$object
->
realname
)
{
// Shorten the name when it is too long or it will break many tables.
if
(
drupal_strlen
(
$object
->
realname
)
>
20
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment