Beginning of socmed import
Former-commit-id: d2b0f68cc699456c27ed21dffefc4e6164cf21aa
--- a/admin/importGov2RegisterRSSFacebookTwitter.php
+++ b/admin/importGov2RegisterRSSFacebookTwitter.php
@@ -1,17 +1,51 @@
<?php
require_once '../include/common.inc.php';
-try {
- $server->create_db('disclosr-agencies');
-} catch (SetteeRestClientException $e) {
- setteErrorHandler($e);
+
+$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;
}
-$db = $server->get_db('disclosr-agencies');
-createAgencyDesignDoc();
-// twitter https://docs.google.com/spreadsheet/fm?id=tsJVd9EYoAjbl014y3qMgWg.03918275400592898296.8568379511161083736&hl=en&fmcmd=5&gid=0
-// RSS https://docs.google.com/spreadsheet/fm?id=tbqjwIDHKHiVYF_glJ93GgA.03918275400592898296.8789688748524615194&authkey=CJDP-uQG&hl=en_GB&fmcmd=5&gid=0
-// facebook https://docs.google.com/spreadsheet/fm?id=tkcqoo9wrgzNWmoANuVhsBw.03918275400592898296.3040387705062056060&authkey=CKzl7r0I&hl=en_GB&fmcmd=5&gid=0
+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/
+// twitter
+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
+// facebook
+//extractCSVAccounts("https://docs.google.com/spreadsheet/pub?hl=en_GB&hl=en_GB&key=0Ah41IAK0HzSTdGtjcW9vOXdyZ3pOV21vQU51VmhzQnc&single=true&gid=0&output=csv","","");
/*
* http://australia.gov.au/news-and-media/media-release-rss-feeds
--- a/getAgency.php
+++ b/getAgency.php
@@ -14,10 +14,10 @@
echo "<ol>";
foreach ($value as $subkey => $subvalue) {
if (isset($schemas['agency']["properties"][$key]['x-property'])) {
- echo '<li property="' . $schemas['agency']["properties"][$key]['x-property'] . '">';
- } else {
- echo "<li>";
- }
+ echo '<li property="' . $schemas['agency']["properties"][$key]['x-property'] . '">';
+ } else {
+ echo "<li>";
+ }
echo "$subvalue</li>";
}
echo "</ol></td></tr>";
@@ -27,11 +27,11 @@
} else {
echo "<span>";
}
- if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") {
- echo "<a href='$value'>view</a></span>";
- } else {
- echo "$value</span>";
- }
+ if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") {
+ echo "<a href='$value'>view</a></span>";
+ } else {
+ echo "$value</span>";
+ }
}
echo "</td></tr>";
}
@@ -53,12 +53,12 @@
} else if ($key == "parentOrg") {
echo "<label for='$key'>$key</label><select id='$key' name='$key'><option value=''> Select... </option>";
$rows = $db->get_view("app", "byDeptStateName")->rows;
- //print_r($rows);
+//print_r($rows);
foreach ($rows as $row) {
echo "<option value='{$row->value}'" . (($row->value == $value) ? "SELECTED" : "") . " >" . str_replace("Department of ", "", $row->key) . "</option>";
}
echo" </select>";
- } else {
+ } else {
echo "<label>$key</label><input class='input-text' type='text' id='$key' name='$key' value='$value'/>";
if ((strpos($key, "URL") > 0 || $key == 'website') && $value != "") {
echo "<a href='$value'>view</a>";
@@ -69,7 +69,7 @@
}
}
}
- //
+//
}
function addDefaultFields($row) {
@@ -78,13 +78,17 @@
foreach ($defaultFields as $defaultField) {
if (!isset($row[$defaultField])) {
if ($schemas['agency']['properties'][$defaultField]['type'] == "string") {
-
- $row[$defaultField] = "";
-
+ $row[$defaultField] = "";
}
if ($schemas['agency']['properties'][$defaultField]['type'] == "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);
}
}
}
@@ -94,20 +98,28 @@
$db = $server->get_db('disclosr-agencies');
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"
// edit?
$row = $db->get($_REQUEST['id']);
- //print_r($row);
+//print_r($row);
if (sizeof($_POST) > 0) {
- //print_r($_POST);
+//print_r($_POST);
foreach ($_POST as $postkey => $postvalue) {
if ($postvalue == "") {
unset($_POST[$postkey]);
}
- if (is_array($postvalue) && count($postvalue) == 1 && $postvalue[0] == "") {
- unset($_POST[$postkey]);
+ if (is_array($postvalue)) {
+ 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']) {
@@ -124,9 +136,9 @@
if ($mode == "edit") {
$row = addDefaultFields(object_to_array($row));
} else {
- $row = object_to_array($row);
- }
-
+ $row = object_to_array($row);
+ }
+
if ($mode == "view") {
echo '<div typeof="schema:GovernmentOrganisation" about="#' . $row['_id'] . '"><table width="100%">';
echo '<tr> <td colspan="2"><h3>' . $row['name'] . "</h3></td></tr>";
@@ -153,44 +165,44 @@
};
</script>
<form id="editform" class="nice" method="post">
- <?php
-
- }
- foreach ($row as $key => $value) {
- echo displayValue($key, $value, $mode);
- }
- if ($mode == "view") {
- echo "</table></div>";
- }
- if ($mode == "edit") {
- echo '<input id="submitbutton" type="submit"/></form>';
- }
-} else {
-
- try {
- /* $rows = $db->get_view("app", "showNamesABNs")->rows;
- //print_r($rows);
- foreach ($rows as $row) {
- // print_r($row);
- echo '<li><a href="getAgency.php?id=' . $row->key . '">' .
- (isset($row->value->name) && $row->value->name != "" ? $row->value->name : "NO NAME " . $row->value->abn)
- . '</a></li>';
- } */
- $rows = $db->get_view("app", "byName")->rows;
- //print_r($rows);
-echo '<ul>';
- foreach ($rows as $row) {
- // print_r($row);
- echo '<li typeof="schema:GovernmentOrganisation foaf:Organization" about="getAgency.php?id=' . $row->value . '">
+ <?php
+
+ }
+ foreach ($row as $key => $value) {
+ echo displayValue($key, $value, $mode);
+ }
+ if ($mode == "view") {
+ echo "</table></div>";
+ }
+ if ($mode == "edit") {
+ echo '<input id="submitbutton" type="submit"/></form>';
+ }
+ } else {
+
+ try {
+ /* $rows = $db->get_view("app", "showNamesABNs")->rows;
+ //print_r($rows);
+ foreach ($rows as $row) {
+ // print_r($row);
+ echo '<li><a href="getAgency.php?id=' . $row->key . '">' .
+ (isset($row->value->name) && $row->value->name != "" ? $row->value->name : "NO NAME " . $row->value->abn)
+ . '</a></li>';
+ } */
+ $rows = $db->get_view("app", "byName")->rows;
+ //print_r($rows);
+ echo '<ul>';
+ foreach ($rows as $row) {
+ // print_r($row);
+ echo '<li typeof="schema:GovernmentOrganisation foaf:Organization" about="getAgency.php?id=' . $row->value . '">
<a href="getAgency.php?id=' . $row->value . '" rel="schema:url foaf:page" property="schema:name foaf:name">' .
- $row->key
- . '</a></li>';
- }
-echo "</ul>";
- } catch (SetteeRestClientException $e) {
- setteErrorHandler($e);
- }
-}
-include_footer();
-?>
-
+ $row->key
+ . '</a></li>';
+ }
+ echo "</ul>";
+ } catch (SetteeRestClientException $e) {
+ setteErrorHandler($e);
+ }
+ }
+ include_footer();
+ ?>
+
--- a/schemas/agency.json.php
+++ b/schemas/agency.json.php
@@ -33,6 +33,8 @@
"appointmentsURL" => Array("type" => "string", "required" => true, "x-title" => "Agency Appointments/Boards", "description" => "Departmental and agency appointments and vacancies , <a href='http://www.aph.gov.au/senate/pubs/standing_orders/d05.htm'>mandated by the Senate</a>"),
"advertisingURL" => Array("type" => "string", "required" => true, "x-title" => "Approved Advertising Campaigns", "description" => " Agency advertising and public information projects, <a href='http://www.aph.gov.au/senate/pubs/standing_orders/d05.htm'>mandated by the Senate</a> "),
"hasRSS" => Array("type" => "array", "required" => true, "x-title" => "Has RSS", "description" => ""),
+ "hasBlog" => Array("type" => "array", "required" => true, "x-title" => "Has Blog", "description" => ""),
+ "hasMobileApp" => Array("type" => "array", "required" => true, "x-title" => "Has Mobile App", "description" => ""),
"hasMailingList" => Array("type" => "array", "required" => true, "x-title" => "Has Mailing List", "description" => "",
"items" => Array("type" => "string")),
"hasTwitter" => Array("type" => "array", "required" => true, "x-title" => "Has Twitter", "description" => "",