1704a815fSMichael Große<?php 2704a815fSMichael Große 3704a815fSMichael Großenamespace dokuwiki\Subscriptions; 4704a815fSMichael Große 5704a815fSMichael Großeuse Diff; 6704a815fSMichael Großeuse InlineDiffFormatter; 7704a815fSMichael Großeuse UnifiedDiffFormatter; 8704a815fSMichael Große 9704a815fSMichael Großeclass PageSubscriptionSender extends SubscriptionSender 10704a815fSMichael Große{ 11704a815fSMichael Große /** 12704a815fSMichael Große * Send the diff for some page change 13704a815fSMichael Große * 14704a815fSMichael Große * @param string $subscriber_mail The target mail address 15704a815fSMichael Große * @param string $template Mail template ('subscr_digest', 'subscr_single', 'mailtext', ...) 16704a815fSMichael Große * @param string $id Page for which the notification is 17704a815fSMichael Große * @param int|null $rev Old revision if any 18704a815fSMichael Große * @param string $summary Change summary if any 19*83734cddSPhy * @param int|null $current_rev New revision if any 20704a815fSMichael Große * 21704a815fSMichael Große * @return bool true if successfully sent 22704a815fSMichael Große */ 23*83734cddSPhy public function sendPageDiff($subscriber_mail, $template, $id, $rev = null, $summary = '', $current_rev = null) 24704a815fSMichael Große { 25704a815fSMichael Große global $DIFF_INLINESTYLES; 26704a815fSMichael Große 27704a815fSMichael Große // prepare replacements (keys not set in hrep will be taken from trep) 28704a815fSMichael Große $trep = [ 29704a815fSMichael Große 'PAGE' => $id, 30*83734cddSPhy 'NEWPAGE' => wl($id, $current_rev ? ('rev=' . $current_rev) : '', true, '&'), 31704a815fSMichael Große 'SUMMARY' => $summary, 32704a815fSMichael Große 'SUBSCRIBE' => wl($id, ['do' => 'subscribe'], true, '&'), 33704a815fSMichael Große ]; 34704a815fSMichael Große $hrep = []; 35704a815fSMichael Große 36704a815fSMichael Große if ($rev) { 37704a815fSMichael Große $subject = 'changed'; 38704a815fSMichael Große $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); 39704a815fSMichael Große 40704a815fSMichael Große $old_content = rawWiki($id, $rev); 41704a815fSMichael Große $new_content = rawWiki($id); 42704a815fSMichael Große 43704a815fSMichael Große $df = new Diff( 44704a815fSMichael Große explode("\n", $old_content), 45704a815fSMichael Große explode("\n", $new_content) 46704a815fSMichael Große ); 47704a815fSMichael Große $dformat = new UnifiedDiffFormatter(); 48704a815fSMichael Große $tdiff = $dformat->format($df); 49704a815fSMichael Große 50704a815fSMichael Große $DIFF_INLINESTYLES = true; 51704a815fSMichael Große $df = new Diff( 52704a815fSMichael Große explode("\n", $old_content), 53704a815fSMichael Große explode("\n", $new_content) 54704a815fSMichael Große ); 55704a815fSMichael Große $dformat = new InlineDiffFormatter(); 56704a815fSMichael Große $hdiff = $dformat->format($df); 57704a815fSMichael Große $hdiff = '<table>' . $hdiff . '</table>'; 58704a815fSMichael Große $DIFF_INLINESTYLES = false; 59704a815fSMichael Große } else { 60704a815fSMichael Große $subject = 'newpage'; 61704a815fSMichael Große $trep['OLDPAGE'] = '---'; 62704a815fSMichael Große $tdiff = rawWiki($id); 63704a815fSMichael Große $hdiff = nl2br(hsc($tdiff)); 64704a815fSMichael Große } 65704a815fSMichael Große 66704a815fSMichael Große $trep['DIFF'] = $tdiff; 67704a815fSMichael Große $hrep['DIFF'] = $hdiff; 68704a815fSMichael Große 69704a815fSMichael Große $headers = ['Message-Id' => $this->getMessageID($id)]; 70704a815fSMichael Große if ($rev) { 71704a815fSMichael Große $headers['In-Reply-To'] = $this->getMessageID($id, $rev); 72704a815fSMichael Große } 73704a815fSMichael Große 74704a815fSMichael Große return $this->send( 75704a815fSMichael Große $subscriber_mail, 76704a815fSMichael Große $subject, 77704a815fSMichael Große $id, 78704a815fSMichael Große $template, 79704a815fSMichael Große $trep, 80704a815fSMichael Große $hrep, 81704a815fSMichael Große $headers 82704a815fSMichael Große ); 83704a815fSMichael Große } 84704a815fSMichael Große} 85