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