Page 1 of 1
Userprofile VCard Export
Posted: Mon Feb 25, 2008 10:30 am
by Linus
Hi Folks!
I have problems trying to export the birthday from a user to the vcf-file.
In the profile form there are 3 input fields (day | month | year).
When the form is saved the variable containing the date is set with mktime:
Code: Select all
$serendipity['POST']['profilebirthday'] = mktime(0, 0, 0, $serendipity['POST']['profilebirthday_month'], serendipity['POST']['profilebirthday_day'], $serendipity['POST']['profilebirthday_year']);
Passing the variable directly to the vcard isn't working because the format "yyyy-mm-dd" is required.
So I tried to change the date with
Code: Select all
strftime("%Y-%m-%d", $serendipity['POST']['profilebirthday']);
which results in the right output-format and is written to the vcf - but always with the date 1970-01-01...
Thanks in advance
Regards Andi
Re: Userprofile VCard Export
Posted: Mon Feb 25, 2008 11:19 am
by garvinhicking
Hi!
Where did you put the strftime command? Directly after the mktime call? If you get 1970, it means the variable for your timestamp contains a zero or is not set.
Regards,
Garvin
Posted: Mon Feb 25, 2008 12:54 pm
by Linus
Hi Garvin,
thanks a lot - you've pointed the right direction. I've changed the following:
Code: Select all
$serendipity['POST']['profilebirthday'] = strftime("%Y-%m-%d",mktime(0, 0, 0,...));
and it worked. This required a change in the inputfields too, because the value was wrong when loading the form.
Wonderful
Mmh that takes me to another question.
Right now I'm storing the vcf's from the authors in uploads/Kontakte/*.vcf. The problem is, that every visitor is able to download them with the right url.
Is there an easy way to store the vcfs in a directory where only logged users can access them?
Greets Andi
Posted: Mon Feb 25, 2008 1:25 pm
by garvinhicking
Hi!
Right now I'm storing the vcf's from the authors in uploads/Kontakte/*.vcf. The problem is, that every visitor is able to download them with the right url.
Is there an easy way to store the vcfs in a directory where only logged users can access them?
Greets Andi
No, there is no means for serendipity to protect browsable directories to user logins. You can only do this if you fetch VCFs dynamically from the DB instead of storing files in the filesystem.
Regards,
Garvin
Posted: Mon Feb 25, 2008 1:43 pm
by Linus
Another way I'm currently thinking about, is to store the vcf files in a folder outside the webroot and creating a new menu item in the administration panel fetching the contents of the folder...
Is there anything to worry about doing it this way? if its possible
Another thing I thought about is to use the download-manager plugin...
Or maybe to encode the vcfs and decode them when downloading from admin-panel?
Posted: Mon Feb 25, 2008 2:28 pm
by garvinhicking
Hi!
But if you fetch the files, do you deletre them afterwards? Else, the files would still be accessible after you fetched them once
I'd really suggest to dynamically build the VCF and make links like "download.php?vcf_id=XXX" and there you can check the serendipity_userLoggedin and authorids to only fetch your own VCF?
Regards,
Garvin
Posted: Tue Feb 26, 2008 8:00 am
by Linus
Hi,
it's me again. I'm trying to modify the userprofile plugin. I want that every author can view the complete profile of another author and export it as vcard. It should be some kind of address management with the ability to download vcf from every users.
Therefore I need to modify the profile page. At the moment I can select an author and get his complete profile.
I've changed the following to get it working:
Code: Select all
function showUser(&$user) {
global $serendipity;
echo '<table border="0" cellspacing="0" cellpadding="3" width="100%">';
$local_properties =& $this->getLocalProperties();
foreach($local_properties as $property => $info) {
echo '<tr><td>'.$info['desc'].'</td><td>'.$user[$property].'</td></tr>';
}
echo '</table>';
}
to:
Code: Select all
function showUser(&$user) {
global $serendipity;
echo '<table border="0" cellspacing="0" cellpadding="3" width="100%">';
$profile =& $this->getConfigVars($user['authorid']);
foreach($this->properties as $property => $info) {
if (isset($serendipity['POST']['submitProfileOptions']) && isset($serendipity['POST']['profile' . $property])) {
$user[$property] = $serendipity['POST']['profile' . $property];
$this->updateConfigVar($property, $profile, $user[$property], $user['authorid']);
$profile[$property] = $user[$property];
} else {
$user[$property] = $profile[$property];
}
$this->showCol($property, $info, $user);
}
echo '</table>';
To provide every author with the ability to export the contact as vcard i've set the export button out of a if clause in function showUsers().
Now to the problem. Everytime I want to export a contact as vcard I get the following error:
FN not specified and N not set; cannot set FN.FN component not set (required).
Catchable fatal error: Object of class PEAR_Error could not be converted to string in /var/www/bretsch/serendipity/plugins/serendipity_event_userprofiles/serendipity_event_userprofiles.php on line 768
I'm not quite sure but I think I got problems with $serendipity['POST']['profileUser']. I'm really stuck in this...
Thanks in Advance
Regards Andi
Posted: Tue Feb 26, 2008 11:07 am
by garvinhicking
Hi!
Try a print_r() on the POST-Data. I sure think you are missing the profile option input, because it does not come from POST but you must fetch it from the Database.
Regards,
Garvin
Posted: Tue Feb 26, 2008 1:41 pm
by Linus
Hi,
Code: Select all
print_r($serendipity['POST']['profileUser']);
shows the right authorid of the selected user which is what I need for creating a VCard:
Code: Select all
function createVCard($authorid) { ...
In the createVCard function I added some prints for debugging too which gives me following results:
$authorid and $serendipity['POST']['profileUser'] are set. But all other POST variables like profilename,... are empty.
It sounds like I have to write a new function getVCard fetching the profile data from database and streaming the vcard with header()...
Am I right or has someone another suggestion?
Regards Andi
Posted: Tue Feb 26, 2008 2:43 pm
by garvinhicking
Hi!
Exactly, you'll need to fetch the vcard data from the database in this case.
Regards,
Garvin
Posted: Thu Feb 28, 2008 8:56 am
by Linus
Hi Garvin,
I got it running

When a user saves his profile a new vcard is written to a folder outside the webroot. If someone wants the vcard from another user, it's fetched from the file not from db (was faster to implement) and then pushed with header()...
Now I got a complete address management with vcard export even with a photo ^^
Thanks a lot
Regards Andi