1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | $service = &$arr[0]; |
---|
6 | $service->addMethod('pwg.piwecard.previewEmail', 'piwecard_ws_previewEmail', |
---|
7 | array( |
---|
8 | 'format_message'=>array(), |
---|
9 | 'message'=>array(), |
---|
10 | ), |
---|
11 | 'Preview the email' |
---|
12 | ); |
---|
13 | |
---|
14 | function piwecard_ws_previewEmail($params, $service) { |
---|
15 | $format_message = $params['format_message']; |
---|
16 | $message = $params['message']; |
---|
17 | |
---|
18 | return previewEmail($format_message, $message); |
---|
19 | } |
---|
20 | |
---|
21 | function previewEmail($format_message, $message) { |
---|
22 | $piwecard = new Piwecard(); |
---|
23 | |
---|
24 | $template_mail = new Template(PIWECARD_MAIL_PATH.'template'); |
---|
25 | $smarty = $template_mail->smarty; |
---|
26 | |
---|
27 | if ($format_message == 'text') { |
---|
28 | $message_output = nl2br($piwecard->get_text_message($message, $smarty)); |
---|
29 | $style = ''; |
---|
30 | } elseif ($format_message == 'html') { |
---|
31 | $output = $piwecard->get_html_message($message, $smarty); |
---|
32 | $dom_document = new DOMDocument(); |
---|
33 | $dom_document->loadHTML($output); |
---|
34 | $style = piwecard_create_style_array($dom_document->getElementsByTagName('style')->item(0)->nodeValue); |
---|
35 | $message_output = $dom_document->saveHTML($dom_document->getElementsByTagName('body')->item(0)); |
---|
36 | $message_output = '<div id="email_body">'.$message_output.'</div>'; |
---|
37 | } |
---|
38 | |
---|
39 | return array('message' => $message_output, 'style' => $style); |
---|
40 | } |
---|
41 | |
---|
42 | function piwecard_create_style_array($style) { |
---|
43 | $style = str_replace(array("\n", "\t"), array('', ''), $style); |
---|
44 | $tok = strtok($style, "{}"); |
---|
45 | |
---|
46 | $sarray = array(); |
---|
47 | while ($tok !== false) { |
---|
48 | array_push($sarray, trim($tok)); |
---|
49 | $tok = strtok("{}"); |
---|
50 | } |
---|
51 | |
---|
52 | $styles = array(); |
---|
53 | |
---|
54 | for($i = 0; $i<count($sarray)-2; $i+=2){ |
---|
55 | $styles[$sarray[$i]] = $sarray[$i+1]; |
---|
56 | } |
---|
57 | |
---|
58 | return $styles; |
---|
59 | } |
---|
60 | ?> |
---|