[pmwiki-users] Function in .tmpl file

Thomas Lederer celok at gmx.net
Mon Mar 20 00:38:31 CST 2006

Patrick R. Michaud schrieb am 17.03.2006 14:29 Uhr:
>> I would also be happy if i could define the function in config.php so
>> that the "real name" is accessible through a $LastModRealName and/or
>> $AuthIDRealName variable... (i actually need both)
> If you can forward your function, or at least let me know how
> it's called, I can give an example of turning it into a page
> variable.

Actually i think that this would be the better way, because the author
does appear at so many places. While <!--function does work in the
template, it does not everywhere. And so i would like to come back to
this offer.

Meanwhile i have identified several places where i would need to insert
the Real Name.

Here i give the script (which is crude, but i hope clear in what it
should do), so maybe can help me how to put that into my config, so that
i have variables which are accessible all over the wiki.

Like: RecentChangesFmt, In a wikipage (Sidebar), Template...

Best Regards,

// Here is what i had as cookbookfile...

<?php if (!defined('PmWiki')) exit();

    This  script should be able to spit out the realname from LDAP
    servers related to to a login

    Mode 1: Output of simple text name
    Mode 2: Output of Link

function LDAPRetrieval($pagename, $args) {

// $args being split, because <!--function passes all paramters as $args

list($requested_user, $mode) = split(" ",$args);

if ($requested_user) {

// search and retrieval of the data from the ldap server

         $ldap_userid = 'uid='.$requested_user;
         $ldap_dn = 'dc=xxxxx,dc=com';
         $ldap_server = 'ldap://xxxxx.com';

         $ldapconn = ldap_connect($ldap_server);
         $ldapbind = ldap_bind($ldapconn);

         $result=ldap_search($ldapconn, $ldap_dn, $ldap_userid);

         $info = ldap_get_entries($ldapconn, $result);

         $result_givenname = $info[0]["givenname"][0];
         $result_nickname = $info[0]["nickname"][0];
         $result_sn = $info[0]["sn"][0];
         $result_mail = $info[0]["mail"][0];

         $result_fullname = $result_nickname ?
                         $result_nickname." ".$result_sn :
                         $result_givenname." ".$result_sn;


// Output
// output should be system if page has no editor (nonexistent pages)
// can show PmWiki-Users letter (documentation pages)
// tested by nonexistence in ldap server (ie !result surname)

$unknown_output = $mode ? $requested_user." (PmWiki-user)" : "system";
if (!$result_sn) {echo $unknown_output;}

// Mode 1: textmode, just drop the name
if ($mode == 1) {echo $result_fullname;}

if ($mode == 2) {
echo "<a href='mailto:'.$result_mail.'$result_fullname' ></a>";

More information about the pmwiki-users mailing list