Rev 6 | Rev 8 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6 | Rev 7 | ||
---|---|---|---|
Line 7... | Line 7... | ||
7 | if ($argc <> 2) { |
7 | if ($argc <> 2) { |
8 | echo "Syntax: $argv[0] <line>\n"; |
8 | echo "Syntax: $argv[0] <line>\n"; |
9 | exit(2); |
9 | exit(2); |
10 | } |
10 | } |
11 | 11 | ||
- | 12 | if (isset($stam_cfg['weblog2_system']) && !empty($stam_cfg['weblog2_system'])) { |
|
- | 13 | ||
- | 14 | ||
- | 15 | $ent = rtrim($argv[1]); |
|
- | 16 | ||
- | 17 | # --- |
|
- | 18 | ||
- | 19 | ||
- | 20 | $oidplus_rest_auth = $stam_cfg['weblog2_auth']; |
|
- | 21 | ||
- | 22 | /* |
|
- | 23 | $data = array(); |
|
- | 24 | $ch = curl_init($stam_cfg['weblog2_system']."rest/v1/objects/oid:".$stam_cfg['weblog2_oid']); |
|
- | 25 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
- | 26 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); |
|
- | 27 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); |
|
- | 28 | curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer $oidplus_rest_auth")); |
|
- | 29 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
- | 30 | $i=0; for($i=0;$i<10;$i++) { $response = curl_exec($ch); if ($response) { break; } else { sleep(1); } } |
|
- | 31 | if ((!$response) || (json_decode($response,true)['status'] < 0)) |
|
- | 32 | { |
|
- | 33 | fwrite(STDERR, "Weblog GET failed: $response\n"); |
|
- | 34 | exit(2); |
|
- | 35 | } |
|
- | 36 | #echo "$response\n\n"; |
|
- | 37 | $children = json_decode($response,true)['children']; |
|
- | 38 | if (count($children) == 0) { |
|
- | 39 | $lfd = 1; |
|
- | 40 | } else { |
|
- | 41 | natsort($children); |
|
- | 42 | $last = end($children); |
|
- | 43 | $arcs = explode('.', $last); |
|
- | 44 | $lfd = end($arcs)+1; |
|
- | 45 | } |
|
- | 46 | */ |
|
- | 47 | ||
- | 48 | $lfd = floor(microtime(true)*10000); |
|
- | 49 | ||
- | 50 | $data = array("title" => "STAM Weblog Entry", "description" => $ent, "ra_email" => "info@daniel-marschall.de"); |
|
- | 51 | $ch = curl_init($stam_cfg['weblog2_system']."rest/v1/objects/oid:".$stam_cfg['weblog2_oid'].".".$lfd); |
|
- | 52 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
- | 53 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
- | 54 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); |
|
- | 55 | curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer $oidplus_rest_auth")); |
|
- | 56 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
- | 57 | $i=0; for($i=0;$i<10;$i++) { $response = curl_exec($ch); if ($response) { break; } else { sleep(1); } } |
|
- | 58 | if ((!$response) || (json_decode($response,true)['status'] < 0)) |
|
- | 59 | { |
|
- | 60 | fwrite(STDERR, "Weblog POST failed: $response\n"); |
|
- | 61 | exit(2); |
|
- | 62 | } |
|
- | 63 | #echo "$response\n\n"; |
|
- | 64 | ||
- | 65 | echo green("Weblog written (".$stam_cfg['weblog2_oid'].".$lfd)!\n"); |
|
- | 66 | ||
- | 67 | # --- |
|
- | 68 | ||
- | 69 | ||
- | 70 | ||
- | 71 | ||
- | 72 | ||
- | 73 | } |
|
- | 74 | ||
- | 75 | ||
- | 76 | ||
- | 77 | } |
|
- | 78 | ||
12 | if (isset($stam_cfg['weblog_host']) && !empty($stam_cfg['weblog_host'])) { |
79 | if (isset($stam_cfg['weblog_host']) && !empty($stam_cfg['weblog_host'])) { |
13 | db_close(); |
80 | db_close(); |
14 | 81 | ||
15 | $weblog_host = $stam_cfg['weblog_host']; |
82 | $weblog_host = $stam_cfg['weblog_host']; |
16 | $weblog_user = $stam_cfg['weblog_user']; |
83 | $weblog_user = $stam_cfg['weblog_user']; |