[submodule "couchdb/couchdb-lucene"] | [submodule "couchdb/couchdb-lucene"] |
path = couchdb/couchdb-lucene | path = couchdb/couchdb-lucene |
url = https://github.com/rnewson/couchdb-lucene.git | url = https://github.com/rnewson/couchdb-lucene.git |
[submodule "couchdb/settee"] | [submodule "couchdb/settee"] |
path = couchdb/settee | path = couchdb/settee |
url = https://github.com/inadarei/settee.git | url = https://github.com/inadarei/settee.git |
[submodule "lib/springy"] | [submodule "lib/springy"] |
path = lib/springy | path = lib/springy |
url = https://github.com/dhotson/springy.git | url = https://github.com/dhotson/springy.git |
[submodule "lib/php-diff"] | [submodule "lib/php-diff"] |
path = lib/php-diff | path = lib/php-diff |
url = https://github.com/chrisboulton/php-diff.git | url = https://github.com/chrisboulton/php-diff.git |
[submodule "lib/Requests"] | [submodule "lib/Requests"] |
path = lib/Requests | path = lib/Requests |
url = https://github.com/rmccue/Requests.git | url = https://github.com/rmccue/Requests.git |
[submodule "javascripts/flotr2"] | [submodule "javascripts/flotr2"] |
path = javascripts/flotr2 | path = javascripts/flotr2 |
url = https://github.com/HumbleSoftware/Flotr2.git | url = https://github.com/HumbleSoftware/Flotr2.git |
[submodule "lib/phpquery"] | |
path = lib/phpquery | |
url = https://github.com/TobiaszCudnik/phpquery.git | |
<?php | |
require_once '../include/common.inc.php'; | |
$db = $server->get_db('disclosr-agencies'); | |
$rows = $db->get_view("app", "byName")->rows; | |
$nametoid = Array(); | |
$accounts = Array(); | |
foreach ($rows as $row) { | |
$nametoid[trim($row->key)] = $row->value; | |
} | |
function extractCSVAccounts($url, $nameField, $accountField, $filter) { | |
global $accounts, $nametoid; | |
$request = Requests::get($url); | |
$Data = str_getcsv($request->body, "\n"); //parse the rows | |
$headers = Array(); | |
foreach ($Data as $num => $line) { | |
$Row = str_getcsv($line, ","); | |
if ($num == 0) { | |
} else if ($num == 1) { | |
$headers = $Row; | |
//print_r($headers); | |
} else { | |
if (isset($Row[array_search($nameField, $headers)])) { | |
$agencyName = $Row[array_search($nameField, $headers)]; | |
if (!$filter || $Row[array_search("State", $headers)] == "NAT") { | |
if (!in_array(trim($agencyName), array_keys($nametoid))) { | |
echo "$agencyName missing" . PHP_EOL; | |
} else { | |
// echo $Row[array_search($nameField, $headers)] . PHP_EOL; | |
} | |
} | |
} else { | |
//echo "error finding agency" . $line . PHP_EOL; | |
} | |
} | |
} | |
} | |
// http://agimo.govspace.gov.au/page/gov2register/ | |
//extractCSVAccounts("https://docs.google.com/spreadsheet/pub?key=0Ap1exl80wB8OdHNKVmQ5RVlvQWpibDAxNHkzcU1nV2c&single=true&gid=0&output=csv", "Agency/Body/Event", "", true); | |
// RSS | |
// https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGJxandJREhLSGlWWUZfZ2xKOTNHZ0E&output=csv | |
extractCSVAccounts("https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGtjcW9vOXdyZ3pOV21vQU51VmhzQnc&single=true&gid=0&output=csv","Agency","Name"); | |
/* | |
* http://australia.gov.au/news-and-media/media-release-rss-feeds | |
* http://australia.gov.au/news-and-media/social-media/blogs | |
* http://australia.gov.au/news-and-media/social-media/twitter | |
* http://australia.gov.au/news-and-media/social-media/facebook | |
* http://australia.gov.au/news-and-media/social-media/youtube | |
* http://australia.gov.au/news-and-media/social-media/flickr | |
* http://australia.gov.au/news-and-media/social-media/apps http://www.harmony.gov.au/get-involved/app-downloads.htm http://www.em.gov.au/Resources/Pages/Before-the-Storm-phone-game.aspx | |
* http://australia.gov.au/news-and-media/social-media/podcasts | |
*/ | |
?> | |
<?php | <?php |
require_once '../include/common.inc.php'; | require_once '../include/common.inc.php'; |
try { | require($basePath.'lib/phpquery/phpQuery/phpQuery.php'); |
$server->create_db('disclosr-agencies'); | |
} catch (SetteeRestClientException $e) { | $db = $server->get_db('disclosr-agencies'); |
setteErrorHandler($e); | $rows = $db->get_view("app", "byName")->rows; |
$nametoid = Array(); | |
$accounts = Array(); | |
foreach ($rows as $row) { | |
$nametoid[trim($row->key)] = $row->value; | |
} | } |
$db = $server->get_db('disclosr-agencies'); | function extractHTMLAccounts($url, $accountType) { |
createAgencyDesignDoc(); | global $accounts, $nametoid; |
$request = Requests::get($url); | |
$doc = phpQuery::newDocumentHTML($request->body); | |
phpQuery::selectDocument($doc); | |
foreach (pq('tr')->elements as $tr) { | |
//echo $tr->nodeValue.PHP_EOL; | |
$agency = ""; | |
$url = ""; | |
foreach ($tr->childNodes as $td) { | |
$class = $td->getAttribute("class"); | |
//echo "cccc $class ".$td->nodeValue.PHP_EOL; | |
if ($class == "s11" || $class == "s10" || $class == "s7") { | |
$agency = $td->nodeValue; | |
} else if ($class == "s6" || $class == "s9"){ | |
$url = $td->nodeValue; | |
foreach($td->childNodes as $a) { | |
$href = $a->getAttribute("href"); | |
if ($href != "") { | |
$url = $href; | |
} | |
} | |
} | |
} | |
if ($agency != "" && $url != "") { | |
if (!in_array(trim($agency), array_keys($nametoid))) { | |
echo trim($agency)." missing" . PHP_EOL; | |
} else { | |
// echo $agency." = ".$url.PHP_EOL; | |
$accounts[$nametoid[trim($agency)]][$accountType][] = $url; | |
} | |
} | |
} | |
} | |
// twitter https://docs.google.com/spreadsheet/fm?id=tsJVd9EYoAjbl014y3qMgWg.03918275400592898296.8568379511161083736&hl=en&fmcmd=5&gid=0 | function extractCSVAccounts($url, $accountType, $nameField, $accountField, $filter) { |
// RSS https://docs.google.com/spreadsheet/fm?id=tbqjwIDHKHiVYF_glJ93GgA.03918275400592898296.8789688748524615194&authkey=CJDP-uQG&hl=en_GB&fmcmd=5&gid=0 | global $accounts, $nametoid; |
// facebook https://docs.google.com/spreadsheet/fm?id=tkcqoo9wrgzNWmoANuVhsBw.03918275400592898296.3040387705062056060&authkey=CKzl7r0I&hl=en_GB&fmcmd=5&gid=0 | $request = Requests::get($url); |
$Data = str_getcsv($request->body, "\n"); //parse the rows | |
$headers = Array(); | |
foreach ($Data as $num => $line) { | |
$Row = str_getcsv($line, ",",'"'); | |
if ($num == 0) { | |
} else if ($num == 1) { | |
$headers = $Row; | |
//print_r($headers); | |
} else { | |
if (isset($Row[array_search($nameField, $headers)])) { | |
$agencyName = $Row[array_search($nameField, $headers)]; | |
if (!$filter || $Row[array_search("State", $headers)] == "NAT") { | |
if (!in_array(trim($agencyName), array_keys($nametoid))) { | |
echo trim($agencyName)." missing" . PHP_EOL; | |
} else { | |
// echo $Row[array_search($nameField, $headers)] . PHP_EOL; | |
$accounts[$nametoid[trim($agencyName)]][$accountType][] = $Row[array_search($accountField, $headers)]; | |
} | |
} | |
} else { | |
//echo "error finding agency" . $line . PHP_EOL; | |
} | |
} | |
} | |
} | |
/* | // http://agimo.govspace.gov.au/page/gov2register/ |
* http://australia.gov.au/news-and-media/media-release-rss-feeds | |
* http://australia.gov.au/news-and-media/social-media/blogs | extractCSVAccounts("https://docs.google.com/spreadsheet/pub?key=0Ap1exl80wB8OdHNKVmQ5RVlvQWpibDAxNHkzcU1nV2c&single=true&gid=0&output=csv", "Twitter", "Agency/Body/Event", "", true); |
* http://australia.gov.au/news-and-media/social-media/twitter | // RSS |
* http://australia.gov.au/news-and-media/social-media/facebook | extractHTMLAccounts("https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGJxandJREhLSGlWWUZfZ2xKOTNHZ0E&output=html", "RSS"); |
* http://australia.gov.au/news-and-media/social-media/youtube | |
* http://australia.gov.au/news-and-media/social-media/flickr | extractHTMLAccounts("https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGtjcW9vOXdyZ3pOV21vQU51VmhzQnc&single=true&gid=0&output=html", "Facebook"); |
* http://australia.gov.au/news-and-media/social-media/apps http://www.harmony.gov.au/get-involved/app-downloads.htm http://www.em.gov.au/Resources/Pages/Before-the-Storm-phone-game.aspx | |
* http://australia.gov.au/news-and-media/social-media/podcasts | |
*/ | |
?> | ?> |
<?php | <?php |
include_once('include/common.inc.php'); | include_once('include/common.inc.php'); |
include_header(); | include_header(); |
function displayValue($key, $value, $mode) { | function displayValue($key, $value, $mode) { |
global $db, $schemas; | global $db, $schemas; |
if ($mode == "view") { | if ($mode == "view") { |
echo "<tr>"; | echo "<tr>"; |
echo "<td>" . $schemas['agency']["properties"][$key]['x-title'] . "<br><small>" . $schemas['agency']["properties"][$key]['description'] . "</small></td><td>"; | echo "<td>" . $schemas['agency']["properties"][$key]['x-title'] . "<br><small>" . $schemas['agency']["properties"][$key]['description'] . "</small></td><td>"; |
if (is_array($value)) { | if (is_array($value)) { |
echo "<ol>"; | echo "<ol>"; |
foreach ($value as $subkey => $subvalue) { | foreach ($value as $subkey => $subvalue) { |
if (isset($schemas['agency']["properties"][$key]['x-property'])) { | if (isset($schemas['agency']["properties"][$key]['x-property'])) { |
echo '<li property="' . $schemas['agency']["properties"][$key]['x-property'] . '">'; | echo '<li property="' . $schemas['agency']["properties"][$key]['x-property'] . '">'; |
} else { | } else { |
echo "<li>"; | echo "<li>"; |
} | } |
echo "$subvalue</li>"; | echo "$subvalue</li>"; |
} | } |
echo "</ol></td></tr>"; | echo "</ol></td></tr>"; |
} else { | } else { |
if (isset($schemas['agency']["properties"][$key]['x-property'])) { | if (isset($schemas['agency']["properties"][$key]['x-property'])) { |
echo '<span property="' . $schemas['agency']["properties"][$key]['x-property'] . '">'; | echo '<span property="' . $schemas['agency']["properties"][$key]['x-property'] . '">'; |
} else { | } else { |
echo "<span>"; | echo "<span>"; |
} | } |
if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") { | if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") { |
echo "<a href='$value'>view</a></span>"; | echo "<a href='$value'>view</a></span>"; |
} else { | } else { |
echo "$value</span>"; | echo "$value</span>"; |
} | } |
} | } |
echo "</td></tr>"; | echo "</td></tr>"; |
} | } |
if ($mode == "edit") { | if ($mode == "edit") { |
if (is_array($value)) { | if (is_array($value)) { |
echo '<div class="row"> | echo '<div class="row"> |
<div class="seven columns"> | <div class="seven columns"> |
<fieldset> | <fieldset> |
<h5>' . $key . '</h5>'; | <h5>' . $key . '</h5>'; |
foreach ($value as $subkey => $subvalue) { | foreach ($value as $subkey => $subvalue) { |
echo "<label>$subkey</label><input class='input-text' type='text' id='$key$subkey' name='$key" . '[' . $subkey . "]' value='$subvalue'/></tr>"; | echo "<label>$subkey</label><input class='input-text' type='text' id='$key$subkey' name='$key" . '[' . $subkey . "]' value='$subvalue'/></tr>"; |
} | } |
echo "</fieldset> | echo "</fieldset> |
</div> | </div> |
</div>"; | </div>"; |
} else { | } else { |
if (strpos($key, "_") === 0) { | if (strpos($key, "_") === 0) { |
echo"<input type='hidden' id='$key' name='$key' value='$value'/>"; | echo"<input type='hidden' id='$key' name='$key' value='$value'/>"; |
} else if ($key == "parentOrg") { | } else if ($key == "parentOrg") { |
echo "<label for='$key'>$key</label><select id='$key' name='$key'><option value=''> Select... </option>"; | echo "<label for='$key'>$key</label><select id='$key' name='$key'><option value=''> Select... </option>"; |
$rows = $db->get_view("app", "byDeptStateName")->rows; | $rows = $db->get_view("app", "byDeptStateName")->rows; |
//print_r($rows); | //print_r($rows); |
foreach ($rows as $row) { | foreach ($rows as $row) { |
echo "<option value='{$row->value}'" . (($row->value == $value) ? "SELECTED" : "") . " >" . str_replace("Department of ", "", $row->key) . "</option>"; | echo "<option value='{$row->value}'" . (($row->value == $value) ? "SELECTED" : "") . " >" . str_replace("Department of ", "", $row->key) . "</option>"; |
} | } |
echo" </select>"; | echo" </select>"; |
} else { | } else { |
echo "<label>$key</label><input class='input-text' type='text' id='$key' name='$key' value='$value'/>"; | echo "<label>$key</label><input class='input-text' type='text' id='$key' name='$key' value='$value'/>"; |
if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") { | if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") { |
echo "<a href='$value'>view</a>"; | echo "<a href='$value'>view</a>"; |
} | } |
if ($key == 'abn') { | if ($key == 'abn') { |
echo "<a href='http://www.abr.business.gov.au/SearchByAbn.aspx?SearchText=$value'>view abn</a>"; | echo "<a href='http://www.abr.business.gov.au/SearchByAbn.aspx?SearchText=$value'>view abn</a>"; |
} | } |
} | } |
} | } |
} | } |
// | // |
} | } |
function addDefaultFields($row) { | function addDefaultFields($row) { |
global $schemas; | global $schemas; |
$defaultFields = array_keys($schemas['agency']['properties']); | $defaultFields = array_keys($schemas['agency']['properties']); |
foreach ($defaultFields as $defaultField) { | foreach ($defaultFields as $defaultField) { |
if (!isset($row[$defaultField])) { | if (!isset($row[$defaultField])) { |
if ($schemas['agency']['properties'][$defaultField]['type'] == "string") { | if ($schemas['agency']['properties'][$defaultField]['type'] == "string") { |
$row[$defaultField] = ""; | |
$row[$defaultField] = ""; | |
} | } |
if ($schemas['agency']['properties'][$defaultField]['type'] == "array") { | if ($schemas['agency']['properties'][$defaultField]['type'] == "array") { |
$row[$defaultField] = Array(""); | $row[$defaultField] = Array(""); |
} | |
} else if ($schemas['agency']['properties'][$defaultField]['type'] == "array") { | |
if (is_array($row[$defaultField])) { | |
$row[$defaultField][] = ""; | |
} else { | |
$value = $row[$defaultField]; | |
$row[$defaultField] = Array($value); | |
} | } |
} | } |
} | } |
return $row; | return $row; |
} | } |
$db = $server->get_db('disclosr-agencies'); | $db = $server->get_db('disclosr-agencies'); |
if (isset($_REQUEST['id'])) { | if (isset($_REQUEST['id'])) { |
//get an agency record as json/html, search by name/abn/id | //get an agency record as json/html, search by name/abn/id |
// by name = startkey="Ham"&endkey="Ham\ufff0" | // by name = startkey="Ham"&endkey="Ham\ufff0" |
// edit? | // edit? |
$row = $db->get($_REQUEST['id']); | $row = $db->get($_REQUEST['id']); |
//print_r($row); | //print_r($row); |
if (sizeof($_POST) > 0) { | if (sizeof($_POST) > 0) { |
//print_r($_POST); | //print_r($_POST); |
foreach ($_POST as $postkey => $postvalue) { | foreach ($_POST as $postkey => $postvalue) { |
if ($postvalue == "") { | if ($postvalue == "") { |
unset($_POST[$postkey]); | unset($_POST[$postkey]); |
} | } |
if (is_array($postvalue) && count($postvalue) == 1 && $postvalue[0] == "") { | if (is_array($postvalue)) { |
unset($_POST[$postkey]); | if (count($postvalue) == 1 && $postvalue[0] == "") { |
unset($_POST[$postkey]); | |
} else { | |
foreach ($_POST[$postkey] as $key => &$value) { | |
if ($value == "") { | |
unset($_POST[$postkey][$key]); | |
} | |
} | |
} | |
} | } |
} | } |
if (isset($_POST['_id']) && $db->get_rev($_POST['_id']) == $_POST['_rev']) { | if (isset($_POST['_id']) && $db->get_rev($_POST['_id']) == $_POST['_rev']) { |
echo "Edited version was latest version, continue saving"; | echo "Edited version was latest version, continue saving"; |
$newdoc = $_POST; | $newdoc = $_POST; |
$newdoc['metadata']['lastModified'] = time(); | $newdoc['metadata']['lastModified'] = time(); |
$row = $db->save($newdoc); | $row = $db->save($newdoc); |
} else { | } else { |
echo "ALERT doc revised by someone else while editing. Document not saved."; | echo "ALERT doc revised by someone else while editing. Document not saved."; |
} | } |
} | } |
$mode = "edit"; | $mode = "edit"; |
if ($mode == "edit") { | if ($mode == "edit") { |
$row = addDefaultFields(object_to_array($row)); | $row = addDefaultFields(object_to_array($row)); |
} else { | } else { |
$row = object_to_array($row); | $row = object_to_array($row); |