1<?php 2 3 4namespace dokuwiki\Subscriptions; 5 6 7use Diff; 8use InlineDiffFormatter; 9use UnifiedDiffFormatter; 10 11class PageSubscriptionSender extends SubscriptionSender 12{ 13 14 /** 15 * Send the diff for some page change 16 * 17 * @param string $subscriber_mail The target mail address 18 * @param string $template Mail template ('subscr_digest', 'subscr_single', 'mailtext', ...) 19 * @param string $id Page for which the notification is 20 * @param int|null $rev Old revision if any 21 * @param string $summary Change summary if any 22 * 23 * @return bool true if successfully sent 24 */ 25 public function sendPageDiff($subscriber_mail, $template, $id, $rev = null, $summary = '') 26 { 27 global $DIFF_INLINESTYLES; 28 29 // prepare replacements (keys not set in hrep will be taken from trep) 30 $trep = [ 31 'PAGE' => $id, 32 'NEWPAGE' => wl($id, '', true, '&'), 33 'SUMMARY' => $summary, 34 'SUBSCRIBE' => wl($id, ['do' => 'subscribe'], true, '&'), 35 ]; 36 $hrep = []; 37 38 if ($rev) { 39 $subject = 'changed'; 40 $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); 41 42 $old_content = rawWiki($id, $rev); 43 $new_content = rawWiki($id); 44 45 $df = new Diff( 46 explode("\n", $old_content), 47 explode("\n", $new_content) 48 ); 49 $dformat = new UnifiedDiffFormatter(); 50 $tdiff = $dformat->format($df); 51 52 $DIFF_INLINESTYLES = true; 53 $df = new Diff( 54 explode("\n", $old_content), 55 explode("\n", $new_content) 56 ); 57 $dformat = new InlineDiffFormatter(); 58 $hdiff = $dformat->format($df); 59 $hdiff = '<table>' . $hdiff . '</table>'; 60 $DIFF_INLINESTYLES = false; 61 } else { 62 $subject = 'newpage'; 63 $trep['OLDPAGE'] = '---'; 64 $tdiff = rawWiki($id); 65 $hdiff = nl2br(hsc($tdiff)); 66 } 67 68 $trep['DIFF'] = $tdiff; 69 $hrep['DIFF'] = $hdiff; 70 71 $headers = ['Message-Id' => $this->getMessageID($id)]; 72 if ($rev) { 73 $headers['In-Reply-To'] = $this->getMessageID($id, $rev); 74 } 75 76 return $this->send( 77 $subscriber_mail, 78 $subject, 79 $id, 80 $template, 81 $trep, 82 $hrep, 83 $headers 84 ); 85 } 86 87} 88