"edit", "e" => "edit minor", "C" => "create", "D" => "delete", "R" => "revert" ); var $_summary = null; var $_payload = null; public function setPayload($payload){ $this->_payload = $payload; } public function attic_write ( $filename ) { if ( strpos ( $filename, 'data/attic' ) !== false ) { return true; } return false; } public function valid_namespace ( ) { global $INFO; $validNamespaces = $this -> getConf ( 'namespaces' ); if ( !empty ( $validNamespaces ) ) { $validNamespacesArr = explode ( ',', $validNamespaces ); foreach ( $validNamespacesArr as $namespace ) { if ( strpos( $namespace, $INFO['namespace'] ) === 0 ) { return true; } } return false; } return true; } public function set_event ( $event ) { $changeType = $event -> data['changeType']; $event_type = $this -> _event_type[$changeType]; $summary = $event -> data['summary']; if ( !empty ( $summary ) ) { $this -> _summary = $summary; } if ( $event_type == 'create' && $this -> getConf ( 'notify_create' ) == 1 ) { $this -> _event = 'create'; return true; } elseif ( $event_type == 'edit' && $this -> getConf ( 'notify_edit' ) == 1 ) { $this -> _event = 'edit'; return true; } elseif ( $event_type == 'edit minor' && ( $this -> getConf ( 'notify_edit' ) == 1 ) && ( $this -> getConf ( 'notify_edit_minor' ) == 1 ) ) { $this -> _event = 'edit minor'; return true; } elseif ( $event_type == 'delete' && $this -> getConf ( 'notify_delete' ) == 1 ) { $this -> _event = 'delete'; return true; } return false; } public function set_payload_text ( $event ) { global $conf; global $lang; global $INFO; $event_name = ''; switch ( $this -> _event ) { case 'create': $title = $this -> getLang ( 't_created' ); $event_name = $this -> getLang ( 'e_created' ); break; case 'edit': $title = $this -> getLang ( 't_updated' ); $event_name = $this -> getLang ( 'e_updated' ); break; case 'edit minor': $title = $this -> getLang ( 't_minor_upd' ); $event_name = $this -> getLang ( 'e_minor_upd' ); break; case 'delete': $title = $this -> getLang ( 't_removed' ); $event_name = $this -> getLang ( 'e_removed' ); break; } if ( $this -> getConf ( 'notify_show_name' ) === 'real name' ) { $user = $INFO['userinfo']['name']; } elseif ( $this -> getConf ( 'notify_show_name' ) === 'username' ) { $user = $_SERVER['REMOTE_USER']; } else { throw new Exception('invalid notify_show_name value'); } $link = $this -> _get_url ( $event, null ); $page = $event -> data['id']; $description = $user.' '.$event_name.' '.$page.'
'; if ( $this -> _event != 'delete' ) { $oldRev = $INFO['meta']['last_change']['date']; if ( !empty ( $oldRev ) ) { $diffURL = $this -> _get_url ( $event, $oldRev ); $description .= ''.$this -> getLang ( 'compare' ).'
'; } } $summary = $this -> _summary; if ( ( strpos ( $this -> _event, 'edit' ) !== false ) && $this -> getConf ( 'notify_show_summary' ) ) { if ( $summary ) { $description .= $lang['summary'] . ": " . $summary; } } $this -> _payload = '' . $title . '
' . $description; } private function _get_url ( $event = null, $Rev ) { global $ID; global $conf; $page = $event -> data['id']; if ( ( $conf['userewrite'] == 1 || $conf['userewrite'] == 2 ) && $conf['useslash'] == true ) $page = str_replace ( ":", "/", $page ); switch ( $conf['userewrite'] ) { case 0: $url = DOKU_URL . "doku.php?id={$page}"; break; case 1: $url = DOKU_URL . $page; break; case 2: $url = DOKU_URL . "doku.php/{$page}"; break; } if ( $Rev != null ) { switch ( $conf['userewrite'] ) { case 0: $url .= "&do=diff&rev={$Rev}"; break; case 1: case 2: $url .= "?do=diff&rev={$Rev}"; break; } } return $url; } public function submit_payload ( ) { $server = rtrim($this->getConf('server'), '/'); $token = $this->getConf('access_token'); $room = trim($this->getConf('room')); if (empty($server) || empty($token) || empty($room)) { throw new Exception("Matrix settings are incomplete."); } // Mimic the exact old legacy join layer mechanism $joinUrl = $server . "/_matrix/client/v3/join/" . urlencode($room); $ch = curl_init($joinUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Authorization: Bearer ' . $token )); $res = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($code === 200) { $data = json_decode($res, true); if (isset($data['room_id'])) { $room = $data['room_id']; // Captured valid canonical crypt target ID! } } else { // If join yields any status other than 200, throw explicit tracking logs $resArr = json_decode($res, true); $errStr = isset($resArr['error']) ? $resArr['error'] : 'HTTP ' . $code; throw new Exception("Legacy handshake routing mapping failed: " . $errStr); } // Deliver payload out to the extracted location block $url = $server . "/_matrix/client/v3/rooms/" . urlencode($room) . "/send/m.room.message"; $msgBody = array( "msgtype" => "m.text", "body" => strip_tags(str_replace(array('
', '
'), "\n", $this->_payload)), "format" => "org.matrix.custom.html", "formatted_body"=> $this->_payload ); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($msgBody)); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Authorization: Bearer ' . $token )); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlErr = curl_error($ch); curl_close($ch); if (!empty($curlErr)) { throw new Exception("Network Error: " . $curlErr); } if ($httpCode < 200 || $httpCode >= 300) { $resArr = json_decode($response, true); $errStr = isset($resArr['error']) ? $resArr['error'] : 'Unknown HTTP Status ' . $httpCode; throw new Exception("Server Error: " . $errStr); } } }