/** * This action will handle frontend process requests, currently only creating the vCard for download. * * @TODO If no vcard is found should redirect to an error message. * @access private * @since 0.7.3 * @return void */ public static function frontendActions() { // Grab an instance of the Connections object. $instance = Connections_Directory(); $process = get_query_var('cn-process'); $token = get_query_var('cn-token'); $id = (int) get_query_var('cn-id'); if ('vcard' === $process) { $slug = get_query_var('cn-entry-slug'); //var_dump($slug); /* * If the token and id values were set, the link was likely from the admin. * Check for those values and validate the token. The primary reason for this * to be able to download vCards of entries that are set to "Unlisted". */ if (!empty($id) && !empty($token)) { if (!wp_verify_nonce($token, 'download_vcard_' . $id)) { wp_die('Invalid vCard Token'); } $entry = $instance->retrieve->entry($id); // Die if no entry was found. if (empty($entry)) { wp_die(__('vCard not available for download.', 'connections')); } $vCard = new cnvCard($entry); //var_dump($vCard);die; } else { $entry = $instance->retrieve->entries(array('slug' => $slug)); //var_dump($entry);die; // Die if no entry was found. if (empty($entry)) { wp_die(__('vCard not available for download.', 'connections')); } $vCard = new cnvCard($entry[0]); //var_dump($vCard);die; } $filename = sanitize_file_name($vCard->getName()); //var_dump($filename); $data = $vCard->getvCard(); //var_dump($data);die; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $filename . '.vcf'); header('Content-Length: ' . strlen($data)); header('Pragma: public'); header("Pragma: no-cache"); //header( "Expires: 0" ); header('Expires: Wed, 11 Jan 1984 05:00:00 GMT'); header('Cache-Control: private'); // header( 'Connection: close' ); ob_clean(); flush(); echo $data; exit; } }
<?php /* * This file belong to the Connections plugin. */ if (empty($wp)) { require_once('wp-load.php'); $token = esc_attr($_GET['token']); $id = (integer) esc_attr($_GET['entry']); if (! wp_verify_nonce($token, 'download_vcard_' . $id) ) wp_die('Invalid vCard Token'); global $connections; $entry = $connections->retrieve->entry($id); $vCard = new cnvCard($entry); $filename = sanitize_file_name($vCard->getFullFirstLastName()); header('Content-Type: text/x-vcard; charset=utf-8'); header("Content-Disposition: attachment; filename=" . $filename . ".vcf"); header("Pragma: public"); echo $vCard->getvCard(); } ?>