Created
May 8, 2013 09:44
-
-
Save dvdsmpsn/5539425 to your computer and use it in GitHub Desktop.
Scrappy PHP script to search a remote Confluence - returns the 1st 6 results only. More details: https://answers.atlassian.com/questions/167066/integrating-confluence-in-to-our-website?page=1#167129
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Search</title> | |
</head> | |
<body> | |
<h1>Search Atlassian's documentation</h1> | |
<form> | |
<input name="q" placeholder="Search Confluence..."> | |
<input type="submit"> | |
</form> | |
<?php if (isset($_GET['q'])) { | |
$query = rawurlencode( $_GET['q']); | |
$timestamp = time(); | |
$baseUrl = 'http://confluence.atlassian.com'; | |
$url = $baseUrl.'/json/contentnamesearch.action?query='.$query.'&_='.$timestamp; | |
$response = file_get_contents($url); | |
$response = json_decode($response); | |
$results = $response->contentNameMatches[0]; | |
?> | |
<h2>Results</h2> | |
<div>Searching: <?php echo $url; ?> | |
<h3>Formatted</h3> | |
<ol> | |
<?php foreach($results as $item) {?> | |
<li><strong><a href="<?= $baseUrl. $item->href ?>"><?= $item->name ?></a></strong> in <a href="<?= $baseUrl.'/display/'.$item->spaceKey ?>"><?= $item->spaceName ?></a></li> | |
<?php } ?> | |
</ol> | |
<h3>Raw JSON</h3> | |
<pre> | |
<?php print_r($response); ?> | |
</pre> | |
<?php } ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment