Created
August 2, 2010 18:55
-
-
Save technosophos/505116 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "../querypath/src/QueryPath/QueryPath.php"; | |
$apikey = 'YOUR_KEY_HERE'; | |
$text = 'YOUR TEXT HERE'; | |
/* | |
// Code for working with this. | |
$qp = qp('./amp2.xml'); | |
$qp->writeXML(); | |
$qp->find('TopicResult'); | |
foreach($qp as $topic) { | |
print $topic->branch('>Topic>Name')->text() . PHP_EOL; | |
print $topic->branch('>RequestingGuidance>Name')->text() . PHP_EOL; | |
} | |
exit; | |
*/ | |
$params = array(); | |
$response = _amplify_do_request($params, $text); | |
$response->writeXML('./amp2.xml'); | |
function _amplify_do_request($params, $content = NULL) { | |
global $apikey; | |
//$url = 'http://portaltnx.openamplify.com/AmplifyWeb/AmplifyThis?'; | |
//$url = 'http://portaltnx.openamplify.com/AmplifyWeb_v11/AmplifyThis?'; | |
$url = 'http://portaltnx20.openamplify.com/AmplifyWeb_v20/AmplifyThis?'; | |
$params += array( | |
'apiKey' => $apikey, //variable_get('amplify_api_key', ''), | |
//'inputText' => node_view($node), | |
); | |
$url .= http_build_query($params, '', '&'); | |
$options = array( | |
'http' => array( | |
'method' => 'GET', | |
'user_agent' => 'QueryPath/2.1 (CLI)', | |
//'content' => http_build_query(array('inputText' => $content)), | |
//'content' => node_view($params), | |
), | |
); | |
if (!empty($content)) { | |
$options['http']['method'] = 'POST'; | |
$options['http']['header'] = 'Content-type: application/x-www-form-urlencoded'; | |
$options['http']['content'] = http_build_query(array('inputText' => $content)); | |
} | |
$context = stream_context_create($options); | |
try { | |
$qp = qp($url, NULL, array('context' => $context)); | |
} | |
catch (Exception $e) { | |
drupal_set_message(t('Could not amplify the document. The remote server did not return the expected data.'), 'error'); | |
//drupal_set_message($e->getMessage(), 'status'); | |
watchdog('amplify', 'Error: @err', array('@err' => $e->getMessage()), WATCHDOG_ERROR); | |
return; | |
} | |
// if (!isset($qp) || $qp->size() == 0) { | |
// return; | |
// } | |
return $qp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment