addMethod('pwg.piwecard.previewEmail', 'piwecard_ws_previewEmail', array( 'format_message'=>array(), 'message'=>array(), ), 'Preview the email' ); /** * Function called by Javascript * @param Array Parameters passed through Javascript * @param * @return String the preview of the email */ function piwecard_ws_previewEmail($params, $service) { $format_message = $params['format_message']; $message = $params['message']; return previewEmail($format_message, $message); } /** * Construct the preview of the email * @param String Email format (text or html) * @param String the email message * @return String the preview of the email */ function previewEmail($format_message, $message) { $piwecard = new Piwecard(); $template_mail = new Template(PIWECARD_MAIL_PATH.'template'); $smarty = $template_mail->smarty; if ($format_message == 'text') { $message_output = nl2br($piwecard->get_text_message(stripslashes(parse($message)), $smarty)); $style = ''; } elseif ($format_message == 'html') { $output = $piwecard->get_html_message(stripslashes(parse($message)), $smarty); $dom_document = new DOMDocument(); $dom_document->loadHTML($output); $styles = piwecard_create_style_array($dom_document->getElementsByTagName('style')->item(0)->nodeValue); $message_output = $dom_document->getElementsByTagName('body')->item(0); $email_body = $dom_document->createElement('div'); $email_body->setAttribute('id', 'email_body'); $message_output->parentNode->insertBefore($email_body, $message_output); $email_body->appendChild($message_output); foreach ($styles as $id => $style) { $dom_document->getElementById(str_replace('#', '', $id))->setAttribute("style", $style); } $message_output = $dom_document->saveHTML(); } return array('message' => $message_output); } /** * Get style from the email template * @param String The value of the node "Style" * @return Array the styles of the email */ function piwecard_create_style_array($style) { $style = str_replace(array("\n", "\t"), array('', ''), $style); $tok = strtok($style, "{}"); $sarray = array(); while ($tok !== false) { array_push($sarray, trim($tok)); $tok = strtok("{}"); } $styles = array(); for($i = 0; $i 'Your Name', '%youremail%' => 'Your email', '%recipientname%' => 'Recipient name', '%recipientemail%' => 'Recipient email', '%website%' => isset($conf['gallery_title']) ? $conf['gallery_title'] : '' , '%websiteurl%' => get_absolute_root_url() , '%ecardurl%' => '', '%ecardtitle%' => 'Ecard title', '%ecardmessage%' => 'The message of the ecard', '%pictureurl%' => get_root_url().PIWECARD_PATH.'admin/images/image_thumb.jpg', '%pictureinfos%' => 'Image infos', ); unset_make_full_url(); $patterns = array(); $replacements = array(); foreach ($ecard_parse as $key => $value) { array_push($patterns, $key); array_push($replacements, $value); } return str_replace($patterns, $replacements, $data); } ?>