function _on_watched_dba_update($object) { // Note: the API key has to be defined in /etc/midgard/midcom.conf $apikey = $GLOBALS['midcom_config']['qaiku_apikey']; $_MIDCOM->load_library('org.openpsa.httplib'); $message = array('channel' => 'opendata', 'source' => 'opengov.fi', 'lang' => 'fi', 'status' => '', 'external_url' => ''); if ($object->get_parameter('fi.opengov.datacatalog', 'qaiku_id')) { // This is already on Qaiku, skip return; } if ($object instanceof midcom_baseclasses_database_article) { // Check that the article is a visible one $topic = new midcom_db_topic($object->topic); if ($topic->component != 'net.nehmer.blog') { return; } $message['status'] = "[blog] {$object->title}"; } elseif ($object instanceof fi_opengov_datacatalog_dataset_dba) { // Check that the dataset is a published one if (!fi_opengov_datacatalog_dataset_dba::matching_license_type($object->guid, 'free')) { // We don't publicize closed datasets return; } $message['status'] = "[dataset] {$object->title}"; } else { return; } $message['external_url'] = $_MIDCOM->permalinks->resolve_permalink($object->guid); $http = new org_openpsa_httplib(); $json = $http->post("http://www.qaiku.com/api/statuses/update.json?apikey={$apikey}", $message); $qaiku = json_decode($json); if (is_object($qaiku) && isset($qaiku->id)) { $object->set_parameter('fi.opengov.datacatalog', 'qaiku_id', $qaiku->id); } }
if (isset($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && !empty($_SERVER['PHP_AUTH_PW'])) { $http_client->basicauth['user'] = $_SERVER['PHP_AUTH_USER']; $http_client->basicauth['password'] = $_SERVER['PHP_AUTH_PW']; } while (!is_null($nodeid)) { // Update script execution time // This should suffice for really large topics as well. set_time_limit(5000); // Reindex the node... $node = $nap->get_node($nodeid); echo "Processing node #{$nodeid}, {$node[MIDCOM_NAV_FULLURL]}: "; flush(); //pass the node-id & the language $post_variables = array('nodeid' => $nodeid, 'language' => $language); $post_string = 'nodeid=' . $nodeid . '&language=' . $language; $response = $http_client->post($reindex_topic_uri, $post_variables, array('User-Agent' => 'midcom-exec-midcom/reindex.php')); if ($response === false) { // returned with failure echo "failure.\n Background processing failed, error: {$http_client->error}\n"; echo "Url: " . $reindex_topic_uri . "?" . $post_string . "\n"; } else { if (!preg_match("#(\n|\r\n)Reindex complete for node http.*\\s*</pre>\\s*\$#", $response)) { // Does not end with 'Reindex complete for node...' echo "failure.\n Background reindex returned unexpected data:\n---\n{$response}\n---\n"; echo "Url: " . $reindex_topic_uri . "?" . $post_string . "\n\n"; } else { // Background reindex ok echo "OK.\n"; } } flush();
<form method="post"> <h2>address and data</h2> URL: <input name="url" value="" /><br/> Key => Value array (for eval())<br/> <textarea name="variables" rows=10 cols=40>'key' => 'value', </textarea> <h2>basic auth (optional)</h2> Username: <input name="username" value="" /><br/> Password: <input name="password" value="" /><br/> <input type="submit" value="post" /> </form> <?php } else { $client = new org_openpsa_httplib(); eval("\$vars = array({$_REQUEST['variables']});"); if (isset($_REQUEST['username']) && !empty($_REQUEST['username']) && isset($_REQUEST['password']) && !empty($_REQUEST['password'])) { $client->basicauth['user'] = $_REQUEST['username']; $client->basicauth['password'] = $_REQUEST['password']; } if (!isset($vars)) { $display = "<h1>Error</h1>\n<p>Could not determine variables to post</p>"; } else { $response = $client->post($_REQUEST['url'], $vars); if (!$response) { $display = "<h1>Error</h1>\n<p>Client error: {$client->error}</p>"; } else { $display = "<h1>Success</h1>\n{$response}"; } } echo $display; }