OpenRat.class.php (5891B)
1 <?php 2 3 4 class OpenRat { 5 6 public $text = ''; 7 public $subject; 8 public $pageId; 9 public $name; 10 public $debug = true; 11 public $timestamp; 12 public $config; 13 14 private $client; 15 16 private function request( $method,$parameter ) 17 { 18 19 $this->client->parameter = $parameter; 20 $this->client->method = $method; 21 $this->client->request(); 22 23 if ( $this->client->status != '200' || $this->debug) 24 { 25 echo '<span style="background-color:'.($this->client->status=='200'?'green':'red').'">HTTP-Status '.$this->client->status.'</span>'; 26 echo "<h4>".$parameter['action'].'/'.$parameter['subaction'].'</h4>'; 27 ?><pre><?php print_r(""); ?></pre><pre><?php print_r($this->client->response); ?></pre><?php 28 } 29 30 $response = json_decode($this->client->response,true); 31 32 if ( $response == null ) 33 { 34 echo '<span style="background-color:red">Kein JSON: <pre>'.htmlentities($this->client->response).'</pre></span>'; 35 exit; 36 } 37 38 return $response; 39 } 40 41 42 public function push() 43 { 44 $filesToPublish = array(); 45 require_once('./cms/openrat/OpenratClient.php'); 46 $this->client = new OpenratClient(); 47 48 $this->client->host = $this->config['host']; 49 $this->client->port = $this->config['port']; 50 $this->client->path = $this->config['path']; 51 $this->client->type ="application/json"; 52 53 54 $response = $this->request( 'GET', 55 array('action' =>'login', 56 'subaction'=>'login') ); 57 58 $token = $response['session']['token']; 59 $this->client->cookie =$response['session']['name'].'='.$response['session']['id']; 60 61 62 $response = $this->request( 'POST', array( 63 'action' => 'login', 64 'subaction' => 'login', 65 'token' => $token, 66 'dbid' => $this->config['database'], 67 'login_name' => $this->config['user' ], 68 'login_password'=> $this->config['password'] ) ); 69 70 $this->client->cookie =$response['session']['name'].'='.$response['session']['id']; 71 $token = $response['session']['token']; 72 73 74 // Projekt auswählen 75 $response = $this->request( 'POST', array( 76 'action' => 'start', 77 'subaction' => 'projectmenu', 78 'token' => $token, 79 'id' => $this->config['projectid']) ); 80 81 // Seite laden. 82 $responsePage = $this->request( 'GET', array 83 ( 84 'action' => 'page', 85 'subaction' => 'info', 86 'id' => $this->pageId, 87 'token' => $token 88 ) ); 89 90 // Inhalt laden und nachschauen, ob es schon einen Kommentare-Ordner gibt. 91 $responseLink = $this->request( 'GET', array 92 ( 93 'action' => 'pageelement', 94 'subaction' => 'edit', 95 'id' => $this->pageId.'_'.$this->config['page_elementid_comments'], 96 'token' => $token 97 ) ); 98 99 $commentFolderId = $responseLink['output']['linkobjectid']; 100 101 if ( empty($commentFolderId)) { 102 103 // Der Kommentarordner existiert noch nicht, also müssen wir diesen anlegen. 104 105 // Wo kommen die Kommentarordner rein? 106 // Kann konfiguriert werden. Falls nicht, dann in den Ordner, der die Seite enthält. 107 $commentContainerFolderId = intval($this->config['comment_folder_id']); 108 if ( $commentContainerFolderId == 0 ) 109 $commentContainerFolderId = $responsePage['output']['parentid']; 110 111 $responseCreate = $this->request( 'POST', array 112 ( 113 'action' => 'folder', 114 'subaction' => 'createfolder', 115 'id' => $commentContainerFolderId, 116 'token' => $token, 117 'name' => 'comment-'.$this->pageId 118 ) ); 119 $commentFolderId = $responseCreate['output']['objectid']; 120 121 // Ordner für die Kommentare in der Seite speichern 122 $response = $this->request( 'POST', array 123 ( 124 'action' => 'pageelement', 125 'subaction' => 'edit', 126 'id' => $this->pageId, 127 'elementid' => $this->config['page_elementid_comments'], 128 'token' => $token, 129 'release' => '1', 130 'linkobjectid' => $commentFolderId 131 ) ); 132 133 } 134 135 136 // Seite für den Kommentar anlegen. 137 $response = $this->request( 'POST', array 138 ( 139 'action' => 'folder', 140 'subaction' => 'createpage', 141 'id' => $commentFolderId, 142 'templateid' => $this->config['comment_templateid'], 143 'token' => $token, 144 'name' => 'Kommentar: '.$this->subject, 145 'filename' => 'comment-'.$this->subject, 146 ) ); 147 148 $commentpageobjectid = $response['output']['objectid']; 149 150 // Text speichern anlegen. 151 $response = $this->request( 'POST', array 152 ( 153 'action' => 'pageelement', 154 'subaction' => 'edit', 155 'id' => $commentpageobjectid, 156 'elementid' => $this->config['elementid_text'], 157 'token' => $token, 158 'release' => '1', 159 'text' => $this->text 160 ) ); 161 162 // Betreff speichern anlegen. 163 $response = $this->request( 'POST', array 164 ( 165 'action' => 'pageelement', 166 'subaction' => 'edit', 167 'id' => $commentpageobjectid, 168 'elementid' => $this->config['elementid_subject'], 169 'token' => $token, 170 'release' => '1', 171 'text' => $this->subject 172 ) ); 173 174 // Name speichern anlegen. 175 $response = $this->request( 'POST', array 176 ( 177 'action' => 'pageelement', 178 'subaction' => 'edit', 179 'id' => $commentpageobjectid, 180 'elementid' => $this->config['elementid_name'], 181 'token' => $token, 182 'release' => '1', 183 'text' => $this->name 184 ) ); 185 186 187 // Veröffentlichen der Seiten, welche jetzt den Kommentar enthält. 188 $response = $this->request( 'POST', array 189 ( 190 'action' => 'page', 191 'subaction' => 'pub', 192 'id' => $this->pageId, 193 'token' => $token 194 ) ); 195 196 197 mail('jan.2015@jandankert.de','Neuer Kommentar von '.$this->name.': '.$this->subject,'Text:\n\n'.$this->text); 198 } 199 200 201 } 202 203 ?>